@sanity-labs/client-fake-for-test 0.31.0 → 0.33.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
@@ -557,6 +557,18 @@ export declare interface GuardDeniedResponse {
557
557
  statusMessage: "Forbidden";
558
558
  }
559
559
 
560
+ /** What `@sanity/client` hands a `requestHandler`, as far as the fake reads it. */
561
+ declare interface HandledRequestOptions {
562
+ url?: string | undefined;
563
+ method?: string | undefined;
564
+ headers?: [string, string][] | Record<string, string> | Headers | undefined;
565
+ body?: unknown;
566
+ query?:
567
+ | URLSearchParams
568
+ | Record<string, string | number | boolean | undefined>
569
+ | undefined;
570
+ }
571
+
560
572
  /** An event as `GET <data base>/history/events/documents/<ids>` serves it. */
561
573
  export declare interface HistoryEvent {
562
574
  type: "createLiveDocument" | "updateLiveDocument";
@@ -702,6 +714,14 @@ export declare interface MutationOptions {
702
714
  tag?: string | null;
703
715
  }
704
716
 
717
+ /**
718
+ * A store id in populus's format, `os` and ten characters
719
+ * (`organizationStoreService.ts:47-51`), without a segment populus disallows
720
+ * (`src/util/createUniqueId.js:39-41`). Derived from the organization so a
721
+ * test can name it before the lookup.
722
+ */
723
+ export declare function organizationStoreId(organizationId: string): string;
724
+
705
725
  /** The statuses populus serves a store in. */
706
726
  declare type OrganizationStoreStatus = "provisioning" | "active";
707
727
 
@@ -1343,6 +1363,48 @@ export declare interface TestClient {
1343
1363
  * change the store's status; the routes serve it once it is `active`.
1344
1364
  */
1345
1365
  organizationStore: (organizationId: string) => TestStore;
1366
+ /**
1367
+ * A `requestHandler` for a real `@sanity/client`, so code that builds its
1368
+ * own client runs against this fake: `createClient({ ...config,
1369
+ * requestHandler: fake.requestHandler() })`. Each request is answered as
1370
+ * {@link TestClient.request} answers it on a sibling bound to the
1371
+ * request's bearer token, API host and API version, and resolves to the
1372
+ * response body. Requests the fake's `request()` does not serve throw its
1373
+ * fake error, as `request()` does; route data API calls through the fake's
1374
+ * own methods instead.
1375
+ */
1376
+ requestHandler: () => (options: HandledRequestOptions) => Promise<unknown>;
1377
+ /**
1378
+ * A `resolveFetch` for a real `@sanity/client`, or a `fetch` for any
1379
+ * code that opens a server-sent event stream itself: `createClient({
1380
+ * ...config, resolveFetch: fake.resolveFetch() })`. It answers the
1381
+ * Workflows store read route's `listen`, as the stream gradient sends
1382
+ * (see [Workflows store](#workflows-store) in the README), and throws a
1383
+ * fake error for any other URL.
1384
+ */
1385
+ resolveFetch: () => () => (
1386
+ input: string | URL,
1387
+ init?: RequestInit,
1388
+ ) => Promise<Response>;
1389
+ /**
1390
+ * End every open listener on `organizationId`'s Workflows store with
1391
+ * gradient's fatal error: a `channelError` event carrying `error`, then a
1392
+ * `disconnect` with reason `error`. `@sanity/client` raises the
1393
+ * `channelError`'s `description`.
1394
+ */
1395
+ failListeners: (
1396
+ organizationId: string,
1397
+ error: {
1398
+ type: string;
1399
+ description: string;
1400
+ },
1401
+ ) => void;
1402
+ /**
1403
+ * End every open listener on `organizationId`'s Workflows store without an
1404
+ * event, as gradient ends one on shutdown or at its lifetime, so the client
1405
+ * reconnects.
1406
+ */
1407
+ dropListeners: (organizationId: string) => void;
1346
1408
  /**
1347
1409
  * Deploy a function, or replace the one with its id, for every handle of
1348
1410
  * the family. Throws for an id shorter than 10 characters, an unknown
@@ -1500,6 +1562,14 @@ export declare interface TestClientIdentity {
1500
1562
  * `…/robots/<id>` instead of `…/users`, and it is never a user row.
1501
1563
  */
1502
1564
  robot?: true;
1565
+ /**
1566
+ * The organization an organization-scoped token is limited to. The
1567
+ * Content Lake refuses it on another organization's store with 403
1568
+ * `permissionDeniedError`, `Unauthorized organization access` (gradient
1569
+ * `pkg/system/session.go:71-94`). Omit for a token with no organization
1570
+ * scope.
1571
+ */
1572
+ organizationScope?: string;
1503
1573
  }
1504
1574
 
1505
1575
  /**
package/dist/index.d.ts CHANGED
@@ -557,6 +557,18 @@ export declare interface GuardDeniedResponse {
557
557
  statusMessage: "Forbidden";
558
558
  }
559
559
 
560
+ /** What `@sanity/client` hands a `requestHandler`, as far as the fake reads it. */
561
+ declare interface HandledRequestOptions {
562
+ url?: string | undefined;
563
+ method?: string | undefined;
564
+ headers?: [string, string][] | Record<string, string> | Headers | undefined;
565
+ body?: unknown;
566
+ query?:
567
+ | URLSearchParams
568
+ | Record<string, string | number | boolean | undefined>
569
+ | undefined;
570
+ }
571
+
560
572
  /** An event as `GET <data base>/history/events/documents/<ids>` serves it. */
561
573
  export declare interface HistoryEvent {
562
574
  type: "createLiveDocument" | "updateLiveDocument";
@@ -702,6 +714,14 @@ export declare interface MutationOptions {
702
714
  tag?: string | null;
703
715
  }
704
716
 
717
+ /**
718
+ * A store id in populus's format, `os` and ten characters
719
+ * (`organizationStoreService.ts:47-51`), without a segment populus disallows
720
+ * (`src/util/createUniqueId.js:39-41`). Derived from the organization so a
721
+ * test can name it before the lookup.
722
+ */
723
+ export declare function organizationStoreId(organizationId: string): string;
724
+
705
725
  /** The statuses populus serves a store in. */
706
726
  declare type OrganizationStoreStatus = "provisioning" | "active";
707
727
 
@@ -1343,6 +1363,48 @@ export declare interface TestClient {
1343
1363
  * change the store's status; the routes serve it once it is `active`.
1344
1364
  */
1345
1365
  organizationStore: (organizationId: string) => TestStore;
1366
+ /**
1367
+ * A `requestHandler` for a real `@sanity/client`, so code that builds its
1368
+ * own client runs against this fake: `createClient({ ...config,
1369
+ * requestHandler: fake.requestHandler() })`. Each request is answered as
1370
+ * {@link TestClient.request} answers it on a sibling bound to the
1371
+ * request's bearer token, API host and API version, and resolves to the
1372
+ * response body. Requests the fake's `request()` does not serve throw its
1373
+ * fake error, as `request()` does; route data API calls through the fake's
1374
+ * own methods instead.
1375
+ */
1376
+ requestHandler: () => (options: HandledRequestOptions) => Promise<unknown>;
1377
+ /**
1378
+ * A `resolveFetch` for a real `@sanity/client`, or a `fetch` for any
1379
+ * code that opens a server-sent event stream itself: `createClient({
1380
+ * ...config, resolveFetch: fake.resolveFetch() })`. It answers the
1381
+ * Workflows store read route's `listen`, as the stream gradient sends
1382
+ * (see [Workflows store](#workflows-store) in the README), and throws a
1383
+ * fake error for any other URL.
1384
+ */
1385
+ resolveFetch: () => () => (
1386
+ input: string | URL,
1387
+ init?: RequestInit,
1388
+ ) => Promise<Response>;
1389
+ /**
1390
+ * End every open listener on `organizationId`'s Workflows store with
1391
+ * gradient's fatal error: a `channelError` event carrying `error`, then a
1392
+ * `disconnect` with reason `error`. `@sanity/client` raises the
1393
+ * `channelError`'s `description`.
1394
+ */
1395
+ failListeners: (
1396
+ organizationId: string,
1397
+ error: {
1398
+ type: string;
1399
+ description: string;
1400
+ },
1401
+ ) => void;
1402
+ /**
1403
+ * End every open listener on `organizationId`'s Workflows store without an
1404
+ * event, as gradient ends one on shutdown or at its lifetime, so the client
1405
+ * reconnects.
1406
+ */
1407
+ dropListeners: (organizationId: string) => void;
1346
1408
  /**
1347
1409
  * Deploy a function, or replace the one with its id, for every handle of
1348
1410
  * the family. Throws for an id shorter than 10 characters, an unknown
@@ -1500,6 +1562,14 @@ export declare interface TestClientIdentity {
1500
1562
  * `…/robots/<id>` instead of `…/users`, and it is never a user row.
1501
1563
  */
1502
1564
  robot?: true;
1565
+ /**
1566
+ * The organization an organization-scoped token is limited to. The
1567
+ * Content Lake refuses it on another organization's store with 403
1568
+ * `permissionDeniedError`, `Unauthorized organization access` (gradient
1569
+ * `pkg/system/session.go:71-94`). Omit for a token with no organization
1570
+ * scope.
1571
+ */
1572
+ organizationScope?: string;
1503
1573
  }
1504
1574
 
1505
1575
  /**