calmlens 0.25.0 → 0.27.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.
- package/README.md +15 -15
- package/bin/calmlens.js +2383 -677
- package/cjs/{BrowserUpload-AO2-2U5Z.js → BrowserUpload-CTqIjCV5.js} +1 -1
- package/{esm/BrowserUpload-D2lemMIU.d.ts → cjs/BrowserUpload-D4sEmd0X.d.ts} +2 -2
- package/{esm/CalmLensAppClient-Dt0t9Bk6.d.ts → cjs/CalmLensAppClient-CCeFnKX8.d.ts} +5 -11
- package/cjs/{CalmLensAppClient-nv6qwja0.js → CalmLensAppClient-CZm-9g22.js} +23 -16
- package/cjs/{CalmLensOptionKeys-BvCac9NO.js → CalmLensOptionKeys-C1w3SqmL.js} +165 -95
- package/cjs/CalmLensServerClient-B7PfocET.d.ts +346 -0
- package/cjs/{CalmLensServerClient-B60kCBCR.js → CalmLensServerClient-ucq3ITjd.js} +281 -315
- package/cjs/{CalmLensTypes-BhR7LFDu.d.ts → CalmLensTypes-HUERg5hI.d.ts} +142 -155
- package/cjs/{Classification-CxRedzgH-C9qlYW_J.d.ts → Classification-CMM2tZpJ-IdIh63n0.d.ts} +6 -7
- package/cjs/{Core-Cw4IxFUq.js → Core-D-1KCqT7.js} +39 -16
- package/cjs/{Core-DSMxC2GL.d.ts → Core-DXAs8mcx.d.ts} +10 -3
- package/{esm/ModerationContextLimits-Bqr0duav.js → cjs/ModerationContextLimits-BcYKgU2X.js} +859 -44
- package/cjs/ReactUpload-BTciTpwB.d.ts +27 -0
- package/cjs/{ReactUpload--oDFltw2.js → ReactUpload-BymgWiC8.js} +38 -2
- package/cjs/{TestTriggers-CiFcTHX3-BmfH4J3f.js → TestTriggers-Cvi7e2KA-DcT1pc_W.js} +91 -22
- package/{esm/TestTriggers-BJ4B-MXR-D1tGifPU.d.ts → cjs/TestTriggers-Dnukm-jm-DoEB7jJc.d.ts} +1 -1
- package/cjs/{UploadController-ObdgTaBl.js → UploadController-C8GPbDKI.js} +16 -3
- package/{esm/WebhookPayload-DLGGOGW6.d.ts → cjs/WebhookPayload-mUmOFH55.d.ts} +152 -9
- package/cjs/app.d.ts +6 -6
- package/cjs/app.js +20 -2
- package/cjs/elements.d.ts +5 -5
- package/cjs/elements.js +105 -68
- package/cjs/{index-AAWuerkU.d.ts → index-Ck7x1YjM.d.ts} +3 -3
- package/cjs/index.d.ts +5 -5
- package/cjs/index.js +19 -1
- package/cjs/react-native.d.ts +3 -3
- package/cjs/react-native.js +7 -5
- package/cjs/react.d.ts +5 -4
- package/cjs/react.js +11 -15
- package/cjs/server.d.ts +6 -6
- package/cjs/server.js +20 -2
- package/cjs/test-inputs.d.ts +1 -1
- package/cjs/test-inputs.js +13 -13
- package/cjs/testing.d.ts +18 -21
- package/cjs/testing.js +99 -147
- package/cjs/{ui-CcuGKTcL.d.ts → ui-BfJNO3c6.d.ts} +2 -2
- package/cjs/{ui-CA16jyfZ.js → ui-CW8BqtZk.js} +7 -5
- package/cjs/ui.d.ts +3 -3
- package/cjs/ui.js +4 -3
- package/cjs/vue.d.ts +15 -8
- package/cjs/vue.js +30 -17
- package/esm/{BrowserUpload-Co4T6uGk.js → BrowserUpload-C01iLeOs.js} +1 -1
- package/{cjs/BrowserUpload-D2lemMIU.d.ts → esm/BrowserUpload-D4sEmd0X.d.ts} +2 -2
- package/{cjs/CalmLensAppClient-Dt0t9Bk6.d.ts → esm/CalmLensAppClient-CCeFnKX8.d.ts} +5 -11
- package/esm/{CalmLensAppClient-BRzy4dwn.js → CalmLensAppClient-CgDogQQC.js} +23 -16
- package/esm/{CalmLensOptionKeys-bE3rb5PN.js → CalmLensOptionKeys-CEwNbpEz.js} +160 -96
- package/esm/CalmLensServerClient-B7PfocET.d.ts +346 -0
- package/esm/{CalmLensServerClient-_PRi90wI.js → CalmLensServerClient-TT6zrAG5.js} +281 -315
- package/esm/{CalmLensTypes-BhR7LFDu.d.ts → CalmLensTypes-HUERg5hI.d.ts} +142 -155
- package/esm/{Classification-CxRedzgH-C9qlYW_J.d.ts → Classification-CMM2tZpJ-IdIh63n0.d.ts} +6 -7
- package/esm/{Core-CtbYmeXG.js → Core-CP6NaqJz.js} +39 -16
- package/esm/{Core-DSMxC2GL.d.ts → Core-DXAs8mcx.d.ts} +10 -3
- package/{cjs/ModerationContextLimits-Cn9RvnZH.js → esm/ModerationContextLimits-BmV8QD32.js} +476 -301
- package/esm/{ReactUpload-B5itHBSF.js → ReactUpload-B72Oq3qE.js} +34 -4
- package/esm/ReactUpload-BTciTpwB.d.ts +27 -0
- package/esm/{TestTriggers-CiFcTHX3-BK2-sgOC.js → TestTriggers-Cvi7e2KA-BA83CRJb.js} +87 -23
- package/{cjs/TestTriggers-BJ4B-MXR-D1tGifPU.d.ts → esm/TestTriggers-Dnukm-jm-DoEB7jJc.d.ts} +1 -1
- package/esm/{UploadController-C7fL3Iz9.js → UploadController-Q7xTqh5w.js} +11 -4
- package/{cjs/WebhookPayload-DLGGOGW6.d.ts → esm/WebhookPayload-mUmOFH55.d.ts} +152 -9
- package/esm/app.d.ts +6 -6
- package/esm/app.js +3 -3
- package/esm/elements.d.ts +5 -5
- package/esm/elements.js +105 -69
- package/esm/{index-AAWuerkU.d.ts → index-Ck7x1YjM.d.ts} +3 -3
- package/esm/index.d.ts +5 -5
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +3 -3
- package/esm/react-native.js +6 -6
- package/esm/react.d.ts +5 -4
- package/esm/react.js +10 -16
- package/esm/server.d.ts +6 -6
- package/esm/server.js +3 -3
- package/esm/styles.css +37 -14
- package/esm/svelte/CalmLensAsset.svelte +1 -1
- package/esm/svelte/CalmLensUploader.svelte +17 -17
- package/esm/svelte/context.js +21 -0
- package/esm/svelte/index.d.ts +12 -0
- package/esm/svelte/index.js +1 -0
- package/esm/test-inputs.d.ts +1 -1
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +18 -21
- package/esm/testing.js +93 -141
- package/esm/{ui-B98AucZA.js → ui-BBDJJkFL.js} +7 -5
- package/esm/{ui-CcuGKTcL.d.ts → ui-BfJNO3c6.d.ts} +2 -2
- package/esm/ui.d.ts +3 -3
- package/esm/ui.js +4 -4
- package/esm/vue.d.ts +15 -8
- package/esm/vue.js +30 -19
- package/package.json +16 -6
- package/cjs/CalmLensServerClient-7XjQaeKu.d.ts +0 -353
- package/cjs/ReactUpload-CW4NzAsh.d.ts +0 -17
- package/esm/CalmLensServerClient-7XjQaeKu.d.ts +0 -353
- package/esm/ReactUpload-CW4NzAsh.d.ts +0 -17
|
@@ -66,9 +66,6 @@ const API_ERROR_CODES = {
|
|
|
66
66
|
ASSET_NOT_RETRYABLE: "asset/not-retryable",
|
|
67
67
|
ASSET_CONTENT_UNAVAILABLE: "asset/content-unavailable",
|
|
68
68
|
ASSET_CONTENT_PURGED: "asset/content-purged",
|
|
69
|
-
ASSET_NOT_DECIDED: "asset/not-decided",
|
|
70
|
-
ASSET_POLICY_CHANGED: "asset/policy-changed",
|
|
71
|
-
ASSET_REVIEWED: "asset/reviewed",
|
|
72
69
|
SUPPORT_TICKET_NOT_FOUND: "support-ticket/not-found",
|
|
73
70
|
DUPLICATE_EXTERNAL_ID: "asset/duplicate-external-id",
|
|
74
71
|
FOLDER_NOT_FOUND: "folder/not-found",
|
|
@@ -384,18 +381,6 @@ const API_ERROR_DEFINITIONS = {
|
|
|
384
381
|
status: 409,
|
|
385
382
|
message: "This asset's content was purged, so it can only be blocked. Upload it again to have it moderated afresh."
|
|
386
383
|
},
|
|
387
|
-
"asset/not-decided": {
|
|
388
|
-
status: 409,
|
|
389
|
-
message: "This asset has no automatic moderation decision to explain yet."
|
|
390
|
-
},
|
|
391
|
-
"asset/policy-changed": {
|
|
392
|
-
status: 409,
|
|
393
|
-
message: "The project's moderation policy has changed since this decision, so it can't be explained as made. Re-run moderation with the current policy instead."
|
|
394
|
-
},
|
|
395
|
-
"asset/reviewed": {
|
|
396
|
-
status: 409,
|
|
397
|
-
message: "A reviewer has decided this asset, so its moderation can't be re-run."
|
|
398
|
-
},
|
|
399
384
|
"support-ticket/not-found": {
|
|
400
385
|
status: 404,
|
|
401
386
|
message: "Support ticket not found."
|
|
@@ -636,6 +621,69 @@ const CALMLENS_ERROR_CODES = {
|
|
|
636
621
|
...API_ERROR_CODES,
|
|
637
622
|
...SDK_ERROR_CODES
|
|
638
623
|
};
|
|
624
|
+
const KIND_PARENTS = {
|
|
625
|
+
error: null,
|
|
626
|
+
api: "error",
|
|
627
|
+
"bad-request": "api",
|
|
628
|
+
authentication: "api",
|
|
629
|
+
"permission-denied": "api",
|
|
630
|
+
"not-found": "api",
|
|
631
|
+
conflict: "api",
|
|
632
|
+
"payload-too-large": "api",
|
|
633
|
+
"unprocessable-entity": "api",
|
|
634
|
+
"rate-limit": "api",
|
|
635
|
+
server: "api",
|
|
636
|
+
connection: "error",
|
|
637
|
+
timeout: "error",
|
|
638
|
+
cancelled: "error",
|
|
639
|
+
"invalid-argument": "error",
|
|
640
|
+
configuration: "invalid-argument",
|
|
641
|
+
"invalid-response": "error",
|
|
642
|
+
"webhook-verification": "error"
|
|
643
|
+
};
|
|
644
|
+
const STATUS_KINDS = {
|
|
645
|
+
400: "bad-request",
|
|
646
|
+
401: "authentication",
|
|
647
|
+
403: "permission-denied",
|
|
648
|
+
404: "not-found",
|
|
649
|
+
409: "conflict",
|
|
650
|
+
413: "payload-too-large",
|
|
651
|
+
422: "unprocessable-entity",
|
|
652
|
+
429: "rate-limit"
|
|
653
|
+
};
|
|
654
|
+
/** The kinds of the SDK's own codes, whatever the status. */
|
|
655
|
+
const CODE_KINDS = {
|
|
656
|
+
"sdk/transport-error": "connection",
|
|
657
|
+
"sdk/timeout": "timeout",
|
|
658
|
+
"sdk/cancelled": "cancelled",
|
|
659
|
+
"sdk/invalid-response": "invalid-response",
|
|
660
|
+
"sdk/response-too-large": "invalid-response",
|
|
661
|
+
"sdk/invalid-argument": "invalid-argument",
|
|
662
|
+
"sdk/invalid-config": "configuration",
|
|
663
|
+
"sdk/no-fetch": "configuration",
|
|
664
|
+
"sdk/invalid-webhook-signature": "webhook-verification",
|
|
665
|
+
"sdk/invalid-webhook-payload": "webhook-verification"
|
|
666
|
+
};
|
|
667
|
+
/**
|
|
668
|
+
* The kind of an error with `code` and `status`: the SDK's own codes by code; any other error by
|
|
669
|
+
* its HTTP status when the API answered (`api` for a status without a kind of its own, or a
|
|
670
|
+
* hidden one); and an error the SDK raised before sending, such as `upload/unsupported-type`, as
|
|
671
|
+
* `invalid-argument`.
|
|
672
|
+
*/
|
|
673
|
+
const errorKindOf = (code, status) => {
|
|
674
|
+
const byCode = CODE_KINDS[code];
|
|
675
|
+
if (byCode) return byCode;
|
|
676
|
+
if (status === void 0) return code === "sdk/http-error" ? "api" : "invalid-argument";
|
|
677
|
+
if (status >= 500) return "server";
|
|
678
|
+
return STATUS_KINDS[status] ?? "api";
|
|
679
|
+
};
|
|
680
|
+
/** Whether `kind` is `ancestor` or one of its descendants. */
|
|
681
|
+
const isErrorKind = (kind, ancestor) => {
|
|
682
|
+
for (let current = kind; current; current = KIND_PARENTS[current]) if (current === ancestor) return true;
|
|
683
|
+
return false;
|
|
684
|
+
};
|
|
685
|
+
/** The longest API error body an error keeps. */
|
|
686
|
+
const MAX_ERROR_BODY_LENGTH = 4096;
|
|
639
687
|
const BRAND = Symbol.for("calmlens.sdk.CalmLensError");
|
|
640
688
|
const RETRYABLE_STATUSES$1 = /* @__PURE__ */ new Set([
|
|
641
689
|
429,
|
|
@@ -658,11 +706,21 @@ const RETRYABLE_CODES = /* @__PURE__ */ new Set([
|
|
|
658
706
|
* from any copy of the SDK, so they work when ESM and CommonJS builds are loaded side by side.
|
|
659
707
|
*/
|
|
660
708
|
var CalmLensError = class CalmLensError extends Error {
|
|
709
|
+
static {
|
|
710
|
+
this.kind = "error";
|
|
711
|
+
}
|
|
661
712
|
constructor(code, options = {}) {
|
|
662
713
|
const id = typeof code === "string" ? code : code.id;
|
|
663
714
|
const defaultMessage = typeof code === "string" ? void 0 : code.defaultMessage;
|
|
664
715
|
super(`[calmlens] ${options.message ?? defaultMessage ?? id}`, { cause: options.cause });
|
|
665
|
-
|
|
716
|
+
const kind = errorKindOf(id, options.status);
|
|
717
|
+
if (new.target === CalmLensError) {
|
|
718
|
+
const KindClass = ERROR_CLASSES[kind];
|
|
719
|
+
if (KindClass !== CalmLensError) return new KindClass(code, options);
|
|
720
|
+
}
|
|
721
|
+
this.name = new.target.name;
|
|
722
|
+
this.kind = kind;
|
|
723
|
+
this.body = options.body?.slice(0, MAX_ERROR_BODY_LENGTH);
|
|
666
724
|
this.code = id;
|
|
667
725
|
this.status = options.status;
|
|
668
726
|
this.details = options.details;
|
|
@@ -675,8 +733,20 @@ var CalmLensError = class CalmLensError extends Error {
|
|
|
675
733
|
static isCalmLensError(value) {
|
|
676
734
|
return typeof value === "object" && value !== null && value[BRAND] === true;
|
|
677
735
|
}
|
|
736
|
+
/**
|
|
737
|
+
* `error instanceof CalmLensNotFoundError` (or any kind's class) is true for errors of that kind
|
|
738
|
+
* and its descendants, from any copy of the SDK.
|
|
739
|
+
*/
|
|
678
740
|
static [Symbol.hasInstance](value) {
|
|
679
|
-
|
|
741
|
+
if (!CalmLensError.isCalmLensError(value)) return false;
|
|
742
|
+
const expected = this.kind;
|
|
743
|
+
if (expected === "error") return true;
|
|
744
|
+
const { kind } = value;
|
|
745
|
+
return kind in KIND_PARENTS && isErrorKind(kind, expected);
|
|
746
|
+
}
|
|
747
|
+
/** Whether this error is of `kind` or a kind beneath it, such as `api` for a `not-found` error. */
|
|
748
|
+
isKind(kind) {
|
|
749
|
+
return isErrorKind(this.kind, kind);
|
|
680
750
|
}
|
|
681
751
|
/**
|
|
682
752
|
* Whether the SDK raised this error itself, with no HTTP response: before sending (an invalid
|
|
@@ -706,9 +776,283 @@ const invalidArgument = (message, details) => new CalmLensError(SDK_ERROR_CODES.
|
|
|
706
776
|
details
|
|
707
777
|
});
|
|
708
778
|
const invalidConfig = (message) => new CalmLensError(SDK_ERROR_CODES.INVALID_CONFIG, { message });
|
|
779
|
+
/** The API, or a proxy in front of it, answered with a non-2xx status. */
|
|
780
|
+
var CalmLensApiError = class extends CalmLensError {
|
|
781
|
+
static {
|
|
782
|
+
this.kind = "api";
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
/** HTTP 400: the request was invalid. */
|
|
786
|
+
var CalmLensBadRequestError = class extends CalmLensApiError {
|
|
787
|
+
static {
|
|
788
|
+
this.kind = "bad-request";
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
/** HTTP 401: the API key is missing or invalid. */
|
|
792
|
+
var CalmLensAuthenticationError = class extends CalmLensApiError {
|
|
793
|
+
static {
|
|
794
|
+
this.kind = "authentication";
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
/** HTTP 403: the API key lacks a grant, or the viewer can't see the asset. */
|
|
798
|
+
var CalmLensPermissionDeniedError = class extends CalmLensApiError {
|
|
799
|
+
static {
|
|
800
|
+
this.kind = "permission-denied";
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
/** HTTP 404: the resource doesn't exist or isn't visible to the API key. */
|
|
804
|
+
var CalmLensNotFoundError = class extends CalmLensApiError {
|
|
805
|
+
static {
|
|
806
|
+
this.kind = "not-found";
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
/** HTTP 409: the request conflicts with the resource's state, such as a changed revision. */
|
|
810
|
+
var CalmLensConflictError = class extends CalmLensApiError {
|
|
811
|
+
static {
|
|
812
|
+
this.kind = "conflict";
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
/** HTTP 413: the content is over a size limit. */
|
|
816
|
+
var CalmLensPayloadTooLargeError = class extends CalmLensApiError {
|
|
817
|
+
static {
|
|
818
|
+
this.kind = "payload-too-large";
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
/** HTTP 422: the content can't be processed. */
|
|
822
|
+
var CalmLensUnprocessableEntityError = class extends CalmLensApiError {
|
|
823
|
+
static {
|
|
824
|
+
this.kind = "unprocessable-entity";
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
/** HTTP 429: too many requests; `retryAfter` says how long to wait. */
|
|
828
|
+
var CalmLensRateLimitError = class extends CalmLensApiError {
|
|
829
|
+
static {
|
|
830
|
+
this.kind = "rate-limit";
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
/** HTTP 500 or above: the API failed. */
|
|
834
|
+
var CalmLensServerError = class extends CalmLensApiError {
|
|
835
|
+
static {
|
|
836
|
+
this.kind = "server";
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
/** No complete response: the connection failed or was cut (`sdk/transport-error`). */
|
|
840
|
+
var CalmLensConnectionError = class extends CalmLensError {
|
|
841
|
+
static {
|
|
842
|
+
this.kind = "connection";
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
/** A request took longer than its timeout, or a wait reached its deadline (`sdk/timeout`). */
|
|
846
|
+
var CalmLensTimeoutError = class extends CalmLensError {
|
|
847
|
+
static {
|
|
848
|
+
this.kind = "timeout";
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
/** The caller cancelled the call through a signal (`sdk/cancelled`). */
|
|
852
|
+
var CalmLensCancelledError = class extends CalmLensError {
|
|
853
|
+
static {
|
|
854
|
+
this.kind = "cancelled";
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
/** The SDK refused the call before sending anything. */
|
|
858
|
+
var CalmLensInvalidArgumentError = class extends CalmLensError {
|
|
859
|
+
static {
|
|
860
|
+
this.kind = "invalid-argument";
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
/** The client's configuration is invalid (`sdk/invalid-config`, `sdk/no-fetch`). */
|
|
864
|
+
var CalmLensConfigurationError = class extends CalmLensInvalidArgumentError {
|
|
865
|
+
static {
|
|
866
|
+
this.kind = "configuration";
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
/** A response wasn't what the operation returns (`sdk/invalid-response`, `sdk/response-too-large`). */
|
|
870
|
+
var CalmLensInvalidResponseError = class extends CalmLensError {
|
|
871
|
+
static {
|
|
872
|
+
this.kind = "invalid-response";
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
/** A webhook delivery couldn't be verified or parsed. */
|
|
876
|
+
var CalmLensWebhookVerificationError = class extends CalmLensError {
|
|
877
|
+
static {
|
|
878
|
+
this.kind = "webhook-verification";
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
/** Each kind's class. */
|
|
882
|
+
const ERROR_CLASSES = {
|
|
883
|
+
error: CalmLensError,
|
|
884
|
+
api: CalmLensApiError,
|
|
885
|
+
"bad-request": CalmLensBadRequestError,
|
|
886
|
+
authentication: CalmLensAuthenticationError,
|
|
887
|
+
"permission-denied": CalmLensPermissionDeniedError,
|
|
888
|
+
"not-found": CalmLensNotFoundError,
|
|
889
|
+
conflict: CalmLensConflictError,
|
|
890
|
+
"payload-too-large": CalmLensPayloadTooLargeError,
|
|
891
|
+
"unprocessable-entity": CalmLensUnprocessableEntityError,
|
|
892
|
+
"rate-limit": CalmLensRateLimitError,
|
|
893
|
+
server: CalmLensServerError,
|
|
894
|
+
connection: CalmLensConnectionError,
|
|
895
|
+
timeout: CalmLensTimeoutError,
|
|
896
|
+
cancelled: CalmLensCancelledError,
|
|
897
|
+
"invalid-argument": CalmLensInvalidArgumentError,
|
|
898
|
+
configuration: CalmLensConfigurationError,
|
|
899
|
+
"invalid-response": CalmLensInvalidResponseError,
|
|
900
|
+
"webhook-verification": CalmLensWebhookVerificationError
|
|
901
|
+
};
|
|
902
|
+
// src/client/CalmLensLogging.ts
|
|
903
|
+
const LOG_LEVELS = [
|
|
904
|
+
"off",
|
|
905
|
+
"info",
|
|
906
|
+
"debug"
|
|
907
|
+
];
|
|
908
|
+
/**
|
|
909
|
+
* An environment variable, in runtimes that have an environment: Node.js, Bun and Deno (with
|
|
910
|
+
* `--allow-env`). Cloudflare Workers and browsers have none, so it is `undefined` there.
|
|
911
|
+
*/
|
|
912
|
+
const readEnv = (name) => {
|
|
913
|
+
const runtime = globalThis;
|
|
914
|
+
try {
|
|
915
|
+
const value = runtime.process?.env?.[name] ?? runtime.Deno?.env?.get(name);
|
|
916
|
+
return value === void 0 || value.trim() === "" ? void 0 : value.trim();
|
|
917
|
+
} catch {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
/** The log level: the option, else `CALMLENS_LOG` from the environment, else `off`. */
|
|
922
|
+
const resolveLogLevel = (option, fromEnv) => {
|
|
923
|
+
if (option !== void 0) {
|
|
924
|
+
if (!LOG_LEVELS.includes(option)) throw invalidConfig(`logLevel must be one of ${LOG_LEVELS.join(", ")}`);
|
|
925
|
+
return option;
|
|
926
|
+
}
|
|
927
|
+
const env = fromEnv ? readEnv("CALMLENS_LOG")?.toLowerCase() : void 0;
|
|
928
|
+
return LOG_LEVELS.includes(env) ? env : "off";
|
|
929
|
+
};
|
|
930
|
+
/**
|
|
931
|
+
* One line about an attempt: what was sent where, how it ended and what happens next. It holds no
|
|
932
|
+
* API key, upload token, query (which can hold viewer claims), signed URL or body.
|
|
933
|
+
*/
|
|
934
|
+
const describeAttempt = (attempt) => {
|
|
935
|
+
const outcome = attempt.status !== null ? `HTTP ${attempt.status}` : attempt.errorCode !== null ? attempt.errorCode : "no response";
|
|
936
|
+
const parts = [
|
|
937
|
+
`[calmlens] ${attempt.operation ?? "request"} ${attempt.method} ${attempt.path}`,
|
|
938
|
+
`attempt ${attempt.attempt}`,
|
|
939
|
+
outcome,
|
|
940
|
+
`${attempt.durationMs}ms`
|
|
941
|
+
];
|
|
942
|
+
if (attempt.requestId) parts.push(`request ${attempt.requestId}`);
|
|
943
|
+
if (attempt.delayMs !== null) parts.push(`retrying in ${attempt.delayMs}ms`);
|
|
944
|
+
return parts.join(" · ");
|
|
945
|
+
};
|
|
946
|
+
// src/client/CalmLensPagination.ts
|
|
947
|
+
/** Attaches `lastResponse` to a parsed JSON result; other values are returned unchanged. */
|
|
948
|
+
const withLastResponse = (value, lastResponse) => {
|
|
949
|
+
if (value && typeof value === "object" && !Object.isFrozen(value)) Object.defineProperty(value, "lastResponse", {
|
|
950
|
+
value: lastResponse,
|
|
951
|
+
enumerable: false,
|
|
952
|
+
writable: false,
|
|
953
|
+
configurable: true
|
|
954
|
+
});
|
|
955
|
+
return value;
|
|
956
|
+
};
|
|
957
|
+
/** `value` with `from`'s `lastResponse`, for results the SDK builds from a response. */
|
|
958
|
+
const copyLastResponse = (value, from) => {
|
|
959
|
+
const lastResponse = from?.lastResponse;
|
|
960
|
+
return lastResponse ? withLastResponse(value, lastResponse) : value;
|
|
961
|
+
};
|
|
962
|
+
/** The most items `autoPagingToArray` collects; iterate with `for await` for more. */
|
|
963
|
+
const AUTO_PAGING_TO_ARRAY_MAX = 1e4;
|
|
964
|
+
/**
|
|
965
|
+
* Iterators stop rather than loop: a page that says more follow must not hand back a cursor this
|
|
966
|
+
* iteration has already sent, which would repeat the same pages forever.
|
|
967
|
+
*/
|
|
968
|
+
const assertNewCursor = (sent, cursor) => {
|
|
969
|
+
if (sent.has(cursor)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
970
|
+
message: "The API returned a cursor it had already returned, with more pages to follow",
|
|
971
|
+
details: { cursor }
|
|
972
|
+
});
|
|
973
|
+
sent.add(cursor);
|
|
974
|
+
};
|
|
975
|
+
/** The cursor each page was requested with, for iteration's repeated-cursor check. */
|
|
976
|
+
const requestCursors = /* @__PURE__ */ new WeakMap();
|
|
977
|
+
const autoPaging = (first) => {
|
|
978
|
+
async function* items() {
|
|
979
|
+
let page = await first;
|
|
980
|
+
const start = requestCursors.get(page);
|
|
981
|
+
const sent = new Set(start === void 0 ? [] : [start]);
|
|
982
|
+
for (;;) {
|
|
983
|
+
const more = page.hasNextPage();
|
|
984
|
+
if (more) assertNewCursor(sent, page.nextCursor);
|
|
985
|
+
yield* page.items;
|
|
986
|
+
if (!more) return;
|
|
987
|
+
page = await page.getNextPage();
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
return {
|
|
991
|
+
[Symbol.asyncIterator]: () => items(),
|
|
992
|
+
async autoPagingToArray(options) {
|
|
993
|
+
const limit = options?.limit;
|
|
994
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 1e4) throw invalidArgument(`autoPagingToArray needs a limit from 1 to ${AUTO_PAGING_TO_ARRAY_MAX}; iterate with for await for more`);
|
|
995
|
+
const collected = [];
|
|
996
|
+
for await (const item of items()) {
|
|
997
|
+
collected.push(item);
|
|
998
|
+
if (collected.length >= limit) break;
|
|
999
|
+
}
|
|
1000
|
+
return collected;
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
};
|
|
1004
|
+
const toListPage = (data, source, cursor) => {
|
|
1005
|
+
if (!data || typeof data !== "object" || !Array.isArray(data.items)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The API returned a list without items" });
|
|
1006
|
+
const hasNextPage = () => data.hasMore === true && typeof data.nextCursor === "string" && data.nextCursor !== "" && (source.feed || data.items.length > 0);
|
|
1007
|
+
const page = data;
|
|
1008
|
+
if (cursor !== void 0) requestCursors.set(page, cursor);
|
|
1009
|
+
const self = Promise.resolve(page);
|
|
1010
|
+
const { [Symbol.asyncIterator]: iterate, autoPagingToArray } = autoPaging(self);
|
|
1011
|
+
Object.defineProperties(page, {
|
|
1012
|
+
hasNextPage: {
|
|
1013
|
+
value: hasNextPage,
|
|
1014
|
+
configurable: true
|
|
1015
|
+
},
|
|
1016
|
+
getNextPage: {
|
|
1017
|
+
value: () => {
|
|
1018
|
+
const next = data.nextCursor ?? void 0;
|
|
1019
|
+
return list(async () => {
|
|
1020
|
+
if (!hasNextPage()) throw invalidArgument("There is no next page; check hasNextPage() first");
|
|
1021
|
+
if (next !== void 0 && next === cursor) assertNewCursor(/* @__PURE__ */ new Set([next]), next);
|
|
1022
|
+
return toListPage(await source.fetchPage(next), source, next);
|
|
1023
|
+
});
|
|
1024
|
+
},
|
|
1025
|
+
configurable: true
|
|
1026
|
+
},
|
|
1027
|
+
autoPagingToArray: {
|
|
1028
|
+
value: autoPagingToArray,
|
|
1029
|
+
configurable: true
|
|
1030
|
+
},
|
|
1031
|
+
[Symbol.asyncIterator]: {
|
|
1032
|
+
value: iterate,
|
|
1033
|
+
configurable: true
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
return page;
|
|
1037
|
+
};
|
|
1038
|
+
const list = (load) => {
|
|
1039
|
+
const first = (async () => load())();
|
|
1040
|
+
return Object.assign(first, autoPaging(first));
|
|
1041
|
+
};
|
|
1042
|
+
/**
|
|
1043
|
+
* A list call: `fetchPage` requests the page at a cursor, the first page at `cursor` (which may
|
|
1044
|
+
* be `undefined`). Failures, including invalid options, reject the promise.
|
|
1045
|
+
*/
|
|
1046
|
+
const listPages = (fetchPage, { cursor, feed = false } = {}) => {
|
|
1047
|
+
const source = {
|
|
1048
|
+
fetchPage,
|
|
1049
|
+
feed
|
|
1050
|
+
};
|
|
1051
|
+
return list(async () => toListPage(await fetchPage(cursor), source, cursor));
|
|
1052
|
+
};
|
|
709
1053
|
// src/client/CalmLensVersion.ts
|
|
710
1054
|
/** This SDK's version, from its package.json. */
|
|
711
|
-
const SDK_VERSION = "0.
|
|
1055
|
+
const SDK_VERSION = "0.27.1";
|
|
712
1056
|
const runtimeName = () => {
|
|
713
1057
|
const runtime = globalThis;
|
|
714
1058
|
if (isReactNativeRuntime()) return "react-native";
|
|
@@ -718,8 +1062,15 @@ const runtimeName = () => {
|
|
|
718
1062
|
if (runtime.process?.versions?.node) return `node/${runtime.process.versions.node}`;
|
|
719
1063
|
return "unknown";
|
|
720
1064
|
};
|
|
721
|
-
/**
|
|
722
|
-
|
|
1065
|
+
/**
|
|
1066
|
+
* The `User-Agent` the SDK sends from server runtimes, e.g. `calmlens-js/0.10.0 (node/22.12.0)`,
|
|
1067
|
+
* followed by the app's `name/version (url)` when `appInfo` names it.
|
|
1068
|
+
*/
|
|
1069
|
+
const getUserAgent = (appInfo) => {
|
|
1070
|
+
const sdk = `calmlens-js/${SDK_VERSION} (${runtimeName()})`;
|
|
1071
|
+
if (!appInfo) return sdk;
|
|
1072
|
+
return `${sdk} ${appInfo.version ? `${appInfo.name}/${appInfo.version}` : appInfo.name}${appInfo.url ? ` (${appInfo.url})` : ""}`;
|
|
1073
|
+
};
|
|
723
1074
|
/** True in a web page, where API keys would be visible to every visitor. */
|
|
724
1075
|
const isBrowserRuntime = () => typeof globalThis.window !== "undefined" && typeof globalThis.document !== "undefined";
|
|
725
1076
|
/** True in a React Native app, where an API key ships inside the app for anyone to extract. */
|
|
@@ -871,6 +1222,7 @@ const responseInfo = (response) => ({
|
|
|
871
1222
|
});
|
|
872
1223
|
/** The `CalmLensError` for a non-2xx response whose body has been read. */
|
|
873
1224
|
const toHttpError = (response, bytes) => {
|
|
1225
|
+
const body = new TextDecoder().decode(bytes.subarray(0, MAX_ERROR_BODY_LENGTH * 4)).slice(0, MAX_ERROR_BODY_LENGTH);
|
|
874
1226
|
let data;
|
|
875
1227
|
try {
|
|
876
1228
|
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
@@ -882,14 +1234,24 @@ const toHttpError = (response, bytes) => {
|
|
|
882
1234
|
message: message ?? code,
|
|
883
1235
|
...info,
|
|
884
1236
|
requestId: info.requestId ?? (typeof requestId === "string" ? requestId : void 0),
|
|
885
|
-
details
|
|
1237
|
+
details,
|
|
1238
|
+
body
|
|
886
1239
|
});
|
|
887
1240
|
}
|
|
888
1241
|
return new CalmLensError(SDK_ERROR_CODES.HTTP_ERROR, {
|
|
889
1242
|
message: `HTTP ${response.status}`,
|
|
890
|
-
...responseInfo(response)
|
|
1243
|
+
...responseInfo(response),
|
|
1244
|
+
body
|
|
891
1245
|
});
|
|
892
1246
|
};
|
|
1247
|
+
/** A URL's path without its query, which can hold viewer claims, for hooks and logs. */
|
|
1248
|
+
const pathOf = (url) => {
|
|
1249
|
+
try {
|
|
1250
|
+
return new URL(url).pathname;
|
|
1251
|
+
} catch {
|
|
1252
|
+
return url.split(/[?#]/)[0] ?? "";
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
893
1255
|
/** Sends requests with the client's credentials, deadlines, retries and response limits. */
|
|
894
1256
|
var CalmLensTransport = class {
|
|
895
1257
|
constructor(settings) {
|
|
@@ -901,12 +1263,42 @@ var CalmLensTransport = class {
|
|
|
901
1263
|
for (const [name, value] of Object.entries(request.headers ?? {})) headers.set(name, value);
|
|
902
1264
|
if (!headers.has("accept") && request.deadline === "body") headers.set("accept", "application/json");
|
|
903
1265
|
if (this.settings.apiKey) headers.set("x-api-key", this.settings.apiKey);
|
|
904
|
-
if (!isBrowserRuntime()) headers.set("user-agent", getUserAgent());
|
|
1266
|
+
if (!isBrowserRuntime()) headers.set("user-agent", getUserAgent(this.settings.appInfo));
|
|
905
1267
|
if (request.idempotencyKey) headers.set("idempotency-key", request.idempotencyKey);
|
|
906
1268
|
return Object.fromEntries(headers.entries());
|
|
907
1269
|
}
|
|
1270
|
+
/** Waits before a retry. Either the client's or the request's signal cancels the wait. */
|
|
1271
|
+
async backoff(ms, request) {
|
|
1272
|
+
const callers = createAttemptSignal(this.signalsFor(request), void 0);
|
|
1273
|
+
try {
|
|
1274
|
+
await this.sleep(ms, callers.signal);
|
|
1275
|
+
} finally {
|
|
1276
|
+
callers.release();
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
signalsFor(request) {
|
|
1280
|
+
return [
|
|
1281
|
+
this.settings.signal,
|
|
1282
|
+
request.signal,
|
|
1283
|
+
request.init?.signal ?? void 0
|
|
1284
|
+
];
|
|
1285
|
+
}
|
|
1286
|
+
maxRetriesFor(request) {
|
|
1287
|
+
return request.maxRetries ?? this.settings.maxRetries;
|
|
1288
|
+
}
|
|
1289
|
+
/** Tells the hook and the logger how an attempt went. Neither ever sees a key or a body. */
|
|
1290
|
+
report(attempt) {
|
|
1291
|
+
const { onAttempt, logger, logLevel } = this.settings;
|
|
1292
|
+
try {
|
|
1293
|
+
onAttempt?.(attempt);
|
|
1294
|
+
} catch {}
|
|
1295
|
+
if (!logger || !logLevel || logLevel === "off") return;
|
|
1296
|
+
const failed = attempt.status === null || attempt.status >= 400;
|
|
1297
|
+
if (logLevel === "debug") logger.debug(describeAttempt(attempt));
|
|
1298
|
+
else if (attempt.delayMs !== null || failed) logger.info(describeAttempt(attempt));
|
|
1299
|
+
}
|
|
908
1300
|
canRetry(request) {
|
|
909
|
-
return this.
|
|
1301
|
+
return this.maxRetriesFor(request) > 0 && (request.method === "GET" || request.method === "HEAD" || !!request.idempotencyKey) && isReplayableBody(request.body);
|
|
910
1302
|
}
|
|
911
1303
|
/**
|
|
912
1304
|
* Sends a request and returns the response, retrying transport failures, timeouts, 429, 500, 502–504 and
|
|
@@ -917,9 +1309,23 @@ var CalmLensTransport = class {
|
|
|
917
1309
|
const fetchImpl = request.fetch ?? this.settings.fetch;
|
|
918
1310
|
const retryable = this.canRetry(request);
|
|
919
1311
|
const headers = this.headersFor(request);
|
|
1312
|
+
const now = this.settings.now ?? Date.now;
|
|
1313
|
+
const path = pathOf(request.url);
|
|
920
1314
|
for (let attemptNumber = 0;; attemptNumber++) {
|
|
921
|
-
const canRetryAgain = retryable && attemptNumber < this.
|
|
922
|
-
const attempt = createAttemptSignal(
|
|
1315
|
+
const canRetryAgain = retryable && attemptNumber < this.maxRetriesFor(request);
|
|
1316
|
+
const attempt = createAttemptSignal(this.signalsFor(request), request.timeoutMs);
|
|
1317
|
+
const started = now();
|
|
1318
|
+
const report = (outcome, delayMs) => this.report({
|
|
1319
|
+
operation: request.operation ?? null,
|
|
1320
|
+
method: request.method,
|
|
1321
|
+
path,
|
|
1322
|
+
attempt: attemptNumber + 1,
|
|
1323
|
+
delayMs,
|
|
1324
|
+
status: outcome.response?.status ?? outcome.error?.status ?? null,
|
|
1325
|
+
requestId: outcome.response?.headers.get("x-request-id") ?? outcome.error?.requestId ?? null,
|
|
1326
|
+
durationMs: Math.max(0, now() - started),
|
|
1327
|
+
errorCode: outcome.error?.code ?? null
|
|
1328
|
+
});
|
|
923
1329
|
let response;
|
|
924
1330
|
try {
|
|
925
1331
|
if (attempt.signal.aborted) throw attempt.signal.reason;
|
|
@@ -944,26 +1350,36 @@ var CalmLensTransport = class {
|
|
|
944
1350
|
attempt.release();
|
|
945
1351
|
const failure = toFailure(cause, attempt);
|
|
946
1352
|
if (canRetryAgain && failure.isRetryable()) {
|
|
947
|
-
|
|
1353
|
+
const delayMs = getRetryDelayMs(attemptNumber);
|
|
1354
|
+
report({ error: failure }, delayMs);
|
|
1355
|
+
await this.backoff(delayMs, request);
|
|
948
1356
|
continue;
|
|
949
1357
|
}
|
|
1358
|
+
report({ error: failure }, null);
|
|
950
1359
|
throw failure;
|
|
951
1360
|
}
|
|
952
1361
|
if (request.deadline === "headers") attempt.clearDeadline();
|
|
953
|
-
if (response.ok)
|
|
954
|
-
response,
|
|
955
|
-
|
|
956
|
-
};
|
|
957
|
-
if (allowHttpErrors) {
|
|
958
|
-
const retryAfter = parseRetryAfter(response.headers.get("retry-after"));
|
|
959
|
-
const delayMs = retryAfter !== void 0 ? retryAfter * 1e3 : getRetryDelayMs(attemptNumber);
|
|
960
|
-
if (!canRetryAgain || !RETRYABLE_STATUSES.has(response.status) || delayMs > 6e4) return {
|
|
1362
|
+
if (response.ok) {
|
|
1363
|
+
report({ response }, null);
|
|
1364
|
+
return {
|
|
961
1365
|
response,
|
|
962
1366
|
attempt
|
|
963
1367
|
};
|
|
1368
|
+
}
|
|
1369
|
+
if (allowHttpErrors) {
|
|
1370
|
+
const retryAfter = parseRetryAfter(response.headers.get("retry-after"));
|
|
1371
|
+
const delayMs = retryAfter !== void 0 ? retryAfter * 1e3 : getRetryDelayMs(attemptNumber);
|
|
1372
|
+
if (!canRetryAgain || !RETRYABLE_STATUSES.has(response.status) || delayMs > 6e4) {
|
|
1373
|
+
report({ response }, null);
|
|
1374
|
+
return {
|
|
1375
|
+
response,
|
|
1376
|
+
attempt
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
report({ response }, delayMs);
|
|
964
1380
|
attempt.release();
|
|
965
1381
|
await response.body?.cancel().catch(() => {});
|
|
966
|
-
await this.
|
|
1382
|
+
await this.backoff(delayMs, request);
|
|
967
1383
|
continue;
|
|
968
1384
|
}
|
|
969
1385
|
let error;
|
|
@@ -976,20 +1392,26 @@ var CalmLensTransport = class {
|
|
|
976
1392
|
}
|
|
977
1393
|
const retryDelayMs = error.retryAfter !== void 0 ? error.retryAfter * 1e3 : getRetryDelayMs(attemptNumber);
|
|
978
1394
|
if (canRetryAgain && retryDelayMs <= 6e4 && error.isRetryable()) {
|
|
979
|
-
|
|
1395
|
+
report({ error }, retryDelayMs);
|
|
1396
|
+
await this.backoff(retryDelayMs, request);
|
|
980
1397
|
continue;
|
|
981
1398
|
}
|
|
1399
|
+
report({ error }, null);
|
|
982
1400
|
throw error;
|
|
983
1401
|
}
|
|
984
1402
|
}
|
|
985
|
-
/**
|
|
1403
|
+
/**
|
|
1404
|
+
* Sends a request and parses its JSON response body. An object or array result carries the
|
|
1405
|
+
* response's status, request ID and headers as its non-enumerable `lastResponse`.
|
|
1406
|
+
*/
|
|
986
1407
|
async json(request) {
|
|
987
1408
|
const { response, attempt } = await this.send(request);
|
|
988
1409
|
try {
|
|
989
1410
|
const bytes = await readBody(response, this.settings.maxResponseBytes);
|
|
990
1411
|
if (bytes.byteLength === 0 && (response.status === 204 || request.method === "DELETE")) return;
|
|
1412
|
+
let data;
|
|
991
1413
|
try {
|
|
992
|
-
|
|
1414
|
+
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
993
1415
|
} catch (cause) {
|
|
994
1416
|
throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
995
1417
|
message: `Invalid JSON response (HTTP ${response.status})`,
|
|
@@ -997,6 +1419,12 @@ var CalmLensTransport = class {
|
|
|
997
1419
|
cause
|
|
998
1420
|
});
|
|
999
1421
|
}
|
|
1422
|
+
return withLastResponse(data, {
|
|
1423
|
+
status: response.status,
|
|
1424
|
+
requestId: response.headers.get("x-request-id") ?? void 0,
|
|
1425
|
+
headers: response.headers,
|
|
1426
|
+
idempotencyKey: request.idempotencyKey
|
|
1427
|
+
});
|
|
1000
1428
|
} catch (cause) {
|
|
1001
1429
|
throw toFailure(cause, attempt);
|
|
1002
1430
|
} finally {
|
|
@@ -1411,6 +1839,10 @@ const validateConnectionOptions = (options) => {
|
|
|
1411
1839
|
if (partSizeBytes !== void 0 && (!Number.isSafeInteger(partSizeBytes) || partSizeBytes < 5242880 || partSizeBytes > 67108864)) throw invalidConfig("partSizeBytes must be an integer from 5 MiB (5242880) to 64 MiB (67108864)");
|
|
1412
1840
|
for (const name of ["fetch", "uploadFetch"]) if (options[name] !== void 0 && typeof options[name] !== "function") throw invalidConfig(`${name} must be a function`);
|
|
1413
1841
|
assertHttpUrl("baseUrl", options.baseUrl);
|
|
1842
|
+
const { appInfo, onAttempt, logger } = options;
|
|
1843
|
+
if (appInfo !== void 0 && (!appInfo || typeof appInfo.name !== "string" || !/^[\x21-\x7e]+$/.test(appInfo.name) || appInfo.version !== void 0 && !/^[\x21-\x7e]+$/.test(String(appInfo.version)) || appInfo.url !== void 0 && !/^[\x20-\x7e]+$/.test(String(appInfo.url)))) throw invalidConfig("appInfo needs a name, and a version, without spaces, and a url, in printable ASCII");
|
|
1844
|
+
if (onAttempt !== void 0 && typeof onAttempt !== "function") throw invalidConfig("onAttempt must be a function");
|
|
1845
|
+
if (logger !== void 0 && (!logger || typeof logger.debug !== "function" || typeof logger.info !== "function")) throw invalidConfig("logger must have debug and info methods, as console does");
|
|
1414
1846
|
};
|
|
1415
1847
|
/**
|
|
1416
1848
|
* Checks server client options before the client sets anything up. `CalmLensServerClient` and
|
|
@@ -1437,7 +1869,7 @@ const validateAppClientOptions = (options) => {
|
|
|
1437
1869
|
if (options.token !== void 0 && typeof options.token !== "string" && typeof options.token !== "function") throw invalidConfig("token must be a string or a function that returns one");
|
|
1438
1870
|
validateConnectionOptions(options);
|
|
1439
1871
|
};
|
|
1440
|
-
/** Checks
|
|
1872
|
+
/** Checks a client's request defaults. */
|
|
1441
1873
|
const validateRequestOptions = (options) => {
|
|
1442
1874
|
assertInteger("timeoutMs", options.timeoutMs, 1);
|
|
1443
1875
|
assertInteger("uploadTimeoutMs", options.uploadTimeoutMs, 1);
|
|
@@ -1735,11 +2167,11 @@ const pollForDecision = async (retrieve, { timeoutMs = DEFAULT_DECISION_TIMEOUT_
|
|
|
1735
2167
|
if (isAssetDecided(asset)) return asset;
|
|
1736
2168
|
const remaining = deadline - now();
|
|
1737
2169
|
if (remaining <= 0) throw new CalmLensError(SDK_ERROR_CODES.TIMEOUT, {
|
|
1738
|
-
message: `Asset ${asset.id} had no moderation decision after ${timeoutMs}ms (classification status: ${asset.classification.status}, moderation
|
|
2170
|
+
message: `Asset ${asset.id} had no moderation decision after ${timeoutMs}ms (classification status: ${asset.classification.status}, moderation decision: ${asset.classification.moderation.decision})`,
|
|
1739
2171
|
details: {
|
|
1740
2172
|
assetId: asset.id,
|
|
1741
2173
|
classificationStatus: asset.classification.status,
|
|
1742
|
-
|
|
2174
|
+
moderationDecision: asset.classification.moderation.decision
|
|
1743
2175
|
}
|
|
1744
2176
|
});
|
|
1745
2177
|
await sleep(Math.min(delay, remaining), signal);
|
|
@@ -1917,7 +2349,7 @@ const getAssetInfo = async (url, options = {}) => {
|
|
|
1917
2349
|
});
|
|
1918
2350
|
return data;
|
|
1919
2351
|
};
|
|
1920
|
-
// src/contract/ModerationContextLimits-
|
|
2352
|
+
// src/contract/ModerationContextLimits-k930WU8i.js
|
|
1921
2353
|
/** The most recent earlier posts CalmLens uses. */
|
|
1922
2354
|
const MODERATION_CONTEXT_USED_ITEMS = 5;
|
|
1923
2355
|
/**
|
|
@@ -1949,4 +2381,387 @@ const selectModerationContextItems = (items) => {
|
|
|
1949
2381
|
}
|
|
1950
2382
|
return selected;
|
|
1951
2383
|
};
|
|
1952
|
-
|
|
2384
|
+
Object.defineProperty(exports, "API_ERROR_CODES", {
|
|
2385
|
+
enumerable: true,
|
|
2386
|
+
get: function() {
|
|
2387
|
+
return API_ERROR_CODES;
|
|
2388
|
+
}
|
|
2389
|
+
});
|
|
2390
|
+
Object.defineProperty(exports, "API_ERROR_DEFINITIONS", {
|
|
2391
|
+
enumerable: true,
|
|
2392
|
+
get: function() {
|
|
2393
|
+
return API_ERROR_DEFINITIONS;
|
|
2394
|
+
}
|
|
2395
|
+
});
|
|
2396
|
+
Object.defineProperty(exports, "AUTO_PAGING_TO_ARRAY_MAX", {
|
|
2397
|
+
enumerable: true,
|
|
2398
|
+
get: function() {
|
|
2399
|
+
return AUTO_PAGING_TO_ARRAY_MAX;
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
Object.defineProperty(exports, "CALMLENS_ERROR_CODES", {
|
|
2403
|
+
enumerable: true,
|
|
2404
|
+
get: function() {
|
|
2405
|
+
return CALMLENS_ERROR_CODES;
|
|
2406
|
+
}
|
|
2407
|
+
});
|
|
2408
|
+
Object.defineProperty(exports, "CDN_RESOURCES", {
|
|
2409
|
+
enumerable: true,
|
|
2410
|
+
get: function() {
|
|
2411
|
+
return CDN_RESOURCES;
|
|
2412
|
+
}
|
|
2413
|
+
});
|
|
2414
|
+
Object.defineProperty(exports, "CalmLensApiError", {
|
|
2415
|
+
enumerable: true,
|
|
2416
|
+
get: function() {
|
|
2417
|
+
return CalmLensApiError;
|
|
2418
|
+
}
|
|
2419
|
+
});
|
|
2420
|
+
Object.defineProperty(exports, "CalmLensAuthenticationError", {
|
|
2421
|
+
enumerable: true,
|
|
2422
|
+
get: function() {
|
|
2423
|
+
return CalmLensAuthenticationError;
|
|
2424
|
+
}
|
|
2425
|
+
});
|
|
2426
|
+
Object.defineProperty(exports, "CalmLensBadRequestError", {
|
|
2427
|
+
enumerable: true,
|
|
2428
|
+
get: function() {
|
|
2429
|
+
return CalmLensBadRequestError;
|
|
2430
|
+
}
|
|
2431
|
+
});
|
|
2432
|
+
Object.defineProperty(exports, "CalmLensCancelledError", {
|
|
2433
|
+
enumerable: true,
|
|
2434
|
+
get: function() {
|
|
2435
|
+
return CalmLensCancelledError;
|
|
2436
|
+
}
|
|
2437
|
+
});
|
|
2438
|
+
Object.defineProperty(exports, "CalmLensConfigurationError", {
|
|
2439
|
+
enumerable: true,
|
|
2440
|
+
get: function() {
|
|
2441
|
+
return CalmLensConfigurationError;
|
|
2442
|
+
}
|
|
2443
|
+
});
|
|
2444
|
+
Object.defineProperty(exports, "CalmLensConflictError", {
|
|
2445
|
+
enumerable: true,
|
|
2446
|
+
get: function() {
|
|
2447
|
+
return CalmLensConflictError;
|
|
2448
|
+
}
|
|
2449
|
+
});
|
|
2450
|
+
Object.defineProperty(exports, "CalmLensConnectionError", {
|
|
2451
|
+
enumerable: true,
|
|
2452
|
+
get: function() {
|
|
2453
|
+
return CalmLensConnectionError;
|
|
2454
|
+
}
|
|
2455
|
+
});
|
|
2456
|
+
Object.defineProperty(exports, "CalmLensError", {
|
|
2457
|
+
enumerable: true,
|
|
2458
|
+
get: function() {
|
|
2459
|
+
return CalmLensError;
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
Object.defineProperty(exports, "CalmLensInvalidArgumentError", {
|
|
2463
|
+
enumerable: true,
|
|
2464
|
+
get: function() {
|
|
2465
|
+
return CalmLensInvalidArgumentError;
|
|
2466
|
+
}
|
|
2467
|
+
});
|
|
2468
|
+
Object.defineProperty(exports, "CalmLensInvalidResponseError", {
|
|
2469
|
+
enumerable: true,
|
|
2470
|
+
get: function() {
|
|
2471
|
+
return CalmLensInvalidResponseError;
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
Object.defineProperty(exports, "CalmLensNotFoundError", {
|
|
2475
|
+
enumerable: true,
|
|
2476
|
+
get: function() {
|
|
2477
|
+
return CalmLensNotFoundError;
|
|
2478
|
+
}
|
|
2479
|
+
});
|
|
2480
|
+
Object.defineProperty(exports, "CalmLensPayloadTooLargeError", {
|
|
2481
|
+
enumerable: true,
|
|
2482
|
+
get: function() {
|
|
2483
|
+
return CalmLensPayloadTooLargeError;
|
|
2484
|
+
}
|
|
2485
|
+
});
|
|
2486
|
+
Object.defineProperty(exports, "CalmLensPermissionDeniedError", {
|
|
2487
|
+
enumerable: true,
|
|
2488
|
+
get: function() {
|
|
2489
|
+
return CalmLensPermissionDeniedError;
|
|
2490
|
+
}
|
|
2491
|
+
});
|
|
2492
|
+
Object.defineProperty(exports, "CalmLensRateLimitError", {
|
|
2493
|
+
enumerable: true,
|
|
2494
|
+
get: function() {
|
|
2495
|
+
return CalmLensRateLimitError;
|
|
2496
|
+
}
|
|
2497
|
+
});
|
|
2498
|
+
Object.defineProperty(exports, "CalmLensServerError", {
|
|
2499
|
+
enumerable: true,
|
|
2500
|
+
get: function() {
|
|
2501
|
+
return CalmLensServerError;
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
Object.defineProperty(exports, "CalmLensTimeoutError", {
|
|
2505
|
+
enumerable: true,
|
|
2506
|
+
get: function() {
|
|
2507
|
+
return CalmLensTimeoutError;
|
|
2508
|
+
}
|
|
2509
|
+
});
|
|
2510
|
+
Object.defineProperty(exports, "CalmLensTransport", {
|
|
2511
|
+
enumerable: true,
|
|
2512
|
+
get: function() {
|
|
2513
|
+
return CalmLensTransport;
|
|
2514
|
+
}
|
|
2515
|
+
});
|
|
2516
|
+
Object.defineProperty(exports, "CalmLensUnprocessableEntityError", {
|
|
2517
|
+
enumerable: true,
|
|
2518
|
+
get: function() {
|
|
2519
|
+
return CalmLensUnprocessableEntityError;
|
|
2520
|
+
}
|
|
2521
|
+
});
|
|
2522
|
+
Object.defineProperty(exports, "CalmLensWebhookVerificationError", {
|
|
2523
|
+
enumerable: true,
|
|
2524
|
+
get: function() {
|
|
2525
|
+
return CalmLensWebhookVerificationError;
|
|
2526
|
+
}
|
|
2527
|
+
});
|
|
2528
|
+
Object.defineProperty(exports, "DEFAULT_CDN_BASE_URL", {
|
|
2529
|
+
enumerable: true,
|
|
2530
|
+
get: function() {
|
|
2531
|
+
return DEFAULT_CDN_BASE_URL;
|
|
2532
|
+
}
|
|
2533
|
+
});
|
|
2534
|
+
Object.defineProperty(exports, "DOMAIN", {
|
|
2535
|
+
enumerable: true,
|
|
2536
|
+
get: function() {
|
|
2537
|
+
return DOMAIN;
|
|
2538
|
+
}
|
|
2539
|
+
});
|
|
2540
|
+
Object.defineProperty(exports, "MAX_DIRECT_IMAGE_UPLOAD_BYTES", {
|
|
2541
|
+
enumerable: true,
|
|
2542
|
+
get: function() {
|
|
2543
|
+
return MAX_DIRECT_IMAGE_UPLOAD_BYTES;
|
|
2544
|
+
}
|
|
2545
|
+
});
|
|
2546
|
+
Object.defineProperty(exports, "MAX_IMAGE_UPLOAD_BYTES", {
|
|
2547
|
+
enumerable: true,
|
|
2548
|
+
get: function() {
|
|
2549
|
+
return MAX_IMAGE_UPLOAD_BYTES;
|
|
2550
|
+
}
|
|
2551
|
+
});
|
|
2552
|
+
Object.defineProperty(exports, "MAX_NON_IMAGE_UPLOAD_BYTES", {
|
|
2553
|
+
enumerable: true,
|
|
2554
|
+
get: function() {
|
|
2555
|
+
return MAX_NON_IMAGE_UPLOAD_BYTES;
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2558
|
+
Object.defineProperty(exports, "MODERATION_CONTEXT_USED_CHARACTERS", {
|
|
2559
|
+
enumerable: true,
|
|
2560
|
+
get: function() {
|
|
2561
|
+
return MODERATION_CONTEXT_USED_CHARACTERS;
|
|
2562
|
+
}
|
|
2563
|
+
});
|
|
2564
|
+
Object.defineProperty(exports, "MODERATION_CONTEXT_USED_ITEMS", {
|
|
2565
|
+
enumerable: true,
|
|
2566
|
+
get: function() {
|
|
2567
|
+
return MODERATION_CONTEXT_USED_ITEMS;
|
|
2568
|
+
}
|
|
2569
|
+
});
|
|
2570
|
+
Object.defineProperty(exports, "SDK_ERROR_CODES", {
|
|
2571
|
+
enumerable: true,
|
|
2572
|
+
get: function() {
|
|
2573
|
+
return SDK_ERROR_CODES;
|
|
2574
|
+
}
|
|
2575
|
+
});
|
|
2576
|
+
Object.defineProperty(exports, "SDK_VERSION", {
|
|
2577
|
+
enumerable: true,
|
|
2578
|
+
get: function() {
|
|
2579
|
+
return SDK_VERSION;
|
|
2580
|
+
}
|
|
2581
|
+
});
|
|
2582
|
+
Object.defineProperty(exports, "appendAssetLocation", {
|
|
2583
|
+
enumerable: true,
|
|
2584
|
+
get: function() {
|
|
2585
|
+
return appendAssetLocation;
|
|
2586
|
+
}
|
|
2587
|
+
});
|
|
2588
|
+
Object.defineProperty(exports, "buildAssetUrl", {
|
|
2589
|
+
enumerable: true,
|
|
2590
|
+
get: function() {
|
|
2591
|
+
return buildAssetUrl;
|
|
2592
|
+
}
|
|
2593
|
+
});
|
|
2594
|
+
Object.defineProperty(exports, "checkOptionKeys", {
|
|
2595
|
+
enumerable: true,
|
|
2596
|
+
get: function() {
|
|
2597
|
+
return checkOptionKeys;
|
|
2598
|
+
}
|
|
2599
|
+
});
|
|
2600
|
+
Object.defineProperty(exports, "checkTransformOptions", {
|
|
2601
|
+
enumerable: true,
|
|
2602
|
+
get: function() {
|
|
2603
|
+
return checkTransformOptions;
|
|
2604
|
+
}
|
|
2605
|
+
});
|
|
2606
|
+
Object.defineProperty(exports, "copyLastResponse", {
|
|
2607
|
+
enumerable: true,
|
|
2608
|
+
get: function() {
|
|
2609
|
+
return copyLastResponse;
|
|
2610
|
+
}
|
|
2611
|
+
});
|
|
2612
|
+
Object.defineProperty(exports, "encodePathSegment", {
|
|
2613
|
+
enumerable: true,
|
|
2614
|
+
get: function() {
|
|
2615
|
+
return encodePathSegment;
|
|
2616
|
+
}
|
|
2617
|
+
});
|
|
2618
|
+
Object.defineProperty(exports, "getAssetInfo", {
|
|
2619
|
+
enumerable: true,
|
|
2620
|
+
get: function() {
|
|
2621
|
+
return getAssetInfo;
|
|
2622
|
+
}
|
|
2623
|
+
});
|
|
2624
|
+
Object.defineProperty(exports, "getRejectedUploadMimeTypeError", {
|
|
2625
|
+
enumerable: true,
|
|
2626
|
+
get: function() {
|
|
2627
|
+
return getRejectedUploadMimeTypeError;
|
|
2628
|
+
}
|
|
2629
|
+
});
|
|
2630
|
+
Object.defineProperty(exports, "invalidArgument", {
|
|
2631
|
+
enumerable: true,
|
|
2632
|
+
get: function() {
|
|
2633
|
+
return invalidArgument;
|
|
2634
|
+
}
|
|
2635
|
+
});
|
|
2636
|
+
Object.defineProperty(exports, "invalidConfig", {
|
|
2637
|
+
enumerable: true,
|
|
2638
|
+
get: function() {
|
|
2639
|
+
return invalidConfig;
|
|
2640
|
+
}
|
|
2641
|
+
});
|
|
2642
|
+
Object.defineProperty(exports, "isAcceptedUploadMimeType", {
|
|
2643
|
+
enumerable: true,
|
|
2644
|
+
get: function() {
|
|
2645
|
+
return isAcceptedUploadMimeType;
|
|
2646
|
+
}
|
|
2647
|
+
});
|
|
2648
|
+
Object.defineProperty(exports, "isBrowserRuntime", {
|
|
2649
|
+
enumerable: true,
|
|
2650
|
+
get: function() {
|
|
2651
|
+
return isBrowserRuntime;
|
|
2652
|
+
}
|
|
2653
|
+
});
|
|
2654
|
+
Object.defineProperty(exports, "isReactNativeRuntime", {
|
|
2655
|
+
enumerable: true,
|
|
2656
|
+
get: function() {
|
|
2657
|
+
return isReactNativeRuntime;
|
|
2658
|
+
}
|
|
2659
|
+
});
|
|
2660
|
+
Object.defineProperty(exports, "listPages", {
|
|
2661
|
+
enumerable: true,
|
|
2662
|
+
get: function() {
|
|
2663
|
+
return listPages;
|
|
2664
|
+
}
|
|
2665
|
+
});
|
|
2666
|
+
Object.defineProperty(exports, "normalizeUploadMimeType", {
|
|
2667
|
+
enumerable: true,
|
|
2668
|
+
get: function() {
|
|
2669
|
+
return normalizeUploadMimeType;
|
|
2670
|
+
}
|
|
2671
|
+
});
|
|
2672
|
+
Object.defineProperty(exports, "parseTransformSelector", {
|
|
2673
|
+
enumerable: true,
|
|
2674
|
+
get: function() {
|
|
2675
|
+
return parseTransformSelector;
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
Object.defineProperty(exports, "pollForDecision", {
|
|
2679
|
+
enumerable: true,
|
|
2680
|
+
get: function() {
|
|
2681
|
+
return pollForDecision;
|
|
2682
|
+
}
|
|
2683
|
+
});
|
|
2684
|
+
Object.defineProperty(exports, "randomUuid", {
|
|
2685
|
+
enumerable: true,
|
|
2686
|
+
get: function() {
|
|
2687
|
+
return randomUuid;
|
|
2688
|
+
}
|
|
2689
|
+
});
|
|
2690
|
+
Object.defineProperty(exports, "readEnv", {
|
|
2691
|
+
enumerable: true,
|
|
2692
|
+
get: function() {
|
|
2693
|
+
return readEnv;
|
|
2694
|
+
}
|
|
2695
|
+
});
|
|
2696
|
+
Object.defineProperty(exports, "resolveLogLevel", {
|
|
2697
|
+
enumerable: true,
|
|
2698
|
+
get: function() {
|
|
2699
|
+
return resolveLogLevel;
|
|
2700
|
+
}
|
|
2701
|
+
});
|
|
2702
|
+
Object.defineProperty(exports, "selectModerationContextItems", {
|
|
2703
|
+
enumerable: true,
|
|
2704
|
+
get: function() {
|
|
2705
|
+
return selectModerationContextItems;
|
|
2706
|
+
}
|
|
2707
|
+
});
|
|
2708
|
+
Object.defineProperty(exports, "serializeTransform", {
|
|
2709
|
+
enumerable: true,
|
|
2710
|
+
get: function() {
|
|
2711
|
+
return serializeTransform;
|
|
2712
|
+
}
|
|
2713
|
+
});
|
|
2714
|
+
Object.defineProperty(exports, "sleep", {
|
|
2715
|
+
enumerable: true,
|
|
2716
|
+
get: function() {
|
|
2717
|
+
return sleep;
|
|
2718
|
+
}
|
|
2719
|
+
});
|
|
2720
|
+
Object.defineProperty(exports, "stringifyQuery", {
|
|
2721
|
+
enumerable: true,
|
|
2722
|
+
get: function() {
|
|
2723
|
+
return stringifyQuery;
|
|
2724
|
+
}
|
|
2725
|
+
});
|
|
2726
|
+
Object.defineProperty(exports, "toTextAssetOptions", {
|
|
2727
|
+
enumerable: true,
|
|
2728
|
+
get: function() {
|
|
2729
|
+
return toTextAssetOptions;
|
|
2730
|
+
}
|
|
2731
|
+
});
|
|
2732
|
+
Object.defineProperty(exports, "toUrlViewerClaims", {
|
|
2733
|
+
enumerable: true,
|
|
2734
|
+
get: function() {
|
|
2735
|
+
return toUrlViewerClaims;
|
|
2736
|
+
}
|
|
2737
|
+
});
|
|
2738
|
+
Object.defineProperty(exports, "transformSelector", {
|
|
2739
|
+
enumerable: true,
|
|
2740
|
+
get: function() {
|
|
2741
|
+
return transformSelector;
|
|
2742
|
+
}
|
|
2743
|
+
});
|
|
2744
|
+
Object.defineProperty(exports, "validateAppClientOptions", {
|
|
2745
|
+
enumerable: true,
|
|
2746
|
+
get: function() {
|
|
2747
|
+
return validateAppClientOptions;
|
|
2748
|
+
}
|
|
2749
|
+
});
|
|
2750
|
+
Object.defineProperty(exports, "validateBatchAssetsOptions", {
|
|
2751
|
+
enumerable: true,
|
|
2752
|
+
get: function() {
|
|
2753
|
+
return validateBatchAssetsOptions;
|
|
2754
|
+
}
|
|
2755
|
+
});
|
|
2756
|
+
Object.defineProperty(exports, "validateServerClientOptions", {
|
|
2757
|
+
enumerable: true,
|
|
2758
|
+
get: function() {
|
|
2759
|
+
return validateServerClientOptions;
|
|
2760
|
+
}
|
|
2761
|
+
});
|
|
2762
|
+
Object.defineProperty(exports, "validateSignAssetUrlOptions", {
|
|
2763
|
+
enumerable: true,
|
|
2764
|
+
get: function() {
|
|
2765
|
+
return validateSignAssetUrlOptions;
|
|
2766
|
+
}
|
|
2767
|
+
});
|