@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/README.md +139 -5
- package/dist/index.cjs +623 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +348 -11
- package/dist/index.d.ts +348 -11
- package/dist/index.js +614 -25
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -63,6 +63,167 @@ var FoxnoseAPIError = class extends FoxnoseError {
|
|
|
63
63
|
this.responseBody = options.responseBody;
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
|
+
var SpendCapExceededError = class extends FoxnoseAPIError {
|
|
67
|
+
/** Spend cap in USD, or null when unset on the server side. */
|
|
68
|
+
capUsd;
|
|
69
|
+
/** ISO timestamp when the current billing cycle resets. */
|
|
70
|
+
cycleResetsAt;
|
|
71
|
+
/** URL where the spend cap can be raised. */
|
|
72
|
+
raiseCapUrl;
|
|
73
|
+
constructor(options) {
|
|
74
|
+
super(options);
|
|
75
|
+
this.name = "SpendCapExceededError";
|
|
76
|
+
this.capUsd = options.capUsd;
|
|
77
|
+
this.cycleResetsAt = options.cycleResetsAt;
|
|
78
|
+
this.raiseCapUrl = options.raiseCapUrl;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var PlanExhaustedError = class extends FoxnoseAPIError {
|
|
82
|
+
/** Usage axis that was exhausted (e.g. retrievals, writes, data_storage, vector_storage). */
|
|
83
|
+
axis;
|
|
84
|
+
/** ISO timestamp when the usage window resets. */
|
|
85
|
+
windowResetsAt;
|
|
86
|
+
/** URL where the plan can be upgraded. */
|
|
87
|
+
upgradeUrl;
|
|
88
|
+
constructor(options) {
|
|
89
|
+
super(options);
|
|
90
|
+
this.name = "PlanExhaustedError";
|
|
91
|
+
this.axis = options.axis;
|
|
92
|
+
this.windowResetsAt = options.windowResetsAt;
|
|
93
|
+
this.upgradeUrl = options.upgradeUrl;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var PlanLimitExceededError = class extends FoxnoseAPIError {
|
|
97
|
+
/** Entity whose limit was exceeded (e.g. collections, environments, api_keys). */
|
|
98
|
+
entity;
|
|
99
|
+
/** Maximum allowed by the current plan. */
|
|
100
|
+
limit;
|
|
101
|
+
/** Current count that triggered the error. */
|
|
102
|
+
current;
|
|
103
|
+
/** URL where the plan can be upgraded, if provided. */
|
|
104
|
+
upgradeUrl;
|
|
105
|
+
constructor(options) {
|
|
106
|
+
super(options);
|
|
107
|
+
this.name = "PlanLimitExceededError";
|
|
108
|
+
this.entity = options.entity;
|
|
109
|
+
this.limit = options.limit;
|
|
110
|
+
this.current = options.current;
|
|
111
|
+
this.upgradeUrl = options.upgradeUrl;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var RateLimitExceededError = class extends FoxnoseAPIError {
|
|
115
|
+
/** Seconds to wait before retrying, from the Retry-After header. */
|
|
116
|
+
retryAfter;
|
|
117
|
+
constructor(options) {
|
|
118
|
+
super(options);
|
|
119
|
+
this.name = "RateLimitExceededError";
|
|
120
|
+
this.retryAfter = options.retryAfter;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var CollectionNotWritableError = class extends FoxnoseAPIError {
|
|
124
|
+
constructor(options) {
|
|
125
|
+
super(options);
|
|
126
|
+
this.name = "CollectionNotWritableError";
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var ExternalIdConflictError = class extends FoxnoseAPIError {
|
|
130
|
+
constructor(options) {
|
|
131
|
+
super(options);
|
|
132
|
+
this.name = "ExternalIdConflictError";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var ContentValidationFailedError = class extends FoxnoseAPIError {
|
|
136
|
+
/** Individual validation problems; each includes a `json_path`. */
|
|
137
|
+
errors;
|
|
138
|
+
/** True when the server capped a very large error list. */
|
|
139
|
+
errorsTruncated;
|
|
140
|
+
constructor(options) {
|
|
141
|
+
super(options);
|
|
142
|
+
this.name = "ContentValidationFailedError";
|
|
143
|
+
this.errors = options.errors ?? [];
|
|
144
|
+
this.errorsTruncated = options.errorsTruncated ?? false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var UpstreamError = class extends FoxnoseAPIError {
|
|
148
|
+
constructor(options) {
|
|
149
|
+
super(options);
|
|
150
|
+
this.name = "UpstreamError";
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
function isPlainObject(value) {
|
|
154
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
155
|
+
}
|
|
156
|
+
function getHeader(headers, name) {
|
|
157
|
+
if (!headers) {
|
|
158
|
+
return void 0;
|
|
159
|
+
}
|
|
160
|
+
const target = name.toLowerCase();
|
|
161
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
162
|
+
if (key.toLowerCase() === target) {
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
function buildAPIError(options) {
|
|
169
|
+
const { statusCode, errorCode, detail, responseHeaders, responseBody } = options;
|
|
170
|
+
const body = isPlainObject(responseBody) ? responseBody : void 0;
|
|
171
|
+
if (statusCode === 402 && errorCode === "spend_cap_reached" && body) {
|
|
172
|
+
return new SpendCapExceededError({
|
|
173
|
+
...options,
|
|
174
|
+
message: "message" in body ? options.message : "Spend cap reached",
|
|
175
|
+
capUsd: typeof body.cap_usd === "number" ? body.cap_usd : body.cap_usd === null ? null : void 0,
|
|
176
|
+
cycleResetsAt: typeof body.cycle_resets_at === "string" ? body.cycle_resets_at : void 0,
|
|
177
|
+
raiseCapUrl: typeof body.raise_cap_url === "string" ? body.raise_cap_url : void 0
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (statusCode === 402 && errorCode === "plan_exhausted" && body) {
|
|
181
|
+
return new PlanExhaustedError({
|
|
182
|
+
...options,
|
|
183
|
+
message: "message" in body ? options.message : "Plan allowance exhausted",
|
|
184
|
+
axis: typeof body.axis === "string" ? body.axis : void 0,
|
|
185
|
+
windowResetsAt: typeof body.window_resets_at === "string" ? body.window_resets_at : void 0,
|
|
186
|
+
upgradeUrl: typeof body.upgrade_url === "string" ? body.upgrade_url : void 0
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (statusCode === 403 && errorCode === "plan_limit_exceeded") {
|
|
190
|
+
const d = isPlainObject(detail) ? detail : {};
|
|
191
|
+
return new PlanLimitExceededError({
|
|
192
|
+
...options,
|
|
193
|
+
entity: typeof d.entity === "string" ? d.entity : void 0,
|
|
194
|
+
limit: typeof d.limit === "number" ? d.limit : void 0,
|
|
195
|
+
current: typeof d.current === "number" ? d.current : void 0,
|
|
196
|
+
upgradeUrl: typeof d.upgrade_url === "string" ? d.upgrade_url : void 0
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (statusCode === 429 && errorCode === "rate_limited") {
|
|
200
|
+
const raw = getHeader(responseHeaders, "Retry-After");
|
|
201
|
+
const parsed = raw !== void 0 ? Number(raw) : NaN;
|
|
202
|
+
return new RateLimitExceededError({
|
|
203
|
+
...options,
|
|
204
|
+
retryAfter: Number.isNaN(parsed) ? void 0 : parsed
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (statusCode === 403 && errorCode === "collection_not_writable") {
|
|
208
|
+
return new CollectionNotWritableError(options);
|
|
209
|
+
}
|
|
210
|
+
if (statusCode === 409 && errorCode === "external_id_conflict") {
|
|
211
|
+
return new ExternalIdConflictError(options);
|
|
212
|
+
}
|
|
213
|
+
if (statusCode === 422 && errorCode === "content_validation_failed") {
|
|
214
|
+
const d = isPlainObject(detail) ? detail : {};
|
|
215
|
+
const errors = Array.isArray(d.errors) ? d.errors : typeof d.json_path === "string" ? [d] : [];
|
|
216
|
+
return new ContentValidationFailedError({
|
|
217
|
+
...options,
|
|
218
|
+
errors,
|
|
219
|
+
errorsTruncated: d.errors_truncated === true
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (statusCode === 502 && errorCode === "upstream_error") {
|
|
223
|
+
return new UpstreamError(options);
|
|
224
|
+
}
|
|
225
|
+
return new FoxnoseAPIError(options);
|
|
226
|
+
}
|
|
66
227
|
var FoxnoseAuthError = class extends FoxnoseError {
|
|
67
228
|
constructor(message) {
|
|
68
229
|
super(message);
|
|
@@ -147,7 +308,7 @@ var DEFAULT_RETRY_CONFIG = {
|
|
|
147
308
|
statusCodes: [408, 425, 429, 500, 502, 503, 504],
|
|
148
309
|
methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
|
|
149
310
|
};
|
|
150
|
-
var SDK_VERSION = "0.
|
|
311
|
+
var SDK_VERSION = "0.5.0";
|
|
151
312
|
var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
|
|
152
313
|
function createConfig(options) {
|
|
153
314
|
if (!options.baseUrl) {
|
|
@@ -276,6 +437,7 @@ var HttpTransport = class {
|
|
|
276
437
|
}
|
|
277
438
|
}
|
|
278
439
|
async sendWithRetries(method, path, options) {
|
|
440
|
+
const allowRetries = options?.allowRetries !== false;
|
|
279
441
|
for (let attempt = 1; attempt <= this.retry.attempts; attempt++) {
|
|
280
442
|
const { url, init } = this.buildRequest(method, path, options);
|
|
281
443
|
const controller = new AbortController();
|
|
@@ -286,7 +448,7 @@ var HttpTransport = class {
|
|
|
286
448
|
response = await fetch(url, init);
|
|
287
449
|
} catch (err) {
|
|
288
450
|
clearTimeout(timeoutId);
|
|
289
|
-
const delay = this.handleTransportError(err, method, attempt);
|
|
451
|
+
const delay = this.handleTransportError(err, method, attempt, !allowRetries);
|
|
290
452
|
if (delay > 0) {
|
|
291
453
|
await this.sleep(delay);
|
|
292
454
|
}
|
|
@@ -295,7 +457,7 @@ var HttpTransport = class {
|
|
|
295
457
|
clearTimeout(timeoutId);
|
|
296
458
|
}
|
|
297
459
|
if (response.status >= 400) {
|
|
298
|
-
if (this.shouldRetry(method, response.status) && attempt < this.retry.attempts) {
|
|
460
|
+
if (allowRetries && this.shouldRetry(method, response.status) && attempt < this.retry.attempts) {
|
|
299
461
|
const delay = this.computeDelay(attempt, response.headers.get("Retry-After"));
|
|
300
462
|
if (delay > 0) {
|
|
301
463
|
await this.sleep(delay);
|
|
@@ -308,8 +470,8 @@ var HttpTransport = class {
|
|
|
308
470
|
}
|
|
309
471
|
throw new FoxnoseTransportError("All retry attempts exhausted");
|
|
310
472
|
}
|
|
311
|
-
handleTransportError(err, method, attempt) {
|
|
312
|
-
const canRetry = this.retry.methods.includes(method.toUpperCase()) && attempt < this.retry.attempts;
|
|
473
|
+
handleTransportError(err, method, attempt, forbidRetry = false) {
|
|
474
|
+
const canRetry = !forbidRetry && this.retry.methods.includes(method.toUpperCase()) && attempt < this.retry.attempts;
|
|
313
475
|
if (!canRetry) {
|
|
314
476
|
const message = err instanceof Error ? err.message : String(err);
|
|
315
477
|
throw new FoxnoseTransportError(message);
|
|
@@ -327,10 +489,12 @@ var HttpTransport = class {
|
|
|
327
489
|
if (text) {
|
|
328
490
|
try {
|
|
329
491
|
const payload = JSON.parse(text);
|
|
330
|
-
message = payload.message ?? message;
|
|
331
|
-
errorCode = payload.error_code;
|
|
332
|
-
detail = payload.detail;
|
|
333
492
|
body = payload;
|
|
493
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
494
|
+
message = payload.message ?? message;
|
|
495
|
+
errorCode = payload.error_code;
|
|
496
|
+
detail = payload.detail;
|
|
497
|
+
}
|
|
334
498
|
} catch {
|
|
335
499
|
body = text;
|
|
336
500
|
}
|
|
@@ -341,7 +505,7 @@ var HttpTransport = class {
|
|
|
341
505
|
response.headers.forEach((value, key) => {
|
|
342
506
|
responseHeaders[key] = value;
|
|
343
507
|
});
|
|
344
|
-
throw
|
|
508
|
+
throw buildAPIError({
|
|
345
509
|
message: message || "API request failed",
|
|
346
510
|
statusCode: response.status,
|
|
347
511
|
errorCode,
|
|
@@ -355,7 +519,38 @@ var HttpTransport = class {
|
|
|
355
519
|
}
|
|
356
520
|
};
|
|
357
521
|
|
|
522
|
+
// src/_deprecation.ts
|
|
523
|
+
var warned = /* @__PURE__ */ new Set();
|
|
524
|
+
function warnDeprecatedMethod(oldName, newName, removal = "1.0") {
|
|
525
|
+
if (warned.has(oldName)) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
warned.add(oldName);
|
|
529
|
+
console.warn(
|
|
530
|
+
`@foxnose/sdk: ${oldName}() is deprecated; use ${newName}() instead. ${oldName}() will be removed in @foxnose/sdk ${removal}.`
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
358
534
|
// src/management/models.ts
|
|
535
|
+
function nestedFieldMeta(opts) {
|
|
536
|
+
if (opts.extra) {
|
|
537
|
+
const reserved = ["component", "component_version", "auto_update"];
|
|
538
|
+
const collisions = reserved.filter(
|
|
539
|
+
(k) => Object.prototype.hasOwnProperty.call(opts.extra, k)
|
|
540
|
+
);
|
|
541
|
+
if (collisions.length > 0) {
|
|
542
|
+
throw new Error(
|
|
543
|
+
`nestedFieldMeta: 'extra' must not include reserved keys: ${collisions.join(", ")}`
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
...opts.extra ?? {},
|
|
549
|
+
component: opts.component,
|
|
550
|
+
component_version: opts.componentVersion,
|
|
551
|
+
auto_update: opts.autoUpdate ?? false
|
|
552
|
+
};
|
|
553
|
+
}
|
|
359
554
|
function resolveKey(value) {
|
|
360
555
|
if (typeof value === "string") {
|
|
361
556
|
return value;
|
|
@@ -375,11 +570,18 @@ function managementPaths(environmentKey) {
|
|
|
375
570
|
projectRoot: (orgKey, projectKey) => `/organizations/${orgKey}/projects/${projectKey}`,
|
|
376
571
|
environmentsBase: (orgKey, projectKey) => `/organizations/${orgKey}/projects/${projectKey}/environments`,
|
|
377
572
|
environmentRoot: (orgKey, projectKey, envKey) => `/organizations/${orgKey}/projects/${projectKey}/environments/${envKey}`,
|
|
378
|
-
// Folder paths
|
|
573
|
+
// Folder paths (deprecated — see Collection paths below).
|
|
379
574
|
foldersTreeRoot: () => `/v1/${environmentKey}/folders/tree`,
|
|
380
575
|
foldersTreeItem: () => `/v1/${environmentKey}/folders/tree/folder`,
|
|
381
576
|
folderVersionsBase: (folderKey) => `/v1/${environmentKey}/folders/${folderKey}/model/versions`,
|
|
382
577
|
folderSchemaTree: (folderKey, versionKey) => `/v1/${environmentKey}/folders/${folderKey}/model/versions/${versionKey}/schema/tree`,
|
|
578
|
+
// Collection paths (canonical going forward; folder paths above hit the
|
|
579
|
+
// deprecated /folders/ URL alias on the server side).
|
|
580
|
+
collectionsTreeRoot: () => `/v1/${environmentKey}/collections/tree`,
|
|
581
|
+
collectionsTreeItem: () => `/v1/${environmentKey}/collections/tree/collection`,
|
|
582
|
+
collectionVersionsBase: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/model/versions`,
|
|
583
|
+
collectionSchemaTree: (collectionKey, versionKey) => `/v1/${environmentKey}/collections/${collectionKey}/model/versions/${versionKey}/schema/tree`,
|
|
584
|
+
collectionSyncComponent: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/sync_component`,
|
|
383
585
|
// Component paths
|
|
384
586
|
componentsRoot: () => `/v1/${environmentKey}/components`,
|
|
385
587
|
componentRoot: (componentKey) => `/v1/${environmentKey}/components/${componentKey}`,
|
|
@@ -398,6 +600,7 @@ function managementPaths(environmentKey) {
|
|
|
398
600
|
apisRoot: () => `/v1/${environmentKey}/api`,
|
|
399
601
|
apiRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}`,
|
|
400
602
|
apiFoldersRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}/folders`,
|
|
603
|
+
apiCollectionsRoot: (apiKey) => `/v1/${environmentKey}/api/${apiKey}/collections`,
|
|
401
604
|
// Management role paths
|
|
402
605
|
managementRolesRoot: () => `/v1/${environmentKey}/permissions/management-api/roles`,
|
|
403
606
|
managementRoleRoot: (roleKey) => `/v1/${environmentKey}/permissions/management-api/roles/${roleKey}`,
|
|
@@ -583,13 +786,84 @@ var ManagementClient = class {
|
|
|
583
786
|
await this.request("DELETE", `${this.paths.apiRoot(key)}/`, { parseJson: false });
|
|
584
787
|
}
|
|
585
788
|
// ------------------------------------------------------------------ //
|
|
586
|
-
// API
|
|
789
|
+
// API ↔ Collection association (canonical)
|
|
587
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 };
|
|
799
|
+
if (options?.allowedMethods !== void 0) {
|
|
800
|
+
body.allowed_methods = options.allowedMethods;
|
|
801
|
+
}
|
|
802
|
+
if (options?.descriptionGetOne !== void 0) {
|
|
803
|
+
body.description_get_one = options.descriptionGetOne;
|
|
804
|
+
}
|
|
805
|
+
if (options?.descriptionGetMany !== void 0) {
|
|
806
|
+
body.description_get_many = options.descriptionGetMany;
|
|
807
|
+
}
|
|
808
|
+
if (options?.descriptionSearch !== void 0) {
|
|
809
|
+
body.description_search = options.descriptionSearch;
|
|
810
|
+
}
|
|
811
|
+
if (options?.descriptionSchema !== void 0) {
|
|
812
|
+
body.description_schema = options.descriptionSchema;
|
|
813
|
+
}
|
|
814
|
+
return this.request("POST", `${this.paths.apiCollectionsRoot(aKey)}/`, {
|
|
815
|
+
jsonBody: body
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
async getApiCollection(apiKey, collectionKey) {
|
|
819
|
+
const aKey = resolveKey(apiKey);
|
|
820
|
+
const cKey = resolveKey(collectionKey);
|
|
821
|
+
return this.request("GET", `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`);
|
|
822
|
+
}
|
|
823
|
+
async updateApiCollection(apiKey, collectionKey, options) {
|
|
824
|
+
const aKey = resolveKey(apiKey);
|
|
825
|
+
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
|
+
}
|
|
842
|
+
return this.request("PUT", `${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`, {
|
|
843
|
+
jsonBody: body
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
async removeApiCollection(apiKey, collectionKey) {
|
|
847
|
+
const aKey = resolveKey(apiKey);
|
|
848
|
+
const cKey = resolveKey(collectionKey);
|
|
849
|
+
await this.request(
|
|
850
|
+
"DELETE",
|
|
851
|
+
`${this.paths.apiCollectionsRoot(aKey)}/${cKey}/`,
|
|
852
|
+
{ parseJson: false }
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
// ------------------------------------------------------------------ //
|
|
856
|
+
// API ↔ Folder association (deprecated; hits legacy /folders/ URL)
|
|
857
|
+
// ------------------------------------------------------------------ //
|
|
858
|
+
/** @deprecated Use {@link listApiCollections} instead. */
|
|
588
859
|
async listApiFolders(apiKey, params) {
|
|
860
|
+
warnDeprecatedMethod("listApiFolders", "listApiCollections");
|
|
589
861
|
const key = resolveKey(apiKey);
|
|
590
862
|
return this.request("GET", `${this.paths.apiFoldersRoot(key)}/`, { params });
|
|
591
863
|
}
|
|
864
|
+
/** @deprecated Use {@link addApiCollection} instead. */
|
|
592
865
|
async addApiFolder(apiKey, folderKey, options) {
|
|
866
|
+
warnDeprecatedMethod("addApiFolder", "addApiCollection");
|
|
593
867
|
const aKey = resolveKey(apiKey);
|
|
594
868
|
const fKey = resolveKey(folderKey);
|
|
595
869
|
const body = { folder: fKey };
|
|
@@ -610,12 +884,16 @@ var ManagementClient = class {
|
|
|
610
884
|
}
|
|
611
885
|
return this.request("POST", `${this.paths.apiFoldersRoot(aKey)}/`, { jsonBody: body });
|
|
612
886
|
}
|
|
887
|
+
/** @deprecated Use {@link getApiCollection} instead. */
|
|
613
888
|
async getApiFolder(apiKey, folderKey) {
|
|
889
|
+
warnDeprecatedMethod("getApiFolder", "getApiCollection");
|
|
614
890
|
const aKey = resolveKey(apiKey);
|
|
615
891
|
const fKey = resolveKey(folderKey);
|
|
616
892
|
return this.request("GET", `${this.paths.apiFoldersRoot(aKey)}/${fKey}/`);
|
|
617
893
|
}
|
|
894
|
+
/** @deprecated Use {@link updateApiCollection} instead. */
|
|
618
895
|
async updateApiFolder(apiKey, folderKey, options) {
|
|
896
|
+
warnDeprecatedMethod("updateApiFolder", "updateApiCollection");
|
|
619
897
|
const aKey = resolveKey(apiKey);
|
|
620
898
|
const fKey = resolveKey(folderKey);
|
|
621
899
|
const body = {};
|
|
@@ -638,7 +916,9 @@ var ManagementClient = class {
|
|
|
638
916
|
jsonBody: body
|
|
639
917
|
});
|
|
640
918
|
}
|
|
919
|
+
/** @deprecated Use {@link removeApiCollection} instead. */
|
|
641
920
|
async removeApiFolder(apiKey, folderKey) {
|
|
921
|
+
warnDeprecatedMethod("removeApiFolder", "removeApiCollection");
|
|
642
922
|
const aKey = resolveKey(apiKey);
|
|
643
923
|
const fKey = resolveKey(folderKey);
|
|
644
924
|
await this.request("DELETE", `${this.paths.apiFoldersRoot(aKey)}/${fKey}/`, {
|
|
@@ -790,39 +1070,271 @@ var ManagementClient = class {
|
|
|
790
1070
|
});
|
|
791
1071
|
}
|
|
792
1072
|
// ------------------------------------------------------------------ //
|
|
793
|
-
//
|
|
1073
|
+
// Collection operations (canonical)
|
|
1074
|
+
// ------------------------------------------------------------------ //
|
|
1075
|
+
async listCollections(params) {
|
|
1076
|
+
return this.request("GET", `${this.paths.collectionsTreeRoot()}/`, { params });
|
|
1077
|
+
}
|
|
1078
|
+
async getCollection(collectionKey) {
|
|
1079
|
+
const key = resolveKey(collectionKey);
|
|
1080
|
+
return this.request("GET", `${this.paths.collectionsTreeItem()}/`, {
|
|
1081
|
+
params: { key }
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
async getCollectionByPath(path) {
|
|
1085
|
+
return this.request("GET", `${this.paths.collectionsTreeItem()}/`, {
|
|
1086
|
+
params: { path }
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
async listCollectionTree(options) {
|
|
1090
|
+
const params = {};
|
|
1091
|
+
if (options?.key) params.key = options.key;
|
|
1092
|
+
if (options?.mode) params.mode = options.mode;
|
|
1093
|
+
return this.request("GET", `${this.paths.collectionsTreeRoot()}/`, { params });
|
|
1094
|
+
}
|
|
1095
|
+
async createCollection(payload) {
|
|
1096
|
+
return this.request("POST", `${this.paths.collectionsTreeRoot()}/`, {
|
|
1097
|
+
jsonBody: payload
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
async updateCollection(collectionKey, payload) {
|
|
1101
|
+
const key = resolveKey(collectionKey);
|
|
1102
|
+
return this.request("PUT", `${this.paths.collectionsTreeItem()}/`, {
|
|
1103
|
+
params: { key },
|
|
1104
|
+
jsonBody: payload
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
async deleteCollection(collectionKey) {
|
|
1108
|
+
const key = resolveKey(collectionKey);
|
|
1109
|
+
await this.request("DELETE", `${this.paths.collectionsTreeItem()}/`, {
|
|
1110
|
+
params: { key },
|
|
1111
|
+
parseJson: false
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
// ------------------------------------------------------------------ //
|
|
1115
|
+
// Collection schema version operations (canonical)
|
|
794
1116
|
// ------------------------------------------------------------------ //
|
|
1117
|
+
async listCollectionVersions(collectionKey, params) {
|
|
1118
|
+
const key = resolveKey(collectionKey);
|
|
1119
|
+
return this.request("GET", `${this.paths.collectionVersionsBase(key)}/`, {
|
|
1120
|
+
params
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
async createCollectionVersion(collectionKey, payload, options) {
|
|
1124
|
+
const key = resolveKey(collectionKey);
|
|
1125
|
+
const params = {};
|
|
1126
|
+
if (options?.copyFrom) {
|
|
1127
|
+
params.copy_from = resolveKey(options.copyFrom);
|
|
1128
|
+
}
|
|
1129
|
+
return this.request("POST", `${this.paths.collectionVersionsBase(key)}/`, {
|
|
1130
|
+
jsonBody: payload,
|
|
1131
|
+
params: Object.keys(params).length > 0 ? params : void 0
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
async getCollectionVersion(collectionKey, versionKey, options) {
|
|
1135
|
+
const cKey = resolveKey(collectionKey);
|
|
1136
|
+
const vKey = resolveKey(versionKey);
|
|
1137
|
+
const params = {};
|
|
1138
|
+
if (options?.includeSchema !== void 0) {
|
|
1139
|
+
params.include_schema = options.includeSchema;
|
|
1140
|
+
}
|
|
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
|
+
}
|
|
1149
|
+
async updateCollectionVersion(collectionKey, versionKey, payload) {
|
|
1150
|
+
const cKey = resolveKey(collectionKey);
|
|
1151
|
+
const vKey = resolveKey(versionKey);
|
|
1152
|
+
return this.request(
|
|
1153
|
+
"PUT",
|
|
1154
|
+
`${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
|
|
1155
|
+
{ jsonBody: payload }
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
async deleteCollectionVersion(collectionKey, versionKey) {
|
|
1159
|
+
const cKey = resolveKey(collectionKey);
|
|
1160
|
+
const vKey = resolveKey(versionKey);
|
|
1161
|
+
await this.request(
|
|
1162
|
+
"DELETE",
|
|
1163
|
+
`${this.paths.collectionVersionsBase(cKey)}/${vKey}/`,
|
|
1164
|
+
{ parseJson: false }
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
async publishCollectionVersion(collectionKey, versionKey) {
|
|
1168
|
+
const cKey = resolveKey(collectionKey);
|
|
1169
|
+
const vKey = resolveKey(versionKey);
|
|
1170
|
+
return this.request(
|
|
1171
|
+
"POST",
|
|
1172
|
+
`${this.paths.collectionVersionsBase(cKey)}/${vKey}/publish/`
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Advance pinned nested fields on a Collection to a target Component version.
|
|
1177
|
+
*
|
|
1178
|
+
* Creates a new published Collection schema version with the affected
|
|
1179
|
+
* `meta.component_version` pins advanced. Fields with `auto_update=true`
|
|
1180
|
+
* and fields already at the requested target version are reported in
|
|
1181
|
+
* `skipped` rather than advanced.
|
|
1182
|
+
*
|
|
1183
|
+
* @param collectionKey The Collection to sync.
|
|
1184
|
+
* @param options.fieldPaths Optional list of nested field paths to advance.
|
|
1185
|
+
* When omitted, every pinned (`auto_update=false`) nested field on the
|
|
1186
|
+
* Collection's current version is considered.
|
|
1187
|
+
* @param options.toVersions Optional per-path override mapping field path
|
|
1188
|
+
* to target Component Version UID. Paths not in this mapping advance to
|
|
1189
|
+
* the referenced Component's `current_version`. When both `fieldPaths`
|
|
1190
|
+
* and `toVersions` are supplied, every key in `toVersions` must also
|
|
1191
|
+
* appear in `fieldPaths`.
|
|
1192
|
+
*
|
|
1193
|
+
* @returns Summary of synced and skipped paths, plus the new
|
|
1194
|
+
* `schema_version` UID (`null` if no paths were advanced).
|
|
1195
|
+
*
|
|
1196
|
+
* @throws `Error` locally (before any HTTP request) when both `fieldPaths`
|
|
1197
|
+
* and `toVersions` are supplied AND `toVersions` contains a key that is
|
|
1198
|
+
* not in `fieldPaths` (mirrors the server-side validator so the misuse
|
|
1199
|
+
* surfaces at the call-site).
|
|
1200
|
+
* @throws `FoxnoseApiError` on:
|
|
1201
|
+
* - 409 `component_sync_conflict` — target version would break existing resources
|
|
1202
|
+
* - 422 `too_many_versions` — Collection schema quota exhausted
|
|
1203
|
+
* - 422 `validation_error` — request body invalid
|
|
1204
|
+
* - 404 — Collection or specified target version missing
|
|
1205
|
+
*
|
|
1206
|
+
* @example
|
|
1207
|
+
* ```ts
|
|
1208
|
+
* // Advance every pinned nested field to its Component's current version.
|
|
1209
|
+
* await client.syncCollectionComponent('articles');
|
|
1210
|
+
*
|
|
1211
|
+
* // Advance a specific path to a chosen Component version.
|
|
1212
|
+
* await client.syncCollectionComponent('articles', {
|
|
1213
|
+
* fieldPaths: ['seo'],
|
|
1214
|
+
* toVersions: { seo: 'ver-def67890' },
|
|
1215
|
+
* });
|
|
1216
|
+
* ```
|
|
1217
|
+
*/
|
|
1218
|
+
async syncCollectionComponent(collectionKey, options = {}) {
|
|
1219
|
+
const cKey = resolveKey(collectionKey);
|
|
1220
|
+
if (options.fieldPaths !== void 0 && options.toVersions !== void 0) {
|
|
1221
|
+
const fieldPathSet = new Set(options.fieldPaths);
|
|
1222
|
+
const extras = Object.keys(options.toVersions).filter((k) => !fieldPathSet.has(k)).sort();
|
|
1223
|
+
if (extras.length > 0) {
|
|
1224
|
+
throw new Error(
|
|
1225
|
+
`toVersions includes paths not present in fieldPaths: [${extras.join(", ")}]`
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
const body = {};
|
|
1230
|
+
if (options.fieldPaths !== void 0) {
|
|
1231
|
+
body.field_paths = options.fieldPaths;
|
|
1232
|
+
}
|
|
1233
|
+
if (options.toVersions !== void 0) {
|
|
1234
|
+
body.to_versions = options.toVersions;
|
|
1235
|
+
}
|
|
1236
|
+
return this.request(
|
|
1237
|
+
"POST",
|
|
1238
|
+
`${this.paths.collectionSyncComponent(cKey)}/`,
|
|
1239
|
+
{ jsonBody: body }
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
// ------------------------------------------------------------------ //
|
|
1243
|
+
// Collection schema field operations (canonical)
|
|
1244
|
+
// ------------------------------------------------------------------ //
|
|
1245
|
+
async listCollectionFields(collectionKey, versionKey, params) {
|
|
1246
|
+
const cKey = resolveKey(collectionKey);
|
|
1247
|
+
const vKey = resolveKey(versionKey);
|
|
1248
|
+
return this.request(
|
|
1249
|
+
"GET",
|
|
1250
|
+
`${this.paths.collectionSchemaTree(cKey, vKey)}/`,
|
|
1251
|
+
{ params }
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
async createCollectionField(collectionKey, versionKey, payload) {
|
|
1255
|
+
const cKey = resolveKey(collectionKey);
|
|
1256
|
+
const vKey = resolveKey(versionKey);
|
|
1257
|
+
return this.request(
|
|
1258
|
+
"POST",
|
|
1259
|
+
`${this.paths.collectionSchemaTree(cKey, vKey)}/`,
|
|
1260
|
+
{ jsonBody: payload }
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
async getCollectionField(collectionKey, versionKey, fieldPath) {
|
|
1264
|
+
const cKey = resolveKey(collectionKey);
|
|
1265
|
+
const vKey = resolveKey(versionKey);
|
|
1266
|
+
return this.request(
|
|
1267
|
+
"GET",
|
|
1268
|
+
`${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
|
|
1269
|
+
{ params: { path: fieldPath } }
|
|
1270
|
+
);
|
|
1271
|
+
}
|
|
1272
|
+
async updateCollectionField(collectionKey, versionKey, fieldPath, payload) {
|
|
1273
|
+
const cKey = resolveKey(collectionKey);
|
|
1274
|
+
const vKey = resolveKey(versionKey);
|
|
1275
|
+
return this.request(
|
|
1276
|
+
"PUT",
|
|
1277
|
+
`${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
|
|
1278
|
+
{ params: { path: fieldPath }, jsonBody: payload }
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
async deleteCollectionField(collectionKey, versionKey, fieldPath) {
|
|
1282
|
+
const cKey = resolveKey(collectionKey);
|
|
1283
|
+
const vKey = resolveKey(versionKey);
|
|
1284
|
+
await this.request(
|
|
1285
|
+
"DELETE",
|
|
1286
|
+
`${this.paths.collectionSchemaTree(cKey, vKey)}/field/`,
|
|
1287
|
+
{ params: { path: fieldPath }, parseJson: false }
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
// ------------------------------------------------------------------ //
|
|
1291
|
+
// Folder operations (deprecated; hit legacy /folders/ URL)
|
|
1292
|
+
// ------------------------------------------------------------------ //
|
|
1293
|
+
/** @deprecated Use {@link listCollections} instead. */
|
|
795
1294
|
async listFolders(params) {
|
|
1295
|
+
warnDeprecatedMethod("listFolders", "listCollections");
|
|
796
1296
|
return this.request("GET", `${this.paths.foldersTreeRoot()}/`, { params });
|
|
797
1297
|
}
|
|
1298
|
+
/** @deprecated Use {@link getCollection} instead. */
|
|
798
1299
|
async getFolder(folderKey) {
|
|
1300
|
+
warnDeprecatedMethod("getFolder", "getCollection");
|
|
799
1301
|
const key = resolveKey(folderKey);
|
|
800
1302
|
return this.request("GET", `${this.paths.foldersTreeItem()}/`, {
|
|
801
1303
|
params: { key }
|
|
802
1304
|
});
|
|
803
1305
|
}
|
|
1306
|
+
/** @deprecated Use {@link getCollectionByPath} instead. */
|
|
804
1307
|
async getFolderByPath(path) {
|
|
1308
|
+
warnDeprecatedMethod("getFolderByPath", "getCollectionByPath");
|
|
805
1309
|
return this.request("GET", `${this.paths.foldersTreeItem()}/`, {
|
|
806
1310
|
params: { path }
|
|
807
1311
|
});
|
|
808
1312
|
}
|
|
1313
|
+
/** @deprecated Use {@link listCollectionTree} instead. */
|
|
809
1314
|
async listFolderTree(options) {
|
|
1315
|
+
warnDeprecatedMethod("listFolderTree", "listCollectionTree");
|
|
810
1316
|
const params = {};
|
|
811
1317
|
if (options?.key) params.key = options.key;
|
|
812
1318
|
if (options?.mode) params.mode = options.mode;
|
|
813
1319
|
return this.request("GET", `${this.paths.foldersTreeRoot()}/`, { params });
|
|
814
1320
|
}
|
|
1321
|
+
/** @deprecated Use {@link createCollection} instead. */
|
|
815
1322
|
async createFolder(payload) {
|
|
1323
|
+
warnDeprecatedMethod("createFolder", "createCollection");
|
|
816
1324
|
return this.request("POST", `${this.paths.foldersTreeRoot()}/`, { jsonBody: payload });
|
|
817
1325
|
}
|
|
1326
|
+
/** @deprecated Use {@link updateCollection} instead. */
|
|
818
1327
|
async updateFolder(folderKey, payload) {
|
|
1328
|
+
warnDeprecatedMethod("updateFolder", "updateCollection");
|
|
819
1329
|
const key = resolveKey(folderKey);
|
|
820
1330
|
return this.request("PUT", `${this.paths.foldersTreeItem()}/`, {
|
|
821
1331
|
params: { key },
|
|
822
1332
|
jsonBody: payload
|
|
823
1333
|
});
|
|
824
1334
|
}
|
|
1335
|
+
/** @deprecated Use {@link deleteCollection} instead. */
|
|
825
1336
|
async deleteFolder(folderKey) {
|
|
1337
|
+
warnDeprecatedMethod("deleteFolder", "deleteCollection");
|
|
826
1338
|
const key = resolveKey(folderKey);
|
|
827
1339
|
await this.request("DELETE", `${this.paths.foldersTreeItem()}/`, {
|
|
828
1340
|
params: { key },
|
|
@@ -830,13 +1342,17 @@ var ManagementClient = class {
|
|
|
830
1342
|
});
|
|
831
1343
|
}
|
|
832
1344
|
// ------------------------------------------------------------------ //
|
|
833
|
-
// Folder version operations
|
|
1345
|
+
// Folder version operations (deprecated)
|
|
834
1346
|
// ------------------------------------------------------------------ //
|
|
1347
|
+
/** @deprecated Use {@link listCollectionVersions} instead. */
|
|
835
1348
|
async listFolderVersions(folderKey, params) {
|
|
1349
|
+
warnDeprecatedMethod("listFolderVersions", "listCollectionVersions");
|
|
836
1350
|
const key = resolveKey(folderKey);
|
|
837
1351
|
return this.request("GET", `${this.paths.folderVersionsBase(key)}/`, { params });
|
|
838
1352
|
}
|
|
1353
|
+
/** @deprecated Use {@link createCollectionVersion} instead. */
|
|
839
1354
|
async createFolderVersion(folderKey, payload, options) {
|
|
1355
|
+
warnDeprecatedMethod("createFolderVersion", "createCollectionVersion");
|
|
840
1356
|
const key = resolveKey(folderKey);
|
|
841
1357
|
const params = {};
|
|
842
1358
|
if (options?.copyFrom) {
|
|
@@ -847,7 +1363,9 @@ var ManagementClient = class {
|
|
|
847
1363
|
params: Object.keys(params).length > 0 ? params : void 0
|
|
848
1364
|
});
|
|
849
1365
|
}
|
|
1366
|
+
/** @deprecated Use {@link getCollectionVersion} instead. */
|
|
850
1367
|
async getFolderVersion(folderKey, versionKey, options) {
|
|
1368
|
+
warnDeprecatedMethod("getFolderVersion", "getCollectionVersion");
|
|
851
1369
|
const fKey = resolveKey(folderKey);
|
|
852
1370
|
const vKey = resolveKey(versionKey);
|
|
853
1371
|
const params = {};
|
|
@@ -858,48 +1376,62 @@ var ManagementClient = class {
|
|
|
858
1376
|
params: Object.keys(params).length > 0 ? params : void 0
|
|
859
1377
|
});
|
|
860
1378
|
}
|
|
1379
|
+
/** @deprecated Use {@link updateCollectionVersion} instead. */
|
|
861
1380
|
async updateFolderVersion(folderKey, versionKey, payload) {
|
|
1381
|
+
warnDeprecatedMethod("updateFolderVersion", "updateCollectionVersion");
|
|
862
1382
|
const fKey = resolveKey(folderKey);
|
|
863
1383
|
const vKey = resolveKey(versionKey);
|
|
864
1384
|
return this.request("PUT", `${this.paths.folderVersionsBase(fKey)}/${vKey}/`, {
|
|
865
1385
|
jsonBody: payload
|
|
866
1386
|
});
|
|
867
1387
|
}
|
|
1388
|
+
/** @deprecated Use {@link deleteCollectionVersion} instead. */
|
|
868
1389
|
async deleteFolderVersion(folderKey, versionKey) {
|
|
1390
|
+
warnDeprecatedMethod("deleteFolderVersion", "deleteCollectionVersion");
|
|
869
1391
|
const fKey = resolveKey(folderKey);
|
|
870
1392
|
const vKey = resolveKey(versionKey);
|
|
871
1393
|
await this.request("DELETE", `${this.paths.folderVersionsBase(fKey)}/${vKey}/`, {
|
|
872
1394
|
parseJson: false
|
|
873
1395
|
});
|
|
874
1396
|
}
|
|
1397
|
+
/** @deprecated Use {@link publishCollectionVersion} instead. */
|
|
875
1398
|
async publishFolderVersion(folderKey, versionKey) {
|
|
1399
|
+
warnDeprecatedMethod("publishFolderVersion", "publishCollectionVersion");
|
|
876
1400
|
const fKey = resolveKey(folderKey);
|
|
877
1401
|
const vKey = resolveKey(versionKey);
|
|
878
1402
|
return this.request("POST", `${this.paths.folderVersionsBase(fKey)}/${vKey}/publish/`);
|
|
879
1403
|
}
|
|
880
1404
|
// ------------------------------------------------------------------ //
|
|
881
|
-
// Folder field operations
|
|
1405
|
+
// Folder field operations (deprecated)
|
|
882
1406
|
// ------------------------------------------------------------------ //
|
|
1407
|
+
/** @deprecated Use {@link listCollectionFields} instead. */
|
|
883
1408
|
async listFolderFields(folderKey, versionKey, params) {
|
|
1409
|
+
warnDeprecatedMethod("listFolderFields", "listCollectionFields");
|
|
884
1410
|
const fKey = resolveKey(folderKey);
|
|
885
1411
|
const vKey = resolveKey(versionKey);
|
|
886
1412
|
return this.request("GET", `${this.paths.folderSchemaTree(fKey, vKey)}/`, { params });
|
|
887
1413
|
}
|
|
1414
|
+
/** @deprecated Use {@link createCollectionField} instead. */
|
|
888
1415
|
async createFolderField(folderKey, versionKey, payload) {
|
|
1416
|
+
warnDeprecatedMethod("createFolderField", "createCollectionField");
|
|
889
1417
|
const fKey = resolveKey(folderKey);
|
|
890
1418
|
const vKey = resolveKey(versionKey);
|
|
891
1419
|
return this.request("POST", `${this.paths.folderSchemaTree(fKey, vKey)}/`, {
|
|
892
1420
|
jsonBody: payload
|
|
893
1421
|
});
|
|
894
1422
|
}
|
|
1423
|
+
/** @deprecated Use {@link getCollectionField} instead. */
|
|
895
1424
|
async getFolderField(folderKey, versionKey, fieldPath) {
|
|
1425
|
+
warnDeprecatedMethod("getFolderField", "getCollectionField");
|
|
896
1426
|
const fKey = resolveKey(folderKey);
|
|
897
1427
|
const vKey = resolveKey(versionKey);
|
|
898
1428
|
return this.request("GET", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
|
|
899
1429
|
params: { path: fieldPath }
|
|
900
1430
|
});
|
|
901
1431
|
}
|
|
1432
|
+
/** @deprecated Use {@link updateCollectionField} instead. */
|
|
902
1433
|
async updateFolderField(folderKey, versionKey, fieldPath, payload) {
|
|
1434
|
+
warnDeprecatedMethod("updateFolderField", "updateCollectionField");
|
|
903
1435
|
const fKey = resolveKey(folderKey);
|
|
904
1436
|
const vKey = resolveKey(versionKey);
|
|
905
1437
|
return this.request("PUT", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
|
|
@@ -907,7 +1439,9 @@ var ManagementClient = class {
|
|
|
907
1439
|
jsonBody: payload
|
|
908
1440
|
});
|
|
909
1441
|
}
|
|
1442
|
+
/** @deprecated Use {@link deleteCollectionField} instead. */
|
|
910
1443
|
async deleteFolderField(folderKey, versionKey, fieldPath) {
|
|
1444
|
+
warnDeprecatedMethod("deleteFolderField", "deleteCollectionField");
|
|
911
1445
|
const fKey = resolveKey(folderKey);
|
|
912
1446
|
const vKey = resolveKey(versionKey);
|
|
913
1447
|
await this.request("DELETE", `${this.paths.folderSchemaTree(fKey, vKey)}/field/`, {
|
|
@@ -1035,32 +1569,41 @@ var ManagementClient = class {
|
|
|
1035
1569
|
return this.request("GET", `${this.paths.resourceBase(fKey)}/${rKey}/`);
|
|
1036
1570
|
}
|
|
1037
1571
|
async createResource(folderKey, payload, options) {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1572
|
+
if (options && typeof options === "object" && "component" in options) {
|
|
1573
|
+
throw new TypeError(
|
|
1574
|
+
"The `component` option has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your call site."
|
|
1575
|
+
);
|
|
1042
1576
|
}
|
|
1577
|
+
const key = resolveKey(folderKey);
|
|
1043
1578
|
const body = { ...payload };
|
|
1044
1579
|
if (options?.externalId) {
|
|
1045
1580
|
body.external_id = options.externalId;
|
|
1046
1581
|
}
|
|
1047
1582
|
return this.request("POST", `${this.paths.resourceBase(key)}/`, {
|
|
1048
|
-
params: Object.keys(params).length ? params : void 0,
|
|
1049
1583
|
jsonBody: body
|
|
1050
1584
|
});
|
|
1051
1585
|
}
|
|
1052
1586
|
async upsertResource(folderKey, payload, options) {
|
|
1587
|
+
if (options && typeof options === "object" && "component" in options) {
|
|
1588
|
+
throw new TypeError(
|
|
1589
|
+
"The `component` option has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your call site."
|
|
1590
|
+
);
|
|
1591
|
+
}
|
|
1053
1592
|
const key = resolveKey(folderKey);
|
|
1054
1593
|
const params = { external_id: options.externalId };
|
|
1055
|
-
if (options.component) {
|
|
1056
|
-
params.component = resolveKey(options.component);
|
|
1057
|
-
}
|
|
1058
1594
|
return this.request("PUT", `${this.paths.resourceBase(key)}/`, {
|
|
1059
1595
|
params,
|
|
1060
1596
|
jsonBody: payload
|
|
1061
1597
|
});
|
|
1062
1598
|
}
|
|
1063
1599
|
async batchUpsertResources(folderKey, items, options) {
|
|
1600
|
+
for (const item of items) {
|
|
1601
|
+
if (item && typeof item === "object" && "component" in item) {
|
|
1602
|
+
throw new TypeError(
|
|
1603
|
+
"BatchUpsertItem.component has been removed. Resources now derive their schema from the folder's model. Remove the `component` field from your batch items."
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1064
1607
|
const fKey = resolveKey(folderKey);
|
|
1065
1608
|
const maxConcurrency = options?.maxConcurrency ?? 5;
|
|
1066
1609
|
if (maxConcurrency < 1) {
|
|
@@ -1078,9 +1621,6 @@ var ManagementClient = class {
|
|
|
1078
1621
|
const processItem = async (index, item) => {
|
|
1079
1622
|
try {
|
|
1080
1623
|
const params = { external_id: item.external_id };
|
|
1081
|
-
if (item.component) {
|
|
1082
|
-
params.component = item.component;
|
|
1083
|
-
}
|
|
1084
1624
|
const result = await this.request(
|
|
1085
1625
|
"PUT",
|
|
1086
1626
|
`${this.paths.resourceBase(fKey)}/`,
|
|
@@ -1516,6 +2056,46 @@ var FluxClient = class {
|
|
|
1516
2056
|
const path = this.buildPath(folderPath, "/_search");
|
|
1517
2057
|
return this.transport.request("POST", path, { jsonBody: body });
|
|
1518
2058
|
}
|
|
2059
|
+
/**
|
|
2060
|
+
* Create a resource in a collection and publish it immediately.
|
|
2061
|
+
*
|
|
2062
|
+
* `folderPath` is the collection path (e.g. `articles` or a nested path such
|
|
2063
|
+
* as `users/usr_1/memories`). `options.key` is an optional external
|
|
2064
|
+
* identifier for deduplication — reusing an existing key raises
|
|
2065
|
+
* {@link ExternalIdConflictError}. The response carries `resource_key`,
|
|
2066
|
+
* `revision_key`, `write_units`, and `published`.
|
|
2067
|
+
*
|
|
2068
|
+
* Writes require an authenticated key with write access: an anonymous caller
|
|
2069
|
+
* gets 401, a key without the `create` grant gets a generic 403
|
|
2070
|
+
* (`access_denied`), and a collection whose connection does not allow writes
|
|
2071
|
+
* raises {@link CollectionNotWritableError}.
|
|
2072
|
+
*
|
|
2073
|
+
* Writes are never retried automatically: a failed write's outcome is
|
|
2074
|
+
* unknown, so re-read with a GET before retrying.
|
|
2075
|
+
*/
|
|
2076
|
+
async createResource(folderPath, data, options) {
|
|
2077
|
+
const path = this.buildPath(folderPath, "/");
|
|
2078
|
+
const body = { data };
|
|
2079
|
+
if (options?.key !== void 0) {
|
|
2080
|
+
body.key = options.key;
|
|
2081
|
+
}
|
|
2082
|
+
return this.transport.request("POST", path, { jsonBody: body, allowRetries: false });
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* Replace a resource's document and publish a new revision. This is a
|
|
2086
|
+
* full-document replace, not a partial merge: fields absent from `data` are
|
|
2087
|
+
* removed.
|
|
2088
|
+
*
|
|
2089
|
+
* Writes require an authenticated key with write access: an anonymous caller
|
|
2090
|
+
* gets 401, a key without the `update` grant gets a generic 403
|
|
2091
|
+
* (`access_denied`), and a collection whose connection does not allow writes
|
|
2092
|
+
* raises {@link CollectionNotWritableError}. Like {@link createResource}, it
|
|
2093
|
+
* is never retried automatically.
|
|
2094
|
+
*/
|
|
2095
|
+
async updateResource(folderPath, resourceKey, data) {
|
|
2096
|
+
const path = this.buildPath(folderPath, `/${resourceKey}/`);
|
|
2097
|
+
return this.transport.request("PUT", path, { jsonBody: { data }, allowRetries: false });
|
|
2098
|
+
}
|
|
1519
2099
|
/** Semantic search using auto-generated embeddings. */
|
|
1520
2100
|
async vectorSearch(folderPath, options) {
|
|
1521
2101
|
const { query, fields, top_k = 10, similarity_threshold, limit, offset, ...rest } = options;
|
|
@@ -1647,8 +2227,11 @@ var FluxClient = class {
|
|
|
1647
2227
|
};
|
|
1648
2228
|
export {
|
|
1649
2229
|
AnonymousAuth,
|
|
2230
|
+
CollectionNotWritableError,
|
|
2231
|
+
ContentValidationFailedError,
|
|
1650
2232
|
DEFAULT_RETRY_CONFIG,
|
|
1651
2233
|
DEFAULT_USER_AGENT,
|
|
2234
|
+
ExternalIdConflictError,
|
|
1652
2235
|
FluxClient,
|
|
1653
2236
|
FoxnoseAPIError,
|
|
1654
2237
|
FoxnoseAuthError,
|
|
@@ -1657,14 +2240,20 @@ export {
|
|
|
1657
2240
|
HttpTransport,
|
|
1658
2241
|
JWTAuth,
|
|
1659
2242
|
ManagementClient,
|
|
2243
|
+
PlanExhaustedError,
|
|
2244
|
+
PlanLimitExceededError,
|
|
2245
|
+
RateLimitExceededError,
|
|
1660
2246
|
SDK_VERSION,
|
|
1661
2247
|
SearchMode,
|
|
1662
2248
|
SecureKeyAuth,
|
|
1663
2249
|
SimpleKeyAuth,
|
|
2250
|
+
SpendCapExceededError,
|
|
1664
2251
|
StaticTokenProvider,
|
|
2252
|
+
UpstreamError,
|
|
1665
2253
|
SDK_VERSION as VERSION,
|
|
1666
2254
|
buildSearchBody,
|
|
1667
2255
|
createConfig,
|
|
2256
|
+
nestedFieldMeta,
|
|
1668
2257
|
resolveKey
|
|
1669
2258
|
};
|
|
1670
2259
|
//# sourceMappingURL=index.js.map
|