@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.cjs
CHANGED
|
@@ -26,6 +26,8 @@ __export(index_exports, {
|
|
|
26
26
|
DEFAULT_RETRY_CONFIG: () => DEFAULT_RETRY_CONFIG,
|
|
27
27
|
DEFAULT_USER_AGENT: () => DEFAULT_USER_AGENT,
|
|
28
28
|
ExternalIdConflictError: () => ExternalIdConflictError,
|
|
29
|
+
FilesQuotaExceededError: () => FilesQuotaExceededError,
|
|
30
|
+
FilesQuotaUnavailableError: () => FilesQuotaUnavailableError,
|
|
29
31
|
FluxClient: () => FluxClient,
|
|
30
32
|
FoxnoseAPIError: () => FoxnoseAPIError,
|
|
31
33
|
FoxnoseAuthError: () => FoxnoseAuthError,
|
|
@@ -45,9 +47,15 @@ __export(index_exports, {
|
|
|
45
47
|
StaticTokenProvider: () => StaticTokenProvider,
|
|
46
48
|
UpstreamError: () => UpstreamError,
|
|
47
49
|
VERSION: () => SDK_VERSION,
|
|
50
|
+
WebhookEndpointLimitExceededError: () => WebhookEndpointLimitExceededError,
|
|
51
|
+
WebhookEndpointNotActiveError: () => WebhookEndpointNotActiveError,
|
|
52
|
+
WebhookEndpointNotFoundError: () => WebhookEndpointNotFoundError,
|
|
53
|
+
WebhookEndpointNotSubscribedError: () => WebhookEndpointNotSubscribedError,
|
|
54
|
+
WebhookEventNotFoundError: () => WebhookEventNotFoundError,
|
|
48
55
|
buildSearchBody: () => buildSearchBody,
|
|
49
56
|
createConfig: () => createConfig,
|
|
50
57
|
nestedFieldMeta: () => nestedFieldMeta,
|
|
58
|
+
parseFindingEvidence: () => parseFindingEvidence,
|
|
51
59
|
resolveKey: () => resolveKey
|
|
52
60
|
});
|
|
53
61
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -147,6 +155,36 @@ var PlanExhaustedError = class extends FoxnoseAPIError {
|
|
|
147
155
|
this.upgradeUrl = options.upgradeUrl;
|
|
148
156
|
}
|
|
149
157
|
};
|
|
158
|
+
var FilesQuotaExceededError = class extends FoxnoseAPIError {
|
|
159
|
+
axis;
|
|
160
|
+
reason;
|
|
161
|
+
usedUnits;
|
|
162
|
+
includedUnits;
|
|
163
|
+
capUsd;
|
|
164
|
+
windowResetsAt;
|
|
165
|
+
upgradeUrl;
|
|
166
|
+
raiseCapUrl;
|
|
167
|
+
constructor(options) {
|
|
168
|
+
super(options);
|
|
169
|
+
this.name = "FilesQuotaExceededError";
|
|
170
|
+
this.axis = options.axis;
|
|
171
|
+
this.reason = options.reason;
|
|
172
|
+
this.usedUnits = options.usedUnits;
|
|
173
|
+
this.includedUnits = options.includedUnits;
|
|
174
|
+
this.capUsd = options.capUsd;
|
|
175
|
+
this.windowResetsAt = options.windowResetsAt;
|
|
176
|
+
this.upgradeUrl = options.upgradeUrl;
|
|
177
|
+
this.raiseCapUrl = options.raiseCapUrl;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var FilesQuotaUnavailableError = class extends FoxnoseAPIError {
|
|
181
|
+
retryAfter;
|
|
182
|
+
constructor(options) {
|
|
183
|
+
super(options);
|
|
184
|
+
this.name = "FilesQuotaUnavailableError";
|
|
185
|
+
this.retryAfter = options.retryAfter;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
150
188
|
var PlanLimitExceededError = class extends FoxnoseAPIError {
|
|
151
189
|
/** Entity whose limit was exceeded (e.g. collections, environments, api_keys). */
|
|
152
190
|
entity;
|
|
@@ -204,6 +242,45 @@ var UpstreamError = class extends FoxnoseAPIError {
|
|
|
204
242
|
this.name = "UpstreamError";
|
|
205
243
|
}
|
|
206
244
|
};
|
|
245
|
+
var WebhookEndpointNotFoundError = class extends FoxnoseAPIError {
|
|
246
|
+
constructor(options) {
|
|
247
|
+
super(options);
|
|
248
|
+
this.name = "WebhookEndpointNotFoundError";
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var WebhookEventNotFoundError = class extends FoxnoseAPIError {
|
|
252
|
+
constructor(options) {
|
|
253
|
+
super(options);
|
|
254
|
+
this.name = "WebhookEventNotFoundError";
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
var WebhookEndpointLimitExceededError = class extends FoxnoseAPIError {
|
|
258
|
+
constructor(options) {
|
|
259
|
+
super(options);
|
|
260
|
+
this.name = "WebhookEndpointLimitExceededError";
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var WebhookEndpointNotActiveError = class extends FoxnoseAPIError {
|
|
264
|
+
/** The endpoint's state (`paused`, `disabled` or `deleted`) when the call named it. */
|
|
265
|
+
reason;
|
|
266
|
+
/** Endpoints a redelivery without `endpoint_id` passed over, each with `endpoint_id` and `reason`. */
|
|
267
|
+
skipped;
|
|
268
|
+
constructor(options) {
|
|
269
|
+
super(options);
|
|
270
|
+
this.name = "WebhookEndpointNotActiveError";
|
|
271
|
+
this.reason = options.reason;
|
|
272
|
+
this.skipped = options.skipped ?? [];
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
var WebhookEndpointNotSubscribedError = class extends FoxnoseAPIError {
|
|
276
|
+
/** Endpoints a redelivery without `endpoint_id` passed over, each with `endpoint_id` and `reason`. */
|
|
277
|
+
skipped;
|
|
278
|
+
constructor(options) {
|
|
279
|
+
super(options);
|
|
280
|
+
this.name = "WebhookEndpointNotSubscribedError";
|
|
281
|
+
this.skipped = options.skipped ?? [];
|
|
282
|
+
}
|
|
283
|
+
};
|
|
207
284
|
function isPlainObject(value) {
|
|
208
285
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
209
286
|
}
|
|
@@ -219,6 +296,11 @@ function getHeader(headers, name) {
|
|
|
219
296
|
}
|
|
220
297
|
return void 0;
|
|
221
298
|
}
|
|
299
|
+
function retryAfterSeconds(headers) {
|
|
300
|
+
const raw = getHeader(headers, "Retry-After");
|
|
301
|
+
const parsed = raw !== void 0 ? Number(raw) : NaN;
|
|
302
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
303
|
+
}
|
|
222
304
|
var CONTENT_VALIDATION_CODES = /* @__PURE__ */ new Set(["content_validation_failed", "data_validation_error"]);
|
|
223
305
|
function buildAPIError(options) {
|
|
224
306
|
const { statusCode, errorCode, detail, responseHeaders, responseBody } = options;
|
|
@@ -241,6 +323,29 @@ function buildAPIError(options) {
|
|
|
241
323
|
upgradeUrl: typeof body.upgrade_url === "string" ? body.upgrade_url : void 0
|
|
242
324
|
});
|
|
243
325
|
}
|
|
326
|
+
if (statusCode === 402 && errorCode === "files_quota_exceeded" && body) {
|
|
327
|
+
const numberOrNull = (value) => typeof value === "number" ? value : value === null ? null : void 0;
|
|
328
|
+
const text = (value) => typeof value === "string" ? value : void 0;
|
|
329
|
+
return new FilesQuotaExceededError({
|
|
330
|
+
...options,
|
|
331
|
+
message: "message" in body ? options.message : "File processing quota reached",
|
|
332
|
+
axis: text(body.axis),
|
|
333
|
+
reason: text(body.reason),
|
|
334
|
+
usedUnits: typeof body.used_units === "number" ? body.used_units : void 0,
|
|
335
|
+
includedUnits: numberOrNull(body.included_units),
|
|
336
|
+
capUsd: numberOrNull(body.cap_usd),
|
|
337
|
+
windowResetsAt: body.window_resets_at === null ? null : text(body.window_resets_at),
|
|
338
|
+
upgradeUrl: text(body.upgrade_url),
|
|
339
|
+
raiseCapUrl: text(body.raise_cap_url)
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
if (statusCode === 503 && errorCode === "files_quota_unavailable") {
|
|
343
|
+
return new FilesQuotaUnavailableError({
|
|
344
|
+
...options,
|
|
345
|
+
message: body && "message" in body ? options.message : "File processing quota is unavailable",
|
|
346
|
+
retryAfter: retryAfterSeconds(responseHeaders)
|
|
347
|
+
});
|
|
348
|
+
}
|
|
244
349
|
if (statusCode === 403 && errorCode === "plan_limit_exceeded") {
|
|
245
350
|
const d = isPlainObject(detail) ? detail : {};
|
|
246
351
|
return new PlanLimitExceededError({
|
|
@@ -252,11 +357,9 @@ function buildAPIError(options) {
|
|
|
252
357
|
});
|
|
253
358
|
}
|
|
254
359
|
if (statusCode === 429 && errorCode === "rate_limited") {
|
|
255
|
-
const raw = getHeader(responseHeaders, "Retry-After");
|
|
256
|
-
const parsed = raw !== void 0 ? Number(raw) : NaN;
|
|
257
360
|
return new RateLimitExceededError({
|
|
258
361
|
...options,
|
|
259
|
-
retryAfter:
|
|
362
|
+
retryAfter: retryAfterSeconds(responseHeaders)
|
|
260
363
|
});
|
|
261
364
|
}
|
|
262
365
|
if (statusCode === 403 && errorCode === "collection_not_writable") {
|
|
@@ -274,6 +377,30 @@ function buildAPIError(options) {
|
|
|
274
377
|
errorsTruncated: d.errors_truncated === true
|
|
275
378
|
});
|
|
276
379
|
}
|
|
380
|
+
if (statusCode === 404 && errorCode === "webhook_endpoint_not_found") {
|
|
381
|
+
return new WebhookEndpointNotFoundError(options);
|
|
382
|
+
}
|
|
383
|
+
if (statusCode === 404 && errorCode === "webhook_event_not_found") {
|
|
384
|
+
return new WebhookEventNotFoundError(options);
|
|
385
|
+
}
|
|
386
|
+
if (statusCode === 409 && errorCode === "limit_exceeded") {
|
|
387
|
+
return new WebhookEndpointLimitExceededError(options);
|
|
388
|
+
}
|
|
389
|
+
if (statusCode === 409 && errorCode === "endpoint_not_active") {
|
|
390
|
+
const d = isPlainObject(detail) ? detail : {};
|
|
391
|
+
return new WebhookEndpointNotActiveError({
|
|
392
|
+
...options,
|
|
393
|
+
reason: typeof d.reason === "string" ? d.reason : void 0,
|
|
394
|
+
skipped: Array.isArray(d.skipped) ? d.skipped : void 0
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
if (statusCode === 409 && errorCode === "endpoint_not_subscribed") {
|
|
398
|
+
const d = isPlainObject(detail) ? detail : {};
|
|
399
|
+
return new WebhookEndpointNotSubscribedError({
|
|
400
|
+
...options,
|
|
401
|
+
skipped: Array.isArray(d.skipped) ? d.skipped : void 0
|
|
402
|
+
});
|
|
403
|
+
}
|
|
277
404
|
if (statusCode === 502 && errorCode === "upstream_error") {
|
|
278
405
|
return new UpstreamError(options);
|
|
279
406
|
}
|
|
@@ -363,7 +490,7 @@ var DEFAULT_RETRY_CONFIG = {
|
|
|
363
490
|
statusCodes: [408, 425, 429, 500, 502, 503, 504],
|
|
364
491
|
methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
|
|
365
492
|
};
|
|
366
|
-
var SDK_VERSION = "0.
|
|
493
|
+
var SDK_VERSION = "0.8.0";
|
|
367
494
|
var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
|
|
368
495
|
function createConfig(options) {
|
|
369
496
|
if (!options.baseUrl) {
|
|
@@ -547,7 +674,7 @@ var HttpTransport = class {
|
|
|
547
674
|
body = payload;
|
|
548
675
|
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
549
676
|
message = payload.message ?? message;
|
|
550
|
-
errorCode = payload.error_code;
|
|
677
|
+
errorCode = payload.error_code ?? payload.code;
|
|
551
678
|
detail = payload.detail;
|
|
552
679
|
}
|
|
553
680
|
} catch {
|
|
@@ -604,6 +731,26 @@ function nestedFieldMeta(opts) {
|
|
|
604
731
|
auto_update: opts.autoUpdate ?? false
|
|
605
732
|
};
|
|
606
733
|
}
|
|
734
|
+
var TEXT_EVIDENCE_KINDS = /* @__PURE__ */ new Set(["hidden_text", "low_legibility_text"]);
|
|
735
|
+
function parseFindingEvidence(finding) {
|
|
736
|
+
if (!TEXT_EVIDENCE_KINDS.has(finding.kind) || !finding.evidence) {
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
let fields;
|
|
740
|
+
try {
|
|
741
|
+
fields = JSON.parse(finding.evidence);
|
|
742
|
+
} catch {
|
|
743
|
+
return null;
|
|
744
|
+
}
|
|
745
|
+
if (typeof fields !== "object" || fields === null || Array.isArray(fields)) {
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
const { parts } = fields;
|
|
749
|
+
if (parts !== void 0 && !Array.isArray(parts)) {
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
return { ...fields, parts: parts ?? [] };
|
|
753
|
+
}
|
|
607
754
|
function resolveKey(value) {
|
|
608
755
|
if (typeof value === "string") {
|
|
609
756
|
return value;
|
|
@@ -643,6 +790,19 @@ function managementPaths(environmentKey) {
|
|
|
643
790
|
// Resource paths
|
|
644
791
|
resourceBase: (folderKey) => `/v1/${environmentKey}/folders/${folderKey}/resources`,
|
|
645
792
|
revisionBase: (folderKey, resourceKey) => `/v1/${environmentKey}/folders/${folderKey}/resources/${resourceKey}/revisions`,
|
|
793
|
+
// Files paths
|
|
794
|
+
uploadLinksRoot: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/upload-links`,
|
|
795
|
+
uploadLinkRoot: (collectionKey, uploadId) => `/v1/${environmentKey}/collections/${collectionKey}/upload-links/${encodeURIComponent(uploadId)}`,
|
|
796
|
+
fileRoot: (collectionKey, resourceKey) => `/v1/${environmentKey}/collections/${collectionKey}/files/${resourceKey}`,
|
|
797
|
+
fileTombstonesRoot: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/files/tombstones`,
|
|
798
|
+
filesPolicyRoot: (collectionKey) => `/v1/${environmentKey}/collections/${collectionKey}/files-policy`,
|
|
799
|
+
filesReviewRoot: () => `/v1/${environmentKey}/files/review`,
|
|
800
|
+
// Webhooks paths
|
|
801
|
+
webhooksRoot: () => `/v1/${environmentKey}/webhooks`,
|
|
802
|
+
webhookEndpointRoot: (endpointId) => `/v1/${environmentKey}/webhooks/endpoints/${encodeURIComponent(endpointId)}`,
|
|
803
|
+
webhookEventRoot: (eventId) => `/v1/${environmentKey}/webhooks/events/${encodeURIComponent(eventId)}`,
|
|
804
|
+
// Caller's own permissions
|
|
805
|
+
myPermissionsRoot: () => `/v1/${environmentKey}/permissions/me`,
|
|
646
806
|
// Management API key paths
|
|
647
807
|
managementApiKeysRoot: () => `/v1/${environmentKey}/permissions/management-api/api-keys`,
|
|
648
808
|
managementApiKeyRoot: (apiKey) => `/v1/${environmentKey}/permissions/management-api/api-keys/${apiKey}`,
|
|
@@ -674,6 +834,21 @@ function managementPaths(environmentKey) {
|
|
|
674
834
|
}
|
|
675
835
|
|
|
676
836
|
// src/management/client.ts
|
|
837
|
+
function hideSecret(response) {
|
|
838
|
+
if (response && typeof response === "object" && "secret" in response) {
|
|
839
|
+
Object.defineProperty(response, "secret", {
|
|
840
|
+
value: response.secret,
|
|
841
|
+
enumerable: false,
|
|
842
|
+
writable: false,
|
|
843
|
+
configurable: true
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
return response;
|
|
847
|
+
}
|
|
848
|
+
function webhookEndpointBody(request) {
|
|
849
|
+
const { collection_keys, ...rest } = request;
|
|
850
|
+
return collection_keys === void 0 ? rest : { ...rest, collection_keys: collection_keys.map((key) => resolveKey(key)) };
|
|
851
|
+
}
|
|
677
852
|
var ManagementClient = class {
|
|
678
853
|
environmentKey;
|
|
679
854
|
transport;
|
|
@@ -751,6 +926,14 @@ var ManagementClient = class {
|
|
|
751
926
|
const key = resolveKey(orgKey);
|
|
752
927
|
return this.request("PUT", `${this.paths.orgRoot(key)}/`, { jsonBody: payload });
|
|
753
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* Write the given fields of an organization and leave the rest alone. The
|
|
931
|
+
* response is the whole organization as stored.
|
|
932
|
+
*/
|
|
933
|
+
async patchOrganization(orgKey, payload) {
|
|
934
|
+
const key = resolveKey(orgKey);
|
|
935
|
+
return this.request("PATCH", `${this.paths.orgRoot(key)}/`, { jsonBody: payload });
|
|
936
|
+
}
|
|
754
937
|
async listRegions() {
|
|
755
938
|
const payload = await this.request("GET", "/regions/") ?? [];
|
|
756
939
|
return Array.isArray(payload) ? payload : [payload];
|
|
@@ -1165,6 +1348,20 @@ var ManagementClient = class {
|
|
|
1165
1348
|
jsonBody: payload
|
|
1166
1349
|
});
|
|
1167
1350
|
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Write the given fields of a collection and leave the rest alone.
|
|
1353
|
+
*
|
|
1354
|
+
* `updateCollection` replaces the whole record; this does not. An omitted
|
|
1355
|
+
* `parent` keeps the collection where it is, and `{ parent: null }` moves it
|
|
1356
|
+
* to the root. The response is the whole collection as stored.
|
|
1357
|
+
*/
|
|
1358
|
+
async patchCollection(collectionKey, payload) {
|
|
1359
|
+
const key = resolveKey(collectionKey);
|
|
1360
|
+
return this.request("PATCH", `${this.paths.collectionsTreeItem()}/`, {
|
|
1361
|
+
params: { key },
|
|
1362
|
+
jsonBody: payload
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1168
1365
|
async deleteCollection(collectionKey) {
|
|
1169
1366
|
const key = resolveKey(collectionKey);
|
|
1170
1367
|
await this.request("DELETE", `${this.paths.collectionsTreeItem()}/`, {
|
|
@@ -1502,6 +1699,14 @@ var ManagementClient = class {
|
|
|
1502
1699
|
const key = resolveKey(componentKey);
|
|
1503
1700
|
return this.request("PUT", `${this.paths.componentRoot(key)}/`, { jsonBody: payload });
|
|
1504
1701
|
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Write the given fields of a component and leave the rest alone. The response
|
|
1704
|
+
* is the whole component as stored.
|
|
1705
|
+
*/
|
|
1706
|
+
async patchComponent(componentKey, payload) {
|
|
1707
|
+
const key = resolveKey(componentKey);
|
|
1708
|
+
return this.request("PATCH", `${this.paths.componentRoot(key)}/`, { jsonBody: payload });
|
|
1709
|
+
}
|
|
1505
1710
|
async deleteComponent(componentKey) {
|
|
1506
1711
|
const key = resolveKey(componentKey);
|
|
1507
1712
|
await this.request("DELETE", `${this.paths.componentRoot(key)}/`, { parseJson: false });
|
|
@@ -1887,6 +2092,317 @@ var ManagementClient = class {
|
|
|
1887
2092
|
protectionLevel: "none"
|
|
1888
2093
|
});
|
|
1889
2094
|
}
|
|
2095
|
+
// ------------------------------------------------------------------ //
|
|
2096
|
+
// Files
|
|
2097
|
+
// ------------------------------------------------------------------ //
|
|
2098
|
+
/**
|
|
2099
|
+
* List a files collection's upload links, newest first. `params` carries `limit` (at
|
|
2100
|
+
* most 100), `offset` and `state`: `active`, `ended` or `all` (the default).
|
|
2101
|
+
*/
|
|
2102
|
+
async listUploadLinks(collectionKey, params) {
|
|
2103
|
+
const key = resolveKey(collectionKey);
|
|
2104
|
+
return this.request("GET", `${this.paths.uploadLinksRoot(key)}/`, { params });
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Create an upload link: a hosted page where an end user adds files.
|
|
2108
|
+
*
|
|
2109
|
+
* The collection must be strict. Works with a user token or a Management API
|
|
2110
|
+
* key of this environment. Read the link back with {@link getUploadLink}; the
|
|
2111
|
+
* Flux upload status answers only the Flux key that started an upload, never
|
|
2112
|
+
* a link made here.
|
|
2113
|
+
*
|
|
2114
|
+
* `upload_url` carries the link's token and is returned only by this call.
|
|
2115
|
+
*/
|
|
2116
|
+
async createUploadLink(collectionKey, request) {
|
|
2117
|
+
const key = resolveKey(collectionKey);
|
|
2118
|
+
return this.transport.request("POST", `${this.paths.uploadLinksRoot(key)}/`, {
|
|
2119
|
+
jsonBody: { ...request, owner: resolveKey(request.owner) },
|
|
2120
|
+
allowRetries: false
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
/** Read one upload link with its sessions and the status of each file. */
|
|
2124
|
+
async getUploadLink(collectionKey, uploadId) {
|
|
2125
|
+
const key = resolveKey(collectionKey);
|
|
2126
|
+
return this.request("GET", `${this.paths.uploadLinkRoot(key, uploadId)}/`);
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Revoke an upload link. Revoking a revoked link returns the same state. Files
|
|
2130
|
+
* already uploaded through the link are not affected.
|
|
2131
|
+
*/
|
|
2132
|
+
async revokeUploadLink(collectionKey, uploadId) {
|
|
2133
|
+
const key = resolveKey(collectionKey);
|
|
2134
|
+
return this.request("POST", `${this.paths.uploadLinkRoot(key, uploadId)}/revoke/`);
|
|
2135
|
+
}
|
|
2136
|
+
/** Read a record's file: its verdict, the checks that ran and every finding. */
|
|
2137
|
+
async getFileAnalysis(collectionKey, resourceKey) {
|
|
2138
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2139
|
+
return this.request("GET", `${root}/analysis/`);
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Release a file held for a reviewer.
|
|
2143
|
+
*
|
|
2144
|
+
* The answer's `outcome` says what happened; a publish that goes back through
|
|
2145
|
+
* processing completes on its own. A file no reviewer holds is
|
|
2146
|
+
* `409 file_not_in_review`, `file_not_ready` or `file_erased`.
|
|
2147
|
+
*/
|
|
2148
|
+
async approveFile(collectionKey, resourceKey) {
|
|
2149
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2150
|
+
return this.transport.request("POST", `${root}/approve/`, { allowRetries: false });
|
|
2151
|
+
}
|
|
2152
|
+
/** Reject a file held for a reviewer. Repeating it returns the same state. */
|
|
2153
|
+
async rejectFile(collectionKey, resourceKey) {
|
|
2154
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2155
|
+
return this.request("POST", `${root}/reject/`);
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Analyze a file again under the collection's live policy.
|
|
2159
|
+
*
|
|
2160
|
+
* Accepted work runs in the background; a published generation keeps serving
|
|
2161
|
+
* until the new one publishes. A `storage_only` collection answers
|
|
2162
|
+
* `409 reanalysis_requires_agent_ready`. This is paid processing: a refusal over
|
|
2163
|
+
* the plan throws {@link FilesQuotaExceededError}, a quota that cannot be read
|
|
2164
|
+
* throws {@link FilesQuotaUnavailableError}, and over a budget is `429`.
|
|
2165
|
+
*/
|
|
2166
|
+
async reanalyzeFile(collectionKey, resourceKey) {
|
|
2167
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2168
|
+
return this.transport.request("POST", `${root}/reanalyze/`, { allowRetries: false });
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Get a short-lived link to a record's original file.
|
|
2172
|
+
*
|
|
2173
|
+
* A state that cannot be downloaded now is a `409`: `detail.reason` of the
|
|
2174
|
+
* thrown error names it. Check `warnings` before opening the file.
|
|
2175
|
+
*/
|
|
2176
|
+
async getFileOriginal(collectionKey, resourceKey) {
|
|
2177
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2178
|
+
return this.request("GET", `${root}/file/original/`);
|
|
2179
|
+
}
|
|
2180
|
+
/**
|
|
2181
|
+
* Get a short-lived link to a record's safe copy. It is an image-only PDF, or a PNG
|
|
2182
|
+
* for an image: read `content_type`.
|
|
2183
|
+
*/
|
|
2184
|
+
async getFileSafeCopy(collectionKey, resourceKey) {
|
|
2185
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2186
|
+
return this.request("GET", `${root}/file/safe-copy/`);
|
|
2187
|
+
}
|
|
2188
|
+
/** Get a short-lived link to the redacted PNG of one page. */
|
|
2189
|
+
async getFilePage(collectionKey, resourceKey, page) {
|
|
2190
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2191
|
+
return this.request("GET", `${root}/file/pages/${page}/`);
|
|
2192
|
+
}
|
|
2193
|
+
/**
|
|
2194
|
+
* Read one page: its redacted image, what was withheld, its tables and the
|
|
2195
|
+
* text an agent receives.
|
|
2196
|
+
*/
|
|
2197
|
+
async getFilePageDetail(collectionKey, resourceKey, page) {
|
|
2198
|
+
const root = this.fileRoot(collectionKey, resourceKey);
|
|
2199
|
+
return this.request("GET", `${root}/file/pages/${page}/detail/`);
|
|
2200
|
+
}
|
|
2201
|
+
/** List a collection's blocked and rejected files, newest first. */
|
|
2202
|
+
async listFileTombstones(collectionKey, params) {
|
|
2203
|
+
const key = resolveKey(collectionKey);
|
|
2204
|
+
return this.request("GET", `${this.paths.fileTombstonesRoot(key)}/`, { params });
|
|
2205
|
+
}
|
|
2206
|
+
/** Read a collection's live files policy. */
|
|
2207
|
+
async getFilesPolicy(collectionKey) {
|
|
2208
|
+
const key = resolveKey(collectionKey);
|
|
2209
|
+
return this.request("GET", `${this.paths.filesPolicyRoot(key)}/`);
|
|
2210
|
+
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Replace a collection's files policy with a new version.
|
|
2213
|
+
*
|
|
2214
|
+
* A full replacement: an omitted field takes its default. Sending the live
|
|
2215
|
+
* body again creates no version.
|
|
2216
|
+
*/
|
|
2217
|
+
async updateFilesPolicy(collectionKey, payload) {
|
|
2218
|
+
const key = resolveKey(collectionKey);
|
|
2219
|
+
return this.request("PUT", `${this.paths.filesPolicyRoot(key)}/`, { jsonBody: payload });
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* List the files held for a reviewer in this environment, newest first.
|
|
2223
|
+
*
|
|
2224
|
+
* `collection` narrows the queue to one collection; one the caller cannot read,
|
|
2225
|
+
* or that does not exist, is an empty page. `params` carries `limit` (at most
|
|
2226
|
+
* 100) and `offset`.
|
|
2227
|
+
*/
|
|
2228
|
+
async listFileReviewQueue(options) {
|
|
2229
|
+
const params = { ...options?.params };
|
|
2230
|
+
if (options?.collection !== void 0) {
|
|
2231
|
+
params.collection = resolveKey(options.collection);
|
|
2232
|
+
}
|
|
2233
|
+
return this.request("GET", `${this.paths.filesReviewRoot()}/`, { params });
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* Read what the authenticated caller may do in this environment.
|
|
2237
|
+
*
|
|
2238
|
+
* Works for a user token and for a Management API key of this environment. A caller
|
|
2239
|
+
* with no grants at all is a `403`; a key of another environment is a
|
|
2240
|
+
* `404 environment_not_found`.
|
|
2241
|
+
*/
|
|
2242
|
+
async getMyPermissions() {
|
|
2243
|
+
return this.request("GET", `${this.paths.myPermissionsRoot()}/`);
|
|
2244
|
+
}
|
|
2245
|
+
// ------------------------------------------------------------------ //
|
|
2246
|
+
// Webhooks
|
|
2247
|
+
// ------------------------------------------------------------------ //
|
|
2248
|
+
/**
|
|
2249
|
+
* List the environment's webhook endpoints, newest first. Each item carries
|
|
2250
|
+
* `stats_24h`; secrets are never included. `params` carries `status` (`active`,
|
|
2251
|
+
* `paused` or `disabled`), `limit` (at most 200) and `offset`.
|
|
2252
|
+
*/
|
|
2253
|
+
async listWebhookEndpoints(params) {
|
|
2254
|
+
return this.request("GET", `${this.paths.webhooksRoot()}/endpoints/`, { params });
|
|
2255
|
+
}
|
|
2256
|
+
/**
|
|
2257
|
+
* Create a webhook endpoint.
|
|
2258
|
+
*
|
|
2259
|
+
* The answer carries the signing `secret`, which is not enumerable: read it as
|
|
2260
|
+
* `created.secret`, and read it again later with {@link getWebhookEndpointSecret}.
|
|
2261
|
+
* An environment holds at most 20 endpoints ({@link WebhookEndpointLimitExceededError}).
|
|
2262
|
+
* A `content` endpoint also needs read access to the content it will deliver.
|
|
2263
|
+
*/
|
|
2264
|
+
async createWebhookEndpoint(request) {
|
|
2265
|
+
const created = await this.transport.request(
|
|
2266
|
+
"POST",
|
|
2267
|
+
`${this.paths.webhooksRoot()}/endpoints/`,
|
|
2268
|
+
{
|
|
2269
|
+
jsonBody: webhookEndpointBody(request),
|
|
2270
|
+
allowRetries: false
|
|
2271
|
+
}
|
|
2272
|
+
);
|
|
2273
|
+
return hideSecret(created);
|
|
2274
|
+
}
|
|
2275
|
+
/** Read one webhook endpoint. It carries neither the secret nor `stats_24h`. */
|
|
2276
|
+
async getWebhookEndpoint(endpointId) {
|
|
2277
|
+
return this.request("GET", `${this.paths.webhookEndpointRoot(endpointId)}/`);
|
|
2278
|
+
}
|
|
2279
|
+
/**
|
|
2280
|
+
* Change the given fields of an endpoint and leave the rest alone.
|
|
2281
|
+
*
|
|
2282
|
+
* `status: 'active'` resumes a paused or disabled endpoint and clears its failure
|
|
2283
|
+
* streak; events that happened meanwhile are not sent, but failed deliveries can be
|
|
2284
|
+
* sent again with {@link recoverWebhookDeliveries}.
|
|
2285
|
+
*/
|
|
2286
|
+
async updateWebhookEndpoint(endpointId, changes) {
|
|
2287
|
+
return this.request("PATCH", `${this.paths.webhookEndpointRoot(endpointId)}/`, {
|
|
2288
|
+
jsonBody: webhookEndpointBody(changes)
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
* Delete an endpoint and its pending deliveries. Its finished deliveries and
|
|
2293
|
+
* attempts stay in the event log for 30 days, with `endpoint.deleted` true.
|
|
2294
|
+
*/
|
|
2295
|
+
async deleteWebhookEndpoint(endpointId) {
|
|
2296
|
+
await this.request("DELETE", `${this.paths.webhookEndpointRoot(endpointId)}/`, {
|
|
2297
|
+
parseJson: false
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2301
|
+
* List an endpoint's deliveries, newest first, each with the event it carries.
|
|
2302
|
+
* `params` carries `limit` (at most 200) and `offset`.
|
|
2303
|
+
*/
|
|
2304
|
+
async listWebhookEndpointDeliveries(endpointId, params) {
|
|
2305
|
+
return this.request("GET", `${this.paths.webhookEndpointRoot(endpointId)}/deliveries/`, {
|
|
2306
|
+
params
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
/**
|
|
2310
|
+
* Read the endpoint's current signing secret: the newest, during a rotation. Needs
|
|
2311
|
+
* `webhooks:update`. `secret` is not enumerable: read it as `response.secret`.
|
|
2312
|
+
*/
|
|
2313
|
+
async getWebhookEndpointSecret(endpointId) {
|
|
2314
|
+
const response = await this.request(
|
|
2315
|
+
"GET",
|
|
2316
|
+
`${this.paths.webhookEndpointRoot(endpointId)}/secret/`
|
|
2317
|
+
);
|
|
2318
|
+
return hideSecret(response);
|
|
2319
|
+
}
|
|
2320
|
+
/**
|
|
2321
|
+
* Create a new signing secret and return it.
|
|
2322
|
+
*
|
|
2323
|
+
* The previous secret stays valid for 24 hours, and deliveries carry a signature for
|
|
2324
|
+
* each valid secret; with `expire_previous_now` it stops at once. Needs
|
|
2325
|
+
* `webhooks:update`. `secret` is not enumerable: read it as `rotation.secret`.
|
|
2326
|
+
*/
|
|
2327
|
+
async rotateWebhookEndpointSecret(endpointId, options) {
|
|
2328
|
+
const response = await this.transport.request(
|
|
2329
|
+
"POST",
|
|
2330
|
+
`${this.paths.webhookEndpointRoot(endpointId)}/secret/rotate/`,
|
|
2331
|
+
{
|
|
2332
|
+
jsonBody: { expire_previous_now: options?.expire_previous_now ?? false },
|
|
2333
|
+
allowRetries: false
|
|
2334
|
+
}
|
|
2335
|
+
);
|
|
2336
|
+
return hideSecret(response);
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Send a sample event of `eventType` to this endpoint only, with `test` true in the
|
|
2340
|
+
* envelope. It is sent whatever the endpoint's event types and collection filter,
|
|
2341
|
+
* but the endpoint must be active ({@link WebhookEndpointNotActiveError}).
|
|
2342
|
+
*/
|
|
2343
|
+
async sendWebhookTestEvent(endpointId, eventType) {
|
|
2344
|
+
return this.transport.request("POST", `${this.paths.webhookEndpointRoot(endpointId)}/test/`, {
|
|
2345
|
+
jsonBody: { event_type: eventType },
|
|
2346
|
+
allowRetries: false
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* Send again the endpoint's failed deliveries created at or after `since`.
|
|
2351
|
+
*
|
|
2352
|
+
* Each becomes a new pending delivery of the same event. One call queues at most
|
|
2353
|
+
* 10,000 deliveries; when `more` is true, call again with the same `since`. `since`
|
|
2354
|
+
* is an ISO 8601 time within the last 30 days; a time without a zone is read as UTC.
|
|
2355
|
+
*/
|
|
2356
|
+
async recoverWebhookDeliveries(endpointId, since) {
|
|
2357
|
+
return this.transport.request(
|
|
2358
|
+
"POST",
|
|
2359
|
+
`${this.paths.webhookEndpointRoot(endpointId)}/recover/`,
|
|
2360
|
+
{
|
|
2361
|
+
jsonBody: { since: since instanceof Date ? since.toISOString() : since },
|
|
2362
|
+
allowRetries: false
|
|
2363
|
+
}
|
|
2364
|
+
);
|
|
2365
|
+
}
|
|
2366
|
+
/**
|
|
2367
|
+
* List the events of the last 30 days, newest first, with `delivery_counts`.
|
|
2368
|
+
* `params` carries `type`, `endpoint` (an endpoint `id`), `status` (`pending`,
|
|
2369
|
+
* `succeeded` or `dead`), `test`, `after`, `before` (ISO 8601), `limit` (at most 200)
|
|
2370
|
+
* and `offset`.
|
|
2371
|
+
*/
|
|
2372
|
+
async listWebhookEvents(params) {
|
|
2373
|
+
return this.request("GET", `${this.paths.webhooksRoot()}/events/`, { params });
|
|
2374
|
+
}
|
|
2375
|
+
/** Read one event with its envelope and all its deliveries, oldest first. */
|
|
2376
|
+
async getWebhookEvent(eventId) {
|
|
2377
|
+
return this.request("GET", `${this.paths.webhookEventRoot(eventId)}/`);
|
|
2378
|
+
}
|
|
2379
|
+
/**
|
|
2380
|
+
* List every attempt to deliver the event, across endpoints, oldest first. `params`
|
|
2381
|
+
* carries `limit` (at most 200) and `offset`.
|
|
2382
|
+
*/
|
|
2383
|
+
async listWebhookEventAttempts(eventId, params) {
|
|
2384
|
+
return this.request("GET", `${this.paths.webhookEventRoot(eventId)}/attempts/`, { params });
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Send the event again as a new delivery, with the same event `id`.
|
|
2388
|
+
*
|
|
2389
|
+
* With `endpoint_id` the event goes to that endpoint. Without it, the event goes to
|
|
2390
|
+
* every endpoint that had a delivery of it and is active and subscribed to it now;
|
|
2391
|
+
* the others are listed in `skipped`.
|
|
2392
|
+
*/
|
|
2393
|
+
async redeliverWebhookEvent(eventId, options) {
|
|
2394
|
+
return this.transport.request("POST", `${this.paths.webhookEventRoot(eventId)}/redeliver/`, {
|
|
2395
|
+
jsonBody: options?.endpoint_id !== void 0 ? { endpoint_id: options.endpoint_id } : {},
|
|
2396
|
+
allowRetries: false
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
/** List the event-type catalogue with the JSON Schema of each payload mode. */
|
|
2400
|
+
async listWebhookEventTypes() {
|
|
2401
|
+
return this.request("GET", `${this.paths.webhooksRoot()}/event-types/`);
|
|
2402
|
+
}
|
|
2403
|
+
fileRoot(collectionKey, resourceKey) {
|
|
2404
|
+
return this.paths.fileRoot(resolveKey(collectionKey), resolveKey(resourceKey));
|
|
2405
|
+
}
|
|
1890
2406
|
};
|
|
1891
2407
|
|
|
1892
2408
|
// src/flux/models.ts
|
|
@@ -2137,6 +2653,45 @@ var FluxClient = class {
|
|
|
2137
2653
|
const path = this.buildPath(folderPath, `/${resourceKey}/`);
|
|
2138
2654
|
return this.transport.request("PUT", path, { jsonBody: { data }, allowRetries: false });
|
|
2139
2655
|
}
|
|
2656
|
+
/**
|
|
2657
|
+
* Get a grant for one upload to a files collection.
|
|
2658
|
+
*
|
|
2659
|
+
* The grant is a credential: pass it on, do not log it. For a strict collection
|
|
2660
|
+
* `folderPath` names the owner, e.g. `support/tickets/tk_1/attachments`. Needs a
|
|
2661
|
+
* key with create access to the collection.
|
|
2662
|
+
*
|
|
2663
|
+
* `options.sessionKey` is an optional idempotency key of 43 URL-safe characters:
|
|
2664
|
+
* a repeat with the same key, collection and owner reaches the same upload
|
|
2665
|
+
* session. A failed request is never retried automatically, so send one to
|
|
2666
|
+
* retry safely.
|
|
2667
|
+
*/
|
|
2668
|
+
async createUploadSignature(folderPath, options) {
|
|
2669
|
+
const path = this.buildPath(folderPath, "/_upload-signature");
|
|
2670
|
+
const sessionKey = options?.sessionKey;
|
|
2671
|
+
return this.transport.request("POST", path, {
|
|
2672
|
+
jsonBody: sessionKey === void 0 ? void 0 : { session_key: sessionKey },
|
|
2673
|
+
allowRetries: false
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
2677
|
+
* Read the status of an upload.
|
|
2678
|
+
*
|
|
2679
|
+
* A key reads the uploads that key started, and the path must name the same
|
|
2680
|
+
* collection and owner. Any other combination is `404 not_found`, which includes
|
|
2681
|
+
* a link made through the Management API: read that one with
|
|
2682
|
+
* `ManagementClient.getUploadLink`.
|
|
2683
|
+
*
|
|
2684
|
+
* `options.statusToken` is the end user's token from the grant, for a client that
|
|
2685
|
+
* holds no key (use `AnonymousAuth`). It answers the end user's view, which never
|
|
2686
|
+
* carries a record key. A request authenticated by a key ignores it.
|
|
2687
|
+
*/
|
|
2688
|
+
async getUploadStatus(folderPath, uploadId, options) {
|
|
2689
|
+
const path = this.buildPath(folderPath, `/_uploads/${encodeURIComponent(uploadId)}`);
|
|
2690
|
+
const statusToken = options?.statusToken;
|
|
2691
|
+
return this.transport.request("GET", path, {
|
|
2692
|
+
headers: statusToken === void 0 ? void 0 : { "X-Upload-Status-Token": statusToken }
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2140
2695
|
/** Semantic search using auto-generated embeddings. */
|
|
2141
2696
|
async vectorSearch(folderPath, options) {
|
|
2142
2697
|
const {
|
|
@@ -2286,6 +2841,8 @@ var FluxClient = class {
|
|
|
2286
2841
|
DEFAULT_RETRY_CONFIG,
|
|
2287
2842
|
DEFAULT_USER_AGENT,
|
|
2288
2843
|
ExternalIdConflictError,
|
|
2844
|
+
FilesQuotaExceededError,
|
|
2845
|
+
FilesQuotaUnavailableError,
|
|
2289
2846
|
FluxClient,
|
|
2290
2847
|
FoxnoseAPIError,
|
|
2291
2848
|
FoxnoseAuthError,
|
|
@@ -2305,9 +2862,15 @@ var FluxClient = class {
|
|
|
2305
2862
|
StaticTokenProvider,
|
|
2306
2863
|
UpstreamError,
|
|
2307
2864
|
VERSION,
|
|
2865
|
+
WebhookEndpointLimitExceededError,
|
|
2866
|
+
WebhookEndpointNotActiveError,
|
|
2867
|
+
WebhookEndpointNotFoundError,
|
|
2868
|
+
WebhookEndpointNotSubscribedError,
|
|
2869
|
+
WebhookEventNotFoundError,
|
|
2308
2870
|
buildSearchBody,
|
|
2309
2871
|
createConfig,
|
|
2310
2872
|
nestedFieldMeta,
|
|
2873
|
+
parseFindingEvidence,
|
|
2311
2874
|
resolveKey
|
|
2312
2875
|
});
|
|
2313
2876
|
//# sourceMappingURL=index.cjs.map
|