@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/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@foxnose/sdk)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
[](https://nodejs.org)
|
|
6
|
+
[](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);
|
|
181
|
-
console.error(err.errorCode);
|
|
182
|
-
console.error(err.detail);
|
|
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);
|
|
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
|
|
749
|
+
});
|
|
750
|
+
return this.normalizePermissionObjectListPayload(payload);
|
|
722
751
|
}
|
|
723
752
|
async addManagementPermissionObject(roleKey, payload) {
|
|
724
753
|
const key = resolveKey(roleKey);
|
|
725
|
-
|
|
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
|
|
818
|
+
});
|
|
819
|
+
return this.normalizePermissionObjectListPayload(payload);
|
|
790
820
|
}
|
|
791
821
|
async addFluxPermissionObject(roleKey, payload) {
|
|
792
822
|
const key = resolveKey(roleKey);
|
|
793
|
-
|
|
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);
|