@api-client/core 0.4.2 → 0.5.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.
Files changed (59) hide show
  1. package/build/browser.d.ts +5 -2
  2. package/build/browser.js +3 -1
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +5 -2
  5. package/build/index.js +3 -1
  6. package/build/index.js.map +1 -1
  7. package/build/src/mocking/LegacyInterfaces.d.ts +1 -1
  8. package/build/src/mocking/ProjectMock.d.ts +1 -1
  9. package/build/src/mocking/legacy/Http.js +1 -1
  10. package/build/src/mocking/legacy/Http.js.map +1 -1
  11. package/build/src/mocking/legacy/HttpResponse.d.ts +1 -1
  12. package/build/src/mocking/legacy/HttpResponse.js +1 -1
  13. package/build/src/mocking/legacy/HttpResponse.js.map +1 -1
  14. package/build/src/mocking/lib/User.d.ts +1 -6
  15. package/build/src/mocking/lib/User.js +1 -15
  16. package/build/src/mocking/lib/User.js.map +1 -1
  17. package/build/src/models/Backend.d.ts +10 -2
  18. package/build/src/models/HttpProject.js +1 -1
  19. package/build/src/models/HttpProject.js.map +1 -1
  20. package/build/src/models/Workspace.d.ts +5 -35
  21. package/build/src/models/Workspace.js +13 -35
  22. package/build/src/models/Workspace.js.map +1 -1
  23. package/build/src/models/legacy/models/base.d.ts +90 -0
  24. package/build/src/models/legacy/models/base.js +2 -0
  25. package/build/src/models/legacy/models/base.js.map +1 -0
  26. package/build/src/models/store/File.d.ts +88 -0
  27. package/build/src/models/store/File.js +82 -0
  28. package/build/src/models/store/File.js.map +1 -0
  29. package/build/src/models/store/Group.d.ts +21 -0
  30. package/build/src/models/store/Group.js +2 -0
  31. package/build/src/models/store/Group.js.map +1 -0
  32. package/build/src/models/store/Permission.d.ts +189 -0
  33. package/build/src/models/store/Permission.js +211 -0
  34. package/build/src/models/store/Permission.js.map +1 -0
  35. package/build/src/models/{User.d.ts → store/User.d.ts} +12 -59
  36. package/build/src/models/{User.js → store/User.js} +0 -0
  37. package/build/src/models/store/User.js.map +1 -0
  38. package/build/src/runtime/store/SpacesSdk.d.ts +4 -4
  39. package/build/src/runtime/store/SpacesSdk.js.map +1 -1
  40. package/build/src/runtime/store/UsersSdk.d.ts +1 -1
  41. package/json8-patch.d.ts +270 -0
  42. package/package.json +2 -2
  43. package/src/mocking/LegacyInterfaces.ts +1 -1
  44. package/src/mocking/ProjectMock.ts +1 -1
  45. package/src/mocking/legacy/Http.ts +1 -1
  46. package/src/mocking/legacy/HttpResponse.ts +1 -1
  47. package/src/mocking/lib/User.ts +1 -21
  48. package/src/models/Backend.ts +10 -2
  49. package/src/models/HttpProject.ts +1 -1
  50. package/src/models/Workspace.ts +16 -54
  51. package/src/models/legacy/models/{base.d.ts → base.ts} +0 -0
  52. package/src/models/store/File.ts +135 -0
  53. package/src/models/store/Group.ts +21 -0
  54. package/src/models/store/Permission.ts +318 -0
  55. package/src/models/store/User.ts +83 -0
  56. package/src/runtime/store/SpacesSdk.ts +5 -5
  57. package/src/runtime/store/UsersSdk.ts +1 -1
  58. package/build/src/models/User.js.map +0 -1
  59. package/src/models/User.ts +0 -138
