@foxnose/sdk 0.2.3 → 0.4.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
@@ -31,12 +31,19 @@ __export(index_exports, {
31
31
  HttpTransport: () => HttpTransport,
32
32
  JWTAuth: () => JWTAuth,
33
33
  ManagementClient: () => ManagementClient,
34
+ PlanExhaustedError: () => PlanExhaustedError,
35
+ PlanLimitExceededError: () => PlanLimitExceededError,
36
+ RateLimitExceededError: () => RateLimitExceededError,
34
37
  SDK_VERSION: () => SDK_VERSION,
38
+ SearchMode: () => SearchMode,
35
39
  SecureKeyAuth: () => SecureKeyAuth,
36
40
  SimpleKeyAuth: () => SimpleKeyAuth,
41
+ SpendCapExceededError: () => SpendCapExceededError,
37
42
  StaticTokenProvider: () => StaticTokenProvider,
38
43
  VERSION: () => SDK_VERSION,
44
+ buildSearchBody: () => buildSearchBody,
39
45
  createConfig: () => createConfig,
46
+ nestedFieldMeta: () => nestedFieldMeta,
40
47
  resolveKey: () => resolveKey
41
48
  });
42
49
  module.exports = __toCommonJS(index_exports);
@@ -106,6 +113,119 @@ var FoxnoseAPIError = class extends FoxnoseError {
106
113
  this.responseBody = options.responseBody;
107
114
  }
108
115
  };
