@foxnose/sdk 0.3.0 → 0.5.0

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.cjs CHANGED
@@ -21,8 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AnonymousAuth: () => AnonymousAuth,
24
+ CollectionNotWritableError: () => CollectionNotWritableError,
25
+ ContentValidationFailedError: () => ContentValidationFailedError,
24
26
  DEFAULT_RETRY_CONFIG: () => DEFAULT_RETRY_CONFIG,
25
27
  DEFAULT_USER_AGENT: () => DEFAULT_USER_AGENT,
28
+ ExternalIdConflictError: () => ExternalIdConflictError,
26
29
  FluxClient: () => FluxClient,
27
30
  FoxnoseAPIError: () => FoxnoseAPIError,
28
31
  FoxnoseAuthError: () => FoxnoseAuthError,
@@ -31,14 +34,20 @@ __export(index_exports, {
31
34
  HttpTransport: () => HttpTransport,
32
35
  JWTAuth: () => JWTAuth,
33
36
  ManagementClient: () => ManagementClient,
37
+ PlanExhaustedError: () => PlanExhaustedError,
38
+ PlanLimitExceededError: () => PlanLimitExceededError,
39
+ RateLimitExceededError: () => RateLimitExceededError,
34
40
  SDK_VERSION: () => SDK_VERSION,
35
41
  SearchMode: () => SearchMode,
36
42
  SecureKeyAuth: () => SecureKeyAuth,
37
43
  SimpleKeyAuth: () => SimpleKeyAuth,
44
+ SpendCapExceededError: () => SpendCapExceededError,
38
45
  StaticTokenProvider: () => StaticTokenProvider,
46
+ UpstreamError: () => UpstreamError,
39
47
  VERSION: () => SDK_VERSION,
40
48
  buildSearchBody: () => buildSearchBody,
41
49
  createConfig: () => createConfig,
50
+ nestedFieldMeta: () => nestedFieldMeta,
42
51
  resolveKey: () => resolveKey
43
52
  });
44
53
  module.exports = __toCommonJS(index_exports);
@@ -108,6 +117,167 @@ var FoxnoseAPIError = class extends FoxnoseError {
108
117
  this.responseBody = options.responseBody;
109
118
  }
110
119
  };
