@inweb/client 25.9.4 → 25.9.6

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.
@@ -1,4 +1,5 @@
1
1
  import { IHttpClient } from "./IHttpClient";
2
+ import { IFileReferences } from "./IFile";
2
3
  import { IAssociatedFileData, IAssemblyVersionInfo, IModelTransformMatrix } from "./IAssembly";
3
4
  import { IShortUserDesc } from "./IUser";
4
5
  import { Model } from "./Model";
@@ -245,7 +246,17 @@ export declare class Assembly {
245
246
  * Deprecated since `25.3`. Use {@link downloadResourceRange | downloadResourceRange()} instead.
246
247
  */
247
248
  downloadFileRange(requestId: number, records: any | null, dataId: string, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<void>;
248
- getReferences(signal?: AbortSignal): Promise<any>;
249
+ /**
250
+ * Returns a list of assembly references containing references from all the files from which
251
+ * the assembly was created.
252
+ *
253
+ * References are images, fonts, or any other files to correct rendering of the assembly.
254
+ *
255
+ * @param signal - An
256
+ * {@link https://developer.mozilla.org/docs/Web/API/AbortController | AbortController}
257
+ * signal, which can be used to abort waiting as desired.
258
+ */
259
+ getReferences(signal?: AbortSignal): Promise<IFileReferences>;
249
260
  /**
250
261
  * Waits for assembly to be created. Assembly is created when it changes to `done` or `failed` status.
251
262
  *
@@ -6,8 +6,14 @@ export declare function error400(text: string, _default?: string): string;
6
6
  * occurs, access denied, or object not found.
7
7
  */
8
8
  export declare class FetchError extends Error {
9
- protected status: number;
10
- protected statusText: string;
9
+ /**
10
+ * {@link https://developer.mozilla.org/docs/Web/HTTP/Status | HTTP status code} of the response.
11
+ */
12
+ status: number;
13
+ /**
14
+ * Status message corresponding to the {@link status | status code}.
15
+ */
16
+ statusText: string;
11
17
  /**
12
18
  * @property status - The
13
19
  * {@link https://developer.mozilla.org/docs/Web/HTTP/Status | HTTP status code} of the response.
package/lib/Api/File.d.ts CHANGED
@@ -466,7 +466,7 @@ export declare class File {
466
466
  */
467
467
  getPermission(permissionId: string): Promise<Permission>;
468
468
  /**
469
- * Creates a new file permission.
469
+ * Creates a new file permission for a user, project, or group.
470
470
  *
471
471
  * @example <caption>Grant the specified user permission to "update" the file.</caption>
472
472
  * const action = "update";
@@ -1,12 +1,36 @@
1
+ /**
2
+ * Defines the data status.
3
+ */
1
4
  export interface IFileDataStatus {
5
+ /**
6
+ * Data state. Can be `none`, `waiting`, `inprogress`, `done` or `failed`.
7
+ */
2
8
  state: string;
9
+ /**
10
+ * Unique ID of the data job.
11
+ */
3
12
  jobId?: string;
4
13
  jobUrl?: string;
5
14
  }
15
+ /**
16
+ * Defines the file status.
17
+ */
6
18
  export interface IFileStatus {
19
+ /**
20
+ * Status of geometry data of `vsfx` type.
21
+ */
7
22
  geometry: IFileDataStatus;
23
+ /**
24
+ * Status of geometry data of `gltf` type.
25
+ */
8
26
  geometryGltf: IFileDataStatus;
27
+ /**
28
+ * Status of the properties.
29
+ */
9
30
  properties: IFileDataStatus;
31
+ /**
32
+ * Status of the validation.
33
+ */
10
34
  validation: IFileDataStatus;
11
35
  }
12
36
  /**
@@ -44,11 +68,11 @@ export interface IFileVersionInfo {
44
68
  ownerId: string;
45
69
  }
46
70
  /**
47
- * Defines the entity, that will have access to the file.
71
+ * Defines the entity, that will have access to the {@link File | file}.
48
72
  */
49
73
  export interface IGrantedTo {
50
74
  /**
51
- * The user entry that has access to the file.
75
+ * The user that has access to the file.
52
76
  */
53
77
  user?: {
54
78
  /**
@@ -61,7 +85,7 @@ export interface IGrantedTo {
61
85
  email: string;
62
86
  };
63
87
  /**
64
- * The project entry that has access to the file.
88
+ * The project that has access to the file.
65
89
  */
66
90
  project?: {
67
91
  /**
@@ -73,4 +97,21 @@ export interface IGrantedTo {
73
97
  */
74
98
  name: string;
75
99
  };
100
+ /**
101
+ * The group that has access to the file.
102
+ */
103
+ group?: {
104
+ /**
105
+ * Project ID.
106
+ */
107
+ projectId: string;
108
+ /**
109
+ * Group ID.
110
+ */
111
+ groupId: string;
112
+ /**
113
+ * Group name.
114
+ */
115
+ name: string;
116
+ };
76
117
  }
@@ -58,6 +58,17 @@ export declare class Permission {
58
58
  /**
59
59
  * Updates permission data on the server.
60
60
  *
61
+ * @example <caption>Update file permissions for the the specified project.</caption>
62
+ * const myFile = client.getFile(myFileId);
63
+ * const permissions = await myFile.getPermissions();
64
+ * const projectPermissions = permissions.filter((permission) =>
65
+ * permission.grantedTo.some((x) => x.project?.id === myProjectId)
66
+ * );
67
+ * const newActions = ["read", "readSourceFile", "update"];
68
+ * await Promise.allSettled(
69
+ * projectPermissions.map((permission) => permission.update({ newActions }))
70
+ * );
71
+ *
61
72
  * @param data - Raw permission data.
62
73
  */
63
74
  update(data: any): Promise<this>;
@@ -3,6 +3,7 @@ import { IShortUserDesc } from "./IUser";
3
3
  import { Role } from "./Role";
4
4
  import { IRoleActions } from "./IRole";
5
5
  import { Member } from "./Member";
6
+ import { File } from "./File";
6
7
  /**
7
8
  * Provides properties and methods for obtaining information about a project on the Open Cloud
8
9
  * Server and managing its {@link Role | roles}, {@link Member | members} and models.
@@ -198,14 +199,14 @@ export declare class Project {
198
199
  */
199
200
  getMember(memberId: string): Promise<Member>;
200
201
  /**
201
- * Add a user to the project to become a member and have permission to perform actions.
202
+ * Adds a user to the project to become a member and have permission to perform actions.
202
203
  *
203
204
  * @param userId - User ID.
204
205
  * @param role - Role name from the list of project {@link getRoles | roles}.
205
206
  */
206
207
  addMember(userId: string, role: string): Promise<Member>;
207
208
  /**
208
- * Remove the specified member from a project.
209
+ * Removes the specified member from a project.
209
210
  *
210
211
  * @param memberId - Member ID.
211
212
  * @returns Returns the raw data of a deleted member.
@@ -231,4 +232,33 @@ export declare class Project {
231
232
  * {@link File.createPermission | File.createPermission()}.
232
233
  */
233
234
  getFilesInformation(): Promise<any[]>;
235
+ /**
236
+ * Returns a list of project models.
237
+ */
238
+ getModels(): Promise<File[]>;
239
+ /**
240
+ * Adds a file to the project with specified permissions.
241
+ *
242
+ * To change file permissions for the project use {@link Permission.update | Permissions.update()}.
243
+ *
244
+ * @param fileId - File ID.
245
+ * @param actions - Actions are allowed to be performed on a file:
246
+ *
247
+ * - `read` - The ability to read file description, geometry data and properties.
248
+ * - `readSourceFile` - The ability to read source file.
249
+ * - `write` - The ability to modify file name, description and references.
250
+ * - `readViewpoint` - The ability to read file viewpoints.
251
+ * - `createViewpoint` - The ability to create file viewpoints.
252
+ *
253
+ * @param _public - Specifies whether all users have access to the file or not.
254
+ * @returns Returns a file instance added to the project.
255
+ */
256
+ addModel(fileId: string, actions: string | string[], _public: boolean): Promise<File>;
257
+ /**
258
+ * Removes the specified file from a project.
259
+ *
260
+ * @param fileId - File ID.
261
+ * @returns Returns a file instance removed from the project.
262
+ */
263
+ removeModel(fileId: string): Promise<File>;
234
264
  }
package/lib/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { FetchError, statusText } from "./Api/FetchError";
7
7
  export { Job } from "./Api/Job";
8
8
  export { IHttpClient } from "./Api/IHttpClient";
9
9
  export { IModelTransformMatrix } from "./Api/IAssembly";
10
- export { IGrantedTo } from "./Api/IFile";
10
+ export { IFileDataStatus, IFileReference, IFileReferences, IFileStatus, IGrantedTo } from "./Api/IFile";
11
11
  export { IRoleActions } from "./Api/IRole";
12
12
  export { IShortUserDesc } from "./Api/IUser";
13
13
  export { Member } from "./Api/Member";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/client",
3
- "version": "25.9.4",
3
+ "version": "25.9.6",
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.9.4"
29
+ "@inweb/eventemitter2": "~25.9.6"
30
30
  }
31
31
  }
@@ -23,6 +23,7 @@
23
23
 
24
24
  import { IHttpClient } from "./IHttpClient";
25
25
  import { FetchError } from "./FetchError";
26
+ import { IFileReferences } from "./IFile";
26
27
  import { IAssociatedFileData, IAssemblyVersionInfo, IModelTransformMatrix } from "./IAssembly";
27
28
  import { IShortUserDesc } from "./IUser";
28
29
  import { Model } from "./Model";
@@ -469,10 +470,26 @@ export class Assembly {
469
470
  await this.downloadResourceRange(dataId, requestId, records, onProgress, signal);
470
471
  }
471
472
 
472
- // Reserved for future use
473
-
474
- getReferences(signal?: AbortSignal): Promise<any> {
475
- return Promise.resolve({ fileId: "", references: [] });
473
+ /**
474
+ * Returns a list of assembly references containing references from all the files from which
475
+ * the assembly was created.
476
+ *
477
+ * References are images, fonts, or any other files to correct rendering of the assembly.
478
+ *
479
+ * @param signal - An
480
+ * {@link https://developer.mozilla.org/docs/Web/API/AbortController | AbortController}
481
+ * signal, which can be used to abort waiting as desired.
482
+ */
483
+ async getReferences(signal?: AbortSignal): Promise<IFileReferences> {
484
+ const references = await Promise.all(
485
+ this.associatedFiles
486
+ .map((file) => `/files/${file.fileId}/references`)
487
+ .map((link) => this.httpClient.get(link, signal).then((response) => response.json()))
488
+ )
489
+ .then((references) => references.map((x) => x.references))
490
+ .then((references) => references.reduce((x, v) => [...v, ...x], []))
491
+ .then((references) => [...new Set(references.map(JSON.stringify))].map((x: string) => JSON.parse(x)));
492
+ return { id: "", references };
476
493
  }
477
494
 
478
495
  /**
@@ -106,8 +106,15 @@ export function error400(text: string, _default = "400"): string {
106
106
  */
107
107
 
108
108
  export class FetchError extends Error {
109
- protected status: number;
110
- protected statusText: string;
109
+ /**
110
+ * {@link https://developer.mozilla.org/docs/Web/HTTP/Status | HTTP status code} of the response.
111
+ */
112
+ public status: number;
113
+
114
+ /**
115
+ * Status message corresponding to the {@link status | status code}.
116
+ */
117
+ public statusText: string;
111
118
 
112
119
  /**
113
120
  * @property status - The
package/src/Api/File.ts CHANGED
@@ -790,7 +790,7 @@ export class File {
790
790
  }
791
791
 
792
792
  /**
793
- * Creates a new file permission.
793
+ * Creates a new file permission for a user, project, or group.
794
794
  *
795
795
  * @example <caption>Grant the specified user permission to "update" the file.</caption>
796
796
  * const action = "update";
package/src/Api/IFile.ts CHANGED
@@ -21,16 +21,45 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
+ /**
25
+ * Defines the data status.
26
+ */
24
27
  export interface IFileDataStatus {
28
+ /**
29
+ * Data state. Can be `none`, `waiting`, `inprogress`, `done` or `failed`.
30
+ */
25
31
  state: string;
32
+
33
+ /**
34
+ * Unique ID of the data job.
35
+ */
26
36
  jobId?: string;
37
+
27
38
  jobUrl?: string;
28
39
  }
29
40
 
41
+ /**
42
+ * Defines the file status.
43
+ */
30
44
  export interface IFileStatus {
45
+ /**
46
+ * Status of geometry data of `vsfx` type.
47
+ */
31
48
  geometry: IFileDataStatus;
49
+
50
+ /**
51
+ * Status of geometry data of `gltf` type.
52
+ */
32
53
  geometryGltf: IFileDataStatus;
54
+
55
+ /**
56
+ * Status of the properties.
57
+ */
33
58
  properties: IFileDataStatus;
59
+
60
+ /**
61
+ * Status of the validation.
62
+ */
34
63
  validation: IFileDataStatus;
35
64
  }
36
65
 
@@ -74,11 +103,11 @@ export interface IFileVersionInfo {
74
103
  }
75
104
 
76
105
  /**
77
- * Defines the entity, that will have access to the file.
106
+ * Defines the entity, that will have access to the {@link File | file}.
78
107
  */
79
108
  export interface IGrantedTo {
80
109
  /**
81
- * The user entry that has access to the file.
110
+ * The user that has access to the file.
82
111
  */
83
112
  user?: {
84
113
  /**
@@ -93,7 +122,7 @@ export interface IGrantedTo {
93
122
  };
94
123
 
95
124
  /**
96
- * The project entry that has access to the file.
125
+ * The project that has access to the file.
97
126
  */
98
127
  project?: {
99
128
  /**
@@ -106,4 +135,24 @@ export interface IGrantedTo {
106
135
  */
107
136
  name: string;
108
137
  };
138
+
139
+ /**
140
+ * The group that has access to the file.
141
+ */
142
+ group?: {
143
+ /**
144
+ * Project ID.
145
+ */
146
+ projectId: string;
147
+
148
+ /**
149
+ * Group ID.
150
+ */
151
+ groupId: string;
152
+
153
+ /**
154
+ * Group name.
155
+ */
156
+ name: string;
157
+ };
109
158
  }
@@ -129,6 +129,17 @@ export class Permission {
129
129
  /**
130
130
  * Updates permission data on the server.
131
131
  *
132
+ * @example <caption>Update file permissions for the the specified project.</caption>
133
+ * const myFile = client.getFile(myFileId);
134
+ * const permissions = await myFile.getPermissions();
135
+ * const projectPermissions = permissions.filter((permission) =>
136
+ * permission.grantedTo.some((x) => x.project?.id === myProjectId)
137
+ * );
138
+ * const newActions = ["read", "readSourceFile", "update"];
139
+ * await Promise.allSettled(
140
+ * projectPermissions.map((permission) => permission.update({ newActions }))
141
+ * );
142
+ *
132
143
  * @param data - Raw permission data.
133
144
  */
134
145
  async update(data: any): Promise<this> {
@@ -26,6 +26,7 @@ import { IShortUserDesc } from "./IUser";
26
26
  import { Role } from "./Role";
27
27
  import { IRoleActions } from "./IRole";
28
28
  import { Member } from "./Member";
29
+ import { File } from "./File";
29
30
  import { userFullName, userInitials } from "./Utils";
30
31
 
31
32
  /**
@@ -387,7 +388,7 @@ export class Project {
387
388
  }
388
389
 
389
390
  /**
390
- * Add a user to the project to become a member and have permission to perform actions.
391
+ * Adds a user to the project to become a member and have permission to perform actions.
391
392
  *
392
393
  * @param userId - User ID.
393
394
  * @param role - Role name from the list of project {@link getRoles | roles}.
@@ -399,7 +400,7 @@ export class Project {
399
400
  }
400
401
 
401
402
  /**
402
- * Remove the specified member from a project.
403
+ * Removes the specified member from a project.
403
404
  *
404
405
  * @param memberId - Member ID.
405
406
  * @returns Returns the raw data of a deleted member.
@@ -480,4 +481,70 @@ export class Project {
480
481
  return items;
481
482
  });
482
483
  }
484
+
485
+ /**
486
+ * Returns a list of project models.
487
+ */
488
+ getModels(): Promise<File[]> {
489
+ return this.getFilesInformation()
490
+ .then((filesInformation) => filesInformation.map((item) => item.file.reference))
491
+ .then((ids) => {
492
+ const searchParams = new URLSearchParams();
493
+ searchParams.set("id", ids.join("|"));
494
+ return this.httpClient.get(`/files?${searchParams.toString()}`);
495
+ })
496
+ .then((response) => response.json())
497
+ .then((files) => files.result.map((data) => new File(data, this.httpClient)));
498
+ }
499
+
500
+ /**
501
+ * Adds a file to the project with specified permissions.
502
+ *
503
+ * To change file permissions for the project use {@link Permission.update | Permissions.update()}.
504
+ *
505
+ * @param fileId - File ID.
506
+ * @param actions - Actions are allowed to be performed on a file:
507
+ *
508
+ * - `read` - The ability to read file description, geometry data and properties.
509
+ * - `readSourceFile` - The ability to read source file.
510
+ * - `write` - The ability to modify file name, description and references.
511
+ * - `readViewpoint` - The ability to read file viewpoints.
512
+ * - `createViewpoint` - The ability to create file viewpoints.
513
+ *
514
+ * @param _public - Specifies whether all users have access to the file or not.
515
+ * @returns Returns a file instance added to the project.
516
+ */
517
+ async addModel(fileId: string, actions: string | string[], _public: boolean): Promise<File> {
518
+ const file = await this.httpClient
519
+ .get(`/files/${fileId}`)
520
+ .then((response) => response.json())
521
+ .then((data) => new File(data, this.httpClient));
522
+
523
+ const grantedTo = [{ project: { id: this.id, name: this.name } }];
524
+ await file.createPermission(actions, grantedTo, _public);
525
+
526
+ return file;
527
+ }
528
+
529
+ /**
530
+ * Removes the specified file from a project.
531
+ *
532
+ * @param fileId - File ID.
533
+ * @returns Returns a file instance removed from the project.
534
+ */
535
+ async removeModel(fileId: string): Promise<File> {
536
+ const file = await this.httpClient
537
+ .get(`/files/${fileId}`)
538
+ .then((response) => response.json())
539
+ .then((data) => new File(data, this.httpClient));
540
+
541
+ const permissions = await file.getPermissions();
542
+ await Promise.allSettled(
543
+ permissions
544
+ .filter((permission) => permission.grantedTo.some((x) => x.project?.id === this.id))
545
+ .map((permission) => permission.delete())
546
+ );
547
+
548
+ return file;
549
+ }
483
550
  }
package/src/index.ts CHANGED
@@ -30,7 +30,7 @@ export { FetchError, statusText } from "./Api/FetchError";
30
30
  export { Job } from "./Api/Job";
31
31
  export { IHttpClient } from "./Api/IHttpClient";
32
32
  export { IModelTransformMatrix } from "./Api/IAssembly";
33
- export { IGrantedTo } from "./Api/IFile";
33
+ export { IFileDataStatus, IFileReference, IFileReferences, IFileStatus, IGrantedTo } from "./Api/IFile";
34
34
  export { IRoleActions } from "./Api/IRole";
35
35
  export { IShortUserDesc } from "./Api/IUser";
36
36
  export { Member } from "./Api/Member";