@somewhatintelligent/kit 0.0.1-beta.1783705886.297c5be
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/package.json +58 -0
- package/src/execution-context/index.ts +16 -0
- package/src/ids/__tests__/index.test.ts +80 -0
- package/src/ids/index.ts +60 -0
- package/src/log/__tests__/http.test.ts +109 -0
- package/src/log/__tests__/index.test.ts +254 -0
- package/src/log/__tests__/instrumented.test.ts +319 -0
- package/src/log/__tests__/scheduled.test.ts +107 -0
- package/src/log/core.ts +230 -0
- package/src/log/http.ts +72 -0
- package/src/log/index.ts +22 -0
- package/src/log/instrumented.ts +191 -0
- package/src/log/scheduled.ts +84 -0
- package/src/react/auth.tsx +63 -0
- package/src/react/index.ts +2 -0
- package/src/react-start/__tests__/dev-envelope.test.ts +153 -0
- package/src/react-start/__tests__/smoke.test.ts +77 -0
- package/src/react-start/auth-provider.tsx +81 -0
- package/src/react-start/client.ts +11 -0
- package/src/react-start/dev-envelope.ts +136 -0
- package/src/react-start/envelope-middleware.ts +135 -0
- package/src/react-start/index.ts +29 -0
- package/src/react-start/logging.ts +70 -0
- package/src/react-start/platform-start-app.ts +382 -0
- package/src/react-start/platform-start-context.ts +25 -0
- package/src/react-start/request-logger.ts +60 -0
- package/src/react-start/service-clients.ts +246 -0
- package/src/request-context/__tests__/index.test.ts +90 -0
- package/src/request-context/index.ts +189 -0
- package/src/roles.ts +25 -0
- package/src/version/__tests__/index.test.ts +140 -0
- package/src/version/index.ts +85 -0
- package/src/version.gen.ts +7 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/__version` — one tiny, shared implementation of the version endpoint
|
|
3
|
+
* so every worker built on these packages answers identically.
|
|
4
|
+
*
|
|
5
|
+
* Where the values come from:
|
|
6
|
+
* - `version` / `commit` are the calling PACKAGE's release stamp (its
|
|
7
|
+
* `version.gen.ts`, written by the release workflow at publish) — the
|
|
8
|
+
* package IS the versioned artifact. Apps built with vite instead bake
|
|
9
|
+
* build-time constants via `define` and pass them through `overrides`.
|
|
10
|
+
* - `environment` reads the worker's existing `ENVIRONMENT` var.
|
|
11
|
+
* - Everything falls back safely — local dev / tests (placeholder stamps)
|
|
12
|
+
* report `0.0.0-dev` / `unknown` / `development` instead of throwing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface VersionInfo {
|
|
16
|
+
worker: string;
|
|
17
|
+
version: string;
|
|
18
|
+
commit: string;
|
|
19
|
+
environment: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { PKG } from "../version.gen";
|
|
23
|
+
|
|
24
|
+
export const VERSION_PATH = "/__version";
|
|
25
|
+
|
|
26
|
+
export interface VersionOptions {
|
|
27
|
+
/** The worker's canonical name (e.g. "guestlist"). */
|
|
28
|
+
worker: string;
|
|
29
|
+
/** The worker's env bindings (any shape — only string vars are read). */
|
|
30
|
+
env?: unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Pathnames that answer. Defaults to just `/__version`. A worker mounted
|
|
33
|
+
* WITHOUT prefix-stripping (guestlist behind bouncer's `/api` passthrough)
|
|
34
|
+
* adds its mounted spelling too, e.g. `["/__version", "/api/__version"]`,
|
|
35
|
+
* so the endpoint stays reachable through the mount.
|
|
36
|
+
*/
|
|
37
|
+
paths?: readonly string[];
|
|
38
|
+
/** Field overrides for build-time-injected values (vite `define` apps). */
|
|
39
|
+
overrides?: Partial<Omit<VersionInfo, "worker">>;
|
|
40
|
+
/**
|
|
41
|
+
* The calling package's release stamp (its `version.gen.ts` PKG) — the
|
|
42
|
+
* source of `version`/`commit`. Placeholder in-repo, real at publish.
|
|
43
|
+
*/
|
|
44
|
+
pkg?: { version?: string; commit?: string };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readStringVar(env: unknown, key: string): string | undefined {
|
|
48
|
+
if (typeof env !== "object" || env === null) return undefined;
|
|
49
|
+
const value = (env as Record<string, unknown>)[key];
|
|
50
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Resolve the version payload for a worker (fallbacks, never throws). */
|
|
54
|
+
export function versionInfo(options: VersionOptions): VersionInfo {
|
|
55
|
+
const { worker, env, overrides, pkg } = options;
|
|
56
|
+
return {
|
|
57
|
+
worker,
|
|
58
|
+
version: overrides?.version ?? pkg?.version ?? "0.0.0-dev",
|
|
59
|
+
commit: overrides?.commit ?? pkg?.commit ?? "unknown",
|
|
60
|
+
environment: overrides?.environment ?? readStringVar(env, "ENVIRONMENT") ?? "development",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Serialize a payload as the endpoint's JSON response. */
|
|
65
|
+
export function versionResponse(info: VersionInfo): Response {
|
|
66
|
+
return new Response(JSON.stringify(info), {
|
|
67
|
+
status: 200,
|
|
68
|
+
headers: {
|
|
69
|
+
"content-type": "application/json; charset=utf-8",
|
|
70
|
+
"cache-control": "no-store",
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Answer a `/__version` request, or return null so the caller's normal
|
|
77
|
+
* routing proceeds. GET/HEAD only — anything else falls through.
|
|
78
|
+
*/
|
|
79
|
+
export function handleVersionRequest(request: Request, options: VersionOptions): Response | null {
|
|
80
|
+
if (request.method !== "GET" && request.method !== "HEAD") return null;
|
|
81
|
+
const paths = options.paths ?? [VERSION_PATH];
|
|
82
|
+
const { pathname } = new URL(request.url);
|
|
83
|
+
if (!paths.includes(pathname)) return null;
|
|
84
|
+
return versionResponse(versionInfo(options));
|
|
85
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// AUTO-STAMPED by scripts/stamp-versions.ts at release — the checked-in
|
|
2
|
+
// values are dev placeholders, identical to the runtime fallbacks.
|
|
3
|
+
export const PKG = {
|
|
4
|
+
name: "@somewhatintelligent/kit",
|
|
5
|
+
version: "0.0.1-beta.1783705886.297c5be",
|
|
6
|
+
commit: "297c5be7d3af822a7f5da906acf27a076332609c",
|
|
7
|
+
} as const;
|