@sanity-labs/client-fake-for-test 0.28.0 → 0.30.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/dist/index.d.cts CHANGED
@@ -138,12 +138,27 @@ export declare interface CreateTestClientOptions {
138
138
  * `/projects/<projectId>` answer as `organizationId`.
139
139
  */
140
140
  organizationId?: string;
141
+ /**
142
+ * The organization stores that exist, by organization id, and their
143
+ * status: what `GET /internal/organization-stores?organizationId=<id>`
144
+ * answers. The lookup creates a `provisioning` store for an organization
145
+ * without one; {@link TestClient.completeOrganizationStoreProvisioning}
146
+ * sets it `active`. Each key must be `organizationId`.
147
+ */
148
+ organizationStores?: Record<string, OrganizationStoreStatus>;
141
149
  /**
142
150
  * The features each project has, keyed by projectId: what
143
151
  * `GET /projects/<projectId>/features` answers, sorted. A project
144
152
  * without an entry has none and answers `[]`.
145
153
  */
146
154
  projectFeatures?: Record<string, string[]>;
155
+ /**
156
+ * The functions deployed with the Functions API, which
157
+ * `request({ method: "POST", uri: "/functions/<idOrName>/invoke" })`
158
+ * invokes. Shared by the whole `withConfig` family; add and remove more
159
+ * with {@link TestClient.addFunction} and {@link TestClient.removeFunction}.
160
+ */
161
+ functions?: TestClientFunction[];
147
162
  /**
148
163
  * Opt-in access-control simulation. When set, the client exposes
149
164
  * `request({ url })` that serves `/users/me` (host-aware), the
@@ -678,6 +693,9 @@ export declare interface MutationOptions {
678
693
  tag?: string | null;
679
694
  }
680
695
 
696
+ /** The statuses populus serves a store in. */
697
+ declare type OrganizationStoreStatus = "provisioning" | "active";
698
+
681
699
  /** Options for `PatchHandle.commit()`. Only `tag` is meaningful to the fake. */
682
700
  export declare interface PatchCommitOptions {
683
701
  /** Request tag, recorded on the mutation log entry (`null` = explicit suppression). */
@@ -938,6 +956,22 @@ export declare type ReleaseState =
938
956
 
939
957
  export declare type ReleaseType = "asap" | "scheduled" | "undecided";
940
958
 
959
+ /** The options `client.request()` takes that the fake reads. */
960
+ declare interface RequestOptions {
961
+ url?: string;
962
+ uri?: string;
963
+ /** `GET` (the default) or `POST`; the fake serves `POST` on the Functions API's invoke route only. */
964
+ method?: "GET" | "POST";
965
+ /** The request body, sent as JSON. */
966
+ body?: unknown;
967
+ /** Request headers; names are case-insensitive. */
968
+ headers?: Record<string, string>;
969
+ /** Query parameters, appended to the URL after the request tag; an array repeats its key. */
970
+ query?: Record<string, string | string[]>;
971
+ signal?: AbortSignal;
972
+ tag?: string | null;
973
+ }
974
+
941
975
  /**
942
976
  * What the Access API (`/access/<type>/<id>/…`) answers about one actor on
943
977
  * one resource: the roles it holds there (served by `…/users` and collected
@@ -1053,12 +1087,7 @@ export declare interface TestClient {
1053
1087
  * actor. Also serves the resource's history, ACL, lookup and Access API
1054
1088
  * endpoints, or the platform's refusal where the resource has none.
1055
1089
  */
1056
- request?: <T>(opts: {
1057
- url?: string;
1058
- uri?: string;
1059
- signal?: AbortSignal;
1060
- tag?: string | null;
1061
- }) => Promise<T>;
1090
+ request?: <T>(opts: RequestOptions) => Promise<T>;
1062
1091
  /**
1063
1092
  * `@sanity/client`'s `getDataUrl(operation, path)`: `<resource
1064
1093
  * base>/<operation>/<path>` on a `resource`-configured handle,
@@ -1290,6 +1319,26 @@ export declare interface TestClient {
1290
1319
  * keeps answering. The outage lasts for the rest of the family's life.
1291
1320
  */
1292
1321
  simulateOutage: (component: PlatformComponent) => void;
1322
+ /**
1323
+ * Finish provisioning the organization's store, as populus's provisioning
1324
+ * workflow does in the background: from the next lookup on, the store is
1325
+ * `active`. Throws unless the organization has a `provisioning` store. A
1326
+ * store whose provisioning never completes stays `provisioning`.
1327
+ */
1328
+ completeOrganizationStoreProvisioning: (organizationId: string) => void;
1329
+ /**
1330
+ * Deploy a function, or replace the one with its id, for every handle of
1331
+ * the family. Throws for an id shorter than 10 characters, an unknown
1332
+ * type, or a name another function holds in the same Blueprint stack.
1333
+ */
1334
+ addFunction: (fn: TestClientFunction) => void;
1335
+ /** Remove the function with this id from the family. Throws when no function has it. */
1336
+ removeFunction: (id: string) => void;
1337
+ /**
1338
+ * Every invocation the Functions API accepted on any handle of the
1339
+ * family, in order. Refused invocations are not recorded.
1340
+ */
1341
+ functionInvocations: () => TestFunctionInvocation[];
1293
1342
  /**
1294
1343
  * Every mutation committed through this client's registry, flattened
1295
1344
  * and in order — `create` / `createOrReplace` / `createIfNotExists` /
@@ -1352,6 +1401,31 @@ export declare interface TestClientAccessControl {
1352
1401
  robot?: true;
1353
1402
  }
1354
1403
 
1404
+ /** A deployed function: what the invoke route looks up by id, or by name within its stack. */
1405
+ export declare interface TestClientFunction {
1406
+ /** The function id, at least 10 characters. */
1407
+ id: string;
1408
+ /** The function's name in its Blueprint stack; unique within the stack. */
1409
+ name: string;
1410
+ type: TestClientFunctionType;
1411
+ /** The Blueprint stack the function was deployed in. */
1412
+ blueprintStackId: string;
1413
+ /** The type of the resource that owns the function. */
1414
+ resourceType: "project" | "organization";
1415
+ /** The id of the project or organization that owns the function. */
1416
+ resourceId: string;
1417
+ }
1418
+
1419
+ /** The function types the Functions API deploys (`src/constants.js`, `SANITY_FUNCTION_*`). */
1420
+ export declare type TestClientFunctionType =
1421
+ | "sanity.function.pubsub"
1422
+ | "sanity.function.document"
1423
+ | "sanity.function.queue"
1424
+ | "sanity.function.durable"
1425
+ | "sanity.function.schedule"
1426
+ | "sanity.function.media-library-asset"
1427
+ | "sanity.function.sync-tag-invalidate";
1428
+
1355
1429
  /**
1356
1430
  * One entry in the token→identity registry (`createTestClient({ identities })`).
1357
1431
  * A handle bound to the entry's token behaves exactly like one configured
@@ -1421,6 +1495,27 @@ export declare interface TestClientResource {
1421
1495
  id: string;
1422
1496
  }
1423
1497
 
1498
+ /** One invocation the Functions API accepted, as the function receives it. */
1499
+ export declare interface TestFunctionInvocation {
1500
+ functionId: string;
1501
+ name: string;
1502
+ blueprintStackId: string;
1503
+ /** The request's `X-Sanity-Scope-Type`. */
1504
+ scopeType: "project" | "organization";
1505
+ /** The request's `X-Sanity-Scope-Id`. */
1506
+ scopeId: string;
1507
+ /** Whether the invocation was synchronous; always `false`, as the fake serves asynchronous invocations only. */
1508
+ sync: boolean;
1509
+ /** The request body's `event`: the function receives `event.data`. */
1510
+ event: {
1511
+ data: Record<string, unknown>;
1512
+ };
1513
+ /** The caller's account-global user id. */
1514
+ invokedBy: {
1515
+ userId: string;
1516
+ };
1517
+ }
1518
+
1424
1519
  /**
1425
1520
  * In-memory document store backing a TestClient. Closure-scoped — created
1426
1521
  * fresh per test, no global state.
package/dist/index.d.ts CHANGED
@@ -138,12 +138,27 @@ export declare interface CreateTestClientOptions {
138
138
  * `/projects/<projectId>` answer as `organizationId`.
139
139
  */
140
140
  organizationId?: string;
141
+ /**
142
+ * The organization stores that exist, by organization id, and their
143
+ * status: what `GET /internal/organization-stores?organizationId=<id>`
144
+ * answers. The lookup creates a `provisioning` store for an organization
145
+ * without one; {@link TestClient.completeOrganizationStoreProvisioning}
146
+ * sets it `active`. Each key must be `organizationId`.
147
+ */
148
+ organizationStores?: Record<string, OrganizationStoreStatus>;
141
149
  /**
142
150
  * The features each project has, keyed by projectId: what
143
151
  * `GET /projects/<projectId>/features` answers, sorted. A project
144
152
  * without an entry has none and answers `[]`.
145
153
  */
146
154
  projectFeatures?: Record<string, string[]>;
155
+ /**
156
+ * The functions deployed with the Functions API, which
157
+ * `request({ method: "POST", uri: "/functions/<idOrName>/invoke" })`
158
+ * invokes. Shared by the whole `withConfig` family; add and remove more
159
+ * with {@link TestClient.addFunction} and {@link TestClient.removeFunction}.
160
+ */
161
+ functions?: TestClientFunction[];
147
162
  /**
148
163
  * Opt-in access-control simulation. When set, the client exposes
149
164
  * `request({ url })` that serves `/users/me` (host-aware), the
@@ -678,6 +693,9 @@ export declare interface MutationOptions {
678
693
  tag?: string | null;
679
694
  }
680
695
 
696
+ /** The statuses populus serves a store in. */
697
+ declare type OrganizationStoreStatus = "provisioning" | "active";
698
+
681
699
  /** Options for `PatchHandle.commit()`. Only `tag` is meaningful to the fake. */
682
700
  export declare interface PatchCommitOptions {
683
701
  /** Request tag, recorded on the mutation log entry (`null` = explicit suppression). */
@@ -938,6 +956,22 @@ export declare type ReleaseState =
938
956
 
939
957
  export declare type ReleaseType = "asap" | "scheduled" | "undecided";
940
958
 
959
+ /** The options `client.request()` takes that the fake reads. */
960
+ declare interface RequestOptions {
961
+ url?: string;
962
+ uri?: string;
963
+ /** `GET` (the default) or `POST`; the fake serves `POST` on the Functions API's invoke route only. */
964
+ method?: "GET" | "POST";
965
+ /** The request body, sent as JSON. */
966
+ body?: unknown;
967
+ /** Request headers; names are case-insensitive. */
968
+ headers?: Record<string, string>;
969
+ /** Query parameters, appended to the URL after the request tag; an array repeats its key. */
970
+ query?: Record<string, string | string[]>;
971
+ signal?: AbortSignal;
972
+ tag?: string | null;
973
+ }
974
+
941
975
  /**
942
976
  * What the Access API (`/access/<type>/<id>/…`) answers about one actor on
943
977
  * one resource: the roles it holds there (served by `…/users` and collected
@@ -1053,12 +1087,7 @@ export declare interface TestClient {
1053
1087
  * actor. Also serves the resource's history, ACL, lookup and Access API
1054
1088
  * endpoints, or the platform's refusal where the resource has none.
1055
1089
  */
1056
- request?: <T>(opts: {
1057
- url?: string;
1058
- uri?: string;
1059
- signal?: AbortSignal;
1060
- tag?: string | null;
1061
- }) => Promise<T>;
1090
+ request?: <T>(opts: RequestOptions) => Promise<T>;
1062
1091
  /**
1063
1092
  * `@sanity/client`'s `getDataUrl(operation, path)`: `<resource
1064
1093
  * base>/<operation>/<path>` on a `resource`-configured handle,
@@ -1290,6 +1319,26 @@ export declare interface TestClient {
1290
1319
  * keeps answering. The outage lasts for the rest of the family's life.
1291
1320
  */
1292
1321
  simulateOutage: (component: PlatformComponent) => void;
1322
+ /**
1323
+ * Finish provisioning the organization's store, as populus's provisioning
1324
+ * workflow does in the background: from the next lookup on, the store is
1325
+ * `active`. Throws unless the organization has a `provisioning` store. A
1326
+ * store whose provisioning never completes stays `provisioning`.
1327
+ */
1328
+ completeOrganizationStoreProvisioning: (organizationId: string) => void;
1329
+ /**
1330
+ * Deploy a function, or replace the one with its id, for every handle of
1331
+ * the family. Throws for an id shorter than 10 characters, an unknown
1332
+ * type, or a name another function holds in the same Blueprint stack.
1333
+ */
1334
+ addFunction: (fn: TestClientFunction) => void;
1335
+ /** Remove the function with this id from the family. Throws when no function has it. */
1336
+ removeFunction: (id: string) => void;
1337
+ /**
1338
+ * Every invocation the Functions API accepted on any handle of the
1339
+ * family, in order. Refused invocations are not recorded.
1340
+ */
1341
+ functionInvocations: () => TestFunctionInvocation[];
1293
1342
  /**
1294
1343
  * Every mutation committed through this client's registry, flattened
1295
1344
  * and in order — `create` / `createOrReplace` / `createIfNotExists` /
@@ -1352,6 +1401,31 @@ export declare interface TestClientAccessControl {
1352
1401
  robot?: true;
1353
1402
  }
1354
1403
 
1404
+ /** A deployed function: what the invoke route looks up by id, or by name within its stack. */
1405
+ export declare interface TestClientFunction {
1406
+ /** The function id, at least 10 characters. */
1407
+ id: string;
1408
+ /** The function's name in its Blueprint stack; unique within the stack. */
1409
+ name: string;
1410
+ type: TestClientFunctionType;
1411
+ /** The Blueprint stack the function was deployed in. */
1412
+ blueprintStackId: string;
1413
+ /** The type of the resource that owns the function. */
1414
+ resourceType: "project" | "organization";
1415
+ /** The id of the project or organization that owns the function. */
1416
+ resourceId: string;
1417
+ }
1418
+
1419
+ /** The function types the Functions API deploys (`src/constants.js`, `SANITY_FUNCTION_*`). */
1420
+ export declare type TestClientFunctionType =
1421
+ | "sanity.function.pubsub"
1422
+ | "sanity.function.document"
1423
+ | "sanity.function.queue"
1424
+ | "sanity.function.durable"
1425
+ | "sanity.function.schedule"
1426
+ | "sanity.function.media-library-asset"
1427
+ | "sanity.function.sync-tag-invalidate";
1428
+
1355
1429
  /**
1356
1430
  * One entry in the token→identity registry (`createTestClient({ identities })`).
1357
1431
  * A handle bound to the entry's token behaves exactly like one configured
@@ -1421,6 +1495,27 @@ export declare interface TestClientResource {
1421
1495
  id: string;
1422
1496
  }
1423
1497
 
1498
+ /** One invocation the Functions API accepted, as the function receives it. */
1499
+ export declare interface TestFunctionInvocation {
1500
+ functionId: string;
1501
+ name: string;
1502
+ blueprintStackId: string;
1503
+ /** The request's `X-Sanity-Scope-Type`. */
1504
+ scopeType: "project" | "organization";
1505
+ /** The request's `X-Sanity-Scope-Id`. */
1506
+ scopeId: string;
1507
+ /** Whether the invocation was synchronous; always `false`, as the fake serves asynchronous invocations only. */
1508
+ sync: boolean;
1509
+ /** The request body's `event`: the function receives `event.data`. */
1510
+ event: {
1511
+ data: Record<string, unknown>;
1512
+ };
1513
+ /** The caller's account-global user id. */
1514
+ invokedBy: {
1515
+ userId: string;
1516
+ };
1517
+ }
1518
+
1424
1519
  /**
1425
1520
  * In-memory document store backing a TestClient. Closure-scoped — created
1426
1521
  * fresh per test, no global state.