zoho-sites-dev-cli 1.0.0 → 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 CHANGED
@@ -5,27 +5,27 @@ Command line interface for managing Zoho Sites components.
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install -g zoho-sites-cli
8
+ npm install -g zoho-sites-dev-cli
9
9
  ```
10
10
 
11
- **Note:** This CLI tool uses CommonJS modules and requires Node.js 14+ for compatibility. The examples below use `zs` for brevity — if you installed `zoho-sites-cli`, run `zoho-sites-cli <command>` instead (e.g. `zoho-sites-cli login`).
11
+ **Note:** This CLI tool uses CommonJS modules and requires Node.js 14+ for compatibility.
12
12
 
13
13
  ## Available Commands
14
14
 
15
- - `zs login` - Login to your account
16
- - `zs logout` - Logout from your account
17
- - `zs whoami` - Show current user information
18
- - `zs status` - Show authentication status
19
- - `zs init` - Initialize a new project
20
- - `zs init-tailwind` - Add Tailwind CSS config to the current project
21
- - `zs pull` - Pull components from server
22
- - `zs create <component_name>` - Create a new component
23
- - `zs push <component_name>` - Push a component to server
24
- - `zs serve [--no-open]` - Start development server (use --no-open to prevent browser from opening)
25
-
26
- - `zs deploy` - Deploy all components to server
27
- - `zs generate-zip [-o path]` - Generate deployment zip (widgets.zip) for server team verification
28
- - `zs install <pkg> [pkg2 ...]` - Create `package.json` if missing and run `npm install` for the specified packages. Use `-D`/`--dev` to install as devDependencies.
15
+ - `zoho-sites-dev-cli login` - Login to your account
16
+ - `zoho-sites-dev-cli logout` - Logout from your account
17
+ - `zoho-sites-dev-cli whoami` - Show current user information
18
+ - `zoho-sites-dev-cli status` - Show authentication status
19
+ - `zoho-sites-dev-cli init` - Initialize a new project
20
+ - `zoho-sites-dev-cli init-tailwind` - Add Tailwind CSS config to the current project
21
+ - `zoho-sites-dev-cli pull` - Pull components from server
22
+ - `zoho-sites-dev-cli create <component_name>` - Create a new component
23
+ - `zoho-sites-dev-cli push <component_name>` - Push a component to server
24
+ - `zoho-sites-dev-cli serve [--no-open]` - Start development server (use --no-open to prevent browser from opening)
25
+
26
+ - `zoho-sites-dev-cli deploy` - Deploy all components to server
27
+ - `zoho-sites-dev-cli generate-zip [-o path]` - Generate deployment zip (widgets.zip) for server team verification
28
+ - `zoho-sites-dev-cli install <pkg> [pkg2 ...]` - Create `package.json` if missing and run `npm install` for the specified packages. Use `-D`/`--dev` to install as devDependencies.
29
29
 
30
30
 
31
31
  ## Quick Start
@@ -33,36 +33,36 @@ npm install -g zoho-sites-cli
33
33
  1. Install the CLI:
34
34
 
35
35
  ```bash
36
- npm install -g zoho-sites-cli
36
+ npm install -g zoho-sites-dev-cli
37
37
  ```
38
38
 
39
39
  2. Login to your account:
40
40
 
41
41
  ```bash
42
- zs login
42
+ zoho-sites-dev-cli login
43
43
  ```
44
44
 
45
45
  3. Initialize a new project:
46
46
 
47
47
  ```bash
48
- zs init
48
+ zoho-sites-dev-cli init
49
49
  ```
50
50
 
51
51
  4. Create a new component:
52
52
 
53
53
  ```bash
54
- zs create my-component
54
+ zoho-sites-dev-cli create my-component
55
55
  ```
56
56
 
57
57
  5. Start development server:
58
58
 
59
59
  ```bash
60
- zs serve
60
+ zoho-sites-dev-cli serve
61
61
  ```
62
62
 
63
63
  6. Deploy your components:
64
64
  ```bash
65
- zs deploy
65
+ zoho-sites-dev-cli deploy
66
66
  ```
67
67
 
68
68
  ## Usage Examples
@@ -73,22 +73,22 @@ Login to your account:
73
73
 
74
74
  ```bash
75
75
  # Install packages (creates package.json if missing)
76
- zs install axios @babel/core
76
+ zoho-sites-dev-cli install axios @babel/core
77
77
 
