@foxnose/sdk 0.2.1 → 0.2.2

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
@@ -552,6 +552,9 @@ declare class ManagementClient {
552
552
  parseJson?: boolean;
553
553
  }): Promise<any>;
554
554
  close(): void;
555
+ private normalizeListPayload;
556
+ private normalizePermissionObjectPayload;
557
+ private normalizePermissionObjectListPayload;
555
558
  listOrganizations(): Promise<OrganizationList>;
556
559
  getOrganization(orgKey: OrgRef): Promise<OrganizationSummary>;
557
560
  updateOrganization(orgKey: OrgRef, payload: Record<string, any>): Promise<OrganizationSummary>;
package/dist/index.js CHANGED
@@ -450,6 +450,38 @@ var ManagementClient = class {
450
450
  close() {
451
451
  this.transport.close();
452
452
  }
453
+ normalizeListPayload(payload) {
454
+ if (Array.isArray(payload)) {
455
+ return payload;
456
+ }
457
+ if (payload && typeof payload === "object") {
458
+ const results = payload.results;
459
+ if (Array.isArray(results)) {
460
+ return results;
461
+ }
462
+ return [payload];
463
+ }
464
+ return [];
465
+ }
466
+ normalizePermissionObjectPayload(payload, requestPayload) {
467
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
468
+ const data = { ...payload };
469
+ if (!("object_key" in data) && "object" in data) {
470
+ data.object_key = data.object;
471
+ delete data.object;
472
+ }
473
+ return data;
474
+ }
475
+ return {
476
+ content_type: requestPayload.content_type,
477
+ object_key: requestPayload.object_key ?? requestPayload.object
478
+ };
479
+ }
480
+ normalizePermissionObjectListPayload(payload) {
481
+ return this.normalizeListPayload(payload).map(
482
+ (item) => this.normalizePermissionObjectPayload(item, item)
483
+ );
484
+ }
453
485
  // ------------------------------------------------------------------ //
454
486
  // Organization operations
455
487
  // ------------------------------------------------------------------ //
@@ -674,14 +706,15 @@ var ManagementClient = class {
674
706
  const key = resolveKey(roleKey);
675
707
  const payload = await this.request("GET", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
676
708
  params: { content_type: contentType }
677
- }) ?? [];
678
- return Array.isArray(payload) ? payload : [payload];
709
+ });
710
+ return this.normalizePermissionObjectListPayload(payload);
679
711
  }
680
712
  async addManagementPermissionObject(roleKey, payload) {
681
713
  const key = resolveKey(roleKey);
682
- return this.request("POST", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
714
+ const data = await this.request("POST", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
683
715
  jsonBody: payload
684
716
  });
717
+ return this.normalizePermissionObjectPayload(data, payload);
685
718
  }
686
719
  async deleteManagementPermissionObject(roleKey, payload) {
687
720
  const key = resolveKey(roleKey);
@@ -742,14 +775,15 @@ var ManagementClient = class {
742
775
  const key = resolveKey(roleKey);
743
776
  const payload = await this.request("GET", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
744
777
  params: { content_type: contentType }
745
- }) ?? [];
746
- return Array.isArray(payload) ? payload : [payload];
778
+ });
779
+ return this.normalizePermissionObjectListPayload(payload);
747
780
  }
748
781
  async addFluxPermissionObject(roleKey, payload) {
749
782
  const key = resolveKey(roleKey);
750
- return this.request("POST", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
783
+ const data = await this.request("POST", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
751
784
  jsonBody: payload
752
785
  });
786
+ return this.normalizePermissionObjectPayload(data, payload);
753
787
  }
754
788
  async deleteFluxPermissionObject(roleKey, payload) {
755
789
  const key = resolveKey(roleKey);