@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.js
CHANGED
|
@@ -1,34 +1,40 @@
|
|
|
1
1
|
import { parse, evaluate } from "groq-js";
|
|
2
|
+
import { ClientError } from "@sanity/client";
|
|
2
3
|
const ERR_PREFIX = "[client-fake-for-test]";
|
|
3
4
|
function fakeError(message) {
|
|
4
5
|
return new Error(`${ERR_PREFIX} ${message}`);
|
|
5
6
|
}
|
|
6
|
-
class PlatformHttpError extends
|
|
7
|
-
statusCode;
|
|
8
|
-
response;
|
|
9
|
-
responseBody;
|
|
10
|
-
details;
|
|
7
|
+
class PlatformHttpError extends ClientError {
|
|
11
8
|
constructor(args) {
|
|
12
|
-
|
|
13
|
-
super(clientErrorMessage(args)), this.name = "PlatformHttpError", this.statusCode = statusCode, this.response = { body, url: path, method, headers: {}, statusCode, statusMessage }, this.responseBody = typeof body == "string" ? body : JSON.stringify(body, null, 2);
|
|
14
|
-
const error = isRecord(body) ? body.error : void 0;
|
|
15
|
-
this.details = isRecord(error) ? error : void 0;
|
|
9
|
+
super(platformResponse(args)), this.name = "PlatformHttpError";
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
12
|
+
function platformResponse(args) {
|
|
13
|
+
const { method, path, statusCode, statusMessage, body } = args;
|
|
14
|
+
return {
|
|
15
|
+
body,
|
|
16
|
+
url: path,
|
|
17
|
+
method,
|
|
18
|
+
headers: { "content-type": `${typeof body == "string" ? "text/html" : "application/json"}; charset=utf-8` },
|
|
19
|
+
statusCode,
|
|
20
|
+
statusMessage
|
|
21
|
+
};
|
|
20
22
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
function transactionRefused(request, cause) {
|
|
24
|
+
return platformResponse({
|
|
25
|
+
...request,
|
|
26
|
+
statusCode: 403,
|
|
27
|
+
statusMessage: "Forbidden",
|
|
28
|
+
body: {
|
|
29
|
+
error: {
|
|
30
|
+
description: `transaction failed: ${cause.description}`,
|
|
31
|
+
items: [{ error: cause, index: 0 }],
|
|
32
|
+
type: "mutationError"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
}
|
|
31
|
-
const notMounted = ({ method, path }) => new PlatformHttpError({
|
|
37
|
+
const DEFAULT_WRITE = { method: "POST", path: "/data/mutate" }, notMounted = ({ method, path }) => new PlatformHttpError({
|
|
32
38
|
method,
|
|
33
39
|
path,
|
|
34
40
|
statusCode: 404,
|
|
@@ -44,7 +50,17 @@ function accessApiError(args) {
|
|
|
44
50
|
body: { statusCode, error: statusMessage, message }
|
|
45
51
|
});
|
|
46
52
|
}
|
|
47
|
-
const
|
|
53
|
+
const sessionNotFound = (request) => new PlatformHttpError({
|
|
54
|
+
...request,
|
|
55
|
+
statusCode: 401,
|
|
56
|
+
statusMessage: "Unauthorized",
|
|
57
|
+
body: {
|
|
58
|
+
error: "Unauthorized",
|
|
59
|
+
errorCode: "SIO-401-ANF",
|
|
60
|
+
message: "Session not found",
|
|
61
|
+
statusCode: 401
|
|
62
|
+
}
|
|
63
|
+
}), noPermission = (request) => accessApiError({
|
|
48
64
|
request,
|
|
49
65
|
statusCode: 403,
|
|
50
66
|
statusMessage: "Forbidden",
|
|
@@ -679,13 +695,17 @@ function attributeRecord(attribute) {
|
|
|
679
695
|
);
|
|
680
696
|
return { type, key, values: { ...values }, activeSource, activeValue };
|
|
681
697
|
}
|
|
682
|
-
class WriteAccessDeniedError extends
|
|
698
|
+
class WriteAccessDeniedError extends ClientError {
|
|
683
699
|
documentId;
|
|
684
700
|
permission;
|
|
685
701
|
matchingGrants;
|
|
686
702
|
constructor(args) {
|
|
687
703
|
super(
|
|
688
|
-
|
|
704
|
+
transactionRefused(args.request ?? DEFAULT_WRITE, {
|
|
705
|
+
description: `Insufficient permissions; permission "${args.permission}" required`,
|
|
706
|
+
permission: args.permission,
|
|
707
|
+
type: "insufficientPermissionsError"
|
|
708
|
+
})
|
|
689
709
|
), this.name = "WriteAccessDeniedError", this.documentId = args.documentId, this.permission = args.permission, this.matchingGrants = args.matchingGrants;
|
|
690
710
|
}
|
|
691
711
|
}
|
|
@@ -715,7 +735,7 @@ async function evaluateWriteAccess(args) {
|
|
|
715
735
|
return { allowed: !1, matchingGrants: matching };
|
|
716
736
|
}
|
|
717
737
|
async function enforceWriteAccess(args) {
|
|
718
|
-
const { document, grants, permission, userId } = args, { allowed, matchingGrants } = await evaluateWriteAccess({
|
|
738
|
+
const { document, grants, permission, userId, request } = args, { allowed, matchingGrants } = await evaluateWriteAccess({
|
|
719
739
|
document,
|
|
720
740
|
grants,
|
|
721
741
|
permission,
|
|
@@ -725,11 +745,13 @@ async function enforceWriteAccess(args) {
|
|
|
725
745
|
throw typeof document._id != "string" ? new WriteAccessDeniedError({
|
|
726
746
|
documentId: "(unknown)",
|
|
727
747
|
permission,
|
|
728
|
-
matchingGrants
|
|
748
|
+
matchingGrants,
|
|
749
|
+
request
|
|
729
750
|
}) : new WriteAccessDeniedError({
|
|
730
751
|
documentId: document._id,
|
|
731
752
|
permission,
|
|
732
|
-
matchingGrants
|
|
753
|
+
matchingGrants,
|
|
754
|
+
request
|
|
733
755
|
});
|
|
734
756
|
}
|
|
735
757
|
function defaultAclPath(projectId, dataset) {
|
|
@@ -839,24 +861,24 @@ function makeRequestImpl(ctx) {
|
|
|
839
861
|
);
|
|
840
862
|
};
|
|
841
863
|
}
|
|
842
|
-
class GuardDeniedError extends
|
|
843
|
-
statusCode = 403;
|
|
864
|
+
class GuardDeniedError extends ClientError {
|
|
844
865
|
type = "guardDeniedError";
|
|
845
866
|
denials;
|
|
846
|
-
|
|
847
|
-
response;
|
|
848
|
-
constructor(denials) {
|
|
867
|
+
constructor(denials, request = DEFAULT_WRITE) {
|
|
849
868
|
const unique = uniqueDenials(denials);
|
|
850
|
-
super(
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
};
|
|
869
|
+
super(
|
|
870
|
+
transactionRefused(request, {
|
|
871
|
+
description: guardDeniedDescription(unique),
|
|
872
|
+
denials: unique,
|
|
873
|
+
type: "guardDeniedError"
|
|
874
|
+
})
|
|
875
|
+
), this.name = "GuardDeniedError", this.denials = unique;
|
|
858
876
|
}
|
|
859
877
|
}
|
|
878
|
+
function guardDeniedDescription(denials) {
|
|
879
|
+
const named = denials.map(({ guardID, name }) => name ? `${guardID} (${name})` : guardID);
|
|
880
|
+
return `mutation denied by ${denials.length} guard(s): ${named.join(" ")}`;
|
|
881
|
+
}
|
|
860
882
|
function uniqueDenials(denials) {
|
|
861
883
|
const seen = /* @__PURE__ */ new Set();
|
|
862
884
|
return denials.filter((denial) => seen.has(denial.guardID) ? !1 : (seen.add(denial.guardID), !0));
|
|
@@ -872,14 +894,14 @@ function mutationContexts(images) {
|
|
|
872
894
|
return context === void 0 ? [] : [context];
|
|
873
895
|
});
|
|
874
896
|
}
|
|
875
|
-
async function enforceMutationGuards(guard, contexts) {
|
|
897
|
+
async function enforceMutationGuards(guard, contexts, request) {
|
|
876
898
|
if (guard === void 0) return;
|
|
877
899
|
const denials = [];
|
|
878
900
|
for (const context of contexts) {
|
|
879
901
|
const denied = await guard(context);
|
|
880
902
|
denied !== void 0 && denials.push(...denied);
|
|
881
903
|
}
|
|
882
|
-
if (denials.length > 0) throw new GuardDeniedError(denials);
|
|
904
|
+
if (denials.length > 0) throw new GuardDeniedError(denials, request);
|
|
883
905
|
}
|
|
884
906
|
function describeType(value) {
|
|
885
907
|
return value === null ? "null" : Array.isArray(value) ? "an array" : `a ${typeof value}`;
|
|
@@ -1277,7 +1299,7 @@ function requireActive(release) {
|
|
|
1277
1299
|
`Release "${release.name}" is "${release.state}", but only "active" releases accept version writes (create / replace / discard / unpublish). Unschedule or unarchive it back to "active" first, or target a different release.`
|
|
1278
1300
|
);
|
|
1279
1301
|
}
|
|
1280
|
-
async function applyAction(store, action) {
|
|
1302
|
+
async function applyAction(store, action, request = ACTIONS_REQUEST) {
|
|
1281
1303
|
switch (action.actionType) {
|
|
1282
1304
|
case "sanity.action.release.create": {
|
|
1283
1305
|
if (maybeRelease(store, action.releaseId) !== void 0)
|
|
@@ -1381,7 +1403,7 @@ async function applyAction(store, action) {
|
|
|
1381
1403
|
return store.remove(release._id), { transactionId: cryptoRandomKey() };
|
|
1382
1404
|
}
|
|
1383
1405
|
case "sanity.action.document.version.create": {
|
|
1384
|
-
if ("baseId" in action) return createVersionFromBase(store, action);
|
|
1406
|
+
if ("baseId" in action) return createVersionFromBase(store, action, request);
|
|
1385
1407
|
const releaseId = action.releaseId ?? (action.document._id !== void 0 ? parseVersionId(action.document._id).releaseId : void 0);
|
|
1386
1408
|
if (releaseId === void 0)
|
|
1387
1409
|
throw fakeError(
|
|
@@ -1428,7 +1450,12 @@ async function applyAction(store, action) {
|
|
|
1428
1450
|
`Cannot publish "${action.publishedId}": draft "${action.draftId}" not found. document.publish promotes an existing draft onto the published id \u2014 create the draft first (e.g. client.createOrReplace({ _id: "${action.draftId}", ... })).`
|
|
1429
1451
|
);
|
|
1430
1452
|
const published = store.get(action.publishedId);
|
|
1431
|
-
requireRevisionMatch(action.draftId, draft._rev, action.ifDraftRevisionId), requireRevisionMatch(
|
|
1453
|
+
requireRevisionMatch(request, action.draftId, draft._rev, action.ifDraftRevisionId), requireRevisionMatch(
|
|
1454
|
+
request,
|
|
1455
|
+
action.publishedId,
|
|
1456
|
+
published?._rev,
|
|
1457
|
+
action.ifPublishedRevisionId
|
|
1458
|
+
);
|
|
1432
1459
|
const promoted = promote({ ...draft, _id: action.publishedId });
|
|
1433
1460
|
return published !== void 0 && (promoted._createdAt = published._createdAt), store.put(promoted), store.remove(action.draftId), { transactionId: cryptoRandomKey() };
|
|
1434
1461
|
}
|
|
@@ -1453,7 +1480,7 @@ function requireDraftOf(action) {
|
|
|
1453
1480
|
`${action.actionType}: draftId "${action.draftId}" is not the draft of publishedId "${action.publishedId}" \u2014 expected draftId "drafts.${action.publishedId}".`
|
|
1454
1481
|
);
|
|
1455
1482
|
}
|
|
1456
|
-
async function createVersionFromBase(store, action) {
|
|
1483
|
+
async function createVersionFromBase(store, action, request) {
|
|
1457
1484
|
const { releaseId, publishedId } = parseVersionId(action.versionId);
|
|
1458
1485
|
if (publishedId !== action.publishedId)
|
|
1459
1486
|
throw fakeError(
|
|
@@ -1465,7 +1492,7 @@ async function createVersionFromBase(store, action) {
|
|
|
1465
1492
|
throw fakeError(
|
|
1466
1493
|
`Cannot create version "${action.versionId}": base document "${action.baseId}" not found. version.create with \`baseId\` copies an existing document; pass \`document\` instead when there is nothing to copy.`
|
|
1467
1494
|
);
|
|
1468
|
-
requireRevisionMatch(action.baseId, base._rev, action.ifBaseRevisionId);
|
|
1495
|
+
requireRevisionMatch(request, action.baseId, base._rev, action.ifBaseRevisionId);
|
|
1469
1496
|
const existing = store.get(action.versionId), copy = {
|
|
1470
1497
|
...base,
|
|
1471
1498
|
_id: action.versionId,
|
|
@@ -1474,14 +1501,33 @@ async function createVersionFromBase(store, action) {
|
|
|
1474
1501
|
}, promoted = promote(copy);
|
|
1475
1502
|
return store.put(promoted), { transactionId: cryptoRandomKey() };
|
|
1476
1503
|
}
|
|
1477
|
-
|
|
1504
|
+
const ACTIONS_REQUEST = { method: "POST", path: "/data/actions" };
|
|
1505
|
+
function requireRevisionMatch(request, documentId, actualRev, expectedRev) {
|
|
1478
1506
|
if (!(expectedRev === void 0 || actualRev === expectedRev))
|
|
1479
|
-
throw
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1507
|
+
throw actualRev === void 0 ? new PlatformHttpError({
|
|
1508
|
+
...request,
|
|
1509
|
+
statusCode: 404,
|
|
1510
|
+
statusMessage: "Not Found",
|
|
1511
|
+
body: {
|
|
1512
|
+
error: {
|
|
1513
|
+
description: `The document with the ID ${JSON.stringify(documentId)} was not found`,
|
|
1514
|
+
id: documentId,
|
|
1515
|
+
type: "documentNotFoundError"
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
}) : new PlatformHttpError({
|
|
1519
|
+
...request,
|
|
1520
|
+
statusCode: 409,
|
|
1521
|
+
statusMessage: "Conflict",
|
|
1522
|
+
body: {
|
|
1523
|
+
error: {
|
|
1524
|
+
currentRevisionID: actualRev,
|
|
1525
|
+
description: `Document ${JSON.stringify(documentId)} has unexpected revision ID (${JSON.stringify(actualRev)}), expected ${JSON.stringify(expectedRev)}`,
|
|
1526
|
+
expectedRevisionID: expectedRev,
|
|
1527
|
+
type: "documentRevisionIDDoesNotMatchError"
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1485
1531
|
}
|
|
1486
1532
|
async function applyActions(store, actions, hooks) {
|
|
1487
1533
|
const list = Array.isArray(actions) ? actions : [actions], snapshot = /* @__PURE__ */ new Map(), guardedIds = /* @__PURE__ */ new Set(), gatedIds = /* @__PURE__ */ new Set(), remember = (id) => {
|
|
@@ -1536,7 +1582,7 @@ async function applyActions(store, actions, hooks) {
|
|
|
1536
1582
|
remember(a.draftId), remember(a.publishedId), guardedIds.add(a.draftId), guardedIds.add(a.publishedId), gatedIds.add(a.publishedId), gatedIds.add(a.draftId);
|
|
1537
1583
|
break;
|
|
1538
1584
|
}
|
|
1539
|
-
last = await applyAction(store, a);
|
|
1585
|
+
last = await applyAction(store, a, hooks?.request);
|
|
1540
1586
|
}
|
|
1541
1587
|
for (const id of gatedIds) {
|
|
1542
1588
|
const before = snapshot.get(id), after = store.get(id);
|
|
@@ -1834,6 +1880,7 @@ function createTestClient(options = {}) {
|
|
|
1834
1880
|
calls: [],
|
|
1835
1881
|
concurrentEdits: /* @__PURE__ */ new Map(),
|
|
1836
1882
|
identities: new Map(Object.entries(options.identities ?? {})),
|
|
1883
|
+
revoked: /* @__PURE__ */ new Set(),
|
|
1837
1884
|
writeChain: Promise.resolve()
|
|
1838
1885
|
}, registry = backend.registry;
|
|
1839
1886
|
if (rejectAmbiguousIdentity("createTestClient()", options), options.token !== void 0 && requireIdentity(backend, options.token, "createTestClient()"), options.resource !== void 0 && validateResource(options.resource), options.documents) {
|
|
@@ -1858,7 +1905,8 @@ function createTestClient(options = {}) {
|
|
|
1858
1905
|
requestTagPrefix: options.requestTagPrefix,
|
|
1859
1906
|
mutationGuard: options.mutationGuard,
|
|
1860
1907
|
token: options.token,
|
|
1861
|
-
useProjectHostname: options.useProjectHostname ?? !0
|
|
1908
|
+
useProjectHostname: options.useProjectHostname ?? !0,
|
|
1909
|
+
hasProjectId: options.projectId !== void 0
|
|
1862
1910
|
});
|
|
1863
1911
|
}
|
|
1864
1912
|
function dedupeIds(results) {
|
|
@@ -1921,7 +1969,7 @@ function makeHandle(handleArgs) {
|
|
|
1921
1969
|
mutationGuard,
|
|
1922
1970
|
token,
|
|
1923
1971
|
useProjectHostname
|
|
1924
|
-
} = handleArgs, { registry } = backend, { projectId, dataset } = resource?.type === "dataset" ? datasetParts(resource.id) : handleArgs, target = resource ?? datasetResource(projectId, dataset), activeAccess = () => {
|
|
1972
|
+
} = handleArgs, { registry } = backend, hasProjectId = handleArgs.hasProjectId || useProjectHostname && resource === void 0 || resource?.type === "dataset", { projectId, dataset } = resource?.type === "dataset" ? datasetParts(resource.id) : handleArgs, target = resource ?? datasetResource(projectId, dataset), activeAccess = () => {
|
|
1925
1973
|
if (token === void 0) return accessControl;
|
|
1926
1974
|
const identity = backend.identities.get(token);
|
|
1927
1975
|
if (identity === void 0)
|
|
@@ -1938,7 +1986,10 @@ function makeHandle(handleArgs) {
|
|
|
1938
1986
|
if (access === void 0)
|
|
1939
1987
|
throw fakeError("this handle has no acting identity (no token or accessControl bound).");
|
|
1940
1988
|
return access;
|
|
1941
|
-
},
|
|
1989
|
+
}, refuseRevoked = (request) => {
|
|
1990
|
+
if (token !== void 0 && backend.revoked.has(token)) throw sessionNotFound(request);
|
|
1991
|
+
}, withSession = (request) => async (opts) => (refuseRevoked({ method: "GET", path: opts.uri ?? opts.url ?? "" }), request(opts)), admitToLake = (request) => {
|
|
1992
|
+
refuseRevoked(request);
|
|
1942
1993
|
const access = activeAccess();
|
|
1943
1994
|
if (access === void 0) return;
|
|
1944
1995
|
const refusal = refusedToken(request, access.grants);
|
|
@@ -1958,13 +2009,13 @@ function makeHandle(handleArgs) {
|
|
|
1958
2009
|
if (access !== void 0)
|
|
1959
2010
|
return capabilities.identity === "global" ? (access.globalUser ?? access.currentUser).id : access.currentUser.id;
|
|
1960
2011
|
};
|
|
1961
|
-
let beforeWrite;
|
|
2012
|
+
let beforeWrite, writeRequest = DEFAULT_WRITE;
|
|
1962
2013
|
const write = (run, request = lakeRequest("POST", "mutate")) => serializeWrite(backend, async () => {
|
|
1963
|
-
admitToLake(request), beforeWrite = new Map(store.all().map((doc) => [doc._id, doc]));
|
|
2014
|
+
admitToLake(request), beforeWrite = new Map(store.all().map((doc) => [doc._id, doc])), writeRequest = request;
|
|
1964
2015
|
try {
|
|
1965
2016
|
return await run();
|
|
1966
2017
|
} finally {
|
|
1967
|
-
beforeWrite = void 0;
|
|
2018
|
+
beforeWrite = void 0, writeRequest = DEFAULT_WRITE;
|
|
1968
2019
|
}
|
|
1969
2020
|
}), commitHistory = (transactionId) => {
|
|
1970
2021
|
beforeWrite !== void 0 && history.commit({ transactionId, author: actorId(), before: beforeWrite, after: store.all() });
|
|
@@ -2031,13 +2082,15 @@ function makeHandle(handleArgs) {
|
|
|
2031
2082
|
document,
|
|
2032
2083
|
grants: access.grants,
|
|
2033
2084
|
permission,
|
|
2034
|
-
userId: actorId()
|
|
2085
|
+
userId: actorId(),
|
|
2086
|
+
request: writeRequest
|
|
2035
2087
|
});
|
|
2036
2088
|
}, guardGate = async (contexts) => {
|
|
2037
2089
|
const identity = actorId();
|
|
2038
2090
|
await enforceMutationGuards(
|
|
2039
2091
|
mutationGuard,
|
|
2040
|
-
contexts.map((context) => ({ ...context, identity }))
|
|
2092
|
+
contexts.map((context) => ({ ...context, identity })),
|
|
2093
|
+
writeRequest
|
|
2041
2094
|
);
|
|
2042
2095
|
}, guardOne = async (action, before, after) => {
|
|
2043
2096
|
await guardGate([{ action, before, after }]);
|
|
@@ -2120,17 +2173,14 @@ function makeHandle(handleArgs) {
|
|
|
2120
2173
|
txnOptions?.returnFirst ?? !1
|
|
2121
2174
|
);
|
|
2122
2175
|
}, runAction = async (actions) => {
|
|
2123
|
-
const request =
|
|
2124
|
-
|
|
2125
|
-
path: `${capabilities.dataBase(target.id)}/actions`
|
|
2126
|
-
};
|
|
2127
|
-
if (capabilities.actions !== "served") throw capabilities.actions(request);
|
|
2176
|
+
const request = lakeRequest("POST", "actions");
|
|
2177
|
+
if (refuseRevoked(request), capabilities.actions !== "served") throw capabilities.actions(request);
|
|
2128
2178
|
return write(async () => {
|
|
2129
2179
|
for (const action of Array.isArray(actions) ? actions : [actions]) {
|
|
2130
2180
|
const refused = capabilities.refusedActions[action.actionType];
|
|
2131
2181
|
if (refused !== void 0) throw refused(request);
|
|
2132
2182
|
}
|
|
2133
|
-
const result = await applyActions(store, actions, { gate, guard: guardGate });
|
|
2183
|
+
const result = await applyActions(store, actions, { gate, guard: guardGate, request });
|
|
2134
2184
|
return commitHistory(result.transactionId), result;
|
|
2135
2185
|
}, request);
|
|
2136
2186
|
}, accessVisibleDocs = async () => {
|
|
@@ -2328,36 +2378,38 @@ function makeHandle(handleArgs) {
|
|
|
2328
2378
|
publishedId
|
|
2329
2379
|
}),
|
|
2330
2380
|
...token !== void 0 || accessControl !== void 0 ? {
|
|
2331
|
-
request:
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
listIdentities: members,
|
|
2338
|
-
platform: {
|
|
2339
|
-
projectId,
|
|
2381
|
+
request: withSession(
|
|
2382
|
+
makeRequestImpl({
|
|
2383
|
+
getAccess: requireActiveAccess,
|
|
2384
|
+
// `@sanity/client` sends every request of a `resource`-configured
|
|
2385
|
+
// client to the global API host.
|
|
2386
|
+
useProjectHostname: useProjectHostname && resource === void 0,
|
|
2340
2387
|
organizationId: backend.organizationId,
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2388
|
+
listIdentities: members,
|
|
2389
|
+
platform: {
|
|
2390
|
+
projectId,
|
|
2391
|
+
organizationId: backend.organizationId,
|
|
2392
|
+
projectFeatures: backend.projectFeatures,
|
|
2393
|
+
own: (asked) => registryKey(asked) === registryKey(target) ? {
|
|
2394
|
+
grants: requireActiveAccess().grants,
|
|
2395
|
+
documents: () => store.all(),
|
|
2396
|
+
history,
|
|
2397
|
+
canRead,
|
|
2398
|
+
admitToLake
|
|
2399
|
+
} : void 0,
|
|
2400
|
+
actorUser: () => {
|
|
2401
|
+
const access = requireActiveAccess();
|
|
2402
|
+
return access.globalUser ?? access.currentUser;
|
|
2403
|
+
},
|
|
2404
|
+
actorAccess: () => requireActiveAccess().access,
|
|
2405
|
+
identities: members,
|
|
2406
|
+
resources: () => [...registry.values()].map((entry) => entry.resource)
|
|
2407
|
+
}
|
|
2408
|
+
})
|
|
2409
|
+
)
|
|
2358
2410
|
} : {},
|
|
2359
2411
|
config: () => ({
|
|
2360
|
-
projectId,
|
|
2412
|
+
...hasProjectId || resource !== void 0 ? { projectId } : {},
|
|
2361
2413
|
dataset,
|
|
2362
2414
|
...resource !== void 0 ? { resource } : {},
|
|
2363
2415
|
perspective,
|
|
@@ -2378,7 +2430,8 @@ function makeHandle(handleArgs) {
|
|
|
2378
2430
|
requestTagPrefix: config.requestTagPrefix ?? requestTagPrefix,
|
|
2379
2431
|
mutationGuard,
|
|
2380
2432
|
token: rebinds ? config.token : token,
|
|
2381
|
-
useProjectHostname: config.useProjectHostname ?? useProjectHostname
|
|
2433
|
+
useProjectHostname: config.useProjectHostname ?? useProjectHostname,
|
|
2434
|
+
hasProjectId: hasProjectId || config.projectId !== void 0
|
|
2382
2435
|
});
|
|
2383
2436
|
},
|
|
2384
2437
|
seed: (documents) => store.seed(documents),
|
|
@@ -2400,6 +2453,9 @@ function makeHandle(handleArgs) {
|
|
|
2400
2453
|
backend.identities.set(identityToken, identity);
|
|
2401
2454
|
},
|
|
2402
2455
|
identities: () => Object.fromEntries(backend.identities),
|
|
2456
|
+
revokeIdentity: (revokedToken) => {
|
|
2457
|
+
requireIdentity(backend, revokedToken, "revokeIdentity()"), backend.revoked.add(revokedToken);
|
|
2458
|
+
},
|
|
2403
2459
|
mutations: () => backend.log.flatMap((entry) => entry.mutations),
|
|
2404
2460
|
transactions: () => [...backend.log],
|
|
2405
2461
|
clearLog: () => {
|