@@ -0,0 +1,318 @@
1
+ import v4 from '../../lib/uuid.js';
2
+
3
+ export const Kind = 'Core#Permission';
4
+
5
+ export type PermissionType = 'user' | 'group' | 'anyone';
6
+ export type PermissionRole = 'owner' | 'reader' | 'commenter' | 'writer';
7
+
8
+ /**
9
+ * A schema describing a permission to a store object.
10
+ */
11
+ export interface IPermission {
12
+ kind: typeof Kind;
13
+ /**
14
+ * The data store key of the permission.
15
+ * This property is generated by the store and is not writable.
16
+ */
17
+ key: string;
18
+ /**
19
+ * The type of the permission.
20
+ *
21
+ * - `user` can access the file by a specific user
22
+ * - `group` can access the file by a group of users
23
+ * - `anyone` the object can be searched by anyone who has access to the store.
24
+ *
25
+ * Note, the `anyone` object does not mean that the end-user sees the file when
26
+ * listing objects in the store. It means the file can be searched for.
27
+ */
28
+ type: PermissionType;
29
+ /**
30
+ * The id of the owner of the permission.
31
+ * The value depends on the `type`. For the `user` type it is the user id.
32
+ * The `group` means the group id. It is not set when the role is `anyone`.
33
+ */
34
+ owner?: string;
35
+ /**
36
+ * The role granted by this permission.
37
+ */
38
+ role: PermissionRole;
39
+ /**
40
+ * The "pretty" name to render with the permission.
41
+ *
42
+ * - `user` type - user's full name
43
+ * - `group` type - the name of the group
44
+ * - `anyone` type - no render name
45
+ */
46
+ displayName?: string;
47
+ /**
48
+ * Optional expiration date of the permission. This is the timestamp when the permission expires.
49
+ * When creating / updating the permission the expiration date must:
50
+ *
51
+ * - be used on a user or a group
52
+ * - the time must be in the future
53
+ */
54
+ expirationTime?: number;
55
+ /**
56
+ * The store id of the user that added this permission.
57
+ */
58
+ addingUser: string;
59
+
60
+ /**
61
+ * Whether the permission object is deleted.
62
+ */
63
+ deleted?: boolean;
64
+ /**
65
+ * The timestamp of when the permission was deleted.
66
+ */
67
+ deletedTime?: number;
68
+ /**
69
+ * The id of the user that has deleted the permission.
70
+ */
71
+ deletingUser?: string;
72
+ }
73
+
74
+ export class Permission {
75
+ kind = Kind;
76
+ /**
77
+ * The data store key of the permission.
78
+ * This property is generated by the store and is not writable.
79
+ */
80
+ key = '';
81
+ /**
82
+ * The type of the permission.
83
+ *
84
+ * - `user` can access the file by a specific user
85
+ * - `group` can access the file by a group of users
86
+ * - `anyone` the object can be searched by anyone who has access to the store.
87
+ *
88
+ * Note, the `anyone` object does not mean that the end-user sees the file when
89
+ * listing objects in the store. It means the file can be searched for.
90
+ */
91
+ type: PermissionType = 'user';
92
+ /**
93
+ * The id of the owner of the permission.
94
+ * The value depends on the `type`. For the `user` type it is the user id.
95
+ * The `group` means the group id. It is not set when the role is `anyone`.
96
+ */
97
+ owner?: string;
98
+ /**
99
+ * The role granted by this permission.
100
+ */
101
+ role: PermissionRole = 'reader';
102
+ /**
103
+ * The "pretty" name to render with the permission.
104
+ *
105
+ * - `user` type - user's full name
106
+ * - `group` type - the name of the group
107
+ * - `anyone` type - no render name
108
+ */
109
+ displayName?: string;
110
+ /**
111
+ * Optional expiration date of the permission. This is the timestamp when the permission expires.
112
+ * When creating / updating the permission the expiration date must:
113
+ *
114
+ * - be used on a user or a group
115
+ * - the time must be in the future
116
+ */
117
+ expirationTime?: number;
118
+
119
+ /**
120
+ * The store id of the user that added this permission.
121
+ */
122
+ addingUser: string = '';
123
+
124
+ /**
125
+ * Whether the file object is deleted.
126
+ */
127
+ deleted?: boolean;
128
+ /**
129
+ * The timestamp of when the file was deleted.
130
+ */
131
+ deletedTime?: number;
132
+ /**
133
+ * The id of the user that has deleted the file.
134
+ */
135
+ deletingUser?: string;
136
+
137
+ /**
138
+ * Creates a Permission object for a user.
139
+ *
140
+ * @param role The user role to set.
141
+ * @param user The user id that has the role.
142
+ */
143
+ static fromUserRole(role: PermissionRole, user: string, addingUser: string): Permission {
144
+ const init: IPermission = {
145
+ key: v4(),
146
+ kind: Kind,
147
+ owner: user,
148
+ role,
149
+ type: 'user',
150
+ addingUser,
151
+ };
152
+ return new Permission(init);
153
+ }
154
+
155
+ /**
156
+ * Creates a Permission object for a group.
157
+ *
158
+ * @param role The group role to set.
159
+ * @param group The group id that has the role.
160
+ */
161
+ static fromGroupRole(role: PermissionRole, group: string, addingUser: string): Permission {
162
+ const init: IPermission = {
163
+ key: v4(),
164
+ kind: Kind,
165
+ owner: group,
166
+ role,
167
+ type: 'group',
168
+ addingUser,
169
+ };
170
+ return new Permission(init);
171
+ }
172
+
173
+ /**
174
+ * Creates a Permission object for a group.
175
+ *
176
+ * @param role The group role to set.
177
+ * @param group The group id that has the role.
178
+ */
179
+ static fromAnyoneRole(role: PermissionRole, addingUser: string): Permission {
180
+ const init: IPermission = {
181
+ key: v4(),
182
+ kind: Kind,
183
+ role,
184
+ type: 'anyone',
185
+ addingUser,
186
+ };
187
+ return new Permission(init);
188
+ }
189
+
190
+ constructor(input?: string | IPermission) {
191
+ let init: IPermission;
192
+ if (typeof input === 'string') {
193
+ init = JSON.parse(input);
194
+ } else if (typeof input === 'object') {
195
+ init = input;
196
+ } else {
197
+ init = {
198
+ kind: Kind,
199
+ key: v4(),
200
+ owner: '',
201
+ role: 'reader',
202
+ type: 'user',
203
+ addingUser: '',
204
+ };
205
+ }
206
+ this.new(init);
207
+ }
208
+
209
+ /**
210
+ * Creates a new environment clearing anything that is so far defined.
211
+ *
212
+ * Note, this throws an error when the environment is not a space.
213
+ */
214
+ new(init: IPermission): void {
215
+ if (!Permission.isPermission(init)) {
216
+ throw new Error(`Not a permission.`);
217
+ }
218
+ const { key = v4(), owner, role, type, displayName, expirationTime, addingUser, deleted, deletedTime, deletingUser } = init;
219
+ this.kind = Kind;
220
+ this.key = key;
221
+ this.owner = owner;
222
+ this.role = role;
223
+ this.type = type;
224
+ this.addingUser = addingUser;
225
+ if (displayName) {
226
+ this.displayName = displayName;
227
+ } else {
228
+ this.displayName = undefined;
229
+ }
230
+ if (typeof expirationTime === 'number') {
231
+ this.expirationTime = expirationTime;
232
+ } else {
233
+ this.expirationTime = undefined;
234
+ }
235
+ if (typeof deleted === 'boolean') {
236
+ this.deleted = deleted;
237
+ this.deletedTime = deletedTime;
238
+ this.deletingUser = deletingUser;
239
+ } else {
240
+ this.deleted = undefined;
241
+ this.deletedTime = undefined;
242
+ this.deletingUser = undefined;
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Checks whether the input is a definition of an user space.
248
+ */
249
+ static isPermission(input: unknown): boolean {
250
+ const typed = input as IPermission;
251
+ if (!input || typed.kind !== Kind) {
252
+ return false;
253
+ }
254
+ return true;
255
+ }
256
+
257
+ toJSON(): IPermission {
258
+ const result: IPermission = {
259
+ kind: Kind,
260
+ key: this.key,
261
+ role: this.role,
262
+ type: this.type,
263
+ addingUser: this.addingUser,
264
+ };
265
+ if (this.owner) {
266
+ result.owner = this.owner;
267
+ }
268
+ if (this.displayName) {
269
+ result.displayName = this.displayName;
270
+ }
271
+ if (this.expirationTime) {
272
+ result.expirationTime = this.expirationTime;
273
+ }
274
+ if (typeof this.deleted === 'boolean') {
275
+ result.deleted = this.deleted;
276
+
277
+ if (this.deletedTime) {
278
+ result.deletedTime = this.deletedTime;
279
+ }
280
+ if (this.deletingUser) {
281
+ result.deletingUser = this.deletingUser;
282
+ }
283
+ }
284
+ return result;
285
+ }
286
+ }
287
+
288
+ /**
289
+ * This is used in the communication with the backend to add/change user's access to the resource.
290
+ */
291
+ export interface IAccessOperation {
292
+ /**
293
+ * The user or group id. Not populated for `anyone` type.
294
+ */
295
+ id?: string;
296
+ /**
297
+ * The permission type
298
+ */
299
+ type: PermissionType;
300
+ }
301
+
302
+ export interface IAccessAddOperation extends IAccessOperation {
303
+ op: "add";
304
+ /**
305
+ * The level that the user or the group has access to.
306
+ */
307
+ value: PermissionRole;
308
+ /**
309
+ * The timestamp when the permission expires.
310
+ */
311
+ expirationTime?: number;
312
+ }
313
+
314
+ export interface IAccessRemoveOperation extends IAccessOperation {
315
+ op: "remove";
316
+ }
317
+
318
+ export type AccessOperation = IAccessAddOperation | IAccessRemoveOperation;
@@ -0,0 +1,83 @@
1
+ export interface IEmail {
2
+ /**
3
+ * When available the email of the user.
4
+ */
5
+ email?: string;
6
+ /**
7
+ * Whether the `email` was verified.
8
+ * Not verified emails should have limited use in the system.
9
+ */
10
+ verified?: boolean;
11
+ }
12
+
13
+ export interface IUserPicture {
14
+ /**
15
+ * When available, the URL to the user's picture image.
16
+ */
17
+ url?: string;
18
+ /**
19
+ * Alternative to the `imageUrl`. When set it is a data URL value of the image.
20
+ */
21
+ data?: string;
22
+ }
23
+
24
+ export const Kind = 'Core#User';
25
+
26
+ interface BaseUser {
27
+ kind: typeof Kind;
28
+ /**
29
+ * Data store key of the user.
30
+ */
31
+ key: string;
32
+ /**
33
+ * The display name of the user.
34
+ */
35
+ name: string;
36
+ /**
37
+ * When available the email of the user.
38
+ */
39
+ email?: IEmail[];
40
+ /**
41
+ * The user picture to render.
42
+ */
43
+ picture?: IUserPicture;
44
+ /**
45
+ * General purpose tags field.
46
+ */
47
+ tags?: string[];
48
+ /**
49
+ * Optional user locale information.
50
+ */
51
+ locale?: string;
52
+ /**
53
+ * Optional metadata related to the auth provider.
54
+ */
55
+ provider?: unknown;
56
+ /**
57
+ * Whether the user is deleted from the system.
58
+ */
59
+ deleted?: boolean;
60
+ /**
61
+ * The timestamp of when the user was deleted.
62
+ */
63
+ deletedTime?: number;
64
+ /**
65
+ * The id of the user that deleted the user.
66
+ */
67
+ deletingUser?: string;
68
+ }
69
+
70
+ /**
71
+ * Represents a user in the system.
72
+ * This can be embedded in various situations like project's revision history,
73
+ * ACL, Authorization, etc.
74
+ *
75
+ * Note, the store implementation may have additional fields that support external
76
+ * identity providers. However, this is not exposed to the user through the API.
77
+ */
78
+ export interface IUser extends BaseUser {
79
+ /**
80
+ * Optional metadata related to the auth provider.
81
+ */
82
+ provider?: unknown;
83
+ }
@@ -2,8 +2,8 @@ import { JsonPatch } from 'json8-patch';
2
2
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
3
3
  import { RouteBuilder } from './RouteBuilder.js';
4
4
  import { IListOptions, IListResponse } from '../../models/Backend.js';
5
- import { IWorkspace, IUserWorkspace, Workspace, Kind as WorkspaceKind } from '../../models/Workspace.js';
6
- import { UserAccessOperation } from '../../models/User.js';
5
+ import { IWorkspace, Workspace, Kind as WorkspaceKind } from '../../models/Workspace.js';
6
+ import { AccessOperation } from '../../models/store/Permission.js';
7
7
 
8
8
  export class SpacesSdk extends SdkBase {
9
9
  /**
@@ -65,7 +65,7 @@ export class SpacesSdk extends SdkBase {
65
65
  * @param key The user space key
66
66
  * @returns The definition of the user space.
67
67
  */
68
- async read(key: string): Promise<IUserWorkspace> {
68
+ async read(key: string): Promise<IWorkspace> {
69
69
  const { token } = this.sdk;
70
70
  const url = this.sdk.getUrl(RouteBuilder.space(key));
71
71
  const result = await this.sdk.http.get(url.toString(), { token });
@@ -78,7 +78,7 @@ export class SpacesSdk extends SdkBase {
78
78
  if (!result.body) {
79
79
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
80
80
  }
81
- let data: IUserWorkspace;
81
+ let data: IWorkspace;
82
82
  try {
83
83
  data = JSON.parse(result.body);
84
84
  } catch (e) {
@@ -145,7 +145,7 @@ export class SpacesSdk extends SdkBase {
145
145
  * @param key The user space key
146
146
  * @param value The patch operation on the space's ACL
147
147
  */
148
- async patchUsers(key: string, value: UserAccessOperation[]): Promise<void> {
148
+ async patchUsers(key: string, value: AccessOperation[]): Promise<void> {
149
149
  const { token } = this.sdk;
150
150
  const url = this.sdk.getUrl(RouteBuilder.spaceUsers(key));
151
151
  const body = JSON.stringify(value);
@@ -1,7 +1,7 @@
1
1
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
3
  import { IListOptions, IListResponse } from '../../models/Backend.js';
4
- import { IUser } from '../../models/User.js';
4
+ import { IUser } from '../../models/store/User.js';
5
5
 
6
6
  export class UsersSdk extends SdkBase {
7
7
  async me(): Promise<IUser> {
@@ -1 +0,0 @@
1
- {"version":3,"file":"User.js","sourceRoot":"","sources":["../../../src/models/User.ts"],"names":[],"mappings":"AAgEA,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAC"}
@@ -1,138 +0,0 @@
1
- export type AccessControlLevel = 'read' | 'comment' | 'write' | 'admin' | 'owner';
2
-
3
- /**
4
- * This is used in the communication with the backend to add/change user's access to the resource.
5
- */
6
- export interface IUserAccessOperation {
7
- /**
8
- * The user id.
9
- */
10
- uid: string;
11
- }
12
-
13
- export interface IUserAccessAddOperation extends IUserAccessOperation {
14
- op: "add";
15
- /**
16
- * The level that the user has access to.
17
- */
18
- value: AccessControlLevel;
19
- }
20
-
21
- export interface IUserAccessRemoveOperation extends IUserAccessOperation {
22
- op: "remove";
23
- }
24
-
25
- export type UserAccessOperation = IUserAccessAddOperation | IUserAccessRemoveOperation;
26
-
27
- /**
28
- * The definition of an access control.
29
- * The user may have access to a workspace so this is the object describing the level of the workspace.
30
- */
31
- export interface IAccessControl {
32
- /**
33
- * The data store key of the referenced object the user has access to.
34
- */
35
- key: string;
36
- /**
37
- * The level that the user has access to.
38
- */
39
- level: AccessControlLevel;
40
- }
41
-
42
- export interface IEmail {
43
- /**
44
- * When available the email of the user.
45
- */
46
- email?: string;
47
- /**
48
- * Whether the `email` was verified.
49
- * Not verified emails should have limited use in the system.
50
- */
51
- verified?: boolean;
52
- }
53
-
54
- export interface IUserPicture {
55
- /**
56
- * When available, the URL to the user's picture image.
57
- */
58
- url?: string;
59
- /**
60
- * Alternative to the `imageUrl`. When set it is a data URL value of the image.
61
- */
62
- data?: string;
63
- }
64
-
65
- export const Kind = 'Core#User';
66
-
67
- interface BaseUser {
68
- kind: typeof Kind;
69
- /**
70
- * Data store key of the user.
71
- */
72
- key: string;
73
- /**
74
- * The display name of the user.
75
- */
76
- name: string;
77
- /**
78
- * When available the email of the user.
79
- */
80
- email?: IEmail[];
81
- /**
82
- * The user picture to render.
83
- */
84
- picture?: IUserPicture;
85
- /**
86
- * General purpose tags field.
87
- */
88
- tags?: string[];
89
- /**
90
- * Optional user locale information.
91
- */
92
- locale?: string;
93
- /**
94
- * Optional metadata related to the auth provider.
95
- */
96
- provider?: unknown;
97
- }
98
-
99
- /**
100
- * Represents a user in the system.
101
- * This can be embedded in various situations like project's revision history,
102
- * ACL, Authorization, etc.
103
- *
104
- * Note, the store implementation may have additional fields that support external
105
- * identity providers. However, this is not exposed to the user through the API.
106
- */
107
- export interface IUser extends BaseUser {
108
- /**
109
- * Optional metadata related to the auth provider.
110
- */
111
- provider?: unknown;
112
- }
113
-
114
- /**
115
- * This object may be created for each user in the system.
116
- * It describes to which spaces user has access to.
117
- */
118
- export interface IUserSpaces {
119
- /**
120
- * The list of access to the spaces for the user.
121
- */
122
- spaces: IAccessControl[];
123
- /**
124
- * The data store key of the user that has access to the space.
125
- * This is also the key of the entry.
126
- */
127
- user: string;
128
- }
129
-
130
- /**
131
- * An abstract user object that contains access information to a space.
132
- */
133
- export interface ISpaceUser extends BaseUser {
134
- /**
135
- * The level that the user has access to.
136
- */
137
- level: AccessControlLevel;
138
- }