@inweb/client 25.10.0 → 25.11.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.
@@ -6,6 +6,7 @@ import { File } from "./File";
6
6
  import { Job } from "./Job";
7
7
  import { Project } from "./Project";
8
8
  import { User } from "./User";
9
+ import { OAuthClient } from "./OAuthClient";
9
10
  /**
10
11
  * Provides methods for managing Open Cloud Server resources such as users, files, assemblies,
11
12
  * jobs, projects, etc.
@@ -136,6 +137,63 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
136
137
  * @returns Returns an object with updated server settings.
137
138
  */
138
139
  updateServerSettings(settings: any): Promise<any>;
140
+ /**
141
+ * Result for OAuth client list.
142
+ *
143
+ * @typedef {any} OAuthClientsResult
144
+ * @property {OAuthClient[]} result - Result client list.
145
+ * @property {number} start - The starting index in the client list in the request.
146
+ * @property {number} limit - The maximum number of requested clients.
147
+ * @property {number} allSize - Total number of OAuth clients on the server.
148
+ * @property {number} size - The number of clients in the result list.
149
+ */
150
+ /**
151
+ * Returns a list of OAuth clients of the server.
152
+ *
153
+ * Only administrators can get a list of OAuth clients. If the current logged in user is not
154
+ * an administrator, an exception will be thrown.
155
+ *
156
+ * @param start - The starting index in the client list. Used for paging.
157
+ * @param limit - The maximum number of clients that should be returned per request. Used for paging.
158
+ */
159
+ getOAuthClients(start?: number, limit?: number): Promise<{
160
+ result: OAuthClient[];
161
+ start: number;
162
+ limit: number;
163
+ allSize: number;
164
+ size: number;
165
+ }>;
166
+ /**
167
+ * Returns information about the specified OAuth client.
168
+ *
169
+ * Only administrators can get OAuth clients. If the current logged in user is not an
170
+ * administrator, an exception will be thrown.
171
+ *
172
+ * @param clientId - Client ID.
173
+ */
174
+ getOAuthClient(clientId: string): Promise<OAuthClient>;
175
+ /**
176
+ * Creates a new OAuth client on the server.
177
+ *
178
+ * Only administrators can create OAuth clients. If the current logged in user is not an
179
+ * administrator, an exception will be thrown.
180
+ *
181
+ * @param name - Client name.
182
+ * @param redirectUrl - Endpoint to which the OAuth 2.0 server sends the response.
183
+ * @param description - Client description.
184
+ */
185
+ createOAuthClient(name: string, redirectUrl: string, description?: string): Promise<OAuthClient>;
186
+ /**
187
+ * Deletes the specified OAuth client from the server.
188
+ *
189
+ * Only administrators can delete OAuth clients. If the current logged in user is not an
190
+ * administrator, an exception will be thrown.
191
+ *
192
+ * @param clientId - Client ID.
193
+ * @returns Returns the raw data of a deleted client. For more information, see
194
+ * {@link https://cloud.opendesign.com/docs//pages/server/api.html#OAuthClient | Open Cloud OAuth Clients API}.
195
+ */
196
+ deleteOAuthClient(clientId: string): Promise<any>;
139
197
  /**
140
198
  * Returns the list of server users.
141
199
  *
@@ -200,10 +258,10 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
200
258
  * Result for file list.
201
259
  *
202
260
  * @typedef {any} FilesResult
203
- * @property {number} allSize - Total number of files the user has access to.
261
+ * @property {File[]} result - Result file list.
204
262
  * @property {number} start - The starting index in the file list in the request.
205
263
  * @property {number} limit - The maximum number of requested files.
206
- * @property {File[]} result - Result file list.
264
+ * @property {number} allSize - Total number of files the user has access to.
207
265
  * @property {number} size - The number of files in the result list.
208
266
  */
209
267
  /**
@@ -221,10 +279,10 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
221
279
  * @param sortField - Allows to specify sort field.
222
280
  */
223
281
  getFiles(start?: number, limit?: number, name?: string, ext?: string | string[], ids?: string | string[], sortByDesc?: boolean, sortField?: string): Promise<{
224
- allSize: number;
282
+ result: File[];
225
283
  start: number;
226
284
  limit: number;
227
- result: File[];
285
+ allSize: number;
228
286
  size: number;
229
287
  }>;
