@inweb/client 25.3.17 → 25.3.19

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 (45) hide show
  1. package/dist/client.js +698 -527
  2. package/dist/client.js.map +1 -1
  3. package/dist/client.min.js +1 -1
  4. package/dist/client.module.js +473 -484
  5. package/dist/client.module.js.map +1 -1
  6. package/lib/Api/Assembly.d.ts +32 -8
  7. package/lib/Api/ClashTest.d.ts +1 -1
  8. package/lib/Api/Client.d.ts +2 -3
  9. package/lib/Api/Fetch.d.ts +6 -0
  10. package/lib/Api/{impl/FetchError.d.ts → FetchError.d.ts} +2 -0
  11. package/lib/Api/File.d.ts +34 -10
  12. package/lib/Api/HttpClient.d.ts +9 -3
  13. package/lib/Api/IHttpClient.d.ts +10 -4
  14. package/lib/Api/Job.d.ts +1 -1
  15. package/lib/Api/Model.d.ts +33 -9
  16. package/lib/Api/Project.d.ts +3 -3
  17. package/lib/Api/User.d.ts +1 -1
  18. package/lib/Api/Utils.d.ts +11 -0
  19. package/lib/Api/XMLHttp.d.ts +7 -0
  20. package/lib/index.d.ts +1 -1
  21. package/package.json +2 -2
  22. package/src/Api/Assembly.ts +76 -70
  23. package/src/Api/ClashTest.ts +10 -19
  24. package/src/Api/Client.ts +92 -56
  25. package/src/Api/Fetch.ts +84 -0
  26. package/src/Api/{impl/http.ts → FetchError.ts} +33 -1
  27. package/src/Api/File.ts +112 -117
  28. package/src/Api/HttpClient.ts +108 -20
  29. package/src/Api/IHttpClient.ts +18 -12
  30. package/src/Api/Job.ts +7 -5
  31. package/src/Api/Member.ts +7 -5
  32. package/src/Api/Model.ts +61 -14
  33. package/src/Api/Permission.ts +6 -5
  34. package/src/Api/Project.ts +93 -88
  35. package/src/Api/Role.ts +6 -5
  36. package/src/Api/User.ts +28 -17
  37. package/src/Api/Utils.ts +104 -0
  38. package/src/Api/XMLHttp.ts +72 -0
  39. package/src/index.ts +1 -1
  40. package/lib/Api/impl/Utils.d.ts +0 -32
  41. package/lib/Api/impl/http.d.ts +0 -66
  42. package/lib/ConvetMath.d.ts +0 -28
  43. package/src/Api/impl/FetchError.ts +0 -48
  44. package/src/Api/impl/Utils.ts +0 -367
  45. package/src/ConvetMath.ts +0 -372
@@ -23,7 +23,7 @@
23
23
 
24
24
  import { IHttpClient } from "./IHttpClient";
25
25
  import { IShortUserDescription } from "./IUser";
26
- import { waitFor, userFullName, userInitials } from "./impl/Utils";
26
+ import { waitFor, userFullName, userInitials } from "./Utils";
27
27
 
28
28
  /**
29
29
  * The base class provides information about the file/assembly clash detection test and test results.
@@ -48,10 +48,7 @@ export class ClashTest {
48
48
  return this.httpClient.get(`${this.basePath}/clashes/${this.id}${relativePath}`);
49
49
  }
50
50
 
51
- protected internalPut(
52
- relativePath: string,
53
- body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
54
- ): Promise<any> {
51
+ protected internalPut(relativePath: string, body?: BodyInit | object): Promise<any> {
55
52
  return this.httpClient.put(`${this.basePath}/clashes/${this.id}${relativePath}`, body);
56
53
  }
57
54
 
@@ -217,13 +214,10 @@ export class ClashTest {
217
214
  *
218
215
  * @async
219
216
  */