116
+ var SpendCapExceededError = class extends FoxnoseAPIError {
117
+ /** Spend cap in USD, or null when unset on the server side. */
118
+ capUsd;
119
+ /** ISO timestamp when the current billing cycle resets. */
120
+ cycleResetsAt;
121
+ /** URL where the spend cap can be raised. */
122
+ raiseCapUrl;
123
+ constructor(options) {
124
+ super(options);
125
+ this.name = "SpendCapExceededError";
126
+ this.capUsd = options.capUsd;
127
+ this.cycleResetsAt = options.cycleResetsAt;
128
+ this.raiseCapUrl = options.raiseCapUrl;
129
+ }
130
+ };
131
+ var PlanExhaustedError = class extends FoxnoseAPIError {
132
+ /** Usage axis that was exhausted (e.g. retrievals, writes, data_storage, vector_storage). */
133
+ axis;
134
+ /** ISO timestamp when the usage window resets. */
135
+ windowResetsAt;
136
+ /** URL where the plan can be upgraded. */
137
+ upgradeUrl;
138
+ constructor(options) {
139
+ super(options);
140
+ this.name = "PlanExhaustedError";
141
+ this.axis = options.axis;
142
+ this.windowResetsAt = options.windowResetsAt;
143
+ this.upgradeUrl = options.upgradeUrl;
144
+ }
145
+ };
146
+ var PlanLimitExceededError = class extends FoxnoseAPIError {
147
+ /** Entity whose limit was exceeded (e.g. collections, environments, api_keys). */
148
+ entity;
149
+ /** Maximum allowed by the current plan. */
150
+ limit;
151
+ /** Current count that triggered the error. */
152
+ current;
153
+ /** URL where the plan can be upgraded, if provided. */
154
+ upgradeUrl;
155
+ constructor(options) {
156
+ super(options);
157
+ this.name = "PlanLimitExceededError";
158
+ this.entity = options.entity;
159
+ this.limit = options.limit;
160
+ this.current = options.current;
161
+ this.upgradeUrl = options.upgradeUrl;
162
+ }
163
+ };
164
+ var RateLimitExceededError = class extends FoxnoseAPIError {
165
+ /** Seconds to wait before retrying, from the Retry-After header. */
166
+ retryAfter;
167
+ constructor(options) {
168
+ super(options);
169
+ this.name = "RateLimitExceededError";
170
+ this.retryAfter = options.retryAfter;
171
+ }
172
+ };
173
+ function isPlainObject(value) {
174
+ return typeof value === "object" && value !== null && !Array.isArray(value);
175
+ }
176
+ function getHeader(headers, name) {
177
+ if (!headers) {
178
+ return void 0;
179
+ }
180
+ const target = name.toLowerCase();
181
+ for (const [key, value] of Object.entries(headers)) {
182
+ if (key.toLowerCase() === target) {
183
+ return value;
184
+ }
185
+ }
186
+ return void 0;
187
+ }
188
+ function buildAPIError(options) {
189
+ const { statusCode, errorCode, detail, responseHeaders, responseBody } = options;
190
+ const body = isPlainObject(responseBody) ? responseBody : void 0;
191
+ if (statusCode === 402 && errorCode === "spend_cap_reached" && body) {
192
+ return new SpendCapExceededError({
193
+ ...options,
194
+ message: "message" in body ? options.message : "Spend cap reached",
195
+ capUsd: typeof body.cap_usd === "number" ? body.cap_usd : body.cap_usd === null ? null : void 0,
196
+ cycleResetsAt: typeof body.cycle_resets_at === "string" ? body.cycle_resets_at : void 0,
197
+ raiseCapUrl: typeof body.raise_cap_url === "string" ? body.raise_cap_url : void 0
198
+ });
199
+ }
200
+ if (statusCode === 402 && errorCode === "plan_exhausted" && body) {
201
+ return new PlanExhaustedError({
202
+ ...options,
203
+ message: "message" in body ? options.message : "Plan allowance exhausted",
204
+ axis: typeof body.axis === "string" ? body.axis : void 0,
205
+ windowResetsAt: typeof body.window_resets_at === "string" ? body.window_resets_at : void 0,
206
+ upgradeUrl: typeof body.upgrade_url === "string" ? body.upgrade_url : void 0
207
+ });
208
+ }
209
+ if (statusCode === 403 && errorCode === "plan_limit_exceeded") {
210
+ const d = isPlainObject(detail) ? detail : {};
211
+ return new PlanLimitExceededError({
212
+ ...options,
213
+ entity: typeof d.entity === "string" ? d.entity : void 0,
214
+ limit: typeof d.limit === "number" ? d.limit : void 0,
215
+ current: typeof d.current === "number" ? d.current : void 0,
216
+ upgradeUrl: typeof d.upgrade_url === "string" ? d.upgrade_url : void 0
217
+ });
218
+ }
219
+ if (statusCode === 429 && errorCode === "rate_limited") {
220
+ const raw = getHeader(responseHeaders, "Retry-After");
221
+ const parsed = raw !== void 0 ? Number(raw) : NaN;
222
+ return new RateLimitExceededError({
223
+ ...options,
224
+ retryAfter: Number.isNaN(parsed) ? void 0 : parsed
225
+ });
226
+ }
227
+ return new FoxnoseAPIError(options);
228
+ }
109
229
  var FoxnoseAuthError = class extends FoxnoseError {
110
230
  constructor(message) {
111
231
  super(message);
@@ -190,7 +310,7 @@ var DEFAULT_RETRY_CONFIG = {
190
310
  statusCodes: [408, 425, 429, 500, 502, 503, 504],
191
311
  methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
192
312
  };
193
- var SDK_VERSION = "0.2.1";
313
+ var SDK_VERSION = "0.4.0";
194
314
  var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
195
315
  function createConfig(options) {
196
316
  if (!options.baseUrl) {
@@ -370,10 +490,12 @@ var HttpTransport = class {
370
490
  if (text) {
371
491
  try {
372
492
  const payload = JSON.parse(text);
373
- message = payload.message ?? message;
374
- errorCode = payload.error_code;
375
- detail = payload.detail;
376
493
  body = payload;
494
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
495
+ message = payload.message ?? message;
496
+ errorCode = payload.error_code;
497
+ detail = payload.detail;
498
+ }
377
499
  } catch {
378
500
  body = text;
379
501
  }
@@ -384,7 +506,7 @@ var HttpTransport = class {
384
506
  response.headers.forEach((value, key) => {
385
507
  responseHeaders[key] = value;
386
508
  });
387
- throw new FoxnoseAPIError({
509
+ throw buildAPIError({
388
510
  message: message || "API request failed",
389
511
  statusCode: response.status,
390
512
  errorCode,
@@ -398,7 +520,38 @@ var HttpTransport = class {
398
520
  }
399
521
  };
400
522
 
523
+ // src/_deprecation.ts
524
+ var warned = /* @__PURE__ */ new Set();
525
+ function warnDeprecatedMethod(oldName, newName, removal = "1.0") {
526
+ if (warned.has(oldName)) {
527
+ return;
528
+ }
529
+ warned.add(oldName);
530
+ console.warn(
531
+ `@foxnose/sdk: ${oldName}() is deprecated; use ${newName}() instead. ${oldName}() will be removed in @foxnose/sdk ${removal}.`
532
+ );
533
+ }
534
+
401
535
  // src/management/models.ts
536
+ function nestedFieldMeta(opts) {
537
+ if (opts.extra) {
538
+ const reserved = ["component", "component_version", "auto_update"];
539
+ const collisions = reserved.filter(
540
+ (k) => Object.prototype.hasOwnProperty.call(opts.extra, k)
541
+ );
542
+ if (collisions.length > 0) {
543
+ throw new Error(
544
+ `nestedFieldMeta: 'extra' must not include reserved keys: ${collisions.join(", ")}`
545
+ );
546
+ }
547
+ }
548
+ return {
549
+ ...opts.extra ?? {},
550
+ component: opts.component,
551
+ component_version: opts.componentVersion,
552
+ auto_update: opts.autoUpdate ?? false
553
+ };
554
+ }
402
555
  function resolveKey(value) {
403
556
  if (typeof value === "string") {
404
557
  return value;
@@ -418,11 +571,18 @@ function managementPaths(environmentKey) {
418
571
  projectRoot: (orgKey, projectKey) => `/organizations/${orgKey}/projects/${projectKey}`,
419
572
  environmentsBase: (orgKey, projectKey) => `/organizations/${orgKey}/projects/${projectKey}/environments`,
420
573
  environmentRoot: (orgKey, projectKey, envKey) => `/organizations/${orgKey}/projects/${projectKey}/environments/${envKey}`,
421
- // Folder paths
574
+ // Folder paths (deprecated — see Collection paths below).
422
575
  foldersTreeRoot: () => `/v1/${environmentKey}/folders/tree`,
423
576
  foldersTreeItem: () => `/v1/${environmentKey}/folders/tree/folder`,
424
577
  folderVersionsBase: (folderKey) => `/v1/${environmentKey}/folders/${folderKey}/model/versions`,
425
578
  folderSchemaTree: (folderKey, versionKey) => `/v1/${environmentKey}/folders/${folderKey}/model/versions/${versionKey}/schema/tree`,
579
+ // Collection paths (canonical going forward; folder paths above hit the
580
+ // deprecated /folders/ URL alias on the server side).
581
+ collectionsTreeRoot: () => `/v1/${environmentKey}/collections/tree`,
582
+ collectionsTreeItem: () => `/v1/${environmentKey}/collections/tree/collection`,
583
+ collectionVersionsBase: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/model/versions`,
584
+ collectionSchemaTree: (collectionKey, versionKey) => `/v1/${environmentKey}/collections/${collectionKey}/model/versions/${versionKey}/schema/tree`,
585
+ collectionSyncComponent: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/sync_component`,
426
586
  // Component paths
427
587
  componentsRoot: () => `/v1/${environmentKey}/components`,
428
588
  componentRoot: (componentKey) => `/v1/${environmentKey}/components/${componentKey}`,
@@ -441,6 +601,7 @@ function managementPaths(environmentKey) {
441
601
  apisRoot: () => `/v1/${environmentKey}/api`,
442
602
  apiRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}`,
443
603
  apiFoldersRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}/folders`,
604
+ apiCollectionsRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}/collections`,
444
605
  // Management role paths
445
606
  managementRolesRoot: () => `/v1/${environmentKey}/permissions/management-api/roles`,
446
607
  managementRoleRoot: (roleKey) => `/v1/${environmentKey}/permissions/management-api/roles/${roleKey}`,
@@ -626,13 +787,84 @@ var ManagementClient = class {
626
787
  await this.request("DELETE", `${this.paths.apiRoot(key)}/`, { parseJson: false });
627
788
  }
628
789
  // ------------------------------------------------------------------ //
629
- // API Folder associations
790
+ // API ↔ Collection association (canonical)
791
+ // ------------------------------------------------------------------ //
792
+ async listApiCollections(apiKey, params) {
793
+ const key = resolveKey(apiKey);
794
+ return this.request("GET", `${this.paths.apiCollectionsRoot(key)}/`, { params });
795
+ }
796
+ async addApiCollection(apiKey, collectionKey, options) {
797
+ const aKey = resolveKey(apiKey);
798
+ const cKey = resolveKey(collectionKey);
799
+ const body = { folder: cKey };
800
+ if (options?.allowedMethods !== void 0) {
801
+ body.allowed_methods = options.allowedMethods;
802
+ }
803
+ if (options?.descriptionGetOne !== void 0) {
804
+ body.description_get_one = options.descriptionGetOne;
805
+ }
806
+ if (options?.descriptionGetMany !== void 0) {
807
+ body.description_get_many = options.descriptionGetMany;
808
+ }
809
+ if (options?.descriptionSearch !== void 0) {
810
+ body.description_search = options.descriptionSearch;
811
+ }
812
+ if (options?.descriptionSchema !== void 0) {
813
+ body.description_schema = options.descriptionSchema;
814
+ }
815
+ return this.request("POST", `${this.paths.apiCollectionsRoot(aKey)}/`, {
816
+ jsonBody: body
817
+ });
818
+ }
819
+ async getApiCollection(apiKey, collectionKey) {
820
+ const aKey = resolveKey(apiKey);
821
+ const cKey = resolveKey(collectionKey);
822
+ return this.request("GET", `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`);
823
+ }
824
+ async updateApiCollection(apiKey, collectionKey, options) {
825
+ const aKey = resolveKey(apiKey);
826
+ const cKey = resolveKey(collectionKey);
827
+ const body = {};
828
+ if (options?.allowedMethods !== void 0) {
829
+ body.allowed_methods = options.allowedMethods;
830
+ }
831
+ if (options?.descriptionGetOne !== void 0) {
832
+ body.description_get_one = options.descriptionGetOne;
833
+ }
834
+ if (options?.descriptionGetMany !== void 0) {
835
+ body.description_get_many = options.descriptionGetMany;
836
+ }
837
+ if (options?.descriptionSearch !== void 0) {
838
+ body.description_search = options.descriptionSearch;
839
+ }
840
+ if (options?.descriptionSchema !== void 0) {
841
+ body.description_schema = options.descriptionSchema;
842
+ }
843
+ return this.request("PUT", `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`, {
844
+ jsonBody: body
845
+ });
846
+ }
847
+ async removeApiCollection(apiKey, collectionKey) {
848
+ const aKey = resolveKey(apiKey);
849
+ const cKey = resolveKey(collectionKey);
850
+ await this.request(
851
+ "DELETE",
852
+ `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`,
853
+ { parseJson: false }
854
+ );
855
+ }
856
+ // ------------------------------------------------------------------ //
857
+ // API ↔ Folder association (deprecated; hits legacy /folders/ URL)
630
858
  // ------------------------------------------------------------------ //
859
+ /** @deprecated Use {@link listApiCollections} instead. */
631
860
  async listApiFolders(apiKey, params) {
861
+ warnDeprecatedMethod("listApiFolders", "listApiCollections");
632
862
  const key = resolveKey(apiKey);
633
863
  return this.request("GET", `${this.paths.apiFoldersRoot(key)}/`, { params });
634
864
  }
865
+ /** @deprecated Use {@link addApiCollection} instead. */
635
866
  async addApiFolder(apiKey, folderKey, options) {
867
+ warnDeprecatedMethod("addApiFolder", "addApiCollection");
636
868
  const aKey = resolveKey(apiKey);
637
869
  const fKey = resolveKey(folderKey);
638
870
  const body = { folder: fKey };
@@ -653,12 +885,16 @@ var ManagementClient = class {
653
885
  }
654
886
  return this.request("POST", `${this.paths.apiFoldersRoot(aKey)}/`, { jsonBody: body });
655
887
  }
888
+ /** @deprecated Use {@link getApiCollection} instead. */
656
889
  async getApiFolder(apiKey, folderKey) {
890
+ warnDeprecatedMethod("getApiFolder", "getApiCollection");
657
891
  const aKey = resolveKey(apiKey);
658
892
  const fKey = resolveKey(folderKey);
659
893
  return this.request("GET", `${this.paths.apiFoldersRoot(aKey)}/${fKey}/`);
660
894
  }
895
+ /** @deprecated Use {@link updateApiCollection} instead. */
661
896
  async updateApiFolder(apiKey, folderKey, options) {
897
+ warnDeprecatedMethod("updateApiFolder", "updateApiCollection");
662
898
  const aKey = resolveKey(apiKey);
663
899
  const fKey = resolveKey(folderKey);
664
900
  const body = {};
@@ -681,7 +917,9 @@ var ManagementClient = class {
681
917
  jsonBody: body
682
918
  });
683
919
  }
920
+ /** @deprecated Use {@link removeApiCollection} instead. */
684
921
  async removeApiFolder(apiKey, folderKey) {
922
+ warnDeprecatedMethod("removeApiFolder", "removeApiCollection");
685
923
  const aKey = resolveKey(apiKey);
686
924
  const fKey = resolveKey(folderKey);
687
925
  await this.request("DELETE", `${this.paths.apiFoldersRoot(aKey)}/${fKey}/`, {
@@ -833,39 +1071,271 @@ var ManagementClient = class {
833
1071
  });
834
1072
  }
835
1073
  // ------------------------------------------------------------------ //
836
- // Folder operations
1074
+ // Collection operations (canonical)
1075
+ // ------------------------------------------------------------------ //
1076
+ async listCollections(params) {
1077
+ return this.request("GET", `${this.paths.collectionsTreeRoot()}/`, { params });
1078
+ }
1079
+ async getCollection(collectionKey) {
1080
+ const key = resolveKey(collectionKey);
1081
+ return this.request("GET", `${this.paths.collectionsTreeItem()}/`, {
1082
+ params: { key }
1083
+ });
1084
+ }
1085
+ async getCollectionByPath(path) {
1086
+ return this.request("GET", `${this.paths.collectionsTreeItem()}/`, {
1087
+ params: { path }
1088
+ });
1089
+ }
1090
+ async listCollectionTree(options) {
1091
+ const params = {};
1092
+ if (options?.key) params.key = options.key;
1093
+ if (options?.mode) params.mode = options.mode;
1094
+ return this.request("GET", `${this.paths.collectionsTreeRoot()}/`, { params });
1095
+ }
1096
+ async createCollection(payload) {
1097
+ return this.request("POST", `${this.paths.collectionsTreeRoot()}/`, {
1098
+ jsonBody: payload
1099
+ });
1100
+ }
1101
+ async updateCollection(collectionKey, payload) {
1102
+ const key = resolveKey(collectionKey);
1103
+ return this.request("PUT", `${this.paths.collectionsTreeItem()}/`, {
1104
+ params: { key },
1105
+ jsonBody: payload
1106
+ });
1107
+ }
1108
+ async deleteCollection(collectionKey) {
1109
+ const key = resolveKey(collectionKey);
1110
+ await this.request("DELETE", `${this.paths.collectionsTreeItem()}/`, {
1111
+ params: { key },
1112
+ parseJson: false
1113
+ });
1114
+ }
1115
+ // ------------------------------------------------------------------ //
1116
+ // Collection schema version operations (canonical)
1117
+ // ------------------------------------------------------------------ //
1118
+ async listCollectionVersions(collectionKey, params) {
1119
+ const key = resolveKey(collectionKey);
1120
+ return this.request("GET", `${this.paths.collectionVersionsBase(key)}/`, {
1121
+ params
1122
+ });
1123
+ }
1124
+ async createCollectionVersion(collectionKey, payload, options) {
1125
+ const key = resolveKey(collectionKey);
1126
+ const params = {};
1127
+ if (options?.copyFrom) {
1128
+ params.copy_from = resolveKey(options.copyFrom);
1129
+ }
1130
+ return this.request("POST", `${this.paths.collectionVersionsBase(key)}/`, {
1131
+ jsonBody: payload,
1132
+ params: Object.keys(params).length > 0 ? params : void 0
1133
+ });
1134
+ }
1135
+ async getCollectionVersion(collectionKey, versionKey, options) {
1136
+ const cKey = resolveKey(collectionKey);
1137
+ const vKey = resolveKey(versionKey);
1138
+ const params = {};
1139
+ if (options?.includeSchema !== void 0) {
1140
+ params.include_schema = options.includeSchema;
1141
+ }
1142
+ return this.request(
1143
+ "GET",
1144
+ `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1145
+ {
1146
+ params: Object.keys(params).length > 0 ? params : void 0
1147
+ }
1148
+ );
1149
+ }
1150
+ async updateCollectionVersion(collectionKey, versionKey, payload) {
1151
+ const cKey = resolveKey(collectionKey);
1152
+ const vKey = resolveKey(versionKey);
1153
+ return this.request(
1154
+ "PUT",
1155
+ `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1156
+ { jsonBody: payload }
1157
+ );
1158
+ }
1159
+ async deleteCollectionVersion(collectionKey, versionKey) {
1160
+ const cKey = resolveKey(collectionKey);
1161
+ const vKey = resolveKey(versionKey);
1162
+ await this.request(
1163
+ "DELETE",
1164
+ `${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
1165
+ { parseJson: false }
1166
+ );
1167
+ }
1168
+ async publishCollectionVersion(collectionKey, versionKey) {
1169
+ const cKey = resolveKey(collectionKey);
1170
+ const vKey = resolveKey(versionKey);
1171
+ return this.request(
1172
+ "POST",
1173
+ `${this.paths.collectionVersionsBase(cKey)}/${vKey}/publish/`
1174
+ );
1175
+ }
1176
+ /**
1177
+ * Advance pinned nested fields on a Collection to a target Component version.
1178
+ *
1179
+ * Creates a new published Collection schema version with the affected
1180
+ * `meta.component_version` pins advanced. Fields with `auto_update=true`
1181
+ * and fields already at the requested target version are reported in
1182
+ * `skipped` rather than advanced.
1183
+ *
1184
+ * @param collectionKey The Collection to sync.
1185
+ * @param options.fieldPaths Optional list of nested field paths to advance.
1186
+ * When omitted, every pinned (`auto_update=false`) nested field on the
1187
+ * Collection's current version is considered.
1188
+ * @param options.toVersions Optional per-path override mapping field path
1189
+ * to target Component Version UID. Paths not in this mapping advance to
1190
+ * the referenced Component's `current_version`. When both `fieldPaths`
1191
+ * and `toVersions` are supplied, every key in `toVersions` must also
1192
+ * appear in `fieldPaths`.
1193
+ *
1194
+ * @returns Summary of synced and skipped paths, plus the new
1195
+ * `schema_version` UID (`null` if no paths were advanced).
1196
+ *
1197
+ * @throws `Error` locally (before any HTTP request) when both `fieldPaths`
1198
+ * and `toVersions` are supplied AND `toVersions` contains a key that is
1199
+ * not in `fieldPaths` (mirrors the server-side validator so the misuse
1200
+ * surfaces at the call-site).
1201
+ * @throws `FoxnoseApiError` on:
1202
+ * - 409 `component_sync_conflict` — target version would break existing resources
1203
+ * - 422 `too_many_versions` — Collection schema quota exhausted
1204
+ * - 422 `validation_error` — request body invalid
1205
+ * - 404 — Collection or specified target version missing
1206
+ *
1207
+ * @example
1208
+ * ```ts
1209
+ * // Advance every pinned nested field to its Component's current version.
1210
+ * await client.syncCollectionComponent('articles');
1211
+ *
1212
+ * // Advance a specific path to a chosen Component version.
1213
+ * await client.syncCollectionComponent('articles', {
1214
+ * fieldPaths: ['seo'],
1215
+ * toVersions: { seo: 'ver-def67890' },
1216
+ * });
1217
+ * ```
1218
+ */
1219
+ async syncCollectionComponent(collectionKey, options = {}) {
1220
+ const cKey = resolveKey(collectionKey);
1221
+ if (options.fieldPaths !== void 0 && options.toVersions !== void 0) {
1222
+ const fieldPathSet = new Set(options.fieldPaths);
1223
+ const extras = Object.keys(options.toVersions).filter((k) => !fieldPathSet.has(k)).sort();
1224
+ if (extras.length > 0) {
1225
+ throw new Error(
1226
+ `toVersions includes paths not present in fieldPaths: [${extras.join(", ")}]`
1227
+ );
1228
+ }
1229
+ }
1230
+ const body = {};
1231
+ if (options.fieldPaths !== void 0) {
1232
+ body.field_paths = options.fieldPaths;
1233
+ }
1234
+ if (options.toVersions !== void 0) {
1235
+ body.to_versions = options.toVersions;
1236
+ }
1237
+ return this.request(
1238
+ "POST",
1239
+ `${this.paths.collectionSyncComponent(cKey)}/`,
1240
+ { jsonBody: body }
1241
+ );
1242
+ }
1243
+ // ------------------------------------------------------------------ //
1244
+ // Collection schema field operations (canonical)
1245
+ // ------------------------------------------------------------------ //
1246
+ async listCollectionFields(collectionKey, versionKey, params) {
1247
+ const cKey = resolveKey(collectionKey);
1248
+ const vKey = resolveKey(versionKey);
1249
+ return this.request(
1250
+ "GET",
1251
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/`,
1252
+ { params }
1253
+ );
1254
+ }
1255
+ async createCollectionField(collectionKey, versionKey, payload) {
1256
+ const cKey = resolveKey(collectionKey);
1257
+ const vKey = resolveKey(versionKey);
1258
+ return this.request(
1259
+ "POST",
1260
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/`,
1261
+ { jsonBody: payload }
1262
+ );
1263
+ }
1264
+ async getCollectionField(collectionKey, versionKey, fieldPath) {
1265
+ const cKey = resolveKey(collectionKey);
1266
+ const vKey = resolveKey(versionKey);
1267
+ return this.request(
1268
+ "GET",
1269
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1270
+ { params: { path: fieldPath } }
1271
+ );
1272
+ }
1273
+ async updateCollectionField(collectionKey, versionKey, fieldPath, payload) {
1274
+ const cKey = resolveKey(collectionKey);
1275
+ const vKey = resolveKey(versionKey);
1276
+ return this.request(
1277
+ "PUT",
1278
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1279
+ { params: { path: fieldPath }, jsonBody: payload }
1280
+ );
1281
+ }
1282
+ async deleteCollectionField(collectionKey, versionKey, fieldPath) {
1283
+ const cKey = resolveKey(collectionKey);
1284
+ const vKey = resolveKey(versionKey);
1285
+ await this.request(
1286
+ "DELETE",
1287
+ `${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
1288
+ { params: { path: fieldPath }, parseJson: false }
1289
+ );
1290
+ }
1291
+ // ------------------------------------------------------------------ //
1292
+ // Folder operations (deprecated; hit legacy /folders/ URL)
837
1293
  // ------------------------------------------------------------------ //
1294
+ /** @deprecated Use {@link listCollections} instead. */
838
1295
  async listFolders(params) {
1296
+ warnDeprecatedMethod("listFolders", "listCollections");
839
1297
  return this.request("GET", `${this.paths.foldersTreeRoot()}/`, { params });
840
1298
  }
1299
+ /** @deprecated Use {@link getCollection} instead. */
841
1300
  async getFolder(folderKey) {
1301
+ warnDeprecatedMethod("getFolder", "getCollection");
842
1302
  const key = resolveKey(folderKey);
843
1303
  return this.request("GET", `${this.paths.foldersTreeItem()}/`, {
844
1304
  params: { key }
845
1305
  });
846
1306
  }
1307
+ /** @deprecated Use {@link getCollectionByPath} instead. */
847
1308
  async getFolderByPath(path) {
1309
+ warnDeprecatedMethod("getFolderByPath", "getCollectionByPath");
848
1310
  return this.request("GET", `${this.paths.foldersTreeItem()}/`, {
849
1311
  params: { path }
850
1312
  });
851
1313
  }
1314
+ /** @deprecated Use {@link listCollectionTree} instead. */
852
1315
  async listFolderTree(options) {
1316
+ warnDeprecatedMethod("listFolderTree", "listCollectionTree");
853
1317
  const params = {};
854
1318
  if (options?.key) params.key = options.key;
855
1319
  if (options?.mode) params.mode = options.mode;
856
1320
  return this.request("GET", `${this.paths.foldersTreeRoot()}/`, { params });
857
1321
  }
1322
+ /** @deprecated Use {@link createCollection} instead. */
858
1323
  async createFolder(payload) {
1324
+ warnDeprecatedMethod("createFolder", "createCollection");
859
1325
  return this.request("POST", `${this.paths.foldersTreeRoot()}/`, { jsonBody: payload });
860
1326
  }
1327
+ /** @deprecated Use {@link updateCollection} instead. */
861
1328
  async updateFolder(folderKey, payload) {
1329
+ warnDeprecatedMethod("updateFolder", "updateCollection");
862
1330
  const key = resolveKey(folderKey);
863
1331
  return this.request("PUT", `${this.paths.foldersTreeItem()}/`, {
864
1332
  params: { key },
865
1333
  jsonBody: payload
866
1334
  });
867
1335
  }
1336
+ /** @deprecated Use {@link deleteCollection} instead. */
868
1337
  async deleteFolder(folderKey) {
1338
+ warnDeprecatedMethod("deleteFolder", "deleteCollection");
869
1339
  const key = resolveKey(folderKey);
870
1340
  await this.request("DELETE", `${this.paths.foldersTreeItem()}/`, {
871
1341
  params: { key },
@@ -873,13 +1343,17 @@ var ManagementClient = class {
873
1343
  });
874
1344
  }
875
1345
  // ------------------------------------------------------------------ //
876
- // Folder version operations
1346
+ // Folder version operations (deprecated)
877
1347
  // ------------------------------------------------------------------ //
1348
+ /** @deprecated Use {@link listCollectionVersions} instead. */
878
1349
  async listFolderVersions(folderKey, params) {
1350
+ warnDeprecatedMethod("listFolderVersions", "listCollectionVersions");
879
1351
  const key = resolveKey(folderKey);
880
1352
  return this.request("GET", `${this.paths.folderVersionsBase(key)}/`, { params });
881
1353
  }
1354
+ /** @deprecated Use {@link createCollectionVersion} instead. */
882
1355
  async createFolderVersion(folderKey, payload, options) {
1356
+ warnDeprecatedMethod("createFolderVersion", "createCollectionVersion");
883
1357
  const key = resolveKey(folderKey);
884
1358
  const params = {};
885
1359
  if (options?.copyFrom) {
@@ -890,7 +1364,9 @@ var ManagementClient = class {
890
1364
  params: Object.keys(params).length > 0 ? params : void 0
891
1365
  });
892
1366
  }
1367
+ /** @deprecated Use {@link getCollectionVersion} instead. */
893
1368
  async getFolderVersion(folderKey, versionKey, options) {
1369
+ warnDeprecatedMethod("getFolderVersion", "getCollectionVersion");
894
1370
  const fKey = resolveKey(folderKey);
895
1371
  const vKey = resolveKey(versionKey);
896
1372
  const params = {};
@@ -901,48 +1377,62 @@ var ManagementClient = class {
901
1377
  params: Object.keys(params).length > 0 ? params : void 0
902
1378
  });
903
1379
  }
1380
+ /** @deprecated Use {@link updateCollectionVersion} instead. */
904
1381
  async updateFolderVersion(folderKey, versionKey, payload) {
1382
+ warnDeprecatedMethod("updateFolderVersion", "updateCollectionVersion");
905
1383
  const fKey = resolveKey(folderKey);
906
1384
  const vKey = resolveKey(versionKey);
907
1385
  return this.request("PUT", `${this.paths.folderVersionsBase(fKey)}/${vKey}/`, {
908
1386
  jsonBody: payload
909
1387
  });
910
1388
  }
1389
+ /** @deprecated Use {@link deleteCollectionVersion} instead. */
911
1390
  async deleteFolderVersion(folderKey, versionKey) {
1391
+ warnDeprecatedMethod("deleteFolderVersion", "deleteCollectionVersion");
912
1392
  const fKey = resolveKey(folderKey);
913
1393
  const vKey = resolveKey(versionKey);
914
1394
  await this.request("DELETE", `${this.paths.folderVersionsBase(fKey)}/${vKey}/`, {
915
1395
  parseJson: false
916
1396
  });
917
1397
  }
1398
+ /** @deprecated Use {@link publishCollectionVersion} instead. */
918
1399
  async publishFolderVersion(folderKey, versionKey) {
1400
+ warnDeprecatedMethod("publishFolderVersion", "publishCollectionVersion");
919
1401
  const fKey = resolveKey(folderKey);
920
1402
  const vKey = resolveKey(versionKey);
921
1403
  return this.request("POST", `${this.paths.folderVersionsBase(fKey)}/${vKey}/publish/`);
922
1404
  }
923
1405
  // ------------------------------------------------------------------ //
924
- // Folder field operations
1406
+ // Folder field operations (deprecated)
925
1407
  // ------------------------------------------------------------------ //
1408
+ /** @deprecated Use {@link listCollectionFields} instead. */
926
1409
  async listFolderFields(folderKey, versionKey, params) {
1410
+ warnDeprecatedMethod("listFolderFields", "listCollectionFields");
927
1411
  const fKey = resolveKey(folderKey);
928
1412
  const vKey = resolveKey(versionKey);
929
1413
  return this.request("GET", `${this.paths.folderSchemaTree(fKey, vKey)}/`, { params });
930
1414
  }
1415
+ /** @deprecated Use {@link createCollectionField} instead. */
931
1416
  async createFolderField(folderKey, versionKey, payload) {
1417
+ warnDeprecatedMethod("createFolderField", "createCollectionField");
932
1418
  const fKey = resolveKey(folderKey);
933
1419
  const vKey = resolveKey(versionKey);
934
1420
  return this.request("POST", `${this.paths.folderSchemaTree(fKey, vKey)}/`, {
935
1421
  jsonBody: payload
936
1422
  });
937
1423
  }
1424
+ /** @deprecated Use {@link getCollectionField} instead. */
938
1425
  async getFolderField(folderKey, versionKey, fieldPath) {
1426
+ warnDeprecatedMethod("getFolderField", "getCollectionField");
939
1427
  const fKey = resolveKey(folderKey);
940
1428
  const vKey = resolveKey(versionKey);
941
1429
  return this.request("GET", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
942
1430
  params: { path: fieldPath }
943
1431
  });
944
1432
  }
1433
+ /** @deprecated Use {@link updateCollectionField} instead. */
945
1434
  async updateFolderField(folderKey, versionKey, fieldPath, payload) {
1435
+ warnDeprecatedMethod("updateFolderField", "updateCollectionField");
946
1436
  const fKey = resolveKey(folderKey);
947
1437
  const vKey = resolveKey(versionKey);
948
1438
  return this.request("PUT", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
@@ -950,7 +1440,9 @@ var ManagementClient = class {
950
1440
  jsonBody: payload
951
1441
  });
952
1442
  }
1443
+ /** @deprecated Use {@link deleteCollectionField} instead. */
953
1444
  async deleteFolderField(folderKey, versionKey, fieldPath) {
1445
+ warnDeprecatedMethod("deleteFolderField", "deleteCollectionField");
954
1446
  const fKey = resolveKey(folderKey);
955
1447
  const vKey = resolveKey(versionKey);
956
1448
  await this.request("DELETE", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
@@ -1078,32 +1570,41 @@ var ManagementClient = class {
1078
1570
  return this.request("GET", `${this.paths.resourceBase(fKey)}/${rKey}/`);
1079
1571
  }
1080
1572
  async createResource(folderKey, payload, options) {
1081
- const key = resolveKey(folderKey);
1082
- const params = {};
1083
- if (options?.component) {
1084
- params.component = resolveKey(options.component);
1573
+ if (options && typeof options === "object" && "component" in options) {
1574
+ throw new TypeError(
1575
+ "The `component` option has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your call site."
1576
+ );
1085
1577
  }
1578
+ const key = resolveKey(folderKey);
1086
1579
  const body = { ...payload };
1087
1580
  if (options?.externalId) {
1088
1581
  body.external_id = options.externalId;
1089
1582
  }
1090
1583
  return this.request("POST", `${this.paths.resourceBase(key)}/`, {
1091
- params: Object.keys(params).length ? params : void 0,
1092
1584
  jsonBody: body
1093
1585
  });
1094
1586
  }
1095
1587
  async upsertResource(folderKey, payload, options) {
1588
+ if (options && typeof options === "object" && "component" in options) {
1589
+ throw new TypeError(
1590
+ "The `component` option has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your call site."
1591
+ );
1592
+ }
1096
1593
  const key = resolveKey(folderKey);
1097
1594
  const params = { external_id: options.externalId };
1098
- if (options.component) {
1099
- params.component = resolveKey(options.component);
1100
- }
1101
1595
  return this.request("PUT", `${this.paths.resourceBase(key)}/`, {
1102
1596
  params,
1103
1597
  jsonBody: payload
1104
1598
  });
1105
1599
  }
1106
1600
  async batchUpsertResources(folderKey, items, options) {
1601
+ for (const item of items) {
1602
+ if (item && typeof item === "object" && "component" in item) {
1603
+ throw new TypeError(
1604
+ "BatchUpsertItem.component has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your batch items."
1605
+ );
1606
+ }
1607
+ }
1107
1608
  const fKey = resolveKey(folderKey);
1108
1609
  const maxConcurrency = options?.maxConcurrency ?? 5;
1109
1610
  if (maxConcurrency < 1) {
@@ -1121,9 +1622,6 @@ var ManagementClient = class {
1121
1622
  const processItem = async (index, item) => {
1122
1623
  try {
1123
1624
  const params = { external_id: item.external_id };
1124
- if (item.component) {
1125
- params.component = item.component;
1126
- }
1127
1625
  const result = await this.request(
1128
1626
  "PUT",
1129
1627
  `${this.paths.resourceBase(fKey)}/`,
@@ -1356,6 +1854,156 @@ var ManagementClient = class {
1356
1854
  }
1357
1855
  };
1358
1856
 
1857
+ // src/flux/models.ts
1858
+ var SearchMode = {
1859
+ TEXT: "text",
1860
+ VECTOR: "vector",
1861
+ VECTOR_BOOSTED: "vector_boosted",
1862
+ HYBRID: "hybrid"
1863
+ };
1864
+ var SEARCH_REQUEST_KNOWN_KEYS = /* @__PURE__ */ new Set([
1865
+ "search_mode",
1866
+ "find_text",
1867
+ "find_phrase",
1868
+ "vector_search",
1869
+ "vector_field_search",
1870
+ "vector_boost_config",
1871
+ "hybrid_config",
1872
+ "limit",
1873
+ "offset"
1874
+ ]);
1875
+ function checkFinite(value, name) {
1876
+ if (!Number.isFinite(value)) {
1877
+ throw new Error(`${name} must be a finite number`);
1878
+ }
1879
+ }
1880
+ function checkThreshold(value, name) {
1881
+ if (value != null) {
1882
+ checkFinite(value, name);
1883
+ if (value < 0 || value > 1) {
1884
+ throw new Error(`${name} must be between 0.0 and 1.0`);
1885
+ }
1886
+ }
1887
+ }
1888
+ function checkPositiveInt(value, name) {
1889
+ if (value != null) {
1890
+ checkFinite(value, name);
1891
+ if (!Number.isInteger(value) || value < 1) {
1892
+ throw new Error(`${name} must be a positive integer (>= 1)`);
1893
+ }
1894
+ }
1895
+ }
1896
+ function validateVectorSearch(vs) {
1897
+ checkPositiveInt(vs.top_k, "top_k");
1898
+ checkThreshold(vs.similarity_threshold, "similarity_threshold");
1899
+ }
1900
+ function validateVectorFieldSearch(vfs) {
1901
+ if (!vfs.query_vector || vfs.query_vector.length === 0) {
1902
+ throw new Error("query_vector must not be empty");
1903
+ }
1904
+ for (let i = 0; i < vfs.query_vector.length; i++) {
1905
+ if (!Number.isFinite(vfs.query_vector[i])) {
1906
+ throw new Error(`query_vector[${i}] must be a finite number`);
1907
+ }
1908
+ }
1909
+ checkPositiveInt(vfs.top_k, "top_k");
1910
+ checkThreshold(vfs.similarity_threshold, "similarity_threshold");
1911
+ }
1912
+ function validateBoostConfig(cfg) {
1913
+ if (cfg.boost_factor != null) {
1914
+ checkFinite(cfg.boost_factor, "boost_factor");
1915
+ if (cfg.boost_factor <= 0) {
1916
+ throw new Error("boost_factor must be > 0");
1917
+ }
1918
+ }
1919
+ checkThreshold(cfg.similarity_threshold, "similarity_threshold");
1920
+ checkPositiveInt(cfg.max_boost_results, "max_boost_results");
1921
+ }
1922
+ function validateHybridConfig(cfg) {
1923
+ if (cfg.vector_weight != null) {
1924
+ checkFinite(cfg.vector_weight, "vector_weight");
1925
+ if (cfg.vector_weight < 0 || cfg.vector_weight > 1) {
1926
+ throw new Error("vector_weight must be between 0.0 and 1.0");
1927
+ }
1928
+ }
1929
+ if (cfg.text_weight != null) {
1930
+ checkFinite(cfg.text_weight, "text_weight");
1931
+ if (cfg.text_weight < 0 || cfg.text_weight > 1) {
1932
+ throw new Error("text_weight must be between 0.0 and 1.0");
1933
+ }
1934
+ }
1935
+ const vw = cfg.vector_weight ?? 0.6;
1936
+ const tw = cfg.text_weight ?? 0.4;
1937
+ if (Math.abs(vw + tw - 1) > 1e-6) {
1938
+ throw new Error(`vector_weight + text_weight must equal 1.0, got ${vw + tw}`);
1939
+ }
1940
+ }
1941
+ function buildSearchBody(req) {
1942
+ const mode = req.search_mode ?? SearchMode.TEXT;
1943
+ const vs = req.vector_search;
1944
+ const vfs = req.vector_field_search;
1945
+ const boost = req.vector_boost_config;
1946
+ const hybrid = req.hybrid_config;
1947
+ const hasText = req.find_text != null || req.find_phrase != null;
1948
+ if (vs) validateVectorSearch(vs);
1949
+ if (vfs) validateVectorFieldSearch(vfs);
1950
+ if (boost) validateBoostConfig(boost);
1951
+ if (hybrid) validateHybridConfig(hybrid);
1952
+ if (vs && vfs) {
1953
+ throw new Error("vector_search and vector_field_search are mutually exclusive");
1954
+ }
1955
+ if (mode === SearchMode.TEXT) {
1956
+ if (vs) throw new Error("vector_search is not allowed in text search mode");
1957
+ if (vfs) throw new Error("vector_field_search is not allowed in text search mode");
1958
+ if (boost) throw new Error("vector_boost_config is not allowed in text search mode");
1959
+ if (hybrid) throw new Error("hybrid_config is not allowed in text search mode");
1960
+ } else if (mode === SearchMode.VECTOR) {
1961
+ if (!vs && !vfs) {
1962
+ throw new Error("vector search mode requires vector_search or vector_field_search");
1963
+ }
1964
+ if (boost) throw new Error("vector_boost_config is not allowed in vector search mode");
1965
+ if (hybrid) throw new Error("hybrid_config is not allowed in vector search mode");
1966
+ } else if (mode === SearchMode.VECTOR_BOOSTED) {
1967
+ if (!vs && !vfs) {
1968
+ throw new Error("vector_boosted mode requires vector_search or vector_field_search");
1969
+ }
1970
+ if (!hasText) throw new Error("vector_boosted mode requires find_text or find_phrase");
1971
+ if (hybrid) throw new Error("hybrid_config is not allowed in vector_boosted mode");
1972
+ } else if (mode === SearchMode.HYBRID) {
1973
+ if (vfs) throw new Error("vector_field_search is not allowed in hybrid mode");
1974
+ if (!vs) throw new Error("hybrid mode requires vector_search");
1975
+ if (!hasText) throw new Error("hybrid mode requires find_text or find_phrase");
1976
+ if (boost) throw new Error("vector_boost_config is not allowed in hybrid mode");
1977
+ } else {
1978
+ const validModes = Object.values(SearchMode).join(", ");
1979
+ throw new Error(`Unknown search_mode: "${mode}". Valid modes: ${validModes}`);
1980
+ }
1981
+ const body = {};
1982
+ for (const [key, value] of Object.entries(req)) {
1983
+ if (value !== void 0) {
1984
+ body[key] = value;
1985
+ }
1986
+ }
1987
+ if (!body.search_mode) {
1988
+ body.search_mode = mode;
1989
+ }
1990
+ return body;
1991
+ }
1992
+ function mergeExtra(validated, extra) {
1993
+ const conflicts = [];
1994
+ for (const key of Object.keys(extra)) {
1995
+ if (SEARCH_REQUEST_KNOWN_KEYS.has(key)) {
1996
+ conflicts.push(key);
1997
+ }
1998
+ }
1999
+ if (conflicts.length > 0) {
2000
+ throw new Error(
2001
+ `extra keys conflict with SearchRequest fields: ${conflicts.sort().join(", ")}. Use the explicit parameters instead.`
2002
+ );
2003
+ }
2004
+ return { ...validated, ...extra };
2005
+ }
2006
+
1359
2007
  // src/flux/client.ts
1360
2008
  function cleanPrefix(prefix) {
1361
2009
  const value = prefix.replace(/^\/+|\/+$/g, "");
@@ -1367,6 +2015,15 @@ function cleanPrefix(prefix) {
1367
2015
  function normalizeFolderPath(folderPath) {
1368
2016
  return folderPath.replace(/^\/+|\/+$/g, "");
1369
2017
  }
2018
+ function stripUndefined(obj) {
2019
+ const result = {};
2020
+ for (const [key, value] of Object.entries(obj)) {
2021
+ if (value !== void 0) {
2022
+ result[key] = value;
2023
+ }
2024
+ }
2025
+ return result;
2026
+ }
1370
2027
  var FluxClient = class {
1371
2028
  apiPrefix;
1372
2029
  transport;
@@ -1400,6 +2057,123 @@ var FluxClient = class {
1400
2057
  const path = this.buildPath(folderPath, "/_search");
1401
2058
  return this.transport.request("POST", path, { jsonBody: body });
1402
2059
  }
2060
+ /** Semantic search using auto-generated embeddings. */
2061
+ async vectorSearch(folderPath, options) {
2062
+ const { query, fields, top_k = 10, similarity_threshold, limit, offset, ...rest } = options;
2063
+ const extra = stripUndefined(rest);
2064
+ const vs = { query, fields, top_k, similarity_threshold };
2065
+ const req = {
2066
+ search_mode: SearchMode.VECTOR,
2067
+ vector_search: vs,
2068
+ limit,
2069
+ offset
2070
+ };
2071
+ const body = mergeExtra(buildSearchBody(req), extra);
2072
+ return this.search(folderPath, body);
2073
+ }
2074
+ /** Search using custom pre-computed embeddings. */
2075
+ async vectorFieldSearch(folderPath, options) {
2076
+ const {
2077
+ field,
2078
+ query_vector,
2079
+ top_k = 10,
2080
+ similarity_threshold,
2081
+ limit,
2082
+ offset,
2083
+ ...rest
2084
+ } = options;
2085
+ const extra = stripUndefined(rest);
2086
+ const vfs = { field, query_vector, top_k, similarity_threshold };
2087
+ const req = {
2088
+ search_mode: SearchMode.VECTOR,
2089
+ vector_field_search: vfs,
2090
+ limit,
2091
+ offset
2092
+ };
2093
+ const body = mergeExtra(buildSearchBody(req), extra);
2094
+ return this.search(folderPath, body);
2095
+ }
2096
+ /** Blended text + vector search with configurable weights. */
2097
+ async hybridSearch(folderPath, options) {
2098
+ const {
2099
+ query,
2100
+ find_text,
2101
+ fields,
2102
+ top_k = 10,
2103
+ similarity_threshold,
2104
+ vector_weight = 0.6,
2105
+ text_weight = 0.4,
2106
+ rerank_results = true,
2107
+ limit,
2108
+ offset,
2109
+ ...rest
2110
+ } = options;
2111
+ const extra = stripUndefined(rest);
2112
+ const vs = { query, fields, top_k, similarity_threshold };
2113
+ const hybrid = { vector_weight, text_weight, rerank_results };
2114
+ const req = {
2115
+ search_mode: SearchMode.HYBRID,
2116
+ find_text,
2117
+ vector_search: vs,
2118
+ hybrid_config: hybrid,
2119
+ limit,
2120
+ offset
2121
+ };
2122
+ const body = mergeExtra(buildSearchBody(req), extra);
2123
+ return this.search(folderPath, body);
2124
+ }
2125
+ /** Text search with results boosted by vector similarity. */
2126
+ async boostedSearch(folderPath, options) {
2127
+ const {
2128
+ find_text,
2129
+ query,
2130
+ field,
2131
+ query_vector,
2132
+ top_k = 10,
2133
+ similarity_threshold,
2134
+ boost_factor = 1.5,
2135
+ boost_similarity_threshold,
2136
+ max_boost_results = 20,
2137
+ limit,
2138
+ offset,
2139
+ ...rest
2140
+ } = options;
2141
+ const extra = stripUndefined(rest);
2142
+ const hasAuto = query != null;
2143
+ const hasCustom = field != null || query_vector != null;
2144
+ if (hasAuto && hasCustom) {
2145
+ throw new Error(
2146
+ "Provide either 'query' for auto-generated embeddings or 'field' + 'query_vector' for custom embeddings, not both"
2147
+ );
2148
+ }
2149
+ let vs;
2150
+ let vfs;
2151
+ if (hasAuto) {
2152
+ vs = { query, top_k, similarity_threshold };
2153
+ } else if (field != null && query_vector != null) {
2154
+ vfs = { field, query_vector, top_k, similarity_threshold };
2155
+ } else {
2156
+ throw new Error(
2157
+ "Provide either 'query' for auto-generated embeddings or 'field' + 'query_vector' for custom embeddings"
2158
+ );
2159
+ }
2160
+ const boostConfig = {
2161
+ boost_factor,
2162
+ similarity_threshold: boost_similarity_threshold,
2163
+ max_boost_results
2164
+ };
2165
+ const req = {
2166
+ search_mode: SearchMode.VECTOR_BOOSTED,
2167
+ find_text,
2168
+ vector_search: vs,
2169
+ vector_field_search: vfs,
2170
+ vector_boost_config: boostConfig,
2171
+ limit,
2172
+ offset
2173
+ };
2174
+ const body = mergeExtra(buildSearchBody(req), extra);
2175
+ return this.search(folderPath, body);
2176
+ }
1403
2177
  async getRouter() {
1404
2178
  const path = `/${this.apiPrefix}/_router`;
1405
2179
  return this.transport.request("GET", path);
@@ -1425,12 +2199,19 @@ var FluxClient = class {
1425
2199
  HttpTransport,
1426
2200
  JWTAuth,
1427
2201
  ManagementClient,
2202
+ PlanExhaustedError,
2203
+ PlanLimitExceededError,
2204
+ RateLimitExceededError,
1428
2205
  SDK_VERSION,
2206
+ SearchMode,
1429
2207
  SecureKeyAuth,
1430
2208
  SimpleKeyAuth,
2209
+ SpendCapExceededError,
1431
2210
  StaticTokenProvider,
1432
2211
  VERSION,
2212
+ buildSearchBody,
1433
2213
  createConfig,
2214
+ nestedFieldMeta,
1434
2215
  resolveKey
1435
2216
  });
1436
2217
  //# sourceMappingURL=index.cjs.map