Skip to content

Commit 2bb515f

Browse files
W-20274055 sf-webapp-dev-command Foundation, messages & type definitions
This commit establishes the foundational files for the sf webapp dev command: - Created TypeScript type definitions (src/config/types.ts) defining 10 interfaces for webapp.json manifest, proxy configuration, authentication, routing, and status tracking. All interfaces include comprehensive JSDoc documentation. - Created JSON Schema (schemas/webapp-config.json) for webapp.json validation with regex patterns for name, version, and apiVersion fields, plus URL validation for dev server configuration. - Created messages file (messages/webapp.dev.md) with 50+ user-facing messages including command descriptions, flag documentation, info messages, error messages with actionable suggestions, warnings, and debug messages. - Updated package.json to add required dependencies: * chokidar (^3.6.0) for file watching * http-proxy (^1.18.1) for proxy server functionality * @types/http-proxy (^1.17.14) for TypeScript type definitions * Added webapp topic to oclif configuration - Created unit tests (test/config/types.test.ts) for TypeScript types - Created sample webapp.json fixture (test/fixtures/sample-webapp.json) for testing These foundational files establish the contracts and interfaces that all subsequent components (AuthManager, RequestRouter, ProxyServer, etc.) will use, enabling parallel development of remaining tasks.
1 parent 8c5b614 commit 2bb515f

6 files changed

Lines changed: 542 additions & 1 deletion

File tree

