@calmlens/sdk 0.16.2 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +399 -162
  2. package/cjs/BrowserUpload-DZ0Vbmxi.js +10 -0
  3. package/cjs/BrowserUpload-uZjVFGfP.d.ts +11 -0
  4. package/cjs/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  5. package/cjs/CalmLensAppClient-DBGmaDlG.js +89 -0
  6. package/cjs/CalmLensConnection-K1TAD1Z-.js +659 -0
  7. package/cjs/CalmLensServerClient-C-pxiz0C.js +645 -0
  8. package/cjs/CalmLensServerClient-JtP687a3.d.ts +235 -0
  9. package/cjs/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  10. package/cjs/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  11. package/cjs/CryptoUtils-B_x8lMIx-YBW1-bvL.js +42 -0
  12. package/cjs/FileIcons-Ob003MdS.js +175 -0
  13. package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +91 -0
  14. package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  15. package/cjs/ModerationContextLimits-Dj1YAl3G.js +1311 -0
  16. package/cjs/ReactUpload-DxtFMr06.js +54 -0
  17. package/cjs/ReactUpload-nZahpmyg.d.ts +17 -0
  18. package/cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  19. package/cjs/TestTriggers-DcArt0Nu-CvoaONUB.js +1326 -0
  20. package/cjs/UploadController-BBkN4Ni6.js +618 -0
  21. package/{esm/index-C9Xw1aid.d.ts → cjs/WebhookPayload-2aL31v0J.d.ts} +131 -155
  22. package/cjs/app.d.ts +7 -44
  23. package/cjs/app.js +11 -89
  24. package/cjs/elements.d.ts +88 -0
  25. package/cjs/elements.js +555 -0
  26. package/cjs/file-icons.d.ts +67 -0
  27. package/cjs/file-icons.js +10 -0
  28. package/cjs/index-CI4BzN4W.d.ts +252 -0
  29. package/cjs/index.d.ts +6 -4
  30. package/cjs/index.js +9 -4
  31. package/cjs/react-native.d.ts +56 -0
  32. package/cjs/react-native.js +495 -0
  33. package/cjs/react.d.ts +30 -0
  34. package/cjs/react.js +370 -0
  35. package/cjs/server.d.ts +12 -191
  36. package/cjs/server.js +18 -378
  37. package/cjs/test-inputs.d.ts +2 -2
  38. package/cjs/test-inputs.js +9 -264
  39. package/cjs/testing.d.ts +285 -190
  40. package/cjs/testing.js +2393 -1203
  41. package/cjs/ui-CgZpgpNo.d.ts +526 -0
  42. package/cjs/ui-KceuoVCM.js +583 -0
  43. package/cjs/ui.d.ts +2 -0
  44. package/cjs/ui.js +27 -0
  45. package/cjs/vue.d.ts +490 -0
  46. package/cjs/vue.js +419 -0
  47. package/esm/BrowserUpload-D7-zNmc0.js +5 -0
  48. package/esm/BrowserUpload-uZjVFGfP.d.ts +11 -0
  49. package/esm/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  50. package/esm/CalmLensAppClient-FVMwrHlH.js +84 -0
  51. package/esm/CalmLensConnection-iyNQHA8L.js +582 -0
  52. package/esm/CalmLensServerClient-JtP687a3.d.ts +235 -0
  53. package/esm/CalmLensServerClient-fQEYKLw4.js +586 -0
  54. package/esm/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  55. package/esm/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  56. package/esm/CryptoUtils-B_x8lMIx-DhuWGzqn.js +25 -0
  57. package/esm/FileIcons-M6dzjFxd.js +128 -0
  58. package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +46 -0
  59. package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  60. package/esm/ModerationContextLimits-D1x_WAtP.js +1114 -0
  61. package/esm/ReactUpload-D6yBCkcw.js +37 -0
  62. package/esm/ReactUpload-nZahpmyg.d.ts +17 -0
  63. package/esm/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  64. package/esm/TestTriggers-DcArt0Nu-s0AQZuWE.js +1266 -0
  65. package/esm/UploadController-txp5NuzH.js +589 -0
  66. package/{cjs/index-C9Xw1aid.d.ts → esm/WebhookPayload-2aL31v0J.d.ts} +131 -155
  67. package/esm/app.d.ts +7 -44
  68. package/esm/app.js +3 -86
  69. package/esm/elements.d.ts +88 -0
  70. package/esm/elements.js +528 -0
  71. package/esm/file-icons.d.ts +67 -0
  72. package/esm/file-icons.js +1 -0
  73. package/esm/index-CI4BzN4W.d.ts +252 -0
  74. package/esm/index.d.ts +6 -4
  75. package/esm/index.js +1 -1
  76. package/esm/react-native.d.ts +56 -0
  77. package/esm/react-native.js +467 -0
  78. package/esm/react.d.ts +30 -0
  79. package/esm/react.js +343 -0
  80. package/esm/server.d.ts +12 -191
  81. package/esm/server.js +3 -369
  82. package/esm/styles.css +147 -0
  83. package/esm/svelte/CalmLensMedia.svelte +134 -0
  84. package/esm/svelte/CalmLensUploader.svelte +175 -0
  85. package/esm/svelte/Icon.svelte +7 -0
  86. package/esm/svelte/index.d.ts +37 -0
  87. package/esm/svelte/index.js +6 -0
  88. package/esm/test-inputs.d.ts +2 -2
  89. package/esm/test-inputs.js +1 -256
  90. package/esm/testing.d.ts +285 -190
  91. package/esm/testing.js +2329 -1122
  92. package/esm/ui-Ca_SpJXf.js +458 -0
  93. package/esm/ui-CgZpgpNo.d.ts +526 -0
  94. package/esm/ui.d.ts +2 -0
  95. package/esm/ui.js +3 -0
  96. package/esm/vue.d.ts +490 -0
  97. package/esm/vue.js +392 -0
  98. package/package.json +110 -11
  99. package/cjs/CalmLensConnection-5Hj3trGr.js +0 -234
  100. package/cjs/CalmLensUtils-BeIl1N6N.js +0 -699
  101. package/cjs/CalmLensVersion-BGpB9t4-.js +0 -480
  102. package/cjs/CalmLensWebhooks-CogUYk8-.js +0 -201
  103. package/cjs/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
  104. package/cjs/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
  105. package/cjs/WebhookPayload-CJoIkGBD.d.ts +0 -11753
  106. package/esm/CalmLensConnection-BAJdoZHy.js +0 -193
  107. package/esm/CalmLensUtils-DqniTKJ8.js +0 -574
  108. package/esm/CalmLensVersion-l_khh4nS.js +0 -415
  109. package/esm/CalmLensWebhooks-BtrKKLvg.js +0 -148
  110. package/esm/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
  111. package/esm/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
  112. package/esm/WebhookPayload-CJoIkGBD.d.ts +0 -11753
@@ -0,0 +1,10 @@
1
+ const require_UploadController = require("./UploadController-BBkN4Ni6.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,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-CgZpgpNo.js";
2
+ import { t as UseCalmLensUploadResult$1 } from "./ReactUpload-nZahpmyg.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,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 };
@@ -0,0 +1,89 @@
1
+ const require_ModerationContextLimits = require("./ModerationContextLimits-Dj1YAl3G.js");
2
+ const require_CalmLensConnection = require("./CalmLensConnection-K1TAD1Z-.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
+ });