@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/README.md
CHANGED
|
@@ -80,7 +80,7 @@ More patterns — passing the fake to code typed against `SanityClient`, asserti
|
|
|
80
80
|
| Config | `config()` | Returns `{ projectId, dataset, perspective, token?, useProjectHostname }` |
|
|
81
81
|
| Config | `withConfig({ projectId?, dataset?, perspective?, accessControl?, token?, useProjectHostname? })` | Sibling handle into the same multi-dataset registry; `token` binds a registered identity (see the token→identity registry below), `accessControl` rebinds it inline — the two are mutually exclusive; `useProjectHostname: false` mints a global-hosted sibling |
|
|
82
82
|
| Perspectives | `raw` / `published` / `drafts` / release stacks | Per-client default or per-`fetch` override; draft/version layering with `_originalId` projection |
|
|
83
|
-
| HTTP | `request({ url? \| uri? })` | Present **only** when the handle has an acting identity (`accessControl`, or a bound `token`). Serves `/users/me` (host-aware: project-scoped record on the project host, `globalUser` on a global-hosted handle), the configured ACL path, and `/projects/<projectId>/users/<ids>` (project-user records with `id` + `sanityUserId`). Calling it without one throws a guidance error. |
|
|
83
|
+
| HTTP | `request({ url? \| uri? })` | Present **only** when the handle has an acting identity (`accessControl`, or a bound `token`). Serves `/users/me` (host-aware: project-scoped record on the project host, `globalUser` on a global-hosted handle), the configured ACL path, `/projects/<projectId>` (the project's members: `{ id, isRobot? }` rows, one per distinct resolved project user), and `/projects/<projectId>/users/<ids>` (project-user records with `id` + `sanityUserId`). Calling it without one throws a guidance error. |
|
|
84
84
|
|
|
85
85
|
#### Mutation return shapes
|
|
86
86
|
|
package/dist/index.cjs
CHANGED
|
@@ -99,7 +99,18 @@ function serveProjectUsers(args) {
|
|
|
99
99
|
return identity === void 0 ? [] : [toRecord(identity)];
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
const PROJECT_USERS_PATH = /^\/projects\/([^/]+)\/users\/([^/]+)$/;
|
|
102
|
+
const PROJECT_USERS_PATH = /^\/projects\/([^/]+)\/users\/([^/]+)$/, PROJECT_PATH = /^\/projects\/([^/]+)$/;
|
|
103
|
+
function serveProject(args) {
|
|
104
|
+
const ids = /* @__PURE__ */ new Set();
|
|
105
|
+
for (const identity of args.identities)
|
|
106
|
+
ids.add(projectUserOf(identity, args.pathProjectId).id);
|
|
107
|
+
return {
|
|
108
|
+
members: [...ids].map((id) => ({
|
|
109
|
+
id,
|
|
110
|
+
...id.startsWith("p-") ? { isRobot: !0 } : {}
|
|
111
|
+
}))
|
|
112
|
+
};
|
|
113
|
+
}
|
|
103
114
|
function makeRequestImpl(ctx) {
|
|
104
115
|
const { getAccess, projectId, dataset, useProjectHostname, listIdentities } = ctx;
|
|
105
116
|
return async (opts) => {
|
|
@@ -115,8 +126,14 @@ function makeRequestImpl(ctx) {
|
|
|
115
126
|
pathProjectId,
|
|
116
127
|
identities: listIdentities()
|
|
117
128
|
});
|
|
129
|
+
const project = path?.match(PROJECT_PATH), [, membersProjectId] = project ?? [];
|
|
130
|
+
if (membersProjectId !== void 0)
|
|
131
|
+
return serveProject({
|
|
132
|
+
pathProjectId: membersProjectId,
|
|
133
|
+
identities: listIdentities()
|
|
134
|
+
});
|
|
118
135
|
throw fakeError(
|
|
119
|
-
`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.`
|
|
136
|
+
`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.`
|
|
120
137
|
);
|
|
121
138
|
};
|
|
122
139
|
}
|
|
@@ -827,7 +844,7 @@ const ISSUES_URL = "https://github.com/sanity-labs/client-fake-for-test/issues",
|
|
|
827
844
|
},
|
|
828
845
|
request: {
|
|
829
846
|
what: "generic HTTP request hook \u2014 only wired up when the handle has an acting identity",
|
|
830
|
-
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."
|
|
847
|
+
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."
|
|
831
848
|
},
|
|
832
849
|
dryRun: {
|
|
833
850
|
what: "not a method \u2014 did you mean the `{ dryRun }` mutation option?",
|