@foxnose/sdk 0.1.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 +29 -4
- package/dist/index.cjs +111 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -9
- package/dist/index.d.ts +23 -9
- package/dist/index.js +111 -69
- 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
|
|
|
@@ -12,6 +13,7 @@ Official TypeScript SDK for the [FoxNose](https://foxnose.net/?utm_source=github
|
|
|
12
13
|
- **Async-only API** built on native `fetch` (Node 18+)
|
|
13
14
|
- **Automatic retries** with exponential backoff and Retry-After support
|
|
14
15
|
- **Four auth strategies** — Anonymous, JWT, Simple key, and Secure (ECDSA P-256)
|
|
16
|
+
- **Flux introspection** — discover route contracts with `/_router` and `/_schema`
|
|
15
17
|
- **Zero dependencies** — uses only Node.js built-in modules
|
|
16
18
|
- **Dual output** — ESM and CommonJS builds with full `.d.ts` declarations
|
|
17
19
|
|
|
@@ -87,9 +89,32 @@ const results = await client.search('articles', {
|
|
|
87
89
|
size: 10,
|
|
88
90
|
});
|
|
89
91
|
|
|
92
|
+
// Discover available routes for this API prefix
|
|
93
|
+
const router = await client.getRouter();
|
|
94
|
+
console.log(router.routes.length);
|
|
95
|
+
|
|
96
|
+
// Get live schema metadata for a folder route
|
|
97
|
+
const schema = await client.getSchema('articles');
|
|
98
|
+
console.log(schema.searchable_fields);
|
|
99
|
+
|
|
90
100
|
client.close();
|
|
91
101
|
```
|
|
92
102
|
|
|
103
|
+
### API Folder Route Descriptions
|
|
104
|
+
|
|
105
|
+
You can configure per-route descriptions when connecting a folder to an API.
|
|
106
|
+
These descriptions are returned by Flux `/_router` introspection.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
await managementClient.addApiFolder(api.key, folder.key, {
|
|
110
|
+
allowedMethods: ['get_many', 'get_one'],
|
|
111
|
+
descriptionGetOne: 'Get one article by key',
|
|
112
|
+
descriptionGetMany: 'List published articles',
|
|
113
|
+
descriptionSearch: 'Search published articles',
|
|
114
|
+
descriptionSchema: 'Read article schema',
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
93
118
|
## Authentication
|
|
94
119
|
|
|
95
120
|
The SDK supports four authentication strategies:
|
|
@@ -153,9 +178,9 @@ try {
|
|
|
153
178
|
await client.getResource('folder', 'nonexistent-key');
|
|
154
179
|
} catch (err) {
|
|
155
180
|
if (err instanceof FoxnoseAPIError) {
|
|
156
|
-
console.error(err.statusCode);
|
|
157
|
-
console.error(err.errorCode);
|
|
158
|
-
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
|
|
159
184
|
} else if (err instanceof FoxnoseTransportError) {
|
|
160
185
|
console.error('Network error:', err.message);
|
|
161
186
|
}
|
|
@@ -180,7 +205,7 @@ const result = await client.batchUpsertResources('folder-key', items, {
|
|
|
180
205
|
});
|
|
181
206
|
|
|
182
207
|
console.log(result.succeeded.length); // Successfully upserted
|
|
183
|
-
console.log(result.failed.length);
|
|
208
|
+
console.log(result.failed.length); // Failed items with errors
|
|
184
209
|
```
|
|
185
210
|
|
|
186
211
|
## Development
|
package/dist/index.cjs
CHANGED
|
@@ -193,7 +193,7 @@ var DEFAULT_RETRY_CONFIG = {
|
|
|
193
193
|
statusCodes: [408, 425, 429, 500, 502, 503, 504],
|
|
194
194
|
methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
|
|
195
195
|
};
|
|
196
|
-
var SDK_VERSION = "0.
|
|
196
|
+
var SDK_VERSION = "0.2.1";
|
|
197
197
|
var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
|
|
198
198
|
function createConfig(options) {
|
|
199
199
|
if (!options.baseUrl) {
|
|
@@ -409,9 +409,7 @@ function resolveKey(value) {
|
|
|
409
409
|
if (value && typeof value === "object" && "key" in value && typeof value.key === "string") {
|
|
410
410
|
return value.key;
|
|
411
411
|
}
|
|
412
|
-
throw new TypeError(
|
|
413
|
-
`Expected a string or an object with a 'key' attribute, got ${typeof value}`
|
|
414
|
-
);
|
|
412
|
+
throw new TypeError(`Expected a string or an object with a 'key' attribute, got ${typeof value}`);
|
|
415
413
|
}
|
|
416
414
|
|
|
417
415
|
// src/management/paths.ts
|
|
@@ -495,6 +493,38 @@ var ManagementClient = class {
|
|
|
495
493
|
close() {
|
|
496
494
|
this.transport.close();
|
|
497
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
|
+
}
|
|
498
528
|
// ------------------------------------------------------------------ //
|
|
499
529
|
// Organization operations
|
|
500
530
|
// ------------------------------------------------------------------ //
|
|
@@ -609,9 +639,21 @@ var ManagementClient = class {
|
|
|
609
639
|
const aKey = resolveKey(apiKey);
|
|
610
640
|
const fKey = resolveKey(folderKey);
|
|
611
641
|
const body = { folder: fKey };
|
|
612
|
-
if (options?.allowedMethods) {
|
|
642
|
+
if (options?.allowedMethods !== void 0) {
|
|
613
643
|
body.allowed_methods = options.allowedMethods;
|
|
614
644
|
}
|
|
645
|
+
if (options?.descriptionGetOne !== void 0) {
|
|
646
|
+
body.description_get_one = options.descriptionGetOne;
|
|
647
|
+
}
|
|
648
|
+
if (options?.descriptionGetMany !== void 0) {
|
|
649
|
+
body.description_get_many = options.descriptionGetMany;
|
|
650
|
+
}
|
|
651
|
+
if (options?.descriptionSearch !== void 0) {
|
|
652
|
+
body.description_search = options.descriptionSearch;
|
|
653
|
+
}
|
|
654
|
+
if (options?.descriptionSchema !== void 0) {
|
|
655
|
+
body.description_schema = options.descriptionSchema;
|
|
656
|
+
}
|
|
615
657
|
return this.request("POST", `${this.paths.apiFoldersRoot(aKey)}/`, { jsonBody: body });
|
|
616
658
|
}
|
|
617
659
|
async getApiFolder(apiKey, folderKey) {
|
|
@@ -623,9 +665,21 @@ var ManagementClient = class {
|
|
|
623
665
|
const aKey = resolveKey(apiKey);
|
|
624
666
|
const fKey = resolveKey(folderKey);
|
|
625
667
|
const body = {};
|
|
626
|
-
if (options?.allowedMethods) {
|
|
668
|
+
if (options?.allowedMethods !== void 0) {
|
|
627
669
|
body.allowed_methods = options.allowedMethods;
|
|
628
670
|
}
|
|
671
|
+
if (options?.descriptionGetOne !== void 0) {
|
|
672
|
+
body.description_get_one = options.descriptionGetOne;
|
|
673
|
+
}
|
|
674
|
+
if (options?.descriptionGetMany !== void 0) {
|
|
675
|
+
body.description_get_many = options.descriptionGetMany;
|
|
676
|
+
}
|
|
677
|
+
if (options?.descriptionSearch !== void 0) {
|
|
678
|
+
body.description_search = options.descriptionSearch;
|
|
679
|
+
}
|
|
680
|
+
if (options?.descriptionSchema !== void 0) {
|
|
681
|
+
body.description_schema = options.descriptionSchema;
|
|
682
|
+
}
|
|
629
683
|
return this.request("PUT", `${this.paths.apiFoldersRoot(aKey)}/${fKey}/`, {
|
|
630
684
|
jsonBody: body
|
|
631
685
|
});
|
|
@@ -695,14 +749,15 @@ var ManagementClient = class {
|
|
|
695
749
|
const key = resolveKey(roleKey);
|
|
696
750
|
const payload = await this.request("GET", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
|
|
697
751
|
params: { content_type: contentType }
|
|
698
|
-
})
|
|
699
|
-
return
|
|
752
|
+
});
|
|
753
|
+
return this.normalizePermissionObjectListPayload(payload);
|
|
700
754
|
}
|
|
701
755
|
async addManagementPermissionObject(roleKey, payload) {
|
|
702
756
|
const key = resolveKey(roleKey);
|
|
703
|
-
|
|
757
|
+
const data = await this.request("POST", `${this.paths.rolePermissionObjectsRoot(key)}/`, {
|
|
704
758
|
jsonBody: payload
|
|
705
759
|
});
|
|
760
|
+
return this.normalizePermissionObjectPayload(data, payload);
|
|
706
761
|
}
|
|
707
762
|
async deleteManagementPermissionObject(roleKey, payload) {
|
|
708
763
|
const key = resolveKey(roleKey);
|
|
@@ -746,11 +801,10 @@ var ManagementClient = class {
|
|
|
746
801
|
}
|
|
747
802
|
async deleteFluxRolePermission(roleKey, contentType) {
|
|
748
803
|
const key = resolveKey(roleKey);
|
|
749
|
-
await this.request(
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
);
|
|
804
|
+
await this.request("DELETE", `${this.paths.fluxRolePermissionsRoot(key)}/`, {
|
|
805
|
+
params: { content_type: contentType },
|
|
806
|
+
parseJson: false
|
|
807
|
+
});
|
|
754
808
|
}
|
|
755
809
|
async replaceFluxRolePermissions(roleKey, permissions) {
|
|
756
810
|
const key = resolveKey(roleKey);
|
|
@@ -764,14 +818,15 @@ var ManagementClient = class {
|
|
|
764
818
|
const key = resolveKey(roleKey);
|
|
765
819
|
const payload = await this.request("GET", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
|
|
766
820
|
params: { content_type: contentType }
|
|
767
|
-
})
|
|
768
|
-
return
|
|
821
|
+
});
|
|
822
|
+
return this.normalizePermissionObjectListPayload(payload);
|
|
769
823
|
}
|
|
770
824
|
async addFluxPermissionObject(roleKey, payload) {
|
|
771
825
|
const key = resolveKey(roleKey);
|
|
772
|
-
|
|
826
|
+
const data = await this.request("POST", `${this.paths.fluxRolePermissionObjectsRoot(key)}/`, {
|
|
773
827
|
jsonBody: payload
|
|
774
828
|
});
|
|
829
|
+
return this.normalizePermissionObjectPayload(data, payload);
|
|
775
830
|
}
|
|
776
831
|
async deleteFluxPermissionObject(roleKey, payload) {
|
|
777
832
|
const key = resolveKey(roleKey);
|
|
@@ -866,10 +921,7 @@ var ManagementClient = class {
|
|
|
866
921
|
async publishFolderVersion(folderKey, versionKey) {
|
|
867
922
|
const fKey = resolveKey(folderKey);
|
|
868
923
|
const vKey = resolveKey(versionKey);
|
|
869
|
-
return this.request(
|
|
870
|
-
"POST",
|
|
871
|
-
`${this.paths.folderVersionsBase(fKey)}/${vKey}/publish/`
|
|
872
|
-
);
|
|
924
|
+
return this.request("POST", `${this.paths.folderVersionsBase(fKey)}/${vKey}/publish/`);
|
|
873
925
|
}
|
|
874
926
|
// ------------------------------------------------------------------ //
|
|
875
927
|
// Folder field operations
|
|
@@ -889,29 +941,25 @@ var ManagementClient = class {
|
|
|
889
941
|
async getFolderField(folderKey, versionKey, fieldPath) {
|
|
890
942
|
const fKey = resolveKey(folderKey);
|
|
891
943
|
const vKey = resolveKey(versionKey);
|
|
892
|
-
return this.request(
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
{ params: { path: fieldPath } }
|
|
896
|
-
);
|
|
944
|
+
return this.request("GET", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
|
|
945
|
+
params: { path: fieldPath }
|
|
946
|
+
});
|
|
897
947
|
}
|
|
898
948
|
async updateFolderField(folderKey, versionKey, fieldPath, payload) {
|
|
899
949
|
const fKey = resolveKey(folderKey);
|
|
900
950
|
const vKey = resolveKey(versionKey);
|
|
901
|
-
return this.request(
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
);
|
|
951
|
+
return this.request("PUT", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
|
|
952
|
+
params: { path: fieldPath },
|
|
953
|
+
jsonBody: payload
|
|
954
|
+
});
|
|
906
955
|
}
|
|
907
956
|
async deleteFolderField(folderKey, versionKey, fieldPath) {
|
|
908
957
|
const fKey = resolveKey(folderKey);
|
|
909
958
|
const vKey = resolveKey(versionKey);
|
|
910
|
-
await this.request(
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
);
|
|
959
|
+
await this.request("DELETE", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
|
|
960
|
+
params: { path: fieldPath },
|
|
961
|
+
parseJson: false
|
|
962
|
+
});
|
|
915
963
|
}
|
|
916
964
|
// ------------------------------------------------------------------ //
|
|
917
965
|
// Component operations
|
|
@@ -966,10 +1014,7 @@ var ManagementClient = class {
|
|
|
966
1014
|
async publishComponentVersion(componentKey, versionKey) {
|
|
967
1015
|
const cKey = resolveKey(componentKey);
|
|
968
1016
|
const vKey = resolveKey(versionKey);
|
|
969
|
-
return this.request(
|
|
970
|
-
"POST",
|
|
971
|
-
`${this.paths.componentVersionsBase(cKey)}/${vKey}/publish/`
|
|
972
|
-
);
|
|
1017
|
+
return this.request("POST", `${this.paths.componentVersionsBase(cKey)}/${vKey}/publish/`);
|
|
973
1018
|
}
|
|
974
1019
|
async updateComponentVersion(componentKey, versionKey, payload) {
|
|
975
1020
|
const cKey = resolveKey(componentKey);
|
|
@@ -1003,29 +1048,25 @@ var ManagementClient = class {
|
|
|
1003
1048
|
async getComponentField(componentKey, versionKey, fieldPath) {
|
|
1004
1049
|
const cKey = resolveKey(componentKey);
|
|
1005
1050
|
const vKey = resolveKey(versionKey);
|
|
1006
|
-
return this.request(
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
{ params: { path: fieldPath } }
|
|
1010
|
-
);
|
|
1051
|
+
return this.request("GET", `${this.paths.componentSchemaTree(cKey, vKey)}/field/`, {
|
|
1052
|
+
params: { path: fieldPath }
|
|
1053
|
+
});
|
|
1011
1054
|
}
|
|
1012
1055
|
async updateComponentField(componentKey, versionKey, fieldPath, payload) {
|
|
1013
1056
|
const cKey = resolveKey(componentKey);
|
|
1014
1057
|
const vKey = resolveKey(versionKey);
|
|
1015
|
-
return this.request(
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
);
|
|
1058
|
+
return this.request("PUT", `${this.paths.componentSchemaTree(cKey, vKey)}/field/`, {
|
|
1059
|
+
params: { path: fieldPath },
|
|
1060
|
+
jsonBody: payload
|
|
1061
|
+
});
|
|
1020
1062
|
}
|
|
1021
1063
|
async deleteComponentField(componentKey, versionKey, fieldPath) {
|
|
1022
1064
|
const cKey = resolveKey(componentKey);
|
|
1023
1065
|
const vKey = resolveKey(versionKey);
|
|
1024
|
-
await this.request(
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
);
|
|
1066
|
+
await this.request("DELETE", `${this.paths.componentSchemaTree(cKey, vKey)}/field/`, {
|
|
1067
|
+
params: { path: fieldPath },
|
|
1068
|
+
parseJson: false
|
|
1069
|
+
});
|
|
1029
1070
|
}
|
|
1030
1071
|
// ------------------------------------------------------------------ //
|
|
1031
1072
|
// Resource operations
|
|
@@ -1190,10 +1231,7 @@ var ManagementClient = class {
|
|
|
1190
1231
|
const fKey = resolveKey(folderKey);
|
|
1191
1232
|
const rKey = resolveKey(resourceKey);
|
|
1192
1233
|
const rvKey = resolveKey(revisionKey);
|
|
1193
|
-
return this.request(
|
|
1194
|
-
"POST",
|
|
1195
|
-
`${this.paths.revisionBase(fKey, rKey)}/${rvKey}/validate/`
|
|
1196
|
-
);
|
|
1234
|
+
return this.request("POST", `${this.paths.revisionBase(fKey, rKey)}/${rvKey}/validate/`);
|
|
1197
1235
|
}
|
|
1198
1236
|
async getRevisionData(folderKey, resourceKey, revisionKey) {
|
|
1199
1237
|
const fKey = resolveKey(folderKey);
|
|
@@ -1298,11 +1336,9 @@ var ManagementClient = class {
|
|
|
1298
1336
|
const oKey = resolveKey(orgKey);
|
|
1299
1337
|
const pKey = resolveKey(projectKey);
|
|
1300
1338
|
const eKey = resolveKey(envKey);
|
|
1301
|
-
await this.request(
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
{ jsonBody: { is_enabled: isEnabled } }
|
|
1305
|
-
);
|
|
1339
|
+
await this.request("POST", `${this.paths.environmentRoot(oKey, pKey, eKey)}/toggle/`, {
|
|
1340
|
+
jsonBody: { is_enabled: isEnabled }
|
|
1341
|
+
});
|
|
1306
1342
|
}
|
|
1307
1343
|
async updateEnvironmentProtection(orgKey, projectKey, envKey, options) {
|
|
1308
1344
|
const oKey = resolveKey(orgKey);
|
|
@@ -1312,11 +1348,9 @@ var ManagementClient = class {
|
|
|
1312
1348
|
if (options.protectionReason) {
|
|
1313
1349
|
body.protection_reason = options.protectionReason;
|
|
1314
1350
|
}
|
|
1315
|
-
return this.request(
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
{ jsonBody: body }
|
|
1319
|
-
);
|
|
1351
|
+
return this.request("PATCH", `${this.paths.environmentRoot(oKey, pKey, eKey)}/protection/`, {
|
|
1352
|
+
jsonBody: body
|
|
1353
|
+
});
|
|
1320
1354
|
}
|
|
1321
1355
|
async clearEnvironmentProtection(orgKey, projectKey, envKey) {
|
|
1322
1356
|
return this.updateEnvironmentProtection(orgKey, projectKey, envKey, {
|
|
@@ -1369,6 +1403,14 @@ var FluxClient = class {
|
|
|
1369
1403
|
const path = this.buildPath(folderPath, "/_search");
|
|
1370
1404
|
return this.transport.request("POST", path, { jsonBody: body });
|
|
1371
1405
|
}
|
|
1406
|
+
async getRouter() {
|
|
1407
|
+
const path = `/${this.apiPrefix}/_router`;
|
|
1408
|
+
return this.transport.request("GET", path);
|
|
1409
|
+
}
|
|
1410
|
+
async getSchema(folderPath) {
|
|
1411
|
+
const path = this.buildPath(folderPath, "/_schema");
|
|
1412
|
+
return this.transport.request("GET", path);
|
|
1413
|
+
}
|
|
1372
1414
|
close() {
|
|
1373
1415
|
this.transport.close();
|
|
1374
1416
|
}
|