78
78
  # Install as devDependencies
79
- zs install -D jest @babel/preset-env
79
+ zoho-sites-dev-cli install -D jest @babel/preset-env
80
80
 
81
81
  # Start the login process
82
- zs login
82
+ zoho-sites-dev-cli login
83
83
 
84
84
  # Check your login status
85
- zs status
85
+ zoho-sites-dev-cli status
86
86
 
87
87
  # Show your current user info
88
- zs whoami
88
+ zoho-sites-dev-cli whoami
89
89
 
90
90
  # Logout when done
91
- zs logout
91
+ zoho-sites-dev-cli logout
92
92
  ```
93
93
 
94
94
  ### Component Management
@@ -97,30 +97,30 @@ Create and manage components:
97
97
 
98
98
  ```bash
99
99
  # Initialize a new project (automatically handles namespace setup)
100
- zs init
100
+ zoho-sites-dev-cli init
101
101
 
102
102
  # Create a new component
103
- zs create my-component
103
+ zoho-sites-dev-cli create my-component
104
104
 
105
105
  # Pull existing components
106
- zs pull
106
+ zoho-sites-dev-cli pull
107
107
 
108
108
  # Push a component to server
109
- zs push my-component
109
+ zoho-sites-dev-cli push my-component
110
110
 
111
111
 
112
112
  ```
113
113
 
114
- The `zs init` command will:
114
+ The `zoho-sites-dev-cli init` command will:
115
115
 
116
116
  1. Fetch your account details (`GET /api/v3/account`) to resolve your asoid (used as `x-site-id` for resource APIs)
117
117
  2. Fetch available workspaces and let you select one (or auto-select if you have only one)
118
118
  3. Fetch apps in that workspace and let you select an app (or auto-select if you have only one)
119
119
  4. Create project structure with configuration files:
120
120
  - `.zs` at project root (project metadata including account `asoid`, workspace, app name, and namespace)
121
- - `webpack.overrides.js` for optional bundling; use `zs init-tailwind` to add Tailwind CSS
121
+ - `webpack.overrides.js` for optional bundling; use `zoho-sites-dev-cli init-tailwind` to add Tailwind CSS
122
122
  - `package.json` initialized with the current user as author and handy scripts
123
- 5. Optionally, run `zs pull` to fetch components (reads `<siteDomain>/<namespace>/__widgets/dist/meta.json` and downloads component files into your project with a progress bar)
123
+ 5. Optionally, run `zoho-sites-dev-cli pull` to fetch components (reads `<siteDomain>/<namespace>/__widgets/dist/meta.json` and downloads component files into your project with a progress bar)
124
124
 
125
125
  Resulting structure example:
126
126
 
@@ -138,10 +138,10 @@ Start the development server with automatic file watching:
138
138
 
139
139
  ```bash
140
140
  # Start server with default settings (opens browser automatically)
141
- zs serve
141
+ zoho-sites-dev-cli serve
142
142
 
143
143
  # Start server without opening browser
144
- zs serve --no-open
144
+ zoho-sites-dev-cli serve --no-open
145
145
 
146
146
  # Server automatically watches for file changes and clears cache
147
147
  # Access components at http://localhost:8083
@@ -240,7 +240,7 @@ npm i -D webpack webpack-cli @babel/core babel-loader @babel/preset-env @babel/p
240
240
 
241
241
  ```bash
242
242
  # Start the development server
243
- zs serve
243
+ zoho-sites-dev-cli serve
244
244
 
245
245
  # In another terminal, create a test component
246
246
  mkdir test-component && cd test-component
@@ -275,7 +275,7 @@ Deploy all components in the current directory:
275
275
  cd my-zs-project
276
276
 
277
277
  # Deploy all components
278
- zs deploy
278
+ zoho-sites-dev-cli deploy
279
279
  ```
280
280
 
281
281
  The deploy command will:
@@ -322,11 +322,6 @@ The deploy command will:
322
322
 
323
323
  ## Environment Variables
324
324
 
325
- ### Authentication
326
-
327
- - `ZS_CLIENT_ID` - OAuth client ID (optional)
328
- - `ZS_CLIENT_SECRET` - OAuth client secret (optional)
329
-
330
325
  ### Development
331
326
 
332
327
  - `ZS_DEV_PORT` - Development server port (default: 3000)
