@data-fair/lib-common-types 0.2.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,4 @@ export interface AccountKeys {
24
24
  export const validate: (data: any) => data is Account
25
25
  export const assertValid: (data: any, options?: import('@data-fair/lib-node/validation.js').AssertValidOptions) => asserts data is Account
26
26
  export const returnValid: (data: any, options?: import('@data-fair/lib-node/validation.js').AssertValidOptions) => Account
27
-
28
- export const schema: any
29
-
27
+
@@ -6,8 +6,7 @@ import { assertValid as assertValidGeneric } from '@data-fair/lib-node/validatio
6
6
 
7
7
  export const schemaExports = [
8
8
  "types",
9
- "validate",
10
- "schema"
9
+ "validate"
11
10
  ]
12
11
 
13
12
  export { validate } from './validate.js'
@@ -18,66 +17,3 @@ export const returnValid = (data, options) => {
18
17
  assertValid(data, options)
19
18
  return data
20
19
  }
21
-
22
- export const schema = {
23
- "$id": "https://github.com/data-fair/lib/account",
24
- "x-exports": [
25
- "types",
26
- "validate",
27
- "schema"
28
- ],
29
- "type": "object",
30
- "title": "account",
31
- "required": [
32
- "type",
33
- "id",
34
- "name"
35
- ],
36
- "properties": {
37
- "type": {
38
- "type": "string",
39
- "enum": [
40
- "user",
41
- "organization"
42
- ]
43
- },
44
- "id": {
45
- "type": "string"
46
- },
47
- "name": {
48
- "type": "string"
49
- },
50
- "department": {
51
- "type": "string"
52
- },
53
- "departmentName": {
54
- "type": "string"
55
- }
56
- },
57
- "$defs": {
58
- "accountKeys": {
59
- "type": "object",
60
- "title": "account keys",
61
- "required": [
62
- "type",
63
- "id"
64
- ],
65
- "additionalProperties": false,
66
- "properties": {
67
- "type": {
68
- "type": "string",
69
- "enum": [
70
- "user",
71
- "organization"
72
- ]
73
- },
74
- "id": {
75
- "type": "string"
76
- },
77
- "department": {
78
- "type": "string"
79
- }
80
- }
81
- }
82
- }
83
- }
@@ -4,7 +4,7 @@
4
4
  "use strict";
5
5
  export const validate = validate14;
6
6
  export default validate14;
7
- const schema16 = {"$id":"https://github.com/data-fair/lib/account","x-exports":["types","validate","schema"],"type":"object","title":"account","required":["type","id","name"],"properties":{"type":{"type":"string","enum":["user","organization"]},"id":{"type":"string"},"name":{"type":"string"},"department":{"type":"string"},"departmentName":{"type":"string"}},"$defs":{"accountKeys":{"type":"object","title":"account keys","required":["type","id"],"additionalProperties":false,"properties":{"type":{"type":"string","enum":["user","organization"]},"id":{"type":"string"},"department":{"type":"string"}}}}};
7
+ const schema16 = {"$id":"https://github.com/data-fair/lib/account","x-exports":["types","validate"],"type":"object","title":"account","required":["type","id","name"],"properties":{"type":{"type":"string","enum":["user","organization"]},"id":{"type":"string"},"name":{"type":"string"},"department":{"type":"string"},"departmentName":{"type":"string"}},"$defs":{"accountKeys":{"type":"object","title":"account keys","required":["type","id"],"additionalProperties":false,"properties":{"type":{"type":"string","enum":["user","organization"]},"id":{"type":"string"},"department":{"type":"string"}}}}};
8
8
 
9
9
  function validate14(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){
10
10
  /*# sourceURL="https://github.com/data-fair/lib/account" */;
package/account/index.js CHANGED
@@ -1 +1 @@
1
- export * from './.type/index.js';
1
+ export * from './.type/index.js'
@@ -0,0 +1,46 @@
1
+ declare const _default: {
2
+ $id: string;
3
+ 'x-exports': string[];
4
+ type: string;
5
+ title: string;
6
+ required: string[];
7
+ properties: {
8
+ type: {
9
+ type: string;
10
+ enum: string[];
11
+ };
12
+ id: {
13
+ type: string;
14
+ };
15
+ name: {
16
+ type: string;
17
+ };
18
+ department: {
19
+ type: string;
20
+ };
21
+ departmentName: {
22
+ type: string;
23
+ };
24
+ };
25
+ $defs: {
26
+ accountKeys: {
27
+ type: string;
28
+ title: string;
29
+ required: string[];
30
+ additionalProperties: boolean;
31
+ properties: {
32
+ type: {
33
+ type: string;
34
+ enum: string[];
35
+ };
36
+ id: {
37
+ type: string;
38
+ };
39
+ department: {
40
+ type: string;
41
+ };
42
+ };
43
+ };
44
+ };
45
+ };
46
+ export default _default;
@@ -0,0 +1,45 @@
1
+ export default {
2
+ $id: 'https://github.com/data-fair/lib/account',
3
+ 'x-exports': ['types', 'validate'],
4
+ type: 'object',
5
+ title: 'account',
6
+ required: ['type', 'id', 'name'],
7
+ properties: {
8
+ type: {
9
+ type: 'string',
10
+ enum: ['user', 'organization']
11
+ },
12
+ id: {
13
+ type: 'string'
14
+ },
15
+ name: {
16
+ type: 'string'
17
+ },
18
+ department: {
19
+ type: 'string'
20
+ },
21
+ departmentName: {
22
+ type: 'string'
23
+ }
24
+ },
25
+ $defs: {
26
+ accountKeys: {
27
+ type: 'object',
28
+ title: 'account keys',
29
+ required: ['type', 'id'],
30
+ additionalProperties: false,
31
+ properties: {
32
+ type: {
33
+ type: 'string',
34
+ enum: ['user', 'organization']
35
+ },
36
+ id: {
37
+ type: 'string'
38
+ },
39
+ department: {
40
+ type: 'string'
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
@@ -95,6 +95,3 @@ export interface Field {
95
95
  [k: string]: unknown;
96
96
  }
97
97
 
98
-
99
- export const schema: any
100
-
@@ -3,159 +3,5 @@
3
3
 
4
4
 
5
5
  export const schemaExports = [
6
- "types",
7
- "schema"
6
+ "types"
8
7
  ]
9
-
10
- export const schema = {
11
- "$id": "https://github.com/data-fair/lib/application",
12
- "title": "Application",
13
- "x-exports": [
14
- "types",
15
- "schema"
16
- ],
17
- "type": "object",
18
- "required": [
19
- "id",
20
- "title",
21
- "exposedUrl",
22
- "href",
23
- "wsUrl",
24
- "owner",
25
- "configuration"
26
- ],
27
- "properties": {
28
- "id": {
29
- "type": "string",
30
- "description": "Globally unique identifier of the application"
31
- },
32
- "title": {
33
- "type": "string",
34
- "description": "Short title of the application"
35
- },
36
- "exposedUrl": {
37
- "type": "string",
38
- "description": "The URL where this application is exposed"
39
- },
40
- "href": {
41
- "type": "string",
42
- "description": "The URL where this resource can be fetched"
43
- },
44
- "wsUrl": {
45
- "type": "string",
46
- "description": "The URL where this application can be accessed through a websocket"
47
- },
48
- "owner": {
49
- "$ref": "https://github.com/data-fair/lib/account#/$defs/accountKeys"
50
- },
51
- "configuration": {
52
- "type": "object",
53
- "description": "A free format configuration object used by applications. A minimal common structure is used to ensure proper linking between applications and datasets and remote services",
54
- "additionalProperties": true,
55
- "properties": {
56
- "datasets": {
57
- "type": "array",
58
- "items": {
59
- "$ref": "#/$defs/dataset"
60
- }
61
- }
62
- }
63
- }
64
- },
65
- "$defs": {
66
- "dataset": {
67
- "type": [
68
- "object",
69
- "null"
70
- ],
71
- "required": [
72
- "href",
73
- "id",
74
- "title",
75
- "finalizedAt"
76
- ],
77
- "properties": {
78
- "href": {
79
- "type": "string"
80
- },
81
- "id": {
82
- "type": "string"
83
- },
84
- "title": {
85
- "type": "string"
86
- },
87
- "key": {
88
- "type": "string",
89
- "description": "Not the id of the dataset, but a key inside this configuration object to define the role of the dataset in this context."
90
- },
91
- "schema": {
92
- "type": "array",
93
- "items": {
94
- "$ref": "#/$defs/field"
95
- }
96
- },
97
- "finalizedAt": {
98
- "type": "string",
99
- "format": "date-time"
100
- }
101
- }
102
- },
103
- "field": {
104
- "type": "object",
105
- "required": [
106
- "key",
107
- "type"
108
- ],
109
- "properties": {
110
- "key": {
111
- "type": "string"
112
- },
113
- "type": {
114
- "type": "string"
115
- },
116
- "format": {
117
- "type": "string"
118
- },
119
- "title": {
120
- "type": "string"
121
- },
122
- "x-originalName": {
123
- "type": "string"
124
- },
125
- "x-group": {
126
- "type": "string"
127
- },
128
- "x-refersTo": {
129
- "deprecated": true,
130
- "type": [
131
- "string",
132
- "null"
133
- ]
134
- },
135
- "x-concept": {
136
- "type": "object",
137
- "properties": {
138
- "id": {
139
- "type": "string"
140
- },
141
- "title": {
142
- "type": "string"
143
- },
144
- "primary": {
145
- "type": "boolean"
146
- }
147
- }
148
- },
149
- "x-labels": {
150
- "type": "object",
151
- "additionalProperties": {
152
- "type": "string"
153
- }
154
- },
155
- "x-labelsRestricted": {
156
- "type": "boolean"
157
- }
158
- }
159
- }
160
- }
161
- }
@@ -1 +1 @@
1
- export * from './.type/index.js';
1
+ export * from './.type/index.js'
@@ -0,0 +1,128 @@
1
+ declare const _default: {
2
+ $id: string;
3
+ title: string;
4
+ 'x-exports': string[];
5
+ type: string;
6
+ required: string[];
7
+ properties: {
8
+ id: {
9
+ type: string;
10
+ description: string;
11
+ };
12
+ title: {
13
+ type: string;
14
+ description: string;
15
+ };
16
+ exposedUrl: {
17
+ type: string;
18
+ description: string;
19
+ };
20
+ href: {
21
+ type: string;
22
+ description: string;
23
+ };
24
+ wsUrl: {
25
+ type: string;
26
+ description: string;
27
+ };
28
+ owner: {
29
+ $ref: string;
30
+ };
31
+ configuration: {
32
+ type: string;
33
+ description: string;
34
+ additionalProperties: boolean;
35
+ properties: {
36
+ datasets: {
37
+ type: string;
38
+ items: {
39
+ $ref: string;
40
+ };
41
+ };
42
+ };
43
+ };
44
+ };
45
+ $defs: {
46
+ dataset: {
47
+ type: string[];
48
+ required: string[];
49
+ properties: {
50
+ href: {
51
+ type: string;
52
+ };
53
+ id: {
54
+ type: string;
55
+ };
56
+ title: {
57
+ type: string;
58
+ };
59
+ key: {
60
+ type: string;
61
+ description: string;
62
+ };
63
+ schema: {
64
+ type: string;
65
+ items: {
66
+ $ref: string;
67
+ };
68
+ };
69
+ finalizedAt: {
70
+ type: string;
71
+ format: string;
72
+ };
73
+ };
74
+ };
75
+ field: {
76
+ type: string;
77
+ required: string[];
78
+ properties: {
79
+ key: {
80
+ type: string;
81
+ };
82
+ type: {
83
+ type: string;
84
+ };
85
+ format: {
86
+ type: string;
87
+ };
88
+ title: {
89
+ type: string;
90
+ };
91
+ 'x-originalName': {
92
+ type: string;
93
+ };
94
+ 'x-group': {
95
+ type: string;
96
+ };
97
+ 'x-refersTo': {
98
+ deprecated: boolean;
99
+ type: string[];
100
+ };
101
+ 'x-concept': {
102
+ type: string;
103
+ properties: {
104
+ id: {
105
+ type: string;
106
+ };
107
+ title: {
108
+ type: string;
109
+ };
110
+ primary: {
111
+ type: string;
112
+ };
113
+ };
114
+ };
115
+ 'x-labels': {
116
+ type: string;
117
+ additionalProperties: {
118
+ type: string;
119
+ };
120
+ };
121
+ 'x-labelsRestricted': {
122
+ type: string;
123
+ };
124
+ };
125
+ };
126
+ };
127
+ };
128
+ export default _default;
@@ -0,0 +1,138 @@
1
+ export default {
2
+ $id: 'https://github.com/data-fair/lib/application',
3
+ title: 'Application',
4
+ 'x-exports': ['types'],
5
+ type: 'object',
6
+ required: [
7
+ 'id',
8
+ 'title',
9
+ 'exposedUrl',
10
+ 'href',
11
+ 'wsUrl',
12
+ 'owner',
13
+ 'configuration'
14
+ ],
15
+ properties: {
16
+ id: {
17
+ type: 'string',
18
+ description: 'Globally unique identifier of the application'
19
+ },
20
+ title: {
21
+ type: 'string',
22
+ description: 'Short title of the application'
23
+ },
24
+ exposedUrl: {
25
+ type: 'string',
26
+ description: 'The URL where this application is exposed'
27
+ },
28
+ href: {
29
+ type: 'string',
30
+ description: 'The URL where this resource can be fetched'
31
+ },
32
+ wsUrl: {
33
+ type: 'string',
34
+ description: 'The URL where this application can be accessed through a websocket'
35
+ },
36
+ owner: {
37
+ $ref: 'https://github.com/data-fair/lib/account#/$defs/accountKeys'
38
+ },
39
+ configuration: {
40
+ type: 'object',
41
+ description: 'A free format configuration object used by applications. A minimal common structure is used to ensure proper linking between applications and datasets and remote services',
42
+ additionalProperties: true,
43
+ properties: {
44
+ datasets: {
45
+ type: 'array',
46
+ items: {
47
+ $ref: '#/$defs/dataset'
48
+ }
49
+ }
50
+ }
51
+ }
52
+ },
53
+ $defs: {
54
+ dataset: {
55
+ type: [
56
+ 'object',
57
+ 'null'
58
+ ],
59
+ required: [
60
+ 'href',
61
+ 'id',
62
+ 'title',
63
+ 'finalizedAt'
64
+ ],
65
+ properties: {
66
+ href: {
67
+ type: 'string'
68
+ },
69
+ id: {
70
+ type: 'string'
71
+ },
72
+ title: {
73
+ type: 'string'
74
+ },
75
+ key: {
76
+ type: 'string',
77
+ description: 'Not the id of the dataset, but a key inside this configuration object to define the role of the dataset in this context.'
78
+ },
79
+ schema: {
80
+ type: 'array',
81
+ items: {
82
+ $ref: '#/$defs/field'
83
+ }
84
+ },
85
+ finalizedAt: {
86
+ type: 'string',
87
+ format: 'date-time'
88
+ }
89
+ }
90
+ },
91
+ field: {
92
+ type: 'object',
93
+ required: [
94
+ 'key',
95
+ 'type'
96
+ ],
97
+ properties: {
98
+ key: {
99
+ type: 'string'
100
+ },
101
+ type: {
102
+ type: 'string'
103
+ },
104
+ format: {
105
+ type: 'string'
106
+ },
107
+ title: {
108
+ type: 'string'
109
+ },
110
+ 'x-originalName': {
111
+ type: 'string'
112
+ },
113
+ 'x-group': { type: 'string' },
114
+ 'x-refersTo': {
115
+ deprecated: true,
116
+ type: ['string', 'null']
117
+ },
118
+ 'x-concept': {
119
+ type: 'object',
120
+ properties: {
121
+ id: { type: 'string' },
122
+ title: { type: 'string' },
123
+ primary: { type: 'boolean' }
124
+ }
125
+ },
126
+ 'x-labels': {
127
+ type: 'object',
128
+ additionalProperties: {
129
+ type: 'string'
130
+ }
131
+ },
132
+ 'x-labelsRestricted': {
133
+ type: 'boolean'
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@data-fair/lib-common-types",
3
- "version": "0.2.0",
3
+ "version": "1.1.0",
4
4
  "description": "Shared schemas and built type definitions in the data-fair stack.",
5
5
  "main": "index.js",
6
+ "scripts": {
7
+ "prepublishOnly": "cd .. && npm run prepublishOnly"
8
+ },
6
9
  "devDependencies": {},
7
10
  "files": [
11
+ "**/schema.json",
8
12
  "**/*.js",
9
13
  "**/*.d.ts"
10
14
  ],
package/processings.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {}
@@ -61,6 +61,4 @@ export interface Account {
61
61
  export const validate: (data: any) => data is SessionState
62
62
  export const assertValid: (data: any, options?: import('@data-fair/lib-node/validation.js').AssertValidOptions) => asserts data is SessionState
63
63
  export const returnValid: (data: any, options?: import('@data-fair/lib-node/validation.js').AssertValidOptions) => SessionState
64
-
65
- export const schema: any
66
-
64
+
@@ -6,8 +6,7 @@ import { assertValid as assertValidGeneric } from '@data-fair/lib-node/validatio
6
6
 
7
7
  export const schemaExports = [
8
8
  "types",
9
- "validate",
10
- "schema"
9
+ "validate"
11
10
  ]
12
11
 
13
12
  export { validate } from './validate.js'
@@ -18,168 +17,3 @@ export const returnValid = (data, options) => {
18
17
  assertValid(data, options)
19
18
  return data
20
19
  }
21
-
22
- export const schema = {
23
- "$id": "https://github.com/data-fair/lib/session-state",
24
- "x-exports": [
25
- "types",
26
- "validate",
27
- "schema"
28
- ],
29
- "type": "object",
30
- "title": "session state",
31
- "additionalProperties": false,
32
- "properties": {
33
- "user": {
34
- "$ref": "#/$defs/user"
35
- },
36
- "organization": {
37
- "$ref": "#/$defs/organizationMembership"
38
- },
39
- "account": {
40
- "$ref": "#/$defs/account"
41
- },
42
- "accountRole": {
43
- "type": "string"
44
- },
45
- "lang": {
46
- "type": "string"
47
- },
48
- "dark": {
49
- "type": "boolean"
50
- }
51
- },
52
- "$defs": {
53
- "organizationMembership": {
54
- "type": "object",
55
- "additionalProperties": false,
56
- "required": [
57
- "id",
58
- "name",
59
- "role"
60
- ],
61
- "properties": {
62
- "id": {
63
- "type": "string"
64
- },
65
- "name": {
66
- "type": "string"
67
- },
68
- "role": {
69
- "type": "string"
70
- },
71
- "department": {
72
- "type": "string"
73
- },
74
- "departmentName": {
75
- "type": "string"
76
- },
77
- "dflt": {
78
- "type": "boolean"
79
- }
80
- }
81
- },
82
- "userRef": {
83
- "type": "object",
84
- "additionalProperties": false,
85
- "required": [
86
- "id",
87
- "name"
88
- ],
89
- "properties": {
90
- "id": {
91
- "type": "string"
92
- },
93
- "name": {
94
- "type": "string"
95
- }
96
- }
97
- },
98
- "user": {
99
- "type": "object",
100
- "additionalProperties": false,
101
- "required": [
102
- "email",
103
- "id",
104
- "name",
105
- "organizations"
106
- ],
107
- "properties": {
108
- "email": {
109
- "type": "string",
110
- "format": "email"
111
- },
112
- "id": {
113
- "type": "string"
114
- },
115
- "name": {
116
- "type": "string"
117
- },
118
- "organizations": {
119
- "type": "array",
120
- "items": {
121
- "$ref": "#/$defs/organizationMembership"
122
- }
123
- },
124
- "isAdmin": {
125
- "type": "integer",
126
- "enum": [
127
- 0,
128
- 1
129
- ]
130
- },
131
- "adminMode": {
132
- "type": "integer",
133
- "enum": [
134
- 0,
135
- 1
136
- ]
137
- },
138
- "asAdmin": {
139
- "$ref": "#/$defs/userRef"
140
- },
141
- "pd": {
142
- "type": "string",
143
- "format": "date"
144
- },
145
- "ipa": {
146
- "type": "integer",
147
- "enum": [
148
- 0,
149
- 1
150
- ]
151
- }
152
- }
153
- },
154
- "account": {
155
- "type": "object",
156
- "additionalProperties": false,
157
- "required": [
158
- "type",
159
- "id",
160
- "name"
161
- ],
162
- "properties": {
163
- "type": {
164
- "type": "string",
165
- "enum": [
166
- "user",
167
- "organization"
168
- ]
169
- },
170
- "id": {
171
- "type": "string"
172
- },
173
- "name": {
174
- "type": "string"
175
- },
176
- "department": {
177
- "type": "string"
178
- },
179
- "departmentName": {
180
- "type": "string"
181
- }
182
- }
183
- }
184
- }
185
- }
@@ -5,7 +5,7 @@ import { fullFormats } from "ajv-formats/dist/formats.js";
5
5
  "use strict";
6
6
  export const validate = validate14;
7
7
  export default validate14;
8
- const schema16 = {"$id":"https://github.com/data-fair/lib/session-state","x-exports":["types","validate","schema"],"type":"object","title":"session state","additionalProperties":false,"properties":{"user":{"$ref":"#/$defs/user"},"organization":{"$ref":"#/$defs/organizationMembership"},"account":{"$ref":"#/$defs/account"},"accountRole":{"type":"string"},"lang":{"type":"string"},"dark":{"type":"boolean"}},"$defs":{"organizationMembership":{"type":"object","additionalProperties":false,"required":["id","name","role"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"role":{"type":"string"},"department":{"type":"string"},"departmentName":{"type":"string"},"dflt":{"type":"boolean"}}},"userRef":{"type":"object","additionalProperties":false,"required":["id","name"],"properties":{"id":{"type":"string"},"name":{"type":"string"}}},"user":{"type":"object","additionalProperties":false,"required":["email","id","name","organizations"],"properties":{"email":{"type":"string","format":"email"},"id":{"type":"string"},"name":{"type":"string"},"organizations":{"type":"array","items":{"$ref":"#/$defs/organizationMembership"}},"isAdmin":{"type":"integer","enum":[0,1]},"adminMode":{"type":"integer","enum":[0,1]},"asAdmin":{"$ref":"#/$defs/userRef"},"pd":{"type":"string","format":"date"},"ipa":{"type":"integer","enum":[0,1]}}},"account":{"type":"object","additionalProperties":false,"required":["type","id","name"],"properties":{"type":{"type":"string","enum":["user","organization"]},"id":{"type":"string"},"name":{"type":"string"},"department":{"type":"string"},"departmentName":{"type":"string"}}}}};
8
+ const schema16 = {"$id":"https://github.com/data-fair/lib/session-state","x-exports":["types","validate"],"type":"object","title":"session state","additionalProperties":false,"properties":{"user":{"$ref":"#/$defs/user"},"organization":{"$ref":"#/$defs/organizationMembership"},"account":{"$ref":"#/$defs/account"},"accountRole":{"type":"string"},"lang":{"type":"string"},"dark":{"type":"boolean"}},"$defs":{"organizationMembership":{"type":"object","additionalProperties":false,"required":["id","name","role"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"role":{"type":"string"},"department":{"type":"string"},"departmentName":{"type":"string"},"dflt":{"type":"boolean"}}},"userRef":{"type":"object","additionalProperties":false,"required":["id","name"],"properties":{"id":{"type":"string"},"name":{"type":"string"}}},"user":{"type":"object","additionalProperties":false,"required":["email","id","name","organizations"],"properties":{"email":{"type":"string","format":"email"},"id":{"type":"string"},"name":{"type":"string"},"organizations":{"type":"array","items":{"$ref":"#/$defs/organizationMembership"}},"isAdmin":{"type":"integer","enum":[0,1]},"adminMode":{"type":"integer","enum":[0,1]},"asAdmin":{"$ref":"#/$defs/userRef"},"pd":{"type":"string","format":"date"},"ipa":{"type":"integer","enum":[0,1]}}},"account":{"type":"object","additionalProperties":false,"required":["type","id","name"],"properties":{"type":{"type":"string","enum":["user","organization"]},"id":{"type":"string"},"name":{"type":"string"},"department":{"type":"string"},"departmentName":{"type":"string"}}}}};
9
9
  const schema18 = {"type":"object","additionalProperties":false,"required":["id","name","role"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"role":{"type":"string"},"department":{"type":"string"},"departmentName":{"type":"string"},"dflt":{"type":"boolean"}}};
10
10
  const schema21 = {"type":"object","additionalProperties":false,"required":["type","id","name"],"properties":{"type":{"type":"string","enum":["user","organization"]},"id":{"type":"string"},"name":{"type":"string"},"department":{"type":"string"},"departmentName":{"type":"string"}}};
11
11
  const schema17 = {"type":"object","additionalProperties":false,"required":["email","id","name","organizations"],"properties":{"email":{"type":"string","format":"email"},"id":{"type":"string"},"name":{"type":"string"},"organizations":{"type":"array","items":{"$ref":"#/$defs/organizationMembership"}},"isAdmin":{"type":"integer","enum":[0,1]},"adminMode":{"type":"integer","enum":[0,1]},"asAdmin":{"$ref":"#/$defs/userRef"},"pd":{"type":"string","format":"date"},"ipa":{"type":"integer","enum":[0,1]}}};
package/session/index.js CHANGED
@@ -1,55 +1,42 @@
1
- import { httpError } from '@data-fair/lib-utils/http-errors.js';
2
- export * from './.type/index.js';
3
- export function isAuthenticated(sessionState) {
4
- return !!sessionState.user;
5
- }
6
- export function assertAuthenticated(sessionState) {
7
- if (!isAuthenticated(sessionState))
8
- throw httpError(401);
9
- }
10
- export function assertAdminMode(sessionState) {
11
- assertAuthenticated(sessionState);
12
- // TODO: use sessionState.locale to internationalize error message
13
- if (!sessionState.user.adminMode)
14
- throw httpError(403, 'super admin only');
15
- }
16
- function matchAccount(userAccount, resourceAccount) {
17
- if (userAccount.type !== resourceAccount.type)
18
- return false;
19
- if (userAccount.id !== resourceAccount.id)
20
- return false;
21
- if (userAccount.department && userAccount.department !== resourceAccount.department)
22
- return false;
23
- return true;
24
- }
25
- export function getAccountRole(sessionState, account, onlyActiveAccount = true) {
26
- if (!isAuthenticated(sessionState))
27
- return null;
28
- if (sessionState.user.adminMode)
29
- return 'admin';
30
- if (onlyActiveAccount) {
31
- if (matchAccount(sessionState.account, account))
32
- return sessionState.accountRole;
1
+ import { httpError } from '@data-fair/lib-utils/http-errors.js'
2
+ export * from './.type/index.js'
3
+ export function isAuthenticated (sessionState) {
4
+ return !!sessionState.user
5
+ }
6
+ export function assertAuthenticated (sessionState) {
7
+ if (!isAuthenticated(sessionState)) { throw httpError(401) }
8
+ }
9
+ export function assertAdminMode (sessionState) {
10
+ assertAuthenticated(sessionState)
11
+ // TODO: use sessionState.locale to internationalize error message
12
+ if (!sessionState.user.adminMode) { throw httpError(403, 'super admin only') }
13
+ }
14
+ function matchAccount (userAccount, resourceAccount) {
15
+ if (userAccount.type !== resourceAccount.type) { return false }
16
+ if (userAccount.id !== resourceAccount.id) { return false }
17
+ if (userAccount.department && userAccount.department !== resourceAccount.department) { return false }
18
+ return true
19
+ }
20
+ export function getAccountRole (sessionState, account, onlyActiveAccount = true) {
21
+ if (!isAuthenticated(sessionState)) { return null }
22
+ if (sessionState.user.adminMode) { return 'admin' }
23
+ if (onlyActiveAccount) {
24
+ if (matchAccount(sessionState.account, account)) { return sessionState.accountRole }
25
+ } else {
26
+ if (account.type === 'user' && sessionState.user.id === account.id) { return 'admin' }
27
+ for (const org of sessionState.user.organizations) {
28
+ if (matchAccount({ type: 'organization', id: org.id, department: org.department }, account)) { return org.role }
33
29
  }
34
- else {
35
- if (account.type === 'user' && sessionState.user.id === account.id)
36
- return 'admin';
37
- for (const org of sessionState.user.organizations) {
38
- if (matchAccount({ type: 'organization', id: org.id, department: org.department }, account))
39
- return org.role;
40
- }
41
- }
42
- return null;
30
+ }
31
+ return null
43
32
  }
44
- export function assertAccountRole(sessionState, account, role, onlyActiveAccount = true) {
45
- const accountRole = getAccountRole(sessionState, account, onlyActiveAccount);
46
- if (accountRole !== role)
47
- throw httpError(403, `requires ${role} role`);
33
+ export function assertAccountRole (sessionState, account, role, onlyActiveAccount = true) {
34
+ const accountRole = getAccountRole(sessionState, account, onlyActiveAccount)
35
+ if (accountRole !== role) { throw httpError(403, `requires ${role} role`) }
48
36
  }
49
- export function isValidAccountType(type) {
50
- return ['user', 'organization'].includes(type);
37
+ export function isValidAccountType (type) {
38
+ return ['user', 'organization'].includes(type)
51
39
  }
52
- export function assertValidAccountType(type) {
53
- if (!isValidAccountType(type))
54
- throw httpError(400, 'invalid account type');
40
+ export function assertValidAccountType (type) {
41
+ if (!isValidAccountType(type)) { throw httpError(400, 'invalid account type') }
55
42
  }
@@ -0,0 +1,133 @@
1
+ declare const _default: {
2
+ $id: string;
3
+ 'x-exports': string[];
4
+ type: string;
5
+ title: string;
6
+ additionalProperties: boolean;
7
+ properties: {
8
+ user: {
9
+ $ref: string;
10
+ };
11
+ organization: {
12
+ $ref: string;
13
+ };
14
+ account: {
15
+ $ref: string;
16
+ };
17
+ accountRole: {
18
+ type: string;
19
+ };
20
+ lang: {
21
+ type: string;
22
+ };
23
+ dark: {
24
+ type: string;
25
+ };
26
+ };
27
+ $defs: {
28
+ organizationMembership: {
29
+ type: string;
30
+ additionalProperties: boolean;
31
+ required: string[];
32
+ properties: {
33
+ id: {
34
+ type: string;
35
+ };
36
+ name: {
37
+ type: string;
38
+ };
39
+ role: {
40
+ type: string;
41
+ };
42
+ department: {
43
+ type: string;
44
+ };
45
+ departmentName: {
46
+ type: string;
47
+ };
48
+ dflt: {
49
+ type: string;
50
+ };
51
+ };
52
+ };
53
+ userRef: {
54
+ type: string;
55
+ additionalProperties: boolean;
56
+ required: string[];
57
+ properties: {
58
+ id: {
59
+ type: string;
60
+ };
61
+ name: {
62
+ type: string;
63
+ };
64
+ };
65
+ };
66
+ user: {
67
+ type: string;
68
+ additionalProperties: boolean;
69
+ required: string[];
70
+ properties: {
71
+ email: {
72
+ type: string;
73
+ format: string;
74
+ };
75
+ id: {
76
+ type: string;
77
+ };
78
+ name: {
79
+ type: string;
80
+ };
81
+ organizations: {
82
+ type: string;
83
+ items: {
84
+ $ref: string;
85
+ };
86
+ };
87
+ isAdmin: {
88
+ type: string;
89
+ enum: number[];
90
+ };
91
+ adminMode: {
92
+ type: string;
93
+ enum: number[];
94
+ };
95
+ asAdmin: {
96
+ $ref: string;
97
+ };
98
+ pd: {
99
+ type: string;
100
+ format: string;
101
+ };
102
+ ipa: {
103
+ type: string;
104
+ enum: number[];
105
+ };
106
+ };
107
+ };
108
+ account: {
109
+ type: string;
110
+ additionalProperties: boolean;
111
+ required: string[];
112
+ properties: {
113
+ type: {
114
+ type: string;
115
+ enum: string[];
116
+ };
117
+ id: {
118
+ type: string;
119
+ };
120
+ name: {
121
+ type: string;
122
+ };
123
+ department: {
124
+ type: string;
125
+ };
126
+ departmentName: {
127
+ type: string;
128
+ };
129
+ };
130
+ };
131
+ };
132
+ };
133
+ export default _default;
@@ -0,0 +1,157 @@
1
+ export default {
2
+ $id: 'https://github.com/data-fair/lib/session-state',
3
+ 'x-exports': ['types', 'validate'],
4
+ type: 'object',
5
+ title: 'session state',
6
+ additionalProperties: false,
7
+ properties: {
8
+ user: {
9
+ $ref: '#/$defs/user'
10
+ },
11
+ organization: {
12
+ $ref: '#/$defs/organizationMembership'
13
+ },
14
+ account: {
15
+ $ref: '#/$defs/account'
16
+ },
17
+ accountRole: {
18
+ type: 'string'
19
+ },
20
+ lang: {
21
+ type: 'string'
22
+ },
23
+ dark: {
24
+ type: 'boolean'
25
+ }
26
+ },
27
+ $defs: {
28
+ organizationMembership: {
29
+ type: 'object',
30
+ additionalProperties: false,
31
+ required: [
32
+ 'id',
33
+ 'name',
34
+ 'role'
35
+ ],
36
+ properties: {
37
+ id: {
38
+ type: 'string'
39
+ },
40
+ name: {
41
+ type: 'string'
42
+ },
43
+ role: {
44
+ type: 'string'
45
+ },
46
+ department: {
47
+ type: 'string'
48
+ },
49
+ departmentName: {
50
+ type: 'string'
51
+ },
52
+ dflt: {
53
+ type: 'boolean'
54
+ }
55
+ }
56
+ },
57
+ userRef: {
58
+ type: 'object',
59
+ additionalProperties: false,
60
+ required: [
61
+ 'id',
62
+ 'name'
63
+ ],
64
+ properties: {
65
+ id: {
66
+ type: 'string'
67
+ },
68
+ name: {
69
+ type: 'string'
70
+ }
71
+ }
72
+ },
73
+ user: {
74
+ type: 'object',
75
+ additionalProperties: false,
76
+ required: [
77
+ 'email',
78
+ 'id',
79
+ 'name',
80
+ 'organizations'
81
+ ],
82
+ properties: {
83
+ email: {
84
+ type: 'string',
85
+ format: 'email'
86
+ },
87
+ id: {
88
+ type: 'string'
89
+ },
90
+ name: {
91
+ type: 'string'
92
+ },
93
+ organizations: {
94
+ type: 'array',
95
+ items: {
96
+ $ref: '#/$defs/organizationMembership'
97
+ }
98
+ },
99
+ isAdmin: {
100
+ type: 'integer',
101
+ enum: [
102
+ 0,
103
+ 1
104
+ ]
105
+ },
106
+ adminMode: {
107
+ type: 'integer',
108
+ enum: [
109
+ 0,
110
+ 1
111
+ ]
112
+ },
113
+ asAdmin: {
114
+ $ref: '#/$defs/userRef'
115
+ },
116
+ pd: {
117
+ type: 'string',
118
+ format: 'date'
119
+ },
120
+ ipa: {
121
+ type: 'integer',
122
+ enum: [
123
+ 0,
124
+ 1
125
+ ]
126
+ }
127
+ }
128
+ },
129
+ account: {
130
+ type: 'object',
131
+ additionalProperties: false,
132
+ required: [
133
+ 'type',
134
+ 'id',
135
+ 'name'
136
+ ],
137
+ properties: {
138
+ type: {
139
+ type: 'string',
140
+ enum: ['user', 'organization']
141
+ },
142
+ id: {
143
+ type: 'string'
144
+ },
145
+ name: {
146
+ type: 'string'
147
+ },
148
+ department: {
149
+ type: 'string'
150
+ },
151
+ departmentName: {
152
+ type: 'string'
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
@@ -1,2 +1,2 @@
1
- import { type SessionState } from './.type/index.js';
2
- export type SessionStateAuthenticated = SessionState & Required<Pick<SessionState, 'user' | 'account' | 'accountRole'>>;
1
+ import { type SessionState } from './.type/index.js'
2
+ export type SessionStateAuthenticated = SessionState & Required<Pick<SessionState, 'user' | 'account' | 'accountRole'>>
package/session/types.js CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ export {}
2
+ // # sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ0eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
package/ws.d.ts CHANGED
@@ -1,22 +1,6 @@
1
- import { type Account } from '@data-fair/lib-common-types/session/index.js';
2
- type logFn = (msg: string, ...args: any[]) => void;
3
- export interface WsClientOpts {
4
- log?: {
5
- info: logFn;
6
- error: logFn;
7
- debug: logFn;
8
- };
9
- url: string;
10
- headers?: Record<string, string>;
11
- apiKey?: string;
12
- adminMode?: boolean;
13
- account?: Account;
14
- }
15
- export type FullWsClientOpts = WsClientOpts & Required<Pick<WsClientOpts, 'log'>>;
16
1
  export interface Message {
17
2
  type: string;
18
3
  channel: string;
19
4
  data?: any;
20
5
  status?: number;
21
6
  }
22
- export {};
package/ws.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {}