@calmlens/sdk 0.16.2 → 0.17.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 (112) hide show
  1. package/README.md +399 -162
  2. package/cjs/BrowserUpload-DZ0Vbmxi.js +10 -0
  3. package/cjs/BrowserUpload-uZjVFGfP.d.ts +11 -0
  4. package/cjs/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  5. package/cjs/CalmLensAppClient-DBGmaDlG.js +89 -0
  6. package/cjs/CalmLensConnection-K1TAD1Z-.js +659 -0
  7. package/cjs/CalmLensServerClient-C-pxiz0C.js +645 -0
  8. package/cjs/CalmLensServerClient-JtP687a3.d.ts +235 -0
  9. package/cjs/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  10. package/cjs/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  11. package/cjs/CryptoUtils-B_x8lMIx-YBW1-bvL.js +42 -0
  12. package/cjs/FileIcons-Ob003MdS.js +175 -0
  13. package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +91 -0
  14. package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  15. package/cjs/ModerationContextLimits-Dj1YAl3G.js +1311 -0
  16. package/cjs/ReactUpload-DxtFMr06.js +54 -0
  17. package/cjs/ReactUpload-nZahpmyg.d.ts +17 -0
  18. package/cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  19. package/cjs/TestTriggers-DcArt0Nu-CvoaONUB.js +1326 -0
  20. package/cjs/UploadController-BBkN4Ni6.js +618 -0
  21. package/{esm/index-C9Xw1aid.d.ts → cjs/WebhookPayload-2aL31v0J.d.ts} +131 -155
  22. package/cjs/app.d.ts +7 -44
  23. package/cjs/app.js +11 -89
  24. package/cjs/elements.d.ts +88 -0
  25. package/cjs/elements.js +555 -0
  26. package/cjs/file-icons.d.ts +67 -0
  27. package/cjs/file-icons.js +10 -0
  28. package/cjs/index-CI4BzN4W.d.ts +252 -0
  29. package/cjs/index.d.ts +6 -4
  30. package/cjs/index.js +9 -4
  31. package/cjs/react-native.d.ts +56 -0
  32. package/cjs/react-native.js +495 -0
  33. package/cjs/react.d.ts +30 -0
  34. package/cjs/react.js +370 -0
  35. package/cjs/server.d.ts +12 -191
  36. package/cjs/server.js +18 -378
  37. package/cjs/test-inputs.d.ts +2 -2
  38. package/cjs/test-inputs.js +9 -264
  39. package/cjs/testing.d.ts +285 -190
  40. package/cjs/testing.js +2393 -1203
  41. package/cjs/ui-CgZpgpNo.d.ts +526 -0
  42. package/cjs/ui-KceuoVCM.js +583 -0
  43. package/cjs/ui.d.ts +2 -0
  44. package/cjs/ui.js +27 -0
  45. package/cjs/vue.d.ts +490 -0
  46. package/cjs/vue.js +419 -0
  47. package/esm/BrowserUpload-D7-zNmc0.js +5 -0
  48. package/esm/BrowserUpload-uZjVFGfP.d.ts +11 -0
  49. package/esm/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  50. package/esm/CalmLensAppClient-FVMwrHlH.js +84 -0
  51. package/esm/CalmLensConnection-iyNQHA8L.js +582 -0
  52. package/esm/CalmLensServerClient-JtP687a3.d.ts +235 -0
  53. package/esm/CalmLensServerClient-fQEYKLw4.js +586 -0
  54. package/esm/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  55. package/esm/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  56. package/esm/CryptoUtils-B_x8lMIx-DhuWGzqn.js +25 -0
  57. package/esm/FileIcons-M6dzjFxd.js +128 -0
  58. package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +46 -0
  59. package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  60. package/esm/ModerationContextLimits-D1x_WAtP.js +1114 -0
  61. package/esm/ReactUpload-D6yBCkcw.js +37 -0
  62. package/esm/ReactUpload-nZahpmyg.d.ts +17 -0
  63. package/esm/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  64. package/esm/TestTriggers-DcArt0Nu-s0AQZuWE.js +1266 -0
  65. package/esm/UploadController-txp5NuzH.js +589 -0
  66. package/{cjs/index-C9Xw1aid.d.ts → esm/WebhookPayload-2aL31v0J.d.ts} +131 -155
  67. package/esm/app.d.ts +7 -44
  68. package/esm/app.js +3 -86
  69. package/esm/elements.d.ts +88 -0
  70. package/esm/elements.js +528 -0
  71. package/esm/file-icons.d.ts +67 -0
  72. package/esm/file-icons.js +1 -0
  73. package/esm/index-CI4BzN4W.d.ts +252 -0
  74. package/esm/index.d.ts +6 -4
  75. package/esm/index.js +1 -1
  76. package/esm/react-native.d.ts +56 -0
  77. package/esm/react-native.js +467 -0
  78. package/esm/react.d.ts +30 -0
  79. package/esm/react.js +343 -0
  80. package/esm/server.d.ts +12 -191
  81. package/esm/server.js +3 -369
  82. package/esm/styles.css +147 -0
  83. package/esm/svelte/CalmLensMedia.svelte +134 -0
  84. package/esm/svelte/CalmLensUploader.svelte +175 -0
  85. package/esm/svelte/Icon.svelte +7 -0
  86. package/esm/svelte/index.d.ts +37 -0
  87. package/esm/svelte/index.js +6 -0
  88. package/esm/test-inputs.d.ts +2 -2
  89. package/esm/test-inputs.js +1 -256
  90. package/esm/testing.d.ts +285 -190
  91. package/esm/testing.js +2329 -1122
  92. package/esm/ui-Ca_SpJXf.js +458 -0
  93. package/esm/ui-CgZpgpNo.d.ts +526 -0
  94. package/esm/ui.d.ts +2 -0
  95. package/esm/ui.js +3 -0
  96. package/esm/vue.d.ts +490 -0
  97. package/esm/vue.js +392 -0
  98. package/package.json +110 -11
  99. package/cjs/CalmLensConnection-5Hj3trGr.js +0 -234
  100. package/cjs/CalmLensUtils-BeIl1N6N.js +0 -699
  101. package/cjs/CalmLensVersion-BGpB9t4-.js +0 -480
  102. package/cjs/CalmLensWebhooks-CogUYk8-.js +0 -201
  103. package/cjs/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
  104. package/cjs/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
  105. package/cjs/WebhookPayload-CJoIkGBD.d.ts +0 -11753
  106. package/esm/CalmLensConnection-BAJdoZHy.js +0 -193
  107. package/esm/CalmLensUtils-DqniTKJ8.js +0 -574
  108. package/esm/CalmLensVersion-l_khh4nS.js +0 -415
  109. package/esm/CalmLensWebhooks-BtrKKLvg.js +0 -148
  110. package/esm/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
  111. package/esm/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
  112. package/esm/WebhookPayload-CJoIkGBD.d.ts +0 -11753
package/cjs/vue.js ADDED
@@ -0,0 +1,419 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_ui = require("./ui-KceuoVCM.js");
3
+ const require_UploadController = require("./UploadController-BBkN4Ni6.js");
4
+ const require_BrowserUpload = require("./BrowserUpload-DZ0Vbmxi.js");
5
+ let vue = require("vue");
6
+ // src/vue.ts
7
+ const icon = (name) => (0, vue.h)("svg", require_ui.ICON_ATTRIBUTES, [(0, vue.h)("path", { d: require_ui.ICONS[name] })]);
8
+ /** Keeps a ref to a controller's snapshot, following the controller if it changes. */
9
+ const subscribeSnapshot = (controller) => {
10
+ const snapshot = (0, vue.shallowRef)((0, vue.toValue)(controller).getSnapshot());
11
+ (0, vue.watch)(() => (0, vue.toValue)(controller), (current, _previous, onCleanup) => {
12
+ onCleanup(current.subscribe((next) => {
13
+ snapshot.value = next;
14
+ }));
15
+ }, { immediate: true });
16
+ return snapshot;
17
+ };
18
+ /**
19
+ * Uploads files through an upload preset and keeps `snapshot` up to date as each one uploads and
20
+ * is checked. Use it to build your own upload UI; `CalmLensUploader` is built on it. Uploads
21
+ * still running when the component unmounts are cancelled.
22
+ */
23
+ const useCalmLensUpload = (options) => {
24
+ const controller = require_UploadController.createUploadController((0, vue.toValue)(options));
25
+ (0, vue.watchEffect)(() => controller.setOptions((0, vue.toValue)(options)));
26
+ const snapshot = subscribeSnapshot(controller);
27
+ (0, vue.onScopeDispose)(() => controller.clear());
28
+ return {
29
+ snapshot,
30
+ controller,
31
+ addFiles: (files) => controller.addFiles(files),
32
+ retry: (key) => controller.retry(key),
33
+ cancel: (key) => controller.cancel(key),
34
+ remove: (key) => controller.remove(key),
35
+ clear: () => controller.clear(),
36
+ start: () => controller.start()
37
+ };
38
+ };
39
+ const optional = (type) => ({
40
+ type,
41
+ default: void 0
42
+ });
43
+ const messagesProp = optional(Object);
44
+ /**
45
+ * A drop zone and file list that uploads through an upload preset, shows each file's progress
46
+ * and moderation decision, and emits `uploaded` for finished uploads.
47
+ */
48
+ const CalmLensUploader = (0, vue.defineComponent)({
49
+ name: "CalmLensUploader",
50
+ props: {
51
+ uploadPresetId: optional(String),
52
+ upload: optional(Function),
53
+ checkStatus: optional(Function),
54
+ createClient: optional(Function),
55
+ token: optional([String, Function]),
56
+ tokenUrl: optional(String),
57
+ accept: optional(String),
58
+ maxFileSize: optional(Number),
59
+ autoUpload: {
60
+ type: Boolean,
61
+ default: true
62
+ },
63
+ multiple: {
64
+ type: Boolean,
65
+ default: false
66
+ },
67
+ maxFiles: optional(Number),
68
+ concurrency: optional(Number),
69
+ decisionTimeoutMs: optional(Number),
70
+ baseUrl: optional(String),
71
+ disabled: {
72
+ type: Boolean,
73
+ default: false
74
+ },
75
+ capture: optional(String),
76
+ messages: messagesProp,
77
+ controller: optional(Object)
78
+ },
79
+ emits: {
80
+ uploaded: (_upload) => true,
81
+ rejected: (_item) => true,
82
+ failed: (_item) => true,
83
+ removed: (_item) => true
84
+ },
85
+ setup(props, { emit }) {
86
+ const own = useCalmLensUpload(() => ({
87
+ uploadPresetId: props.uploadPresetId,
88
+ upload: props.upload,
89
+ checkStatus: props.checkStatus,
90
+ createClient: props.createClient,
91
+ token: props.token,
92
+ tokenUrl: props.tokenUrl,
93
+ accept: props.accept,
94
+ maxFileSize: props.maxFileSize,
95
+ autoUpload: props.autoUpload,
96
+ multiple: props.multiple,
97
+ maxFiles: props.maxFiles,
98
+ concurrency: props.concurrency,
99
+ decisionTimeoutMs: props.decisionTimeoutMs,
100
+ baseUrl: props.baseUrl,
101
+ onUploaded: (value) => emit("uploaded", value),
102
+ onRejected: (item) => emit("rejected", item),
103
+ onFailed: (item) => emit("failed", item),
104
+ onRemoved: (item) => emit("removed", item)
105
+ }));
106
+ const controller = (0, vue.computed)(() => props.controller ?? own.controller);
107
+ const snapshot = subscribeSnapshot(controller);
108
+ const messages = (0, vue.computed)(() => require_ui.resolveMessages(props.messages));
109
+ const dragging = (0, vue.ref)(false);
110
+ const input = (0, vue.ref)();
111
+ const openPicker = () => {
112
+ if (!props.disabled) input.value?.click();
113
+ };
114
+ const onDragOver = (event) => {
115
+ event.preventDefault();
116
+ if (!props.disabled) dragging.value = true;
117
+ };
118
+ return () => {
119
+ const text = messages.value;
120
+ const queue = controller.value;
121
+ const { accept, multiple } = queue.options;
122
+ const items = snapshot.value.items;
123
+ const view = require_ui.describeUploader(snapshot.value, queue.options, text);
124
+ return (0, vue.h)("div", { class: "calmlens-uploader" }, [
125
+ view.showDropzone && (0, vue.h)("div", {
126
+ class: "calmlens-dropzone",
127
+ "data-dragging": dragging.value || void 0,
128
+ "data-disabled": props.disabled || void 0,
129
+ onClick: openPicker,
130
+ onDragover: onDragOver,
131
+ onDragenter: onDragOver,
132
+ onDragleave: (event) => {
133
+ if (!event.currentTarget.contains(event.relatedTarget)) dragging.value = false;
134
+ },
135
+ onDrop: (event) => {
136
+ event.preventDefault();
137
+ dragging.value = false;
138
+ if (!props.disabled && event.dataTransfer) queue.addFiles(event.dataTransfer.files);
139
+ },
140
+ onPaste: (event) => {
141
+ const files = event.clipboardData?.files;
142
+ if (!props.disabled && files?.length) queue.addFiles(files);
143
+ }
144
+ }, [
145
+ (0, vue.h)("span", { class: "calmlens-dropzone__icon" }, [icon("upload")]),
146
+ (0, vue.h)("div", { class: "calmlens-dropzone__text" }, [(0, vue.h)("p", { class: "calmlens-dropzone__title" }, dragging.value ? text.dropzoneTitleDragging : text.dropzoneTitle), view.hint && (0, vue.h)("p", { class: "calmlens-dropzone__hint" }, view.hint)]),
147
+ (0, vue.h)("button", {
148
+ type: "button",
149
+ class: "calmlens-button",
150
+ "data-variant": "outline",
151
+ disabled: props.disabled,
152
+ onClick: (event) => {
153
+ event.stopPropagation();
154
+ openPicker();
155
+ }
156
+ }, view.chooseLabel)
157
+ ]),
158
+ (0, vue.h)("input", {
159
+ ref: input,
160
+ type: "file",
161
+ hidden: true,
162
+ accept,
163
+ multiple,
164
+ capture: props.capture,
165
+ disabled: props.disabled,
166
+ onChange: (event) => {
167
+ const target = event.target;
168
+ if (target.files) queue.addFiles(target.files);
169
+ target.value = "";
170
+ }
171
+ }),
172
+ items.length > 0 && (0, vue.h)("ul", { class: "calmlens-uploads" }, items.map((item) => {
173
+ const itemView = require_ui.describeUploadItem(item, text);
174
+ return (0, vue.h)("li", {
175
+ key: item.key,
176
+ class: "calmlens-upload",
177
+ "data-stage": item.stage,
178
+ "data-outcome": itemView.outcome
179
+ }, [
180
+ item.previewUrl ? (0, vue.h)("img", {
181
+ class: "calmlens-upload__thumb",
182
+ src: item.previewUrl,
183
+ alt: ""
184
+ }) : (0, vue.h)("span", {
185
+ class: "calmlens-upload__thumb",
186
+ "data-kind": "file",
187
+ "aria-hidden": "true",
188
+ innerHTML: itemView.fileIcon
189
+ }),
190
+ (0, vue.h)("div", { class: "calmlens-upload__body" }, [
191
+ (0, vue.h)("span", { class: "calmlens-upload__name" }, item.file.name),
192
+ (0, vue.h)("span", { class: "calmlens-upload__size" }, itemView.size),
193
+ itemView.busy && (0, vue.h)("div", {
194
+ class: "calmlens-progress",
195
+ role: "progressbar",
196
+ "aria-label": itemView.message,
197
+ "aria-valuemin": 0,
198
+ "aria-valuemax": 100,
199
+ "aria-valuenow": itemView.progressPercent
200
+ }, [(0, vue.h)("div", {
201
+ class: "calmlens-progress__bar",
202
+ style: itemView.progressPercent === void 0 ? void 0 : { width: `${itemView.progressPercent}%` }
203
+ })]),
204
+ itemView.message && (0, vue.h)("p", {
205
+ class: "calmlens-upload__message",
206
+ role: "status"
207
+ }, itemView.message)
208
+ ]),
209
+ (0, vue.h)("div", { class: "calmlens-upload__actions" }, [
210
+ !view.showDropzone && (0, vue.h)("button", {
211
+ type: "button",
212
+ class: "calmlens-button",
213
+ "data-variant": "outline",
214
+ "data-size": "small",
215
+ disabled: props.disabled,
216
+ onClick: openPicker
217
+ }, text.chooseAnother),
218
+ itemView.canRetry && (0, vue.h)("button", {
219
+ type: "button",
220
+ class: "calmlens-icon-button",
221
+ "aria-label": text.retry,
222
+ title: text.retry,
223
+ onClick: () => queue.retry(item.key)
224
+ }, [icon("retry")]),
225
+ (0, vue.h)("button", {
226
+ type: "button",
227
+ class: "calmlens-icon-button",
228
+ "aria-label": itemView.removeLabel,
229
+ title: itemView.removeLabel,
230
+ onClick: () => queue.remove(item.key)
231
+ }, [icon("remove")])
232
+ ])
233
+ ]);
234
+ }))
235
+ ]);
236
+ };
237
+ }
238
+ });
239
+ /**
240
+ * Shows an asset from the CalmLens CDN with responsive widths and a blurred placeholder while
241
+ * it loads. Age-restricted assets stay behind the placeholder and a reveal button until
242
+ * `ageConfirmed` is set; blocked and purged assets show an unavailable notice.
243
+ */
244
+ const CalmLensMedia = (0, vue.defineComponent)({
245
+ name: "CalmLensMedia",
246
+ props: {
247
+ /** An asset from the API, which supplies the project, ID, status, type and preview. */
248
+ asset: optional(Object),
249
+ /** Required without `asset`. */
250
+ projectId: optional(String),
251
+ /** Required without `asset`. */
252
+ assetId: optional(String),
253
+ status: optional(String),
254
+ contentRemoved: optional(Boolean),
255
+ type: optional(String),
256
+ resource: optional(String),
257
+ lens: optional(String),
258
+ transform: optional([
259
+ String,
260
+ Object,
261
+ Array
262
+ ]),
263
+ widths: optional(Array),
264
+ url: optional(String),
265
+ placeholder: {
266
+ type: Boolean,
267
+ default: true
268
+ },
269
+ placeholderHash: optional(String),
270
+ placeholderUrl: optional(String),
271
+ averageColor: optional(String),
272
+ cdnBaseUrl: optional(String),
273
+ viewerClaims: optional(Object),
274
+ alt: {
275
+ type: String,
276
+ default: ""
277
+ },
278
+ aspectRatio: optional(Number),
279
+ width: optional(Number),
280
+ height: optional(Number),
281
+ sizes: optional(String),
282
+ fit: optional(String),
283
+ position: optional(String),
284
+ lazy: {
285
+ type: Boolean,
286
+ default: true
287
+ },
288
+ fetchPriority: optional(String),
289
+ controls: {
290
+ type: Boolean,
291
+ default: true
292
+ },
293
+ messages: messagesProp,
294
+ /** Bound by `@reveal`; declared as a prop so the button shows only when something listens. */
295
+ onReveal: optional(Function)
296
+ },
297
+ setup(props) {
298
+ const messages = (0, vue.computed)(() => require_ui.resolveMessages(props.messages));
299
+ const resolved = (0, vue.computed)(() => require_ui.resolveMediaProps(props));
300
+ const state = (0, vue.computed)(() => require_ui.getMediaState(resolved.value));
301
+ const loadKey = (0, vue.computed)(() => require_ui.getMediaLoadKey(state.value));
302
+ const load = (0, vue.ref)("loading");
303
+ const image = (0, vue.ref)();
304
+ (0, vue.watch)(loadKey, () => {
305
+ load.value = "loading";
306
+ });
307
+ (0, vue.onMounted)(() => {
308
+ if (image.value?.complete && image.value.naturalWidth > 0) load.value = "loaded";
309
+ });
310
+ const onError = () => {
311
+ load.value = "error";
312
+ };
313
+ return () => {
314
+ const current = state.value;
315
+ const text = messages.value;
316
+ const view = resolved.value;
317
+ const ratio = require_ui.getMediaAspectRatio(view);
318
+ const failed = load.value === "error";
319
+ const placeholderUrl = current.kind === "audio" || current.kind === "unavailable" ? void 0 : current.placeholderUrl;
320
+ const showPlaceholder = placeholderUrl && (current.kind === "gated" || current.kind === "image" && load.value !== "loaded");
321
+ const notice = (children) => (0, vue.h)("figcaption", { class: "calmlens-media__notice" }, children);
322
+ return (0, vue.h)("figure", {
323
+ class: "calmlens-media",
324
+ "data-kind": current.kind,
325
+ "data-state": load.value,
326
+ "data-sized": ratio ? "" : void 0,
327
+ style: {
328
+ aspectRatio: ratio,
329
+ backgroundColor: view.averageColor,
330
+ "--calmlens-fit": props.fit,
331
+ "--calmlens-position": props.position
332
+ }
333
+ }, [
334
+ showPlaceholder && (0, vue.h)("img", {
335
+ class: "calmlens-media__placeholder",
336
+ src: placeholderUrl,
337
+ alt: "",
338
+ "aria-hidden": "true"
339
+ }),
340
+ current.kind === "image" && !failed && (0, vue.h)("img", {
341
+ key: loadKey.value,
342
+ ref: image,
343
+ class: "calmlens-media__content",
344
+ src: current.src,
345
+ srcset: current.srcSet,
346
+ sizes: props.sizes,
347
+ alt: props.alt,
348
+ width: view.width,
349
+ height: view.height,
350
+ loading: props.lazy ? "lazy" : void 0,
351
+ decoding: "async",
352
+ fetchpriority: props.fetchPriority,
353
+ onLoad: () => {
354
+ load.value = "loaded";
355
+ },
356
+ onError
357
+ }),
358
+ current.kind === "video" && !failed && (0, vue.h)("video", {
359
+ class: "calmlens-media__content",
360
+ src: current.src,
361
+ controls: props.controls,
362
+ playsinline: true,
363
+ preload: "metadata",
364
+ "aria-label": props.alt || void 0,
365
+ onError: () => {
366
+ load.value = "error";
367
+ }
368
+ }),
369
+ current.kind === "audio" && !failed && (0, vue.h)("audio", {
370
+ class: "calmlens-media__content",
371
+ src: current.src,
372
+ controls: props.controls,
373
+ preload: "metadata",
374
+ "aria-label": props.alt || void 0,
375
+ onError: () => {
376
+ load.value = "error";
377
+ }
378
+ }),
379
+ current.kind === "gated" && notice([
380
+ (0, vue.h)("strong", text.sensitiveTitle),
381
+ (0, vue.h)("p", text.sensitiveBody),
382
+ props.onReveal && (0, vue.h)("button", {
383
+ type: "button",
384
+ class: "calmlens-button",
385
+ onClick: props.onReveal
386
+ }, text.reveal)
387
+ ]),
388
+ (current.kind === "unavailable" || failed) && notice([(0, vue.h)("p", [icon("unavailable"), (0, vue.h)("span", { class: "calmlens-media__label" }, require_ui.getMediaUnavailableMessage(current, text))])])
389
+ ]);
390
+ };
391
+ }
392
+ });
393
+ exports.CALMLENS_STYLES = require_ui.CALMLENS_STYLES;
394
+ exports.CALMLENS_THEME = require_ui.CALMLENS_THEME;
395
+ exports.CalmLensMedia = CalmLensMedia;
396
+ exports.CalmLensUploader = CalmLensUploader;
397
+ exports.DEFAULT_MESSAGES = require_ui.DEFAULT_MESSAGES;
398
+ exports.ICONS = require_ui.ICONS;
399
+ exports.ICON_ATTRIBUTES = require_ui.ICON_ATTRIBUTES;
400
+ exports.UploadController = require_UploadController.UploadController;
401
+ exports.createProgressFetch = require_UploadController.createProgressFetch;
402
+ exports.createUploadController = require_BrowserUpload.createUploadController;
403
+ exports.describeUploadItem = require_ui.describeUploadItem;
404
+ exports.describeUploader = require_ui.describeUploader;
405
+ exports.formatBytes = require_ui.formatBytes;
406
+ exports.formatMessage = require_ui.formatMessage;
407
+ exports.getDropzoneHint = require_ui.getDropzoneHint;
408
+ exports.getMediaAspectRatio = require_ui.getMediaAspectRatio;
409
+ exports.getMediaLoadKey = require_ui.getMediaLoadKey;
410
+ exports.getMediaState = require_ui.getMediaState;
411
+ exports.getMediaUnavailableMessage = require_ui.getMediaUnavailableMessage;
412
+ exports.getUploadItemMessage = require_ui.getUploadItemMessage;
413
+ exports.getUploadItemOutcome = require_ui.getUploadItemOutcome;
414
+ exports.isFileAccepted = require_UploadController.isFileAccepted;
415
+ exports.pickMediaSource = require_ui.pickMediaSource;
416
+ exports.resolveMediaProps = require_ui.resolveMediaProps;
417
+ exports.resolveMessages = require_ui.resolveMessages;
418
+ exports.resolveTheme = require_ui.resolveTheme;
419
+ exports.useCalmLensUpload = useCalmLensUpload;
@@ -0,0 +1,5 @@
1
+ import { n as createUploadController$1 } from "./UploadController-txp5NuzH.js";
2
+ // src/ui/BrowserUpload.ts
3
+ /** Creates an upload queue for the browser components, such as one a form starts on submit. */
4
+ const createUploadController = (options) => createUploadController$1(options);
5
+ export { createUploadController as t };
@@ -0,0 +1,11 @@
1
+ import { F as UploadItem$1, I as UploadSnapshot$1, M as UploadController, N as UploadControllerOptions$1, O as CalmLensUpload$1, P as UploadFile, f as UploaderProps$1 } from "./ui-CgZpgpNo.js";
2
+ import { t as UseCalmLensUploadResult$1 } from "./ReactUpload-nZahpmyg.js";
3
+ type UploadItem<F extends UploadFile = File> = UploadItem$1<F>;
4
+ type CalmLensUpload<F extends UploadFile = File> = CalmLensUpload$1<F>;
5
+ type UploadSnapshot<F extends UploadFile = File> = UploadSnapshot$1<F>;
6
+ type UploadControllerOptions<F extends UploadFile = File> = UploadControllerOptions$1<F>;
7
+ type UploaderProps<F extends UploadFile = File> = UploaderProps$1<F>;
8
+ type UseCalmLensUploadResult<F extends UploadFile = File> = UseCalmLensUploadResult$1<F>;
9
+ /** Creates an upload queue for the browser components, such as one a form starts on submit. */
10
+ declare const createUploadController: <F extends UploadFile = File>(options: UploadControllerOptions<F>) => UploadController<F>;
11
+ export { UploaderProps as a, UploadSnapshot as i, UploadControllerOptions as n, UseCalmLensUploadResult as o, UploadItem as r, createUploadController as s, CalmLensUpload as t };
@@ -0,0 +1,40 @@
1
+ import { Ct as UploadAssetPartOptions, Tt as UploadedAsset, pt as RetrieveAssetOptions, w as CalmLensAppClientOptions, wt as UploadPresetSubmitAssetOptions } from "./CalmLensTypes-9Vt16pc7.js";
2
+ declare const inspectSymbol: unique symbol;
3
+ /**
4
+ * The CalmLens client for browsers and React Native apps. It uploads through an upload preset,
5
+ * with an upload token from your server when the preset requires one, and never holds an API
6
+ * key. It can upload (`assets.create`, `assets.classify`, `assets.uploadPart`) and check its own
7
+ * uploads (`assets.retrieve`). Every method throws `CalmLensError` on failure.
8
+ */
9
+ declare class CalmLensAppClient {
10
+ #private;
11
+ constructor(options: CalmLensAppClientOptions);
12
+ /** Keeps tokens out of `console.log`, `util.inspect` and `JSON.stringify`. */
13
+ [inspectSymbol](): string;
14
+ toJSON(): {
15
+ uploadPresetId: string;
16
+ baseUrl: string;
17
+ };
18
+ private get uploadsPath();
19
+ /** A fresh token for a new upload, when the client has one. */
20
+ private newUploadToken;
21
+ /** The `Authorization` header for an upload this client started. */
22
+ private authHeaders;
23
+ /** Uploads with a new token, kept for the upload's parts and status checks. */
24
+ private submit;
25
+ /** Uploads through the client's upload preset and checks those uploads. */
26
+ get assets(): {
27
+ /** Uploads a file and queues it for moderation. */
28
+ create: (options: UploadPresetSubmitAssetOptions) => Promise<UploadedAsset>;
29
+ /** Uploads a file and waits for its moderation decision. */
30
+ classify: (options: UploadPresetSubmitAssetOptions) => Promise<UploadedAsset>;
31
+ /**
32
+ * Uploads the next part of a multipart upload this client started. The upload's queue
33
+ * mode, chosen when it started, applies when the final part arrives.
34
+ */
35
+ uploadPart: ({ assetId, ...options }: UploadAssetPartOptions) => Promise<UploadedAsset>;
36
+ /** Checks an upload this client made. `status` is present when the preset shows decisions. */
37
+ retrieve: ({ assetId }: RetrieveAssetOptions) => Promise<UploadedAsset>;
38
+ };
39
+ }
40
+ export { CalmLensAppClient as t };
@@ -0,0 +1,84 @@
1
+ import { A as invalidArgument, _ as validateAppClientOptions, j as invalidConfig, l as encodePathSegment } from "./ModerationContextLimits-D1x_WAtP.js";
2
+ import { c as prepareSubmitAssetOptions, i as expectUploadedAsset, l as resolveConnectionOptions, t as CalmLensConnection } from "./CalmLensConnection-iyNQHA8L.js";
3
+ // src/client/CalmLensAppClient.ts
4
+ const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
5
+ /**
6
+ * The CalmLens client for browsers and React Native apps. It uploads through an upload preset,
7
+ * with an upload token from your server when the preset requires one, and never holds an API
8
+ * key. It can upload (`assets.create`, `assets.classify`, `assets.uploadPart`) and check its own
9
+ * uploads (`assets.retrieve`). Every method throws `CalmLensError` on failure.
10
+ */
11
+ var CalmLensAppClient = class {
12
+ #uploadPresetId;
13
+ #token;
14
+ /** The token each upload started with, for its parts and status checks. */
15
+ #uploadTokens = /* @__PURE__ */ new Map();
16
+ #connection;
17
+ constructor(options) {
18
+ validateAppClientOptions(options);
19
+ const { token, uploadPresetId, ...rest } = options;
20
+ this.#uploadPresetId = uploadPresetId;
21
+ this.#token = token;
22
+ this.#connection = new CalmLensConnection(resolveConnectionOptions(rest));
23
+ }
24
+ /** Keeps tokens out of `console.log`, `util.inspect` and `JSON.stringify`. */
25
+ [inspectSymbol]() {
26
+ return `CalmLensAppClient { uploadPresetId: ${JSON.stringify(this.#uploadPresetId)}, baseUrl: ${JSON.stringify(this.#connection.options.baseUrl)} }`;
27
+ }
28
+ toJSON() {
29
+ return {
30
+ uploadPresetId: this.#uploadPresetId,
31
+ baseUrl: this.#connection.options.baseUrl
32
+ };
33
+ }
34
+ get uploadsPath() {
35
+ return `/upload-presets/${encodeURIComponent(this.#uploadPresetId)}/assets`;
36
+ }
37
+ /** A fresh token for a new upload, when the client has one. */
38
+ async newUploadToken() {
39
+ const token = typeof this.#token === "function" ? await this.#token() : this.#token;
40
+ if (token !== void 0 && (typeof token !== "string" || !token)) throw invalidConfig("token must return a non-empty string");
41
+ return token;
42
+ }
43
+ /** The `Authorization` header for an upload this client started. */
44
+ authHeaders(assetId) {
45
+ const token = this.#uploadTokens.get(assetId);
46
+ return token ? { Authorization: `Bearer ${token}` } : {};
47
+ }
48
+ /** Uploads with a new token, kept for the upload's parts and status checks. */
49
+ async submit(options, queue) {
50
+ if (!options || typeof options !== "object") throw invalidArgument("Upload options are required");
51
+ if (!("content" in options) && !("part" in options)) throw invalidArgument("Uploads through an upload preset need content or a part");
52
+ prepareSubmitAssetOptions(options, { deferUploadChecks: this.#connection.deferUploadChecks });
53
+ const token = await this.newUploadToken();
54
+ const data = await this.#connection.submitRawUpload(this.uploadsPath, options, queue, token ? { Authorization: `Bearer ${token}` } : {});
55
+ const uploaded = expectUploadedAsset(data);
56
+ if (token) this.#uploadTokens.set(uploaded.id, token);
57
+ return uploaded;
58
+ }
59
+ /** Uploads through the client's upload preset and checks those uploads. */
60
+ get assets() {
61
+ return {
62
+ /** Uploads a file and queues it for moderation. */
63
+ create: (options) => this.submit(options, true),
64
+ /** Uploads a file and waits for its moderation decision. */
65
+ classify: (options) => this.submit(options, false),
66
+ /**
67
+ * Uploads the next part of a multipart upload this client started. The upload's queue
68
+ * mode, chosen when it started, applies when the final part arrives.
69
+ */
70
+ uploadPart: async ({ assetId, ...options }) => {
71
+ const encodedAssetId = encodePathSegment(assetId, "Asset ID");
72
+ const data = await this.#connection.uploadPart(`${this.uploadsPath}/${encodedAssetId}/part`, options, this.authHeaders(assetId));
73
+ return expectUploadedAsset(data);
74
+ },
75
+ /** Checks an upload this client made. `status` is present when the preset shows decisions. */
76
+ retrieve: async ({ assetId }) => {
77
+ const encodedAssetId = encodePathSegment(assetId, "Asset ID");
78
+ const data = await this.#connection.json("GET", `${this.uploadsPath}/${encodedAssetId}`, { headers: this.authHeaders(assetId) });
79
+ return expectUploadedAsset(data);
80
+ }
81
+ };
82
+ }
83
+ };
84
+ export { CalmLensAppClient as t };