@@ -355,7 +350,7 @@ The ZS SDK includes powerful compilers for transforming components and CSS:
355
350
  Bundles components using webpack configuration for optimal performance:
356
351
 
357
352
  ```javascript
358
- const { webpackCompiler } = require("zoho-sites-cli/src/compilers/webpack-compiler.js");
353
+ const { webpackCompiler } = require("zoho-sites-dev-cli/src/compilers/webpack-compiler.js");
359
354
 
360
355
  // Bundle components using webpack
361
356
  const components = ["MyComponent", "AnotherComponent"];
@@ -367,7 +362,7 @@ const bundledCode = await webpackCompiler.bundleWithWebpack(components);
367
362
  Processes CSS with PostCSS, including prefixing, minification, and validation:
368
363
 
369
364
  ```javascript
370
- const { compileCSS } = require("zoho-sites-cli/src/compilers/css-compiler.js");
365
+ const { compileCSS } = require("zoho-sites-dev-cli/src/compilers/css-compiler.js");
371
366
 
372
367
  // Compile base64 encoded CSS
373
368
  const base64CSS = Buffer.from(cssCode).toString("base64");
@@ -378,7 +373,7 @@ const processedCSS = await compileCSS(base64CSS, "ComponentName");
378
373
 
379
374
  You can use Tailwind utility classes in your widgets. The SDK includes Tailwind at build time—you do not need to install `tailwindcss` in your project.
380
375
 
381
- - **Config:** Add `tailwind.config.js` at project root by running `zs init-tailwind`. Edit `content` to your component paths (e.g. `["./*/index.js", "./*/**/*.js", "./*/styles.css"]`) so only used utilities are generated.
376
+ - **Config:** Add `tailwind.config.js` at project root by running `zoho-sites-dev-cli init-tailwind`. Edit `content` to your component paths (e.g. `["./*/index.js", "./*/**/*.js", "./*/styles.css"]`) so only used utilities are generated.
382
377
  - **Scoping:** All Tailwind output is scoped with `[data-element-type^="namespace_"]` so styles apply only inside your widget roots and do not clash with other widgets.
383
378
  - **Merge:** Tailwind CSS is built once per namespace and prepended to the combined `dist/styles.css` along with your component CSS.
384
379
  - **Deploy:** Include `tailwind.config.js` (and optional `postcss.config.js`) in your project; they are copied into the deploy package automatically.
@@ -13,11 +13,12 @@ const { generateZip } = require('../src/commands/generate-zip.js'); //No I18N
13
13
  const { install } = require('../src/commands/install.js'); //No I18N
14
14
 
15
15
  const { i18n } = require('../src/utils/i18n.js'); //No I18N
16
+ const { getCliName } = require('../src/utils/cliName.js'); //No I18N
16
17
 
17
18
  const program = new Command();
18
19
 
19
20
  program
20
- .name('zoho-sites-dev-cli')
21
+ .name(getCliName())
21
22
  .description(i18n.t('cli.description')) //No I18N
22
23
  .version('1.0.0'); //No I18N
23
24
 
