@calmlens/sdk 0.16.3 → 0.18.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.
Files changed (114) hide show
  1. package/README.md +425 -181
  2. package/bin/calmlens.js +16016 -0
  3. package/bin/package.json +1 -0
  4. package/cjs/BrowserUpload-BT091eOB.d.ts +11 -0
  5. package/cjs/BrowserUpload-CQwXEGFv.js +10 -0
  6. package/cjs/CalmLensAppClient-CHQGu-Do.js +89 -0
  7. package/cjs/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  8. package/cjs/CalmLensConnection-B8Bu2j3y.js +659 -0
  9. package/cjs/CalmLensServerClient-C5o2A8MW.js +645 -0
  10. package/cjs/CalmLensServerClient-JtP687a3.d.ts +235 -0
  11. package/cjs/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  12. package/cjs/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  13. package/cjs/CryptoUtils-B_x8lMIx-YBW1-bvL.js +42 -0
  14. package/cjs/FileIcons-Ob003MdS.js +175 -0
  15. package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +91 -0
  16. package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  17. package/cjs/ModerationContextLimits-DelWfmiJ.js +1311 -0
  18. package/cjs/ReactUpload-CAyCsyG6.d.ts +17 -0
  19. package/cjs/ReactUpload-Cfg5JYUq.js +54 -0
  20. package/cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  21. package/cjs/TestTriggers-DTc_iMJF-BjMPq4_3.js +1327 -0
  22. package/cjs/UploadController-BGO1eyzb.js +618 -0
  23. package/{esm/index-C9Xw1aid.d.ts → cjs/WebhookPayload-2aL31v0J.d.ts} +131 -155
  24. package/cjs/app.d.ts +7 -44
  25. package/cjs/app.js +11 -89
  26. package/cjs/elements.d.ts +88 -0
  27. package/cjs/elements.js +555 -0
  28. package/cjs/file-icons.d.ts +67 -0
  29. package/cjs/file-icons.js +10 -0
  30. package/cjs/index-CI4BzN4W.d.ts +252 -0
  31. package/cjs/index.d.ts +6 -4
  32. package/cjs/index.js +9 -4
  33. package/cjs/react-native.d.ts +56 -0
  34. package/cjs/react-native.js +495 -0
  35. package/cjs/react.d.ts +30 -0
  36. package/cjs/react.js +370 -0
  37. package/cjs/server.d.ts +12 -191
  38. package/cjs/server.js +18 -378
  39. package/cjs/test-inputs.d.ts +2 -2
  40. package/cjs/test-inputs.js +9 -264
  41. package/cjs/testing.d.ts +285 -190
  42. package/cjs/testing.js +2393 -1203
  43. package/cjs/ui-CC1GOoMg.js +583 -0
  44. package/cjs/ui-wIiMfqMB.d.ts +526 -0
  45. package/cjs/ui.d.ts +2 -0
  46. package/cjs/ui.js +27 -0
  47. package/cjs/vue.d.ts +490 -0
  48. package/cjs/vue.js +419 -0
  49. package/esm/BrowserUpload-BT091eOB.d.ts +11 -0
  50. package/esm/BrowserUpload-D2xBWqhm.js +5 -0
  51. package/esm/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  52. package/esm/CalmLensAppClient-DuFas_dW.js +84 -0
  53. package/esm/CalmLensConnection-MxwwLXdl.js +582 -0
  54. package/esm/CalmLensServerClient-D80_mKpW.js +586 -0
  55. package/esm/CalmLensServerClient-JtP687a3.d.ts +235 -0
  56. package/esm/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  57. package/esm/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  58. package/esm/CryptoUtils-B_x8lMIx-DhuWGzqn.js +25 -0
  59. package/esm/FileIcons-M6dzjFxd.js +128 -0
  60. package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +46 -0
  61. package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  62. package/esm/ModerationContextLimits-BaX2QnU8.js +1114 -0
  63. package/esm/ReactUpload-CAyCsyG6.d.ts +17 -0
  64. package/esm/ReactUpload-CL2XC8WS.js +37 -0
  65. package/esm/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  66. package/esm/TestTriggers-DTc_iMJF-HfB533Gx.js +1267 -0
  67. package/esm/UploadController-qjoYGCwx.js +589 -0
  68. package/{cjs/index-C9Xw1aid.d.ts → esm/WebhookPayload-2aL31v0J.d.ts} +131 -155
  69. package/esm/app.d.ts +7 -44
  70. package/esm/app.js +3 -86
  71. package/esm/elements.d.ts +88 -0
  72. package/esm/elements.js +528 -0
  73. package/esm/file-icons.d.ts +67 -0
  74. package/esm/file-icons.js +1 -0
  75. package/esm/index-CI4BzN4W.d.ts +252 -0
  76. package/esm/index.d.ts +6 -4
  77. package/esm/index.js +1 -1
  78. package/esm/react-native.d.ts +56 -0
  79. package/esm/react-native.js +467 -0
  80. package/esm/react.d.ts +30 -0
  81. package/esm/react.js +343 -0
  82. package/esm/server.d.ts +12 -191
  83. package/esm/server.js +3 -369
  84. package/esm/styles.css +147 -0
  85. package/esm/svelte/CalmLensMedia.svelte +134 -0
  86. package/esm/svelte/CalmLensUploader.svelte +175 -0
  87. package/esm/svelte/Icon.svelte +7 -0
  88. package/esm/svelte/index.d.ts +37 -0
  89. package/esm/svelte/index.js +6 -0
  90. package/esm/test-inputs.d.ts +2 -2
  91. package/esm/test-inputs.js +1 -256
  92. package/esm/testing.d.ts +285 -190
  93. package/esm/testing.js +2329 -1122
  94. package/esm/ui-CCY3yXFn.js +458 -0
  95. package/esm/ui-wIiMfqMB.d.ts +526 -0
  96. package/esm/ui.d.ts +2 -0
  97. package/esm/ui.js +3 -0
  98. package/esm/vue.d.ts +490 -0
  99. package/esm/vue.js +392 -0
  100. package/package.json +118 -13
  101. package/cjs/CalmLensConnection-BNUHp_AQ.js +0 -234
  102. package/cjs/CalmLensUtils-o171ownK.js +0 -699
  103. package/cjs/CalmLensVersion-DwhgxQK5.js +0 -480
  104. package/cjs/CalmLensWebhooks-BKrq30Yp.js +0 -201
  105. package/cjs/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
  106. package/cjs/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
  107. package/cjs/WebhookPayload-CJoIkGBD.d.ts +0 -11753
  108. package/esm/CalmLensConnection-XTqmlwzG.js +0 -193
  109. package/esm/CalmLensUtils-DsF8Aa_x.js +0 -574
  110. package/esm/CalmLensVersion-DcifRKsx.js +0 -415
  111. package/esm/CalmLensWebhooks-BvGyk5d3.js +0 -148
  112. package/esm/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
  113. package/esm/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
  114. package/esm/WebhookPayload-CJoIkGBD.d.ts +0 -11753
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,11 @@
1
+ import { F as UploadItem$1, I as UploadSnapshot$1, M as UploadController, N as UploadControllerOptions$1, O as CalmLensUpload$1, P as UploadFile, f as UploaderProps$1 } from "./ui-wIiMfqMB.js";
2
+ import { t as UseCalmLensUploadResult$1 } from "./ReactUpload-CAyCsyG6.js";
3
+ type UploadItem<F extends UploadFile = File> = UploadItem$1<F>;
4
+ type CalmLensUpload<F extends UploadFile = File> = CalmLensUpload$1<F>;
5
+ type UploadSnapshot<F extends UploadFile = File> = UploadSnapshot$1<F>;
6
+ type UploadControllerOptions<F extends UploadFile = File> = UploadControllerOptions$1<F>;
7
+ type UploaderProps<F extends UploadFile = File> = UploaderProps$1<F>;
8
+ type UseCalmLensUploadResult<F extends UploadFile = File> = UseCalmLensUploadResult$1<F>;
9
+ /** Creates an upload queue for the browser components, such as one a form starts on submit. */
10
+ declare const createUploadController: <F extends UploadFile = File>(options: UploadControllerOptions<F>) => UploadController<F>;
11
+ export { UploaderProps as a, UploadSnapshot as i, UploadControllerOptions as n, UseCalmLensUploadResult as o, UploadItem as r, createUploadController as s, CalmLensUpload as t };
@@ -0,0 +1,10 @@
1
+ const require_UploadController = require("./UploadController-BGO1eyzb.js");
2
+ // src/ui/BrowserUpload.ts
3
+ /** Creates an upload queue for the browser components, such as one a form starts on submit. */
4
+ const createUploadController = (options) => require_UploadController.createUploadController(options);
5
+ Object.defineProperty(exports, "createUploadController", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createUploadController;
9
+ }
10
+ });
@@ -0,0 +1,89 @@
1
+ const require_ModerationContextLimits = require("./ModerationContextLimits-DelWfmiJ.js");
2
+ const require_CalmLensConnection = require("./CalmLensConnection-B8Bu2j3y.js");
3
+ // src/client/CalmLensAppClient.ts
4
+ const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
5
+ /**
6
+ * The CalmLens client for browsers and React Native apps. It uploads through an upload preset,
7
+ * with an upload token from your server when the preset requires one, and never holds an API
8
+ * key. It can upload (`assets.create`, `assets.classify`, `assets.uploadPart`) and check its own
9
+ * uploads (`assets.retrieve`). Every method throws `CalmLensError` on failure.
10
+ */
11
+ var CalmLensAppClient = class {
12
+ #uploadPresetId;
13
+ #token;
14
+ /** The token each upload started with, for its parts and status checks. */
15
+ #uploadTokens = /* @__PURE__ */ new Map();
16
+ #connection;
17
+ constructor(options) {
18
+ require_ModerationContextLimits.validateAppClientOptions(options);
19
+ const { token, uploadPresetId, ...rest } = options;
20
+ this.#uploadPresetId = uploadPresetId;
21
+ this.#token = token;
22
+ this.#connection = new require_CalmLensConnection.CalmLensConnection(require_CalmLensConnection.resolveConnectionOptions(rest));
23
+ }
24
+ /** Keeps tokens out of `console.log`, `util.inspect` and `JSON.stringify`. */
25
+ [inspectSymbol]() {
26
+ return `CalmLensAppClient { uploadPresetId: ${JSON.stringify(this.#uploadPresetId)}, baseUrl: ${JSON.stringify(this.#connection.options.baseUrl)} }`;
27
+ }
28
+ toJSON() {
29
+ return {
30
+ uploadPresetId: this.#uploadPresetId,
31
+ baseUrl: this.#connection.options.baseUrl
32
+ };
33
+ }
34
+ get uploadsPath() {
35
+ return `/upload-presets/${encodeURIComponent(this.#uploadPresetId)}/assets`;
36
+ }
37
+ /** A fresh token for a new upload, when the client has one. */
38
+ async newUploadToken() {
39
+ const token = typeof this.#token === "function" ? await this.#token() : this.#token;
40
+ if (token !== void 0 && (typeof token !== "string" || !token)) throw require_ModerationContextLimits.invalidConfig("token must return a non-empty string");
41
+ return token;
42
+ }
43
+ /** The `Authorization` header for an upload this client started. */
44
+ authHeaders(assetId) {
45
+ const token = this.#uploadTokens.get(assetId);
46
+ return token ? { Authorization: `Bearer ${token}` } : {};
47
+ }
48
+ /** Uploads with a new token, kept for the upload's parts and status checks. */
49
+ async submit(options, queue) {
50
+ if (!options || typeof options !== "object") throw require_ModerationContextLimits.invalidArgument("Upload options are required");
51
+ if (!("content" in options) && !("part" in options)) throw require_ModerationContextLimits.invalidArgument("Uploads through an upload preset need content or a part");
52
+ require_CalmLensConnection.prepareSubmitAssetOptions(options, { deferUploadChecks: this.#connection.deferUploadChecks });
53
+ const token = await this.newUploadToken();
54
+ const data = await this.#connection.submitRawUpload(this.uploadsPath, options, queue, token ? { Authorization: `Bearer ${token}` } : {});
55
+ const uploaded = require_CalmLensConnection.expectUploadedAsset(data);
56
+ if (token) this.#uploadTokens.set(uploaded.id, token);
57
+ return uploaded;
58
+ }
59
+ /** Uploads through the client's upload preset and checks those uploads. */
60
+ get assets() {
61
+ return {
62
+ /** Uploads a file and queues it for moderation. */
63
+ create: (options) => this.submit(options, true),
64
+ /** Uploads a file and waits for its moderation decision. */
65
+ classify: (options) => this.submit(options, false),
66
+ /**
67
+ * Uploads the next part of a multipart upload this client started. The upload's queue
68
+ * mode, chosen when it started, applies when the final part arrives.
69
+ */
70
+ uploadPart: async ({ assetId, ...options }) => {
71
+ const encodedAssetId = require_ModerationContextLimits.encodePathSegment(assetId, "Asset ID");
72
+ const data = await this.#connection.uploadPart(`${this.uploadsPath}/${encodedAssetId}/part`, options, this.authHeaders(assetId));
73
+ return require_CalmLensConnection.expectUploadedAsset(data);
74
+ },
75
+ /** Checks an upload this client made. `status` is present when the preset shows decisions. */
76
+ retrieve: async ({ assetId }) => {
77
+ const encodedAssetId = require_ModerationContextLimits.encodePathSegment(assetId, "Asset ID");
78
+ const data = await this.#connection.json("GET", `${this.uploadsPath}/${encodedAssetId}`, { headers: this.authHeaders(assetId) });
79
+ return require_CalmLensConnection.expectUploadedAsset(data);
80
+ }
81
+ };
82
+ }
83
+ };
84
+ Object.defineProperty(exports, "CalmLensAppClient", {
85
+ enumerable: true,
86
+ get: function() {
87
+ return CalmLensAppClient;
88
+ }
89
+ });
@@ -0,0 +1,40 @@
1
+ import { Ct as UploadAssetPartOptions, Tt as UploadedAsset, pt as RetrieveAssetOptions, w as CalmLensAppClientOptions, wt as UploadPresetSubmitAssetOptions } from "./CalmLensTypes-9Vt16pc7.js";
2
+ declare const inspectSymbol: unique symbol;
3
+ /**
4
+ * The CalmLens client for browsers and React Native apps. It uploads through an upload preset,
5
+ * with an upload token from your server when the preset requires one, and never holds an API
6
+ * key. It can upload (`assets.create`, `assets.classify`, `assets.uploadPart`) and check its own
7
+ * uploads (`assets.retrieve`). Every method throws `CalmLensError` on failure.
8
+ */
9
+ declare class CalmLensAppClient {
10
+ #private;
11
+ constructor(options: CalmLensAppClientOptions);
12
+ /** Keeps tokens out of `console.log`, `util.inspect` and `JSON.stringify`. */
13
+ [inspectSymbol](): string;
14
+ toJSON(): {
15
+ uploadPresetId: string;
16
+ baseUrl: string;
17
+ };
18
+ private get uploadsPath();
19
+ /** A fresh token for a new upload, when the client has one. */
20
+ private newUploadToken;
21
+ /** The `Authorization` header for an upload this client started. */
22
+ private authHeaders;
23
+ /** Uploads with a new token, kept for the upload's parts and status checks. */
24
+ private submit;
25
+ /** Uploads through the client's upload preset and checks those uploads. */
26
+ get assets(): {
27
+ /** Uploads a file and queues it for moderation. */
28
+ create: (options: UploadPresetSubmitAssetOptions) => Promise<UploadedAsset>;
29
+ /** Uploads a file and waits for its moderation decision. */
30
+ classify: (options: UploadPresetSubmitAssetOptions) => Promise<UploadedAsset>;
31
+ /**
32
+ * Uploads the next part of a multipart upload this client started. The upload's queue
33
+ * mode, chosen when it started, applies when the final part arrives.
34
+ */
35
+ uploadPart: ({ assetId, ...options }: UploadAssetPartOptions) => Promise<UploadedAsset>;
36
+ /** Checks an upload this client made. `status` is present when the preset shows decisions. */
37
+ retrieve: ({ assetId }: RetrieveAssetOptions) => Promise<UploadedAsset>;
38
+ };
39
+ }
40
+ export { CalmLensAppClient as t };