@sanity-labs/client-fake-for-test 0.29.0 → 0.31.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
@@ -152,6 +152,13 @@ export declare interface CreateTestClientOptions {
152
152
  * without an entry has none and answers `[]`.
153
153
  */
154
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[];
155
162
  /**
156
163
  * Opt-in access-control simulation. When set, the client exposes
157
164
  * `request({ url })` that serves `/users/me` (host-aware), the
@@ -647,6 +654,15 @@ export declare interface MutationLogEntry {
647
654
  dataset: string;
648
655
  /** The resource the transaction targeted, on a `resource`-configured handle. */
649
656
  resource?: TestClientResource;
657
+ /**
658
+ * The organization store the transaction targeted, for a write over the
659
+ * Workflows store routes; `projectId` and `dataset` are then the calling
660
+ * handle's, not where the write landed.
661
+ */
662
+ organizationStore?: {
663
+ id: string;
664
+ organizationId: string;
665
+ };
650
666
  mutations: TxnMutation[];
651
667
  /** Request tag the commit carried, when one was passed (`null` = explicit suppression). */
652
668
  tag?: string | null;
@@ -953,6 +969,12 @@ export declare type ReleaseType = "asap" | "scheduled" | "undecided";
953
969
  declare interface RequestOptions {
954
970
  url?: string;
955
971
  uri?: string;
972
+ /** `GET` (the default) or `POST`; the fake serves `POST` on the Functions API's invoke route only. */
973
+ method?: "GET" | "POST";
974
+ /** The request body, sent as JSON. */
975
+ body?: unknown;
976
+ /** Request headers; names are case-insensitive. */
977
+ headers?: Record<string, string>;
956
978
  /** Query parameters, appended to the URL after the request tag; an array repeats its key. */
957
979
  query?: Record<string, string | string[]>;
958
980
  signal?: AbortSignal;
@@ -1313,6 +1335,27 @@ export declare interface TestClient {
1313
1335
  * store whose provisioning never completes stays `provisioning`.
1314
1336
  */
1315
1337
  completeOrganizationStoreProvisioning: (organizationId: string) => void;
1338
+ /**
1339
+ * The documents of the organization's store, the Workflows store, which
1340
+ * the Workflows store routes of {@link TestClient.request} read and write:
1341
+ * seed it, or read what a test wrote. Throws unless the organization has a
1342
+ * store (seed `organizationStores`, or look it up first). Seeding does not
1343
+ * change the store's status; the routes serve it once it is `active`.
1344
+ */
1345
+ organizationStore: (organizationId: string) => TestStore;
1346
+ /**
1347
+ * Deploy a function, or replace the one with its id, for every handle of
1348
+ * the family. Throws for an id shorter than 10 characters, an unknown
1349
+ * type, or a name another function holds in the same Blueprint stack.
1350
+ */
1351
+ addFunction: (fn: TestClientFunction) => void;
1352
+ /** Remove the function with this id from the family. Throws when no function has it. */
1353
+ removeFunction: (id: string) => void;
1354
+ /**
1355
+ * Every invocation the Functions API accepted on any handle of the
1356
+ * family, in order. Refused invocations are not recorded.
1357
+ */
1358
+ functionInvocations: () => TestFunctionInvocation[];
1316
1359
  /**
1317
1360
  * Every mutation committed through this client's registry, flattened
1318
1361
  * and in order — `create` / `createOrReplace` / `createIfNotExists` /
@@ -1375,6 +1418,31 @@ export declare interface TestClientAccessControl {
1375
1418
  robot?: true;
1376
1419
  }
1377
1420
 
1421
+ /** A deployed function: what the invoke route looks up by id, or by name within its stack. */
1422
+ export declare interface TestClientFunction {
1423
+ /** The function id, at least 10 characters. */
1424
+ id: string;
1425
+ /** The function's name in its Blueprint stack; unique within the stack. */
1426
+ name: string;
1427
+ type: TestClientFunctionType;
1428
+ /** The Blueprint stack the function was deployed in. */
1429
+ blueprintStackId: string;
1430
+ /** The type of the resource that owns the function. */
1431
+ resourceType: "project" | "organization";
1432
+ /** The id of the project or organization that owns the function. */
1433
+ resourceId: string;
1434
+ }
1435
+
1436
+ /** The function types the Functions API deploys (`src/constants.js`, `SANITY_FUNCTION_*`). */
1437
+ export declare type TestClientFunctionType =
1438
+ | "sanity.function.pubsub"
1439
+ | "sanity.function.document"
1440
+ | "sanity.function.queue"
1441
+ | "sanity.function.durable"
1442
+ | "sanity.function.schedule"
1443
+ | "sanity.function.media-library-asset"
1444
+ | "sanity.function.sync-tag-invalidate";
1445
+
1378
1446
  /**
1379
1447
  * One entry in the token→identity registry (`createTestClient({ identities })`).
1380
1448
  * A handle bound to the entry's token behaves exactly like one configured
@@ -1444,6 +1512,27 @@ export declare interface TestClientResource {
1444
1512
  id: string;
1445
1513
  }
1446
1514
 
1515
+ /** One invocation the Functions API accepted, as the function receives it. */
1516
+ export declare interface TestFunctionInvocation {
1517
+ functionId: string;
1518
+ name: string;
1519
+ blueprintStackId: string;
1520
+ /** The request's `X-Sanity-Scope-Type`. */
1521
+ scopeType: "project" | "organization";
1522
+ /** The request's `X-Sanity-Scope-Id`. */
1523
+ scopeId: string;
1524
+ /** Whether the invocation was synchronous; always `false`, as the fake serves asynchronous invocations only. */
1525
+ sync: boolean;
1526
+ /** The request body's `event`: the function receives `event.data`. */
1527
+ event: {
1528
+ data: Record<string, unknown>;
1529
+ };
1530
+ /** The caller's account-global user id. */
1531
+ invokedBy: {
1532
+ userId: string;
1533
+ };
1534
+ }
1535
+
1447
1536
  /**
1448
1537
  * In-memory document store backing a TestClient. Closure-scoped — created
1449
1538
  * fresh per test, no global state.
package/dist/index.d.ts CHANGED
@@ -152,6 +152,13 @@ export declare interface CreateTestClientOptions {
152
152
  * without an entry has none and answers `[]`.
153
153
  */
154
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[];
155
162
  /**
156
163
  * Opt-in access-control simulation. When set, the client exposes
157
164
  * `request({ url })` that serves `/users/me` (host-aware), the
@@ -647,6 +654,15 @@ export declare interface MutationLogEntry {
647
654
  dataset: string;
648
655
  /** The resource the transaction targeted, on a `resource`-configured handle. */
649
656
  resource?: TestClientResource;
657
+ /**
658
+ * The organization store the transaction targeted, for a write over the
659
+ * Workflows store routes; `projectId` and `dataset` are then the calling
660
+ * handle's, not where the write landed.
661
+ */
662
+ organizationStore?: {
663
+ id: string;
664
+ organizationId: string;
665
+ };
650
666
  mutations: TxnMutation[];
651
667
  /** Request tag the commit carried, when one was passed (`null` = explicit suppression). */
652
668
  tag?: string | null;
@@ -953,6 +969,12 @@ export declare type ReleaseType = "asap" | "scheduled" | "undecided";
953
969
  declare interface RequestOptions {
954
970
  url?: string;
955
971
  uri?: string;
972
+ /** `GET` (the default) or `POST`; the fake serves `POST` on the Functions API's invoke route only. */
973
+ method?: "GET" | "POST";
974
+ /** The request body, sent as JSON. */
975
+ body?: unknown;
976
+ /** Request headers; names are case-insensitive. */
977
+ headers?: Record<string, string>;
956
978
  /** Query parameters, appended to the URL after the request tag; an array repeats its key. */
957
979
  query?: Record<string, string | string[]>;
958
980
  signal?: AbortSignal;
@@ -1313,6 +1335,27 @@ export declare interface TestClient {
1313
1335
  * store whose provisioning never completes stays `provisioning`.
1314
1336
  */
1315
1337
  completeOrganizationStoreProvisioning: (organizationId: string) => void;
1338
+ /**
1339
+ * The documents of the organization's store, the Workflows store, which
1340
+ * the Workflows store routes of {@link TestClient.request} read and write:
1341
+ * seed it, or read what a test wrote. Throws unless the organization has a
1342
+ * store (seed `organizationStores`, or look it up first). Seeding does not
1343
+ * change the store's status; the routes serve it once it is `active`.
1344
+ */
1345
+ organizationStore: (organizationId: string) => TestStore;
1346
+ /**
1347
+ * Deploy a function, or replace the one with its id, for every handle of
1348
+ * the family. Throws for an id shorter than 10 characters, an unknown
1349
+ * type, or a name another function holds in the same Blueprint stack.
1350
+ */
1351
+ addFunction: (fn: TestClientFunction) => void;
1352
+ /** Remove the function with this id from the family. Throws when no function has it. */
1353
+ removeFunction: (id: string) => void;
1354
+ /**
1355
+ * Every invocation the Functions API accepted on any handle of the
1356
+ * family, in order. Refused invocations are not recorded.
1357
+ */
1358
+ functionInvocations: () => TestFunctionInvocation[];
1316
1359
  /**
1317
1360
  * Every mutation committed through this client's registry, flattened
1318
1361
  * and in order — `create` / `createOrReplace` / `createIfNotExists` /
@@ -1375,6 +1418,31 @@ export declare interface TestClientAccessControl {
1375
1418
  robot?: true;
1376
1419
  }
1377
1420
 
1421
+ /** A deployed function: what the invoke route looks up by id, or by name within its stack. */
1422
+ export declare interface TestClientFunction {
1423
+ /** The function id, at least 10 characters. */
1424
+ id: string;
1425
+ /** The function's name in its Blueprint stack; unique within the stack. */
1426
+ name: string;
1427
+ type: TestClientFunctionType;
1428
+ /** The Blueprint stack the function was deployed in. */
1429
+ blueprintStackId: string;
1430
+ /** The type of the resource that owns the function. */
1431
+ resourceType: "project" | "organization";
1432
+ /** The id of the project or organization that owns the function. */
1433
+ resourceId: string;
1434
+ }
1435
+
1436
+ /** The function types the Functions API deploys (`src/constants.js`, `SANITY_FUNCTION_*`). */
1437
+ export declare type TestClientFunctionType =
1438
+ | "sanity.function.pubsub"
1439
+ | "sanity.function.document"
1440
+ | "sanity.function.queue"
1441
+ | "sanity.function.durable"
1442
+ | "sanity.function.schedule"
1443
+ | "sanity.function.media-library-asset"
1444
+ | "sanity.function.sync-tag-invalidate";
1445
+
1378
1446
  /**
1379
1447
  * One entry in the token→identity registry (`createTestClient({ identities })`).
1380
1448
  * A handle bound to the entry's token behaves exactly like one configured
@@ -1444,6 +1512,27 @@ export declare interface TestClientResource {
1444
1512
  id: string;
1445
1513
  }
1446
1514
 
1515
+ /** One invocation the Functions API accepted, as the function receives it. */
1516
+ export declare interface TestFunctionInvocation {
1517
+ functionId: string;
1518
+ name: string;
1519
+ blueprintStackId: string;
1520
+ /** The request's `X-Sanity-Scope-Type`. */
1521
+ scopeType: "project" | "organization";
1522
+ /** The request's `X-Sanity-Scope-Id`. */
1523
+ scopeId: string;
1524
+ /** Whether the invocation was synchronous; always `false`, as the fake serves asynchronous invocations only. */
1525
+ sync: boolean;
1526
+ /** The request body's `event`: the function receives `event.data`. */
1527
+ event: {
1528
+ data: Record<string, unknown>;
1529
+ };
1530
+ /** The caller's account-global user id. */
1531
+ invokedBy: {
1532
+ userId: string;
1533
+ };
1534
+ }
1535
+
1447
1536
  /**
1448
1537
  * In-memory document store backing a TestClient. Closure-scoped — created
1449
1538
  * fresh per test, no global state.