zoho-sites-dev-cli 0.0.0-stage → 1.0.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.
- package/README.md +396 -2
- package/bin/zoho-sites-dev-cli.js +108 -0
- package/config/default.json +26 -0
- package/index.js +6 -0
- package/package.json +55 -4
- package/src/commands/auth.js +125 -0
- package/src/commands/create.js +175 -0
- package/src/commands/deploy.js +409 -0
- package/src/commands/generate-zip.js +49 -0
- package/src/commands/index.js +23 -0
- package/src/commands/init-tailwind.js +57 -0
- package/src/commands/init.js +449 -0
- package/src/commands/install.js +90 -0
- package/src/commands/login.js +253 -0
- package/src/commands/pull.js +41 -0
- package/src/commands/serve.js +163 -0
- package/src/compilers/css-compiler.js +230 -0
- package/src/compilers/css-ignore-loader.js +33 -0
- package/src/compilers/plugins/index.js +12 -0
- package/src/compilers/plugins/root-selector-transform-plugin.js +79 -0
- package/src/compilers/tailwind-compiler.js +102 -0
- package/src/compilers/webpack-compiler.js +512 -0
- package/src/compilers/webpack-config.js +103 -0
- package/src/config/constants.js +164 -0
- package/src/config/environments/audiences.js +19 -0
- package/src/config/environments/index.js +78 -0
- package/src/config/environments/internal.js +72 -0
- package/src/config/environments/production.js +54 -0
- package/src/locales/en.json +216 -0
- package/src/services/devServer.js +583 -0
- package/src/services/oauthService.js +796 -0
- package/src/templates/component/fields.json +6 -0
- package/src/templates/component/index.js +11 -0
- package/src/templates/component/llm.md +9 -0
- package/src/templates/component/meta.json +9 -0
- package/src/templates/component/styles.css +3 -0
- package/src/templates/oauth/complete.html +41 -0
- package/src/templates/oauth/error.html +69 -0
- package/src/templates/oauth/invalid-request.html +58 -0
- package/src/templates/oauth/loading.html +80 -0
- package/src/templates/oauth/not-found.html +33 -0
- package/src/templates/oauth/success.html +70 -0
- package/src/templates/oauth/timeout.html +56 -0
- package/src/templates/oauth/token-error.html +57 -0
- package/src/utils/cliName.js +35 -0
- package/src/utils/configUtil.js +67 -0
- package/src/utils/httpUtil.js +351 -0
- package/src/utils/i18n.js +222 -0
- package/src/utils/loadingUtil.js +190 -0
- package/src/utils/secureConfig.js +75 -0
- package/src/utils/secureStorage.js +230 -0
- package/src/utils/templateLoader.js +89 -0
- package/src/utils/urlUtil.js +372 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple loading spinner for CLI
|
|
3
|
+
* Provides visual feedback for long-running operations
|
|
4
|
+
*/
|
|
5
|
+
class LoadingSpinner {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
8
|
+
this.currentFrame = 0;
|
|
9
|
+
this.interval = null;
|
|
10
|
+
this.message = '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
start(message = 'Loading...') {
|
|
14
|
+
this.stop(); // Stop any existing spinner
|
|
15
|
+
this.message = message;
|
|
16
|
+
this.currentFrame = 0;
|
|
17
|
+
|
|
18
|
+
// Hide cursor
|
|
19
|
+
process.stdout.write('\x1B[?25l');
|
|
20
|
+
|
|
21
|
+
this.interval = setInterval(() => {
|
|
22
|
+
process.stdout.write('\r\x1B[K'); // Clear line
|
|
23
|
+
process.stdout.write(`${this.frames[this.currentFrame]} ${this.message}`);
|
|
24
|
+
this.currentFrame = (this.currentFrame + 1) % this.frames.length;
|
|
25
|
+
}, 80);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
stop(finalMessage = null) {
|
|
29
|
+
if (this.interval) {
|
|
30
|
+
clearInterval(this.interval);
|
|
31
|
+
this.interval = null;
|
|
32
|
+
|
|
33
|
+
// Clear the line and show final message
|
|
34
|
+
process.stdout.write('\r\x1B[K');
|
|
35
|
+
if (finalMessage) {
|
|
36
|
+
console.log(finalMessage);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Show cursor
|
|
40
|
+
process.stdout.write('\x1B[?25h');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
update(message) {
|
|
45
|
+
this.message = message;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Loading utility class for managing loading states and messages
|
|
51
|
+
*/
|
|
52
|
+
class LoadingUtil {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.spinner = new LoadingSpinner();
|
|
55
|
+
this.isEnabled = true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Enable or disable loading spinner
|
|
60
|
+
* @param {boolean} enabled - Whether to show spinner
|
|
61
|
+
*/
|
|
62
|
+
setEnabled(enabled) {
|
|
63
|
+
this.isEnabled = enabled;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Start loading with a message
|
|
68
|
+
* @param {string} message - Loading message to display
|
|
69
|
+
*/
|
|
70
|
+
start(message = 'Loading...') {
|
|
71
|
+
if (this.isEnabled) {
|
|
72
|
+
this.spinner.start(message);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Stop loading with optional final message
|
|
78
|
+
* @param {string} finalMessage - Final message to display
|
|
79
|
+
*/
|
|
80
|
+
stop(finalMessage = null) {
|
|
81
|
+
if (this.isEnabled) {
|
|
82
|
+
this.spinner.stop(finalMessage);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Update the loading message
|
|
88
|
+
* @param {string} message - New message to display
|
|
89
|
+
*/
|
|
90
|
+
update(message) {
|
|
91
|
+
if (this.isEnabled) {
|
|
92
|
+
this.spinner.update(message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Generate appropriate loading message based on operation type
|
|
98
|
+
* @param {string} operation - Type of operation (auth, sites, deploy, etc.)
|
|
99
|
+
* @param {string} method - HTTP method (GET, POST, etc.)
|
|
100
|
+
* @returns {string} Loading message
|
|
101
|
+
*/
|
|
102
|
+
getLoadingMessage(operation, method = 'GET') {
|
|
103
|
+
const methodUpper = method.toUpperCase();
|
|
104
|
+
|
|
105
|
+
switch (operation) {
|
|
106
|
+
case 'auth':
|
|
107
|
+
case 'oauth':
|
|
108
|
+
return '🔐 Authenticating...';
|
|
109
|
+
|
|
110
|
+
case 'sites':
|
|
111
|
+
return `🌐 ${methodUpper === 'GET' ? 'Fetching' : 'Updating'} site data...`;
|
|
112
|
+
|
|
113
|
+
case 'deploy':
|
|
114
|
+
return '🚀 Deploying...';
|
|
115
|
+
|
|
116
|
+
case 'upload':
|
|
117
|
+
return '📤 Uploading files...';
|
|
118
|
+
|
|
119
|
+
case 'download':
|
|
120
|
+
return '📥 Downloading...';
|
|
121
|
+
|
|
122
|
+
case 'init':
|
|
123
|
+
return '🏗️ Initializing project...';
|
|
124
|
+
|
|
125
|
+
case 'build':
|
|
126
|
+
return '🔨 Building project...';
|
|
127
|
+
|
|
128
|
+
case 'serve':
|
|
129
|
+
return '🌐 Starting development server...';
|
|
130
|
+
|
|
131
|
+
case 'login':
|
|
132
|
+
return '🔑 Logging in...';
|
|
133
|
+
|
|
134
|
+
case 'logout':
|
|
135
|
+
return '👋 Logging out...';
|
|
136
|
+
|
|
137
|
+
default:
|
|
138
|
+
return `⏳ ${methodUpper} request in progress...`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Generate loading message from URL
|
|
144
|
+
* @param {string} url - Request URL
|
|
145
|
+
* @param {string} method - HTTP method
|
|
146
|
+
* @returns {string} Loading message
|
|
147
|
+
*/
|
|
148
|
+
getLoadingMessageFromUrl(url, method = 'GET') {
|
|
149
|
+
if (!url) return this.getLoadingMessage('default', method);
|
|
150
|
+
|
|
151
|
+
if (url.includes('/auth/') || url.includes('/oauth/')) {
|
|
152
|
+
return this.getLoadingMessage('auth', method);
|
|
153
|
+
} else if (url.includes('/sites/')) {
|
|
154
|
+
return this.getLoadingMessage('sites', method);
|
|
155
|
+
} else if (url.includes('/deploy')) {
|
|
156
|
+
return this.getLoadingMessage('deploy', method);
|
|
157
|
+
} else if (url.includes('/upload')) {
|
|
158
|
+
return this.getLoadingMessage('upload', method);
|
|
159
|
+
} else if (url.includes('/download')) {
|
|
160
|
+
return this.getLoadingMessage('download', method);
|
|
161
|
+
} else {
|
|
162
|
+
return this.getLoadingMessage('default', method);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Execute a function with loading spinner
|
|
168
|
+
* @param {Function} fn - Function to execute
|
|
169
|
+
* @param {string} message - Loading message
|
|
170
|
+
* @param {string} successMessage - Success message
|
|
171
|
+
* @param {string} errorMessage - Error message
|
|
172
|
+
* @returns {Promise} Result of the function
|
|
173
|
+
*/
|
|
174
|
+
async withLoading(fn, message = 'Loading...', successMessage = '✅ Completed', errorMessage = '❌ Failed') {
|
|
175
|
+
try {
|
|
176
|
+
this.start(message);
|
|
177
|
+
const result = await fn();
|
|
178
|
+
this.stop(successMessage);
|
|
179
|
+
return result;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
this.stop(errorMessage);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Create a singleton instance
|
|
188
|
+
const loadingUtil = new LoadingUtil();
|
|
189
|
+
|
|
190
|
+
module.exports = { LoadingUtil, LoadingSpinner, loadingUtil };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { join } = require('path');
|
|
4
|
+
const { homedir } = require('os');
|
|
5
|
+
const { i18n } = require('./i18n.js');
|
|
6
|
+
const { ALGORITHM } = require('../config/constants.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SecureConfig {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.configDir = join(homedir(), '.zs-cli');
|
|
14
|
+
this.configFile = join(this.configDir, 'client.enc');
|
|
15
|
+
this.keyFile = join(this.configDir, '.key');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Generate or retrieve encryption key
|
|
19
|
+
getEncryptionKey() {
|
|
20
|
+
try {
|
|
21
|
+
if (fs.existsSync(this.keyFile)) {
|
|
22
|
+
return fs.readFileSync(this.keyFile);
|
|
23
|
+
} else {
|
|
24
|
+
// Generate new key
|
|
25
|
+
const key = crypto.randomBytes(32);
|
|
26
|
+
this.ensureConfigDir();
|
|
27
|
+
fs.writeFileSync(this.keyFile, key, { mode: 0o600 });
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
// Fallback to derived key if key file cannot be created
|
|
32
|
+
return crypto.scryptSync('zs-cli-key', 'salt', 32);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Ensure config directory exists
|
|
37
|
+
ensureConfigDir() {
|
|
38
|
+
if (!fs.existsSync(this.configDir)) {
|
|
39
|
+
fs.mkdirSync(this.configDir, { recursive: true, mode: 0o700 });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Encrypt data
|
|
44
|
+
encrypt(text, key) {
|
|
45
|
+
const iv = crypto.randomBytes(16);
|
|
46
|
+
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
|
|
47
|
+
|
|
48
|
+
let encrypted = cipher.update(text, 'utf8', 'hex');
|
|
49
|
+
encrypted += cipher.final('hex');
|
|
50
|
+
|
|
51
|
+
const authTag = cipher.getAuthTag();
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
iv: iv.toString('hex'),
|
|
55
|
+
authTag: authTag.toString('hex'),
|
|
56
|
+
encrypted: encrypted
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Decrypt data
|
|
61
|
+
decrypt(encryptedData, key) {
|
|
62
|
+
const decipher = crypto.createDecipheriv(ALGORITHM, key, Buffer.from(encryptedData.iv, 'hex'));
|
|
63
|
+
|
|
64
|
+
decipher.setAuthTag(Buffer.from(encryptedData.authTag, 'hex'));
|
|
65
|
+
|
|
66
|
+
let decrypted = decipher.update(encryptedData.encrypted, 'hex', 'utf8');
|
|
67
|
+
decrypted += decipher.final('utf8');
|
|
68
|
+
|
|
69
|
+
return decrypted;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = SecureConfig;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SecureStorage – persists user auth data and environment config for the ZS CLI.
|
|
3
|
+
*
|
|
4
|
+
* Layout of ~/.zs-cli/config.enc (AES-encrypted JSON):
|
|
5
|
+
* {
|
|
6
|
+
* user_name, email, environment,
|
|
7
|
+
* expires_at, last_login,
|
|
8
|
+
* access_token, refresh_token,
|
|
9
|
+
* // For DEV environment only:
|
|
10
|
+
* dev_auth_url, dev_site_url, dev_site_builder_url
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const crypto = require('crypto');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const { join } = require('path');
|
|
17
|
+
const { homedir } = require('os');
|
|
18
|
+
const { ENCRYPTION_KEY, ALGORITHM } = require('../config/constants.js');
|
|
19
|
+
|
|
20
|
+
const CONFIG_DIR = join(homedir(), '.zs-cli');
|
|
21
|
+
const CONFIG_FILE = join(CONFIG_DIR, 'config.enc');
|
|
22
|
+
|
|
23
|
+
class SecureStorage {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.ensureConfigDir();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
ensureConfigDir() {
|
|
29
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
30
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Encryption helpers
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
encrypt(text) {
|
|
39
|
+
const key = crypto.scryptSync(ENCRYPTION_KEY, 'salt', 32);
|
|
40
|
+
const iv = crypto.randomBytes(16);
|
|
41
|
+
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
|
|
42
|
+
|
|
43
|
+
let encrypted = cipher.update(text, 'utf8', 'hex');
|
|
44
|
+
encrypted += cipher.final('hex');
|
|
45
|
+
|
|
46
|
+
return iv.toString('hex') + ':' + encrypted;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
decrypt(encryptedText) {
|
|
50
|
+
const key = crypto.scryptSync(ENCRYPTION_KEY, 'salt', 32);
|
|
51
|
+
const textParts = encryptedText.split(':');
|
|
52
|
+
const iv = Buffer.from(textParts.shift(), 'hex');
|
|
53
|
+
const encrypted = textParts.join(':');
|
|
54
|
+
const decipher = crypto.createDecipheriv(ALGORITHM, key, iv);
|
|
55
|
+
|
|
56
|
+
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
|
57
|
+
decrypted += decipher.final('utf8');
|
|
58
|
+
|
|
59
|
+
return decrypted;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Store / retrieve auth data
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Persist auth data, including tokens, in the encrypted config file.
|
|
68
|
+
*
|
|
69
|
+
* @param {Object} authData
|
|
70
|
+
* @param {string} authData.access_token
|
|
71
|
+
* @param {string} authData.refresh_token
|
|
72
|
+
* @param {string} authData.user_name
|
|
73
|
+
* @param {string} authData.email
|
|
74
|
+
* @param {string} authData.environment - 'dev' | 'usdc'
|
|
75
|
+
* @param {string} authData.expires_at
|
|
76
|
+
* @param {string} [authData.dev_auth_url] - required when environment=dev
|
|
77
|
+
* @param {string} [authData.dev_site_url] - required when environment=dev
|
|
78
|
+
* @param {string} [authData.dev_site_builder_url] - optional, only for dev
|
|
79
|
+
*/
|
|
80
|
+
async storeAuthData(authData) {
|
|
81
|
+
const {
|
|
82
|
+
access_token,
|
|
83
|
+
refresh_token,
|
|
84
|
+
user_name,
|
|
85
|
+
email,
|
|
86
|
+
environment,
|
|
87
|
+
expires_at,
|
|
88
|
+
dev_auth_url,
|
|
89
|
+
dev_site_url,
|
|
90
|
+
dev_site_builder_url,
|
|
91
|
+
...otherData
|
|
92
|
+
} = authData;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const configData = {
|
|
96
|
+
access_token,
|
|
97
|
+
refresh_token,
|
|
98
|
+
user_name,
|
|
99
|
+
email,
|
|
100
|
+
environment,
|
|
101
|
+
expires_at,
|
|
102
|
+
last_login: new Date().toISOString(),
|
|
103
|
+
...(dev_auth_url && { dev_auth_url }),
|
|
104
|
+
...(dev_site_url && { dev_site_url }),
|
|
105
|
+
...(dev_site_builder_url && { dev_site_builder_url }),
|
|
106
|
+
...otherData,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
fs.writeFileSync(CONFIG_FILE, this.encrypt(JSON.stringify(configData)), { mode: 0o600 });
|
|
110
|
+
return true;
|
|
111
|
+
} catch (_) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Retrieve the full auth data object from the encrypted config file.
|
|
118
|
+
*/
|
|
119
|
+
async getAuthData() {
|
|
120
|
+
try {
|
|
121
|
+
if (!fs.existsSync(CONFIG_FILE)) return null;
|
|
122
|
+
|
|
123
|
+
const encryptedData = fs.readFileSync(CONFIG_FILE, 'utf8');
|
|
124
|
+
return JSON.parse(this.decrypt(encryptedData));
|
|
125
|
+
} catch (_) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// Convenience getters
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
async isLoggedIn() {
|
|
135
|
+
const authData = await this.getAuthData();
|
|
136
|
+
if (!authData || !authData.access_token) return false;
|
|
137
|
+
|
|
138
|
+
if (authData.expires_at) {
|
|
139
|
+
if (new Date() >= new Date(authData.expires_at)) return false;
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async getCurrentUser() {
|
|
145
|
+
const authData = await this.getAuthData();
|
|
146
|
+
if (!authData) return null;
|
|
147
|
+
return {
|
|
148
|
+
user_name: authData.user_name,
|
|
149
|
+
email: authData.email,
|
|
150
|
+
environment: authData.environment,
|
|
151
|
+
last_login: authData.last_login,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// DEV environment URL helpers
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
|
|
159
|
+
async getDevAuthUrl() {
|
|
160
|
+
const authData = await this.getAuthData();
|
|
161
|
+
return authData?.dev_auth_url || null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async getDevSiteUrl() {
|
|
165
|
+
const authData = await this.getAuthData();
|
|
166
|
+
return authData?.dev_site_url || null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async getDevSiteBuilderUrl() {
|
|
170
|
+
const authData = await this.getAuthData();
|
|
171
|
+
return authData?.dev_site_builder_url || null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
// Token management
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
async clearAuthData() {
|
|
179
|
+
try {
|
|
180
|
+
if (fs.existsSync(CONFIG_FILE)) fs.unlinkSync(CONFIG_FILE);
|
|
181
|
+
return true;
|
|
182
|
+
} catch (_) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async updateAccessToken(newAccessToken, expiresAt = null) {
|
|
188
|
+
try {
|
|
189
|
+
const authData = await this.getAuthData();
|
|
190
|
+
if (!authData?.email) throw new Error('No user logged in');
|
|
191
|
+
|
|
192
|
+
const fileData = {
|
|
193
|
+
...authData,
|
|
194
|
+
access_token: newAccessToken,
|
|
195
|
+
...(expiresAt && { expires_at: expiresAt }),
|
|
196
|
+
};
|
|
197
|
+
fs.writeFileSync(CONFIG_FILE, this.encrypt(JSON.stringify(fileData)), { mode: 0o600 });
|
|
198
|
+
return true;
|
|
199
|
+
} catch (_) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ---------------------------------------------------------------------------
|
|
205
|
+
// Static helpers (used by UrlUtil and other modules without an instance)
|
|
206
|
+
// ---------------------------------------------------------------------------
|
|
207
|
+
|
|
208
|
+
static async getEnvironment() {
|
|
209
|
+
const storage = new SecureStorage();
|
|
210
|
+
const authData = await storage.getAuthData();
|
|
211
|
+
return authData?.environment || null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static async getDevAuthUrl() {
|
|
215
|
+
const storage = new SecureStorage();
|
|
216
|
+
return storage.getDevAuthUrl();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
static async getDevSiteUrl() {
|
|
220
|
+
const storage = new SecureStorage();
|
|
221
|
+
return storage.getDevSiteUrl();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static async getDevSiteBuilderUrl() {
|
|
225
|
+
const storage = new SecureStorage();
|
|
226
|
+
return storage.getDevSiteBuilderUrl();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module.exports = SecureStorage;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
class TemplateLoader {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.templatesDir = path.join(__dirname, '../templates');
|
|
7
|
+
this.cache = new Map();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Load a template from file
|
|
12
|
+
* @param {string} templatePath - Path to template file relative to templates directory
|
|
13
|
+
* @returns {string} Template content
|
|
14
|
+
*/
|
|
15
|
+
loadTemplate(templatePath) {
|
|
16
|
+
// Check cache first for performance
|
|
17
|
+
if (this.cache.has(templatePath)) {
|
|
18
|
+
return this.cache.get(templatePath);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const fullPath = path.join(this.templatesDir, templatePath);
|
|
23
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
24
|
+
|
|
25
|
+
// Cache the template content
|
|
26
|
+
this.cache.set(templatePath, content);
|
|
27
|
+
|
|
28
|
+
return content;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(`Template not found: ${templatePath}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Render a template with data substitution
|
|
36
|
+
* @param {string} templatePath - Path to template file
|
|
37
|
+
* @param {Object} data - Data to substitute in template
|
|
38
|
+
* @returns {string} Rendered template
|
|
39
|
+
*/
|
|
40
|
+
renderTemplate(templatePath, data = {}) {
|
|
41
|
+
const template = this.loadTemplate(templatePath);
|
|
42
|
+
|
|
43
|
+
// Simple placeholder replacement
|
|
44
|
+
return template.replace(/\{\{(\w+)\}\}/g, (match, key) => {
|
|
45
|
+
return data[key] !== undefined ? data[key] : match;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Clear template cache (useful for development)
|
|
51
|
+
*/
|
|
52
|
+
clearCache() {
|
|
53
|
+
this.cache.clear();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Preload commonly used templates
|
|
58
|
+
*/
|
|
59
|
+
preloadTemplates() {
|
|
60
|
+
const commonTemplates = [
|
|
61
|
+
'oauth/error.html',
|
|
62
|
+
'oauth/loading.html',
|
|
63
|
+
'oauth/success.html',
|
|
64
|
+
'oauth/token-error.html',
|
|
65
|
+
'oauth/timeout.html',
|
|
66
|
+
'oauth/complete.html',
|
|
67
|
+
'oauth/invalid-request.html',
|
|
68
|
+
'oauth/not-found.html',
|
|
69
|
+
'component/index.js',
|
|
70
|
+
'component/fields.json',
|
|
71
|
+
'component/meta.json',
|
|
72
|
+
'component/styles.css',
|
|
73
|
+
'component/llm.md'
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
commonTemplates.forEach(templatePath => {
|
|
77
|
+
try {
|
|
78
|
+
this.loadTemplate(templatePath);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
// Silently skip templates that can't be preloaded
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Export singleton instance
|
|
87
|
+
const templateLoader = new TemplateLoader();
|
|
88
|
+
|
|
89
|
+
module.exports = { templateLoader, TemplateLoader };
|