@memberjunction/installer 5.41.0 → 5.43.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 (52) hide show
  1. package/dist/InstallerEngine.d.ts.map +1 -1
  2. package/dist/InstallerEngine.js +6 -1
  3. package/dist/InstallerEngine.js.map +1 -1
  4. package/dist/adapters/FileSystemAdapter.d.ts +9 -0
  5. package/dist/adapters/FileSystemAdapter.d.ts.map +1 -1
  6. package/dist/adapters/FileSystemAdapter.js +12 -0
  7. package/dist/adapters/FileSystemAdapter.js.map +1 -1
  8. package/dist/diagnostics/ClaudePackDoctor.d.ts +65 -0
  9. package/dist/diagnostics/ClaudePackDoctor.d.ts.map +1 -0
  10. package/dist/diagnostics/ClaudePackDoctor.js +310 -0
  11. package/dist/diagnostics/ClaudePackDoctor.js.map +1 -0
  12. package/dist/distribution/DistributionAssembler.d.ts +31 -1
  13. package/dist/distribution/DistributionAssembler.d.ts.map +1 -1
  14. package/dist/distribution/DistributionAssembler.js +59 -7
  15. package/dist/distribution/DistributionAssembler.js.map +1 -1
  16. package/dist/distribution/createBundle.d.ts +7 -0
  17. package/dist/distribution/createBundle.d.ts.map +1 -1
  18. package/dist/distribution/createBundle.js +5 -3
  19. package/dist/distribution/createBundle.js.map +1 -1
  20. package/dist/models/InstallConfig.d.ts +12 -6
  21. package/dist/models/InstallConfig.d.ts.map +1 -1
  22. package/dist/models/InstallConfig.js +188 -16
  23. package/dist/models/InstallConfig.js.map +1 -1
  24. package/dist/models/InstallPlan.d.ts +14 -1
  25. package/dist/models/InstallPlan.d.ts.map +1 -1
  26. package/dist/models/InstallPlan.js +3 -1
  27. package/dist/models/InstallPlan.js.map +1 -1
  28. package/dist/phases/ConfigurePhase.d.ts +62 -0
  29. package/dist/phases/ConfigurePhase.d.ts.map +1 -1
  30. package/dist/phases/ConfigurePhase.js +275 -22
  31. package/dist/phases/ConfigurePhase.js.map +1 -1
  32. package/dist/phases/DatabaseProvisionPhase.d.ts +44 -0
  33. package/dist/phases/DatabaseProvisionPhase.d.ts.map +1 -1
  34. package/dist/phases/DatabaseProvisionPhase.js +142 -55
  35. package/dist/phases/DatabaseProvisionPhase.js.map +1 -1
  36. package/dist/phases/DependencyPhase.d.ts +20 -0
  37. package/dist/phases/DependencyPhase.d.ts.map +1 -1
  38. package/dist/phases/DependencyPhase.js +25 -2
  39. package/dist/phases/DependencyPhase.js.map +1 -1
  40. package/dist/phases/MigratePhase.d.ts +8 -2
  41. package/dist/phases/MigratePhase.d.ts.map +1 -1
  42. package/dist/phases/MigratePhase.js +32 -5
  43. package/dist/phases/MigratePhase.js.map +1 -1
  44. package/dist/phases/PreflightPhase.d.ts +29 -0
  45. package/dist/phases/PreflightPhase.d.ts.map +1 -1
  46. package/dist/phases/PreflightPhase.js +70 -4
  47. package/dist/phases/PreflightPhase.js.map +1 -1
  48. package/dist/phases/ScaffoldPhase.d.ts +23 -0
  49. package/dist/phases/ScaffoldPhase.d.ts.map +1 -1
  50. package/dist/phases/ScaffoldPhase.js +69 -2
  51. package/dist/phases/ScaffoldPhase.js.map +1 -1
  52. package/package.json +1 -1
@@ -71,6 +71,13 @@ export interface CreatePlanInput {
71
71
  * steps by quick-checking manifests before rebuilding (`--fast`).
72
72
  */
73
73
  Fast?: boolean;
74
+ /**
75
+ * Exclude the Claude Code pack from the install (`--no-claude-pack`).
76
+ * By default the pack ships alongside the distribution so end users get the
77
+ * full Claude-Code-aware MJ experience after `mj install` finishes — honoring
78
+ * Goal #1 of `plans/claude-install-pack.md`. Pass `true` to opt out.
79
+ */
80
+ NoClaudePack?: boolean;
74
81
  }
75
82
  /**
76
83
  * Runtime options passed to {@link InstallerEngine.Run}.
@@ -193,6 +200,11 @@ export declare class InstallPlan {
193
200
  Phases: PhaseInfo[];
194
201
  /** Timestamp when this plan was created. */
