@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,235 @@
1
+ import { o as HashList, s as HashListEntry } from "./ModerationContext-9lGm-Mna-CcmbRnOy.js";
2
+ import { $ as IterateAssetsOptions, A as ClassifyTextOptions, B as EnsureLensesOptions, C as BatchAssetsResponse, Ct as UploadAssetPartOptions, E as CdnAssetUrlOptions, Et as VerifyWebhookSignatureOptions, G as HashListEntryIdOptions, H as FolderIdOptions, I as DecideAssetOptions, J as HashListPage, Jt as AssetSearchQuery, K as HashListEntryPage, L as DeleteAssetContentOptions, M as CreateAssetSignedUrlOptions, Mt as GetEventsResponse, N as CreateFolderOptions, Nt as PostAssetSignedUrlResponse, O as CdnServeOptions, Ot as WaitForAssetDecisionOptions, P as CreateHashListOptions, Q as IterateAssetChildrenOptions, R as DeleteAssetOptions, S as BatchAssetsOptions, St as UpdateHashListOptions, T as CalmLensServerClientOptions, U as FolderPage, Ut as Folder, V as ExplainAssetOptions, _t as SignedUploadToken, at as ListFoldersOptions, bt as UpdateAssetOptions, ct as MoveAssetOptions, et as Lens, ft as RequestOptions, g as AssetSearchResponse, gt as SignUploadTokenOptions, h as AssetPage, i as AssetChildrenPage, it as ListEventsOptions, lt as MoveFolderOptions, mt as RetryAssetOptions, n as Asset, nt as ListAssetChildrenOptions, ot as ListHashListEntriesOptions, pt as RetrieveAssetOptions, q as HashListIdOptions, rt as ListAssetsOptions, st as ListHashListsOptions, t as AddHashListEntryOptions, xt as UpdateFolderOptions, yt as SubmitAssetOptions, z as EnsureLensOptions } from "./CalmLensTypes-9Vt16pc7.js";
3
+ import "./WebhookPayload-2aL31v0J.js";
4
+ interface LensCache {
5
+ readonly ensuredLenses: Map<string, Lens>;
6
+ readonly pendingEnsureLenses: Map<string, Promise<void>>;
7
+ }
8
+ declare const inspectSymbol: unique symbol;
9
+ /**
10
+ * The CalmLens API client for your server, authenticated with a project API key. Create one per
11
+ * project and reuse it; it holds no connections. Every method takes one options object and
12
+ * throws `CalmLensError` on failure. Browsers and apps upload with `CalmLensAppClient` instead.
13
+ */
14
+ declare class CalmLensServerClient {
15
+ #private;
16
+ /**
17
+ * Verifies that a webhook delivery came from CalmLens: checks the `v1=` HMAC-SHA256 in
18
+ * `x-calmlens-signature` over `"<x-calmlens-timestamp>.<raw body>"` and rejects timestamps
19
+ * more than `toleranceSeconds` (default 300) from now, which stops replayed deliveries.
20
+ * Also exported as `verifyWebhookSignature`; `parseWebhookEvent` verifies and parses.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const payload = await request.text();
25
+ * const isValid = await CalmLensServerClient.verifyWebhookSignature({
26
+ * payload,
27
+ * headers: request.headers,
28
+ * secret: process.env.CALMLENS_WEBHOOK_SECRET!,
29
+ * });
30
+ * ```
31
+ */
32
+ static verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<boolean>;
33
+ constructor(options: CalmLensServerClientOptions, lenses?: LensCache);
34
+ /**
35
+ * A client with different cancellation, deadlines or retries for the calls made through it,
36
+ * sharing this client's credentials and lens cache. This client is unchanged.
37
+ */
38
+ withRequestOptions(options: RequestOptions): CalmLensServerClient;
39
+ /** Keeps the API key out of `console.log`, `util.inspect` and `JSON.stringify`. */
40
+ [inspectSymbol](): string;
41
+ toJSON(): {
42
+ projectId: string;
43
+ baseUrl: string;
44
+ cdnBaseUrl: string;
45
+ };
46
+ private get projectPath();
47
+ private request;
48
+ private submitAsset;
49
+ get cdn(): {
50
+ /**
51
+ * Builds a CDN URL for asset content or a preview, without a request. Private assets
52
+ * need a signed URL (`assets.createSignedUrl`) or an authenticated request; public
53
+ * age-restricted assets additionally require `viewerClaims.ageConfirmed: true`.
54
+ */
55
+ getAssetUrl: ({ assetIdentifier, ...options }: CdnAssetUrlOptions) => string;
56
+ /**
57
+ * Fetches asset content or a preview from the CDN with the client's API key, and returns
58
+ * the `Response` as soon as headers arrive, so the body streams. Non-2xx responses are
59
+ * returned, not thrown; `timeoutMs` covers only the wait for headers.
60
+ */
61
+ serve: ({ assetIdentifier, init, ...urlOptions }: CdnServeOptions) => Promise<Response>;
62
+ };
63
+ get text(): {
64
+ /**
65
+ * Moderates text and waits for the decision. Sends `text` as `text/plain` content named
66
+ * `text` unless you pass `name`.
67
+ */
68
+ classify: (options: ClassifyTextOptions) => Promise<Asset>;
69
+ };
70
+ /** Assets: uploads, moderation and management. */
71
+ get assets(): {
72
+ /** Searches accessible assets by keyword or a natural-language description. */
73
+ search: (options: Partial<AssetSearchQuery> & {
74
+ query: string;
75
+ }) => Promise<AssetSearchResponse>;
76
+ /** Lists one page of the project's assets, with optional filter and ordering. */
77
+ list: (options?: ListAssetsOptions) => Promise<AssetPage>;
78
+ /**
79
+ * Yields every asset matching `options`, fetching pages as needed. The cursor keeps the position
80
+ * stable when other assets are inserted or deleted.
81
+ */
82
+ iterate: (options?: IterateAssetsOptions) => AsyncGenerator<Asset, void, undefined>;
83
+ /** Retrieves an asset with its status and classification results. */
84
+ retrieve: ({ assetId }: RetrieveAssetOptions) => Promise<Asset>;
85
+ /** Updates an asset's editable fields. */
86
+ update: ({ assetId, ...body }: UpdateAssetOptions) => Promise<Asset>;
87
+ /** Lists one page of the assets extracted from a website or multimedia document. */
88
+ listChildren: ({ assetId, ...options }?: ListAssetChildrenOptions) => Promise<AssetChildrenPage>;
89
+ /** Yields every child of an asset, fetching pages as needed. */
90
+ iterateChildren: (options: IterateAssetChildrenOptions) => AsyncGenerator<Asset, void, undefined>;
91
+ /**
92
+ * Uploads an asset and queues it for moderation, returning immediately with processing
93
+ * status `processing` (or `uploading` for the first multipart part). Retried safely with an
94
+ * `Idempotency-Key`.
95
+ */
96
+ create: (options: SubmitAssetOptions) => Promise<Asset>;
97
+ /**
98
+ * Uploads an asset and waits for its moderation decision. Audio and video still finish
99
+ * in the background. Retried safely with an `Idempotency-Key`.
100
+ */
101
+ classify: (options: SubmitAssetOptions) => Promise<Asset>;
102
+ /**
103
+ * Uploads the next part of a multipart upload. The upload's queue mode, chosen when it
104
+ * started, applies when the final part arrives; pass `queue` to override it.
105
+ */
106
+ uploadPart: ({ assetId, ...options }: UploadAssetPartOptions) => Promise<Asset>;
107
+ /**
108
+ * Creates a short-lived signed CDN URL, so browsers can load private content without
109
+ * an API key.
110
+ */
111
+ createSignedUrl: ({ assetId, ...options }: CreateAssetSignedUrlOptions) => Promise<PostAssetSignedUrlResponse>;
112
+ /** Moves an asset into a folder, or to the project root with `folderId: null`. */
113
+ move: ({ assetId, folderId }: MoveAssetOptions) => Promise<Asset>;
114
+ /**
115
+ * Processes an asset that failed (classification status `failed`) again. It returns to
116
+ * `processing` and is
117
+ * moderated like a new upload; its content must still be stored.
118
+ */
119
+ retry: ({ assetId }: RetryAssetOptions) => Promise<Asset>;
120
+ /**
121
+ * Records a reviewer's decision, replacing the policy's: the asset's moderation status
122
+ * becomes `decision`, the note joins its review history and the matching `asset.<status>`
123
+ * event is sent. An asset still pending moderation can only be blocked or purged. Purging
124
+ * needs `confirmPurge: true` and permanently deletes the stored content.
125
+ */
126
+ decide: ({ assetId, ...body }: DecideAssetOptions) => Promise<Asset>;
127
+ /**
128
+ * Completes the policy evidence behind a decided asset's moderation decision: the report's
129
+ * `classification.moderation.evidence` becomes `full` and every action stays as
130
+ * decided. With `rerun: true` the asset is moderated again with the project's current policy
131
+ * and returns in `processing`; use it when the policy has changed since the decision
132
+ * (`asset/policy-changed`).
133
+ */
134
+ explain: ({ assetId, rerun }: ExplainAssetOptions) => Promise<Asset>;
135
+ /**
136
+ * Waits until an asset's `classification.moderation.status` is no longer `pending` (`allowed`,
137
+ * `limited`, `age-restricted`, `blocked` or `purged`), or its `classification.status` is `failed`, and returns that asset, checking every few seconds. Rejects with `sdk/timeout` if there is no
138
+ * decision within `timeoutMs` (default 60000). Webhooks report decisions without polling.
139
+ */
140
+ waitForDecision: ({ assetId, ...options }: WaitForAssetDecisionOptions) => Promise<Asset>;
141
+ /**
142
+ * Removes an asset's stored content (source, preview and retained extracted text) while
143
+ * keeping the asset record, metadata and classification results. The returned asset has
144
+ * `content.status` set to `removed` and `content.removalReason` to `requested`; the CDN no longer serves it.
145
+ */
146
+ deleteContent: ({ assetId }: DeleteAssetContentOptions) => Promise<Asset>;
147
+ /** Deletes an asset record together with its stored content. */
148
+ delete: ({ assetId }: DeleteAssetOptions) => Promise<void>;
149
+ /**
150
+ * Deletes up to 500 assets (`operation: "delete"`) or removes their stored content
151
+ * (`"remove-content"`) in one request. Every asset must exist in the project and the key
152
+ * needs `assets:delete` for its folder, or nothing is queued. Resolves with
153
+ * `{ queued: true }` once queued; the work runs in the background and records
154
+ * `asset.deleted` or `asset.content-removed` for each asset. Assets under a safety hold
155
+ * are skipped. Not retried: it carries no `Idempotency-Key`.
156
+ */
157
+ batch: ({ assetIds, operation }: BatchAssetsOptions) => Promise<BatchAssetsResponse>;
158
+ };
159
+ /**
160
+ * Signs upload tokens on your server, so a browser or app can upload through an upload preset
161
+ * that requires one. Signing happens locally with your API key: it makes no request.
162
+ */
163
+ get uploadTokens(): {
164
+ /**
165
+ * Signs a single-use token for one upload through `uploadPresetId`. Give `token` to the
166
+ * browser or app, which passes it to `CalmLensAppClient` as `token`.
167
+ */
168
+ sign: (options: SignUploadTokenOptions) => Promise<SignedUploadToken>;
169
+ };
170
+ private buildAssets;
171
+ get events(): {
172
+ /**
173
+ * Lists project events after a cursor, oldest first. Call without `cursor` to get a cursor
174
+ * for "now", then poll with each response's `nextCursor`. Webhook deliveries carry the same
175
+ * events reshaped as `{ id, type, createdAt, projectId, data }`.
176
+ */
177
+ list: (options?: ListEventsOptions) => Promise<GetEventsResponse>;
178
+ /**
179
+ * Yields pages of events after `cursor` until no more are waiting. Save each page's
180
+ * `nextCursor` to resume later. Without `cursor`, yields one empty page whose `nextCursor`
181
+ * is "now".
182
+ */
183
+ pages: (options?: ListEventsOptions) => AsyncGenerator<GetEventsResponse, void, undefined>;
184
+ };
185
+ private iterateEventPages;
186
+ private iteratePages;
187
+ get folders(): {
188
+ /**
189
+ * Lists one page of child folders, sorted by name unless `ordering` says otherwise. Pass
190
+ * `nextCursor` as `cursor` for the next page; fetch a branch when it is opened.
191
+ */
192
+ list: (options?: ListFoldersOptions) => Promise<FolderPage>;
193
+ retrieve: ({ folderId }: FolderIdOptions) => Promise<Folder>;
194
+ /** Creates a folder at the project root or inside `parentId`. */
195
+ create: (options: CreateFolderOptions) => Promise<Folder>;
196
+ update: ({ folderId, ...body }: UpdateFolderOptions) => Promise<Folder>;
197
+ /** Deletes an empty folder; throws `folder/not-empty` otherwise. */
198
+ delete: ({ folderId }: FolderIdOptions) => Promise<void>;
199
+ /** Moves a folder under `parentId`, or to the project root with `parentId: null`. */
200
+ move: ({ folderId, parentId }: MoveFolderOptions) => Promise<Folder>;
201
+ };
202
+ /**
203
+ * Hash lists hold PDQ hashes of images the project never wants again. Image uploads are
204
+ * compared with every list: `flag` lists record matches, `block` lists also block close ones.
205
+ */
206
+ get hashLists(): {
207
+ /** Lists one page of the project's hash lists, newest first. */
208
+ list: (options?: ListHashListsOptions) => Promise<HashListPage>;
209
+ retrieve: ({ hashListId }: HashListIdOptions) => Promise<HashList>;
210
+ create: (options: CreateHashListOptions) => Promise<HashList>;
211
+ /** Renames a list or changes its action; the new action applies to later uploads. */
212
+ update: ({ hashListId, ...body }: UpdateHashListOptions) => Promise<HashList>;
213
+ /** Deletes the list and every entry in it. */
214
+ delete: ({ hashListId }: HashListIdOptions) => Promise<void>;
215
+ /** Lists one page of a list's entries, newest first. */
216
+ listEntries: ({ hashListId, ...query }: ListHashListEntriesOptions) => Promise<HashListEntryPage>;
217
+ /** Adds a hash, or an image asset's hash; a hash already in the list returns its entry. */
218
+ addEntry: ({ hashListId, ...body }: AddHashListEntryOptions) => Promise<HashListEntry>;
219
+ removeEntry: ({ entryId }: HashListEntryIdOptions) => Promise<void>;
220
+ };
221
+ /**
222
+ * Create a named lens at any positive version, or update it with a greater version.
223
+ * Supplying the same definition and version is idempotent.
224
+ */
225
+ ensureLens(options: EnsureLensOptions): Promise<Lens>;
226
+ /**
227
+ * Create or update several named lenses. New definitions are sent in one API request, or in
228
+ * consecutive requests of at most {@link ENSURE_LENSES_MAX_PER_REQUEST} definitions, in order.
229
+ * Each lens follows the same versioning and idempotency rules as ensureLens().
230
+ */
231
+ ensureLenses({ lenses }: EnsureLensesOptions): Promise<Lens[]>;
232
+ private submitEnsureLenses;
233
+ private submitEnsureLensesChunk;
234
+ }
235
+ export { CalmLensServerClient as t };