230
288
  /**
@@ -296,10 +354,10 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
296
354
  * Result for job list.
297
355
  *
298
356
  * @typedef {any} JobsResult
299
- * @property {number} allSize - Total number of jobs created by the user.
357
+ * @property {Job[]} result - Result job list.
300
358
  * @property {number} start - The starting index in the job list in the request.
301
359
  * @property {number} limit - The maximum number of requested jobs.
302
- * @property {Job[]} result - Result job list.
360
+ * @property {number} allSize - Total number of jobs created by the user.
303
361
  * @property {number} size - The number of jobs in the result list.
304
362
  */
305
363
  /**
@@ -313,10 +371,10 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
313
371
  * @param {boolean} sortField - Allows to specify sort field.
314
372
  */
315
373
  getJobs(status?: string | string[], limit?: number, start?: number, sortByDesc?: boolean, sortField?: string): Promise<{
316
- allSize: number;
374
+ result: Job[];
317
375
  start: number;
318
376
  limit: number;
319
- result: Job[];
377
+ allSize: number;
320
378
  size: number;
321
379
  }>;
322
380
  /**
@@ -356,10 +414,10 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
356
414
  * Result for assembly list.
357
415
  *
358
416
  * @typedef {any} AssembliesResult
359
- * @property {number} allSize - Total number of assemblies the user has access to.
417
+ * @property {Assembly[]} result - Result assembly list.
360
418
  * @property {number} start - The starting index in the assembly list in the request.
361
419
  * @property {number} limit - The maximum number of requested assemblies.
362
- * @property {Assembly[]} result - Result assembly list.
420
+ * @property {number} allSize - Total number of assemblies the user has access to.
363
421
  * @property {number} size - The number of assemblies in the result list.
364
422
  */
365
423
  /**
@@ -375,10 +433,10 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
375
433
  * @param sortField - Allows to specify sort field.
376
434
  */
377
435
  getAssemblies(start?: number, limit?: number, name?: string, ids?: string | string[], sortByDesc?: boolean, sortField?: string): Promise<{
378
- allSize: number;
436
+ result: Assembly[];
379
437
  start: number;
380
438
  limit: number;
381
- result: Assembly[];
439
+ allSize: number;
382
440
  size: number;
383
441
  }>;
384
442
  /**
@@ -423,10 +481,10 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
423
481
  * Result for project list.
424
482
  *
425
483
  * @typedef {any} ProjectsResult
426
- * @property {number} allSize - Total number of projects the user has access to.
484
+ * @property {Project[]} result - Result project list.
427
485
  * @property {number} start - The starting index in the project list in the request.
428
486
  * @property {number} limit - The maximum number of requested projects.
429
- * @property {Project[]} result - Result project list.
487
+ * @property {number} allSize - Total number of projects the user has access to.
430
488
  * @property {number} size - The number of projects in the result list.
431
489
  */
432
490
  /**
@@ -440,10 +498,10 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
440
498
  * projects are sorted by name in ascending order.
441
499
  */
442
500
  getProjects(start?: number, limit?: number, name?: string, ids?: string | string[], sortByDesc?: boolean): Promise<{
443
- allSize: number;
501
+ result: Project[];
444
502
  start: number;
445
503
  limit: number;
446
- result: Project[];
504
+ allSize: number;
447
505
  size: number;
448
506
  }>;