195
202
  CreatedAt: Date;
203
+ /**
204
+ * Whether to skip the Claude Code pack during scaffolding. Defaults to `false`
205
+ * — the pack ships alongside the distribution. `--no-claude-pack` flips this on.
206
+ */
207
+ NoClaudePack: boolean;
196
208
  /**
197
209
  * Create a new install plan.
198
210
  *
@@ -200,8 +212,9 @@ export declare class InstallPlan {
200
212
  * @param dir - Target install directory.
201
213
  * @param config - Merged configuration values.
202
214
  * @param skipPhases - Set of phase IDs to skip during execution.
215
+ * @param noClaudePack - When `true`, the Claude pack is excluded from the scaffold.
203
216
  */
204
- constructor(tag: string, dir: string, config: PartialInstallConfig, skipPhases?: Set<PhaseId>);
217
+ constructor(tag: string, dir: string, config: PartialInstallConfig, skipPhases?: Set<PhaseId>, noClaudePack?: boolean);
205
218
  /**
206
219
  * Generate a human-readable summary of the install plan.
207
220
  *
@@ -1 +1 @@
1
- {"version":3,"file":"InstallPlan.d.ts","sourceRoot":"","sources":["../../src/models/InstallPlan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,4DAA4D;IAC5D,EAAE,EAAE,OAAO,CAAC;IACZ,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,eAAe;IAC9B,kFAAkF;IAClF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,GAAG,EAAE,MAAM,CAAC;IACZ,0EAA0E;IAC1E,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,0DAA0D;IAC1D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iDAAiD;IACjD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,IAAI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E,MAAM,EACX,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,oBAAoB,EAC5B,UAAU,GAAE,GAAG,CAAC,OAAO,CAAa,EACpC,YAAY,UAAQ;IA2BtB;;;;;;;OAOG;IACH,SAAS,IAAI,MAAM;CAkBpB"}
@@ -66,11 +66,13 @@ export class InstallPlan {
66
66
  * @param dir - Target install directory.
67
67
  * @param config - Merged configuration values.
68
68
  * @param skipPhases - Set of phase IDs to skip during execution.
69
+ * @param noClaudePack - When `true`, the Claude pack is excluded from the scaffold.
69
70
  */
