@sanity-labs/client-fake-for-test 0.9.1 → 0.10.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 +1 -1
- package/dist/index.cjs +20 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -108,7 +108,8 @@ export declare interface CreateTestClientOptions {
|
|
|
108
108
|
/**
|
|
109
109
|
* Opt-in access-control simulation. When set, the client exposes
|
|
110
110
|
* `request({ url })` that serves `/users/me` (host-aware), the
|
|
111
|
-
* configured ACL path,
|
|
111
|
+
* configured ACL path, `/projects/<projectId>` (members), and
|
|
112
|
+
* `/projects/<projectId>/users/<ids>`,
|
|
112
113
|
* AND every mutation is gated through the supplied `grants`
|
|
113
114
|
* — writes that the grants don't permit throw a `WriteAccessDeniedError`
|
|
114
115
|
* shaped like Sanity's 403. Lets tests demonstrate the full
|
|
@@ -594,6 +595,12 @@ export declare type PatchOp =
|
|
|
594
595
|
|
|
595
596
|
export declare type Perspective = "raw" | "published" | "drafts" | string[];
|
|
596
597
|
|
|
598
|
+
/** One row of the `/projects/<projectId>` members response. */
|
|
599
|
+
export declare interface ProjectMemberRecord {
|
|
600
|
+
id: string;
|
|
601
|
+
isRobot?: boolean;
|
|
602
|
+
}
|
|
603
|
+
|
|
597
604
|
/**
|
|
598
605
|
* A row served by the project-users directory endpoint
|
|
599
606
|
* (`/projects/<projectId>/users/<id>`), mirroring Sanity's project user
|
package/dist/index.d.ts
CHANGED
|
@@ -108,7 +108,8 @@ export declare interface CreateTestClientOptions {
|
|
|
108
108
|
/**
|
|
109
109
|
* Opt-in access-control simulation. When set, the client exposes
|
|
110
110
|
* `request({ url })` that serves `/users/me` (host-aware), the
|
|
111
|
-
* configured ACL path,
|
|
111
|
+
* configured ACL path, `/projects/<projectId>` (members), and
|
|
112
|
+
* `/projects/<projectId>/users/<ids>`,
|
|
112
113
|
* AND every mutation is gated through the supplied `grants`
|
|
113
114
|
* — writes that the grants don't permit throw a `WriteAccessDeniedError`
|
|
114
115
|
* shaped like Sanity's 403. Lets tests demonstrate the full
|
|
@@ -594,6 +595,12 @@ export declare type PatchOp =
|
|
|
594
595
|
|
|
595
596
|
export declare type Perspective = "raw" | "published" | "drafts" | string[];
|
|
596
597
|
|
|
598
|
+
/** One row of the `/projects/<projectId>` members response. */
|
|
599
|
+
export declare interface ProjectMemberRecord {
|
|
600
|
+
id: string;
|
|
601
|
+
isRobot?: boolean;
|
|
602
|
+
}
|
|
603
|
+
|
|
597
604
|
/**
|
|
598
605
|
* A row served by the project-users directory endpoint
|
|
599
606
|
* (`/projects/<projectId>/users/<id>`), mirroring Sanity's project user
|
package/dist/index.js
CHANGED
|
@@ -97,7 +97,18 @@ function serveProjectUsers(args) {
|
|
|
97
97
|
return identity === void 0 ? [] : [toRecord(identity)];
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
const PROJECT_USERS_PATH = /^\/projects\/([^/]+)\/users\/([^/]+)$/;
|
|
100
|
+
const PROJECT_USERS_PATH = /^\/projects\/([^/]+)\/users\/([^/]+)$/, PROJECT_PATH = /^\/projects\/([^/]+)$/;
|
|
101
|
+
function serveProject(args) {
|
|
102
|
+
const ids = /* @__PURE__ */ new Set();
|
|
103
|
+
for (const identity of args.identities)
|
|
104
|
+
ids.add(projectUserOf(identity, args.pathProjectId).id);
|
|
105
|
+
return {
|
|
106
|
+
members: [...ids].map((id) => ({
|
|
107
|
+
id,
|
|
108
|
+
...id.startsWith("p-") ? { isRobot: !0 } : {}
|
|
109
|
+
}))
|
|
110
|
+
};
|
|
111
|
+
}
|
|
101
112
|
function makeRequestImpl(ctx) {
|
|
102
113
|
const { getAccess, projectId, dataset, useProjectHostname, listIdentities } = ctx;
|
|
103
114
|
return async (opts) => {
|
|
@@ -113,8 +124,14 @@ function makeRequestImpl(ctx) {
|
|
|
113
124
|
pathProjectId,
|
|
114
125
|
identities: listIdentities()
|
|
115
126
|
});
|
|
127
|
+
const project = path?.match(PROJECT_PATH), [, membersProjectId] = project ?? [];
|
|
128
|
+
if (membersProjectId !== void 0)
|
|
129
|
+
return serveProject({
|
|
130
|
+
pathProjectId: membersProjectId,
|
|
131
|
+
identities: listIdentities()
|
|
132
|
+
});
|
|
116
133
|
throw fakeError(
|
|
117
|
-
`request(): no handler for path "${path}". With access control configured, the fake serves "/users/me", "${aclPath}", and "/projects/<projectId>/users/<ids>". For any other endpoint, register a stub (client.stub("request", fn)) or intercept the HTTP call with a tool like MSW.`
|
|
134
|
+
`request(): no handler for path "${path}". With access control configured, the fake serves "/users/me", "${aclPath}", "/projects/<projectId>" (members), and "/projects/<projectId>/users/<ids>". For any other endpoint, register a stub (client.stub("request", fn)) or intercept the HTTP call with a tool like MSW.`
|
|
118
135
|
);
|
|
119
136
|
};
|
|
120
137
|
}
|
|
@@ -825,7 +842,7 @@ const ISSUES_URL = "https://github.com/sanity-labs/client-fake-for-test/issues",
|
|
|
825
842
|
},
|
|
826
843
|
request: {
|
|
827
844
|
what: "generic HTTP request hook \u2014 only wired up when the handle has an acting identity",
|
|
828
|
-
workaround: "Create the client with `accessControl`, or bind a registered token (`identities` + `token` / `withConfig({ token })`), to enable request() (it serves /users/me, the ACL path, and /projects/<projectId>/users/<ids>). Or register a stub."
|
|
845
|
+
workaround: "Create the client with `accessControl`, or bind a registered token (`identities` + `token` / `withConfig({ token })`), to enable request() (it serves /users/me, the ACL path, /projects/<projectId>, and /projects/<projectId>/users/<ids>). Or register a stub."
|
|
829
846
|
},
|
|
830
847
|
dryRun: {
|
|
831
848
|
what: "not a method \u2014 did you mean the `{ dryRun }` mutation option?",
|