@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/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@foxnose/sdk)](https://www.npmjs.com/package/@foxnose/sdk)
4
4
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
5
5
  [![Node.js](https://img.shields.io/badge/node-%3E%3D18-green)](https://nodejs.org)
6
+ [![codecov](https://codecov.io/gh/FoxNoseTech/foxnose-typescript/branch/main/graph/badge.svg)](https://codecov.io/gh/FoxNoseTech/foxnose-typescript)
6
7
 
7
8
  Official TypeScript SDK for the [FoxNose](https://foxnose.net/?utm_source=github&utm_medium=repository&utm_campaign=foxnose-typescript) platform — a managed knowledge layer for RAG and AI agents.
8
9
 
@@ -177,9 +178,9 @@ try {
177
178
  await client.getResource('folder', 'nonexistent-key');
178
179
  } catch (err) {
179
180
  if (err instanceof FoxnoseAPIError) {
180
- console.error(err.statusCode); // 404
181
- console.error(err.errorCode); // "not_found"
182
- console.error(err.detail); // Additional error details
181
+ console.error(err.statusCode); // 404
182
+ console.error(err.errorCode); // "not_found"
183
+ console.error(err.detail); // Additional error details
183
184
  } else if (err instanceof FoxnoseTransportError) {
184
185
  console.error('Network error:', err.message);
185
186
  }
@@ -204,7 +205,7 @@ const result = await client.batchUpsertResources('folder-key', items, {
204
205
  });
205
206
 
206
207
  console.log(result.succeeded.length); // Successfully upserted
207
- console.log(result.failed.length); // Failed items with errors
208
+ console.log(result.failed.length); // Failed items with errors
208
209
  ```
209
210
 
210
211
  ## Development
package/dist/index.cjs CHANGED
@@ -493,6 +493,38 @@ var ManagementClient = class {
493
493
  close() {
494
494
  this.transport.close();
495
495
  }
496
+ normalizeListPayload(payload) {
497
+ if (Array.isArray(payload)) {
498
+ return payload;
499
+ }
500
+ if (payload && typeof payload === "object") {
501
+ const results = payload.results;
502
+ if (Array.isArray(results)) {
503
+ return results;
504
+ }
505
+ return [payload];
506
+ }
507
+ return [];
508
+ }
509
+ normalizePermissionObjectPayload(payload, requestPayload) {
510
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
511
+ const data = { ...payload };
512
+ if (!("object_key" in data) && "object" in data) {
513
+ data.object_key = data.object;
514
+ delete data.object;
515
+ }
516
+ return data;
517
+ }
518
+ return {
519
+ content_type: requestPayload.content_type,
520
+ object_key: requestPayload.object_key ?? requestPayload.object
521
+ };
522
+ }
523
+ normalizePermissionObjectListPayload(payload) {
524
+ return this.normalizeListPayload(payload).map(
525
+ (item) => this.normalizePermissionObjectPayload(item, item)
526
+ );
527
+ }
496
528
  // ------------------------------------------------------------------ //
497
529
  // Organization operations
498
530
  // ------------------------------------------------------------------ //
@@ -717,14 +749,15 @@ var ManagementClient = class {
717
749
  const key = resolveKey(roleKey);
718
750
  const payload = await this.request("GET", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
719
751
  params: { content_type: contentType }
720
- }) ?? [];
721
- return Array.isArray(payload) ? payload : [payload];
752
+ });
753
+ return this.normalizePermissionObjectListPayload(payload);
722
754
  }
723
755
  async addManagementPermissionObject(roleKey, payload) {
724
756
  const key = resolveKey(roleKey);
725
- return this.request("POST", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
757
+ const data = await this.request("POST", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
726
758
  jsonBody: payload
727
759
  });
760
+ return this.normalizePermissionObjectPayload(data, payload);
728
761
  }
729
762
  async deleteManagementPermissionObject(roleKey, payload) {
730
763
  const key = resolveKey(roleKey);
@@ -785,14 +818,15 @@ var ManagementClient = class {
785
818
  const key = resolveKey(roleKey);
786
819
  const payload = await this.request("GET", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
787
820
  params: { content_type: contentType }
788
- }) ?? [];
789
- return Array.isArray(payload) ? payload : [payload];
821
+ });
822
+ return this.normalizePermissionObjectListPayload(payload);
790
823
  }
791
824
  async addFluxPermissionObject(roleKey, payload) {
792
825
  const key = resolveKey(roleKey);
793
- return this.request("POST", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
826
+ const data = await this.request("POST", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
794
827
  jsonBody: payload
795
828
  });
829
+ return this.normalizePermissionObjectPayload(data, payload);
796
830
  }
797
831
  async deleteFluxPermissionObject(roleKey, payload) {
798
832
  const key = resolveKey(roleKey);