calmlens 0.19.0 → 0.21.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.
Files changed (108) hide show
  1. package/README.md +13 -9
  2. package/bin/calmlens.js +1646 -706
  3. package/cjs/{BrowserUpload-CJ4Xc9bR.js → BrowserUpload-CeSwiMo5.js} +1 -1
  4. package/{esm/BrowserUpload-RkxV_Vv7.d.ts → cjs/BrowserUpload-D-NnAN7g.d.ts} +2 -2
  5. package/cjs/{CalmLensAppClient-LHMEQ-UZ.js → CalmLensAppClient-0UVCuNqW.js} +30 -10
  6. package/cjs/{CalmLensAppClient-B5gfOB6J.d.ts → CalmLensAppClient-gG16T2py.d.ts} +13 -3
  7. package/cjs/{CalmLensOptionKeys-BUj7v5AG.js → CalmLensOptionKeys-CYY6elxg.js} +242 -345
  8. package/cjs/{CalmLensServerClient-DCSbwIBs.d.ts → CalmLensServerClient-BHx3x_nZ.d.ts} +107 -49
  9. package/cjs/{CalmLensServerClient-BVOEUT_v.js → CalmLensServerClient-nfu6_YEW.js} +297 -92
  10. package/cjs/{CalmLensTypes-DpU-hXq2.d.ts → CalmLensTypes-CUB0YYVz.d.ts} +26601 -27354
  11. package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
  12. package/cjs/Core-C82YmjjX.d.ts +823 -0
  13. package/cjs/Core-Dc3cteU7.js +998 -0
  14. package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
  15. package/cjs/{ModerationContextLimits-FDpQmw_T.js → ModerationContextLimits-BxOmeSqq.js} +970 -278
  16. package/cjs/{ReactUpload-BvpW4hJi.js → ReactUpload-BK2O3dnK.js} +1 -1
  17. package/cjs/{ReactUpload-huIMnOJ4.d.ts → ReactUpload-DiiXfKvj.d.ts} +1 -1
  18. package/cjs/{TestTriggers-CMwMrbjy-K0YBzu2a.js → TestTriggers-BTyXtX0Q-ATuFDhLX.js} +343 -35
  19. package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
  20. package/cjs/{UploadController-D4qOZZc3.js → UploadController-DLyiLDTB.js} +34 -14
  21. package/cjs/{WebhookPayload-CQg8BBZQ.d.ts → WebhookPayload-BLT2y_Jy.d.ts} +93 -86
  22. package/cjs/app.d.ts +6 -7
  23. package/cjs/app.js +4 -3
  24. package/cjs/elements.d.ts +123 -22
  25. package/cjs/elements.js +553 -156
  26. package/cjs/file-icons.d.ts +2 -67
  27. package/cjs/index-CKRgjV16.d.ts +16 -0
  28. package/cjs/index.d.ts +5 -6
  29. package/cjs/index.js +3 -2
  30. package/cjs/react-native.d.ts +52 -11
  31. package/cjs/react-native.js +231 -99
  32. package/cjs/react.d.ts +42 -9
  33. package/cjs/react.js +381 -118
  34. package/cjs/server.d.ts +48 -7
  35. package/cjs/server.js +7 -3
  36. package/cjs/test-inputs.d.ts +2 -2
  37. package/cjs/test-inputs.js +13 -9
  38. package/cjs/testing.d.ts +29 -16
  39. package/cjs/testing.js +1511 -397
  40. package/cjs/ui-CTBUxnVp.d.ts +139 -0
  41. package/cjs/ui-CZ8exACq.js +1359 -0
  42. package/cjs/ui.d.ts +3 -2
  43. package/cjs/ui.js +45 -22
  44. package/cjs/vue.d.ts +802 -199
  45. package/cjs/vue.js +359 -127
  46. package/{cjs/BrowserUpload-RkxV_Vv7.d.ts → esm/BrowserUpload-D-NnAN7g.d.ts} +2 -2
  47. package/esm/{BrowserUpload-DpzS2bbj.js → BrowserUpload-i9OhCzMJ.js} +1 -1
  48. package/esm/{CalmLensAppClient-BjlvBweS.js → CalmLensAppClient-CK4_Py0c.js} +30 -10
  49. package/esm/{CalmLensAppClient-B5gfOB6J.d.ts → CalmLensAppClient-gG16T2py.d.ts} +13 -3
  50. package/esm/{CalmLensOptionKeys-BKez0Wiw.js → CalmLensOptionKeys-BGZlIsT2.js} +235 -338
  51. package/esm/{CalmLensServerClient-DCSbwIBs.d.ts → CalmLensServerClient-BHx3x_nZ.d.ts} +107 -49
  52. package/esm/{CalmLensServerClient-DemxbNMn.js → CalmLensServerClient-dAQUcDWb.js} +274 -93
  53. package/esm/{CalmLensTypes-DpU-hXq2.d.ts → CalmLensTypes-CUB0YYVz.d.ts} +26601 -27354
  54. package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
  55. package/esm/Core-BxeIud_S.js +843 -0
  56. package/esm/Core-C82YmjjX.d.ts +823 -0
  57. package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
  58. package/esm/{ModerationContextLimits-lLfmyLni.js → ModerationContextLimits-B6_RalCQ.js} +911 -261
  59. package/esm/{ReactUpload-huIMnOJ4.d.ts → ReactUpload-DiiXfKvj.d.ts} +1 -1
  60. package/esm/{ReactUpload-6klucehl.js → ReactUpload-DxwVqfX1.js} +1 -1
  61. package/esm/{TestTriggers-CMwMrbjy-bdowBBKw.js → TestTriggers-BTyXtX0Q-GRB9jQwo.js} +320 -36
  62. package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
  63. package/esm/{UploadController-UxP6gj7A.js → UploadController-D9Z-h00Q.js} +34 -14
  64. package/esm/{WebhookPayload-CQg8BBZQ.d.ts → WebhookPayload-BLT2y_Jy.d.ts} +93 -86
  65. package/esm/app.d.ts +6 -7
  66. package/esm/app.js +3 -3
  67. package/esm/elements.d.ts +123 -22
  68. package/esm/elements.js +497 -128
  69. package/esm/file-icons.d.ts +2 -67
  70. package/esm/index-CKRgjV16.d.ts +16 -0
  71. package/esm/index.d.ts +5 -6
  72. package/esm/index.js +1 -1
  73. package/esm/react-native.d.ts +52 -11
  74. package/esm/react-native.js +205 -75
  75. package/esm/react.d.ts +42 -9
  76. package/esm/react.js +327 -91
  77. package/esm/server.d.ts +48 -7
  78. package/esm/server.js +3 -3
  79. package/esm/styles.css +142 -22
  80. package/esm/svelte/AssetViewer.svelte +25 -0
  81. package/esm/svelte/CalmLensAsset.svelte +318 -0
  82. package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
  83. package/esm/svelte/CalmLensImageViewer.svelte +7 -0
  84. package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
  85. package/esm/svelte/CalmLensTextViewer.svelte +7 -0
  86. package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
  87. package/esm/svelte/index.d.ts +29 -6
  88. package/esm/svelte/index.js +7 -2
  89. package/esm/test-inputs.d.ts +2 -2
  90. package/esm/test-inputs.js +1 -1
  91. package/esm/testing.d.ts +29 -16
  92. package/esm/testing.js +1507 -393
  93. package/esm/ui-CTBUxnVp.d.ts +139 -0
  94. package/esm/ui-Cr7s6JHm.js +1258 -0
  95. package/esm/ui.d.ts +3 -2
  96. package/esm/ui.js +4 -3
  97. package/esm/vue.d.ts +802 -199
  98. package/esm/vue.js +308 -103
  99. package/package.json +3 -1
  100. package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
  101. package/cjs/index-BcDDQJF2.d.ts +0 -253
  102. package/cjs/ui-B23r8BvW.d.ts +0 -539
  103. package/cjs/ui-Dq-cm6Rx.js +0 -586
  104. package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
  105. package/esm/index-BcDDQJF2.d.ts +0 -253
  106. package/esm/svelte/CalmLensMedia.svelte +0 -134
  107. package/esm/ui-B23r8BvW.d.ts +0 -539
  108. package/esm/ui-Bn29rfAi.js +0 -461
