@calmlens/sdk 0.16.3 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +425 -181
- package/bin/calmlens.js +16016 -0
- package/bin/package.json +1 -0
- package/cjs/BrowserUpload-BT091eOB.d.ts +11 -0
- package/cjs/BrowserUpload-CQwXEGFv.js +10 -0
- package/cjs/CalmLensAppClient-CHQGu-Do.js +89 -0
- package/cjs/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
- package/cjs/CalmLensConnection-B8Bu2j3y.js +659 -0
- package/cjs/CalmLensServerClient-C5o2A8MW.js +645 -0
- package/cjs/CalmLensServerClient-JtP687a3.d.ts +235 -0
- package/cjs/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
- package/cjs/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
- package/cjs/CryptoUtils-B_x8lMIx-YBW1-bvL.js +42 -0
- package/cjs/FileIcons-Ob003MdS.js +175 -0
- package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +91 -0
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
- package/cjs/ModerationContextLimits-DelWfmiJ.js +1311 -0
- package/cjs/ReactUpload-CAyCsyG6.d.ts +17 -0
- package/cjs/ReactUpload-Cfg5JYUq.js +54 -0
- package/cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
- package/cjs/TestTriggers-DTc_iMJF-BjMPq4_3.js +1327 -0
- package/cjs/UploadController-BGO1eyzb.js +618 -0
- package/{esm/index-C9Xw1aid.d.ts → cjs/WebhookPayload-2aL31v0J.d.ts} +131 -155
- package/cjs/app.d.ts +7 -44
- package/cjs/app.js +11 -89
- package/cjs/elements.d.ts +88 -0
- package/cjs/elements.js +555 -0
- package/cjs/file-icons.d.ts +67 -0
- package/cjs/file-icons.js +10 -0
- package/cjs/index-CI4BzN4W.d.ts +252 -0
- package/cjs/index.d.ts +6 -4
- package/cjs/index.js +9 -4
- package/cjs/react-native.d.ts +56 -0
- package/cjs/react-native.js +495 -0
- package/cjs/react.d.ts +30 -0
- package/cjs/react.js +370 -0
- package/cjs/server.d.ts +12 -191
- package/cjs/server.js +18 -378
- package/cjs/test-inputs.d.ts +2 -2
- package/cjs/test-inputs.js +9 -264
- package/cjs/testing.d.ts +285 -190
- package/cjs/testing.js +2393 -1203
- package/cjs/ui-CC1GOoMg.js +583 -0
- package/cjs/ui-wIiMfqMB.d.ts +526 -0
- package/cjs/ui.d.ts +2 -0
- package/cjs/ui.js +27 -0
- package/cjs/vue.d.ts +490 -0
- package/cjs/vue.js +419 -0
- package/esm/BrowserUpload-BT091eOB.d.ts +11 -0
- package/esm/BrowserUpload-D2xBWqhm.js +5 -0
- package/esm/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
- package/esm/CalmLensAppClient-DuFas_dW.js +84 -0
- package/esm/CalmLensConnection-MxwwLXdl.js +582 -0
- package/esm/CalmLensServerClient-D80_mKpW.js +586 -0
- package/esm/CalmLensServerClient-JtP687a3.d.ts +235 -0
- package/esm/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
- package/esm/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
- package/esm/CryptoUtils-B_x8lMIx-DhuWGzqn.js +25 -0
- package/esm/FileIcons-M6dzjFxd.js +128 -0
- package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +46 -0
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
- package/esm/ModerationContextLimits-BaX2QnU8.js +1114 -0
- package/esm/ReactUpload-CAyCsyG6.d.ts +17 -0
- package/esm/ReactUpload-CL2XC8WS.js +37 -0
- package/esm/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
- package/esm/TestTriggers-DTc_iMJF-HfB533Gx.js +1267 -0
- package/esm/UploadController-qjoYGCwx.js +589 -0
- package/{cjs/index-C9Xw1aid.d.ts → esm/WebhookPayload-2aL31v0J.d.ts} +131 -155
- package/esm/app.d.ts +7 -44
- package/esm/app.js +3 -86
- package/esm/elements.d.ts +88 -0
- package/esm/elements.js +528 -0
- package/esm/file-icons.d.ts +67 -0
- package/esm/file-icons.js +1 -0
- package/esm/index-CI4BzN4W.d.ts +252 -0
- package/esm/index.d.ts +6 -4
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +56 -0
- package/esm/react-native.js +467 -0
- package/esm/react.d.ts +30 -0
- package/esm/react.js +343 -0
- package/esm/server.d.ts +12 -191
- package/esm/server.js +3 -369
- package/esm/styles.css +147 -0
- package/esm/svelte/CalmLensMedia.svelte +134 -0
- package/esm/svelte/CalmLensUploader.svelte +175 -0
- package/esm/svelte/Icon.svelte +7 -0
- package/esm/svelte/index.d.ts +37 -0
- package/esm/svelte/index.js +6 -0
- package/esm/test-inputs.d.ts +2 -2
- package/esm/test-inputs.js +1 -256
- package/esm/testing.d.ts +285 -190
- package/esm/testing.js +2329 -1122
- package/esm/ui-CCY3yXFn.js +458 -0
- package/esm/ui-wIiMfqMB.d.ts +526 -0
- package/esm/ui.d.ts +2 -0
- package/esm/ui.js +3 -0
- package/esm/vue.d.ts +490 -0
- package/esm/vue.js +392 -0
- package/package.json +118 -13
- package/cjs/CalmLensConnection-BNUHp_AQ.js +0 -234
- package/cjs/CalmLensUtils-o171ownK.js +0 -699
- package/cjs/CalmLensVersion-DwhgxQK5.js +0 -480
- package/cjs/CalmLensWebhooks-BKrq30Yp.js +0 -201
- package/cjs/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
- package/cjs/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
- package/cjs/WebhookPayload-CJoIkGBD.d.ts +0 -11753
- package/esm/CalmLensConnection-XTqmlwzG.js +0 -193
- package/esm/CalmLensUtils-DsF8Aa_x.js +0 -574
- package/esm/CalmLensVersion-DcifRKsx.js +0 -415
- package/esm/CalmLensWebhooks-BvGyk5d3.js +0 -148
- package/esm/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
- package/esm/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
- package/esm/WebhookPayload-CJoIkGBD.d.ts +0 -11753
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
const require_CalmLensVersion = require("./CalmLensVersion-DwhgxQK5.js");
|
|
2
|
-
const require_CalmLensUtils = require("./CalmLensUtils-o171ownK.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
|
-
});
|