@calmlens/sdk 0.15.0 → 0.16.2
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 +30 -10
- package/cjs/{CalmLensConnection-DoemramF.js → CalmLensConnection-5Hj3trGr.js} +2 -2
- package/cjs/{CalmLensUtils-Cv1Ylp9-.js → CalmLensUtils-BeIl1N6N.js} +7 -7
- package/cjs/{CalmLensVersion-CuxKdijk.js → CalmLensVersion-BGpB9t4-.js} +6 -1
- package/cjs/{CalmLensWebhooks-qrL-Zdu3.js → CalmLensWebhooks-CogUYk8-.js} +7 -7
- package/cjs/Classification-BNhgwGEm-DmA9VEuE.d.ts +4806 -0
- package/cjs/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +44 -0
- package/cjs/{WebhookPayload-vy8HNMaK.d.ts → WebhookPayload-CJoIkGBD.d.ts} +1019 -5100
- package/cjs/app.d.ts +4 -3
- package/cjs/app.js +3 -3
- package/cjs/{index-Dz340UQ9.d.ts → index-C9Xw1aid.d.ts} +139 -141
- package/cjs/index.d.ts +4 -3
- package/cjs/index.js +1 -1
- package/cjs/server.d.ts +8 -7
- package/cjs/server.js +17 -22
- package/cjs/test-inputs.d.ts +2 -0
- package/cjs/test-inputs.js +265 -0
- package/cjs/testing.d.ts +5 -5
- package/cjs/testing.js +7943 -101
- package/esm/{CalmLensConnection-CQLoUoBd.js → CalmLensConnection-BAJdoZHy.js} +2 -2
- package/esm/{CalmLensUtils-B3S--hBG.js → CalmLensUtils-DqniTKJ8.js} +7 -7
- package/esm/{CalmLensVersion-N71PMJAz.js → CalmLensVersion-l_khh4nS.js} +6 -1
- package/esm/{CalmLensWebhooks-BxMSx1Vm.js → CalmLensWebhooks-BtrKKLvg.js} +7 -7
- package/esm/Classification-BNhgwGEm-DmA9VEuE.d.ts +4806 -0
- package/esm/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +44 -0
- package/esm/{WebhookPayload-vy8HNMaK.d.ts → WebhookPayload-CJoIkGBD.d.ts} +1019 -5100
- package/esm/app.d.ts +4 -3
- package/esm/app.js +3 -3
- package/esm/{index-Dz340UQ9.d.ts → index-C9Xw1aid.d.ts} +139 -141
- package/esm/index.d.ts +4 -3
- package/esm/index.js +1 -1
- package/esm/server.d.ts +8 -7
- package/esm/server.js +17 -22
- package/esm/test-inputs.d.ts +2 -0
- package/esm/test-inputs.js +256 -0
- package/esm/testing.d.ts +5 -5
- package/esm/testing.js +7922 -80
- package/package.json +19 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as invalidArgument, o as CalmLensError, s as SDK_ERROR_CODES, u as API_ERROR_CODES } from "./CalmLensVersion-
|
|
2
|
-
import { a as stringifyQuery, b as getRejectedUploadMimeTypeError, d as CalmLensTransport, g as validateAssetPayload, h as getAssetPayloadByteLength, i as randomUuid, m as assetToData, v as MAX_IMAGE_UPLOAD_BYTES, x as isRejectedUploadMimeType, y as MIN_MULTIPART_IMAGE_UPLOAD_BYTES } from "./CalmLensUtils-
|
|
1
|
+
import { c as invalidArgument, o as CalmLensError, s as SDK_ERROR_CODES, u as API_ERROR_CODES } from "./CalmLensVersion-l_khh4nS.js";
|
|
2
|
+
import { a as stringifyQuery, b as getRejectedUploadMimeTypeError, d as CalmLensTransport, g as validateAssetPayload, h as getAssetPayloadByteLength, i as randomUuid, m as assetToData, v as MAX_IMAGE_UPLOAD_BYTES, x as isRejectedUploadMimeType, y as MIN_MULTIPART_IMAGE_UPLOAD_BYTES } from "./CalmLensUtils-DqniTKJ8.js";
|
|
3
3
|
//#region src/client/CalmLensConnection.ts
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 12e4;
|
|
5
5
|
const DEFAULT_MAX_RETRIES = 2;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { c as invalidArgument, l as invalidConfig, n as getUserAgent, o as CalmLensError, r as isBrowserRuntime, s as SDK_ERROR_CODES, u as API_ERROR_CODES } from "./CalmLensVersion-
|
|
1
|
+
import { c as invalidArgument, l as invalidConfig, n as getUserAgent, o as CalmLensError, r as isBrowserRuntime, s as SDK_ERROR_CODES, u as API_ERROR_CODES } from "./CalmLensVersion-l_khh4nS.js";
|
|
2
|
+
//#region src/contract/SharedConstants-Dn7ZJF5S.js
|
|
2
3
|
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
3
4
|
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
4
5
|
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
@@ -15,7 +16,7 @@ const isRejectedUploadMimeType = (mimeType) => REJECTED_UPLOAD_MIME_TYPE_SET.has
|
|
|
15
16
|
const getRejectedUploadMimeTypeError = (mimeType) => `${normalizeUploadMimeType(mimeType)} is not a valid upload file type. Uploads must use a concrete file MIME type that CalmLens can store and process, such as image/png, image/jpeg, application/pdf, or text/plain.`;
|
|
16
17
|
const DOMAIN = "calmlens.com";
|
|
17
18
|
//#endregion
|
|
18
|
-
//#region
|
|
19
|
+
//#region src/contract/AssetPayload.js
|
|
19
20
|
const uint8ArrayInputToNumbers = (value) => {
|
|
20
21
|
if (Array.isArray(value)) return value;
|
|
21
22
|
return Array.from(value);
|
|
@@ -505,15 +506,14 @@ const serializeTransform = (transform) => {
|
|
|
505
506
|
};
|
|
506
507
|
/** Returns the selector string the API and CDN accept for a string or structured transform. */
|
|
507
508
|
const transformSelector = (transform) => transform === void 0 || typeof transform === "string" ? transform : serializeTransform(transform);
|
|
508
|
-
/** Appends a CDN lens (`/@name`)
|
|
509
|
+
/** Appends a CDN lens (`/@name`) followed by any direct transform selector to an asset URL. */
|
|
509
510
|
const appendCdnSelector = (url, options) => {
|
|
510
|
-
if (options.lens
|
|
511
|
-
if (options.lens) return `${url}/@${encodePathSegment(options.lens, "Lens")}`;
|
|
511
|
+
if (options.lens) url = `${url}/@${encodePathSegment(options.lens, "Lens")}`;
|
|
512
512
|
if (!options.transform) return url;
|
|
513
|
-
if (typeof options.transform !== "string") return `${url}
|
|
513
|
+
if (typeof options.transform !== "string") return `${url}${options.lens ? "," : "/"}${serializeTransform(options.transform)}`;
|
|
514
514
|
const transform = options.transform.replace(/^\/+/, "");
|
|
515
515
|
if (transform.includes("..") || transform.includes("?") || transform.includes("#")) throw invalidArgument("Transform cannot contain \"..\", \"?\" or \"#\"");
|
|
516
|
-
return `${url}
|
|
516
|
+
return `${url}${options.lens ? "," : "/"}${encodeURI(transform).replace(/%5B/g, "[").replace(/%5D/g, "]")}`;
|
|
517
517
|
};
|
|
518
518
|
const appendQueryValue = (parts, key, value) => {
|
|
519
519
|
if (value === void 0 || value === null) return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/client/CalmLensErrorCodes.ts
|
|
2
2
|
/** Error codes the CalmLens API documents, by name. */
|
|
3
3
|
const API_ERROR_CODES = {
|
|
4
|
+
INVALID_CURSOR: "validation/invalid-cursor",
|
|
4
5
|
MISSING_TOKEN: "auth/missing-token",
|
|
5
6
|
INVALID_API_KEY: "auth/invalid-api-key",
|
|
6
7
|
API_KEY_PROJECT_MISMATCH: "auth/project-mismatch",
|
|
@@ -63,6 +64,10 @@ const API_ERROR_CODES = {
|
|
|
63
64
|
};
|
|
64
65
|
/** The HTTP status and default message the API returns with each documented error code. */
|
|
65
66
|
const API_ERROR_DEFINITIONS = {
|
|
67
|
+
"validation/invalid-cursor": {
|
|
68
|
+
status: 400,
|
|
69
|
+
message: "The cursor is invalid or belongs to a different query."
|
|
70
|
+
},
|
|
66
71
|
"auth/missing-token": {
|
|
67
72
|
status: 401,
|
|
68
73
|
message: "Authentication required. Send your project API key in the X-Api-Key header."
|
|
@@ -390,7 +395,7 @@ const invalidConfig = (message) => new CalmLensError(SDK_ERROR_CODES.INVALID_CON
|
|
|
390
395
|
//#endregion
|
|
391
396
|
//#region src/client/CalmLensVersion.ts
|
|
392
397
|
/** This SDK's version, from its package.json. */
|
|
393
|
-
const SDK_VERSION = "0.
|
|
398
|
+
const SDK_VERSION = "0.16.2";
|
|
394
399
|
const runtimeName = () => {
|
|
395
400
|
const runtime = globalThis;
|
|
396
401
|
if (isReactNativeRuntime()) return "react-native";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { c as invalidArgument, o as CalmLensError, s as SDK_ERROR_CODES } from "./CalmLensVersion-
|
|
2
|
-
import { n as encodePathSegment } from "./CalmLensUtils-
|
|
3
|
-
//#region
|
|
1
|
+
import { c as invalidArgument, o as CalmLensError, s as SDK_ERROR_CODES } from "./CalmLensVersion-l_khh4nS.js";
|
|
2
|
+
import { n as encodePathSegment } from "./CalmLensUtils-DqniTKJ8.js";
|
|
3
|
+
//#region src/contract/JsonUtils.js
|
|
4
4
|
const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
|
|
5
5
|
if (!nestedValue || typeof nestedValue !== "object" || Array.isArray(nestedValue)) return nestedValue;
|
|
6
6
|
return Object.fromEntries(Object.keys(nestedValue).sort().map((key) => [key, nestedValue[key]]));
|
|
7
7
|
});
|
|
8
8
|
//#endregion
|
|
9
|
-
//#region
|
|
9
|
+
//#region src/contract/CryptoUtils-Cb7_Afa0.js
|
|
10
10
|
const encoder = new TextEncoder();
|
|
11
11
|
/** Lowercase hex of `bytes`, two characters per byte. */
|
|
12
12
|
const bytesToHex = (bytes) => Array.from(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
@@ -31,7 +31,7 @@ const timingSafeEqual = (a, b) => {
|
|
|
31
31
|
return difference === 0;
|
|
32
32
|
};
|
|
33
33
|
//#endregion
|
|
34
|
-
//#region
|
|
34
|
+
//#region src/contract/UploadToken.js
|
|
35
35
|
const UPLOAD_TOKEN_PREFIX = "clut_";
|
|
36
36
|
const UPLOAD_TOKEN_MAX_TTL_SECONDS = 3600;
|
|
37
37
|
const SIGNING_CONTEXT = "calmlens-upload-token:v1:";
|
|
@@ -124,7 +124,7 @@ async function verifyWebhookSignature(options) {
|
|
|
124
124
|
/**
|
|
125
125
|
* Verifies a webhook delivery and parses its body. Throws `sdk/invalid-webhook-signature`
|
|
126
126
|
* when the signature or timestamp does not verify, and `sdk/invalid-webhook-payload` when a
|
|
127
|
-
* verified body is not a webhook event.
|
|
127
|
+
* verified body is not a webhook event. Unknown event types, fact values and fields remain available.
|
|
128
128
|
*
|
|
129
129
|
* Event types and fact keys added to CalmLens after this SDK version are returned as they are,
|
|
130
130
|
* so keep a default branch when you switch on `type`.
|
|
@@ -141,7 +141,7 @@ async function parseWebhookEvent(options) {
|
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
const candidate = event;
|
|
144
|
-
if (!candidate || typeof candidate !== "object" || typeof candidate.id !== "string" || typeof candidate.type !== "string" || typeof candidate.projectId !== "string" || !candidate.data || typeof candidate.data !== "object") throw new CalmLensError(SDK_ERROR_CODES.INVALID_WEBHOOK_PAYLOAD, { message: "Webhook body is not a CalmLens event" });
|
|
144
|
+
if (!candidate || typeof candidate !== "object" || typeof candidate.id !== "string" || typeof candidate.type !== "string" || typeof candidate.projectId !== "string" || !candidate.data || typeof candidate.data !== "object" || Array.isArray(candidate.data)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_WEBHOOK_PAYLOAD, { message: "Webhook body is not a CalmLens event" });
|
|
145
145
|
return event;
|
|
146
146
|
}
|
|
147
147
|
//#endregion
|