@salesforce/angular-plugin-ui-bundle 10.23.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/LICENSE.txt +82 -0
- package/README.md +3 -0
- package/dist/api-version.d.ts +11 -0
- package/dist/api-version.d.ts.map +1 -0
- package/dist/api-version.js +20 -0
- package/dist/bin/serve.d.ts +8 -0
- package/dist/bin/serve.d.ts.map +1 -0
- package/dist/bin/serve.js +72 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/middleware/html.d.ts +8 -0
- package/dist/middleware/html.d.ts.map +1 -0
- package/dist/middleware/html.js +141 -0
- package/dist/middleware/proxy.d.ts +8 -0
- package/dist/middleware/proxy.d.ts.map +1 -0
- package/dist/middleware/proxy.js +96 -0
- package/dist/plugins/api-version.d.ts +21 -0
- package/dist/plugins/api-version.d.ts.map +1 -0
- package/dist/plugins/api-version.js +28 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +21 -0
- package/package.json +50 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Terms of Use
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Salesforce, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
These Terms of Use govern the download, installation, and/or use of this
|
|
6
|
+
software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
|
|
7
|
+
last updated on April 15, 2025, and constitute a legally binding
|
|
8
|
+
agreement between you and Salesforce. If you do not agree to these Terms of
|
|
9
|
+
Use, do not install or use the Software.
|
|
10
|
+
|
|
11
|
+
Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
|
|
12
|
+
copyright license to reproduce, prepare derivative works of, publicly
|
|
13
|
+
display, publicly perform, sublicense, and distribute the Software and
|
|
14
|
+
derivative works subject to these Terms. These Terms shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
Subject to the limited rights expressly granted hereunder, Salesforce
|
|
18
|
+
reserves all rights, title, and interest in and to all intellectual
|
|
19
|
+
property subsisting in the Software. No rights are granted to you hereunder
|
|
20
|
+
other than as expressly set forth herein. Users residing in countries on
|
|
21
|
+
the United States Office of Foreign Assets Control sanction list, or which
|
|
22
|
+
are otherwise subject to a US export embargo, may not use the Software.
|
|
23
|
+
|
|
24
|
+
Implementation of the Software may require development work, for which you
|
|
25
|
+
are responsible. The Software may contain bugs, errors and
|
|
26
|
+
incompatibilities and is made available on an AS IS basis without support,
|
|
27
|
+
updates, or service level commitments.
|
|
28
|
+
|
|
29
|
+
Salesforce reserves the right at any time to modify, suspend, or
|
|
30
|
+
discontinue, the Software (or any part thereof) with or without notice. You
|
|
31
|
+
agree that Salesforce shall not be liable to you or to any third party for
|
|
32
|
+
any modification, suspension, or discontinuance.
|
|
33
|
+
|
|
34
|
+
You agree to defend Salesforce against any claim, demand, suit or
|
|
35
|
+
proceeding made or brought against Salesforce by a third party arising out
|
|
36
|
+
of or accruing from (a) your use of the Software, and (b) any application
|
|
37
|
+
you develop with the Software that infringes any copyright, trademark,
|
|
38
|
+
trade secret, trade dress, patent, or other intellectual property right of
|
|
39
|
+
any person or defames any person or violates their rights of publicity or
|
|
40
|
+
privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
|
|
41
|
+
from any damages, attorney fees, and costs finally awarded against
|
|
42
|
+
Salesforce as a result of, or for any amounts paid by Salesforce under a
|
|
43
|
+
settlement approved by you in writing of, a Claim Against Salesforce,
|
|
44
|
+
provided Salesforce (x) promptly gives you written notice of the Claim
|
|
45
|
+
Against Salesforce, (y) gives you sole control of the defense and
|
|
46
|
+
settlement of the Claim Against Salesforce (except that you may not settle
|
|
47
|
+
any Claim Against Salesforce unless it unconditionally releases Salesforce
|
|
48
|
+
of all liability), and (z) gives you all reasonable assistance, at your
|
|
49
|
+
expense.
|
|
50
|
+
|
|
51
|
+
WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
|
|
52
|
+
SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
53
|
+
IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
|
|
54
|
+
INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
55
|
+
PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
|
|
56
|
+
OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
|
|
57
|
+
CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
|
|
58
|
+
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
59
|
+
|
|
60
|
+
These Terms of Use shall be governed exclusively by the internal laws of
|
|
61
|
+
the State of California, without regard to its conflicts of laws
|
|
62
|
+
rules. Each party hereby consents to the exclusive jurisdiction of the
|
|
63
|
+
state and federal courts located in San Francisco County, California to
|
|
64
|
+
adjudicate any dispute arising out of or relating to these Terms of Use and
|
|
65
|
+
the download, installation, and/or use of the Software. Except as expressly
|
|
66
|
+
stated herein, these Terms of Use constitute the entire agreement between
|
|
67
|
+
the parties, and supersede all prior and contemporaneous agreements,
|
|
68
|
+
proposals, or representations, written or oral, concerning their subject
|
|
69
|
+
matter. No modification, amendment, or waiver of any provision of these
|
|
70
|
+
Terms of Use shall be effective unless it is by an update to these Terms of
|
|
71
|
+
Use that Salesforce makes available, or is in writing and signed by the
|
|
72
|
+
party against whom the modification, amendment, or waiver is to be
|
|
73
|
+
asserted.
|
|
74
|
+
|
|
75
|
+
Data Privacy: Salesforce may collect, process, and store device,
|
|
76
|
+
system, and other information related to your use of the Software. This
|
|
77
|
+
information includes, but is not limited to, IP address, user metrics, and
|
|
78
|
+
other data ("Usage Data"). Salesforce may use Usage Data for analytics,
|
|
79
|
+
product development, and marketing purposes. You acknowledge that files
|
|
80
|
+
generated in conjunction with the Software may contain sensitive or
|
|
81
|
+
confidential data, and you are solely responsible for anonymizing and
|
|
82
|
+
protecting such data.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the Salesforce org API version from the connected sf CLI session.
|
|
8
|
+
* Falls back to DEFAULT_API_VERSION when no org is connected or on error.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveApiVersion(orgAlias?: string): Promise<string>;
|
|
11
|
+
//# sourceMappingURL=api-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-version.d.ts","sourceRoot":"","sources":["../src/api-version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAO1E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { getOrgInfo } from "@salesforce/ui-bundle/app";
|
|
7
|
+
import { DEFAULT_API_VERSION } from "./utils.js";
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the Salesforce org API version from the connected sf CLI session.
|
|
10
|
+
* Falls back to DEFAULT_API_VERSION when no org is connected or on error.
|
|
11
|
+
*/
|
|
12
|
+
export async function resolveApiVersion(orgAlias) {
|
|
13
|
+
try {
|
|
14
|
+
const orgInfo = await getOrgInfo(orgAlias);
|
|
15
|
+
return orgInfo?.apiVersion || DEFAULT_API_VERSION;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return DEFAULT_API_VERSION;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/bin/serve.ts"],"names":[],"mappings":";AACA;;;;GAIG"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --no-deprecation
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* For full license text, see the LICENSE.txt file
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* sf-angular-serve — dev server wrapper for Angular CLI UI Bundles.
|
|
9
|
+
*
|
|
10
|
+
* Resolves API version from sf CLI session, then spawns ng serve with:
|
|
11
|
+
* --define: substitutes __SF_API_VERSION__ in Vite's optimizeDeps prebundle
|
|
12
|
+
* --port: pins to SF_UIBUNDLE_PORT (default 5173) for orchestrator discovery
|
|
13
|
+
*
|
|
14
|
+
* Why this exists: Angular CLI's esbuild plugin (angular.json plugins[]) only
|
|
15
|
+
* reaches the app build pass. Vite's optimizeDeps prebundle is a separate
|
|
16
|
+
* esbuild invocation — --define is the only way to reach it.
|
|
17
|
+
*/
|
|
18
|
+
import { spawn } from "node:child_process";
|
|
19
|
+
import { createRequire } from "node:module";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
import { pathToFileURL } from "node:url";
|
|
22
|
+
import { createApiVersionPlugin } from "../plugins/api-version.js";
|
|
23
|
+
import { getPort } from "../utils.js";
|
|
24
|
+
const { version } = await createApiVersionPlugin();
|
|
25
|
+
const port = getPort();
|
|
26
|
+
// esbuild --define needs valid JS source for the value ("68.0", not 68.0), so
|
|
27
|
+
// JSON.stringify once. No shell here (spawn without shell:true), so there is no
|
|
28
|
+
// shell to strip a quoting layer — a second stringify would bake literal quotes
|
|
29
|
+
// into the value and produce /services/data/v"68.0"/.
|
|
30
|
+
const defineArg = `__SF_API_VERSION__=${JSON.stringify(version)}`;
|
|
31
|
+
// Resolve Angular CLI bin without shell: spawn ng.js with the current Node executable.
|
|
32
|
+
// This works cross-platform (Windows included) without shell: true.
|
|
33
|
+
//
|
|
34
|
+
// Resolve from the consuming app first (process.cwd() = where sf-angular-serve was
|
|
35
|
+
// invoked). This is required in local dev where the plugin is symlinked via `file:`:
|
|
36
|
+
// import.meta.url then points outside the app, so a module-relative resolve would miss
|
|
37
|
+
// the app's @angular/cli. Fall back to module-relative for hoisted published installs.
|
|
38
|
+
function resolveNgCli() {
|
|
39
|
+
try {
|
|
40
|
+
const requireFromApp = createRequire(pathToFileURL(join(process.cwd(), "package.json")));
|
|
41
|
+
return requireFromApp.resolve("@angular/cli/bin/ng.js");
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return createRequire(import.meta.url).resolve("@angular/cli/bin/ng.js");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
let ngPath;
|
|
48
|
+
try {
|
|
49
|
+
ngPath = resolveNgCli();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
console.error("[sf-angular-serve] Error: @angular/cli is not installed.\n" +
|
|
53
|
+
"Please install it in your project: npm install --save-dev @angular/cli");
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
const child = spawn(process.execPath, [ngPath, "serve", `--define=${defineArg}`, `--port=${port}`], {
|
|
57
|
+
stdio: "inherit",
|
|
58
|
+
env: { ...process.env, NODE_OPTIONS: "--no-deprecation" },
|
|
59
|
+
});
|
|
60
|
+
child.on("error", (err) => {
|
|
61
|
+
console.error("[sf-angular-serve] Failed to start ng:", err.message);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
});
|
|
64
|
+
child.on("exit", (code) => {
|
|
65
|
+
process.exit(code ?? 0);
|
|
66
|
+
});
|
|
67
|
+
process.on("SIGINT", () => {
|
|
68
|
+
child.kill("SIGINT");
|
|
69
|
+
});
|
|
70
|
+
process.on("SIGTERM", () => {
|
|
71
|
+
child.kill("SIGTERM");
|
|
72
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
export type { SalesforceOptions, Middleware } from "./types.ts";
|
|
7
|
+
export type { ApiVersionResult } from "./plugins/api-version.ts";
|
|
8
|
+
export { createApiVersionPlugin } from "./plugins/api-version.ts";
|
|
9
|
+
export { DEFAULT_API_VERSION, DEFAULT_PORT, getPort } from "./utils.ts";
|
|
10
|
+
export { createProxyMiddleware } from "./middleware/proxy.ts";
|
|
11
|
+
export { createHtmlMiddleware } from "./middleware/html.ts";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
export { createApiVersionPlugin } from "./plugins/api-version.js";
|
|
7
|
+
export { DEFAULT_API_VERSION, DEFAULT_PORT, getPort } from "./utils.js";
|
|
8
|
+
export { createProxyMiddleware } from "./middleware/proxy.js";
|
|
9
|
+
export { createHtmlMiddleware } from "./middleware/html.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import type { Middleware, SalesforceOptions } from "../types.ts";
|
|
7
|
+
export declare function createHtmlMiddleware(options?: SalesforceOptions): Promise<Middleware>;
|
|
8
|
+
//# sourceMappingURL=html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/middleware/html.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmBH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA8DjE,wBAAsB,oBAAoB,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CA+E/F"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* HTML injection middleware for ng serve.
|
|
8
|
+
* Intercepts HTML navigation responses (SPA routes) and injects the Live
|
|
9
|
+
* Preview script, SFDC_ENV global, and base href. Skips static files and
|
|
10
|
+
* /services/ paths.
|
|
11
|
+
*
|
|
12
|
+
* Execution order: BEFORE proxy middleware (wrapping must happen first).
|
|
13
|
+
*
|
|
14
|
+
* The transform is split into two parts within this file: createIndexHtmlTransformer
|
|
15
|
+
* is a pure string-in/string-out function (easy to unit-test on its own), and
|
|
16
|
+
* createHtmlMiddleware is the res/req plumbing that buffers the response and feeds
|
|
17
|
+
* it through that transform. The transformer is intentionally not part of the
|
|
18
|
+
* package's public API — it is only ever consumed by this middleware.
|
|
19
|
+
*/
|
|
20
|
+
import { getOrgInfo } from "@salesforce/ui-bundle/app";
|
|
21
|
+
import { injectLivePreviewScript } from "@salesforce/ui-bundle/proxy";
|
|
22
|
+
import { getCodeBuilderBasePath, getPort } from "../utils.js";
|
|
23
|
+
/**
|
|
24
|
+
* Factory: creates an HTML transform function bound to the current environment.
|
|
25
|
+
* Resolves basePath once (from CODE_BUILDER_FRAMEWORK_PROXY_URI or "/") and
|
|
26
|
+
* returns a pure transform. Only invoked by the ng serve middleware, so it
|
|
27
|
+
* always injects — there is no build-time caller to guard against.
|
|
28
|
+
*/
|
|
29
|
+
async function createIndexHtmlTransformer(options = {}) {
|
|
30
|
+
const port = getPort();
|
|
31
|
+
const codeBuilderProxyUrl = process.env.CODE_BUILDER_FRAMEWORK_PROXY_URI;
|
|
32
|
+
const isCodeBuilder = !!codeBuilderProxyUrl;
|
|
33
|
+
const basePath = isCodeBuilder ? getCodeBuilderBasePath(codeBuilderProxyUrl, port) : "/";
|
|
34
|
+
const apiPath = basePath;
|
|
35
|
+
// Resolve org URL for SFDC_ENV (used by Lightning Out, etc.)
|
|
36
|
+
let orgUrl;
|
|
37
|
+
try {
|
|
38
|
+
const orgInfo = await getOrgInfo(options.orgAlias);
|
|
39
|
+
orgUrl = orgInfo?.instanceUrl;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
orgUrl = undefined;
|
|
43
|
+
}
|
|
44
|
+
if (options.debug) {
|
|
45
|
+
console.log(`[angular-plugin-ui-bundle] HTML transformer: basePath="${basePath}", isCodeBuilder=${isCodeBuilder}, port=${port}, orgUrl=${orgUrl}`);
|
|
46
|
+
}
|
|
47
|
+
return (html) => {
|
|
48
|
+
// 1. Live Preview script (enables VS Code extension communication)
|
|
49
|
+
html = injectLivePreviewScript(html);
|
|
50
|
+
// 2. Inject <base href> with computed basePath (Code Builder or "/")
|
|
51
|
+
// If a base tag exists, replace it; otherwise inject after <head> (or skip if no <head>)
|
|
52
|
+
const baseHref = basePath.endsWith("/") ? basePath : `${basePath}/`;
|
|
53
|
+
// Match any <base ...> tag (single/double quotes, attributes in any order).
|
|
54
|
+
const baseTagRegex = /<base\b[^>]*>/i;
|
|
55
|
+
if (baseTagRegex.test(html)) {
|
|
56
|
+
html = html.replace(baseTagRegex, `<base href="${baseHref}">`);
|
|
57
|
+
}
|
|
58
|
+
else if (/<head(\s[^>]*)?>/i.test(html)) {
|
|
59
|
+
html = html.replace(/<head(\s[^>]*)?>/i, (match) => `${match}\n <base href="${baseHref}">`);
|
|
60
|
+
}
|
|
61
|
+
// 3. SFDC_ENV global (basePath + apiPath + orgUrl)
|
|
62
|
+
const orgUrlEntry = orgUrl ? `, orgUrl: "${orgUrl}"` : "";
|
|
63
|
+
const sfdcEnvScript = `<script>(function() { globalThis.SFDC_ENV = { basePath: "${basePath}", apiPath: "${apiPath}"${orgUrlEntry} }; })();</script>`;
|
|
64
|
+
if (html.includes("</head>")) {
|
|
65
|
+
html = html.replace("</head>", ` ${sfdcEnvScript}\n</head>`);
|
|
66
|
+
}
|
|
67
|
+
return html;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export async function createHtmlMiddleware(options = {}) {
|
|
71
|
+
const htmlTransformer = await createIndexHtmlTransformer(options);
|
|
72
|
+
return (req, res, next) => {
|
|
73
|
+
// Skip static files (.js, .css, .ico) and internal paths
|
|
74
|
+
const url = req.url?.split("?")[0] ?? "/";
|
|
75
|
+
const hasExtension = url.lastIndexOf(".") > url.lastIndexOf("/");
|
|
76
|
+
const isServicePath = url.startsWith("/services/") || url.startsWith("/@");
|
|
77
|
+
if (hasExtension || isServicePath) {
|
|
78
|
+
if (next)
|
|
79
|
+
next();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Wrap response to intercept HTML from Angular's Vite dev server
|
|
83
|
+
const originalEnd = res.end.bind(res);
|
|
84
|
+
let body = Buffer.from("");
|
|
85
|
+
res.write = function (chunk) {
|
|
86
|
+
body = Buffer.concat([body, Buffer.from(chunk)]);
|
|
87
|
+
return true;
|
|
88
|
+
};
|
|
89
|
+
res.end = function (chunk) {
|
|
90
|
+
if (chunk) {
|
|
91
|
+
body = Buffer.concat([body, Buffer.from(chunk)]);
|
|
92
|
+
}
|
|
93
|
+
// Skip transformation if content-type header is present and not text/html
|
|
94
|
+
const contentType = res.getHeader("content-type");
|
|
95
|
+
if (contentType !== undefined) {
|
|
96
|
+
const contentTypeStr = Array.isArray(contentType)
|
|
97
|
+
? (contentType[0] ?? "")
|
|
98
|
+
: String(contentType);
|
|
99
|
+
if (!contentTypeStr.includes("text/html")) {
|
|
100
|
+
originalEnd(body);
|
|
101
|
+
return res;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const html = body.toString("utf8");
|
|
105
|
+
try {
|
|
106
|
+
const transformedResult = htmlTransformer(html);
|
|
107
|
+
Promise.resolve(transformedResult)
|
|
108
|
+
.then((finalHtml) => {
|
|
109
|
+
if (options.debug) {
|
|
110
|
+
console.log("[angular-plugin-ui-bundle] HTML transformed for dev mode");
|
|
111
|
+
}
|
|
112
|
+
const finalBuffer = Buffer.from(finalHtml, "utf8");
|
|
113
|
+
if (!res.headersSent) {
|
|
114
|
+
res.setHeader("content-length", finalBuffer.byteLength);
|
|
115
|
+
}
|
|
116
|
+
originalEnd(finalBuffer);
|
|
117
|
+
})
|
|
118
|
+
.catch((error) => {
|
|
119
|
+
console.error("[angular-plugin-ui-bundle] HTML transformation failed:", error);
|
|
120
|
+
const fallbackBuffer = Buffer.from(html, "utf8");
|
|
121
|
+
if (!res.headersSent) {
|
|
122
|
+
res.setHeader("content-length", fallbackBuffer.byteLength);
|
|
123
|
+
}
|
|
124
|
+
originalEnd(fallbackBuffer);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error("[angular-plugin-ui-bundle] HTML transformation failed:", error);
|
|
129
|
+
const fallbackBuffer = Buffer.from(html, "utf8");
|
|
130
|
+
if (!res.headersSent) {
|
|
131
|
+
res.setHeader("content-length", fallbackBuffer.byteLength);
|
|
132
|
+
}
|
|
133
|
+
originalEnd(fallbackBuffer);
|
|
134
|
+
}
|
|
135
|
+
return res;
|
|
136
|
+
};
|
|
137
|
+
// Let Angular serve the HTML — we intercept via wrapped res.end
|
|
138
|
+
if (next)
|
|
139
|
+
next();
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import type { Middleware, SalesforceOptions } from "../types.ts";
|
|
7
|
+
export declare function createProxyMiddleware(options?: SalesforceOptions): Promise<Middleware>;
|
|
8
|
+
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/middleware/proxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgBH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAuBjE,wBAAsB,qBAAqB,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CAkEhG"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Proxy middleware factory.
|
|
8
|
+
* Forwards /services/* requests to the connected Salesforce org with auth.
|
|
9
|
+
* Watches ui-bundle.json for route changes and rebuilds handler automatically.
|
|
10
|
+
*
|
|
11
|
+
* Execution order: AFTER HTML middleware.
|
|
12
|
+
*/
|
|
13
|
+
import { resolve } from "node:path";
|
|
14
|
+
import { loadManifest, getOrgInfo } from "@salesforce/ui-bundle/app";
|
|
15
|
+
import { createProxyHandler } from "@salesforce/ui-bundle/proxy";
|
|
16
|
+
import { watch } from "chokidar";
|
|
17
|
+
import { getCodeBuilderBasePath, getPort } from "../utils.js";
|
|
18
|
+
function buildHandler(manifest, orgInfo, options) {
|
|
19
|
+
const port = getPort();
|
|
20
|
+
const codeBuilderProxyUrl = process.env.CODE_BUILDER_FRAMEWORK_PROXY_URI;
|
|
21
|
+
const target = codeBuilderProxyUrl
|
|
22
|
+
? getCodeBuilderBasePath(codeBuilderProxyUrl, port)
|
|
23
|
+
: `http://localhost:${port}`;
|
|
24
|
+
// basePath must be undefined for local dev (not "/") to avoid double-slash in routes
|
|
25
|
+
const basePath = codeBuilderProxyUrl
|
|
26
|
+
? getCodeBuilderBasePath(codeBuilderProxyUrl, port)
|
|
27
|
+
: undefined;
|
|
28
|
+
return createProxyHandler(manifest, orgInfo, target, basePath, {
|
|
29
|
+
debug: options.debug ?? false,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export async function createProxyMiddleware(options = {}) {
|
|
33
|
+
// Function-local state — captured by closures below
|
|
34
|
+
let cachedManifest;
|
|
35
|
+
let cachedOrgInfo;
|
|
36
|
+
let currentHandler;
|
|
37
|
+
const manifestPath = resolve(process.cwd(), "ui-bundle.json");
|
|
38
|
+
if (!cachedManifest) {
|
|
39
|
+
cachedManifest = await loadManifest(manifestPath);
|
|
40
|
+
}
|
|
41
|
+
if (!cachedOrgInfo) {
|
|
42
|
+
try {
|
|
43
|
+
cachedOrgInfo = await getOrgInfo(options.orgAlias);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
cachedOrgInfo = undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (cachedManifest) {
|
|
50
|
+
currentHandler = buildHandler(cachedManifest, cachedOrgInfo, options);
|
|
51
|
+
}
|
|
52
|
+
// Watch manifest — rebuild handler on change (no browser reload, manual refresh needed)
|
|
53
|
+
const watcher = watch(manifestPath, { ignoreInitial: true });
|
|
54
|
+
watcher.on("change", async () => {
|
|
55
|
+
try {
|
|
56
|
+
const updated = await loadManifest(manifestPath);
|
|
57
|
+
if (updated) {
|
|
58
|
+
cachedManifest = updated;
|
|
59
|
+
currentHandler = buildHandler(cachedManifest, cachedOrgInfo, options);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error("[angular-plugin-ui-bundle] Failed to reload ui-bundle.json:", error);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const middleware = async (req, res, next) => {
|
|
67
|
+
// Health check for sf ui-bundle dev orchestrator
|
|
68
|
+
if (req.url?.includes("sfProxyHealthCheck=true")) {
|
|
69
|
+
res.setHeader("X-Salesforce-UIBundle-Proxy", "true");
|
|
70
|
+
res.writeHead(200);
|
|
71
|
+
res.end();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (currentHandler) {
|
|
75
|
+
try {
|
|
76
|
+
await currentHandler(req, res, next);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error("[angular-plugin-ui-bundle] Proxy handler error:", error);
|
|
80
|
+
if (next)
|
|
81
|
+
next();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// No manifest loaded — 503 for API requests, pass through for others
|
|
86
|
+
if (req.url?.startsWith("/services")) {
|
|
87
|
+
res.writeHead(503, { "Content-Type": "application/json" });
|
|
88
|
+
res.end(JSON.stringify({ error: "Proxy not initialized" }));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (next)
|
|
92
|
+
next();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return middleware;
|
|
96
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import type { Plugin } from "esbuild";
|
|
7
|
+
import type { SalesforceOptions } from "../types.ts";
|
|
8
|
+
export interface ApiVersionResult {
|
|
9
|
+
plugin: Plugin;
|
|
10
|
+
version: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* esbuild plugin that substitutes __SF_API_VERSION__ at build time.
|
|
14
|
+
* Wired into angular.json plugins[] via @angular-builders/custom-esbuild.
|
|
15
|
+
*
|
|
16
|
+
* Returns { plugin, version } because esbuild rejects unknown properties
|
|
17
|
+
* on Plugin objects — version is exposed separately for bin/serve.ts to
|
|
18
|
+
* forward via --define.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createApiVersionPlugin(options?: SalesforceOptions): Promise<ApiVersionResult>;
|
|
21
|
+
//# sourceMappingURL=api-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-version.d.ts","sourceRoot":"","sources":["../../src/plugins/api-version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,SAAS,CAAC;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC3C,OAAO,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CAgB3B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import { resolveApiVersion } from "../api-version.js";
|
|
7
|
+
/**
|
|
8
|
+
* esbuild plugin that substitutes __SF_API_VERSION__ at build time.
|
|
9
|
+
* Wired into angular.json plugins[] via @angular-builders/custom-esbuild.
|
|
10
|
+
*
|
|
11
|
+
* Returns { plugin, version } because esbuild rejects unknown properties
|
|
12
|
+
* on Plugin objects — version is exposed separately for bin/serve.ts to
|
|
13
|
+
* forward via --define.
|
|
14
|
+
*/
|
|
15
|
+
export async function createApiVersionPlugin(options = {}) {
|
|
16
|
+
const version = await resolveApiVersion(options.orgAlias);
|
|
17
|
+
if (options.debug) {
|
|
18
|
+
console.log(`[angular-plugin-ui-bundle] API version resolved: ${version}`);
|
|
19
|
+
}
|
|
20
|
+
const plugin = {
|
|
21
|
+
name: "@salesforce/angular-plugin-ui-bundle:api-version",
|
|
22
|
+
setup(build) {
|
|
23
|
+
build.initialOptions.define ??= {};
|
|
24
|
+
build.initialOptions.define["__SF_API_VERSION__"] = JSON.stringify(version);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
return { plugin, version };
|
|
28
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
7
|
+
export interface SalesforceOptions {
|
|
8
|
+
orgAlias?: string;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type Middleware = (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => void;
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,CACxB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,KACzB,IAAI,CAAC"}
|
package/dist/types.js
ADDED
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_API_VERSION = "65.0";
|
|
7
|
+
export declare const DEFAULT_PORT = 5173;
|
|
8
|
+
export declare function getPort(): number;
|
|
9
|
+
/** Extract path from Code Builder proxy URI. Same logic as vite-plugin-ui-bundle. */
|
|
10
|
+
export declare function getCodeBuilderBasePath(proxyUri: string, port: number): string;
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,wBAAgB,OAAO,IAAI,MAAM,CAEhC;AAED,qFAAqF;AACrF,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ7E"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_API_VERSION = "65.0";
|
|
7
|
+
export const DEFAULT_PORT = 5173;
|
|
8
|
+
export function getPort() {
|
|
9
|
+
return parseInt(process.env.SF_UIBUNDLE_PORT || DEFAULT_PORT.toString(), 10);
|
|
10
|
+
}
|
|
11
|
+
/** Extract path from Code Builder proxy URI. Same logic as vite-plugin-ui-bundle. */
|
|
12
|
+
export function getCodeBuilderBasePath(proxyUri, port) {
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(proxyUri.replace("{{port}}", port.toString()));
|
|
15
|
+
return url.pathname;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error("Failed to parse CODE_BUILDER_FRAMEWORK_PROXY_URI:", error);
|
|
19
|
+
return `/absproxy/${port}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/angular-plugin-ui-bundle",
|
|
3
|
+
"description": "Angular CLI plugin for Salesforce UI Bundles",
|
|
4
|
+
"version": "10.23.0",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"sf-angular-serve": "./dist/bin/serve.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.build.json",
|
|
25
|
+
"clean": "rm -rf dist",
|
|
26
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"test:coverage": "vitest run --coverage"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@salesforce/ui-bundle": "^10.23.0",
|
|
33
|
+
"chokidar": "^4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^24.9.2",
|
|
37
|
+
"esbuild": "^0.27.4",
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"vitest": "^4.0.6"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@angular-builders/custom-esbuild": "^21.0.0"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20.0.0"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
50
|
+
}
|