@inweb/client 25.4.2 → 25.4.4

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.
package/src/Api/Client.ts CHANGED
@@ -40,7 +40,7 @@ import { parseArgs } from "./Utils";
40
40
  */
41
41
  export class Client extends EventEmitter2<ClientEventMap> {
42
42
  private _serverUrl = "";
43
- private _httpClient: IHttpClient = new HttpClient("");
43
+ public httpClient: IHttpClient = new HttpClient("");
44
44
  private _user: User | null = null;
45
45
  public eventEmitter: EventEmitter2 = this;
46
46
 
@@ -114,7 +114,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
114
114
  */
115
115
  configure(params: { serverUrl?: string }): this {
116
116
  this._serverUrl = (params.serverUrl || "").replace(/\/+$/, "");
117
- this._httpClient = new HttpClient(this.serverUrl);
117
+ this.httpClient = new HttpClient(this.serverUrl);
118
118
  this._user = null;
119
119
  return this;
120
120
  }
@@ -133,7 +133,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
133
133
  * @async
134
134
  */
135
135
  version(): Promise<any> {
136
- return this._httpClient
136
+ return this.httpClient
137
137
  .get("/version")
138
138
  .then((response) => response.json())
139
139
  .then((data) => ({
@@ -154,7 +154,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
154
154
  * `username` from email.
155
155
  */
156
156
  registerUser(email: string, password: string, userName?: string): Promise<any> {
157
- return this._httpClient
157
+ return this.httpClient
158
158
  .post("/register", {
159
159
  email,
160
160
  password,
@@ -172,7 +172,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
172
172
  * @param password - User password.
173
173
  */
174
174
  resendConfirmationEmail(email: string, password: string): Promise<any> {
175
- return this._httpClient
175
+ return this.httpClient
176
176
  .post("/register/email-confirmation", { email, password })
177
177
  .then((response) => response.json());
178
178
  }
@@ -184,7 +184,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
184
184
  * @param emailConfirmationId - Confirmation code from the Confirmation Email.
185
185
  */
186
186
  confirmUserEmail(emailConfirmationId: string): Promise<any> {
187
- return this._httpClient
187
+ return this.httpClient
188
188
  .get(`/register/email-confirmation/${emailConfirmationId}`)
189
189
  .then((response) => response.json());
190
190
  }
@@ -198,8 +198,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
198
198
  */
199
199
  async signInWithEmail(email: string, password: string): Promise<User> {
200
200
  const credentials = btoa(unescape(encodeURIComponent(email + ":" + password)));
201
- this._httpClient.headers = { Authorization: "Basic " + credentials };
202
- const response = await this._httpClient.get("/token");
201
+ this.httpClient.headers = { Authorization: "Basic " + credentials };
202
+ const response = await this.httpClient.get("/token");
203
203
  const data = await response.json();
204
204
  return this.setCurrentUser(data);
205
205
  }
@@ -211,8 +211,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
211
211
  * @param token - An access token for authentication request. See {@link User.token} for more details.
212
212
  */
213
213
  async signInWithToken(token: string): Promise<User> {
214
- this._httpClient.headers = { Authorization: token };
215
- const response = await this._httpClient.get("/user");
214
+ this.httpClient.headers = { Authorization: token };
215
+ const response = await this.httpClient.get("/user");
216
216
  const data = await response.json();
217
217
  return this.setCurrentUser(data);
218
218
  }
@@ -225,24 +225,26 @@ export class Client extends EventEmitter2<ClientEventMap> {
225
225
  * - Open the `provider.url` link using `window.open()`.
226
226
  * - Add a `/oauth` path (server-defined) handler to the router. In this handler, show an error
227
227
  * message if the `error` search parameter is present, or log in with the `token` search parameter.
228
+ *
229
+ * @async
228
230
  */
229
231
  getIdentityProviders(): Promise<any> {
230
- return this._httpClient.get("/identity").then((response) => response.json());
232
+ return this.httpClient.get("/identity").then((response) => response.json());
231
233
  }
232
234
 
233
235
  // Save the current logged in user information for internal use.
234
236
 
235
237
  private setCurrentUser(data: any): User {
236
- this._user = new User(data, this._httpClient);
237
- this._httpClient.headers = { Authorization: data.tokenInfo.token };
238
- this._httpClient.signInUserId = this._user.id;
238
+ this._user = new User(data, this.httpClient);
239
+ this.httpClient.headers = { Authorization: data.tokenInfo.token };
240
+ this.httpClient.signInUserId = this._user.id;
239
241
  return this._user;
240
242
  }
241
243
 
242
244
  private clearCurrentUser(): void {
243
245
  this._user = null;
244
- this._httpClient.headers = {};
245
- this._httpClient.signInUserId = "";
246
+ this.httpClient.headers = {};
247
+ this.httpClient.signInUserId = "";
246
248
  }
247
249
 
248
250
  /**
@@ -250,7 +252,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
250
252
  * in or the logged in user has deleted himself.
251
253
  */
252
254
  getCurrentUser(): User | null {
253
- if (this._user && !this._httpClient.signInUserId) this._user = null;
255
+ if (this._user && !this.httpClient.signInUserId) this._user = null;
254
256
  return this._user;
255
257
  }
256
258
 
@@ -261,11 +263,11 @@ export class Client extends EventEmitter2<ClientEventMap> {
261
263
  * @async
262
264
  */
263
265
  getUsers(): Promise<User[]> {
264
- return this._httpClient
266
+ return this.httpClient
265
267
  .get("/users")
266
268
  .then((response) => response.json())
267
269
  .then((array) => array.map((data) => ({ id: data.id, ...data.userBrief })))
268
- .then((array) => array.map((data) => new User(data, this._httpClient)));
270
+ .then((array) => array.map((data) => new User(data, this.httpClient)));
269
271
  }
270
272
 
271
273
  /**
@@ -277,18 +279,18 @@ export class Client extends EventEmitter2<ClientEventMap> {
277
279
  * @param userId - User ID.
278
280
  */
279
281
  getUser(userId: string): Promise<User> {
280
- if (userId === this._httpClient.signInUserId) {
281
- return this._httpClient
282
+ if (userId === this.httpClient.signInUserId) {
283
+ return this.httpClient
282
284
  .get("/user")
283
285
  .then((response) => response.json())
284
286
  .then((data) => ({ id: userId, ...data }))
285
- .then((data) => new User(data, this._httpClient));
287
+ .then((data) => new User(data, this.httpClient));
286
288
  } else {
287
- return this._httpClient
289
+ return this.httpClient
288
290
  .get(`/users/${userId}`)
289
291
  .then((response) => response.json())
290
292
  .then((data) => ({ id: data.id, ...data.userBrief }))
291
- .then((data) => new User(data, this._httpClient));
293
+ .then((data) => new User(data, this.httpClient));
292
294
  }
293
295
  }
294
296
 
@@ -324,7 +326,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
324
326
  } = {}
325
327
  ): Promise<User> {
326
328
  const { isAdmin, userName, ...rest } = params;
327
- return this._httpClient
329
+ return this.httpClient
328
330
  .post("/users", {
329
331
  isAdmin,
330
332
  userBrief: {
@@ -336,7 +338,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
336
338
  })
337
339
  .then((response) => response.json())
338
340
  .then((data) => ({ id: data.id, ...data.userBrief }))
339
- .then((data) => new User(data, this._httpClient));
341
+ .then((data) => new User(data, this.httpClient));
340
342
  }
341
343
 
342
344
  /**
@@ -353,11 +355,11 @@ export class Client extends EventEmitter2<ClientEventMap> {
353
355
  * @returns Returns the raw data of a deleted user.
354
356
  */
355
357
  deleteUser(userId: string): Promise<any> {
356
- return this._httpClient
358
+ return this.httpClient
357
359
  .delete(`/users/${userId}`)
358
360
  .then((response) => response.json())
359
361
  .then((data) => {
360
- if (userId === this._httpClient.signInUserId) {
362
+ if (userId === this.httpClient.signInUserId) {
361
363
  this.clearCurrentUser();
362
364
  }
363
365
  return data;
@@ -420,13 +422,13 @@ export class Client extends EventEmitter2<ClientEventMap> {
420
422
  let queryString = searchParams.toString();
421
423
  if (queryString) queryString = "?" + queryString;
422
424
 
423
- return this._httpClient
425
+ return this.httpClient
424
426
  .get(`/files${queryString}`)
425
427
  .then((response) => response.json())
426
428
  .then((files) => {
427
429
  return {
428
430
  ...files,
429
- result: files.result.map((data) => new File(data, this._httpClient)),
431
+ result: files.result.map((data) => new File(data, this.httpClient)),
430
432
  };
431
433
  });
432
434
  }
@@ -438,10 +440,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
438
440
  * @param fileId - File ID.
439
441
  */
440
442
  getFile(fileId: string): Promise<File> {
441
- return this._httpClient
443
+ return this.httpClient
442
444
  .get(`/files/${fileId}`)
443
445
  .then((response) => response.json())
444
- .then((data) => new File(data, this._httpClient));
446
+ .then((data) => new File(data, this.httpClient));
445
447
  }
446
448
 
447
449
  /**
@@ -490,13 +492,13 @@ export class Client extends EventEmitter2<ClientEventMap> {
490
492
  waitForDone: false,
491
493
  }
492
494
  ): Promise<File> {
493
- const result = await this._httpClient
495
+ const result = await this.httpClient
494
496
  .uploadFile("/files", file, (progress) => {
495
497
  this.emitEvent({ type: "uploadprogress", data: progress, file });
496
498
  params.onProgress?.(progress, file);
497
499
  })
498
500
  .then((xhr: XMLHttpRequest) => JSON.parse(xhr.responseText))
499
- .then((data) => new File(data, this._httpClient));
501
+ .then((data) => new File(data, this.httpClient));
500
502
 
501
503
  const geometryType = typeof params.geometry === "string" ? params.geometry : "vsfx";
502
504
 
@@ -518,7 +520,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
518
520
  * @returns Returns the raw data of a deleted file.
519
521
  */
520
522
  deleteFile(fileId: string): Promise<any> {
521
- return this._httpClient.delete(`/files/${fileId}`).then((response) => response.json());
523
+ return this.httpClient.delete(`/files/${fileId}`).then((response) => response.json());
522
524
  }
523
525
 
524
526
  /**
@@ -532,7 +534,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
532
534
  * and abort it if desired.
533
535
  */
534
536
  downloadFile(fileId: string, onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer> {
535
- return this._httpClient
537
+ return this.httpClient
536
538
  .downloadFile(`/files/${fileId}/downloads`, onProgress, signal)
537
539
  .then((response) => response.arrayBuffer());
538
540
  }
@@ -581,12 +583,12 @@ export class Client extends EventEmitter2<ClientEventMap> {
581
583
  let queryString = searchParams.toString();
582
584
  if (queryString) queryString = "?" + queryString;
583
585
 
584
- return this._httpClient
586
+ return this.httpClient
585
587
  .get(`/jobs${queryString}`)
586
588
  .then((response) => response.json())
587
589
  .then((jobs) => ({
588
590
  ...jobs,
589
- result: jobs.result.map((data) => new Job(data, this._httpClient)),
591
+ result: jobs.result.map((data) => new Job(data, this.httpClient)),
590
592
  }));
591
593
  }
592
594
 
@@ -597,10 +599,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
597
599
  * @param jobId - Job ID.
598
600
  */
599
601
  getJob(jobId: string): Promise<Job> {
600
- return this._httpClient
602
+ return this.httpClient
601
603
  .get(`/jobs/${jobId}`)
602
604
  .then((response) => response.json())
603
- .then((data) => new Job(data, this._httpClient));
605
+ .then((data) => new Job(data, this.httpClient));
604
606
  }
605
607
 
606
608
  /**
@@ -622,14 +624,14 @@ export class Client extends EventEmitter2<ClientEventMap> {
622
624
  * for the File Converter tool in form "--arg=value".
623
625
  */
624
626
  createJob(fileId: string, outputFormat: string, parameters?: string | object): Promise<Job> {
625
- return this._httpClient
627
+ return this.httpClient
626
628
  .post("/jobs", {
627
629
  fileId,
628
630
  outputFormat,
629
631
  parameters: parseArgs(parameters),
630
632
  })
631
633
  .then((response) => response.json())
632
- .then((data) => new Job(data, this._httpClient));
634
+ .then((data) => new Job(data, this.httpClient));
633
635
  }
634
636
 
635
637
  /**
@@ -641,7 +643,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
641
643
  * @returns Returns the raw data of a deleted job.
642
644
  */
643
645
  deleteJob(jobId: string): Promise<any> {
644
- return this._httpClient.delete(`/jobs/${jobId}`).then((response) => response.json());
646
+ return this.httpClient.delete(`/jobs/${jobId}`).then((response) => response.json());
645
647
  }
646
648
 
647
649
  /**
@@ -692,13 +694,13 @@ export class Client extends EventEmitter2<ClientEventMap> {
692
694
  let queryString = searchParams.toString();
693
695
  if (queryString) queryString = "?" + queryString;
694
696
 
695
- return this._httpClient
697
+ return this.httpClient
696
698
  .get(`/assemblies${queryString}`)
697
699
  .then((response) => response.json())
698
700
  .then((assemblies) => {
699
701
  return {
700
702
  ...assemblies,
701
- result: assemblies.result.map((data) => new Assembly(data, this._httpClient)),
703
+ result: assemblies.result.map((data) => new Assembly(data, this.httpClient)),
702
704
  };
703
705
  });
704
706
  }
@@ -710,10 +712,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
710
712
  * @param assemblyId - Assembly ID.
711
713
  */
712
714
  getAssembly(assemblyId: string): Promise<Assembly> {
713
- return this._httpClient
715
+ return this.httpClient
714
716
  .get(`/assemblies/${assemblyId}`)
715
717
  .then((response) => response.json())
716
- .then((data) => new Assembly(data, this._httpClient));
718
+ .then((data) => new Assembly(data, this.httpClient));
717
719
  }
718
720
 
719
721
  /**
@@ -736,10 +738,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
736
738
  }
737
739
  ): Promise<Assembly> {
738
740
  const { waitForDone } = params ?? {};
739
- return this._httpClient
741
+ return this.httpClient
740
742
  .post("/assemblies", { name, files })
741
743
  .then((response) => response.json())
742
- .then((data) => new Assembly(data, this._httpClient))
744
+ .then((data) => new Assembly(data, this.httpClient))
743
745
  .then((result) => (waitForDone ? result.waitForDone(params) : result));
744
746
  }
745
747
 
@@ -751,7 +753,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
751
753
  * @returns Returns the raw data of a deleted assembly.
752
754
  */
753
755
  deleteAssembly(assemblyId: string): Promise<any> {
754
- return this._httpClient.delete(`/assemblies/${assemblyId}`).then((response) => response.json());
756
+ return this.httpClient.delete(`/assemblies/${assemblyId}`).then((response) => response.json());
755
757
  }
756
758
 
757
759
  /**
@@ -797,7 +799,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
797
799
 
798
800
  let queryString = searchParams.toString();
799
801
  if (queryString) queryString = "?" + queryString;
800
- return this._httpClient
802
+ return this.httpClient
801
803
  .get(`/projects${queryString}`)
802
804
  .then((response) => response.json())
803
805
  .then((projects) => {
@@ -823,7 +825,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
823
825
  .then((projects) => {
824
826
  return {
825
827
  ...projects,
826
- result: projects.result.map((data) => new Project(data, this._httpClient)),
828
+ result: projects.result.map((data) => new Project(data, this.httpClient)),
827
829
  };
828
830
  });
829
831
  }
@@ -835,10 +837,10 @@ export class Client extends EventEmitter2<ClientEventMap> {
835
837
  * @param projectId - Project ID.
836
838
  */
837
839
  getProject(projectId: string): Promise<Project> {
838
- return this._httpClient
840
+ return this.httpClient
839
841
  .get(`/projects/${projectId}`)
840
842
  .then((response) => response.json())
841
- .then((data) => new Project(data, this._httpClient));
843
+ .then((data) => new Project(data, this.httpClient));
842
844
  }
843
845
 
844
846
  /**
@@ -860,7 +862,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
860
862
  endDate?: Date | string,
861
863
  avatarUrl?: string
862
864
  ): Promise<Project> {
863
- return this._httpClient
865
+ return this.httpClient
864
866
  .post("/projects", {
865
867
  name,
866
868
  description,
@@ -869,7 +871,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
869
871
  avatarUrl,
870
872
  })
871
873
  .then((response) => response.json())
872
- .then((data) => new Project(data, this._httpClient));
874
+ .then((data) => new Project(data, this.httpClient));
873
875
  }
874
876
 
875
877
  /**
@@ -880,7 +882,7 @@ export class Client extends EventEmitter2<ClientEventMap> {
880
882
  * @returns Returns the raw data of a deleted project.
881
883
  */
882
884
  deleteProject(projectId: string): Promise<any> {
883
- return this._httpClient
885
+ return this.httpClient
884
886
  .delete(`/projects/${projectId}`)
885
887
  .then((response) => response.text())
886
888
  .then((text) => {
package/src/Api/Fetch.ts CHANGED
@@ -21,7 +21,7 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { FetchError, statusText, error400 } from "./FetchError";
24
+ import { FetchError, error400 } from "./FetchError";
25
25
 
26
26
  function handleFetchError(response: Response): Promise<Response> {
27
27
  if (!response.ok) {
@@ -39,7 +39,7 @@ function handleFetchError(response: Response): Promise<Response> {
39
39
  });
40
40
  }
41
41
  default:
42
- return Promise.reject(new FetchError(response.status, statusText(response.status)));
42
+ return Promise.reject(new FetchError(response.status));
43
43
  }
44
44
  }
45
45
  return Promise.resolve(response);
package/src/Api/File.ts CHANGED
@@ -506,9 +506,8 @@ export class File {
506
506
  }
507
507
 
508
508
  /**
509
- * Returns viewpoint preview image as <a
510
- * href="https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
511
- * target="_blank">Data URL</a>.
509
+ * Returns viewpoint preview image as
510
+ * {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL}.
512
511
  *
513
512
  * @async
514
513
  * @param guid - Viewpoint GUID.
@@ -26,9 +26,9 @@ import { $fetch } from "./Fetch";
26
26
  import { $xmlhttp } from "./XMLHttp";
27
27
 
28
28
  export class HttpClient implements IHttpClient {
29
- serverUrl: string;
30
- headers: HeadersInit = {};
31
- signInUserId = "";
29
+ public serverUrl: string;
30
+ public headers: HeadersInit = {};
31
+ public signInUserId = "";
32
32
 
33
33
  constructor(serverUrl: string) {
34
34
  this.serverUrl = serverUrl;
package/src/Api/Job.ts CHANGED
@@ -30,7 +30,7 @@ import { waitFor } from "./Utils";
30
30
  */
31
31
  export class Job {
32
32
  private _data: any;
33
- protected httpClient: IHttpClient;
33
+ public httpClient: IHttpClient;
34
34
 
35
35
  /**
36
36
  * @param data - An object that implements job data storage.
package/src/Api/Member.ts CHANGED
@@ -30,8 +30,8 @@ import { userFullName, userInitials } from "./Utils";
30
30
  */
31
31
  export class Member {
32
32
  private _data: any;
33
- protected projectId: string;
34
- protected httpClient: IHttpClient;
33
+ public projectId: string;
34
+ public httpClient: IHttpClient;
35
35
 
36
36
  /**
37
37
  * @param data - An object that implements member data storage.
package/src/Api/Model.ts CHANGED
@@ -223,9 +223,8 @@ export class Model {
223
223
  }
224
224
 
225
225
  /**
226
- * Returns viewpoint preview image as <a
227
- * href="https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
228
- * target="_blank">Data URL</a>.
226
+ * Returns viewpoint preview image as
227
+ * {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL}.
229
228
  *
230
229
  * @async
231
230
  * @param guid - Viewpoint GIID.
@@ -29,8 +29,8 @@ import { IHttpClient } from "./IHttpClient";
29
29
  */
30
30
  export class Permission {
31
31
  private _data: any;
32
- protected fileId: string;
33
- protected httpClient: IHttpClient;
32
+ public fileId: string;
33
+ public httpClient: IHttpClient;
34
34
 
35
35
  /**
36
36
  * @param data - An object that implements permission data storage.
@@ -32,7 +32,7 @@ import { userFullName, userInitials } from "./Utils";
32
32
  */
33
33
  export class Project {
34
34
  private _data: any;
35
- protected httpClient: IHttpClient;
35
+ public httpClient: IHttpClient;
36
36
 
37
37
  /**
38
38
  * @param data - An object that implements project data storage.
package/src/Api/Role.ts CHANGED
@@ -28,8 +28,8 @@ import { IHttpClient } from "./IHttpClient";
28
28
  */
29
29
  export class Role {
30
30
  private _data: any;
31
- protected projectId: string;
32
- protected httpClient: IHttpClient;
31
+ public projectId: string;
32
+ public httpClient: IHttpClient;
33
33
 
34
34
  /**
35
35
  * @param data - An object that implements role data storage.
package/src/Api/User.ts CHANGED
@@ -66,7 +66,7 @@ export interface UserParams {
66
66
  */
67
67
  export class User {
68
68
  private _data: any;
69
- protected httpClient: IHttpClient;
69
+ public httpClient: IHttpClient;
70
70
 
71
71
  /**
72
72
  * @param data - An object that implements user data storage.
package/src/index.ts CHANGED
@@ -26,6 +26,7 @@ export { Client } from "./Api/Client";
26
26
  export { ClashTest } from "./Api/ClashTest";
27
27
  export * from "./Api/ClientEvents";
28
28
  export { File } from "./Api/File";
29
+ export { FetchError, statusText } from "./Api/FetchError";
29
30
  export { Job } from "./Api/Job";
30
31
  export { Member } from "./Api/Member";
31
32
  export { Model } from "./Api/Model";