@haneinfo/app-tooling 0.8.0 → 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.
Files changed (57) hide show
  1. package/README.md +63 -1
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +121 -1
  4. package/dist/cli.js.map +1 -1
  5. package/dist/doctor/checks/authgate.d.ts +5 -0
  6. package/dist/doctor/checks/authgate.d.ts.map +1 -0
  7. package/dist/doctor/checks/authgate.js +162 -0
  8. package/dist/doctor/checks/authgate.js.map +1 -0
  9. package/dist/doctor/checks/env.d.ts +6 -0
  10. package/dist/doctor/checks/env.d.ts.map +1 -0
  11. package/dist/doctor/checks/env.js +102 -0
  12. package/dist/doctor/checks/env.js.map +1 -0
  13. package/dist/doctor/checks/live.d.ts +5 -0
  14. package/dist/doctor/checks/live.d.ts.map +1 -0
  15. package/dist/doctor/checks/live.js +89 -0
  16. package/dist/doctor/checks/live.js.map +1 -0
  17. package/dist/doctor/index.d.ts +9 -0
  18. package/dist/doctor/index.d.ts.map +1 -0
  19. package/dist/doctor/index.js +74 -0
  20. package/dist/doctor/index.js.map +1 -0
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +4 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/init/env-file.d.ts +18 -0
  26. package/dist/init/env-file.d.ts.map +1 -0
  27. package/dist/init/env-file.js +157 -0
  28. package/dist/init/env-file.js.map +1 -0
  29. package/dist/init/index.d.ts +33 -0
  30. package/dist/init/index.d.ts.map +1 -0
  31. package/dist/init/index.js +179 -0
  32. package/dist/init/index.js.map +1 -0
  33. package/dist/init/runner.d.ts +15 -0
  34. package/dist/init/runner.d.ts.map +1 -0
  35. package/dist/init/runner.js +51 -0
  36. package/dist/init/runner.js.map +1 -0
  37. package/dist/init/secrets.d.ts +10 -0
  38. package/dist/init/secrets.d.ts.map +1 -0
  39. package/dist/init/secrets.js +35 -0
  40. package/dist/init/secrets.js.map +1 -0
  41. package/dist/init/steps/accounts.d.ts +9 -0
  42. package/dist/init/steps/accounts.d.ts.map +1 -0
  43. package/dist/init/steps/accounts.js +75 -0
  44. package/dist/init/steps/accounts.js.map +1 -0
  45. package/dist/init/steps/authgate.d.ts +6 -0
  46. package/dist/init/steps/authgate.d.ts.map +1 -0
  47. package/dist/init/steps/authgate.js +46 -0
  48. package/dist/init/steps/authgate.js.map +1 -0
  49. package/dist/init/steps/env.d.ts +8 -0
  50. package/dist/init/steps/env.d.ts.map +1 -0
  51. package/dist/init/steps/env.js +61 -0
  52. package/dist/init/steps/env.js.map +1 -0
  53. package/dist/init/steps/preflight.d.ts +12 -0
  54. package/dist/init/steps/preflight.d.ts.map +1 -0
  55. package/dist/init/steps/preflight.js +127 -0
  56. package/dist/init/steps/preflight.js.map +1 -0
  57. package/package.json +1 -1
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loopbackAddresses = loopbackAddresses;
4
+ exports.checkLive = checkLive;
5
+ const node_http_1 = require("node:http");
6
+ const node_net_1 = require("node:net");
7
+ const TIMEOUT_MS = 2_000;
8
+ function loopbackAddresses(host) {
9
+ const name = host.toLowerCase().replace(/^\[([^\]]+)\]$/, '$1');
10
+ if (/^(?:[a-z\d](?:[a-z\d-]*[a-z\d])?\.)*localhost\.?$/.test(name)) {
11
+ // Resolve localhost names locally, without DNS or a hosts-file override.
12
+ return ['127.0.0.1', '::1'];
13
+ }
14
+ if ((0, node_net_1.isIP)(name) === 4 && name.startsWith('127.'))
15
+ return [name];
16
+ if (!name.includes('%') && (0, node_net_1.isIP)(name) === 6) {
17
+ const canonical = new URL(`http://[${name}]`).hostname.slice(1, -1);
18
+ if (canonical === '::1' || /^::ffff:7f[\da-f]{2}:[\da-f]{1,4}$/.test(canonical)) {
19
+ return [canonical];
20
+ }
21
+ }
22
+ return [];
23
+ }
24
+ function tcp(host, port) {
25
+ return new Promise((resolve) => {
26
+ const socket = (0, node_net_1.connect)({ host, port });
27
+ socket.setTimeout(TIMEOUT_MS);
28
+ const finish = (passed) => {
29
+ socket.destroy();
30
+ resolve(passed);
31
+ };
32
+ socket.once('connect', () => finish(true));
33
+ socket.once('timeout', () => finish(false));
34
+ socket.once('error', () => finish(false));
35
+ });
36
+ }
37
+ function health(port) {
38
+ return new Promise((resolve) => {
39
+ const req = (0, node_http_1.request)({
40
+ hostname: '127.0.0.1',
41
+ port,
42
+ path: '/healthz',
43
+ signal: AbortSignal.timeout(TIMEOUT_MS),
44
+ agent: false,
45
+ }, (res) => {
46
+ resolve(res.statusCode === 200);
47
+ res.destroy();
48
+ });
49
+ req.once('error', () => resolve(false));
50
+ req.end();
51
+ });
52
+ }
53
+ async function checkLive(env, authgate) {
54
+ const db = async () => {
55
+ const value = env.get('DATABASE_URL');
56
+ const url = value && URL.canParse(value) ? new URL(value) : undefined;
57
+ const path = '.env';
58
+ const hosts = url ? loopbackAddresses(url.hostname) : [];
59
+ const port = Number(url?.port || '5432');
60
+ if (!url || !['postgres:', 'postgresql:'].includes(url.protocol) || !hosts.length) {
61
+ return {
62
+ code: 'DATABASE_LIVE_TARGET',
63
+ path,
64
+ message: 'Set DATABASE_URL to a PostgreSQL URL on loopback or a .localhost hostname.',
65
+ };
66
+ }
67
+ if (port > 0 && (await Promise.all(hosts.map((host) => tcp(host, port)))).some(Boolean)) {
68
+ return undefined;
69
+ }
70
+ return {
71
+ code: 'DATABASE_LIVE',
72
+ path,
73
+ message: 'Start the App database and check the port in DATABASE_URL.',
74
+ };
75
+ };
76
+ const edge = async () => {
77
+ const value = authgate.get('AG_EDGE_PORT') ?? '';
78
+ const port = Number(value);
79
+ if (/^\d+$/.test(value) && port > 0 && port <= 65535 && (await health(port)))
80
+ return undefined;
81
+ return {
82
+ code: 'AUTHGATE_LIVE',
83
+ path: 'deploy/authgate/.env',
84
+ message: 'Set AG_EDGE_PORT and start the local AuthGate stack so /healthz returns HTTP 200.',
85
+ };
86
+ };
87
+ return (await Promise.all([db(), edge()])).filter((issue) => issue !== undefined);
88
+ }
89
+ //# sourceMappingURL=live.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live.js","sourceRoot":"","sources":["../../../src/doctor/checks/live.ts"],"names":[],"mappings":";;AAOA,8CAcC;AAoCD,8BAkCC;AA3FD,yCAAoC;AACpC,uCAAyC;AAIzC,MAAM,UAAU,GAAG,KAAK,CAAC;AAEzB,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IAChE,IAAI,mDAAmD,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnE,yEAAyE;QACzE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,IAAI,IAAA,eAAI,EAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAA,eAAI,EAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,SAAS,KAAK,KAAK,IAAI,oCAAoC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAChF,OAAO,CAAC,SAAS,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,GAAG,CAAC,IAAY,EAAE,IAAY;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,IAAA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AM,CAAC,KAAK,CAAC,CAAC;QAC3B,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,SAAS,CAAC;QAC/F,OAAO;YACL,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,sBAAsB;YAC5B,OAAO,EAAE,mFAAmF;SAC7F,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { CheckReport } from '../checks';
2
+ import { type Runner } from '../init/runner';
3
+ export type DoctorProfile = 'dev' | 'production';
4
+ export type DoctorReport = Omit<CheckReport, 'target'> & {
5
+ target: 'doctor';
6
+ };
7
+ export declare function doctorApp(root: string, profile?: DoctorProfile, runner?: Runner): DoctorReport;
8
+ export declare function doctorAppLive(root: string, runner?: Runner): Promise<DoctorReport>;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/doctor/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,KAAK,MAAM,EAAO,MAAM,gBAAgB,CAAC;AAOlD,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,YAAY,CAAC;AACjD,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC;AAE9E,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,aAAqB,EAC9B,MAAM,GAAE,MAAY,GACnB,YAAY,CAEd;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAK7F"}
@@ -0,0 +1,74 @@
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.doctorApp = doctorApp;
7
+ exports.doctorAppLive = doctorAppLive;
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const env_file_1 = require("../init/env-file");
10
+ const runner_1 = require("../init/runner");
11
+ const authgate_1 = require("../init/steps/authgate");
12
+ const authgate_2 = require("./checks/authgate");
13
+ const env_1 = require("./checks/env");
14
+ const live_1 = require("./checks/live");
15
+ function doctorApp(root, profile = 'dev', runner = runner_1.run) {
16
+ return inspectApp(root, profile, runner).report;
17
+ }
18
+ async function doctorAppLive(root, runner = runner_1.run) {
19
+ const { report, settings, authgate } = inspectApp(root, 'dev', runner);
20
+ report.issues.push(...(await (0, live_1.checkLive)(settings, authgate)));
21
+ report.passed = report.issues.length === 0;
22
+ return report;
23
+ }
24
+ function inspectApp(root, profile, runner) {
25
+ const issues = [];
26
+ const warnings = [];
27
+ const env = (0, env_file_1.readOptionalFile)(node_path_1.default.join(root, '.env'));
28
+ const example = env === undefined ? (0, env_file_1.readOptionalFile)(node_path_1.default.join(root, '.env.example')) : undefined;
29
+ if (env === undefined) {
30
+ issues.push({
31
+ code: 'ENV_MISSING',
32
+ path: '.env',
33
+ message: 'Create .env from .env.example or run haneinfo-app init --only env.',
34
+ });
35
+ }
36
+ if (runner('git', ['rev-parse', '--is-inside-work-tree'], root).stdout.trim() === 'true') {
37
+ const tracked = runner('git', ['ls-files', '-z', '--', '.env'], root);
38
+ if (tracked.status !== 0)
39
+ throw new Error('Could not check whether .env is tracked');
40
+ if (tracked.stdout) {
41
+ issues.push({
42
+ code: 'ENV_TRACKED',
43
+ path: '.env',
44
+ message: 'Remove .env from the Git index, ignore it, and rotate any committed secrets.',
45
+ });
46
+ }
47
+ }
48
+ const authgateFile = 'deploy/authgate/.env';
49
+ const authgateText = (0, env_file_1.readOptionalFile)((0, authgate_1.authgateEnvPath)(root));
50
+ const authgate = new env_file_1.EnvFile(authgateText ?? '');
51
+ if (authgateText !== undefined) {
52
+ for (const [key, value] of authgate.entries()) {
53
+ if (key.startsWith('AG_') && !value.trim()) {
54
+ issues.push({
55
+ code: 'AUTHGATE_ENV_EMPTY',
56
+ path: authgateFile,
57
+ message: `Fill ${key} using the AuthGate dev stack setup.`,
58
+ });
59
+ }
60
+ }
61
+ (0, env_1.checkPlaceholders)(authgate, authgateFile, issues);
62
+ }
63
+ const production = profile === 'production';
64
+ const file = env === undefined ? '.env.example' : '.env';
65
+ const settings = new env_file_1.EnvFile(env ?? example ?? '');
66
+ (0, env_1.checkPlaceholders)(settings, file, issues);
67
+ if (env !== undefined || example !== undefined)
68
+ (0, env_1.checkDatabase)(settings, file, issues);
69
+ (0, env_1.checkRuntimeEnv)(settings, file, production, issues, warnings);
70
+ (0, authgate_2.checkAuthGate)(settings, file, (0, env_file_1.readOptionalFile)(node_path_1.default.join(root, authgate_2.POLICY_FILE)), production, issues, warnings);
71
+ const report = { target: 'doctor', issues, warnings, passed: issues.length === 0 };
72
+ return { report, settings, authgate };
73
+ }
74
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/doctor/index.ts"],"names":[],"mappings":";;;;;AAaA,8BAMC;AAED,sCAKC;AA1BD,0DAA6B;AAE7B,+CAA6D;AAC7D,2CAAkD;AAClD,qDAAyD;AAEzD,gDAA+D;AAC/D,sCAAiF;AACjF,wCAA0C;AAK1C,SAAgB,SAAS,CACvB,IAAY,EACZ,UAAyB,KAAK,EAC9B,SAAiB,YAAG;IAEpB,OAAO,UAA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,IAAI,kBAAO,CAAC,GAAG,IAAI,OAAO,IAAI,EAAE,CAAC,CAAC;IACnD,IAAA,uBAAiB,EAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1C,IAAI,GAAG,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS;QAAE,IAAA,mBAAa,EAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACtF,IAAA,qBAAe,EAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC9D,IAAA,wBAAa,EACX,QAAQ,EACR,IAAI,EACJ,IAAA,2BAAgB,EAAC,mBAAI,CAAC,IAAI,CAAC,IAAI,EAAE,sBAAW,CAAC,CAAC,EAC9C,UAAU,EACV,MAAM,EACN,QAAQ,CACT,CAAC;IACF,MAAM,MAAM,GAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IACjG,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AACxC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from './checks';
2
2
  export * from './cli';
