calmlens 0.25.0 → 0.27.1

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 (95) hide show
  1. package/README.md +15 -15
  2. package/bin/calmlens.js +2383 -677
  3. package/cjs/{BrowserUpload-AO2-2U5Z.js → BrowserUpload-CTqIjCV5.js} +1 -1
  4. package/{esm/BrowserUpload-D2lemMIU.d.ts → cjs/BrowserUpload-D4sEmd0X.d.ts} +2 -2
  5. package/{esm/CalmLensAppClient-Dt0t9Bk6.d.ts → cjs/CalmLensAppClient-CCeFnKX8.d.ts} +5 -11
  6. package/cjs/{CalmLensAppClient-nv6qwja0.js → CalmLensAppClient-CZm-9g22.js} +23 -16
  7. package/cjs/{CalmLensOptionKeys-BvCac9NO.js → CalmLensOptionKeys-C1w3SqmL.js} +165 -95
  8. package/cjs/CalmLensServerClient-B7PfocET.d.ts +346 -0
  9. package/cjs/{CalmLensServerClient-B60kCBCR.js → CalmLensServerClient-ucq3ITjd.js} +281 -315
  10. package/cjs/{CalmLensTypes-BhR7LFDu.d.ts → CalmLensTypes-HUERg5hI.d.ts} +142 -155
  11. package/cjs/{Classification-CxRedzgH-C9qlYW_J.d.ts → Classification-CMM2tZpJ-IdIh63n0.d.ts} +6 -7
  12. package/cjs/{Core-Cw4IxFUq.js → Core-D-1KCqT7.js} +39 -16
  13. package/cjs/{Core-DSMxC2GL.d.ts → Core-DXAs8mcx.d.ts} +10 -3
  14. package/{esm/ModerationContextLimits-Bqr0duav.js → cjs/ModerationContextLimits-BcYKgU2X.js} +859 -44
  15. package/cjs/ReactUpload-BTciTpwB.d.ts +27 -0
  16. package/cjs/{ReactUpload--oDFltw2.js → ReactUpload-BymgWiC8.js} +38 -2
  17. package/cjs/{TestTriggers-CiFcTHX3-BmfH4J3f.js → TestTriggers-Cvi7e2KA-DcT1pc_W.js} +91 -22
  18. package/{esm/TestTriggers-BJ4B-MXR-D1tGifPU.d.ts → cjs/TestTriggers-Dnukm-jm-DoEB7jJc.d.ts} +1 -1
  19. package/cjs/{UploadController-ObdgTaBl.js → UploadController-C8GPbDKI.js} +16 -3
  20. package/{esm/WebhookPayload-DLGGOGW6.d.ts → cjs/WebhookPayload-mUmOFH55.d.ts} +152 -9
  21. package/cjs/app.d.ts +6 -6
  22. package/cjs/app.js +20 -2
  23. package/cjs/elements.d.ts +5 -5
  24. package/cjs/elements.js +105 -68
  25. package/cjs/{index-AAWuerkU.d.ts → index-Ck7x1YjM.d.ts} +3 -3
  26. package/cjs/index.d.ts +5 -5
  27. package/cjs/index.js +19 -1
  28. package/cjs/react-native.d.ts +3 -3
  29. package/cjs/react-native.js +7 -5
  30. package/cjs/react.d.ts +5 -4
  31. package/cjs/react.js +11 -15
  32. package/cjs/server.d.ts +6 -6
  33. package/cjs/server.js +20 -2
  34. package/cjs/test-inputs.d.ts +1 -1
  35. package/cjs/test-inputs.js +13 -13
  36. package/cjs/testing.d.ts +18 -21
  37. package/cjs/testing.js +99 -147
  38. package/cjs/{ui-CcuGKTcL.d.ts → ui-BfJNO3c6.d.ts} +2 -2
  39. package/cjs/{ui-CA16jyfZ.js → ui-CW8BqtZk.js} +7 -5
  40. package/cjs/ui.d.ts +3 -3
  41. package/cjs/ui.js +4 -3
  42. package/cjs/vue.d.ts +15 -8
  43. package/cjs/vue.js +30 -17
  44. package/esm/{BrowserUpload-Co4T6uGk.js → BrowserUpload-C01iLeOs.js} +1 -1
  45. package/{cjs/BrowserUpload-D2lemMIU.d.ts → esm/BrowserUpload-D4sEmd0X.d.ts} +2 -2
  46. package/{cjs/CalmLensAppClient-Dt0t9Bk6.d.ts → esm/CalmLensAppClient-CCeFnKX8.d.ts} +5 -11
  47. package/esm/{CalmLensAppClient-BRzy4dwn.js → CalmLensAppClient-CgDogQQC.js} +23 -16
  48. package/esm/{CalmLensOptionKeys-bE3rb5PN.js → CalmLensOptionKeys-CEwNbpEz.js} +160 -96
  49. package/esm/CalmLensServerClient-B7PfocET.d.ts +346 -0
  50. package/esm/{CalmLensServerClient-_PRi90wI.js → CalmLensServerClient-TT6zrAG5.js} +281 -315
  51. package/esm/{CalmLensTypes-BhR7LFDu.d.ts → CalmLensTypes-HUERg5hI.d.ts} +142 -155
  52. package/esm/{Classification-CxRedzgH-C9qlYW_J.d.ts → Classification-CMM2tZpJ-IdIh63n0.d.ts} +6 -7
  53. package/esm/{Core-CtbYmeXG.js → Core-CP6NaqJz.js} +39 -16
  54. package/esm/{Core-DSMxC2GL.d.ts → Core-DXAs8mcx.d.ts} +10 -3
  55. package/{cjs/ModerationContextLimits-Cn9RvnZH.js → esm/ModerationContextLimits-BmV8QD32.js} +476 -301
  56. package/esm/{ReactUpload-B5itHBSF.js → ReactUpload-B72Oq3qE.js} +34 -4
  57. package/esm/ReactUpload-BTciTpwB.d.ts +27 -0
  58. package/esm/{TestTriggers-CiFcTHX3-BK2-sgOC.js → TestTriggers-Cvi7e2KA-BA83CRJb.js} +87 -23
  59. package/{cjs/TestTriggers-BJ4B-MXR-D1tGifPU.d.ts → esm/TestTriggers-Dnukm-jm-DoEB7jJc.d.ts} +1 -1
  60. package/esm/{UploadController-C7fL3Iz9.js → UploadController-Q7xTqh5w.js} +11 -4
  61. package/{cjs/WebhookPayload-DLGGOGW6.d.ts → esm/WebhookPayload-mUmOFH55.d.ts} +152 -9
  62. package/esm/app.d.ts +6 -6
  63. package/esm/app.js +3 -3
  64. package/esm/elements.d.ts +5 -5
  65. package/esm/elements.js +105 -69
  66. package/esm/{index-AAWuerkU.d.ts → index-Ck7x1YjM.d.ts} +3 -3
  67. package/esm/index.d.ts +5 -5
  68. package/esm/index.js +1 -1
  69. package/esm/react-native.d.ts +3 -3
  70. package/esm/react-native.js +6 -6
  71. package/esm/react.d.ts +5 -4
  72. package/esm/react.js +10 -16
  73. package/esm/server.d.ts +6 -6
  74. package/esm/server.js +3 -3
  75. package/esm/styles.css +37 -14
  76. package/esm/svelte/CalmLensAsset.svelte +1 -1
  77. package/esm/svelte/CalmLensUploader.svelte +17 -17
  78. package/esm/svelte/context.js +21 -0
  79. package/esm/svelte/index.d.ts +12 -0
  80. package/esm/svelte/index.js +1 -0
  81. package/esm/test-inputs.d.ts +1 -1
  82. package/esm/test-inputs.js +1 -1
  83. package/esm/testing.d.ts +18 -21
  84. package/esm/testing.js +93 -141
  85. package/esm/{ui-B98AucZA.js → ui-BBDJJkFL.js} +7 -5
  86. package/esm/{ui-CcuGKTcL.d.ts → ui-BfJNO3c6.d.ts} +2 -2
  87. package/esm/ui.d.ts +3 -3
  88. package/esm/ui.js +4 -4
  89. package/esm/vue.d.ts +15 -8
  90. package/esm/vue.js +30 -19
  91. package/package.json +16 -6
  92. package/cjs/CalmLensServerClient-7XjQaeKu.d.ts +0 -353
  93. package/cjs/ReactUpload-CW4NzAsh.d.ts +0 -17
  94. package/esm/CalmLensServerClient-7XjQaeKu.d.ts +0 -353
  95. package/esm/ReactUpload-CW4NzAsh.d.ts +0 -17
