calmlens 0.31.1 → 0.33.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 +54 -42
- package/cjs/{BrowserUpload-BwBE37LM.js → BrowserUpload-Al3ER3ki.js} +1 -1
- package/cjs/{BrowserUpload-BAH54V1q.d.ts → BrowserUpload-CURmX-DR.d.ts} +2 -2
- package/cjs/{CalmLensAppClient-CdlcDd5l.d.ts → CalmLensAppClient-DII9cdTD.d.ts} +3 -3
- package/cjs/{CalmLensAppClient-D6Y7MgH_.js → CalmLensAppClient-DWIy2yPF.js} +4 -4
- package/cjs/{CalmLensCdn-Q68faCEE.js → CalmLensCdn-6ZqvG8-v.js} +56 -22
- package/cjs/{CalmLensConnection-j2aBsuNx.js → CalmLensConnection-Qp9ucGHO.js} +7 -16
- package/cjs/{CalmLensServerClient-CtS66dCU.d.ts → CalmLensServerClient-CPwGfFR-.d.ts} +10 -10
- package/cjs/{CalmLensServerClient-CjK691kq.js → CalmLensServerClient-DRLyvnA1.js} +19 -19
- package/cjs/{CalmLensTypes-87kiUg0H.d.ts → CalmLensTypes-DF7wh23M.d.ts} +16527 -16498
- package/cjs/{Core-Ccy4-_sN.d.ts → Core-Dnm9bJPB.d.ts} +2 -2
- package/cjs/{Core-Dsj4tRNP.js → Core-rYZedJhi.js} +2 -2
- package/cjs/{ReactUpload-DBhppuxM.d.ts → ReactUpload-B7wrDPk8.d.ts} +1 -1
- package/cjs/{ReactUpload-B7SdNAel.js → ReactUpload-Bj6-CciJ.js} +1 -1
- package/{esm/TestTriggers-Daxebd0V.d.ts → cjs/TestTriggers-CjDhhz78.d.ts} +1 -11
- package/cjs/{UploadController-DsIENVY1.js → UploadController-DCr7oN6L.js} +1 -1
- package/cjs/{WebhookPayload-B4rA_Dvm.d.ts → WebhookPayload-CUMsersa.d.ts} +1 -1
- package/cjs/app.d.ts +5 -5
- package/cjs/app.js +2 -2
- package/cjs/elements.d.ts +4 -4
- package/cjs/elements.js +4 -4
- package/cjs/{index-CWUnLKoF.d.ts → index-B511mjeS.d.ts} +2 -2
- package/cjs/index.d.ts +4 -4
- package/cjs/index.js +1 -1
- package/cjs/react-native.d.ts +2 -2
- package/cjs/react-native.js +4 -4
- package/cjs/react.d.ts +4 -4
- package/cjs/react.js +5 -5
- package/cjs/server.d.ts +5 -5
- package/cjs/server.js +2 -2
- package/cjs/test-inputs.d.ts +15 -3
- package/cjs/test-inputs.js +105 -2
- package/cjs/testing.d.ts +14 -6
- package/cjs/testing.js +122 -53
- package/cjs/{ui-sjnJhloQ.d.ts → ui-B83Pqjom.d.ts} +2 -2
- package/cjs/{ui-BC70R8KT.js → ui-BS9eFCI7.js} +8 -8
- 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/esm/{BrowserUpload-BAH54V1q.d.ts → BrowserUpload-CURmX-DR.d.ts} +2 -2
- package/esm/{BrowserUpload-DSLCpWgz.js → BrowserUpload-DOcZaSWT.js} +1 -1
- package/esm/{CalmLensAppClient-BKanqwYL.js → CalmLensAppClient-B7IkEK2D.js} +4 -4
- package/esm/{CalmLensAppClient-CdlcDd5l.d.ts → CalmLensAppClient-DII9cdTD.d.ts} +3 -3
- package/esm/{CalmLensCdn-CL1P1v2t.js → CalmLensCdn-DpJ7kIqG.js} +39 -23
- package/esm/{CalmLensConnection-CHNNULpg.js → CalmLensConnection-BYUqUitO.js} +7 -16
- package/esm/{CalmLensServerClient-CtS66dCU.d.ts → CalmLensServerClient-CPwGfFR-.d.ts} +10 -10
- package/esm/{CalmLensServerClient-CBjSqROz.js → CalmLensServerClient-DpkreSH6.js} +19 -19
- package/esm/{CalmLensTypes-87kiUg0H.d.ts → CalmLensTypes-DF7wh23M.d.ts} +16527 -16498
- package/esm/{Core-WxPuobo_.js → Core-DGF84gwM.js} +2 -2
- package/esm/{Core-Ccy4-_sN.d.ts → Core-Dnm9bJPB.d.ts} +2 -2
- package/esm/{ReactUpload-DBhppuxM.d.ts → ReactUpload-B7wrDPk8.d.ts} +1 -1
- package/esm/{ReactUpload-U49veoZl.js → ReactUpload-rDvF5arL.js} +1 -1
- package/{cjs/TestTriggers-Daxebd0V.d.ts → esm/TestTriggers-CjDhhz78.d.ts} +1 -11
- package/esm/{UploadController-X2gEFMGy.js → UploadController-cXocXbjd.js} +1 -1
- package/esm/{WebhookPayload-B4rA_Dvm.d.ts → WebhookPayload-CUMsersa.d.ts} +1 -1
- package/esm/app.d.ts +5 -5
- package/esm/app.js +2 -2
- package/esm/elements.d.ts +4 -4
- package/esm/elements.js +4 -4
- package/esm/{index-CWUnLKoF.d.ts → index-B511mjeS.d.ts} +2 -2
- package/esm/index.d.ts +4 -4
- package/esm/index.js +1 -1
- 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 +5 -5
- package/esm/server.js +2 -2
- package/esm/test-inputs.d.ts +15 -3
- package/esm/test-inputs.js +105 -2
- package/esm/testing.d.ts +14 -6
- package/esm/testing.js +122 -53
- package/esm/{ui-sjnJhloQ.d.ts → ui-B83Pqjom.d.ts} +2 -2
- package/esm/{ui-DS85DGfi.js → ui-C0wgePYT.js} +8 -8
- 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/cjs/testing.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_CalmLensTestInputArguments = require("./CalmLensTestInputArguments-PYuRmE0j.js");
|
|
3
3
|
const require_CalmLensError = require("./CalmLensError-ifj5rLmk.js");
|
|
4
|
-
const require_CalmLensCdn = require("./CalmLensCdn-
|
|
5
|
-
const require_CalmLensServerClient = require("./CalmLensServerClient-
|
|
6
|
-
const require_CalmLensConnection = require("./CalmLensConnection-
|
|
4
|
+
const require_CalmLensCdn = require("./CalmLensCdn-6ZqvG8-v.js");
|
|
5
|
+
const require_CalmLensServerClient = require("./CalmLensServerClient-DRLyvnA1.js");
|
|
6
|
+
const require_CalmLensConnection = require("./CalmLensConnection-Qp9ucGHO.js");
|
|
7
7
|
const require_CryptoUtils_BLCa_oZe = require("./CryptoUtils-BLCa-oZe-leCkr1ko.js");
|
|
8
|
-
const require_CalmLensAppClient = require("./CalmLensAppClient-
|
|
9
|
-
const require_UploadController = require("./UploadController-
|
|
8
|
+
const require_CalmLensAppClient = require("./CalmLensAppClient-DWIy2yPF.js");
|
|
9
|
+
const require_UploadController = require("./UploadController-DCr7oN6L.js");
|
|
10
10
|
let zod = require("zod");
|
|
11
11
|
let zod$1 = require_CalmLensTestInputArguments.__toESM(zod, 1);
|
|
12
12
|
zod = require_CalmLensTestInputArguments.__toESM(zod);
|
|
@@ -8535,7 +8535,6 @@ var MockDecision = class {
|
|
|
8535
8535
|
rule: null,
|
|
8536
8536
|
automatedStatus: status,
|
|
8537
8537
|
regions: [],
|
|
8538
|
-
linkSafety: null,
|
|
8539
8538
|
timeline: null,
|
|
8540
8539
|
flaggedCategories: evaluated.filter(([, score]) => action(score) !== "allow").map(([category]) => category),
|
|
8541
8540
|
raw: {
|
|
@@ -8703,20 +8702,6 @@ const MOCK_ASSET_FILTER_FIELDS = {
|
|
|
8703
8702
|
"=out="
|
|
8704
8703
|
]
|
|
8705
8704
|
},
|
|
8706
|
-
description: {
|
|
8707
|
-
kind: "text",
|
|
8708
|
-
nullable: true,
|
|
8709
|
-
operators: [
|
|
8710
|
-
"==",
|
|
8711
|
-
"!=",
|
|
8712
|
-
">",
|
|
8713
|
-
">=",
|
|
8714
|
-
"<",
|
|
8715
|
-
"<=",
|
|
8716
|
-
"=in=",
|
|
8717
|
-
"=out="
|
|
8718
|
-
]
|
|
8719
|
-
},
|
|
8720
8705
|
externalId: {
|
|
8721
8706
|
kind: "text",
|
|
8722
8707
|
nullable: true,
|
|
@@ -9235,17 +9220,20 @@ const filterAssets = (items, filter) => {
|
|
|
9235
9220
|
return items.filter((item) => matchesNode(item, node));
|
|
9236
9221
|
};
|
|
9237
9222
|
const MAX_SEARCH_TOKENS = 8;
|
|
9238
|
-
/**
|
|
9239
|
-
|
|
9223
|
+
/**
|
|
9224
|
+
* The keyword fields the API searches, in the order it reports matches. `extractedText` is the
|
|
9225
|
+
* asset's retained text: empty unless its content is stored.
|
|
9226
|
+
*/
|
|
9227
|
+
const searchFieldValues = (asset, extractedText) => [
|
|
9240
9228
|
["name", asset.name],
|
|
9241
9229
|
["id", asset.id],
|
|
9242
9230
|
["externalId", asset.externalId ?? ""],
|
|
9243
|
-
["description", asset.description ?? ""],
|
|
9244
9231
|
["tags", asset.tags?.join(" ") ?? ""],
|
|
9245
9232
|
["type", asset.type],
|
|
9246
9233
|
["content.format", asset.content?.format ?? ""],
|
|
9247
9234
|
["content.extension", asset.content?.extension ?? ""],
|
|
9248
|
-
["classification.moderation.decision", asset.classification.moderation.decision ?? "pending"]
|
|
9235
|
+
["classification.moderation.decision", asset.classification.moderation.decision ?? "pending"],
|
|
9236
|
+
["content.extractedText", extractedText]
|
|
9249
9237
|
];
|
|
9250
9238
|
/** The API's keyword score for the whole lowercased query. */
|
|
9251
9239
|
const keywordScore = (values, query) => {
|
|
@@ -9264,15 +9252,15 @@ const keywordScore = (values, query) => {
|
|
|
9264
9252
|
};
|
|
9265
9253
|
/**
|
|
9266
9254
|
* Keyword search as the API runs it: every whitespace-separated token (case-insensitive, at
|
|
9267
|
-
* most 8) must appear in some searchable field
|
|
9268
|
-
* newest first.
|
|
9255
|
+
* most 8) must appear in some searchable field, including the asset's retained text, which
|
|
9256
|
+
* `extractedTexts` maps by asset ID. Results are ranked by the API's score, then newest first.
|
|
9269
9257
|
*/
|
|
9270
|
-
const searchAssets = (assets, query, limit) => {
|
|
9258
|
+
const searchAssets = (assets, extractedTexts, query, limit) => {
|
|
9271
9259
|
const normalized = query.trim().toLowerCase();
|
|
9272
9260
|
const tokens = [...new Set(normalized.split(/\s+/).filter(Boolean))].slice(0, MAX_SEARCH_TOKENS);
|
|
9273
9261
|
if (tokens.length === 0) return [];
|
|
9274
9262
|
return assets.map((asset) => {
|
|
9275
|
-
const fields = searchFieldValues(asset).map(([field, value]) => [field, value.toLowerCase()]);
|
|
9263
|
+
const fields = searchFieldValues(asset, extractedTexts.get(asset.id) ?? "").map(([field, value]) => [field, value.toLowerCase()]);
|
|
9276
9264
|
return {
|
|
9277
9265
|
asset,
|
|
9278
9266
|
matches: tokens.every((token) => fields.some(([, value]) => value.includes(token))),
|
|
@@ -9382,8 +9370,12 @@ const checkMockUploadPreset = (preset) => {
|
|
|
9382
9370
|
if (unknown.length) throw require_CalmLensError.invalidArgument(`Unknown mockOptions.preset key${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}`, { options: unknown });
|
|
9383
9371
|
};
|
|
9384
9372
|
const MAX_PAGE_SIZE = 100;
|
|
9385
|
-
/**
|
|
9373
|
+
/** Hashes with a lower PDQ quality never match (HashList.ts, HASH_MATCH_MIN_QUALITY). */
|
|
9386
9374
|
const HASH_MATCH_MIN_QUALITY = 50;
|
|
9375
|
+
/** Hashes this many bits apart or fewer match (HashList.ts, HASH_MATCH_MAX_DISTANCE). */
|
|
9376
|
+
const HASH_MATCH_MAX_DISTANCE = 31;
|
|
9377
|
+
/** A block list blocks only matches this close; looser ones are flagged (HASH_BLOCK_MAX_DISTANCE). */
|
|
9378
|
+
const HASH_BLOCK_MAX_DISTANCE = 16;
|
|
9387
9379
|
/** The most hash matches an asset records (HashList.ts). */
|
|
9388
9380
|
const MAX_RECORDED_HASH_MATCHES = 10;
|
|
9389
9381
|
const MAX_DECISION_NOTE_LENGTH = 1499;
|
|
@@ -9628,7 +9620,6 @@ const invalidField = (code, path) => new ApiFailure(400, require_CalmLensError.A
|
|
|
9628
9620
|
/** The asset fields an upload carries in its body; the API refuses them in the query string. */
|
|
9629
9621
|
const UPLOAD_OPTION_KEYS = [
|
|
9630
9622
|
"name",
|
|
9631
|
-
"description",
|
|
9632
9623
|
"processingOptions",
|
|
9633
9624
|
"visibility",
|
|
9634
9625
|
"metadata",
|
|
@@ -9861,12 +9852,14 @@ var MockCalmLensApi = class {
|
|
|
9861
9852
|
this.cdnBaseUrl = "";
|
|
9862
9853
|
this.lenses = /* @__PURE__ */ new Map();
|
|
9863
9854
|
this.eventFeed = [];
|
|
9855
|
+
this.usedUploadTokens = /* @__PURE__ */ new Set();
|
|
9864
9856
|
this.assetEventSequences = /* @__PURE__ */ new Map();
|
|
9865
9857
|
this.processingOptions = /* @__PURE__ */ new Map();
|
|
9866
9858
|
this.openUploads = /* @__PURE__ */ new Map();
|
|
9867
9859
|
this.idempotentResults = /* @__PURE__ */ new Map();
|
|
9868
9860
|
this.pendingFailures = [];
|
|
9869
9861
|
this.servedUrls = /* @__PURE__ */ new Map();
|
|
9862
|
+
this.perceptualHashes = [];
|
|
9870
9863
|
this.pendingReviews = /* @__PURE__ */ new Map();
|
|
9871
9864
|
this.requestCount = 0;
|
|
9872
9865
|
this.useTimers = false;
|
|
@@ -9931,6 +9924,24 @@ var MockCalmLensApi = class {
|
|
|
9931
9924
|
type: type.trim()
|
|
9932
9925
|
});
|
|
9933
9926
|
}
|
|
9927
|
+
/**
|
|
9928
|
+
* Makes an image upload of exactly `content` hash as `hash` (64 hexadecimal characters, a PDQ
|
|
9929
|
+
* hash) with `quality`, instead of the SHA-256 of its bytes.
|
|
9930
|
+
*/
|
|
9931
|
+
setPerceptualHash(content, hash, quality = 100) {
|
|
9932
|
+
const bytes = typeof content === "string" ? new TextEncoder().encode(content) : content instanceof ArrayBuffer ? new Uint8Array(content.slice(0)) : content instanceof Uint8Array ? new Uint8Array(content) : void 0;
|
|
9933
|
+
if (!bytes) throw require_CalmLensError.invalidArgument("content must be bytes or a string");
|
|
9934
|
+
if (typeof hash !== "string" || !/^[0-9a-f]{64}$/i.test(hash.trim())) throw require_CalmLensError.invalidArgument("hash must be a PDQ hash of 64 hexadecimal characters");
|
|
9935
|
+
if (typeof quality !== "number" || !Number.isInteger(quality) || quality < 0 || quality > 100) throw require_CalmLensError.invalidArgument("quality must be a whole number from 0 to 100");
|
|
9936
|
+
const declared = {
|
|
9937
|
+
bytes,
|
|
9938
|
+
hash: hash.trim().toLowerCase(),
|
|
9939
|
+
quality
|
|
9940
|
+
};
|
|
9941
|
+
const index = this.perceptualHashes.findIndex((known) => sameBytes(known.bytes, bytes));
|
|
9942
|
+
if (index === -1) this.perceptualHashes.push(declared);
|
|
9943
|
+
else this.perceptualHashes[index] = declared;
|
|
9944
|
+
}
|
|
9934
9945
|
/** A `fetch` that answers a client's requests from memory; app clients pass their session. */
|
|
9935
9946
|
createFetch(endpoints, session) {
|
|
9936
9947
|
return ((input, init) => this.handle(input, init, endpoints(), session));
|
|
@@ -10736,8 +10747,9 @@ var MockCalmLensApi = class {
|
|
|
10736
10747
|
}
|
|
10737
10748
|
/**
|
|
10738
10749
|
* Keyword search like the API's: every whitespace-separated token must appear,
|
|
10739
|
-
* case-insensitively, in the asset's name, ID, external ID,
|
|
10740
|
-
*
|
|
10750
|
+
* case-insensitively, in the asset's name, ID, external ID, tags, type, content format or
|
|
10751
|
+
* extension, moderation status, or retained text while its content is stored. There is no
|
|
10752
|
+
* semantic search.
|
|
10741
10753
|
*/
|
|
10742
10754
|
async searchAssets(params) {
|
|
10743
10755
|
const query = (params.get("query") ?? "").trim();
|
|
@@ -10746,9 +10758,11 @@ var MockCalmLensApi = class {
|
|
|
10746
10758
|
const pageSize = this.integer(params, "pageSize", 10);
|
|
10747
10759
|
if (pageSize < 1) throw invalidField("validation/too-small", "pageSize");
|
|
10748
10760
|
if (pageSize > MAX_SEARCH_PAGE_SIZE) throw invalidField("validation/too-big", "pageSize");
|
|
10761
|
+
const assets = await this.databaseStorage.listAssets(this.projectId);
|
|
10762
|
+
const extractedTexts = new Map(await Promise.all(assets.map(async (asset) => [asset.id, await this.searchText(asset)])));
|
|
10749
10763
|
return {
|
|
10750
10764
|
query,
|
|
10751
|
-
items: searchAssets(
|
|
10765
|
+
items: searchAssets(assets, extractedTexts, query, pageSize),
|
|
10752
10766
|
semanticStatus: "disabled"
|
|
10753
10767
|
};
|
|
10754
10768
|
}
|
|
@@ -11091,7 +11105,6 @@ var MockCalmLensApi = class {
|
|
|
11091
11105
|
createdAt: now,
|
|
11092
11106
|
updatedAt: now,
|
|
11093
11107
|
name: fields.name,
|
|
11094
|
-
description: fields.description ?? null,
|
|
11095
11108
|
externalId: fields.externalId ?? null,
|
|
11096
11109
|
externalUrl: fields.url ?? fields.externalUrl ?? null,
|
|
11097
11110
|
type,
|
|
@@ -11288,10 +11301,19 @@ var MockCalmLensApi = class {
|
|
|
11288
11301
|
}
|
|
11289
11302
|
/** An earlier post's text, to the most CalmLens reads of one post; empty once its content is gone. */
|
|
11290
11303
|
async contextText(asset) {
|
|
11304
|
+
const text = (await this.retainedText(asset)).trim();
|
|
11305
|
+
return Array.from(text).slice(0, MODERATION_CONTEXT_MAX_ITEM_CHARACTERS).join("");
|
|
11306
|
+
}
|
|
11307
|
+
/** The text keyword search reads, like the API: the retained text, only while content is stored. */
|
|
11308
|
+
async searchText(asset) {
|
|
11309
|
+
return asset.content.status === "stored" ? this.retainedText(asset) : "";
|
|
11310
|
+
}
|
|
11311
|
+
/** A text upload's stored bytes, or the text extracted from its content (such as OCR). */
|
|
11312
|
+
async retainedText(asset) {
|
|
11291
11313
|
const extracted = asset.content.extractedText;
|
|
11292
11314
|
const bytes = asset.type === "plaintext-document" && await this.storedBytes(asset);
|
|
11293
|
-
|
|
11294
|
-
return
|
|
11315
|
+
if (bytes) return new TextDecoder().decode(bytes);
|
|
11316
|
+
return extracted?.type === "string" ? extracted.content : "";
|
|
11295
11317
|
}
|
|
11296
11318
|
async storedBytes(asset) {
|
|
11297
11319
|
if (asset.content.status === "removed") return null;
|
|
@@ -11302,28 +11324,40 @@ var MockCalmLensApi = class {
|
|
|
11302
11324
|
}
|
|
11303
11325
|
/**
|
|
11304
11326
|
* A decided image with its hash and the project's hash list matches, as the API records them
|
|
11305
|
-
* (AssetClassification.ts,
|
|
11327
|
+
* (AssetClassification.ts, HashMatching.ts and HashList.ts). The mock computes no PDQ hash: an
|
|
11306
11328
|
* image's `content.perceptualHash` is the SHA-256 of its bytes in lowercase hex, with quality
|
|
11307
|
-
* 100,
|
|
11308
|
-
*
|
|
11309
|
-
*
|
|
11310
|
-
*
|
|
11329
|
+
* 100, unless `setPerceptualHash` declared one for those bytes. An entry matches a hash up to 31
|
|
11330
|
+
* bits away, so different images' SHA-256 stand-ins never match, and an entry taken from an
|
|
11331
|
+
* image matches the same bytes at distance 0. Hashes below quality 50 never match. A match takes
|
|
11332
|
+
* its list's action, except that a block list only flags matches more than 16 bits away;
|
|
11333
|
+
* blocking matches come first, then the closest. A block raises an allowed, limited or
|
|
11334
|
+
* age-restricted decision to `blocked`, with `source: "hash-list"`, and a flag only records the
|
|
11335
|
+
* match.
|
|
11311
11336
|
*/
|
|
11312
11337
|
async withHashMatches(asset, bytes) {
|
|
11313
|
-
const hash
|
|
11314
|
-
|
|
11315
|
-
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11338
|
+
const { hash, quality } = this.perceptualHashes.find((known) => sameBytes(known.bytes, bytes)) ?? {
|
|
11339
|
+
hash: await sha256Hex(bytes),
|
|
11340
|
+
quality: 100
|
|
11341
|
+
};
|
|
11342
|
+
const matches = [...this.hashListEntries.values()].flatMap((entry) => {
|
|
11343
|
+
const list = this.hashLists.get(entry.hashListId);
|
|
11344
|
+
const distance = hashDistance(hash, entry.hash);
|
|
11345
|
+
if (!list || quality < HASH_MATCH_MIN_QUALITY || entry.quality !== null && entry.quality < HASH_MATCH_MIN_QUALITY || distance > HASH_MATCH_MAX_DISTANCE) return [];
|
|
11346
|
+
const action = list.action === "block" && distance <= HASH_BLOCK_MAX_DISTANCE ? "block" : "flag";
|
|
11347
|
+
return [{
|
|
11348
|
+
source: "hash-list",
|
|
11349
|
+
hashListId: entry.hashListId,
|
|
11350
|
+
hashListEntryId: entry.id,
|
|
11351
|
+
distance,
|
|
11352
|
+
action
|
|
11353
|
+
}];
|
|
11354
|
+
}).sort((a, b) => Number(b.action === "block") - Number(a.action === "block") || a.distance - b.distance).slice(0, MAX_RECORDED_HASH_MATCHES);
|
|
11321
11355
|
const hashed = {
|
|
11322
11356
|
...asset,
|
|
11323
11357
|
content: {
|
|
11324
11358
|
...asset.content,
|
|
11325
11359
|
perceptualHash: hash,
|
|
11326
|
-
perceptualHashQuality:
|
|
11360
|
+
perceptualHashQuality: quality
|
|
11327
11361
|
}
|
|
11328
11362
|
};
|
|
11329
11363
|
if (!matches.length) return hashed;
|
|
@@ -11657,7 +11691,9 @@ var MockCalmLensApi = class {
|
|
|
11657
11691
|
const fields = this.uploadFields(request);
|
|
11658
11692
|
const token = request.headers.get("authorization");
|
|
11659
11693
|
if (preset.access === "token" && !token) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_TOKEN_REQUIRED);
|
|
11660
|
-
const
|
|
11694
|
+
const claims = token ? require_CalmLensServerClient.decodeUploadToken(token.replace(/^Bearer /, ""))?.claims : void 0;
|
|
11695
|
+
if (claims && this.usedUploadTokens.has(claims.n)) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_TOKEN_USED);
|
|
11696
|
+
const tokenExternalId = claims?.x;
|
|
11661
11697
|
if (fields.externalId && fields.externalId !== tokenExternalId) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "externalId" } });
|
|
11662
11698
|
for (const field of [
|
|
11663
11699
|
"metadata",
|
|
@@ -11679,6 +11715,7 @@ var MockCalmLensApi = class {
|
|
|
11679
11715
|
limitBytes: preset.maxSizeInBytes,
|
|
11680
11716
|
source: "preset"
|
|
11681
11717
|
} });
|
|
11718
|
+
if (claims) this.usedUploadTokens.add(claims.n);
|
|
11682
11719
|
const asset = await this.storeAsset({
|
|
11683
11720
|
...fields,
|
|
11684
11721
|
externalId: tokenExternalId,
|
|
@@ -11689,7 +11726,10 @@ var MockCalmLensApi = class {
|
|
|
11689
11726
|
...preset.processingOptions?.features && { features: preset.processingOptions.features },
|
|
11690
11727
|
retainContent: preset.processingOptions?.retainContent ?? true
|
|
11691
11728
|
}
|
|
11692
|
-
}, request.query.get("wait") === "false")
|
|
11729
|
+
}, request.query.get("wait") === "false").catch((error) => {
|
|
11730
|
+
if (claims) this.usedUploadTokens.delete(claims.n);
|
|
11731
|
+
throw error;
|
|
11732
|
+
});
|
|
11693
11733
|
session.uploads.add(asset.id);
|
|
11694
11734
|
return toUploaded(asset);
|
|
11695
11735
|
}
|
|
@@ -12246,6 +12286,25 @@ var MockCalmLensApi = class {
|
|
|
12246
12286
|
});
|
|
12247
12287
|
}
|
|
12248
12288
|
};
|
|
12289
|
+
/** The SHA-256 of `bytes` in lowercase hex. */
|
|
12290
|
+
async function sha256Hex(bytes) {
|
|
12291
|
+
return [...new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
12292
|
+
}
|
|
12293
|
+
/** How many bits two 64-character hex hashes differ by. */
|
|
12294
|
+
function hashDistance(a, b) {
|
|
12295
|
+
let distance = 0;
|
|
12296
|
+
for (let i = 0; i < 64; i += 8) {
|
|
12297
|
+
let bits = (Number.parseInt(a.slice(i, i + 8), 16) ^ Number.parseInt(b.slice(i, i + 8), 16)) >>> 0;
|
|
12298
|
+
while (bits) {
|
|
12299
|
+
bits &= bits - 1;
|
|
12300
|
+
distance++;
|
|
12301
|
+
}
|
|
12302
|
+
}
|
|
12303
|
+
return distance;
|
|
12304
|
+
}
|
|
12305
|
+
function sameBytes(a, b) {
|
|
12306
|
+
return a.length === b.length && a.every((byte, i) => byte === b[i]);
|
|
12307
|
+
}
|
|
12249
12308
|
// src/testing/MockStorage.ts
|
|
12250
12309
|
var InMemoryMockImageStorage = class {
|
|
12251
12310
|
constructor() {
|
|
@@ -12431,7 +12490,7 @@ var MockCalmLensServerClient = class extends require_CalmLensServerClient.CalmLe
|
|
|
12431
12490
|
}
|
|
12432
12491
|
/**
|
|
12433
12492
|
* Fetches a URL of the mock's CDN as a browser would, without the API key: a signed asset URL
|
|
12434
|
-
* from `cdn.signAssetUrl
|
|
12493
|
+
* from `cdn.signAssetUrl`, or a public one from `cdn.getAssetUrl`.
|
|
12435
12494
|
* The request is recorded like any other.
|
|
12436
12495
|
*/
|
|
12437
12496
|
fetchCdn(url, init) {
|
|
@@ -12477,6 +12536,16 @@ var MockCalmLensServerClient = class extends require_CalmLensServerClient.CalmLe
|
|
|
12477
12536
|
this.#api.serveUrl(url, content);
|
|
12478
12537
|
}
|
|
12479
12538
|
/**
|
|
12539
|
+
* Makes the mock hash an image upload of exactly `content` (bytes, or text as UTF-8) as `hash`, a
|
|
12540
|
+
* PDQ hash of 64 hexadecimal characters, with `quality` (0 to 100, default 100), instead of the
|
|
12541
|
+
* SHA-256 of its bytes. Hash list entries match hashes up to 31 bits away, as in CalmLens, so a
|
|
12542
|
+
* test can make a resized or recompressed copy a near match of a listed image: declare the
|
|
12543
|
+
* copy's hash a few bits from the entry's.
|
|
12544
|
+
*/
|
|
12545
|
+
setPerceptualHash(content, hash, quality = 100) {
|
|
12546
|
+
this.#api.setPerceptualHash(content, hash, quality);
|
|
12547
|
+
}
|
|
12548
|
+
/**
|
|
12480
12549
|
* Changes the grants of the mock's API key, as editing the key in the portal would: later
|
|
12481
12550
|
* requests, such as `cdn.serve`, use them. The key itself stays the same, so idempotency keys
|
|
12482
12551
|
* it used still replay.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./CalmLensTypes-
|
|
2
|
-
import { K as AssetOptions, Z as AssetView, ct as DocumentViewerOptions, dt as TextViewerOptions, lt as PdfAssetOptions, pt as ViewerOptions, q as AssetSession, ut as SpreadsheetViewerOptions } from "./Core-
|
|
1
|
+
import "./CalmLensTypes-DF7wh23M.js";
|
|
2
|
+
import { K as AssetOptions, Z as AssetView, ct as DocumentViewerOptions, dt as TextViewerOptions, lt as PdfAssetOptions, pt as ViewerOptions, q as AssetSession, ut as SpreadsheetViewerOptions } from "./Core-Dnm9bJPB.js";
|
|
3
3
|
import "pdfjs-dist";
|
|
4
4
|
/** A viewer mounted into an element, which it owns the children of. */
|
|
5
5
|
interface AssetViewer<O extends ViewerOptions = ViewerOptions> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_CalmLensCdn = require("./CalmLensCdn-
|
|
2
|
-
require("./Core-
|
|
1
|
+
const require_CalmLensCdn = require("./CalmLensCdn-6ZqvG8-v.js");
|
|
2
|
+
require("./Core-rYZedJhi.js");
|
|
3
3
|
// src/ui/viewers/PdfLoader.ts
|
|
4
4
|
let loading;
|
|
5
5
|
/**
|
|
@@ -81,11 +81,11 @@ const responseCode = async (response) => {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
|
-
* The CDN URLs a viewer loads: resource paths beneath the asset URL
|
|
85
|
-
* with the viewer claims that say something. When a URL
|
|
86
|
-
* signed one does, it asks `onExpired` once for a fresh
|
|
87
|
-
* has worked (`loaded`), so a URL that keeps failing ends in the
|
|
88
|
-
* `onExpired` nothing is refreshed.
|
|
84
|
+
* The CDN URLs a viewer loads: resource paths beneath the asset URL of `src` (a public or signed
|
|
85
|
+
* asset URL, or a resource URL beneath one), with the viewer claims that say something. When a URL
|
|
86
|
+
* stops working (`refresh`), as an expired signed one does, it asks `onExpired` once for a fresh
|
|
87
|
+
* URL, and again only after that one has worked (`loaded`), so a URL that keeps failing ends in the
|
|
88
|
+
* viewer's fallback. Without `onExpired` nothing is refreshed.
|
|
89
89
|
*/
|
|
90
90
|
var ViewerUrls = class {
|
|
91
91
|
#options;
|
|
@@ -112,7 +112,7 @@ var ViewerUrls = class {
|
|
|
112
112
|
/** A resource's URL beneath the asset URL. The placeholder is never age-gated, so it needs no age claim. */
|
|
113
113
|
url(resource, transform) {
|
|
114
114
|
const { viewerClaims } = this.#options;
|
|
115
|
-
return require_CalmLensCdn.appendAssetLocation(this.#src, {
|
|
115
|
+
return require_CalmLensCdn.appendAssetLocation(require_CalmLensCdn.assetUrlOf(this.#src), {
|
|
116
116
|
resource,
|
|
117
117
|
transform,
|
|
118
118
|
viewerClaims: resource === "placeholder" && viewerClaims ? { region: viewerClaims.region } : viewerClaims
|
package/cjs/ui.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as MediaPlayback, A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadFile, G as AssetImageSource, H as AssetDisplay, I as UploadItem, J as AssetSessionState, K as AssetOptions, L as UploadSnapshot, M as UploadClient, N as UploadController, O as CalmLensProvidedOptions, P as UploadControllerOptions, Q as INSTANT_LOAD_MS, R as UploadStage, S as formatBytes, T as getUploadItemMessage, U as AssetDocumentOptions, V as withProvidedOptions, W as AssetImageOptions, X as AssetVideoOptions, Y as AssetSpreadsheetOptions, Z as AssetView, _ as DEFAULT_MESSAGES, _t as DEFAULT_VIEWER_MESSAGES, a as ProgressFetchOptions, at as isImageReady, b as describeUploadItem, bt as resolveViewerMessages, c as ICON_ATTRIBUTES, ct as DocumentViewerOptions, d as AssetDisplayOptions, dt as TextViewerOptions, et as getAssetAspectRatio, f as AssetEventHandlers, ft as ViewerAsset, g as CalmLensMessages, gt as isSpreadsheetFormat, h as UploaderProps, ht as getAssetViewerKind, i as CALMLENS_STYLES, it as getPlayedPercent, j as CustomUploadResult, k as CalmLensUpload, l as IconName, lt as PdfAssetOptions, m as UploaderDisplayOptions, mt as ViewerTextOptions, n as CalmLensTheme, nt as getAssetViewKey, o as createProgressFetch, ot as pickAssetSource, p as AssetProps, pt as ViewerOptions, q as AssetSession, r as resolveTheme, rt as getPeakHeights, s as ICONS, st as AssetViewerKind, t as CALMLENS_THEME, tt as getAssetView, u as ASSET_FILE_ICON_SIZE, ut as SpreadsheetViewerOptions, v as UploadItemView, vt as ViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, yt as formatViewerMessage, z as createUploadController } from "./Core-
|
|
2
|
-
import { _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as AssetViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as ViewerState, y as createDocumentViewer } from "./ui-
|
|
1
|
+
import { $ as MediaPlayback, A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadFile, G as AssetImageSource, H as AssetDisplay, I as UploadItem, J as AssetSessionState, K as AssetOptions, L as UploadSnapshot, M as UploadClient, N as UploadController, O as CalmLensProvidedOptions, P as UploadControllerOptions, Q as INSTANT_LOAD_MS, R as UploadStage, S as formatBytes, T as getUploadItemMessage, U as AssetDocumentOptions, V as withProvidedOptions, W as AssetImageOptions, X as AssetVideoOptions, Y as AssetSpreadsheetOptions, Z as AssetView, _ as DEFAULT_MESSAGES, _t as DEFAULT_VIEWER_MESSAGES, a as ProgressFetchOptions, at as isImageReady, b as describeUploadItem, bt as resolveViewerMessages, c as ICON_ATTRIBUTES, ct as DocumentViewerOptions, d as AssetDisplayOptions, dt as TextViewerOptions, et as getAssetAspectRatio, f as AssetEventHandlers, ft as ViewerAsset, g as CalmLensMessages, gt as isSpreadsheetFormat, h as UploaderProps, ht as getAssetViewerKind, i as CALMLENS_STYLES, it as getPlayedPercent, j as CustomUploadResult, k as CalmLensUpload, l as IconName, lt as PdfAssetOptions, m as UploaderDisplayOptions, mt as ViewerTextOptions, n as CalmLensTheme, nt as getAssetViewKey, o as createProgressFetch, ot as pickAssetSource, p as AssetProps, pt as ViewerOptions, q as AssetSession, r as resolveTheme, rt as getPeakHeights, s as ICONS, st as AssetViewerKind, t as CALMLENS_THEME, tt as getAssetView, u as ASSET_FILE_ICON_SIZE, ut as SpreadsheetViewerOptions, v as UploadItemView, vt as ViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, yt as formatViewerMessage, z as createUploadController } from "./Core-Dnm9bJPB.js";
|
|
2
|
+
import { _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as AssetViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as ViewerState, y as createDocumentViewer } from "./ui-B83Pqjom.js";
|
|
3
3
|
export { ASSET_FILE_ICON_SIZE, ASSET_VIEWERS, type AssetDisplay, type AssetDisplayOptions, type AssetDocumentOptions, type AssetEventHandlers, type AssetImageOptions, type AssetImageSource, type AssetOptions, type AssetProps, AssetSession, type AssetSessionState, type AssetSpreadsheetOptions, type AssetVideoOptions, type AssetView, type AssetViewer, type AssetViewerKind, AssetViewerMount, AssetViewerName, AssetViewerOptionsByKind, CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensProvidedOptions, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, DEFAULT_VIEWER_MESSAGES, type DocumentViewerOptions, ICONS, ICON_ATTRIBUTES, INSTANT_LOAD_MS, type IconName, type MediaPlayback, MediaStreamPlayer, type MountedViewerKind, type PdfAssetOptions, type ProgressFetchOptions, type SpreadsheetCell, type SpreadsheetRow, type SpreadsheetSheet, type SpreadsheetViewerOptions, type TextViewerOptions, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, VIEWER_STYLES, type ViewerAsset, type ViewerMessages, type ViewerOptions, type ViewerState, type ViewerTextOptions, createDocumentViewer, createProgressFetch, createSpreadsheetViewer, createTextViewer, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, formatViewerMessage, getAssetAspectRatio, getAssetView, getAssetViewKey, getAssetViewerKind, getDropzoneHint, getMountedViewerOptions, getPeakHeights, getPlayedPercent, getSpreadsheetPage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, isImageReady, isMountedViewerKind, isSpreadsheetFormat, loadPdfJs, parseSpreadsheetText, pickAssetSource, resolveMessages, resolveTheme, resolveViewerMessages, spreadsheetColumnIndex, withProvidedOptions };
|
package/cjs/ui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ui = require("./ui-
|
|
3
|
-
const require_Core = require("./Core-
|
|
4
|
-
const require_UploadController = require("./UploadController-
|
|
2
|
+
const require_ui = require("./ui-BS9eFCI7.js");
|
|
3
|
+
const require_Core = require("./Core-rYZedJhi.js");
|
|
4
|
+
const require_UploadController = require("./UploadController-DCr7oN6L.js");
|
|
5
5
|
exports.ASSET_FILE_ICON_SIZE = require_Core.ASSET_FILE_ICON_SIZE;
|
|
6
6
|
exports.ASSET_VIEWERS = require_ui.ASSET_VIEWERS;
|
|
7
7
|
exports.AssetSession = require_Core.AssetSession;
|
package/cjs/vue.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { O as CalmLensAppClientOptions, g as AssetModerationStatus, i as AssetAvailability,
|
|
2
|
-
import "./index-
|
|
3
|
-
import { $ as MediaPlayback, A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadFile, G as AssetImageSource, H as AssetDisplay, J as AssetSessionState, K as AssetOptions, M as UploadClient, N as UploadController, O as CalmLensProvidedOptions, Q as INSTANT_LOAD_MS, R as UploadStage, S as formatBytes, T as getUploadItemMessage, U as AssetDocumentOptions, V as withProvidedOptions, W as AssetImageOptions, X as AssetVideoOptions, Y as AssetSpreadsheetOptions, Z as AssetView, _ as DEFAULT_MESSAGES, _t as DEFAULT_VIEWER_MESSAGES, a as ProgressFetchOptions, at as isImageReady, b as describeUploadItem, bt as resolveViewerMessages, c as ICON_ATTRIBUTES, ct as DocumentViewerOptions, d as AssetDisplayOptions, dt as TextViewerOptions, et as getAssetAspectRatio, f as AssetEventHandlers, ft as ViewerAsset, g as CalmLensMessages, gt as isSpreadsheetFormat, ht as getAssetViewerKind, i as CALMLENS_STYLES, it as getPlayedPercent, j as CustomUploadResult, l as IconName, lt as PdfAssetOptions, m as UploaderDisplayOptions, mt as ViewerTextOptions, n as CalmLensTheme, nt as getAssetViewKey, o as createProgressFetch, ot as pickAssetSource, p as AssetProps, pt as ViewerOptions, q as AssetSession, r as resolveTheme, rt as getPeakHeights, s as ICONS, st as AssetViewerKind, t as CALMLENS_THEME, tt as getAssetView, u as ASSET_FILE_ICON_SIZE, ut as SpreadsheetViewerOptions, v as UploadItemView, vt as ViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, yt as formatViewerMessage } from "./Core-
|
|
4
|
-
import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-
|
|
5
|
-
import { _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as AssetViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as ViewerState, y as createDocumentViewer } from "./ui-
|
|
1
|
+
import { O as CalmLensAppClientOptions, g as AssetModerationStatus, i as AssetAvailability, un as ViewerClaims } from "./CalmLensTypes-DF7wh23M.js";
|
|
2
|
+
import "./index-B511mjeS.js";
|
|
3
|
+
import { $ as MediaPlayback, A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadFile, G as AssetImageSource, H as AssetDisplay, J as AssetSessionState, K as AssetOptions, M as UploadClient, N as UploadController, O as CalmLensProvidedOptions, Q as INSTANT_LOAD_MS, R as UploadStage, S as formatBytes, T as getUploadItemMessage, U as AssetDocumentOptions, V as withProvidedOptions, W as AssetImageOptions, X as AssetVideoOptions, Y as AssetSpreadsheetOptions, Z as AssetView, _ as DEFAULT_MESSAGES, _t as DEFAULT_VIEWER_MESSAGES, a as ProgressFetchOptions, at as isImageReady, b as describeUploadItem, bt as resolveViewerMessages, c as ICON_ATTRIBUTES, ct as DocumentViewerOptions, d as AssetDisplayOptions, dt as TextViewerOptions, et as getAssetAspectRatio, f as AssetEventHandlers, ft as ViewerAsset, g as CalmLensMessages, gt as isSpreadsheetFormat, ht as getAssetViewerKind, i as CALMLENS_STYLES, it as getPlayedPercent, j as CustomUploadResult, l as IconName, lt as PdfAssetOptions, m as UploaderDisplayOptions, mt as ViewerTextOptions, n as CalmLensTheme, nt as getAssetViewKey, o as createProgressFetch, ot as pickAssetSource, p as AssetProps, pt as ViewerOptions, q as AssetSession, r as resolveTheme, rt as getPeakHeights, s as ICONS, st as AssetViewerKind, t as CALMLENS_THEME, tt as getAssetView, u as ASSET_FILE_ICON_SIZE, ut as SpreadsheetViewerOptions, v as UploadItemView, vt as ViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, yt as formatViewerMessage } from "./Core-Dnm9bJPB.js";
|
|
4
|
+
import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-CURmX-DR.js";
|
|
5
|
+
import { _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as AssetViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as ViewerState, y as createDocumentViewer } from "./ui-B83Pqjom.js";
|
|
6
6
|
import { App, MaybeRefOrGetter, PropType, ShallowRef } from "vue";
|
|
7
7
|
/** Shows a text asset's text, escaped, in a scrolling region. */
|
|
8
8
|
export declare const CalmLensTextViewer: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
package/cjs/vue.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ui = require("./ui-
|
|
3
|
-
const require_Core = require("./Core-
|
|
4
|
-
const require_UploadController = require("./UploadController-
|
|
2
|
+
const require_ui = require("./ui-BS9eFCI7.js");
|
|
3
|
+
const require_Core = require("./Core-rYZedJhi.js");
|
|
4
|
+
const require_UploadController = require("./UploadController-DCr7oN6L.js");
|
|
5
5
|
const require_FileIcons = require("./FileIcons-Ob003MdS.js");
|
|
6
|
-
const require_BrowserUpload = require("./BrowserUpload-
|
|
6
|
+
const require_BrowserUpload = require("./BrowserUpload-Al3ER3ki.js");
|
|
7
7
|
let vue = require("vue");
|
|
8
8
|
// src/viewers/Vue.ts
|
|
9
9
|
const optional$1 = (type) => ({
|
|
@@ -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-Dnm9bJPB.js";
|
|
2
|
+
import { r as UseCalmLensUploadResult$1 } from "./ReactUpload-B7wrDPk8.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
|
-
import { n as createUploadController$1 } from "./UploadController-
|
|
1
|
+
import { n as createUploadController$1 } from "./UploadController-cXocXbjd.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) => createUploadController$1(options);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as invalidConfig, S as invalidArgument } from "./CalmLensError-C15tWu8W.js";
|
|
2
|
-
import { S as validateAppClientOptions, d as checkOptionKeys, o as buildAssetUrl, p as encodePathSegment, u as DEFAULT_CDN_BASE_URL } from "./CalmLensCdn-
|
|
3
|
-
import { c as prepareSubmitAssetOptions, f as APP_OPTION_KEYS, i as expectUploadedAsset, l as resolveConnectionOptions, t as CalmLensConnection, u as splitsIntoParts } from "./CalmLensConnection-
|
|
2
|
+
import { S as validateAppClientOptions, d as checkOptionKeys, o as buildAssetUrl, p as encodePathSegment, u as DEFAULT_CDN_BASE_URL } from "./CalmLensCdn-DpJ7kIqG.js";
|
|
3
|
+
import { c as prepareSubmitAssetOptions, f as APP_OPTION_KEYS, i as expectUploadedAsset, l as resolveConnectionOptions, t as CalmLensConnection, u as splitsIntoParts } from "./CalmLensConnection-BYUqUitO.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. */
|
|
@@ -85,8 +85,8 @@ var CalmLensAppClient = class {
|
|
|
85
85
|
get cdn() {
|
|
86
86
|
return {
|
|
87
87
|
/**
|
|
88
|
-
* Builds a public asset's CDN URL: the
|
|
89
|
-
*
|
|
88
|
+
* Builds a public asset's CDN URL: the URL of `resource` (`rendered` unless one is given),
|
|
89
|
+
* with its lens or transform and the viewer claims. Private assets need a URL your
|
|
90
90
|
* server signs with `cdn.signAssetUrl`. The project is the client's `projectId` unless the
|
|
91
91
|
* call names one.
|
|
92
92
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { It as RequestOptions, M as CdnAssetUrlOptions, O as CalmLensAppClientOptions, cn as UploadedAsset, rn as UploadAssetPartOptions, sn as UploadPresetSubmitAssetOptions, zt as RetrieveAssetOptions } from "./CalmLensTypes-DF7wh23M.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,
|
|
@@ -25,8 +25,8 @@ declare class CalmLensAppClient {
|
|
|
25
25
|
/** Public asset URLs, built without a request. */
|
|
26
26
|
get cdn(): {
|
|
27
27
|
/**
|
|
28
|
-
* Builds a public asset's CDN URL: the
|
|
29
|
-
*
|
|
28
|
+
* Builds a public asset's CDN URL: the URL of `resource` (`rendered` unless one is given),
|
|
29
|
+
* with its lens or transform and the viewer claims. Private assets need a URL your
|
|
30
30
|
* server signs with `cdn.signAssetUrl`. The project is the client's `projectId` unless the
|
|
31
31
|
* call names one.
|
|
32
32
|
*/
|
|
@@ -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.33.0";
|
|
156
156
|
const runtimeName = () => {
|
|
157
157
|
const runtime = globalThis;
|
|
158
158
|
if (isReactNativeRuntime()) return "react-native";
|
|
@@ -536,7 +536,7 @@ var CalmLensTransport = class {
|
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
538
|
};
|
|
539
|
-
// src/contract/SharedConstants-
|
|
539
|
+
// src/contract/SharedConstants-CxzZSxDw.js
|
|
540
540
|
const IMPERSONATION_COOKIE_NAME = "CL_impersonation";
|
|
541
541
|
const DAY_MS = 864e5;
|
|
542
542
|
const YEAR_MS = 365 * DAY_MS;
|
|
@@ -745,6 +745,13 @@ const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
|
745
745
|
const MAX_DIRECT_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
746
746
|
const MAX_NON_IMAGE_UPLOAD_MB = 5e3;
|
|
747
747
|
const MAX_NON_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => MAX_NON_IMAGE_UPLOAD_MB * 1024 * 1024)();
|
|
748
|
+
/** PDFs: read in ranges of pages past `LONG_DOCUMENT_MIN_BYTES`, below the 4 GiB PDFium reads by range. */
|
|
749
|
+
const MAX_PDF_UPLOAD_BYTES = /* @__PURE__ */ (() => 2097152e3)();
|
|
750
|
+
/**
|
|
751
|
+
* Documents other than PDFs (Word, spreadsheets, presentations, OpenDocument and the formats
|
|
752
|
+
* LibreOffice converts): read whole, as the document processor reads at most this much.
|
|
753
|
+
*/
|
|
754
|
+
const MAX_OTHER_DOCUMENT_UPLOAD_BYTES = /* @__PURE__ */ (() => 52428800)();
|
|
748
755
|
const normalizeUploadMimeType = (mimeType) => mimeType.toLowerCase().split(";")[0]?.trim() || mimeType.toLowerCase().trim();
|
|
749
756
|
const getRejectedUploadMimeTypeError = (mimeType) => `${normalizeUploadMimeType(mimeType)} is not a valid upload file type. Uploads must use a concrete file MIME type that CalmLens can store and process, such as image/png, image/jpeg, application/pdf, or text/plain.`;
|
|
750
757
|
const DOMAIN = "calmlens.com";
|
|
@@ -924,6 +931,22 @@ const UPLOAD_MIME_TYPES = [
|
|
|
924
931
|
"application/xml",
|
|
925
932
|
"application/yaml"
|
|
926
933
|
];
|
|
934
|
+
const UPLOAD_MIME_DOCUMENTS = [
|
|
935
|
+
"application/pdf",
|
|
936
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
937
|
+
"application/vnd.ms-word.document.macroenabled.12",
|
|
938
|
+
"application/msword",
|
|
939
|
+
"application/rtf",
|
|
940
|
+
"application/vnd.oasis.opendocument.text",
|
|
941
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
942
|
+
"application/vnd.ms-excel.sheet.macroenabled.12",
|
|
943
|
+
"application/vnd.ms-excel",
|
|
944
|
+
"application/vnd.oasis.opendocument.spreadsheet",
|
|
945
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
946
|
+
"application/vnd.ms-powerpoint.presentation.macroenabled.12",
|
|
947
|
+
"application/vnd.ms-powerpoint",
|
|
948
|
+
"application/vnd.oasis.opendocument.presentation"
|
|
949
|
+
];
|
|
927
950
|
// src/client/CalmLensUtils.ts
|
|
928
951
|
const assertHttpUrl = (name, value) => {
|
|
929
952
|
if (value === void 0) return;
|
|
@@ -1367,35 +1390,28 @@ const viewerClaimsQuery = (claims) => {
|
|
|
1367
1390
|
return sent ? `?${new URLSearchParams({ viewerClaims: JSON.stringify(sent) })}` : "";
|
|
1368
1391
|
};
|
|
1369
1392
|
/**
|
|
1370
|
-
* Appends a resource, its `@lens` and transform selector, and the
|
|
1371
|
-
*
|
|
1393
|
+
* Appends a resource (`rendered` unless one is given), its `@lens` and transform selector, and the
|
|
1394
|
+
* viewer claims to an asset URL (public or signed).
|
|
1372
1395
|
*/
|
|
1373
1396
|
const appendAssetLocation = (assetUrl, location) => {
|
|
1374
|
-
const { resource, lens, transform, viewerClaims } = location;
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
if (UNSELECTABLE.has(resource) && selected) throw invalidArgument(`The ${resource} resource takes no lens or transform`);
|
|
1382
|
-
path = `${assetUrl}/${ASSET_RESOURCE_PATHS[resource]}`;
|
|
1383
|
-
const selector = transformSelector(transform);
|
|
1384
|
-
const parts = [...lens !== void 0 ? [`@${encodePathSegment(lens, "Lens")}`] : [], ...selector ? [typeof transform === "string" ? encodeURI(selector) : selector] : []];
|
|
1385
|
-
if (parts.length) path = `${path}/${parts.join(",")}`;
|
|
1386
|
-
}
|
|
1387
|
-
return `${path}${viewerClaimsQuery(viewerClaims)}`;
|
|
1397
|
+
const { resource = "rendered", lens, transform, viewerClaims } = location;
|
|
1398
|
+
if (typeof resource !== "string" || !Object.hasOwn(ASSET_RESOURCE_PATHS, resource)) throw invalidArgument(`resource must be one of ${CDN_RESOURCES.join(", ")}`);
|
|
1399
|
+
if (UNSELECTABLE.has(resource) && (lens !== void 0 || transform !== void 0)) throw invalidArgument(`The ${resource} resource takes no lens or transform`);
|
|
1400
|
+
const selector = transformSelector(transform);
|
|
1401
|
+
const parts = [...lens !== void 0 ? [`@${encodePathSegment(lens, "Lens")}`] : [], ...selector ? [typeof transform === "string" ? encodeURI(selector) : selector] : []];
|
|
1402
|
+
const path = `${assetUrl}/${ASSET_RESOURCE_PATHS[resource]}`;
|
|
1403
|
+
return `${parts.length ? `${path}/${parts.join(",")}` : path}${viewerClaimsQuery(viewerClaims)}`;
|
|
1388
1404
|
};
|
|
1389
1405
|
/**
|
|
1390
|
-
* The lens, transform and viewer claims added to a URL the API signed for `location.resource
|
|
1391
|
-
* which already ends in that resource.
|
|
1406
|
+
* The lens, transform and viewer claims added to a URL the API signed for `location.resource`
|
|
1407
|
+
* (`rendered` unless one is given), which already ends in that resource.
|
|
1392
1408
|
*/
|
|
1393
1409
|
const appendSignedLocation = (signedUrl, location) => {
|
|
1394
|
-
const resourcePath = location.resource
|
|
1410
|
+
const resourcePath = `/${ASSET_RESOURCE_PATHS[location.resource ?? "rendered"]}`;
|
|
1395
1411
|
if (!signedUrl.endsWith(resourcePath)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The signed asset URL doesn't end in the resource it was signed for" });
|
|
1396
1412
|
return `${signedUrl}${appendAssetLocation("", location).slice(resourcePath.length)}`;
|
|
1397
1413
|
};
|
|
1398
|
-
/** An asset's public URL beneath a CDN base URL, with any
|
|
1414
|
+
/** An asset's public resource URL beneath a CDN base URL, with any selector and claims. */
|
|
1399
1415
|
const buildAssetUrl = (cdnBaseUrl, projectId, options) => {
|
|
1400
1416
|
const { assetId, externalId, resource, lens, transform, viewerClaims } = options;
|
|
1401
1417
|
const base = `${cdnBaseUrl.replace(/\/+$/, "")}/assets/${encodePathSegment(projectId, "Project ID")}/${getAssetSegment({
|
|
@@ -1483,4 +1499,4 @@ const getAssetInfo = async (url, options = {}) => {
|
|
|
1483
1499
|
});
|
|
1484
1500
|
return data;
|
|
1485
1501
|
};
|
|
1486
|
-
export {
|
|
1502
|
+
export { MAX_OTHER_DOCUMENT_UPLOAD_BYTES as A, copyLastResponse as B, validateBatchAssetsOptions as C, MAX_DIRECT_IMAGE_UPLOAD_BYTES as D, DOMAIN as E, sleep as F, readEnv as H, SDK_VERSION as I, isBrowserRuntime as L, getRejectedUploadMimeTypeError as M, normalizeUploadMimeType as N, MAX_IMAGE_UPLOAD_BYTES as O, CalmLensTransport as P, isReactNativeRuntime as R, validateAppClientOptions as S, UPLOAD_MIME_DOCUMENTS as T, resolveLogLevel as U, listPages as V, randomUuid as _, assetUrlOf as a, toTextAssetOptions as b, toUrlViewerClaims as c, checkOptionKeys as d, checkTransformOptions as f, pollForDecision as g, parseTransformSelector as h, appendSignedLocation as i, MAX_PDF_UPLOAD_BYTES as j, MAX_NON_IMAGE_UPLOAD_BYTES as k, validateSignAssetUrlOptions as l, isAcceptedUploadMimeType as m, CDN_RESOURCES as n, buildAssetUrl as o, encodePathSegment as p, appendAssetLocation as r, getAssetInfo as s, ASSET_RESOURCE_PATHS as t, DEFAULT_CDN_BASE_URL as u, serializeTransform as v, validateServerClientOptions as w, transformSelector as x, stringifyQuery as y, AUTO_PAGING_TO_ARRAY_MAX as z };
|