-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
71 lines (63 loc) · 2.57 KB
/
Copy pathindex.ts
File metadata and controls
71 lines (63 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { npmDistTagForCliVersion } from "../../../../public-cli";
import type { FileOp } from "../file-writer/types";
import type { PatchContext, PatchView } from "../../types";
import { AbstractRulePatcher } from "../base";
import { type ViteSupport, buildViteProxyOp } from "../vite-support";
import { appTemplate } from "./templates";
const SDK_DEPENDENCY = "@zitadel/sdk-solid";
/**
* Rule-based patcher for a Vite + Solid single-page app. Inherits the shared
* `.zitadel/` base files from {@link AbstractRulePatcher} and contributes the
* managed `src/App.tsx` auth entry, a non-destructive `vite.config.*` merge
* that adds the `/__nextgen` dev proxy (attaching the project secret from
* `ZITADEL_PROJECT_SECRET` only to `POST /sessions/exchange`), the `VITE_`-prefixed
* project id, and the SDK dep.
*
* Unlike Next.js — whose middleware runs the proxy and token exchange
* server-side — a SPA has no server, so the dev proxy provides the same-origin
* `/__nextgen` path locally. In production that path comes from a platform
* rewrite or minimal worker (ADR 036); CLI scaffolding for it is tracked in
* issue #560.
*/
export class SolidPatcher extends AbstractRulePatcher implements ViteSupport {
canPatch(framework: string): boolean {
return framework === "solid";
}
viteProxyOp(devPort: number, server: string): FileOp {
return buildViteProxyOp(devPort, server);
}
protected routeOps(ctx: PatchContext): FileOp[] {
return [
{ kind: "write", path: "src/App.tsx", contents: appTemplate(ctx) },
this.viteProxyOp(ctx.framework.devPort, ctx.server),
// Vite only exposes VITE_-prefixed vars to client code (import.meta.env).
{ kind: "merge-env", path: ".env.example", entries: { VITE_ZITADEL_PROJECT_ID: "" } },
{
kind: "merge-env",
path: ".env.local",
entries: { VITE_ZITADEL_PROJECT_ID: ctx.project.id },
},
{
kind: "add-dep",
name: SDK_DEPENDENCY,
version: npmDistTagForCliVersion(ctx.cliVersion),
},
];
}
protected routeFiles(_view: PatchView): ReadonlyArray<string> {
return ["src/App.tsx"];
}
protected routeDeps(_view: PatchView): ReadonlyArray<string> {
return [SDK_DEPENDENCY];
}
protected override routeConfigEdits(_view: PatchView): ReadonlyArray<string> {
return ["vite.config.*"];
}
protected summary(_ctx: PatchContext): { title: string; detail: string } {
return {
title: "Solid (Vite) integration",
detail:
"Wrote src/App.tsx auth entry and merged the /__nextgen dev proxy into vite.config.*.",
};
}
}