forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-account.js
More file actions
113 lines (100 loc) · 2.67 KB
/
Copy pathuser-account.js
File metadata and controls
113 lines (100 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use strict'
/* eslint-disable node/no-deprecated-api */
const url = require('url')
/**
* Represents a Solid user account (created as a result of Signup, etc).
*/
class UserAccount {
/**
* @constructor
* @param [options={}] {Object}
* @param [options.username] {string}
* @param [options.webId] {string}
* @param [options.name] {string}
* @param [options.email] {string}
* @param [options.externalWebId] {string}
* @param [options.localAccountId] {string}
*/
constructor (options = {}) {
this.username = options.username
this.webId = options.webId
this.name = options.name
this.email = options.email
this.externalWebId = options.externalWebId
this.localAccountId = options.localAccountId
this.idp = options.idp
}
/**
* Factory method, returns an instance of `UserAccount`.
*
* @param [options={}] {Object} See `contructor()` docstring.
*
* @return {UserAccount}
*/
static from (options = {}) {
return new UserAccount(options)
}
/**
* Returns the display name for the account.
*
* @return {string}
*/
get displayName () {
return this.name || this.username || this.email || 'Solid account'
}
/**
* Returns the id key for the user account (for use with the user store, for
* example), consisting of the WebID URI minus the protocol and slashes.
* Usage:
*
* ```
* userAccount.webId = 'https://alice.example.com/profile/card#me'
* userAccount.id // -> 'alice.example.com/profile/card#me'
* ```
*
* @return {string}
*/
get id () {
if (!this.webId) { return null }
const parsed = url.parse(this.webId)
let id = parsed.host + parsed.pathname
if (parsed.hash) {
id += parsed.hash
}
return id
}
get accountUri () {
if (!this.webId) { return null }
const parsed = url.parse(this.webId)
return parsed.protocol + '//' + parsed.host
}
/**
* Returns the Uri to the account's Pod
*
* @return {string}
*/
get podUri () {
const webIdUrl = url.parse(this.webId)
const podUrl = `${webIdUrl.protocol}//${webIdUrl.host}`
return url.format(podUrl)
}
/**
* Returns the URI of the WebID Profile for this account.
* Usage:
*
* ```
* // userAccount.webId === 'https://alice.example.com/profile/card#me'
*
* userAccount.profileUri // -> 'https://alice.example.com/profile/card'
* ```
*
* @return {string|null}
*/
get profileUri () {
if (!this.webId) { return null }
const parsed = url.parse(this.webId)
// Note that the hash fragment gets dropped
return parsed.protocol + '//' + parsed.host + parsed.pathname
}
}
module.exports = UserAccount