@memberjunction/installer 0.0.1 → 5.6.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/InstallerEngine.d.ts +182 -0
- package/dist/InstallerEngine.d.ts.map +1 -0
- package/dist/InstallerEngine.js +571 -0
- package/dist/InstallerEngine.js.map +1 -0
- package/dist/adapters/FileSystemAdapter.d.ts +197 -0
- package/dist/adapters/FileSystemAdapter.d.ts.map +1 -0
- package/dist/adapters/FileSystemAdapter.js +355 -0
- package/dist/adapters/FileSystemAdapter.js.map +1 -0
- package/dist/adapters/GitHubReleaseProvider.d.ts +197 -0
- package/dist/adapters/GitHubReleaseProvider.d.ts.map +1 -0
- package/dist/adapters/GitHubReleaseProvider.js +348 -0
- package/dist/adapters/GitHubReleaseProvider.js.map +1 -0
- package/dist/adapters/ProcessRunner.d.ts +174 -0
- package/dist/adapters/ProcessRunner.d.ts.map +1 -0
- package/dist/adapters/ProcessRunner.js +264 -0
- package/dist/adapters/ProcessRunner.js.map +1 -0
- package/dist/adapters/SqlServerAdapter.d.ts +78 -0
- package/dist/adapters/SqlServerAdapter.d.ts.map +1 -0
- package/dist/adapters/SqlServerAdapter.js +120 -0
- package/dist/adapters/SqlServerAdapter.js.map +1 -0
- package/dist/errors/InstallerError.d.ts +92 -0
- package/dist/errors/InstallerError.d.ts.map +1 -0
- package/dist/errors/InstallerError.js +66 -0
- package/dist/errors/InstallerError.js.map +1 -0
- package/dist/events/InstallerEvents.d.ts +255 -0
- package/dist/events/InstallerEvents.d.ts.map +1 -0
- package/dist/events/InstallerEvents.js +96 -0
- package/dist/events/InstallerEvents.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/models/Diagnostics.d.ts +121 -0
- package/dist/models/Diagnostics.d.ts.map +1 -0
- package/dist/models/Diagnostics.js +75 -0
- package/dist/models/Diagnostics.js.map +1 -0
- package/dist/models/InstallConfig.d.ts +139 -0
- package/dist/models/InstallConfig.d.ts.map +1 -0
- package/dist/models/InstallConfig.js +207 -0
- package/dist/models/InstallConfig.js.map +1 -0
- package/dist/models/InstallPlan.d.ts +189 -0
- package/dist/models/InstallPlan.d.ts.map +1 -0
- package/dist/models/InstallPlan.js +117 -0
- package/dist/models/InstallPlan.js.map +1 -0
- package/dist/models/InstallState.d.ts +173 -0
- package/dist/models/InstallState.d.ts.map +1 -0
- package/dist/models/InstallState.js +203 -0
- package/dist/models/InstallState.js.map +1 -0
- package/dist/models/VersionInfo.d.ts +53 -0
- package/dist/models/VersionInfo.d.ts.map +1 -0
- package/dist/models/VersionInfo.js +2 -0
- package/dist/models/VersionInfo.js.map +1 -0
- package/dist/phases/CodeGenPhase.d.ts +364 -0
- package/dist/phases/CodeGenPhase.d.ts.map +1 -0
- package/dist/phases/CodeGenPhase.js +1086 -0
- package/dist/phases/CodeGenPhase.js.map +1 -0
- package/dist/phases/ConfigurePhase.d.ts +86 -0
- package/dist/phases/ConfigurePhase.d.ts.map +1 -0
- package/dist/phases/ConfigurePhase.js +439 -0
- package/dist/phases/ConfigurePhase.js.map +1 -0
- package/dist/phases/DatabaseProvisionPhase.d.ts +82 -0
- package/dist/phases/DatabaseProvisionPhase.d.ts.map +1 -0
- package/dist/phases/DatabaseProvisionPhase.js +284 -0
- package/dist/phases/DatabaseProvisionPhase.js.map +1 -0
- package/dist/phases/DependencyPhase.d.ts +88 -0
- package/dist/phases/DependencyPhase.d.ts.map +1 -0
- package/dist/phases/DependencyPhase.js +237 -0
- package/dist/phases/DependencyPhase.js.map +1 -0
- package/dist/phases/MigratePhase.d.ts +70 -0
- package/dist/phases/MigratePhase.d.ts.map +1 -0
- package/dist/phases/MigratePhase.js +96 -0
- package/dist/phases/MigratePhase.js.map +1 -0
- package/dist/phases/PlatformCompatPhase.d.ts +193 -0
- package/dist/phases/PlatformCompatPhase.d.ts.map +1 -0
- package/dist/phases/PlatformCompatPhase.js +587 -0
- package/dist/phases/PlatformCompatPhase.js.map +1 -0
- package/dist/phases/PreflightPhase.d.ts +119 -0
- package/dist/phases/PreflightPhase.d.ts.map +1 -0
- package/dist/phases/PreflightPhase.js +394 -0
- package/dist/phases/PreflightPhase.js.map +1 -0
- package/dist/phases/ScaffoldPhase.d.ts +99 -0
- package/dist/phases/ScaffoldPhase.d.ts.map +1 -0
- package/dist/phases/ScaffoldPhase.js +235 -0
- package/dist/phases/ScaffoldPhase.js.map +1 -0
- package/dist/phases/SmokeTestPhase.d.ts +111 -0
- package/dist/phases/SmokeTestPhase.d.ts.map +1 -0
- package/dist/phases/SmokeTestPhase.js +426 -0
- package/dist/phases/SmokeTestPhase.js.map +1 -0
- package/package.json +26 -7
- package/README.md +0 -45
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase C — Database Provisioning
|
|
3
|
+
*
|
|
4
|
+
* Generates idempotent SQL scripts for database setup and prompts the user
|
|
5
|
+
* to execute them manually in SSMS or Azure Data Studio. Then validates
|
|
6
|
+
* that SQL Server is reachable at the configured host:port.
|
|
7
|
+
*
|
|
8
|
+
* Two scripts are generated:
|
|
9
|
+
* 1. **`mj-db-setup.sql`** — Creates the database (if not exists), `__mj` schema,
|
|
10
|
+
* SQL logins, database users, and role grants. All statements are idempotent
|
|
11
|
+
* (safe to run multiple times).
|
|
12
|
+
* 2. **`mj-db-validate.sql`** — Verifies the schema, users, and roles exist.
|
|
13
|
+
* Run this to confirm the setup script was executed correctly.
|
|
14
|
+
*
|
|
15
|
+
* The phase does **not** execute SQL directly — it generates scripts and asks
|
|
16
|
+
* the user to run them. This design avoids requiring a SQL driver dependency
|
|
17
|
+
* in the installer and gives users full visibility into what's being executed.
|
|
18
|
+
*
|
|
19
|
+
* @module phases/DatabaseProvisionPhase
|
|
20
|
+
* @see SqlServerAdapter — used for TCP connectivity validation.
|
|
21
|
+
* @see ConfigurePhase — provides the database credentials used in script generation.
|
|
22
|
+
*/
|
|
23
|
+
import type { InstallerEventEmitter } from '../events/InstallerEvents.js';
|
|
24
|
+
import type { PartialInstallConfig } from '../models/InstallConfig.js';
|
|
25
|
+
/**
|
|
26
|
+
* Input context for the database provisioning phase.
|
|
27
|
+
*
|
|
28
|
+
* @see DatabaseProvisionPhase.Run
|
|
29
|
+
*/
|
|
30
|
+
export interface DatabaseProvisionContext {
|
|
31
|
+
/** Absolute path to the target install directory. */
|
|
32
|
+
Dir: string;
|
|
33
|
+
/** Current install config with database credentials from the configure phase. */
|
|
34
|
+
Config: PartialInstallConfig;
|
|
35
|
+
/** Non-interactive mode — skips the "run this script" prompt. */
|
|
36
|
+
Yes: boolean;
|
|
37
|
+
/** Event emitter for progress, prompt, and log events. */
|
|
38
|
+
Emitter: InstallerEventEmitter;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Result of the database provisioning phase.
|
|
42
|
+
*
|
|
43
|
+
* @see DatabaseProvisionPhase.Run
|
|
44
|
+
*/
|
|
45
|
+
export interface DatabaseProvisionResult {
|
|
46
|
+
/** Absolute paths of the SQL script files that were generated. */
|
|
47
|
+
ScriptsGenerated: string[];
|
|
48
|
+
/** Whether the post-script TCP connectivity validation passed. */
|
|
49
|
+
ValidationPassed: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Phase C — Generates SQL provisioning scripts and validates database connectivity.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const dbPhase = new DatabaseProvisionPhase();
|
|
57
|
+
* const result = await dbPhase.Run({
|
|
58
|
+
* Dir: '/path/to/install',
|
|
59
|
+
* Config: { DatabaseHost: 'localhost', DatabasePort: 1433, DatabaseName: 'MJ' },
|
|
60
|
+
* Yes: false,
|
|
61
|
+
* Emitter: emitter,
|
|
62
|
+
* });
|
|
63
|
+
* console.log(`Scripts: ${result.ScriptsGenerated.join(', ')}`);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare class DatabaseProvisionPhase {
|
|
67
|
+
private fileSystem;
|
|
68
|
+
private sqlAdapter;
|
|
69
|
+
/**
|
|
70
|
+
* Execute the database provisioning phase: generate scripts, prompt user,
|
|
71
|
+
* and validate connectivity.
|
|
72
|
+
*
|
|
73
|
+
* @param context - Database provision input with directory, config, mode, and emitter.
|
|
74
|
+
* @returns Script paths and validation result.
|
|
75
|
+
* @throws {InstallerError} With code `DB_UNREACHABLE` if SQL Server connectivity fails after script execution.
|
|
76
|
+
*/
|
|
77
|
+
Run(context: DatabaseProvisionContext): Promise<DatabaseProvisionResult>;
|
|
78
|
+
private generateSetupScript;
|
|
79
|
+
private generateValidateScript;
|
|
80
|
+
private promptForScriptExecution;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=DatabaseProvisionPhase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseProvisionPhase.d.ts","sourceRoot":"","sources":["../../src/phases/DatabaseProvisionPhase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAKvE;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,iFAAiF;IACjF,MAAM,EAAE,oBAAoB,CAAC;IAC7B,iEAAiE;IACjE,GAAG,EAAE,OAAO,CAAC;IACb,0DAA0D;IAC1D,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,kEAAkE;IAClE,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,kEAAkE;IAClE,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,UAAU,CAA0B;IAE5C;;;;;;;OAOG;IACG,GAAG,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAuE9E,OAAO,CAAC,mBAAmB;IA6H3B,OAAO,CAAC,sBAAsB;YAyChB,wBAAwB;CAevC"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase C — Database Provisioning
|
|
3
|
+
*
|
|
4
|
+
* Generates idempotent SQL scripts for database setup and prompts the user
|
|
5
|
+
* to execute them manually in SSMS or Azure Data Studio. Then validates
|
|
6
|
+
* that SQL Server is reachable at the configured host:port.
|
|
7
|
+
*
|
|
8
|
+
* Two scripts are generated:
|
|
9
|
+
* 1. **`mj-db-setup.sql`** — Creates the database (if not exists), `__mj` schema,
|
|
10
|
+
* SQL logins, database users, and role grants. All statements are idempotent
|
|
11
|
+
* (safe to run multiple times).
|
|
12
|
+
* 2. **`mj-db-validate.sql`** — Verifies the schema, users, and roles exist.
|
|
13
|
+
* Run this to confirm the setup script was executed correctly.
|
|
14
|
+
*
|
|
15
|
+
* The phase does **not** execute SQL directly — it generates scripts and asks
|
|
16
|
+
* the user to run them. This design avoids requiring a SQL driver dependency
|
|
17
|
+
* in the installer and gives users full visibility into what's being executed.
|
|
18
|
+
*
|
|
19
|
+
* @module phases/DatabaseProvisionPhase
|
|
20
|
+
* @see SqlServerAdapter — used for TCP connectivity validation.
|
|
21
|
+
* @see ConfigurePhase — provides the database credentials used in script generation.
|
|
22
|
+
*/
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import { InstallerError } from '../errors/InstallerError.js';
|
|
25
|
+
import { FileSystemAdapter } from '../adapters/FileSystemAdapter.js';
|
|
26
|
+
import { SqlServerAdapter } from '../adapters/SqlServerAdapter.js';
|
|
27
|
+
/**
|
|
28
|
+
* Phase C — Generates SQL provisioning scripts and validates database connectivity.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const dbPhase = new DatabaseProvisionPhase();
|
|
33
|
+
* const result = await dbPhase.Run({
|
|
34
|
+
* Dir: '/path/to/install',
|
|
35
|
+
* Config: { DatabaseHost: 'localhost', DatabasePort: 1433, DatabaseName: 'MJ' },
|
|
36
|
+
* Yes: false,
|
|
37
|
+
* Emitter: emitter,
|
|
38
|
+
* });
|
|
39
|
+
* console.log(`Scripts: ${result.ScriptsGenerated.join(', ')}`);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export class DatabaseProvisionPhase {
|
|
43
|
+
constructor() {
|
|
44
|
+
this.fileSystem = new FileSystemAdapter();
|
|
45
|
+
this.sqlAdapter = new SqlServerAdapter();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Execute the database provisioning phase: generate scripts, prompt user,
|
|
49
|
+
* and validate connectivity.
|
|
50
|
+
*
|
|
51
|
+
* @param context - Database provision input with directory, config, mode, and emitter.
|
|
52
|
+
* @returns Script paths and validation result.
|
|
53
|
+
* @throws {InstallerError} With code `DB_UNREACHABLE` if SQL Server connectivity fails after script execution.
|
|
54
|
+
*/
|
|
55
|
+
async Run(context) {
|
|
56
|
+
const { Config: config, Emitter: emitter } = context;
|
|
57
|
+
// Step 1: Generate SQL scripts
|
|
58
|
+
emitter.Emit('step:progress', {
|
|
59
|
+
Type: 'step:progress',
|
|
60
|
+
Phase: 'database',
|
|
61
|
+
Message: 'Generating database setup scripts...',
|
|
62
|
+
});
|
|
63
|
+
const scripts = this.generateSetupScript(config);
|
|
64
|
+
const scriptPath = path.join(context.Dir, 'mj-db-setup.sql');
|
|
65
|
+
await this.fileSystem.WriteText(scriptPath, scripts);
|
|
66
|
+
const validateScript = this.generateValidateScript(config);
|
|
67
|
+
const validatePath = path.join(context.Dir, 'mj-db-validate.sql');
|
|
68
|
+
await this.fileSystem.WriteText(validatePath, validateScript);
|
|
69
|
+
emitter.Emit('log', {
|
|
70
|
+
Type: 'log',
|
|
71
|
+
Level: 'info',
|
|
72
|
+
Message: `SQL scripts saved to:\n - ${scriptPath}\n - ${validatePath}`,
|
|
73
|
+
});
|
|
74
|
+
// Step 2: Prompt user to execute the script
|
|
75
|
+
if (!context.Yes) {
|
|
76
|
+
await this.promptForScriptExecution(emitter, scriptPath);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
emitter.Emit('warn', {
|
|
80
|
+
Type: 'warn',
|
|
81
|
+
Phase: 'database',
|
|
82
|
+
Message: 'Non-interactive mode: skipping SQL script execution prompt. Run mj-db-setup.sql manually if needed.',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Step 3: Validate connectivity
|
|
86
|
+
emitter.Emit('step:progress', {
|
|
87
|
+
Type: 'step:progress',
|
|
88
|
+
Phase: 'database',
|
|
89
|
+
Message: 'Validating database connectivity...',
|
|
90
|
+
});
|
|
91
|
+
const host = config.DatabaseHost ?? 'localhost';
|
|
92
|
+
const port = config.DatabasePort ?? 1433;
|
|
93
|
+
const connectivity = await this.sqlAdapter.CheckConnectivity(host, port);
|
|
94
|
+
if (!connectivity.Reachable) {
|
|
95
|
+
throw new InstallerError('database', 'DB_UNREACHABLE', `Cannot connect to SQL Server at ${host}:${port}. ${connectivity.ErrorMessage ?? ''}`, `Ensure SQL Server is running and accessible. Then run the setup script: ${scriptPath}`);
|
|
96
|
+
}
|
|
97
|
+
emitter.Emit('log', {
|
|
98
|
+
Type: 'log',
|
|
99
|
+
Level: 'info',
|
|
100
|
+
Message: `Database connectivity verified at ${host}:${port} (${connectivity.LatencyMs}ms)`,
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
ScriptsGenerated: [scriptPath, validatePath],
|
|
104
|
+
ValidationPassed: true,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
// SQL script generation
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
generateSetupScript(config) {
|
|
111
|
+
const dbName = config.DatabaseName ?? 'MemberJunction';
|
|
112
|
+
const codeGenUser = config.CodeGenUser ?? 'MJ_CodeGen';
|
|
113
|
+
const codeGenPassword = config.CodeGenPassword ?? 'CHANGE_ME';
|
|
114
|
+
const apiUser = config.APIUser ?? 'MJ_Connect';
|
|
115
|
+
const apiPassword = config.APIPassword ?? 'CHANGE_ME';
|
|
116
|
+
return `-- MemberJunction Database Setup Script
|
|
117
|
+
-- Generated by MJ Installer
|
|
118
|
+
-- This script is idempotent (safe to run multiple times)
|
|
119
|
+
--
|
|
120
|
+
-- Run this script as a sysadmin against your SQL Server instance.
|
|
121
|
+
-- It creates the database, logins, users, and role grants.
|
|
122
|
+
|
|
123
|
+
--============================================================================
|
|
124
|
+
-- 1. Create database (if not exists)
|
|
125
|
+
--============================================================================
|
|
126
|
+
IF NOT EXISTS (SELECT 1 FROM sys.databases WHERE name = '${dbName}')
|
|
127
|
+
BEGIN
|
|
128
|
+
CREATE DATABASE [${dbName}];
|
|
129
|
+
PRINT 'Created database: ${dbName}';
|
|
130
|
+
END
|
|
131
|
+
ELSE
|
|
132
|
+
PRINT 'Database already exists: ${dbName}';
|
|
133
|
+
GO
|
|
134
|
+
|
|
135
|
+
USE [${dbName}];
|
|
136
|
+
GO
|
|
137
|
+
|
|
138
|
+
--============================================================================
|
|
139
|
+
-- 2. Create __mj schema (if not exists)
|
|
140
|
+
--============================================================================
|
|
141
|
+
IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = '__mj')
|
|
142
|
+
BEGIN
|
|
143
|
+
EXEC('CREATE SCHEMA [__mj]');
|
|
144
|
+
PRINT 'Created schema: __mj';
|
|
145
|
+
END
|
|
146
|
+
GO
|
|
147
|
+
|
|
148
|
+
--============================================================================
|
|
149
|
+
-- 3. Create logins (server-level)
|
|
150
|
+
--============================================================================
|
|
151
|
+
USE [master];
|
|
152
|
+
GO
|
|
153
|
+
|
|
154
|
+
IF NOT EXISTS (SELECT 1 FROM sys.server_principals WHERE name = '${codeGenUser}')
|
|
155
|
+
BEGIN
|
|
156
|
+
CREATE LOGIN [${codeGenUser}] WITH PASSWORD = '${codeGenPassword}';
|
|
157
|
+
PRINT 'Created login: ${codeGenUser}';
|
|
158
|
+
END
|
|
159
|
+
GO
|
|
160
|
+
|
|
161
|
+
IF NOT EXISTS (SELECT 1 FROM sys.server_principals WHERE name = '${apiUser}')
|
|
162
|
+
BEGIN
|
|
163
|
+
CREATE LOGIN [${apiUser}] WITH PASSWORD = '${apiPassword}';
|
|
164
|
+
PRINT 'Created login: ${apiUser}';
|
|
165
|
+
END
|
|
166
|
+
GO
|
|
167
|
+
|
|
168
|
+
--============================================================================
|
|
169
|
+
-- 4. Create database users
|
|
170
|
+
--============================================================================
|
|
171
|
+
USE [${dbName}];
|
|
172
|
+
GO
|
|
173
|
+
|
|
174
|
+
IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = '${codeGenUser}')
|
|
175
|
+
BEGIN
|
|
176
|
+
CREATE USER [${codeGenUser}] FOR LOGIN [${codeGenUser}];
|
|
177
|
+
PRINT 'Created user: ${codeGenUser}';
|
|
178
|
+
END
|
|
179
|
+
GO
|
|
180
|
+
|
|
181
|
+
IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = '${apiUser}')
|
|
182
|
+
BEGIN
|
|
183
|
+
CREATE USER [${apiUser}] FOR LOGIN [${apiUser}];
|
|
184
|
+
PRINT 'Created user: ${apiUser}';
|
|
185
|
+
END
|
|
186
|
+
GO
|
|
187
|
+
|
|
188
|
+
--============================================================================
|
|
189
|
+
-- 5. Grant roles
|
|
190
|
+
--============================================================================
|
|
191
|
+
-- CodeGen needs elevated permissions for schema modifications
|
|
192
|
+
IF NOT EXISTS (SELECT 1 FROM sys.database_role_members rm
|
|
193
|
+
JOIN sys.database_principals rp ON rm.role_principal_id = rp.principal_id
|
|
194
|
+
JOIN sys.database_principals mp ON rm.member_principal_id = mp.principal_id
|
|
195
|
+
WHERE rp.name = 'db_owner' AND mp.name = '${codeGenUser}')
|
|
196
|
+
BEGIN
|
|
197
|
+
ALTER ROLE db_owner ADD MEMBER [${codeGenUser}];
|
|
198
|
+
PRINT 'Granted db_owner to ${codeGenUser}';
|
|
199
|
+
END
|
|
200
|
+
GO
|
|
201
|
+
|
|
202
|
+
-- API user needs read/write + execute
|
|
203
|
+
IF NOT EXISTS (SELECT 1 FROM sys.database_role_members rm
|
|
204
|
+
JOIN sys.database_principals rp ON rm.role_principal_id = rp.principal_id
|
|
205
|
+
JOIN sys.database_principals mp ON rm.member_principal_id = mp.principal_id
|
|
206
|
+
WHERE rp.name = 'db_datareader' AND mp.name = '${apiUser}')
|
|
207
|
+
BEGIN
|
|
208
|
+
ALTER ROLE db_datareader ADD MEMBER [${apiUser}];
|
|
209
|
+
PRINT 'Granted db_datareader to ${apiUser}';
|
|
210
|
+
END
|
|
211
|
+
GO
|
|
212
|
+
|
|
213
|
+
IF NOT EXISTS (SELECT 1 FROM sys.database_role_members rm
|
|
214
|
+
JOIN sys.database_principals rp ON rm.role_principal_id = rp.principal_id
|
|
215
|
+
JOIN sys.database_principals mp ON rm.member_principal_id = mp.principal_id
|
|
216
|
+
WHERE rp.name = 'db_datawriter' AND mp.name = '${apiUser}')
|
|
217
|
+
BEGIN
|
|
218
|
+
ALTER ROLE db_datawriter ADD MEMBER [${apiUser}];
|
|
219
|
+
PRINT 'Granted db_datawriter to ${apiUser}';
|
|
220
|
+
END
|
|
221
|
+
GO
|
|
222
|
+
|
|
223
|
+
GRANT EXECUTE TO [${apiUser}];
|
|
224
|
+
GO
|
|
225
|
+
|
|
226
|
+
PRINT '';
|
|
227
|
+
PRINT '=== MemberJunction database setup complete ===';
|
|
228
|
+
PRINT 'Database: ${dbName}';
|
|
229
|
+
PRINT 'CodeGen user: ${codeGenUser}';
|
|
230
|
+
PRINT 'API user: ${apiUser}';
|
|
231
|
+
`;
|
|
232
|
+
}
|
|
233
|
+
generateValidateScript(config) {
|
|
234
|
+
const dbName = config.DatabaseName ?? 'MemberJunction';
|
|
235
|
+
const codeGenUser = config.CodeGenUser ?? 'MJ_CodeGen';
|
|
236
|
+
const apiUser = config.APIUser ?? 'MJ_Connect';
|
|
237
|
+
return `-- MemberJunction Database Validation Script
|
|
238
|
+
-- Generated by MJ Installer
|
|
239
|
+
-- Run this to verify the database setup is correct.
|
|
240
|
+
|
|
241
|
+
USE [${dbName}];
|
|
242
|
+
GO
|
|
243
|
+
|
|
244
|
+
PRINT 'Checking database: ${dbName}';
|
|
245
|
+
PRINT '';
|
|
246
|
+
|
|
247
|
+
-- Check __mj schema
|
|
248
|
+
IF EXISTS (SELECT 1 FROM sys.schemas WHERE name = '__mj')
|
|
249
|
+
PRINT '[PASS] __mj schema exists';
|
|
250
|
+
ELSE
|
|
251
|
+
PRINT '[FAIL] __mj schema NOT found';
|
|
252
|
+
|
|
253
|
+
-- Check users
|
|
254
|
+
IF EXISTS (SELECT 1 FROM sys.database_principals WHERE name = '${codeGenUser}')
|
|
255
|
+
PRINT '[PASS] User ${codeGenUser} exists';
|
|
256
|
+
ELSE
|
|
257
|
+
PRINT '[FAIL] User ${codeGenUser} NOT found';
|
|
258
|
+
|
|
259
|
+
IF EXISTS (SELECT 1 FROM sys.database_principals WHERE name = '${apiUser}')
|
|
260
|
+
PRINT '[PASS] User ${apiUser} exists';
|
|
261
|
+
ELSE
|
|
262
|
+
PRINT '[FAIL] User ${apiUser} NOT found';
|
|
263
|
+
|
|
264
|
+
PRINT '';
|
|
265
|
+
PRINT '=== Validation complete ===';
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
268
|
+
// ---------------------------------------------------------------------------
|
|
269
|
+
// Prompt helper
|
|
270
|
+
// ---------------------------------------------------------------------------
|
|
271
|
+
async promptForScriptExecution(emitter, scriptPath) {
|
|
272
|
+
await new Promise((resolve) => {
|
|
273
|
+
emitter.Emit('prompt', {
|
|
274
|
+
Type: 'prompt',
|
|
275
|
+
PromptId: 'run-db-script',
|
|
276
|
+
PromptType: 'confirm',
|
|
277
|
+
Message: `Please run "${scriptPath}" in SSMS or Azure Data Studio, then confirm to continue.`,
|
|
278
|
+
Default: 'yes',
|
|
279
|
+
Resolve: resolve,
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=DatabaseProvisionPhase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseProvisionPhase.js","sourceRoot":"","sources":["../../src/phases/DatabaseProvisionPhase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AA8BnE;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,sBAAsB;IAAnC;QACU,eAAU,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACrC,eAAU,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAsQ9C,CAAC;IApQC;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,OAAiC;QACzC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAErD,+BAA+B;QAC/B,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE;YAC5B,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,UAAU;YACjB,OAAO,EAAE,sCAAsC;SAChD,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACjD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QAC7D,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,O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Z,OAAO;;;;;;;qDAOQ,OAAO;;2CAEjB,OAAO;sCACZ,OAAO;;;;oBAIzB,OAAO;;;;;mBAKR,MAAM;uBACF,WAAW;mBACf,OAAO;CACzB,CAAC;IACA,CAAC;IAEO,sBAAsB,CAAC,MAA4B;QACzD,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,IAAI,gBAAgB,CAAC;QACvD,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,YAAY,CAAC;QACvD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,YAAY,CAAC;QAE/C,OAAO;;;;OAIJ,MAAM;;;4BAGe,MAAM;;;;;;;;;;iEAU+B,WAAW;yBACnD,WAAW;;yBAEX,WAAW;;iEAE6B,OAAO;yBAC/C,OAAO;;yBAEP,OAAO;;;;CAI/B,CAAC;IACA,CAAC;IAED,8EAA8E;IAC9E,gBAAgB;IAChB,8EAA8E;IAEtE,KAAK,CAAC,wBAAwB,CACpC,OAA8B,EAC9B,UAAkB;QAElB,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;YACpC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE;gBACrB,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,eAAe;gBACzB,UAAU,EAAE,SAAS;gBACrB,OAAO,EAAE,eAAe,UAAU,2DAA2D;gBAC7F,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase G — Dependencies (Install + Build)
|
|
3
|
+
*
|
|
4
|
+
* Runs `npm install` at the repo root to install all workspace dependencies,
|
|
5
|
+
* then `npm run build` to compile all ~170 packages in the monorepo.
|
|
6
|
+
*
|
|
7
|
+
* Key behaviors:
|
|
8
|
+
* - **ERESOLVE retry**: If `npm install` fails with peer dependency conflicts,
|
|
9
|
+
* automatically retries with `--legacy-peer-deps`.
|
|
10
|
+
* - **Partial build tolerance**: Build failures in codegen-managed packages
|
|
11
|
+
* (entity forms, bootstrap) are treated as partial success since CodeGen
|
|
12
|
+
* will regenerate their source and rebuild in a later phase.
|
|
13
|
+
* - **Audit warnings**: npm vulnerability reports are logged as informational
|
|
14
|
+
* warnings — users are explicitly told NOT to run `npm audit fix --force`.
|
|
15
|
+
*
|
|
16
|
+
* @module phases/DependencyPhase
|
|
17
|
+
* @see CodeGenPhase — handles rebuilding codegen-managed packages after code generation.
|
|
18
|
+
* @see PlatformCompatPhase — patches scripts before this phase runs.
|
|
19
|
+
*/
|
|
20
|
+
import type { InstallerEventEmitter } from '../events/InstallerEvents.js';
|
|
21
|
+
/**
|
|
22
|
+
* Input context for the dependency phase.
|
|
23
|
+
*
|
|
24
|
+
* @see DependencyPhase.Run
|
|
25
|
+
*/
|
|
26
|
+
export interface DependencyContext {
|
|
27
|
+
/** Absolute path to the repo root (where `npm install` and `npm run build` are executed). */
|
|
28
|
+
Dir: string;
|
|
29
|
+
/** Event emitter for progress, warn, and log events. */
|
|
30
|
+
Emitter: InstallerEventEmitter;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of the dependency phase.
|
|
34
|
+
*
|
|
35
|
+
* @see DependencyPhase.Run
|
|
36
|
+
*/
|
|
37
|
+
export interface DependencyResult {
|
|
38
|
+
/** Whether `npm install` completed successfully. */
|
|
39
|
+
InstallSuccess: boolean;
|
|
40
|
+
/** Whether `npm run build` completed fully (`false` if partial). */
|
|
41
|
+
BuildSuccess: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the build was partial — codegen-managed packages failed
|
|
44
|
+
* but all other packages succeeded. CodeGen will fix these.
|
|
45
|
+
*/
|
|
46
|
+
BuildPartial: boolean;
|
|
47
|
+
/** Non-fatal warnings collected during install and build (e.g., npm audit advisories). */
|
|
48
|
+
Warnings: string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Phase G — Installs npm dependencies and builds all workspace packages.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const deps = new DependencyPhase();
|
|
56
|
+
* const result = await deps.Run({ Dir: '/path/to/install', Emitter: emitter });
|
|
57
|
+
* if (result.BuildPartial) {
|
|
58
|
+
* console.log('Partial build — CodeGen will fix remaining packages');
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare class DependencyPhase {
|
|
63
|
+
private processRunner;
|
|
64
|
+
/**
|
|
65
|
+
* Execute the dependency phase: `npm install` then `npm run build`.
|
|
66
|
+
*
|
|
67
|
+
* @param context - Dependency input with directory and emitter.
|
|
68
|
+
* @returns Install/build status and collected warnings.
|
|
69
|
+
* @throws {InstallerError} With code `NPM_INSTALL_FAILED` or `NPM_INSTALL_TIMEOUT` on install failure.
|
|
70
|
+
* @throws {InstallerError} With code `BUILD_FAILED` or `BUILD_TIMEOUT` on non-codegen build failure.
|
|
71
|
+
*/
|
|
72
|
+
Run(context: DependencyContext): Promise<DependencyResult>;
|
|
73
|
+
private runNpmInstall;
|
|
74
|
+
/**
|
|
75
|
+
* Runs npm run build. Returns true if the build was "partial" (only codegen-managed
|
|
76
|
+
* packages failed), false if it fully succeeded. Throws on hard failures.
|
|
77
|
+
*/
|
|
78
|
+
private runNpmBuild;
|
|
79
|
+
/**
|
|
80
|
+
* Extract failed package names from turbo's stderr output.
|
|
81
|
+
* Turbo outputs lines like: "Failed: @memberjunction/ng-core-entity-forms#build"
|
|
82
|
+
*/
|
|
83
|
+
private extractFailedTurboPackages;
|
|
84
|
+
private runNpmInstallOnce;
|
|
85
|
+
private isEresolveError;
|
|
86
|
+
private lastNLines;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=DependencyPhase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DependencyPhase.d.ts","sourceRoot":"","sources":["../../src/phases/DependencyPhase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAmB1E;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,6FAA6F;IAC7F,GAAG,EAAE,MAAM,CAAC;IACZ,wDAAwD;IACxD,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,cAAc,EAAE,OAAO,CAAC;IACxB,oEAAoE;IACpE,YAAY,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB,0FAA0F;IAC1F,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,aAAa,CAAuB;IAE5C;;;;;;;OAOG;IACG,GAAG,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAsBlD,aAAa;IAmF3B;;;OAGG;YACW,WAAW;IAgFzB;;;OAGG;IACH,OAAO,CAAC,0BAA0B;YAcpB,iBAAiB;IA4B/B,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,UAAU;CAInB"}
|