@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/cjs/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ModerateTextOptions, B as UpdateFolderOptions, C as IterateAssetChildrenOptions, D as ListAssetChildrenOptions, G as AssetSearchQuery, I as RetrieveAssetOptions, J as PostAssetSignedUrlResponse, K as WebhookEventPayload, L as RetryAssetOptions, M as MoveFolderOptions, O as ListAssetsOptions, Q as TypedEvent, R as SubmitAssetOptions, T as Lens, V as UploadAssetPartOptions, X as Folder, Y as AssetBinaryPayloadInput, Z as Event, _ as DeleteAssetOptions, a as AssetSearchResponse, at as ClassificationCategory, b as FolderIdOptions, d as CdnAssetUrlOptions, f as CdnServeOptions, g as DeleteAssetContentOptions, i as AssetPage, j as MoveAssetOptions, k as ListEventsOptions, m as CreateFolderOptions, n as AssetChildrenPage, p as CreateAssetSignedUrlOptions, q as GetEventsResponse, s as AssetStatus, t as Asset, u as CalmLensClientOptions, v as EnsureLensOptions, w as IterateAssetsOptions, y as EnsureLensesOptions, z as UpdateAssetOptions } from "./CalmLensTypes-DjYFaTyh.js";
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/MockCalmLensClient.d.ts
106
- interface MockCalmLensClientOptions extends CalmLensClientOptions {
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
- /** 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;
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 `CalmLensClient` with the same methods, validation and error
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 MockCalmLensClient {
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 `CalmLensClient` (validated the same way), plus `mockOptions`. */
162
- constructor(options: MockCalmLensClientOptions);
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: MockCalmLensOperation): MockCalmLensCall[];
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: Partial<AssetSearchQuery> & {
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, MockCalmLensClientOptions, MockCalmLensOperation, MockDatabaseStorage, MockEventInput, MockImageStorage, MockRequestFailure, MockStoredContent };
304
+ export type { MockCalmLensCall, MockCalmLensOperation, MockCalmLensOperationOptions, MockCalmLensServerClientOptions, MockDatabaseStorage, MockEventInput, MockImageStorage, MockRequestFailure, MockStoredContent };