3
3
  export * from './dictionary';
4
+ export * from './doctor';
4
5
  export * from './enums';
6
+ export { setEnvValue } from './init/env-file';
5
7
  export * from './integration-contracts';
6
8
  export * from './scaffold';
7
9
  export * from './scopes';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -14,10 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.setEnvValue = void 0;
17
18
  __exportStar(require("./checks"), exports);
18
19
  __exportStar(require("./cli"), exports);
19
20
  __exportStar(require("./dictionary"), exports);
21
+ __exportStar(require("./doctor"), exports);
20
22
  __exportStar(require("./enums"), exports);
23
+ var env_file_1 = require("./init/env-file");
24
+ Object.defineProperty(exports, "setEnvValue", { enumerable: true, get: function () { return env_file_1.setEnvValue; } });
21
25
  __exportStar(require("./integration-contracts"), exports);
22
26
  __exportStar(require("./scaffold"), exports);
23
27
  __exportStar(require("./scopes"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,wCAAsB;AACtB,+CAA6B;AAC7B,0CAAwB;AACxB,0DAAwC;AACxC,6CAA2B;AAC3B,2CAAyB;AACzB,sDAAoC;AACpC,kDAAgC;AAChC,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,wCAAsB;AACtB,+CAA6B;AAC7B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA8C;AAArC,uGAAA,WAAW,OAAA;AACpB,0DAAwC;AACxC,6CAA2B;AAC3B,2CAAyB;AACzB,sDAAoC;AACpC,kDAAgC;AAChC,6CAA2B"}
@@ -0,0 +1,18 @@
1
+ export declare function readOptionalFile(file: string): string | undefined;
2
+ export declare class EnvFile {
3
+ private assignments;
4
+ private commented;
5
+ private newline;
6
+ text: string;
7
+ constructor(text: string);
8
+ private parse;
9
+ get(key: string): string | undefined;
10
+ entries(): [string, string][];
11
+ private append;
12
+ addMissingFrom(example: EnvFile): string[];
13
+ set(key: string, value: string): void;
14
+ }
15
+ export declare function writeEnvFile(file: string, previous: string | undefined, text: string): void;
16
+ /** Write one value directly to the App's .env, leaving commented-out keys disabled. */
17
+ export declare function setEnvValue(root: string, key: string, value: string): void;
18
+ //# sourceMappingURL=env-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-file.d.ts","sourceRoot":"","sources":["../../src/init/env-file.ts"],"names":[],"mappings":"AAqBA,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOjE;AAED,qBAAa,OAAO;IAClB,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,OAAO,CAAS;IACxB,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,EAAE,MAAM;IAMxB,OAAO,CAAC,KAAK;IAuCb,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIpC,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;IAI7B,OAAO,CAAC,MAAM;IAMd,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE;IAU1C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAwBtC;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAwB3F;AAED,uFAAuF;AACvF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAM1E"}
@@ -0,0 +1,157 @@
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.EnvFile = void 0;
7
+ exports.readOptionalFile = readOptionalFile;
8
+ exports.writeEnvFile = writeEnvFile;
9
+ exports.setEnvValue = setEnvValue;
10
+ const node_fs_1 = require("node:fs");
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ function readOptionalFile(file) {
13
+ try {
14
+ return (0, node_fs_1.readFileSync)(file, 'utf8');
15
+ }
16
+ catch (error) {
17
+ if (error.code === 'ENOENT')
18
+ return undefined;
19
+ throw error;
20
+ }
21
+ }
22
+ class EnvFile {
23
+ constructor(text) {
24
+ this.assignments = new Map();
25
+ this.commented = new Set();
26
+ this.text = text;
27
+ this.newline = text.match(/\r\n|\n|\r/)?.[0] ?? '\n';
28
+ this.parse();
29
+ }
30
+ parse() {
31
+ this.assignments.clear();
32
+ this.commented.clear();
33
+ const lines = /([^\r\n]*)(?:\r\n|\r|\n|$)/g;
34
+ for (let line = lines.exec(this.text); line?.[0]; line = lines.exec(this.text)) {
35
+ const body = line[1] ?? '';
36
+ const commented = /^\s*#+\s*(?:export\s+)?([\w.-]+)\s*=/.exec(body)?.[1];
37
+ if (commented)
38
+ this.commented.add(commented);
39
+ const prefix = /^[\s\uFEFF]*(?:export[ \t]+)?([\w.-]+)[ \t]*=[ \t]*/.exec(body);
40
+ const key = prefix?.[1];
41
+ if (!prefix || !key)
42
+ continue;
43
+ const start = line.index + prefix[0].length;
44
+ let lineEnd = line.index + body.length;
45
+ const delimiter = this.text[start] ?? '';
46
+ const close = ['"', "'", '\x60'].includes(delimiter)
47
+ ? this.text.indexOf(delimiter, start + 1)
48
+ : -1;
49
+ let end;
50
+ let quote = '';
51
+ let value;
52
+ if (close !== -1 && /^[ \t]*(?:#.*)?(?:\r|\n|$)/.test(this.text.slice(close + 1))) {
53
+ quote = delimiter;
54
+ end = close + 1;
55
+ value = this.text.slice(start + 1, close);
56
+ if (quote === '"')
57
+ value = value.replace(/\\n/g, '\n').replace(/\\r/g, '\r');
58
+ const tail = /^[^\r\n]*/.exec(this.text.slice(end))?.[0] ?? '';
59
+ lineEnd = end + tail.length;
60
+ lines.lastIndex =
61
+ lineEnd + (this.text.slice(lineEnd).match(/^(?:\r\n|\r|\n)/)?.[0].length ?? 0);
62
+ }
63
+ else {
64
+ value = (body.slice(prefix[0].length).split('#', 1)[0] ?? '').trimEnd();
65
+ end = start + value.length;
66
+ }
67
+ this.assignments.set(key, { key, value, quote, start, end, lineStart: line.index, lineEnd });
68
+ }
69
+ }
70
+ get(key) {
71
+ return this.assignments.get(key)?.value;
72
+ }
73
+ entries() {
74
+ return Array.from(this.assignments.values(), ({ key, value }) => [key, value]);
75
+ }
76
+ append(line) {
77
+ if (this.text && !/[\r\n]$/.test(this.text))
78
+ this.text += this.newline;
79
+ this.text += line + this.newline;
80
+ this.parse();
81
+ }
82
+ addMissingFrom(example) {
83
+ const added = [];
84
+ for (const { key, lineStart, lineEnd } of example.assignments.values()) {
85
+ if (this.assignments.has(key) || this.commented.has(key))
86
+ continue;
87
+ this.append(example.text.slice(lineStart, lineEnd).replace(/^\uFEFF/, ''));
88
+ added.push(key);
89
+ }
90
+ return added;
91
+ }
92
+ set(key, value) {
93
+ if (!/^[\w.-]+$/.test(key))
94
+ throw new Error('Invalid environment key');
95
+ const assignment = this.assignments.get(key);
96
+ if (assignment?.value === value || (!assignment && this.commented.has(key)))
97
+ return;
98
+ let quote = assignment?.quote ?? '';
99
+ if (!quote && /[#\r\n]|^\s|\s$|^['"\x60]/.test(value)) {
100
+ quote = ["'", '\x60', '"'].find((candidate) => !value.includes(candidate)) ?? '';
101
+ if (!quote)
102
+ throw new Error('Environment value needs a compatible quote delimiter');
103
+ }
104
+ if (quote && value.includes(quote)) {
105
+ throw new Error('Environment value contains its quote delimiter');
106
+ }
107
+ if (quote === '"' && /\\[nr]/.test(value)) {
108
+ throw new Error('Environment value contains a literal escape in double quotes');
109
+ }
110
+ const encoded = quote + value + quote;
111
+ if (!assignment) {
112
+ this.append(`${key}=${encoded}`);
113
+ return;
114
+ }
115
+ this.text = this.text.slice(0, assignment.start) + encoded + this.text.slice(assignment.end);
116
+ this.parse();
117
+ }
118
+ }
119
+ exports.EnvFile = EnvFile;
120
+ function writeEnvFile(file, previous, text) {
121
+ const lock = `${file}.lock`;
122
+ const lockFd = (0, node_fs_1.openSync)(lock, 'wx', 0o600);
123
+ try {
124
+ if (readOptionalFile(file) !== previous) {
125
+ throw new Error('Environment file changed during setup');
126
+ }
127
+ const temp = (0, node_fs_1.mkdtempSync)(node_path_1.default.join(node_path_1.default.dirname(file), '.env-'));
128
+ try {
129
+ const staged = node_path_1.default.join(temp, '.env');
130
+ const fd = (0, node_fs_1.openSync)(staged, 'wx', 0o600);
131
+ try {
132
+ (0, node_fs_1.writeFileSync)(fd, text, 'utf8');
133
+ }
134
+ finally {
135
+ (0, node_fs_1.closeSync)(fd);
136
+ }
137
+ (0, node_fs_1.renameSync)(staged, file);
138
+ }
139
+ finally {
140
+ (0, node_fs_1.rmSync)(temp, { recursive: true, force: true });
141
+ }
142
+ }
143
+ finally {
144
+ (0, node_fs_1.closeSync)(lockFd);
145
+ (0, node_fs_1.rmSync)(lock);
146
+ }
147
+ }
148
+ /** Write one value directly to the App's .env, leaving commented-out keys disabled. */
149
+ function setEnvValue(root, key, value) {
150
+ const file = node_path_1.default.resolve(root, '.env');
151
+ const previous = readOptionalFile(file);
152
+ const env = new EnvFile(previous ?? '');
153
+ env.set(key, value);
154
+ if (env.text !== (previous ?? ''))
155
+ writeEnvFile(file, previous, env.text);
156
+ }
157
+ //# sourceMappingURL=env-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-file.js","sourceRoot":"","sources":["../../src/init/env-file.ts"],"names":[],"mappings":";;;;;;AAqBA,4CAOC;AAuGD,oCAwBC;AAGD,kCAMC;AApKD,qCAQiB;AACjB,0DAA6B;AAY7B,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,IAAI,CAAC;QACH,OAAO,IAAA,sBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACzE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAa,OAAO;IAMlB,YAAY,IAAY;QALhB,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC5C,cAAS,GAAG,IAAI,GAAG,EAAU,CAAC;QAKpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QACrD,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAEO,KAAK;QACX,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,6BAA6B,CAAC;QAC5C,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,IAAI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SAAgB,WAAW,CAAC,IAAY,EAAE,GAAW,EAAE,KAAa;IAClE,MAAM,IAAI,GAAG,mBAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IACxC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpB,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;QAAE,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { type DoctorReport } from '../doctor';
2
+ import { type Runner } from './runner';
3
+ import { devAccounts } from './steps/accounts';
4
+ import { type InitIssue } from './steps/preflight';
5
+ export interface InitEnvReport {
6
+ status: 'passed' | 'blocked' | 'missing';
7
+ dryRun: boolean;
8
+ changes: string[];
9
+ issues: InitIssue[];
10
+ }
11
+ export declare function initEnv(options: {
12
+ root: string;
13
+ dryRun: boolean;
14
+ }, runner?: Runner): Promise<InitEnvReport>;
15
+ export declare const INIT_STAGES: readonly ["env", "authgate", "database", "app-steps", "verify"];
16
+ export type InitStage = (typeof INIT_STAGES)[number];
17
+ type StageStatus = 'passed' | 'planned' | 'skipped' | 'blocked';
18
+ interface InitReport extends InitEnvReport {
19
+ stages: {
20
+ name: InitStage | 'preflight';
21
+ status: StageStatus;
22
+ }[];
23
+ doctor?: DoctorReport;
24
+ accounts?: ReturnType<typeof devAccounts>;
25
+ next?: string;
26
+ }
27
+ export declare function initApp(options: {
28
+ root: string;
29
+ dryRun: boolean;
30
+ stages: readonly InitStage[];
31
+ }, runner?: Runner): Promise<InitReport>;
32
+ export {};
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3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AAS,EAAE,CAAA;CAAE,EACxE,MAAM,GAAE,MAAY,GACnB,OAAO,CAAC,UAAU,CAAC,CAyGrB"}
@@ -0,0 +1,179 @@
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.INIT_STAGES = void 0;
7
+ exports.initEnv = initEnv;
8
+ exports.initApp = initApp;
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const doctor_1 = require("../doctor");
11
+ const env_file_1 = require("./env-file");
12
+ const runner_1 = require("./runner");
13
+ const accounts_1 = require("./steps/accounts");
14
+ const authgate_1 = require("./steps/authgate");
15
+ const env_1 = require("./steps/env");
16
+ const preflight_1 = require("./steps/preflight");
17
+ async function initEnv(options, runner = runner_1.run) {
18
+ const { report, apply } = await prepareEnv(node_path_1.default.resolve(options.root), options.dryRun, true, runner);
19
+ apply?.();
20
+ return report;
21
+ }
22
+ async function prepareEnv(root, dryRun, setupEnv, runner, reuseServices = false) {
23
+ const blocked = (issues) => ({
24
+ report: { status: 'blocked', dryRun, changes: [], issues },
25
+ });
26
+ const example = (0, env_file_1.readOptionalFile)(node_path_1.default.join(root, '.env.example'));
27
+ if (example === undefined)
28
+ return blocked([{ keys: [], message: 'Add a root .env.example before running init.' }]);
29
+ const file = node_path_1.default.join(root, '.env');
30
+ const previous = (0, env_file_1.readOptionalFile)(file);
31
+ const template = new env_file_1.EnvFile(example);
32
+ const plan = setupEnv ? (0, env_1.planEnv)(previous, template) : undefined;
33
+ if (plan?.missing.length) {
34
+ return {
35
+ report: {
36
+ status: 'missing',
37
+ dryRun,
38
+ changes: [],
39
+ issues: [
40
+ { keys: plan.missing, message: 'Set these required keys in .env and rerun init.' },
41
+ ],
42
+ },
43
+ };
44
+ }
45
+ // Inspect storage before checking ports so a running Compose project reports the secret guard.
46
+ if (plan?.generationKeys.length) {
47
+ const compose = (0, preflight_1.composeHasData)(root, new env_file_1.EnvFile(previous ?? example), runner);
48
+ if (compose !== false) {
49
+ return blocked([
50
+ {
51
+ keys: plan.generationKeys,
52
+ message: compose
53
+ ? 'The Compose project already has containers or volumes. Restore the existing values before rerunning init.'
54
+ : 'Could not verify Compose storage. Check Docker and the Compose project configuration, then rerun init.',
55
+ },
56
+ ]);
57
+ }
58
+ }
59
+ const issues = await (0, preflight_1.preflight)(root, template, runner, reuseServices);
60
+ if (issues.length)
61
+ return blocked(issues);
62
+ const report = {
63
+ status: 'passed',
64
+ dryRun,
65
+ changes: plan?.changes ?? [],
66
+ issues: [],
67
+ };
68
+ if (!plan || dryRun || (previous !== undefined && !plan.changes.length))
69
+ return { report };
70
+ return { report, apply: () => (0, env_file_1.writeEnvFile)(file, previous, plan.apply()) };
71
+ }
72
+ exports.INIT_STAGES = ['env', 'authgate', 'database', 'app-steps', 'verify'];
73
+ function appScripts(root) {
74
+ const manifest = (0, env_file_1.readOptionalFile)(node_path_1.default.join(root, 'package.json'));
75
+ return manifest
76
+ ? (JSON.parse(manifest).scripts ?? {})
77
+ : {};
78
+ }
79
+ const PRISMA_SCRIPTS = ['prisma:deploy', 'prisma:generate', 'prisma:seed'];
80
+ const AUTHGATE_SCRIPTS = ['authgate:init', 'authgate:up'];
81
+ const AG_RUN_ENV = ['AG_ENV_FILE', 'AG_PROJECT'];
82
+ const COMPOSE_RUN_ENV = ['COMPOSE_FILE', 'COMPOSE_PATH_SEPARATOR', 'COMPOSE_PROJECT_NAME'];
83
+ async function initApp(options, runner = runner_1.run) {
84
+ const { dryRun, stages } = options;
85
+ const root = node_path_1.default.resolve(options.root);
86
+ const use = (stage) => stages.includes(stage);
87
+ const scripts = appScripts(root);
88
+ const backend = node_path_1.default.join(root, 'backend');
89
+ const dbRoot = PRISMA_SCRIPTS.every((script) => scripts[script]) ? root : backend;
90
+ const dbScripts = dbRoot === root || !use('database') ? scripts : appScripts(backend);
91
+ const report = { dryRun, status: 'passed', changes: [], issues: [], stages: [] };
92
+ const record = (name, status) => report.stages.push({ name, status });
93
+ const block = (stage, issue) => {
94
+ record(stage, 'blocked');
95
+ report.status = 'blocked';
96
+ report.issues.push(issue);
97
+ return report;
98
+ };
99
+ const runStage = (command, args, cwd, label, envKeys, docker = false) => {
100
+ if (dryRun || runner(command, args, cwd, { quiet: true, envKeys, docker }).status === 0)
101
+ return undefined;
102
+ return {
103
+ keys: [],
104
+ message: `${label} failed. Run it directly in the App to diagnose the failure.`,
105
+ };
106
+ };
107
+ const env = await prepareEnv(root, dryRun, use('env'), runner, true);
108
+ if (env.report.status !== 'passed') {
109
+ record('preflight', 'blocked');
110
+ return { ...report, ...env.report };
111
+ }
112
+ record('preflight', 'passed');
113
+ if (use('authgate')) {
114
+ const keys = AUTHGATE_SCRIPTS.filter((script) => !scripts[script]);
115
+ if (keys.length)
116
+ return block('authgate', { keys, message: 'Add the required App scripts to package.json.' });
117
+ const guard = (0, authgate_1.guardAuthgateEnv)(root, runner);
118
+ if (guard)
119
+ return block('authgate', guard);
120
+ }
121
+ if (use('database')) {
122
+ const keys = PRISMA_SCRIPTS.filter((script) => !dbScripts[script]);
123
+ if (keys.length)
124
+ return block('database', {
125
+ keys,
126
+ message: 'Add the required Prisma scripts in the App root or backend.',
127
+ });
128
+ }
129
+ const completed = dryRun ? 'planned' : 'passed';
130
+ if (use('env')) {
131
+ env.apply?.();
132
+ report.changes = env.report.changes;
133
+ record('env', completed);
134
+ }
135
+ if (use('authgate')) {
136
+ for (const script of AUTHGATE_SCRIPTS) {
137
+ const issue = runStage('pnpm', ['run', script], root, `pnpm ${script}`, AG_RUN_ENV, true);
138
+ if (issue)
139
+ return block('authgate', issue);
140
+ }
141
+ record('authgate', completed);
142
+ }
143
+ if (use('database')) {
144
+ const issue = runStage('docker', ['compose', '--env-file', '.env', 'up', '-d', '--wait', '--wait-timeout', '180', 'db'], root, 'Starting the App database with Docker Compose', COMPOSE_RUN_ENV);
145
+ if (issue)
146
+ return block('database', issue);
147
+ for (const script of PRISMA_SCRIPTS) {
148
+ const failed = runStage('pnpm', ['run', script], dbRoot, `pnpm ${script}`);
149
+ if (failed)
150
+ return block('database', failed);
151
+ }
152
+ record('database', completed);
153
+ }
154
+ if (use('app-steps')) {
155
+ if (scripts['setup:app']) {
156
+ const issue = runStage('pnpm', ['run', 'setup:app'], root, 'pnpm setup:app');
157
+ if (issue)
158
+ return block('app-steps', issue);
159
+ record('app-steps', completed);
160
+ }
161
+ else
162
+ record('app-steps', 'skipped');
163
+ }
164
+ if (use('verify')) {
165
+ if (!dryRun) {
166
+ report.doctor = await (0, doctor_1.doctorAppLive)(root, runner);
167
+ if (!report.doctor.passed) {
168
+ report.status = 'blocked';
169
+ record('verify', 'blocked');
170
+ return report;
171
+ }
172
+ report.accounts = (0, accounts_1.devAccounts)(root);
173
+ report.next = 'pnpm dev';
174
+ }
175
+ record('verify', completed);
176
+ }
177
+ return report;
178
+ }
179
+ //# sourceMappingURL=index.js.map