hazo_env 0.10.4 → 0.12.1

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 (53) hide show
  1. package/CHANGE_LOG.md +79 -0
  2. package/config/hazo_env_config.ini.sample +61 -0
  3. package/dist/cli.js +329 -0
  4. package/dist/deploy/build.d.ts +91 -0
  5. package/dist/deploy/build.d.ts.map +1 -0
  6. package/dist/deploy/build.js +389 -0
  7. package/dist/deploy/clean.d.ts +63 -0
  8. package/dist/deploy/clean.d.ts.map +1 -0
  9. package/dist/deploy/clean.js +135 -0
  10. package/dist/deploy/index.d.ts +13 -0
  11. package/dist/deploy/index.d.ts.map +1 -0
  12. package/dist/deploy/index.js +22 -0
  13. package/dist/deploy/init.d.ts +20 -0
  14. package/dist/deploy/init.d.ts.map +1 -0
  15. package/dist/deploy/init.js +131 -0
  16. package/dist/deploy/peer.d.ts +18 -0
  17. package/dist/deploy/peer.d.ts.map +1 -0
  18. package/dist/deploy/peer.js +48 -0
  19. package/dist/deploy/pm2-start.d.ts +100 -0
  20. package/dist/deploy/pm2-start.d.ts.map +1 -0
  21. package/dist/deploy/pm2-start.js +228 -0
  22. package/dist/deploy/rollback.d.ts +22 -0
  23. package/dist/deploy/rollback.d.ts.map +1 -0
  24. package/dist/deploy/rollback.js +196 -0
  25. package/dist/deploy/runner.d.ts +8 -0
  26. package/dist/deploy/runner.d.ts.map +1 -0
  27. package/dist/deploy/runner.js +35 -0
  28. package/dist/deploy/state.d.ts +19 -0
  29. package/dist/deploy/state.d.ts.map +1 -0
  30. package/dist/deploy/state.js +52 -0
  31. package/dist/deploy/status.d.ts +54 -0
  32. package/dist/deploy/status.d.ts.map +1 -0
  33. package/dist/deploy/status.js +182 -0
  34. package/dist/deploy/switch.d.ts +40 -0
  35. package/dist/deploy/switch.d.ts.map +1 -0
  36. package/dist/deploy/switch.js +183 -0
  37. package/dist/deploy/types.d.ts +96 -0
  38. package/dist/deploy/types.d.ts.map +1 -0
  39. package/dist/deploy/types.js +16 -0
  40. package/dist/deploy/verify.d.ts +41 -0
  41. package/dist/deploy/verify.d.ts.map +1 -0
  42. package/dist/deploy/verify.js +214 -0
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3 -0
  46. package/dist/resolve/connect.d.ts.map +1 -1
  47. package/dist/resolve/connect.js +15 -1
  48. package/dist/resolve/deploy.d.ts +8 -0
  49. package/dist/resolve/deploy.d.ts.map +1 -0
  50. package/dist/resolve/deploy.js +140 -0
  51. package/dist/types/index.d.ts +10 -0
  52. package/dist/types/index.d.ts.map +1 -1
  53. package/package.json +12 -12
