@foxnose/sdk 0.2.1 → 0.2.3
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/README.md +5 -4
- package/dist/index.cjs +40 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +40 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
@@ -104,9 +104,6 @@ var SecureKeyAuth = class {
|
|
|
104
104
|
try {
|
|
105
105
|
const parsed = new URL(request.url);
|
|
106
106
|
path = parsed.pathname || "/";
|
|
107
|
-
if (parsed.search) {
|
|
108
|
-
path = `${path}${parsed.search}`;
|
|
109
|
-
}
|
|
110
107
|
} catch {
|
|
111
108
|
path = request.path || "/";
|
|
112
109
|
}
|
|
@@ -450,6 +447,38 @@ var ManagementClient = class {
|
|
|
450
447
|
close() {
|
|
451
448
|
this.transport.close();
|
|
452
449
|
}
|
|
450
|
+
normalizeListPayload(payload) {
|
|
451
|
+
if (Array.isArray(payload)) {
|
|
452
|
+
return payload;
|
|
453
|
+
}
|
|
454
|
+
if (payload && typeof payload === "object") {
|
|
455
|
+
const results = payload.results;
|
|
456
|
+
if (Array.isArray(results)) {
|
|
457
|
+
return results;
|
|
458
|
+
}
|
|
459
|
+
return [payload];
|
|
460
|
+
}
|
|
461
|
+
return [];
|
|
462
|
+
}
|
|
463
|
+
normalizePermissionObjectPayload(payload, requestPayload) {
|
|
464
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
465
|
+
const data = { ...payload };
|
|
466
|
+
if (!("object_key" in data) && "object" in data) {
|
|
467
|
+
data.object_key = data.object;
|
|
468
|
+
delete data.object;
|
|
469
|
+
}
|
|
470
|
+
return data;
|
|
471
|
+
}
|
|
472
|
+
return {
|
|
473
|
+
content_type: requestPayload.content_type,
|
|
474
|
+
object_key: requestPayload.object_key ?? requestPayload.object
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
normalizePermissionObjectListPayload(payload) {
|
|
478
|
+
return this.normalizeListPayload(payload).map(
|
|
479
|
+
(item) => this.normalizePermissionObjectPayload(item, item)
|
|
480
|
+
);
|
|
481
|
+
}
|
|
453
482
|
// ------------------------------------------------------------------ //
|
|
454
483
|
// Organization operations
|
|
455
484
|
// ------------------------------------------------------------------ //
|
|
@@ -674,14 +703,15 @@ var ManagementClient = class {
|
|
|
674
703
|
const key = resolveKey(roleKey);
|
|
675
704
|
const payload = await this.request("GET", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
|
|
676
705
|
params: { content_type: contentType }
|
|
677
|
-
})
|
|
678
|
-
return
|
|
706
|
+
});
|
|
707
|
+
return this.normalizePermissionObjectListPayload(payload);
|
|
679
708
|
}
|
|
680
709
|
async addManagementPermissionObject(roleKey, payload) {
|
|
681
710
|
const key = resolveKey(roleKey);
|
|
682
|
-
|
|
711
|
+
const data = await this.request("POST", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
|
|
683
712
|
jsonBody: payload
|
|
684
713
|
});
|
|
714
|
+
return this.normalizePermissionObjectPayload(data, payload);
|
|
685
715
|
}
|
|
686
716
|
async deleteManagementPermissionObject(roleKey, payload) {
|
|
687
717
|
const key = resolveKey(roleKey);
|
|
@@ -742,14 +772,15 @@ var ManagementClient = class {
|
|
|
742
772
|
const key = resolveKey(roleKey);
|
|
743
773
|
const payload = await this.request("GET", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
|
|
744
774
|
params: { content_type: contentType }
|
|
745
|
-
})
|
|
746
|
-
return
|
|
775
|
+
});
|
|
776
|
+
return this.normalizePermissionObjectListPayload(payload);
|
|
747
777
|
}
|
|
748
778
|
async addFluxPermissionObject(roleKey, payload) {
|
|
749
779
|
const key = resolveKey(roleKey);
|
|
750
|
-
|
|
780
|
+
const data = await this.request("POST", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
|
|
751
781
|
jsonBody: payload
|
|
752
782
|
});
|
|
783
|
+
return this.normalizePermissionObjectPayload(data, payload);
|
|
753
784
|
}
|
|
754
785
|
async deleteFluxPermissionObject(roleKey, payload) {
|
|
755
786
|
const key = resolveKey(roleKey);
|