70
- constructor(tag, dir, config, skipPhases = new Set()) {
71
+ constructor(tag, dir, config, skipPhases = new Set(), noClaudePack = false) {
71
72
  this.Tag = tag;
72
73
  this.Dir = dir;
73
74
  this.Config = config;
75
+ this.NoClaudePack = noClaudePack;
74
76
  this.CreatedAt = new Date();
75
77
  const allPhases = [
76
78
  'preflight',
@@ -1 +1 @@
1
- {"version":3,"file":"InstallPlan.js","sourceRoot":"","sources":["../../src/models/InstallPlan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAmJH;;;GAGG;AACH,MAAM,iBAAiB,GAA4B;IACjD,SAAS,EAAE,kDAAkD;IAC7D,QAAQ,EAAE,8BAA8B;IACxC,QAAQ,EAAE,wCAAwC;IAClD,OAAO,EAAE,yBAAyB;IAClC,SAAS,EAAE,8BAA8B;IACzC,QAAQ,EAAE,qCAAqC;IAC/C,YAAY,EAAE,gCAAgC;IAC9C,OAAO,EAAE,oCAAoC;IAC7C,UAAU,EAAE,oCAAoC;CACjD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,WAAW;IAgBtB;;;;;;;OAOG;IACH,YAAY,GAAW,EAAE,GAAW,EAAE,MAA4B,EAAE,aAA2B,IAAI,GAAG,EAAE;QACtG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC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CAAC,SAAS,CAAC,WAAW,EAAE,EAAE;YAC9C,EAAE;YACF,WAAW;SACZ,CAAC;QAEF,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;YAClD,KAAK,CAAC,IAAI,CAAC,OAAO,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QAC1E,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -98,6 +98,21 @@ export declare class ConfigurePhase {
98
98
  * @returns A fully populated config object.
99
99
  */
100
100
  private resolveConfig;
101
+ /**
102
+ * Ensures the install directory has a `.gitignore` that ignores environment
103
+ * secret files (`.env`, `.env.*`) while keeping the committed `.env.example`.
104
+ *
105
+ * Idempotent: creates the file when absent, and appends only the missing entries
106
+ * when one already exists (never reorders or rewrites the user's existing lines).
107
+ *
108
+ * Fixes the original scaffolding gap where a generated project shipped without a
109
+ * `.gitignore`, so the real `.env` written by this phase could be committed to a
110
+ * public repo.
111
+ *
112
+ * @param dir - Install directory root.
113
+ * @returns The `.gitignore` path and whether it was created/modified.
114
+ */
115
+ private ensureGitignoreProtectsEnv;
101
116
  /**
102
117
  * Write a fresh `.env` file with all config values including the encryption key.
103
118
  *
@@ -159,6 +174,53 @@ export declare class ConfigurePhase {
159
174
  * @returns The content with the variable guaranteed to be present.
160
175
  */
161
176
  private ensureEnvVar;
177
+ /**
178
+ * Patch `apps/MJExplorer/package.json` (or `packages/MJExplorer/package.json`)
179
+ * to inject `--port <ExplorerPort>` into the `start` script when ExplorerPort
180
+ * differs from Angular's default (4200). Without this patch, `ng serve`
181
+ * always binds to 4200 regardless of what the user configured.
182
+ *
183
+ * Returns the path of the patched file when a write occurred, otherwise null.
184
+ */
185
+ private patchExplorerNgServePort;
186
+ /**
187
+ * Detect the indentation a JSON file uses by inspecting the first
188
+ * indented line. Returns the raw indent string (e.g., `" "`, `" "`,
189
+ * `"\t"`). Falls back to two spaces when no indentation can be detected.
190
+ */
191
+ private detectJsonIndent;
192
+ /** Return the first path in the list that exists on disk, or null. */
193
+ private firstExisting;
194
+ /**
195
+ * Keys that should be kept in sync between the root `.env` and
196
+ * `apps/MJAPI/.env` (or `packages/MJAPI/.env`). The user typically edits
197
+ * the root file when adjusting database credentials post-install; without
198
+ * propagating those edits to the MJAPI-local copy, MJAPI silently keeps
199
+ * connecting to the original (often wrong) target.
200
+ *
201
+ * Keep this list focused on cross-file invariants — anything truly
202
+ * MJAPI-specific (e.g., GRAPHQL_PORT overrides, MJAPI-only auth keys)
203
+ * should stay where it is.
204
+ */
205
+ private static readonly ROOT_TO_MJAPI_SYNC_KEYS;
206
+ /**
207
+ * Update the MJAPI .env's shared keys (database credentials, schema) to
208
+ * match the root .env. Returns the patched MJAPI content. Keys not present
209
+ * in the root are left untouched; keys present in root but not in MJAPI
210
+ * are appended. Keys MJAPI-only (e.g., ASK_SKIP_API_URL) are preserved.
211
+ */
212
+ private syncEnvFieldsFromRoot;
213
+ /**
214
+ * Extract a single env var's raw value from dotenv-style content.
215
+ * Returns the value with surrounding quotes stripped, or undefined if absent.
216
+ */
217
+ private extractEnvValue;
218
+ /**
219
+ * Replace an existing `NAME=...` line with the new value, or append it
220
+ * if absent. Preserves the rest of the file as-is. Uses single-quoted
221
+ * form to match the rest of the .env file's convention.
222
+ */
223
+ private replaceOrAppendEnvVar;
162
224
  /**
163
225
  * Create or preserve Explorer environment files (`environment.ts`,
164
226
  * `environment.development.ts`).
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigurePhase.d.ts","sourceRoot":"","sources":["../../src/phases/ConfigurePhase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,KAAK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A0B;IAkCxC;;;;;OAKG;YACW,YAAY;IAyD1B;;;;;;OAMG;YACW,gBAAgB;IAwC9B;;;;;;;;;OASG;IACH,OAAO,CAAC,iBAAiB;IA0BzB;;;;;;;;;OASG;IACH,OAAO,CAAC,yBAAyB;IA4BjC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,gBAAgB;IAiBxB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,YAAY;IAUpB;;;;;;;OAOG;YACW,wBAAwB;IA8CtC;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAKxB,sEAAsE;YACxD,aAAa;IAO3B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAc5C;IAEH;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAU7B;;;OAGG;IACH,OAAO,CAAC,eAAe;IAWvB;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAc7B;;;;;;;;;;;;OAYG;YACW,0BAA0B;IAqFxC;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAqC/B;;;;;OAKG;YACW,mBAAmB;IA4DjC;;;OAGG;IACH,OAAO,CAAC,YAAY;IAkBpB;;;;;OAKG;YACW,4BAA4B;IAoF1C;;;OAGG;IACH,OAAO,CAAC,WAAW;IAqBnB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAuBrB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAwBpB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,WAAW;IASnB;;OAEG;YACW,mBAAmB;IAajC;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;CAGlC"}
@@ -91,7 +91,12 @@ export class ConfigurePhase {
91
91
  }
92
92
  else if (await this.fileSystem.FileExists(mjapiEnvPath)) {
93
93
  const existingMjapiEnv = await this.fileSystem.ReadText(mjapiEnvPath);
94
- const patchedMjapiEnv = this.ensureEnvVar(existingMjapiEnv, 'MJ_BASE_ENCRYPTION_KEY', config.BaseEncryptionKey ?? '');
94
+ // Sync DB/auth fields from root to MJAPI — root is the canonical source
95
+ // of database settings (anyone editing them edits root). Without this,
96
+ // MJAPI keeps the original values from initial install and silently
97
+ // fails to connect when the user updates root .env.
98
+ let patchedMjapiEnv = this.syncEnvFieldsFromRoot(existingMjapiEnv, patchedRootEnv);
99
+ patchedMjapiEnv = this.ensureEnvVar(patchedMjapiEnv, 'MJ_BASE_ENCRYPTION_KEY', config.BaseEncryptionKey ?? '');
95
100
  if (patchedMjapiEnv !== existingMjapiEnv) {
96
101
  await this.fileSystem.WriteText(mjapiEnvPath, patchedMjapiEnv);
97
102
  filesWritten.push(mjapiEnvPath);
@@ -110,6 +115,16 @@ export class ConfigurePhase {
110
115
  filesWritten.push(mjapiEnvPath);
111
116
  }
112
117
  }
118
+ // Step 2.5: .gitignore — guarantee the secrets just written (.env, .env.*) are
119
+ // git-ignored. Scaffolded MJ projects historically shipped without a .gitignore,
120
+ // so a `git init && git add .` committed real .env credentials into public repos.
121
+ const gitignoreResult = await this.ensureGitignoreProtectsEnv(context.Dir);
122
+ if (gitignoreResult.Written) {
123
+ filesWritten.push(gitignoreResult.Path);
124
+ }
125
+ else {
126
+ filesPreserved.push(gitignoreResult.Path);
127
+ }
113
128
  // Step 3: mj.config.cjs — preserve existing, create if missing, patch encryption + user
114
129
  const configCjsPath = path.join(context.Dir, 'mj.config.cjs');
115
130
  if (!overwrite && await this.fileSystem.FileExists(configCjsPath)) {
@@ -148,6 +163,14 @@ export class ConfigurePhase {
148
163
  const envFilesResult = await this.updateExplorerEnvironments(context.Dir, config, emitter, overwrite);
149
164
  filesWritten.push(...envFilesResult.Written);
150
165
  filesPreserved.push(...envFilesResult.Preserved);
166
+ // Step 4b: Explorer ng serve port — patch the start script if ExplorerPort
167
+ // differs from Angular's default (4200). Without this, `ng serve` ignores
168
+ // the user's configured port and the dev server collides with anything
169
+ // else on 4200.
170
+ const explorerPortPatched = await this.patchExplorerNgServePort(context.Dir, config);
171
+ if (explorerPortPatched) {
172
+ filesWritten.push(explorerPortPatched);
173
+ }
151
174
  // Auth-not-configured warning — more specific than the generic defaults warning
152
175
  if (config.AuthProvider === 'none') {
153
176
  emitter.Emit('warn', {
@@ -265,6 +288,49 @@ export class ConfigurePhase {
265
288
  // ---------------------------------------------------------------------------
266
289
  // File generation
267
290
  // ---------------------------------------------------------------------------
291
+ /**
292
+ * Ensures the install directory has a `.gitignore` that ignores environment
293
+ * secret files (`.env`, `.env.*`) while keeping the committed `.env.example`.
294
+ *
295
+ * Idempotent: creates the file when absent, and appends only the missing entries
296
+ * when one already exists (never reorders or rewrites the user's existing lines).
297
+ *
298
+ * Fixes the original scaffolding gap where a generated project shipped without a
299
+ * `.gitignore`, so the real `.env` written by this phase could be committed to a
300
+ * public repo.
301
+ *
302
+ * @param dir - Install directory root.
303
+ * @returns The `.gitignore` path and whether it was created/modified.
304
+ */
305
+ async ensureGitignoreProtectsEnv(dir) {
306
+ const gitignorePath = path.join(dir, '.gitignore');
307
+ // `.env.*` also matches `.env.example`, so re-include it with a negation that
308
+ // must follow the broad pattern to take effect.
309
+ const requiredEntries = ['.env', '.env.*', '!.env.example'];
310
+ if (await this.fileSystem.FileExists(gitignorePath)) {
311
+ const existing = await this.fileSystem.ReadText(gitignorePath);
312
+ const lines = existing.split(/\r?\n/).map((l) => l.trim());
313
+ const missing = requiredEntries.filter((entry) => !lines.includes(entry));
314
+ if (missing.length === 0) {
315
+ return { Path: gitignorePath, Written: false };
316
+ }
317
+ const appended = existing.replace(/\s*$/, '') +
318
+ '\n\n# Environment secrets (added by MJ installer)\n' +
319
+ missing.join('\n') +
320
+ '\n';
321
+ await this.fileSystem.WriteText(gitignorePath, appended);
322
+ return { Path: gitignorePath, Written: true };
323
+ }
324
+ const body = '# Environment secrets — never commit real credentials\n' +
325
+ '.env\n' +
326
+ '.env.*\n' +
327
+ '!.env.example\n\n' +
328
+ '# Dependencies & build output\n' +
329
+ 'node_modules/\n' +
330
+ 'dist/\n';
331
+ await this.fileSystem.WriteText(gitignorePath, body);
332
+ return { Path: gitignorePath, Written: true };
333
+ }
268
334
  /**
269
335
  * Write a fresh `.env` file with all config values including the encryption key.
270
336
  *
@@ -273,6 +339,14 @@ export class ConfigurePhase {
273
339
  */
274
340
  async writeEnvFile(envPath, config) {
275
341
  const trustCert = config.DatabaseTrustCert ? 'DB_TRUST_SERVER_CERTIFICATE=1' : '';
342
+ // Accept both internal-shape (`ClientID`, `TenantID`, ...) and user-facing
343
+ // shape (`CLIENT_ID`, `TENANT_ID`, ...) keys in AuthProviderValues — see
344
+ // generateEnvironmentFile() for rationale.
345
+ const authValues = config.AuthProviderValues ?? {};
346
+ const clientId = authValues.CLIENT_ID ?? authValues.ClientID ?? '';
347
+ const tenantId = authValues.TENANT_ID ?? authValues.TenantID ?? '';
348
+ const clientSecret = authValues.AUTH0_CLIENT_SECRET ?? authValues.ClientSecret ?? '';
349
+ const auth0Domain = authValues.AUTH0_DOMAIN ?? authValues.Domain ?? '';
276
350
  const content = `#Database Setup
277
351
  DB_HOST='${config.DatabaseHost}'
278
352
  DB_PORT=${config.DatabasePort}
@@ -303,13 +377,13 @@ UPDATE_USER_CACHE_WHEN_NOT_FOUND=1
303
377
  UPDATE_USER_CACHE_WHEN_NOT_FOUND_DELAY=5000
304
378
 
305
379
  # AUTHENTICATION SECTION
306
- WEB_CLIENT_ID=${config.AuthProviderValues?.ClientID ?? ''}
307
- TENANT_ID=${config.AuthProviderValues?.TenantID ?? ''}
380
+ WEB_CLIENT_ID=${clientId}
381
+ TENANT_ID=${tenantId}
308
382
 
309
383
  # Auth0 Section
310
- AUTH0_CLIENT_ID=${config.AuthProviderValues?.ClientID ?? ''}
311
- AUTH0_CLIENT_SECRET=${config.AuthProviderValues?.ClientSecret ?? ''}
312
- AUTH0_DOMAIN=${config.AuthProviderValues?.Domain ?? ''}
384
+ AUTH0_CLIENT_ID=${clientId}
385
+ AUTH0_CLIENT_SECRET=${clientSecret}
386
+ AUTH0_DOMAIN=${auth0Domain}
313
387
 
314
388
  # Skip API
315
389
  ASK_SKIP_API_URL='http://localhost:8000'
@@ -325,12 +399,17 @@ ASK_SKIP_ORGANIZATION_ID=1
325
399
  * @param config - Fully resolved config.
326
400
  */
327
401
  async writeMjConfigCjs(configPath, config, resolvedVersion) {
402
+ // codegen-lib's newUserSetupSchema requires PascalCase keys
403
+ // (UserName/FirstName/LastName/Email). Writing camelCase here causes the
404
+ // entire mj.config.cjs to fail schema validation in codegen-lib, leaving
405
+ // configInfo as {} — which then surfaces as "config.server is required"
406
+ // when codegen tries to build the SQL connection.
328
407
  const newUserSection = config.CreateNewUser
329
408
  ? ` newUserSetup: {
330
- userName: '${config.CreateNewUser.Username}',
331
- firstName: '${config.CreateNewUser.FirstName}',
332
- lastName: '${config.CreateNewUser.LastName}',
333
- email: '${config.CreateNewUser.Email}',
409
+ UserName: '${config.CreateNewUser.Username}',
410
+ FirstName: '${config.CreateNewUser.FirstName}',
411
+ LastName: '${config.CreateNewUser.LastName}',
412
+ Email: '${config.CreateNewUser.Email}',
334
413
  },
335
414
  `
336
415
  : '';
@@ -366,10 +445,10 @@ ${versionSection}${newUserSection} output: [],
366
445
  */
367
446
  patchNewUserSetup(content, newUser) {
368
447
  const newUserBlock = `newUserSetup: {
369
- userName: '${newUser.Username}',
370
- firstName: '${newUser.FirstName}',
371
- lastName: '${newUser.LastName}',
372
- email: '${newUser.Email}',
448
+ UserName: '${newUser.Username}',
449
+ FirstName: '${newUser.FirstName}',
450
+ LastName: '${newUser.LastName}',
451
+ Email: '${newUser.Email}',
373
452
  }`;
374
453
  // Try to replace existing newUserSetup block
375
454
  const existingPattern = /newUserSetup:\s*\{[^}]*\}/;
@@ -460,6 +539,147 @@ ${versionSection}${newUserSection} output: [],
460
539
  const suffix = content.endsWith('\n') ? '' : '\n';
461
540
  return `${content}${suffix}${name}='${value}'\n`;
462
541
  }
542
+ /**
543
+ * Patch `apps/MJExplorer/package.json` (or `packages/MJExplorer/package.json`)
544
+ * to inject `--port <ExplorerPort>` into the `start` script when ExplorerPort
545
+ * differs from Angular's default (4200). Without this patch, `ng serve`
546
+ * always binds to 4200 regardless of what the user configured.
547
+ *
548
+ * Returns the path of the patched file when a write occurred, otherwise null.
549
+ */
550
+ async patchExplorerNgServePort(dir, config) {
551
+ const explorerPort = config.ExplorerPort;
552
+ if (explorerPort === undefined || explorerPort === 4200)
553
+ return null;
554
+ const candidates = [
555
+ path.join(dir, 'apps', 'MJExplorer', 'package.json'),
556
+ path.join(dir, 'packages', 'MJExplorer', 'package.json'),
557
+ ];
558
+ const pkgPath = await this.firstExisting(candidates);
559
+ if (!pkgPath)
560
+ return null;
561
+ const raw = await this.fileSystem.ReadText(pkgPath);
562
+ const pkg = JSON.parse(raw);
563
+ if (!pkg.scripts)
564
+ return null;
565
+ const portArg = `--port ${explorerPort}`;
566
+ // Match `ng serve` as a whole-word token so `echo "ng serve"` or
567
+ // `do-not-ng-serve` don't get falsely patched. The `\b` on the right
568
+ // accepts space, end-of-string, or any non-word character.
569
+ const ngServeRe = /\bng\s+serve\b/;
570
+ // Match `--port <token>` (numeric OR non-numeric) so a script that
571
+ // already declares any --port (even a typo'd one) is left alone — the
572
+ // user's explicit choice wins over our override.
573
+ const explicitPortRe = /--port[\s=]+\S+/;
574
+ let touched = false;
575
+ for (const scriptName of Object.keys(pkg.scripts)) {
576
+ const script = pkg.scripts[scriptName];
577
+ if (typeof script !== 'string')
578
+ continue;
579
+ if (!ngServeRe.test(script))
580
+ continue;
581
+ if (explicitPortRe.test(script))
582
+ continue;
583
+ pkg.scripts[scriptName] = `${script} ${portArg}`;
584
+ touched = true;
585
+ }
586
+ if (!touched)
587
+ return null;
588
+ // Preserve the original file's indentation (2-space, 4-space, or tab).
589
+ // Without this, repeated writes would normalize the file's whitespace.
590
+ const indent = this.detectJsonIndent(raw);
591
+ const trailingNewline = raw.endsWith('\n') ? '\n' : '';
592
+ await this.fileSystem.WriteText(pkgPath, JSON.stringify(pkg, null, indent) + trailingNewline);
593
+ return pkgPath;
594
+ }
595
+ /**
596
+ * Detect the indentation a JSON file uses by inspecting the first
597
+ * indented line. Returns the raw indent string (e.g., `" "`, `" "`,
598
+ * `"\t"`). Falls back to two spaces when no indentation can be detected.
599
+ */
600
+ detectJsonIndent(content) {
601
+ const match = content.match(/\n([ \t]+)/);
602
+ return match ? match[1] : ' ';
603
+ }
604
+ /** Return the first path in the list that exists on disk, or null. */
605
+ async firstExisting(candidates) {
606
+ for (const candidate of candidates) {
607
+ if (await this.fileSystem.FileExists(candidate))
608
+ return candidate;
609
+ }
610
+ return null;
611
+ }
612
+ /**
613
+ * Keys that should be kept in sync between the root `.env` and
614
+ * `apps/MJAPI/.env` (or `packages/MJAPI/.env`). The user typically edits
615
+ * the root file when adjusting database credentials post-install; without
616
+ * propagating those edits to the MJAPI-local copy, MJAPI silently keeps
617
+ * connecting to the original (often wrong) target.
618
+ *
619
+ * Keep this list focused on cross-file invariants — anything truly
620
+ * MJAPI-specific (e.g., GRAPHQL_PORT overrides, MJAPI-only auth keys)
621
+ * should stay where it is.
622
+ */
623
+ static { this.ROOT_TO_MJAPI_SYNC_KEYS = Object.freeze([
624
+ // SQL Server / generic env var names
625
+ 'DB_HOST', 'DB_PORT', 'DB_DATABASE',
626
+ 'DB_USERNAME', 'DB_PASSWORD',
627
+ 'CODEGEN_DB_USERNAME', 'CODEGEN_DB_PASSWORD',
628
+ 'DB_TRUST_SERVER_CERTIFICATE',
629
+ 'MJ_CORE_SCHEMA',
630
+ // PostgreSQL-preferred env var names — codegen-lib's `DEFAULT_CODEGEN_CONFIG`
631
+ // accepts these when `dbPlatform === 'postgresql'`, so a PG install whose
632
+ // `.env` uses the PG_* names must have those keys synced root → MJAPI too.
633
+ // Without this, a re-run of `mj install` would update the root `.env` but
634
+ // leave MJAPI pointing at the stale original PG credentials.
635
+ 'PG_HOST', 'PG_PORT', 'PG_DATABASE',
636
+ 'PG_USERNAME', 'PG_PASSWORD',
637
+ ]); }
638
+ /**
639
+ * Update the MJAPI .env's shared keys (database credentials, schema) to
640
+ * match the root .env. Returns the patched MJAPI content. Keys not present
641
+ * in the root are left untouched; keys present in root but not in MJAPI
642
+ * are appended. Keys MJAPI-only (e.g., ASK_SKIP_API_URL) are preserved.
643
+ */
644
+ syncEnvFieldsFromRoot(mjapiContent, rootContent) {
645
+ let result = mjapiContent;
646
+ for (const key of ConfigurePhase.ROOT_TO_MJAPI_SYNC_KEYS) {
647
+ const rootValue = this.extractEnvValue(rootContent, key);
648
+ if (rootValue === undefined)
649
+ continue;
650
+ result = this.replaceOrAppendEnvVar(result, key, rootValue);
651
+ }
652
+ return result;
653
+ }
654
+ /**
655
+ * Extract a single env var's raw value from dotenv-style content.
656
+ * Returns the value with surrounding quotes stripped, or undefined if absent.
657
+ */
658
+ extractEnvValue(content, name) {
659
+ const pattern = new RegExp(`^\\s*${name}\\s*=\\s*(.*?)\\s*$`, 'm');
660
+ const match = content.match(pattern);
661
+ if (!match)
662
+ return undefined;
663
+ let value = match[1];
664
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
665
+ value = value.slice(1, -1);
666
+ }
667
+ return value;
668
+ }
669
+ /**
670
+ * Replace an existing `NAME=...` line with the new value, or append it
671
+ * if absent. Preserves the rest of the file as-is. Uses single-quoted
672
+ * form to match the rest of the .env file's convention.
673
+ */
674
+ replaceOrAppendEnvVar(content, name, value) {
675
+ const pattern = new RegExp(`^\\s*${name}\\s*=.*$`, 'm');
676
+ const newLine = `${name}='${value}'`;
677
+ if (pattern.test(content)) {
678
+ return content.replace(pattern, newLine);
679
+ }
680
+ const suffix = content.endsWith('\n') ? '' : '\n';
681
+ return `${content}${suffix}${newLine}\n`;
682
+ }
463
683
  // ---------------------------------------------------------------------------
464
684
  // Explorer environment files
465
685
  // ---------------------------------------------------------------------------
@@ -556,12 +776,19 @@ ${versionSection}${newUserSection} output: [],
556
776
  */
557
777
  generateEnvironmentFile(config, production) {
558
778
  const authType = this.mapAuthType(config.AuthProvider);
559
- const clientId = config.AuthProviderValues?.ClientID ?? '';
560
- const tenantId = config.AuthProviderValues?.TenantID ?? '';
779
+ // Accept both internal-shape keys (`ClientID`, `TenantID`, `Domain`) and
780
+ // user-facing shape keys (`CLIENT_ID`, `TENANT_ID`, `AUTH0_DOMAIN`).
781
+ // Interactive prompts and env vars populate the internal shape; an
782
+ // install.config.json author would naturally type the underscored shape
783
+ // that matches `.env` and `environment.ts` conventions, so we have to
784
+ // read either.
785
+ const values = config.AuthProviderValues ?? {};
786
+ const clientId = values.CLIENT_ID ?? values.ClientID ?? '';
787
+ const tenantId = values.TENANT_ID ?? values.TenantID ?? '';
561
788
  const authority = tenantId
562
789
  ? `https://login.microsoftonline.com/${tenantId}`
563
790
  : '';
564
- const auth0Domain = config.AuthProviderValues?.Domain ?? '';
791
+ const auth0Domain = values.AUTH0_DOMAIN ?? values.Domain ?? '';
565
792
  const apiPort = config.APIPort ?? 4000;
566
793
  const explorerPort = config.ExplorerPort ?? 4200;
567
794
  const redirectUri = `http://localhost:${explorerPort}`;
@@ -675,12 +902,16 @@ ${versionSection}${newUserSection} output: [],
675
902
  async patchExplorerEnvironmentFile(filePath, config) {
676
903
  let content = await this.fileSystem.ReadText(filePath);
677
904
  const original = content;
678
- const clientId = config.AuthProviderValues?.ClientID ?? '';
679
- const tenantId = config.AuthProviderValues?.TenantID ?? '';
905
+ // Accept both internal-shape keys (`ClientID`, `TenantID`, `Domain`) and
906
+ // user-facing shape keys (`CLIENT_ID`, `TENANT_ID`, `AUTH0_DOMAIN`) — see
907
+ // generateEnvironmentFile() for the rationale.
908
+ const values = config.AuthProviderValues ?? {};
909
+ const clientId = values.CLIENT_ID ?? values.ClientID ?? '';
910
+ const tenantId = values.TENANT_ID ?? values.TenantID ?? '';
680
911
  const authority = tenantId
681
912
  ? `https://login.microsoftonline.com/${tenantId}`
682
913
  : '';
683
- const auth0Domain = config.AuthProviderValues?.Domain ?? '';
914
+ const auth0Domain = values.AUTH0_DOMAIN ?? values.Domain ?? '';
684
915
  const apiPort = config.APIPort ?? 4000;
685
916
  const explorerPort = config.ExplorerPort ?? 4200;
686
917
  const authType = this.mapAuthType(config.AuthProvider);
@@ -696,14 +927,36 @@ ${versionSection}${newUserSection} output: [],
696
927
  AUTH0_DOMAIN: auth0Domain,
697
928
  AUTH0_CLIENTID: clientId,
698
929
  };
930
+ // URL fields where the scaffold writes a non-empty default (`localhost:4000`
931
+ // for GraphQL, `localhost:4200` for the Explorer redirect). When the user
932
+ // configures a different port, those scaffold defaults need to be
933
+ // overwritten — not just empty-string patched. Any OTHER existing value
934
+ // (custom hostname, https://, etc.) is presumed dev-customized and is
935
+ // preserved.
936
+ const scaffoldDefaultURLs = {
937
+ GRAPHQL_URI: /^https?:\/\/localhost:4000\/?$/,
938
+ GRAPHQL_WS_URI: /^wss?:\/\/localhost:4000\/?$/,
939
+ REDIRECT_URI: /^https?:\/\/localhost:4200\/?$/,
940
+ };
699
941
  for (const [field, value] of Object.entries(patches)) {
700
942
  if (!value)
701
943
  continue;
702
- // Match: "FIELD": "" or "FIELD": '' or FIELD: "" or FIELD: ''
703
- // Only patches empty values — preserves any dev-customized values.
944
+ // 1. Empty-value patch — fills in fields the scaffold left blank.
704
945
  const emptyPattern = new RegExp(`(["']?${field}["']?\\s*[:=]\\s*)(?:["']{2}|["']\\s*["'])`);
705
946
  if (emptyPattern.test(content)) {
706
947
  content = content.replace(emptyPattern, `$1'${value}'`);
948
+ continue;
949
+ }
950
+ // 2. Scaffold-default URL overwrite — replaces only the precise
951
+ // `localhost:4000` / `localhost:4200` defaults, never user-edited
952
+ // URLs (different host, https, etc.).
953
+ const scaffoldDefault = scaffoldDefaultURLs[field];
954
+ if (scaffoldDefault) {
955
+ const valuedPattern = new RegExp(`(["']?${field}["']?\\s*[:=]\\s*["'])([^"']*)(["'])`);
956
+ const match = content.match(valuedPattern);
957
+ if (match && scaffoldDefault.test(match[2])) {
958
+ content = content.replace(valuedPattern, `$1${value}$3`);
959
+ }
707
960
  }
708
961
  }
709
962
  if (content !== original) {