@calmlens/sdk 0.10.1 → 0.12.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/README.md +60 -16
- package/cjs/CalmLensConnection-CYtBP-vu.js +516 -0
- package/cjs/CalmLensError-CKwMKV0S.js +362 -0
- package/cjs/CalmLensUtils-Dg3s4loH.js +367 -0
- package/cjs/CalmLensWebhooks-BTPxKvcD.js +201 -0
- package/cjs/{CalmLensTypes-DjYFaTyh.d.ts → WebhookPayload-Cgb32aSH.d.ts} +5423 -3844
- package/cjs/app.d.ts +43 -0
- package/cjs/app.js +91 -0
- package/cjs/index-BgmWj3KL.d.ts +350 -0
- package/cjs/index.d.ts +3 -382
- package/cjs/index.js +5 -816
- package/cjs/server.d.ts +202 -0
- package/cjs/server.js +371 -0
- package/cjs/src-Dsc8Pn6v.js +45 -0
- package/cjs/testing.d.ts +54 -18
- package/cjs/testing.js +191 -62
- package/esm/CalmLensConnection-wLNy0OIP.js +475 -0
- package/esm/CalmLensError-CihGG26K.js +321 -0
- package/esm/CalmLensUtils-Cx32j2zt.js +260 -0
- package/esm/CalmLensWebhooks-DShmAal4.js +148 -0
- package/esm/{CalmLensTypes-DjYFaTyh.d.ts → WebhookPayload-Cgb32aSH.d.ts} +5423 -3844
- package/esm/app.d.ts +43 -0
- package/esm/app.js +87 -0
- package/esm/index-BgmWj3KL.d.ts +350 -0
- package/esm/index.d.ts +3 -382
- package/esm/index.js +3 -807
- package/esm/server.d.ts +202 -0
- package/esm/server.js +361 -0
- package/esm/src-CJhrILvM.js +22 -0
- package/esm/testing.d.ts +54 -18
- package/esm/testing.js +142 -13
- package/package.json +23 -1
- package/cjs/CalmLensWebhooks-DJnaLpRy.js +0 -741
- package/esm/CalmLensWebhooks-DLUozliX.js +0 -556
package/cjs/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { $ as SearchAssetsOptions, A as DeleteAssetContentOptions, B as Lens, C as CdnAssetUrlOptions, D as CreateAssetSignedUrlOptions, G as ModerateTextOptions, H as ListAssetChildrenOptions, K as MoveAssetOptions, M as EnsureLensOptions, N as EnsureLensesOptions, O as CreateFolderOptions, P as FolderIdOptions, Q as RetryAssetOptions, R as IterateAssetChildrenOptions, S as CalmLensServerClientOptions, U as ListAssetsOptions, W as ListEventsOptions, Z as RetrieveAssetOptions, _t as TypedEvent, at as UpdateFolderOptions, d as Asset, et as SignUploadTokenOptions, ft as GetEventsResponse, g as AssetSearchResponse, h as AssetPage, ht as Event, it as UpdateAssetOptions, j as DeleteAssetOptions, kt as AssetBinaryPayloadInput, mt as Folder, ot as UploadAssetPartOptions, p as AssetChildrenPage, pt as PostAssetSignedUrlResponse, q as MoveFolderOptions, r as ClassificationCategory, rt as SubmitAssetOptions, t as WebhookEventPayload, tt as SignedUploadToken, v as AssetStatus, w as CdnServeOptions, z as IterateAssetsOptions } from "./WebhookPayload-Cgb32aSH.js";
|
|
2
2
|
import * as zod from "zod";
|
|
3
3
|
//#region ../shared/src/TestTriggers.d.ts
|
|
4
4
|
type ClassificationTestSignal = ClassificationCategory | "sexual.involving-minors" | "violence.graphic";
|
|
@@ -34,6 +34,8 @@ declare const GRANT_SCHEMA: zod.ZodObject<{
|
|
|
34
34
|
"project:manage": "project:manage";
|
|
35
35
|
"settings:read": "settings:read";
|
|
36
36
|
"settings:write": "settings:write";
|
|
37
|
+
"upload-presets:read": "upload-presets:read";
|
|
38
|
+
"upload-presets:write": "upload-presets:write";
|
|
37
39
|
}>>;
|
|
38
40
|
folderId: zod.ZodNullable<zod.ZodString>;
|
|
39
41
|
includeSubfolders: zod.ZodBoolean;
|
|
@@ -102,8 +104,8 @@ export declare class InMemoryMockDatabaseStorage implements MockDatabaseStorage
|
|
|
102
104
|
deleteFolder(folderId: string): Promise<void>;
|
|
103
105
|
}
|
|
104
106
|
//#endregion
|
|
105
|
-
//#region src/testing/
|
|
106
|
-
interface
|
|
107
|
+
//#region src/testing/MockCalmLensServerClient.d.ts
|
|
108
|
+
interface MockCalmLensServerClientOptions extends CalmLensServerClientOptions {
|
|
107
109
|
mockOptions?: {
|
|
108
110
|
databaseStorage?: MockDatabaseStorage;
|
|
109
111
|
imageStorage?: MockImageStorage;
|
|
@@ -116,13 +118,44 @@ interface MockCalmLensClientOptions extends CalmLensClientOptions {
|
|
|
116
118
|
signedUrlBaseUrl?: string;
|
|
117
119
|
};
|
|
118
120
|
}
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
/** The options each `MockCalmLensServerClient` method was given, by operation name. */
|
|
122
|
+
interface MockCalmLensOperationOptions {
|
|
123
|
+
"assets.list": ListAssetsOptions;
|
|
124
|
+
"assets.search": SearchAssetsOptions;
|
|
125
|
+
"assets.retrieve": RetrieveAssetOptions;
|
|
126
|
+
"assets.update": UpdateAssetOptions;
|
|
127
|
+
"assets.listChildren": ListAssetChildrenOptions;
|
|
128
|
+
"assets.create": SubmitAssetOptions;
|
|
129
|
+
"assets.moderate": SubmitAssetOptions;
|
|
130
|
+
"assets.uploadPart": UploadAssetPartOptions;
|
|
131
|
+
"assets.createSignedUrl": CreateAssetSignedUrlOptions;
|
|
132
|
+
"assets.move": MoveAssetOptions;
|
|
133
|
+
"assets.retry": RetryAssetOptions;
|
|
134
|
+
"assets.deleteContent": DeleteAssetContentOptions;
|
|
135
|
+
"assets.delete": DeleteAssetOptions;
|
|
136
|
+
"text.moderate": ModerateTextOptions;
|
|
137
|
+
"cdn.serve": CdnServeOptions;
|
|
138
|
+
"events.list": ListEventsOptions;
|
|
139
|
+
"folders.list": undefined;
|
|
140
|
+
"folders.retrieve": FolderIdOptions;
|
|
141
|
+
"folders.create": CreateFolderOptions;
|
|
142
|
+
"folders.update": UpdateFolderOptions;
|
|
143
|
+
"folders.delete": FolderIdOptions;
|
|
144
|
+
"folders.move": MoveFolderOptions;
|
|
145
|
+
ensureLens: EnsureLensOptions;
|
|
146
|
+
ensureLenses: EnsureLensesOptions;
|
|
147
|
+
"uploadTokens.sign": SignUploadTokenOptions;
|
|
125
148
|
}
|
|
149
|
+
/** A `MockCalmLensServerClient` method, named like its path on the client. */
|
|
150
|
+
type MockCalmLensOperation = keyof MockCalmLensOperationOptions;
|
|
151
|
+
/**
|
|
152
|
+
* One recorded call: the method and the options object it was given, exactly as passed. Narrow
|
|
153
|
+
* on `operation` (or use `callsTo`) to get its options type.
|
|
154
|
+
*/
|
|
155
|
+
type MockCalmLensCall<TOperation extends MockCalmLensOperation = MockCalmLensOperation> = { [Operation in TOperation]: {
|
|
156
|
+
operation: Operation;
|
|
157
|
+
options: MockCalmLensOperationOptions[Operation];
|
|
158
|
+
}; }[TOperation];
|
|
126
159
|
/**
|
|
127
160
|
* What a simulated request failure throws: `"transport-error"` and `"timeout"` throw the same
|
|
128
161
|
* `CalmLensError` the real client throws for a network failure (`sdk/transport-error`) or a
|
|
@@ -134,11 +167,11 @@ type MockEventInput = Partial<Omit<TypedEvent, "type">> & {
|
|
|
134
167
|
type: TypedEvent["type"];
|
|
135
168
|
};
|
|
136
169
|
/**
|
|
137
|
-
* An in-memory stand-in for `
|
|
170
|
+
* An in-memory stand-in for `CalmLensServerClient` with the same methods, validation and error
|
|
138
171
|
* codes. API errors carry the HTTP status, a `requestId` and response headers like the real
|
|
139
172
|
* client's, so error handling can be tested without a network.
|
|
140
173
|
*/
|
|
141
|
-
export declare class
|
|
174
|
+
export declare class MockCalmLensServerClient {
|
|
142
175
|
readonly databaseStorage: MockDatabaseStorage;
|
|
143
176
|
readonly imageStorage: MockImageStorage;
|
|
144
177
|
private readonly createId;
|
|
@@ -149,6 +182,7 @@ export declare class MockCalmLensClient {
|
|
|
149
182
|
private readonly signedUrlBaseUrl;
|
|
150
183
|
private readonly cdnBaseUrl;
|
|
151
184
|
private readonly projectId;
|
|
185
|
+
private readonly apiKey;
|
|
152
186
|
private readonly lenses;
|
|
153
187
|
private readonly eventFeed;
|
|
154
188
|
/** The queue mode each open multipart upload was started with, as the API saves it. */
|
|
@@ -158,8 +192,8 @@ export declare class MockCalmLensClient {
|
|
|
158
192
|
private readonly pendingFailures;
|
|
159
193
|
/** Every call made through this client, oldest first. */
|
|
160
194
|
readonly calls: MockCalmLensCall[];
|
|
161
|
-
/** Accepts the same options as `
|
|
162
|
-
constructor(options:
|
|
195
|
+
/** Accepts the same options as `CalmLensServerClient` (validated the same way), plus `mockOptions`. */
|
|
196
|
+
constructor(options: MockCalmLensServerClientOptions);
|
|
163
197
|
/**
|
|
164
198
|
* Makes the next call (or the next call to `operation`) throw `failure` instead of running,
|
|
165
199
|
* as if the request never completed. Queue several to fail several calls in a row.
|
|
@@ -168,7 +202,7 @@ export declare class MockCalmLensClient {
|
|
|
168
202
|
operation?: MockCalmLensOperation;
|
|
169
203
|
}): void;
|
|
170
204
|
/** Calls recorded for one operation, oldest first. */
|
|
171
|
-
callsTo(operation:
|
|
205
|
+
callsTo<TOperation extends MockCalmLensOperation>(operation: TOperation): MockCalmLensCall<TOperation>[];
|
|
172
206
|
/**
|
|
173
207
|
* Adds an event to the feed `events.list` reads, as if CalmLens had recorded it. Returns the
|
|
174
208
|
* stored event; pass it to `toWebhookEventPayload` to build a matching webhook body.
|
|
@@ -211,9 +245,7 @@ export declare class MockCalmLensClient {
|
|
|
211
245
|
* description and tags, best match first. Mock scores are 1 for an exact match and 0.5
|
|
212
246
|
* otherwise; `mode` is accepted but there is no semantic search.
|
|
213
247
|
*/
|
|
214
|
-
search: (options:
|
|
215
|
-
query: string;
|
|
216
|
-
}) => Promise<AssetSearchResponse>;
|
|
248
|
+
search: (options: SearchAssetsOptions) => Promise<AssetSearchResponse>;
|
|
217
249
|
/** Lists assets with the real client's paging, `ordering`, `folderId` and `filter`. */
|
|
218
250
|
list: (options?: ListAssetsOptions) => Promise<AssetPage>;
|
|
219
251
|
iterate: (options?: IterateAssetsOptions) => AsyncGenerator<Asset, void, undefined>;
|
|
@@ -231,6 +263,10 @@ export declare class MockCalmLensClient {
|
|
|
231
263
|
deleteContent: (options: DeleteAssetContentOptions) => Promise<Asset>;
|
|
232
264
|
delete: (options: DeleteAssetOptions) => Promise<void>;
|
|
233
265
|
};
|
|
266
|
+
/** Signs real upload tokens with the mock's API key, like the real client, without a request. */
|
|
267
|
+
get uploadTokens(): {
|
|
268
|
+
sign: (options: SignUploadTokenOptions) => Promise<SignedUploadToken>;
|
|
269
|
+
};
|
|
234
270
|
get folders(): {
|
|
235
271
|
list: () => Promise<Folder[]>;
|
|
236
272
|
retrieve: (options: FolderIdOptions) => Promise<Folder>;
|
|
@@ -265,4 +301,4 @@ export declare const createWebhookHeaders: (options: {
|
|
|
265
301
|
timestampSeconds?: number;
|
|
266
302
|
}) => Promise<Record<string, string>>;
|
|
267
303
|
//#endregion
|
|
268
|
-
export type { MockCalmLensCall,
|
|
304
|
+
export type { MockCalmLensCall, MockCalmLensOperation, MockCalmLensOperationOptions, MockCalmLensServerClientOptions, MockDatabaseStorage, MockEventInput, MockImageStorage, MockRequestFailure, MockStoredContent };
|