messages/webapp.dev.md

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# summary
2+
3+
Preview a web app locally without needing to deploy
4+
5+
# description
6+
7+
Starts a local development server for a Web Application, using the local project files. This enables rapid development with hot reloading and immediate feedback.
8+
9+
The command launches a local proxy server that sits between your web application and Salesforce, automatically injecting authentication headers from the CLI's stored tokens. This allows your web app to make authenticated API calls to Salesforce without exposing credentials.
10+
11+
# flags.name.summary
12+
13+
Identifies the Web Application
14+
15+
# flags.name.description
16+
17+
The unique name of the web application as defined in webapp.json. This is used to load the appropriate configuration and settings.
18+
19+
# flags.url.summary
20+
21+
Dev server origin to forward UI/HMR/static requests
22+
23+
# flags.url.description
24+
25+
The URL where your dev server is running (e.g., http://localhost:5173). Required if webapp.json does not contain a dev.command or dev.url configuration. All non-Salesforce API requests will be forwarded to this URL.
26+
27+
# flags.port.summary
28+
29+
Local proxy port
30+
31+
# flags.port.description
32+
33+
The port on which the proxy server will listen. Your browser should connect to this port, not directly to the dev server. The proxy will forward authenticated requests to Salesforce and other requests to your dev server.
34+
35+
# flags.target-org.summary
36+
37+
Org to use for auth
38+
39+
# flags.target-org.description
40+
41+
The Salesforce org alias or username to use for authentication. The proxy will use this org's credentials to authenticate API requests to Salesforce.
42+
43+
# flags.debug.summary
44+
45+
Enable verbose proxy logging
46+
47+
# flags.debug.description
48+
49+
When enabled, the proxy will log detailed information about each request including headers, routing decisions, and response status. Useful for debugging authentication or routing issues. Note: Access tokens are never logged even in debug mode.
50+
51+
# flags.open.summary
52+
53+
Auto-open proxy URL in default browser
54+
55+
# flags.open.description
56+
57+
When enabled, automatically opens the proxy URL in your default browser after the proxy server starts.
58+
59+
# examples
60+
61+
- Start the development server with explicit dev server URL:
62+
63+
<%= config.bin %> <%= command.id %> --name myWebApp --url http://localhost:5173 --target-org myorg
64+
65+
- Start the development server using webapp.json configuration:
66+
67+
<%= config.bin %> <%= command.id %> --name myWebApp --target-org myorg
68+
69+
- Start with custom port and auto-open browser:
70+
71+
<%= config.bin %> <%= command.id %> --name myWebApp --target-org myorg --port 4546 --open
72+
73+
- Start with debug logging:
74+
75+
<%= config.bin %> <%= command.id %> --name myWebApp --target-org myorg --debug
76+
77+
# info.starting
78+
79+
Starting development server for web app: %s
80+
81+
# info.using-target-org
82+
83+
Using target org: %s
84+
85+
# info.proxy-running
86+
87+
Proxy server running on %s
88+
89+
# info.dev-server-url
90+
91+
Dev server URL: %s
92+
93+
# info.opening-browser
94+
95+
Opening browser...
96+
97+
# info.ready
98+
99+
Web app development server is ready!
100+
101+
# info.press-ctrl-c
102+
103+
Press Ctrl+C to stop the server
104+
105+
# info.starting-dev-server
106+
107+
Starting dev server with command: %s
108+
109+
# info.dev-server-started
110+
111+
Dev server started at: %s
112+
113+
# info.watching-manifest
114+
115+
Watching webapp.json for changes...
116+
117+
# info.manifest-reloaded
118+
119+
Manifest reloaded successfully
120+
121+
# error.manifest-not-found
122+
123+
webapp.json not found in the current directory. Run 'sf webapp generate' to create a new web app.
124+
125+
# error.manifest-invalid
126+
127+
Invalid webapp.json: %s
128+
129+
# error.manifest-validation-failed
130+
131+
Manifest validation failed:
132+
%s
133+
134+
# error.org-not-found
135+
136+
Org '%s' not found. Check available orgs with 'sf org list'.
137+
138+
# error.org-auth-failed
139+
140+
Failed to authenticate with org '%s'. Run 'sf org login web --alias %s' to re-authenticate.
141+
142+
# error.token-expired
143+
144+
Your org authentication has expired. Run 'sf org login web --alias %s' to re-authenticate.
145+
146+
# error.token-refresh-failed
147+
148+
Failed to refresh access token. Run 'sf org login web --alias %s' to re-authenticate.
149+
150+
# error.dev-server-failed
151+
152+
Dev server failed to start: %s
153+
154+
# error.dev-server-command-required
155+
156+
No dev server URL provided and webapp.json does not contain dev.command or dev.url. Please provide --url flag or configure dev settings in webapp.json.
157+
158+
# error.dev-server-timeout
159+
160+
Dev server did not start within 30 seconds. Check the command in webapp.json and ensure your dev server outputs its URL to stdout.
161+
162+
# error.port-in-use
163+
164+
Port %s is already in use. Try a different port with --port flag.
165+
166+
# error.proxy-start-failed
167+
168+
Failed to start proxy server: %s
169+
170+
# error.network-error
171+
172+
Network error: %s. Check your internet connection.
173+
174+
# error.request-failed
175+
176+
Request to %s failed: %s
177+
178+
# error.invalid-url
179+
180+
Invalid URL: %s
181+
182+
# error.connection-refused
183+
184+
Connection refused to %s. Ensure the dev server is running.
185+
186+
# warning.no-manifest-dev-config
187+
188+
webapp.json does not contain dev configuration. Using provided --url flag.
189+
190+
# warning.manifest-dev-command-override
191+
192+
webapp.json contains dev.command but --url flag provided. Using --url flag.
193+
194+
# warning.dev-server-stderr
195+
196+
Dev server error: %s
197+
198+
# debug.request-received
199+
200+
[REQUEST] %s %s
201+
202+
# debug.routing-decision
203+
204+
[ROUTING] %s -> %s (auth: %s)
205+
206+
# debug.auth-headers-injected
207+
208+
[AUTH] Authorization headers injected
209+
210+
# debug.proxying-request
211+
212+
[PROXY] Forwarding to %s
213+
214+
# debug.response-received
215+
216+
[RESPONSE] %s %s
217+
218+
# debug.websocket-upgrade
219+
220+
[WEBSOCKET] Upgrading connection for %s
221+
222+
# debug.manifest-change-detected
223+
224+
[MANIFEST] Change detected, reloading...
225+
226+
# debug.token-refresh-attempt
227+
228+
[AUTH] Token expired, attempting refresh...
229+
230+
# debug.token-refresh-success
231+
232+
[AUTH] Token refresh successful
233+

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
"@oclif/core": "^4",
99
"@salesforce/core": "^8.23.4",
1010
"@salesforce/kit": "^3.2.4",
11-
"@salesforce/sf-plugins-core": "^12"
11+
"@salesforce/sf-plugins-core": "^12",
12+
"chokidar": "^3.6.0",
13+
"http-proxy": "^1.18.1"
1214
},
1315
"devDependencies": {
1416
"@oclif/plugin-command-snapshot": "^5.3.8",
1517
"@salesforce/cli-plugins-testkit": "^5.3.41",
1618
"@salesforce/dev-scripts": "^11.0.4",
1719
"@salesforce/plugin-command-reference": "^3.1.77",
20+
"@types/http-proxy": "^1.17.14",
1821
"eslint-plugin-sf-plugin": "^1.20.33",
1922
"oclif": "^4.22.40",
2023
"ts-node": "^10.9.2",
@@ -54,6 +57,9 @@
5457
"topics": {
5558
"hello": {
5659
"description": "Commands to say hello."
60+
},
61+
"webapp": {
62+
"description": "Commands for web application development."
5763
}
5864
},
5965
"flexibleTaxonomy": true

schemas/webapp-config.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://schemas.salesforce.com/webapp-config.json",
4+
"title": "Salesforce Web Application Configuration",
5+
"description": "Configuration schema for Salesforce web applications",
6+
"type": "object",
7+
"required": ["name", "label", "version", "apiVersion", "outputDir"],
8+
"properties": {
9+
"name": {
10+
"type": "string",
11+
"description": "Unique name identifier for the web app",
12+
"pattern": "^[a-zA-Z][a-zA-Z0-9_]*$",
13+
"examples": ["customerPortal", "myApp", "sales_dashboard"]
14+
},
15+
"label": {
16+
"type": "string",
17+
"description": "Human-readable label for the web app",
18+
"minLength": 1,
19+
"examples": ["Customer Portal", "My Application"]
20+
},
21+
"description": {
22+
"type": "string",
23+
"description": "Description of the web app"
24+
},
25+
"version": {
26+
"type": "string",
27+
"description": "Version of the web app in semantic versioning format",
28+
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$",
29+
"examples": ["1.0.0", "2.1.3"]
30+
},
31+
"apiVersion": {
32+
"type": "string",
33+
"description": "Salesforce API version",
34+
"pattern": "^[0-9]+\\.[0-9]+$",
35+
"examples": ["60.0", "61.0"]
36+
},
37+
"outputDir": {
38+
"type": "string",
39+
"description": "Output directory for built assets",
40+
"examples": ["dist", "build", "out"]
41+
},
42+
"dev": {
43+
"type": "object",
44+
"description": "Development configuration",
45+
"properties": {
46+
"command": {
47+
"type": "string",
48+
"description": "Command to run the dev server (e.g., 'npm run dev')",
49+
"examples": ["npm run dev", "yarn dev", "pnpm dev"]
50+
},
51+
"url": {
52+
"type": "string",
53+
"description": "Explicit URL for the dev server",
54+
"pattern": "^https?://[^\\s]+$",
55+
"examples": ["http://localhost:3000", "http://localhost:5173"]
56+
}
57+
},
58+
"additionalProperties": false
59+
}
60+
},
61+
"additionalProperties": true
62+
}
63+

0 commit comments

Comments
 (0)