120
+ var SpendCapExceededError = class extends FoxnoseAPIError {
121
+ /** Spend cap in USD, or null when unset on the server side. */
122
+ capUsd;
123
+ /** ISO timestamp when the current billing cycle resets. */
124
+ cycleResetsAt;
125
+ /** URL where the spend cap can be raised. */
126
+ raiseCapUrl;
127
+ constructor(options) {
128
+ super(options);
129
+ this.name = "SpendCapExceededError";
130
+ this.capUsd = options.capUsd;
131
+ this.cycleResetsAt = options.cycleResetsAt;
132
+ this.raiseCapUrl = options.raiseCapUrl;
133
+ }
134
+ };
135
+ var PlanExhaustedError = class extends FoxnoseAPIError {
136
+ /** Usage axis that was exhausted (e.g. retrievals, writes, data_storage, vector_storage). */
137
+ axis;
138
+ /** ISO timestamp when the usage window resets. */
139
+ windowResetsAt;
140
+ /** URL where the plan can be upgraded. */
141
+ upgradeUrl;
142
+ constructor(options) {
143
+ super(options);
144
+ this.name = "PlanExhaustedError";
145
+ this.axis = options.axis;
146
+ this.windowResetsAt = options.windowResetsAt;
147
+ this.upgradeUrl = options.upgradeUrl;
148
+ }
149
+ };
150
+ var PlanLimitExceededError = class extends FoxnoseAPIError {
151
+ /** Entity whose limit was exceeded (e.g. collections, environments, api_keys). */
152
+ entity;
153
+ /** Maximum allowed by the current plan. */
154
+ limit;
155
+ /** Current count that triggered the error. */
156
+ current;
157
+ /** URL where the plan can be upgraded, if provided. */
158
+ upgradeUrl;
159
+ constructor(options) {
160
+ super(options);
161
+ this.name = "PlanLimitExceededError";
162
+ this.entity = options.entity;
163
+ this.limit = options.limit;
164
+ this.current = options.current;
165
+ this.upgradeUrl = options.upgradeUrl;
166
+ }
167
+ };
168
+ var RateLimitExceededError = class extends FoxnoseAPIError {
169
+ /** Seconds to wait before retrying, from the Retry-After header. */
170
+ retryAfter;
171
+ constructor(options) {
172
+ super(options);
173
+ this.name = "RateLimitExceededError";
174
+ this.retryAfter = options.retryAfter;
175
+ }
176
+ };
177
+ var CollectionNotWritableError = class extends FoxnoseAPIError {
178
+ constructor(options) {
179
+ super(options);
180
+ this.name = "CollectionNotWritableError";
181
+ }
182
+ };
183
+ var ExternalIdConflictError = class extends FoxnoseAPIError {
184
+ constructor(options) {
185
+ super(options);
186
+ this.name = "ExternalIdConflictError";
187
+ }
188
+ };
189
+ var ContentValidationFailedError = class extends FoxnoseAPIError {
190
+ /** Individual validation problems; each includes a `json_path`. */
191
+ errors;
192
+ /** True when the server capped a very large error list. */
193
+ errorsTruncated;
194
+ constructor(options) {
195
+ super(options);
196
+ this.name = "ContentValidationFailedError";
197
+ this.errors = options.errors ?? [];
198
+ this.errorsTruncated = options.errorsTruncated ?? false;
199
+ }
200
+ };
201
+ var UpstreamError = class extends FoxnoseAPIError {
202
+ constructor(options) {
203
+ super(options);
204
+ this.name = "UpstreamError";
205
+ }
206
+ };
207
+ function isPlainObject(value) {
208
+ return typeof value === "object" && value !== null && !Array.isArray(value);
209
+ }
210
+ function getHeader(headers, name) {
211
+ if (!headers) {
212
+ return void 0;
213
+ }
214
+ const target = name.toLowerCase();
215
+ for (const [key, value] of Object.entries(headers)) {
216
+ if (key.toLowerCase() === target) {
217
+ return value;
218
+ }
219
+ }
220
+ return void 0;
221
+ }
222
+ function buildAPIError(options) {
223
+ const { statusCode, errorCode, detail, responseHeaders, responseBody } = options;
224
+ const body = isPlainObject(responseBody) ? responseBody : void 0;
225
+ if (statusCode === 402 && errorCode === "spend_cap_reached" && body) {
226
+ return new SpendCapExceededError({
227
+ ...options,
228
+ message: "message" in body ? options.message : "Spend cap reached",
229
+ capUsd: typeof body.cap_usd === "number" ? body.cap_usd : body.cap_usd === null ? null : void 0,
230
+ cycleResetsAt: typeof body.cycle_resets_at === "string" ? body.cycle_resets_at : void 0,
231
+ raiseCapUrl: typeof body.raise_cap_url === "string" ? body.raise_cap_url : void 0
232
+ });
233
+ }
234
+ if (statusCode === 402 && errorCode === "plan_exhausted" && body) {
235
+ return new PlanExhaustedError({
236
+ ...options,
237
+ message: "message" in body ? options.message : "Plan allowance exhausted",
238
+ axis: typeof body.axis === "string" ? body.axis : void 0,
239
+ windowResetsAt: typeof body.window_resets_at === "string" ? body.window_resets_at : void 0,
240
+ upgradeUrl: typeof body.upgrade_url === "string" ? body.upgrade_url : void 0
241
+ });
242
+ }
243
+ if (statusCode === 403 && errorCode === "plan_limit_exceeded") {
244
+ const d = isPlainObject(detail) ? detail : {};
245
+ return new PlanLimitExceededError({
246
+ ...options,
247
+ entity: typeof d.entity === "string" ? d.entity : void 0,
248
+ limit: typeof d.limit === "number" ? d.limit : void 0,
249
+ current: typeof d.current === "number" ? d.current : void 0,
250
+ upgradeUrl: typeof d.upgrade_url === "string" ? d.upgrade_url : void 0
251
+ });
252
+ }
253
+ if (statusCode === 429 && errorCode === "rate_limited") {
254
+ const raw = getHeader(responseHeaders, "Retry-After");
255
+ const parsed = raw !== void 0 ? Number(raw) : NaN;
256
+ return new RateLimitExceededError({
257
+ ...options,
258
+ retryAfter: Number.isNaN(parsed) ? void 0 : parsed
259
+ });
260
+ }
261
+ if (statusCode === 403 && errorCode === "collection_not_writable") {
262
+ return new CollectionNotWritableError(options);
263
+ }
264
+ if (statusCode === 409 && errorCode === "external_id_conflict") {
265
+ return new ExternalIdConflictError(options);
266
+ }
267
+ if (statusCode === 422 && errorCode === "content_validation_failed") {
268
+ const d = isPlainObject(detail) ? detail : {};
269
+ const errors = Array.isArray(d.errors) ? d.errors : typeof d.json_path === "string" ? [d] : [];
270
+ return new ContentValidationFailedError({
271
+ ...options,
272
+ errors,
273
+ errorsTruncated: d.errors_truncated === true
274
+ });
275
+ }
276
+ if (statusCode === 502 && errorCode === "upstream_error") {
277
+ return new UpstreamError(options);
278
+ }
279
+ return new FoxnoseAPIError(options);
280
+ }
111
281
  var FoxnoseAuthError = class extends FoxnoseError {
112
282
  constructor(message) {
113
283
  super(message);
@@ -192,7 +362,7 @@ var DEFAULT_RETRY_CONFIG = {
192
362
  statusCodes: [408, 425, 429, 500, 502, 503, 504],
193
363
  methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
194
364
  };
195
- var SDK_VERSION = "0.3.0";
365
+ var SDK_VERSION = "0.5.0";
196
366
  var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
197
367
  function createConfig(options) {
198
368
  if (!options.baseUrl) {
@@ -321,6 +491,7 @@ var HttpTransport = class {
321
491
  }
322
492
  }
323
493
  async sendWithRetries(method, path, options) {
494
+ const allowRetries = options?.allowRetries !== false;
324
495
  for (let attempt = 1; attempt <= this.retry.attempts; attempt++) {
325
496
  const { url, init } = this.buildRequest(method, path, options);
326
497
  const controller = new AbortController();
@@ -331,7 +502,7 @@ var HttpTransport = class {
331
502
  response = await fetch(url, init);
332
503
  } catch (err) {
333
504
  clearTimeout(timeoutId);
334
- const delay = this.handleTransportError(err, method, attempt);
505
+ const delay = this.handleTransportError(err, method, attempt, !allowRetries);
335
506
  if (delay > 0) {
336
507
  await this.sleep(delay);
337
508
  }
@@ -340,7 +511,7 @@ var HttpTransport = class {
340
511
  clearTimeout(timeoutId);
341
512
  }
342
513
  if (response.status >= 400) {
343
- if (this.shouldRetry(method, response.status) && attempt < this.retry.attempts) {
514
+ if (allowRetries && this.shouldRetry(method, response.status) && attempt < this.retry.attempts) {
344
515
  const delay = this.computeDelay(attempt, response.headers.get("Retry-After"));
345
516
  if (delay > 0) {
346
517
  await this.sleep(delay);
@@ -353,8 +524,8 @@ var HttpTransport = class {
353
524
  }
354
525
  throw new FoxnoseTransportError("All retry attempts exhausted");
355
526
  }
356
- handleTransportError(err, method, attempt) {
357
- const canRetry = this.retry.methods.includes(method.toUpperCase()) && attempt < this.retry.attempts;
527
+ handleTransportError(err, method, attempt, forbidRetry = false) {
528
+ const canRetry = !forbidRetry && this.retry.methods.includes(method.toUpperCase()) && attempt < this.retry.attempts;
358
529
  if (!canRetry) {
359
530
  const message = err instanceof Error ? err.message : String(err);
360
531
  throw new FoxnoseTransportError(message);
@@ -372,10 +543,12 @@ var HttpTransport = class {
372
543
  if (text) {
373
544
  try {
374
545
  const payload = JSON.parse(text);
375
- message = payload.message ?? message;
376
- errorCode = payload.error_code;
377
- detail = payload.detail;
378
546
  body = payload;
547
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
548
+ message = payload.message ?? message;
549
+ errorCode = payload.error_code;
550
+ detail = payload.detail;
551
+ }
379
552
  } catch {
380
553
  body = text;
381
554
  }
@@ -386,7 +559,7 @@ var HttpTransport = class {
386
559
  response.headers.forEach((value, key) => {
387
560
  responseHeaders[key] = value;
388
561
  });
389
- throw new FoxnoseAPIError({
562
+ throw buildAPIError({
390
563
  message: message || "API request failed",
391
564
  statusCode: response.status,
392
565
  errorCode,
@@ -400,7 +573,38 @@ var HttpTransport = class {
400
573
  }
401
574
  };
402
575
 
576
+ // src/_deprecation.ts
577
+ var warned = /* @__PURE__ */ new Set();
578
+ function warnDeprecatedMethod(oldName, newName, removal = "1.0") {
579
+ if (warned.has(oldName)) {
580
+ return;
581
+ }
582
+ warned.add(oldName);
583
+ console.warn(
584
+ `@foxnose/sdk: ${oldName}() is deprecated; use ${newName}() instead. ${oldName}() will be removed in @foxnose/sdk ${removal}.`
585
+ );
586
+ }
587
+
403
588
  // src/management/models.ts
589
+ function nestedFieldMeta(opts) {
590
+ if (opts.extra) {
591
+ const reserved = ["component", "component_version", "auto_update"];
592
+ const collisions = reserved.filter(
593
+ (k) => Object.prototype.hasOwnProperty.call(opts.extra, k)
594
+ );
595
+ if (collisions.length > 0) {
596
+ throw new Error(
597
+ `nestedFieldMeta: 'extra' must not include reserved keys: ${collisions.join(", ")}`
598
+ );
599
+ }
600
+ }
601
+ return {
602
+ ...opts.extra ?? {},
603
+ component: opts.component,
604
+ component_version: opts.componentVersion,
605
+ auto_update: opts.autoUpdate ?? false
606
+ };
607
+ }
404
608
  function resolveKey(value) {
405
609
  if (typeof value === "string") {
406
610
  return value;
@@ -420,11 +624,18 @@ function managementPaths(environmentKey) {
420
624
  projectRoot: (orgKey, projectKey) => `/organizations/${orgKey}/projects/${projectKey}`,
421
625
  environmentsBase: (orgKey, projectKey) => `/organizations/${orgKey}/projects/${projectKey}/environments`,
422
626
  environmentRoot: (orgKey, projectKey, envKey) => `/organizations/${orgKey}/projects/${projectKey}/environments/${envKey}`,
423
- // Folder paths
627
+ // Folder paths (deprecated — see Collection paths below).
424
628
  foldersTreeRoot: () => `/v1/${environmentKey}/folders/tree`,
425
629
  foldersTreeItem: () => `/v1/${environmentKey}/folders/tree/folder`,
426
630
  folderVersionsBase: (folderKey) => `/v1/${environmentKey}/folders/${folderKey}/model/versions`,
427
631
  folderSchemaTree: (folderKey, versionKey) => `/v1/${environmentKey}/folders/${folderKey}/model/versions/${versionKey}/schema/tree`,
632
+ // Collection paths (canonical going forward; folder paths above hit the
633
+ // deprecated /folders/ URL alias on the server side).
634
+ collectionsTreeRoot: () => `/v1/${environmentKey}/collections/tree`,
635
+ collectionsTreeItem: () => `/v1/${environmentKey}/collections/tree/collection`,
636
+ collectionVersionsBase: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/model/versions`,
637
+ collectionSchemaTree: (collectionKey, versionKey) => `/v1/${environmentKey}/collections/${collectionKey}/model/versions/${versionKey}/schema/tree`,
638
+ collectionSyncComponent: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/sync_component`,
428
639
  // Component paths
429
640
  componentsRoot: () => `/v1/${environmentKey}/components`,
430
641
  componentRoot: (componentKey) => `/v1/${environmentKey}/components/${componentKey}`,
@@ -443,6 +654,7 @@ function managementPaths(environmentKey) {
443
654
  apisRoot: () => `/v1/${environmentKey}/api`,
444
655
  apiRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}`,
445
656
  apiFoldersRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}/folders`,
657
+ apiCollectionsRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}/collections`,
446
658
  // Management role paths
447
659
  managementRolesRoot: () => `/v1/${environmentKey}/permissions/management-api/roles`,
448
660
  managementRoleRoot: (roleKey) => `/v1/${environmentKey}/permissions/management-api/roles/${roleKey}`,
@@ -628,13 +840,84 @@ var ManagementClient = class {
628
840
  await this.request("DELETE", `${this.paths.apiRoot(key)}/`, { parseJson: false });
629
841
  }
630
842
  // ------------------------------------------------------------------ //
631
- // API Folder associations
843
+ // API ↔ Collection association (canonical)
632
844
  // ------------------------------------------------------------------ //
845
+ async listApiCollections(apiKey, params) {
846
+ const key = resolveKey(apiKey);
847
+ return this.request("GET", `${this.paths.apiCollectionsRoot(key)}/`, { params });
848
+ }
849
+ async addApiCollection(apiKey, collectionKey, options) {
850
+ const aKey = resolveKey(apiKey);
851
+ const cKey = resolveKey(collectionKey);
852
+ const body = { folder: cKey };
853
+ if (options?.allowedMethods !== void 0) {
854
+ body.allowed_methods = options.allowedMethods;
855
+ }
856
+ if (options?.descriptionGetOne !== void 0) {
857
+ body.description_get_one = options.descriptionGetOne;
858
+ }
859
+ if (options?.descriptionGetMany !== void 0) {
860
+ body.description_get_many = options.descriptionGetMany;
861
+ }
862
+ if (options?.descriptionSearch !== void 0) {
863
+ body.description_search = options.descriptionSearch;
864
+ }
865
+ if (options?.descriptionSchema !== void 0) {
866
+ body.description_schema = options.descriptionSchema;
867
+ }
868
+ return this.request("POST", `${this.paths.apiCollectionsRoot(aKey)}/`, {
869
+ jsonBody: body
870
+ });
871
+ }
872
+ async getApiCollection(apiKey, collectionKey) {
873
+ const aKey = resolveKey(apiKey);
874
+ const cKey = resolveKey(collectionKey);
875
+ return this.request("GET", `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`);
876
+ }
877
+ async updateApiCollection(apiKey, collectionKey, options) {
878
+ const aKey = resolveKey(apiKey);
879
+ const cKey = resolveKey(collectionKey);
880
+ const body = {};
881
+ if (options?.allowedMethods !== void 0) {
882
+ body.allowed_methods = options.allowedMethods;
883
+ }
884
+ if (options?.descriptionGetOne !== void 0) {
885
+ body.description_get_one = options.descriptionGetOne;
886
+ }
887
+ if (options?.descriptionGetMany !== void 0) {
888
+ body.description_get_many = options.descriptionGetMany;
889
+ }
890
+ if (options?.descriptionSearch !== void 0) {
891
+ body.description_search = options.descriptionSearch;
892
+ }
893
+ if (options?.descriptionSchema !== void 0) {
894
+ body.description_schema = options.descriptionSchema;
895
+ }
896
+ return this.request("PUT", `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`, {
897
+ jsonBody: body
898
+ });
899
+ }
900
+ async removeApiCollection(apiKey, collectionKey) {
901
+ const aKey = resolveKey(apiKey);
902
+ const cKey = resolveKey(collectionKey);
903
+ await this.request(
904
+ "DELETE",
905
+ `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`,
906
+ { parseJson: false }
907
+ );
908
+ }
909
+ // ------------------------------------------------------------------ //
910
+ // API ↔ Folder association (deprecated; hits legacy /folders/ URL)
911
+ // ------------------------------------------------------------------ //
912
+ /** @deprecated Use {@link listApiCollections} instead. */
633
913
  async listApiFolders(apiKey, params) {
914
+ warnDeprecatedMethod("listApiFolders", "listApiCollections");
634
915
  const key = resolveKey(apiKey);
635
916
  return this.request("GET", `${this.paths.apiFoldersRoot(key)}/`, { params });
636
917
  }
918
+ /** @deprecated Use {@link addApiCollection} instead. */
637
919
  async addApiFolder(apiKey, folderKey, options) {
920
+ warnDeprecatedMethod("addApiFolder", "addApiCollection");
638
921
  const aKey = resolveKey(apiKey);
639
922
  const fKey = resolveKey(folderKey);
640
923
  const body = { folder: fKey };
@@ -655,12 +938,16 @@ var ManagementClient = class {
655
938
  }
656
939
  return this.request("POST", `${this.paths.apiFoldersRoot(aKey)}/`, { jsonBody: body });
657
940
  }
941
+ /** @deprecated Use {@link getApiCollection} instead. */
658
942
  async getApiFolder(apiKey, folderKey) {
943
+ warnDeprecatedMethod("getApiFolder", "getApiCollection");
659
944
  const aKey = resolveKey(apiKey);
660
945
  const fKey = resolveKey(folderKey);
661
946
  return this.request("GET", `${this.paths.apiFoldersRoot(aKey)}/${fKey}/`);
662
947
  }
948
+ /** @deprecated Use {@link updateApiCollection} instead. */
663
949
  async updateApiFolder(apiKey, folderKey, options) {
950
+ warnDeprecatedMethod("updateApiFolder", "updateApiCollection");
664
951
  const aKey = resolveKey(apiKey);
665
952
  const fKey = resolveKey(folderKey);
666
953
  const body = {};
@@ -683,7 +970,9 @@ var ManagementClient = class {
683
970
  jsonBody: body
684
971
  });
685
972
  }
973
+ /** @deprecated Use {@link removeApiCollection} instead. */
686
974
  async removeApiFolder(apiKey, folderKey) {
975
+ warnDeprecatedMethod("removeApiFolder", "removeApiCollection");
687
976
  const aKey = resolveKey(apiKey);
688
977
  const fKey = resolveKey(folderKey);
689
978
  await this.request("DELETE", `${this.paths.apiFoldersRoot(aKey)}/${fKey}/`, {
@@ -835,39 +1124,271 @@ var ManagementClient = class {
835
1124
  });
836
1125
  }
837
1126
  // ------------------------------------------------------------------ //
838
- // Folder operations
1127
+ // Collection operations (canonical)
1128
+ // ------------------------------------------------------------------ //
1129
+ async listCollections(params) {
1130
+ return this.request("GET", `${this.paths.collectionsTreeRoot()}/`, { params });
1131
+ }
1132
+ async getCollection(collectionKey) {
1133
+ const key = resolveKey(collectionKey);
1134
+ return this.request("GET", `${this.paths.collectionsTreeItem()}/`, {
1135
+ params: { key }
1136
+ });
1137
+ }
1138
+ async getCollectionByPath(path) {
1139
+ return this.request("GET", `${this.paths.collectionsTreeItem()}/`, {
1140
+ params: { path }
1141
+ });
1142
+ }
1143
+ async listCollectionTree(options) {
1144
+ const params = {};
1145
+ if (options?.key) params.key = options.key;
1146
+ if (options?.mode) params.mode = options.mode;
1147
+ return this.request("GET", `${this.paths.collectionsTreeRoot()}/`, { params });
1148
+ }
1149
+ async createCollection(payload) {
1150
+ return this.request("POST", `${this.paths.collectionsTreeRoot()}/`, {
1151
+ jsonBody: payload
1152
+ });
1153
+ }
1154
+ async updateCollection(collectionKey, payload) {
1155
+ const key = resolveKey(collectionKey);
1156
+ return this.request("PUT", `${this.paths.collectionsTreeItem()}/`, {
1157
+ params: { key },
1158
+ jsonBody: payload
1159
+ });
1160
+ }
1161
+ async deleteCollection(collectionKey) {
1162
+ const key = resolveKey(collectionKey);
1163
+ await this.request("DELETE", `${this.paths.collectionsTreeItem()}/`, {
1164
+ params: { key },
1165
+ parseJson: false
1166
+ });
1167
+ }
1168
+ // ------------------------------------------------------------------ //
1169
+ // Collection schema version operations (canonical)
839
1170
  // ------------------------------------------------------------------ //
1171
+ async listCollectionVersions(collectionKey, params) {
1172
+ const key = resolveKey(collectionKey);
1173
+ return this.request("GET", `${this.paths.collectionVersionsBase(key)}/`, {
1174
+ params
1175
+ });
1176
+ }
1177
+ async createCollectionVersion(collectionKey, payload, options) {
1178
+ const key = resolveKey(collectionKey);
1179
+ const params = {};
1180
+ if (options?.copyFrom) {
1181
+ params.copy_from = resolveKey(options.copyFrom);
1182
+ }
1183
+ return this.request("POST", `${this.paths.collectionVersionsBase(key)}/`, {
1184
+ jsonBody: payload,
1185
+ params: Object.keys(params).length > 0 ? params : void 0
1186
+ });
1187
+ }
1188
+ async getCollectionVersion(collectionKey, versionKey, options) {
1189
+ const cKey = resolveKey(collectionKey);
1190
+ const vKey = resolveKey(versionKey);
1191
+ const params = {};
1192
+ if (options?.includeSchema !== void 0) {
1193
+ params.include_schema = options.includeSchema;
1194
+ }
1195
+ return this.request(
1196
+ "GET",
1197
+ `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1198
+ {
1199
+ params: Object.keys(params).length > 0 ? params : void 0
1200
+ }
1201
+ );
1202
+ }
1203
+ async updateCollectionVersion(collectionKey, versionKey, payload) {
1204
+ const cKey = resolveKey(collectionKey);
1205
+ const vKey = resolveKey(versionKey);
1206
+ return this.request(
1207
+ "PUT",
1208
+ `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1209
+ { jsonBody: payload }
1210
+ );
1211
+ }
1212
+ async deleteCollectionVersion(collectionKey, versionKey) {
1213
+ const cKey = resolveKey(collectionKey);
1214
+ const vKey = resolveKey(versionKey);
1215
+ await this.request(
1216
+ "DELETE",
1217
+ `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1218
+ { parseJson: false }
1219
+ );
1220
+ }
1221
+ async publishCollectionVersion(collectionKey, versionKey) {
1222
+ const cKey = resolveKey(collectionKey);
1223
+ const vKey = resolveKey(versionKey);
1224
+ return this.request(
1225
+ "POST",
1226
+ `${this.paths.collectionVersionsBase(cKey)}/${vKey}/publish/`
1227
+ );
1228
+ }
1229
+ /**
1230
+ * Advance pinned nested fields on a Collection to a target Component version.
1231
+ *
1232
+ * Creates a new published Collection schema version with the affected
1233
+ * `meta.component_version` pins advanced. Fields with `auto_update=true`
1234
+ * and fields already at the requested target version are reported in
1235
+ * `skipped` rather than advanced.
1236
+ *
1237
+ * @param collectionKey The Collection to sync.
1238
+ * @param options.fieldPaths Optional list of nested field paths to advance.
1239
+ * When omitted, every pinned (`auto_update=false`) nested field on the
1240
+ * Collection's current version is considered.
1241
+ * @param options.toVersions Optional per-path override mapping field path
1242
+ * to target Component Version UID. Paths not in this mapping advance to
1243
+ * the referenced Component's `current_version`. When both `fieldPaths`
1244
+ * and `toVersions` are supplied, every key in `toVersions` must also
1245
+ * appear in `fieldPaths`.
1246
+ *
1247
+ * @returns Summary of synced and skipped paths, plus the new
1248
+ * `schema_version` UID (`null` if no paths were advanced).
1249
+ *
1250
+ * @throws `Error` locally (before any HTTP request) when both `fieldPaths`
1251
+ * and `toVersions` are supplied AND `toVersions` contains a key that is
1252
+ * not in `fieldPaths` (mirrors the server-side validator so the misuse
1253
+ * surfaces at the call-site).
1254
+ * @throws `FoxnoseApiError` on:
1255
+ * - 409 `component_sync_conflict` — target version would break existing resources
1256
+ * - 422 `too_many_versions` — Collection schema quota exhausted
1257
+ * - 422 `validation_error` — request body invalid
1258
+ * - 404 — Collection or specified target version missing
1259
+ *
1260
+ * @example
1261
+ * ```ts
1262
+ * // Advance every pinned nested field to its Component's current version.
1263
+ * await client.syncCollectionComponent('articles');
1264
+ *
1265
+ * // Advance a specific path to a chosen Component version.
1266
+ * await client.syncCollectionComponent('articles', {
1267
+ * fieldPaths: ['seo'],
1268
+ * toVersions: { seo: 'ver-def67890' },
1269
+ * });
1270
+ * ```
1271
+ */
1272
+ async syncCollectionComponent(collectionKey, options = {}) {
1273
+ const cKey = resolveKey(collectionKey);
1274
+ if (options.fieldPaths !== void 0 && options.toVersions !== void 0) {
1275
+ const fieldPathSet = new Set(options.fieldPaths);
1276
+ const extras = Object.keys(options.toVersions).filter((k) => !fieldPathSet.has(k)).sort();
1277
+ if (extras.length > 0) {
1278
+ throw new Error(
1279
+ `toVersions includes paths not present in fieldPaths: [${extras.join(", ")}]`
1280
+ );
1281
+ }
1282
+ }
1283
+ const body = {};
1284
+ if (options.fieldPaths !== void 0) {
1285
+ body.field_paths = options.fieldPaths;
1286
+ }
1287
+ if (options.toVersions !== void 0) {
1288
+ body.to_versions = options.toVersions;
1289
+ }
1290
+ return this.request(
1291
+ "POST",
1292
+ `${this.paths.collectionSyncComponent(cKey)}/`,
1293
+ { jsonBody: body }
1294
+ );
1295
+ }
1296
+ // ------------------------------------------------------------------ //
1297
+ // Collection schema field operations (canonical)
1298
+ // ------------------------------------------------------------------ //
1299
+ async listCollectionFields(collectionKey, versionKey, params) {
1300
+ const cKey = resolveKey(collectionKey);
1301
+ const vKey = resolveKey(versionKey);
1302
+ return this.request(
1303
+ "GET",
1304
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/`,
1305
+ { params }
1306
+ );
1307
+ }
1308
+ async createCollectionField(collectionKey, versionKey, payload) {
1309
+ const cKey = resolveKey(collectionKey);
1310
+ const vKey = resolveKey(versionKey);
1311
+ return this.request(
1312
+ "POST",
1313
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/`,
1314
+ { jsonBody: payload }
1315
+ );
1316
+ }
1317
+ async getCollectionField(collectionKey, versionKey, fieldPath) {
1318
+ const cKey = resolveKey(collectionKey);
1319
+ const vKey = resolveKey(versionKey);
1320
+ return this.request(
1321
+ "GET",
1322
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1323
+ { params: { path: fieldPath } }
1324
+ );
1325
+ }
1326
+ async updateCollectionField(collectionKey, versionKey, fieldPath, payload) {
1327
+ const cKey = resolveKey(collectionKey);
1328
+ const vKey = resolveKey(versionKey);
1329
+ return this.request(
1330
+ "PUT",
1331
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1332
+ { params: { path: fieldPath }, jsonBody: payload }
1333
+ );
1334
+ }
1335
+ async deleteCollectionField(collectionKey, versionKey, fieldPath) {
1336
+ const cKey = resolveKey(collectionKey);
1337
+ const vKey = resolveKey(versionKey);
1338
+ await this.request(
1339
+ "DELETE",
1340
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1341
+ { params: { path: fieldPath }, parseJson: false }
1342
+ );
1343
+ }
1344
+ // ------------------------------------------------------------------ //
1345
+ // Folder operations (deprecated; hit legacy /folders/ URL)
1346
+ // ------------------------------------------------------------------ //
1347
+ /** @deprecated Use {@link listCollections} instead. */
840
1348
  async listFolders(params) {
1349
+ warnDeprecatedMethod("listFolders", "listCollections");
841
1350
  return this.request("GET", `${this.paths.foldersTreeRoot()}/`, { params });
842
1351
  }
1352
+ /** @deprecated Use {@link getCollection} instead. */
843
1353
  async getFolder(folderKey) {
1354
+ warnDeprecatedMethod("getFolder", "getCollection");
844
1355
  const key = resolveKey(folderKey);
845
1356
  return this.request("GET", `${this.paths.foldersTreeItem()}/`, {
846
1357
  params: { key }
847
1358
  });
848
1359
  }
1360
+ /** @deprecated Use {@link getCollectionByPath} instead. */
849
1361
  async getFolderByPath(path) {
1362
+ warnDeprecatedMethod("getFolderByPath", "getCollectionByPath");
850
1363
  return this.request("GET", `${this.paths.foldersTreeItem()}/`, {
851
1364
  params: { path }
852
1365
  });
853
1366
  }
1367
+ /** @deprecated Use {@link listCollectionTree} instead. */
854
1368
  async listFolderTree(options) {
1369
+ warnDeprecatedMethod("listFolderTree", "listCollectionTree");
855
1370
  const params = {};
856
1371
  if (options?.key) params.key = options.key;
857
1372
  if (options?.mode) params.mode = options.mode;
858
1373
  return this.request("GET", `${this.paths.foldersTreeRoot()}/`, { params });
859
1374
  }
1375
+ /** @deprecated Use {@link createCollection} instead. */
860
1376
  async createFolder(payload) {
1377
+ warnDeprecatedMethod("createFolder", "createCollection");
861
1378
  return this.request("POST", `${this.paths.foldersTreeRoot()}/`, { jsonBody: payload });
862
1379
  }
1380
+ /** @deprecated Use {@link updateCollection} instead. */
863
1381
  async updateFolder(folderKey, payload) {
1382
+ warnDeprecatedMethod("updateFolder", "updateCollection");
864
1383
  const key = resolveKey(folderKey);
865
1384
  return this.request("PUT", `${this.paths.foldersTreeItem()}/`, {
866
1385
  params: { key },
867
1386
  jsonBody: payload
868
1387
  });
869
1388
  }
1389
+ /** @deprecated Use {@link deleteCollection} instead. */
870
1390
  async deleteFolder(folderKey) {
1391
+ warnDeprecatedMethod("deleteFolder", "deleteCollection");
871
1392
  const key = resolveKey(folderKey);
872
1393
  await this.request("DELETE", `${this.paths.foldersTreeItem()}/`, {
873
1394
  params: { key },
@@ -875,13 +1396,17 @@ var ManagementClient = class {
875
1396
  });
876
1397
  }
877
1398
  // ------------------------------------------------------------------ //
878
- // Folder version operations
1399
+ // Folder version operations (deprecated)
879
1400
  // ------------------------------------------------------------------ //
1401
+ /** @deprecated Use {@link listCollectionVersions} instead. */
880
1402
  async listFolderVersions(folderKey, params) {
1403
+ warnDeprecatedMethod("listFolderVersions", "listCollectionVersions");
881
1404
  const key = resolveKey(folderKey);
882
1405
  return this.request("GET", `${this.paths.folderVersionsBase(key)}/`, { params });
883
1406
  }
1407
+ /** @deprecated Use {@link createCollectionVersion} instead. */
884
1408
  async createFolderVersion(folderKey, payload, options) {
1409
+ warnDeprecatedMethod("createFolderVersion", "createCollectionVersion");
885
1410
  const key = resolveKey(folderKey);
886
1411
  const params = {};
887
1412
  if (options?.copyFrom) {
@@ -892,7 +1417,9 @@ var ManagementClient = class {
892
1417
  params: Object.keys(params).length > 0 ? params : void 0
893
1418
  });
894
1419
  }
1420
+ /** @deprecated Use {@link getCollectionVersion} instead. */
895
1421
  async getFolderVersion(folderKey, versionKey, options) {
1422
+ warnDeprecatedMethod("getFolderVersion", "getCollectionVersion");
896
1423
  const fKey = resolveKey(folderKey);
897
1424
  const vKey = resolveKey(versionKey);
898
1425
  const params = {};
@@ -903,48 +1430,62 @@ var ManagementClient = class {
903
1430
  params: Object.keys(params).length > 0 ? params : void 0
904
1431
  });
905
1432
  }
1433
+ /** @deprecated Use {@link updateCollectionVersion} instead. */
906
1434
  async updateFolderVersion(folderKey, versionKey, payload) {
1435
+ warnDeprecatedMethod("updateFolderVersion", "updateCollectionVersion");
907
1436
  const fKey = resolveKey(folderKey);
908
1437
  const vKey = resolveKey(versionKey);
909
1438
  return this.request("PUT", `${this.paths.folderVersionsBase(fKey)}/${vKey}/`, {
910
1439
  jsonBody: payload
911
1440
  });
912
1441
  }
1442
+ /** @deprecated Use {@link deleteCollectionVersion} instead. */
913
1443
  async deleteFolderVersion(folderKey, versionKey) {
1444
+ warnDeprecatedMethod("deleteFolderVersion", "deleteCollectionVersion");
914
1445
  const fKey = resolveKey(folderKey);
915
1446
  const vKey = resolveKey(versionKey);
916
1447
  await this.request("DELETE", `${this.paths.folderVersionsBase(fKey)}/${vKey}/`, {
917
1448
  parseJson: false
918
1449
  });
919
1450
  }
1451
+ /** @deprecated Use {@link publishCollectionVersion} instead. */
920
1452
  async publishFolderVersion(folderKey, versionKey) {
1453
+ warnDeprecatedMethod("publishFolderVersion", "publishCollectionVersion");
921
1454
  const fKey = resolveKey(folderKey);
922
1455
  const vKey = resolveKey(versionKey);
923
1456
  return this.request("POST", `${this.paths.folderVersionsBase(fKey)}/${vKey}/publish/`);
924
1457
  }
925
1458
  // ------------------------------------------------------------------ //
926
- // Folder field operations
1459
+ // Folder field operations (deprecated)
927
1460
  // ------------------------------------------------------------------ //
1461
+ /** @deprecated Use {@link listCollectionFields} instead. */
928
1462
  async listFolderFields(folderKey, versionKey, params) {
1463
+ warnDeprecatedMethod("listFolderFields", "listCollectionFields");
929
1464
  const fKey = resolveKey(folderKey);
930
1465
  const vKey = resolveKey(versionKey);
931
1466
  return this.request("GET", `${this.paths.folderSchemaTree(fKey, vKey)}/`, { params });
932
1467
  }
1468
+ /** @deprecated Use {@link createCollectionField} instead. */
933
1469
  async createFolderField(folderKey, versionKey, payload) {
1470
+ warnDeprecatedMethod("createFolderField", "createCollectionField");
934
1471
  const fKey = resolveKey(folderKey);
935
1472
  const vKey = resolveKey(versionKey);
936
1473
  return this.request("POST", `${this.paths.folderSchemaTree(fKey, vKey)}/`, {
937
1474
  jsonBody: payload
938
1475
  });
939
1476
  }
1477
+ /** @deprecated Use {@link getCollectionField} instead. */
940
1478
  async getFolderField(folderKey, versionKey, fieldPath) {
1479
+ warnDeprecatedMethod("getFolderField", "getCollectionField");
941
1480
  const fKey = resolveKey(folderKey);
942
1481
  const vKey = resolveKey(versionKey);
943
1482
  return this.request("GET", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
944
1483
  params: { path: fieldPath }
945
1484
  });
946
1485
  }
1486
+ /** @deprecated Use {@link updateCollectionField} instead. */
947
1487
  async updateFolderField(folderKey, versionKey, fieldPath, payload) {
1488
+ warnDeprecatedMethod("updateFolderField", "updateCollectionField");
948
1489
  const fKey = resolveKey(folderKey);
949
1490
  const vKey = resolveKey(versionKey);
950
1491
  return this.request("PUT", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
@@ -952,7 +1493,9 @@ var ManagementClient = class {
952
1493
  jsonBody: payload
953
1494
  });
954
1495
  }
1496
+ /** @deprecated Use {@link deleteCollectionField} instead. */
955
1497
  async deleteFolderField(folderKey, versionKey, fieldPath) {
1498
+ warnDeprecatedMethod("deleteFolderField", "deleteCollectionField");
956
1499
  const fKey = resolveKey(folderKey);
957
1500
  const vKey = resolveKey(versionKey);
958
1501
  await this.request("DELETE", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
@@ -1080,32 +1623,41 @@ var ManagementClient = class {
1080
1623
  return this.request("GET", `${this.paths.resourceBase(fKey)}/${rKey}/`);
1081
1624
  }
1082
1625
  async createResource(folderKey, payload, options) {
1083
- const key = resolveKey(folderKey);
1084
- const params = {};
1085
- if (options?.component) {
1086
- params.component = resolveKey(options.component);
1626
+ if (options && typeof options === "object" && "component" in options) {
1627
+ throw new TypeError(
1628
+ "The `component` option has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your call site."
1629
+ );
1087
1630
  }
1631
+ const key = resolveKey(folderKey);
1088
1632
  const body = { ...payload };
1089
1633
  if (options?.externalId) {
1090
1634
  body.external_id = options.externalId;
1091
1635
  }
1092
1636
  return this.request("POST", `${this.paths.resourceBase(key)}/`, {
1093
- params: Object.keys(params).length ? params : void 0,
1094
1637
  jsonBody: body
1095
1638
  });
1096
1639
  }
1097
1640
  async upsertResource(folderKey, payload, options) {
1641
+ if (options && typeof options === "object" && "component" in options) {
1642
+ throw new TypeError(
1643
+ "The `component` option has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your call site."
1644
+ );
1645
+ }
1098
1646
  const key = resolveKey(folderKey);
1099
1647
  const params = { external_id: options.externalId };
1100
- if (options.component) {
1101
- params.component = resolveKey(options.component);
1102
- }
1103
1648
  return this.request("PUT", `${this.paths.resourceBase(key)}/`, {
1104
1649
  params,
1105
1650
  jsonBody: payload
1106
1651
  });
1107
1652
  }
1108
1653
  async batchUpsertResources(folderKey, items, options) {
1654
+ for (const item of items) {
1655
+ if (item && typeof item === "object" && "component" in item) {
1656
+ throw new TypeError(
1657
+ "BatchUpsertItem.component has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your batch items."
1658
+ );
1659
+ }
1660
+ }
1109
1661
  const fKey = resolveKey(folderKey);
1110
1662
  const maxConcurrency = options?.maxConcurrency ?? 5;
1111
1663
  if (maxConcurrency < 1) {
@@ -1123,9 +1675,6 @@ var ManagementClient = class {
1123
1675
  const processItem = async (index, item) => {
1124
1676
  try {
1125
1677
  const params = { external_id: item.external_id };
1126
- if (item.component) {
1127
- params.component = item.component;
1128
- }
1129
1678
  const result = await this.request(
1130
1679
  "PUT",
1131
1680
  `${this.paths.resourceBase(fKey)}/`,
@@ -1561,6 +2110,46 @@ var FluxClient = class {
1561
2110
  const path = this.buildPath(folderPath, "/_search");
1562
2111
  return this.transport.request("POST", path, { jsonBody: body });
1563
2112
  }
2113
+ /**
2114
+ * Create a resource in a collection and publish it immediately.
2115
+ *
2116
+ * `folderPath` is the collection path (e.g. `articles` or a nested path such
2117
+ * as `users/usr_1/memories`). `options.key` is an optional external
2118
+ * identifier for deduplication — reusing an existing key raises
2119
+ * {@link ExternalIdConflictError}. The response carries `resource_key`,
2120
+ * `revision_key`, `write_units`, and `published`.
2121
+ *
2122
+ * Writes require an authenticated key with write access: an anonymous caller
2123
+ * gets 401, a key without the `create` grant gets a generic 403
2124
+ * (`access_denied`), and a collection whose connection does not allow writes
2125
+ * raises {@link CollectionNotWritableError}.
2126
+ *
2127
+ * Writes are never retried automatically: a failed write's outcome is
2128
+ * unknown, so re-read with a GET before retrying.
2129
+ */
2130
+ async createResource(folderPath, data, options) {
2131
+ const path = this.buildPath(folderPath, "/");
2132
+ const body = { data };
2133
+ if (options?.key !== void 0) {
2134
+ body.key = options.key;
2135
+ }
2136
+ return this.transport.request("POST", path, { jsonBody: body, allowRetries: false });
2137
+ }
2138
+ /**
2139
+ * Replace a resource's document and publish a new revision. This is a
2140
+ * full-document replace, not a partial merge: fields absent from `data` are
2141
+ * removed.
2142
+ *
2143
+ * Writes require an authenticated key with write access: an anonymous caller
2144
+ * gets 401, a key without the `update` grant gets a generic 403
2145
+ * (`access_denied`), and a collection whose connection does not allow writes
2146
+ * raises {@link CollectionNotWritableError}. Like {@link createResource}, it
2147
+ * is never retried automatically.
2148
+ */
2149
+ async updateResource(folderPath, resourceKey, data) {
2150
+ const path = this.buildPath(folderPath, `/${resourceKey}/`);
2151
+ return this.transport.request("PUT", path, { jsonBody: { data }, allowRetries: false });
2152
+ }
1564
2153
  /** Semantic search using auto-generated embeddings. */
1565
2154
  async vectorSearch(folderPath, options) {
1566
2155
  const { query, fields, top_k = 10, similarity_threshold, limit, offset, ...rest } = options;
@@ -1693,8 +2282,11 @@ var FluxClient = class {
1693
2282
  // Annotate the CommonJS export names for ESM import in node:
1694
2283
  0 && (module.exports = {
1695
2284
  AnonymousAuth,
2285
+ CollectionNotWritableError,
2286
+ ContentValidationFailedError,
1696
2287
  DEFAULT_RETRY_CONFIG,
1697
2288
  DEFAULT_USER_AGENT,
2289
+ ExternalIdConflictError,
1698
2290
  FluxClient,
1699
2291
  FoxnoseAPIError,
1700
2292
  FoxnoseAuthError,
@@ -1703,14 +2295,20 @@ var FluxClient = class {
1703
2295
  HttpTransport,
1704
2296
  JWTAuth,
1705
2297
  ManagementClient,
2298
+ PlanExhaustedError,
2299
+ PlanLimitExceededError,
2300
+ RateLimitExceededError,
1706
2301
  SDK_VERSION,
1707
2302
  SearchMode,
1708
2303
  SecureKeyAuth,
1709
2304
  SimpleKeyAuth,
2305
+ SpendCapExceededError,
1710
2306
  StaticTokenProvider,
2307
+ UpstreamError,
1711
2308
  VERSION,
1712
2309
  buildSearchBody,
1713
2310
  createConfig,
2311
+ nestedFieldMeta,
1714
2312
  resolveKey
1715
2313
  });
1716
2314
  //# sourceMappingURL=index.cjs.map