@singularlogic/coreplatts 0.0.18 → 0.0.21

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/dist/index.d.ts CHANGED
@@ -138,6 +138,20 @@ interface Group {
138
138
  [key: string]: any[];
139
139
  };
140
140
  }
141
+ interface DisplayGroup {
142
+ id: string;
143
+ name: string;
144
+ description?: string;
145
+ tags?: string[];
146
+ numberOfDatasets?: number;
147
+ numberOfResources?: number;
148
+ totalSize?: number;
149
+ numUsers?: number;
150
+ users?: string[];
151
+ }
152
+ type UsersPart = Pick<DisplayGroup, "id" | "name" | "numUsers" | "users">;
153
+ type StatsPart = Omit<DisplayGroup, "numUsers" | "users">;
154
+ declare function mergeGroupsByIdName(stats: StatsPart[], users: UsersPart[]): DisplayGroup[];
141
155
  declare enum Role {
142
156
  ADMIN,
143
157
  MEMBER
@@ -163,7 +177,7 @@ type TokenProvider = () => string | Promise<string>;
163
177
  interface IClient$1 {
164
178
  login(email: string, password: string): Promise<OidcToken>;
165
179
  myUser(token?: string): Promise<User>;
166
- allOrganizations(token?: string): Promise<Group[]>;
180
+ allOrganizations(token?: string): Promise<DisplayGroup[]>;
167
181
  myOrganizations(token?: string): Promise<Group[]>;
168
182
  organizationByID(id: string, token?: string): Promise<Group>;
169
183
  organizationByName(name: string, token?: string): Promise<Group>;
@@ -217,7 +231,7 @@ declare class Client implements IClient$1 {
217
231
  */
218
232
  totalInfo(): Promise<TotalInfo>;
219
233
  myUser(token?: string): Promise<User>;
220
- allOrganizations(token?: string): Promise<Group[]>;
234
+ allOrganizations(token?: string): Promise<DisplayGroup[]>;
221
235
  myOrganizations(token?: string): Promise<Group[]>;
222
236
  organizationByID(id: string, token?: string): Promise<Group>;
223
237
  organizationByName(name: string, token?: string): Promise<Group>;
@@ -237,4 +251,4 @@ declare class Client implements IClient$1 {
237
251
 
238
252
  type IClient = IClient$1;
239
253
 
240
- export { type Bucket, Client, type ErrorReport, type FileModel, type FolderList, type FolderModel, type Group, type IClient, type Meta, type MultipartWrapper, type OidcToken, type PartInfo, Role, type TotalInfo, type Updated, type User, type UserRoles };
254
+ export { type Bucket, Client, type DisplayGroup, type ErrorReport, type FileModel, type FolderList, type FolderModel, type Group, type IClient, type Meta, type MultipartWrapper, type OidcToken, type PartInfo, Role, type StatsPart, type TotalInfo, type Updated, type User, type UserRoles, type UsersPart, mergeGroupsByIdName };
package/dist/index.js CHANGED
@@ -68,11 +68,32 @@ var __async = (__this, __arguments, generator) => {
68
68
  var index_exports = {};
69
69
  __export(index_exports, {
70
70
  Client: () => Client,
71
- Role: () => Role
71
+ Role: () => Role,
72
+ mergeGroupsByIdName: () => mergeGroupsByIdName
72
73
  });
73
74
  module.exports = __toCommonJS(index_exports);
74
75
 
75
76
  // src/models/group.account.models.ts
77
+ function mergeGroupsByIdName(stats, users) {
78
+ const byKey = /* @__PURE__ */ new Map();
79
+ const key = (g) => {
80
+ var _a, _b;
81
+ return `${(_a = g.id) != null ? _a : ""}||${(_b = g.name) != null ? _b : ""}`;
82
+ };
83
+ for (const g of stats) {
84
+ byKey.set(key(g), __spreadValues({}, g));
85
+ }
86
+ for (const u of users) {
87
+ const k = key(u);
88
+ const existing = byKey.get(k);
89
+ if (existing) {
90
+ byKey.set(k, __spreadProps(__spreadValues({}, existing), { users: u.users, numUsers: u.numUsers }));
91
+ } else {
92
+ byKey.set(k, __spreadValues({}, u));
93
+ }
94
+ }
95
+ return Array.from(byKey.values());
96
+ }
76
97
  var Role = /* @__PURE__ */ ((Role2) => {
77
98
  Role2["ADMIN"] = "admin";
78
99
  Role2["MEMBER"] = "member";
@@ -222,6 +243,14 @@ var GroupConsumer = class extends BaseConsumer {
222
243
  getAllGroups(token) {
223
244
  return this.getMany("all", null, token);
224
245
  }
246
+ getGroupUsers(gname, gid, token) {
247
+ let addPath = "";
248
+ addPath = addPath + (gname ? `?name=${gname}` : "") + (gid ? `?id=${gid}` : "");
249
+ return this._httpClient.get(this.path + "describe" + addPath, { headers: { "Authorization": "Bearer " + token } }).then((resp) => resp.data).catch((error) => {
250
+ console.error(`\u274C Error in posting:`, error);
251
+ return null;
252
+ });
253
+ }
225
254
  getUserGroups(token) {
226
255
  return this.getMany("", null, token);
227
256
  }
@@ -277,6 +306,13 @@ var BucketConsumer = class extends BaseConsumer {
277
306
  deleteBucket(id, token) {
278
307
  return this.delete("/" + id, token);
279
308
  }
309
+ getBucketInfo(gid, token) {
310
+ let addPath = gid ? `?id=${gid}` : "";
311
+ return this._httpClient.get(this.path + addPath, { headers: { "Authorization": "Bearer " + token } }).then((resp) => resp.data).catch((error) => {
312
+ console.error(`\u274C Error in posting:`, error);
313
+ return null;
314
+ });
315
+ }
280
316
  };
281
317
 
282
318
  // src/utils/utils.ts
@@ -897,7 +933,12 @@ var Client = class {
897
933
  return this._userConsumer.getUser(token);
898
934
  }
899
935
  allOrganizations(token) {
900
- return this._groupConsumer.getAllGroups(token);
936
+ return Promise.all([
937
+ this._bucketConsumer.getBucketInfo(void 0, token),
938
+ this._groupConsumer.getGroupUsers(void 0, void 0, token)
939
+ ]).then(
940
+ ([stats, users]) => mergeGroupsByIdName(stats != null ? stats : [], users != null ? users : [])
941
+ );
901
942
  }
902
943
  myOrganizations(token) {
903
944
  return this._groupConsumer.getUserGroups(token);
@@ -966,5 +1007,6 @@ var Client = class {
966
1007
  // Annotate the CommonJS export names for ESM import in node:
967
1008
  0 && (module.exports = {
968
1009
  Client,
969
- Role
1010
+ Role,
1011
+ mergeGroupsByIdName
970
1012
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularlogic/coreplatts",
3
- "version": "0.0.18",
3
+ "version": "0.0.21",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [