@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
@@ -1,234 +0,0 @@
1
- const require_CalmLensVersion = require("./CalmLensVersion-BGpB9t4-.js");
2
- const require_CalmLensUtils = require("./CalmLensUtils-BeIl1N6N.js");
3
- //#region src/client/CalmLensConnection.ts
4
- const DEFAULT_TIMEOUT_MS = 12e4;
5
- const DEFAULT_MAX_RETRIES = 2;
6
- const DEFAULT_MAX_RESPONSE_BYTES = 33554432;
7
- /**
8
- * Bytes as a fetch body. They're sent as they are rather than in a Blob: React Native can't
9
- * build a Blob from bytes, and every fetch accepts a Uint8Array.
10
- */
11
- const toBodyBytes = (value) => value.buffer instanceof ArrayBuffer ? value : Uint8Array.from(value);
12
- const toRawUploadBody = (payload) => {
13
- const data = require_CalmLensUtils.assetToData(payload);
14
- if (data instanceof Response) {
15
- if (!data.body) throw new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Response upload data must have a body" });
16
- return data.body;
17
- }
18
- if (data instanceof ArrayBuffer || data instanceof Blob) return data;
19
- if ("getReader" in data) return data;
20
- return toBodyBytes(data);
21
- };
22
- const setOptionalQueryValue = (params, key, value) => {
23
- if (value !== void 0 && value !== null) params.set(key, typeof value === "string" ? value : JSON.stringify(value));
24
- };
25
- const assertValidUploadMimeType = (mimeType) => {
26
- if (require_CalmLensUtils.isRejectedUploadMimeType(mimeType)) throw new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.API_ERROR_CODES.INVALID_UPLOAD_MIME_TYPE, {
27
- message: require_CalmLensUtils.getRejectedUploadMimeTypeError(mimeType),
28
- details: { mimeType }
29
- });
30
- };
31
- const isImageMimeType = (mimeType) => mimeType.toLowerCase().startsWith("image/");
32
- const invalidPayload = (message) => new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message });
33
- /** Checks upload options before anything is sent. */
34
- const prepareSubmitAssetOptions = (options) => {
35
- if (!options || typeof options !== "object") throw require_CalmLensVersion.invalidArgument("Asset options are required");
36
- if (!("content" in options) && !("url" in options) && !("part" in options)) throw invalidPayload("Either file content, URL, or multipart part is required");
37
- if (!options.name) throw invalidPayload("Asset name is required");
38
- if (!("part" in options) && "isFinal" in options) throw invalidPayload("isFinal is only valid for multipart uploads");
39
- if ("part" in options && options.part.partNumber && options.part.partNumber > 1) throw new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.API_ERROR_CODES.USE_UPLOAD_PART, { message: "Use uploadPart for multipart upload parts after the first part" });
40
- if ("content" in options) {
41
- assertValidUploadMimeType(options.content.type);
42
- if (!("plainText" in options.content)) {
43
- const validation = require_CalmLensUtils.validateAssetPayload(options.content);
44
- if (!validation.ok) throw invalidPayload(validation.error);
45
- }
46
- }
47
- if ("part" in options) {
48
- assertValidUploadMimeType(options.part.type);
49
- const partSizeInBytes = options.part.sizeInBytes ?? require_CalmLensUtils.getAssetPayloadByteLength(options.part);
50
- if (isImageMimeType(options.part.type) && partSizeInBytes !== void 0) {
51
- if (partSizeInBytes > require_CalmLensUtils.MAX_IMAGE_UPLOAD_BYTES) throw new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.API_ERROR_CODES.MULTIPART_IMAGE_TOO_LARGE, { message: "Multipart image uploads cannot exceed 20MB." });
52
- if (options.part.isFinal && partSizeInBytes < require_CalmLensUtils.MIN_MULTIPART_IMAGE_UPLOAD_BYTES) throw new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.API_ERROR_CODES.MULTIPART_IMAGE_TOO_SMALL, { message: "Multipart image uploads must total at least 10MB." });
53
- }
54
- const validation = require_CalmLensUtils.validateAssetPayload(options.part, {
55
- multipart: true,
56
- isFinal: options.part.isFinal
57
- });
58
- if (!validation.ok) throw invalidPayload(validation.error);
59
- }
60
- return options;
61
- };
62
- const newIdempotencyKey = () => require_CalmLensUtils.randomUuid();
63
- /** Text content is small, so it keeps the API deadline; binary files may be arbitrarily large. */
64
- const isTextPayload = (payload) => "plainText" in payload;
65
- const hasStringStatus = (value) => !!value && typeof value === "object" && typeof value.status === "string";
66
- const isAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id && hasStringStatus(data.processing) && hasStringStatus(data.moderation);
67
- const isUploadedAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id;
68
- const expectUploadedAsset = (data) => {
69
- if (!isUploadedAsset(data)) throw new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.SDK_ERROR_CODES.INVALID_RESPONSE, {
70
- message: "Expected an uploaded asset response",
71
- status: 200
72
- });
73
- return data;
74
- };
75
- const expectAsset = (data) => {
76
- if (!isAsset(data)) throw new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.SDK_ERROR_CODES.INVALID_RESPONSE, {
77
- message: "Expected an asset response",
78
- status: 200
79
- });
80
- return data;
81
- };
82
- /** Fills in the default API base URL and drops trailing slashes. */
83
- const resolveConnectionOptions = (options) => ({
84
- ...options,
85
- baseUrl: (options.baseUrl ?? `https://api.calmlens.com/v1`).replace(/\/+$/, "")
86
- });
87
- /** One client's transport, base URL and deadlines, and the requests both clients make. */
88
- var CalmLensConnection = class {
89
- constructor(options, apiKey) {
90
- this.options = options;
91
- const resolveFetch = () => {
92
- const fetchImpl = this.options.fetch ?? globalThis.fetch;
93
- if (typeof fetchImpl !== "function") throw new require_CalmLensVersion.CalmLensError(require_CalmLensVersion.SDK_ERROR_CODES.NO_FETCH, { message: "No fetch implementation is available; pass one as the fetch option" });
94
- return fetchImpl;
95
- };
96
- this.transport = new require_CalmLensUtils.CalmLensTransport({
97
- apiKey,
98
- fetch: ((input, init) => resolveFetch()(input, init)),
99
- signal: options.signal,
100
- maxRetries: options.maxRetries ?? DEFAULT_MAX_RETRIES,
101
- maxResponseBytes: options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES
102
- });
103
- }
104
- get timeoutMs() {
105
- return this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
106
- }
107
- url(path, query) {
108
- const search = query ? require_CalmLensUtils.stringifyQuery(query) : "";
109
- return `${this.options.baseUrl}${path}${search ? `?${search}` : ""}`;
110
- }
111
- /** A JSON request whose deadline covers reading the response. */
112
- json(method, path, { query, body, headers, idempotencyKey } = {}) {
113
- return this.transport.json({
114
- method,
115
- url: this.url(path, query),
116
- headers: body === void 0 ? headers : {
117
- ...headers,
118
- "Content-Type": "application/json"
119
- },
120
- body: body === void 0 ? void 0 : JSON.stringify(body),
121
- idempotencyKey,
122
- timeoutMs: this.timeoutMs,
123
- deadline: "body"
124
- });
125
- }
126
- upload(url, payload, headers, idempotencyKey) {
127
- return this.transport.json({
128
- method: "POST",
129
- url,
130
- headers,
131
- body: toRawUploadBody(payload),
132
- idempotencyKey,
133
- timeoutMs: isTextPayload(payload) ? this.timeoutMs : this.options.uploadTimeoutMs,
134
- deadline: "body",
135
- fetch: this.options.uploadFetch
136
- });
137
- }
138
- /**
139
- * Uploads file content or a first multipart part to `uploadsPath` (`.../assets`), as raw
140
- * bytes with the options in the query.
141
- */
142
- submitRawUpload(uploadsPath, options, queue, authHeaders = {}) {
143
- const query = new URLSearchParams();
144
- query.set("name", options.name);
145
- query.set("queue", String(queue));
146
- setOptionalQueryValue(query, "description", options.description);
147
- setOptionalQueryValue(query, "processingOptions", options.processingOptions);
148
- setOptionalQueryValue(query, "visibility", options.visibility);
149
- setOptionalQueryValue(query, "metadata", options.metadata);
150
- setOptionalQueryValue(query, "externalId", options.externalId);
151
- setOptionalQueryValue(query, "externalUrl", options.externalUrl);
152
- setOptionalQueryValue(query, "folderId", options.folderId);
153
- setOptionalQueryValue(query, "uploadPresetId", options.uploadPresetId);
154
- const isMultipart = "part" in options;
155
- const payload = isMultipart ? options.part : options.content;
156
- query.set("contentType", payload.type);
157
- setOptionalQueryValue(query, "sizeInBytes", payload.sizeInBytes ?? require_CalmLensUtils.getAssetPayloadByteLength(payload));
158
- if (isMultipart) {
159
- const part = payload;
160
- const multipartOptions = options;
161
- query.set("partNumber", String(part.partNumber ?? 1));
162
- query.set("isFinal", String(part.isFinal ?? false));
163
- setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? multipartOptions.sizeInBytes);
164
- setOptionalQueryValue(query, "totalSizeInBytes", multipartOptions.totalSizeInBytes);
165
- }
166
- return this.upload(this.url(`${uploadsPath}?${query}`), payload, {
167
- ...authHeaders,
168
- "Content-Type": payload.type,
169
- "X-CalmLens-Upload": isMultipart ? "part" : "content"
170
- }, options.idempotencyKey ?? newIdempotencyKey());
171
- }
172
- /** Uploads the next part of a multipart upload to `partPath` (`.../assets/{id}/part`). */
173
- uploadPart(partPath, { part, queue, idempotencyKey }, authHeaders = {}) {
174
- if (!part) throw require_CalmLensVersion.invalidArgument("Part options are required");
175
- const validation = require_CalmLensUtils.validateAssetPayload(part, {
176
- multipart: true,
177
- isFinal: part.isFinal
178
- });
179
- if (!validation.ok) throw invalidPayload(validation.error);
180
- const query = new URLSearchParams({
181
- partNumber: String(part.partNumber),
182
- isFinal: String(part.isFinal ?? false)
183
- });
184
- if (queue !== void 0) query.set("queue", String(queue));
185
- setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? require_CalmLensUtils.getAssetPayloadByteLength(part));
186
- return this.upload(this.url(`${partPath}?${query}`), part, {
187
- ...authHeaders,
188
- "X-CalmLens-Upload": "part"
189
- }, idempotencyKey ?? newIdempotencyKey());
190
- }
191
- };
192
- //#endregion
193
- Object.defineProperty(exports, "CalmLensConnection", {
194
- enumerable: true,
195
- get: function() {
196
- return CalmLensConnection;
197
- }
198
- });
199
- Object.defineProperty(exports, "expectAsset", {
200
- enumerable: true,
201
- get: function() {
202
- return expectAsset;
203
- }
204
- });
205
- Object.defineProperty(exports, "expectUploadedAsset", {
206
- enumerable: true,
207
- get: function() {
208
- return expectUploadedAsset;
209
- }
210
- });
211
- Object.defineProperty(exports, "invalidPayload", {
212
- enumerable: true,
213
- get: function() {
214
- return invalidPayload;
215
- }
216
- });
217
- Object.defineProperty(exports, "newIdempotencyKey", {
218
- enumerable: true,
219
- get: function() {
220
- return newIdempotencyKey;
221
- }
222
- });
223
- Object.defineProperty(exports, "prepareSubmitAssetOptions", {
224
- enumerable: true,
225
- get: function() {
226
- return prepareSubmitAssetOptions;
227
- }
228
- });
229
- Object.defineProperty(exports, "resolveConnectionOptions", {
230
- enumerable: true,
231
- get: function() {
232
- return resolveConnectionOptions;
233
- }
234
- });