220
- checkout(): Promise<this> {
221
- return this.internalGet("")
222
- .then((response) => response.json())
223
- .then((data) => {
224
- this.data = data;
225
- return this;
226
- });
217
+ async checkout(): Promise<this> {
218
+ const response = await this.internalGet("");
219
+ this.data = await response.json();
220
+ return this;
227
221
  }
228
222
 
229
223
  /**
@@ -232,13 +226,10 @@ export class ClashTest {
232
226
  * @async
233
227
  * @param data - Raw test data.
234
228
  */
235
- update(data: any): Promise<this> {
236
- return this.internalPut("", data)
237
- .then((response) => response.json())
238
- .then((data) => {
239
- this.data = data;
240
- return this;
241
- });
229
+ async update(data: any): Promise<this> {
230
+ const response = await this.internalPut("", data);
231
+ this.data = await response.json();
232
+ return this;
242
233
  }
243
234
 
244
235
  /**
package/src/Api/Client.ts CHANGED
@@ -31,7 +31,7 @@ import { File } from "./File";
31
31
  import { Job } from "./Job";
32
32
  import { Project } from "./Project";
33
33
  import { User } from "./User";
34
- import { downloadProgress, json, text, parseArgs } from "./impl/Utils";
34
+ import { parseArgs } from "./Utils";
35
35
 
36
36
  /**
37
37
  * The `Client.js` library class that provides methods to access the [Open Cloud
@@ -58,7 +58,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
58
58
  }
59
59
 
60
60
  /**
61
- * Open Cloud Server URL. Use {@link Client#configure | configure()} to change server URL.
61
+ * Open Cloud Server URL. Use {@link Client.configure()} to change server URL.
62
62
  *
63
63
  * @readonly
64
64
  */
@@ -67,8 +67,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
67
67
  }
68
68
 
69
69
  /**
70
- * Deprecated since `25.3`. Use [Viewer.options]{@link Viewer#options} instead to change
71
- * Viewer parameters.
70
+ * Deprecated since `25.3`. Use {@link Viewer.options()} instead to change Viewer parameters.
72
71
  */
73
72
  get options(): any {
74
73
  console.warn(
@@ -204,7 +203,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
204
203
  async signInWithEmail(email: string, password: string): Promise<User> {
205
204
  const credentials = btoa(unescape(encodeURIComponent(email + ":" + password)));
206
205
  this._httpClient.headers = { Authorization: "Basic " + credentials };
207
- const data = await json(this._httpClient.get("/token"));
206
+ const response = await this._httpClient.get("/token");
207
+ const data = await response.json();
208
208
  return this.setCurrentUser(data);
209
209
  }
210
210
 
@@ -217,7 +217,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
217
217
  */
218
218
  async signInWithToken(token: string): Promise<User> {
219
219
  this._httpClient.headers = { Authorization: token };
220
- const data = await json(this._httpClient.get("/user"));
220
+ const response = await this._httpClient.get("/user");
221
+ const data = await response.json();
221
222
  return this.setCurrentUser(data);
222
223
  }
223
224
 
@@ -252,7 +253,9 @@ export class Client extends EventEmitter2<ClientEventMap> {
252
253
  * @async
253
254
  */
254
255
  getUsers(): Promise<User[]> {
255
- return json(this._httpClient.get("/users"))
256
+ return this._httpClient
257
+ .get("/users")
258
+ .then((response) => response.json())
256
259
  .then((array) => array.map((data) => ({ id: data.id, ...data.userBrief })))
257
260
  .then((array) => array.map((data) => new User(data, this._httpClient)));
258
261
  }
@@ -267,11 +270,15 @@ export class Client extends EventEmitter2<ClientEventMap> {
267
270
  */
268
271
  getUser(userId: string): Promise<User> {
269
272
  if (userId === this._httpClient.signInUserId) {
270
- return json(this._httpClient.get("/user"))
273
+ return this._httpClient
274
+ .get("/user")
275
+ .then((response) => response.json())
271
276
  .then((data) => ({ id: userId, ...data }))
272
277
  .then((data) => new User(data, this._httpClient));
273
278
  } else {
274
- return json(this._httpClient.get(`/users/${userId}`))
279
+ return this._httpClient
280
+ .get(`/users/${userId}`)
281
+ .then((response) => response.json())
275
282
  .then((data) => ({ id: data.id, ...data.userBrief }))
276
283
  .then((data) => new User(data, this._httpClient));
277
284
  }
@@ -309,8 +316,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
309
316
  } = {}
310
317
  ): Promise<User> {
311
318
  const { isAdmin, userName, ...rest } = params;
312
- return json(
313
- this._httpClient.post("/users", {
319
+ return this._httpClient
320
+ .post("/users", {
314
321
  isAdmin,
315
322
  userBrief: {
316
323
  ...rest,
@@ -319,7 +326,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
319
326
  },
320
327
  password,
321
328
  })
322
- )
329
+ .then((response) => response.json())
323
330
  .then((data) => ({ id: data.id, ...data.userBrief }))
324
331
  .then((data) => new User(data, this._httpClient));
325
332
  }
@@ -338,12 +345,15 @@ export class Client extends EventEmitter2<ClientEventMap> {
338
345
  * @returns Returns the raw data of a deleted user.
339
346
  */
340
347
  deleteUser(userId: string): Promise<any> {
341
- return json(this._httpClient.delete(`/users/${userId}`)).then((data) => {
342
- if (userId === this._httpClient.signInUserId) {
343
- this.clearCurrentUser();
344
- }
345
- return data;
346
- });
348
+ return this._httpClient
349
+ .delete(`/users/${userId}`)
350
+ .then((response) => response.json())
351
+ .then((data) => {
352
+ if (userId === this._httpClient.signInUserId) {
353
+ this.clearCurrentUser();
354
+ }
355
+ return data;
356
+ });
347
357
  }
348
358
 
349
359
  /**
@@ -402,12 +412,15 @@ export class Client extends EventEmitter2<ClientEventMap> {
402
412
  let queryString = searchParams.toString();
403
413
  if (queryString) queryString = "?" + queryString;
404
414
 
405
- return json(this._httpClient.get(`/files${queryString}`)).then((files) => {
406
- return {
407
- ...files,
408
- result: files.result.map((data) => new File(data, this._httpClient)),
409
- };
410
- });
415
+ return this._httpClient
416
+ .get(`/files${queryString}`)
417
+ .then((response) => response.json())
418
+ .then((files) => {
419
+ return {
420
+ ...files,
421
+ result: files.result.map((data) => new File(data, this._httpClient)),
422
+ };
423
+ });
411
424
  }
412
425
 
413
426
  /**
@@ -417,7 +430,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
417
430
  * @param fileId - File ID.
418
431
  */
419
432
  getFile(fileId: string): Promise<File> {
420
- return json(this._httpClient.get(`/files/${fileId}`)).then((data) => new File(data, this._httpClient));
433
+ return this._httpClient
434
+ .get(`/files/${fileId}`)
435
+ .then((response) => response.json())
436
+ .then((data) => new File(data, this._httpClient));
421
437
  }
422
438
 
423
439
  /**
@@ -467,7 +483,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
467
483
  }
468
484
  ): Promise<File> {
469
485
  const result = await this._httpClient
470
- .postFile("/files", file, (progress) => {
486
+ .uploadFile("/files", file, (progress) => {
471
487
  this.emitEvent({ type: "uploadprogress", data: progress, file });
472
488
  params.onProgress?.(progress, file);
473
489
  })
@@ -492,7 +508,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
492
508
  * @returns Returns the raw data of a deleted file.
493
509
  */
494
510
  deleteFile(fileId: string): Promise<any> {
495
- return json(this._httpClient.delete(`/files/${fileId}`));
511
+ return this._httpClient.delete(`/files/${fileId}`).then((response) => response.json());
496
512
  }
497
513
 
498
514
  /**
@@ -507,8 +523,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
507
523
  */
508
524
  downloadFile(fileId: string, onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer> {
509
525
  return this._httpClient
510
- .get(`/files/${fileId}/downloads`, signal)
511
- .then((response) => downloadProgress(response, onProgress))
526
+ .downloadFile(`/files/${fileId}/downloads`, onProgress, signal)
512
527
  .then((response) => response.arrayBuffer());
513
528
  }
514
529
 
@@ -556,10 +571,13 @@ export class Client extends EventEmitter2<ClientEventMap> {
556
571
  let queryString = searchParams.toString();
557
572
  if (queryString) queryString = "?" + queryString;
558
573
 
559
- return json(this._httpClient.get(`/jobs${queryString}`)).then((jobs) => ({
560
- ...jobs,
561
- result: jobs.result.map((data) => new Job(data, this._httpClient)),
562
- }));
574
+ return this._httpClient
575
+ .get(`/jobs${queryString}`)
576
+ .then((response) => response.json())
577
+ .then((jobs) => ({
578
+ ...jobs,
579
+ result: jobs.result.map((data) => new Job(data, this._httpClient)),
580
+ }));
563
581
  }
564
582
 
565
583
  /**
@@ -569,7 +587,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
569
587
  * @param jobId - Job ID.
570
588
  */
571
589
  getJob(jobId: string): Promise<Job> {
572
- return json(this._httpClient.get(`/jobs/${jobId}`)).then((data) => new Job(data, this._httpClient));
590
+ return this._httpClient
591
+ .get(`/jobs/${jobId}`)
592
+ .then((response) => response.json())
593
+ .then((data) => new Job(data, this._httpClient));
573
594
  }
574
595
 
575
596
  /**
@@ -610,7 +631,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
610
631
  * @returns Returns the raw data of a deleted job.
611
632
  */
612
633
  deleteJob(jobId: string): Promise<any> {
613
- return json(this._httpClient.delete(`/jobs/${jobId}`));
634
+ return this._httpClient.delete(`/jobs/${jobId}`).then((response) => response.json());
614
635
  }
615
636
 
616
637
  /**
@@ -661,12 +682,15 @@ export class Client extends EventEmitter2<ClientEventMap> {
661
682
  let queryString = searchParams.toString();
662
683
  if (queryString) queryString = "?" + queryString;
663
684
 
664
- return json(this._httpClient.get(`/assemblies${queryString}`)).then((assemblies) => {
665
- return {
666
- ...assemblies,
667
- result: assemblies.result.map((data) => new Assembly(data, this._httpClient)),
668
- };
669
- });
685
+ return this._httpClient
686
+ .get(`/assemblies${queryString}`)
687
+ .then((response) => response.json())
688
+ .then((assemblies) => {
689
+ return {
690
+ ...assemblies,
691
+ result: assemblies.result.map((data) => new Assembly(data, this._httpClient)),
692
+ };
693
+ });
670
694
  }
671
695
 
672
696
  /**
@@ -676,7 +700,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
676
700
  * @param assemblyId - Assembly ID.
677
701
  */
678
702
  getAssembly(assemblyId: string): Promise<Assembly> {
679
- return json(this._httpClient.get(`/assemblies/${assemblyId}`)).then((data) => new Assembly(data, this._httpClient));
703
+ return this._httpClient
704
+ .get(`/assemblies/${assemblyId}`)
705
+ .then((response) => response.json())
706
+ .then((data) => new Assembly(data, this._httpClient));
680
707
  }
681
708
 
682
709
  /**
@@ -714,7 +741,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
714
741
  * @returns Returns the raw data of a deleted assembly.
715
742
  */
716
743
  deleteAssembly(assemblyId: string): Promise<any> {
717
- return json(this._httpClient.delete(`/assemblies/${assemblyId}`));
744
+ return this._httpClient.delete(`/assemblies/${assemblyId}`).then((response) => response.json());
718
745
  }
719
746
 
720
747
  /**
@@ -760,7 +787,9 @@ export class Client extends EventEmitter2<ClientEventMap> {
760
787
 
761
788
  let queryString = searchParams.toString();
762
789
  if (queryString) queryString = "?" + queryString;
763
- return json(this._httpClient.get(`/projects${queryString}`))
790
+ return this._httpClient
791
+ .get(`/projects${queryString}`)
792
+ .then((response) => response.json())
764
793
  .then((projects) => {
765
794
  // fix for server 23.5 and below
766
795
  if (Array.isArray(projects)) {
@@ -796,7 +825,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
796
825
  * @param projectId - Project ID.
797
826
  */
798
827
  getProject(projectId: string): Promise<Project> {
799
- return json(this._httpClient.get(`/projects/${projectId}`)).then((data) => new Project(data, this._httpClient));
828
+ return this._httpClient
829
+ .get(`/projects/${projectId}`)
830
+ .then((response) => response.json())
831
+ .then((data) => new Project(data, this._httpClient));
800
832
  }
801
833
 
802
834
  /**
@@ -818,15 +850,16 @@ export class Client extends EventEmitter2<ClientEventMap> {
818
850
  endDate?: Date | string,
819
851
  avatarUrl?: string
820
852
  ): Promise<Project> {
821
- return json(
822
- this._httpClient.post("/projects", {
853
+ return this._httpClient
854
+ .post("/projects", {
823
855
  name,
824
856
  description,
825
857
  startDate: startDate instanceof Date ? startDate.toISOString() : startDate,
826
858
  endDate: endDate instanceof Date ? endDate.toISOString() : endDate,
827
859
  avatarUrl,
828
860
  })
829
- ).then((data) => new Project(data, this._httpClient));
861
+ .then((response) => response.json())
862
+ .then((data) => new Project(data, this._httpClient));
830
863
  }
831
864
 
832
865
  /**
@@ -837,13 +870,16 @@ export class Client extends EventEmitter2<ClientEventMap> {
837
870
  * @returns Returns the raw data of a deleted project.
838
871
  */
839
872
  deleteProject(projectId: string): Promise<any> {
840
- return text(this._httpClient.delete(`/projects/${projectId}`)).then((text) => {
841
- // fix for server 23.5 and below
842
- try {
843
- return JSON.parse(text);
844
- } catch {
845
- return { id: projectId };
846
- }
847
- });
873
+ return this._httpClient
874
+ .delete(`/projects/${projectId}`)
875
+ .then((response) => response.text())
876
+ .then((text) => {
877
+ // fix for server 23.5 and below
878
+ try {
879
+ return JSON.parse(text);
880
+ } catch {
881
+ return { id: projectId };
882
+ }
883
+ });
848
884
  }
849
885
  }
@@ -0,0 +1,84 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { FetchError, statusText, error400 } from "./FetchError";
25
+
26
+ function handleFetchError(response: Response): Promise<Response> {
27
+ if (!response.ok) {
28
+ switch (response.status) {
29
+ case 400: {
30
+ return response.text().then((text) => {
31
+ console.error(text);
32
+ return Promise.reject(new FetchError(400, error400(text)));
33
+ });
34
+ }
35
+ case 500: {
36
+ return response.text().then((text) => {
37
+ console.error(error400(text, text));
38
+ return Promise.reject(new FetchError(500));
39
+ });
40
+ }
41
+ default:
42
+ return Promise.reject(new FetchError(response.status, statusText(response.status)));
43
+ }
44
+ }
45
+ return Promise.resolve(response);
46
+ }
47
+
48
+ export function $fetch(
49
+ url: string,
50
+ params: {
51
+ method: "GET" | "POST" | "PUT" | "DELETE";
52
+ headers?: HeadersInit;
53
+ body?: BodyInit | object;
54
+ signal?: AbortSignal;
55
+ } = { method: "GET" }
56
+ ): Promise<Response> {
57
+ const headers = { ...params.headers };
58
+ delete headers["Content-Type"];
59
+
60
+ let body: FormData | string;
61
+ if (params.method === "POST" || params.method === "PUT") {
62
+ if (params.body instanceof FormData) {
63
+ body = params.body;
64
+ } else if (params.body instanceof Blob) {
65
+ body = new FormData();
66
+ body.append("file", params.body);
67
+ } else if (params.body instanceof ArrayBuffer) {
68
+ body = new FormData();
69
+ body.append("file", new Blob([params.body]));
70
+ } else if (typeof params.body === "object") {
71
+ body = JSON.stringify(params.body);
72
+ headers["Content-Type"] = "application/json";
73
+ } else if (typeof params.body === "string") {
74
+ body = params.body;
75
+ headers["Content-Type"] = "text/plain";
76
+ }
77
+ }
78
+
79
+ const init: RequestInit = { method: params.method, headers };
80
+ if (body) init.body = body;
81
+ if (params.signal) init.signal = params.signal;
82
+
83
+ return fetch(url, init).then(handleFetchError);
84
+ }
@@ -21,7 +21,7 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- export const STATUS_CODES = {
24
+ const STATUS_CODES = {
25
25
  100: "Continue",
26
26
  101: "Switching Protocols",
27
27
  102: "Processing",
@@ -90,3 +90,35 @@ export const STATUS_CODES = {
90
90
  export function statusText(status: number): string {
91
91
  return STATUS_CODES[status] || `Error ${status}`;
92
92
  }
93
+
94
+ export function error400(text: string, _default = "400") {
95
+ try {
96
+ return JSON.parse(text).description;
97
+ } catch {
98
+ return _default;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * The `FetchError` object indicates an error when request to Open Cloud Server could not be
104
+ * performed. A `FetchError` is typically (but not exclusively) thrown when a network error
105
+ * occurs, access denied, or object not found.
106
+ */
107
+
108
+ export class FetchError extends Error {
109
+ protected status: number;
110
+ protected statusText: string;
111
+
112
+ /**
113
+ * @property status - The <a href="https://developer.mozilla.org/docs/Web/HTTP/Status" target
114
+ * ="_blank">HTTP status code</a> of the response.
115
+ * @property message - Error message. Inherited from <a
116
+ * href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error"
117
+ * target ="_blank">Error</a>.
118
+ */
119
+ constructor(status: number, message?: string) {
120
+ super(message || statusText(status));
121
+ this.status = status;
122
+ this.statusText = statusText(status);
123
+ }
124
+ }