@salesforce/vite-plugin-webapp-experimental 0.2.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/README.md +3 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +109 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +38 -0
- package/package.json +34 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export interface PluginOptions {
|
|
3
|
+
/** Salesforce org alias */
|
|
4
|
+
orgAlias?: string;
|
|
5
|
+
/** Enable verbose logging */
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export default function webappsPlugin(options?: PluginOptions): Plugin;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAUlD,MAAM,WAAW,aAAa;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAID,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAoIzE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { loadManifest, getOrgInfo } from "@salesforce/webapp-experimental/app";
|
|
2
|
+
import { createProxyHandler } from "@salesforce/webapp-experimental/proxy";
|
|
3
|
+
import { getBasePath, getCodeBuilderBasePath, getPort, getDevServerTarget, DEFAULT_API_VERSION, DEFAULT_PORT, } from "./utils.js";
|
|
4
|
+
const codeBuilderProxyUrl = process.env.CODE_BUILDER_FRAMEWORK_PROXY_URI;
|
|
5
|
+
export default function webappsPlugin(options = {}) {
|
|
6
|
+
const proxyOptions = {
|
|
7
|
+
debug: options.debug ?? false,
|
|
8
|
+
};
|
|
9
|
+
let orgInfo;
|
|
10
|
+
let manifest;
|
|
11
|
+
let proxyHandler;
|
|
12
|
+
const getBasePathBound = (mode) => getBasePath(mode, codeBuilderProxyUrl, getPort());
|
|
13
|
+
return {
|
|
14
|
+
name: "@salesforce/vite-plugin-webapp-experimental",
|
|
15
|
+
async config(_config, env) {
|
|
16
|
+
// Note: At this stage we may not have the correct manifest path yet,
|
|
17
|
+
// so we only load the org info to get the API version
|
|
18
|
+
// Development server configuration
|
|
19
|
+
let version;
|
|
20
|
+
try {
|
|
21
|
+
orgInfo = await getOrgInfo(options.orgAlias);
|
|
22
|
+
version = orgInfo?.apiVersion || DEFAULT_API_VERSION;
|
|
23
|
+
if (options.debug) {
|
|
24
|
+
console.log(`[webapps-plugin] Using Salesforce API version: ${version}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
version = DEFAULT_API_VERSION;
|
|
29
|
+
}
|
|
30
|
+
const isCodeBuilder = !!codeBuilderProxyUrl;
|
|
31
|
+
const define = {
|
|
32
|
+
__SF_API_VERSION__: JSON.stringify(version),
|
|
33
|
+
__SF_SERVER_BASE_PATH__: JSON.stringify(""),
|
|
34
|
+
};
|
|
35
|
+
if (isCodeBuilder && env.mode !== "production") {
|
|
36
|
+
const basePath = getCodeBuilderBasePath(codeBuilderProxyUrl, getPort());
|
|
37
|
+
define["__SF_SERVER_BASE_PATH__"] = JSON.stringify(basePath);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
define,
|
|
41
|
+
base: getBasePath(env.mode, codeBuilderProxyUrl, getPort()),
|
|
42
|
+
server: {
|
|
43
|
+
port: getPort(),
|
|
44
|
+
// Code Builder specific configuration
|
|
45
|
+
...(isCodeBuilder && {
|
|
46
|
+
// Allow any host to connect to the dev server
|
|
47
|
+
allowedHosts: true,
|
|
48
|
+
strictPort: true, // Fail if port is already occupied
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
async configResolved(config) {
|
|
54
|
+
try {
|
|
55
|
+
manifest = await loadManifest(`${config.root ?? process.cwd()}/webapp.json`);
|
|
56
|
+
const target = getDevServerTarget(codeBuilderProxyUrl, config.server.port ?? DEFAULT_PORT);
|
|
57
|
+
proxyHandler = createProxyHandler(manifest, orgInfo, target, getBasePathBound(config.mode), proxyOptions);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error(`[webapps-plugin] Initialization failed:`, error);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
configureServer(server) {
|
|
64
|
+
// Add middleware to handle all requests (API, rewrites, redirects, and dev server forwarding)
|
|
65
|
+
// Must run BEFORE Vite's internal middlewares (hence not returning a post-hook function)
|
|
66
|
+
server.middlewares.use(async (req, res, next) => {
|
|
67
|
+
// Let proxy handler handle all requests
|
|
68
|
+
if (proxyHandler) {
|
|
69
|
+
try {
|
|
70
|
+
await proxyHandler(req, res, next);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error("[webapps-plugin] Proxy handler error:", error);
|
|
74
|
+
next();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// Only return 503 for Salesforce API requests when handler not initialized
|
|
79
|
+
if (req.url?.startsWith("/services")) {
|
|
80
|
+
res.writeHead(503, { "Content-Type": "application/json" });
|
|
81
|
+
res.end(JSON.stringify({
|
|
82
|
+
error: "SERVICE_UNAVAILABLE",
|
|
83
|
+
message: "Proxy not initialized.",
|
|
84
|
+
}));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
next();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
async handleHotUpdate({ file, server }) {
|
|
92
|
+
// Watch for manifest changes and reload
|
|
93
|
+
if (file.endsWith("webapp.json")) {
|
|
94
|
+
const updatedManifest = await loadManifest(file);
|
|
95
|
+
if (updatedManifest) {
|
|
96
|
+
// Update context with new manifest
|
|
97
|
+
manifest = updatedManifest;
|
|
98
|
+
// Recreate proxy handler with updated appContext
|
|
99
|
+
const target = getDevServerTarget(codeBuilderProxyUrl, server.config.server.port ?? DEFAULT_PORT);
|
|
100
|
+
proxyHandler = createProxyHandler(manifest, orgInfo, target, getBasePathBound(server.config.mode), proxyOptions);
|
|
101
|
+
server.ws.send({
|
|
102
|
+
type: "full-reload",
|
|
103
|
+
path: "*",
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const DEFAULT_PORT = 5173;
|
|
2
|
+
export declare const DEFAULT_API_VERSION = "65.0";
|
|
3
|
+
/**
|
|
4
|
+
* Calculate the code builder base path from the proxy URI (CODE_BUILDER_FRAMEWORK_PROXY_URI) and dev server port
|
|
5
|
+
* @param proxyUri - The full proxy URI (e.g., https://name.iad.001.sf.code-builder.platform.salesforce.com/absproxy/{{port}})
|
|
6
|
+
* @param port - The port number to replace {{port}} with (e.g., "5173")
|
|
7
|
+
* @returns The parsed path with port (e.g., /absproxy/5173/)
|
|
8
|
+
*/
|
|
9
|
+
export declare function getCodeBuilderBasePath(proxyUri: string, port: number): string;
|
|
10
|
+
export declare function getBasePath(mode: string, codeBuilderProxyUrl: string | undefined, port: number): string;
|
|
11
|
+
export declare function getDevServerTarget(codeBuilderProxyUrl: string | undefined, port: number): string;
|
|
12
|
+
export declare function getPort(): number;
|
|
13
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ7E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,UAY9F;AAED,wBAAgB,kBAAkB,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,UAMvF;AAED,wBAAgB,OAAO,WAEtB"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const DEFAULT_PORT = 5173;
|
|
2
|
+
export const DEFAULT_API_VERSION = "65.0";
|
|
3
|
+
/**
|
|
4
|
+
* Calculate the code builder base path from the proxy URI (CODE_BUILDER_FRAMEWORK_PROXY_URI) and dev server port
|
|
5
|
+
* @param proxyUri - The full proxy URI (e.g., https://name.iad.001.sf.code-builder.platform.salesforce.com/absproxy/{{port}})
|
|
6
|
+
* @param port - The port number to replace {{port}} with (e.g., "5173")
|
|
7
|
+
* @returns The parsed path with port (e.g., /absproxy/5173/)
|
|
8
|
+
*/
|
|
9
|
+
export function getCodeBuilderBasePath(proxyUri, port) {
|
|
10
|
+
try {
|
|
11
|
+
const url = new URL(proxyUri.replace("{{port}}", port.toString()));
|
|
12
|
+
return url.pathname;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.error("Failed to parse CODE_BUILDER_FRAMEWORK_PROXY_URI:", error);
|
|
16
|
+
return `/absproxy/${port}`; // Default code builder proxy path
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function getBasePath(mode, codeBuilderProxyUrl, port) {
|
|
20
|
+
const isProd = mode === "production";
|
|
21
|
+
if (isProd) {
|
|
22
|
+
return "/lwr/application/ai/vibe-static";
|
|
23
|
+
}
|
|
24
|
+
if (!codeBuilderProxyUrl) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
// Code Builder: extract path from proxy URI and include port
|
|
28
|
+
return getCodeBuilderBasePath(codeBuilderProxyUrl, port);
|
|
29
|
+
}
|
|
30
|
+
export function getDevServerTarget(codeBuilderProxyUrl, port) {
|
|
31
|
+
if (codeBuilderProxyUrl) {
|
|
32
|
+
return getCodeBuilderBasePath(codeBuilderProxyUrl, port);
|
|
33
|
+
}
|
|
34
|
+
return `http://localhost:${port}`;
|
|
35
|
+
}
|
|
36
|
+
export function getPort() {
|
|
37
|
+
return parseInt(process.env.SF_WEBAPP_PORT || DEFAULT_PORT.toString(), 10);
|
|
38
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/vite-plugin-webapp-experimental",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc --build",
|
|
17
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
18
|
+
"dev": "tsc --build --watch"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@salesforce/webapp-experimental": "^0.2.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"vite": "^7.0.0",
|
|
25
|
+
"vitest": "^4.0.6"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"vite": "^7.0.0"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20.0.0"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "a806910fe9c132ad3cc0ca63302072b0076699b9"
|
|
34
|
+
}
|