calmlens 0.20.0 → 0.22.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 +15 -10
- package/bin/calmlens.js +1848 -679
- package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-Bwlib4Zc.js} +1 -1
- package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-DUYMo9PZ.js} +30 -10
- package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-YvgV995V.js} +318 -374
- package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-3N-gdsxC.js} +346 -89
- package/cjs/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/cjs/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/cjs/Core-C33pkBmf.d.ts +826 -0
- package/cjs/Core-Cm5Z1oJ9.js +1001 -0
- package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
- package/cjs/{ModerationContextLimits-2nIv7Zh3.js → ModerationContextLimits-ud1xpZRK.js} +727 -268
- package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-DQ0BYISX.js} +1 -1
- package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-D29T_R0M-D6Bu-Mln.js} +355 -47
- package/cjs/{UploadController-MLVs97Zt.js → UploadController-l8fZM2qT.js} +34 -14
- package/{esm/WebhookPayload-DkukERKE.d.ts → cjs/WebhookPayload-Dt6DttS0.d.ts} +120 -86
- package/cjs/app.d.ts +6 -7
- package/cjs/app.js +4 -3
- package/cjs/elements.d.ts +123 -22
- package/cjs/elements.js +553 -156
- package/cjs/file-icons.d.ts +2 -67
- package/cjs/index-Bde1wjiw.d.ts +16 -0
- package/cjs/index.d.ts +5 -6
- package/cjs/index.js +3 -2
- package/cjs/react-native.d.ts +52 -11
- package/cjs/react-native.js +231 -99
- package/cjs/react.d.ts +42 -9
- package/cjs/react.js +381 -118
- package/cjs/server.d.ts +48 -7
- package/cjs/server.js +7 -3
- package/cjs/test-inputs.d.ts +2 -2
- package/cjs/test-inputs.js +13 -9
- package/cjs/testing.d.ts +29 -15
- package/cjs/testing.js +1722 -433
- package/cjs/ui-BRA4HQ8r.js +1359 -0
- package/cjs/ui-YQuvbidU.d.ts +139 -0
- package/cjs/ui.d.ts +3 -2
- package/cjs/ui.js +45 -22
- package/cjs/vue.d.ts +802 -199
- package/cjs/vue.js +359 -127
- package/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-GRZVB0G_.js} +1 -1
- package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-B5QIJ6KS.js} +30 -10
- package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BG7Qrh8-.js} +317 -367
- package/esm/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-bRUAebi-.js} +323 -90
- package/esm/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/esm/Core-BvQe4moS.js +846 -0
- package/esm/Core-C33pkBmf.d.ts +826 -0
- package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
- package/esm/{ModerationContextLimits-Chw-AzgL.js → ModerationContextLimits-CrxSnVZ3.js} +682 -253
- package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-BMO8saxT.js} +1 -1
- package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-D29T_R0M-Ztc74ucs.js} +332 -48
- package/esm/{UploadController-BJZghJpg.js → UploadController-DnJrWiE4.js} +34 -14
- package/{cjs/WebhookPayload-DkukERKE.d.ts → esm/WebhookPayload-Dt6DttS0.d.ts} +120 -86
- package/esm/app.d.ts +6 -7
- package/esm/app.js +3 -3
- package/esm/elements.d.ts +123 -22
- package/esm/elements.js +497 -128
- package/esm/file-icons.d.ts +2 -67
- package/esm/index-Bde1wjiw.d.ts +16 -0
- package/esm/index.d.ts +5 -6
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +52 -11
- package/esm/react-native.js +205 -75
- package/esm/react.d.ts +42 -9
- package/esm/react.js +327 -91
- package/esm/server.d.ts +48 -7
- package/esm/server.js +3 -3
- package/esm/styles.css +142 -22
- package/esm/svelte/AssetViewer.svelte +25 -0
- package/esm/svelte/CalmLensAsset.svelte +318 -0
- package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
- package/esm/svelte/CalmLensImageViewer.svelte +7 -0
- package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
- package/esm/svelte/CalmLensTextViewer.svelte +7 -0
- package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
- package/esm/svelte/index.d.ts +29 -6
- package/esm/svelte/index.js +7 -2
- package/esm/test-inputs.d.ts +2 -2
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +29 -15
- package/esm/testing.js +1718 -429
- package/esm/ui-YQuvbidU.d.ts +139 -0
- package/esm/ui-heryDd6g.js +1258 -0
- package/esm/ui.d.ts +3 -2
- package/esm/ui.js +4 -3
- package/esm/vue.d.ts +802 -199
- package/esm/vue.js +308 -103
- package/package.json +4 -2
- package/cjs/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/cjs/index-DxbJ_Xaa.d.ts +0 -253
- package/cjs/ui-BSqPGKrZ.d.ts +0 -539
- package/cjs/ui-CX1z2pD9.js +0 -586
- package/esm/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/esm/index-DxbJ_Xaa.d.ts +0 -253
- package/esm/svelte/CalmLensMedia.svelte +0 -134
- package/esm/ui-BSqPGKrZ.d.ts +0 -539
- package/esm/ui-CXH7xJpb.js +0 -461
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_ModerationContextLimits = require("./ModerationContextLimits-
|
|
1
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-ud1xpZRK.js");
|
|
2
2
|
// src/contract/AssetPayload.js
|
|
3
3
|
const bufferInputToBytes = (value) => {
|
|
4
4
|
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
@@ -76,288 +76,18 @@ const validateAssetPayload = (payload, options) => {
|
|
|
76
76
|
};
|
|
77
77
|
return { ok: true };
|
|
78
78
|
};
|
|
79
|
-
// src/contract/Media.js
|
|
80
|
-
/** Limits shared with the media decoder. Oversized clips fail; they are never truncated. */
|
|
81
|
-
const MAX_MEDIA_UPLOAD_BYTES = 52428800;
|
|
82
|
-
const RETRY_MAX_DELAY_MS = 8e3;
|
|
83
|
-
const RETRYABLE_STATUSES = /* @__PURE__ */ new Set([
|
|
84
|
-
429,
|
|
85
|
-
502,
|
|
86
|
-
503,
|
|
87
|
-
504
|
|
88
|
-
]);
|
|
89
|
-
const timeoutReason = () => {
|
|
90
|
-
const reason = /* @__PURE__ */ new Error("The operation timed out.");
|
|
91
|
-
reason.name = "TimeoutError";
|
|
92
|
-
return reason;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Links the callers' signals and a per-attempt deadline. `AbortSignal.any` holds its sources
|
|
96
|
-
* weakly, so a long-lived caller signal doesn't collect a listener per streamed response;
|
|
97
|
-
* runtimes without it get explicit listeners that `release` removes.
|
|
98
|
-
*/
|
|
99
|
-
const createAttemptSignal = (signals, timeoutMs) => {
|
|
100
|
-
const callers = signals.filter((signal) => signal !== void 0);
|
|
101
|
-
const deadline = new AbortController();
|
|
102
|
-
let timedOut = false;
|
|
103
|
-
let signal;
|
|
104
|
-
let onAbort;
|
|
105
|
-
if (typeof AbortSignal.any === "function") signal = AbortSignal.any([...callers, deadline.signal]);
|
|
106
|
-
else {
|
|
107
|
-
const controller = new AbortController();
|
|
108
|
-
signal = controller.signal;
|
|
109
|
-
onAbort = (event) => controller.abort(event.target.reason);
|
|
110
|
-
for (const source of [...callers, deadline.signal]) if (source.aborted) controller.abort(source.reason);
|
|
111
|
-
else source.addEventListener("abort", onAbort, { once: true });
|
|
112
|
-
}
|
|
113
|
-
let timer = timeoutMs === void 0 ? void 0 : setTimeout(() => {
|
|
114
|
-
timedOut = true;
|
|
115
|
-
deadline.abort(timeoutReason());
|
|
116
|
-
}, timeoutMs);
|
|
117
|
-
return {
|
|
118
|
-
signal,
|
|
119
|
-
isTimedOut: () => timedOut,
|
|
120
|
-
isCancelled: () => callers.some((caller) => caller.aborted),
|
|
121
|
-
clearDeadline: () => {
|
|
122
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
123
|
-
timer = void 0;
|
|
124
|
-
},
|
|
125
|
-
release: () => {
|
|
126
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
127
|
-
timer = void 0;
|
|
128
|
-
if (onAbort) for (const caller of callers) caller.removeEventListener("abort", onAbort);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
};
|
|
79
|
+
// src/contract/Media-B2PMcUf7.js
|
|
132
80
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
81
|
+
* Limits shared with the media decoder. Oversized media fails; it is never truncated.
|
|
82
|
+
*
|
|
83
|
+
* A clip of up to `MAX_MEDIA_DURATION_SECONDS` and `MAX_MEDIA_UPLOAD_BYTES` is analysed in one
|
|
84
|
+
* pass, and these are also the limits of a free upload (made before billing is set up). With
|
|
85
|
+
* billing set up, longer media up to the long-media limits is analysed in sections. The media
|
|
86
|
+
* processor accepts up to an hour and 2 GiB, so these limits can grow to that without a new
|
|
87
|
+
* container image.
|
|
135
88
|
*/
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
const toFailure = (cause, attempt) => {
|
|
139
|
-
if (require_ModerationContextLimits.CalmLensError.isCalmLensError(cause)) return cause;
|
|
140
|
-
if (attempt.isCancelled()) return new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.CANCELLED, {
|
|
141
|
-
message: "Request cancelled",
|
|
142
|
-
cause
|
|
143
|
-
});
|
|
144
|
-
if (attempt.isTimedOut()) return new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.TIMEOUT, {
|
|
145
|
-
message: "Request timed out",
|
|
146
|
-
cause
|
|
147
|
-
});
|
|
148
|
-
return new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.TRANSPORT_ERROR, {
|
|
149
|
-
message: "Request failed",
|
|
150
|
-
cause
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
154
|
-
if (signal?.aborted) {
|
|
155
|
-
reject(new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const onAbort = () => {
|
|
159
|
-
clearTimeout(timer);
|
|
160
|
-
reject(new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
|
|
161
|
-
};
|
|
162
|
-
const timer = setTimeout(() => {
|
|
163
|
-
signal?.removeEventListener("abort", onAbort);
|
|
164
|
-
resolve();
|
|
165
|
-
}, ms);
|
|
166
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
167
|
-
});
|
|
168
|
-
/** Exponential backoff with jitter: half the delay is fixed, the other half random. */
|
|
169
|
-
const getRetryDelayMs = (attempt, random = Math.random) => {
|
|
170
|
-
const delay = Math.min(RETRY_MAX_DELAY_MS, 500 * 2 ** attempt);
|
|
171
|
-
return Math.round(delay / 2 + random() * (delay / 2));
|
|
172
|
-
};
|
|
173
|
-
/** Parses `Retry-After` as seconds or an HTTP date, in seconds from `now`. */
|
|
174
|
-
const parseRetryAfter = (value, now = Date.now()) => {
|
|
175
|
-
if (!value) return void 0;
|
|
176
|
-
const trimmed = value.trim();
|
|
177
|
-
if (/^\d+$/.test(trimmed)) return Number(trimmed);
|
|
178
|
-
const date = Date.parse(trimmed);
|
|
179
|
-
if (Number.isNaN(date)) return void 0;
|
|
180
|
-
return Math.max(0, Math.ceil((date - now) / 1e3));
|
|
181
|
-
};
|
|
182
|
-
/** Bodies that can be sent again unchanged. Streams are consumed by the first attempt. */
|
|
183
|
-
const isReplayableBody = (body) => body === void 0 || body === null || typeof body === "string" || body instanceof Blob || body instanceof ArrayBuffer || ArrayBuffer.isView(body) || body instanceof URLSearchParams;
|
|
184
|
-
const isApiErrorPayload = (value) => !!value && typeof value === "object" && typeof value.code === "string";
|
|
185
|
-
/** Reads at most `limit` bytes of a body, failing with `sdk/response-too-large` beyond that. */
|
|
186
|
-
const readBody = async (response, limit) => {
|
|
187
|
-
const declared = Number(response.headers.get("content-length"));
|
|
188
|
-
const tooLarge = () => new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.RESPONSE_TOO_LARGE, {
|
|
189
|
-
message: `Response body exceeds ${limit} bytes`,
|
|
190
|
-
status: response.status,
|
|
191
|
-
requestId: response.headers.get("x-request-id") ?? void 0,
|
|
192
|
-
headers: response.headers
|
|
193
|
-
});
|
|
194
|
-
if (Number.isFinite(declared) && declared > limit) {
|
|
195
|
-
await response.body?.cancel().catch(() => {});
|
|
196
|
-
throw tooLarge();
|
|
197
|
-
}
|
|
198
|
-
if (!response.body) return /* @__PURE__ */ new Uint8Array(0);
|
|
199
|
-
const reader = response.body.getReader();
|
|
200
|
-
const chunks = [];
|
|
201
|
-
let total = 0;
|
|
202
|
-
for (;;) {
|
|
203
|
-
const { done, value } = await reader.read();
|
|
204
|
-
if (done) break;
|
|
205
|
-
total += value.byteLength;
|
|
206
|
-
if (total > limit) {
|
|
207
|
-
await reader.cancel().catch(() => {});
|
|
208
|
-
throw tooLarge();
|
|
209
|
-
}
|
|
210
|
-
chunks.push(value);
|
|
211
|
-
}
|
|
212
|
-
const bytes = new Uint8Array(total);
|
|
213
|
-
let offset = 0;
|
|
214
|
-
for (const chunk of chunks) {
|
|
215
|
-
bytes.set(chunk, offset);
|
|
216
|
-
offset += chunk.byteLength;
|
|
217
|
-
}
|
|
218
|
-
return bytes;
|
|
219
|
-
};
|
|
220
|
-
const responseInfo = (response) => ({
|
|
221
|
-
status: response.status,
|
|
222
|
-
requestId: response.headers.get("x-request-id") ?? void 0,
|
|
223
|
-
headers: response.headers,
|
|
224
|
-
retryAfter: parseRetryAfter(response.headers.get("retry-after"))
|
|
225
|
-
});
|
|
226
|
-
/** The `CalmLensError` for a non-2xx response whose body has been read. */
|
|
227
|
-
const toHttpError = (response, bytes) => {
|
|
228
|
-
let data;
|
|
229
|
-
try {
|
|
230
|
-
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
231
|
-
} catch {}
|
|
232
|
-
if (isApiErrorPayload(data)) {
|
|
233
|
-
const { code, message, details, requestId } = data;
|
|
234
|
-
const info = responseInfo(response);
|
|
235
|
-
return new require_ModerationContextLimits.CalmLensError(code, {
|
|
236
|
-
message: message ?? code,
|
|
237
|
-
...info,
|
|
238
|
-
requestId: info.requestId ?? (typeof requestId === "string" ? requestId : void 0),
|
|
239
|
-
details
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
return new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.HTTP_ERROR, {
|
|
243
|
-
message: `HTTP ${response.status}`,
|
|
244
|
-
...responseInfo(response)
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
/** Sends requests with the client's credentials, deadlines, retries and response limits. */
|
|
248
|
-
var CalmLensTransport = class {
|
|
249
|
-
constructor(settings) {
|
|
250
|
-
this.settings = settings;
|
|
251
|
-
this.sleep = settings.sleep ?? sleep;
|
|
252
|
-
}
|
|
253
|
-
headersFor(request) {
|
|
254
|
-
const headers = new Headers(request.init?.headers);
|
|
255
|
-
for (const [name, value] of Object.entries(request.headers ?? {})) headers.set(name, value);
|
|
256
|
-
if (!headers.has("accept") && request.deadline === "body") headers.set("accept", "application/json");
|
|
257
|
-
if (this.settings.apiKey) headers.set("x-api-key", this.settings.apiKey);
|
|
258
|
-
if (!require_ModerationContextLimits.isBrowserRuntime()) headers.set("user-agent", require_ModerationContextLimits.getUserAgent());
|
|
259
|
-
if (request.idempotencyKey) headers.set("idempotency-key", request.idempotencyKey);
|
|
260
|
-
return Object.fromEntries(headers.entries());
|
|
261
|
-
}
|
|
262
|
-
canRetry(request) {
|
|
263
|
-
return this.settings.maxRetries > 0 && (request.method === "GET" || request.method === "HEAD" || !!request.idempotencyKey) && isReplayableBody(request.body);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Sends a request and returns the response, retrying transport failures, timeouts, 429, 502–504 and
|
|
267
|
-
* `idempotency/request-in-progress` when the request is safe to repeat. Non-2xx responses
|
|
268
|
-
* throw unless `allowHttpErrors` is set. Call `release` once the body has been read.
|
|
269
|
-
*/
|
|
270
|
-
async send(request, { allowHttpErrors = false } = {}) {
|
|
271
|
-
const fetchImpl = request.fetch ?? this.settings.fetch;
|
|
272
|
-
const retryable = this.canRetry(request);
|
|
273
|
-
const headers = this.headersFor(request);
|
|
274
|
-
for (let attemptNumber = 0;; attemptNumber++) {
|
|
275
|
-
const canRetryAgain = retryable && attemptNumber < this.settings.maxRetries;
|
|
276
|
-
const attempt = createAttemptSignal([this.settings.signal, request.init?.signal ?? void 0], request.timeoutMs);
|
|
277
|
-
let response;
|
|
278
|
-
try {
|
|
279
|
-
if (attempt.signal.aborted) throw attempt.signal.reason;
|
|
280
|
-
response = await fetchImpl(request.url, {
|
|
281
|
-
...request.init,
|
|
282
|
-
method: request.method,
|
|
283
|
-
headers,
|
|
284
|
-
body: request.body,
|
|
285
|
-
redirect: "manual",
|
|
286
|
-
signal: attempt.signal,
|
|
287
|
-
duplex: "half"
|
|
288
|
-
});
|
|
289
|
-
if (isRedirect(response)) {
|
|
290
|
-
await response.body?.cancel().catch(() => {});
|
|
291
|
-
throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.HTTP_ERROR, {
|
|
292
|
-
message: `Unexpected redirect (HTTP ${response.status})`,
|
|
293
|
-
...responseInfo(response),
|
|
294
|
-
status: response.status || void 0
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
} catch (cause) {
|
|
298
|
-
attempt.release();
|
|
299
|
-
const failure = toFailure(cause, attempt);
|
|
300
|
-
if (canRetryAgain && failure.isRetryable()) {
|
|
301
|
-
await this.sleep(getRetryDelayMs(attemptNumber), this.settings.signal);
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
throw failure;
|
|
305
|
-
}
|
|
306
|
-
if (request.deadline === "headers") attempt.clearDeadline();
|
|
307
|
-
if (response.ok) return {
|
|
308
|
-
response,
|
|
309
|
-
attempt
|
|
310
|
-
};
|
|
311
|
-
if (allowHttpErrors) {
|
|
312
|
-
const retryAfter = parseRetryAfter(response.headers.get("retry-after"));
|
|
313
|
-
const delayMs = retryAfter !== void 0 ? retryAfter * 1e3 : getRetryDelayMs(attemptNumber);
|
|
314
|
-
if (!canRetryAgain || !RETRYABLE_STATUSES.has(response.status) || delayMs > 6e4) return {
|
|
315
|
-
response,
|
|
316
|
-
attempt
|
|
317
|
-
};
|
|
318
|
-
attempt.release();
|
|
319
|
-
await response.body?.cancel().catch(() => {});
|
|
320
|
-
await this.sleep(delayMs, this.settings.signal);
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
let error;
|
|
324
|
-
try {
|
|
325
|
-
error = toHttpError(response, await readBody(response, this.settings.maxResponseBytes));
|
|
326
|
-
} catch (cause) {
|
|
327
|
-
error = toFailure(cause, attempt);
|
|
328
|
-
} finally {
|
|
329
|
-
attempt.release();
|
|
330
|
-
}
|
|
331
|
-
const retryDelayMs = error.retryAfter !== void 0 ? error.retryAfter * 1e3 : getRetryDelayMs(attemptNumber);
|
|
332
|
-
if (canRetryAgain && retryDelayMs <= 6e4 && error.isRetryable()) {
|
|
333
|
-
await this.sleep(retryDelayMs, this.settings.signal);
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
throw error;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
/** Sends a request and parses its JSON response body. */
|
|
340
|
-
async json(request) {
|
|
341
|
-
const { response, attempt } = await this.send(request);
|
|
342
|
-
try {
|
|
343
|
-
const bytes = await readBody(response, this.settings.maxResponseBytes);
|
|
344
|
-
if (bytes.byteLength === 0 && (response.status === 204 || request.method === "DELETE")) return;
|
|
345
|
-
try {
|
|
346
|
-
return JSON.parse(new TextDecoder().decode(bytes));
|
|
347
|
-
} catch (cause) {
|
|
348
|
-
throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
349
|
-
message: `Invalid JSON response (HTTP ${response.status})`,
|
|
350
|
-
...responseInfo(response),
|
|
351
|
-
cause
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
} catch (cause) {
|
|
355
|
-
throw toFailure(cause, attempt);
|
|
356
|
-
} finally {
|
|
357
|
-
attempt.release();
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
};
|
|
89
|
+
const MAX_MEDIA_UPLOAD_BYTES = 52428800;
|
|
90
|
+
const MAX_LONG_MEDIA_UPLOAD_BYTES = 2147483648;
|
|
361
91
|
/**
|
|
362
92
|
* Where `calmlens/testing` puts its hooks in client options. Not part of the public API:
|
|
363
93
|
* the mock clients run the real clients against their in-memory API with these.
|
|
@@ -405,23 +135,105 @@ const splitsIntoParts = (content, partSizeBytes) => {
|
|
|
405
135
|
* build a Blob from bytes, and every fetch accepts a Uint8Array.
|
|
406
136
|
*/
|
|
407
137
|
const toBodyBytes = (value) => value.buffer instanceof ArrayBuffer ? value : Uint8Array.from(value);
|
|
408
|
-
|
|
138
|
+
/** The bytes of an upload's content or part, as a Blob, bytes or a one-shot stream. */
|
|
139
|
+
const toUploadData = (payload) => {
|
|
409
140
|
const data = assetToData(payload);
|
|
410
141
|
if (data instanceof Response) {
|
|
411
142
|
if (!data.body) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Response upload data must have a body" });
|
|
412
143
|
return data.body;
|
|
413
144
|
}
|
|
414
|
-
if (data instanceof
|
|
145
|
+
if (data instanceof Blob) return data;
|
|
146
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
415
147
|
if ("getReader" in data) return data;
|
|
416
148
|
return toBodyBytes(data);
|
|
417
149
|
};
|
|
150
|
+
/** An upload's bytes as a raw part body (parts after the first carry no options). */
|
|
151
|
+
const toRawUploadBody = (payload) => toUploadData(payload);
|
|
152
|
+
const textEncoder = new TextEncoder();
|
|
153
|
+
/**
|
|
154
|
+
* An upload form: `multipart/form-data` with the asset's fields as the JSON `options` part, then
|
|
155
|
+
* the bytes as the `file` part. Asset fields never go in the URL, which proxies and servers log.
|
|
156
|
+
* Bytes stay bytes (React Native can't build a Blob from them), a Blob stays a Blob, and a stream
|
|
157
|
+
* is wrapped so the file is still sent as it is read.
|
|
158
|
+
*/
|
|
159
|
+
const toUploadForm = (options, payload) => {
|
|
160
|
+
const boundary = `calmlens-${require_ModerationContextLimits.randomUuid()}`;
|
|
161
|
+
const head = `--${boundary}\r\nContent-Disposition: form-data; name="options"\r\nContent-Type: application/json\r\n\r\n${JSON.stringify(options)}\r\n--${boundary}\r\nContent-Disposition: form-data; name="file"\r\nContent-Type: ${payload.type.replace(/[\r\n]/g, "")}\r\n\r\n`;
|
|
162
|
+
const tail = `\r\n--${boundary}--\r\n`;
|
|
163
|
+
const contentType = `multipart/form-data; boundary=${boundary}`;
|
|
164
|
+
const data = toUploadData(payload);
|
|
165
|
+
if (data instanceof Blob) return {
|
|
166
|
+
body: new Blob([
|
|
167
|
+
head,
|
|
168
|
+
data,
|
|
169
|
+
tail
|
|
170
|
+
]),
|
|
171
|
+
contentType
|
|
172
|
+
};
|
|
173
|
+
const headBytes = textEncoder.encode(head);
|
|
174
|
+
const tailBytes = textEncoder.encode(tail);
|
|
175
|
+
if (data instanceof Uint8Array) {
|
|
176
|
+
const body = new Uint8Array(headBytes.length + data.length + tailBytes.length);
|
|
177
|
+
body.set(headBytes);
|
|
178
|
+
body.set(data, headBytes.length);
|
|
179
|
+
body.set(tailBytes, headBytes.length + data.length);
|
|
180
|
+
return {
|
|
181
|
+
body,
|
|
182
|
+
contentType
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const reader = data.getReader();
|
|
186
|
+
let stage = "head";
|
|
187
|
+
return {
|
|
188
|
+
body: new ReadableStream({
|
|
189
|
+
async pull(controller) {
|
|
190
|
+
if (stage === "head") {
|
|
191
|
+
stage = "file";
|
|
192
|
+
controller.enqueue(headBytes);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (stage === "done") return;
|
|
196
|
+
const { done, value } = await reader.read();
|
|
197
|
+
if (!done) {
|
|
198
|
+
if (value.byteLength) controller.enqueue(value);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
stage = "done";
|
|
202
|
+
controller.enqueue(tailBytes);
|
|
203
|
+
controller.close();
|
|
204
|
+
},
|
|
205
|
+
cancel: (reason) => reader.cancel(reason)
|
|
206
|
+
}),
|
|
207
|
+
contentType
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
/** The options an upload sends, without the transport ones and without empty values. */
|
|
211
|
+
const uploadFields = (options) => Object.fromEntries(UPLOAD_OPTION_KEYS.flatMap((key) => options[key] === void 0 || options[key] === null ? [] : [[key, options[key]]]));
|
|
212
|
+
/** The asset fields an upload carries in its body: the API refuses them in the query string. */
|
|
213
|
+
const UPLOAD_OPTION_KEYS = [
|
|
214
|
+
"name",
|
|
215
|
+
"description",
|
|
216
|
+
"processingOptions",
|
|
217
|
+
"visibility",
|
|
218
|
+
"metadata",
|
|
219
|
+
"tags",
|
|
220
|
+
"authorId",
|
|
221
|
+
"context",
|
|
222
|
+
"externalId",
|
|
223
|
+
"externalUrl",
|
|
224
|
+
"folderId",
|
|
225
|
+
"uploadPresetId"
|
|
226
|
+
];
|
|
418
227
|
const setOptionalQueryValue = (params, key, value) => {
|
|
419
|
-
if (value !== void 0 && value !== null) params.set(key,
|
|
228
|
+
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
420
229
|
};
|
|
421
230
|
const assertValidUploadMimeType = (mimeType) => {
|
|
422
|
-
if (!require_ModerationContextLimits.isAcceptedUploadMimeType(mimeType)) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.
|
|
231
|
+
if (!require_ModerationContextLimits.isAcceptedUploadMimeType(mimeType)) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, {
|
|
423
232
|
message: require_ModerationContextLimits.getRejectedUploadMimeTypeError(mimeType),
|
|
424
|
-
details: {
|
|
233
|
+
details: {
|
|
234
|
+
mimeType,
|
|
235
|
+
source: "calmlens"
|
|
236
|
+
}
|
|
425
237
|
});
|
|
426
238
|
};
|
|
427
239
|
const isImageMimeType = (mimeType) => mimeType.toLowerCase().startsWith("image/");
|
|
@@ -433,16 +245,23 @@ const assertDeclaredPayloadSize = (payload, declared = payload.sizeInBytes) => {
|
|
|
433
245
|
if (!Number.isSafeInteger(declared) || declared < 0 || measured !== void 0 && measured !== declared) throw invalidPayload("sizeInBytes must match the payload byte length");
|
|
434
246
|
};
|
|
435
247
|
/**
|
|
436
|
-
* Refuses
|
|
437
|
-
*
|
|
438
|
-
*
|
|
248
|
+
* Refuses content whose known size is over the API's limit for its type, so nothing is sent and
|
|
249
|
+
* an oversized file fails at once instead of after its upload. In one request, images can be up
|
|
250
|
+
* to 10 MiB (larger ones are uploaded in parts), audio and video up to 50 MiB and other files up
|
|
251
|
+
* to 5,000 MiB. Sent in parts (`inParts`), audio and video can be up to 2 GiB; the API holds free
|
|
252
|
+
* uploads, made before billing is set up, to 50 MiB itself. Images in parts are checked apart.
|
|
439
253
|
*/
|
|
440
|
-
const
|
|
441
|
-
const size = content.sizeInBytes ?? getAssetPayloadByteLength(content);
|
|
254
|
+
const assertUploadSize = (type, size, inParts) => {
|
|
442
255
|
if (size === void 0) return;
|
|
443
|
-
const
|
|
444
|
-
const [limit, message] =
|
|
445
|
-
if (size > limit) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.
|
|
256
|
+
const mime = type.toLowerCase();
|
|
257
|
+
const [limit, message] = mime.startsWith("image/") ? [require_ModerationContextLimits.MAX_DIRECT_IMAGE_UPLOAD_BYTES, "Images uploaded in one request can be at most 10 MiB; upload larger images in parts"] : mime.startsWith("audio/") || mime.startsWith("video/") ? [inParts ? MAX_LONG_MEDIA_UPLOAD_BYTES : MAX_MEDIA_UPLOAD_BYTES, "Audio and video files can be at most 50 MiB in one request, or 2 GiB in parts"] : [require_ModerationContextLimits.MAX_NON_IMAGE_UPLOAD_BYTES, "Files can be at most 5,000 MiB"];
|
|
258
|
+
if (size > limit) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
259
|
+
message,
|
|
260
|
+
details: {
|
|
261
|
+
limitBytes: limit,
|
|
262
|
+
source: "plan"
|
|
263
|
+
}
|
|
264
|
+
});
|
|
446
265
|
};
|
|
447
266
|
/** Checks upload options before anything is sent. */
|
|
448
267
|
const prepareSubmitAssetOptions = (options, { deferUploadChecks = false, partSizeBytes = DEFAULT_PART_SIZE_BYTES } = {}) => {
|
|
@@ -457,8 +276,14 @@ const prepareSubmitAssetOptions = (options, { deferUploadChecks = false, partSiz
|
|
|
457
276
|
const inParts = splitsIntoParts(options.content, partSizeBytes);
|
|
458
277
|
if (inParts && (options.idempotencyKey?.length ?? 0) > 240) throw require_ModerationContextLimits.invalidArgument(`idempotencyKey can be at most 240 characters for an upload sent in parts`);
|
|
459
278
|
if (!deferUploadChecks && inParts && isImageMimeType(options.content.type)) {
|
|
460
|
-
if ((getAssetPayloadByteLength(options.content) ?? 0) > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.
|
|
461
|
-
|
|
279
|
+
if ((getAssetPayloadByteLength(options.content) ?? 0) > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
280
|
+
message: "Multipart image uploads cannot exceed 20 MiB.",
|
|
281
|
+
details: {
|
|
282
|
+
limitBytes: require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES,
|
|
283
|
+
source: "plan"
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
} else if (!deferUploadChecks) assertUploadSize(options.content.type, options.content.sizeInBytes ?? getAssetPayloadByteLength(options.content), inParts);
|
|
462
287
|
if (!("plainText" in options.content)) {
|
|
463
288
|
const validation = validateAssetPayload(options.content);
|
|
464
289
|
if (!validation.ok) throw invalidPayload(validation.error);
|
|
@@ -469,8 +294,15 @@ const prepareSubmitAssetOptions = (options, { deferUploadChecks = false, partSiz
|
|
|
469
294
|
assertValidUploadMimeType(options.part.type);
|
|
470
295
|
const partSizeInBytes = options.part.sizeInBytes ?? getAssetPayloadByteLength(options.part);
|
|
471
296
|
if (!deferUploadChecks && isImageMimeType(options.part.type) && partSizeInBytes !== void 0) {
|
|
472
|
-
if (partSizeInBytes > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.
|
|
297
|
+
if (partSizeInBytes > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
298
|
+
message: "Multipart image uploads cannot exceed 20 MiB.",
|
|
299
|
+
details: {
|
|
300
|
+
limitBytes: require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES,
|
|
301
|
+
source: "plan"
|
|
302
|
+
}
|
|
303
|
+
});
|
|
473
304
|
}
|
|
305
|
+
if (!deferUploadChecks && !isImageMimeType(options.part.type)) assertUploadSize(options.part.type, options.totalSizeInBytes, true);
|
|
474
306
|
const validation = validateAssetPayload(options.part, {
|
|
475
307
|
multipart: true,
|
|
476
308
|
isFinal: deferUploadChecks || options.part.isFinal
|
|
@@ -491,7 +323,7 @@ const newIdempotencyKey = () => require_ModerationContextLimits.randomUuid();
|
|
|
491
323
|
const isTextPayload = (payload) => "plainText" in payload;
|
|
492
324
|
const hasStringStatus = (value) => !!value && typeof value === "object" && typeof value.status === "string";
|
|
493
325
|
const isAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id && hasStringStatus(data.classification) && hasStringStatus(data.upload) && typeof data.classification?.moderation?.status === "string";
|
|
494
|
-
const isUploadedAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id;
|
|
326
|
+
const isUploadedAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id && hasStringStatus(data.classification) && hasStringStatus(data.upload);
|
|
495
327
|
const expectUploadedAsset = (data) => {
|
|
496
328
|
if (!isUploadedAsset(data)) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
497
329
|
message: "Expected an uploaded asset response",
|
|
@@ -521,7 +353,7 @@ var CalmLensConnection = class {
|
|
|
521
353
|
return fetchImpl;
|
|
522
354
|
};
|
|
523
355
|
this.hooks = getMockHooks(options);
|
|
524
|
-
this.transport = new CalmLensTransport({
|
|
356
|
+
this.transport = new require_ModerationContextLimits.CalmLensTransport({
|
|
525
357
|
apiKey,
|
|
526
358
|
sleep: this.hooks?.sleep,
|
|
527
359
|
fetch: ((input, init) => resolveFetch()(input, init)),
|
|
@@ -532,7 +364,7 @@ var CalmLensConnection = class {
|
|
|
532
364
|
}
|
|
533
365
|
/** How the client waits between polls and retries. */
|
|
534
366
|
get sleep() {
|
|
535
|
-
return this.hooks?.sleep ?? sleep;
|
|
367
|
+
return this.hooks?.sleep ?? require_ModerationContextLimits.sleep;
|
|
536
368
|
}
|
|
537
369
|
/** Whether multipart size checks are left to the API (mock clients only). */
|
|
538
370
|
get deferUploadChecks() {
|
|
@@ -560,53 +392,62 @@ var CalmLensConnection = class {
|
|
|
560
392
|
deadline: "body"
|
|
561
393
|
});
|
|
562
394
|
}
|
|
563
|
-
upload(url,
|
|
395
|
+
upload(url, body, headers, idempotencyKey, text) {
|
|
564
396
|
return this.transport.json({
|
|
565
397
|
method: "POST",
|
|
566
398
|
url,
|
|
567
399
|
headers,
|
|
568
|
-
body
|
|
400
|
+
body,
|
|
569
401
|
idempotencyKey,
|
|
570
|
-
timeoutMs:
|
|
402
|
+
timeoutMs: text ? this.timeoutMs : this.options.uploadTimeoutMs,
|
|
571
403
|
deadline: "body",
|
|
572
404
|
fetch: this.options.uploadFetch
|
|
573
405
|
});
|
|
574
406
|
}
|
|
575
407
|
/**
|
|
576
|
-
* Uploads file content or a first multipart part to `uploadsPath` (`.../assets`)
|
|
577
|
-
*
|
|
408
|
+
* Uploads file content or a first multipart part to `uploadsPath` (`.../assets`). Plain text
|
|
409
|
+
* goes as a JSON body; other content as an upload form, the asset's fields in its options part
|
|
410
|
+
* and the bytes in its file part. Either way the query holds only transport values.
|
|
578
411
|
*/
|
|
579
|
-
|
|
580
|
-
const query = new URLSearchParams();
|
|
581
|
-
query.set("name", options.name);
|
|
582
|
-
query.set("queue", String(queue));
|
|
583
|
-
setOptionalQueryValue(query, "description", options.description);
|
|
584
|
-
setOptionalQueryValue(query, "processingOptions", options.processingOptions);
|
|
585
|
-
setOptionalQueryValue(query, "visibility", options.visibility);
|
|
586
|
-
setOptionalQueryValue(query, "metadata", options.metadata);
|
|
587
|
-
setOptionalQueryValue(query, "authorId", options.authorId);
|
|
588
|
-
setOptionalQueryValue(query, "context", options.context);
|
|
589
|
-
setOptionalQueryValue(query, "externalId", options.externalId);
|
|
590
|
-
setOptionalQueryValue(query, "externalUrl", options.externalUrl);
|
|
591
|
-
setOptionalQueryValue(query, "folderId", options.folderId);
|
|
592
|
-
setOptionalQueryValue(query, "uploadPresetId", options.uploadPresetId);
|
|
412
|
+
submitUpload(uploadsPath, options, wait, authHeaders = {}) {
|
|
593
413
|
const isMultipart = "part" in options;
|
|
594
414
|
const payload = isMultipart ? options.part : options.content;
|
|
415
|
+
const multipartOptions = options;
|
|
416
|
+
const idempotencyKey = options.idempotencyKey ?? newIdempotencyKey();
|
|
417
|
+
const fields = uploadFields(options);
|
|
418
|
+
if (isTextPayload(payload)) {
|
|
419
|
+
const { sizeInBytes: _size, ...text } = payload;
|
|
420
|
+
const body = isMultipart ? {
|
|
421
|
+
...fields,
|
|
422
|
+
part: text,
|
|
423
|
+
...multipartOptions.sizeInBytes === void 0 ? {} : { sizeInBytes: multipartOptions.sizeInBytes },
|
|
424
|
+
...multipartOptions.totalSizeInBytes === void 0 ? {} : { totalSizeInBytes: multipartOptions.totalSizeInBytes }
|
|
425
|
+
} : {
|
|
426
|
+
...fields,
|
|
427
|
+
content: text
|
|
428
|
+
};
|
|
429
|
+
return this.upload(this.url(uploadsPath, { wait }), JSON.stringify(body), {
|
|
430
|
+
...authHeaders,
|
|
431
|
+
"Content-Type": "application/json"
|
|
432
|
+
}, idempotencyKey, true);
|
|
433
|
+
}
|
|
434
|
+
const query = new URLSearchParams();
|
|
435
|
+
query.set("wait", String(wait));
|
|
595
436
|
query.set("contentType", payload.type);
|
|
596
437
|
setOptionalQueryValue(query, "sizeInBytes", payload.sizeInBytes ?? getAssetPayloadByteLength(payload));
|
|
597
438
|
if (isMultipart) {
|
|
598
439
|
const part = payload;
|
|
599
|
-
const multipartOptions = options;
|
|
600
440
|
query.set("partNumber", String(part.partNumber ?? 1));
|
|
601
441
|
query.set("isFinal", String(part.isFinal ?? false));
|
|
602
442
|
setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? multipartOptions.sizeInBytes);
|
|
603
443
|
setOptionalQueryValue(query, "totalSizeInBytes", multipartOptions.totalSizeInBytes);
|
|
604
444
|
}
|
|
605
|
-
|
|
445
|
+
const form = toUploadForm(fields, payload);
|
|
446
|
+
return this.upload(this.url(`${uploadsPath}?${query}`), form.body, {
|
|
606
447
|
...authHeaders,
|
|
607
|
-
"Content-Type":
|
|
448
|
+
"Content-Type": form.contentType,
|
|
608
449
|
"X-CalmLens-Upload": isMultipart ? "part" : "content"
|
|
609
|
-
},
|
|
450
|
+
}, idempotencyKey, false);
|
|
610
451
|
}
|
|
611
452
|
/** Content larger than this is uploaded in parts. */
|
|
612
453
|
get partSizeBytes() {
|
|
@@ -619,14 +460,14 @@ var CalmLensConnection = class {
|
|
|
619
460
|
* upload. A part the API already has is skipped, and a final part that finds the upload already
|
|
620
461
|
* completed reads it back with `retrieve`.
|
|
621
462
|
*/
|
|
622
|
-
async submitInParts(uploadsPath, options,
|
|
463
|
+
async submitInParts(uploadsPath, options, wait, { authHeaders = {}, partPath, onStarted, retrieve }) {
|
|
623
464
|
const { content, idempotencyKey, ...fields } = options;
|
|
624
465
|
const source = getSplittableContent(content);
|
|
625
466
|
const partSize = this.partSizeBytes;
|
|
626
467
|
const count = Math.ceil(source.size / partSize);
|
|
627
468
|
const key = idempotencyKey ?? newIdempotencyKey();
|
|
628
469
|
const part = (partNumber) => source.slice((partNumber - 1) * partSize, Math.min(partNumber * partSize, source.size));
|
|
629
|
-
const first = await this.
|
|
470
|
+
const first = await this.submitUpload(uploadsPath, {
|
|
630
471
|
...fields,
|
|
631
472
|
part: {
|
|
632
473
|
...part(1),
|
|
@@ -636,7 +477,7 @@ var CalmLensConnection = class {
|
|
|
636
477
|
},
|
|
637
478
|
totalSizeInBytes: source.size,
|
|
638
479
|
idempotencyKey: key
|
|
639
|
-
},
|
|
480
|
+
}, wait, authHeaders);
|
|
640
481
|
const assetId = expectUploadedAsset(first).id;
|
|
641
482
|
onStarted?.(assetId);
|
|
642
483
|
let result = first;
|
|
@@ -666,7 +507,7 @@ var CalmLensConnection = class {
|
|
|
666
507
|
return result;
|
|
667
508
|
}
|
|
668
509
|
/** Uploads the next part of a multipart upload to `partPath` (`.../assets/{id}/part`). */
|
|
669
|
-
uploadPart(partPath, { part,
|
|
510
|
+
uploadPart(partPath, { part, wait, idempotencyKey }, authHeaders = {}) {
|
|
670
511
|
if (!part) throw require_ModerationContextLimits.invalidArgument("Part options are required");
|
|
671
512
|
assertDeclaredPayloadSize(part);
|
|
672
513
|
const validation = validateAssetPayload(part, {
|
|
@@ -678,12 +519,12 @@ var CalmLensConnection = class {
|
|
|
678
519
|
partNumber: String(part.partNumber),
|
|
679
520
|
isFinal: String(part.isFinal ?? false)
|
|
680
521
|
});
|
|
681
|
-
if (
|
|
522
|
+
if (wait !== void 0) query.set("wait", String(wait));
|
|
682
523
|
setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? getAssetPayloadByteLength(part));
|
|
683
|
-
return this.upload(this.url(`${partPath}?${query}`), part, {
|
|
524
|
+
return this.upload(this.url(`${partPath}?${query}`), toRawUploadBody(part), {
|
|
684
525
|
...authHeaders,
|
|
685
526
|
"X-CalmLens-Upload": "part"
|
|
686
|
-
}, idempotencyKey ?? newIdempotencyKey());
|
|
527
|
+
}, idempotencyKey ?? newIdempotencyKey(), isTextPayload(part));
|
|
687
528
|
}
|
|
688
529
|
};
|
|
689
530
|
// src/client/CalmLensOptionKeys.ts
|
|
@@ -704,6 +545,7 @@ const SERVER_OPTION_KEYS = {
|
|
|
704
545
|
"part",
|
|
705
546
|
"processingOptions",
|
|
706
547
|
"sizeInBytes",
|
|
548
|
+
"tags",
|
|
707
549
|
"totalSizeInBytes",
|
|
708
550
|
"uploadPresetId",
|
|
709
551
|
"url",
|
|
@@ -723,19 +565,12 @@ const SERVER_OPTION_KEYS = {
|
|
|
723
565
|
"part",
|
|
724
566
|
"processingOptions",
|
|
725
567
|
"sizeInBytes",
|
|
568
|
+
"tags",
|
|
726
569
|
"totalSizeInBytes",
|
|
727
570
|
"uploadPresetId",
|
|
728
571
|
"url",
|
|
729
572
|
"visibility"
|
|
730
573
|
],
|
|
731
|
-
"assets.createSignedUrl": [
|
|
732
|
-
"assetId",
|
|
733
|
-
"expiresInSeconds",
|
|
734
|
-
"lens",
|
|
735
|
-
"resource",
|
|
736
|
-
"transform",
|
|
737
|
-
"viewerClaims"
|
|
738
|
-
],
|
|
739
574
|
"assets.decide": [
|
|
740
575
|
"assetId",
|
|
741
576
|
"confirmPurge",
|
|
@@ -743,40 +578,48 @@ const SERVER_OPTION_KEYS = {
|
|
|
743
578
|
"note"
|
|
744
579
|
],
|
|
745
580
|
"assets.delete": ["assetId"],
|
|
746
|
-
"assets.deleteContent": ["assetId"],
|
|
747
581
|
"assets.explain": ["assetId", "rerun"],
|
|
748
582
|
"assets.iterate": [
|
|
749
583
|
"cursor",
|
|
750
584
|
"filter",
|
|
751
|
-
"
|
|
752
|
-
"
|
|
753
|
-
"pageSize"
|
|
585
|
+
"pageSize",
|
|
586
|
+
"sort"
|
|
754
587
|
],
|
|
755
588
|
"assets.iterateChildren": [
|
|
756
589
|
"assetId",
|
|
757
590
|
"cursor",
|
|
758
|
-
"
|
|
591
|
+
"pageSize",
|
|
592
|
+
"sort"
|
|
593
|
+
],
|
|
594
|
+
"assets.iterateTimeline": [
|
|
595
|
+
"assetId",
|
|
596
|
+
"cursor",
|
|
759
597
|
"pageSize"
|
|
760
598
|
],
|
|
761
599
|
"assets.list": [
|
|
762
600
|
"cursor",
|
|
763
601
|
"filter",
|
|
764
|
-
"
|
|
765
|
-
"
|
|
766
|
-
"pageSize"
|
|
602
|
+
"pageSize",
|
|
603
|
+
"sort"
|
|
767
604
|
],
|
|
768
605
|
"assets.listChildren": [
|
|
769
606
|
"assetId",
|
|
770
607
|
"cursor",
|
|
771
|
-
"
|
|
608
|
+
"pageSize",
|
|
609
|
+
"sort"
|
|
610
|
+
],
|
|
611
|
+
"assets.listTimeline": [
|
|
612
|
+
"assetId",
|
|
613
|
+
"cursor",
|
|
772
614
|
"pageSize"
|
|
773
615
|
],
|
|
774
616
|
"assets.move": ["assetId", "folderId"],
|
|
617
|
+
"assets.removeContent": ["assetId"],
|
|
775
618
|
"assets.retrieve": ["assetId"],
|
|
776
619
|
"assets.retry": ["assetId"],
|
|
777
620
|
"assets.search": [
|
|
778
|
-
"limit",
|
|
779
621
|
"mode",
|
|
622
|
+
"pageSize",
|
|
780
623
|
"query"
|
|
781
624
|
],
|
|
782
625
|
"assets.update": [
|
|
@@ -792,7 +635,18 @@ const SERVER_OPTION_KEYS = {
|
|
|
792
635
|
"assets.uploadPart": [
|
|
793
636
|
"assetId",
|
|
794
637
|
"part",
|
|
795
|
-
"
|
|
638
|
+
"wait"
|
|
639
|
+
],
|
|
640
|
+
"cdn.signAssetUrl": [
|
|
641
|
+
"assetId",
|
|
642
|
+
"expiresIn",
|
|
643
|
+
"externalId",
|
|
644
|
+
"lens",
|
|
645
|
+
"original",
|
|
646
|
+
"projectId",
|
|
647
|
+
"resource",
|
|
648
|
+
"transform",
|
|
649
|
+
"viewerClaims"
|
|
796
650
|
],
|
|
797
651
|
"ensureLens": [
|
|
798
652
|
"active",
|
|
@@ -800,20 +654,36 @@ const SERVER_OPTION_KEYS = {
|
|
|
800
654
|
"identifier",
|
|
801
655
|
"name",
|
|
802
656
|
"transform",
|
|
803
|
-
"type"
|
|
804
|
-
"version"
|
|
657
|
+
"type"
|
|
805
658
|
],
|
|
806
659
|
"ensureLenses": ["lenses"],
|
|
807
|
-
"events.list": [
|
|
808
|
-
|
|
660
|
+
"events.list": [
|
|
661
|
+
"assetId",
|
|
662
|
+
"cursor",
|
|
663
|
+
"pageSize",
|
|
664
|
+
"types"
|
|
665
|
+
],
|
|
666
|
+
"events.pages": [
|
|
667
|
+
"assetId",
|
|
668
|
+
"cursor",
|
|
669
|
+
"pageSize",
|
|
670
|
+
"types"
|
|
671
|
+
],
|
|
809
672
|
"folders.create": ["name", "parentId"],
|
|
810
673
|
"folders.delete": ["folderId"],
|
|
674
|
+
"folders.iterate": [
|
|
675
|
+
"cursor",
|
|
676
|
+
"pageSize",
|
|
677
|
+
"parentId",
|
|
678
|
+
"search",
|
|
679
|
+
"sort"
|
|
680
|
+
],
|
|
811
681
|
"folders.list": [
|
|
812
682
|
"cursor",
|
|
813
|
-
"ordering",
|
|
814
683
|
"pageSize",
|
|
815
684
|
"parentId",
|
|
816
|
-
"search"
|
|
685
|
+
"search",
|
|
686
|
+
"sort"
|
|
817
687
|
],
|
|
818
688
|
"folders.move": ["folderId", "parentId"],
|
|
819
689
|
"folders.retrieve": ["folderId"],
|
|
@@ -831,16 +701,27 @@ const SERVER_OPTION_KEYS = {
|
|
|
831
701
|
"name"
|
|
832
702
|
],
|
|
833
703
|
"hashLists.delete": ["hashListId"],
|
|
704
|
+
"hashLists.iterate": [
|
|
705
|
+
"cursor",
|
|
706
|
+
"pageSize",
|
|
707
|
+
"sort"
|
|
708
|
+
],
|
|
709
|
+
"hashLists.iterateEntries": [
|
|
710
|
+
"cursor",
|
|
711
|
+
"hashListId",
|
|
712
|
+
"pageSize",
|
|
713
|
+
"sort"
|
|
714
|
+
],
|
|
834
715
|
"hashLists.list": [
|
|
835
716
|
"cursor",
|
|
836
|
-
"
|
|
837
|
-
"
|
|
717
|
+
"pageSize",
|
|
718
|
+
"sort"
|
|
838
719
|
],
|
|
839
720
|
"hashLists.listEntries": [
|
|
840
721
|
"cursor",
|
|
841
722
|
"hashListId",
|
|
842
|
-
"
|
|
843
|
-
"
|
|
723
|
+
"pageSize",
|
|
724
|
+
"sort"
|
|
844
725
|
],
|
|
845
726
|
"hashLists.removeEntry": ["entryId"],
|
|
846
727
|
"hashLists.retrieve": ["hashListId"],
|
|
@@ -850,12 +731,37 @@ const SERVER_OPTION_KEYS = {
|
|
|
850
731
|
"hashListId",
|
|
851
732
|
"name"
|
|
852
733
|
],
|
|
853
|
-
"
|
|
854
|
-
"
|
|
855
|
-
"
|
|
856
|
-
"
|
|
857
|
-
"
|
|
734
|
+
"lenses.create": [
|
|
735
|
+
"active",
|
|
736
|
+
"description",
|
|
737
|
+
"identifier",
|
|
738
|
+
"name",
|
|
739
|
+
"transform",
|
|
740
|
+
"type"
|
|
741
|
+
],
|
|
742
|
+
"lenses.delete": ["lensId"],
|
|
743
|
+
"lenses.iterate": [
|
|
744
|
+
"cursor",
|
|
745
|
+
"pageSize",
|
|
746
|
+
"sort"
|
|
747
|
+
],
|
|
748
|
+
"lenses.list": [
|
|
749
|
+
"cursor",
|
|
750
|
+
"pageSize",
|
|
751
|
+
"sort"
|
|
752
|
+
],
|
|
753
|
+
"lenses.retrieve": ["lensId"],
|
|
754
|
+
"lenses.update": [
|
|
755
|
+
"active",
|
|
756
|
+
"description",
|
|
757
|
+
"lensId",
|
|
758
|
+
"name",
|
|
759
|
+
"transform",
|
|
760
|
+
"type"
|
|
858
761
|
],
|
|
762
|
+
"metadataFields.delete": ["fieldId", "revision"],
|
|
763
|
+
"metadataFields.ensure": ["fields", "revision"],
|
|
764
|
+
"metadataFields.list": [],
|
|
859
765
|
"policies.assign": ["policyId"],
|
|
860
766
|
"policies.create": [
|
|
861
767
|
"description",
|
|
@@ -864,8 +770,23 @@ const SERVER_OPTION_KEYS = {
|
|
|
864
770
|
"settings"
|
|
865
771
|
],
|
|
866
772
|
"policies.delete": ["policyId"],
|
|
867
|
-
"policies.
|
|
773
|
+
"policies.iterate": [
|
|
774
|
+
"cursor",
|
|
775
|
+
"pageSize",
|
|
776
|
+
"sort"
|
|
777
|
+
],
|
|
778
|
+
"policies.list": [
|
|
779
|
+
"cursor",
|
|
780
|
+
"pageSize",
|
|
781
|
+
"sort"
|
|
782
|
+
],
|
|
783
|
+
"policies.reset": [
|
|
784
|
+
"policyId",
|
|
785
|
+
"presetVersion",
|
|
786
|
+
"revision"
|
|
787
|
+
],
|
|
868
788
|
"policies.retrieve": ["policyId"],
|
|
789
|
+
"policies.retrieveAssigned": [],
|
|
869
790
|
"policies.setAutomaticUpdates": [
|
|
870
791
|
"enabled",
|
|
871
792
|
"policyId",
|
|
@@ -879,6 +800,17 @@ const SERVER_OPTION_KEYS = {
|
|
|
879
800
|
"revision",
|
|
880
801
|
"settings"
|
|
881
802
|
],
|
|
803
|
+
"policies.upgrade": [
|
|
804
|
+
"policyId",
|
|
805
|
+
"presetVersion",
|
|
806
|
+
"revision"
|
|
807
|
+
],
|
|
808
|
+
"projectSettings.get": [],
|
|
809
|
+
"projectSettings.update": [
|
|
810
|
+
"revision",
|
|
811
|
+
"searchIndexingBudgetUnits",
|
|
812
|
+
"settings"
|
|
813
|
+
],
|
|
882
814
|
"text.classify": [
|
|
883
815
|
"authorId",
|
|
884
816
|
"context",
|
|
@@ -889,9 +821,22 @@ const SERVER_OPTION_KEYS = {
|
|
|
889
821
|
"metadata",
|
|
890
822
|
"name",
|
|
891
823
|
"processingOptions",
|
|
824
|
+
"tags",
|
|
892
825
|
"text",
|
|
893
826
|
"uploadPresetId",
|
|
894
827
|
"visibility"
|
|
828
|
+
],
|
|
829
|
+
"uploadPresets.delete": ["uploadPresetId"],
|
|
830
|
+
"uploadPresets.ensure": ["uploadPresets"],
|
|
831
|
+
"uploadPresets.iterate": [
|
|
832
|
+
"cursor",
|
|
833
|
+
"pageSize",
|
|
834
|
+
"sort"
|
|
835
|
+
],
|
|
836
|
+
"uploadPresets.list": [
|
|
837
|
+
"cursor",
|
|
838
|
+
"pageSize",
|
|
839
|
+
"sort"
|
|
895
840
|
]
|
|
896
841
|
};
|
|
897
842
|
/** The option keys each `CalmLensAppClient` method sends to the API. */
|
|
@@ -918,7 +863,7 @@ const APP_OPTION_KEYS = {
|
|
|
918
863
|
"assets.uploadPart": [
|
|
919
864
|
"assetId",
|
|
920
865
|
"part",
|
|
921
|
-
"
|
|
866
|
+
"wait"
|
|
922
867
|
]
|
|
923
868
|
};
|
|
924
869
|
/**
|
|
@@ -934,6 +879,7 @@ const NULLABLE_OPTION_KEYS = {
|
|
|
934
879
|
"folderId",
|
|
935
880
|
"metadata",
|
|
936
881
|
"processingOptions",
|
|
882
|
+
"tags",
|
|
937
883
|
"uploadPresetId",
|
|
938
884
|
"visibility"
|
|
939
885
|
],
|
|
@@ -945,11 +891,12 @@ const NULLABLE_OPTION_KEYS = {
|
|
|
945
891
|
"folderId",
|
|
946
892
|
"metadata",
|
|
947
893
|
"processingOptions",
|
|
894
|
+
"tags",
|
|
948
895
|
"uploadPresetId",
|
|
949
896
|
"visibility"
|
|
950
897
|
],
|
|
951
|
-
"assets.iterate": ["filter"
|
|
952
|
-
"assets.list": ["filter"
|
|
898
|
+
"assets.iterate": ["filter"],
|
|
899
|
+
"assets.list": ["filter"],
|
|
953
900
|
"assets.move": ["folderId"],
|
|
954
901
|
"assets.update": [
|
|
955
902
|
"description",
|
|
@@ -964,6 +911,8 @@ const NULLABLE_OPTION_KEYS = {
|
|
|
964
911
|
"hashLists.addEntry": ["label", "quality"],
|
|
965
912
|
"hashLists.create": ["description"],
|
|
966
913
|
"hashLists.update": ["description"],
|
|
914
|
+
"lenses.create": ["description", "transform"],
|
|
915
|
+
"lenses.update": ["description", "transform"],
|
|
967
916
|
"text.classify": [
|
|
968
917
|
"authorId",
|
|
969
918
|
"context",
|
|
@@ -972,6 +921,7 @@ const NULLABLE_OPTION_KEYS = {
|
|
|
972
921
|
"folderId",
|
|
973
922
|
"metadata",
|
|
974
923
|
"processingOptions",
|
|
924
|
+
"tags",
|
|
975
925
|
"uploadPresetId",
|
|
976
926
|
"visibility"
|
|
977
927
|
]
|
|
@@ -1060,12 +1010,6 @@ Object.defineProperty(exports, "resolveConnectionOptions", {
|
|
|
1060
1010
|
return resolveConnectionOptions;
|
|
1061
1011
|
}
|
|
1062
1012
|
});
|
|
1063
|
-
Object.defineProperty(exports, "sleep", {
|
|
1064
|
-
enumerable: true,
|
|
1065
|
-
get: function() {
|
|
1066
|
-
return sleep;
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
1013
|
Object.defineProperty(exports, "splitsIntoParts", {
|
|
1070
1014
|
enumerable: true,
|
|
1071
1015
|
get: function() {
|