@sanity-labs/client-fake-for-test 0.17.2 → 0.18.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/README.md +47 -2
- package/dist/index.cjs +157 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -39
- package/dist/index.d.ts +76 -39
- package/dist/index.js +153 -97
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ClientError } from "@sanity/client";
|
|
2
|
+
|
|
1
3
|
export declare type Action = ReleaseAction | VersionAction | DocumentAction;
|
|
2
4
|
|
|
3
5
|
/** Options for `action()`. Only `tag` is meaningful to the fake. */
|
|
@@ -449,25 +451,46 @@ export declare interface GuardConfig {
|
|
|
449
451
|
recorded?: Set<string>;
|
|
450
452
|
}
|
|
451
453
|
|
|
452
|
-
/**
|
|
453
|
-
export declare
|
|
454
|
-
|
|
454
|
+
/** The `guardDeniedError` gradient writes for a guard's denial (`proto.GuardDeniedError`). */
|
|
455
|
+
export declare interface GuardDeniedDetails {
|
|
456
|
+
description: string;
|
|
457
|
+
denials: MutationGuardDenial[];
|
|
458
|
+
type: "guardDeniedError";
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* The Content Lake's 403 when a mutation guard denies a write: a
|
|
463
|
+
* `ClientError` built from the response gradient sends, a
|
|
464
|
+
* `guardDeniedError` wrapped in a `mutationError`. `denials` and `type` lift
|
|
465
|
+
* the guard's answer to the top for callers that match on them.
|
|
466
|
+
*/
|
|
467
|
+
export declare class GuardDeniedError extends ClientError {
|
|
455
468
|
readonly type = "guardDeniedError";
|
|
456
469
|
readonly denials: MutationGuardDenial[];
|
|
457
|
-
readonly
|
|
470
|
+
readonly statusCode: 403;
|
|
458
471
|
readonly response: GuardDeniedResponse;
|
|
459
|
-
constructor(
|
|
472
|
+
constructor(
|
|
473
|
+
denials: readonly MutationGuardDenial[],
|
|
474
|
+
request?: PlatformRequest,
|
|
475
|
+
);
|
|
460
476
|
}
|
|
461
477
|
|
|
478
|
+
/** The `response` of a {@link GuardDeniedError}: the Content Lake's 403 for a guarded write. */
|
|
462
479
|
export declare interface GuardDeniedResponse {
|
|
463
480
|
body: {
|
|
464
481
|
error: {
|
|
465
|
-
|
|
466
|
-
|
|
482
|
+
description: string;
|
|
483
|
+
items: [
|
|
484
|
+
{
|
|
485
|
+
error: GuardDeniedDetails;
|
|
486
|
+
index: 0;
|
|
487
|
+
},
|
|
488
|
+
];
|
|
489
|
+
type: "mutationError";
|
|
467
490
|
};
|
|
468
491
|
};
|
|
469
492
|
url: string;
|
|
470
|
-
method:
|
|
493
|
+
method: string;
|
|
471
494
|
headers: Record<string, string>;
|
|
472
495
|
statusCode: 403;
|
|
473
496
|
statusMessage: "Forbidden";
|
|
@@ -692,34 +715,30 @@ export declare type Perspective =
|
|
|
692
715
|
| (string & {})
|
|
693
716
|
| string[];
|
|
694
717
|
|
|
695
|
-
/**
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
718
|
+
/**
|
|
719
|
+
* The platform's refusal, as the `ClientError` `@sanity/client` throws for
|
|
720
|
+
* the same response: the fake hands `ClientError` the response the client
|
|
721
|
+
* would have received, and `ClientError` derives `statusCode`, `message`,
|
|
722
|
+
* `responseBody` and `details` from it. So `instanceof ClientError` holds for
|
|
723
|
+
* the `@sanity/client` the consumer has installed.
|
|
724
|
+
*/
|
|
725
|
+
export declare class PlatformHttpError extends ClientError {
|
|
726
|
+
constructor(args: PlatformResponseArgs);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/** A request the platform answers. `path` is the API path, without host or API version. */
|
|
730
|
+
declare interface PlatformRequest {
|
|
731
|
+
method: "GET" | "POST";
|
|
732
|
+
path: string;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/** What the platform answered, and to which request. */
|
|
736
|
+
declare interface PlatformResponseArgs {
|
|
699
737
|
method: string;
|
|
700
|
-
|
|
738
|
+
path: string;
|
|
701
739
|
statusCode: number;
|
|
702
740
|
statusMessage: string;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* The platform's refusal, shaped like the `ClientError` `@sanity/client`
|
|
707
|
-
* throws for the same response: `statusCode`, `response`, `responseBody`,
|
|
708
|
-
* `details`, and a `message` derived from the body the way the client
|
|
709
|
-
* derives it.
|
|
710
|
-
*/
|
|
711
|
-
export declare class PlatformHttpError extends Error {
|
|
712
|
-
readonly statusCode: number;
|
|
713
|
-
readonly response: PlatformErrorResponse;
|
|
714
|
-
readonly responseBody: string;
|
|
715
|
-
readonly details: unknown;
|
|
716
|
-
constructor(args: {
|
|
717
|
-
method: string;
|
|
718
|
-
path: string;
|
|
719
|
-
statusCode: number;
|
|
720
|
-
statusMessage: string;
|
|
721
|
-
body: unknown;
|
|
722
|
-
});
|
|
741
|
+
body: unknown;
|
|
723
742
|
}
|
|
724
743
|
|
|
725
744
|
/** One row of the `/projects/<projectId>` members response. */
|
|
@@ -1056,7 +1075,11 @@ export declare interface TestClient {
|
|
|
1056
1075
|
* handle is bound to a registered identity.
|
|
1057
1076
|
*/
|
|
1058
1077
|
config: () => {
|
|
1059
|
-
|
|
1078
|
+
/**
|
|
1079
|
+
* Absent on a handle created global-hosted (`useProjectHostname: false`)
|
|
1080
|
+
* without a `projectId`, as in `@sanity/client`.
|
|
1081
|
+
*/
|
|
1082
|
+
projectId?: string;
|
|
1060
1083
|
dataset: string;
|
|
1061
1084
|
/** Present iff the handle is `resource`-configured. */
|
|
1062
1085
|
resource?: TestClientResource;
|
|
@@ -1170,6 +1193,15 @@ export declare interface TestClient {
|
|
|
1170
1193
|
addIdentity: (token: string, identity: TestClientIdentity) => void;
|
|
1171
1194
|
/** Snapshot of the registered token→identity entries. */
|
|
1172
1195
|
identities: () => Record<string, TestClientIdentity>;
|
|
1196
|
+
/**
|
|
1197
|
+
* Revoke a registered token, as when it expires or is deleted: it stays
|
|
1198
|
+
* registered and still binds, but from the next request on every Content
|
|
1199
|
+
* Lake and platform request made with it (on any handle) rejects with the
|
|
1200
|
+
* platform's 401 `Session not found`, and nothing is written. Revocation
|
|
1201
|
+
* is permanent for the family; `addIdentity` does not restore it. Unknown
|
|
1202
|
+
* tokens throw.
|
|
1203
|
+
*/
|
|
1204
|
+
revokeIdentity: (token: string) => void;
|
|
1173
1205
|
/**
|
|
1174
1206
|
* Every mutation committed through this client's registry, flattened
|
|
1175
1207
|
* and in order — `create` / `createOrReplace` / `createIfNotExists` /
|
|
@@ -1471,12 +1503,15 @@ export declare function wrapWithGuards<T extends object>(
|
|
|
1471
1503
|
): T;
|
|
1472
1504
|
|
|
1473
1505
|
/**
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1506
|
+
* The Content Lake's 403 when a configured-grants check rejects a write: a
|
|
1507
|
+
* `ClientError` built from the response gradient sends, an
|
|
1508
|
+
* `insufficientPermissionsError` wrapped in a `mutationError`
|
|
1509
|
+
* (`pkg/security/errors.go` `InsufficientPermissionsError`). It also carries
|
|
1510
|
+
* the doc id, the attempted permission, and the count of matching grants
|
|
1511
|
+
* (for parity with the engine's `permission-denied` disabled-reason), which
|
|
1512
|
+
* the platform's answer does not name.
|
|
1478
1513
|
*/
|
|
1479
|
-
export declare class WriteAccessDeniedError extends
|
|
1514
|
+
export declare class WriteAccessDeniedError extends ClientError {
|
|
1480
1515
|
readonly documentId: string;
|
|
1481
1516
|
readonly permission: DocumentValuePermission;
|
|
1482
1517
|
readonly matchingGrants: number;
|
|
@@ -1484,6 +1519,8 @@ export declare class WriteAccessDeniedError extends Error {
|
|
|
1484
1519
|
documentId: string;
|
|
1485
1520
|
permission: DocumentValuePermission;
|
|
1486
1521
|
matchingGrants: number;
|
|
1522
|
+
/** The write the Content Lake refused; defaults to a `/data/mutate` request. */
|
|
1523
|
+
request?: PlatformRequest;
|
|
1487
1524
|
});
|
|
1488
1525
|
}
|
|
1489
1526
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ClientError } from "@sanity/client";
|
|
2
|
+
|
|
1
3
|
export declare type Action = ReleaseAction | VersionAction | DocumentAction;
|
|
2
4
|
|
|
3
5
|
/** Options for `action()`. Only `tag` is meaningful to the fake. */
|
|
@@ -449,25 +451,46 @@ export declare interface GuardConfig {
|
|
|
449
451
|
recorded?: Set<string>;
|
|
450
452
|
}
|
|
451
453
|
|
|
452
|
-
/**
|
|
453
|
-
export declare
|
|
454
|
-
|
|
454
|
+
/** The `guardDeniedError` gradient writes for a guard's denial (`proto.GuardDeniedError`). */
|
|
455
|
+
export declare interface GuardDeniedDetails {
|
|
456
|
+
description: string;
|
|
457
|
+
denials: MutationGuardDenial[];
|
|
458
|
+
type: "guardDeniedError";
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* The Content Lake's 403 when a mutation guard denies a write: a
|
|
463
|
+
* `ClientError` built from the response gradient sends, a
|
|
464
|
+
* `guardDeniedError` wrapped in a `mutationError`. `denials` and `type` lift
|
|
465
|
+
* the guard's answer to the top for callers that match on them.
|
|
466
|
+
*/
|
|
467
|
+
export declare class GuardDeniedError extends ClientError {
|
|
455
468
|
readonly type = "guardDeniedError";
|
|
456
469
|
readonly denials: MutationGuardDenial[];
|
|
457
|
-
readonly
|
|
470
|
+
readonly statusCode: 403;
|
|
458
471
|
readonly response: GuardDeniedResponse;
|
|
459
|
-
constructor(
|
|
472
|
+
constructor(
|
|
473
|
+
denials: readonly MutationGuardDenial[],
|
|
474
|
+
request?: PlatformRequest,
|
|
475
|
+
);
|
|
460
476
|
}
|
|
461
477
|
|
|
478
|
+
/** The `response` of a {@link GuardDeniedError}: the Content Lake's 403 for a guarded write. */
|
|
462
479
|
export declare interface GuardDeniedResponse {
|
|
463
480
|
body: {
|
|
464
481
|
error: {
|
|
465
|
-
|
|
466
|
-
|
|
482
|
+
description: string;
|
|
483
|
+
items: [
|
|
484
|
+
{
|
|
485
|
+
error: GuardDeniedDetails;
|
|
486
|
+
index: 0;
|
|
487
|
+
},
|
|
488
|
+
];
|
|
489
|
+
type: "mutationError";
|
|
467
490
|
};
|
|
468
491
|
};
|
|
469
492
|
url: string;
|
|
470
|
-
method:
|
|
493
|
+
method: string;
|
|
471
494
|
headers: Record<string, string>;
|
|
472
495
|
statusCode: 403;
|
|
473
496
|
statusMessage: "Forbidden";
|
|
@@ -692,34 +715,30 @@ export declare type Perspective =
|
|
|
692
715
|
| (string & {})
|
|
693
716
|
| string[];
|
|
694
717
|
|
|
695
|
-
/**
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
718
|
+
/**
|
|
719
|
+
* The platform's refusal, as the `ClientError` `@sanity/client` throws for
|
|
720
|
+
* the same response: the fake hands `ClientError` the response the client
|
|
721
|
+
* would have received, and `ClientError` derives `statusCode`, `message`,
|
|
722
|
+
* `responseBody` and `details` from it. So `instanceof ClientError` holds for
|
|
723
|
+
* the `@sanity/client` the consumer has installed.
|
|
724
|
+
*/
|
|
725
|
+
export declare class PlatformHttpError extends ClientError {
|
|
726
|
+
constructor(args: PlatformResponseArgs);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/** A request the platform answers. `path` is the API path, without host or API version. */
|
|
730
|
+
declare interface PlatformRequest {
|
|
731
|
+
method: "GET" | "POST";
|
|
732
|
+
path: string;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/** What the platform answered, and to which request. */
|
|
736
|
+
declare interface PlatformResponseArgs {
|
|
699
737
|
method: string;
|
|
700
|
-
|
|
738
|
+
path: string;
|
|
701
739
|
statusCode: number;
|
|
702
740
|
statusMessage: string;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* The platform's refusal, shaped like the `ClientError` `@sanity/client`
|
|
707
|
-
* throws for the same response: `statusCode`, `response`, `responseBody`,
|
|
708
|
-
* `details`, and a `message` derived from the body the way the client
|
|
709
|
-
* derives it.
|
|
710
|
-
*/
|
|
711
|
-
export declare class PlatformHttpError extends Error {
|
|
712
|
-
readonly statusCode: number;
|
|
713
|
-
readonly response: PlatformErrorResponse;
|
|
714
|
-
readonly responseBody: string;
|
|
715
|
-
readonly details: unknown;
|
|
716
|
-
constructor(args: {
|
|
717
|
-
method: string;
|
|
718
|
-
path: string;
|
|
719
|
-
statusCode: number;
|
|
720
|
-
statusMessage: string;
|
|
721
|
-
body: unknown;
|
|
722
|
-
});
|
|
741
|
+
body: unknown;
|
|
723
742
|
}
|
|
724
743
|
|
|
725
744
|
/** One row of the `/projects/<projectId>` members response. */
|
|
@@ -1056,7 +1075,11 @@ export declare interface TestClient {
|
|
|
1056
1075
|
* handle is bound to a registered identity.
|
|
1057
1076
|
*/
|
|
1058
1077
|
config: () => {
|
|
1059
|
-
|
|
1078
|
+
/**
|
|
1079
|
+
* Absent on a handle created global-hosted (`useProjectHostname: false`)
|
|
1080
|
+
* without a `projectId`, as in `@sanity/client`.
|
|
1081
|
+
*/
|
|
1082
|
+
projectId?: string;
|
|
1060
1083
|
dataset: string;
|
|
1061
1084
|
/** Present iff the handle is `resource`-configured. */
|
|
1062
1085
|
resource?: TestClientResource;
|
|
@@ -1170,6 +1193,15 @@ export declare interface TestClient {
|
|
|
1170
1193
|
addIdentity: (token: string, identity: TestClientIdentity) => void;
|
|
1171
1194
|
/** Snapshot of the registered token→identity entries. */
|
|
1172
1195
|
identities: () => Record<string, TestClientIdentity>;
|
|
1196
|
+
/**
|
|
1197
|
+
* Revoke a registered token, as when it expires or is deleted: it stays
|
|
1198
|
+
* registered and still binds, but from the next request on every Content
|
|
1199
|
+
* Lake and platform request made with it (on any handle) rejects with the
|
|
1200
|
+
* platform's 401 `Session not found`, and nothing is written. Revocation
|
|
1201
|
+
* is permanent for the family; `addIdentity` does not restore it. Unknown
|
|
1202
|
+
* tokens throw.
|
|
1203
|
+
*/
|
|
1204
|
+
revokeIdentity: (token: string) => void;
|
|
1173
1205
|
/**
|
|
1174
1206
|
* Every mutation committed through this client's registry, flattened
|
|
1175
1207
|
* and in order — `create` / `createOrReplace` / `createIfNotExists` /
|
|
@@ -1471,12 +1503,15 @@ export declare function wrapWithGuards<T extends object>(
|
|
|
1471
1503
|
): T;
|
|
1472
1504
|
|
|
1473
1505
|
/**
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1506
|
+
* The Content Lake's 403 when a configured-grants check rejects a write: a
|
|
1507
|
+
* `ClientError` built from the response gradient sends, an
|
|
1508
|
+
* `insufficientPermissionsError` wrapped in a `mutationError`
|
|
1509
|
+
* (`pkg/security/errors.go` `InsufficientPermissionsError`). It also carries
|
|
1510
|
+
* the doc id, the attempted permission, and the count of matching grants
|
|
1511
|
+
* (for parity with the engine's `permission-denied` disabled-reason), which
|
|
1512
|
+
* the platform's answer does not name.
|
|
1478
1513
|
*/
|
|
1479
|
-
export declare class WriteAccessDeniedError extends
|
|
1514
|
+
export declare class WriteAccessDeniedError extends ClientError {
|
|
1480
1515
|
readonly documentId: string;
|
|
1481
1516
|
readonly permission: DocumentValuePermission;
|
|
1482
1517
|
readonly matchingGrants: number;
|
|
@@ -1484,6 +1519,8 @@ export declare class WriteAccessDeniedError extends Error {
|
|
|
1484
1519
|
documentId: string;
|
|
1485
1520
|
permission: DocumentValuePermission;
|
|
1486
1521
|
matchingGrants: number;
|
|
1522
|
+
/** The write the Content Lake refused; defaults to a `/data/mutate` request. */
|
|
1523
|
+
request?: PlatformRequest;
|
|
1487
1524
|
});
|
|
1488
1525
|
}
|
|
1489
1526
|
|