@@ -1,4 +1,4 @@
1
- import { D as MAX_NON_IMAGE_UPLOAD_BYTES, E as MAX_IMAGE_UPLOAD_BYTES, F as API_ERROR_CODES, M as SDK_ERROR_CODES, N as invalidArgument, O as getRejectedUploadMimeTypeError, T as MAX_DIRECT_IMAGE_UPLOAD_BYTES, a as getUserAgent, h as stringifyQuery, j as CalmLensError, k as isRejectedUploadMimeType, o as isBrowserRuntime, p as randomUuid, r as selectModerationContextItems } from "./ModerationContextLimits-lLfmyLni.js";
1
+ import { A as getRejectedUploadMimeTypeError, B as invalidArgument, D as MAX_DIRECT_IMAGE_UPLOAD_BYTES, H as API_ERROR_CODES, M as CalmLensTransport, N as sleep, O as MAX_IMAGE_UPLOAD_BYTES, R as CalmLensError, _ as randomUuid, k as MAX_NON_IMAGE_UPLOAD_BYTES, m as isAcceptedUploadMimeType, r as selectModerationContextItems, y as stringifyQuery, z as SDK_ERROR_CODES } from "./ModerationContextLimits-B6_RalCQ.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
- * A redirect the SDK must not follow: it would send the API key to another origin. Browsers report
134
- * a manual redirect as an opaque response; other runtimes return the 3xx with its Location.
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 isRedirect = (response) => response.type === "opaqueredirect" || response.status >= 300 && response.status < 400 && response.headers.has("location");
137
- /** Turns anything thrown while sending or reading a request into a `CalmLensError`. */
138
- const toFailure = (cause, attempt) => {
139
- if (CalmLensError.isCalmLensError(cause)) return cause;
140
- if (attempt.isCancelled()) return new CalmLensError(SDK_ERROR_CODES.CANCELLED, {
141
- message: "Request cancelled",
142
- cause
143
- });
144
- if (attempt.isTimedOut()) return new CalmLensError(SDK_ERROR_CODES.TIMEOUT, {
145
- message: "Request timed out",
146
- cause
147
- });
148
- return new CalmLensError(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 CalmLensError(SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
156
- return;
157
- }
158
- const onAbort = () => {
159
- clearTimeout(timer);
160
- reject(new CalmLensError(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 CalmLensError(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 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 CalmLensError(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 (!isBrowserRuntime()) headers.set("user-agent", 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 CalmLensError(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 CalmLensError(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.
@@ -419,9 +149,12 @@ const setOptionalQueryValue = (params, key, value) => {
419
149
  if (value !== void 0 && value !== null) params.set(key, typeof value === "string" ? value : JSON.stringify(value));
420
150
  };
421
151
  const assertValidUploadMimeType = (mimeType) => {
422
- if (isRejectedUploadMimeType(mimeType)) throw new CalmLensError(API_ERROR_CODES.INVALID_UPLOAD_MIME_TYPE, {
152
+ if (!isAcceptedUploadMimeType(mimeType)) throw new CalmLensError(API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, {
423
153
  message: getRejectedUploadMimeTypeError(mimeType),
424
- details: { mimeType }
154
+ details: {
155
+ mimeType,
156
+ source: "calmlens"
157
+ }
425
158
  });
426
159
  };
427
160
  const isImageMimeType = (mimeType) => mimeType.toLowerCase().startsWith("image/");
@@ -433,16 +166,23 @@ const assertDeclaredPayloadSize = (payload, declared = payload.sizeInBytes) => {
433
166
  if (!Number.isSafeInteger(declared) || declared < 0 || measured !== void 0 && measured !== declared) throw invalidPayload("sizeInBytes must match the payload byte length");
434
167
  };
435
168
  /**
436
- * Refuses one-request content whose known size is over the API's limit for its type: images up
437
- * to 10 MiB (larger ones are uploaded in parts), audio and video up to 50 MiB, other files up to
438
- * 5,000 MiB. Nothing is sent, so an oversized file fails at once instead of after its upload.
169
+ * Refuses content whose known size is over the API's limit for its type, so nothing is sent and
170
+ * an oversized file fails at once instead of after its upload. In one request, images can be up
171
+ * to 10 MiB (larger ones are uploaded in parts), audio and video up to 50 MiB and other files up
172
+ * to 5,000 MiB. Sent in parts (`inParts`), audio and video can be up to 2 GiB; the API holds free
173
+ * uploads, made before billing is set up, to 50 MiB itself. Images in parts are checked apart.
439
174
  */
440
- const assertDirectUploadSize = (content) => {
441
- const size = content.sizeInBytes ?? getAssetPayloadByteLength(content);
175
+ const assertUploadSize = (type, size, inParts) => {
442
176
  if (size === void 0) return;
443
- const type = content.type.toLowerCase();
444
- const [limit, message] = type.startsWith("image/") ? [MAX_DIRECT_IMAGE_UPLOAD_BYTES, "Images uploaded in one request can be at most 10 MiB; upload larger images in parts"] : type.startsWith("audio/") || type.startsWith("video/") ? [MAX_MEDIA_UPLOAD_BYTES, "Audio and video files can be at most 50 MiB"] : [MAX_NON_IMAGE_UPLOAD_BYTES, "Files can be at most 5,000 MiB"];
445
- if (size > limit) throw new CalmLensError(API_ERROR_CODES.FILE_TOO_LARGE, { message });
177
+ const mime = type.toLowerCase();
178
+ const [limit, message] = mime.startsWith("image/") ? [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"] : [MAX_NON_IMAGE_UPLOAD_BYTES, "Files can be at most 5,000 MiB"];
179
+ if (size > limit) throw new CalmLensError(API_ERROR_CODES.UPLOAD_TOO_LARGE, {
180
+ message,
181
+ details: {
182
+ limitBytes: limit,
183
+ source: "plan"
184
+ }
185
+ });
446
186
  };
447
187
  /** Checks upload options before anything is sent. */
448
188
  const prepareSubmitAssetOptions = (options, { deferUploadChecks = false, partSizeBytes = DEFAULT_PART_SIZE_BYTES } = {}) => {
@@ -457,8 +197,14 @@ const prepareSubmitAssetOptions = (options, { deferUploadChecks = false, partSiz
457
197
  const inParts = splitsIntoParts(options.content, partSizeBytes);
458
198
  if (inParts && (options.idempotencyKey?.length ?? 0) > 240) throw invalidArgument(`idempotencyKey can be at most 240 characters for an upload sent in parts`);
459
199
  if (!deferUploadChecks && inParts && isImageMimeType(options.content.type)) {
460
- if ((getAssetPayloadByteLength(options.content) ?? 0) > MAX_IMAGE_UPLOAD_BYTES) throw new CalmLensError(API_ERROR_CODES.MULTIPART_IMAGE_TOO_LARGE, { message: "Multipart image uploads cannot exceed 20MB." });
461
- } else if (!deferUploadChecks) assertDirectUploadSize(options.content);
200
+ if ((getAssetPayloadByteLength(options.content) ?? 0) > MAX_IMAGE_UPLOAD_BYTES) throw new CalmLensError(API_ERROR_CODES.UPLOAD_TOO_LARGE, {
201
+ message: "Multipart image uploads cannot exceed 20 MiB.",
202
+ details: {
203
+ limitBytes: MAX_IMAGE_UPLOAD_BYTES,
204
+ source: "plan"
205
+ }
206
+ });
207
+ } else if (!deferUploadChecks) assertUploadSize(options.content.type, options.content.sizeInBytes ?? getAssetPayloadByteLength(options.content), inParts);
462
208
  if (!("plainText" in options.content)) {
463
209
  const validation = validateAssetPayload(options.content);
464
210
  if (!validation.ok) throw invalidPayload(validation.error);
@@ -469,8 +215,15 @@ const prepareSubmitAssetOptions = (options, { deferUploadChecks = false, partSiz
469
215
  assertValidUploadMimeType(options.part.type);
470
216
  const partSizeInBytes = options.part.sizeInBytes ?? getAssetPayloadByteLength(options.part);
471
217
  if (!deferUploadChecks && isImageMimeType(options.part.type) && partSizeInBytes !== void 0) {
472
- if (partSizeInBytes > MAX_IMAGE_UPLOAD_BYTES) throw new CalmLensError(API_ERROR_CODES.MULTIPART_IMAGE_TOO_LARGE, { message: "Multipart image uploads cannot exceed 20MB." });
218
+ if (partSizeInBytes > MAX_IMAGE_UPLOAD_BYTES) throw new CalmLensError(API_ERROR_CODES.UPLOAD_TOO_LARGE, {
219
+ message: "Multipart image uploads cannot exceed 20 MiB.",
220
+ details: {
221
+ limitBytes: MAX_IMAGE_UPLOAD_BYTES,
222
+ source: "plan"
223
+ }
224
+ });
473
225
  }
226
+ if (!deferUploadChecks && !isImageMimeType(options.part.type)) assertUploadSize(options.part.type, options.totalSizeInBytes, true);
474
227
  const validation = validateAssetPayload(options.part, {
475
228
  multipart: true,
476
229
  isFinal: deferUploadChecks || options.part.isFinal
@@ -491,7 +244,7 @@ const newIdempotencyKey = () => randomUuid();
491
244
  const isTextPayload = (payload) => "plainText" in payload;
492
245
  const hasStringStatus = (value) => !!value && typeof value === "object" && typeof value.status === "string";
493
246
  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;
247
+ const isUploadedAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id && hasStringStatus(data.classification) && hasStringStatus(data.upload);
495
248
  const expectUploadedAsset = (data) => {
496
249
  if (!isUploadedAsset(data)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
497
250
  message: "Expected an uploaded asset response",
@@ -576,14 +329,15 @@ var CalmLensConnection = class {
576
329
  * Uploads file content or a first multipart part to `uploadsPath` (`.../assets`), as raw
577
330
  * bytes with the options in the query.
578
331
  */
579
- submitRawUpload(uploadsPath, options, queue, authHeaders = {}) {
332
+ submitRawUpload(uploadsPath, options, wait, authHeaders = {}) {
580
333
  const query = new URLSearchParams();
581
334
  query.set("name", options.name);
582
- query.set("queue", String(queue));
335
+ query.set("wait", String(wait));
583
336
  setOptionalQueryValue(query, "description", options.description);
584
337
  setOptionalQueryValue(query, "processingOptions", options.processingOptions);
585
338
  setOptionalQueryValue(query, "visibility", options.visibility);
586
339
  setOptionalQueryValue(query, "metadata", options.metadata);
340
+ setOptionalQueryValue(query, "tags", options.tags);
587
341
  setOptionalQueryValue(query, "authorId", options.authorId);
588
342
  setOptionalQueryValue(query, "context", options.context);
589
343
  setOptionalQueryValue(query, "externalId", options.externalId);
@@ -619,7 +373,7 @@ var CalmLensConnection = class {
619
373
  * upload. A part the API already has is skipped, and a final part that finds the upload already
620
374
  * completed reads it back with `retrieve`.
621
375
  */
622
- async submitInParts(uploadsPath, options, queue, { authHeaders = {}, partPath, onStarted, retrieve }) {
376
+ async submitInParts(uploadsPath, options, wait, { authHeaders = {}, partPath, onStarted, retrieve }) {
623
377
  const { content, idempotencyKey, ...fields } = options;
624
378
  const source = getSplittableContent(content);
625
379
  const partSize = this.partSizeBytes;
@@ -636,7 +390,7 @@ var CalmLensConnection = class {
636
390
  },
637
391
  totalSizeInBytes: source.size,
638
392
  idempotencyKey: key
639
- }, queue, authHeaders);
393
+ }, wait, authHeaders);
640
394
  const assetId = expectUploadedAsset(first).id;
641
395
  onStarted?.(assetId);
642
396
  let result = first;
@@ -666,7 +420,7 @@ var CalmLensConnection = class {
666
420
  return result;
667
421
  }
668
422
  /** Uploads the next part of a multipart upload to `partPath` (`.../assets/{id}/part`). */
669
- uploadPart(partPath, { part, queue, idempotencyKey }, authHeaders = {}) {
423
+ uploadPart(partPath, { part, wait, idempotencyKey }, authHeaders = {}) {
670
424
  if (!part) throw invalidArgument("Part options are required");
671
425
  assertDeclaredPayloadSize(part);
672
426
  const validation = validateAssetPayload(part, {
@@ -678,7 +432,7 @@ var CalmLensConnection = class {
678
432
  partNumber: String(part.partNumber),
679
433
  isFinal: String(part.isFinal ?? false)
680
434
  });
681
- if (queue !== void 0) query.set("queue", String(queue));
435
+ if (wait !== void 0) query.set("wait", String(wait));
682
436
  setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? getAssetPayloadByteLength(part));
683
437
  return this.upload(this.url(`${partPath}?${query}`), part, {
684
438
  ...authHeaders,
@@ -704,6 +458,7 @@ const SERVER_OPTION_KEYS = {
704
458
  "part",
705
459
  "processingOptions",
706
460
  "sizeInBytes",
461
+ "tags",
707
462
  "totalSizeInBytes",
708
463
  "uploadPresetId",
709
464
  "url",
@@ -723,19 +478,12 @@ const SERVER_OPTION_KEYS = {
723
478
  "part",
724
479
  "processingOptions",
725
480
  "sizeInBytes",
481
+ "tags",
726
482
  "totalSizeInBytes",
727
483
  "uploadPresetId",
728
484
  "url",
729
485
  "visibility"
730
486
  ],
731
- "assets.createSignedUrl": [
732
- "assetId",
733
- "expiresInSeconds",
734
- "lens",
735
- "resource",
736
- "transform",
737
- "viewerClaims"
738
- ],
739
487
  "assets.decide": [
740
488
  "assetId",
741
489
  "confirmPurge",
@@ -743,40 +491,48 @@ const SERVER_OPTION_KEYS = {
743
491
  "note"
744
492
  ],
745
493
  "assets.delete": ["assetId"],
746
- "assets.deleteContent": ["assetId"],
747
494
  "assets.explain": ["assetId", "rerun"],
748
495
  "assets.iterate": [
749
496
  "cursor",
750
497
  "filter",
751
- "folderId",
752
- "ordering",
753
- "pageSize"
498
+ "pageSize",
499
+ "sort"
754
500
  ],
755
501
  "assets.iterateChildren": [
756
502
  "assetId",
757
503
  "cursor",
758
- "ordering",
504
+ "pageSize",
505
+ "sort"
506
+ ],
507
+ "assets.iterateTimeline": [
508
+ "assetId",
509
+ "cursor",
759
510
  "pageSize"
760
511
  ],
761
512
  "assets.list": [
762
513
  "cursor",
763
514
  "filter",
764
- "folderId",
765
- "ordering",
766
- "pageSize"
515
+ "pageSize",
516
+ "sort"
767
517
  ],
768
518
  "assets.listChildren": [
769
519
  "assetId",
770
520
  "cursor",
771
- "ordering",
521
+ "pageSize",
522
+ "sort"
523
+ ],
524
+ "assets.listTimeline": [
525
+ "assetId",
526
+ "cursor",
772
527
  "pageSize"
773
528
  ],
774
529
  "assets.move": ["assetId", "folderId"],
530
+ "assets.removeContent": ["assetId"],
775
531
  "assets.retrieve": ["assetId"],
776
532
  "assets.retry": ["assetId"],
777
533
  "assets.search": [
778
- "limit",
779
534
  "mode",
535
+ "pageSize",
780
536
  "query"
781
537
  ],
782
538
  "assets.update": [
@@ -792,7 +548,18 @@ const SERVER_OPTION_KEYS = {
792
548
  "assets.uploadPart": [
793
549
  "assetId",
794
550
  "part",
795
- "queue"
551
+ "wait"
552
+ ],
553
+ "cdn.signAssetUrl": [
554
+ "assetId",
555
+ "expiresIn",
556
+ "externalId",
557
+ "lens",
558
+ "original",
559
+ "projectId",
560
+ "resource",
561
+ "transform",
562
+ "viewerClaims"
796
563
  ],
797
564
  "ensureLens": [
798
565
  "active",
@@ -800,20 +567,36 @@ const SERVER_OPTION_KEYS = {
800
567
  "identifier",
801
568
  "name",
802
569
  "transform",
803
- "type",
804
- "version"
570
+ "type"
805
571
  ],
806
572
  "ensureLenses": ["lenses"],
807
- "events.list": ["cursor", "pageSize"],
808
- "events.pages": ["cursor", "pageSize"],
573
+ "events.list": [
574
+ "assetId",
575
+ "cursor",
576
+ "pageSize",
577
+ "types"
578
+ ],
579
+ "events.pages": [
580
+ "assetId",
581
+ "cursor",
582
+ "pageSize",
583
+ "types"
584
+ ],
809
585
  "folders.create": ["name", "parentId"],
810
586
  "folders.delete": ["folderId"],
587
+ "folders.iterate": [
588
+ "cursor",
589
+ "pageSize",
590
+ "parentId",
591
+ "search",
592
+ "sort"
593
+ ],
811
594
  "folders.list": [
812
595
  "cursor",
813
- "ordering",
814
596
  "pageSize",
815
597
  "parentId",
816
- "search"
598
+ "search",
599
+ "sort"
817
600
  ],
818
601
  "folders.move": ["folderId", "parentId"],
819
602
  "folders.retrieve": ["folderId"],
@@ -831,16 +614,27 @@ const SERVER_OPTION_KEYS = {
831
614
  "name"
832
615
  ],
833
616
  "hashLists.delete": ["hashListId"],
617
+ "hashLists.iterate": [
618
+ "cursor",
619
+ "pageSize",
620
+ "sort"
621
+ ],
622
+ "hashLists.iterateEntries": [
623
+ "cursor",
624
+ "hashListId",
625
+ "pageSize",
626
+ "sort"
627
+ ],
834
628
  "hashLists.list": [
835
629
  "cursor",
836
- "ordering",
837
- "pageSize"
630
+ "pageSize",
631
+ "sort"
838
632
  ],
839
633
  "hashLists.listEntries": [
840
634
  "cursor",
841
635
  "hashListId",
842
- "ordering",
843
- "pageSize"
636
+ "pageSize",
637
+ "sort"
844
638
  ],
845
639
  "hashLists.removeEntry": ["entryId"],
846
640
  "hashLists.retrieve": ["hashListId"],
@@ -850,11 +644,33 @@ const SERVER_OPTION_KEYS = {
850
644
  "hashListId",
851
645
  "name"
852
646
  ],
853
- "policies.applyPreset": [
854
- "operation",
855
- "policyId",
856
- "presetVersion",
857
- "revision"
647
+ "lenses.create": [
648
+ "active",
649
+ "description",
650
+ "identifier",
651
+ "name",
652
+ "transform",
653
+ "type"
654
+ ],
655
+ "lenses.delete": ["lensId"],
656
+ "lenses.iterate": [
657
+ "cursor",
658
+ "pageSize",
659
+ "sort"
660
+ ],
661
+ "lenses.list": [
662
+ "cursor",
663
+ "pageSize",
664
+ "sort"
665
+ ],
666
+ "lenses.retrieve": ["lensId"],
667
+ "lenses.update": [
668
+ "active",
669
+ "description",
670
+ "lensId",
671
+ "name",
672
+ "transform",
673
+ "type"
858
674
  ],
859
675
  "policies.assign": ["policyId"],
860
676
  "policies.create": [
@@ -864,8 +680,23 @@ const SERVER_OPTION_KEYS = {
864
680
  "settings"
865
681
  ],
866
682
  "policies.delete": ["policyId"],
867
- "policies.list": [],
683
+ "policies.iterate": [
684
+ "cursor",
685
+ "pageSize",
686
+ "sort"
687
+ ],
688
+ "policies.list": [
689
+ "cursor",
690
+ "pageSize",
691
+ "sort"
692
+ ],
693
+ "policies.reset": [
694
+ "policyId",
695
+ "presetVersion",
696
+ "revision"
697
+ ],
868
698
  "policies.retrieve": ["policyId"],
699
+ "policies.retrieveAssigned": [],
869
700
  "policies.setAutomaticUpdates": [
870
701
  "enabled",
871
702
  "policyId",
@@ -879,6 +710,11 @@ const SERVER_OPTION_KEYS = {
879
710
  "revision",
880
711
  "settings"
881
712
  ],
713
+ "policies.upgrade": [
714
+ "policyId",
715
+ "presetVersion",
716
+ "revision"
717
+ ],
882
718
  "text.classify": [
883
719
  "authorId",
884
720
  "context",
@@ -889,6 +725,7 @@ const SERVER_OPTION_KEYS = {
889
725
  "metadata",
890
726
  "name",
891
727
  "processingOptions",
728
+ "tags",
892
729
  "text",
893
730
  "uploadPresetId",
894
731
  "visibility"
@@ -918,7 +755,67 @@ const APP_OPTION_KEYS = {
918
755
  "assets.uploadPart": [
919
756
  "assetId",
920
757
  "part",
921
- "queue"
758
+ "wait"
759
+ ]
760
+ };
761
+ /**
762
+ * The option keys each `CalmLensServerClient` method sends as `null` when given `null`; any
763
+ * other option given as `null` is left out, as the API refuses `null` for it.
764
+ */
765
+ const NULLABLE_OPTION_KEYS = {
766
+ "assets.classify": [
767
+ "authorId",
768
+ "context",
769
+ "description",
770
+ "externalId",
771
+ "folderId",
772
+ "metadata",
773
+ "processingOptions",
774
+ "tags",
775
+ "uploadPresetId",
776
+ "visibility"
777
+ ],
778
+ "assets.create": [
779
+ "authorId",
780
+ "context",
781
+ "description",
782
+ "externalId",
783
+ "folderId",
784
+ "metadata",
785
+ "processingOptions",
786
+ "tags",
787
+ "uploadPresetId",
788
+ "visibility"
789
+ ],
790
+ "assets.iterate": ["filter"],
791
+ "assets.list": ["filter"],
792
+ "assets.move": ["folderId"],
793
+ "assets.update": [
794
+ "description",
795
+ "externalId",
796
+ "externalUrl",
797
+ "metadata",
798
+ "tags",
799
+ "visibility"
800
+ ],
801
+ "folders.create": ["parentId"],
802
+ "folders.move": ["parentId"],
803
+ "hashLists.addEntry": ["label", "quality"],
804
+ "hashLists.create": ["description"],
805
+ "hashLists.update": ["description"],
806
+ "lenses.create": ["description", "transform"],
807
+ "lenses.update": ["description", "transform"],
808
+ "text.classify": [
809
+ "authorId",
810
+ "context",
811
+ "description",
812
+ "externalId",
813
+ "folderId",
814
+ "metadata",
815
+ "processingOptions",
816
+ "tags",
817
+ "uploadPresetId",
818
+ "visibility"
922
819
  ]
923
820
  };
924
- export { expectAsset as a, invalidPayload as c, resolveConnectionOptions as d, splitsIntoParts as f, validateAssetPayload as g, assetToData as h, MOCK_HOOKS as i, newIdempotencyKey as l, assetDataToUint8Array as m, SERVER_OPTION_KEYS as n, expectUploadedAsset as o, sleep as p, CalmLensConnection as r, getMockHooks as s, APP_OPTION_KEYS as t, prepareSubmitAssetOptions as u };
821
+ export { MOCK_HOOKS as a, getMockHooks as c, prepareSubmitAssetOptions as d, resolveConnectionOptions as f, validateAssetPayload as g, assetToData as h, CalmLensConnection as i, invalidPayload as l, assetDataToUint8Array as m, NULLABLE_OPTION_KEYS as n, expectAsset as o, splitsIntoParts as p, SERVER_OPTION_KEYS as r, expectUploadedAsset as s, APP_OPTION_KEYS as t, newIdempotencyKey as u };