rivet-design 0.9.10 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/flags.d.ts +3 -0
- package/dist/config/flags.d.ts.map +1 -1
- package/dist/config/flags.js +1 -0
- package/dist/config/flags.js.map +1 -1
- package/dist/config/proxy.d.ts +1 -0
- package/dist/config/proxy.d.ts.map +1 -1
- package/dist/config/proxy.js +9 -1
- package/dist/config/proxy.js.map +1 -1
- package/dist/prototype-host.d.ts +2 -0
- package/dist/prototype-host.d.ts.map +1 -0
- package/dist/prototype-host.js +56 -0
- package/dist/prototype-host.js.map +1 -0
- package/dist/routes/agentVariants.d.ts +2 -1
- package/dist/routes/agentVariants.d.ts.map +1 -1
- package/dist/routes/agentVariants.js +104 -1
- package/dist/routes/agentVariants.js.map +1 -1
- package/dist/routes/prototypeHost.d.ts +13 -0
- package/dist/routes/prototypeHost.d.ts.map +1 -0
- package/dist/routes/prototypeHost.js +207 -0
- package/dist/routes/prototypeHost.js.map +1 -0
- package/dist/services/BundleStore.d.ts +36 -0
- package/dist/services/BundleStore.d.ts.map +1 -0
- package/dist/services/BundleStore.js +102 -0
- package/dist/services/BundleStore.js.map +1 -0
- package/dist/services/PrototypeBuildService.d.ts +38 -0
- package/dist/services/PrototypeBuildService.d.ts.map +1 -0
- package/dist/services/PrototypeBuildService.js +165 -0
- package/dist/services/PrototypeBuildService.js.map +1 -0
- package/dist/services/PrototypeDeployService.d.ts +34 -0
- package/dist/services/PrototypeDeployService.d.ts.map +1 -0
- package/dist/services/PrototypeDeployService.js +115 -0
- package/dist/services/PrototypeDeployService.js.map +1 -0
- package/dist/services/SupabaseAuthService.d.ts +25 -0
- package/dist/services/SupabaseAuthService.d.ts.map +1 -0
- package/dist/services/SupabaseAuthService.js +56 -0
- package/dist/services/SupabaseAuthService.js.map +1 -0
- package/dist/services/VariantHistoryService.d.ts +23 -0
- package/dist/services/VariantHistoryService.d.ts.map +1 -1
- package/dist/services/VariantHistoryService.js +22 -0
- package/dist/services/VariantHistoryService.js.map +1 -1
- package/package.json +3 -2
- package/src/ui/dist/assets/{main-ChnGmvJG.js → main-CIJUZXe8.js} +52 -52
- package/src/ui/dist/index.html +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prototypeHost.js","sourceRoot":"","sources":["../../src/routes/prototypeHost.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,gDAAwB;AACxB,qCAA8D;AAC9D,+BAA2B;AAC3B,4CAA+C;AAI/C,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,qBAAqB,CAAC,CAAC;AAEhD;8EAC8E;AAC9E,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C,MAAM,IAAI,GAA2B;IACnC,OAAO,EAAE,0BAA0B;IACnC,MAAM,EAAE,0BAA0B;IAClC,MAAM,EAAE,yBAAyB;IACjC,KAAK,EAAE,uCAAuC;IAC9C,MAAM,EAAE,uCAAuC;IAC/C,OAAO,EAAE,iCAAiC;IAC1C,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,cAAc;IACtB,OAAO,EAAE,WAAW;IACpB,QAAQ,EAAE,YAAY;IACtB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,mBAAmB;IAC3B,OAAO,EAAE,iBAAiB;IAC1B,MAAM,EAAE,2BAA2B;IACnC,MAAM,EAAE,iCAAiC;IACzC,OAAO,EAAE,kBAAkB;CAC5B,CAAC;AAEF,MAAM,gBAAgB,GAAG,MAAC,CAAC,MAAM,CAAC;IAChC,IAAI,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,OAAO,EAAE,M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file in a prototype bundle. `path` is POSIX-relative to the bundle root
|
|
2
|
+
* (e.g. `assets/index-abc.js`); `content` is base64-encoded bytes. This is the
|
|
3
|
+
* wire shape the client uploads and the host stores — kept dependency-free so
|
|
4
|
+
* no tar/zip library is needed on either side. */
|
|
5
|
+
export interface BundleFile {
|
|
6
|
+
path: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}
|
|
9
|
+
export interface BundleStore {
|
|
10
|
+
/** Write a bundle's files under `deployId`. Overwrites any prior content. */
|
|
11
|
+
put(deployId: string, files: BundleFile[]): Promise<void>;
|
|
12
|
+
/** Read a single asset (already validated/normalized by the caller's router).
|
|
13
|
+
* Returns null when the bundle or asset doesn't exist. */
|
|
14
|
+
read(deployId: string, assetPath: string): Promise<Buffer | null>;
|
|
15
|
+
/** True when a bundle directory exists for `deployId`. */
|
|
16
|
+
has(deployId: string): Promise<boolean>;
|
|
17
|
+
/** Absolute on-disk root for a bundle (used by the static-serving worker). */
|
|
18
|
+
rootFor(deployId: string): string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Filesystem-backed bundle store. Extracts each uploaded file under
|
|
22
|
+
* `<root>/<deployId>/`. Single-instance only (a Render persistent disk is not
|
|
23
|
+
* shared across instances) — fine for the MVP; swap for object storage later
|
|
24
|
+
* behind this same interface.
|
|
25
|
+
*/
|
|
26
|
+
export declare class DiskBundleStore implements BundleStore {
|
|
27
|
+
private readonly root;
|
|
28
|
+
constructor(root: string);
|
|
29
|
+
rootFor(deployId: string): string;
|
|
30
|
+
put(deployId: string, files: BundleFile[]): Promise<void>;
|
|
31
|
+
has(deployId: string): Promise<boolean>;
|
|
32
|
+
read(deployId: string, assetPath: string): Promise<Buffer | null>;
|
|
33
|
+
}
|
|
34
|
+
/** Best-effort check that the configured bundle root is writable at boot. */
|
|
35
|
+
export declare const ensureBundleRoot: (root: string) => Promise<void>;
|
|
36
|
+
//# sourceMappingURL=BundleStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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&& this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ensureBundleRoot = exports.DiskBundleStore = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const logger_1 = require("../utils/logger");
|
|
11
|
+
const log = (0, logger_1.createLogger)('BundleStore');
|
|
12
|
+
/** Reject paths that try to escape the bundle root. Mirrors the lexical
|
|
13
|
+
* containment + traversal checks used in VariantHistoryService. */
|
|
14
|
+
const assertSafeBundlePath = (relPath) => {
|
|
15
|
+
if (relPath.length === 0 ||
|
|
16
|
+
relPath.includes('\0') ||
|
|
17
|
+
path_1.default.isAbsolute(relPath) ||
|
|
18
|
+
relPath.split(/[\\/]+/).some((part) => part === '..')) {
|
|
19
|
+
throw new Error(`BundleStore: invalid bundle path '${relPath}'`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Filesystem-backed bundle store. Extracts each uploaded file under
|
|
24
|
+
* `<root>/<deployId>/`. Single-instance only (a Render persistent disk is not
|
|
25
|
+
* shared across instances) — fine for the MVP; swap for object storage later
|
|
26
|
+
* behind this same interface.
|
|
27
|
+
*/
|
|
28
|
+
class DiskBundleStore {
|
|
29
|
+
root;
|
|
30
|
+
constructor(root) {
|
|
31
|
+
this.root = root;
|
|
32
|
+
}
|
|
33
|
+
rootFor(deployId) {
|
|
34
|
+
return path_1.default.join(this.root, deployId);
|
|
35
|
+
}
|
|
36
|
+
async put(deployId, files) {
|
|
37
|
+
const bundleRoot = this.rootFor(deployId);
|
|
38
|
+
// Stage then atomically swap so a partially written bundle is never served.
|
|
39
|
+
const stagingRoot = `${bundleRoot}.tmp-${process.pid}-${Date.now()}`;
|
|
40
|
+
await promises_1.default.rm(stagingRoot, { recursive: true, force: true });
|
|
41
|
+
await promises_1.default.mkdir(stagingRoot, { recursive: true });
|
|
42
|
+
try {
|
|
43
|
+
for (const file of files) {
|
|
44
|
+
assertSafeBundlePath(file.path);
|
|
45
|
+
const target = path_1.default.join(stagingRoot, file.path);
|
|
46
|
+
// Defense in depth: ensure the resolved path is still inside staging.
|
|
47
|
+
const rel = path_1.default.relative(stagingRoot, target);
|
|
48
|
+
if (rel.startsWith('..') || path_1.default.isAbsolute(rel)) {
|
|
49
|
+
throw new Error(`BundleStore: path escapes bundle root '${file.path}'`);
|
|
50
|
+
}
|
|
51
|
+
await promises_1.default.mkdir(path_1.default.dirname(target), { recursive: true });
|
|
52
|
+
await promises_1.default.writeFile(target, Buffer.from(file.content, 'base64'));
|
|
53
|
+
}
|
|
54
|
+
await promises_1.default.rm(bundleRoot, { recursive: true, force: true });
|
|
55
|
+
await promises_1.default.rename(stagingRoot, bundleRoot);
|
|
56
|
+
log.info(`Stored bundle ${deployId} (${files.length} files)`);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
await promises_1.default.rm(stagingRoot, { recursive: true, force: true });
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async has(deployId) {
|
|
64
|
+
try {
|
|
65
|
+
const stat = await promises_1.default.stat(this.rootFor(deployId));
|
|
66
|
+
return stat.isDirectory();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async read(deployId, assetPath) {
|
|
73
|
+
assertSafeBundlePath(assetPath);
|
|
74
|
+
const bundleRoot = this.rootFor(deployId);
|
|
75
|
+
const target = path_1.default.join(bundleRoot, assetPath);
|
|
76
|
+
const rel = path_1.default.relative(bundleRoot, target);
|
|
77
|
+
if (rel.startsWith('..') || path_1.default.isAbsolute(rel))
|
|
78
|
+
return null;
|
|
79
|
+
try {
|
|
80
|
+
const stat = await promises_1.default.stat(target);
|
|
81
|
+
if (!stat.isFile())
|
|
82
|
+
return null;
|
|
83
|
+
return await promises_1.default.readFile(target);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
const code = err.code;
|
|
87
|
+
if (code !== 'ENOENT')
|
|
88
|
+
log.warn(`read failed for ${deployId}/${assetPath}`, err);
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.DiskBundleStore = DiskBundleStore;
|
|
94
|
+
/** Best-effort check that the configured bundle root is writable at boot. */
|
|
95
|
+
const ensureBundleRoot = async (root) => {
|
|
96
|
+
await promises_1.default.mkdir(root, { recursive: true });
|
|
97
|
+
if (!fs_1.default.existsSync(root)) {
|
|
98
|
+
throw new Error(`BundleStore: bundle root '${root}' could not be created`);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
exports.ensureBundleRoot = ensureBundleRoot;
|
|
102
|
+
//# sourceMappingURL=BundleStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BundleStore.js","sourceRoot":"","sources":["../../src/services/BundleStore.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,2DAAqC;AACrC,gDAAwB;AACxB,4CAA+C;AAE/C,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,aAAa,CAAC,CAAC;AAWxC;oEACoE;AACpE,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAQ,EAAE;IACrD,IACE,OAAO,CAAC,MAAM,KAAK,CAAC;QACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtB,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,EACrD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,OAAO,GAAG,CAAC,CAAC;IACnE,C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AAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC9C,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,cAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAC9D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,kBAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAAE,OAAO,IAAI,CAAC;YAChC,OAAO,MAAM,kBAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,GAAI,GAA6B,CAAC,IAAI,CAAC;YACjD,IAAI,IAAI,KAAK,QAAQ;gBAAE,GAAG,CAAC,IAAI,CAAC,mBAAmB,QAAQ,IAAI,SAAS,EAAE,EAAE,GAAG,CAAC,CAAC;YACjF,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA3DD,0CA2DC;AAED,6EAA6E;AACtE,MAAM,gBAAgB,GAAG,KAAK,EAAE,IAAY,EAAiB,EAAE;IACpE,MAAM,kBAAU,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,wBAAwB,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC,CAAC;AALW,QAAA,gBAAgB,oBAK3B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BundleFile } from './BundleStore';
|
|
2
|
+
export declare class PrototypeBuildError extends Error {
|
|
3
|
+
/** Tail of the failing step's stderr, for surfacing in the UI toast. */
|
|
4
|
+
readonly detail?: string | undefined;
|
|
5
|
+
constructor(message: string,
|
|
6
|
+
/** Tail of the failing step's stderr, for surfacing in the UI toast. */
|
|
7
|
+
detail?: string | undefined);
|
|
8
|
+
}
|
|
9
|
+
export interface BuildResult {
|
|
10
|
+
files: BundleFile[];
|
|
11
|
+
/** Total decoded byte size of the bundle (pre-base64). */
|
|
12
|
+
totalBytes: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds a fresh-project (Vite) variant into a static bundle ready to upload to
|
|
16
|
+
* the Prototype Preview Host.
|
|
17
|
+
*
|
|
18
|
+
* The variant snapshot under `.rivet/variants/.../files/` is treated as
|
|
19
|
+
* immutable, so we copy it to an OS temp scratch dir and build there. We run
|
|
20
|
+
* `vite build --base=./` directly (not `npm run build`) so a `tsc` type error
|
|
21
|
+
* in agent-generated code doesn't block a purely visual deploy, and so asset
|
|
22
|
+
* URLs are relative (the host serves under `/p/<deployId>/` and injects a
|
|
23
|
+
* matching `<base href>`).
|
|
24
|
+
*/
|
|
25
|
+
export declare class PrototypeBuildService {
|
|
26
|
+
/** Build `filesDir` (the variant's `files/`) and return the packed bundle. */
|
|
27
|
+
build(filesDir: string): Promise<BuildResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Pack an already-built static bundle (a variant's `files/` dir) for upload
|
|
30
|
+
* without a build step. Used for history static-preview variants, which are
|
|
31
|
+
* already servable static sites — there's nothing to compile.
|
|
32
|
+
*/
|
|
33
|
+
packStatic(filesDir: string): Promise<BuildResult>;
|
|
34
|
+
/** Walk a directory and return every file base64-encoded. */
|
|
35
|
+
private packDir;
|
|
36
|
+
private runStep;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=PrototypeBuildService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrototypeBuildService.d.ts","sourceRoot":"","sources":["../../src/services/PrototypeBuildService.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAiBhD,qBAAa,mBAAoB,SAAQ,KAAK;IAG1C,wEAAwE;IACxE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;gBAFxB,OAAO,EAAE,MAAM;IACf,wEAAwE;IAC/D,MAAM,CAAC,EAAE,MAAM,YAAA;CAK3B;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD;;;;;;;;;;GAUG;AACH,qBAAa,qBAAqB;IAChC,8EAA8E;IACxE,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAkDnD;;;;OAIG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IASxD,6DAA6D;YAC/C,OAAO;IAsBrB,OAAO,CAAC,OAAO;CAqEhB"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PrototypeBuildService = exports.PrototypeBuildError = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const logger_1 = require("../utils/logger");
|
|
13
|
+
const log = (0, logger_1.createLogger)('PrototypeBuildService');
|
|
14
|
+
/** Dirs never copied into the build scratch — they're either huge, regenerated,
|
|
15
|
+
* or history/VCS noise. Mirrors VariantHistoryService.COPY_EXCLUDE. */
|
|
16
|
+
const COPY_EXCLUDE = new Set([
|
|
17
|
+
'node_modules',
|
|
18
|
+
'.git',
|
|
19
|
+
'.vite',
|
|
20
|
+
'.rivet',
|
|
21
|
+
'dist',
|
|
22
|
+
'build',
|
|
23
|
+
'.next',
|
|
24
|
+
'.cache',
|
|
25
|
+
]);
|
|
26
|
+
class PrototypeBuildError extends Error {
|
|
27
|
+
detail;
|
|
28
|
+
constructor(message,
|
|
29
|
+
/** Tail of the failing step's stderr, for surfacing in the UI toast. */
|
|
30
|
+
detail) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.detail = detail;
|
|
33
|
+
this.name = 'PrototypeBuildError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.PrototypeBuildError = PrototypeBuildError;
|
|
37
|
+
const INSTALL_TIMEOUT_MS = 180_000;
|
|
38
|
+
const BUILD_TIMEOUT_MS = 120_000;
|
|
39
|
+
/**
|
|
40
|
+
* Builds a fresh-project (Vite) variant into a static bundle ready to upload to
|
|
41
|
+
* the Prototype Preview Host.
|
|
42
|
+
*
|
|
43
|
+
* The variant snapshot under `.rivet/variants/.../files/` is treated as
|
|
44
|
+
* immutable, so we copy it to an OS temp scratch dir and build there. We run
|
|
45
|
+
* `vite build --base=./` directly (not `npm run build`) so a `tsc` type error
|
|
46
|
+
* in agent-generated code doesn't block a purely visual deploy, and so asset
|
|
47
|
+
* URLs are relative (the host serves under `/p/<deployId>/` and injects a
|
|
48
|
+
* matching `<base href>`).
|
|
49
|
+
*/
|
|
50
|
+
class PrototypeBuildService {
|
|
51
|
+
/** Build `filesDir` (the variant's `files/`) and return the packed bundle. */
|
|
52
|
+
async build(filesDir) {
|
|
53
|
+
const pkgJson = path_1.default.join(filesDir, 'package.json');
|
|
54
|
+
if (!fs_1.default.existsSync(pkgJson)) {
|
|
55
|
+
throw new PrototypeBuildError('This prototype has no package.json — only fresh Vite app prototypes can be deployed.');
|
|
56
|
+
}
|
|
57
|
+
const scratch = await promises_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rivet-deploy-'));
|
|
58
|
+
try {
|
|
59
|
+
const projectDir = path_1.default.join(scratch, 'app');
|
|
60
|
+
await promises_1.default.cp(filesDir, projectDir, {
|
|
61
|
+
recursive: true,
|
|
62
|
+
filter: (src) => !COPY_EXCLUDE.has(path_1.default.basename(src)),
|
|
63
|
+
});
|
|
64
|
+
const hasLockfile = fs_1.default.existsSync(path_1.default.join(projectDir, 'package-lock.json'));
|
|
65
|
+
await this.runStep('npm', hasLockfile ? ['ci'] : ['install', '--no-audit', '--no-fund'], projectDir, INSTALL_TIMEOUT_MS, 'install dependencies');
|
|
66
|
+
await this.runStep('npx', ['vite', 'build', '--base=./'], projectDir, BUILD_TIMEOUT_MS, 'build the prototype');
|
|
67
|
+
const distDir = path_1.default.join(projectDir, 'dist');
|
|
68
|
+
if (!fs_1.default.existsSync(path_1.default.join(distDir, 'index.html'))) {
|
|
69
|
+
throw new PrototypeBuildError('Build completed but produced no dist/index.html — unable to deploy.');
|
|
70
|
+
}
|
|
71
|
+
return await this.packDir(distDir);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await promises_1.default.rm(scratch, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Pack an already-built static bundle (a variant's `files/` dir) for upload
|
|
79
|
+
* without a build step. Used for history static-preview variants, which are
|
|
80
|
+
* already servable static sites — there's nothing to compile.
|
|
81
|
+
*/
|
|
82
|
+
async packStatic(filesDir) {
|
|
83
|
+
if (!fs_1.default.existsSync(path_1.default.join(filesDir, 'index.html'))) {
|
|
84
|
+
throw new PrototypeBuildError('This prototype has no index.html to deploy.');
|
|
85
|
+
}
|
|
86
|
+
return this.packDir(filesDir);
|
|
87
|
+
}
|
|
88
|
+
/** Walk a directory and return every file base64-encoded. */
|
|
89
|
+
async packDir(distDir) {
|
|
90
|
+
const files = [];
|
|
91
|
+
let totalBytes = 0;
|
|
92
|
+
const walk = async (dir, prefix) => {
|
|
93
|
+
const entries = await promises_1.default.readdir(dir, { withFileTypes: true });
|
|
94
|
+
for (const entry of entries) {
|
|
95
|
+
if (COPY_EXCLUDE.has(entry.name))
|
|
96
|
+
continue;
|
|
97
|
+
const abs = path_1.default.join(dir, entry.name);
|
|
98
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
99
|
+
if (entry.isDirectory()) {
|
|
100
|
+
await walk(abs, rel);
|
|
101
|
+
}
|
|
102
|
+
else if (entry.isFile()) {
|
|
103
|
+
const body = await promises_1.default.readFile(abs);
|
|
104
|
+
totalBytes += body.length;
|
|
105
|
+
files.push({ path: rel, content: body.toString('base64') });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
await walk(distDir, '');
|
|
110
|
+
return { files, totalBytes };
|
|
111
|
+
}
|
|
112
|
+
runStep(cmd, args, cwd, timeoutMs, label) {
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
const proc = (0, child_process_1.spawn)(cmd, args, {
|
|
115
|
+
cwd,
|
|
116
|
+
env: { ...process.env },
|
|
117
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
118
|
+
detached: false,
|
|
119
|
+
});
|
|
120
|
+
// Keep only the tail of stderr — enough to explain a failure without
|
|
121
|
+
// holding megabytes of npm/vite chatter in memory.
|
|
122
|
+
let stderrTail = '';
|
|
123
|
+
const appendTail = (data) => {
|
|
124
|
+
stderrTail = (stderrTail + data.toString()).slice(-4_000);
|
|
125
|
+
};
|
|
126
|
+
// Drain stdout too: with `stdio: 'pipe'` and no consumer the OS pipe
|
|
127
|
+
// buffer fills and the child blocks (same hazard as the dev-server spawn).
|
|
128
|
+
proc.stdout?.on('data', (d) => {
|
|
129
|
+
log.debug(`[deploy-build] ${d.toString().trim()}`);
|
|
130
|
+
});
|
|
131
|
+
proc.stderr?.on('data', (d) => {
|
|
132
|
+
appendTail(d);
|
|
133
|
+
log.debug(`[deploy-build] ${d.toString().trim()}`);
|
|
134
|
+
});
|
|
135
|
+
const timer = setTimeout(() => {
|
|
136
|
+
try {
|
|
137
|
+
proc.kill('SIGTERM');
|
|
138
|
+
}
|
|
139
|
+
catch { /* ignore */ }
|
|
140
|
+
setTimeout(() => {
|
|
141
|
+
try {
|
|
142
|
+
proc.kill('SIGKILL');
|
|
143
|
+
}
|
|
144
|
+
catch { /* ignore */ }
|
|
145
|
+
}, 5_000).unref();
|
|
146
|
+
reject(new PrototypeBuildError(`Timed out trying to ${label} (after ${Math.round(timeoutMs / 1000)}s).`, stderrTail.trim()));
|
|
147
|
+
}, timeoutMs);
|
|
148
|
+
proc.on('error', (err) => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
reject(new PrototypeBuildError(`Failed to ${label}: ${err.message}`, stderrTail.trim()));
|
|
151
|
+
});
|
|
152
|
+
proc.on('close', (code) => {
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
if (code === 0) {
|
|
155
|
+
resolve();
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
reject(new PrototypeBuildError(`Failed to ${label} (exit ${code}).`, stderrTail.trim()));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.PrototypeBuildService = PrototypeBuildService;
|
|
165
|
+
//# sourceMappingURL=PrototypeBuildService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrototypeBuildService.js","sourceRoot":"","sources":["../../src/services/PrototypeBuildService.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAsC;AACtC,4CAAoB;AACpB,2DAAqC;AACrC,4CAAoB;AACpB,gDAAwB;AACxB,4CAA+C;AAG/C,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,uBAAuB,CAAC,CAAC;AAElD;wEACwE;AACxE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,cAAc;IACd,MAAM;IACN,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;CACT,CAAC,CAAC;AAEH,MAAa,mBAAoB,SAAQ,KAAK;IAIjC;IAHX,YACE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,KAAK,EAAE,CAAC;gBAClB,MAAM,CACJ,IAAI,mBAAmB,CACrB,uBAAuB,KAAK,WAAW,IAAI,CAAC,KAAK,CAC/C,SAAS,GAAG,IAAI,CACjB,KAAK,EACN,UAAU,CAAC,IAAI,EAAE,CAClB,CACF,CAAC;YACJ,CAAC,EAAE,SAAS,CAAC,CAAC;YAEd,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACvB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,MAAM,CACJ,IAAI,mBAAmB,CACrB,aAAa,KAAK,KAAK,GAAG,CAAC,OAAO,EAAE,EACpC,UAAU,CAAC,IAAI,EAAE,CAClB,CACF,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBACxB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;oBACf,OAAO,EAAE,CAAC;gBACZ,CAAC;qBAAM,CAAC;oBACN,MAAM,CACJ,IAAI,mBAAmB,CACrB,aAAa,KAAK,UAAU,IAAI,IAAI,EACpC,UAAU,CAAC,IAAI,EAAE,CAClB,CACF,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9JD,sDA8JC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PrototypeBuildService } from './PrototypeBuildService';
|
|
2
|
+
export interface DeployResult {
|
|
3
|
+
deployId: string;
|
|
4
|
+
shareUrl: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Orchestrates deploying a fresh-project variant to the Prototype Preview Host:
|
|
8
|
+
* build locally → gzip the file-list → upload with the user's Rivet JWT.
|
|
9
|
+
*
|
|
10
|
+
* Auth mirrors `GatewayClient`: attach `Authorization: Bearer <jwt>` from
|
|
11
|
+
* `ConfigManager.getAuthToken()`, and on a 401 refresh the token via the proxy
|
|
12
|
+
* and retry once. The host holds all hosting credentials — the client only ever
|
|
13
|
+
* sends its own token.
|
|
14
|
+
*/
|
|
15
|
+
export declare class PrototypeDeployService {
|
|
16
|
+
private buildService;
|
|
17
|
+
private hostUrl;
|
|
18
|
+
private proxyUrl;
|
|
19
|
+
private configManager;
|
|
20
|
+
constructor(buildService?: PrototypeBuildService, hostUrl?: string, proxyUrl?: string);
|
|
21
|
+
/** Build the variant's `files/` dir (Vite app) and publish it. */
|
|
22
|
+
deploy(filesDir: string): Promise<DeployResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Publish an already-built static bundle (the variant's `files/` dir) with no
|
|
25
|
+
* build step. Used for history static-preview variants, which are already
|
|
26
|
+
* servable static sites.
|
|
27
|
+
*/
|
|
28
|
+
deployStatic(filesDir: string): Promise<DeployResult>;
|
|
29
|
+
private publishFiles;
|
|
30
|
+
private publish;
|
|
31
|
+
/** Refresh the access token using the stored refresh token. Mirrors GatewayClient. */
|
|
32
|
+
private refreshAccessToken;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=PrototypeDeployService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrototypeDeployService.d.ts","sourceRoot":"","sources":["../../src/services/PrototypeDeployService.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,qBAAa,sBAAsB;IAI/B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ;IALlB,OAAO,CAAC,aAAa,CAAsB;gBAGjC,YAAY,GAAE,qBAAmD,EACjE,OAAO,GAAE,MAA2B,EACpC,QAAQ,GAAE,MAAkB;IAGtC,kEAAkE;IAC5D,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAKrD;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;YAK7C,YAAY;YAcZ,OAAO;IAkDrB,sFAAsF;YACxE,kBAAkB;CAyBjC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrototypeDeployService = void 0;
|
|
4
|
+
const zlib_1 = require("zlib");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
const ConfigManager_1 = require("./ConfigManager");
|
|
7
|
+
const proxy_1 = require("../config/proxy");
|
|
8
|
+
const PrototypeBuildService_1 = require("./PrototypeBuildService");
|
|
9
|
+
const log = (0, logger_1.createLogger)('PrototypeDeployService');
|
|
10
|
+
/**
|
|
11
|
+
* Orchestrates deploying a fresh-project variant to the Prototype Preview Host:
|
|
12
|
+
* build locally → gzip the file-list → upload with the user's Rivet JWT.
|
|
13
|
+
*
|
|
14
|
+
* Auth mirrors `GatewayClient`: attach `Authorization: Bearer <jwt>` from
|
|
15
|
+
* `ConfigManager.getAuthToken()`, and on a 401 refresh the token via the proxy
|
|
16
|
+
* and retry once. The host holds all hosting credentials — the client only ever
|
|
17
|
+
* sends its own token.
|
|
18
|
+
*/
|
|
19
|
+
class PrototypeDeployService {
|
|
20
|
+
buildService;
|
|
21
|
+
hostUrl;
|
|
22
|
+
proxyUrl;
|
|
23
|
+
configManager = (0, ConfigManager_1.getConfigManager)();
|
|
24
|
+
constructor(buildService = new PrototypeBuildService_1.PrototypeBuildService(), hostUrl = proxy_1.PROTOTYPE_HOST_URL, proxyUrl = proxy_1.PROXY_URL) {
|
|
25
|
+
this.buildService = buildService;
|
|
26
|
+
this.hostUrl = hostUrl;
|
|
27
|
+
this.proxyUrl = proxyUrl;
|
|
28
|
+
}
|
|
29
|
+
/** Build the variant's `files/` dir (Vite app) and publish it. */
|
|
30
|
+
async deploy(filesDir) {
|
|
31
|
+
const { files, totalBytes } = await this.buildService.build(filesDir);
|
|
32
|
+
return this.publishFiles(files, totalBytes, 'Built');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Publish an already-built static bundle (the variant's `files/` dir) with no
|
|
36
|
+
* build step. Used for history static-preview variants, which are already
|
|
37
|
+
* servable static sites.
|
|
38
|
+
*/
|
|
39
|
+
async deployStatic(filesDir) {
|
|
40
|
+
const { files, totalBytes } = await this.buildService.packStatic(filesDir);
|
|
41
|
+
return this.publishFiles(files, totalBytes, 'Packed');
|
|
42
|
+
}
|
|
43
|
+
async publishFiles(files, totalBytes, verb) {
|
|
44
|
+
log.info(`${verb} prototype bundle: ${files.length} files, ${Math.round(totalBytes / 1024)}KB`);
|
|
45
|
+
const payload = (0, zlib_1.gzipSync)(Buffer.from(JSON.stringify({ files })));
|
|
46
|
+
return this.publish(payload, 0);
|
|
47
|
+
}
|
|
48
|
+
async publish(payload, retryCount) {
|
|
49
|
+
const authToken = this.configManager.getAuthToken();
|
|
50
|
+
if (!authToken) {
|
|
51
|
+
throw new Error('Not authenticated. Please run `rivet login` to deploy a prototype.');
|
|
52
|
+
}
|
|
53
|
+
const response = await fetch(`${this.hostUrl}/publish`, {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
Authorization: `Bearer ${authToken}`,
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
'Content-Encoding': 'gzip',
|
|
59
|
+
},
|
|
60
|
+
// Node's fetch accepts a Buffer at runtime; the DOM BodyInit type doesn't
|
|
61
|
+
// list it, so cast. (GatewayClient only ever sends strings, so it never
|
|
62
|
+
// needed this.)
|
|
63
|
+
body: payload,
|
|
64
|
+
});
|
|
65
|
+
if (response.status === 401 && retryCount === 0) {
|
|
66
|
+
log.warn('Token expired, attempting to refresh...');
|
|
67
|
+
const refreshed = await this.refreshAccessToken();
|
|
68
|
+
if (refreshed) {
|
|
69
|
+
return this.publish(payload, retryCount + 1);
|
|
70
|
+
}
|
|
71
|
+
throw new Error('Authentication expired. Please run `rivet logout` and `rivet login` to re-authenticate.');
|
|
72
|
+
}
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
const body = await response.json().catch(() => ({}));
|
|
75
|
+
const message = body.message ??
|
|
76
|
+
`Deploy failed (${response.status}).`;
|
|
77
|
+
throw new Error(message);
|
|
78
|
+
}
|
|
79
|
+
const result = (await response.json());
|
|
80
|
+
if (!result.deployId || !result.shareUrl) {
|
|
81
|
+
throw new Error('Deploy host returned an unexpected response.');
|
|
82
|
+
}
|
|
83
|
+
return { deployId: result.deployId, shareUrl: result.shareUrl };
|
|
84
|
+
}
|
|
85
|
+
/** Refresh the access token using the stored refresh token. Mirrors GatewayClient. */
|
|
86
|
+
async refreshAccessToken() {
|
|
87
|
+
const refreshToken = this.configManager.getRefreshToken();
|
|
88
|
+
if (!refreshToken) {
|
|
89
|
+
log.warn('No refresh token available');
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const response = await fetch(`${this.proxyUrl}/api/auth/refresh`, {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: { 'Content-Type': 'application/json' },
|
|
96
|
+
body: JSON.stringify({ refreshToken }),
|
|
97
|
+
});
|
|
98
|
+
if (!response.ok)
|
|
99
|
+
return false;
|
|
100
|
+
const result = await response.json();
|
|
101
|
+
if (result.success && result.token) {
|
|
102
|
+
const email = this.configManager.getEmail() || '';
|
|
103
|
+
this.configManager.setAuth(result.token, email, result.refreshToken);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
log.warn('Error refreshing token:', err);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.PrototypeDeployService = PrototypeDeployService;
|
|
115
|
+
//# sourceMappingURL=PrototypeDeployService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrototypeDeployService.js","sourceRoot":"","sources":["../../src/services/PrototypeDeployService.ts"],"names":[],"mappings":";;;AAAA,+BAAgC;AAChC,4CAA+C;AAC/C,mDAAmD;AACnD,2CAAgE;AAChE,mEAAgE;AAEhE,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,wBAAwB,CAAC,CAAC;AAOnD;;;;;;;;GAQG;AACH,MAAa,sBAAsB;IAIvB;IACA;IACA;IALF,aAAa,GAAG,IAAA,gCAAgB,GAAE,CAAC;IAE3C,YACU,eAAsC,IAAI,6CAAqB,EAAE,EACjE,UAAkB,0BAAkB,EACpC,WAAmB,iBAAS;QAF5B,iBAAY,GAAZ,YAAY,CAAqD;QACjE,YAAO,GAAP,OAAO,CAA6B;QACpC,aAAQ,GAAR,QAAQ,CAAoB;IACnC,CAAC;IAEJ,kEAAkE;IAClE,KAAK,CAAC,MAAM,CAAC,QAAgB;QAC3B,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,QAAgB;QACjC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAEO,KAAK,CAAC,YAAY,CACxB,KAA0C,EAC1C,UAAkB,EAClB,IAAY;QAEZ,GAAG,CAAC,IAAI,CACN,GAAG,IAAI,sBAAsB,KAAK,CAAC,MAAM,WAAW,IAAI,CA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,CAAC,KAAK,EAAE,CAAC;gBACnC,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;gBAClD,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;gBACrE,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;YACzC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAnHD,wDAmHC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface VerifiedUser {
|
|
2
|
+
id: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Minimal, dependency-free verifier for Rivet (Supabase) JWTs.
|
|
7
|
+
*
|
|
8
|
+
* The proxy (`src/proxy`) verifies tokens with `@supabase/supabase-js`, but that
|
|
9
|
+
* package and the whole `src/proxy` tree are excluded from the main `tsc` build.
|
|
10
|
+
* The Prototype Preview Host is part of the main build, so it can't reuse that
|
|
11
|
+
* service. Instead we hit Supabase's GoTrue REST endpoint directly with `fetch`
|
|
12
|
+
* — exactly what `supabase.auth.getUser(token)` does under the hood — using the
|
|
13
|
+
* same `SUPABASE_URL` / `SUPABASE_ANON_KEY` the proxy already holds.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SupabaseAuthService {
|
|
16
|
+
private readonly url;
|
|
17
|
+
private readonly anonKey;
|
|
18
|
+
constructor(opts?: {
|
|
19
|
+
url?: string;
|
|
20
|
+
anonKey?: string;
|
|
21
|
+
});
|
|
22
|
+
/** Returns the user for a valid JWT, or null when the token is missing/invalid. */
|
|
23
|
+
verifyToken(token: string): Promise<VerifiedUser | null>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=SupabaseAuthService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SupabaseAuthService.d.ts","sourceRoot":"","sources":["../../src/services/SupabaseAuthService.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,IAAI,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAYrD,mFAAmF;IAC7E,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;CAsB/D"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SupabaseAuthService = void 0;
|
|
4
|
+
const logger_1 = require("../utils/logger");
|
|
5
|
+
const log = (0, logger_1.createLogger)('SupabaseAuthService');
|
|
6
|
+
/**
|
|
7
|
+
* Minimal, dependency-free verifier for Rivet (Supabase) JWTs.
|
|
8
|
+
*
|
|
9
|
+
* The proxy (`src/proxy`) verifies tokens with `@supabase/supabase-js`, but that
|
|
10
|
+
* package and the whole `src/proxy` tree are excluded from the main `tsc` build.
|
|
11
|
+
* The Prototype Preview Host is part of the main build, so it can't reuse that
|
|
12
|
+
* service. Instead we hit Supabase's GoTrue REST endpoint directly with `fetch`
|
|
13
|
+
* — exactly what `supabase.auth.getUser(token)` does under the hood — using the
|
|
14
|
+
* same `SUPABASE_URL` / `SUPABASE_ANON_KEY` the proxy already holds.
|
|
15
|
+
*/
|
|
16
|
+
class SupabaseAuthService {
|
|
17
|
+
url;
|
|
18
|
+
anonKey;
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
const url = opts?.url ?? process.env.SUPABASE_URL;
|
|
21
|
+
const anonKey = opts?.anonKey ?? process.env.SUPABASE_ANON_KEY;
|
|
22
|
+
if (!url || !anonKey) {
|
|
23
|
+
throw new Error('SUPABASE_URL and SUPABASE_ANON_KEY must be set to verify auth tokens');
|
|
24
|
+
}
|
|
25
|
+
this.url = url.replace(/\/+$/, '');
|
|
26
|
+
this.anonKey = anonKey;
|
|
27
|
+
}
|
|
28
|
+
/** Returns the user for a valid JWT, or null when the token is missing/invalid. */
|
|
29
|
+
async verifyToken(token) {
|
|
30
|
+
if (!token)
|
|
31
|
+
return null;
|
|
32
|
+
try {
|
|
33
|
+
const res = await fetch(`${this.url}/auth/v1/user`, {
|
|
34
|
+
headers: {
|
|
35
|
+
apikey: this.anonKey,
|
|
36
|
+
Authorization: `Bearer ${token}`,
|
|
37
|
+
},
|
|
38
|
+
signal: AbortSignal.timeout(10_000),
|
|
39
|
+
});
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
log.debug(`Token verification failed (${res.status})`);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const user = (await res.json());
|
|
45
|
+
if (!user?.id)
|
|
46
|
+
return null;
|
|
47
|
+
return { id: user.id, email: user.email };
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
log.warn('Error verifying token', err);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.SupabaseAuthService = SupabaseAuthService;
|
|
56
|
+
//# sourceMappingURL=SupabaseAuthService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SupabaseAuthService.js","sourceRoot":"","sources":["../../src/services/SupabaseAuthService.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAE/C,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,qBAAqB,CAAC,CAAC;AAOhD;;;;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