@api-client/core 0.3.8 → 0.3.11

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.
@@ -144,7 +144,7 @@ export class Workspace {
144
144
  this.info = new Thing({ kind: ThingKind, name: '' });
145
145
  }
146
146
  if (Array.isArray(users)) {
147
- this.users = users;
147
+ this.users = [...users];
148
148
  } else {
149
149
  this.users = [];
150
150
  }
@@ -175,7 +175,7 @@ export class Workspace {
175
175
  owner,
176
176
  };
177
177
  if (Array.isArray(users) && users.length) {
178
- result.users = users;
178
+ result.users = [...users];
179
179
  }
180
180
  return result;
181
181
  }
@@ -474,6 +474,36 @@ class SpacesSdk extends SdkBase {
474
474
  throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
475
475
  }
476
476
  }
477
+
478
+ /**
479
+ * Lists uses having access to the user space.
480
+ *
481
+ * @param key The user space key
482
+ */
483
+ async listUsers(key: string): Promise<IListResponse> {
484
+ const { token } = this.sdk;
485
+ const url = this.sdk.getUrl(`/spaces/${key}/users`);
486
+ const result = await this.sdk.http.get(url.toString(), { token });
487
+ this.inspectCommonStatusCodes(result.status);
488
+ const E_PREFIX = 'Unable to list users in the space. ';
489
+ if (result.status !== 200) {
490
+ this.logInvalidResponse(result);
491
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
492
+ }
493
+ if (!result.body) {
494
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
495
+ }
496
+ let data: IListResponse;
497
+ try {
498
+ data = JSON.parse(result.body);
499
+ } catch (e) {
500
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
501
+ }
502
+ if (!Array.isArray(data.data)) {
503
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
504
+ }
505
+ return data;
506
+ }
477
507
  }
478
508
 
479
509
  class HttpClient extends SdkBase {
@@ -835,4 +865,31 @@ class UsersSdk extends SdkBase {
835
865
  }
836
866
  return data;
837
867
  }
868
+
869
+ /**
870
+ * Reads a user information from the store.
871
+ * @param key The user key.
872
+ * @returns The user object
873
+ */
874
+ async read(key: string): Promise<IUser> {
875
+ const { token } = this.sdk;
876
+ const url = this.sdk.getUrl(`/users/${key}`);
877
+ const result = await this.sdk.http.get(url.toString(), { token });
878
+ this.inspectCommonStatusCodes(result.status);
879
+ const E_PREFIX = 'Unable to read the user info. ';
880
+ if (result.status !== 200) {
881
+ this.logInvalidResponse(result);
882
+ throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
883
+ }
884
+ if (!result.body) {
885
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
886
+ }
887
+ let data: IUser;
888
+ try {
889
+ data = JSON.parse(result.body);
890
+ } catch (e) {
891
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
892
+ }
893
+ return data;
894
+ }
838
895
  }