@geekmidas/constructs 10.0.0-alpha.131 → 10.0.0-alpha.132
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/endpoints/index.cjs +7 -0
- package/dist/endpoints/index.d.cts +2 -1
- package/dist/endpoints/index.d.cts.map +1 -1
- package/dist/endpoints/index.d.mts +2 -1
- package/dist/endpoints/index.d.mts.map +1 -1
- package/dist/endpoints/index.mjs +2 -1
- package/dist/site.cjs +55 -1
- package/dist/site.cjs.map +1 -1
- package/dist/site.d.cts +46 -0
- package/dist/site.d.cts.map +1 -1
- package/dist/site.d.mts +46 -0
- package/dist/site.d.mts.map +1 -1
- package/dist/site.mjs +53 -3
- package/dist/site.mjs.map +1 -1
- package/dist/websocket-api.cjs +1 -1
- package/dist/websocket-api.cjs.map +1 -1
- package/dist/websocket-api.d.cts.map +1 -1
- package/dist/websocket-api.d.mts.map +1 -1
- package/dist/websocket-api.mjs +2 -2
- package/dist/websocket-api.mjs.map +1 -1
- package/package.json +31 -31
package/dist/endpoints/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ const require_functions = require("../functions-DLF6-IK8.cjs");
|
|
|
4
4
|
const require_Endpoint = require("../Endpoint-BcUorcBa.cjs");
|
|
5
5
|
const require_surfaceEnv = require("../surfaceEnv-CNimK76p.cjs");
|
|
6
6
|
const require_readRequestBody = require("../readRequestBody-Dej_L3c4.cjs");
|
|
7
|
+
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
7
8
|
exports.BUILT_IN_SECURITY_SCHEMES = require_EndpointFactory.BUILT_IN_SECURITY_SCHEMES;
|
|
8
9
|
exports.Endpoint = require_Endpoint.Endpoint;
|
|
9
10
|
exports.EndpointBuilder = require_EndpointFactory.EndpointBuilder;
|
|
@@ -36,3 +37,9 @@ exports.getSecurityScheme = require_EndpointFactory.getSecurityScheme;
|
|
|
36
37
|
exports.isBuiltInSecurityScheme = require_EndpointFactory.isBuiltInSecurityScheme;
|
|
37
38
|
exports.publishConstructEvents = require_functions.publishConstructEvents;
|
|
38
39
|
exports.readRequestBody = require_readRequestBody.readRequestBody;
|
|
40
|
+
Object.defineProperty(exports, "trustsOrigin", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function() {
|
|
43
|
+
return _geekmidas_manifest.trustsOrigin;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -2,6 +2,7 @@ import { s as publishConstructEvents } from "../Construct-127M7yrl.cjs";
|
|
|
2
2
|
import { A as SecurityScheme, C as ActorExtractor, D as BuiltInSecuritySchemeId, E as BUILT_IN_SECURITY_SCHEMES, M as getSecurityScheme, N as isBuiltInSecurityScheme, O as OAuthFlow, S as RlsContextExtractor, T as Authorizer, _ as SessionAuth, a as EndpointContext, b as RlsConfig, c as EndpointSchemas, d as HeaderFn, f as RedirectStatus, g as NoAuthenticator, h as SuccessStatus, i as Endpoint, j as createAuthorizer, k as OAuthFlows, l as EndpointStatus, n as ConvertRouteParams, o as EndpointHandler, p as ResponseBuilder, r as CookieFn, s as EndpointOutput, u as EndpointSurface, v as RLS_BYPASS, w as MappedAudit, x as RlsContext, y as RlsBypass } from "../Endpoint-BEh-jW-f.cjs";
|
|
3
3
|
import { a as UPLOAD_POST_SCHEMA, c as UploadContentTypeUnresolved, d as UploadOptions, f as UploadPost, i as UploadHandler, l as UploadExpiryInvalid, n as EndpointBuilder, o as UploadAcceptInvalid, r as UploadEndpointBuilder, s as UploadContentTypeRefused, t as EndpointFactory, u as UploadMaxSizeInvalid } from "../EndpointFactory-B2dCS9dy.cjs";
|
|
4
4
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
5
|
+
import { trustsOrigin } from "@geekmidas/manifest";
|
|
5
6
|
import { Context } from "hono";
|
|
6
7
|
import { HttpError } from "@geekmidas/errors";
|
|
7
8
|
//#region src/endpoints/lazyAccessors.d.ts
|
|
@@ -101,5 +102,5 @@ export declare function defaultEnvParser(): EnvironmentParser<{}>;
|
|
|
101
102
|
/** The parser for an endpoint, from its surface or the default. */
|
|
102
103
|
export declare function envParserFor(surface: EndpointSurface | undefined): EnvironmentParser<{}>;
|
|
103
104
|
//#endregion
|
|
104
|
-
export { type ActorExtractor, type Authorizer, BUILT_IN_SECURITY_SCHEMES, type BuiltInSecuritySchemeId, type ConvertRouteParams, Endpoint, EndpointBuilder, type EndpointContext, EndpointFactory, type EndpointHandler, type EndpointOutput, type EndpointSchemas, type EndpointStatus, type MappedAudit, NoAuthenticator, type OAuthFlow, type OAuthFlows, RLS_BYPASS, RedirectStatus, type RequestBodySource, ResponseBuilder, type RlsBypass, type RlsConfig, type RlsContext, type RlsContextExtractor, type SecurityScheme, type SessionAuth, SuccessStatus, UPLOAD_POST_SCHEMA, UploadAcceptInvalid, UploadContentTypeRefused, UploadContentTypeUnresolved, UploadEndpointBuilder, UploadExpiryInvalid, type UploadHandler, UploadMaxSizeInvalid, type UploadOptions, type UploadPost, createAuthorizer, getSecurityScheme, isBuiltInSecurityScheme, publishConstructEvents };
|
|
105
|
+
export { type ActorExtractor, type Authorizer, BUILT_IN_SECURITY_SCHEMES, type BuiltInSecuritySchemeId, type ConvertRouteParams, Endpoint, EndpointBuilder, type EndpointContext, EndpointFactory, type EndpointHandler, type EndpointOutput, type EndpointSchemas, type EndpointStatus, type MappedAudit, NoAuthenticator, type OAuthFlow, type OAuthFlows, RLS_BYPASS, RedirectStatus, type RequestBodySource, ResponseBuilder, type RlsBypass, type RlsConfig, type RlsContext, type RlsContextExtractor, type SecurityScheme, type SessionAuth, SuccessStatus, UPLOAD_POST_SCHEMA, UploadAcceptInvalid, UploadContentTypeRefused, UploadContentTypeUnresolved, UploadEndpointBuilder, UploadExpiryInvalid, type UploadHandler, UploadMaxSizeInvalid, type UploadOptions, type UploadPost, createAuthorizer, getSecurityScheme, isBuiltInSecurityScheme, publishConstructEvents, trustsOrigin };
|
|
105
106
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/endpoints/lazyAccessors.ts","../../src/endpoints/readRequestBody.ts","../../src/endpoints/surfaceEnv.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/endpoints/lazyAccessors.ts","../../src/endpoints/readRequestBody.ts","../../src/endpoints/surfaceEnv.ts"],"mappings":";;;;;;;;;;;;;wBAgBgB,kBAAkB,GAAG,UAAU;;;;;;wBAqB/B,kBAAkB,GAAG,UAAU;;;;;wBAgC/B,wBACf,SAAS,wDACP;;;;;wBAoCa,wBACf,+BACA,mCACE;;;;wBAmHa,qBAAqB;;;;wBAUrB,qBAAqB;;;;;;;qBCrOxB;;;;;qBAWA,sCAAsC;WAC7B;EAArB,YAAqB;;;;;;qBAiBT,6BAA6B;WAE/B;EADV,YACU,qBACT,QAAQ;;;;;;UAeO;EAChB,QAAQ;EACR,QAAQ;EACR,YAAY,QAAQ;;UAGJ;;;;;;EAMhB;;;;;;;;;;;;;;wBAeqB,gBACrB,QAAQ,mBACR,wCACA,SAAS,yBACP;;;;;;;;;;wBCnDa,oBAAoB;;wBASpB,aACf,SAAS,8BACP"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { s as publishConstructEvents } from "../Construct-DySlwh8o.mjs";
|
|
2
2
|
import { A as SecurityScheme, C as ActorExtractor, D as BuiltInSecuritySchemeId, E as BUILT_IN_SECURITY_SCHEMES, M as getSecurityScheme, N as isBuiltInSecurityScheme, O as OAuthFlow, S as RlsContextExtractor, T as Authorizer, _ as SessionAuth, a as EndpointContext, b as RlsConfig, c as EndpointSchemas, d as HeaderFn, f as RedirectStatus, g as NoAuthenticator, h as SuccessStatus, i as Endpoint, j as createAuthorizer, k as OAuthFlows, l as EndpointStatus, n as ConvertRouteParams, o as EndpointHandler, p as ResponseBuilder, r as CookieFn, s as EndpointOutput, u as EndpointSurface, v as RLS_BYPASS, w as MappedAudit, x as RlsContext, y as RlsBypass } from "../Endpoint-DTXDggNl.mjs";
|
|
3
3
|
import { a as UPLOAD_POST_SCHEMA, c as UploadContentTypeUnresolved, d as UploadOptions, f as UploadPost, i as UploadHandler, l as UploadExpiryInvalid, n as EndpointBuilder, o as UploadAcceptInvalid, r as UploadEndpointBuilder, s as UploadContentTypeRefused, t as EndpointFactory, u as UploadMaxSizeInvalid } from "../EndpointFactory-D2HXcUrJ.mjs";
|
|
4
|
+
import { trustsOrigin } from "@geekmidas/manifest";
|
|
4
5
|
import { HttpError } from "@geekmidas/errors";
|
|
5
6
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
6
7
|
import { Context } from "hono";
|
|
@@ -101,5 +102,5 @@ export declare function defaultEnvParser(): EnvironmentParser<{}>;
|
|
|
101
102
|
/** The parser for an endpoint, from its surface or the default. */
|
|
102
103
|
export declare function envParserFor(surface: EndpointSurface | undefined): EnvironmentParser<{}>;
|
|
103
104
|
//#endregion
|
|
104
|
-
export { type ActorExtractor, type Authorizer, BUILT_IN_SECURITY_SCHEMES, type BuiltInSecuritySchemeId, type ConvertRouteParams, Endpoint, EndpointBuilder, type EndpointContext, EndpointFactory, type EndpointHandler, type EndpointOutput, type EndpointSchemas, type EndpointStatus, type MappedAudit, NoAuthenticator, type OAuthFlow, type OAuthFlows, RLS_BYPASS, RedirectStatus, type RequestBodySource, ResponseBuilder, type RlsBypass, type RlsConfig, type RlsContext, type RlsContextExtractor, type SecurityScheme, type SessionAuth, SuccessStatus, UPLOAD_POST_SCHEMA, UploadAcceptInvalid, UploadContentTypeRefused, UploadContentTypeUnresolved, UploadEndpointBuilder, UploadExpiryInvalid, type UploadHandler, UploadMaxSizeInvalid, type UploadOptions, type UploadPost, createAuthorizer, getSecurityScheme, isBuiltInSecurityScheme, publishConstructEvents };
|
|
105
|
+
export { type ActorExtractor, type Authorizer, BUILT_IN_SECURITY_SCHEMES, type BuiltInSecuritySchemeId, type ConvertRouteParams, Endpoint, EndpointBuilder, type EndpointContext, EndpointFactory, type EndpointHandler, type EndpointOutput, type EndpointSchemas, type EndpointStatus, type MappedAudit, NoAuthenticator, type OAuthFlow, type OAuthFlows, RLS_BYPASS, RedirectStatus, type RequestBodySource, ResponseBuilder, type RlsBypass, type RlsConfig, type RlsContext, type RlsContextExtractor, type SecurityScheme, type SessionAuth, SuccessStatus, UPLOAD_POST_SCHEMA, UploadAcceptInvalid, UploadContentTypeRefused, UploadContentTypeUnresolved, UploadEndpointBuilder, UploadExpiryInvalid, type UploadHandler, UploadMaxSizeInvalid, type UploadOptions, type UploadPost, createAuthorizer, getSecurityScheme, isBuiltInSecurityScheme, publishConstructEvents, trustsOrigin };
|
|
105
106
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/endpoints/lazyAccessors.ts","../../src/endpoints/readRequestBody.ts","../../src/endpoints/surfaceEnv.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/endpoints/lazyAccessors.ts","../../src/endpoints/readRequestBody.ts","../../src/endpoints/surfaceEnv.ts"],"mappings":";;;;;;;;;;;;;wBAgBgB,kBAAkB,GAAG,UAAU;;;;;;wBAqB/B,kBAAkB,GAAG,UAAU;;;;;wBAgC/B,wBACf,SAAS,wDACP;;;;;wBAoCa,wBACf,+BACA,mCACE;;;;wBAmHa,qBAAqB;;;;wBAUrB,qBAAqB;;;;;;;qBCrOxB;;;;;qBAWA,sCAAsC;WAC7B;EAArB,YAAqB;;;;;;qBAiBT,6BAA6B;WAE/B;EADV,YACU,qBACT,QAAQ;;;;;;UAeO;EAChB,QAAQ;EACR,QAAQ;EACR,YAAY,QAAQ;;UAGJ;;;;;;EAMhB;;;;;;;;;;;;;;wBAeqB,gBACrB,QAAQ,mBACR,wCACA,SAAS,yBACP;;;;;;;;;;wBCnDa,oBAAoB;;wBASpB,aACf,SAAS,8BACP"}
|
package/dist/endpoints/index.mjs
CHANGED
|
@@ -3,4 +3,5 @@ import { i as publishConstructEvents } from "../functions-BvIDQKAA.mjs";
|
|
|
3
3
|
import { a as NoAuthenticator, i as SuccessStatus, n as RedirectStatus, r as ResponseBuilder, t as Endpoint } from "../Endpoint-BgvG36NO.mjs";
|
|
4
4
|
import { n as envParserFor, t as defaultEnvParser } from "../surfaceEnv-wMT5QzgZ.mjs";
|
|
5
5
|
import { a as createApiGatewayCookies, c as createHonoCookies, d as createNoopHeaders, i as readRequestBody, l as createHonoHeaders, n as SUPPORTED_BODY_TYPES, o as createApiGatewayHeaders, r as UnsupportedRequestContentType, t as MalformedRequestBody, u as createNoopCookies } from "../readRequestBody-BTIl3k-D.mjs";
|
|
6
|
-
|
|
6
|
+
import { trustsOrigin } from "@geekmidas/manifest";
|
|
7
|
+
export { BUILT_IN_SECURITY_SCHEMES, Endpoint, EndpointBuilder, EndpointFactory, MalformedRequestBody, NoAuthenticator, RLS_BYPASS, RedirectStatus, ResponseBuilder, SUPPORTED_BODY_TYPES, SuccessStatus, UPLOAD_POST_SCHEMA, UnsupportedRequestContentType, UploadAcceptInvalid, UploadContentTypeRefused, UploadContentTypeUnresolved, UploadEndpointBuilder, UploadExpiryInvalid, UploadMaxSizeInvalid, createApiGatewayCookies, createApiGatewayHeaders, createAuthorizer, createHonoCookies, createHonoHeaders, createNoopCookies, createNoopHeaders, defaultEnvParser, envParserFor, getSecurityScheme, isBuiltInSecurityScheme, publishConstructEvents, readRequestBody, trustsOrigin };
|
package/dist/site.cjs
CHANGED
|
@@ -25,6 +25,46 @@ let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
|
25
25
|
* is not a site — it is reached by a scheme, not a URL — and is its own
|
|
26
26
|
* construct: see `MobileApp`.
|
|
27
27
|
*/
|
|
28
|
+
/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */
|
|
29
|
+
var WildcardSiteNeedsHosts = class extends Error {
|
|
30
|
+
id;
|
|
31
|
+
constructor(id) {
|
|
32
|
+
super(`'${id}' answers on every subdomain, so it has to say which of them are tenants: pass \`hosts\`, a GET endpoint answering 200 for a host it serves and 404 otherwise.`);
|
|
33
|
+
this.id = id;
|
|
34
|
+
this.name = "WildcardSiteNeedsHosts";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** `hosts` on a site with one host, where there is nothing to check. */
|
|
38
|
+
var SiteHostsNeedsWildcard = class extends Error {
|
|
39
|
+
id;
|
|
40
|
+
constructor(id) {
|
|
41
|
+
super(`'${id}' names a \`hosts\` check but answers on one host. Declare \`subdomain: '*'\` to serve every subdomain, or drop \`hosts\`.`);
|
|
42
|
+
this.id = id;
|
|
43
|
+
this.name = "SiteHostsNeedsWildcard";
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */
|
|
47
|
+
var SiteHostsNotGet = class extends Error {
|
|
48
|
+
id;
|
|
49
|
+
method;
|
|
50
|
+
route;
|
|
51
|
+
constructor(id, method, route) {
|
|
52
|
+
super(`'${id}' checks its hosts with ${method} ${route}, but the edge asks with GET ${route}?domain=<host>. Make it a GET endpoint.`);
|
|
53
|
+
this.id = id;
|
|
54
|
+
this.method = method;
|
|
55
|
+
this.route = route;
|
|
56
|
+
this.name = "SiteHostsNotGet";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/** A wildcard site that says it holds the base domain. */
|
|
60
|
+
var WildcardSiteCannotBeRoot = class extends Error {
|
|
61
|
+
id;
|
|
62
|
+
constructor(id) {
|
|
63
|
+
super(`'${id}' answers on every subdomain, so it cannot also hold the base domain. Drop \`root: true\`, and declare the site the base domain points at separately.`);
|
|
64
|
+
this.id = id;
|
|
65
|
+
this.name = "WildcardSiteCannotBeRoot";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
28
68
|
var StaticSite = class StaticSite {
|
|
29
69
|
config;
|
|
30
70
|
dependencies;
|
|
@@ -35,6 +75,11 @@ var StaticSite = class StaticSite {
|
|
|
35
75
|
this.dependencies = dependencies;
|
|
36
76
|
this.id = (0, _geekmidas_manifest.canonicalId)(id);
|
|
37
77
|
this.keys = { url: (0, _geekmidas_manifest.provideKey)(this.id, "url") };
|
|
78
|
+
const wildcard = config.subdomain === _geekmidas_manifest.WILDCARD_SUBDOMAIN;
|
|
79
|
+
if (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);
|
|
80
|
+
if (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);
|
|
81
|
+
if (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);
|
|
82
|
+
if (config.hosts && config.hosts.method.toUpperCase() !== "GET") throw new SiteHostsNotGet(this.id, config.hosts.method, config.hosts.route);
|
|
38
83
|
}
|
|
39
84
|
/**
|
|
40
85
|
* What this site calls.
|
|
@@ -51,11 +96,16 @@ var StaticSite = class StaticSite {
|
|
|
51
96
|
return new StaticSite(this.id, this.config, [...this.dependencies, ...constructs.map(require_construct_interface.edgeTo)]);
|
|
52
97
|
}
|
|
53
98
|
declare() {
|
|
99
|
+
const { hosts } = this.config;
|
|
54
100
|
return [{
|
|
55
101
|
kind: "site",
|
|
56
102
|
id: this.id,
|
|
57
103
|
variant: this.config.variant ?? "static",
|
|
58
104
|
...this.config.subdomain ? { subdomain: this.config.subdomain } : {},
|
|
105
|
+
...hosts ? { hosts: {
|
|
106
|
+
surface: (0, _geekmidas_manifest.canonicalId)(hosts.surface.id),
|
|
107
|
+
path: hosts.route
|
|
108
|
+
} } : {},
|
|
59
109
|
app: {
|
|
60
110
|
path: this.config.path,
|
|
61
111
|
...this.config.port ? { port: this.config.port } : {},
|
|
@@ -68,11 +118,15 @@ var StaticSite = class StaticSite {
|
|
|
68
118
|
secret: this.config.password.secret.id,
|
|
69
119
|
stages: [...this.config.password.stages]
|
|
70
120
|
} } : {},
|
|
71
|
-
provides: [this.keys.url]
|
|
121
|
+
provides: [this.keys.url, ...hosts ? [(0, _geekmidas_manifest.provideKey)(this.id, "domain"), (0, _geekmidas_manifest.provideKey)(this.id, "protectedSubdomains")] : []]
|
|
72
122
|
}];
|
|
73
123
|
}
|
|
74
124
|
};
|
|
75
125
|
//#endregion
|
|
126
|
+
exports.SiteHostsNeedsWildcard = SiteHostsNeedsWildcard;
|
|
127
|
+
exports.SiteHostsNotGet = SiteHostsNotGet;
|
|
76
128
|
exports.StaticSite = StaticSite;
|
|
129
|
+
exports.WildcardSiteCannotBeRoot = WildcardSiteCannotBeRoot;
|
|
130
|
+
exports.WildcardSiteNeedsHosts = WildcardSiteNeedsHosts;
|
|
77
131
|
|
|
78
132
|
//# sourceMappingURL=site.cjs.map
|
package/dist/site.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.cjs","names":["canonicalId","provideKey","edgeTo"],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * It has no `.service`. A site is not a process that registers clients — it is\n * built, and the values it needs are inlined or fetched by its own framework —\n * so the edge is {@link Declarable} rather than {@link Consumable}, and the\n * asymmetry is the honest one: a site consumes addresses, not connections.\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n} from '@geekmidas/manifest';\nimport { type Declarable, edgeTo } from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: provideKey(this.id, 'url') };\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(edgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tprovides: [this.keys.url],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6HA,IAAa,aAAb,MAAa,WAEb;CAMmB;CAOA;CAZlB;CACA;CAEA,YACC,IACA,QAOA,eAAuD,CAAC,GACvD;EARgB,KAAA,SAAA;EAOA,KAAA,eAAA;EAEjB,KAAK,MAAA,GAAKA,oBAAAA,YAAAA,CAAY,EAAY;EAClC,KAAK,OAAO,EAAE,MAAA,GAAKC,oBAAAA,WAAAA,CAAW,KAAK,IAAI,KAAK,EAAE;CAC/C;;;;;;;;;;;;CAaA,UAAU,YAAsD;EAC/D,OAAO,IAAI,WAAkB,KAAK,IAA4B,KAAK,QAAQ,CAC1E,GAAG,KAAK,cACR,GAAG,WAAW,IAAIC,4BAAAA,MAAM,CACzB,CAAC;CACF;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,SAAS,KAAK,OAAO,WAAW;GAChC,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,KAAK;IACJ,MAAM,KAAK,OAAO;IAClB,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI,CAAC;IACrD,GAAI,KAAK,OAAO,SAAS,EAAE,QAAQ,KAAK,OAAO,OAAO,IAAI,CAAC;GAC5D;GACA,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;GACzC,cAAc,KAAK;GACnB,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GACJ,GAAI,KAAK,OAAO,WACb,EACA,UAAU;IACT,QAAQ,KAAK,OAAO,SAAS,OAAO;IACpC,QAAQ,CAAC,GAAG,KAAK,OAAO,SAAS,MAAM;GACxC,EACD,IACC,CAAC;GACJ,UAAU,CAAC,KAAK,KAAK,GAAG;EACzB,CACD;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"site.cjs","names":["canonicalId","provideKey","WILDCARD_SUBDOMAIN","edgeTo"],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * It has no `.service`. A site is not a process that registers clients — it is\n * built, and the values it needs are inlined or fetched by its own framework —\n * so the edge is {@link Declarable} rather than {@link Consumable}, and the\n * asymmetry is the honest one: a site consumes addresses, not connections.\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\nimport { type Declarable, edgeTo } from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t *\n\t * `'*'` answers on every subdomain nothing else does — one host per\n\t * tenant, `acme.myapp.com` — and then `hosts` names which of them are\n\t * real. Every other app keeps its own host, and a project has at most one\n\t * such site.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * With `subdomain: '*'`, the route that says which hosts are tenants: an\n\t * exported `GET` endpoint the edge asks before it serves a host,\n\t * `?domain=<host>`, answering `200` for a tenant and `404` otherwise.\n\t *\n\t * It runs without a session and belongs to no public API.\n\t */\n\thosts?: SiteHostsEndpoint;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n}\n\n/**\n * The shape of the endpoint `hosts` names — read structurally, so a site\n * module never loads the endpoint machinery to say which route it means.\n */\nexport interface SiteHostsEndpoint {\n\troute: string;\n\tmethod: string;\n\tsurface: { id: string };\n}\n\n/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */\nexport class WildcardSiteNeedsHosts extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it has to say which of them ` +\n\t\t\t\t`are tenants: pass \\`hosts\\`, a GET endpoint answering 200 for a ` +\n\t\t\t\t`host it serves and 404 otherwise.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteNeedsHosts';\n\t}\n}\n\n/** `hosts` on a site with one host, where there is nothing to check. */\nexport class SiteHostsNeedsWildcard extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' names a \\`hosts\\` check but answers on one host. ` +\n\t\t\t\t`Declare \\`subdomain: '*'\\` to serve every subdomain, or drop \\`hosts\\`.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNeedsWildcard';\n\t}\n}\n\n/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */\nexport class SiteHostsNotGet extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly method: string,\n\t\treadonly route: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' checks its hosts with ${method} ${route}, but the edge asks ` +\n\t\t\t\t`with GET ${route}?domain=<host>. Make it a GET endpoint.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNotGet';\n\t}\n}\n\n/** A wildcard site that says it holds the base domain. */\nexport class WildcardSiteCannotBeRoot extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it cannot also hold the base ` +\n\t\t\t\t`domain. Drop \\`root: true\\`, and declare the site the base domain ` +\n\t\t\t\t`points at separately.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCannotBeRoot';\n\t}\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: provideKey(this.id, 'url') };\n\n\t\tconst wildcard = config.subdomain === WILDCARD_SUBDOMAIN;\n\t\tif (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);\n\t\tif (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);\n\t\tif (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);\n\t\tif (config.hosts && config.hosts.method.toUpperCase() !== 'GET') {\n\t\t\tthrow new SiteHostsNotGet(\n\t\t\t\tthis.id,\n\t\t\t\tconfig.hosts.method,\n\t\t\t\tconfig.hosts.route,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(edgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tconst { hosts } = this.config;\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(hosts\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thosts: {\n\t\t\t\t\t\t\t\tsurface: canonicalId(hosts.surface.id),\n\t\t\t\t\t\t\t\tpath: hosts.route,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\t...(hosts\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tprovideKey(this.id, 'domain'),\n\t\t\t\t\t\t\t\tprovideKey(this.id, 'protectedSubdomains'),\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":"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"}
|
package/dist/site.d.cts
CHANGED
|
@@ -22,8 +22,21 @@ export interface StaticSiteConfig {
|
|
|
22
22
|
* The label it answers on under a stage's domain — `api` for
|
|
23
23
|
* `api.myapp.com`, from `domains` — and under the project locally,
|
|
24
24
|
* `api.myapp.localhost`. Absent, its id kebab-cased.
|
|
25
|
+
*
|
|
26
|
+
* `'*'` answers on every subdomain nothing else does — one host per
|
|
27
|
+
* tenant, `acme.myapp.com` — and then `hosts` names which of them are
|
|
28
|
+
* real. Every other app keeps its own host, and a project has at most one
|
|
29
|
+
* such site.
|
|
25
30
|
*/
|
|
26
31
|
subdomain?: string;
|
|
32
|
+
/**
|
|
33
|
+
* With `subdomain: '*'`, the route that says which hosts are tenants: an
|
|
34
|
+
* exported `GET` endpoint the edge asks before it serves a host,
|
|
35
|
+
* `?domain=<host>`, answering `200` for a tenant and `404` otherwise.
|
|
36
|
+
*
|
|
37
|
+
* It runs without a session and belongs to no public API.
|
|
38
|
+
*/
|
|
39
|
+
hosts?: SiteHostsEndpoint;
|
|
27
40
|
/**
|
|
28
41
|
* The port it answers on locally.
|
|
29
42
|
*
|
|
@@ -94,6 +107,39 @@ export interface StaticSiteConfig {
|
|
|
94
107
|
stages: readonly [DeployedStage, ...DeployedStage[]];
|
|
95
108
|
};
|
|
96
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* The shape of the endpoint `hosts` names — read structurally, so a site
|
|
112
|
+
* module never loads the endpoint machinery to say which route it means.
|
|
113
|
+
*/
|
|
114
|
+
export interface SiteHostsEndpoint {
|
|
115
|
+
route: string;
|
|
116
|
+
method: string;
|
|
117
|
+
surface: {
|
|
118
|
+
id: string;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */
|
|
122
|
+
export declare class WildcardSiteNeedsHosts extends Error {
|
|
123
|
+
readonly id: string;
|
|
124
|
+
constructor(id: string);
|
|
125
|
+
}
|
|
126
|
+
/** `hosts` on a site with one host, where there is nothing to check. */
|
|
127
|
+
export declare class SiteHostsNeedsWildcard extends Error {
|
|
128
|
+
readonly id: string;
|
|
129
|
+
constructor(id: string);
|
|
130
|
+
}
|
|
131
|
+
/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */
|
|
132
|
+
export declare class SiteHostsNotGet extends Error {
|
|
133
|
+
readonly id: string;
|
|
134
|
+
readonly method: string;
|
|
135
|
+
readonly route: string;
|
|
136
|
+
constructor(id: string, method: string, route: string);
|
|
137
|
+
}
|
|
138
|
+
/** A wildcard site that says it holds the base domain. */
|
|
139
|
+
export declare class WildcardSiteCannotBeRoot extends Error {
|
|
140
|
+
readonly id: string;
|
|
141
|
+
constructor(id: string);
|
|
142
|
+
}
|
|
97
143
|
export declare class StaticSite<TName extends string = string> implements Declarable<TName> {
|
|
98
144
|
private readonly config;
|
|
99
145
|
/**
|
package/dist/site.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.cts","names":[],"sources":["../src/site.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"site.d.cts","names":[],"sources":["../src/site.ts"],"mappings":";;;;;;;;;;;;iBA4CiB;;;;;;;EAOhB;;;;;;;;;;;EAWA;;;;;;;;EAQA,QAAQ;;;;;;;EAOR;;;;;;;EAOA;IAAW;IAAiB;;;;;;;;;;EAS5B;;;;;;;;;EASA,UAAU;;;;;;;EAOV,YAAY;;;;;;;;;;;;;;;;;;;;;;;;EAwBZ;IACC,QAAQ;IACR,kBAAkB,kBAAkB;;;;;;;iBAQrB;EAChB;EACA;EACA;IAAW;;;;qBAIC,+BAA+B;WACtB;EAArB,YAAqB;;;qBAWT,+BAA+B;WACtB;EAArB,YAAqB;;;qBAUT,wBAAwB;WAE1B;WACA;WACA;EAHV,YACU,YACA,gBACA;;;qBAWE,iCAAiC;WACxB;EAArB,YAAqB;;qBAUT,WAAW,0CACZ,WAAW;mBAOJ;;;;;;;mBAOA;WAZT,IAAI;WACJ;IAAQ;;EAEjB,YACC,IAAI,cAAc,QACD,QAAQ,kBAOR;;;;;;;EAAA,wBAAuB;;;;;;;;;;;;EA6BzC,UAAU,qBAAqB,eAAe,WAAW;EAOzD,WAAW"}
|
package/dist/site.d.mts
CHANGED
|
@@ -22,8 +22,21 @@ export interface StaticSiteConfig {
|
|
|
22
22
|
* The label it answers on under a stage's domain — `api` for
|
|
23
23
|
* `api.myapp.com`, from `domains` — and under the project locally,
|
|
24
24
|
* `api.myapp.localhost`. Absent, its id kebab-cased.
|
|
25
|
+
*
|
|
26
|
+
* `'*'` answers on every subdomain nothing else does — one host per
|
|
27
|
+
* tenant, `acme.myapp.com` — and then `hosts` names which of them are
|
|
28
|
+
* real. Every other app keeps its own host, and a project has at most one
|
|
29
|
+
* such site.
|
|
25
30
|
*/
|
|
26
31
|
subdomain?: string;
|
|
32
|
+
/**
|
|
33
|
+
* With `subdomain: '*'`, the route that says which hosts are tenants: an
|
|
34
|
+
* exported `GET` endpoint the edge asks before it serves a host,
|
|
35
|
+
* `?domain=<host>`, answering `200` for a tenant and `404` otherwise.
|
|
36
|
+
*
|
|
37
|
+
* It runs without a session and belongs to no public API.
|
|
38
|
+
*/
|
|
39
|
+
hosts?: SiteHostsEndpoint;
|
|
27
40
|
/**
|
|
28
41
|
* The port it answers on locally.
|
|
29
42
|
*
|
|
@@ -94,6 +107,39 @@ export interface StaticSiteConfig {
|
|
|
94
107
|
stages: readonly [DeployedStage, ...DeployedStage[]];
|
|
95
108
|
};
|
|
96
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* The shape of the endpoint `hosts` names — read structurally, so a site
|
|
112
|
+
* module never loads the endpoint machinery to say which route it means.
|
|
113
|
+
*/
|
|
114
|
+
export interface SiteHostsEndpoint {
|
|
115
|
+
route: string;
|
|
116
|
+
method: string;
|
|
117
|
+
surface: {
|
|
118
|
+
id: string;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */
|
|
122
|
+
export declare class WildcardSiteNeedsHosts extends Error {
|
|
123
|
+
readonly id: string;
|
|
124
|
+
constructor(id: string);
|
|
125
|
+
}
|
|
126
|
+
/** `hosts` on a site with one host, where there is nothing to check. */
|
|
127
|
+
export declare class SiteHostsNeedsWildcard extends Error {
|
|
128
|
+
readonly id: string;
|
|
129
|
+
constructor(id: string);
|
|
130
|
+
}
|
|
131
|
+
/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */
|
|
132
|
+
export declare class SiteHostsNotGet extends Error {
|
|
133
|
+
readonly id: string;
|
|
134
|
+
readonly method: string;
|
|
135
|
+
readonly route: string;
|
|
136
|
+
constructor(id: string, method: string, route: string);
|
|
137
|
+
}
|
|
138
|
+
/** A wildcard site that says it holds the base domain. */
|
|
139
|
+
export declare class WildcardSiteCannotBeRoot extends Error {
|
|
140
|
+
readonly id: string;
|
|
141
|
+
constructor(id: string);
|
|
142
|
+
}
|
|
97
143
|
export declare class StaticSite<TName extends string = string> implements Declarable<TName> {
|
|
98
144
|
private readonly config;
|
|
99
145
|
/**
|
package/dist/site.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.mts","names":[],"sources":["../src/site.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"site.d.mts","names":[],"sources":["../src/site.ts"],"mappings":";;;;;;;;;;;;iBA4CiB;;;;;;;EAOhB;;;;;;;;;;;EAWA;;;;;;;;EAQA,QAAQ;;;;;;;EAOR;;;;;;;EAOA;IAAW;IAAiB;;;;;;;;;;EAS5B;;;;;;;;;EASA,UAAU;;;;;;;EAOV,YAAY;;;;;;;;;;;;;;;;;;;;;;;;EAwBZ;IACC,QAAQ;IACR,kBAAkB,kBAAkB;;;;;;;iBAQrB;EAChB;EACA;EACA;IAAW;;;;qBAIC,+BAA+B;WACtB;EAArB,YAAqB;;;qBAWT,+BAA+B;WACtB;EAArB,YAAqB;;;qBAUT,wBAAwB;WAE1B;WACA;WACA;EAHV,YACU,YACA,gBACA;;;qBAWE,iCAAiC;WACxB;EAArB,YAAqB;;qBAUT,WAAW,0CACZ,WAAW;mBAOJ;;;;;;;mBAOA;WAZT,IAAI;WACJ;IAAQ;;EAEjB,YACC,IAAI,cAAc,QACD,QAAQ,kBAOR;;;;;;;EAAA,wBAAuB;;;;;;;;;;;;EA6BzC,UAAU,qBAAqB,eAAe,WAAW;EAOzD,WAAW"}
|
package/dist/site.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { edgeTo } from "./construct-interface.mjs";
|
|
2
|
-
import { canonicalId, provideKey } from "@geekmidas/manifest";
|
|
2
|
+
import { WILDCARD_SUBDOMAIN, canonicalId, provideKey } from "@geekmidas/manifest";
|
|
3
3
|
//#region src/site.ts
|
|
4
4
|
/**
|
|
5
5
|
* `StaticSite` — a frontend, declared like anything else.
|
|
@@ -24,6 +24,46 @@ import { canonicalId, provideKey } from "@geekmidas/manifest";
|
|
|
24
24
|
* is not a site — it is reached by a scheme, not a URL — and is its own
|
|
25
25
|
* construct: see `MobileApp`.
|
|
26
26
|
*/
|
|
27
|
+
/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */
|
|
28
|
+
var WildcardSiteNeedsHosts = class extends Error {
|
|
29
|
+
id;
|
|
30
|
+
constructor(id) {
|
|
31
|
+
super(`'${id}' answers on every subdomain, so it has to say which of them are tenants: pass \`hosts\`, a GET endpoint answering 200 for a host it serves and 404 otherwise.`);
|
|
32
|
+
this.id = id;
|
|
33
|
+
this.name = "WildcardSiteNeedsHosts";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/** `hosts` on a site with one host, where there is nothing to check. */
|
|
37
|
+
var SiteHostsNeedsWildcard = class extends Error {
|
|
38
|
+
id;
|
|
39
|
+
constructor(id) {
|
|
40
|
+
super(`'${id}' names a \`hosts\` check but answers on one host. Declare \`subdomain: '*'\` to serve every subdomain, or drop \`hosts\`.`);
|
|
41
|
+
this.id = id;
|
|
42
|
+
this.name = "SiteHostsNeedsWildcard";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */
|
|
46
|
+
var SiteHostsNotGet = class extends Error {
|
|
47
|
+
id;
|
|
48
|
+
method;
|
|
49
|
+
route;
|
|
50
|
+
constructor(id, method, route) {
|
|
51
|
+
super(`'${id}' checks its hosts with ${method} ${route}, but the edge asks with GET ${route}?domain=<host>. Make it a GET endpoint.`);
|
|
52
|
+
this.id = id;
|
|
53
|
+
this.method = method;
|
|
54
|
+
this.route = route;
|
|
55
|
+
this.name = "SiteHostsNotGet";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/** A wildcard site that says it holds the base domain. */
|
|
59
|
+
var WildcardSiteCannotBeRoot = class extends Error {
|
|
60
|
+
id;
|
|
61
|
+
constructor(id) {
|
|
62
|
+
super(`'${id}' answers on every subdomain, so it cannot also hold the base domain. Drop \`root: true\`, and declare the site the base domain points at separately.`);
|
|
63
|
+
this.id = id;
|
|
64
|
+
this.name = "WildcardSiteCannotBeRoot";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
27
67
|
var StaticSite = class StaticSite {
|
|
28
68
|
config;
|
|
29
69
|
dependencies;
|
|
@@ -34,6 +74,11 @@ var StaticSite = class StaticSite {
|
|
|
34
74
|
this.dependencies = dependencies;
|
|
35
75
|
this.id = canonicalId(id);
|
|
36
76
|
this.keys = { url: provideKey(this.id, "url") };
|
|
77
|
+
const wildcard = config.subdomain === WILDCARD_SUBDOMAIN;
|
|
78
|
+
if (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);
|
|
79
|
+
if (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);
|
|
80
|
+
if (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);
|
|
81
|
+
if (config.hosts && config.hosts.method.toUpperCase() !== "GET") throw new SiteHostsNotGet(this.id, config.hosts.method, config.hosts.route);
|
|
37
82
|
}
|
|
38
83
|
/**
|
|
39
84
|
* What this site calls.
|
|
@@ -50,11 +95,16 @@ var StaticSite = class StaticSite {
|
|
|
50
95
|
return new StaticSite(this.id, this.config, [...this.dependencies, ...constructs.map(edgeTo)]);
|
|
51
96
|
}
|
|
52
97
|
declare() {
|
|
98
|
+
const { hosts } = this.config;
|
|
53
99
|
return [{
|
|
54
100
|
kind: "site",
|
|
55
101
|
id: this.id,
|
|
56
102
|
variant: this.config.variant ?? "static",
|
|
57
103
|
...this.config.subdomain ? { subdomain: this.config.subdomain } : {},
|
|
104
|
+
...hosts ? { hosts: {
|
|
105
|
+
surface: canonicalId(hosts.surface.id),
|
|
106
|
+
path: hosts.route
|
|
107
|
+
} } : {},
|
|
58
108
|
app: {
|
|
59
109
|
path: this.config.path,
|
|
60
110
|
...this.config.port ? { port: this.config.port } : {},
|
|
@@ -67,11 +117,11 @@ var StaticSite = class StaticSite {
|
|
|
67
117
|
secret: this.config.password.secret.id,
|
|
68
118
|
stages: [...this.config.password.stages]
|
|
69
119
|
} } : {},
|
|
70
|
-
provides: [this.keys.url]
|
|
120
|
+
provides: [this.keys.url, ...hosts ? [provideKey(this.id, "domain"), provideKey(this.id, "protectedSubdomains")] : []]
|
|
71
121
|
}];
|
|
72
122
|
}
|
|
73
123
|
};
|
|
74
124
|
//#endregion
|
|
75
|
-
export { StaticSite };
|
|
125
|
+
export { SiteHostsNeedsWildcard, SiteHostsNotGet, StaticSite, WildcardSiteCannotBeRoot, WildcardSiteNeedsHosts };
|
|
76
126
|
|
|
77
127
|
//# sourceMappingURL=site.mjs.map
|
package/dist/site.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.mjs","names":[],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * It has no `.service`. A site is not a process that registers clients — it is\n * built, and the values it needs are inlined or fetched by its own framework —\n * so the edge is {@link Declarable} rather than {@link Consumable}, and the\n * asymmetry is the honest one: a site consumes addresses, not connections.\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n} from '@geekmidas/manifest';\nimport { type Declarable, edgeTo } from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: provideKey(this.id, 'url') };\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(edgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tprovides: [this.keys.url],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6HA,IAAa,aAAb,MAAa,WAEb;CAMmB;CAOA;CAZlB;CACA;CAEA,YACC,IACA,QAOA,eAAuD,CAAC,GACvD;EARgB,KAAA,SAAA;EAOA,KAAA,eAAA;EAEjB,KAAK,KAAK,YAAY,EAAY;EAClC,KAAK,OAAO,EAAE,KAAK,WAAW,KAAK,IAAI,KAAK,EAAE;CAC/C;;;;;;;;;;;;CAaA,UAAU,YAAsD;EAC/D,OAAO,IAAI,WAAkB,KAAK,IAA4B,KAAK,QAAQ,CAC1E,GAAG,KAAK,cACR,GAAG,WAAW,IAAI,MAAM,CACzB,CAAC;CACF;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,SAAS,KAAK,OAAO,WAAW;GAChC,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,KAAK;IACJ,MAAM,KAAK,OAAO;IAClB,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI,CAAC;IACrD,GAAI,KAAK,OAAO,SAAS,EAAE,QAAQ,KAAK,OAAO,OAAO,IAAI,CAAC;GAC5D;GACA,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;GACzC,cAAc,KAAK;GACnB,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GACJ,GAAI,KAAK,OAAO,WACb,EACA,UAAU;IACT,QAAQ,KAAK,OAAO,SAAS,OAAO;IACpC,QAAQ,CAAC,GAAG,KAAK,OAAO,SAAS,MAAM;GACxC,EACD,IACC,CAAC;GACJ,UAAU,CAAC,KAAK,KAAK,GAAG;EACzB,CACD;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"site.mjs","names":[],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * It has no `.service`. A site is not a process that registers clients — it is\n * built, and the values it needs are inlined or fetched by its own framework —\n * so the edge is {@link Declarable} rather than {@link Consumable}, and the\n * asymmetry is the honest one: a site consumes addresses, not connections.\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovideKey,\n\ttype SiteDeclaration,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\nimport { type Declarable, edgeTo } from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t *\n\t * `'*'` answers on every subdomain nothing else does — one host per\n\t * tenant, `acme.myapp.com` — and then `hosts` names which of them are\n\t * real. Every other app keeps its own host, and a project has at most one\n\t * such site.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * With `subdomain: '*'`, the route that says which hosts are tenants: an\n\t * exported `GET` endpoint the edge asks before it serves a host,\n\t * `?domain=<host>`, answering `200` for a tenant and `404` otherwise.\n\t *\n\t * It runs without a session and belongs to no public API.\n\t */\n\thosts?: SiteHostsEndpoint;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n}\n\n/**\n * The shape of the endpoint `hosts` names — read structurally, so a site\n * module never loads the endpoint machinery to say which route it means.\n */\nexport interface SiteHostsEndpoint {\n\troute: string;\n\tmethod: string;\n\tsurface: { id: string };\n}\n\n/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */\nexport class WildcardSiteNeedsHosts extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it has to say which of them ` +\n\t\t\t\t`are tenants: pass \\`hosts\\`, a GET endpoint answering 200 for a ` +\n\t\t\t\t`host it serves and 404 otherwise.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteNeedsHosts';\n\t}\n}\n\n/** `hosts` on a site with one host, where there is nothing to check. */\nexport class SiteHostsNeedsWildcard extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' names a \\`hosts\\` check but answers on one host. ` +\n\t\t\t\t`Declare \\`subdomain: '*'\\` to serve every subdomain, or drop \\`hosts\\`.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNeedsWildcard';\n\t}\n}\n\n/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */\nexport class SiteHostsNotGet extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly method: string,\n\t\treadonly route: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' checks its hosts with ${method} ${route}, but the edge asks ` +\n\t\t\t\t`with GET ${route}?domain=<host>. Make it a GET endpoint.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNotGet';\n\t}\n}\n\n/** A wildcard site that says it holds the base domain. */\nexport class WildcardSiteCannotBeRoot extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it cannot also hold the base ` +\n\t\t\t\t`domain. Drop \\`root: true\\`, and declare the site the base domain ` +\n\t\t\t\t`points at separately.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCannotBeRoot';\n\t}\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: provideKey(this.id, 'url') };\n\n\t\tconst wildcard = config.subdomain === WILDCARD_SUBDOMAIN;\n\t\tif (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);\n\t\tif (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);\n\t\tif (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);\n\t\tif (config.hosts && config.hosts.method.toUpperCase() !== 'GET') {\n\t\t\tthrow new SiteHostsNotGet(\n\t\t\t\tthis.id,\n\t\t\t\tconfig.hosts.method,\n\t\t\t\tconfig.hosts.route,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(edgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tconst { hosts } = this.config;\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(hosts\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thosts: {\n\t\t\t\t\t\t\t\tsurface: canonicalId(hosts.surface.id),\n\t\t\t\t\t\t\t\tpath: hosts.route,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\t...(hosts\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tprovideKey(this.id, 'domain'),\n\t\t\t\t\t\t\t\tprovideKey(this.id, 'protectedSubdomains'),\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsJA,IAAa,yBAAb,cAA4C,MAAM;CAC5B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,+JAGR;EALoB,KAAA,KAAA;EAMpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,yBAAb,cAA4C,MAAM;CAC5B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,2HAER;EAJoB,KAAA,KAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAEhC;CACA;CACA;CAHV,YACC,IACA,QACA,OACC;EACD,MACC,IAAI,GAAG,0BAA0B,OAAO,GAAG,MAAM,+BACpC,MAAM,wCACpB;EAPS,KAAA,KAAA;EACA,KAAA,SAAA;EACA,KAAA,QAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,2BAAb,cAA8C,MAAM;CAC9B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,sJAGR;EALoB,KAAA,KAAA;EAMpB,KAAK,OAAO;CACb;AACD;AAEA,IAAa,aAAb,MAAa,WAEb;CAMmB;CAOA;CAZlB;CACA;CAEA,YACC,IACA,QAOA,eAAuD,CAAC,GACvD;EARgB,KAAA,SAAA;EAOA,KAAA,eAAA;EAEjB,KAAK,KAAK,YAAY,EAAY;EAClC,KAAK,OAAO,EAAE,KAAK,WAAW,KAAK,IAAI,KAAK,EAAE;EAE9C,MAAM,WAAW,OAAO,cAAc;EACtC,IAAI,YAAY,CAAC,OAAO,OAAO,MAAM,IAAI,uBAAuB,KAAK,EAAE;EACvE,IAAI,CAAC,YAAY,OAAO,OAAO,MAAM,IAAI,uBAAuB,KAAK,EAAE;EACvE,IAAI,YAAY,OAAO,MAAM,MAAM,IAAI,yBAAyB,KAAK,EAAE;EACvE,IAAI,OAAO,SAAS,OAAO,MAAM,OAAO,YAAY,MAAM,OACzD,MAAM,IAAI,gBACT,KAAK,IACL,OAAO,MAAM,QACb,OAAO,MAAM,KACd;CAEF;;;;;;;;;;;;CAaA,UAAU,YAAsD;EAC/D,OAAO,IAAI,WAAkB,KAAK,IAA4B,KAAK,QAAQ,CAC1E,GAAG,KAAK,cACR,GAAG,WAAW,IAAI,MAAM,CACzB,CAAC;CACF;CAEA,UAAyB;EACxB,MAAM,EAAE,UAAU,KAAK;EACvB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,SAAS,KAAK,OAAO,WAAW;GAChC,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,GAAI,QACD,EACA,OAAO;IACN,SAAS,YAAY,MAAM,QAAQ,EAAE;IACrC,MAAM,MAAM;GACb,EACD,IACC,CAAC;GACJ,KAAK;IACJ,MAAM,KAAK,OAAO;IAClB,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI,CAAC;IACrD,GAAI,KAAK,OAAO,SAAS,EAAE,QAAQ,KAAK,OAAO,OAAO,IAAI,CAAC;GAC5D;GACA,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;GACzC,cAAc,KAAK;GACnB,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GACJ,GAAI,KAAK,OAAO,WACb,EACA,UAAU;IACT,QAAQ,KAAK,OAAO,SAAS,OAAO;IACpC,QAAQ,CAAC,GAAG,KAAK,OAAO,SAAS,MAAM;GACxC,EACD,IACC,CAAC;GACJ,UAAU,CACT,KAAK,KAAK,KACV,GAAI,QACD,CACA,WAAW,KAAK,IAAI,QAAQ,GAC5B,WAAW,KAAK,IAAI,qBAAqB,CAC1C,IACC,CAAC,CACL;EACD,CACD;CACD;AACD"}
|
package/dist/websocket-api.cjs
CHANGED
|
@@ -391,7 +391,7 @@ var WebSocketSurfaceServer = class WebSocketSurfaceServer {
|
|
|
391
391
|
async upgrade(request, socket, head) {
|
|
392
392
|
if (this.closing) return refuse(socket, 503, "Service Unavailable");
|
|
393
393
|
const origin = request.headers.origin;
|
|
394
|
-
if (origin && !this.options.trustedOrigins
|
|
394
|
+
if (origin && !(0, _geekmidas_manifest.trustsOrigin)(origin, this.options.trustedOrigins)) return refuse(socket, 403, "Forbidden");
|
|
395
395
|
const connectionId = `${this.instance}.${(this.next++).toString(36)}`;
|
|
396
396
|
const headers = headersOf(request);
|
|
397
397
|
let data = {};
|