@foxnose/sdk 0.5.1 → 0.6.1

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/dist/index.js CHANGED
@@ -165,6 +165,7 @@ function getHeader(headers, name) {
165
165
  }
166
166
  return void 0;
167
167
  }
168
+ var CONTENT_VALIDATION_CODES = /* @__PURE__ */ new Set(["content_validation_failed", "data_validation_error"]);
168
169
  function buildAPIError(options) {
169
170
  const { statusCode, errorCode, detail, responseHeaders, responseBody } = options;
170
171
  const body = isPlainObject(responseBody) ? responseBody : void 0;
@@ -210,7 +211,7 @@ function buildAPIError(options) {
210
211
  if (statusCode === 409 && errorCode === "external_id_conflict") {
211
212
  return new ExternalIdConflictError(options);
212
213
  }
213
- if (statusCode === 422 && errorCode === "content_validation_failed") {
214
+ if (statusCode === 422 && CONTENT_VALIDATION_CODES.has(errorCode)) {
214
215
  const d = isPlainObject(detail) ? detail : {};
215
216
  const errors = Array.isArray(d.errors) ? d.errors : typeof d.json_path === "string" ? [d] : [];
216
217
  return new ContentValidationFailedError({
@@ -308,7 +309,7 @@ var DEFAULT_RETRY_CONFIG = {
308
309
  statusCodes: [408, 425, 429, 500, 502, 503, 504],
309
310
  methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
310
311
  };
311
- var SDK_VERSION = "0.5.1";
312
+ var SDK_VERSION = "0.6.1";
312
313
  var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
313
314
  function createConfig(options) {
314
315
  if (!options.baseUrl) {
@@ -535,9 +536,7 @@ function warnDeprecatedMethod(oldName, newName, removal = "1.0") {
535
536
  function nestedFieldMeta(opts) {
536
537
  if (opts.extra) {
537
538
  const reserved = ["component", "component_version", "auto_update"];
538
- const collisions = reserved.filter(
539
- (k) => Object.prototype.hasOwnProperty.call(opts.extra, k)
540
- );
539
+ const collisions = reserved.filter((k) => Object.prototype.hasOwnProperty.call(opts.extra, k));
541
540
  if (collisions.length > 0) {
542
541
  throw new Error(
543
542
  `nestedFieldMeta: 'extra' must not include reserved keys: ${collisions.join(", ")}`
@@ -596,6 +595,7 @@ function managementPaths(environmentKey) {
596
595
  // Flux API key paths
597
596
  fluxApiKeysRoot: () => `/v1/${environmentKey}/permissions/flux-api/api-keys`,
598
597
  fluxApiKeyRoot: (apiKey) => `/v1/${environmentKey}/permissions/flux-api/api-keys/${apiKey}`,
598
+ fluxApiKeyBearerTokenRoot: (apiKey) => `/v1/${environmentKey}/permissions/flux-api/api-keys/${apiKey}/bearer-token`,
599
599
  // API management paths
600
600
  apisRoot: () => `/v1/${environmentKey}/api`,
601
601
  apiRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}`,
@@ -764,6 +764,41 @@ var ManagementClient = class {
764
764
  const k = resolveKey(key);
765
765
  await this.request("DELETE", `${this.paths.fluxApiKeyRoot(k)}/`, { parseJson: false });
766
766
  }
767
+ /**
768
+ * Issue a bearer token for a Flux API key, or replace the existing one.
769
+ *
770
+ * A bearer token exists for clients that accept a single token value and send
771
+ * it as `Authorization: Bearer <token>` with no way to choose the scheme —
772
+ * hosted MCP connectors, notably the Claude API's `mcp_servers`. Those clients
773
+ * cannot send `Simple` or `Secure` at all.
774
+ *
775
+ * THE PLAINTEXT IS RETURNED ONLY HERE, AND ONLY ONCE. The service stores a
776
+ * hash, exactly as it does for `secret_key`, so a lost token is re-issued
777
+ * rather than recovered. Subsequent key reads expose only
778
+ * `bearer_token_prefix`.
779
+ *
780
+ * The key itself is untouched: `public_key`, `secret_key`, `role` and grants
781
+ * all survive, so `Simple` and `Secure` integrations keep working across a
782
+ * re-issue. That is what makes this the way to cut off a connector without
783
+ * recreating a key and reconfiguring everything that uses it.
784
+ *
785
+ * There is at most one token per key; calling this again replaces it.
786
+ */
787
+ async issueFluxApiKeyBearerToken(key) {
788
+ const k = resolveKey(key);
789
+ return this.request("POST", `${this.paths.fluxApiKeyBearerTokenRoot(k)}/`);
790
+ }
791
+ /**
792
+ * Revoke a Flux API key's bearer token. The key and its role keep working.
793
+ *
794
+ * Idempotent: succeeds whether or not a token was issued.
795
+ */
796
+ async revokeFluxApiKeyBearerToken(key) {
797
+ const k = resolveKey(key);
798
+ await this.request("DELETE", `${this.paths.fluxApiKeyBearerTokenRoot(k)}/`, {
799
+ parseJson: false
800
+ });
801
+ }
767
802
  // ------------------------------------------------------------------ //
768
803
  // API management operations
769
804
  // ------------------------------------------------------------------ //
@@ -785,17 +820,17 @@ var ManagementClient = class {
785
820
  const key = resolveKey(apiKey);
786
821
  await this.request("DELETE", `${this.paths.apiRoot(key)}/`, { parseJson: false });
787
822
  }
788
- // ------------------------------------------------------------------ //
789
- // API ↔ Collection association (canonical)
790
- // ------------------------------------------------------------------ //
791
- async listApiCollections(apiKey, params) {
792
- const key = resolveKey(apiKey);
793
- return this.request("GET", `${this.paths.apiCollectionsRoot(key)}/`, { params });
794
- }
795
- async addApiCollection(apiKey, collectionKey, options) {
796
- const aKey = resolveKey(apiKey);
797
- const cKey = resolveKey(collectionKey);
798
- const body = { folder: cKey };
823
+ /**
824
+ * Build the request body shared by all four API-collection-association
825
+ * writers: {@link addApiCollection}, {@link updateApiCollection}, and
826
+ * their deprecated `*ApiFolder*` twins. All four accept {@link
827
+ * ApiFolderOptions}, so this is the one place that maps its camelCase
828
+ * fields to wire snake_case — adding a field here, rather than to each
829
+ * method separately, is what keeps the deprecated twins from silently
830
+ * swallowing a field the type says they accept.
831
+ */
832
+ buildApiFolderPayload(options) {
833
+ const body = {};
799
834
  if (options?.allowedMethods !== void 0) {
800
835
  body.allowed_methods = options.allowedMethods;
801
836
  }
@@ -811,6 +846,25 @@ var ManagementClient = class {
811
846
  if (options?.descriptionSchema !== void 0) {
812
847
  body.description_schema = options.descriptionSchema;
813
848
  }
849
+ if (options?.unscopedLevels !== void 0) {
850
+ body.unscoped_levels = options.unscopedLevels;
851
+ }
852
+ if (options?.unscopedAncestors !== void 0) {
853
+ body.unscoped_ancestors = options.unscopedAncestors;
854
+ }
855
+ return body;
856
+ }
857
+ // ------------------------------------------------------------------ //
858
+ // API ↔ Collection association (canonical)
859
+ // ------------------------------------------------------------------ //
860
+ async listApiCollections(apiKey, params) {
861
+ const key = resolveKey(apiKey);
862
+ return this.request("GET", `${this.paths.apiCollectionsRoot(key)}/`, { params });
863
+ }
864
+ async addApiCollection(apiKey, collectionKey, options) {
865
+ const aKey = resolveKey(apiKey);
866
+ const cKey = resolveKey(collectionKey);
867
+ const body = { folder: cKey, ...this.buildApiFolderPayload(options) };
814
868
  return this.request("POST", `${this.paths.apiCollectionsRoot(aKey)}/`, {
815
869
  jsonBody: body
816
870
  });
@@ -823,22 +877,7 @@ var ManagementClient = class {
823
877
  async updateApiCollection(apiKey, collectionKey, options) {
824
878
  const aKey = resolveKey(apiKey);
825
879
  const cKey = resolveKey(collectionKey);
826
- const body = {};
827
- if (options?.allowedMethods !== void 0) {
828
- body.allowed_methods = options.allowedMethods;
829
- }
830
- if (options?.descriptionGetOne !== void 0) {
831
- body.description_get_one = options.descriptionGetOne;
832
- }
833
- if (options?.descriptionGetMany !== void 0) {
834
- body.description_get_many = options.descriptionGetMany;
835
- }
836
- if (options?.descriptionSearch !== void 0) {
837
- body.description_search = options.descriptionSearch;
838
- }
839
- if (options?.descriptionSchema !== void 0) {
840
- body.description_schema = options.descriptionSchema;
841
- }
880
+ const body = this.buildApiFolderPayload(options);
842
881
  return this.request("PUT", `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`, {
843
882
  jsonBody: body
844
883
  });
@@ -846,11 +885,9 @@ var ManagementClient = class {
846
885
  async removeApiCollection(apiKey, collectionKey) {
847
886
  const aKey = resolveKey(apiKey);
848
887
  const cKey = resolveKey(collectionKey);
849
- await this.request(
850
- "DELETE",
851
- `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`,
852
- { parseJson: false }
853
- );
888
+ await this.request("DELETE", `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`, {
889
+ parseJson: false
890
+ });
854
891
  }
855
892
  // ------------------------------------------------------------------ //
856
893
  // API ↔ Folder association (deprecated; hits legacy /folders/ URL)
@@ -866,22 +903,7 @@ var ManagementClient = class {
866
903
  warnDeprecatedMethod("addApiFolder", "addApiCollection");
867
904
  const aKey = resolveKey(apiKey);
868
905
  const fKey = resolveKey(folderKey);
869
- const body = { folder: fKey };
870
- if (options?.allowedMethods !== void 0) {
871
- body.allowed_methods = options.allowedMethods;
872
- }
873
- if (options?.descriptionGetOne !== void 0) {
874
- body.description_get_one = options.descriptionGetOne;
875
- }
876
- if (options?.descriptionGetMany !== void 0) {
877
- body.description_get_many = options.descriptionGetMany;
878
- }
879
- if (options?.descriptionSearch !== void 0) {
880
- body.description_search = options.descriptionSearch;
881
- }
882
- if (options?.descriptionSchema !== void 0) {
883
- body.description_schema = options.descriptionSchema;
884
- }
906
+ const body = { folder: fKey, ...this.buildApiFolderPayload(options) };
885
907
  return this.request("POST", `${this.paths.apiFoldersRoot(aKey)}/`, { jsonBody: body });
886
908
  }
887
909
  /** @deprecated Use {@link getApiCollection} instead. */
@@ -896,22 +918,7 @@ var ManagementClient = class {
896
918
  warnDeprecatedMethod("updateApiFolder", "updateApiCollection");
897
919
  const aKey = resolveKey(apiKey);
898
920
  const fKey = resolveKey(folderKey);
899
- const body = {};
900
- if (options?.allowedMethods !== void 0) {
901
- body.allowed_methods = options.allowedMethods;
902
- }
903
- if (options?.descriptionGetOne !== void 0) {
904
- body.description_get_one = options.descriptionGetOne;
905
- }
906
- if (options?.descriptionGetMany !== void 0) {
907
- body.description_get_many = options.descriptionGetMany;
908
- }
909
- if (options?.descriptionSearch !== void 0) {
910
- body.description_search = options.descriptionSearch;
911
- }
912
- if (options?.descriptionSchema !== void 0) {
913
- body.description_schema = options.descriptionSchema;
914
- }
921
+ const body = this.buildApiFolderPayload(options);
915
922
  return this.request("PUT", `${this.paths.apiFoldersRoot(aKey)}/${fKey}/`, {
916
923
  jsonBody: body
917
924
  });
@@ -1138,39 +1145,28 @@ var ManagementClient = class {
1138
1145
  if (options?.includeSchema !== void 0) {
1139
1146
  params.include_schema = options.includeSchema;
1140
1147
  }
1141
- return this.request(
1142
- "GET",
1143
- `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1144
- {
1145
- params: Object.keys(params).length > 0 ? params : void 0
1146
- }
1147
- );
1148
+ return this.request("GET", `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`, {
1149
+ params: Object.keys(params).length > 0 ? params : void 0
1150
+ });
1148
1151
  }
1149
1152
  async updateCollectionVersion(collectionKey, versionKey, payload) {
1150
1153
  const cKey = resolveKey(collectionKey);
1151
1154
  const vKey = resolveKey(versionKey);
1152
- return this.request(
1153
- "PUT",
1154
- `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1155
- { jsonBody: payload }
1156
- );
1155
+ return this.request("PUT", `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`, {
1156
+ jsonBody: payload
1157
+ });
1157
1158
  }
1158
1159
  async deleteCollectionVersion(collectionKey, versionKey) {
1159
1160
  const cKey = resolveKey(collectionKey);
1160
1161
  const vKey = resolveKey(versionKey);
1161
- await this.request(
1162
- "DELETE",
1163
- `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1164
- { parseJson: false }
1165
- );
1162
+ await this.request("DELETE", `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`, {
1163
+ parseJson: false
1164
+ });
1166
1165
  }
1167
1166
  async publishCollectionVersion(collectionKey, versionKey) {
1168
1167
  const cKey = resolveKey(collectionKey);
1169
1168
  const vKey = resolveKey(versionKey);
1170
- return this.request(
1171
- "POST",
1172
- `${this.paths.collectionVersionsBase(cKey)}/${vKey}/publish/`
1173
- );
1169
+ return this.request("POST", `${this.paths.collectionVersionsBase(cKey)}/${vKey}/publish/`);
1174
1170
  }
1175
1171
  /**
1176
1172
  * Advance pinned nested fields on a Collection to a target Component version.
@@ -1233,11 +1229,7 @@ var ManagementClient = class {
1233
1229
  if (options.toVersions !== void 0) {
1234
1230
  body.to_versions = options.toVersions;
1235
1231
  }
1236
- return this.request(
1237
- "POST",
1238
- `${this.paths.collectionSyncComponent(cKey)}/`,
1239
- { jsonBody: body }
1240
- );
1232
+ return this.request("POST", `${this.paths.collectionSyncComponent(cKey)}/`, { jsonBody: body });
1241
1233
  }
1242
1234
  // ------------------------------------------------------------------ //
1243
1235
  // Collection schema field operations (canonical)
@@ -1245,47 +1237,37 @@ var ManagementClient = class {
1245
1237
  async listCollectionFields(collectionKey, versionKey, params) {
1246
1238
  const cKey = resolveKey(collectionKey);
1247
1239
  const vKey = resolveKey(versionKey);
1248
- return this.request(
1249
- "GET",
1250
- `${this.paths.collectionSchemaTree(cKey, vKey)}/`,
1251
- { params }
1252
- );
1240
+ return this.request("GET", `${this.paths.collectionSchemaTree(cKey, vKey)}/`, { params });
1253
1241
  }
1254
1242
  async createCollectionField(collectionKey, versionKey, payload) {
1255
1243
  const cKey = resolveKey(collectionKey);
1256
1244
  const vKey = resolveKey(versionKey);
1257
- return this.request(
1258
- "POST",
1259
- `${this.paths.collectionSchemaTree(cKey, vKey)}/`,
1260
- { jsonBody: payload }
1261
- );
1245
+ return this.request("POST", `${this.paths.collectionSchemaTree(cKey, vKey)}/`, {
1246
+ jsonBody: payload
1247
+ });
1262
1248
  }
1263
1249
  async getCollectionField(collectionKey, versionKey, fieldPath) {
1264
1250
  const cKey = resolveKey(collectionKey);
1265
1251
  const vKey = resolveKey(versionKey);
1266
- return this.request(
1267
- "GET",
1268
- `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1269
- { params: { path: fieldPath } }
1270
- );
1252
+ return this.request("GET", `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`, {
1253
+ params: { path: fieldPath }
1254
+ });
1271
1255
  }
1272
1256
  async updateCollectionField(collectionKey, versionKey, fieldPath, payload) {
1273
1257
  const cKey = resolveKey(collectionKey);
1274
1258
  const vKey = resolveKey(versionKey);
1275
- return this.request(
1276
- "PUT",
1277
- `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1278
- { params: { path: fieldPath }, jsonBody: payload }
1279
- );
1259
+ return this.request("PUT", `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`, {
1260
+ params: { path: fieldPath },
1261
+ jsonBody: payload
1262
+ });
1280
1263
  }
1281
1264
  async deleteCollectionField(collectionKey, versionKey, fieldPath) {
1282
1265
  const cKey = resolveKey(collectionKey);
1283
1266
  const vKey = resolveKey(versionKey);
1284
- await this.request(
1285
- "DELETE",
1286
- `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1287
- { params: { path: fieldPath }, parseJson: false }
1288
- );
1267
+ await this.request("DELETE", `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`, {
1268
+ params: { path: fieldPath },
1269
+ parseJson: false
1270
+ });
1289
1271
  }
1290
1272
  // ------------------------------------------------------------------ //
1291
1273
  // Folder operations (deprecated; hit legacy /folders/ URL)
@@ -1989,6 +1971,11 @@ function buildSearchBody(req) {
1989
1971
  return body;
1990
1972
  }
1991
1973
  function mergeExtra(validated, extra) {
1974
+ if ("truncate_text" in extra) {
1975
+ throw new Error(
1976
+ "'truncate_text' is a query parameter, not a body field. Pass it via the 'queryParams' option instead."
1977
+ );
1978
+ }
1992
1979
  const conflicts = [];
1993
1980
  for (const key of Object.keys(extra)) {
1994
1981
  if (SEARCH_REQUEST_KNOWN_KEYS.has(key)) {
@@ -2052,9 +2039,9 @@ var FluxClient = class {
2052
2039
  const path = this.buildPath(folderPath, `/${resourceKey}`);
2053
2040
  return this.transport.request("GET", path, { params });
2054
2041
  }
2055
- async search(folderPath, body) {
2042
+ async search(folderPath, body, options) {
2056
2043
  const path = this.buildPath(folderPath, "/_search");
2057
- return this.transport.request("POST", path, { jsonBody: body });
2044
+ return this.transport.request("POST", path, { jsonBody: body, params: options?.params });
2058
2045
  }
2059
2046
  /**
2060
2047
  * Create a resource in a collection and publish it immediately.
@@ -2098,7 +2085,16 @@ var FluxClient = class {
2098
2085
  }
2099
2086
  /** Semantic search using auto-generated embeddings. */
2100
2087
  async vectorSearch(folderPath, options) {
2101
- const { query, fields, top_k = 10, similarity_threshold, limit, offset, ...rest } = options;
2088
+ const {
2089
+ query,
2090
+ fields,
2091
+ top_k = 10,
2092
+ similarity_threshold,
2093
+ limit,
2094
+ offset,
2095
+ queryParams,
2096
+ ...rest
2097
+ } = options;
2102
2098
  const extra = stripUndefined(rest);
2103
2099
  const vs = { query, fields, top_k, similarity_threshold };
2104
2100
  const req = {
@@ -2108,7 +2104,7 @@ var FluxClient = class {
2108
2104
  offset
2109
2105
  };
2110
2106
  const body = mergeExtra(buildSearchBody(req), extra);
2111
- return this.search(folderPath, body);
2107
+ return this.search(folderPath, body, { params: queryParams });
2112
2108
  }
2113
2109
  /** Search using custom pre-computed embeddings. */
2114
2110
  async vectorFieldSearch(folderPath, options) {
@@ -2119,6 +2115,7 @@ var FluxClient = class {
2119
2115
  similarity_threshold,
2120
2116
  limit,
2121
2117
  offset,
2118
+ queryParams,
2122
2119
  ...rest
2123
2120
  } = options;
2124
2121
  const extra = stripUndefined(rest);
@@ -2130,7 +2127,7 @@ var FluxClient = class {
2130
2127
  offset
2131
2128
  };
2132
2129
  const body = mergeExtra(buildSearchBody(req), extra);
2133
- return this.search(folderPath, body);
2130
+ return this.search(folderPath, body, { params: queryParams });
2134
2131
  }
2135
2132
  /** Blended text + vector search with configurable weights. */
2136
2133
  async hybridSearch(folderPath, options) {
@@ -2145,6 +2142,7 @@ var FluxClient = class {
2145
2142
  rerank_results = true,
2146
2143
  limit,
2147
2144
  offset,
2145
+ queryParams,
2148
2146
  ...rest
2149
2147
  } = options;
2150
2148
  const extra = stripUndefined(rest);
@@ -2159,7 +2157,7 @@ var FluxClient = class {
2159
2157
  offset
2160
2158
  };
2161
2159
  const body = mergeExtra(buildSearchBody(req), extra);
2162
- return this.search(folderPath, body);
2160
+ return this.search(folderPath, body, { params: queryParams });
2163
2161
  }
2164
2162
  /** Text search with results boosted by vector similarity. */
2165
2163
  async boostedSearch(folderPath, options) {
@@ -2175,6 +2173,7 @@ var FluxClient = class {
2175
2173
  max_boost_results = 20,
2176
2174
  limit,
2177
2175
  offset,
2176
+ queryParams,
2178
2177
  ...rest
2179
2178
  } = options;
2180
2179
  const extra = stripUndefined(rest);
@@ -2211,7 +2210,7 @@ var FluxClient = class {
2211
2210
  offset
2212
2211
  };
2213
2212
  const body = mergeExtra(buildSearchBody(req), extra);
2214
- return this.search(folderPath, body);
2213
+ return this.search(folderPath, body, { params: queryParams });
2215
2214
  }
2216
2215
  async getRouter() {
2217
2216
  const path = `/${this.apiPrefix}/_router`;