@calmlens/sdk 0.15.0 → 0.16.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 +29 -9
- package/cjs/{CalmLensConnection-DoemramF.js → CalmLensConnection-CPdx_acA.js} +2 -2
- package/cjs/{CalmLensUtils-Cv1Ylp9-.js → CalmLensUtils-DvhY8-cU.js} +1 -1
- package/cjs/{CalmLensVersion-CuxKdijk.js → CalmLensVersion-CrlGk2gX.js} +6 -1
- package/cjs/{CalmLensWebhooks-qrL-Zdu3.js → CalmLensWebhooks-C2VrleZm.js} +4 -4
- package/cjs/Classification-DJU_DfOO.d.ts +4565 -0
- package/cjs/TestTriggers-CxFZ-3uz.d.ts +43 -0
- package/cjs/{WebhookPayload-vy8HNMaK.d.ts → WebhookPayload-BfUmVu2y.d.ts} +77 -4622
- package/cjs/app.d.ts +4 -3
- package/cjs/app.js +3 -3
- package/cjs/{index-Dz340UQ9.d.ts → index-VxklV9OQ.d.ts} +4 -1
- 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 -21
- package/cjs/test-inputs.d.ts +2 -0
- package/cjs/test-inputs.js +265 -0
- package/cjs/testing.d.ts +2 -4
- package/cjs/testing.js +48 -27
- package/esm/{CalmLensConnection-CQLoUoBd.js → CalmLensConnection-DYo5U2L0.js} +2 -2
- package/esm/{CalmLensUtils-B3S--hBG.js → CalmLensUtils-BDtpOfho.js} +1 -1
- package/esm/{CalmLensVersion-N71PMJAz.js → CalmLensVersion-CchG7NWy.js} +6 -1
- package/esm/{CalmLensWebhooks-BxMSx1Vm.js → CalmLensWebhooks-B7nQMCHx.js} +4 -4
- package/esm/Classification-DJU_DfOO.d.ts +4565 -0
- package/esm/TestTriggers-CxFZ-3uz.d.ts +43 -0
- package/esm/{WebhookPayload-vy8HNMaK.d.ts → WebhookPayload-BfUmVu2y.d.ts} +77 -4622
- package/esm/app.d.ts +4 -3
- package/esm/app.js +3 -3
- package/esm/{index-Dz340UQ9.d.ts → index-VxklV9OQ.d.ts} +4 -1
- 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 -21
- package/esm/test-inputs.d.ts +2 -0
- package/esm/test-inputs.js +256 -0
- package/esm/testing.d.ts +2 -4
- package/esm/testing.js +48 -27
- package/package.json +13 -2
package/cjs/testing.js
CHANGED
|
@@ -21,9 +21,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
|
-
const require_CalmLensVersion = require("./CalmLensVersion-
|
|
25
|
-
const require_CalmLensWebhooks = require("./CalmLensWebhooks-
|
|
26
|
-
const require_CalmLensUtils = require("./CalmLensUtils-
|
|
24
|
+
const require_CalmLensVersion = require("./CalmLensVersion-CrlGk2gX.js");
|
|
25
|
+
const require_CalmLensWebhooks = require("./CalmLensWebhooks-C2VrleZm.js");
|
|
26
|
+
const require_CalmLensUtils = require("./CalmLensUtils-DvhY8-cU.js");
|
|
27
27
|
let zod = require("zod");
|
|
28
28
|
zod = __toESM(zod);
|
|
29
29
|
require("zod/v4");
|
|
@@ -581,18 +581,43 @@ const inferAssetType = (options) => {
|
|
|
581
581
|
return "file";
|
|
582
582
|
};
|
|
583
583
|
const createPage = (items, query) => {
|
|
584
|
-
const pageIndex = query.pageIndex ?? 0;
|
|
585
584
|
const pageSize = query.pageSize ?? 10;
|
|
586
|
-
if (!Number.isInteger(
|
|
587
|
-
|
|
588
|
-
|
|
585
|
+
if (!Number.isInteger(pageSize) || pageSize < 1 || pageSize > 100) throw require_CalmLensVersion.invalidArgument("Invalid page size");
|
|
586
|
+
const ordering = query.ordering?.length ? [...query.ordering] : [{
|
|
587
|
+
field: "createdAt",
|
|
588
|
+
direction: "DESC"
|
|
589
|
+
}];
|
|
590
|
+
if (ordering.some(({ field }) => field !== "createdAt" && field !== "id")) throw require_CalmLensVersion.invalidArgument("Invalid ordering");
|
|
591
|
+
if (!ordering.some(({ field }) => field === "id")) ordering.push({
|
|
592
|
+
field: "id",
|
|
593
|
+
direction: ordering[0].direction
|
|
594
|
+
});
|
|
595
|
+
let remaining = orderItems(items, ordering);
|
|
596
|
+
if (query.cursor) {
|
|
597
|
+
let values;
|
|
598
|
+
try {
|
|
599
|
+
values = JSON.parse(atob(query.cursor));
|
|
600
|
+
if (!Array.isArray(values) || values.length !== ordering.length || values.some((value, i) => ordering[i].field === "id" ? typeof value !== "string" : typeof value !== "number" || !Number.isFinite(value))) throw new Error();
|
|
601
|
+
} catch {
|
|
602
|
+
throw require_CalmLensVersion.invalidArgument("Invalid cursor");
|
|
603
|
+
}
|
|
604
|
+
remaining = remaining.filter((item) => {
|
|
605
|
+
for (const [i, rule] of ordering.entries()) {
|
|
606
|
+
const result = compareValues(item[rule.field], values[i]);
|
|
607
|
+
if (result) return rule.direction === "DESC" ? result < 0 : result > 0;
|
|
608
|
+
}
|
|
609
|
+
return false;
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
const pageItems = remaining.slice(0, pageSize);
|
|
613
|
+
const hasMore = remaining.length > pageSize;
|
|
614
|
+
const last = pageItems.at(-1);
|
|
589
615
|
return {
|
|
590
|
-
items:
|
|
591
|
-
total: items.length,
|
|
592
|
-
pageIndex,
|
|
616
|
+
items: pageItems,
|
|
593
617
|
pageSize,
|
|
594
|
-
|
|
595
|
-
|
|
618
|
+
hasMore,
|
|
619
|
+
ordering,
|
|
620
|
+
nextCursor: hasMore && last ? btoa(JSON.stringify(ordering.map(({ field }) => last[field]))) : null
|
|
596
621
|
};
|
|
597
622
|
};
|
|
598
623
|
const compareValues = (left, right) => {
|
|
@@ -930,10 +955,12 @@ var MockCalmLensServerClient = class {
|
|
|
930
955
|
}
|
|
931
956
|
}
|
|
932
957
|
async *iteratePages(listPage) {
|
|
933
|
-
|
|
934
|
-
|
|
958
|
+
let cursor;
|
|
959
|
+
for (;;) {
|
|
960
|
+
const page = await listPage(cursor);
|
|
935
961
|
yield* page.items;
|
|
936
|
-
if (!page.hasMore || page.items.length === 0) return;
|
|
962
|
+
if (!page.nextCursor || !page.hasMore || page.items.length === 0) return;
|
|
963
|
+
cursor = page.nextCursor;
|
|
937
964
|
}
|
|
938
965
|
}
|
|
939
966
|
get text() {
|
|
@@ -982,14 +1009,11 @@ var MockCalmLensServerClient = class {
|
|
|
982
1009
|
let assets = await this.databaseStorage.listAssets(this.projectId);
|
|
983
1010
|
if (options.folderId !== void 0) assets = assets.filter((asset) => (asset.folderId ?? null) === options.folderId);
|
|
984
1011
|
assets = filterAssets(assets, options.filter);
|
|
985
|
-
return createPage(
|
|
986
|
-
...options,
|
|
987
|
-
pageIndex: options.pageIndex ?? 0
|
|
988
|
-
});
|
|
1012
|
+
return createPage(assets, options);
|
|
989
1013
|
},
|
|
990
|
-
iterate: (options = {}) => this.iteratePages((
|
|
1014
|
+
iterate: (options = {}) => this.iteratePages((cursor) => this.assets.list({
|
|
991
1015
|
...options,
|
|
992
|
-
|
|
1016
|
+
cursor
|
|
993
1017
|
})),
|
|
994
1018
|
retrieve: async (options) => {
|
|
995
1019
|
this.begin("assets.retrieve", options);
|
|
@@ -1000,16 +1024,13 @@ var MockCalmLensServerClient = class {
|
|
|
1000
1024
|
const { assetId, ...options } = childrenOptions;
|
|
1001
1025
|
require_CalmLensUtils.encodePathSegment(assetId, "Asset ID");
|
|
1002
1026
|
const assets = await this.databaseStorage.listAssets(this.projectId);
|
|
1003
|
-
return createPage(
|
|
1004
|
-
...options,
|
|
1005
|
-
pageIndex: options.pageIndex ?? 0
|
|
1006
|
-
});
|
|
1027
|
+
return createPage(assets.filter((asset) => asset.parentId === assetId), options);
|
|
1007
1028
|
},
|
|
1008
1029
|
iterateChildren: (options) => {
|
|
1009
1030
|
require_CalmLensUtils.encodePathSegment(options?.assetId, "Asset ID");
|
|
1010
|
-
return this.iteratePages((
|
|
1031
|
+
return this.iteratePages((cursor) => this.assets.listChildren({
|
|
1011
1032
|
...options,
|
|
1012
|
-
|
|
1033
|
+
cursor
|
|
1013
1034
|
}));
|
|
1014
1035
|
},
|
|
1015
1036
|
update: async (options) => {
|
|
@@ -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-CchG7NWy.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-BDtpOfho.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,4 @@
|
|
|
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-CchG7NWy.js";
|
|
2
2
|
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
3
3
|
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
4
4
|
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
@@ -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.0";
|
|
394
399
|
const runtimeName = () => {
|
|
395
400
|
const runtime = globalThis;
|
|
396
401
|
if (isReactNativeRuntime()) return "react-native";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as invalidArgument, o as CalmLensError, s as SDK_ERROR_CODES } from "./CalmLensVersion-
|
|
2
|
-
import { n as encodePathSegment } from "./CalmLensUtils-
|
|
1
|
+
import { c as invalidArgument, o as CalmLensError, s as SDK_ERROR_CODES } from "./CalmLensVersion-CchG7NWy.js";
|
|
2
|
+
import { n as encodePathSegment } from "./CalmLensUtils-BDtpOfho.js";
|
|
3
3
|
//#region ../shared/src/JsonUtils.ts
|
|
4
4
|
const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
|
|
5
5
|
if (!nestedValue || typeof nestedValue !== "object" || Array.isArray(nestedValue)) return nestedValue;
|
|
@@ -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
|