449
507
  /**
@@ -0,0 +1,108 @@
1
+ import { IHttpClient } from "./IHttpClient";
2
+ /**
3
+ * Provides properties and methods for obtaining information about a OAuth 2.0 client that have
4
+ * access the Open Cloud Server API.
5
+ */
6
+ export declare class OAuthClient {
7
+ private _data;
8
+ httpClient: IHttpClient;
9
+ /**
10
+ * @param data - Raw client data received from the server. For more information, see
11
+ * {@link https://cloud.opendesign.com/docs//pages/server/api.html#OAuthClient | Open Cloud OAuth Clients API}.
12
+ * @param httpClient - HTTP client instance used to send requests to the REST API server.
13
+ */
14
+ constructor(data: any, httpClient: IHttpClient);
15
+ private internalGet;
16
+ protected internalPost(relativePath: string, body?: BodyInit | object): Promise<Response>;
17
+ private internalPut;
18
+ private internalDelete;
19
+ /**
20
+ * OAuth 2.0 server authorization endpoint.
21
+ */
22
+ get authUrl(): string;
23
+ /**
24
+ * OAuth 2.0 server token endpoint.
25
+ */
26
+ get accessTokenUrl(): string;
27
+ /**
28
+ * Unique client ID.
29
+ *
30
+ * @readonly
31
+ */
32
+ get clientId(): string;
33
+ /**
34
+ * Client creation time (UTC) in the format specified in
35
+ * {@link https://www.wikipedia.org/wiki/ISO_8601 | ISO 8601}.
36
+ */
37
+ get createdAt(): string;
38
+ /**
39
+ * Client application description.
40
+ */
41
+ get description(): string;
42
+ set description(value: string);
43
+ /**
44
+ * Client data received from the server. For more information, see
45
+ * {@link https://cloud.opendesign.com/docs//pages/server/api.html#OAuthClient | Open Cloud OAuth Clients API}.
46
+ *
47
+ * @readonly
48
+ */
49
+ get data(): any;
50
+ set data(value: any);
51
+ /**
52
+ * Client application name.
53
+ */
54
+ get name(): string;
55
+ set name(value: string);
56
+ /**
57
+ * The endpoint to which the OAuth 2.0 server sends the response.
58
+ */
59
+ get redirectUrl(): string;
60
+ set redirectUrl(value: string);
61
+ /**
62
+ * Client secret.
63
+ *
64
+ * @readonly
65
+ */
66
+ get secret(): string;
67
+ /**
68
+ * Client last update time (UTC) in the format specified in
69
+ * {@link https://www.wikipedia.org/wiki/ISO_8601 | ISO 8601}.
70
+ */
71
+ get updatedAt(): string;
72
+ /**
73
+ * Reloads clien data from the server.
74
+ */
75
+ checkout(): Promise<this>;
76
+ /**
77
+ * Updates client data on the server.
78
+ *
79
+ * Only administrators can update OAuth clients. If the current logged in user is not an
80
+ * administrator, an exception will be thrown.
81
+ *
82
+ * @param data - Raw client data. For more information, see
83
+ * {@link https://cloud.opendesign.com/docs//pages/server/api.html#OAuthClient | Open Cloud OAuth Clients API}.
84
+ */
85
+ update(data: any): Promise<this>;
86
+ /**
87
+ * Deletes a client from the server.
88
+ *
89
+ * Only administrators can delete OAuth clients. If the current logged in user is not an
90
+ * administrator, an exception will be thrown.
91
+ *
92
+ * @returns Returns the raw data of a deleted client. For more information, see
93
+ * {@link https://cloud.opendesign.com/docs//pages/server/api.html#OAuthClient | Open Cloud OAuth Clients API}.
94
+ */
95
+ delete(): Promise<any>;
96
+ /**
97
+ * Saves client properties changes to the server. Call this method to update client data on
98
+ * the server after any property changes.
99
+ *
100
+ * Only administrators can update OAuth clients. If the current logged in user is not an
101
+ * administrator, an exception will be thrown.
102
+ */
103
+ save(): Promise<this>;
104
+ /**
105
+ * Revokes the access tokens for all users of the client application.
106
+ */
107
+ revoke(): Promise<this>;
108
+ }
package/lib/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export { IRoleActions } from "./Api/IRole";
12
12
  export { IShortUserDesc } from "./Api/IUser";
13
13
  export { Member } from "./Api/Member";
14
14
  export { Model } from "./Api/Model";
15
+ export { OAuthClient } from "./Api/OAuthClient";
15
16
  export { Permission } from "./Api/Permission";
16
17
  export { Project } from "./Api/Project";
17
18
  export { Role } from "./Api/Role";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/client",
3
- "version": "25.10.0",
3
+ "version": "25.11.0",
4
4
  "description": "JavaScript REST API client for the Open Cloud Server",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,6 +26,6 @@
26
26
  "docs": "typedoc"
27
27
  },
28
28
  "dependencies": {
29
- "@inweb/eventemitter2": "~25.10.0"
29
+ "@inweb/eventemitter2": "~25.11.0"
30
30
  }
31
31
  }
package/src/Api/Client.ts CHANGED
@@ -32,6 +32,7 @@ import { File } from "./File";
32
32
  import { Job } from "./Job";
33
33
  import { Project } from "./Project";
34
34
  import { User } from "./User";
35
+ import { OAuthClient } from "./OAuthClient";
35
36
  import { parseArgs } from "./Utils";
36
37
 
