calmlens 0.18.3 → 0.20.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 +5682 -5036
- package/cjs/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
- package/cjs/{BrowserUpload-UxIAGNdv.js → BrowserUpload-CjSHjx3C.js} +1 -1
- package/{esm/CalmLensAppClient-CV_K26Ce.d.ts → cjs/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
- package/cjs/{CalmLensAppClient-D6p7MAFz.js → CalmLensAppClient-NaCxOVlM.js} +32 -11
- package/cjs/{CalmLensConnection-CYoUl5go.js → CalmLensOptionKeys-p2QK687A.js} +430 -9
- package/cjs/{CalmLensServerClient-p23cl97D.js → CalmLensServerClient-BDzTthxE.js} +173 -55
- package/cjs/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
- package/cjs/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
- package/cjs/{ModerationContextLimits-DCLXMxyA.js → ModerationContextLimits-2nIv7Zh3.js} +495 -49
- package/cjs/{ReactUpload-BcdNWLiU.js → ReactUpload-BdTRCTGA.js} +1 -1
- package/cjs/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
- package/{esm/TestTriggers-By07LR31-CmK0yTyR.d.ts → cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
- package/cjs/{TestTriggers-DTc_iMJF-BjMPq4_3.js → TestTriggers-DbhsNPdg-DjvVuc2h.js} +434 -74
- package/cjs/{UploadController-Cxu0bufo.js → UploadController-MLVs97Zt.js} +17 -5
- package/{esm/WebhookPayload-2aL31v0J.d.ts → cjs/WebhookPayload-DkukERKE.d.ts} +29 -3
- package/cjs/app.d.ts +6 -6
- package/cjs/app.js +2 -2
- package/cjs/elements.d.ts +3 -3
- package/cjs/elements.js +3 -3
- package/cjs/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
- package/cjs/index.d.ts +5 -5
- package/cjs/index.js +1 -1
- package/cjs/react-native.d.ts +3 -3
- package/cjs/react-native.js +3 -3
- package/cjs/react.d.ts +3 -3
- package/cjs/react.js +4 -4
- package/cjs/server.d.ts +6 -6
- package/cjs/server.js +2 -2
- package/cjs/test-inputs.d.ts +1 -1
- package/cjs/test-inputs.js +9 -9
- package/cjs/testing.d.ts +12 -8
- package/cjs/testing.js +298 -35
- package/{esm/ui-wIiMfqMB.d.ts → cjs/ui-BSqPGKrZ.d.ts} +17 -4
- package/cjs/{ui-C0XXJS52.js → ui-CX1z2pD9.js} +13 -10
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +2 -2
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +3 -3
- package/esm/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
- package/esm/{BrowserUpload-BXG2isHV.js → BrowserUpload-CAVkRotw.js} +1 -1
- package/{cjs/CalmLensAppClient-CV_K26Ce.d.ts → esm/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
- package/esm/{CalmLensAppClient-BMgXamoN.js → CalmLensAppClient-PQ9VBvlW.js} +28 -7
- package/esm/{CalmLensConnection-DBoDh06c.js → CalmLensOptionKeys-Do2mPP6w.js} +407 -10
- package/esm/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
- package/esm/{CalmLensServerClient-Dt7rCITa.js → CalmLensServerClient-C_H5aAsV.js} +165 -47
- package/esm/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
- package/esm/{ModerationContextLimits-KMQ8puoa.js → ModerationContextLimits-Chw-AzgL.js} +462 -46
- package/esm/{ReactUpload-CFy_wETY.js → ReactUpload-CMmL0R5Q.js} +1 -1
- package/esm/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
- package/{cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts → esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
- package/esm/{TestTriggers-DTc_iMJF-HfB533Gx.js → TestTriggers-DbhsNPdg-CUdrv8Nm.js} +405 -72
- package/esm/{UploadController-Cs-bxUbt.js → UploadController-BJZghJpg.js} +17 -5
- package/{cjs/WebhookPayload-2aL31v0J.d.ts → esm/WebhookPayload-DkukERKE.d.ts} +29 -3
- package/esm/app.d.ts +6 -6
- package/esm/app.js +2 -2
- package/esm/elements.d.ts +3 -3
- package/esm/elements.js +3 -3
- package/esm/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
- 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 +3 -3
- package/esm/react.d.ts +3 -3
- package/esm/react.js +4 -4
- package/esm/server.d.ts +6 -6
- package/esm/server.js +2 -2
- 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 +287 -23
- package/{cjs/ui-wIiMfqMB.d.ts → esm/ui-BSqPGKrZ.d.ts} +17 -4
- package/esm/{ui-BqYkISSE.js → ui-CXH7xJpb.js} +12 -9
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +2 -2
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +3 -3
- package/package.json +1 -1
- package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +0 -91
- package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +0 -46
- /package/cjs/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
- /package/esm/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const require_UploadController = require("./UploadController-Cxu0bufo.js");
|
|
1
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-2nIv7Zh3.js");
|
|
2
|
+
const require_UploadController = require("./UploadController-MLVs97Zt.js");
|
|
4
3
|
const require_FileIcons = require("./FileIcons-Ob003MdS.js");
|
|
5
4
|
// src/ui/Icons.ts
|
|
6
5
|
/** Path data for the components' 24×24 stroke icons, so every framework draws the same ones. */
|
|
@@ -47,7 +46,14 @@ const decodePlaceholderHash = (hash) => {
|
|
|
47
46
|
}
|
|
48
47
|
return decodedPlaceholders.get(hash);
|
|
49
48
|
};
|
|
50
|
-
const
|
|
49
|
+
const withWidth = (base, width) => {
|
|
50
|
+
if (width === void 0) return base;
|
|
51
|
+
if (base === void 0 || typeof base !== "string") return {
|
|
52
|
+
...base,
|
|
53
|
+
width
|
|
54
|
+
};
|
|
55
|
+
return [require_ModerationContextLimits.transformSelector(base), require_ModerationContextLimits.serializeTransform({ width })].filter(Boolean).join(",");
|
|
56
|
+
};
|
|
51
57
|
/**
|
|
52
58
|
* Fills the props left unset from `asset`, if there is one: the project and ID, its moderation
|
|
53
59
|
* status, `video` or `audio` for those asset types, and its stored preview's ThumbHash, average
|
|
@@ -75,7 +81,7 @@ const resolveMediaProps = (props) => {
|
|
|
75
81
|
let status = props.status ?? asset.classification?.moderation?.status ?? "allowed";
|
|
76
82
|
for (const entry of regionEntries) {
|
|
77
83
|
const region = props.viewerClaims?.region;
|
|
78
|
-
if (region && (entry.region === region || entry.region === "EU" &&
|
|
84
|
+
if (region && (entry.region === region || entry.region === "EU" && require_ModerationContextLimits.EU_COUNTRIES.has(region))) {
|
|
79
85
|
const regionalStatus = statuses[entry.action];
|
|
80
86
|
if (regionalStatus && ranks[regionalStatus] > ranks[status]) status = regionalStatus;
|
|
81
87
|
}
|
|
@@ -126,7 +132,7 @@ const buildMediaState = ({ projectId, assetId, status = "allowed", contentRemove
|
|
|
126
132
|
...asset,
|
|
127
133
|
resource: chosen,
|
|
128
134
|
lens: rendered ? lens : void 0,
|
|
129
|
-
transform: rendered ?
|
|
135
|
+
transform: rendered ? withWidth(transform, options.width) : void 0
|
|
130
136
|
});
|
|
131
137
|
};
|
|
132
138
|
if (type === "audio") return {
|
|
@@ -144,10 +150,7 @@ const buildMediaState = ({ projectId, assetId, status = "allowed", contentRemove
|
|
|
144
150
|
placeholderUrl
|
|
145
151
|
};
|
|
146
152
|
const sources = [...new Set(widths ?? [])].filter((width) => Number.isSafeInteger(width) && width > 0).sort((a, b) => a - b).map((width) => ({
|
|
147
|
-
src: build({
|
|
148
|
-
type: "imageTransform",
|
|
149
|
-
options: { width }
|
|
150
|
-
} }),
|
|
153
|
+
src: build({ width }),
|
|
151
154
|
width
|
|
152
155
|
}));
|
|
153
156
|
return {
|
package/cjs/ui.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, type IconName, type MediaAsset, type MediaDisplayOptions, type MediaImageSource, type MediaOptions, type MediaProps, type MediaSettings, type MediaSource, type MediaState, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };
|
|
1
|
+
import { A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as getUploadItemOutcome, E as getUploadItemMessage, F as UploadFile, G as MediaSource, H as MediaImageSource, I as UploadItem, J as pickMediaSource, K as MediaState, L as UploadSnapshot, M as UploadClient, N as UploadController, O as resolveMessages, P as UploadControllerOptions, R as UploadStage, S as formatBytes, T as getMediaUnavailableMessage, U as MediaOptions, V as MediaAsset, W as MediaSettings, Y as resolveMediaProps, _ as DEFAULT_MESSAGES, a as ProgressFetchOptions, b as describeUploadItem, c as ICON_ATTRIBUTES, d as MediaProps, f as UploaderDisplayOptions, g as CalmLensMessages, h as getMediaLoadKey, i as CALMLENS_STYLES, j as CustomUploadResult, k as CalmLensUpload, l as IconName, m as getMediaAspectRatio, n as CalmLensTheme, o as createProgressFetch, p as UploaderProps, q as getMediaState, r as resolveTheme, s as ICONS, t as CALMLENS_THEME, u as MediaDisplayOptions, v as UploadItemView, w as getDropzoneHint, x as describeUploader, y as UploaderView, z as createUploadController } from "./ui-BSqPGKrZ.js";
|
|
2
|
+
export { CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, type IconName, type MediaAsset, type MediaDisplayOptions, type MediaImageSource, type MediaOptions, type MediaProps, type MediaSettings, type MediaSource, type MediaState, type ProgressFetchOptions, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };
|
package/cjs/ui.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ui = require("./ui-
|
|
3
|
-
const require_UploadController = require("./UploadController-
|
|
2
|
+
const require_ui = require("./ui-CX1z2pD9.js");
|
|
3
|
+
const require_UploadController = require("./UploadController-MLVs97Zt.js");
|
|
4
4
|
exports.CALMLENS_STYLES = require_ui.CALMLENS_STYLES;
|
|
5
5
|
exports.CALMLENS_THEME = require_ui.CALMLENS_THEME;
|
|
6
6
|
exports.DEFAULT_MESSAGES = require_ui.DEFAULT_MESSAGES;
|
package/cjs/vue.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./index-
|
|
3
|
-
import { A as
|
|
4
|
-
import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-
|
|
1
|
+
import { E as CalmLensAppClientOptions, Mt as ViewerClaims, h as AssetModerationStatus, j as CdnTransform } from "./CalmLensTypes-COJbOuiv.js";
|
|
2
|
+
import "./index-DxbJ_Xaa.js";
|
|
3
|
+
import { A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as getUploadItemOutcome, E as getUploadItemMessage, F as UploadFile, G as MediaSource, H as MediaImageSource, J as pickMediaSource, K as MediaState, M as UploadClient, N as UploadController, O as resolveMessages, R as UploadStage, S as formatBytes, T as getMediaUnavailableMessage, U as MediaOptions, V as MediaAsset, W as MediaSettings, Y as resolveMediaProps, _ as DEFAULT_MESSAGES, a as ProgressFetchOptions, b as describeUploadItem, c as ICON_ATTRIBUTES, d as MediaProps, f as UploaderDisplayOptions, g as CalmLensMessages, h as getMediaLoadKey, i as CALMLENS_STYLES, j as CustomUploadResult, l as IconName, m as getMediaAspectRatio, n as CalmLensTheme, o as createProgressFetch, q as getMediaState, r as resolveTheme, s as ICONS, t as CALMLENS_THEME, u as MediaDisplayOptions, v as UploadItemView, w as getDropzoneHint, x as describeUploader, y as UploaderView } from "./ui-BSqPGKrZ.js";
|
|
4
|
+
import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-C07aL9Vq.js";
|
|
5
5
|
import { MaybeRefOrGetter, PropType, ShallowRef } from "vue";
|
|
6
6
|
export interface UseCalmLensUploadResult<F extends UploadFile = File> {
|
|
7
7
|
snapshot: Readonly<ShallowRef<UploadSnapshot<F>>>;
|
|
@@ -487,4 +487,4 @@ export declare const CalmLensMedia: import("vue").DefineComponent<import("vue").
|
|
|
487
487
|
messages: Partial<CalmLensMessages>;
|
|
488
488
|
onReveal: () => void;
|
|
489
489
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
490
|
-
export { CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, type IconName, type MediaAsset, type MediaDisplayOptions, type MediaImageSource, type MediaOptions, type MediaProps, type MediaSettings, type MediaSource, type MediaState, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };
|
|
490
|
+
export { CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, type IconName, type MediaAsset, type MediaDisplayOptions, type MediaImageSource, type MediaOptions, type MediaProps, type MediaSettings, type MediaSource, type MediaState, type ProgressFetchOptions, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };
|
package/cjs/vue.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ui = require("./ui-
|
|
3
|
-
const require_UploadController = require("./UploadController-
|
|
4
|
-
const require_BrowserUpload = require("./BrowserUpload-
|
|
2
|
+
const require_ui = require("./ui-CX1z2pD9.js");
|
|
3
|
+
const require_UploadController = require("./UploadController-MLVs97Zt.js");
|
|
4
|
+
const require_BrowserUpload = require("./BrowserUpload-CjSHjx3C.js");
|
|
5
5
|
let vue = require("vue");
|
|
6
6
|
// src/vue.ts
|
|
7
7
|
const icon = (name) => (0, vue.h)("svg", require_ui.ICON_ATTRIBUTES, [(0, vue.h)("path", { d: require_ui.ICONS[name] })]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as UploadItem$1,
|
|
2
|
-
import { t 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, k as CalmLensUpload$1, p as UploaderProps$1 } from "./ui-BSqPGKrZ.js";
|
|
2
|
+
import { t as UseCalmLensUploadResult$1 } from "./ReactUpload-CRJNPB5T.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-BJZghJpg.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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as UploadedAsset, E as CalmLensAppClientOptions, Ot as UploadAssetPartOptions, gt as RetrieveAssetOptions, kt as UploadPresetSubmitAssetOptions } from "./CalmLensTypes-COJbOuiv.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,
|
|
@@ -32,9 +32,9 @@ declare class CalmLensAppClient {
|
|
|
32
32
|
* Uploads the next part of a multipart upload this client started. The upload's queue
|
|
33
33
|
* mode, chosen when it started, applies when the final part arrives.
|
|
34
34
|
*/
|
|
35
|
-
uploadPart: (
|
|
35
|
+
uploadPart: (partOptions: UploadAssetPartOptions) => Promise<UploadedAsset>;
|
|
36
36
|
/** Checks an upload this client made. `status` is present when the preset shows decisions. */
|
|
37
|
-
retrieve: (
|
|
37
|
+
retrieve: (options: RetrieveAssetOptions) => Promise<UploadedAsset>;
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
export { CalmLensAppClient as t };
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { F as invalidArgument, I as invalidConfig, d as encodePathSegment, l as checkOptionKeys, x as validateAppClientOptions } from "./ModerationContextLimits-Chw-AzgL.js";
|
|
2
|
+
import { d as prepareSubmitAssetOptions, f as resolveConnectionOptions, i as CalmLensConnection, p as splitsIntoParts, s as expectUploadedAsset, t as APP_OPTION_KEYS } from "./CalmLensOptionKeys-Do2mPP6w.js";
|
|
3
3
|
// src/client/CalmLensAppClient.ts
|
|
4
4
|
const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
5
|
+
/** `options`, once `checkOptionKeys` finds only keys `operation` takes. */
|
|
6
|
+
const checked = (operation, options) => {
|
|
7
|
+
checkOptionKeys(options, operation, APP_OPTION_KEYS);
|
|
8
|
+
return options;
|
|
9
|
+
};
|
|
5
10
|
/**
|
|
6
11
|
* The CalmLens client for browsers and React Native apps. It uploads through an upload preset,
|
|
7
12
|
* with an upload token from your server when the preset requires one, and never holds an API
|
|
@@ -49,8 +54,22 @@ var CalmLensAppClient = class {
|
|
|
49
54
|
async submit(options, queue) {
|
|
50
55
|
if (!options || typeof options !== "object") throw invalidArgument("Upload options are required");
|
|
51
56
|
if (!("content" in options) && !("part" in options)) throw invalidArgument("Uploads through an upload preset need content or a part");
|
|
52
|
-
prepareSubmitAssetOptions(options, {
|
|
57
|
+
prepareSubmitAssetOptions(options, {
|
|
58
|
+
deferUploadChecks: this.#connection.deferUploadChecks,
|
|
59
|
+
partSizeBytes: this.#connection.partSizeBytes
|
|
60
|
+
});
|
|
53
61
|
const token = await this.newUploadToken();
|
|
62
|
+
if ("content" in options && splitsIntoParts(options.content, this.#connection.partSizeBytes)) {
|
|
63
|
+
const data = await this.#connection.submitInParts(this.uploadsPath, options, queue, {
|
|
64
|
+
authHeaders: token ? { Authorization: `Bearer ${token}` } : {},
|
|
65
|
+
partPath: (assetId) => `${this.uploadsPath}/${encodeURIComponent(assetId)}/part`,
|
|
66
|
+
onStarted: (assetId) => {
|
|
67
|
+
if (token) this.#uploadTokens.set(assetId, token);
|
|
68
|
+
},
|
|
69
|
+
retrieve: (assetId) => this.assets.retrieve({ assetId })
|
|
70
|
+
});
|
|
71
|
+
return expectUploadedAsset(data);
|
|
72
|
+
}
|
|
54
73
|
const data = await this.#connection.submitRawUpload(this.uploadsPath, options, queue, token ? { Authorization: `Bearer ${token}` } : {});
|
|
55
74
|
const uploaded = expectUploadedAsset(data);
|
|
56
75
|
if (token) this.#uploadTokens.set(uploaded.id, token);
|
|
@@ -60,20 +79,22 @@ var CalmLensAppClient = class {
|
|
|
60
79
|
get assets() {
|
|
61
80
|
return {
|
|
62
81
|
/** Uploads a file and queues it for moderation. */
|
|
63
|
-
create: (options) => this.submit(options, true),
|
|
82
|
+
create: async (options) => this.submit(checked("assets.create", options), true),
|
|
64
83
|
/** Uploads a file and waits for its moderation decision. */
|
|
65
|
-
classify: (options) => this.submit(options, false),
|
|
84
|
+
classify: async (options) => this.submit(checked("assets.classify", options), false),
|
|
66
85
|
/**
|
|
67
86
|
* Uploads the next part of a multipart upload this client started. The upload's queue
|
|
68
87
|
* mode, chosen when it started, applies when the final part arrives.
|
|
69
88
|
*/
|
|
70
|
-
uploadPart: async (
|
|
89
|
+
uploadPart: async (partOptions) => {
|
|
90
|
+
const { assetId, ...options } = checked("assets.uploadPart", partOptions);
|
|
71
91
|
const encodedAssetId = encodePathSegment(assetId, "Asset ID");
|
|
72
92
|
const data = await this.#connection.uploadPart(`${this.uploadsPath}/${encodedAssetId}/part`, options, this.authHeaders(assetId));
|
|
73
93
|
return expectUploadedAsset(data);
|
|
74
94
|
},
|
|
75
95
|
/** Checks an upload this client made. `status` is present when the preset shows decisions. */
|
|
76
|
-
retrieve: async (
|
|
96
|
+
retrieve: async (options) => {
|
|
97
|
+
const { assetId } = checked("assets.retrieve", options);
|
|
77
98
|
const encodedAssetId = encodePathSegment(assetId, "Asset ID");
|
|
78
99
|
const data = await this.#connection.json("GET", `${this.uploadsPath}/${encodedAssetId}`, { headers: this.authHeaders(assetId) });
|
|
79
100
|
return expectUploadedAsset(data);
|