@authrim/setup 0.1.63 → 0.1.64
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/__tests__/migrate.test.d.ts +5 -0
- package/dist/__tests__/migrate.test.d.ts.map +1 -0
- package/dist/__tests__/migrate.test.js +273 -0
- package/dist/__tests__/migrate.test.js.map +1 -0
- package/dist/__tests__/paths.test.d.ts +2 -0
- package/dist/__tests__/paths.test.d.ts.map +1 -0
- package/dist/__tests__/paths.test.js +257 -0
- package/dist/__tests__/paths.test.js.map +1 -0
- package/dist/cli/commands/config.d.ts +1 -0
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/config.js +41 -7
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/deploy.d.ts +1 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -1
- package/dist/cli/commands/deploy.js +181 -19
- package/dist/cli/commands/deploy.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +267 -82
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/migrate.d.ts +21 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -0
- package/dist/cli/commands/migrate.js +166 -0
- package/dist/cli/commands/migrate.js.map +1 -0
- package/dist/core/admin.d.ts +18 -1
- package/dist/core/admin.d.ts.map +1 -1
- package/dist/core/admin.js +36 -7
- package/dist/core/admin.js.map +1 -1
- package/dist/core/config.d.ts +10 -2
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +6 -2
- package/dist/core/config.js.map +1 -1
- package/dist/core/keys.d.ts +55 -4
- package/dist/core/keys.d.ts.map +1 -1
- package/dist/core/keys.js +104 -12
- package/dist/core/keys.js.map +1 -1
- package/dist/core/lock.d.ts +60 -3
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +108 -4
- package/dist/core/lock.js.map +1 -1
- package/dist/core/migrate.d.ts +95 -0
- package/dist/core/migrate.d.ts.map +1 -0
- package/dist/core/migrate.js +549 -0
- package/dist/core/migrate.js.map +1 -0
- package/dist/core/paths.d.ts +171 -0
- package/dist/core/paths.d.ts.map +1 -0
- package/dist/core/paths.js +319 -0
- package/dist/core/paths.js.map +1 -0
- package/dist/core/wrangler-sync.d.ts +88 -0
- package/dist/core/wrangler-sync.d.ts.map +1 -0
- package/dist/core/wrangler-sync.js +242 -0
- package/dist/core/wrangler-sync.js.map +1 -0
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/web/api.d.ts.map +1 -1
- package/dist/web/api.js +102 -28
- package/dist/web/api.js.map +1 -1
- package/dist/web/ui.d.ts.map +1 -1
- package/dist/web/ui.js +831 -273
- package/dist/web/ui.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path Management Module
|
|
3
|
+
*
|
|
4
|
+
* Centralized path resolution for Authrim configuration files.
|
|
5
|
+
* Supports both legacy (flat files) and new (.authrim/{env}/) structures.
|
|
6
|
+
*
|
|
7
|
+
* Legacy Structure:
|
|
8
|
+
* project/
|
|
9
|
+
* ├── authrim-config.json
|
|
10
|
+
* ├── authrim-lock.json
|
|
11
|
+
* └── .keys/{env}/
|
|
12
|
+
*
|
|
13
|
+
* New Structure:
|
|
14
|
+
* project/
|
|
15
|
+
* └── .authrim/
|
|
16
|
+
* └── {env}/
|
|
17
|
+
* ├── config.json
|
|
18
|
+
* ├── lock.json
|
|
19
|
+
* ├── version.txt
|
|
20
|
+
* └── keys/
|
|
21
|
+
*/
|
|
22
|
+
export interface PathConfig {
|
|
23
|
+
/** Base directory (usually cwd) */
|
|
24
|
+
baseDir: string;
|
|
25
|
+
/** Environment name */
|
|
26
|
+
env: string;
|
|
27
|
+
}
|
|
28
|
+
export interface EnvironmentPaths {
|
|
29
|
+
/** Root directory for this environment: .authrim/{env}/ */
|
|
30
|
+
root: string;
|
|
31
|
+
/** Configuration file: .authrim/{env}/config.json */
|
|
32
|
+
config: string;
|
|
33
|
+
/** Lock file with resource IDs: .authrim/{env}/lock.json */
|
|
34
|
+
lock: string;
|
|
35
|
+
/** Version tracking file: .authrim/{env}/version.txt */
|
|
36
|
+
version: string;
|
|
37
|
+
/** Keys directory: .authrim/{env}/keys/ */
|
|
38
|
+
keys: string;
|
|
39
|
+
/** Wrangler configs directory: .authrim/{env}/wrangler/ */
|
|
40
|
+
wrangler: string;
|
|
41
|
+
/** Specific key file paths */
|
|
42
|
+
keyFiles: KeyFilePaths;
|
|
43
|
+
}
|
|
44
|
+
export interface KeyFilePaths {
|
|
45
|
+
privateKey: string;
|
|
46
|
+
publicKey: string;
|
|
47
|
+
rpTokenEncryptionKey: string;
|
|
48
|
+
adminApiSecret: string;
|
|
49
|
+
keyManagerSecret: string;
|
|
50
|
+
setupToken: string;
|
|
51
|
+
metadata: string;
|
|
52
|
+
emailFrom: string;
|
|
53
|
+
resendApiKey: string;
|
|
54
|
+
}
|
|
55
|
+
export interface LegacyPaths {
|
|
56
|
+
/** Configuration file: authrim-config.json */
|
|
57
|
+
config: string;
|
|
58
|
+
/** Lock file: authrim-lock.json */
|
|
59
|
+
lock: string;
|
|
60
|
+
/** Keys directory: .keys/{env}/ */
|
|
61
|
+
keys: string;
|
|
62
|
+
/** Specific key file paths */
|
|
63
|
+
keyFiles: KeyFilePaths;
|
|
64
|
+
}
|
|
65
|
+
export type StructureType = 'new' | 'legacy' | 'none';
|
|
66
|
+
export interface StructureInfo {
|
|
67
|
+
type: StructureType;
|
|
68
|
+
/** Available environments (for 'new' type) */
|
|
69
|
+
envs: string[];
|
|
70
|
+
/** Detected environment name (for 'legacy' type, if determinable) */
|
|
71
|
+
legacyEnv?: string;
|
|
72
|
+
}
|
|
73
|
+
/** Root directory name for new structure */
|
|
74
|
+
export declare const AUTHRIM_DIR = ".authrim";
|
|
75
|
+
/** Legacy config file name */
|
|
76
|
+
export declare const LEGACY_CONFIG_FILE = "authrim-config.json";
|
|
77
|
+
/** Legacy lock file name */
|
|
78
|
+
export declare const LEGACY_LOCK_FILE = "authrim-lock.json";
|
|
79
|
+
/** Legacy keys directory */
|
|
80
|
+
export declare const LEGACY_KEYS_DIR = ".keys";
|
|
81
|
+
/** New structure config file name */
|
|
82
|
+
export declare const CONFIG_FILE = "config.json";
|
|
83
|
+
/** New structure lock file name */
|
|
84
|
+
export declare const LOCK_FILE = "lock.json";
|
|
85
|
+
/** Version tracking file name */
|
|
86
|
+
export declare const VERSION_FILE = "version.txt";
|
|
87
|
+
/** Keys subdirectory name */
|
|
88
|
+
export declare const KEYS_DIR = "keys";
|
|
89
|
+
/** Wrangler configs subdirectory name */
|
|
90
|
+
export declare const WRANGLER_DIR = "wrangler";
|
|
91
|
+
/**
|
|
92
|
+
* Get paths for new directory structure (.authrim/{env}/)
|
|
93
|
+
*/
|
|
94
|
+
export declare function getEnvironmentPaths(config: PathConfig): EnvironmentPaths;
|
|
95
|
+
/**
|
|
96
|
+
* Get paths for legacy structure (flat files)
|
|
97
|
+
*/
|
|
98
|
+
export declare function getLegacyPaths(baseDir: string, env: string): LegacyPaths;
|
|
99
|
+
/**
|
|
100
|
+
* Get the .authrim root directory path
|
|
101
|
+
*/
|
|
102
|
+
export declare function getAuthrimRoot(baseDir: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Detect which structure is in use
|
|
105
|
+
*
|
|
106
|
+
* Returns:
|
|
107
|
+
* - { type: 'new', envs: [...] } if .authrim/ structure exists with environments
|
|
108
|
+
* - { type: 'legacy', envs: [], legacyEnv: 'name' } if legacy files exist
|
|
109
|
+
* - { type: 'none', envs: [] } if no configuration exists
|
|
110
|
+
*/
|
|
111
|
+
export declare function detectStructure(baseDir: string): StructureInfo;
|
|
112
|
+
/**
|
|
113
|
+
* Check if migration from legacy to new structure is needed
|
|
114
|
+
*/
|
|
115
|
+
export declare function needsMigration(baseDir: string): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* List all available environments
|
|
118
|
+
*
|
|
119
|
+
* For new structure: returns environments from .authrim/
|
|
120
|
+
* For legacy structure: returns environment from .keys/
|
|
121
|
+
* For mixed: returns all found environments
|
|
122
|
+
*/
|
|
123
|
+
export declare function listEnvironments(baseDir: string): string[];
|
|
124
|
+
/**
|
|
125
|
+
* Check if an environment exists (in either structure)
|
|
126
|
+
*/
|
|
127
|
+
export declare function environmentExists(baseDir: string, env: string): boolean;
|
|
128
|
+
export interface ResolvePathsOptions {
|
|
129
|
+
baseDir: string;
|
|
130
|
+
env: string;
|
|
131
|
+
/** Force legacy structure */
|
|
132
|
+
forceLegacy?: boolean;
|
|
133
|
+
/** Force new structure */
|
|
134
|
+
forceNew?: boolean;
|
|
135
|
+
}
|
|
136
|
+
export type ResolvedPaths = {
|
|
137
|
+
type: 'new';
|
|
138
|
+
paths: EnvironmentPaths;
|
|
139
|
+
} | {
|
|
140
|
+
type: 'legacy';
|
|
141
|
+
paths: LegacyPaths;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Resolve paths based on detected structure or explicit options
|
|
145
|
+
*
|
|
146
|
+
* Priority:
|
|
147
|
+
* 1. If forceNew is true, use new structure
|
|
148
|
+
* 2. If forceLegacy is true, use legacy structure
|
|
149
|
+
* 3. If new structure exists for this env, use it
|
|
150
|
+
* 4. If legacy structure exists, use it
|
|
151
|
+
* 5. Default to new structure for new environments
|
|
152
|
+
*/
|
|
153
|
+
export declare function resolvePaths(options: ResolvePathsOptions): ResolvedPaths;
|
|
154
|
+
/**
|
|
155
|
+
* Get the relative path from environment root to keys directory
|
|
156
|
+
* Used for secretsPath in config
|
|
157
|
+
*/
|
|
158
|
+
export declare function getRelativeKeysPath(): string;
|
|
159
|
+
/**
|
|
160
|
+
* Get the relative path for legacy secretsPath
|
|
161
|
+
*/
|
|
162
|
+
export declare function getLegacyRelativeKeysPath(env: string): string;
|
|
163
|
+
/**
|
|
164
|
+
* Validate environment name
|
|
165
|
+
*/
|
|
166
|
+
export declare function validateEnvName(env: string): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Get absolute path, resolving relative paths against baseDir
|
|
169
|
+
*/
|
|
170
|
+
export declare function toAbsolutePath(baseDir: string, relativePath: string): string;
|
|
171
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/core/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AASH,MAAM,WAAW,UAAU;IACzB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,QAAQ,EA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1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAcvE;AAMD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,6BAA6B;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,CAAC;AAE3C;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa,CA6BxE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7D;AAMD;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGpD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAK5E"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path Management Module
|
|
3
|
+
*
|
|
4
|
+
* Centralized path resolution for Authrim configuration files.
|
|
5
|
+
* Supports both legacy (flat files) and new (.authrim/{env}/) structures.
|
|
6
|
+
*
|
|
7
|
+
* Legacy Structure:
|
|
8
|
+
* project/
|
|
9
|
+
* ├── authrim-config.json
|
|
10
|
+
* ├── authrim-lock.json
|
|
11
|
+
* └── .keys/{env}/
|
|
12
|
+
*
|
|
13
|
+
* New Structure:
|
|
14
|
+
* project/
|
|
15
|
+
* └── .authrim/
|
|
16
|
+
* └── {env}/
|
|
17
|
+
* ├── config.json
|
|
18
|
+
* ├── lock.json
|
|
19
|
+
* ├── version.txt
|
|
20
|
+
* └── keys/
|
|
21
|
+
*/
|
|
22
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
23
|
+
import { join, resolve } from 'node:path';
|
|
24
|
+
// =============================================================================
|
|
25
|
+
// Constants
|
|
26
|
+
// =============================================================================
|
|
27
|
+
/** Root directory name for new structure */
|
|
28
|
+
export const AUTHRIM_DIR = '.authrim';
|
|
29
|
+
/** Legacy config file name */
|
|
30
|
+
export const LEGACY_CONFIG_FILE = 'authrim-config.json';
|
|
31
|
+
/** Legacy lock file name */
|
|
32
|
+
export const LEGACY_LOCK_FILE = 'authrim-lock.json';
|
|
33
|
+
/** Legacy keys directory */
|
|
34
|
+
export const LEGACY_KEYS_DIR = '.keys';
|
|
35
|
+
/** New structure config file name */
|
|
36
|
+
export const CONFIG_FILE = 'config.json';
|
|
37
|
+
/** New structure lock file name */
|
|
38
|
+
export const LOCK_FILE = 'lock.json';
|
|
39
|
+
/** Version tracking file name */
|
|
40
|
+
export const VERSION_FILE = 'version.txt';
|
|
41
|
+
/** Keys subdirectory name */
|
|
42
|
+
export const KEYS_DIR = 'keys';
|
|
43
|
+
/** Wrangler configs subdirectory name */
|
|
44
|
+
export const WRANGLER_DIR = 'wrangler';
|
|
45
|
+
// =============================================================================
|
|
46
|
+
// Path Resolution Functions
|
|
47
|
+
// =============================================================================
|
|
48
|
+
/**
|
|
49
|
+
* Get key file paths for a given keys directory
|
|
50
|
+
*/
|
|
51
|
+
function getKeyFilePaths(keysDir) {
|
|
52
|
+
return {
|
|
53
|
+
privateKey: join(keysDir, 'private.pem'),
|
|
54
|
+
publicKey: join(keysDir, 'public.jwk.json'),
|
|
55
|
+
rpTokenEncryptionKey: join(keysDir, 'rp_token_encryption_key.txt'),
|
|
56
|
+
adminApiSecret: join(keysDir, 'admin_api_secret.txt'),
|
|
57
|
+
keyManagerSecret: join(keysDir, 'key_manager_secret.txt'),
|
|
58
|
+
setupToken: join(keysDir, 'setup_token.txt'),
|
|
59
|
+
metadata: join(keysDir, 'metadata.json'),
|
|
60
|
+
emailFrom: join(keysDir, 'email_from.txt'),
|
|
61
|
+
resendApiKey: join(keysDir, 'resend_api_key.txt'),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get paths for new directory structure (.authrim/{env}/)
|
|
66
|
+
*/
|
|
67
|
+
export function getEnvironmentPaths(config) {
|
|
68
|
+
const { baseDir, env } = config;
|
|
69
|
+
const root = join(baseDir, AUTHRIM_DIR, env);
|
|
70
|
+
const keysDir = join(root, KEYS_DIR);
|
|
71
|
+
const wranglerDir = join(root, WRANGLER_DIR);
|
|
72
|
+
return {
|
|
73
|
+
root,
|
|
74
|
+
config: join(root, CONFIG_FILE),
|
|
75
|
+
lock: join(root, LOCK_FILE),
|
|
76
|
+
version: join(root, VERSION_FILE),
|
|
77
|
+
keys: keysDir,
|
|
78
|
+
wrangler: wranglerDir,
|
|
79
|
+
keyFiles: getKeyFilePaths(keysDir),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get paths for legacy structure (flat files)
|
|
84
|
+
*/
|
|
85
|
+
export function getLegacyPaths(baseDir, env) {
|
|
86
|
+
const keysDir = join(baseDir, LEGACY_KEYS_DIR, env);
|
|
87
|
+
return {
|
|
88
|
+
config: join(baseDir, LEGACY_CONFIG_FILE),
|
|
89
|
+
lock: join(baseDir, LEGACY_LOCK_FILE),
|
|
90
|
+
keys: keysDir,
|
|
91
|
+
keyFiles: getKeyFilePaths(keysDir),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the .authrim root directory path
|
|
96
|
+
*/
|
|
97
|
+
export function getAuthrimRoot(baseDir) {
|
|
98
|
+
return join(baseDir, AUTHRIM_DIR);
|
|
99
|
+
}
|
|
100
|
+
// =============================================================================
|
|
101
|
+
// Structure Detection
|
|
102
|
+
// =============================================================================
|
|
103
|
+
/**
|
|
104
|
+
* Detect which structure is in use
|
|
105
|
+
*
|
|
106
|
+
* Returns:
|
|
107
|
+
* - { type: 'new', envs: [...] } if .authrim/ structure exists with environments
|
|
108
|
+
* - { type: 'legacy', envs: [], legacyEnv: 'name' } if legacy files exist
|
|
109
|
+
* - { type: 'none', envs: [] } if no configuration exists
|
|
110
|
+
*/
|
|
111
|
+
export function detectStructure(baseDir) {
|
|
112
|
+
const authrimDir = join(baseDir, AUTHRIM_DIR);
|
|
113
|
+
const legacyConfig = join(baseDir, LEGACY_CONFIG_FILE);
|
|
114
|
+
const legacyLock = join(baseDir, LEGACY_LOCK_FILE);
|
|
115
|
+
const legacyKeys = join(baseDir, LEGACY_KEYS_DIR);
|
|
116
|
+
// Check for new structure first
|
|
117
|
+
if (existsSync(authrimDir)) {
|
|
118
|
+
try {
|
|
119
|
+
const entries = readdirSync(authrimDir, { withFileTypes: true });
|
|
120
|
+
const envs = entries
|
|
121
|
+
.filter((d) => d.isDirectory())
|
|
122
|
+
.filter((d) => {
|
|
123
|
+
// Verify it's a valid environment directory (has config.json or keys/)
|
|
124
|
+
const envPath = join(authrimDir, d.name);
|
|
125
|
+
return existsSync(join(envPath, CONFIG_FILE)) || existsSync(join(envPath, KEYS_DIR));
|
|
126
|
+
})
|
|
127
|
+
.map((d) => d.name);
|
|
128
|
+
if (envs.length > 0) {
|
|
129
|
+
return { type: 'new', envs };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Ignore errors reading directory
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Check for legacy structure
|
|
137
|
+
if (existsSync(legacyConfig) || existsSync(legacyLock)) {
|
|
138
|
+
let legacyEnv;
|
|
139
|
+
// Try to determine env from config file
|
|
140
|
+
if (existsSync(legacyConfig)) {
|
|
141
|
+
try {
|
|
142
|
+
const config = JSON.parse(readFileSync(legacyConfig, 'utf-8'));
|
|
143
|
+
legacyEnv = config.environment?.prefix;
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// Ignore parse errors
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Try to determine env from lock file if not found in config
|
|
150
|
+
if (!legacyEnv && existsSync(legacyLock)) {
|
|
151
|
+
try {
|
|
152
|
+
const lock = JSON.parse(readFileSync(legacyLock, 'utf-8'));
|
|
153
|
+
legacyEnv = lock.env;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Ignore parse errors
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Try to find env from .keys directory
|
|
160
|
+
if (!legacyEnv && existsSync(legacyKeys)) {
|
|
161
|
+
try {
|
|
162
|
+
const entries = readdirSync(legacyKeys, { withFileTypes: true });
|
|
163
|
+
const envDirs = entries.filter((d) => d.isDirectory()).map((d) => d.name);
|
|
164
|
+
if (envDirs.length === 1) {
|
|
165
|
+
legacyEnv = envDirs[0];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// Ignore errors
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { type: 'legacy', envs: [], legacyEnv };
|
|
173
|
+
}
|
|
174
|
+
// Check if only .keys exists (partial legacy setup)
|
|
175
|
+
if (existsSync(legacyKeys)) {
|
|
176
|
+
try {
|
|
177
|
+
const entries = readdirSync(legacyKeys, { withFileTypes: true });
|
|
178
|
+
const envDirs = entries.filter((d) => d.isDirectory()).map((d) => d.name);
|
|
179
|
+
if (envDirs.length > 0) {
|
|
180
|
+
return { type: 'legacy', envs: [], legacyEnv: envDirs[0] };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// Ignore errors
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return { type: 'none', envs: [] };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Check if migration from legacy to new structure is needed
|
|
191
|
+
*/
|
|
192
|
+
export function needsMigration(baseDir) {
|
|
193
|
+
const structure = detectStructure(baseDir);
|
|
194
|
+
return structure.type === 'legacy';
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* List all available environments
|
|
198
|
+
*
|
|
199
|
+
* For new structure: returns environments from .authrim/
|
|
200
|
+
* For legacy structure: returns environment from .keys/
|
|
201
|
+
* For mixed: returns all found environments
|
|
202
|
+
*/
|
|
203
|
+
export function listEnvironments(baseDir) {
|
|
204
|
+
const envs = new Set();
|
|
205
|
+
// Check new structure
|
|
206
|
+
const authrimDir = join(baseDir, AUTHRIM_DIR);
|
|
207
|
+
if (existsSync(authrimDir)) {
|
|
208
|
+
try {
|
|
209
|
+
const entries = readdirSync(authrimDir, { withFileTypes: true });
|
|
210
|
+
entries
|
|
211
|
+
.filter((d) => d.isDirectory())
|
|
212
|
+
.filter((d) => {
|
|
213
|
+
const envPath = join(authrimDir, d.name);
|
|
214
|
+
return existsSync(join(envPath, CONFIG_FILE)) || existsSync(join(envPath, KEYS_DIR));
|
|
215
|
+
})
|
|
216
|
+
.forEach((d) => envs.add(d.name));
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
// Ignore errors
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Check legacy .keys structure
|
|
223
|
+
const legacyKeys = join(baseDir, LEGACY_KEYS_DIR);
|
|
224
|
+
if (existsSync(legacyKeys)) {
|
|
225
|
+
try {
|
|
226
|
+
const entries = readdirSync(legacyKeys, { withFileTypes: true });
|
|
227
|
+
entries
|
|
228
|
+
.filter((d) => d.isDirectory())
|
|
229
|
+
.forEach((d) => envs.add(d.name));
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
// Ignore errors
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return Array.from(envs).sort();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Check if an environment exists (in either structure)
|
|
239
|
+
*/
|
|
240
|
+
export function environmentExists(baseDir, env) {
|
|
241
|
+
// Check new structure
|
|
242
|
+
const newPaths = getEnvironmentPaths({ baseDir, env });
|
|
243
|
+
if (existsSync(newPaths.root) && (existsSync(newPaths.config) || existsSync(newPaths.keys))) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
// Check legacy structure
|
|
247
|
+
const legacyPaths = getLegacyPaths(baseDir, env);
|
|
248
|
+
if (existsSync(legacyPaths.keys)) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Resolve paths based on detected structure or explicit options
|
|
255
|
+
*
|
|
256
|
+
* Priority:
|
|
257
|
+
* 1. If forceNew is true, use new structure
|
|
258
|
+
* 2. If forceLegacy is true, use legacy structure
|
|
259
|
+
* 3. If new structure exists for this env, use it
|
|
260
|
+
* 4. If legacy structure exists, use it
|
|
261
|
+
* 5. Default to new structure for new environments
|
|
262
|
+
*/
|
|
263
|
+
export function resolvePaths(options) {
|
|
264
|
+
const { baseDir, env, forceLegacy, forceNew } = options;
|
|
265
|
+
// Explicit overrides
|
|
266
|
+
if (forceNew) {
|
|
267
|
+
return { type: 'new', paths: getEnvironmentPaths({ baseDir, env }) };
|
|
268
|
+
}
|
|
269
|
+
if (forceLegacy) {
|
|
270
|
+
return { type: 'legacy', paths: getLegacyPaths(baseDir, env) };
|
|
271
|
+
}
|
|
272
|
+
// Check if new structure exists for this environment
|
|
273
|
+
const newPaths = getEnvironmentPaths({ baseDir, env });
|
|
274
|
+
if (existsSync(newPaths.root)) {
|
|
275
|
+
return { type: 'new', paths: newPaths };
|
|
276
|
+
}
|
|
277
|
+
// Check if legacy structure exists
|
|
278
|
+
const legacyPaths = getLegacyPaths(baseDir, env);
|
|
279
|
+
if (existsSync(legacyPaths.config) ||
|
|
280
|
+
existsSync(legacyPaths.lock) ||
|
|
281
|
+
existsSync(legacyPaths.keys)) {
|
|
282
|
+
return { type: 'legacy', paths: legacyPaths };
|
|
283
|
+
}
|
|
284
|
+
// Default to new structure for new environments
|
|
285
|
+
return { type: 'new', paths: newPaths };
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Get the relative path from environment root to keys directory
|
|
289
|
+
* Used for secretsPath in config
|
|
290
|
+
*/
|
|
291
|
+
export function getRelativeKeysPath() {
|
|
292
|
+
return './keys/';
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Get the relative path for legacy secretsPath
|
|
296
|
+
*/
|
|
297
|
+
export function getLegacyRelativeKeysPath(env) {
|
|
298
|
+
return `./.keys/${env}/`;
|
|
299
|
+
}
|
|
300
|
+
// =============================================================================
|
|
301
|
+
// Utility Functions
|
|
302
|
+
// =============================================================================
|
|
303
|
+
/**
|
|
304
|
+
* Validate environment name
|
|
305
|
+
*/
|
|
306
|
+
export function validateEnvName(env) {
|
|
307
|
+
// Must start with lowercase letter, contain only lowercase letters, numbers, and hyphens
|
|
308
|
+
return /^[a-z][a-z0-9-]*$/.test(env);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Get absolute path, resolving relative paths against baseDir
|
|
312
|
+
*/
|
|
313
|
+
export function toAbsolutePath(baseDir, relativePath) {
|
|
314
|
+
if (relativePath.startsWith('/')) {
|
|
315
|
+
return relativePath;
|
|
316
|
+
}
|
|
317
|
+
return resolve(baseDir, relativePath);
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/core/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+D1C,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,4C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M,CAAC;QAC9B,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC;QAC5B,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,EAC5B,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAChD,CAAC;IAED,gDAAgD;IAChD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,GAAW;IACnD,OAAO,WAAW,GAAG,GAAG,CAAC;AAC3B,CAAC;AAED,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,yFAAyF;IACzF,OAAO,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,YAAoB;IAClE,IAAI,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrangler Configuration Sync Utility
|
|
3
|
+
*
|
|
4
|
+
* Manages synchronization between master wrangler.toml files in .authrim/{env}/wrangler/
|
|
5
|
+
* and the deployment copies in packages/ar-star/wrangler.{env}.toml.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Detects manual modifications to deployment configs
|
|
9
|
+
* - Protects user edits from being overwritten
|
|
10
|
+
* - Maintains portable master copies in environment directory
|
|
11
|
+
*/
|
|
12
|
+
import { getEnvironmentPaths } from './paths.js';
|
|
13
|
+
import { type ResourceIds } from './wrangler.js';
|
|
14
|
+
import type { AuthrimConfig } from './config.js';
|
|
15
|
+
export interface WranglerSyncOptions {
|
|
16
|
+
/** Base directory */
|
|
17
|
+
baseDir: string;
|
|
18
|
+
/** Environment name */
|
|
19
|
+
env: string;
|
|
20
|
+
/** Packages directory (where ar-* components are) */
|
|
21
|
+
packagesDir: string;
|
|
22
|
+
/** Force overwrite without prompting */
|
|
23
|
+
force?: boolean;
|
|
24
|
+
/** Dry run - don't actually write files */
|
|
25
|
+
dryRun?: boolean;
|
|
26
|
+
/** Progress callback */
|
|
27
|
+
onProgress?: (msg: string) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface WranglerSyncResult {
|
|
30
|
+
/** Whether sync completed successfully */
|
|
31
|
+
success: boolean;
|
|
32
|
+
/** Components that were synced */
|
|
33
|
+
synced: string[];
|
|
34
|
+
/** Components where manual edits were detected */
|
|
35
|
+
manualEdits: string[];
|
|
36
|
+
/** Components that were skipped */
|
|
37
|
+
skipped: string[];
|
|
38
|
+
/** Errors encountered */
|
|
39
|
+
errors: string[];
|
|
40
|
+
}
|
|
41
|
+
export type SyncAction = 'keep' | 'overwrite' | 'backup';
|
|
42
|
+
export interface ManualEditCallback {
|
|
43
|
+
(component: string, masterPath: string, deployPath: string): Promise<SyncAction>;
|
|
44
|
+
}
|
|
45
|
+
export interface WranglerFileStatus {
|
|
46
|
+
component: string;
|
|
47
|
+
masterExists: boolean;
|
|
48
|
+
deployExists: boolean;
|
|
49
|
+
inSync: boolean;
|
|
50
|
+
masterPath: string;
|
|
51
|
+
deployPath: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the master wrangler.toml path for a component
|
|
55
|
+
*/
|
|
56
|
+
export declare function getMasterWranglerPath(envPaths: ReturnType<typeof getEnvironmentPaths>, component: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Get the deploy wrangler.toml path for a component
|
|
59
|
+
*/
|
|
60
|
+
export declare function getDeployWranglerPath(packagesDir: string, component: string, env: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Check the sync status of all wrangler configs
|
|
63
|
+
*/
|
|
64
|
+
export declare function checkWranglerStatus(options: Pick<WranglerSyncOptions, 'baseDir' | 'env' | 'packagesDir'>): Promise<WranglerFileStatus[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Generate and save master wrangler.toml files to .authrim/{env}/wrangler/
|
|
67
|
+
*/
|
|
68
|
+
export declare function saveMasterWranglerConfigs(config: AuthrimConfig, resourceIds: ResourceIds, options: Pick<WranglerSyncOptions, 'baseDir' | 'env' | 'dryRun' | 'onProgress'>): Promise<{
|
|
69
|
+
success: boolean;
|
|
70
|
+
files: string[];
|
|
71
|
+
errors: string[];
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Sync master wrangler configs to deployment locations
|
|
75
|
+
*
|
|
76
|
+
* This copies from .authrim/{env}/wrangler/ to packages/ar-star/wrangler.{env}.toml
|
|
77
|
+
* while detecting and protecting manual edits.
|
|
78
|
+
*/
|
|
79
|
+
export declare function syncWranglerConfigs(options: WranglerSyncOptions, onManualEdit?: ManualEditCallback): Promise<WranglerSyncResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Backup deploy wrangler configs before sync
|
|
82
|
+
*/
|
|
83
|
+
export declare function backupDeployConfigs(options: Pick<WranglerSyncOptions, 'env' | 'packagesDir' | 'onProgress'>): Promise<string[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Restore deploy wrangler configs from backup
|
|
86
|
+
*/
|
|
87
|
+
export declare function restoreDeployConfigs(options: Pick<WranglerSyncOptions, 'env' | 'packagesDir' | 'onProgress'>): Promise<string[]>;
|
|
88
|
+
//# sourceMappingURL=wrangler-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler-sync.d.ts","sourceRoot":"","sources":["../../src/core/wrangler-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO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