37
38
  /**
@@ -278,6 +279,104 @@ export class Client extends EventEmitter2<ClientEventMap> {
278
279
  return this.httpClient.put("/settings", settings).then((response) => response.json());
279
280
  }
280
281
 
282
+ /**
283
+ * Result for OAuth client list.
284
+ *
285
+ * @typedef {any} OAuthClientsResult
286
+ * @property {OAuthClient[]} result - Result client list.
287
+ * @property {number} start - The starting index in the client list in the request.
288
+ * @property {number} limit - The maximum number of requested clients.
289
+ * @property {number} allSize - Total number of OAuth clients on the server.
290
+ * @property {number} size - The number of clients in the result list.
291
+ */
292
+
293
+ /**
294
+ * Returns a list of OAuth clients of the server.
295
+ *
296
+ * Only administrators can get a list of OAuth clients. If the current logged in user is not
297
+ * an administrator, an exception will be thrown.
298
+ *
299
+ * @param start - The starting index in the client list. Used for paging.
300
+ * @param limit - The maximum number of clients that should be returned per request. Used for paging.
301
+ */
302
+ getOAuthClients(
303
+ start?: number,
304
+ limit?: number
305
+ ): Promise<{
306
+ result: OAuthClient[];
307
+ start: number;
308
+ limit: number;
309
+ allSize: number;
310
+ size: number;
311
+ }> {
312
+ const searchParams = new URLSearchParams();
313
+ if (start > 0) searchParams.set("start", start.toString());
314
+ if (limit > 0) searchParams.set("limit", limit.toString());
315
+
316
+ let queryString = searchParams.toString();
317
+ if (queryString) queryString = "?" + queryString;
318
+
319
+ return this.httpClient
320
+ .get(`/oauth/clients${queryString}`)
321
+ .then((response) => response.json())
322
+ .then((clients) => {
323
+ return {
324
+ ...clients,
325
+ result: clients.result.map((data) => new OAuthClient(data, this.httpClient)),
326
+ };
327
+ });
328
+ }
329
+
330
+ /**
331
+ * Returns information about the specified OAuth client.
332
+ *
333
+ * Only administrators can get OAuth clients. If the current logged in user is not an
334
+ * administrator, an exception will be thrown.
335
+ *
336
+ * @param clientId - Client ID.
337
+ */
338
+ getOAuthClient(clientId: string): Promise<OAuthClient> {
339
+ return this.httpClient
340
+ .get(`/oauth/clients/${clientId}`)
341
+ .then((response) => response.json())
342
+ .then((data) => new OAuthClient(data, this.httpClient));
343
+ }
344
+
345
+ /**
346
+ * Creates a new OAuth client on the server.
347
+ *
348
+ * Only administrators can create OAuth clients. If the current logged in user is not an
349
+ * administrator, an exception will be thrown.
350
+ *
351
+ * @param name - Client name.
352
+ * @param redirectUrl - Endpoint to which the OAuth 2.0 server sends the response.
353
+ * @param description - Client description.
354
+ */
355
+ createOAuthClient(name: string, redirectUrl: string, description?: string): Promise<OAuthClient> {
356
+ return this.httpClient
357
+ .post("/oauth/clients", {
358
+ name,
359
+ redirectUrl,
360
+ description,
361
+ })
362
+ .then((response) => response.json())
363
+ .then((data) => new OAuthClient(data, this.httpClient));
364
+ }
365
+
366
+ /**
367
+ * Deletes the specified OAuth client from the server.
368
+ *
369
+ * Only administrators can delete OAuth clients. If the current logged in user is not an
370
+ * administrator, an exception will be thrown.
371
+ *
372
+ * @param clientId - Client ID.
373
+ * @returns Returns the raw data of a deleted client. For more information, see
374
+ * {@link https://cloud.opendesign.com/docs//pages/server/api.html#OAuthClient | Open Cloud OAuth Clients API}.
375
+ */
376
+ deleteOAuthClient(clientId: string): Promise<any> {
377
+ return this.httpClient.delete(`/oauth/clients/${clientId}`).then((response) => response.json());
378
+ }
379
+
281
380
  /**
282
381
  * Returns the list of server users.
283
382
  *
@@ -401,10 +500,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
401
500
  * Result for file list.
402
501
  *
403
502
  * @typedef {any} FilesResult
404
- * @property {number} allSize - Total number of files the user has access to.
503
+ * @property {File[]} result - Result file list.
405
504
  * @property {number} start - The starting index in the file list in the request.
406
505
  * @property {number} limit - The maximum number of requested files.
407
- * @property {File[]} result - Result file list.
506
+ * @property {number} allSize - Total number of files the user has access to.
408
507
  * @property {number} size - The number of files in the result list.
409
508
  */
410
509
 
