calmlens 0.29.2 → 0.31.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/bin/calmlens.js +17 -45
- package/{esm/BrowserUpload-CeGsM9h1.d.ts → cjs/BrowserUpload-BAH54V1q.d.ts} +2 -2
- package/cjs/{BrowserUpload-CCXt4DAY.js → BrowserUpload-IiRDbL85.js} +1 -1
- package/cjs/{CalmLensAppClient-ea-qXkmD.js → CalmLensAppClient-BBcq6pJg.js} +10 -10
- package/cjs/{CalmLensAppClient-D-BD_Ny1.d.ts → CalmLensAppClient-CdlcDd5l.d.ts} +1 -1
- package/cjs/{ModerationContextLimits-1XP4ZTQk.js → CalmLensCdn-2VbArrj-.js} +2 -52
- package/cjs/{CalmLensConnection-BrySN2M3.js → CalmLensConnection-CpnDGa8W.js} +15 -22
- package/cjs/{CalmLensError-DPHJaVjX.js → CalmLensError-ifj5rLmk.js} +5 -0
- package/{esm/CalmLensServerClient-BYN_N0lt.d.ts → cjs/CalmLensServerClient-CtS66dCU.d.ts} +12 -8
- package/cjs/{CalmLensServerClient-FD7H7KvL.js → CalmLensServerClient-DbemlDXj.js} +38 -37
- package/cjs/{CalmLensTestInputArguments-BXDBAOg_.js → CalmLensTestInputArguments-PYuRmE0j.js} +1 -1
- package/cjs/{CalmLensTypes-C2blKgTu.d.ts → CalmLensTypes-87kiUg0H.d.ts} +208 -10
- package/cjs/{Classification-CMM2tZpJ-IdIh63n0.d.ts → Classification-C3pkrGYS-B7EygpJn.d.ts} +16 -50
- package/cjs/{Core-CNmoxDCW.d.ts → Core-Ccy4-_sN.d.ts} +2 -2
- package/cjs/{Core-DMFa3EUp.js → Core-xy9aV1ED.js} +8 -8
- package/cjs/{ReactUpload-gaeiPSeH.js → ReactUpload-BX3XOVfb.js} +1 -1
- package/{esm/ReactUpload-kqEe6gcN.d.ts → cjs/ReactUpload-DBhppuxM.d.ts} +1 -1
- package/cjs/{TestTriggers-CFnel6a9.d.ts → TestTriggers-Daxebd0V.d.ts} +1 -1
- package/cjs/{UploadController-CyPTBuZg.js → UploadController-CmTjpOfp.js} +2 -2
- package/{esm/WebhookPayload-DZWlnvcY.d.ts → cjs/WebhookPayload-B4rA_Dvm.d.ts} +13 -7
- package/cjs/app.d.ts +6 -6
- package/cjs/app.js +8 -11
- package/cjs/elements.d.ts +4 -4
- package/cjs/elements.js +4 -4
- package/cjs/{index-Dl2qwS8L.d.ts → index-CWUnLKoF.d.ts} +8 -4
- package/cjs/index.d.ts +5 -5
- package/cjs/index.js +7 -10
- package/cjs/react-native.d.ts +2 -2
- package/cjs/react-native.js +7 -7
- package/cjs/react.d.ts +4 -4
- package/cjs/react.js +5 -5
- package/cjs/server.d.ts +12 -12
- package/cjs/server.js +9 -12
- package/cjs/test-inputs.d.ts +1 -1
- package/cjs/test-inputs.js +1 -1
- package/cjs/testing.d.ts +12 -8
- package/cjs/testing.js +89 -37
- package/cjs/{ui-DNP1uWQy.js → ui-BJKh49aM.js} +3 -3
- package/cjs/{ui-BtmJC-f9.d.ts → ui-sjnJhloQ.d.ts} +2 -2
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +3 -3
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +4 -4
- package/{cjs/BrowserUpload-CeGsM9h1.d.ts → esm/BrowserUpload-BAH54V1q.d.ts} +2 -2
- package/esm/{BrowserUpload-Bu6eWqQS.js → BrowserUpload-C5aXj6QC.js} +1 -1
- package/esm/{CalmLensAppClient-D-BD_Ny1.d.ts → CalmLensAppClient-CdlcDd5l.d.ts} +1 -1
- package/esm/{CalmLensAppClient-xp-fH6Lz.js → CalmLensAppClient-gAd0C_Q_.js} +3 -3
- package/esm/{ModerationContextLimits-CtAyz60h.js → CalmLensCdn-CcxEY6wB.js} +3 -35
- package/esm/{CalmLensConnection-DwG5yBk2.js → CalmLensConnection-CfGVp95D.js} +2 -9
- package/esm/{CalmLensError-BDWThPCr.js → CalmLensError-C15tWu8W.js} +5 -0
- package/esm/{CalmLensServerClient-CKlNBBo3.js → CalmLensServerClient-CPWeRVWO.js} +18 -17
- package/{cjs/CalmLensServerClient-BYN_N0lt.d.ts → esm/CalmLensServerClient-CtS66dCU.d.ts} +12 -8
- package/esm/{CalmLensTestInputArguments-Xh4GIadS.js → CalmLensTestInputArguments-CqPADTkl.js} +1 -1
- package/esm/{CalmLensTypes-C2blKgTu.d.ts → CalmLensTypes-87kiUg0H.d.ts} +208 -10
- package/esm/{Classification-CMM2tZpJ-IdIh63n0.d.ts → Classification-C3pkrGYS-B7EygpJn.d.ts} +16 -50
- package/esm/{Core-CNmoxDCW.d.ts → Core-Ccy4-_sN.d.ts} +2 -2
- package/esm/{Core-DnCeTmvS.js → Core-DTcxpv3O.js} +3 -3
- package/{cjs/ReactUpload-kqEe6gcN.d.ts → esm/ReactUpload-DBhppuxM.d.ts} +1 -1
- package/esm/{ReactUpload-D30YlRui.js → ReactUpload-Dg7MtjbJ.js} +1 -1
- package/esm/{TestTriggers-CFnel6a9.d.ts → TestTriggers-Daxebd0V.d.ts} +1 -1
- package/esm/{UploadController-DENryQ8H.js → UploadController-DVsTVJVv.js} +2 -2
- package/{cjs/WebhookPayload-DZWlnvcY.d.ts → esm/WebhookPayload-B4rA_Dvm.d.ts} +13 -7
- package/esm/app.d.ts +6 -6
- package/esm/app.js +4 -4
- package/esm/elements.d.ts +4 -4
- package/esm/elements.js +4 -4
- package/esm/{index-Dl2qwS8L.d.ts → index-CWUnLKoF.d.ts} +8 -4
- package/esm/index.d.ts +5 -5
- package/esm/index.js +3 -3
- package/esm/react-native.d.ts +2 -2
- package/esm/react-native.js +4 -4
- package/esm/react.d.ts +4 -4
- package/esm/react.js +5 -5
- package/esm/server.d.ts +12 -12
- package/esm/server.js +4 -4
- package/esm/test-inputs.d.ts +1 -1
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +12 -8
- package/esm/testing.js +74 -22
- package/esm/{ui-DUEBbRJ0.js → ui-DUao8UY0.js} +2 -2
- package/esm/{ui-BtmJC-f9.d.ts → ui-sjnJhloQ.d.ts} +2 -2
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +3 -3
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +4 -4
- package/package.json +1 -1
package/bin/calmlens.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
// package.json
|
|
6
|
-
var version = "0.
|
|
6
|
+
var version = "0.31.0";
|
|
7
7
|
|
|
8
8
|
// src/contract/ModerationCategories-CHFRoeWV.js
|
|
9
9
|
var CLASSIFICATION_CATEGORIES = [
|
|
@@ -139,6 +139,7 @@ var API_ERROR_CODES = {
|
|
|
139
139
|
REMOTE_URL_UNAVAILABLE: "remote-url/unavailable",
|
|
140
140
|
APPEAL_NOT_FOUND: "appeal/not-found",
|
|
141
141
|
APPEAL_JUDGMENT_NOT_FOUND: "appeal/judgment-not-found",
|
|
142
|
+
CONTEXT_ASSET_NOT_FOUND: "context/asset-not-found",
|
|
142
143
|
APPEAL_ASSET_NOT_FOUND: "appeal/asset-not-found",
|
|
143
144
|
APPEAL_PERMISSION_DENIED: "appeal/permission-denied",
|
|
144
145
|
APPEAL_ALREADY_REVIEWED: "appeal/already-reviewed",
|
|
@@ -1882,28 +1883,6 @@ var validateAssetPayload = (payload, options) => {
|
|
|
1882
1883
|
// src/contract/Media-B2PMcUf7.js
|
|
1883
1884
|
var MAX_MEDIA_UPLOAD_BYTES = 52428800;
|
|
1884
1885
|
var MAX_LONG_MEDIA_UPLOAD_BYTES = 2147483648;
|
|
1885
|
-
// src/contract/ModerationContextLimits-k930WU8i.js
|
|
1886
|
-
var countModerationContextCharacters = (text) => {
|
|
1887
|
-
let count = 0;
|
|
1888
|
-
for (const _ of text)
|
|
1889
|
-
count++;
|
|
1890
|
-
return count;
|
|
1891
|
-
};
|
|
1892
|
-
var selectModerationContextItems = (items) => {
|
|
1893
|
-
const selected = [];
|
|
1894
|
-
let characters = 0;
|
|
1895
|
-
for (let index = items.length - 1;index >= 0; index--) {
|
|
1896
|
-
if (selected.length === 5)
|
|
1897
|
-
break;
|
|
1898
|
-
const item = items[index];
|
|
1899
|
-
const length = countModerationContextCharacters(item.text);
|
|
1900
|
-
if (selected.length && characters + length > 2000)
|
|
1901
|
-
break;
|
|
1902
|
-
selected.unshift(item);
|
|
1903
|
-
characters += length;
|
|
1904
|
-
}
|
|
1905
|
-
return selected;
|
|
1906
|
-
};
|
|
1907
1886
|
// src/client/CalmLensOptionKeys.ts
|
|
1908
1887
|
var SERVER_OPTION_KEYS = {
|
|
1909
1888
|
"assets.batch": ["assetIds", "operation"],
|
|
@@ -2235,12 +2214,6 @@ var prepareSubmitAssetOptions = (input, {
|
|
|
2235
2214
|
if (!validation.ok)
|
|
2236
2215
|
throw invalidPayload(validation.error);
|
|
2237
2216
|
}
|
|
2238
|
-
if (options.context !== undefined) {
|
|
2239
|
-
if (!options.context || !Array.isArray(options.context.items)) {
|
|
2240
|
-
throw invalidArgument("context.items must be an array of earlier posts");
|
|
2241
|
-
}
|
|
2242
|
-
return { ...options, context: { items: selectModerationContextItems(options.context.items) } };
|
|
2243
|
-
}
|
|
2244
2217
|
return options;
|
|
2245
2218
|
};
|
|
2246
2219
|
var newIdempotencyKey = () => randomUuid();
|
|
@@ -2994,7 +2967,7 @@ class CalmLensServerClient {
|
|
|
2994
2967
|
list: (options = {}, requestOptions) => this.#paginate("events.list", options, requestOptions, ({ types, ...query }) => this.#send("events.list", requestOptions, "GET", `${this.#projectPath}/events`, {
|
|
2995
2968
|
query: { ...query, types: types?.length ? types.join(",") : undefined }
|
|
2996
2969
|
})),
|
|
2997
|
-
retrieveAsset: async (event, requestOptions) => event.
|
|
2970
|
+
retrieveAsset: async (event, requestOptions) => event.resource?.kind === "asset" ? this.assets.retrieve({ assetId: event.resource.id }, requestOptions) : null
|
|
2998
2971
|
};
|
|
2999
2972
|
}
|
|
3000
2973
|
get folders() {
|
|
@@ -19042,8 +19015,7 @@ var toWebhookEventPayload = (event) => ({
|
|
|
19042
19015
|
severity: event.severity,
|
|
19043
19016
|
title: event.title,
|
|
19044
19017
|
description: event.description ?? null,
|
|
19045
|
-
|
|
19046
|
-
assetSequence: event.assetSequence ?? null,
|
|
19018
|
+
resource: event.resource ?? null,
|
|
19047
19019
|
facts: event.facts,
|
|
19048
19020
|
createdAt: event.createdAt
|
|
19049
19021
|
});
|
|
@@ -19162,20 +19134,20 @@ var unavailableWarning = (unavailableTypes) => [
|
|
|
19162
19134
|
""
|
|
19163
19135
|
].join(`
|
|
19164
19136
|
`);
|
|
19165
|
-
var
|
|
19166
|
-
const
|
|
19137
|
+
var inResourceOrder = (events) => {
|
|
19138
|
+
const byResource = new Map;
|
|
19167
19139
|
for (const event of events)
|
|
19168
|
-
if (event.
|
|
19169
|
-
|
|
19170
|
-
for (const
|
|
19171
|
-
|
|
19140
|
+
if (event.resource)
|
|
19141
|
+
byResource.set(event.resource.id, [...byResource.get(event.resource.id) ?? [], event]);
|
|
19142
|
+
for (const resourceEvents of byResource.values())
|
|
19143
|
+
resourceEvents.sort((a, b) => (a.resource?.sequence ?? 0) - (b.resource?.sequence ?? 0));
|
|
19172
19144
|
const next = new Map;
|
|
19173
19145
|
return events.map((event) => {
|
|
19174
|
-
if (!event.
|
|
19146
|
+
if (!event.resource)
|
|
19175
19147
|
return event;
|
|
19176
|
-
const index = next.get(event.
|
|
19177
|
-
next.set(event.
|
|
19178
|
-
return
|
|
19148
|
+
const index = next.get(event.resource.id) ?? 0;
|
|
19149
|
+
next.set(event.resource.id, index + 1);
|
|
19150
|
+
return byResource.get(event.resource.id)[index];
|
|
19179
19151
|
});
|
|
19180
19152
|
};
|
|
19181
19153
|
var listen = async (options) => {
|
|
@@ -19194,7 +19166,7 @@ var listen = async (options) => {
|
|
|
19194
19166
|
if (failures > 0)
|
|
19195
19167
|
log(`${formatTime(new Date)} Reconnected to CalmLens.`);
|
|
19196
19168
|
failures = 0;
|
|
19197
|
-
for (const event of
|
|
19169
|
+
for (const event of inResourceOrder(page.items)) {
|
|
19198
19170
|
if (eventTypes.size > 0 && !eventTypes.has(event.type))
|
|
19199
19171
|
continue;
|
|
19200
19172
|
await deliverEvent(event, { ...options, log });
|
|
@@ -19354,8 +19326,8 @@ Commands:
|
|
|
19354
19326
|
receives, so listen and trigger need no API key or project ID.
|
|
19355
19327
|
logout Revoke and forget the key from login.
|
|
19356
19328
|
listen Forward your project's events to a local webhook handler with the same flat
|
|
19357
|
-
body (id, projectId, actor, type, severity, title, description,
|
|
19358
|
-
|
|
19329
|
+
body (id, projectId, actor, type, severity, title, description, resource,
|
|
19330
|
+
facts, createdAt) and headers (x-calmlens-delivery,
|
|
19359
19331
|
x-calmlens-timestamp, x-calmlens-signature: v1=...) as real deliveries. No
|
|
19360
19332
|
public URL needed. Like real deliveries, network errors, timeouts, 408, 425, 429
|
|
19361
19333
|
and 5xx responses are retried, up to 7 attempts with the same delivery ID, here
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as UploadFile, I as UploadItem$1, L as UploadSnapshot$1, N as UploadController, P as UploadControllerOptions$1, h as UploaderProps$1, k as CalmLensUpload$1 } from "./Core-
|
|
2
|
-
import { r as UseCalmLensUploadResult$1 } from "./ReactUpload-
|
|
1
|
+
import { F as UploadFile, I as UploadItem$1, L as UploadSnapshot$1, N as UploadController, P as UploadControllerOptions$1, h as UploaderProps$1, k as CalmLensUpload$1 } from "./Core-Ccy4-_sN.js";
|
|
2
|
+
import { r as UseCalmLensUploadResult$1 } from "./ReactUpload-DBhppuxM.js";
|
|
3
3
|
type UploadItem<F extends UploadFile = File> = UploadItem$1<F>;
|
|
4
4
|
type CalmLensUpload<F extends UploadFile = File> = CalmLensUpload$1<F>;
|
|
5
5
|
type UploadSnapshot<F extends UploadFile = File> = UploadSnapshot$1<F>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_UploadController = require("./UploadController-
|
|
1
|
+
const require_UploadController = require("./UploadController-CmTjpOfp.js");
|
|
2
2
|
// src/ui/BrowserUpload.ts
|
|
3
3
|
/** Creates an upload queue for the browser components, such as one a form starts on submit. */
|
|
4
4
|
const createUploadController = (options) => require_UploadController.createUploadController(options);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const require_CalmLensError = require("./CalmLensError-
|
|
2
|
-
const
|
|
3
|
-
const require_CalmLensConnection = require("./CalmLensConnection-
|
|
1
|
+
const require_CalmLensError = require("./CalmLensError-ifj5rLmk.js");
|
|
2
|
+
const require_CalmLensCdn = require("./CalmLensCdn-2VbArrj-.js");
|
|
3
|
+
const require_CalmLensConnection = require("./CalmLensConnection-CpnDGa8W.js");
|
|
4
4
|
// src/client/CalmLensAppClient.ts
|
|
5
5
|
const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
6
6
|
/** `options`, once `checkOptionKeys` finds only keys `operation` takes. */
|
|
7
7
|
const checked = (operation, options) => {
|
|
8
|
-
|
|
8
|
+
require_CalmLensCdn.checkOptionKeys(options, operation, require_CalmLensConnection.APP_OPTION_KEYS);
|
|
9
9
|
return options;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
@@ -23,12 +23,12 @@ var CalmLensAppClient = class {
|
|
|
23
23
|
#projectId;
|
|
24
24
|
#cdnBaseUrl;
|
|
25
25
|
constructor(options) {
|
|
26
|
-
|
|
26
|
+
require_CalmLensCdn.validateAppClientOptions(options);
|
|
27
27
|
const { token, uploadPresetId, projectId, cdnBaseUrl, ...rest } = options;
|
|
28
28
|
this.#uploadPresetId = uploadPresetId;
|
|
29
29
|
this.#token = token;
|
|
30
30
|
this.#projectId = projectId;
|
|
31
|
-
this.#cdnBaseUrl = (cdnBaseUrl ??
|
|
31
|
+
this.#cdnBaseUrl = (cdnBaseUrl ?? require_CalmLensCdn.DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
|
|
32
32
|
this.#connection = new require_CalmLensConnection.CalmLensConnection(require_CalmLensConnection.resolveConnectionOptions(rest));
|
|
33
33
|
}
|
|
34
34
|
/** Keeps tokens out of `console.log`, `util.inspect` and `JSON.stringify`. */
|
|
@@ -72,7 +72,7 @@ var CalmLensAppClient = class {
|
|
|
72
72
|
onStarted: (assetId) => {
|
|
73
73
|
if (token) this.#uploadTokens.set(assetId, token);
|
|
74
74
|
},
|
|
75
|
-
retrieve: async (assetId, read) => require_CalmLensConnection.expectUploadedAsset(await read.json("GET", `${this.uploadsPath}/${
|
|
75
|
+
retrieve: async (assetId, read) => require_CalmLensConnection.expectUploadedAsset(await read.json("GET", `${this.uploadsPath}/${require_CalmLensCdn.encodePathSegment(assetId, "Asset ID")}`, { headers: this.authHeaders(assetId) }))
|
|
76
76
|
});
|
|
77
77
|
return require_CalmLensConnection.expectUploadedAsset(data);
|
|
78
78
|
}
|
|
@@ -94,7 +94,7 @@ getAssetUrl: (urlOptions) => {
|
|
|
94
94
|
const { projectId, ...options } = checked("cdn.getAssetUrl", urlOptions);
|
|
95
95
|
const project = projectId ?? this.#projectId;
|
|
96
96
|
if (project === void 0) throw require_CalmLensError.invalidArgument("Pass projectId, here or in the client's options");
|
|
97
|
-
return
|
|
97
|
+
return require_CalmLensCdn.buildAssetUrl(this.#cdnBaseUrl, project, options);
|
|
98
98
|
} };
|
|
99
99
|
}
|
|
100
100
|
/** Uploads through the client's upload preset and checks those uploads. */
|
|
@@ -110,14 +110,14 @@ getAssetUrl: (urlOptions) => {
|
|
|
110
110
|
*/
|
|
111
111
|
uploadPart: async (partOptions, requestOptions) => {
|
|
112
112
|
const { assetId, ...options } = checked("assets.uploadPart", partOptions);
|
|
113
|
-
const encodedAssetId =
|
|
113
|
+
const encodedAssetId = require_CalmLensCdn.encodePathSegment(assetId, "Asset ID");
|
|
114
114
|
const data = await this.#connection.forCall("assets.uploadPart", requestOptions).uploadPart(`${this.uploadsPath}/${encodedAssetId}/part`, options, this.authHeaders(assetId));
|
|
115
115
|
return require_CalmLensConnection.expectUploadedAsset(data);
|
|
116
116
|
},
|
|
117
117
|
/** Checks an upload this client made. `classification.moderation.decision` is present when the preset shows decisions. */
|
|
118
118
|
retrieve: async (options, requestOptions) => {
|
|
119
119
|
const { assetId } = checked("assets.retrieve", options);
|
|
120
|
-
const encodedAssetId =
|
|
120
|
+
const encodedAssetId = require_CalmLensCdn.encodePathSegment(assetId, "Asset ID");
|
|
121
121
|
const data = await this.#connection.forCall("assets.retrieve", requestOptions).json("GET", `${this.uploadsPath}/${encodedAssetId}`, { headers: this.authHeaders(assetId) });
|
|
122
122
|
return require_CalmLensConnection.expectUploadedAsset(data);
|
|
123
123
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $t as UploadPresetSubmitAssetOptions, M as CdnAssetUrlOptions, Mt as RetrieveAssetOptions, O as CalmLensAppClientOptions, Yt as UploadAssetPartOptions, en as UploadedAsset, kt as RequestOptions } from "./CalmLensTypes-
|
|
1
|
+
import { $t as UploadPresetSubmitAssetOptions, M as CdnAssetUrlOptions, Mt as RetrieveAssetOptions, O as CalmLensAppClientOptions, Yt as UploadAssetPartOptions, en as UploadedAsset, kt as RequestOptions } from "./CalmLensTypes-87kiUg0H.js";
|
|
2
2
|
declare const inspectSymbol: unique symbol;
|
|
3
3
|
/**
|
|
4
4
|
* The CalmLens client for browsers and React Native apps. It uploads through an upload preset,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_CalmLensError = require("./CalmLensError-
|
|
1
|
+
const require_CalmLensError = require("./CalmLensError-ifj5rLmk.js");
|
|
2
2
|
// src/client/CalmLensLogging.ts
|
|
3
3
|
const LOG_LEVELS = [
|
|
4
4
|
"off",
|
|
@@ -152,7 +152,7 @@ const listPages = (fetchPage, { cursor, feed = false } = {}) => {
|
|
|
152
152
|
};
|
|
153
153
|
// src/client/CalmLensVersion.ts
|
|
154
154
|
/** This SDK's version, from its package.json. */
|
|
155
|
-
const SDK_VERSION = "0.
|
|
155
|
+
const SDK_VERSION = "0.31.0";
|
|
156
156
|
const runtimeName = () => {
|
|
157
157
|
const runtime = globalThis;
|
|
158
158
|
if (isReactNativeRuntime()) return "react-native";
|
|
@@ -1483,38 +1483,6 @@ const getAssetInfo = async (url, options = {}) => {
|
|
|
1483
1483
|
});
|
|
1484
1484
|
return data;
|
|
1485
1485
|
};
|
|
1486
|
-
// src/contract/ModerationContextLimits-k930WU8i.js
|
|
1487
|
-
/** The most recent earlier posts CalmLens uses. */
|
|
1488
|
-
const MODERATION_CONTEXT_USED_ITEMS = 5;
|
|
1489
|
-
/**
|
|
1490
|
-
* The most characters of earlier posts CalmLens uses. The newest post always fits, since no post
|
|
1491
|
-
* may be longer.
|
|
1492
|
-
*/
|
|
1493
|
-
const MODERATION_CONTEXT_USED_CHARACTERS = 2e3;
|
|
1494
|
-
/** Unicode code points, as every SDK counts characters. */
|
|
1495
|
-
const countModerationContextCharacters = (text) => {
|
|
1496
|
-
let count = 0;
|
|
1497
|
-
for (const _ of text) count++;
|
|
1498
|
-
return count;
|
|
1499
|
-
};
|
|
1500
|
-
/**
|
|
1501
|
-
* The earlier posts CalmLens uses: the most recent ones, newest first, while at most
|
|
1502
|
-
* `MODERATION_CONTEXT_USED_ITEMS` and `MODERATION_CONTEXT_USED_CHARACTERS` allow, returned oldest
|
|
1503
|
-
* first. The newest post is always kept, so an over-long one is left for validation to reject.
|
|
1504
|
-
*/
|
|
1505
|
-
const selectModerationContextItems = (items) => {
|
|
1506
|
-
const selected = [];
|
|
1507
|
-
let characters = 0;
|
|
1508
|
-
for (let index = items.length - 1; index >= 0; index--) {
|
|
1509
|
-
if (selected.length === 5) break;
|
|
1510
|
-
const item = items[index];
|
|
1511
|
-
const length = countModerationContextCharacters(item.text);
|
|
1512
|
-
if (selected.length && characters + length > 2e3) break;
|
|
1513
|
-
selected.unshift(item);
|
|
1514
|
-
characters += length;
|
|
1515
|
-
}
|
|
1516
|
-
return selected;
|
|
1517
|
-
};
|
|
1518
1486
|
Object.defineProperty(exports, "ASSET_RESOURCE_PATHS", {
|
|
1519
1487
|
enumerable: true,
|
|
1520
1488
|
get: function() {
|
|
@@ -1569,18 +1537,6 @@ Object.defineProperty(exports, "MAX_NON_IMAGE_UPLOAD_BYTES", {
|
|
|
1569
1537
|
return MAX_NON_IMAGE_UPLOAD_BYTES;
|
|
1570
1538
|
}
|
|
1571
1539
|
});
|
|
1572
|
-
Object.defineProperty(exports, "MODERATION_CONTEXT_USED_CHARACTERS", {
|
|
1573
|
-
enumerable: true,
|
|
1574
|
-
get: function() {
|
|
1575
|
-
return MODERATION_CONTEXT_USED_CHARACTERS;
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1578
|
-
Object.defineProperty(exports, "MODERATION_CONTEXT_USED_ITEMS", {
|
|
1579
|
-
enumerable: true,
|
|
1580
|
-
get: function() {
|
|
1581
|
-
return MODERATION_CONTEXT_USED_ITEMS;
|
|
1582
|
-
}
|
|
1583
|
-
});
|
|
1584
1540
|
Object.defineProperty(exports, "SDK_VERSION", {
|
|
1585
1541
|
enumerable: true,
|
|
1586
1542
|
get: function() {
|
|
@@ -1707,12 +1663,6 @@ Object.defineProperty(exports, "resolveLogLevel", {
|
|
|
1707
1663
|
return resolveLogLevel;
|
|
1708
1664
|
}
|
|
1709
1665
|
});
|
|
1710
|
-
Object.defineProperty(exports, "selectModerationContextItems", {
|
|
1711
|
-
enumerable: true,
|
|
1712
|
-
get: function() {
|
|
1713
|
-
return selectModerationContextItems;
|
|
1714
|
-
}
|
|
1715
|
-
});
|
|
1716
1666
|
Object.defineProperty(exports, "serializeTransform", {
|
|
1717
1667
|
enumerable: true,
|
|
1718
1668
|
get: function() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_CalmLensError = require("./CalmLensError-
|
|
2
|
-
const
|
|
1
|
+
const require_CalmLensError = require("./CalmLensError-ifj5rLmk.js");
|
|
2
|
+
const require_CalmLensCdn = require("./CalmLensCdn-2VbArrj-.js");
|
|
3
3
|
// src/contract/AssetPayload.js
|
|
4
4
|
const bufferInputToBytes = (value) => {
|
|
5
5
|
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
@@ -514,7 +514,7 @@ const textEncoder = new TextEncoder();
|
|
|
514
514
|
* read only the current part. Streams remain streamed, and buffered bodies remain retryable.
|
|
515
515
|
*/
|
|
516
516
|
const toUploadForm = async (options, payload) => {
|
|
517
|
-
const boundary = `calmlens-${
|
|
517
|
+
const boundary = `calmlens-${require_CalmLensCdn.randomUuid()}`;
|
|
518
518
|
const head = `--${boundary}\r\nContent-Disposition: form-data; name="options"\r\nContent-Type: application/json\r\n\r\n${JSON.stringify(options)}\r\n--${boundary}\r\nContent-Disposition: form-data; name="file"\r\nContent-Type: ${payload.type.replace(/[\r\n]/g, "")}\r\n\r\n`;
|
|
519
519
|
const tail = `\r\n--${boundary}--\r\n`;
|
|
520
520
|
const contentType = `multipart/form-data; boundary=${boundary}`;
|
|
@@ -578,8 +578,8 @@ const setOptionalQueryValue = (params, key, value) => {
|
|
|
578
578
|
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
579
579
|
};
|
|
580
580
|
const assertValidUploadMimeType = (mimeType) => {
|
|
581
|
-
if (!
|
|
582
|
-
message:
|
|
581
|
+
if (!require_CalmLensCdn.isAcceptedUploadMimeType(mimeType)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, {
|
|
582
|
+
message: require_CalmLensCdn.getRejectedUploadMimeTypeError(mimeType),
|
|
583
583
|
details: {
|
|
584
584
|
mimeType,
|
|
585
585
|
source: "calmlens"
|
|
@@ -604,7 +604,7 @@ const assertDeclaredPayloadSize = (payload, declared = payload.sizeInBytes) => {
|
|
|
604
604
|
const assertUploadSize = (type, size, inParts) => {
|
|
605
605
|
if (size === void 0) return;
|
|
606
606
|
const mime = type.toLowerCase();
|
|
607
|
-
const [limit, message] = mime.startsWith("image/") ? [
|
|
607
|
+
const [limit, message] = mime.startsWith("image/") ? [require_CalmLensCdn.MAX_DIRECT_IMAGE_UPLOAD_BYTES, "Images uploaded in one request can be at most 10 MiB; upload larger images in parts"] : mime.startsWith("audio/") || mime.startsWith("video/") ? [inParts ? MAX_LONG_MEDIA_UPLOAD_BYTES : MAX_MEDIA_UPLOAD_BYTES, "Audio and video files can be at most 50 MiB in one request, or 2 GiB in parts"] : [require_CalmLensCdn.MAX_NON_IMAGE_UPLOAD_BYTES, "Files can be at most 5,000 MiB"];
|
|
608
608
|
if (size > limit) throw new require_CalmLensError.CalmLensError(require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
609
609
|
message,
|
|
610
610
|
details: {
|
|
@@ -648,10 +648,10 @@ const prepareSubmitAssetOptions = (input, { deferUploadChecks = false, partSizeB
|
|
|
648
648
|
const inParts = splitsIntoParts(options.content, partSizeBytes);
|
|
649
649
|
if (inParts && (options.idempotencyKey?.length ?? 0) > 240) throw require_CalmLensError.invalidArgument(`idempotencyKey can be at most 240 characters for an upload sent in parts`);
|
|
650
650
|
if (!deferUploadChecks && inParts && isImageMimeType(options.content.type)) {
|
|
651
|
-
if ((getAssetPayloadByteLength(options.content) ?? 0) >
|
|
651
|
+
if ((getAssetPayloadByteLength(options.content) ?? 0) > require_CalmLensCdn.MAX_IMAGE_UPLOAD_BYTES) throw new require_CalmLensError.CalmLensError(require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
652
652
|
message: "Multipart image uploads cannot exceed 20 MiB.",
|
|
653
653
|
details: {
|
|
654
|
-
limitBytes:
|
|
654
|
+
limitBytes: require_CalmLensCdn.MAX_IMAGE_UPLOAD_BYTES,
|
|
655
655
|
source: "plan"
|
|
656
656
|
}
|
|
657
657
|
});
|
|
@@ -666,10 +666,10 @@ const prepareSubmitAssetOptions = (input, { deferUploadChecks = false, partSizeB
|
|
|
666
666
|
assertValidUploadMimeType(options.part.type);
|
|
667
667
|
const partSizeInBytes = options.part.sizeInBytes ?? getAssetPayloadByteLength(options.part);
|
|
668
668
|
if (!deferUploadChecks && isImageMimeType(options.part.type) && partSizeInBytes !== void 0) {
|
|
669
|
-
if (partSizeInBytes >
|
|
669
|
+
if (partSizeInBytes > require_CalmLensCdn.MAX_IMAGE_UPLOAD_BYTES) throw new require_CalmLensError.CalmLensError(require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
670
670
|
message: "Multipart image uploads cannot exceed 20 MiB.",
|
|
671
671
|
details: {
|
|
672
|
-
limitBytes:
|
|
672
|
+
limitBytes: require_CalmLensCdn.MAX_IMAGE_UPLOAD_BYTES,
|
|
673
673
|
source: "plan"
|
|
674
674
|
}
|
|
675
675
|
});
|
|
@@ -681,16 +681,9 @@ const prepareSubmitAssetOptions = (input, { deferUploadChecks = false, partSizeB
|
|
|
681
681
|
});
|
|
682
682
|
if (!validation.ok) throw invalidPayload(validation.error);
|
|
683
683
|
}
|
|
684
|
-
if (options.context !== void 0) {
|
|
685
|
-
if (!options.context || !Array.isArray(options.context.items)) throw require_CalmLensError.invalidArgument("context.items must be an array of earlier posts");
|
|
686
|
-
return {
|
|
687
|
-
...options,
|
|
688
|
-
context: { items: require_ModerationContextLimits.selectModerationContextItems(options.context.items) }
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
684
|
return options;
|
|
692
685
|
};
|
|
693
|
-
const newIdempotencyKey = () =>
|
|
686
|
+
const newIdempotencyKey = () => require_CalmLensCdn.randomUuid();
|
|
694
687
|
/** Text content is small, so it keeps the API deadline; binary files may be arbitrarily large. */
|
|
695
688
|
const isTextPayload = (payload) => "plainText" in payload;
|
|
696
689
|
const hasStringStatus = (value) => !!value && typeof value === "object" && typeof value.status === "string";
|
|
@@ -757,8 +750,8 @@ var CalmLensConnection = class CalmLensConnection {
|
|
|
757
750
|
return fetchImpl;
|
|
758
751
|
};
|
|
759
752
|
this.hooks = getMockHooks(options);
|
|
760
|
-
const logLevel =
|
|
761
|
-
this.transport = new
|
|
753
|
+
const logLevel = require_CalmLensCdn.resolveLogLevel(options.logLevel, readEnvironment);
|
|
754
|
+
this.transport = new require_CalmLensCdn.CalmLensTransport({
|
|
762
755
|
apiKey,
|
|
763
756
|
sleep: this.hooks?.sleep,
|
|
764
757
|
fetch: ((input, init) => resolveFetch()(input, init)),
|
|
@@ -831,7 +824,7 @@ var CalmLensConnection = class CalmLensConnection {
|
|
|
831
824
|
}
|
|
832
825
|
/** How the client waits between polls and retries. */
|
|
833
826
|
get sleep() {
|
|
834
|
-
return this.hooks?.sleep ??
|
|
827
|
+
return this.hooks?.sleep ?? require_CalmLensCdn.sleep;
|
|
835
828
|
}
|
|
836
829
|
/** Whether multipart size checks are left to the API (mock clients only). */
|
|
837
830
|
get deferUploadChecks() {
|
|
@@ -842,7 +835,7 @@ var CalmLensConnection = class CalmLensConnection {
|
|
|
842
835
|
}
|
|
843
836
|
/** The URL of `path` (which may carry a query already) with `query` and the call's `extraQuery`. */
|
|
844
837
|
url(path, query) {
|
|
845
|
-
const search = [query, this.call.extraQuery].map((values) => values ?
|
|
838
|
+
const search = [query, this.call.extraQuery].map((values) => values ? require_CalmLensCdn.stringifyQuery(values) : "").filter(Boolean).join("&");
|
|
846
839
|
const separator = path.includes("?") ? "&" : "?";
|
|
847
840
|
return `${this.options.baseUrl}${path}${search ? `${separator}${search}` : ""}`;
|
|
848
841
|
}
|
|
@@ -115,6 +115,7 @@ const API_ERROR_CODES = {
|
|
|
115
115
|
REMOTE_URL_UNAVAILABLE: "remote-url/unavailable",
|
|
116
116
|
APPEAL_NOT_FOUND: "appeal/not-found",
|
|
117
117
|
APPEAL_JUDGMENT_NOT_FOUND: "appeal/judgment-not-found",
|
|
118
|
+
CONTEXT_ASSET_NOT_FOUND: "context/asset-not-found",
|
|
118
119
|
APPEAL_ASSET_NOT_FOUND: "appeal/asset-not-found",
|
|
119
120
|
APPEAL_PERMISSION_DENIED: "appeal/permission-denied",
|
|
120
121
|
APPEAL_ALREADY_REVIEWED: "appeal/already-reviewed",
|
|
@@ -580,6 +581,10 @@ const API_ERROR_DEFINITIONS = {
|
|
|
580
581
|
status: 404,
|
|
581
582
|
message: "The judgment event is unavailable, belongs to another project or cannot supply an asset decision. Supply explicit context instead."
|
|
582
583
|
},
|
|
584
|
+
"context/asset-not-found": {
|
|
585
|
+
status: 400,
|
|
586
|
+
message: "A context item names an asset this project doesn't have. Reference an earlier post uploaded to the same project."
|
|
587
|
+
},
|
|
583
588
|
"appeal/asset-not-found": {
|
|
584
589
|
status: 404,
|
|
585
590
|
message: "The linked asset does not exist in this project."
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as FolderPage, At as ResetPolicyOptions, B as CreateHashListOptions, D as BatchAssetsResponse, Dt as RequestAssetReviewOptions, E as BatchAssetsOptions, Et as RemoveAssetContentOptions, Ft as SetPolicyAutomaticUpdatesOptions, G as DeleteAssetOptions, Gt as UpdateLensOptions, Ht as UpdateAssetOptions, I as ClassifyTextOptions,
|
|
3
|
-
import { d as ListPromise, l as CalmLensResponse, r as CdnResponse } from "./WebhookPayload-
|
|
1
|
+
import { c as HashList, l as HashListEntry } from "./Classification-C3pkrGYS-B7EygpJn.js";
|
|
2
|
+
import { $ as FolderPage, At as ResetPolicyOptions, B as CreateHashListOptions, Bn as AssetInfo, Cn as ProjectSettingsResource, D as BatchAssetsResponse, Dt as RequestAssetReviewOptions, E as BatchAssetsOptions, Et as RemoveAssetContentOptions, Ft as SetPolicyAutomaticUpdatesOptions, G as DeleteAssetOptions, Gt as UpdateLensOptions, Ht as UpdateAssetOptions, I as ClassifyTextOptions, It as SignAssetUrlOptions, J as EnsureLensesOptions, Jt as UpgradePolicyOptions, K as DeleteMetadataFieldOptions, Kt as UpdatePolicyOptions, Lt as SignUploadTokenOptions, M as CdnAssetUrlOptions, Mt as RetrieveAssetOptions, Nt as RetryAssetOptions, P as CdnServeOptions, Pn as Policy, Q as FolderIdOptions, Qt as UploadPresetPage, Rn as AssetSearchQuery, Rt as SignedAssetUrl, Sn as MetadataFieldsResource, T as AssignPolicyOptions, Tt as PolicyPage, U as CreatePolicyOptions, Ut as UpdateFolderOptions, V as CreateLensOptions, Vt as SubmitAssetOptions, W as DecideAssetOptions, Wt as UpdateHashListOptions, X as EnsureUploadPresetsOptions, Y as EnsureMetadataFieldsOptions, Yt as UploadAssetPartOptions, Z as EnsureUploadPresetsResponse, Zt as UploadPresetIdOptions, _ as AssetPage, _t as ListLensesOptions, b as AssetTimelinePage, bt as MoveAssetOptions, ct as LensIdOptions, dt as ListAssetTimelineOptions, et as GetAssetInfoOptions, ft as ListAssetsOptions, gt as ListHashListsOptions, ht as ListHashListEntriesOptions, it as HashListPage, jt as RetrieveAssetByExternalIdOptions, k as CalmLensServerClientOptions, kt as RequestOptions, ln as GetEventsResponse, lt as LensPage, mt as ListFoldersOptions, nt as HashListEntryPage, o as AssetChildrenPage, pt as ListEventsOptions, q as EnsureLensOptions, qt as UpdateProjectSettingsOptions, r as Asset, rn as WaitForAssetDecisionOptions, rt as HashListIdOptions, sn as AssetReviewRequest, st as Lens, t as AddHashListEntryOptions, tn as VerifyWebhookSignatureOptions, tt as HashListEntryIdOptions, ut as ListAssetChildrenOptions, v as AssetSearchResponse, vt as ListPoliciesOptions, wt as PolicyIdOptions, xn as Folder, xt as MoveFolderOptions, yt as ListUploadPresetsOptions, z as CreateFolderOptions, zt as SignedUploadToken } from "./CalmLensTypes-87kiUg0H.js";
|
|
3
|
+
import { d as ListPromise, l as CalmLensResponse, r as CdnResponse } from "./WebhookPayload-B4rA_Dvm.js";
|
|
4
4
|
interface TransportRequest {
|
|
5
5
|
/** The client method sending the request, such as `assets.retrieve`, for hooks and logs. */
|
|
6
6
|
operation?: string;
|
|
@@ -242,13 +242,17 @@ declare class CalmLensServerClient {
|
|
|
242
242
|
list: (options?: ListEventsOptions, requestOptions?: RequestOptions) => ListPromise<GetEventsResponse>;
|
|
243
243
|
/**
|
|
244
244
|
* Retrieves the asset an event is about, as it is now, such as one from `events.list` or a
|
|
245
|
-
* parsed webhook delivery; events carry only the asset's ID
|
|
246
|
-
* event that isn't about an asset, and rejects with `asset/not-found` once the
|
|
247
|
-
* deleted. The asset's `
|
|
248
|
-
* `
|
|
245
|
+
* parsed webhook delivery; events carry only the asset's ID, in `resource`. Resolves to
|
|
246
|
+
* `null` for an event that isn't about an asset, and rejects with `asset/not-found` once the
|
|
247
|
+
* asset is deleted. The asset's `sequence` orders it against events: an event with a higher
|
|
248
|
+
* `resource.sequence` happened after this state, one with an equal or lower one is reflected
|
|
249
|
+
* in it.
|
|
249
250
|
*/
|
|
250
251
|
retrieveAsset: (event: {
|
|
251
|
-
readonly
|
|
252
|
+
readonly resource?: {
|
|
253
|
+
readonly kind: string;
|
|
254
|
+
readonly id: string;
|
|
255
|
+
} | null;
|
|
252
256
|
}, requestOptions?: RequestOptions) => Promise<CalmLensResponse<Asset> | null>;
|
|
253
257
|
};
|
|
254
258
|
get folders(): {
|