@foxnose/sdk 0.6.1 → 0.8.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 +170 -0
- package/dist/index.cjs +568 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1094 -63
- package/dist/index.d.ts +1094 -63
- package/dist/index.js +560 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -93,6 +93,36 @@ var PlanExhaustedError = class extends FoxnoseAPIError {
|
|
|
93
93
|
this.upgradeUrl = options.upgradeUrl;
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
+
var FilesQuotaExceededError = class extends FoxnoseAPIError {
|
|
97
|
+
axis;
|
|
98
|
+
reason;
|
|
99
|
+
usedUnits;
|
|
100
|
+
includedUnits;
|
|
101
|
+
capUsd;
|
|
102
|
+
windowResetsAt;
|
|
103
|
+
upgradeUrl;
|
|
104
|
+
raiseCapUrl;
|
|
105
|
+
constructor(options) {
|
|
106
|
+
super(options);
|
|
107
|
+
this.name = "FilesQuotaExceededError";
|
|
108
|
+
this.axis = options.axis;
|
|
109
|
+
this.reason = options.reason;
|
|
110
|
+
this.usedUnits = options.usedUnits;
|
|
111
|
+
this.includedUnits = options.includedUnits;
|
|
112
|
+
this.capUsd = options.capUsd;
|
|
113
|
+
this.windowResetsAt = options.windowResetsAt;
|
|
114
|
+
this.upgradeUrl = options.upgradeUrl;
|
|
115
|
+
this.raiseCapUrl = options.raiseCapUrl;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var FilesQuotaUnavailableError = class extends FoxnoseAPIError {
|
|
119
|
+
retryAfter;
|
|
120
|
+
constructor(options) {
|
|
121
|
+
super(options);
|
|
122
|
+
this.name = "FilesQuotaUnavailableError";
|
|
123
|
+
this.retryAfter = options.retryAfter;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
96
126
|
var PlanLimitExceededError = class extends FoxnoseAPIError {
|
|
97
127
|
/** Entity whose limit was exceeded (e.g. collections, environments, api_keys). */
|
|
98
128
|
entity;
|
|
@@ -150,6 +180,45 @@ var UpstreamError = class extends FoxnoseAPIError {
|
|
|
150
180
|
this.name = "UpstreamError";
|
|
151
181
|
}
|
|
152
182
|
};
|
|
183
|
+
var WebhookEndpointNotFoundError = class extends FoxnoseAPIError {
|
|
184
|
+
constructor(options) {
|
|
185
|
+
super(options);
|
|
186
|
+
this.name = "WebhookEndpointNotFoundError";
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var WebhookEventNotFoundError = class extends FoxnoseAPIError {
|
|
190
|
+
constructor(options) {
|
|
191
|
+
super(options);
|
|
192
|
+
this.name = "WebhookEventNotFoundError";
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var WebhookEndpointLimitExceededError = class extends FoxnoseAPIError {
|
|
196
|
+
constructor(options) {
|
|
197
|
+
super(options);
|
|
198
|
+
this.name = "WebhookEndpointLimitExceededError";
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var WebhookEndpointNotActiveError = class extends FoxnoseAPIError {
|
|
202
|
+
/** The endpoint's state (`paused`, `disabled` or `deleted`) when the call named it. */
|
|
203
|
+
reason;
|
|
204
|
+
/** Endpoints a redelivery without `endpoint_id` passed over, each with `endpoint_id` and `reason`. */
|
|
205
|
+
skipped;
|
|
206
|
+
constructor(options) {
|
|
207
|
+
super(options);
|
|
208
|
+
this.name = "WebhookEndpointNotActiveError";
|
|
209
|
+
this.reason = options.reason;
|
|
210
|
+
this.skipped = options.skipped ?? [];
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
var WebhookEndpointNotSubscribedError = class extends FoxnoseAPIError {
|
|
214
|
+
/** Endpoints a redelivery without `endpoint_id` passed over, each with `endpoint_id` and `reason`. */
|
|
215
|
+
skipped;
|
|
216
|
+
constructor(options) {
|
|
217
|
+
super(options);
|
|
218
|
+
this.name = "WebhookEndpointNotSubscribedError";
|
|
219
|
+
this.skipped = options.skipped ?? [];
|
|
220
|
+
}
|
|
221
|
+
};
|
|
153
222
|
function isPlainObject(value) {
|
|
154
223
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
155
224
|
}
|
|
@@ -165,6 +234,11 @@ function getHeader(headers, name) {
|
|
|
165
234
|
}
|
|
166
235
|
return void 0;
|
|
167
236
|
}
|
|
237
|
+
function retryAfterSeconds(headers) {
|
|
238
|
+
const raw = getHeader(headers, "Retry-After");
|
|
239
|
+
const parsed = raw !== void 0 ? Number(raw) : NaN;
|
|
240
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
241
|
+
}
|
|
168
242
|
var CONTENT_VALIDATION_CODES = /* @__PURE__ */ new Set(["content_validation_failed", "data_validation_error"]);
|
|
169
243
|
function buildAPIError(options) {
|
|
170
244
|
const { statusCode, errorCode, detail, responseHeaders, responseBody } = options;
|
|
@@ -187,6 +261,29 @@ function buildAPIError(options) {
|
|
|
187
261
|
upgradeUrl: typeof body.upgrade_url === "string" ? body.upgrade_url : void 0
|
|
188
262
|
});
|
|
189
263
|
}
|
|
264
|
+
if (statusCode === 402 && errorCode === "files_quota_exceeded" && body) {
|
|
265
|
+
const numberOrNull = (value) => typeof value === "number" ? value : value === null ? null : void 0;
|
|
266
|
+
const text = (value) => typeof value === "string" ? value : void 0;
|
|
267
|
+
return new FilesQuotaExceededError({
|
|
268
|
+
...options,
|
|
269
|
+
message: "message" in body ? options.message : "File processing quota reached",
|
|
270
|
+
axis: text(body.axis),
|
|
271
|
+
reason: text(body.reason),
|
|
272
|
+
usedUnits: typeof body.used_units === "number" ? body.used_units : void 0,
|
|
273
|
+
includedUnits: numberOrNull(body.included_units),
|
|
274
|
+
capUsd: numberOrNull(body.cap_usd),
|
|
275
|
+
windowResetsAt: body.window_resets_at === null ? null : text(body.window_resets_at),
|
|
276
|
+
upgradeUrl: text(body.upgrade_url),
|
|
277
|
+
raiseCapUrl: text(body.raise_cap_url)
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
if (statusCode === 503 && errorCode === "files_quota_unavailable") {
|
|
281
|
+
return new FilesQuotaUnavailableError({
|
|
282
|
+
...options,
|
|
283
|
+
message: body && "message" in body ? options.message : "File processing quota is unavailable",
|
|
284
|
+
retryAfter: retryAfterSeconds(responseHeaders)
|
|
285
|
+
});
|
|
286
|
+
}
|
|
190
287
|
if (statusCode === 403 && errorCode === "plan_limit_exceeded") {
|
|
191
288
|
const d = isPlainObject(detail) ? detail : {};
|
|
192
289
|
return new PlanLimitExceededError({
|
|
@@ -198,11 +295,9 @@ function buildAPIError(options) {
|
|
|
198
295
|
});
|
|
199
296
|
}
|
|
200
297
|
if (statusCode === 429 && errorCode === "rate_limited") {
|
|
201
|
-
const raw = getHeader(responseHeaders, "Retry-After");
|
|
202
|
-
const parsed = raw !== void 0 ? Number(raw) : NaN;
|
|
203
298
|
return new RateLimitExceededError({
|
|
204
299
|
...options,
|
|
205
|
-
retryAfter:
|
|
300
|
+
retryAfter: retryAfterSeconds(responseHeaders)
|
|
206
301
|
});
|
|
207
302
|
}
|
|
208
303
|
if (statusCode === 403 && errorCode === "collection_not_writable") {
|
|
@@ -220,6 +315,30 @@ function buildAPIError(options) {
|
|
|
220
315
|
errorsTruncated: d.errors_truncated === true
|
|
221
316
|
});
|
|
222
317
|
}
|
|
318
|
+
if (statusCode === 404 && errorCode === "webhook_endpoint_not_found") {
|
|
319
|
+
return new WebhookEndpointNotFoundError(options);
|
|
320
|
+
}
|
|
321
|
+
if (statusCode === 404 && errorCode === "webhook_event_not_found") {
|
|
322
|
+
return new WebhookEventNotFoundError(options);
|
|
323
|
+
}
|
|
324
|
+
if (statusCode === 409 && errorCode === "limit_exceeded") {
|
|
325
|
+
return new WebhookEndpointLimitExceededError(options);
|
|
326
|
+
}
|
|
327
|
+
if (statusCode === 409 && errorCode === "endpoint_not_active") {
|
|
328
|
+
const d = isPlainObject(detail) ? detail : {};
|
|
329
|
+
return new WebhookEndpointNotActiveError({
|
|
330
|
+
...options,
|
|
331
|
+
reason: typeof d.reason === "string" ? d.reason : void 0,
|
|
332
|
+
skipped: Array.isArray(d.skipped) ? d.skipped : void 0
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (statusCode === 409 && errorCode === "endpoint_not_subscribed") {
|
|
336
|
+
const d = isPlainObject(detail) ? detail : {};
|
|
337
|
+
return new WebhookEndpointNotSubscribedError({
|
|
338
|
+
...options,
|
|
339
|
+
skipped: Array.isArray(d.skipped) ? d.skipped : void 0
|
|
340
|
+
});
|
|
341
|
+
}
|
|
223
342
|
if (statusCode === 502 && errorCode === "upstream_error") {
|
|
224
343
|
return new UpstreamError(options);
|
|
225
344
|
}
|
|
@@ -309,7 +428,7 @@ var DEFAULT_RETRY_CONFIG = {
|
|
|
309
428
|
statusCodes: [408, 425, 429, 500, 502, 503, 504],
|
|
310
429
|
methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
|
|
311
430
|
};
|
|
312
|
-
var SDK_VERSION = "0.
|
|
431
|
+
var SDK_VERSION = "0.8.0";
|
|
313
432
|
var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
|
|
314
433
|
function createConfig(options) {
|
|
315
434
|
if (!options.baseUrl) {
|
|
@@ -493,7 +612,7 @@ var HttpTransport = class {
|
|
|
493
612
|
body = payload;
|
|
494
613
|
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
495
614
|
message = payload.message ?? message;
|
|
496
|
-
errorCode = payload.error_code;
|
|
615
|
+
errorCode = payload.error_code ?? payload.code;
|
|
497
616
|
detail = payload.detail;
|
|
498
617
|
}
|
|
499
618
|
} catch {
|
|
@@ -550,6 +669,26 @@ function nestedFieldMeta(opts) {
|
|
|
550
669
|
auto_update: opts.autoUpdate ?? false
|
|
551
670
|
};
|
|
552
671
|
}
|
|
672
|
+
var TEXT_EVIDENCE_KINDS = /* @__PURE__ */ new Set(["hidden_text", "low_legibility_text"]);
|
|
673
|
+
function parseFindingEvidence(finding) {
|
|
674
|
+
if (!TEXT_EVIDENCE_KINDS.has(finding.kind) || !finding.evidence) {
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
let fields;
|
|
678
|
+
try {
|
|
679
|
+
fields = JSON.parse(finding.evidence);
|
|
680
|
+
} catch {
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
if (typeof fields !== "object" || fields === null || Array.isArray(fields)) {
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
const { parts } = fields;
|
|
687
|
+
if (parts !== void 0 && !Array.isArray(parts)) {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
return { ...fields, parts: parts ?? [] };
|
|
691
|
+
}
|
|
553
692
|
function resolveKey(value) {
|
|
554
693
|
if (typeof value === "string") {
|
|
555
694
|
return value;
|
|
@@ -589,6 +728,19 @@ function managementPaths(environmentKey) {
|
|
|
589
728
|
// Resource paths
|
|
590
729
|
resourceBase: (folderKey) => `/v1/${environmentKey}/folders/${folderKey}/resources`,
|
|
591
730
|
revisionBase: (folderKey, resourceKey) => `/v1/${environmentKey}/folders/${folderKey}/resources/${resourceKey}/revisions`,
|
|
731
|
+
// Files paths
|
|
732
|
+
uploadLinksRoot: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/upload-links`,
|
|
733
|
+
uploadLinkRoot: (collectionKey, uploadId) => `/v1/${environmentKey}/collections/${collectionKey}/upload-links/${encodeURIComponent(uploadId)}`,
|
|
734
|
+
fileRoot: (collectionKey, resourceKey) => `/v1/${environmentKey}/collections/${collectionKey}/files/${resourceKey}`,
|
|
735
|
+
fileTombstonesRoot: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/files/tombstones`,
|
|
736
|
+
filesPolicyRoot: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/files-policy`,
|
|
737
|
+
filesReviewRoot: () => `/v1/${environmentKey}/files/review`,
|
|
738
|
+
// Webhooks paths
|
|
739
|
+
webhooksRoot: () => `/v1/${environmentKey}/webhooks`,
|
|
740
|
+
webhookEndpointRoot: (endpointId) => `/v1/${environmentKey}/webhooks/endpoints/${encodeURIComponent(endpointId)}`,
|
|
741
|
+
webhookEventRoot: (eventId) => `/v1/${environmentKey}/webhooks/events/${encodeURIComponent(eventId)}`,
|
|
742
|
+
// Caller's own permissions
|
|
743
|
+
myPermissionsRoot: () => `/v1/${environmentKey}/permissions/me`,
|
|
592
744
|
// Management API key paths
|
|
593
745
|
managementApiKeysRoot: () => `/v1/${environmentKey}/permissions/management-api/api-keys`,
|
|
594
746
|
managementApiKeyRoot: (apiKey) => `/v1/${environmentKey}/permissions/management-api/api-keys/${apiKey}`,
|
|
@@ -620,6 +772,21 @@ function managementPaths(environmentKey) {
|
|
|
620
772
|
}
|
|
621
773
|
|
|
622
774
|
// src/management/client.ts
|
|
775
|
+
function hideSecret(response) {
|
|
776
|
+
if (response && typeof response === "object" && "secret" in response) {
|
|
777
|
+
Object.defineProperty(response, "secret", {
|
|
778
|
+
value: response.secret,
|
|
779
|
+
enumerable: false,
|
|
780
|
+
writable: false,
|
|
781
|
+
configurable: true
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
return response;
|
|
785
|
+
}
|
|
786
|
+
function webhookEndpointBody(request) {
|
|
787
|
+
const { collection_keys, ...rest } = request;
|
|
788
|
+
return collection_keys === void 0 ? rest : { ...rest, collection_keys: collection_keys.map((key) => resolveKey(key)) };
|
|
789
|
+
}
|
|
623
790
|
var ManagementClient = class {
|
|
624
791
|
environmentKey;
|
|
625
792
|
transport;
|
|
@@ -697,6 +864,14 @@ var ManagementClient = class {
|
|
|
697
864
|
const key = resolveKey(orgKey);
|
|
698
865
|
return this.request("PUT", `${this.paths.orgRoot(key)}/`, { jsonBody: payload });
|
|
699
866
|
}
|
|
867
|
+
/**
|
|
868
|
+
* Write the given fields of an organization and leave the rest alone. The
|
|
869
|
+
* response is the whole organization as stored.
|
|
870
|
+
*/
|
|
871
|
+
async patchOrganization(orgKey, payload) {
|
|
872
|
+
const key = resolveKey(orgKey);
|
|
873
|
+
return this.request("PATCH", `${this.paths.orgRoot(key)}/`, { jsonBody: payload });
|
|
874
|
+
}
|
|
700
875
|
async listRegions() {
|
|
701
876
|
const payload = await this.request("GET", "/regions/") ?? [];
|
|
702
877
|
return Array.isArray(payload) ? payload : [payload];
|
|
@@ -1111,6 +1286,20 @@ var ManagementClient = class {
|
|
|
1111
1286
|
jsonBody: payload
|
|
1112
1287
|
});
|
|
1113
1288
|
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Write the given fields of a collection and leave the rest alone.
|
|
1291
|
+
*
|
|
1292
|
+
* `updateCollection` replaces the whole record; this does not. An omitted
|
|
1293
|
+
* `parent` keeps the collection where it is, and `{ parent: null }` moves it
|
|
1294
|
+
* to the root. The response is the whole collection as stored.
|
|
1295
|
+
*/
|
|
1296
|
+
async patchCollection(collectionKey, payload) {
|
|
1297
|
+
const key = resolveKey(collectionKey);
|
|
1298
|
+
return this.request("PATCH", `${this.paths.collectionsTreeItem()}/`, {
|
|
1299
|
+
params: { key },
|
|
1300
|
+
jsonBody: payload
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1114
1303
|
async deleteCollection(collectionKey) {
|
|
1115
1304
|
const key = resolveKey(collectionKey);
|
|
1116
1305
|
await this.request("DELETE", `${this.paths.collectionsTreeItem()}/`, {
|
|
@@ -1448,6 +1637,14 @@ var ManagementClient = class {
|
|
|
1448
1637
|
const key = resolveKey(componentKey);
|
|
1449
1638
|
return this.request("PUT", `${this.paths.componentRoot(key)}/`, { jsonBody: payload });
|
|
1450
1639
|
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Write the given fields of a component and leave the rest alone. The response
|
|
1642
|
+
* is the whole component as stored.
|
|
1643
|
+
*/
|
|
1644
|
+
async patchComponent(componentKey, payload) {
|
|
1645
|
+
const key = resolveKey(componentKey);
|
|
1646
|
+
return this.request("PATCH", `${this.paths.componentRoot(key)}/`, { jsonBody: payload });
|
|
1647
|
+
}
|
|
1451
1648
|
async deleteComponent(componentKey) {
|
|
1452
1649
|
const key = resolveKey(componentKey);
|
|
1453
1650
|
await this.request("DELETE", `${this.paths.componentRoot(key)}/`, { parseJson: false });
|
|
@@ -1833,6 +2030,317 @@ var ManagementClient = class {
|
|
|
1833
2030
|
protectionLevel: "none"
|
|
1834
2031
|
});
|
|
1835
2032
|
}
|
|
2033
|
+
// ------------------------------------------------------------------ //
|
|
2034
|
+
// Files
|
|
2035
|
+
// ------------------------------------------------------------------ //
|
|
2036
|
+
/**
|
|
2037
|
+
* List a files collection's upload links, newest first. `params` carries `limit` (at
|
|
2038
|
+
* most 100), `offset` and `state`: `active`, `ended` or `all` (the default).
|
|
2039
|
+
*/
|
|
2040
|
+
async listUploadLinks(collectionKey, params) {
|
|
2041
|
+
const key = resolveKey(collectionKey);
|
|
2042
|
+
return this.request("GET", `${this.paths.uploadLinksRoot(key)}/`, { params });
|
|
2043
|
+
}
|
|
2044
|
+
/**
|
|
2045
|
+
* Create an upload link: a hosted page where an end user adds files.
|
|
2046
|
+
*
|
|
2047
|
+
* The collection must be strict. Works with a user token or a Management API
|
|
2048
|
+
* key of this environment. Read the link back with {@link getUploadLink}; the
|
|
2049
|
+
* Flux upload status answers only the Flux key that started an upload, never
|
|
2050
|
+
* a link made here.
|
|
2051
|
+
*
|
|
2052
|
+
* `upload_url` carries the link's token and is returned only by this call.
|
|
2053
|
+
*/
|
|
2054
|
+
async createUploadLink(collectionKey, request) {
|
|
2055
|
+
const key = resolveKey(collectionKey);
|
|
2056
|
+
return this.transport.request("POST", `${this.paths.uploadLinksRoot(key)}/`, {
|
|
2057
|
+
jsonBody: { ...request, owner: resolveKey(request.owner) },
|
|
2058
|
+
allowRetries: false
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
/** Read one upload link with its sessions and the status of each file. */
|
|
2062
|
+
async getUploadLink(collectionKey, uploadId) {
|
|
2063
|
+
const key = resolveKey(collectionKey);
|
|
2064
|
+
return this.request("GET", `${this.paths.uploadLinkRoot(key, uploadId)}/`);
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* Revoke an upload link. Revoking a revoked link returns the same state. Files
|
|
2068
|
+
* already uploaded through the link are not affected.
|
|
2069
|
+
*/
|
|
2070
|
+
async revokeUploadLink(collectionKey, uploadId) {
|
|
2071
|
+
const key = resolveKey(collectionKey);
|
|
2072
|
+
return this.request("POST", `${this.paths.uploadLinkRoot(key, uploadId)}/revoke/`);
|
|
2073
|
+
}
|
|
2074
|
+
/** Read a record's file: its verdict, the checks that ran and every finding. */
|
|
2075
|
+
async getFileAnalysis(collectionKey, resourceKey) {
|
|
2076
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2077
|
+
return this.request("GET", `${root}/analysis/`);
|
|
2078
|
+
}
|
|
2079
|
+
/**
|
|
2080
|
+
* Release a file held for a reviewer.
|
|
2081
|
+
*
|
|
2082
|
+
* The answer's `outcome` says what happened; a publish that goes back through
|
|
2083
|
+
* processing completes on its own. A file no reviewer holds is
|
|
2084
|
+
* `409 file_not_in_review`, `file_not_ready` or `file_erased`.
|
|
2085
|
+
*/
|
|
2086
|
+
async approveFile(collectionKey, resourceKey) {
|
|
2087
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2088
|
+
return this.transport.request("POST", `${root}/approve/`, { allowRetries: false });
|
|
2089
|
+
}
|
|
2090
|
+
/** Reject a file held for a reviewer. Repeating it returns the same state. */
|
|
2091
|
+
async rejectFile(collectionKey, resourceKey) {
|
|
2092
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2093
|
+
return this.request("POST", `${root}/reject/`);
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* Analyze a file again under the collection's live policy.
|
|
2097
|
+
*
|
|
2098
|
+
* Accepted work runs in the background; a published generation keeps serving
|
|
2099
|
+
* until the new one publishes. A `storage_only` collection answers
|
|
2100
|
+
* `409 reanalysis_requires_agent_ready`. This is paid processing: a refusal over
|
|
2101
|
+
* the plan throws {@link FilesQuotaExceededError}, a quota that cannot be read
|
|
2102
|
+
* throws {@link FilesQuotaUnavailableError}, and over a budget is `429`.
|
|
2103
|
+
*/
|
|
2104
|
+
async reanalyzeFile(collectionKey, resourceKey) {
|
|
2105
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2106
|
+
return this.transport.request("POST", `${root}/reanalyze/`, { allowRetries: false });
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* Get a short-lived link to a record's original file.
|
|
2110
|
+
*
|
|
2111
|
+
* A state that cannot be downloaded now is a `409`: `detail.reason` of the
|
|
2112
|
+
* thrown error names it. Check `warnings` before opening the file.
|
|
2113
|
+
*/
|
|
2114
|
+
async getFileOriginal(collectionKey, resourceKey) {
|
|
2115
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2116
|
+
return this.request("GET", `${root}/file/original/`);
|
|
2117
|
+
}
|
|
2118
|
+
/**
|
|
2119
|
+
* Get a short-lived link to a record's safe copy. It is an image-only PDF, or a PNG
|
|
2120
|
+
* for an image: read `content_type`.
|
|
2121
|
+
*/
|
|
2122
|
+
async getFileSafeCopy(collectionKey, resourceKey) {
|
|
2123
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2124
|
+
return this.request("GET", `${root}/file/safe-copy/`);
|
|
2125
|
+
}
|
|
2126
|
+
/** Get a short-lived link to the redacted PNG of one page. */
|
|
2127
|
+
async getFilePage(collectionKey, resourceKey, page) {
|
|
2128
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2129
|
+
return this.request("GET", `${root}/file/pages/${page}/`);
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Read one page: its redacted image, what was withheld, its tables and the
|
|
2133
|
+
* text an agent receives.
|
|
2134
|
+
*/
|
|
2135
|
+
async getFilePageDetail(collectionKey, resourceKey, page) {
|
|
2136
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2137
|
+
return this.request("GET", `${root}/file/pages/${page}/detail/`);
|
|
2138
|
+
}
|
|
2139
|
+
/** List a collection's blocked and rejected files, newest first. */
|
|
2140
|
+
async listFileTombstones(collectionKey, params) {
|
|
2141
|
+
const key = resolveKey(collectionKey);
|
|
2142
|
+
return this.request("GET", `${this.paths.fileTombstonesRoot(key)}/`, { params });
|
|
2143
|
+
}
|
|
2144
|
+
/** Read a collection's live files policy. */
|
|
2145
|
+
async getFilesPolicy(collectionKey) {
|
|
2146
|
+
const key = resolveKey(collectionKey);
|
|
2147
|
+
return this.request("GET", `${this.paths.filesPolicyRoot(key)}/`);
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* Replace a collection's files policy with a new version.
|
|
2151
|
+
*
|
|
2152
|
+
* A full replacement: an omitted field takes its default. Sending the live
|
|
2153
|
+
* body again creates no version.
|
|
2154
|
+
*/
|
|
2155
|
+
async updateFilesPolicy(collectionKey, payload) {
|
|
2156
|
+
const key = resolveKey(collectionKey);
|
|
2157
|
+
return this.request("PUT", `${this.paths.filesPolicyRoot(key)}/`, { jsonBody: payload });
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* List the files held for a reviewer in this environment, newest first.
|
|
2161
|
+
*
|
|
2162
|
+
* `collection` narrows the queue to one collection; one the caller cannot read,
|
|
2163
|
+
* or that does not exist, is an empty page. `params` carries `limit` (at most
|
|
2164
|
+
* 100) and `offset`.
|
|
2165
|
+
*/
|
|
2166
|
+
async listFileReviewQueue(options) {
|
|
2167
|
+
const params = { ...options?.params };
|
|
2168
|
+
if (options?.collection !== void 0) {
|
|
2169
|
+
params.collection = resolveKey(options.collection);
|
|
2170
|
+
}
|
|
2171
|
+
return this.request("GET", `${this.paths.filesReviewRoot()}/`, { params });
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Read what the authenticated caller may do in this environment.
|
|
2175
|
+
*
|
|
2176
|
+
* Works for a user token and for a Management API key of this environment. A caller
|
|
2177
|
+
* with no grants at all is a `403`; a key of another environment is a
|
|
2178
|
+
* `404 environment_not_found`.
|
|
2179
|
+
*/
|
|
2180
|
+
async getMyPermissions() {
|
|
2181
|
+
return this.request("GET", `${this.paths.myPermissionsRoot()}/`);
|
|
2182
|
+
}
|
|
2183
|
+
// ------------------------------------------------------------------ //
|
|
2184
|
+
// Webhooks
|
|
2185
|
+
// ------------------------------------------------------------------ //
|
|
2186
|
+
/**
|
|
2187
|
+
* List the environment's webhook endpoints, newest first. Each item carries
|
|
2188
|
+
* `stats_24h`; secrets are never included. `params` carries `status` (`active`,
|
|
2189
|
+
* `paused` or `disabled`), `limit` (at most 200) and `offset`.
|
|
2190
|
+
*/
|
|
2191
|
+
async listWebhookEndpoints(params) {
|
|
2192
|
+
return this.request("GET", `${this.paths.webhooksRoot()}/endpoints/`, { params });
|
|
2193
|
+
}
|
|
2194
|
+
/**
|
|
2195
|
+
* Create a webhook endpoint.
|
|
2196
|
+
*
|
|
2197
|
+
* The answer carries the signing `secret`, which is not enumerable: read it as
|
|
2198
|
+
* `created.secret`, and read it again later with {@link getWebhookEndpointSecret}.
|
|
2199
|
+
* An environment holds at most 20 endpoints ({@link WebhookEndpointLimitExceededError}).
|
|
2200
|
+
* A `content` endpoint also needs read access to the content it will deliver.
|
|
2201
|
+
*/
|
|
2202
|
+
async createWebhookEndpoint(request) {
|
|
2203
|
+
const created = await this.transport.request(
|
|
2204
|
+
"POST",
|
|
2205
|
+
`${this.paths.webhooksRoot()}/endpoints/`,
|
|
2206
|
+
{
|
|
2207
|
+
jsonBody: webhookEndpointBody(request),
|
|
2208
|
+
allowRetries: false
|
|
2209
|
+
}
|
|
2210
|
+
);
|
|
2211
|
+
return hideSecret(created);
|
|
2212
|
+
}
|
|
2213
|
+
/** Read one webhook endpoint. It carries neither the secret nor `stats_24h`. */
|
|
2214
|
+
async getWebhookEndpoint(endpointId) {
|
|
2215
|
+
return this.request("GET", `${this.paths.webhookEndpointRoot(endpointId)}/`);
|
|
2216
|
+
}
|
|
2217
|
+
/**
|
|
2218
|
+
* Change the given fields of an endpoint and leave the rest alone.
|
|
2219
|
+
*
|
|
2220
|
+
* `status: 'active'` resumes a paused or disabled endpoint and clears its failure
|
|
2221
|
+
* streak; events that happened meanwhile are not sent, but failed deliveries can be
|
|
2222
|
+
* sent again with {@link recoverWebhookDeliveries}.
|
|
2223
|
+
*/
|
|
2224
|
+
async updateWebhookEndpoint(endpointId, changes) {
|
|
2225
|
+
return this.request("PATCH", `${this.paths.webhookEndpointRoot(endpointId)}/`, {
|
|
2226
|
+
jsonBody: webhookEndpointBody(changes)
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Delete an endpoint and its pending deliveries. Its finished deliveries and
|
|
2231
|
+
* attempts stay in the event log for 30 days, with `endpoint.deleted` true.
|
|
2232
|
+
*/
|
|
2233
|
+
async deleteWebhookEndpoint(endpointId) {
|
|
2234
|
+
await this.request("DELETE", `${this.paths.webhookEndpointRoot(endpointId)}/`, {
|
|
2235
|
+
parseJson: false
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* List an endpoint's deliveries, newest first, each with the event it carries.
|
|
2240
|
+
* `params` carries `limit` (at most 200) and `offset`.
|
|
2241
|
+
*/
|
|
2242
|
+
async listWebhookEndpointDeliveries(endpointId, params) {
|
|
2243
|
+
return this.request("GET", `${this.paths.webhookEndpointRoot(endpointId)}/deliveries/`, {
|
|
2244
|
+
params
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
/**
|
|
2248
|
+
* Read the endpoint's current signing secret: the newest, during a rotation. Needs
|
|
2249
|
+
* `webhooks:update`. `secret` is not enumerable: read it as `response.secret`.
|
|
2250
|
+
*/
|
|
2251
|
+
async getWebhookEndpointSecret(endpointId) {
|
|
2252
|
+
const response = await this.request(
|
|
2253
|
+
"GET",
|
|
2254
|
+
`${this.paths.webhookEndpointRoot(endpointId)}/secret/`
|
|
2255
|
+
);
|
|
2256
|
+
return hideSecret(response);
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* Create a new signing secret and return it.
|
|
2260
|
+
*
|
|
2261
|
+
* The previous secret stays valid for 24 hours, and deliveries carry a signature for
|
|
2262
|
+
* each valid secret; with `expire_previous_now` it stops at once. Needs
|
|
2263
|
+
* `webhooks:update`. `secret` is not enumerable: read it as `rotation.secret`.
|
|
2264
|
+
*/
|
|
2265
|
+
async rotateWebhookEndpointSecret(endpointId, options) {
|
|
2266
|
+
const response = await this.transport.request(
|
|
2267
|
+
"POST",
|
|
2268
|
+
`${this.paths.webhookEndpointRoot(endpointId)}/secret/rotate/`,
|
|
2269
|
+
{
|
|
2270
|
+
jsonBody: { expire_previous_now: options?.expire_previous_now ?? false },
|
|
2271
|
+
allowRetries: false
|
|
2272
|
+
}
|
|
2273
|
+
);
|
|
2274
|
+
return hideSecret(response);
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* Send a sample event of `eventType` to this endpoint only, with `test` true in the
|
|
2278
|
+
* envelope. It is sent whatever the endpoint's event types and collection filter,
|
|
2279
|
+
* but the endpoint must be active ({@link WebhookEndpointNotActiveError}).
|
|
2280
|
+
*/
|
|
2281
|
+
async sendWebhookTestEvent(endpointId, eventType) {
|
|
2282
|
+
return this.transport.request("POST", `${this.paths.webhookEndpointRoot(endpointId)}/test/`, {
|
|
2283
|
+
jsonBody: { event_type: eventType },
|
|
2284
|
+
allowRetries: false
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Send again the endpoint's failed deliveries created at or after `since`.
|
|
2289
|
+
*
|
|
2290
|
+
* Each becomes a new pending delivery of the same event. One call queues at most
|
|
2291
|
+
* 10,000 deliveries; when `more` is true, call again with the same `since`. `since`
|
|
2292
|
+
* is an ISO 8601 time within the last 30 days; a time without a zone is read as UTC.
|
|
2293
|
+
*/
|
|
2294
|
+
async recoverWebhookDeliveries(endpointId, since) {
|
|
2295
|
+
return this.transport.request(
|
|
2296
|
+
"POST",
|
|
2297
|
+
`${this.paths.webhookEndpointRoot(endpointId)}/recover/`,
|
|
2298
|
+
{
|
|
2299
|
+
jsonBody: { since: since instanceof Date ? since.toISOString() : since },
|
|
2300
|
+
allowRetries: false
|
|
2301
|
+
}
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2304
|
+
/**
|
|
2305
|
+
* List the events of the last 30 days, newest first, with `delivery_counts`.
|
|
2306
|
+
* `params` carries `type`, `endpoint` (an endpoint `id`), `status` (`pending`,
|
|
2307
|
+
* `succeeded` or `dead`), `test`, `after`, `before` (ISO 8601), `limit` (at most 200)
|
|
2308
|
+
* and `offset`.
|
|
2309
|
+
*/
|
|
2310
|
+
async listWebhookEvents(params) {
|
|
2311
|
+
return this.request("GET", `${this.paths.webhooksRoot()}/events/`, { params });
|
|
2312
|
+
}
|
|
2313
|
+
/** Read one event with its envelope and all its deliveries, oldest first. */
|
|
2314
|
+
async getWebhookEvent(eventId) {
|
|
2315
|
+
return this.request("GET", `${this.paths.webhookEventRoot(eventId)}/`);
|
|
2316
|
+
}
|
|
2317
|
+
/**
|
|
2318
|
+
* List every attempt to deliver the event, across endpoints, oldest first. `params`
|
|
2319
|
+
* carries `limit` (at most 200) and `offset`.
|
|
2320
|
+
*/
|
|
2321
|
+
async listWebhookEventAttempts(eventId, params) {
|
|
2322
|
+
return this.request("GET", `${this.paths.webhookEventRoot(eventId)}/attempts/`, { params });
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Send the event again as a new delivery, with the same event `id`.
|
|
2326
|
+
*
|
|
2327
|
+
* With `endpoint_id` the event goes to that endpoint. Without it, the event goes to
|
|
2328
|
+
* every endpoint that had a delivery of it and is active and subscribed to it now;
|
|
2329
|
+
* the others are listed in `skipped`.
|
|
2330
|
+
*/
|
|
2331
|
+
async redeliverWebhookEvent(eventId, options) {
|
|
2332
|
+
return this.transport.request("POST", `${this.paths.webhookEventRoot(eventId)}/redeliver/`, {
|
|
2333
|
+
jsonBody: options?.endpoint_id !== void 0 ? { endpoint_id: options.endpoint_id } : {},
|
|
2334
|
+
allowRetries: false
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
/** List the event-type catalogue with the JSON Schema of each payload mode. */
|
|
2338
|
+
async listWebhookEventTypes() {
|
|
2339
|
+
return this.request("GET", `${this.paths.webhooksRoot()}/event-types/`);
|
|
2340
|
+
}
|
|
2341
|
+
fileRoot(collectionKey, resourceKey) {
|
|
2342
|
+
return this.paths.fileRoot(resolveKey(collectionKey), resolveKey(resourceKey));
|
|
2343
|
+
}
|
|
1836
2344
|
};
|
|
1837
2345
|
|
|
1838
2346
|
// src/flux/models.ts
|
|
@@ -2083,6 +2591,45 @@ var FluxClient = class {
|
|
|
2083
2591
|
const path = this.buildPath(folderPath, `/${resourceKey}/`);
|
|
2084
2592
|
return this.transport.request("PUT", path, { jsonBody: { data }, allowRetries: false });
|
|
2085
2593
|
}
|
|
2594
|
+
/**
|
|
2595
|
+
* Get a grant for one upload to a files collection.
|
|
2596
|
+
*
|
|
2597
|
+
* The grant is a credential: pass it on, do not log it. For a strict collection
|
|
2598
|
+
* `folderPath` names the owner, e.g. `support/tickets/tk_1/attachments`. Needs a
|
|
2599
|
+
* key with create access to the collection.
|
|
2600
|
+
*
|
|
2601
|
+
* `options.sessionKey` is an optional idempotency key of 43 URL-safe characters:
|
|
2602
|
+
* a repeat with the same key, collection and owner reaches the same upload
|
|
2603
|
+
* session. A failed request is never retried automatically, so send one to
|
|
2604
|
+
* retry safely.
|
|
2605
|
+
*/
|
|
2606
|
+
async createUploadSignature(folderPath, options) {
|
|
2607
|
+
const path = this.buildPath(folderPath, "/_upload-signature");
|
|
2608
|
+
const sessionKey = options?.sessionKey;
|
|
2609
|
+
return this.transport.request("POST", path, {
|
|
2610
|
+
jsonBody: sessionKey === void 0 ? void 0 : { session_key: sessionKey },
|
|
2611
|
+
allowRetries: false
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Read the status of an upload.
|
|
2616
|
+
*
|
|
2617
|
+
* A key reads the uploads that key started, and the path must name the same
|
|
2618
|
+
* collection and owner. Any other combination is `404 not_found`, which includes
|
|
2619
|
+
* a link made through the Management API: read that one with
|
|
2620
|
+
* `ManagementClient.getUploadLink`.
|
|
2621
|
+
*
|
|
2622
|
+
* `options.statusToken` is the end user's token from the grant, for a client that
|
|
2623
|
+
* holds no key (use `AnonymousAuth`). It answers the end user's view, which never
|
|
2624
|
+
* carries a record key. A request authenticated by a key ignores it.
|
|
2625
|
+
*/
|
|
2626
|
+
async getUploadStatus(folderPath, uploadId, options) {
|
|
2627
|
+
const path = this.buildPath(folderPath, `/_uploads/${encodeURIComponent(uploadId)}`);
|
|
2628
|
+
const statusToken = options?.statusToken;
|
|
2629
|
+
return this.transport.request("GET", path, {
|
|
2630
|
+
headers: statusToken === void 0 ? void 0 : { "X-Upload-Status-Token": statusToken }
|
|
2631
|
+
});
|
|
2632
|
+
}
|
|
2086
2633
|
/** Semantic search using auto-generated embeddings. */
|
|
2087
2634
|
async vectorSearch(folderPath, options) {
|
|
2088
2635
|
const {
|
|
@@ -2231,6 +2778,8 @@ export {
|
|
|
2231
2778
|
DEFAULT_RETRY_CONFIG,
|
|
2232
2779
|
DEFAULT_USER_AGENT,
|
|
2233
2780
|
ExternalIdConflictError,
|
|
2781
|
+
FilesQuotaExceededError,
|
|
2782
|
+
FilesQuotaUnavailableError,
|
|
2234
2783
|
FluxClient,
|
|
2235
2784
|
FoxnoseAPIError,
|
|
2236
2785
|
FoxnoseAuthError,
|
|
@@ -2250,9 +2799,15 @@ export {
|
|
|
2250
2799
|
StaticTokenProvider,
|
|
2251
2800
|
UpstreamError,
|
|
2252
2801
|
SDK_VERSION as VERSION,
|
|
2802
|
+
WebhookEndpointLimitExceededError,
|
|
2803
|
+
WebhookEndpointNotActiveError,
|
|
2804
|
+
WebhookEndpointNotFoundError,
|
|
2805
|
+
WebhookEndpointNotSubscribedError,
|
|
2806
|
+
WebhookEventNotFoundError,
|
|
2253
2807
|
buildSearchBody,
|
|
2254
2808
|
createConfig,
|
|
2255
2809
|
nestedFieldMeta,
|
|
2810
|
+
parseFindingEvidence,
|
|
2256
2811
|
resolveKey
|
|
2257
2812
|
};
|
|
2258
2813
|
//# sourceMappingURL=index.js.map
|