@@ -1,4 +1,4 @@
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-Bqr0duav.js";
1
+ import { B as resolveLogLevel, D as MAX_IMAGE_UPLOAD_BYTES, E as MAX_DIRECT_IMAGE_UPLOAD_BYTES, M as sleep, O as MAX_NON_IMAGE_UPLOAD_BYTES, Y as CalmLensError, _ as randomUuid, j as CalmLensTransport, k as getRejectedUploadMimeTypeError, lt as API_ERROR_CODES, m as isAcceptedUploadMimeType, ot as SDK_ERROR_CODES, r as selectModerationContextItems, st as invalidArgument, y as stringifyQuery } from "./ModerationContextLimits-BmV8QD32.js";
2
2
  // src/contract/AssetPayload.js
3
3
  const bufferInputToBytes = (value) => {
4
4
  if (value instanceof ArrayBuffer) return new Uint8Array(value);
@@ -12,8 +12,9 @@ const getRawBase64 = (value) => {
12
12
  return value.slice(markerIndex + 8);
13
13
  };
14
14
  const validateBase64PayloadString = (payload, options) => {
15
- const raw = getRawBase64(payload.base64).replace(/\s/g, "");
16
- if (options?.multipart && raw.length % 4 !== 0) return {
15
+ const raw = getRawBase64(payload.base64);
16
+ const whitespace = /\s/.test(raw) ? raw.match(/\s/g)?.length ?? 0 : 0;
17
+ if (options?.multipart && (raw.length - whitespace) % 4 !== 0) return {
17
18
  ok: false,
18
19
  error: BASE64_PART_BOUNDARY_ERROR
19
20
  };
@@ -30,7 +31,7 @@ const assetToData = (payload) => {
30
31
  if (payload.uint8Array !== void 0) return Uint8Array.from(payload.uint8Array);
31
32
  if (payload.base64 === void 0) throw new Error("Invalid asset payload");
32
33
  const raw = getRawBase64(payload.base64);
33
- if (typeof Buffer !== "undefined") return Uint8Array.from(Buffer.from(raw, "base64"));
34
+ if (typeof Buffer !== "undefined") return Buffer.from(raw, "base64");
34
35
  const binary = atob(raw);
35
36
  return Uint8Array.from(binary, (char) => char.charCodeAt(0));
36
37
  };
@@ -153,23 +154,17 @@ const textEncoder = new TextEncoder();
153
154
  /**
154
155
  * An upload form: `multipart/form-data` with the asset's fields as the JSON `options` part, then
155
156
  * 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.
157
+ * Bytes stay bytes (React Native can't build a Blob from them). Read Blob bytes before composing
158
+ * the form: Bun's Blob constructor drops disk-backed BunFile parts. Automatic multipart uploads
159
+ * read only the current part. Streams remain streamed, and buffered bodies remain retryable.
158
160
  */
159
- const toUploadForm = (options, payload) => {
161
+ const toUploadForm = async (options, payload) => {
160
162
  const boundary = `calmlens-${randomUuid()}`;
161
163
  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
164
  const tail = `\r\n--${boundary}--\r\n`;
163
165
  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
- };
166
+ const input = toUploadData(payload);
167
+ const data = input instanceof Blob ? new Uint8Array(await input.arrayBuffer()) : input;
173
168
  const headBytes = textEncoder.encode(head);
174
169
  const tailBytes = textEncoder.encode(tail);
175
170
  if (data instanceof Uint8Array) {
@@ -264,7 +259,29 @@ const assertUploadSize = (type, size, inParts) => {
264
259
  });
265
260
  };
266
261
  /** Checks upload options before anything is sent. */
267
- const prepareSubmitAssetOptions = (options, { deferUploadChecks = false, partSizeBytes = DEFAULT_PART_SIZE_BYTES } = {}) => {
262
+ const isBlob = (value) => typeof Blob !== "undefined" && value instanceof Blob;
263
+ /**
264
+ * `content` given as a `Blob` or `File`, as the `{ data, type }` the rest of the client reads: the
265
+ * content type is the Blob's own, and a File's name is the asset's when the options give none.
266
+ */
267
+ const withContentObject = (options) => {
268
+ if (!options || typeof options !== "object" || !("content" in options)) return options;
269
+ const content = options.content;
270
+ if (!isBlob(content)) return options;
271
+ if (!content.type) throw invalidPayload("The Blob has no type: create it with one, such as new Blob([bytes], { type: \"image/png\" }), or pass { data, type }");
272
+ const fileName = typeof File !== "undefined" && content instanceof File ? content.name : void 0;
273
+ const named = options;
274
+ return {
275
+ ...options,
276
+ ...named.name || !fileName ? {} : { name: fileName },
277
+ content: {
278
+ data: content,
279
+ type: content.type
280
+ }
281
+ };
282
+ };
283
+ const prepareSubmitAssetOptions = (input, { deferUploadChecks = false, partSizeBytes = DEFAULT_PART_SIZE_BYTES } = {}) => {
284
+ const options = withContentObject(input);
268
285
  if (!options || typeof options !== "object") throw invalidArgument("Asset options are required");
269
286
  if (!("content" in options) && !("url" in options) && !("part" in options)) throw invalidPayload("Either file content, URL, or multipart part is required");
270
287
  if (!options.name) throw invalidPayload("Asset name is required");
@@ -322,7 +339,11 @@ const newIdempotencyKey = () => randomUuid();
322
339
  /** Text content is small, so it keeps the API deadline; binary files may be arbitrarily large. */
323
340
  const isTextPayload = (payload) => "plainText" in payload;
324
341
  const hasStringStatus = (value) => !!value && typeof value === "object" && typeof value.status === "string";
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";
342
+ const hasDecision = (data) => {
343
+ const decision = data.classification?.moderation?.decision;
344
+ return decision === null || typeof decision === "string";
345
+ };
346
+ const isAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id && hasStringStatus(data.classification) && hasStringStatus(data.upload) && hasDecision(data);
326
347
  const isUploadedAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id && hasStringStatus(data.classification) && hasStringStatus(data.upload);
327
348
  const expectUploadedAsset = (data) => {
328
349
  if (!isUploadedAsset(data)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
@@ -338,30 +359,114 @@ const expectAsset = (data) => {
338
359
  });
339
360
  return data;
340
361
  };
362
+ /** Checks one call's request options. */
363
+ const validateCallOptions = (options) => {
364
+ if (options === void 0) return;
365
+ if (!options || typeof options !== "object" || Array.isArray(options)) throw invalidArgument("Request options must be an object");
366
+ const known = [
367
+ "signal",
368
+ "timeoutMs",
369
+ "maxRetries",
370
+ "idempotencyKey",
371
+ "headers",
372
+ "extraQuery",
373
+ "extraBody"
374
+ ];
375
+ const unknown = Object.keys(options).filter((key) => !known.includes(key));
376
+ if (unknown.length) throw invalidArgument(`Unknown request options: ${unknown.join(", ")}`, { options: unknown });
377
+ const { timeoutMs, maxRetries, idempotencyKey, headers, extraQuery, extraBody } = options;
378
+ if (timeoutMs !== void 0 && (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1)) throw invalidArgument("timeoutMs must be a positive integer");
379
+ if (maxRetries !== void 0 && (!Number.isSafeInteger(maxRetries) || maxRetries < 0)) throw invalidArgument("maxRetries must be a non-negative integer");
380
+ if (idempotencyKey !== void 0 && (typeof idempotencyKey !== "string" || !idempotencyKey)) throw invalidArgument("idempotencyKey must be a non-empty string");
381
+ for (const [name, value] of Object.entries({
382
+ headers,
383
+ extraQuery,
384
+ extraBody
385
+ })) if (value !== void 0 && (!value || typeof value !== "object" || Array.isArray(value))) throw invalidArgument(`${name} must be an object`);
386
+ if (options.signal !== void 0 && !(options.signal instanceof AbortSignal)) throw invalidArgument("signal must be an AbortSignal");
387
+ };
388
+ const isPlainObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
341
389
  /** Fills in the default API base URL and drops trailing slashes. */
342
390
  const resolveConnectionOptions = (options) => ({
343
391
  ...options,
344
392
  baseUrl: (options.baseUrl ?? `https://api.calmlens.com/v1`).replace(/\/+$/, "")
345
393
  });
346
394
  /** One client's transport, base URL and deadlines, and the requests both clients make. */
347
- var CalmLensConnection = class {
348
- constructor(options, apiKey) {
395
+ var CalmLensConnection = class CalmLensConnection {
396
+ constructor(options, apiKey, { readEnvironment = false, shared } = {}) {
349
397
  this.options = options;
398
+ if (shared) {
399
+ this.transport = shared.transport;
400
+ this.hooks = shared.hooks;
401
+ this.call = shared.call;
402
+ return;
403
+ }
404
+ this.call = {};
350
405
  const resolveFetch = () => {
351
406
  const fetchImpl = this.options.fetch ?? globalThis.fetch;
352
407
  if (typeof fetchImpl !== "function") throw new CalmLensError(SDK_ERROR_CODES.NO_FETCH, { message: "No fetch implementation is available; pass one as the fetch option" });
353
408
  return fetchImpl;
354
409
  };
355
410
  this.hooks = getMockHooks(options);
411
+ const logLevel = resolveLogLevel(options.logLevel, readEnvironment);
356
412
  this.transport = new CalmLensTransport({
357
413
  apiKey,
358
414
  sleep: this.hooks?.sleep,
359
415
  fetch: ((input, init) => resolveFetch()(input, init)),
360
416
  signal: options.signal,
361
417
  maxRetries: options.maxRetries ?? 2,
362
- maxResponseBytes: options.maxResponseBytes ?? 33554432
418
+ maxResponseBytes: options.maxResponseBytes ?? 33554432,
419
+ appInfo: options.appInfo,
420
+ logLevel,
421
+ logger: logLevel === "off" ? void 0 : options.logger ?? console,
422
+ onAttempt: options.onAttempt,
423
+ now: this.hooks?.now
363
424
  });
364
425
  }
426
+ /**
427
+ * This connection for one call: its requests carry `operation` to the attempt hook and logs, and
428
+ * follow `requestOptions` (checked here) over the client's.
429
+ */
430
+ forCall(operation, requestOptions) {
431
+ validateCallOptions(requestOptions);
432
+ return new CalmLensConnection(this.options, void 0, { shared: {
433
+ transport: this.transport,
434
+ hooks: this.hooks,
435
+ call: {
436
+ ...this.call,
437
+ ...requestOptions,
438
+ operation
439
+ }
440
+ } });
441
+ }
442
+ /** The call's transport settings, for a request built here or by the client. */
443
+ callRequest() {
444
+ const { operation, signal, maxRetries } = this.call;
445
+ return {
446
+ operation,
447
+ signal,
448
+ maxRetries
449
+ };
450
+ }
451
+ /** The call's extra headers under the SDK's own, which win. */
452
+ callHeaders(headers) {
453
+ return this.call.headers ? {
454
+ ...this.call.headers,
455
+ ...headers
456
+ } : headers;
457
+ }
458
+ /** The call's `extraBody` merged into a JSON body. */
459
+ callBody(method, body) {
460
+ const { extraBody } = this.call;
461
+ if (!extraBody) return body;
462
+ if (method === "GET" || method === "HEAD") throw invalidArgument("extraBody needs a request with a body");
463
+ if (body === void 0) return extraBody;
464
+ if (!isPlainObject(body)) throw invalidArgument("extraBody needs a JSON object body");
465
+ return {
466
+ ...body,
467
+ ...extraBody
468
+ };
469
+ }
365
470
  /** How the client waits between polls and retries. */
366
471
  get sleep() {
367
472
  return this.hooks?.sleep ?? sleep;
@@ -371,35 +476,40 @@ var CalmLensConnection = class {
371
476
  return this.hooks?.deferUploadChecks ?? false;
372
477
  }
373
478
  get timeoutMs() {
374
- return this.options.timeoutMs ?? 12e4;
479
+ return this.call.timeoutMs ?? this.options.timeoutMs ?? 12e4;
375
480
  }
481
+ /** The URL of `path` (which may carry a query already) with `query` and the call's `extraQuery`. */
376
482
  url(path, query) {
377
- const search = query ? stringifyQuery(query) : "";
378
- return `${this.options.baseUrl}${path}${search ? `?${search}` : ""}`;
483
+ const search = [query, this.call.extraQuery].map((values) => values ? stringifyQuery(values) : "").filter(Boolean).join("&");
484
+ const separator = path.includes("?") ? "&" : "?";
485
+ return `${this.options.baseUrl}${path}${search ? `${separator}${search}` : ""}`;
379
486
  }
380
487
  /** A JSON request whose deadline covers reading the response. */
381
488
  json(method, path, { query, body, headers, idempotencyKey } = {}) {
489
+ const sent = this.callBody(method, body);
382
490
  return this.transport.json({
491
+ ...this.callRequest(),
383
492
  method,
384
493
  url: this.url(path, query),
385
- headers: body === void 0 ? headers : {
494
+ headers: this.callHeaders(sent === void 0 ? headers : {
386
495
  ...headers,
387
496
  "Content-Type": "application/json"
388
- },
389
- body: body === void 0 ? void 0 : JSON.stringify(body),
390
- idempotencyKey,
497
+ }),
498
+ body: sent === void 0 ? void 0 : JSON.stringify(sent),
499
+ idempotencyKey: idempotencyKey ?? this.call.idempotencyKey,
391
500
  timeoutMs: this.timeoutMs,
392
501
  deadline: "body"
393
502
  });
394
503
  }
395
504
  upload(url, body, headers, idempotencyKey, text) {
396
505
  return this.transport.json({
506
+ ...this.callRequest(),
397
507
  method: "POST",
398
508
  url,
399
- headers,
509
+ headers: this.callHeaders(headers),
400
510
  body,
401
511
  idempotencyKey,
402
- timeoutMs: text ? this.timeoutMs : this.options.uploadTimeoutMs,
512
+ timeoutMs: text ? this.timeoutMs : this.call.timeoutMs ?? this.options.uploadTimeoutMs,
403
513
  deadline: "body",
404
514
  fetch: this.options.uploadFetch
405
515
  });
@@ -409,12 +519,15 @@ var CalmLensConnection = class {
409
519
  * goes as a JSON body; other content as an upload form, the asset's fields in its options part
410
520
  * and the bytes in its file part. Either way the query holds only transport values.
411
521
  */
412
- submitUpload(uploadsPath, options, wait, authHeaders = {}) {
522
+ async submitUpload(uploadsPath, options, wait, authHeaders = {}) {
413
523
  const isMultipart = "part" in options;
414
524
  const payload = isMultipart ? options.part : options.content;
415
525
  const multipartOptions = options;
416
- const idempotencyKey = options.idempotencyKey ?? newIdempotencyKey();
417
- const fields = uploadFields(options);
526
+ const idempotencyKey = options.idempotencyKey ?? this.call.idempotencyKey ?? newIdempotencyKey();
527
+ const fields = {
528
+ ...uploadFields(options),
529
+ ...this.call.extraBody
530
+ };
418
531
  if (isTextPayload(payload)) {
419
532
  const { sizeInBytes: _size, ...text } = payload;
420
533
  const body = isMultipart ? {
@@ -442,7 +555,7 @@ var CalmLensConnection = class {
442
555
  setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? multipartOptions.sizeInBytes);
443
556
  setOptionalQueryValue(query, "totalSizeInBytes", multipartOptions.totalSizeInBytes);
444
557
  }
445
- const form = toUploadForm(fields, payload);
558
+ const form = await toUploadForm(fields, payload);
446
559
  return this.upload(this.url(`${uploadsPath}?${query}`), form.body, {
447
560
  ...authHeaders,
448
561
  "Content-Type": form.contentType,
@@ -465,7 +578,7 @@ var CalmLensConnection = class {
465
578
  const source = getSplittableContent(content);
466
579
  const partSize = this.partSizeBytes;
467
580
  const count = Math.ceil(source.size / partSize);
468
- const key = idempotencyKey ?? newIdempotencyKey();
581
+ const key = idempotencyKey ?? this.call.idempotencyKey ?? newIdempotencyKey();
469
582
  const part = (partNumber) => source.slice((partNumber - 1) * partSize, Math.min(partNumber * partSize, source.size));
470
583
  const first = await this.submitUpload(uploadsPath, {
471
584
  ...fields,
@@ -480,11 +593,19 @@ var CalmLensConnection = class {
480
593
  }, wait, authHeaders);
481
594
  const assetId = expectUploadedAsset(first).id;
482
595
  onStarted?.(assetId);
596
+ const laterParts = new CalmLensConnection(this.options, void 0, { shared: {
597
+ transport: this.transport,
598
+ hooks: this.hooks,
599
+ call: {
600
+ ...this.call,
601
+ extraBody: void 0
602
+ }
603
+ } });
483
604
  let result = first;
484
605
  for (let partNumber = 2; partNumber <= count;) {
485
606
  const isFinal = partNumber === count;
486
607
  try {
487
- result = await this.uploadPart(partPath(assetId), {
608
+ result = await laterParts.uploadPart(partPath(assetId), {
488
609
  part: {
489
610
  ...part(partNumber),
490
611
  partNumber,
@@ -509,6 +630,7 @@ var CalmLensConnection = class {
509
630
  /** Uploads the next part of a multipart upload to `partPath` (`.../assets/{id}/part`). */
510
631
  uploadPart(partPath, { part, wait, idempotencyKey }, authHeaders = {}) {
511
632
  if (!part) throw invalidArgument("Part options are required");
633
+ if (this.call.extraBody) throw invalidArgument("A part's body is its bytes: extraBody can't apply");
512
634
  assertDeclaredPayloadSize(part);
513
635
  const validation = validateAssetPayload(part, {
514
636
  multipart: true,
@@ -524,7 +646,7 @@ var CalmLensConnection = class {
524
646
  return this.upload(this.url(`${partPath}?${query}`), toRawUploadBody(part), {
525
647
  ...authHeaders,
526
648
  "X-CalmLens-Upload": "part"
527
- }, idempotencyKey ?? newIdempotencyKey(), isTextPayload(part));
649
+ }, idempotencyKey ?? this.call.idempotencyKey ?? newIdempotencyKey(), isTextPayload(part));
528
650
  }
529
651
  };
530
652
  // src/client/CalmLensOptionKeys.ts
@@ -578,24 +700,6 @@ const SERVER_OPTION_KEYS = {
578
700
  "note"
579
701
  ],
580
702
  "assets.delete": ["assetId"],
581
- "assets.explain": ["assetId", "rerun"],
582
- "assets.iterate": [
583
- "cursor",
584
- "filter",
585
- "pageSize",
586
- "sort"
587
- ],
588
- "assets.iterateChildren": [
589
- "assetId",
590
- "cursor",
591
- "pageSize",
592
- "sort"
593
- ],
594
- "assets.iterateTimeline": [
595
- "assetId",
596
- "cursor",
597
- "pageSize"
598
- ],
599
703
  "assets.list": [
600
704
  "cursor",
601
705
  "filter",
@@ -663,21 +767,8 @@ const SERVER_OPTION_KEYS = {
663
767
  "pageSize",
664
768
  "types"
665
769
  ],
666
- "events.pages": [
667
- "assetId",
668
- "cursor",
669
- "pageSize",
670
- "types"
671
- ],
672
770
  "folders.create": ["name", "parentId"],
673
771
  "folders.delete": ["folderId"],
674
- "folders.iterate": [
675
- "cursor",
676
- "pageSize",
677
- "parentId",
678
- "search",
679
- "sort"
680
- ],
681
772
  "folders.list": [
682
773
  "cursor",
683
774
  "pageSize",
@@ -701,17 +792,6 @@ const SERVER_OPTION_KEYS = {
701
792
  "name"
702
793
  ],
703
794
  "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
- ],
715
795
  "hashLists.list": [
716
796
  "cursor",
717
797
  "pageSize",
@@ -740,11 +820,6 @@ const SERVER_OPTION_KEYS = {
740
820
  "type"
741
821
  ],
742
822
  "lenses.delete": ["lensId"],
743
- "lenses.iterate": [
744
- "cursor",
745
- "pageSize",
746
- "sort"
747
- ],
748
823
  "lenses.list": [
749
824
  "cursor",
750
825
  "pageSize",
@@ -770,11 +845,6 @@ const SERVER_OPTION_KEYS = {
770
845
  "settings"
771
846
  ],
772
847
  "policies.delete": ["policyId"],
773
- "policies.iterate": [
774
- "cursor",
775
- "pageSize",
776
- "sort"
777
- ],
778
848
  "policies.list": [
779
849
  "cursor",
780
850
  "pageSize",
@@ -828,11 +898,6 @@ const SERVER_OPTION_KEYS = {
828
898
  ],
829
899
  "uploadPresets.delete": ["uploadPresetId"],
830
900
  "uploadPresets.ensure": ["uploadPresets"],
831
- "uploadPresets.iterate": [
832
- "cursor",
833
- "pageSize",
834
- "sort"
835
- ],
836
901
  "uploadPresets.list": [
837
902
  "cursor",
838
903
  "pageSize",
@@ -895,7 +960,6 @@ const NULLABLE_OPTION_KEYS = {
895
960
  "uploadPresetId",
896
961
  "visibility"
897
962
  ],
898
- "assets.iterate": ["filter"],
899
963
  "assets.list": ["filter"],
900
964
  "assets.move": ["folderId"],
901
965
  "assets.update": [
@@ -926,4 +990,4 @@ const NULLABLE_OPTION_KEYS = {
926
990
  "visibility"
927
991
  ]
928
992
  };
929
- 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 };
993
+ export { validateAssetPayload as _, MOCK_HOOKS as a, getMockHooks as c, prepareSubmitAssetOptions as d, resolveConnectionOptions as f, assetToData as g, assetDataToUint8Array as h, CalmLensConnection as i, invalidPayload as l, validateCallOptions 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 };