@@ -430,7 +529,13 @@ export class Client extends EventEmitter2<ClientEventMap> {
430
529
  ids?: string | string[],
431
530
  sortByDesc?: boolean,
432
531
  sortField?: string
433
- ): Promise<{ allSize: number; start: number; limit: number; result: File[]; size: number }> {
532
+ ): Promise<{
533
+ result: File[];
534
+ start: number;
535
+ limit: number;
536
+ allSize: number;
537
+ size: number;
538
+ }> {
434
539
  const searchParams = new URLSearchParams();
435
540
  if (start > 0) searchParams.set("start", start.toString());
436
541
  if (limit > 0) searchParams.set("limit", limit.toString());
@@ -571,10 +676,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
571
676
  * Result for job list.
572
677
  *
573
678
  * @typedef {any} JobsResult
574
- * @property {number} allSize - Total number of jobs created by the user.
679
+ * @property {Job[]} result - Result job list.
575
680
  * @property {number} start - The starting index in the job list in the request.
576
681
  * @property {number} limit - The maximum number of requested jobs.
577
- * @property {Job[]} result - Result job list.
682
+ * @property {number} allSize - Total number of jobs created by the user.
578
683
  * @property {number} size - The number of jobs in the result list.
579
684
  */
580
685
 
@@ -594,7 +699,13 @@ export class Client extends EventEmitter2<ClientEventMap> {
594
699
  start?: number,
595
700
  sortByDesc?: boolean,
596
701
  sortField?: string
597
- ): Promise<{ allSize: number; start: number; limit: number; result: Job[]; size: number }> {
702
+ ): Promise<{
703
+ result: Job[];
704
+ start: number;
705
+ limit: number;
706
+ allSize: number;
707
+ size: number;
708
+ }> {
598
709
  const searchParams = new URLSearchParams();
599
710
  if (start > 0) searchParams.set("start", start.toString());
600
711
  if (limit > 0) searchParams.set("limit", limit.toString());
@@ -674,10 +785,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
674
785
  * Result for assembly list.
675
786
  *
676
787
  * @typedef {any} AssembliesResult
677
- * @property {number} allSize - Total number of assemblies the user has access to.
788
+ * @property {Assembly[]} result - Result assembly list.
678
789
  * @property {number} start - The starting index in the assembly list in the request.
679
790
  * @property {number} limit - The maximum number of requested assemblies.
680
- * @property {Assembly[]} result - Result assembly list.
791
+ * @property {number} allSize - Total number of assemblies the user has access to.
681
792
  * @property {number} size - The number of assemblies in the result list.
682
793
  */
683
794
 
@@ -700,7 +811,13 @@ export class Client extends EventEmitter2<ClientEventMap> {
700
811
  ids?: string | string[],
701
812
  sortByDesc?: boolean,
702
813
  sortField?: string
703
- ): Promise<{ allSize: number; start: number; limit: number; result: Assembly[]; size: number }> {
814
+ ): Promise<{
815
+ result: Assembly[];
816
+ start: number;
817
+ limit: number;
818
+ allSize: number;
819
+ size: number;
820
+ }> {
704
821
  const searchParams = new URLSearchParams();
705
822
  if (start > 0) searchParams.set("start", start.toString());
706
823
  if (limit > 0) searchParams.set("limit", limit.toString());
@@ -790,10 +907,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
790
907
  * Result for project list.
791
908
  *
792
909
  * @typedef {any} ProjectsResult
793
- * @property {number} allSize - Total number of projects the user has access to.
910
+ * @property {Project[]} result - Result project list.
794
911
  * @property {number} start - The starting index in the project list in the request.
795
912
  * @property {number} limit - The maximum number of requested projects.
796
- * @property {Project[]} result - Result project list.
913
+ * @property {number} allSize - Total number of projects the user has access to.
797
914
  * @property {number} size - The number of projects in the result list.
798
915
  */
799
916
 
@@ -813,7 +930,13 @@ export class Client extends EventEmitter2<ClientEventMap> {
813
930
  name?: string,
814
931
  ids?: string | string[],
815
932
  sortByDesc?: boolean
816
- ): Promise<{ allSize: number; start: number; limit: number; result: Project[]; size: number }> {
933
+ ): Promise<{
934
+ result: Project[];
935
+ start: number;
936
+ limit: number;
937
+ allSize: number;
938
+ size: number;
939
+ }> {
817
940
  const searchParams = new URLSearchParams();
818
941
  if (start > 0) searchParams.set("start", start.toString());
819
942
  if (limit > 0) searchParams.set("limit", limit.toString());