@powerhousedao/reactor-api 6.2.3-dev.77 → 6.2.3-dev.78
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/dist/{base-document-models-Dh70m9Bh.mjs → base-document-models-By4P20-z.mjs} +4 -4
- package/dist/{base-document-models-Dh70m9Bh.mjs.map → base-document-models-By4P20-z.mjs.map} +1 -1
- package/dist/{error-info-CCQcLAcW.mjs → error-info-BaEL50f5.mjs} +68 -6
- package/dist/error-info-BaEL50f5.mjs.map +1 -0
- package/dist/index.d.mts +203 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1024 -859
- package/dist/index.mjs.map +1 -1
- package/dist/{package-subgraph-check-DhCWO3YR.mjs → package-subgraph-check-6tK9LMg1.mjs} +4 -4
- package/dist/{package-subgraph-check-DhCWO3YR.mjs.map → package-subgraph-check-6tK9LMg1.mjs.map} +1 -1
- package/dist/{pglite-node-BMux5A2Y.mjs → pglite-node-DOFZDYCK.mjs} +4 -4
- package/dist/pglite-node-DOFZDYCK.mjs.map +1 -0
- package/dist/src/graphql/subgraph-types.mjs +1 -1
- package/dist/src/pglite/pglite-node.d.mts +38 -5
- package/dist/src/pglite/pglite-node.d.mts.map +1 -1
- package/dist/src/pglite/pglite-node.mjs +5 -5
- package/dist/src/pglite/worker/entry.mjs +1 -1
- package/package.json +13 -13
- package/dist/error-info-CCQcLAcW.mjs.map +0 -1
- package/dist/pglite-node-BMux5A2Y.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d978d340-82ad-56d2-8827-0daf9ed3bf67")}catch(e){}}();
|
|
3
3
|
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
4
4
|
import { A as CanonicalDocumentIdResolutionError, C as loadSubgraphs, D as RequestClientBinder, E as callerSubject, F as AuthEvaluationUnsupportedError, I as AuthenticationRequiredError, L as ForbiddenError, M as AuthorizationPolicy, N as AuthorizedDocumentHandle, O as AuthService, P as createAuthorizationService, R as MalformedStoredOperationError, S as loadProcessors, T as BaseSubgraph, _ as PACKAGE_MODULE_FAILED, c as piecesFromListModule, d as buildGraphQlDriveDocument, f as buildGraphqlOperation, g as runDetached, h as reportFailure, i as PIECE_SOURCE_LIST, j as createCanonicalDocumentIdResolver, k as createCredentialInvalidator, l as extractDocumentModels, m as isSubgraphClass, o as pieceListLocation, p as buildGraphqlOperations, s as piecesFromCdnList, t as extractSubgraphs, u as buildGraphQlDocument, v as debounce, w as manifestDeclaredSubgraphs, x as loadDocumentModels, y as extractUpgradeManifests, z as RefusalNotRecordedError } from "./subgraph-extraction-zUDn2zX_.mjs";
|
|
5
|
-
import { A as getDocumentModelSubgraphName, C as createMergedSchema, D as generateDocumentModelSchema, E as findSubgraphTypeCollisions, F as reservedTypeNamesTaken, I as typeDefinitionNames, L as schema_default$1, M as getGeneratedDocumentModelTypes, N as hasOperationSchemas, O as generatedTypesOf, P as reservedTypeNames, S as buildSubgraphSchemaModule, T as documentModelSubgraphTypes, _ as describeOwnershipConflicts, a as inspectionAdminTypeDefs, b as assembleSubgraphTypeDefs, c as HOST_ORIGIN, d as byClaimPriority, f as decideAdmission, g as collectSubgraphClaims, h as supergraphClaimLosers, i as inspectionTypeDefs, j as getDocumentModelTypeDefs, k as getDocumentModelSchemaName, l as RegistrationOrder, m as documentModelSubgraphSources, n as systemTypeDefs, o as CORE_ORIGIN, p as describeOrigin, r as schema_default$2, s as DOCUMENT_MODEL_ORIGIN, t as baseDocumentModels, u as admitDocumentModels, v as DocumentModelSchemaCache, w as createSchema, x as buildDocumentModelSchema, y as SubgraphTypeCollisionError } from "./base-document-models-
|
|
5
|
+
import { A as getDocumentModelSubgraphName, C as createMergedSchema, D as generateDocumentModelSchema, E as findSubgraphTypeCollisions, F as reservedTypeNamesTaken, I as typeDefinitionNames, L as schema_default$1, M as getGeneratedDocumentModelTypes, N as hasOperationSchemas, O as generatedTypesOf, P as reservedTypeNames, S as buildSubgraphSchemaModule, T as documentModelSubgraphTypes, _ as describeOwnershipConflicts, a as inspectionAdminTypeDefs, b as assembleSubgraphTypeDefs, c as HOST_ORIGIN, d as byClaimPriority, f as decideAdmission, g as collectSubgraphClaims, h as supergraphClaimLosers, i as inspectionTypeDefs, j as getDocumentModelTypeDefs, k as getDocumentModelSchemaName, l as RegistrationOrder, m as documentModelSubgraphSources, n as systemTypeDefs, o as CORE_ORIGIN, p as describeOrigin, r as schema_default$2, s as DOCUMENT_MODEL_ORIGIN, t as baseDocumentModels, u as admitDocumentModels, v as DocumentModelSchemaCache, w as createSchema, x as buildDocumentModelSchema, y as SubgraphTypeCollisionError } from "./base-document-models-By4P20-z.mjs";
|
|
6
6
|
import { n as createApolloFetchHandler } from "./adapter-gateway-apollo-D-EdZ4e-.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import { f as openCurrentPgliteForVerify, p as preparePgliteDataDir } from "./pglite-node-
|
|
7
|
+
import { a as resolvePgliteMaintenance, i as resolvePgliteFsync, m as PGLITE_UTC_PARSERS, r as createDurableNodeFs } from "./error-info-BaEL50f5.mjs";
|
|
8
|
+
import { f as openCurrentPgliteForVerify, p as preparePgliteDataDir } from "./pglite-node-DOFZDYCK.mjs";
|
|
9
9
|
import { findPackageJSON, isBuiltin } from "node:module";
|
|
10
10
|
import { AnalyticsQueryEngine } from "@powerhousedao/analytics-engine-core";
|
|
11
11
|
import { AnalyticsModel, AnalyticsResolvers, typedefs } from "@powerhousedao/analytics-engine-graphql";
|
|
@@ -20,9 +20,9 @@ import path, { isAbsolute, join } from "node:path";
|
|
|
20
20
|
import { match } from "path-to-regexp";
|
|
21
21
|
import posix from "node:path/posix";
|
|
22
22
|
import { Readable } from "node:stream";
|
|
23
|
-
import nodeFs, { existsSync, readFileSync, watchFile } from "node:fs";
|
|
24
23
|
import { pipeline } from "node:stream/promises";
|
|
25
24
|
import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
25
|
+
import nodeFs, { existsSync, readFileSync, watchFile } from "node:fs";
|
|
26
26
|
import { monitorEventLoopDelay } from "node:perf_hooks";
|
|
27
27
|
import { pathToFileURL } from "node:url";
|
|
28
28
|
import { camelCase } from "change-case";
|
|
@@ -402,133 +402,6 @@ const WS_AUTH_CLOSE_REASONS = [
|
|
|
402
402
|
WS_CLOSE_REASON_CREDENTIAL_REVOKED
|
|
403
403
|
];
|
|
404
404
|
//#endregion
|
|
405
|
-
//#region src/http/namespace.ts
|
|
406
|
-
/**
|
|
407
|
-
* A package's namespace is its npm name, used verbatim as one or two path
|
|
408
|
-
* segments. Nothing is slugged: dropping the scope, folding `.`/`_` to `-` or
|
|
409
|
-
* lower-casing would all map distinct package names onto one namespace, and a
|
|
410
|
-
* lossy mapping means two packages can silently claim the same URL space.
|
|
411
|
-
* Verbatim is injective, so there is no collision left to detect.
|
|
412
|
-
*/
|
|
413
|
-
/**
|
|
414
|
-
* npm's package-name grammar, per segment. Deliberately the same shape the HTTP
|
|
415
|
-
* package loader validates with, so a name that can be installed can be routed.
|
|
416
|
-
*/
|
|
417
|
-
const SEGMENT = /^[a-z0-9][-a-z0-9._]*$/i;
|
|
418
|
-
/** Segments that would read as path traversal rather than as a name. */
|
|
419
|
-
const TRAVERSAL = /* @__PURE__ */ new Set([".", ".."]);
|
|
420
|
-
var InvalidNamespaceError = class extends Error {};
|
|
421
|
-
/**
|
|
422
|
-
* Turns a package name into the path segments it occupies.
|
|
423
|
-
* `@powerhousedao/workflow` → ["@powerhousedao", "workflow"]
|
|
424
|
-
* `document-model` → ["document-model"]
|
|
425
|
-
*/
|
|
426
|
-
function namespaceSegments(packageName) {
|
|
427
|
-
if (!packageName) throw new InvalidNamespaceError("Package name is empty");
|
|
428
|
-
const scoped = packageName.startsWith("@");
|
|
429
|
-
const parts = (scoped ? packageName.slice(1) : packageName).split("/");
|
|
430
|
-
if (parts.length !== (scoped ? 2 : 1)) throw new InvalidNamespaceError(`"${packageName}" is not a package name: expected ${scoped ? "@scope/name" : "name"}`);
|
|
431
|
-
for (const part of parts) if (TRAVERSAL.has(part) || !SEGMENT.test(part)) throw new InvalidNamespaceError(`"${packageName}" contains a segment that is not a valid npm name part: "${part}"`);
|
|
432
|
-
return scoped ? [`@${parts[0]}`, parts[1]] : parts;
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* The path a package's routes hang off, relative to the package prefix.
|
|
436
|
-
* Scoped names occupy two segments — the addressing unpkg and jsdelivr use.
|
|
437
|
-
*/
|
|
438
|
-
function namespacePath(packageName) {
|
|
439
|
-
return namespaceSegments(packageName).join("/");
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* The same path with the leading `@` percent-encoded. Both routers match the
|
|
443
|
-
* raw pathname, so a client that percent-encodes each segment would otherwise
|
|
444
|
-
* 404. Registering both spellings avoids decoding the pathname before matching,
|
|
445
|
-
* which would turn `%2f` into `/` and let a crafted URL cross segment
|
|
446
|
-
* boundaries. `%40` cannot introduce a boundary, which is what makes this safe.
|
|
447
|
-
*/
|
|
448
|
-
function encodedNamespacePath(packageName) {
|
|
449
|
-
const path = namespacePath(packageName);
|
|
450
|
-
return path.startsWith("@") ? `%40${path.slice(1)}` : void 0;
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* A route path a package supplied. Must be relative and must not climb out of
|
|
454
|
-
* the scope.
|
|
455
|
-
*/
|
|
456
|
-
function assertRelativeRoutePath(path) {
|
|
457
|
-
if (path.startsWith("/")) throw new InvalidNamespaceError(`Route path "${path}" must be relative to the scope, not absolute`);
|
|
458
|
-
if (/^[a-z][a-z0-9+.-]*:/i.test(path)) throw new InvalidNamespaceError(`Route path "${path}" must be a path, not a URL`);
|
|
459
|
-
if (path.split("/").some((segment) => TRAVERSAL.has(segment))) throw new InvalidNamespaceError(`Route path "${path}" must not contain "." or ".." segments`);
|
|
460
|
-
return path.replace(/^\/+|\/+$/g, "");
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Resolves the npm name a package is routed under from the key the package
|
|
464
|
-
* manager holds it by. That key is the specifier as configured, which is not
|
|
465
|
-
* always a name:
|
|
466
|
-
* - `@scope/pkg` — already a name.
|
|
467
|
-
* - `@scope/pkg@1.3.9` — a registry spec; only the loader strips the tag.
|
|
468
|
-
* - `/Users/me/project` — the local project, which switchboard registers by
|
|
469
|
-
* `process.cwd()`. Its real name lives in its package.json.
|
|
470
|
-
*
|
|
471
|
-
* Deriving a URL segment straight from the key would give a developer's home
|
|
472
|
-
* directory a route namespace, so the path form is resolved rather than slugged.
|
|
473
|
-
*/
|
|
474
|
-
function resolvePackageName(key, readPackageJsonName = defaultReadName) {
|
|
475
|
-
const withoutVersion = stripVersionSpec(key);
|
|
476
|
-
if (isPackageName(withoutVersion)) return withoutVersion;
|
|
477
|
-
if (key.startsWith("/") || key.startsWith(".")) {
|
|
478
|
-
const name = readPackageJsonName(key);
|
|
479
|
-
if (name && isPackageName(name)) return name;
|
|
480
|
-
throw new InvalidNamespaceError(`Package at "${key}" has no usable name in its package.json, so it cannot host routes`);
|
|
481
|
-
}
|
|
482
|
-
throw new InvalidNamespaceError(`"${key}" is not a package name and not a path, so it cannot host routes`);
|
|
483
|
-
}
|
|
484
|
-
function isPackageName(value) {
|
|
485
|
-
try {
|
|
486
|
-
namespaceSegments(value);
|
|
487
|
-
return true;
|
|
488
|
-
} catch {
|
|
489
|
-
return false;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
/** `@scope/pkg@1.3.9` → `@scope/pkg`; `pkg@1.0.0` → `pkg`. */
|
|
493
|
-
function stripVersionSpec(key) {
|
|
494
|
-
const at = key.lastIndexOf("@");
|
|
495
|
-
if (at <= 0) return key;
|
|
496
|
-
return key.slice(0, at);
|
|
497
|
-
}
|
|
498
|
-
function defaultReadName(dir) {
|
|
499
|
-
try {
|
|
500
|
-
const raw = readFileSync(join(dir, "package.json"), "utf8");
|
|
501
|
-
const parsed = JSON.parse(raw);
|
|
502
|
-
return typeof parsed.name === "string" ? parsed.name : void 0;
|
|
503
|
-
} catch {
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* A mount path the host named for one of its own route groups.
|
|
509
|
-
*
|
|
510
|
-
* The host owns the whole URL space — it holds the adapter — so unlike a
|
|
511
|
-
* package it may name an absolute path. That is the difference between hosting
|
|
512
|
-
* and being hosted, and it is why this lives on the service rather than on a
|
|
513
|
-
* scope: a package is only ever handed a scope, and a scope has no way to
|
|
514
|
-
* express a path outside itself.
|
|
515
|
-
*
|
|
516
|
-
* What the host still may not name is anything that is not one stable literal
|
|
517
|
-
* prefix. A traversal segment, or a pattern segment, would make the group's own
|
|
518
|
-
* routes unpredictable relative to each other. Returns the normalized path,
|
|
519
|
-
* with a leading and no trailing slash.
|
|
520
|
-
*/
|
|
521
|
-
function assertHostMountPath(path) {
|
|
522
|
-
if (!path.startsWith("/")) throw new InvalidNamespaceError(`Host mount path "${path}" must be absolute, e.g. "/webhooks"`);
|
|
523
|
-
const segments = path.split("/").filter((segment) => segment.length > 0);
|
|
524
|
-
if (segments.length === 0) throw new InvalidNamespaceError(`Host mount path "${path}" is the whole URL space, which is the adapter rather than a scope of it`);
|
|
525
|
-
for (const segment of segments) {
|
|
526
|
-
if (TRAVERSAL.has(segment)) throw new InvalidNamespaceError(`Host mount path "${path}" must not contain "." or ".." segments`);
|
|
527
|
-
if (segment.startsWith(":") || segment.includes("*")) throw new InvalidNamespaceError(`Host mount path "${path}" must be a literal prefix, not a pattern: "${segment}"`);
|
|
528
|
-
}
|
|
529
|
-
return `/${segments.join("/")}`;
|
|
530
|
-
}
|
|
531
|
-
//#endregion
|
|
532
405
|
//#region src/http/node-response.ts
|
|
533
406
|
/** Converts Node incoming headers to Fetch Headers. */
|
|
534
407
|
function fetchHeaders(req) {
|
|
@@ -631,744 +504,877 @@ function writeError(res, status, message) {
|
|
|
631
504
|
res.setHeader("content-length", Buffer.byteLength(body));
|
|
632
505
|
res.end(body);
|
|
633
506
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const DEFAULT_MAX_BODY_BYTES$1 = 1048576;
|
|
643
|
-
const ANONYMOUS = {
|
|
644
|
-
user: void 0,
|
|
645
|
-
authEnabled: false
|
|
507
|
+
/** Header each scheme reads when the caller does not name one: the name the format is
|
|
508
|
+
* most often carried in, not a property of it, so `WebhookVerification.header` overrides any of them. */
|
|
509
|
+
const DEFAULT_SCHEME_HEADER = {
|
|
510
|
+
none: "",
|
|
511
|
+
token: "x-webhook-token",
|
|
512
|
+
hmac: "x-signature",
|
|
513
|
+
"hmac-prefixed": "x-hub-signature-256",
|
|
514
|
+
"hmac-timestamped": "stripe-signature"
|
|
646
515
|
};
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
/** A scope at a host-named path; on the service, not `IHttpScope`, so a package can never name one. Namespacing is package
|
|
685
|
-
* policy: the host owns its URL space and third parties hold its URLs, so the path is verbatim and outside the package prefix. */
|
|
686
|
-
hostScope(name, mountPath) {
|
|
687
|
-
const base = assertHostMountPath(mountPath);
|
|
688
|
-
if (base === this.#prefix || base.startsWith(`${this.#prefix}/`)) throw new InvalidNamespaceError(`Host scope "${name}" cannot mount at "${base}": that is the package route prefix, which packages own`);
|
|
689
|
-
return this.#scope({
|
|
690
|
-
owner: name,
|
|
691
|
-
base,
|
|
692
|
-
encodedBase: void 0,
|
|
693
|
-
claim: `the mount path "${base}"`,
|
|
694
|
-
webhooks: void 0,
|
|
695
|
-
onDispose: () => void 0
|
|
696
|
-
});
|
|
516
|
+
const OK = { ok: true };
|
|
517
|
+
/** Constant-time over equal-length inputs; a length mismatch is already a rejection, so
|
|
518
|
+
* the early return leaks nothing a caller could not measure. */
|
|
519
|
+
function secureEquals(a, b) {
|
|
520
|
+
const left = Buffer.from(a, "utf8");
|
|
521
|
+
const right = Buffer.from(b, "utf8");
|
|
522
|
+
if (left.length !== right.length) return false;
|
|
523
|
+
return timingSafeEqual(left, right);
|
|
524
|
+
}
|
|
525
|
+
function hmacDigest(secret, payload, verification) {
|
|
526
|
+
return createHmac(verification.algorithm ?? "sha256", secret).update(payload).digest(verification.encoding ?? "hex");
|
|
527
|
+
}
|
|
528
|
+
/** Hex folds case, so an uppercased digest still verifies. Base64 must not: two distinct
|
|
529
|
+
* digests can differ only in case, so folding there would accept a signature that is not the one computed. */
|
|
530
|
+
function digestEquals(presented, expected, verification) {
|
|
531
|
+
const candidate = presented.trim();
|
|
532
|
+
if ((verification.encoding ?? "hex") === "base64") return secureEquals(candidate, expected);
|
|
533
|
+
return secureEquals(candidate.toLowerCase(), expected.toLowerCase());
|
|
534
|
+
}
|
|
535
|
+
/** The label `hmac-prefixed` expects before the digest. */
|
|
536
|
+
function signaturePrefix(verification) {
|
|
537
|
+
return verification.prefix ?? `${verification.algorithm ?? "sha256"}=`;
|
|
538
|
+
}
|
|
539
|
+
/** `t=<unix>,v1=<hex>[,v1=<hex>…]`. Several `v1` values appear while a secret is being
|
|
540
|
+
* rotated, and any one of them matching is a pass. */
|
|
541
|
+
function parseTimestampedHeader(value) {
|
|
542
|
+
const signatures = [];
|
|
543
|
+
let timestamp;
|
|
544
|
+
for (const part of value.split(",")) {
|
|
545
|
+
const separator = part.indexOf("=");
|
|
546
|
+
if (separator < 0) continue;
|
|
547
|
+
const key = part.slice(0, separator).trim();
|
|
548
|
+
const item = part.slice(separator + 1).trim();
|
|
549
|
+
if (key === "t") timestamp = Number(item);
|
|
550
|
+
else if (key === "v1") signatures.push(item);
|
|
697
551
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
552
|
+
return {
|
|
553
|
+
timestamp,
|
|
554
|
+
signatures
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
function schemeHeader(verification) {
|
|
558
|
+
return (verification.header ?? DEFAULT_SCHEME_HEADER[verification.scheme]).toLowerCase();
|
|
559
|
+
}
|
|
560
|
+
/** Verifies a delivery against the configured scheme; `raw` must be the exact bytes
|
|
561
|
+
* received. The reason is for the log only: callers answer a fixed 401, so a probing sender learns nothing from the body. */
|
|
562
|
+
function verifyWebhook(options) {
|
|
563
|
+
const { verification, headers, raw } = options;
|
|
564
|
+
if (verification.scheme === "none") return OK;
|
|
565
|
+
if (!verification.secret) return {
|
|
566
|
+
ok: false,
|
|
567
|
+
reason: "signing secret missing"
|
|
568
|
+
};
|
|
569
|
+
const header = schemeHeader(verification);
|
|
570
|
+
const presented = headers[header];
|
|
571
|
+
if (!presented) return {
|
|
572
|
+
ok: false,
|
|
573
|
+
reason: `header "${header}" absent`
|
|
574
|
+
};
|
|
575
|
+
const secret = verification.secret;
|
|
576
|
+
const tolerance = verification.toleranceSeconds ?? 300;
|
|
577
|
+
switch (verification.scheme) {
|
|
578
|
+
case "token": return secureEquals(presented, secret) ? OK : {
|
|
579
|
+
ok: false,
|
|
580
|
+
reason: "token mismatch"
|
|
581
|
+
};
|
|
582
|
+
case "hmac": return digestEquals(presented, hmacDigest(secret, raw, verification), verification) ? OK : {
|
|
583
|
+
ok: false,
|
|
584
|
+
reason: "hmac mismatch"
|
|
585
|
+
};
|
|
586
|
+
case "hmac-prefixed": return digestEquals(presented, `${signaturePrefix(verification)}${hmacDigest(secret, raw, verification)}`, verification) ? OK : {
|
|
587
|
+
ok: false,
|
|
588
|
+
reason: "hmac mismatch"
|
|
589
|
+
};
|
|
590
|
+
case "hmac-timestamped": {
|
|
591
|
+
const { timestamp, signatures } = parseTimestampedHeader(presented);
|
|
592
|
+
if (timestamp === void 0 || !Number.isFinite(timestamp)) return {
|
|
593
|
+
ok: false,
|
|
594
|
+
reason: "no timestamp in the signature header"
|
|
595
|
+
};
|
|
596
|
+
if (signatures.length === 0) return {
|
|
597
|
+
ok: false,
|
|
598
|
+
reason: "no v1 signature in the header"
|
|
599
|
+
};
|
|
600
|
+
const nowMs = (options.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
601
|
+
if (Math.abs(nowMs / 1e3 - timestamp) > tolerance) return {
|
|
602
|
+
ok: false,
|
|
603
|
+
reason: "timestamp outside the replay window"
|
|
604
|
+
};
|
|
605
|
+
const expected = hmacDigest(secret, Buffer.concat([Buffer.from(`${timestamp}.`, "utf8"), raw]), verification);
|
|
606
|
+
let matched = false;
|
|
607
|
+
for (const signature of signatures) if (digestEquals(signature, expected, verification)) matched = true;
|
|
608
|
+
return matched ? OK : {
|
|
609
|
+
ok: false,
|
|
610
|
+
reason: "hmac mismatch"
|
|
611
|
+
};
|
|
733
612
|
}
|
|
734
613
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
614
|
+
}
|
|
615
|
+
/** Headers that would put a credential in a log or run journal. The configured signature
|
|
616
|
+
* header joins them: it is an HMAC of the body under a live secret. */
|
|
617
|
+
const REDACTED_HEADERS = /* @__PURE__ */ new Set([
|
|
618
|
+
"authorization",
|
|
619
|
+
"proxy-authorization",
|
|
620
|
+
"cookie",
|
|
621
|
+
"set-cookie",
|
|
622
|
+
"x-api-key",
|
|
623
|
+
"x-webhook-token",
|
|
624
|
+
"x-signature",
|
|
625
|
+
"x-hub-signature",
|
|
626
|
+
"x-hub-signature-256",
|
|
627
|
+
"stripe-signature"
|
|
628
|
+
]);
|
|
629
|
+
const REDACTED = "[redacted]";
|
|
630
|
+
function redactHeaders(headers, extra) {
|
|
631
|
+
const redacted = {};
|
|
632
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
633
|
+
const key = name.toLowerCase();
|
|
634
|
+
redacted[key] = REDACTED_HEADERS.has(key) || extra && key === extra.toLowerCase() ? REDACTED : value;
|
|
743
635
|
}
|
|
744
|
-
|
|
745
|
-
|
|
636
|
+
return redacted;
|
|
637
|
+
}
|
|
638
|
+
/** JSON and form bodies become objects; anything else stays decoded text, so a verified
|
|
639
|
+
* XML or CSV payload is still reachable downstream. */
|
|
640
|
+
function parseWebhookBody(raw, contentType) {
|
|
641
|
+
if (raw.length === 0) return void 0;
|
|
642
|
+
const type = (contentType ?? "").split(";")[0].trim().toLowerCase();
|
|
643
|
+
const text = raw.toString("utf8");
|
|
644
|
+
if (type === "application/json" || type.endsWith("+json")) try {
|
|
645
|
+
return JSON.parse(text);
|
|
646
|
+
} catch {
|
|
647
|
+
return text;
|
|
746
648
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
649
|
+
if (type === "application/x-www-form-urlencoded") return Object.fromEntries(new URLSearchParams(text));
|
|
650
|
+
return text;
|
|
651
|
+
}
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region src/http/webhook-service.ts
|
|
654
|
+
const logger$2 = childLogger(["reactor-api", "webhooks"]);
|
|
655
|
+
/** The flat, token-addressed path family. */
|
|
656
|
+
const WEBHOOK_SEGMENT = "webhooks";
|
|
657
|
+
const DEFAULT_MAX_BODY_BYTES$1 = 1048576;
|
|
658
|
+
const DEFAULT_DEDUPE_TTL_SECONDS = 300;
|
|
659
|
+
function readPublicOrigin(origin) {
|
|
660
|
+
return (typeof origin === "function" ? origin() : origin).replace(/\/+$/, "");
|
|
661
|
+
}
|
|
662
|
+
/** One host route for `/webhooks/:token`, dispatching by token. The flat path leaks
|
|
663
|
+
* neither package nor document; the namespace lives in the token record, which is also what stops one package's token reaching another's handler. */
|
|
664
|
+
var WebhookService = class {
|
|
665
|
+
#store;
|
|
666
|
+
#path;
|
|
751
667
|
#publicUrl;
|
|
752
|
-
#
|
|
753
|
-
#encodedBase;
|
|
754
|
-
#adapter;
|
|
755
|
-
#authService;
|
|
756
|
-
#onDispose;
|
|
668
|
+
#scope;
|
|
757
669
|
#registrations = /* @__PURE__ */ new Map();
|
|
758
|
-
#
|
|
759
|
-
constructor(
|
|
760
|
-
this
|
|
761
|
-
this.#
|
|
762
|
-
this.#publicUrl =
|
|
763
|
-
this.#trustProxy = options.trustProxy;
|
|
764
|
-
this.#encodedBase = options.encodedBase;
|
|
765
|
-
this.#adapter = options.adapter;
|
|
766
|
-
this.#authService = options.authService;
|
|
767
|
-
this.#onDispose = options.onDispose;
|
|
768
|
-
this.#webhooks = options.webhooks ?? unavailableWebhooks(options.owner);
|
|
769
|
-
}
|
|
770
|
-
get baseUrl() {
|
|
771
|
-
return `${this.#publicUrl}${this.#base}`;
|
|
772
|
-
}
|
|
773
|
-
get webhooks() {
|
|
774
|
-
return this.#webhooks;
|
|
775
|
-
}
|
|
776
|
-
get(path, a, b) {
|
|
777
|
-
return this.#shorthand("GET", path, a, b);
|
|
778
|
-
}
|
|
779
|
-
post(path, a, b) {
|
|
780
|
-
return this.#shorthand("POST", path, a, b);
|
|
670
|
+
#routes = [];
|
|
671
|
+
constructor({ store, basePath = "/", publicUrl }) {
|
|
672
|
+
this.#store = store;
|
|
673
|
+
this.#path = posix.join("/", basePath, WEBHOOK_SEGMENT);
|
|
674
|
+
this.#publicUrl = publicUrl;
|
|
781
675
|
}
|
|
782
|
-
|
|
783
|
-
|
|
676
|
+
/** The scope the endpoint family serves from, handed over once the route service exists;
|
|
677
|
+
* separate from the constructor only because that service takes this one as an option. */
|
|
678
|
+
attach(scope) {
|
|
679
|
+
this.#scope = scope;
|
|
784
680
|
}
|
|
785
|
-
|
|
786
|
-
|
|
681
|
+
async init() {
|
|
682
|
+
await this.#store.init();
|
|
683
|
+
if (this.#routes.length) return;
|
|
684
|
+
if (!this.#scope) throw new Error("The webhook service has no HTTP scope; the host must call attach() before a package registers");
|
|
685
|
+
this.#routes = [this.#scope.nodeRoute({
|
|
686
|
+
method: [
|
|
687
|
+
"DELETE",
|
|
688
|
+
"GET",
|
|
689
|
+
"HEAD",
|
|
690
|
+
"PATCH",
|
|
691
|
+
"POST",
|
|
692
|
+
"PUT"
|
|
693
|
+
],
|
|
694
|
+
path: ":token",
|
|
695
|
+
auth: "public",
|
|
696
|
+
handler: (req, res, ctx) => void this.#deliver(req, res, ctx.params)
|
|
697
|
+
})];
|
|
787
698
|
}
|
|
788
|
-
|
|
789
|
-
|
|
699
|
+
dispose() {
|
|
700
|
+
for (const handle of this.#routes) handle.dispose();
|
|
701
|
+
this.#routes = [];
|
|
702
|
+
this.#registrations.clear();
|
|
790
703
|
}
|
|
791
|
-
|
|
792
|
-
|
|
704
|
+
/** The facade a package's HTTP scope exposes as `scope.webhooks`. */
|
|
705
|
+
scopeFor(namespace) {
|
|
706
|
+
return {
|
|
707
|
+
hasPublicOrigin: this.hasPublicOrigin,
|
|
708
|
+
register: async (spec) => {
|
|
709
|
+
await this.init();
|
|
710
|
+
const key = `${namespace}|${spec.name}`;
|
|
711
|
+
this.#registrations.set(key, {
|
|
712
|
+
namespace,
|
|
713
|
+
spec
|
|
714
|
+
});
|
|
715
|
+
return {
|
|
716
|
+
endpointFor: async (ownerKey) => {
|
|
717
|
+
const row = await this.#store.ensure(namespace, spec.name, ownerKey);
|
|
718
|
+
return {
|
|
719
|
+
token: row.token,
|
|
720
|
+
url: this.urlFor(row.token),
|
|
721
|
+
createdAt: row.createdAt
|
|
722
|
+
};
|
|
723
|
+
},
|
|
724
|
+
revoke: (ownerKey) => this.#store.revoke(namespace, spec.name, ownerKey),
|
|
725
|
+
list: async () => (await this.#store.list(namespace, spec.name)).map((row) => ({
|
|
726
|
+
key: row.ownerKey,
|
|
727
|
+
token: row.token,
|
|
728
|
+
url: this.urlFor(row.token),
|
|
729
|
+
createdAt: row.createdAt
|
|
730
|
+
}))
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
};
|
|
793
734
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
const
|
|
797
|
-
if (!handler) throw new Error(`Route ${method} ${path} was registered with no handler`);
|
|
798
|
-
return this.route({
|
|
799
|
-
...options,
|
|
800
|
-
method,
|
|
801
|
-
path,
|
|
802
|
-
handler
|
|
803
|
-
});
|
|
735
|
+
/** Releases every registration a package made. */
|
|
736
|
+
disposeScope(namespace) {
|
|
737
|
+
for (const [key, registration] of this.#registrations) if (registration.namespace === namespace) this.#registrations.delete(key);
|
|
804
738
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
739
|
+
/** The URL to hand a provider. Absolute whenever the host knows its own origin: a
|
|
740
|
+
* relative path is useless to the third party that has to call it. */
|
|
741
|
+
urlFor(token) {
|
|
742
|
+
const path = posix.join(this.#path, token);
|
|
743
|
+
return this.#publicUrl === void 0 ? path : `${readPublicOrigin(this.#publicUrl)}${path}`;
|
|
808
744
|
}
|
|
809
|
-
|
|
810
|
-
|
|
745
|
+
/** Whether `urlFor` can produce something a provider could call. */
|
|
746
|
+
get hasPublicOrigin() {
|
|
747
|
+
return this.#publicUrl !== void 0;
|
|
811
748
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
/** Mounts one route under this scope's namespace, in both the verbatim and the
|
|
818
|
-
* percent-encoded spelling of a scoped name. */
|
|
819
|
-
#register(spec, run) {
|
|
820
|
-
const relative = assertRelativeRoutePath(spec.path);
|
|
821
|
-
const methods = Array.isArray(spec.method) ? spec.method : [spec.method];
|
|
822
|
-
const routePath = relative ? posix.join(this.#base, relative) : this.#base;
|
|
823
|
-
const key = `${methods.join(",")} ${routePath}`;
|
|
824
|
-
if (this.#registrations.has(key)) throw new Error(`Route ${key} is already registered by "${this.owner}"`);
|
|
825
|
-
const handles = [];
|
|
826
|
-
const paths = [routePath];
|
|
827
|
-
if (this.#encodedBase) paths.push(relative ? posix.join(this.#encodedBase, relative) : this.#encodedBase);
|
|
828
|
-
for (const path of paths) for (const method of methods) handles.push(this.#adapter.mountNodeRoute(method, path, (req, res) => {
|
|
829
|
-
this.#guard(spec, req, res, run);
|
|
830
|
-
}, {
|
|
831
|
-
rawBody: true,
|
|
832
|
-
prefix: spec.prefix
|
|
833
|
-
}));
|
|
834
|
-
this.#registrations.set(key, {
|
|
835
|
-
path: routePath,
|
|
836
|
-
handles
|
|
837
|
-
});
|
|
838
|
-
logger$2.debug("Registered @route for @package", key, this.owner);
|
|
839
|
-
return {
|
|
840
|
-
url: `${this.#publicUrl}${routePath}`,
|
|
841
|
-
dispose: () => {
|
|
842
|
-
const registration = this.#registrations.get(key);
|
|
843
|
-
if (!registration) return;
|
|
844
|
-
for (const handle of registration.handles) handle.dispose();
|
|
845
|
-
this.#registrations.delete(key);
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
/** Authenticate, then run. */
|
|
850
|
-
async #guard(spec, req, res, run) {
|
|
851
|
-
try {
|
|
852
|
-
const actor = await this.#authenticate(spec.auth ?? "renown", req, res);
|
|
853
|
-
if (actor === REJECTED) return;
|
|
854
|
-
await run(req, res, {
|
|
855
|
-
params: routeParams(req),
|
|
856
|
-
user: actor?.user,
|
|
857
|
-
authEnabled: actor?.authEnabled ?? false,
|
|
858
|
-
transport: resolveTransport(req, this.#trustProxy)
|
|
859
|
-
});
|
|
860
|
-
} catch (error) {
|
|
861
|
-
logger$2.error("Route handler failed for @package", this.owner, error);
|
|
862
|
-
writeError(res, 500, "Internal server error");
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
/** Resolves the caller, answering the request itself when the route refuses it;
|
|
866
|
-
* returns REJECTED in that case so the caller stops. */
|
|
867
|
-
async #authenticate(auth, req, res) {
|
|
868
|
-
if (auth === "public") return void 0;
|
|
869
|
-
if (typeof auth === "function") {
|
|
870
|
-
const result = await auth(req);
|
|
871
|
-
if (!result.authorized) {
|
|
872
|
-
if ("response" in result) await writeResponse(res, result.response, req.method ?? "GET");
|
|
873
|
-
else writeError(res, result.status, result.message);
|
|
874
|
-
return REJECTED;
|
|
875
|
-
}
|
|
749
|
+
async #deliver(req, res, params) {
|
|
750
|
+
const token = params.token;
|
|
751
|
+
if (!token) {
|
|
752
|
+
writeError(res, 404, "Unknown endpoint");
|
|
876
753
|
return;
|
|
877
754
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
let init = {
|
|
901
|
-
method,
|
|
902
|
-
headers: fetchHeaders(req),
|
|
903
|
-
signal: controller.signal
|
|
904
|
-
};
|
|
905
|
-
if (method !== "GET" && method !== "HEAD" && body !== "none") {
|
|
906
|
-
if (body === "stream") init = {
|
|
907
|
-
...init,
|
|
908
|
-
body: Readable.toWeb(req),
|
|
909
|
-
duplex: "half"
|
|
755
|
+
try {
|
|
756
|
+
const row = await this.#store.find(token);
|
|
757
|
+
if (!row) {
|
|
758
|
+
writeError(res, 404, "Unknown endpoint");
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
const registrationKey = `${row.namespace}|${row.endpoint}`;
|
|
762
|
+
const registration = this.#registrations.get(registrationKey);
|
|
763
|
+
if (!registration) {
|
|
764
|
+
writeError(res, 503, "Endpoint temporarily unavailable");
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
const { spec } = registration;
|
|
768
|
+
const method = (req.method ?? "POST").toUpperCase();
|
|
769
|
+
const perEndpoint = spec.policyFor ? await spec.policyFor(row.ownerKey) : {};
|
|
770
|
+
if (!perEndpoint) {
|
|
771
|
+
writeError(res, 404, "Unknown endpoint");
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
const policy = {
|
|
775
|
+
...spec.defaults,
|
|
776
|
+
...perEndpoint
|
|
910
777
|
};
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
778
|
+
if (policy.methods && !policy.methods.includes(method)) {
|
|
779
|
+
writeError(res, 405, "Method not allowed");
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
let raw;
|
|
783
|
+
try {
|
|
784
|
+
raw = await readBody(req, policy.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES$1);
|
|
785
|
+
} catch (error) {
|
|
786
|
+
if (error instanceof BodyTooLargeError) {
|
|
787
|
+
res.setHeader("connection", "close");
|
|
788
|
+
res.once("finish", () => req.destroy());
|
|
789
|
+
writeError(res, 413, "Payload too large");
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
throw error;
|
|
793
|
+
}
|
|
794
|
+
const verification = policy.verify;
|
|
795
|
+
if (verification) {
|
|
796
|
+
const result = verifyWebhook({
|
|
797
|
+
verification,
|
|
798
|
+
headers: headerRecord(req),
|
|
799
|
+
raw
|
|
800
|
+
});
|
|
801
|
+
if (!result.ok) {
|
|
802
|
+
logger$2.warn("Rejected webhook delivery for @package/@endpoint: @reason", row.namespace, row.endpoint, result.reason);
|
|
803
|
+
writeError(res, 401, "Signature verification failed");
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
808
|
+
const queryParams = Object.fromEntries(url.searchParams);
|
|
809
|
+
const signatureHeader = verification ? schemeHeader(verification) : void 0;
|
|
810
|
+
const headers = headerRecord(req);
|
|
811
|
+
const body = parseWebhookBody(raw, headers["content-type"]);
|
|
812
|
+
const challenge = challengeValue(policy.challengeField, queryParams, headers, body);
|
|
813
|
+
if (challenge !== void 0) {
|
|
814
|
+
res.statusCode = 200;
|
|
815
|
+
res.setHeader("content-type", "text/plain");
|
|
816
|
+
res.end(challenge);
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
let recordedKey;
|
|
820
|
+
if (policy.dedupe) {
|
|
821
|
+
const key = dedupeKey(policy.dedupe.field, queryParams, headers, body);
|
|
822
|
+
recordedKey = key;
|
|
823
|
+
if (key !== void 0 && await this.#store.seen(token, key, policy.dedupe.ttlSeconds ?? DEFAULT_DEDUPE_TTL_SECONDS)) {
|
|
824
|
+
res.statusCode = 200;
|
|
825
|
+
res.end();
|
|
826
|
+
return;
|
|
922
827
|
}
|
|
923
|
-
if (raw.length) init = {
|
|
924
|
-
...init,
|
|
925
|
-
body: new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength)
|
|
926
|
-
};
|
|
927
828
|
}
|
|
829
|
+
const reply = await spec.onRequest({
|
|
830
|
+
key: row.ownerKey,
|
|
831
|
+
method,
|
|
832
|
+
path: url.pathname,
|
|
833
|
+
queryParams,
|
|
834
|
+
headers: redactHeaders(headers, signatureHeader),
|
|
835
|
+
raw,
|
|
836
|
+
body
|
|
837
|
+
});
|
|
838
|
+
if (reply.unprocessed === true && recordedKey !== void 0) try {
|
|
839
|
+
await this.#store.forget(token, recordedKey);
|
|
840
|
+
} catch (error) {
|
|
841
|
+
logger$2.warn("Could not forget an unprocessed webhook delivery: @error", error);
|
|
842
|
+
}
|
|
843
|
+
res.statusCode = reply.status;
|
|
844
|
+
if (reply.body !== void 0 && method !== "HEAD") {
|
|
845
|
+
res.setHeader("content-type", reply.contentType ?? "text/plain");
|
|
846
|
+
res.end(reply.body);
|
|
847
|
+
} else res.end();
|
|
848
|
+
} catch (error) {
|
|
849
|
+
logger$2.error("Webhook delivery failed for @method", req.method, error);
|
|
850
|
+
writeError(res, 500, "Internal server error");
|
|
928
851
|
}
|
|
929
|
-
await writeResponse(res, await spec.handler(new Request(url, init), {
|
|
930
|
-
...ctx,
|
|
931
|
-
rawBody: body === "raw" ? raw ?? Buffer.alloc(0) : void 0,
|
|
932
|
-
signal: controller.signal
|
|
933
|
-
}), method);
|
|
934
852
|
}
|
|
935
853
|
};
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
const
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
for (const [key, value] of Object.entries(params)) if (typeof value === "string") out[key] = value;
|
|
942
|
-
else if (Array.isArray(value)) out[key] = value.join("/");
|
|
943
|
-
return out;
|
|
944
|
-
}
|
|
945
|
-
/** Stands in for a package that cannot be routed — its key resolves to no npm name. Registering a route throws with
|
|
946
|
-
* the reason; nothing else does, so the package still loads and its non-HTTP behaviour is unaffected. */
|
|
947
|
-
var UnroutableScope = class {
|
|
948
|
-
owner;
|
|
949
|
-
baseUrl = "";
|
|
950
|
-
#reason;
|
|
951
|
-
constructor(packageKey, reason) {
|
|
952
|
-
this.owner = packageKey;
|
|
953
|
-
this.#reason = reason;
|
|
954
|
-
}
|
|
955
|
-
#refuse() {
|
|
956
|
-
throw new Error(`Package "${this.owner}" cannot host HTTP routes: ${this.#reason}`);
|
|
957
|
-
}
|
|
958
|
-
get() {
|
|
959
|
-
this.#refuse();
|
|
960
|
-
}
|
|
961
|
-
post() {
|
|
962
|
-
this.#refuse();
|
|
963
|
-
}
|
|
964
|
-
put() {
|
|
965
|
-
this.#refuse();
|
|
966
|
-
}
|
|
967
|
-
patch() {
|
|
968
|
-
this.#refuse();
|
|
969
|
-
}
|
|
970
|
-
delete() {
|
|
971
|
-
this.#refuse();
|
|
854
|
+
function headerRecord(req) {
|
|
855
|
+
const headers = {};
|
|
856
|
+
for (const [name, value] of Object.entries(req.headers)) {
|
|
857
|
+
if (value === void 0) continue;
|
|
858
|
+
headers[name.toLowerCase()] = Array.isArray(value) ? value.join(", ") : value;
|
|
972
859
|
}
|
|
973
|
-
|
|
974
|
-
|
|
860
|
+
return headers;
|
|
861
|
+
}
|
|
862
|
+
function scalar(value) {
|
|
863
|
+
if (typeof value === "string" && value !== "") return value;
|
|
864
|
+
if (typeof value === "number") return String(value);
|
|
865
|
+
}
|
|
866
|
+
/** Walks a dot-separated path into the parsed body. */
|
|
867
|
+
function bodyPath(path, body) {
|
|
868
|
+
let current = body;
|
|
869
|
+
for (const segment of path.split(".")) {
|
|
870
|
+
if (!current || typeof current !== "object") return void 0;
|
|
871
|
+
current = current[segment];
|
|
975
872
|
}
|
|
976
|
-
|
|
977
|
-
this.#refuse();
|
|
978
|
-
}
|
|
979
|
-
nodeRoute() {
|
|
980
|
-
this.#refuse();
|
|
981
|
-
}
|
|
982
|
-
get webhooks() {
|
|
983
|
-
return unavailableWebhooks(this.owner);
|
|
984
|
-
}
|
|
985
|
-
dispose() {}
|
|
986
|
-
};
|
|
987
|
-
/** Stands in when the host has no webhook store configured. */
|
|
988
|
-
function unavailableWebhooks(packageName) {
|
|
989
|
-
return {
|
|
990
|
-
hasPublicOrigin: false,
|
|
991
|
-
register: () => Promise.reject(/* @__PURE__ */ new Error(`Webhooks are not available on this host, so "${packageName}" cannot register one`))
|
|
992
|
-
};
|
|
873
|
+
return scalar(current);
|
|
993
874
|
}
|
|
994
|
-
/**
|
|
995
|
-
*
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
"
|
|
1001
|
-
"hmac-timestamped": "stripe-signature"
|
|
1002
|
-
};
|
|
1003
|
-
const OK = { ok: true };
|
|
1004
|
-
/** Constant-time over equal-length inputs; a length mismatch is already a rejection, so
|
|
1005
|
-
* the early return leaks nothing a caller could not measure. */
|
|
1006
|
-
function secureEquals(a, b) {
|
|
1007
|
-
const left = Buffer.from(a, "utf8");
|
|
1008
|
-
const right = Buffer.from(b, "utf8");
|
|
1009
|
-
if (left.length !== right.length) return false;
|
|
1010
|
-
return timingSafeEqual(left, right);
|
|
875
|
+
/** Resolves where a provider put a value. A bare string means query first, then a
|
|
876
|
+
* top-level body field; `{ header }` and `{ body }` reach what that cannot — GitHub's delivery id is a header, Stripe's event id is nested. */
|
|
877
|
+
function fieldValue(field, queryParams, headers, body) {
|
|
878
|
+
if (typeof field === "object") return "header" in field ? scalar(headers[field.header.toLowerCase()]) : bodyPath(field.body, body);
|
|
879
|
+
const fromQuery = scalar(queryParams[field]);
|
|
880
|
+
if (fromQuery !== void 0) return fromQuery;
|
|
881
|
+
return body && typeof body === "object" ? scalar(body[field]) : void 0;
|
|
1011
882
|
}
|
|
1012
|
-
function
|
|
1013
|
-
return
|
|
883
|
+
function challengeValue(field, queryParams, headers, body) {
|
|
884
|
+
return field === void 0 ? void 0 : fieldValue(field, queryParams, headers, body);
|
|
1014
885
|
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
function digestEquals(presented, expected, verification) {
|
|
1018
|
-
const candidate = presented.trim();
|
|
1019
|
-
if ((verification.encoding ?? "hex") === "base64") return secureEquals(candidate, expected);
|
|
1020
|
-
return secureEquals(candidate.toLowerCase(), expected.toLowerCase());
|
|
886
|
+
function dedupeKey(field, queryParams, headers, body) {
|
|
887
|
+
return fieldValue(field, queryParams, headers, body);
|
|
1021
888
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region src/http/namespace.ts
|
|
891
|
+
/**
|
|
892
|
+
* A package's namespace is its npm name, used verbatim as one or two path
|
|
893
|
+
* segments. Nothing is slugged: dropping the scope, folding `.`/`_` to `-` or
|
|
894
|
+
* lower-casing would all map distinct package names onto one namespace, and a
|
|
895
|
+
* lossy mapping means two packages can silently claim the same URL space.
|
|
896
|
+
* Verbatim is injective, so there is no collision left to detect.
|
|
897
|
+
*/
|
|
898
|
+
/**
|
|
899
|
+
* npm's package-name grammar, per segment. Deliberately the same shape the HTTP
|
|
900
|
+
* package loader validates with, so a name that can be installed can be routed.
|
|
901
|
+
*/
|
|
902
|
+
const SEGMENT = /^[a-z0-9][-a-z0-9._]*$/i;
|
|
903
|
+
/** Segments that would read as path traversal rather than as a name. */
|
|
904
|
+
const TRAVERSAL = /* @__PURE__ */ new Set([".", ".."]);
|
|
905
|
+
var InvalidNamespaceError = class extends Error {};
|
|
906
|
+
/**
|
|
907
|
+
* Turns a package name into the path segments it occupies.
|
|
908
|
+
* `@powerhousedao/workflow` → ["@powerhousedao", "workflow"]
|
|
909
|
+
* `document-model` → ["document-model"]
|
|
910
|
+
*/
|
|
911
|
+
function namespaceSegments(packageName) {
|
|
912
|
+
if (!packageName) throw new InvalidNamespaceError("Package name is empty");
|
|
913
|
+
const scoped = packageName.startsWith("@");
|
|
914
|
+
const parts = (scoped ? packageName.slice(1) : packageName).split("/");
|
|
915
|
+
if (parts.length !== (scoped ? 2 : 1)) throw new InvalidNamespaceError(`"${packageName}" is not a package name: expected ${scoped ? "@scope/name" : "name"}`);
|
|
916
|
+
for (const part of parts) if (TRAVERSAL.has(part) || !SEGMENT.test(part)) throw new InvalidNamespaceError(`"${packageName}" contains a segment that is not a valid npm name part: "${part}"`);
|
|
917
|
+
return scoped ? [`@${parts[0]}`, parts[1]] : parts;
|
|
1025
918
|
}
|
|
1026
|
-
/**
|
|
1027
|
-
*
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
919
|
+
/**
|
|
920
|
+
* The path a package's routes hang off, relative to the package prefix.
|
|
921
|
+
* Scoped names occupy two segments — the addressing unpkg and jsdelivr use.
|
|
922
|
+
*/
|
|
923
|
+
function namespacePath(packageName) {
|
|
924
|
+
return namespaceSegments(packageName).join("/");
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* The same path with the leading `@` percent-encoded. Both routers match the
|
|
928
|
+
* raw pathname, so a client that percent-encodes each segment would otherwise
|
|
929
|
+
* 404. Registering both spellings avoids decoding the pathname before matching,
|
|
930
|
+
* which would turn `%2f` into `/` and let a crafted URL cross segment
|
|
931
|
+
* boundaries. `%40` cannot introduce a boundary, which is what makes this safe.
|
|
932
|
+
*/
|
|
933
|
+
function encodedNamespacePath(packageName) {
|
|
934
|
+
const path = namespacePath(packageName);
|
|
935
|
+
return path.startsWith("@") ? `%40${path.slice(1)}` : void 0;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* A route path a package supplied. Must be relative and must not climb out of
|
|
939
|
+
* the scope.
|
|
940
|
+
*/
|
|
941
|
+
function assertRelativeRoutePath(path) {
|
|
942
|
+
if (path.startsWith("/")) throw new InvalidNamespaceError(`Route path "${path}" must be relative to the scope, not absolute`);
|
|
943
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(path)) throw new InvalidNamespaceError(`Route path "${path}" must be a path, not a URL`);
|
|
944
|
+
if (path.split("/").some((segment) => TRAVERSAL.has(segment))) throw new InvalidNamespaceError(`Route path "${path}" must not contain "." or ".." segments`);
|
|
945
|
+
return path.replace(/^\/+|\/+$/g, "");
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Resolves the npm name a package is routed under from the key the package
|
|
949
|
+
* manager holds it by. That key is the specifier as configured, which is not
|
|
950
|
+
* always a name:
|
|
951
|
+
* - `@scope/pkg` — already a name.
|
|
952
|
+
* - `@scope/pkg@1.3.9` — a registry spec; only the loader strips the tag.
|
|
953
|
+
* - `/Users/me/project` — the local project, which switchboard registers by
|
|
954
|
+
* `process.cwd()`. Its real name lives in its package.json.
|
|
955
|
+
*
|
|
956
|
+
* Deriving a URL segment straight from the key would give a developer's home
|
|
957
|
+
* directory a route namespace, so the path form is resolved rather than slugged.
|
|
958
|
+
*/
|
|
959
|
+
function resolvePackageName(key, readPackageJsonName = defaultReadName) {
|
|
960
|
+
const withoutVersion = stripVersionSpec(key);
|
|
961
|
+
if (isPackageName(withoutVersion)) return withoutVersion;
|
|
962
|
+
if (key.startsWith("/") || key.startsWith(".")) {
|
|
963
|
+
const name = readPackageJsonName(key);
|
|
964
|
+
if (name && isPackageName(name)) return name;
|
|
965
|
+
throw new InvalidNamespaceError(`Package at "${key}" has no usable name in its package.json, so it cannot host routes`);
|
|
1038
966
|
}
|
|
1039
|
-
|
|
1040
|
-
timestamp,
|
|
1041
|
-
signatures
|
|
1042
|
-
};
|
|
967
|
+
throw new InvalidNamespaceError(`"${key}" is not a package name and not a path, so it cannot host routes`);
|
|
1043
968
|
}
|
|
1044
|
-
function
|
|
1045
|
-
|
|
969
|
+
function isPackageName(value) {
|
|
970
|
+
try {
|
|
971
|
+
namespaceSegments(value);
|
|
972
|
+
return true;
|
|
973
|
+
} catch {
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
1046
976
|
}
|
|
1047
|
-
/**
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
reason: `header "${header}" absent`
|
|
1061
|
-
};
|
|
1062
|
-
const secret = verification.secret;
|
|
1063
|
-
const tolerance = verification.toleranceSeconds ?? 300;
|
|
1064
|
-
switch (verification.scheme) {
|
|
1065
|
-
case "token": return secureEquals(presented, secret) ? OK : {
|
|
1066
|
-
ok: false,
|
|
1067
|
-
reason: "token mismatch"
|
|
1068
|
-
};
|
|
1069
|
-
case "hmac": return digestEquals(presented, hmacDigest(secret, raw, verification), verification) ? OK : {
|
|
1070
|
-
ok: false,
|
|
1071
|
-
reason: "hmac mismatch"
|
|
1072
|
-
};
|
|
1073
|
-
case "hmac-prefixed": return digestEquals(presented, `${signaturePrefix(verification)}${hmacDigest(secret, raw, verification)}`, verification) ? OK : {
|
|
1074
|
-
ok: false,
|
|
1075
|
-
reason: "hmac mismatch"
|
|
1076
|
-
};
|
|
1077
|
-
case "hmac-timestamped": {
|
|
1078
|
-
const { timestamp, signatures } = parseTimestampedHeader(presented);
|
|
1079
|
-
if (timestamp === void 0 || !Number.isFinite(timestamp)) return {
|
|
1080
|
-
ok: false,
|
|
1081
|
-
reason: "no timestamp in the signature header"
|
|
1082
|
-
};
|
|
1083
|
-
if (signatures.length === 0) return {
|
|
1084
|
-
ok: false,
|
|
1085
|
-
reason: "no v1 signature in the header"
|
|
1086
|
-
};
|
|
1087
|
-
const nowMs = (options.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
1088
|
-
if (Math.abs(nowMs / 1e3 - timestamp) > tolerance) return {
|
|
1089
|
-
ok: false,
|
|
1090
|
-
reason: "timestamp outside the replay window"
|
|
1091
|
-
};
|
|
1092
|
-
const expected = hmacDigest(secret, Buffer.concat([Buffer.from(`${timestamp}.`, "utf8"), raw]), verification);
|
|
1093
|
-
let matched = false;
|
|
1094
|
-
for (const signature of signatures) if (digestEquals(signature, expected, verification)) matched = true;
|
|
1095
|
-
return matched ? OK : {
|
|
1096
|
-
ok: false,
|
|
1097
|
-
reason: "hmac mismatch"
|
|
1098
|
-
};
|
|
1099
|
-
}
|
|
977
|
+
/** `@scope/pkg@1.3.9` → `@scope/pkg`; `pkg@1.0.0` → `pkg`. */
|
|
978
|
+
function stripVersionSpec(key) {
|
|
979
|
+
const at = key.lastIndexOf("@");
|
|
980
|
+
if (at <= 0) return key;
|
|
981
|
+
return key.slice(0, at);
|
|
982
|
+
}
|
|
983
|
+
function defaultReadName(dir) {
|
|
984
|
+
try {
|
|
985
|
+
const raw = readFileSync(join(dir, "package.json"), "utf8");
|
|
986
|
+
const parsed = JSON.parse(raw);
|
|
987
|
+
return typeof parsed.name === "string" ? parsed.name : void 0;
|
|
988
|
+
} catch {
|
|
989
|
+
return;
|
|
1100
990
|
}
|
|
1101
991
|
}
|
|
1102
|
-
/**
|
|
1103
|
-
*
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
992
|
+
/**
|
|
993
|
+
* A mount path the host named for one of its own route groups.
|
|
994
|
+
*
|
|
995
|
+
* The host owns the whole URL space — it holds the adapter — so unlike a
|
|
996
|
+
* package it may name an absolute path. That is the difference between hosting
|
|
997
|
+
* and being hosted, and it is why this lives on the service rather than on a
|
|
998
|
+
* scope: a package is only ever handed a scope, and a scope has no way to
|
|
999
|
+
* express a path outside itself.
|
|
1000
|
+
*
|
|
1001
|
+
* What the host still may not name is anything that is not one stable literal
|
|
1002
|
+
* prefix. A traversal segment, or a pattern segment, would make the group's own
|
|
1003
|
+
* routes unpredictable relative to each other. Returns the normalized path,
|
|
1004
|
+
* with a leading and no trailing slash.
|
|
1005
|
+
*/
|
|
1006
|
+
function assertHostMountPath(path) {
|
|
1007
|
+
if (!path.startsWith("/")) throw new InvalidNamespaceError(`Host mount path "${path}" must be absolute, e.g. "/webhooks"`);
|
|
1008
|
+
const segments = path.split("/").filter((segment) => segment.length > 0);
|
|
1009
|
+
if (segments.length === 0) throw new InvalidNamespaceError(`Host mount path "${path}" is the whole URL space, which is the adapter rather than a scope of it`);
|
|
1010
|
+
for (const segment of segments) {
|
|
1011
|
+
if (TRAVERSAL.has(segment)) throw new InvalidNamespaceError(`Host mount path "${path}" must not contain "." or ".." segments`);
|
|
1012
|
+
if (segment.startsWith(":") || segment.includes("*")) throw new InvalidNamespaceError(`Host mount path "${path}" must be a literal prefix, not a pattern: "${segment}"`);
|
|
1013
|
+
}
|
|
1014
|
+
return `/${segments.join("/")}`;
|
|
1015
|
+
}
|
|
1016
|
+
//#endregion
|
|
1017
|
+
//#region src/http/route-service.ts
|
|
1018
|
+
const logger$1 = childLogger(["reactor-api", "http-routes"]);
|
|
1019
|
+
/** The segment package routes live under, inside the host's base path. */
|
|
1020
|
+
const PACKAGE_ROUTE_SEGMENT = "api";
|
|
1021
|
+
/** The namespace core's own subgraphs and services register under. */
|
|
1022
|
+
const CORE_PACKAGE_NAME = "@powerhousedao/reactor-api";
|
|
1023
|
+
/** Generous enough for any request a route should be buffering at all. */
|
|
1024
|
+
const DEFAULT_MAX_BODY_BYTES = 1048576;
|
|
1025
|
+
const ANONYMOUS = {
|
|
1026
|
+
user: void 0,
|
|
1027
|
+
authEnabled: false
|
|
1028
|
+
};
|
|
1029
|
+
/** Owns the URL space packages serve from, handing each a scope bound to its own namespace. The prefix nests inside
|
|
1030
|
+
* the host's base path (`<basePath>/api`), so core collisions are prevented by URL shape, not a reserved-name list. */
|
|
1031
|
+
var HttpRouteService = class {
|
|
1032
|
+
#adapter;
|
|
1033
|
+
#authService;
|
|
1034
|
+
#prefix;
|
|
1035
|
+
#publicUrl;
|
|
1036
|
+
#trustProxy;
|
|
1037
|
+
#scopes = /* @__PURE__ */ new Map();
|
|
1038
|
+
#webhooks;
|
|
1039
|
+
constructor({ httpAdapter, basePath = "/", authService, webhooks, publicUrl = "", trustProxy = false }) {
|
|
1040
|
+
this.#adapter = httpAdapter;
|
|
1041
|
+
this.#authService = authService;
|
|
1042
|
+
this.#webhooks = webhooks;
|
|
1043
|
+
this.#publicUrl = publicUrl;
|
|
1044
|
+
this.#trustProxy = trustProxy;
|
|
1045
|
+
this.#prefix = posix.join("/", basePath, "api");
|
|
1046
|
+
}
|
|
1047
|
+
/** The absolute path packages are mounted under. */
|
|
1048
|
+
get prefix() {
|
|
1049
|
+
return this.#prefix;
|
|
1050
|
+
}
|
|
1051
|
+
/** The scope for a package; idempotent per name, so a reload cannot accumulate namespaces. Throws when two packages
|
|
1052
|
+
* resolve to one namespace — with verbatim names that means one package configured twice, a genuine ambiguity. */
|
|
1053
|
+
scopeFor(packageKey) {
|
|
1054
|
+
const packageName = resolvePackageName(packageKey);
|
|
1055
|
+
const namespace = namespacePath(packageName);
|
|
1056
|
+
const encoded = encodedNamespacePath(packageName);
|
|
1057
|
+
return this.#scope({
|
|
1058
|
+
owner: packageName,
|
|
1059
|
+
base: posix.join(this.#prefix, namespace),
|
|
1060
|
+
encodedBase: encoded ? posix.join(this.#prefix, encoded) : void 0,
|
|
1061
|
+
claim: `the route namespace "${namespace}"`,
|
|
1062
|
+
webhooks: this.#webhooks?.scopeFor(packageName),
|
|
1063
|
+
onDispose: () => this.#webhooks?.disposeScope(packageName)
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
/** A scope at a host-named path; on the service, not `IHttpScope`, so a package can never name one. Namespacing is package
|
|
1067
|
+
* policy: the host owns its URL space and third parties hold its URLs, so the path is verbatim and outside the package prefix. */
|
|
1068
|
+
hostScope(name, mountPath) {
|
|
1069
|
+
const base = assertHostMountPath(mountPath);
|
|
1070
|
+
if (base === this.#prefix || base.startsWith(`${this.#prefix}/`)) throw new InvalidNamespaceError(`Host scope "${name}" cannot mount at "${base}": that is the package route prefix, which packages own`);
|
|
1071
|
+
return this.#scope({
|
|
1072
|
+
owner: name,
|
|
1073
|
+
base,
|
|
1074
|
+
encodedBase: void 0,
|
|
1075
|
+
claim: `the mount path "${base}"`,
|
|
1076
|
+
webhooks: void 0,
|
|
1077
|
+
onDispose: () => void 0
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
/** Idempotent per base path, so a package reload cannot accumulate namespaces. Two owners wanting one path is an error —
|
|
1081
|
+
* with verbatim names that needs one package configured twice at different versions, a genuine ambiguity, not a clash. */
|
|
1082
|
+
#scope(options) {
|
|
1083
|
+
const { owner, base } = options;
|
|
1084
|
+
const existing = this.#scopes.get(base);
|
|
1085
|
+
if (existing) {
|
|
1086
|
+
if (existing.owner !== owner) throw new Error(`"${owner}" wants ${options.claim}, which "${existing.owner}" already holds`);
|
|
1087
|
+
return existing;
|
|
1088
|
+
}
|
|
1089
|
+
const scope = new HttpScope({
|
|
1090
|
+
owner,
|
|
1091
|
+
base,
|
|
1092
|
+
encodedBase: options.encodedBase,
|
|
1093
|
+
publicUrl: this.#publicUrl,
|
|
1094
|
+
trustProxy: this.#trustProxy,
|
|
1095
|
+
adapter: this.#adapter,
|
|
1096
|
+
authService: this.#authService,
|
|
1097
|
+
webhooks: options.webhooks,
|
|
1098
|
+
onDispose: () => {
|
|
1099
|
+
this.#scopes.delete(base);
|
|
1100
|
+
options.onDispose();
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
this.#scopes.set(base, scope);
|
|
1104
|
+
return scope;
|
|
1105
|
+
}
|
|
1106
|
+
/** Like {@link scopeFor}, but never throws: a key resolving to no usable npm name gets a scope that refuses
|
|
1107
|
+
* registrations, so one unroutable package cannot stop the host booting — it fails only if it serves a route. */
|
|
1108
|
+
scopeForOrNull(packageKey) {
|
|
1109
|
+
try {
|
|
1110
|
+
return this.scopeFor(packageKey);
|
|
1111
|
+
} catch (error) {
|
|
1112
|
+
if (!(error instanceof InvalidNamespaceError)) throw error;
|
|
1113
|
+
logger$1.warn("Package \"@package\" cannot host HTTP routes: @reason", packageKey, error.message);
|
|
1114
|
+
return new UnroutableScope(packageKey, error.message);
|
|
1115
|
+
}
|
|
1122
1116
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
if (type === "application/json" || type.endsWith("+json")) try {
|
|
1132
|
-
return JSON.parse(text);
|
|
1133
|
-
} catch {
|
|
1134
|
-
return text;
|
|
1117
|
+
/** Releases a package's routes, e.g. when it is replaced or removed. */
|
|
1118
|
+
disposeScope(packageKey) {
|
|
1119
|
+
try {
|
|
1120
|
+
const namespace = namespacePath(resolvePackageName(packageKey));
|
|
1121
|
+
this.#scopes.get(posix.join(this.#prefix, namespace))?.dispose();
|
|
1122
|
+
} catch (error) {
|
|
1123
|
+
if (!(error instanceof InvalidNamespaceError)) throw error;
|
|
1124
|
+
}
|
|
1135
1125
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
const WEBHOOK_SEGMENT = "webhooks";
|
|
1144
|
-
const DEFAULT_MAX_BODY_BYTES = 1048576;
|
|
1145
|
-
const DEFAULT_DEDUPE_TTL_SECONDS = 300;
|
|
1146
|
-
/** One host route for `/webhooks/:token`, dispatching by token. The flat path leaks
|
|
1147
|
-
* neither package nor document; the namespace lives in the token record, which is also what stops one package's token reaching another's handler. */
|
|
1148
|
-
var WebhookService = class {
|
|
1149
|
-
#store;
|
|
1150
|
-
#path;
|
|
1126
|
+
disposeAll() {
|
|
1127
|
+
for (const scope of [...this.#scopes.values()]) scope.dispose();
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
var HttpScope = class {
|
|
1131
|
+
owner;
|
|
1132
|
+
#base;
|
|
1151
1133
|
#publicUrl;
|
|
1152
|
-
#
|
|
1134
|
+
#trustProxy;
|
|
1135
|
+
#encodedBase;
|
|
1136
|
+
#adapter;
|
|
1137
|
+
#authService;
|
|
1138
|
+
#onDispose;
|
|
1153
1139
|
#registrations = /* @__PURE__ */ new Map();
|
|
1154
|
-
#
|
|
1155
|
-
constructor(
|
|
1156
|
-
this
|
|
1157
|
-
this.#
|
|
1158
|
-
this.#publicUrl = publicUrl
|
|
1140
|
+
#webhooks;
|
|
1141
|
+
constructor(options) {
|
|
1142
|
+
this.owner = options.owner;
|
|
1143
|
+
this.#base = options.base;
|
|
1144
|
+
this.#publicUrl = options.publicUrl;
|
|
1145
|
+
this.#trustProxy = options.trustProxy;
|
|
1146
|
+
this.#encodedBase = options.encodedBase;
|
|
1147
|
+
this.#adapter = options.adapter;
|
|
1148
|
+
this.#authService = options.authService;
|
|
1149
|
+
this.#onDispose = options.onDispose;
|
|
1150
|
+
this.#webhooks = options.webhooks ?? unavailableWebhooks(options.owner);
|
|
1159
1151
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
attach(scope) {
|
|
1163
|
-
this.#scope = scope;
|
|
1152
|
+
get baseUrl() {
|
|
1153
|
+
return `${readPublicOrigin(this.#publicUrl)}${this.#base}`;
|
|
1164
1154
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
if (this.#routes.length) return;
|
|
1168
|
-
if (!this.#scope) throw new Error("The webhook service has no HTTP scope; the host must call attach() before a package registers");
|
|
1169
|
-
this.#routes = [this.#scope.nodeRoute({
|
|
1170
|
-
method: [
|
|
1171
|
-
"DELETE",
|
|
1172
|
-
"GET",
|
|
1173
|
-
"HEAD",
|
|
1174
|
-
"PATCH",
|
|
1175
|
-
"POST",
|
|
1176
|
-
"PUT"
|
|
1177
|
-
],
|
|
1178
|
-
path: ":token",
|
|
1179
|
-
auth: "public",
|
|
1180
|
-
handler: (req, res, ctx) => void this.#deliver(req, res, ctx.params)
|
|
1181
|
-
})];
|
|
1155
|
+
get webhooks() {
|
|
1156
|
+
return this.#webhooks;
|
|
1182
1157
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
this.#routes = [];
|
|
1186
|
-
this.#registrations.clear();
|
|
1158
|
+
get(path, a, b) {
|
|
1159
|
+
return this.#shorthand("GET", path, a, b);
|
|
1187
1160
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
return {
|
|
1191
|
-
hasPublicOrigin: this.hasPublicOrigin,
|
|
1192
|
-
register: async (spec) => {
|
|
1193
|
-
await this.init();
|
|
1194
|
-
const key = `${namespace}|${spec.name}`;
|
|
1195
|
-
this.#registrations.set(key, {
|
|
1196
|
-
namespace,
|
|
1197
|
-
spec
|
|
1198
|
-
});
|
|
1199
|
-
return {
|
|
1200
|
-
endpointFor: async (ownerKey) => {
|
|
1201
|
-
const row = await this.#store.ensure(namespace, spec.name, ownerKey);
|
|
1202
|
-
return {
|
|
1203
|
-
token: row.token,
|
|
1204
|
-
url: this.urlFor(row.token),
|
|
1205
|
-
createdAt: row.createdAt
|
|
1206
|
-
};
|
|
1207
|
-
},
|
|
1208
|
-
revoke: (ownerKey) => this.#store.revoke(namespace, spec.name, ownerKey),
|
|
1209
|
-
list: async () => (await this.#store.list(namespace, spec.name)).map((row) => ({
|
|
1210
|
-
key: row.ownerKey,
|
|
1211
|
-
token: row.token,
|
|
1212
|
-
url: this.urlFor(row.token),
|
|
1213
|
-
createdAt: row.createdAt
|
|
1214
|
-
}))
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
};
|
|
1161
|
+
post(path, a, b) {
|
|
1162
|
+
return this.#shorthand("POST", path, a, b);
|
|
1218
1163
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
for (const [key, registration] of this.#registrations) if (registration.namespace === namespace) this.#registrations.delete(key);
|
|
1164
|
+
put(path, a, b) {
|
|
1165
|
+
return this.#shorthand("PUT", path, a, b);
|
|
1222
1166
|
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
urlFor(token) {
|
|
1226
|
-
const path = posix.join(this.#path, token);
|
|
1227
|
-
return this.#publicUrl ? `${this.#publicUrl}${path}` : path;
|
|
1167
|
+
patch(path, a, b) {
|
|
1168
|
+
return this.#shorthand("PATCH", path, a, b);
|
|
1228
1169
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
return this.#publicUrl !== void 0;
|
|
1170
|
+
delete(path, a, b) {
|
|
1171
|
+
return this.#shorthand("DELETE", path, a, b);
|
|
1232
1172
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
const url = new URL(req.url ?? "/", "http://localhost");
|
|
1292
|
-
const queryParams = Object.fromEntries(url.searchParams);
|
|
1293
|
-
const signatureHeader = verification ? schemeHeader(verification) : void 0;
|
|
1294
|
-
const headers = headerRecord(req);
|
|
1295
|
-
const body = parseWebhookBody(raw, headers["content-type"]);
|
|
1296
|
-
const challenge = challengeValue(policy.challengeField, queryParams, headers, body);
|
|
1297
|
-
if (challenge !== void 0) {
|
|
1298
|
-
res.statusCode = 200;
|
|
1299
|
-
res.setHeader("content-type", "text/plain");
|
|
1300
|
-
res.end(challenge);
|
|
1301
|
-
return;
|
|
1302
|
-
}
|
|
1303
|
-
let recordedKey;
|
|
1304
|
-
if (policy.dedupe) {
|
|
1305
|
-
const key = dedupeKey(policy.dedupe.field, queryParams, headers, body);
|
|
1306
|
-
recordedKey = key;
|
|
1307
|
-
if (key !== void 0 && await this.#store.seen(token, key, policy.dedupe.ttlSeconds ?? DEFAULT_DEDUPE_TTL_SECONDS)) {
|
|
1308
|
-
res.statusCode = 200;
|
|
1309
|
-
res.end();
|
|
1310
|
-
return;
|
|
1311
|
-
}
|
|
1173
|
+
head(path, a, b) {
|
|
1174
|
+
return this.#shorthand("HEAD", path, a, b);
|
|
1175
|
+
}
|
|
1176
|
+
#shorthand(method, path, a, b) {
|
|
1177
|
+
const options = typeof a === "function" ? {} : a;
|
|
1178
|
+
const handler = typeof a === "function" ? a : b;
|
|
1179
|
+
if (!handler) throw new Error(`Route ${method} ${path} was registered with no handler`);
|
|
1180
|
+
return this.route({
|
|
1181
|
+
...options,
|
|
1182
|
+
method,
|
|
1183
|
+
path,
|
|
1184
|
+
handler
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
route(spec) {
|
|
1188
|
+
const body = spec.body ?? "parsed";
|
|
1189
|
+
return this.#register(spec, (req, res, ctx) => this.#serve(spec, body, req, res, ctx));
|
|
1190
|
+
}
|
|
1191
|
+
nodeRoute(spec) {
|
|
1192
|
+
return this.#register(spec, (req, res, ctx) => spec.handler(req, res, ctx));
|
|
1193
|
+
}
|
|
1194
|
+
dispose() {
|
|
1195
|
+
for (const registration of this.#registrations.values()) for (const handle of registration.handles) handle.dispose();
|
|
1196
|
+
this.#registrations.clear();
|
|
1197
|
+
this.#onDispose();
|
|
1198
|
+
}
|
|
1199
|
+
/** Mounts one route under this scope's namespace, in both the verbatim and the
|
|
1200
|
+
* percent-encoded spelling of a scoped name. */
|
|
1201
|
+
#register(spec, run) {
|
|
1202
|
+
const relative = assertRelativeRoutePath(spec.path);
|
|
1203
|
+
const methods = Array.isArray(spec.method) ? spec.method : [spec.method];
|
|
1204
|
+
const routePath = relative ? posix.join(this.#base, relative) : this.#base;
|
|
1205
|
+
const key = `${methods.join(",")} ${routePath}`;
|
|
1206
|
+
if (this.#registrations.has(key)) throw new Error(`Route ${key} is already registered by "${this.owner}"`);
|
|
1207
|
+
const handles = [];
|
|
1208
|
+
const paths = [routePath];
|
|
1209
|
+
if (this.#encodedBase) paths.push(relative ? posix.join(this.#encodedBase, relative) : this.#encodedBase);
|
|
1210
|
+
for (const path of paths) for (const method of methods) handles.push(this.#adapter.mountNodeRoute(method, path, (req, res) => {
|
|
1211
|
+
this.#guard(spec, req, res, run);
|
|
1212
|
+
}, {
|
|
1213
|
+
rawBody: true,
|
|
1214
|
+
prefix: spec.prefix
|
|
1215
|
+
}));
|
|
1216
|
+
this.#registrations.set(key, {
|
|
1217
|
+
path: routePath,
|
|
1218
|
+
handles
|
|
1219
|
+
});
|
|
1220
|
+
logger$1.debug("Registered @route for @package", key, this.owner);
|
|
1221
|
+
const publicUrl = this.#publicUrl;
|
|
1222
|
+
return {
|
|
1223
|
+
get url() {
|
|
1224
|
+
return `${readPublicOrigin(publicUrl)}${routePath}`;
|
|
1225
|
+
},
|
|
1226
|
+
dispose: () => {
|
|
1227
|
+
const registration = this.#registrations.get(key);
|
|
1228
|
+
if (!registration) return;
|
|
1229
|
+
for (const handle of registration.handles) handle.dispose();
|
|
1230
|
+
this.#registrations.delete(key);
|
|
1312
1231
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
/** Authenticate, then run. */
|
|
1235
|
+
async #guard(spec, req, res, run) {
|
|
1236
|
+
try {
|
|
1237
|
+
const actor = await this.#authenticate(spec.auth ?? "renown", req, res);
|
|
1238
|
+
if (actor === REJECTED) return;
|
|
1239
|
+
await run(req, res, {
|
|
1240
|
+
params: routeParams(req),
|
|
1241
|
+
user: actor?.user,
|
|
1242
|
+
authEnabled: actor?.authEnabled ?? false,
|
|
1243
|
+
transport: resolveTransport(req, this.#trustProxy)
|
|
1321
1244
|
});
|
|
1322
|
-
if (reply.unprocessed === true && recordedKey !== void 0) try {
|
|
1323
|
-
await this.#store.forget(token, recordedKey);
|
|
1324
|
-
} catch (error) {
|
|
1325
|
-
logger$1.warn("Could not forget an unprocessed webhook delivery: @error", error);
|
|
1326
|
-
}
|
|
1327
|
-
res.statusCode = reply.status;
|
|
1328
|
-
if (reply.body !== void 0 && method !== "HEAD") {
|
|
1329
|
-
res.setHeader("content-type", reply.contentType ?? "text/plain");
|
|
1330
|
-
res.end(reply.body);
|
|
1331
|
-
} else res.end();
|
|
1332
1245
|
} catch (error) {
|
|
1333
|
-
logger$1.error("
|
|
1246
|
+
logger$1.error("Route handler failed for @package", this.owner, error);
|
|
1334
1247
|
writeError(res, 500, "Internal server error");
|
|
1335
1248
|
}
|
|
1336
1249
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
if (
|
|
1342
|
-
|
|
1250
|
+
/** Resolves the caller, answering the request itself when the route refuses it;
|
|
1251
|
+
* returns REJECTED in that case so the caller stops. */
|
|
1252
|
+
async #authenticate(auth, req, res) {
|
|
1253
|
+
if (auth === "public") return void 0;
|
|
1254
|
+
if (typeof auth === "function") {
|
|
1255
|
+
const result = await auth(req);
|
|
1256
|
+
if (!result.authorized) {
|
|
1257
|
+
if ("response" in result) await writeResponse(res, result.response, req.method ?? "GET");
|
|
1258
|
+
else writeError(res, result.status, result.message);
|
|
1259
|
+
return REJECTED;
|
|
1260
|
+
}
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
if (!this.#authService) return ANONYMOUS;
|
|
1264
|
+
const result = await this.#authService.verifyBearer(req.headers.authorization);
|
|
1265
|
+
if (result instanceof Response) {
|
|
1266
|
+
await writeResponse(res, result, req.method ?? "GET");
|
|
1267
|
+
return REJECTED;
|
|
1268
|
+
}
|
|
1269
|
+
if (result.auth_enabled && !result.user && auth === "renown") {
|
|
1270
|
+
writeError(res, 401, "Authentication required");
|
|
1271
|
+
return REJECTED;
|
|
1272
|
+
}
|
|
1273
|
+
return {
|
|
1274
|
+
user: result.user,
|
|
1275
|
+
authEnabled: result.auth_enabled
|
|
1276
|
+
};
|
|
1343
1277
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1278
|
+
/** Builds the Fetch Request from the raw stream and runs the handler. */
|
|
1279
|
+
async #serve(spec, body, req, res, ctx) {
|
|
1280
|
+
const method = req.method ?? "GET";
|
|
1281
|
+
const url = `${ctx.transport.baseUrl}${req.url ?? "/"}`;
|
|
1282
|
+
const controller = new AbortController();
|
|
1283
|
+
req.once("close", () => controller.abort());
|
|
1284
|
+
let raw;
|
|
1285
|
+
let init = {
|
|
1286
|
+
method,
|
|
1287
|
+
headers: fetchHeaders(req),
|
|
1288
|
+
signal: controller.signal
|
|
1289
|
+
};
|
|
1290
|
+
if (method !== "GET" && method !== "HEAD" && body !== "none") {
|
|
1291
|
+
if (body === "stream") init = {
|
|
1292
|
+
...init,
|
|
1293
|
+
body: Readable.toWeb(req),
|
|
1294
|
+
duplex: "half"
|
|
1295
|
+
};
|
|
1296
|
+
else {
|
|
1297
|
+
try {
|
|
1298
|
+
raw = await readBody(req, spec.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES);
|
|
1299
|
+
} catch (error) {
|
|
1300
|
+
if (error instanceof BodyTooLargeError) {
|
|
1301
|
+
res.setHeader("connection", "close");
|
|
1302
|
+
res.once("finish", () => req.destroy());
|
|
1303
|
+
writeError(res, 413, "Payload too large");
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
throw error;
|
|
1307
|
+
}
|
|
1308
|
+
if (raw.length) init = {
|
|
1309
|
+
...init,
|
|
1310
|
+
body: new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength)
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
await writeResponse(res, await spec.handler(new Request(url, init), {
|
|
1315
|
+
...ctx,
|
|
1316
|
+
rawBody: body === "raw" ? raw ?? Buffer.alloc(0) : void 0,
|
|
1317
|
+
signal: controller.signal
|
|
1318
|
+
}), method);
|
|
1356
1319
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
const
|
|
1364
|
-
if (
|
|
1365
|
-
return
|
|
1366
|
-
}
|
|
1367
|
-
function challengeValue(field, queryParams, headers, body) {
|
|
1368
|
-
return field === void 0 ? void 0 : fieldValue(field, queryParams, headers, body);
|
|
1320
|
+
};
|
|
1321
|
+
const REJECTED = Symbol("rejected");
|
|
1322
|
+
function routeParams(req) {
|
|
1323
|
+
const params = req.params;
|
|
1324
|
+
if (!params || typeof params !== "object") return {};
|
|
1325
|
+
const out = {};
|
|
1326
|
+
for (const [key, value] of Object.entries(params)) if (typeof value === "string") out[key] = value;
|
|
1327
|
+
else if (Array.isArray(value)) out[key] = value.join("/");
|
|
1328
|
+
return out;
|
|
1369
1329
|
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1330
|
+
/** Stands in for a package that cannot be routed — its key resolves to no npm name. Registering a route throws with
|
|
1331
|
+
* the reason; nothing else does, so the package still loads and its non-HTTP behaviour is unaffected. */
|
|
1332
|
+
var UnroutableScope = class {
|
|
1333
|
+
owner;
|
|
1334
|
+
baseUrl = "";
|
|
1335
|
+
#reason;
|
|
1336
|
+
constructor(packageKey, reason) {
|
|
1337
|
+
this.owner = packageKey;
|
|
1338
|
+
this.#reason = reason;
|
|
1339
|
+
}
|
|
1340
|
+
#refuse() {
|
|
1341
|
+
throw new Error(`Package "${this.owner}" cannot host HTTP routes: ${this.#reason}`);
|
|
1342
|
+
}
|
|
1343
|
+
get() {
|
|
1344
|
+
this.#refuse();
|
|
1345
|
+
}
|
|
1346
|
+
post() {
|
|
1347
|
+
this.#refuse();
|
|
1348
|
+
}
|
|
1349
|
+
put() {
|
|
1350
|
+
this.#refuse();
|
|
1351
|
+
}
|
|
1352
|
+
patch() {
|
|
1353
|
+
this.#refuse();
|
|
1354
|
+
}
|
|
1355
|
+
delete() {
|
|
1356
|
+
this.#refuse();
|
|
1357
|
+
}
|
|
1358
|
+
head() {
|
|
1359
|
+
this.#refuse();
|
|
1360
|
+
}
|
|
1361
|
+
route() {
|
|
1362
|
+
this.#refuse();
|
|
1363
|
+
}
|
|
1364
|
+
nodeRoute() {
|
|
1365
|
+
this.#refuse();
|
|
1366
|
+
}
|
|
1367
|
+
get webhooks() {
|
|
1368
|
+
return unavailableWebhooks(this.owner);
|
|
1369
|
+
}
|
|
1370
|
+
dispose() {}
|
|
1371
|
+
};
|
|
1372
|
+
/** Stands in when the host has no webhook store configured. */
|
|
1373
|
+
function unavailableWebhooks(packageName) {
|
|
1374
|
+
return {
|
|
1375
|
+
hasPublicOrigin: false,
|
|
1376
|
+
register: () => Promise.reject(/* @__PURE__ */ new Error(`Webhooks are not available on this host, so "${packageName}" cannot register one`))
|
|
1377
|
+
};
|
|
1372
1378
|
}
|
|
1373
1379
|
//#endregion
|
|
1374
1380
|
//#region src/http/webhook-store.ts
|
|
@@ -1639,6 +1645,11 @@ let DocumentChangeType = /* @__PURE__ */ function(DocumentChangeType) {
|
|
|
1639
1645
|
DocumentChangeType["Updated"] = "UPDATED";
|
|
1640
1646
|
return DocumentChangeType;
|
|
1641
1647
|
}({});
|
|
1648
|
+
let DriveNodeKind = /* @__PURE__ */ function(DriveNodeKind) {
|
|
1649
|
+
DriveNodeKind["File"] = "FILE";
|
|
1650
|
+
DriveNodeKind["Folder"] = "FOLDER";
|
|
1651
|
+
return DriveNodeKind;
|
|
1652
|
+
}({});
|
|
1642
1653
|
let PropagationMode = /* @__PURE__ */ function(PropagationMode) {
|
|
1643
1654
|
PropagationMode["Cascade"] = "CASCADE";
|
|
1644
1655
|
PropagationMode["Orphan"] = "ORPHAN";
|
|
@@ -1653,6 +1664,7 @@ const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
|
|
|
1653
1664
|
const definedNonNullAnySchema = z$1.any().refine((v) => isDefinedNonNullAny(v));
|
|
1654
1665
|
const AuthDecisionSchema = z$1.enum(AuthDecision);
|
|
1655
1666
|
const DocumentChangeTypeSchema = z$1.enum(DocumentChangeType);
|
|
1667
|
+
const DriveNodeKindSchema = z$1.enum(DriveNodeKind);
|
|
1656
1668
|
const PropagationModeSchema = z$1.enum(PropagationMode);
|
|
1657
1669
|
const SyncEnvelopeTypeSchema = z$1.enum(SyncEnvelopeType);
|
|
1658
1670
|
function ActionCandidateInputSchema() {
|
|
@@ -1891,6 +1903,23 @@ const JobInfoFieldsFragmentDoc = gql`
|
|
|
1891
1903
|
}
|
|
1892
1904
|
}
|
|
1893
1905
|
`;
|
|
1906
|
+
const DriveNodeFieldsFragmentDoc = gql`
|
|
1907
|
+
fragment DriveNodeFields on DriveNode {
|
|
1908
|
+
... on DriveFileNode {
|
|
1909
|
+
id
|
|
1910
|
+
driveId
|
|
1911
|
+
name
|
|
1912
|
+
parentFolder
|
|
1913
|
+
documentType
|
|
1914
|
+
}
|
|
1915
|
+
... on DriveFolderNode {
|
|
1916
|
+
id
|
|
1917
|
+
driveId
|
|
1918
|
+
name
|
|
1919
|
+
parentFolder
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
`;
|
|
1894
1923
|
const GetDocumentModelsDocument = gql`
|
|
1895
1924
|
query GetDocumentModels($namespace: String, $paging: PagingInput) {
|
|
1896
1925
|
documentModels(namespace: $namespace, paging: $paging) {
|
|
@@ -2141,6 +2170,44 @@ const GetCreateDefaultsDocument = gql`
|
|
|
2141
2170
|
}
|
|
2142
2171
|
}
|
|
2143
2172
|
`;
|
|
2173
|
+
const GetDriveNodesDocument = gql`
|
|
2174
|
+
query GetDriveNodes(
|
|
2175
|
+
$driveId: ID!
|
|
2176
|
+
$parentFolder: ID
|
|
2177
|
+
$paging: PagingInput
|
|
2178
|
+
$kind: DriveNodeKind
|
|
2179
|
+
) {
|
|
2180
|
+
driveNodes(
|
|
2181
|
+
driveId: $driveId
|
|
2182
|
+
parentFolder: $parentFolder
|
|
2183
|
+
paging: $paging
|
|
2184
|
+
kind: $kind
|
|
2185
|
+
) {
|
|
2186
|
+
results {
|
|
2187
|
+
...DriveNodeFields
|
|
2188
|
+
}
|
|
2189
|
+
nextCursor
|
|
2190
|
+
hasMore
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
${DriveNodeFieldsFragmentDoc}
|
|
2194
|
+
`;
|
|
2195
|
+
const GetDriveNodeDocument = gql`
|
|
2196
|
+
query GetDriveNode($driveId: ID!, $id: ID!) {
|
|
2197
|
+
driveNode(driveId: $driveId, id: $id) {
|
|
2198
|
+
...DriveNodeFields
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
${DriveNodeFieldsFragmentDoc}
|
|
2202
|
+
`;
|
|
2203
|
+
const GetDriveDescendantsDocument = gql`
|
|
2204
|
+
query GetDriveDescendants($driveId: ID!, $root: ID!) {
|
|
2205
|
+
driveDescendants(driveId: $driveId, root: $root) {
|
|
2206
|
+
...DriveNodeFields
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
${DriveNodeFieldsFragmentDoc}
|
|
2210
|
+
`;
|
|
2144
2211
|
const EvaluateActionsDocument = gql`
|
|
2145
2212
|
query EvaluateActions(
|
|
2146
2213
|
$documentIdentifier: String!
|
|
@@ -2522,6 +2589,15 @@ function getSdk(requester) {
|
|
|
2522
2589
|
GetCreateDefaults(variables, options) {
|
|
2523
2590
|
return requester(GetCreateDefaultsDocument, variables, options);
|
|
2524
2591
|
},
|
|
2592
|
+
GetDriveNodes(variables, options) {
|
|
2593
|
+
return requester(GetDriveNodesDocument, variables, options);
|
|
2594
|
+
},
|
|
2595
|
+
GetDriveNode(variables, options) {
|
|
2596
|
+
return requester(GetDriveNodeDocument, variables, options);
|
|
2597
|
+
},
|
|
2598
|
+
GetDriveDescendants(variables, options) {
|
|
2599
|
+
return requester(GetDriveDescendantsDocument, variables, options);
|
|
2600
|
+
},
|
|
2525
2601
|
EvaluateActions(variables, options) {
|
|
2526
2602
|
return requester(EvaluateActionsDocument, variables, options);
|
|
2527
2603
|
},
|
|
@@ -2995,7 +3071,6 @@ function isDriveContainerType(documentType) {
|
|
|
2995
3071
|
}
|
|
2996
3072
|
//#endregion
|
|
2997
3073
|
//#region src/graphql/reactor/resolvers.ts
|
|
2998
|
-
const REACTOR_DRIVE_DOCUMENT_TYPE = "powerhouse/reactor-drive";
|
|
2999
3074
|
/** The branch a mutation applies to when the caller names none. */
|
|
3000
3075
|
const DEFAULT_BRANCH = "main";
|
|
3001
3076
|
/** The `Query.<field>` coordinates handed the write client outside a mutation. */
|
|
@@ -3006,32 +3081,15 @@ const WRITE_CLIENT_QUERIES = Object.entries({
|
|
|
3006
3081
|
peerAgreement: "syncManager",
|
|
3007
3082
|
jobStatus: "read"
|
|
3008
3083
|
}).filter(([, binding]) => binding === "write").map(([field]) => field);
|
|
3009
|
-
/** The reactor-drive client a reactor-drive parent needs, or the refusal. */
|
|
3010
|
-
function requireReactorDriveClient(reactorDriveClient) {
|
|
3011
|
-
if (!reactorDriveClient) throw new GraphQLError("Reactor-drive parent encountered but no reactorDriveClient is configured on this switchboard");
|
|
3012
|
-
return reactorDriveClient;
|
|
3013
|
-
}
|
|
3014
3084
|
/**
|
|
3015
3085
|
* Adds a document to a drive parent and returns what to read back once the
|
|
3016
|
-
* write is readable.
|
|
3017
|
-
* client, which still has the facade's waiting shape.
|
|
3086
|
+
* write is readable. `write.drives` picks the drive type's strategy.
|
|
3018
3087
|
*/
|
|
3019
|
-
async function addFileToDrive(clients,
|
|
3020
|
-
if (driveType === REACTOR_DRIVE_DOCUMENT_TYPE) {
|
|
3021
|
-
const added = await requireReactorDriveClient(reactorDriveClient).addFile(driveId, document);
|
|
3022
|
-
return {
|
|
3023
|
-
documentId: added.header.id,
|
|
3024
|
-
branch: added.header.branch || DEFAULT_BRANCH
|
|
3025
|
-
};
|
|
3026
|
-
}
|
|
3088
|
+
async function addFileToDrive(clients, driveId, document) {
|
|
3027
3089
|
return (await clients.write.drives.addFile(driveId, document)).readable;
|
|
3028
3090
|
}
|
|
3029
3091
|
/** Removes a drive parent's node, waiting until the removal is readable. */
|
|
3030
|
-
async function removeNodeFromDrive(clients,
|
|
3031
|
-
if (driveType === REACTOR_DRIVE_DOCUMENT_TYPE) {
|
|
3032
|
-
await requireReactorDriveClient(reactorDriveClient).removeNode(driveId, nodeId);
|
|
3033
|
-
return;
|
|
3034
|
-
}
|
|
3092
|
+
async function removeNodeFromDrive(clients, driveId, nodeId) {
|
|
3035
3093
|
await (await clients.write.drives.removeNode(driveId, nodeId)).readable;
|
|
3036
3094
|
}
|
|
3037
3095
|
/**
|
|
@@ -3403,7 +3461,7 @@ async function assertSlugAvailable(read, slug, documentId) {
|
|
|
3403
3461
|
}
|
|
3404
3462
|
throw new GraphQLError(`The slug "${slug}" is taken by ${holder}; choose another.`);
|
|
3405
3463
|
}
|
|
3406
|
-
async function createDocument(clients, args,
|
|
3464
|
+
async function createDocument(clients, args, _reactorDriveClient, subject) {
|
|
3407
3465
|
if (!args.document || typeof args.document !== "object") throw new GraphQLError("Invalid document: must be an object");
|
|
3408
3466
|
const document = args.document;
|
|
3409
3467
|
if (!document.header || typeof document.header !== "object") throw new GraphQLError("Invalid document: missing or invalid header");
|
|
@@ -3413,7 +3471,7 @@ async function createDocument(clients, args, reactorDriveClient, subject) {
|
|
|
3413
3471
|
try {
|
|
3414
3472
|
if (parentIdOrSlug) {
|
|
3415
3473
|
const parent = await clients.read.get(parentIdOrSlug, subject && { subject });
|
|
3416
|
-
if (isDriveContainerType(parent.header.documentType)) receipt = await addFileToDrive(clients, parent.header.
|
|
3474
|
+
if (isDriveContainerType(parent.header.documentType)) receipt = await addFileToDrive(clients, parent.header.id, document);
|
|
3417
3475
|
else receipt = await (await clients.write.create(document, parentIdOrSlug)).readable;
|
|
3418
3476
|
} else receipt = await (await clients.write.create(document)).readable;
|
|
3419
3477
|
} catch (error) {
|
|
@@ -3426,7 +3484,7 @@ async function createDocument(clients, args, reactorDriveClient, subject) {
|
|
|
3426
3484
|
throw new GraphQLError(`Failed to convert created document to GraphQL: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3427
3485
|
}
|
|
3428
3486
|
}
|
|
3429
|
-
async function createEmptyDocument(clients, args,
|
|
3487
|
+
async function createEmptyDocument(clients, args, _reactorDriveClient, subject) {
|
|
3430
3488
|
const parentIdOrSlug = fromInputMaybe(args.parentIdOrSlug);
|
|
3431
3489
|
const name = fromInputMaybe(args.name);
|
|
3432
3490
|
let receipt;
|
|
@@ -3437,7 +3495,7 @@ async function createEmptyDocument(clients, args, reactorDriveClient, subject) {
|
|
|
3437
3495
|
const module = await clients.read.getDocumentModelModule(args.documentType);
|
|
3438
3496
|
const document = withSignaturePolicy(module.utils.createDocument(), await clients.read.getCreateSignaturePolicy());
|
|
3439
3497
|
if (name) document.header.name = name;
|
|
3440
|
-
receipt = await addFileToDrive(clients, parent.header.
|
|
3498
|
+
receipt = await addFileToDrive(clients, parent.header.id, document);
|
|
3441
3499
|
} else receipt = await (await clients.write.createEmpty(args.documentType, { parentIdentifier: parentIdOrSlug })).readable;
|
|
3442
3500
|
} else receipt = await (await clients.write.createEmpty(args.documentType, {})).readable;
|
|
3443
3501
|
} catch (error) {
|
|
@@ -3450,7 +3508,7 @@ async function createEmptyDocument(clients, args, reactorDriveClient, subject) {
|
|
|
3450
3508
|
throw new GraphQLError(`Failed to convert created document to GraphQL: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3451
3509
|
}
|
|
3452
3510
|
}
|
|
3453
|
-
async function createDocumentWithInitialState(clients, args,
|
|
3511
|
+
async function createDocumentWithInitialState(clients, args, _reactorDriveClient, subject) {
|
|
3454
3512
|
const parentIdOrSlug = fromInputMaybe(args.parentIdOrSlug);
|
|
3455
3513
|
const name = fromInputMaybe(args.name);
|
|
3456
3514
|
const slug = fromInputMaybe(args.slug);
|
|
@@ -3486,7 +3544,7 @@ async function createDocumentWithInitialState(clients, args, reactorDriveClient,
|
|
|
3486
3544
|
throw new GraphQLError(`Parent document not found: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3487
3545
|
}
|
|
3488
3546
|
if (isDriveContainerType(parent.header.documentType)) try {
|
|
3489
|
-
receipt = await addFileToDrive(clients, parent.header.
|
|
3547
|
+
receipt = await addFileToDrive(clients, parent.header.id, document);
|
|
3490
3548
|
} catch (error) {
|
|
3491
3549
|
throw new GraphQLError(`Failed to create document in drive: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3492
3550
|
}
|
|
@@ -3784,13 +3842,13 @@ async function moveRelationship(clients, args, subject) {
|
|
|
3784
3842
|
throw new GraphQLError(`Failed to convert documents to GraphQL: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
3785
3843
|
}
|
|
3786
3844
|
}
|
|
3787
|
-
async function deleteDocument(clients, args,
|
|
3845
|
+
async function deleteDocument(clients, args, _reactorDriveClient) {
|
|
3788
3846
|
const propagate = toReactorPropagationMode(args.propagate);
|
|
3789
3847
|
try {
|
|
3790
3848
|
const driveParent = (await clients.read.getIncomingRelationships(args.idOrSlug, "child")).results.find((p) => isDriveContainerType(p.header.documentType));
|
|
3791
3849
|
if (driveParent) {
|
|
3792
3850
|
const documentId = await clients.read.resolveIdOrSlug(args.idOrSlug);
|
|
3793
|
-
await removeNodeFromDrive(clients, driveParent.header.
|
|
3851
|
+
await removeNodeFromDrive(clients, driveParent.header.id, documentId);
|
|
3794
3852
|
} else await (await clients.write.deleteDocument(args.idOrSlug, propagate)).readable;
|
|
3795
3853
|
return true;
|
|
3796
3854
|
} catch (error) {
|
|
@@ -5391,6 +5449,8 @@ var GraphQLManager = class {
|
|
|
5391
5449
|
* it for reactor-drive parents.
|
|
5392
5450
|
*/
|
|
5393
5451
|
reactorDriveClient;
|
|
5452
|
+
/** See {@link GraphQLManagerOptions.driveNodes}. */
|
|
5453
|
+
driveNodes;
|
|
5394
5454
|
authorizationService;
|
|
5395
5455
|
/** Route service in use: the injected one, or one built on first need. */
|
|
5396
5456
|
#fallbackRoutes;
|
|
@@ -5449,6 +5509,7 @@ var GraphQLManager = class {
|
|
|
5449
5509
|
this.port = options.port ?? 4001;
|
|
5450
5510
|
this.authorizationService = options.authorizationService;
|
|
5451
5511
|
this.reactorDriveClient = options.reactorDriveClient;
|
|
5512
|
+
this.driveNodes = options.driveNodes;
|
|
5452
5513
|
this.syncServingGate = options.syncServingGate;
|
|
5453
5514
|
this.httpRoutes = options.httpRoutes;
|
|
5454
5515
|
this.attachments = options.attachments;
|
|
@@ -7225,6 +7286,19 @@ const CreateDefaultsDTO = z.object({
|
|
|
7225
7286
|
signaturePolicy: z.string(),
|
|
7226
7287
|
protocolVersions: JSONObjectDTO
|
|
7227
7288
|
}).strip();
|
|
7289
|
+
const DriveNodeDTO = z.object({
|
|
7290
|
+
id: z.string(),
|
|
7291
|
+
driveId: z.string(),
|
|
7292
|
+
name: z.string(),
|
|
7293
|
+
parentFolder: z.string().nullable().optional(),
|
|
7294
|
+
documentType: z.string().optional()
|
|
7295
|
+
}).strip();
|
|
7296
|
+
const DriveNodeListDTO = z.array(DriveNodeDTO);
|
|
7297
|
+
const DriveNodePageDTO = z.object({
|
|
7298
|
+
results: z.array(DriveNodeDTO),
|
|
7299
|
+
nextCursor: z.string().nullable().optional(),
|
|
7300
|
+
hasMore: z.boolean()
|
|
7301
|
+
}).strip();
|
|
7228
7302
|
const ActionEvaluationDTO = z.object({
|
|
7229
7303
|
decision: z.enum(["ALLOW", "DENY"]),
|
|
7230
7304
|
reason: z.string().nullable().optional()
|
|
@@ -7279,6 +7353,15 @@ const operationValidators = {
|
|
|
7279
7353
|
GetCreateDefaults: (data) => {
|
|
7280
7354
|
if (data.createDefaults) CreateDefaultsDTO.parse(data.createDefaults);
|
|
7281
7355
|
},
|
|
7356
|
+
GetDriveNodes: (data) => {
|
|
7357
|
+
if (data.driveNodes) DriveNodePageDTO.parse(data.driveNodes);
|
|
7358
|
+
},
|
|
7359
|
+
GetDriveNode: (data) => {
|
|
7360
|
+
if (data.driveNode) DriveNodeDTO.parse(data.driveNode);
|
|
7361
|
+
},
|
|
7362
|
+
GetDriveDescendants: (data) => {
|
|
7363
|
+
if (data.driveDescendants) DriveNodeListDTO.parse(data.driveDescendants);
|
|
7364
|
+
},
|
|
7282
7365
|
EvaluateActions: (data) => {
|
|
7283
7366
|
if (data.evaluateActions) ActionEvaluationsDTO.parse(data.evaluateActions);
|
|
7284
7367
|
},
|
|
@@ -7349,6 +7432,49 @@ function createReactorGraphQLClient(url, fetchImpl = fetch, headers) {
|
|
|
7349
7432
|
return getSdk(createValidatingRequester(url, fetchImpl, headers));
|
|
7350
7433
|
}
|
|
7351
7434
|
//#endregion
|
|
7435
|
+
//#region src/graphql/reactor/drive-nodes.ts
|
|
7436
|
+
const DEFAULT_LIMIT = 100;
|
|
7437
|
+
/** The node source, or the refusal a host without one answers with. */
|
|
7438
|
+
function requireDriveNodeSource(source) {
|
|
7439
|
+
if (!source) throw new GraphQLError("Drive node queries are unavailable: no drive node source is configured on this server", { extensions: { code: "DRIVE_NODE_SOURCE_NOT_CONFIGURED" } });
|
|
7440
|
+
return source;
|
|
7441
|
+
}
|
|
7442
|
+
/** The GraphQL type of a node record, for the `DriveNode` union. */
|
|
7443
|
+
function driveNodeTypeName(node) {
|
|
7444
|
+
const kind = node.kind;
|
|
7445
|
+
if (kind === "file" || kind === "folder") return kind === "file" ? "DriveFileNode" : "DriveFolderNode";
|
|
7446
|
+
return "documentType" in node ? "DriveFileNode" : "DriveFolderNode";
|
|
7447
|
+
}
|
|
7448
|
+
/** One node; undefined when absent or when the drive is withheld. */
|
|
7449
|
+
async function getServedNode(source, gate, driveId, nodeId) {
|
|
7450
|
+
if (!await gate.servesDrive(driveId)) return;
|
|
7451
|
+
return source.getNode(driveId, nodeId);
|
|
7452
|
+
}
|
|
7453
|
+
/** The descendants of `root`; empty when the drive is withheld. */
|
|
7454
|
+
async function getServedDescendants(source, gate, driveId, root) {
|
|
7455
|
+
if (!await gate.servesDrive(driveId)) return [];
|
|
7456
|
+
return source.getDescendants(driveId, root);
|
|
7457
|
+
}
|
|
7458
|
+
/** One page of nodes; empty when the drive is withheld. */
|
|
7459
|
+
async function listServedNodes(source, gate, driveId, parentFolder, paging, kind) {
|
|
7460
|
+
if (!await gate.servesDrive(driveId)) return {
|
|
7461
|
+
results: [],
|
|
7462
|
+
nextCursor: void 0,
|
|
7463
|
+
hasMore: false
|
|
7464
|
+
};
|
|
7465
|
+
const limit = paging?.limit ?? DEFAULT_LIMIT;
|
|
7466
|
+
const wanted = !kind ? void 0 : kind === "FILE" ? "file" : "folder";
|
|
7467
|
+
const page = await source.listChildren(driveId, parentFolder, {
|
|
7468
|
+
cursor: paging?.cursor ?? "",
|
|
7469
|
+
limit
|
|
7470
|
+
}, void 0, wanted);
|
|
7471
|
+
return {
|
|
7472
|
+
results: page.results,
|
|
7473
|
+
nextCursor: page.nextCursor,
|
|
7474
|
+
hasMore: page.nextCursor !== void 0
|
|
7475
|
+
};
|
|
7476
|
+
}
|
|
7477
|
+
//#endregion
|
|
7352
7478
|
//#region src/graphql/reactor/pubsub.ts
|
|
7353
7479
|
const pubSub = new PubSub();
|
|
7354
7480
|
function getPubSub() {
|
|
@@ -7517,6 +7643,20 @@ var ReactorSubgraph = class extends BaseSubgraph {
|
|
|
7517
7643
|
return handle;
|
|
7518
7644
|
}
|
|
7519
7645
|
/**
|
|
7646
|
+
* The read gate a drive node read passes, as the reactor-drive subgraph
|
|
7647
|
+
* applies it: the drive is listed to the caller (reactor read gate, then the
|
|
7648
|
+
* host's ACL); its nodes are then served as the legacy node list was.
|
|
7649
|
+
*/
|
|
7650
|
+
#driveNodeGate(ctx) {
|
|
7651
|
+
return { servesDrive: async (driveId) => {
|
|
7652
|
+
try {
|
|
7653
|
+
return await this.listsDocument(driveId, ctx);
|
|
7654
|
+
} catch {
|
|
7655
|
+
return false;
|
|
7656
|
+
}
|
|
7657
|
+
} };
|
|
7658
|
+
}
|
|
7659
|
+
/**
|
|
7520
7660
|
* Returns the drive id when the given identifier (id or slug) refers
|
|
7521
7661
|
* to a drive document, otherwise undefined. Used by deleteDocument to
|
|
7522
7662
|
* decide whether to invalidate the drive-ownership cache after a
|
|
@@ -7623,6 +7763,7 @@ var ReactorSubgraph = class extends BaseSubgraph {
|
|
|
7623
7763
|
}
|
|
7624
7764
|
typeDefs = gql(schema_default$2);
|
|
7625
7765
|
resolvers = {
|
|
7766
|
+
DriveNode: { __resolveType: (node) => driveNodeTypeName(node) },
|
|
7626
7767
|
PHDocument: { operations: async (parent, args, ctx) => {
|
|
7627
7768
|
this.logger.debug("PHDocument.operations(@parent.id, @args)", parent.id, args);
|
|
7628
7769
|
await this.assertCanReadCanonical(parent.id, ctx);
|
|
@@ -7791,6 +7932,18 @@ var ReactorSubgraph = class extends BaseSubgraph {
|
|
|
7791
7932
|
throw error;
|
|
7792
7933
|
}
|
|
7793
7934
|
},
|
|
7935
|
+
driveNodes: async (_parent, args, ctx) => {
|
|
7936
|
+
this.logger.debug("driveNodes(@args)", args);
|
|
7937
|
+
return listServedNodes(requireDriveNodeSource(this.graphqlManager.driveNodes), this.#driveNodeGate(ctx), args.driveId, "parentFolder" in args ? args.parentFolder ?? null : void 0, args.paging, args.kind);
|
|
7938
|
+
},
|
|
7939
|
+
driveNode: async (_parent, args, ctx) => {
|
|
7940
|
+
this.logger.debug("driveNode(@args)", args);
|
|
7941
|
+
return await getServedNode(requireDriveNodeSource(this.graphqlManager.driveNodes), this.#driveNodeGate(ctx), args.driveId, args.id) ?? null;
|
|
7942
|
+
},
|
|
7943
|
+
driveDescendants: async (_parent, args, ctx) => {
|
|
7944
|
+
this.logger.debug("driveDescendants(@args)", args);
|
|
7945
|
+
return getServedDescendants(requireDriveNodeSource(this.graphqlManager.driveNodes), this.#driveNodeGate(ctx), args.driveId, args.root);
|
|
7946
|
+
},
|
|
7794
7947
|
createDefaults: async (_parent, args, ctx) => {
|
|
7795
7948
|
this.logger.debug("createDefaults(@args)", args);
|
|
7796
7949
|
try {
|
|
@@ -8281,10 +8434,10 @@ const ADMIN_USERS = getAdminUsers();
|
|
|
8281
8434
|
//#endregion
|
|
8282
8435
|
//#region src/graphql/system/version.ts
|
|
8283
8436
|
function getVersion() {
|
|
8284
|
-
return "6.2.3-dev.
|
|
8437
|
+
return "6.2.3-dev.78";
|
|
8285
8438
|
}
|
|
8286
8439
|
function getGitHash() {
|
|
8287
|
-
return "
|
|
8440
|
+
return "1c899a137d71c6be7e24a23bbe2163e07f2cc5a1";
|
|
8288
8441
|
}
|
|
8289
8442
|
function getGitUrl() {
|
|
8290
8443
|
return buildTreeUrl(getGitHash());
|
|
@@ -10792,6 +10945,7 @@ function getDbClient(connectionString = void 0, pgliteFactory) {
|
|
|
10792
10945
|
const pgliteInstance = isPg ? void 0 : pgliteFactory ? pgliteFactory(connectionString) : connectionString ? new PGlite({
|
|
10793
10946
|
fs: createDurableNodeFs(NodeFS, connectionString, {
|
|
10794
10947
|
fsync: resolvePgliteFsync(process.env),
|
|
10948
|
+
...resolvePgliteMaintenance(process.env),
|
|
10795
10949
|
logger
|
|
10796
10950
|
}),
|
|
10797
10951
|
parsers: PGLITE_UTC_PARSERS
|
|
@@ -11041,7 +11195,7 @@ function resolveGatewayAdapterType(logger) {
|
|
|
11041
11195
|
/**
|
|
11042
11196
|
* Sets up the subgraph manager and registers subgraphs
|
|
11043
11197
|
*/
|
|
11044
|
-
async function setupGraphQLManager({ httpAdapter, authFetchMiddleware, requireAuthFetchMiddleware, httpServer, wsServer, clients, relationalDb, analyticsStore, syncManager, subgraphs, logger, authorizationService, authService, documentPermissionService, enableDocumentModelSubgraphs, port, reactorDriveClient, syncServingGate, httpRoutes, attachments, inspection, driveStore, reportError }) {
|
|
11198
|
+
async function setupGraphQLManager({ httpAdapter, authFetchMiddleware, requireAuthFetchMiddleware, httpServer, wsServer, clients, relationalDb, analyticsStore, syncManager, subgraphs, logger, authorizationService, authService, documentPermissionService, enableDocumentModelSubgraphs, port, reactorDriveClient, driveNodes, syncServingGate, httpRoutes, attachments, inspection, driveStore, reportError }) {
|
|
11045
11199
|
const graphqlManager = new GraphQLManager({
|
|
11046
11200
|
wsCredentialRecheckIntervalMs: resolveWsCredentialRecheckIntervalMs(process.env.WS_CREDENTIAL_RECHECK_INTERVAL_MS, logger),
|
|
11047
11201
|
path: config.basePath,
|
|
@@ -11062,6 +11216,7 @@ async function setupGraphQLManager({ httpAdapter, authFetchMiddleware, requireAu
|
|
|
11062
11216
|
port,
|
|
11063
11217
|
authorizationService,
|
|
11064
11218
|
reactorDriveClient,
|
|
11219
|
+
driveNodes,
|
|
11065
11220
|
syncServingGate,
|
|
11066
11221
|
httpRoutes,
|
|
11067
11222
|
attachments,
|
|
@@ -11093,6 +11248,11 @@ async function startServer(httpAdapter, port, httpsOptions, logger) {
|
|
|
11093
11248
|
wsServer
|
|
11094
11249
|
};
|
|
11095
11250
|
}
|
|
11251
|
+
function boundPortOf(httpServer) {
|
|
11252
|
+
const address = httpServer.address();
|
|
11253
|
+
if (address === null || typeof address === "string") throw new Error(`The HTTP server is not bound to a TCP port: ${String(address)}`);
|
|
11254
|
+
return address.port;
|
|
11255
|
+
}
|
|
11096
11256
|
/**
|
|
11097
11257
|
* Private helper function that sets up common infrastructure before API initialization.
|
|
11098
11258
|
* This includes auth configuration, database setup, and package manager initialization.
|
|
@@ -11258,7 +11418,8 @@ async function _setupCommonInfrastructure(options) {
|
|
|
11258
11418
|
packages: options.packages ?? [],
|
|
11259
11419
|
reportError: options.reportError
|
|
11260
11420
|
});
|
|
11261
|
-
const
|
|
11421
|
+
const listenPort = { current: port };
|
|
11422
|
+
const publicUrl = resolvePublicOrigin(listenPort);
|
|
11262
11423
|
const webhooks = new WebhookService({
|
|
11263
11424
|
store: new RelationalWebhookStore(relationalDb),
|
|
11264
11425
|
basePath: config.basePath,
|
|
@@ -11274,7 +11435,7 @@ async function _setupCommonInfrastructure(options) {
|
|
|
11274
11435
|
});
|
|
11275
11436
|
webhooks.attach(httpRoutes.hostScope(CORE_PACKAGE_NAME, path.posix.join("/", config.basePath ?? "/", WEBHOOK_SEGMENT)));
|
|
11276
11437
|
return {
|
|
11277
|
-
|
|
11438
|
+
listenPort,
|
|
11278
11439
|
httpAdapter,
|
|
11279
11440
|
httpRoutes,
|
|
11280
11441
|
authFetchMiddleware,
|
|
@@ -11297,7 +11458,7 @@ async function _setupCommonInfrastructure(options) {
|
|
|
11297
11458
|
/**
|
|
11298
11459
|
* Private helper function containing common setup logic for API initialization
|
|
11299
11460
|
*/
|
|
11300
|
-
async function _setupAPI(clients, syncManager, reactorProcessorManager, httpAdapter, authFetchMiddleware, requireAuthFetchMiddleware, authEnabled, authService,
|
|
11461
|
+
async function _setupAPI(clients, syncManager, reactorProcessorManager, httpAdapter, authFetchMiddleware, requireAuthFetchMiddleware, authEnabled, authService, listenPort, packages, relationalDb, analyticsStore, documentPermissionService, processors, subgraphs, options, processorApp, readModels, attachments, attachmentReferenceIndex, attachmentReferenceProjection, authorizationConfig, documentModelRegistry, dbClosers = [], reactorDriveClient, syncServingGate, httpRoutes, attachmentReadsFollowDocumentPolicy = false, inspection, driveStore, driveNodes) {
|
|
11301
11462
|
const hostModuleBase = {
|
|
11302
11463
|
...createReactorHostModuleBase({
|
|
11303
11464
|
client: clients.client,
|
|
@@ -11338,7 +11499,9 @@ async function _setupAPI(clients, syncManager, reactorProcessorManager, httpAdap
|
|
|
11338
11499
|
}
|
|
11339
11500
|
}))).flat());
|
|
11340
11501
|
}
|
|
11341
|
-
const { httpServer, wsServer } = await startServer(httpAdapter,
|
|
11502
|
+
const { httpServer, wsServer } = await startServer(httpAdapter, listenPort.current, options.https, logger);
|
|
11503
|
+
const boundPort = boundPortOf(httpServer);
|
|
11504
|
+
listenPort.current = boundPort;
|
|
11342
11505
|
const authorizationService = createAuthorizationService(authorizationConfig, documentPermissionService, createGetParentIdsFn(clients.read));
|
|
11343
11506
|
logger.info(`Authorization service initialized (policy: ${authorizationConfig.policy})`);
|
|
11344
11507
|
assertAttachmentPolicyReadsAllowed(attachmentReadsFollowDocumentPolicy, syncServingGate !== void 0);
|
|
@@ -11373,8 +11536,9 @@ async function _setupAPI(clients, syncManager, reactorProcessorManager, httpAdap
|
|
|
11373
11536
|
authService,
|
|
11374
11537
|
documentPermissionService,
|
|
11375
11538
|
enableDocumentModelSubgraphs: options.enableDocumentModelSubgraphs,
|
|
11376
|
-
port,
|
|
11539
|
+
port: boundPort,
|
|
11377
11540
|
reactorDriveClient,
|
|
11541
|
+
driveNodes,
|
|
11378
11542
|
syncServingGate,
|
|
11379
11543
|
httpRoutes,
|
|
11380
11544
|
attachments: attachmentClientProvider,
|
|
@@ -11392,7 +11556,7 @@ async function _setupAPI(clients, syncManager, reactorProcessorManager, httpAdap
|
|
|
11392
11556
|
syncManager,
|
|
11393
11557
|
authorizeRequest: createMcpRequestAuthorizer(authService, authorizationService)
|
|
11394
11558
|
}, httpAdapter);
|
|
11395
|
-
logger.info(`MCP server available at http://localhost:${
|
|
11559
|
+
logger.info(`MCP server available at http://localhost:${boundPort}/mcp`);
|
|
11396
11560
|
}
|
|
11397
11561
|
const dispose = buildApiDispose({
|
|
11398
11562
|
graphqlManager,
|
|
@@ -11404,6 +11568,7 @@ async function _setupAPI(clients, syncManager, reactorProcessorManager, httpAdap
|
|
|
11404
11568
|
});
|
|
11405
11569
|
return {
|
|
11406
11570
|
httpAdapter,
|
|
11571
|
+
port: boundPort,
|
|
11407
11572
|
httpServer,
|
|
11408
11573
|
httpRoutes: httpRoutes ?? new HttpRouteService({ httpAdapter }),
|
|
11409
11574
|
graphqlManager,
|
|
@@ -11499,9 +11664,9 @@ function resolvePermissionCacheTtlMs(raw, logger) {
|
|
|
11499
11664
|
return parsed;
|
|
11500
11665
|
}
|
|
11501
11666
|
async function initializeAndStartAPI(clientInitializer, options, processorApp) {
|
|
11502
|
-
const {
|
|
11667
|
+
const { listenPort, httpAdapter, httpRoutes, authFetchMiddleware, requireAuthFetchMiddleware, authEnabled, authService, relationalDb, analyticsStore, documentPermissionService: providedDocumentPermissionService, ownDocumentPermissions, authorizationConfig, attachments, attachmentReferenceIndex, packages, dbClosers, readiness, attachmentReadsFollowDocumentPolicy } = await _setupCommonInfrastructure(options);
|
|
11503
11668
|
const { documentModels, upgradeManifests, processors, subgraphs } = await packages.init();
|
|
11504
|
-
const { module: reactorClientModule, reactorDriveClient, attachmentReferenceProjection = {
|
|
11669
|
+
const { module: reactorClientModule, reactorDriveClient, driveNodes, attachmentReferenceProjection = {
|
|
11505
11670
|
status: "unavailable",
|
|
11506
11671
|
reason: "initializer-did-not-report"
|
|
11507
11672
|
}, permissionsDb } = await clientInitializer(documentModels, {
|
|
@@ -11523,11 +11688,11 @@ async function initializeAndStartAPI(clientInitializer, options, processorApp) {
|
|
|
11523
11688
|
read: reactorClientModule.read,
|
|
11524
11689
|
write: reactorClientModule.write,
|
|
11525
11690
|
client: reactorClient
|
|
11526
|
-
}, syncManager, reactorProcessorManager, httpAdapter, authFetchMiddleware, requireAuthFetchMiddleware, authEnabled, authService,
|
|
11691
|
+
}, syncManager, reactorProcessorManager, httpAdapter, authFetchMiddleware, requireAuthFetchMiddleware, authEnabled, authService, listenPort, packages, relationalDb, analyticsStore, documentPermissionService, processors, subgraphs, options, processorApp, readModels, attachments, attachmentReferenceIndex, attachmentReferenceProjection, authorizationConfig, documentModelRegistry, dbClosers, reactorDriveClient, buildSyncServingGate(reactorClientModule.reactorModule, authorizationConfig, options.logger ?? defaultLogger), httpRoutes, attachmentReadsFollowDocumentPolicy, reactorClientModule.reactorModule && options.inspection !== false ? createReactorInspectionSource(reactorClientModule.reactorModule, {
|
|
11527
11692
|
admin: process.env.INSPECTION_ADMIN_ENABLED === "true",
|
|
11528
11693
|
...options.inspection,
|
|
11529
11694
|
attachmentStore: attachmentInspectionStore(attachments)
|
|
11530
|
-
}) : void 0, reactorClientModule.reactorModule?.reactor),
|
|
11695
|
+
}) : void 0, reactorClientModule.reactorModule?.reactor, driveNodes),
|
|
11531
11696
|
client: reactorClient,
|
|
11532
11697
|
read: reactorClientModule.read,
|
|
11533
11698
|
write: reactorClientModule.write,
|
|
@@ -11548,12 +11713,12 @@ async function initializeAndStartAPI(clientInitializer, options, processorApp) {
|
|
|
11548
11713
|
* dev` behind a tunnel and, at worst, obviously wrong rather than silently
|
|
11549
11714
|
* unusable.
|
|
11550
11715
|
*/
|
|
11551
|
-
function resolvePublicOrigin(
|
|
11716
|
+
function resolvePublicOrigin(listenPort) {
|
|
11552
11717
|
const explicit = process.env.PUBLIC_URL ?? process.env.RENDER_EXTERNAL_URL;
|
|
11553
11718
|
if (explicit) return withScheme(explicit);
|
|
11554
11719
|
const domain = process.env.HEROKU_APP_DEFAULT_DOMAIN_NAME;
|
|
11555
11720
|
if (domain) return withScheme(domain);
|
|
11556
|
-
return `http://localhost:${
|
|
11721
|
+
return () => `http://localhost:${listenPort.current}`;
|
|
11557
11722
|
}
|
|
11558
11723
|
function withScheme(origin) {
|
|
11559
11724
|
const trimmed = origin.replace(/\/+$/, "");
|
|
@@ -11718,7 +11883,7 @@ var PackageManagementService = class {
|
|
|
11718
11883
|
}
|
|
11719
11884
|
};
|
|
11720
11885
|
//#endregion
|
|
11721
|
-
export { ADMIN_USERS, ActionCandidateInputSchema, ActionContextInputSchema, ActionInputSchema, AddRelationshipDocument, AnalyticsSubgraph, AttachmentAccessFailed, AttachmentAccessService, AttachmentAccessUnavailable, AttachmentClientProvider, AuthDecision, AuthDecisionSchema, AuthEvaluationUnsupportedError, AuthService, AuthSubgraph, AuthenticationRequiredError, AuthorizationPolicy, AuthorizedAttachmentService, AuthorizedDocumentHandle, BaseSubgraph, CORE_PACKAGE_NAME, CanonicalDocumentIdResolutionError, ChannelMetaInputSchema, ConsistencyCoordinateInputSchema, ConsistencyTokenInputSchema, CreateDocumentDocument, CreateEmptyDocumentDocument, DEFAULT_INSPECTION_THROTTLE, DEFAULT_PERMISSION_CACHE_OPTIONS, DEFAULT_PERMISSION_CACHE_TTL_MS, DeleteDocumentDocument, DeleteDocumentsDocument, DocumentChangeType, DocumentChangeTypeSchema, DocumentChangesDocument, DocumentModelSchemaCache, DocumentOperationsFilterInputSchema, DocumentPermissionService, DocumentPermissionSnapshot, DocumentRelationshipFieldsFragmentDoc, EvaluateActionsDocument, ExecuteBatchDocument, ExecutionJobInputSchema, FindDocumentsDocument, ForbiddenError, GetCreateDefaultsDocument, GetDocumentDocument, GetDocumentIncomingRelationshipEdgesDocument, GetDocumentIncomingRelationshipsDocument, GetDocumentModelsDocument, GetDocumentOperationsDocument, GetDocumentOutgoingRelationshipEdgesDocument, GetDocumentOutgoingRelationshipsDocument, GetDocumentServedDocument, GetDocumentWithOperationsDocument, GetJobStatusDocument, GraphQLManager, HttpDocumentModelLoader, HttpPackageLoader, HttpRouteService, ImportPackageLoader, InMemoryPackageStorage, InspectionAdminSubgraph, InspectionSubgraph, InspectionThrottle, InspectionThrottledError, InvalidNamespaceError, JobChangesDocument, JobInfoFieldsFragmentDoc, MalformedStoredOperationError, MemoryWebhookStore, MoveRelationshipDocument, MutateDocumentAsyncDocument, MutateDocumentDocument, NodeEventLoopDelay, OperationContextInputSchema, OperationInputSchema, OperationWithContextInputSchema, OperationsFilterInputSchema, PACKAGE_ROUTE_SEGMENT, PGLITE_UTC_PARSERS, PackageManagementService, PackageManager, PackagesSubgraph, PagingInputSchema, PermissionCache, PhDocumentFieldsFragmentDoc, PollSyncEnvelopesDocument, PrivacyPermissionAdapter, PropagationMode, PropagationModeSchema, PushSyncEnvelopesDocument, ReactorSignerAppInputSchema, ReactorSignerInputSchema, ReactorSignerUserInputSchema, ReactorSubgraph, RefusalNotRecordedError, RelationalWebhookStore, RemoteCursorInputSchema, RemoteFilterInputSchema, RemoveRelationshipDocument, RenameDocumentDocument, RequestLoadRecorder, SearchFilterInputSchema, SetPreferredEditorDocument, SubgraphTypeCollisionError, SyncEnvelopeInputSchema, SyncEnvelopeType, SyncEnvelopeTypeSchema, SyncRefusalInputSchema, SystemSubgraph, TouchChannelDocument, TouchChannelInputSchema, UpdateRelationshipDocument, ViewFilterInputSchema, WEBHOOK_SEGMENT, WS_AUTH_CLOSE_REASONS, WS_CLOSE_REASON_AUTHENTICATION_REQUIRED, WS_CLOSE_REASON_BEARER_REJECTED, WS_CLOSE_REASON_CREDENTIAL_REVOKED, WebhookService, assembleSubgraphTypeDefs, assertAttachmentPolicyReadsAllowed, assertAuthRequiredForDocumentPermissions, assertCredentialVerifierForSource, assertHostMountPath, assertRequireAuthenticatedCallerAllowed, assertSkipCredentialVerificationAllowed, baseDocumentModels, buildDocumentModelSchema, buildGraphQlDocument, buildGraphQlDriveDocument, buildGraphqlOperation, buildGraphqlOperations, buildSubgraphSchemaModule, callerSubject, createAuthFetchMiddleware, createCanonicalDocumentIdResolver, createCredentialInvalidator, createGatewayAdapter, createHttpAdapter, createInspectionResolvers, createMergedSchema, createReactorGraphQLClient, createReactorInspectionSource, createRenownCredentialVerifier, createSchema, createWsAuthHandlers, decodeExplorerUrlState, definedNonNullAnySchema, documentModelSubgraphTypes, driveIdFromUrl, extractSubgraphs, extractSubgraphsFromModule, findSubgraphTypeCollisions, generateDocumentModelSchema, generatedTypesOf, getAuthContext, getDbClient, getDocumentModelSchemaName, getDocumentModelSubgraphName, getDocumentModelTypeDefs, getExplorerPrefix, getGeneratedDocumentModelTypes, getGitHash, getGitUrl, getSdk, getUniqueDocumentModels, getUniqueUpgradeManifests, getVersion, hasOperationSchemas, initAnalyticsStoreSql, initializeAndStartAPI, inspectionAdminTypeDefs, inspectionTypeDefs, isCountedRequest, isDefinedNonNullAny, isExpectedLoaderMiss, isListedAdmin, isPostgresConnectionString, isSubgraphClass, namespacePath, namespaceSegments, newWebhookToken, parseDriveUrl, parseWebhookBody, piecesBaseUrl, redactHeaders, renderGraphqlPlayground, reportFailure, reservedTypeNames, reservedTypeNamesTaken, resolveCredentialCacheTtlMs, resolvePackageName, resolvePermissionCacheTtlMs, resolveRenownConfig, runDetached, typeDefinitionNames, verifyWebhook };
|
|
11886
|
+
export { ADMIN_USERS, ActionCandidateInputSchema, ActionContextInputSchema, ActionInputSchema, AddRelationshipDocument, AnalyticsSubgraph, AttachmentAccessFailed, AttachmentAccessService, AttachmentAccessUnavailable, AttachmentClientProvider, AuthDecision, AuthDecisionSchema, AuthEvaluationUnsupportedError, AuthService, AuthSubgraph, AuthenticationRequiredError, AuthorizationPolicy, AuthorizedAttachmentService, AuthorizedDocumentHandle, BaseSubgraph, CORE_PACKAGE_NAME, CanonicalDocumentIdResolutionError, ChannelMetaInputSchema, ConsistencyCoordinateInputSchema, ConsistencyTokenInputSchema, CreateDocumentDocument, CreateEmptyDocumentDocument, DEFAULT_INSPECTION_THROTTLE, DEFAULT_PERMISSION_CACHE_OPTIONS, DEFAULT_PERMISSION_CACHE_TTL_MS, DeleteDocumentDocument, DeleteDocumentsDocument, DocumentChangeType, DocumentChangeTypeSchema, DocumentChangesDocument, DocumentModelSchemaCache, DocumentOperationsFilterInputSchema, DocumentPermissionService, DocumentPermissionSnapshot, DocumentRelationshipFieldsFragmentDoc, DriveNodeFieldsFragmentDoc, DriveNodeKind, DriveNodeKindSchema, EvaluateActionsDocument, ExecuteBatchDocument, ExecutionJobInputSchema, FindDocumentsDocument, ForbiddenError, GetCreateDefaultsDocument, GetDocumentDocument, GetDocumentIncomingRelationshipEdgesDocument, GetDocumentIncomingRelationshipsDocument, GetDocumentModelsDocument, GetDocumentOperationsDocument, GetDocumentOutgoingRelationshipEdgesDocument, GetDocumentOutgoingRelationshipsDocument, GetDocumentServedDocument, GetDocumentWithOperationsDocument, GetDriveDescendantsDocument, GetDriveNodeDocument, GetDriveNodesDocument, GetJobStatusDocument, GraphQLManager, HttpDocumentModelLoader, HttpPackageLoader, HttpRouteService, ImportPackageLoader, InMemoryPackageStorage, InspectionAdminSubgraph, InspectionSubgraph, InspectionThrottle, InspectionThrottledError, InvalidNamespaceError, JobChangesDocument, JobInfoFieldsFragmentDoc, MalformedStoredOperationError, MemoryWebhookStore, MoveRelationshipDocument, MutateDocumentAsyncDocument, MutateDocumentDocument, NodeEventLoopDelay, OperationContextInputSchema, OperationInputSchema, OperationWithContextInputSchema, OperationsFilterInputSchema, PACKAGE_ROUTE_SEGMENT, PGLITE_UTC_PARSERS, PackageManagementService, PackageManager, PackagesSubgraph, PagingInputSchema, PermissionCache, PhDocumentFieldsFragmentDoc, PollSyncEnvelopesDocument, PrivacyPermissionAdapter, PropagationMode, PropagationModeSchema, PushSyncEnvelopesDocument, ReactorSignerAppInputSchema, ReactorSignerInputSchema, ReactorSignerUserInputSchema, ReactorSubgraph, RefusalNotRecordedError, RelationalWebhookStore, RemoteCursorInputSchema, RemoteFilterInputSchema, RemoveRelationshipDocument, RenameDocumentDocument, RequestLoadRecorder, SearchFilterInputSchema, SetPreferredEditorDocument, SubgraphTypeCollisionError, SyncEnvelopeInputSchema, SyncEnvelopeType, SyncEnvelopeTypeSchema, SyncRefusalInputSchema, SystemSubgraph, TouchChannelDocument, TouchChannelInputSchema, UpdateRelationshipDocument, ViewFilterInputSchema, WEBHOOK_SEGMENT, WS_AUTH_CLOSE_REASONS, WS_CLOSE_REASON_AUTHENTICATION_REQUIRED, WS_CLOSE_REASON_BEARER_REJECTED, WS_CLOSE_REASON_CREDENTIAL_REVOKED, WebhookService, assembleSubgraphTypeDefs, assertAttachmentPolicyReadsAllowed, assertAuthRequiredForDocumentPermissions, assertCredentialVerifierForSource, assertHostMountPath, assertRequireAuthenticatedCallerAllowed, assertSkipCredentialVerificationAllowed, baseDocumentModels, buildDocumentModelSchema, buildGraphQlDocument, buildGraphQlDriveDocument, buildGraphqlOperation, buildGraphqlOperations, buildSubgraphSchemaModule, callerSubject, createAuthFetchMiddleware, createCanonicalDocumentIdResolver, createCredentialInvalidator, createGatewayAdapter, createHttpAdapter, createInspectionResolvers, createMergedSchema, createReactorGraphQLClient, createReactorInspectionSource, createRenownCredentialVerifier, createSchema, createWsAuthHandlers, decodeExplorerUrlState, definedNonNullAnySchema, documentModelSubgraphTypes, driveIdFromUrl, extractSubgraphs, extractSubgraphsFromModule, findSubgraphTypeCollisions, generateDocumentModelSchema, generatedTypesOf, getAuthContext, getDbClient, getDocumentModelSchemaName, getDocumentModelSubgraphName, getDocumentModelTypeDefs, getExplorerPrefix, getGeneratedDocumentModelTypes, getGitHash, getGitUrl, getSdk, getUniqueDocumentModels, getUniqueUpgradeManifests, getVersion, hasOperationSchemas, initAnalyticsStoreSql, initializeAndStartAPI, inspectionAdminTypeDefs, inspectionTypeDefs, isCountedRequest, isDefinedNonNullAny, isExpectedLoaderMiss, isListedAdmin, isPostgresConnectionString, isSubgraphClass, namespacePath, namespaceSegments, newWebhookToken, parseDriveUrl, parseWebhookBody, piecesBaseUrl, redactHeaders, renderGraphqlPlayground, reportFailure, reservedTypeNames, reservedTypeNamesTaken, resolveCredentialCacheTtlMs, resolvePackageName, resolvePermissionCacheTtlMs, resolveRenownConfig, runDetached, typeDefinitionNames, verifyWebhook };
|
|
11722
11887
|
|
|
11723
11888
|
//# sourceMappingURL=index.mjs.map
|
|
11724
|
-
//# debugId=
|
|
11889
|
+
//# debugId=d978d340-82ad-56d2-8827-0daf9ed3bf67
|