@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/cjs/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as TypedEvent, A as ListEventsOptions, B as UpdateAssetOptions, E as Lens, H as UploadAssetPartOptions, J as GetEventsResponse, K as AssetSearchQuery, L as RetrieveAssetOptions, M as MoveAssetOptions, N as MoveFolderOptions, O as ListAssetChildrenOptions, Q as Event, R as RetryAssetOptions, T as IterateAssetsOptions, V as UpdateFolderOptions, X as AssetBinaryPayloadInput, Y as PostAssetSignedUrlResponse, Z as Folder, _ as DeleteAssetContentOptions, a as AssetSearchResponse, b as EnsureLensesOptions, d as CdnAssetUrlOptions, f as CdnServeOptions, h as CreateFolderOptions, i as AssetPage, j as ModerateTextOptions, k as ListAssetsOptions, m as CreateAssetSignedUrlOptions, n as AssetChildrenPage, ot as ClassificationCategory, q as WebhookEventPayload, s as AssetStatus, t as Asset, u as CalmLensClientOptions, v as DeleteAssetOptions, w as IterateAssetChildrenOptions, x as FolderIdOptions, y as EnsureLensOptions, z as SubmitAssetOptions } from "./CalmLensTypes-BZ-nxhr_.js";
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/MockCalmLensClient.d.ts
106
- interface MockCalmLensClientOptions extends CalmLensClientOptions {
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
- /** A `MockCalmLensClient` method, named like its path on the client. */
120
- type MockCalmLensOperation = "assets.list" | "assets.search" | "assets.retrieve" | "assets.update" | "assets.listChildren" | "assets.create" | "assets.moderate" | "assets.uploadPart" | "assets.createSignedUrl" | "assets.move" | "assets.retry" | "assets.deleteContent" | "assets.delete" | "text.moderate" | "cdn.serve" | "events.list" | "folders.list" | "folders.retrieve" | "folders.create" | "folders.update" | "folders.delete" | "folders.move" | "ensureLens" | "ensureLenses";
121
- /** One recorded call: the method and the options object it was given, exactly as passed. */
122
- interface MockCalmLensCall {
123
- operation: MockCalmLensOperation;
124
- options: unknown;
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 `CalmLensClient` with the same methods, validation and error
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 MockCalmLensClient {
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 `CalmLensClient` (validated the same way), plus `mockOptions`. */
162
- constructor(options: MockCalmLensClientOptions);
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: MockCalmLensOperation): MockCalmLensCall[];
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: Partial<AssetSearchQuery> & {
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, MockCalmLensClientOptions, MockCalmLensOperation, MockDatabaseStorage, MockEventInput, MockImageStorage, MockRequestFailure, MockStoredContent };
309
+ export type { MockCalmLensCall, MockCalmLensOperation, MockCalmLensOperationOptions, MockCalmLensServerClientOptions, MockDatabaseStorage, MockEventInput, MockImageStorage, MockRequestFailure, MockStoredContent };