@sanity-labs/client-fake-for-test 0.17.3 → 0.19.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 +43 -6
- package/dist/index.cjs +175 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -40
- package/dist/index.d.ts +72 -40
- package/dist/index.js +171 -91
- 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. */
|
|
@@ -1282,10 +1301,18 @@ export declare interface TestClientIdentity {
|
|
|
1282
1301
|
* Access API entries, keyed `"<access type>:<id>"` (`"organization:<id>"`,
|
|
1283
1302
|
* `"media-library:<id>"`, `"canvas:<id>"`, `"dashboard:<id>"`,
|
|
1284
1303
|
* `"project:<projectId>"`). On a non-project resource, an entry with
|
|
1285
|
-
* `roles` makes the identity a member there. Project membership needs no
|
|
1286
|
-
*
|
|
1304
|
+
* `roles` makes the identity a member there. Project membership needs no
|
|
1305
|
+
* entry: see `projectId`.
|
|
1287
1306
|
*/
|
|
1288
1307
|
access?: Record<string, ResourceAccess>;
|
|
1308
|
+
/**
|
|
1309
|
+
* The project a project-scoped token belongs to, as a robot token belongs
|
|
1310
|
+
* to the project that issued it. The identity is a member of that project
|
|
1311
|
+
* only, and its token is refused on any other project's API host. Omit
|
|
1312
|
+
* for a token the fake treats as a member of every project, accepted on
|
|
1313
|
+
* every host.
|
|
1314
|
+
*/
|
|
1315
|
+
projectId?: string;
|
|
1289
1316
|
}
|
|
1290
1317
|
|
|
1291
1318
|
/**
|
|
@@ -1484,12 +1511,15 @@ export declare function wrapWithGuards<T extends object>(
|
|
|
1484
1511
|
): T;
|
|
1485
1512
|
|
|
1486
1513
|
/**
|
|
1487
|
-
*
|
|
1488
|
-
*
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1514
|
+
* The Content Lake's 403 when a configured-grants check rejects a write: a
|
|
1515
|
+
* `ClientError` built from the response gradient sends, an
|
|
1516
|
+
* `insufficientPermissionsError` wrapped in a `mutationError`
|
|
1517
|
+
* (`pkg/security/errors.go` `InsufficientPermissionsError`). It also carries
|
|
1518
|
+
* the doc id, the attempted permission, and the count of matching grants
|
|
1519
|
+
* (for parity with the engine's `permission-denied` disabled-reason), which
|
|
1520
|
+
* the platform's answer does not name.
|
|
1491
1521
|
*/
|
|
1492
|
-
export declare class WriteAccessDeniedError extends
|
|
1522
|
+
export declare class WriteAccessDeniedError extends ClientError {
|
|
1493
1523
|
readonly documentId: string;
|
|
1494
1524
|
readonly permission: DocumentValuePermission;
|
|
1495
1525
|
readonly matchingGrants: number;
|
|
@@ -1497,6 +1527,8 @@ export declare class WriteAccessDeniedError extends Error {
|
|
|
1497
1527
|
documentId: string;
|
|
1498
1528
|
permission: DocumentValuePermission;
|
|
1499
1529
|
matchingGrants: number;
|
|
1530
|
+
/** The write the Content Lake refused; defaults to a `/data/mutate` request. */
|
|
1531
|
+
request?: PlatformRequest;
|
|
1500
1532
|
});
|
|
1501
1533
|
}
|
|
1502
1534
|
|
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. */
|
|
@@ -1282,10 +1301,18 @@ export declare interface TestClientIdentity {
|
|
|
1282
1301
|
* Access API entries, keyed `"<access type>:<id>"` (`"organization:<id>"`,
|
|
1283
1302
|
* `"media-library:<id>"`, `"canvas:<id>"`, `"dashboard:<id>"`,
|
|
1284
1303
|
* `"project:<projectId>"`). On a non-project resource, an entry with
|
|
1285
|
-
* `roles` makes the identity a member there. Project membership needs no
|
|
1286
|
-
*
|
|
1304
|
+
* `roles` makes the identity a member there. Project membership needs no
|
|
1305
|
+
* entry: see `projectId`.
|
|
1287
1306
|
*/
|
|
1288
1307
|
access?: Record<string, ResourceAccess>;
|
|
1308
|
+
/**
|
|
1309
|
+
* The project a project-scoped token belongs to, as a robot token belongs
|
|
1310
|
+
* to the project that issued it. The identity is a member of that project
|
|
1311
|
+
* only, and its token is refused on any other project's API host. Omit
|
|
1312
|
+
* for a token the fake treats as a member of every project, accepted on
|
|
1313
|
+
* every host.
|
|
1314
|
+
*/
|
|
1315
|
+
projectId?: string;
|
|
1289
1316
|
}
|
|
1290
1317
|
|
|
1291
1318
|
/**
|
|
@@ -1484,12 +1511,15 @@ export declare function wrapWithGuards<T extends object>(
|
|
|
1484
1511
|
): T;
|
|
1485
1512
|
|
|
1486
1513
|
/**
|
|
1487
|
-
*
|
|
1488
|
-
*
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1514
|
+
* The Content Lake's 403 when a configured-grants check rejects a write: a
|
|
1515
|
+
* `ClientError` built from the response gradient sends, an
|
|
1516
|
+
* `insufficientPermissionsError` wrapped in a `mutationError`
|
|
1517
|
+
* (`pkg/security/errors.go` `InsufficientPermissionsError`). It also carries
|
|
1518
|
+
* the doc id, the attempted permission, and the count of matching grants
|
|
1519
|
+
* (for parity with the engine's `permission-denied` disabled-reason), which
|
|
1520
|
+
* the platform's answer does not name.
|
|
1491
1521
|
*/
|
|
1492
|
-
export declare class WriteAccessDeniedError extends
|
|
1522
|
+
export declare class WriteAccessDeniedError extends ClientError {
|
|
1493
1523
|
readonly documentId: string;
|
|
1494
1524
|
readonly permission: DocumentValuePermission;
|
|
1495
1525
|
readonly matchingGrants: number;
|
|
@@ -1497,6 +1527,8 @@ export declare class WriteAccessDeniedError extends Error {
|
|
|
1497
1527
|
documentId: string;
|
|
1498
1528
|
permission: DocumentValuePermission;
|
|
1499
1529
|
matchingGrants: number;
|
|
1530
|
+
/** The write the Content Lake refused; defaults to a `/data/mutate` request. */
|
|
1531
|
+
request?: PlatformRequest;
|
|
1500
1532
|
});
|
|
1501
1533
|
}
|
|
1502
1534
|
|