@sanity-labs/client-fake-for-test 0.28.0 → 0.29.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 +31 -2
- package/dist/index.cjs +179 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -6
- package/dist/index.d.ts +29 -6
- package/dist/index.js +180 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -200,11 +200,11 @@ The Content Lake refuses the token on every request it serves (queries, document
|
|
|
200
200
|
| `i` that is not a string | 400, `token field "i" must be a string` |
|
|
201
201
|
| `x` at or before now | 403 `{ error: { type: "permissionDeniedError", description: "Token has expired (at 2026-11-20 12:00:30 +0000 UTC)" } }` |
|
|
202
202
|
|
|
203
|
-
A JWT that does not verify still binds, as production clients accept any string; the refusal comes on the first request. Without `internalTokenKeys` a JWT is an unknown token, as before. An internal token has no session, so `revokeIdentity` throws for one: mint one whose `x` has passed instead. The project API (populus) verifies internal tokens with its own key and answers differently; the fake
|
|
203
|
+
A JWT that does not verify still binds, as production clients accept any string; the refusal comes on the first request. Without `internalTokenKeys` a JWT is an unknown token, as before. An internal token has no session, so `revokeIdentity` throws for one: mint one whose `x` has passed instead. The project API (populus) verifies internal tokens with its own key and answers differently; the fake models that only for the [organization store lookup](#organization-stores), so `request()` of `/users/me`, `/projects/…`, the Access API or an ACL throws a fake error with an internal token. A token with claims the Content Lake reads but the fake does not model (`tokenType`, `guid`, `s`, `z`, `audit`, `act`) binds, and throws a fake error on a Content Lake request instead of a guessed answer; `exp`, `iat`, `nbf` or a claims segment that is not a JSON object throw when the token binds. A missing `i`, or a `g…` global user id other than `god` (which gradient maps to a project user), throws its fake error on a request, after the 400 and 403 checks above.
|
|
204
204
|
|
|
205
205
|
#### Platform outages
|
|
206
206
|
|
|
207
|
-
`client.simulateOutage("project-api")` takes the project API (populus) down, as in an outage. From the next request on, every `request()` it serves throws a `PlatformServerError`, on every handle of the family, siblings made before and after the call alike: `/users/me`, `/projects/<projectId>` and everything under it (members, users, roles, features, the dataset ACL), `/organizations/<id>/users/me/attributes`, the Access API, resource lookup (`/canvases/<id>`, …) and a Media Library's or Canvas's ACL. `PlatformServerError` extends `@sanity/client`'s `ServerError`, which the client throws for a status of 500 or more, not `ClientError`, and the client does not retry it:
|
|
207
|
+
`client.simulateOutage("project-api")` takes the project API (populus) down, as in an outage. From the next request on, every `request()` it serves throws a `PlatformServerError`, on every handle of the family, siblings made before and after the call alike: `/users/me`, `/projects/<projectId>` and everything under it (members, users, roles, features, the dataset ACL), `/organizations/<id>/users/me/attributes`, the organization store lookup, the Access API, resource lookup (`/canvases/<id>`, …) and a Media Library's or Canvas's ACL. `PlatformServerError` extends `@sanity/client`'s `ServerError`, which the client throws for a status of 500 or more, not `ClientError`, and the client does not retry it:
|
|
208
208
|
|
|
209
209
|
```ts
|
|
210
210
|
{
|
|
@@ -222,6 +222,34 @@ A JWT that does not verify still binds, as production clients accept any string;
|
|
|
222
222
|
|
|
223
223
|
That is the body populus sends for an unexpected error: its error handler sends Boom's payload, and Boom hides the error's own message behind a fixed one. The Content Lake keeps answering (queries, documents, mutations, actions, the History API), as does a route a resource does not mount (Express's 404). A token without a session is still refused with its 401 first, as the gateway checks the session before it routes. The call is recorded in `client.calls()` with its error. `"project-api"` is the only component so far, and an outage lasts for the rest of the family's life; create a new client for a healthy platform.
|
|
224
224
|
|
|
225
|
+
#### Organization stores
|
|
226
|
+
|
|
227
|
+
Populus keeps one document store per organization, which a service looks up with `GET /internal/organization-stores?organizationId=<id>`. Give the client its organization, and `request()` answers the lookup as populus does (`src/controllers/internal/organizationStores.ts`):
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
const client = createTestClient({
|
|
231
|
+
useProjectHostname: false,
|
|
232
|
+
organizationId: "oAbc",
|
|
233
|
+
internalTokenKeys: [publicKeyPem],
|
|
234
|
+
token: serviceToken, // an RS256 JWT with tokenType: "service"
|
|
235
|
+
organizationStores: { oAbc: "active" }, // optional: a store that already exists
|
|
236
|
+
});
|
|
237
|
+
await client.request({ uri: "/internal/organization-stores", query: { organizationId: "oAbc" } });
|
|
238
|
+
// { id: "os…", organizationId: "oAbc", status: "active" }
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The first lookup for an organization without a store creates one `provisioning`, as populus does, and every later lookup answers the same store. In populus a background workflow then sets it `active`; in the fake `client.completeOrganizationStoreProvisioning("oAbc")` stands for that workflow finishing, and the next lookup answers `active`. A store whose provisioning never completes stays `provisioning`. The id is `os` and ten characters, derived from the organization id, so the same organization always gets the same id. Stores are shared by the whole `withConfig` family.
|
|
242
|
+
|
|
243
|
+
| Request | Answer |
|
|
244
|
+
| --- | --- |
|
|
245
|
+
| A registered identity's token (a user or robot session), or an internal token that is not a service token | 401 `{ statusCode: 401, error: "Unauthorized", message: "A service session is required for this endpoint" }` |
|
|
246
|
+
| An internal token without a signature, signed by another key, or past its `x` | 401, `jwt signature is required` / `invalid signature` / `Session expired` |
|
|
247
|
+
| A missing, empty, repeated or unknown query parameter | 400 `{ statusCode: 400, error: "Bad Request", message: "Validation failed", validation: { query: { source: "query", keys: [<key>], message: '"organizationId" is required' } } }` |
|
|
248
|
+
| An organization other than `organizationId` | 404, `Organization <id> not found` |
|
|
249
|
+
| While `simulateOutage("project-api")` is in effect | 500 (see [Platform outages](#platform-outages)); no store is created |
|
|
250
|
+
|
|
251
|
+
Populus answers only `provisioning` and `active` stores, so the lookup never answers another status, and seeding another status throws. `request()` takes a `query` object as `@sanity/client` does, appended to the URL after the request tag; every route reads its parameters from that URL. A `tag` in `query`, and bracketed query keys such as `organizationId[]` (which Express parses into nested values), throw a fake error.
|
|
252
|
+
|
|
225
253
|
#### Missing datasets
|
|
226
254
|
|
|
227
255
|
`createTestClient({ missingDatasets: ["p1:staged"] })` names datasets the platform does not have, as `"<projectId>:<dataset>"` keys. Every Content Lake request on one (queries, documents, mutations, actions, the History API) throws the `PlatformHttpError` the Content Lake answers for a missing dataset, on every handle of the family:
|
|
@@ -412,6 +440,7 @@ Useful in test bodies, but a giveaway that the code under test isn't using the r
|
|
|
412
440
|
| `client.identities()` | Snapshot of the registered token→identity entries |
|
|
413
441
|
| `client.revokeIdentity(token)` | Make every later request on a registered token answer 401 `Session not found` (see [Unknown tokens and revoked tokens](#unknown-tokens-and-revoked-tokens)) |
|
|
414
442
|
| `createTestClient({ internalTokenKeys: [publicKeyPem] })` | Verify JWT bearers as the Content Lake does (see [Internal tokens](#internal-tokens)) |
|
|
443
|
+
| `client.completeOrganizationStoreProvisioning(organizationId)` | Set the organization's `provisioning` store `active`, as populus's provisioning workflow does (see [Organization stores](#organization-stores)) |
|
|
415
444
|
| `client.simulateOutage("project-api")` | Make every later project API request answer populus's 500 (see [Platform outages](#platform-outages)) |
|
|
416
445
|
| `createTestClient({ datasets: { "p:d": [...] } })` | Seed multiple `(projectId, dataset)` stores up front |
|
|
417
446
|
| `createTestClient({ resources: { "media-library:ml1": [...] } })` | Seed any resource type up front; keys are `"<type>:<id>"` |
|
package/dist/index.cjs
CHANGED
|
@@ -513,6 +513,98 @@ function createDocumentHistory() {
|
|
|
513
513
|
function historyIds(list) {
|
|
514
514
|
return list.split(",").map((id) => decodeURIComponent(id));
|
|
515
515
|
}
|
|
516
|
+
const ORGANIZATION_STORES_PATH = "/internal/organization-stores";
|
|
517
|
+
function serveOrganizationStore(args) {
|
|
518
|
+
const { stores, organizationIds, session, request, query } = args;
|
|
519
|
+
refuseSession(request, session);
|
|
520
|
+
const organizationId = organizationIdOf(request, query);
|
|
521
|
+
if (!organizationIds.includes(organizationId))
|
|
522
|
+
throw boom(request, 404, "Not Found", `Organization ${organizationId} not found`);
|
|
523
|
+
const existing = stores.get(organizationId);
|
|
524
|
+
if (existing !== void 0) return { ...existing };
|
|
525
|
+
const store = {
|
|
526
|
+
id: organizationStoreId(organizationId),
|
|
527
|
+
organizationId,
|
|
528
|
+
status: "provisioning"
|
|
529
|
+
};
|
|
530
|
+
return stores.set(organizationId, store), { ...store };
|
|
531
|
+
}
|
|
532
|
+
function completeProvisioning(stores, organizationId) {
|
|
533
|
+
const store = stores.get(organizationId);
|
|
534
|
+
if (store?.status !== "provisioning")
|
|
535
|
+
throw fakeError(
|
|
536
|
+
`completeOrganizationStoreProvisioning(): organization "${organizationId}" has ` + (store === void 0 ? "no store. Populus creates one on the first GET /internal/organization-stores." : "an active store already.")
|
|
537
|
+
);
|
|
538
|
+
store.status = "active";
|
|
539
|
+
}
|
|
540
|
+
function refuseSession(request, session) {
|
|
541
|
+
const refused = "refused" in session ? session.refused : session.tokenType !== "service" && "A service session is required for this endpoint";
|
|
542
|
+
if (refused) throw boom(request, 401, "Unauthorized", refused);
|
|
543
|
+
}
|
|
544
|
+
function organizationIdOf(request, query) {
|
|
545
|
+
const nested = [...query.keys()].find((key) => key.includes("["));
|
|
546
|
+
if (nested !== void 0)
|
|
547
|
+
throw fakeError(
|
|
548
|
+
`request(): ${request.path} got query key "${nested}"; Express parses bracketed keys into nested values, which the fake does not model. Pass flat query parameters.`
|
|
549
|
+
);
|
|
550
|
+
const unknown = [...new Set(query.keys())].filter((key) => key !== "tag").find((key) => key !== "organizationId"), values = query.getAll("organizationId"), failure = values.length === 0 && {
|
|
551
|
+
key: "organizationId",
|
|
552
|
+
message: '"organizationId" is required'
|
|
553
|
+
} || values.length > 1 && {
|
|
554
|
+
key: "organizationId",
|
|
555
|
+
message: '"organizationId" must be a string'
|
|
556
|
+
} || values[0] === "" && {
|
|
557
|
+
key: "organizationId",
|
|
558
|
+
message: '"organizationId" is not allowed to be empty'
|
|
559
|
+
} || unknown !== void 0 && {
|
|
560
|
+
key: unknown,
|
|
561
|
+
message: `"${unknown}" is not allowed`
|
|
562
|
+
};
|
|
563
|
+
if (failure)
|
|
564
|
+
throw new PlatformHttpError({
|
|
565
|
+
...request,
|
|
566
|
+
statusCode: 400,
|
|
567
|
+
statusMessage: "Bad Request",
|
|
568
|
+
body: {
|
|
569
|
+
statusCode: 400,
|
|
570
|
+
error: "Bad Request",
|
|
571
|
+
message: "Validation failed",
|
|
572
|
+
validation: {
|
|
573
|
+
query: {
|
|
574
|
+
source: "query",
|
|
575
|
+
keys: [escapeHtml(failure.key)],
|
|
576
|
+
message: failure.message
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
return values[0];
|
|
582
|
+
}
|
|
583
|
+
const DISALLOWED_SEGMENTS = ["ad", "api", "xxx"];
|
|
584
|
+
function organizationStoreId(organizationId) {
|
|
585
|
+
for (let attempt = 0; ; attempt++) {
|
|
586
|
+
const id = `os${node_crypto.createHash("sha256").update(`${organizationId}:${attempt}`).digest("hex").slice(0, 10)}`;
|
|
587
|
+
if (!DISALLOWED_SEGMENTS.some((segment) => id.includes(segment))) return id;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function escapeHtml(text) {
|
|
591
|
+
const entities = {
|
|
592
|
+
'"': """,
|
|
593
|
+
"&": "&",
|
|
594
|
+
"'": "'",
|
|
595
|
+
"<": "<",
|
|
596
|
+
">": ">"
|
|
597
|
+
};
|
|
598
|
+
return text.replace(/["&'<>]/g, (char) => entities[char]);
|
|
599
|
+
}
|
|
600
|
+
function boom(request, statusCode, statusMessage, message) {
|
|
601
|
+
return new PlatformHttpError({
|
|
602
|
+
...request,
|
|
603
|
+
statusCode,
|
|
604
|
+
statusMessage,
|
|
605
|
+
body: { statusCode, error: statusMessage, message }
|
|
606
|
+
});
|
|
607
|
+
}
|
|
516
608
|
const ACCESS_PATH = /^\/access\/([^/]+)\/([^/]+)(\/.*)?$/, ACCESS_USER_PATH = /^\/users\/([^/]+)$/, ACCESS_ROLE_PATH = /^\/roles\/([^/]+)$/, ACCESS_ROBOT_PATH = /^\/robots(?:\/([^/]+))?$/, PROJECT_ROLES_PATH = /^\/projects\/([^/]+)\/roles$/, PROJECT_FEATURES_PATH = /^\/projects\/([^/]+)\/features$/, MY_ATTRIBUTES_PATH = /^\/organizations\/([^/]+)\/users\/me\/attributes$/, DATA_HISTORY_PATH = /^\/data\/history\/([^/]+)(\/.*)$/, ACCESS_API_SINCE = "2025-07-11", PROJECT_API_PATHS = [
|
|
517
609
|
/^\/users\/me$/,
|
|
518
610
|
/^\/projects\/[^/]+$/,
|
|
@@ -520,7 +612,8 @@ const ACCESS_PATH = /^\/access\/([^/]+)\/([^/]+)(\/.*)?$/, ACCESS_USER_PATH = /^
|
|
|
520
612
|
PROJECT_ROLES_PATH,
|
|
521
613
|
PROJECT_FEATURES_PATH,
|
|
522
614
|
MY_ATTRIBUTES_PATH,
|
|
523
|
-
ACCESS_PATH
|
|
615
|
+
ACCESS_PATH,
|
|
616
|
+
new RegExp(`^${ORGANIZATION_STORES_PATH}$`)
|
|
524
617
|
];
|
|
525
618
|
function servedByProjectApi(path) {
|
|
526
619
|
if (PROJECT_API_PATHS.some((pattern) => pattern.test(path))) return !0;
|
|
@@ -536,8 +629,19 @@ function usersPage(data) {
|
|
|
536
629
|
return { ...page(data), totalCount: data.length };
|
|
537
630
|
}
|
|
538
631
|
const UNMODELLED_PROFILE = { provider: "sanity", createdAt: (/* @__PURE__ */ new Date(0)).toISOString() };
|
|
539
|
-
async function servePlatformRequest(ctx,
|
|
540
|
-
const { path } = request, queryStart =
|
|
632
|
+
async function servePlatformRequest(ctx, request) {
|
|
633
|
+
const { path } = request, queryStart = request.url.indexOf("?"), query = new URLSearchParams(queryStart === -1 ? "" : request.url.slice(queryStart + 1));
|
|
634
|
+
if (path === ORGANIZATION_STORES_PATH)
|
|
635
|
+
return {
|
|
636
|
+
value: serveOrganizationStore({
|
|
637
|
+
stores: ctx.organizationStores,
|
|
638
|
+
organizationIds: ctx.organizationId === void 0 ? [] : [ctx.organizationId],
|
|
639
|
+
session: ctx.populusSession(),
|
|
640
|
+
request,
|
|
641
|
+
query
|
|
642
|
+
})
|
|
643
|
+
};
|
|
644
|
+
const myAttributes = path.match(MY_ATTRIBUTES_PATH);
|
|
541
645
|
if (myAttributes !== null) {
|
|
542
646
|
const organizationId = decodeURIComponent(myAttributes[1]);
|
|
543
647
|
return serveMyAttributes({ ctx, request, organizationId, query });
|
|
@@ -1028,7 +1132,7 @@ function makeRequestImpl(ctx) {
|
|
|
1028
1132
|
identities: listIdentities(),
|
|
1029
1133
|
organizationId
|
|
1030
1134
|
});
|
|
1031
|
-
const served = path === void 0 ? void 0 : await servePlatformRequest(platform,
|
|
1135
|
+
const served = path === void 0 ? void 0 : await servePlatformRequest(platform, requestFor(opts));
|
|
1032
1136
|
if (served !== void 0) return served.value;
|
|
1033
1137
|
throw fakeError(
|
|
1034
1138
|
`request(): no handler for path "${path}". With access control configured, the fake serves "/users/me", the handle's ACL ("<data base>/acl"), "/projects/<projectId>" (members), "/projects/<projectId>/users/<ids>", "/projects/<projectId>/roles", "/projects/<projectId>/features", the History API (client.getDataUrl("history", \u2026)), resource lookup ("/media-libraries/<id>", "/canvases/<id>", "/dashboards/<id>") and the Access API ("/access/<type>/<id>/roles[/<name>] | users[/<id>] | robots[/<id>] | user-permissions/me[/check]") and the caller's attributes ("/organizations/<id>/users/me/attributes"). For any other endpoint, register a stub (client.stub("request", fn)) or intercept the HTTP call with a tool like MSW.`
|
|
@@ -1945,9 +2049,11 @@ function jwtError(token, keys) {
|
|
|
1945
2049
|
function identityOf(claims) {
|
|
1946
2050
|
const unmodelledClaims = UNMODELLED_CLAIMS.filter((key) => key in claims);
|
|
1947
2051
|
if (unmodelledClaims.length > 0)
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
2052
|
+
return {
|
|
2053
|
+
identity: { user: { id: "" }, grants: [] },
|
|
2054
|
+
expiresAt: void 0,
|
|
2055
|
+
unmodelled: `internal token: the Content Lake reads the ${unmodelledClaims.map((key) => `"${key}"`).join(", ")} claim(s), which the fake does not model; it reads "i", "g" and "x".`
|
|
2056
|
+
};
|
|
1951
2057
|
const { i: id, g: grantList = [], x: rawExpiry } = claims;
|
|
1952
2058
|
let expiresAt;
|
|
1953
2059
|
if (rawExpiry != null) {
|
|
@@ -1984,6 +2090,32 @@ function checkInternalToken(token, keys) {
|
|
|
1984
2090
|
const parsed = jwtError(token, keys);
|
|
1985
2091
|
return "error" in parsed ? { refused: `invalid JWT token ${quoted(token)}: ${parsed.error}` } : identityOf(parsed.claims);
|
|
1986
2092
|
}
|
|
2093
|
+
function populusSession(token, keys) {
|
|
2094
|
+
const [headerSegment, claimsSegment, signatureSegment] = token.split(".");
|
|
2095
|
+
if (signatureSegment.trim() === "") {
|
|
2096
|
+
const decoded = [headerSegment, claimsSegment].map(decodeSegment);
|
|
2097
|
+
if (decoded.some((bytes) => typeof bytes == "string"))
|
|
2098
|
+
throw fakeError(
|
|
2099
|
+
"internal token: a segment is not base64url; jsonwebtoken's answer to it is not modelled."
|
|
2100
|
+
);
|
|
2101
|
+
return decoded.forEach(
|
|
2102
|
+
(bytes, index) => jsonObject(bytes, index === 0 ? "header" : "claims segment")
|
|
2103
|
+
), { refused: "jwt signature is required" };
|
|
2104
|
+
}
|
|
2105
|
+
const parsed = jwtError(token, keys);
|
|
2106
|
+
if ("error" in parsed) {
|
|
2107
|
+
if (parsed.error === "crypto/rsa: verification error") return { refused: "invalid signature" };
|
|
2108
|
+
throw fakeError(
|
|
2109
|
+
`internal token: populus refuses it with jsonwebtoken's 401 (gradient's reason: ${parsed.error}), whose message the fake does not model.`
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
const { tokenType, x } = parsed.claims;
|
|
2113
|
+
if (x != null && typeof x != "number")
|
|
2114
|
+
throw fakeError(
|
|
2115
|
+
`internal token: "x" must be a number of epoch seconds; got ${JSON.stringify(x)}.`
|
|
2116
|
+
);
|
|
2117
|
+
return x && x < Math.ceil(Date.now() / 1e3) ? { refused: "Session expired" } : { tokenType };
|
|
2118
|
+
}
|
|
1987
2119
|
function goTime(epochSeconds) {
|
|
1988
2120
|
const date = new Date(epochSeconds * 1e3);
|
|
1989
2121
|
if (Number.isNaN(date.getTime()) || date.getUTCFullYear() < 1e3)
|
|
@@ -2272,11 +2404,30 @@ function seedEntry(registry, resource, documents) {
|
|
|
2272
2404
|
const entry = ensureEntry(registry, resource);
|
|
2273
2405
|
entry.store.seed(documents), entry.exists = !0;
|
|
2274
2406
|
}
|
|
2407
|
+
function seedOrganizationStores(options) {
|
|
2408
|
+
const seeded = Object.entries(options.organizationStores ?? {}), unserved = seeded.find(([, status]) => status !== "provisioning" && status !== "active");
|
|
2409
|
+
if (unserved !== void 0)
|
|
2410
|
+
throw fakeError(
|
|
2411
|
+
`createTestClient(): \`organizationStores\` seeds "${unserved[0]}" as ${JSON.stringify(unserved[1])}; populus serves only "provisioning" and "active" stores.`
|
|
2412
|
+
);
|
|
2413
|
+
const stray = seeded.find(([organizationId]) => organizationId !== options.organizationId);
|
|
2414
|
+
if (stray !== void 0)
|
|
2415
|
+
throw fakeError(
|
|
2416
|
+
`createTestClient(): \`organizationStores\` has a store for "${stray[0]}", which is not the configured \`organizationId\`; populus creates stores only for organizations it has.`
|
|
2417
|
+
);
|
|
2418
|
+
return new Map(
|
|
2419
|
+
seeded.map(([organizationId, status]) => [
|
|
2420
|
+
organizationId,
|
|
2421
|
+
{ id: organizationStoreId(organizationId), organizationId, status }
|
|
2422
|
+
])
|
|
2423
|
+
);
|
|
2424
|
+
}
|
|
2275
2425
|
function createTestClient(options = {}) {
|
|
2276
2426
|
const defaultProjectId = options.projectId ?? DEFAULT_PROJECT_ID, defaultDataset = options.dataset ?? DEFAULT_DATASET, backend = {
|
|
2277
2427
|
registry: /* @__PURE__ */ new Map(),
|
|
2278
2428
|
organizationId: options.organizationId,
|
|
2279
2429
|
projectFeatures: options.projectFeatures ?? {},
|
|
2430
|
+
organizationStores: seedOrganizationStores(options),
|
|
2280
2431
|
log: [],
|
|
2281
2432
|
stubs: /* @__PURE__ */ new Map(),
|
|
2282
2433
|
calls: [],
|
|
@@ -2408,7 +2559,7 @@ function makeHandle(handleArgs) {
|
|
|
2408
2559
|
if (access === void 0)
|
|
2409
2560
|
throw fakeError("this handle has no acting identity (no token or accessControl bound).");
|
|
2410
2561
|
return access;
|
|
2411
|
-
}, projectHosted = useProjectHostname && resource === void 0,
|
|
2562
|
+
}, projectHosted = useProjectHostname && resource === void 0, refuseSession2 = (request) => {
|
|
2412
2563
|
if (token === void 0 || internal() !== void 0) return;
|
|
2413
2564
|
if (backend.revoked.has(token)) throw sessionNotFound(request);
|
|
2414
2565
|
const tokenProjectId = backend.identities.get(token)?.projectId;
|
|
@@ -2421,15 +2572,15 @@ function makeHandle(handleArgs) {
|
|
|
2421
2572
|
if (refusal !== void 0) throw refusal;
|
|
2422
2573
|
}, withSession = (request) => async (opts) => {
|
|
2423
2574
|
const sent = rawRequest(opts);
|
|
2424
|
-
if (internal() !== void 0 && servedByProjectApi(sent.path))
|
|
2575
|
+
if (internal() !== void 0 && servedByProjectApi(sent.path) && sent.path !== ORGANIZATION_STORES_PATH)
|
|
2425
2576
|
throw fakeError(
|
|
2426
2577
|
`request(): "${sent.path}" with an internal token. The project API (populus) verifies internal tokens with its own key and answers differently from the Content Lake; the fake does not model that. Use a registered identity's token there.`
|
|
2427
2578
|
);
|
|
2428
|
-
if (
|
|
2579
|
+
if (refuseSession2(sent), backend.outages.has("project-api") && servedByProjectApi(sent.path))
|
|
2429
2580
|
throw projectApiDown(sent);
|
|
2430
2581
|
return request(opts);
|
|
2431
2582
|
}, admitToLake = (request) => {
|
|
2432
|
-
if (
|
|
2583
|
+
if (refuseSession2(request), missingKey !== void 0) {
|
|
2433
2584
|
const parts = datasetParts(target.id);
|
|
2434
2585
|
throw datasetNotFound(request, parts.projectId, parts.dataset);
|
|
2435
2586
|
}
|
|
@@ -2486,7 +2637,18 @@ function makeHandle(handleArgs) {
|
|
|
2486
2637
|
["skipCrossDatasetReferenceValidation", options.skipCrossDatasetReferenceValidation]
|
|
2487
2638
|
]
|
|
2488
2639
|
});
|
|
2489
|
-
}, rawRequest = (opts) =>
|
|
2640
|
+
}, rawRequest = (opts) => {
|
|
2641
|
+
if (opts.query !== void 0 && "tag" in opts.query)
|
|
2642
|
+
throw fakeError("request(): pass the request tag as `tag`, not in `query`.");
|
|
2643
|
+
return platformRequest({
|
|
2644
|
+
method: "GET",
|
|
2645
|
+
uri: opts.uri ?? opts.url ?? "",
|
|
2646
|
+
tag: opts.tag,
|
|
2647
|
+
query: Object.entries(opts.query ?? {}).flatMap(
|
|
2648
|
+
([key, value]) => (Array.isArray(value) ? value : [value]).map((one) => [key, one])
|
|
2649
|
+
)
|
|
2650
|
+
});
|
|
2651
|
+
}, members = () => [
|
|
2490
2652
|
...backend.identities.values(),
|
|
2491
2653
|
...token === void 0 && accessControl !== void 0 ? [
|
|
2492
2654
|
{
|
|
@@ -2688,7 +2850,7 @@ function makeHandle(handleArgs) {
|
|
|
2688
2850
|
tag,
|
|
2689
2851
|
canUseCdn: !1
|
|
2690
2852
|
});
|
|
2691
|
-
if (
|
|
2853
|
+
if (refuseSession2(request), capabilities.actions !== "served") throw capabilities.actions(request);
|
|
2692
2854
|
return write(async () => {
|
|
2693
2855
|
for (const action of Array.isArray(actions) ? actions : [actions]) {
|
|
2694
2856
|
const refused = capabilities.refusedActions[action.actionType];
|
|
@@ -2924,6 +3086,9 @@ function makeHandle(handleArgs) {
|
|
|
2924
3086
|
apiVersion,
|
|
2925
3087
|
organizationId: backend.organizationId,
|
|
2926
3088
|
projectFeatures: backend.projectFeatures,
|
|
3089
|
+
organizationStores: backend.organizationStores,
|
|
3090
|
+
// A registered identity's session is a user or robot session, never a service one.
|
|
3091
|
+
populusSession: () => token === void 0 || internal() === void 0 ? { tokenType: void 0 } : populusSession(token, backend.internalTokenKeys),
|
|
2927
3092
|
own: (asked) => registryKey(asked) === registryKey(target) ? {
|
|
2928
3093
|
grants: requireActiveAccess().grants,
|
|
2929
3094
|
documents: () => store.all(),
|
|
@@ -3012,6 +3177,7 @@ function makeHandle(handleArgs) {
|
|
|
3012
3177
|
simulateOutage: (component) => {
|
|
3013
3178
|
backend.outages.add(component);
|
|
3014
3179
|
},
|
|
3180
|
+
completeOrganizationStoreProvisioning: (organizationId) => completeProvisioning(backend.organizationStores, organizationId),
|
|
3015
3181
|
mutations: () => backend.log.flatMap((entry) => entry.mutations),
|
|
3016
3182
|
transactions: () => [...backend.log],
|
|
3017
3183
|
clearLog: () => {
|