@@ -1,18 +1,26 @@
1
1
  {
2
2
  "audience": "internal",
3
3
  "oauth": {
4
- "clientId": "1000.419PQKF0RWR8M5MH4NMGVFN81IQQVR",
5
- "clientSecret": "5611024e300d739f85857ec154e99f284829a5e1df",
6
4
  "scope": "ZohoSites.resource.READ,ZohoSites.blogs.CREATE,zohoSites.blogs.READ,aaaserver.profile.read",
7
5
  "accessType": "offline",
8
6
  "prompt": "consent",
9
- "defaultPort": 3030
10
- },
11
- "environments": {
12
- "usdc": {
13
- "authDomain": "https://accounts.zoho.com",
14
- "siteDomain": "https://sites.zoho.com",
15
- "siteBuilderDomainTemplate": "https://sitebuilder-{siteId}.zoho.com"
7
+ "defaultPort": 3030,
8
+ "clients": {
9
+ "localzoho": {
10
+ "clientId": "1000.BW3HGGDUV5JXCARZB65I9EAZN7R6IR"
11
+ },
12
+ "usdc": {
13
+ "clientId": "REPLACE_WITH_USDC_CLIENT_ID"
14
+ },
15
+ "indc": {
16
+ "clientId": "REPLACE_WITH_INDC_CLIENT_ID"
17
+ },
18
+ "eudc": {
19
+ "clientId": "REPLACE_WITH_EUDC_CLIENT_ID"
20
+ },
21
+ "audc": {
22
+ "clientId": "REPLACE_WITH_AUDC_CLIENT_ID"
23
+ }
16
24
  }
17
25
  }
18
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zoho-sites-dev-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "ZS CLI - Manage your site components",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -1,4 +1,5 @@
1
1
  const SecureStorage = require('../utils/secureStorage.js');
2
+ const OAuthService = require('../services/oauthService.js');
2
3
  const {i18n} = require('../utils/i18n.js');
3
4
  const chalk = require('chalk');
4
5
 
@@ -29,18 +30,16 @@ async function logout() {
29
30
 
30
31
  // Who am I command - show current user info
31
32
  async function whoami() {
32
- const storage = new SecureStorage();
33
-
33
+ const oauthService = new OAuthService();
34
+
34
35
  try {
35
- const isLoggedIn = await storage.isLoggedIn();
36
-
37
- if (!isLoggedIn) {
36
+ const authData = await oauthService.getValidAuthData();
37
+
38
+ if (!authData || !authData.access_token) {
38
39
  i18n.warning('commands.auth.notLoggedIn');
39
40
  i18n.info('commands.auth.loginToAuthenticate');
40
41
  return;
41
42
  }
42
-
43
- const authData = await storage.getAuthData();
44
43
 
45
44
  if (!authData) {
46
45
  i18n.error('commands.auth.authenticationDataNotFound');
@@ -64,10 +63,6 @@ async function whoami() {
64
63
  i18n.gray('commands.auth.userId', { userId: authData.user_id });
65
64
  }
66
65
 
67
- if (authData.token_type) {
68
- i18n.gray('commands.auth.tokenType', { tokenType: authData.token_type });
69
- }
70
-
71
66
  if (authData.permissions) {
72
67
  i18n.info('commands.auth.permissions', { permissions: authData.permissions.join(', ') });
73
68
  }
@@ -79,13 +74,7 @@ async function whoami() {
79
74
  if (authData.expires_at) {
80
75
  const expiresAt = new Date(authData.expires_at);
81
76
  const now = new Date();
82
- const timeUntilExpiry = expiresAt - now;
83
-
84
- if (timeUntilExpiry > 0) {
85
- const hours = Math.floor(timeUntilExpiry / (1000 * 60 * 60));
86
- const minutes = Math.floor((timeUntilExpiry % (1000 * 60 * 60)) / (1000 * 60));
87
- i18n.success('commands.auth.tokenExpiresIn', { hours: hours, minutes: minutes });
88
- } else {
77
+ if (expiresAt - now <= 0) {
89
78
  i18n.error('commands.auth.tokenExpired');
90
79
  i18n.info('commands.auth.loginToReauthenticate');
91
80
  }
@@ -22,6 +22,9 @@ const SecureStorage = require("../utils/secureStorage.js");
22
22
  */
23
23
  async function createTempDir() {
24
24
  const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "zs-deploy-"));
25
+ if (typeof fs.chmod === "function") {
26
+ await fs.chmod(tempDir, 0o700);
27
+ }
25
28
  return tempDir;
26
29
  }
27
30
 
@@ -144,27 +147,47 @@ async function copyTailwindAndPostcssConfig(tempDir) {
144
147
  * @returns {Promise<string>} Path to zip file
145
148
  */
146
149
  async function createZipFile(tempDir, customZipPath) {
147
- const zipPath = customZipPath || path.join(path.dirname(tempDir), "components.zip");
150
+ const zipPath = customZipPath || path.join(tempDir, "components.zip");
151
+ const resolvedZipPath = path.resolve(zipPath);
152
+ const streamOptions = customZipPath
153
+ ? {}
154
+ : { flags: "wx", mode: 0o600 };
148
155
 
149
156
  return new Promise((resolve, reject) => {
150
- const output = createWriteStream(zipPath);
157
+ let settled = false;
158
+ const output = createWriteStream(zipPath, streamOptions);
151
159
  const archive = archiver("zip", {
152
160
  zlib: { level: 9 }, // Maximum compression
153
161
  });
154
162
 
163
+ const fail = (err) => {
164
+ if (settled) return;
165
+ settled = true;
166
+ archive.abort();
167
+ reject(err);
168
+ };
169
+
155
170
  output.on("close", () => {
171
+ if (settled) return;
172
+ settled = true;
156
173
  i18n.info("commands.deploy.zipCreated", { size: archive.pointer() });
157
174
  resolve(zipPath);
158
175
  });
159
176
 
160
- archive.on("error", (err) => {
161
- reject(err);
162
- });
177
+ output.on("error", fail);
178
+
179
+ archive.on("error", fail);
163
180
 
164
181
  archive.pipe(output);
165
182
  // Server expects a single top-level directory in the zip (e.g. widgets/).
166
183
  // Use 'widgets' so entries are widgets/assets/, widgets/event/, etc.
167
- archive.directory(tempDir, "widgets");
184
+ // Exclude the output zip itself since temporary archives live inside tempDir.
185
+ archive.directory(tempDir, "widgets", (entry) => {
186
+ if (path.resolve(tempDir, entry.name) === resolvedZipPath) {
187
+ return false;
188
+ }
189
+ return entry;
190
+ });
168
191
  archive.finalize();
169
192
  });
170
193
  }
@@ -277,16 +300,22 @@ async function getDeploymentEnvironment(providedEnvironment) {
277
300
  */
278
301
  async function cleanup(tempDir, zipPath) {
279
302
  try {
303
+ // Remove zip file first (it normally lives inside tempDir)
304
+ if (zipPath) {
305
+ try {
306
+ await fs.unlink(zipPath);
307
+ } catch (err) {
308
+ if (err.code !== "ENOENT") {
309
+ throw err;
310
+ }
311
+ }
312
+ }
313
+
280
314
  // Remove temp directory
281
315
  if (tempDir) {
282
316
  await fs.rm(tempDir, { recursive: true, force: true });
283
317
  }
284
318
 
285
- // Remove zip file
286
- if (zipPath) {
287
- await fs.unlink(zipPath);
288
- }
289
-
290
319
  i18n.info("commands.deploy.cleanupComplete");
291
320
  } catch (error) {
292
321
  i18n.warning("commands.deploy.cleanupFailed", { error: error.message });
@@ -9,6 +9,7 @@ const {
9
9
  WEBPACK_OVERRIDES_FILE
10
10
  } = require("../config/constants.js");
11
11
  const SecureStorage = require("../utils/secureStorage.js");
12
+ const { getCliName } = require("../utils/cliName.js");
12
13
 
13
14
  const WORKSPACES_PARENT_PATH = "/__workspaces";
14
15
  const WORKSPACE_RESOURCE_TYPE = "/__conf/devhub_workspace";
@@ -112,7 +113,7 @@ async function assertAuthenticated() {
112
113
  const authenticated = await isAuthenticated();
113
114
  if (!authenticated) {
114
115
  throw new Error(
115
- "Authentication required. Please run `zs login` to authenticate before initializing a project."
116
+ `Authentication required. Please run \`${getCliName()} login\` to authenticate before initializing a project.`
116
117
  );
117
118
  }
118
119
  }
@@ -183,7 +184,7 @@ async function fetchWorkspaces(asoid) {
183
184
 
184
185
  if (workspaces.length === 0) {
185
186
  throw new Error(
186
- "No workspaces found. Please create a workspace in the Zoho Sites dashboard before running 'zs init'."
187
+ `No workspaces found. Please create a workspace in the Zoho Sites dashboard before running '${getCliName()} init'.`
187
188
  );
188
189
  }
189
190
 
@@ -222,7 +223,7 @@ async function fetchAppsForWorkspace(workspace, asoid) {
222
223
 
223
224
  if (apps.length === 0) {
224
225
  throw new Error(
225
- `No apps found in workspace "${workspace.name}". Please create an app in the Zoho Sites dashboard before running 'zs init'.`
226
+ `No apps found in workspace "${workspace.name}". Please create an app in the Zoho Sites dashboard before running '${getCliName()} init'.`
226
227
  );
227
228
  }
228
229
 
@@ -387,10 +388,10 @@ async function writePackageJson(folderName, app) {
387
388
  private: true,
388
389
  type: "commonjs",
389
390
  scripts: {
390
- start: "zs serve",
391
- serve: "zs serve",
392
- pull: "zs pull",
393
- create: "zs create",
391
+ start: `${getCliName()} serve`,
392
+ serve: `${getCliName()} serve`,
393
+ pull: `${getCliName()} pull`,
394
+ create: `${getCliName()} create`,
394
395
  },
395
396
  };
396
397
 
@@ -2,6 +2,7 @@ const fs = require("node:fs");
2
2
  const path = require("node:path");
3
3
  const { spawn } = require("node:child_process");
4
4
  const { i18n } = require("../utils/i18n.js");
5
+ const { getCliName } = require("../utils/cliName.js");
5
6
 
6
7
  function sanitizePackageName(name) {
7
8
  if (!name) {
@@ -27,7 +28,7 @@ function ensurePackageJson(cwd) {
27
28
  license: "MIT",
28
29
  type: "commonjs",
29
30
  scripts: {
30
- start: "zs serve"
31
+ start: `${getCliName()} serve`
31
32
  }
32
33
  };
33
34
 
@@ -121,11 +121,13 @@ async function selectEnvironment() {
121
121
  return { environmentName: environment, authUrl, devSiteUrl, devSiteBuilderUrl, promptMode: selected.promptMode };
122
122
  }
123
123
 
124
- async function performOAuthAuthentication(authUrl) {
124
+ async function performOAuthAuthentication(authUrl, environmentName) {
125
125
  const oauthService = new OAuthService();
126
126
  i18n.info('commands.login.startingAuth');
127
127
 
128
128
  try {
129
+ // Bind the environment-specific OAuth client before opening the browser.
130
+ oauthService.setClientForEnvironment(environmentName);
129
131
  const { tokenData, userProfile } = await oauthService.completeAuthentication(authUrl);
130
132
  return { tokenData, userProfile, oauthService };
131
133
  } catch (oauthError) {
@@ -224,8 +226,11 @@ async function login() {
224
226
  // 3. Environment selection (+ Dev 1 URL prompts if needed)
225
227
  const { environmentName, authUrl, devSiteUrl, devSiteBuilderUrl, promptMode } = await selectEnvironment();
226
228
 
227
- // 4. OAuth authentication
228
- const { tokenData, userProfile, oauthService } = await performOAuthAuthentication(authUrl);
229
+ // 4. OAuth authentication (uses oauth.clients.<environment> credentials)
230
+ const { tokenData, userProfile, oauthService } = await performOAuthAuthentication(
231
+ authUrl,
232
+ environmentName
233
+ );
229
234
 
230
235
  // 5. Prepare auth data
231
236
  const authData = prepareAuthData(
@@ -7,6 +7,7 @@ const { SERVER_CONFIG } = require('../config/constants.js');
7
7
  const { UrlUtil } = require('../utils/urlUtil.js');
8
8
  const SecureStorage = require('../utils/secureStorage.js');
9
9
  const { readProjectConfig } = require('../utils/configUtil.js');
10
+ const { getCliName } = require('../utils/cliName.js');
10
11
 
11
12
  // Load compilers
12
13
  const compilerPath = path.resolve(__dirname, '../compilers');
@@ -73,7 +74,7 @@ async function getEnvironment(config) {
73
74
  // Ignore errors, will throw below
74
75
  }
75
76
 
76
- throw new Error('Environment not found in config. Please run "zs init" or "zs login" to set up the environment.');
77
+ throw new Error(`Environment not found in config. Please run "${getCliName()} init" or "${getCliName()} login" to set up the environment.`);
77
78
  }
78
79
 
79
80
  /**
@@ -89,7 +90,7 @@ async function startWebpackDevServer(config, shouldOpenBrowser = true) {
89
90
  // Get defaultSiteId from config
90
91
  const defaultSiteId = getDefaultSiteId(config);
91
92
  if (!defaultSiteId) {
92
- throw new Error('defaultSiteId, siteId, or asoid not found in .zs file. Please ensure your project is properly initialized with \'zs init\'.');
93
+ throw new Error(`defaultSiteId, siteId, or asoid not found in .zs file. Please ensure your project is properly initialized with '${getCliName()} init'.`);
93
94
  }
94
95
 
95
96
  // Get environment from config or SecureStorage
@@ -17,10 +17,6 @@ const appConfig = require('config');
17
17
  const { DEFAULT_AUDIENCE } = require('./environments/audiences.js');
18
18
  const AUDIENCE = appConfig.has('audience') ? appConfig.get('audience') : DEFAULT_AUDIENCE;
19
19
 
20
- // OAuth Client Credentials (hardcoded in config/default.json)
21
- const CLIENT_ID = appConfig.get('oauth.clientId');
22
- const CLIENT_SECRET = appConfig.get('oauth.clientSecret');
23
-
24
20
  // OAuth Server Configuration
25
21
  const DEFAULT_PORT = appConfig.get('oauth.defaultPort');
26
22
 
@@ -31,6 +27,49 @@ const DEFAULT_SCOPE = appConfig.get('oauth.scope');
31
27
  const ACCESS_TYPE = appConfig.get('oauth.accessType');
32
28
  const PROMPT = appConfig.get('oauth.prompt');
33
29
 
30
+ /**
31
+ * Resolve OAuth client credentials for a login environment id
32
+ * (csez | localzoho | usdc | indc | eudc | audc).
33
+ *
34
+ * Credentials live under oauth.clients in config/default.json and are
35
+ * filtered at package-prep time by audience (see prepare-dist-package.js):
36
+ * - csez : source/sdk only — never shipped in published builds
37
+ * - localzoho : source/sdk + internal (zoho-sites-dev-cli) only
38
+ * - production : all builds (usdc, indc, eudc, audc, …)
39
+ *
40
+ * @param {string} environmentId
41
+ * @returns {{ clientId: string }}
42
+ */
43
+ function getOAuthClient(environmentId) {
44
+ if (!environmentId) {
45
+ throw new Error('Environment id is required to resolve OAuth client credentials.');
46
+ }
47
+
48
+ if (!appConfig.has('oauth.clients')) {
49
+ throw new Error(
50
+ `OAuth client credentials for "${environmentId}" are not configured. ` +
51
+ 'Add oauth.clients in config/default.json.'
52
+ );
53
+ }
54
+
55
+ const clients = appConfig.get('oauth.clients');
56
+ const client = clients && clients[environmentId];
57
+ const clientId = client && client.clientId;
58
+
59
+ if (!clientId || String(clientId).startsWith('REPLACE_WITH_')) {
60
+ throw new Error(
61
+ `OAuth client credentials for "${environmentId}" are missing from this build. ` +
62
+ (environmentId === 'csez'
63
+ ? 'CSEZ credentials are only available in the local sdk source checkout.'
64
+ : environmentId === 'localzoho'
65
+ ? 'Localzoho credentials are only available in the sdk source or zoho-sites-dev-cli builds.'
66
+ : `Set oauth.clients.${environmentId} in config/default.json.`)
67
+ );
68
+ }
69
+
70
+ return { clientId };
71
+ }
72
+
34
73
  // Timeouts
35
74
  const AUTH_TIMEOUT = 5 * 60 * 1000; // 5 minutes
36
75
  const SERVER_CLEANUP_DELAY = 8000; // 8 seconds
@@ -44,6 +83,7 @@ const CONFIG_FILE_NAME = '.zs';
44
83
 
45
84
  // Server configuration
46
85
  const SERVER_CONFIG = {
86
+ HTTP_HOST: '127.0.0.1',
47
87
  HTTP_PORT: 8083,
48
88
  CACHE_TTL: 3600 // 1 hour
49
89
  };
@@ -100,8 +140,7 @@ module.exports = {
100
140
  AUDIENCE,
101
141
  HTTP_PROTOCOL,
102
142
  HTTPS_PROTOCOL,
103
- CLIENT_ID,
104
- CLIENT_SECRET,
143
+ getOAuthClient,
105
144
  DEFAULT_PORT,
106
145
  DEFAULT_SCOPE,
107
146
  ACCESS_TYPE,
@@ -59,8 +59,8 @@ const LOCALZOHO_INTERNAL = {
59
59
  id: 'localzoho',
60
60
  label: 'Localzoho',
61
61
  authDomain: LOCALZOHO_AUTH_DOMAIN,
62
- siteDomain: 'https://sites.localzoho.com',
63
- siteBuilderDomainTemplate: 'https://{siteId}-builder.integv3.localzohositescontent.com', // PLACEHOLDER: confirm constant builder URL
62
+ siteDomain: 'https://sites-module2.localzoho.com',
63
+ siteBuilderDomainTemplate: 'https://{siteId}-builder.module2v3.localzohositescontent.com', // PLACEHOLDER: confirm constant builder URL
64
64
  promptMode: 'none',
65
65
  };
66
66