@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 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
@@ -147,9 +147,6 @@ var SecureKeyAuth = class {
147
147
  try {
148
148
  const parsed = new URL(request.url);
149
149
  path = parsed.pathname || "/";
150
- if (parsed.search) {
151
- path = `${path}${parsed.search}`;
152
- }
153
150
  } catch {
154
151
  path = request.path || "/";
155
152
  }
@@ -493,6 +490,38 @@ var ManagementClient = class {
493
490
  close() {
494
491
  this.transport.close();
495
492
  }
493
+ normalizeListPayload(payload) {
494
+ if (Array.isArray(payload)) {
495
+ return payload;
496
+ }
497
+ if (payload && typeof payload === "object") {
498
+ const results = payload.results;
499
+ if (Array.isArray(results)) {
500
+ return results;
501
+ }
502
+ return [payload];
503
+ }
504
+ return [];
505
+ }
506
+ normalizePermissionObjectPayload(payload, requestPayload) {
507
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
508
+ const data = { ...payload };
509
+ if (!("object_key" in data) && "object" in data) {
510
+ data.object_key = data.object;
511
+ delete data.object;
512
+ }
513
+ return data;
514
+ }
515
+ return {
516
+ content_type: requestPayload.content_type,
517
+ object_key: requestPayload.object_key ?? requestPayload.object
518
+ };
519
+ }
520
+ normalizePermissionObjectListPayload(payload) {
521
+ return this.normalizeListPayload(payload).map(
522
+ (item) => this.normalizePermissionObjectPayload(item, item)
523
+ );
524
+ }
496
525
  // ------------------------------------------------------------------ //
497
526
  // Organization operations
498
527
  // ------------------------------------------------------------------ //
@@ -717,14 +746,15 @@ var ManagementClient = class {
717
746
  const key = resolveKey(roleKey);
718
747
  const payload = await this.request("GET", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
719
748
  params: { content_type: contentType }
720
- }) ?? [];
721
- return Array.isArray(payload) ? payload : [payload];
749
+ });
750
+ return this.normalizePermissionObjectListPayload(payload);
722
751
  }
723
752
  async addManagementPermissionObject(roleKey, payload) {
724
753
  const key = resolveKey(roleKey);
725
- return this.request("POST", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
754
+ const data = await this.request("POST", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
726
755
  jsonBody: payload
727
756
  });
757
+ return this.normalizePermissionObjectPayload(data, payload);
728
758
  }
729
759
  async deleteManagementPermissionObject(roleKey, payload) {
730
760
  const key = resolveKey(roleKey);
@@ -785,14 +815,15 @@ var ManagementClient = class {
785
815
  const key = resolveKey(roleKey);
786
816
  const payload = await this.request("GET", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
787
817
  params: { content_type: contentType }
788
- }) ?? [];
789
- return Array.isArray(payload) ? payload : [payload];
818
+ });
819
+ return this.normalizePermissionObjectListPayload(payload);
790
820
  }
791
821
  async addFluxPermissionObject(roleKey, payload) {
792
822
  const key = resolveKey(roleKey);
793
- return this.request("POST", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
823
+ const data = await this.request("POST", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
794
824
  jsonBody: payload
795
825
  });
826
+ return this.normalizePermissionObjectPayload(data, payload);
796
827
  }
797
828
  async deleteFluxPermissionObject(roleKey, payload) {
798
829
  const key = resolveKey(roleKey);