@calmlens/sdk 0.11.0 → 0.13.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 +73 -16
- package/cjs/CalmLensConnection-DzRDCMOP.js +233 -0
- package/cjs/CalmLensUtils-vX5H_vMn.js +699 -0
- package/cjs/CalmLensVersion-DjhsJ1gj.js +410 -0
- package/cjs/CalmLensWebhooks-hVquX5L1.js +201 -0
- package/cjs/WebhookPayload-B7CgSmI5.d.ts +11928 -0
- package/cjs/app.d.ts +43 -0
- package/cjs/app.js +91 -0
- package/cjs/index-BywTQbRq.d.ts +352 -0
- package/cjs/index.d.ts +3 -382
- package/cjs/index.js +4 -816
- package/cjs/server.d.ts +210 -0
- package/cjs/server.js +384 -0
- package/cjs/testing.d.ts +59 -18
- package/cjs/testing.js +245 -99
- package/esm/CalmLensConnection-D8VsTdsA.js +192 -0
- package/esm/CalmLensUtils-B4i3Z2He.js +574 -0
- package/esm/CalmLensVersion-DK4BMEST.js +345 -0
- package/esm/CalmLensWebhooks-DyCoEvpf.js +148 -0
- package/esm/WebhookPayload-B7CgSmI5.d.ts +11928 -0
- package/esm/app.d.ts +43 -0
- package/esm/app.js +87 -0
- package/esm/index-BywTQbRq.d.ts +352 -0
- package/esm/index.d.ts +3 -382
- package/esm/index.js +1 -807
- package/esm/server.d.ts +210 -0
- package/esm/server.js +374 -0
- package/esm/testing.d.ts +59 -18
- package/esm/testing.js +195 -49
- package/package.json +23 -1
- package/cjs/CalmLensTypes-BZ-nxhr_.d.ts +0 -8613
- package/cjs/CalmLensWebhooks-CH2PaPs0.js +0 -784
- package/esm/CalmLensTypes-BZ-nxhr_.d.ts +0 -8613
- package/esm/CalmLensWebhooks-3Otbubyf.js +0 -593
package/cjs/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as SearchAssetsOptions, A as DeleteAssetContentOptions, At as AssetBinaryPayloadInput, 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, at as UpdateFolderOptions, d as Asset, et as SignUploadTokenOptions, g as AssetSearchResponse, gt as Event, h as AssetPage, ht as Folder, it as UpdateAssetOptions, j as DeleteAssetOptions, mt as PostAssetSignedUrlResponse, ot as UploadAssetPartOptions, p as AssetChildrenPage, pt as GetEventsResponse, q as MoveFolderOptions, r as ClassificationCategory, rt as SubmitAssetOptions, t as WebhookEventPayload, tt as SignedUploadToken, ut as WaitForAssetDecisionOptions, v as AssetStatus, vt as TypedEvent, w as CdnServeOptions, z as IterateAssetsOptions } from "./WebhookPayload-B7CgSmI5.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";
|
|
@@ -32,8 +32,12 @@ declare const GRANT_SCHEMA: zod.ZodObject<{
|
|
|
32
32
|
"metadata:read": "metadata:read";
|
|
33
33
|
"metadata:write": "metadata:write";
|
|
34
34
|
"project:manage": "project:manage";
|
|
35
|
+
"reviews:read": "reviews:read";
|
|
36
|
+
"reviews:write": "reviews:write";
|
|
35
37
|
"settings:read": "settings:read";
|
|
36
38
|
"settings:write": "settings:write";
|
|
39
|
+
"upload-presets:read": "upload-presets:read";
|
|
40
|
+
"upload-presets:write": "upload-presets:write";
|
|
37
41
|
}>>;
|
|
38
42
|
folderId: zod.ZodNullable<zod.ZodString>;
|
|
39
43
|
includeSubfolders: zod.ZodBoolean;
|
|
@@ -102,8 +106,8 @@ export declare class InMemoryMockDatabaseStorage implements MockDatabaseStorage
|
|
|
102
106
|
deleteFolder(folderId: string): Promise<void>;
|
|
103
107
|
}
|
|
104
108
|
//#endregion
|
|
105
|
-
//#region src/testing/
|
|
106
|
-
interface
|
|
109
|
+
//#region src/testing/MockCalmLensServerClient.d.ts
|
|
110
|
+
interface MockCalmLensServerClientOptions extends CalmLensServerClientOptions {
|
|
107
111
|
mockOptions?: {
|
|
108
112
|
databaseStorage?: MockDatabaseStorage;
|
|
109
113
|
imageStorage?: MockImageStorage;
|
|
@@ -116,13 +120,45 @@ interface MockCalmLensClientOptions extends CalmLensClientOptions {
|
|
|
116
120
|
signedUrlBaseUrl?: string;
|
|
117
121
|
};
|
|
118
122
|
}
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
/** The options each `MockCalmLensServerClient` method was given, by operation name. */
|
|
124
|
+
interface MockCalmLensOperationOptions {
|
|
125
|
+
"assets.list": ListAssetsOptions;
|
|
126
|
+
"assets.search": SearchAssetsOptions;
|
|
127
|
+
"assets.retrieve": RetrieveAssetOptions;
|
|
128
|
+
"assets.update": UpdateAssetOptions;
|
|
129
|
+
"assets.listChildren": ListAssetChildrenOptions;
|
|
130
|
+
"assets.create": SubmitAssetOptions;
|
|
131
|
+
"assets.moderate": SubmitAssetOptions;
|
|
132
|
+
"assets.uploadPart": UploadAssetPartOptions;
|
|
133
|
+
"assets.createSignedUrl": CreateAssetSignedUrlOptions;
|
|
134
|
+
"assets.move": MoveAssetOptions;
|
|
135
|
+
"assets.retry": RetryAssetOptions;
|
|
136
|
+
"assets.waitForDecision": WaitForAssetDecisionOptions;
|
|
137
|
+
"assets.deleteContent": DeleteAssetContentOptions;
|
|
138
|
+
"assets.delete": DeleteAssetOptions;
|
|
139
|
+
"text.moderate": ModerateTextOptions;
|
|
140
|
+
"cdn.serve": CdnServeOptions;
|
|
141
|
+
"events.list": ListEventsOptions;
|
|
142
|
+
"folders.list": undefined;
|
|
143
|
+
"folders.retrieve": FolderIdOptions;
|
|
144
|
+
"folders.create": CreateFolderOptions;
|
|
145
|
+
"folders.update": UpdateFolderOptions;
|
|
146
|
+
"folders.delete": FolderIdOptions;
|
|
147
|
+
"folders.move": MoveFolderOptions;
|
|
148
|
+
ensureLens: EnsureLensOptions;
|
|
149
|
+
ensureLenses: EnsureLensesOptions;
|
|
150
|
+
"uploadTokens.sign": SignUploadTokenOptions;
|
|
125
151
|
}
|
|
152
|
+
/** A `MockCalmLensServerClient` method, named like its path on the client. */
|
|
153
|
+
type MockCalmLensOperation = keyof MockCalmLensOperationOptions;
|
|
154
|
+
/**
|
|
155
|
+
* One recorded call: the method and the options object it was given, exactly as passed. Narrow
|
|
156
|
+
* on `operation` (or use `callsTo`) to get its options type.
|
|
157
|
+
*/
|
|
158
|
+
type MockCalmLensCall<TOperation extends MockCalmLensOperation = MockCalmLensOperation> = { [Operation in TOperation]: {
|
|
159
|
+
operation: Operation;
|
|
160
|
+
options: MockCalmLensOperationOptions[Operation];
|
|
161
|
+
}; }[TOperation];
|
|
126
162
|
/**
|
|
127
163
|
* What a simulated request failure throws: `"transport-error"` and `"timeout"` throw the same
|
|
128
164
|
* `CalmLensError` the real client throws for a network failure (`sdk/transport-error`) or a
|
|
@@ -134,11 +170,11 @@ type MockEventInput = Partial<Omit<TypedEvent, "type">> & {
|
|
|
134
170
|
type: TypedEvent["type"];
|
|
135
171
|
};
|
|
136
172
|
/**
|
|
137
|
-
* An in-memory stand-in for `
|
|
173
|
+
* An in-memory stand-in for `CalmLensServerClient` with the same methods, validation and error
|
|
138
174
|
* codes. API errors carry the HTTP status, a `requestId` and response headers like the real
|
|
139
175
|
* client's, so error handling can be tested without a network.
|
|
140
176
|
*/
|
|
141
|
-
export declare class
|
|
177
|
+
export declare class MockCalmLensServerClient {
|
|
142
178
|
readonly databaseStorage: MockDatabaseStorage;
|
|
143
179
|
readonly imageStorage: MockImageStorage;
|
|
144
180
|
private readonly createId;
|
|
@@ -149,6 +185,7 @@ export declare class MockCalmLensClient {
|
|
|
149
185
|
private readonly signedUrlBaseUrl;
|
|
150
186
|
private readonly cdnBaseUrl;
|
|
151
187
|
private readonly projectId;
|
|
188
|
+
private readonly apiKey;
|
|
152
189
|
private readonly lenses;
|
|
153
190
|
private readonly eventFeed;
|
|
154
191
|
/** The queue mode each open multipart upload was started with, as the API saves it. */
|
|
@@ -158,8 +195,8 @@ export declare class MockCalmLensClient {
|
|
|
158
195
|
private readonly pendingFailures;
|
|
159
196
|
/** Every call made through this client, oldest first. */
|
|
160
197
|
readonly calls: MockCalmLensCall[];
|
|
161
|
-
/** Accepts the same options as `
|
|
162
|
-
constructor(options:
|
|
198
|
+
/** Accepts the same options as `CalmLensServerClient` (validated the same way), plus `mockOptions`. */
|
|
199
|
+
constructor(options: MockCalmLensServerClientOptions);
|
|
163
200
|
/**
|
|
164
201
|
* Makes the next call (or the next call to `operation`) throw `failure` instead of running,
|
|
165
202
|
* as if the request never completed. Queue several to fail several calls in a row.
|
|
@@ -168,7 +205,7 @@ export declare class MockCalmLensClient {
|
|
|
168
205
|
operation?: MockCalmLensOperation;
|
|
169
206
|
}): void;
|
|
170
207
|
/** Calls recorded for one operation, oldest first. */
|
|
171
|
-
callsTo(operation:
|
|
208
|
+
callsTo<TOperation extends MockCalmLensOperation>(operation: TOperation): MockCalmLensCall<TOperation>[];
|
|
172
209
|
/**
|
|
173
210
|
* Adds an event to the feed `events.list` reads, as if CalmLens had recorded it. Returns the
|
|
174
211
|
* stored event; pass it to `toWebhookEventPayload` to build a matching webhook body.
|
|
@@ -211,9 +248,7 @@ export declare class MockCalmLensClient {
|
|
|
211
248
|
* description and tags, best match first. Mock scores are 1 for an exact match and 0.5
|
|
212
249
|
* otherwise; `mode` is accepted but there is no semantic search.
|
|
213
250
|
*/
|
|
214
|
-
search: (options:
|
|
215
|
-
query: string;
|
|
216
|
-
}) => Promise<AssetSearchResponse>;
|
|
251
|
+
search: (options: SearchAssetsOptions) => Promise<AssetSearchResponse>;
|
|
217
252
|
/** Lists assets with the real client's paging, `ordering`, `folderId` and `filter`. */
|
|
218
253
|
list: (options?: ListAssetsOptions) => Promise<AssetPage>;
|
|
219
254
|
iterate: (options?: IterateAssetsOptions) => AsyncGenerator<Asset, void, undefined>;
|
|
@@ -228,9 +263,15 @@ export declare class MockCalmLensClient {
|
|
|
228
263
|
createSignedUrl: (signedUrlOptions: CreateAssetSignedUrlOptions) => Promise<PostAssetSignedUrlResponse>;
|
|
229
264
|
move: (options: MoveAssetOptions) => Promise<Asset>;
|
|
230
265
|
retry: (options: RetryAssetOptions) => Promise<Asset>;
|
|
266
|
+
/** Waits like the real client, checking the mock's storage for a decision. */
|
|
267
|
+
waitForDecision: (options: WaitForAssetDecisionOptions) => Promise<Asset>;
|
|
231
268
|
deleteContent: (options: DeleteAssetContentOptions) => Promise<Asset>;
|
|
232
269
|
delete: (options: DeleteAssetOptions) => Promise<void>;
|
|
233
270
|
};
|
|
271
|
+
/** Signs real upload tokens with the mock's API key, like the real client, without a request. */
|
|
272
|
+
get uploadTokens(): {
|
|
273
|
+
sign: (options: SignUploadTokenOptions) => Promise<SignedUploadToken>;
|
|
274
|
+
};
|
|
234
275
|
get folders(): {
|
|
235
276
|
list: () => Promise<Folder[]>;
|
|
236
277
|
retrieve: (options: FolderIdOptions) => Promise<Folder>;
|
|
@@ -265,4 +306,4 @@ export declare const createWebhookHeaders: (options: {
|
|
|
265
306
|
timestampSeconds?: number;
|
|
266
307
|
}) => Promise<Record<string, string>>;
|
|
267
308
|
//#endregion
|
|
268
|
-
export type { MockCalmLensCall,
|
|
309
|
+
export type { MockCalmLensCall, MockCalmLensOperation, MockCalmLensOperationOptions, MockCalmLensServerClientOptions, MockDatabaseStorage, MockEventInput, MockImageStorage, MockRequestFailure, MockStoredContent };
|