@@ -0,0 +1,140 @@
1
+ // hazo_env/src/resolve/deploy.ts — Server-only deploy config resolver
2
+ //
3
+ // Reads the [deploy] section from hazo_env_config.ini and applies defaults.
4
+ // Follows the pattern of resolve/connect.ts / resolve/files.ts: load the INI
5
+ // via HazoConfig, read one section, throw a typed HazoConfigError on missing
6
+ // required fields.
7
+ import path from 'node:path';
8
+ import { HazoConfig } from 'hazo_config/server';
9
+ import { HazoConfigError } from 'hazo_core';
10
+ const DEFAULTS = {
11
+ prod_port: 3000,
12
+ staging_port: 3001,
13
+ health_url: '/api/health',
14
+ min_disk_mb: 1024,
15
+ min_memory_mb: 512,
16
+ branch: 'main',
17
+ db_strategy: 'auto',
18
+ build_cmd: 'npm run build',
19
+ install_cmd: 'npm ci',
20
+ pre_build_cmd: 'rm -rf .next',
21
+ migrate_cmd: '',
22
+ };
23
+ function findConfigFile() {
24
+ return path.resolve(process.cwd(), 'config', 'hazo_env_config.ini');
25
+ }
26
+ function loadConfig() {
27
+ const filePath = findConfigFile();
28
+ try {
29
+ return new HazoConfig({ filePath });
30
+ }
31
+ catch {
32
+ throw new HazoConfigError({
33
+ code: 'HAZO_ENV_CONFIG_FILE_MISSING',
34
+ pkg: 'hazo_env',
35
+ message: `Config file not found: ${filePath}. Create config/hazo_env_config.ini.`,
36
+ });
37
+ }
38
+ }
39
+ /**
40
+ * Parse an INI integer field, applying `fallback` only when the field is
41
+ * ABSENT. A field that IS present but not a valid integer (e.g. `prod_port
42
+ * = abc`) throws a clear `HazoConfigError` instead of silently falling back
43
+ * to the default — matching `db_strategy`'s existing validation below
44
+ * rather than masking a typo as "3000, no error" (Fix 8).
45
+ *
46
+ * Uses `Number(...)` rather than `parseInt`, which deliberately rejects
47
+ * trailing garbage (`parseInt('3000abc', 10)` === 3000; `Number('3000abc')`
48
+ * is NaN) so a value that's only partially numeric is still caught.
49
+ */
50
+ function parseIntField(key, value, fallback) {
51
+ if (value === undefined)
52
+ return fallback;
53
+ const trimmed = value.trim();
54
+ const parsed = Number(trimmed);
55
+ if (trimmed === '' || !Number.isInteger(parsed)) {
56
+ throw new HazoConfigError({
57
+ code: 'HAZO_ENV_CONFIG_INVALID_DEPLOY_INT_FIELD',
58
+ pkg: 'hazo_env',
59
+ message: `[deploy] ${key} "${value}" is invalid. Expected an integer.`,
60
+ });
61
+ }
62
+ return parsed;
63
+ }
64
+ /**
65
+ * Collects `post_switch_cmd`, `post_switch_cmd_2`, `post_switch_cmd_3`, ...
66
+ * from the [deploy] section, in numeric order. Numbering starts implicitly
67
+ * at the unsuffixed key (`post_switch_cmd`) and continues with `_2`, `_3`, etc.
68
+ */
69
+ function collectPostSwitchCmds(section) {
70
+ const cmds = [];
71
+ const first = section['post_switch_cmd'];
72
+ if (typeof first === 'string' && first.trim())
73
+ cmds.push(first.trim());
74
+ let n = 2;
75
+ for (;;) {
76
+ const value = section[`post_switch_cmd_${n}`];
77
+ if (typeof value !== 'string' || !value.trim())
78
+ break;
79
+ cmds.push(value.trim());
80
+ n += 1;
81
+ }
82
+ return cmds;
83
+ }
84
+ const VALID_DB_STRATEGIES = new Set(['auto', 'copy', 'shared']);
85
+ /**
86
+ * Resolve the `[deploy]` section of hazo_env_config.ini into a typed
87
+ * DeployConfig. `app_name` and `dir_suffix` are the only fields without a
88
+ * default — every other field falls back to a sane value when omitted.
89
+ */
90
+ export function resolveDeployConfig() {
91
+ const config = loadConfig();
92
+ const section = config.getSection('deploy');
93
+ if (!section) {
94
+ throw new HazoConfigError({
95
+ code: 'HAZO_ENV_CONFIG_MISSING_DEPLOY_SECTION',
96
+ pkg: 'hazo_env',
97
+ message: 'No [deploy] section found in hazo_env_config.ini.',
98
+ });
99
+ }
100
+ const app_name = section['app_name'];
101
+ if (!app_name) {
102
+ throw new HazoConfigError({
103
+ code: 'HAZO_ENV_CONFIG_MISSING_DEPLOY_APP_NAME',
104
+ pkg: 'hazo_env',
105
+ message: '[deploy] section is missing required field "app_name".',
106
+ });
107
+ }
108
+ const dir_suffix = section['dir_suffix'];
109
+ if (!dir_suffix) {
110
+ throw new HazoConfigError({
111
+ code: 'HAZO_ENV_CONFIG_MISSING_DEPLOY_DIR_SUFFIX',
112
+ pkg: 'hazo_env',
113
+ message: '[deploy] section is missing required field "dir_suffix".',
114
+ });
115
+ }
116
+ const db_strategy_raw = section['db_strategy'] ?? DEFAULTS.db_strategy;
117
+ if (!VALID_DB_STRATEGIES.has(db_strategy_raw)) {
118
+ throw new HazoConfigError({
119
+ code: 'HAZO_ENV_CONFIG_INVALID_DB_STRATEGY',
120
+ pkg: 'hazo_env',
121
+ message: `[deploy] db_strategy "${db_strategy_raw}" is invalid. Expected "auto", "copy", or "shared".`,
122
+ });
123
+ }
124
+ return {
125
+ app_name,
126
+ dir_suffix,
127
+ prod_port: parseIntField('prod_port', section['prod_port'], DEFAULTS.prod_port),
128
+ staging_port: parseIntField('staging_port', section['staging_port'], DEFAULTS.staging_port),
129
+ health_url: section['health_url'] ?? DEFAULTS.health_url,
130
+ min_disk_mb: parseIntField('min_disk_mb', section['min_disk_mb'], DEFAULTS.min_disk_mb),
131
+ min_memory_mb: parseIntField('min_memory_mb', section['min_memory_mb'], DEFAULTS.min_memory_mb),
132
+ branch: section['branch'] ?? DEFAULTS.branch,
133
+ db_strategy: db_strategy_raw,
134
+ build_cmd: section['build_cmd'] ?? DEFAULTS.build_cmd,
135
+ install_cmd: section['install_cmd'] ?? DEFAULTS.install_cmd,
136
+ pre_build_cmd: section['pre_build_cmd'] ?? DEFAULTS.pre_build_cmd,
137
+ migrate_cmd: section['migrate_cmd'] ?? DEFAULTS.migrate_cmd,
138
+ post_switch_cmds: collectPostSwitchCmds(section),
139
+ };
140
+ }
@@ -13,6 +13,16 @@ export interface DbEnvConfig {
13
13
  type: 'sqlite' | 'postgrest';
14
14
  sqlite?: {
15
15
  database_path: string;
16
+ /** Which SQLite engine hazo_connect should use. Defaults to 'sql.js' when
17
+ * omitted — matches hazo_connect's own default, see its HazoConnectConfig.
18
+ * 'sql.js' keeps one in-memory copy per process and overwrites the whole
19
+ * file on every write, which corrupts the on-disk file when more than
20
+ * one process (or, in Next.js dev, more than one webpack bundle —
21
+ * middleware.ts compiles separately from route handlers) holds its own
22
+ * copy open against the same path. 'better-sqlite3' opens the file
23
+ * natively with real OS-level WAL locking and is the one that's safe
24
+ * under concurrent access. */
25
+ driver?: 'sql.js' | 'better-sqlite3';
16
26
  };
17
27
  postgrest?: {
18
28
  base_url: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,sDAAsD;AACtD,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnE,mCAAmC;AACnC,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,CAAC;AAE5E,iFAAiF;AACjF,MAAM,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC;AAElC,0EAA0E;AAC1E,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAErD,2CAA2C;AAC3C,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEtD,yEAAyE;AACzE,MAAM,WAAW,WAAW;IA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AAErD,2CAA2C;AAC3C,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEtD,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC7B,MAAM,CAAC,EAAE;QACP,aAAa,EAAE,MAAM,CAAC;QACtB;;;;;;;;uCAQ+B;QAC/B,MAAM,CAAC,EAAE,QAAQ,GAAG,gBAAgB,CAAC;KACtC,CAAC;IACF,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACnD;AAED,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;KAC9B,CAAC;CACH;AAED,8BAA8B;AAC9B,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,uCAAuC;AACvC,MAAM,WAAW,qBAAqB;IACpC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hazo_env",
3
- "version": "0.10.4",
3
+ "version": "0.12.1",
4
4
  "description": "Canonical environment resolver — typed env names, per-env DB/file/secret config, doctor and CLI for hazo apps",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,14 +40,14 @@
40
40
  "picocolors": "^1.1.1"
41
41
  },
42
42
  "peerDependencies": {
43
- "hazo_core": "^2.4.1",
44
- "hazo_config": "^2.6.0",
45
- "hazo_connect": "^4.3.3",
46
- "hazo_files": "^3.4.0",
47
- "hazo_secure": "^1.8.1",
43
+ "hazo_core": "^2.5.0",
44
+ "hazo_config": "^2.7.2",
45
+ "hazo_connect": "^4.3.5",
46
+ "hazo_files": "^3.7.0",
47
+ "hazo_secure": "^1.9.1",
48
48
  "hazo_audit": "^2.3.0",
49
- "hazo_pdf": "^2.4.0",
50
- "hazo_i18n": "^0.9.0",
49
+ "hazo_pdf": "^2.5.0",
50
+ "hazo_i18n": "^0.17.0",
51
51
  "react": "^18.0.0 || ^19.0.0",
52
52
  "react-dom": "^18.0.0 || ^19.0.0",
53
53
  "next": "^14.0.0 || ^16.0.0"
@@ -90,10 +90,10 @@
90
90
  "@types/node": "^22.10.0",
91
91
  "@types/react": "^19.0.0",
92
92
  "@types/react-dom": "^19.0.0",
93
- "hazo_core": "^2.4.1",
94
- "hazo_config": "^2.6.0",
95
- "hazo_connect": "^4.3.3",
96
- "hazo_files": "^3.4.0",
93
+ "hazo_core": "^2.5.0",
94
+ "hazo_config": "^2.7.2",
95
+ "hazo_connect": "^4.3.5",
96
+ "hazo_files": "^3.7.0",
97
97
  "next": "^16.0.10",
98
98
  "react": "^19.0.0",
99
99
  "react-dom": "^19.0.0",