@salesforce/ui-bundle 12.11.0 → 12.12.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/dist/app/dev-config.d.ts +37 -0
- package/dist/app/dev-config.d.ts.map +1 -0
- package/dist/app/dev-config.js +42 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +2 -0
- package/dist/index.js +2 -0
- package/dist/package.json.js +1 -1
- package/dist/proxy/handler.d.ts +6 -0
- package/dist/proxy/handler.d.ts.map +1 -1
- package/dist/proxy/handler.js +101 -20
- package/dist/proxy/routing.d.ts +18 -2
- package/dist/proxy/routing.d.ts.map +1 -1
- package/dist/proxy/routing.js +44 -14
- package/package.json +2 -2
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Dev-only proxy configuration, read from `ui-bundle.dev.json` at dev/preview
|
|
8
|
+
* time. This is NOT the deploy manifest (`ui-bundle.json`) — it is never
|
|
9
|
+
* bundled or deployed, and the platform never sees it. When the file is absent
|
|
10
|
+
* the plugin behaves exactly as it does without any dev config (today's
|
|
11
|
+
* behavior).
|
|
12
|
+
*
|
|
13
|
+
* `corePaths` extends the proxy's hardcoded allowlist with Core-served UI
|
|
14
|
+
* assets (an embedded LWR/Aura micro-frontend and its bootstrap assets) the
|
|
15
|
+
* stock list omits. Forwarded to the org, but with same-origin referer/origin
|
|
16
|
+
* and WITHOUT live-preview `<script>` injection.
|
|
17
|
+
*
|
|
18
|
+
* Custom Connect API paths (e.g. Codey's `codeystudio`) are NOT configurable
|
|
19
|
+
* here — the allowlist for those is managed inside the Vite plugin itself
|
|
20
|
+
* (`routing.ts`). A team needing a new API path submits a PR to the plugin.
|
|
21
|
+
*/
|
|
22
|
+
export interface DevProxyConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Glob patterns for Core-served UI assets to forward to the org with
|
|
25
|
+
* same-origin headers and no HTML injection. Each must be a root-anchored path.
|
|
26
|
+
*/
|
|
27
|
+
corePaths?: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Load and validate the optional dev-proxy config (`ui-bundle.dev.json`).
|
|
31
|
+
*
|
|
32
|
+
* @param configPath - Path to the ui-bundle.dev.json file
|
|
33
|
+
* @returns The parsed config, or `undefined` if the file does not exist
|
|
34
|
+
* @throws Error if the file exists but is invalid JSON or fails validation
|
|
35
|
+
*/
|
|
36
|
+
export declare function loadDevProxyConfig(configPath: string): Promise<DevProxyConfig | undefined>;
|
|
37
|
+
//# sourceMappingURL=dev-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-config.d.ts","sourceRoot":"","sources":["../../src/app/dev-config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,cAAc;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAoCD;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAoBhG"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
function validateDevProxyPaths(field, patterns) {
|
|
3
|
+
if (!patterns) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (!Array.isArray(patterns)) {
|
|
7
|
+
throw new Error(`ui-bundle.dev.json: "${field}" must be an array of path strings`);
|
|
8
|
+
}
|
|
9
|
+
for (const pattern of patterns) {
|
|
10
|
+
if (typeof pattern !== "string" || !pattern.startsWith("/")) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`ui-bundle.dev.json: "${field}" entries must be root-anchored paths starting with "/" (got ${JSON.stringify(pattern)})`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if (pattern.startsWith("//") || pattern.includes("..")) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`ui-bundle.dev.json: "${field}" entries must not start with "//" or contain ".." (got ${JSON.stringify(pattern)})`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function loadDevProxyConfig(configPath) {
|
|
23
|
+
let content;
|
|
24
|
+
try {
|
|
25
|
+
content = await readFile(configPath, "utf-8");
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
const parsed = JSON.parse(content);
|
|
33
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
34
|
+
throw new Error(`ui-bundle.dev.json: expected a JSON object, got ${JSON.stringify(parsed)}`);
|
|
35
|
+
}
|
|
36
|
+
const config = parsed;
|
|
37
|
+
validateDevProxyPaths("corePaths", config.corePaths);
|
|
38
|
+
return config;
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
loadDevProxyConfig
|
|
42
|
+
};
|
package/dist/app/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type { OrgInfo } from './org';
|
|
|
7
7
|
export { getOrgInfo, refreshOrgAuth } from './org';
|
|
8
8
|
export type { UIBundleManifest, UIBundleTarget, RoutingConfig, RewriteRule, RedirectRule, } from './manifest';
|
|
9
9
|
export { loadManifest, resolveMetaTarget, UI_BUNDLE_TARGETS } from './manifest';
|
|
10
|
+
export type { DevProxyConfig } from './dev-config';
|
|
11
|
+
export { loadDevProxyConfig } from './dev-config';
|
|
10
12
|
export type { MetaXmlOptions } from './meta-xml';
|
|
11
13
|
export { generateUIBundleMetaXml } from './meta-xml';
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/app/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACnD,YAAY,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,WAAW,EACX,YAAY,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAChF,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACnD,YAAY,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,WAAW,EACX,YAAY,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAChF,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/app/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { getOrgInfo, refreshOrgAuth } from "./org.js";
|
|
2
2
|
import { UI_BUNDLE_TARGETS, loadManifest, resolveMetaTarget } from "./manifest.js";
|
|
3
|
+
import { loadDevProxyConfig } from "./dev-config.js";
|
|
3
4
|
import { generateUIBundleMetaXml } from "./meta-xml.js";
|
|
4
5
|
export {
|
|
5
6
|
UI_BUNDLE_TARGETS,
|
|
6
7
|
generateUIBundleMetaXml,
|
|
7
8
|
getOrgInfo,
|
|
9
|
+
loadDevProxyConfig,
|
|
8
10
|
loadManifest,
|
|
9
11
|
refreshOrgAuth,
|
|
10
12
|
resolveMetaTarget
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createRecord, deleteRecord, getRecord, updateRecord } from "./api/utils
|
|
|
4
4
|
import { getCurrentUser } from "./api/utils/user.js";
|
|
5
5
|
import { getOrgInfo, refreshOrgAuth } from "./app/org.js";
|
|
6
6
|
import { UI_BUNDLE_TARGETS, loadManifest, resolveMetaTarget } from "./app/manifest.js";
|
|
7
|
+
import { loadDevProxyConfig } from "./app/dev-config.js";
|
|
7
8
|
import { generateUIBundleMetaXml } from "./app/meta-xml.js";
|
|
8
9
|
import { UIBUNDLE_HEALTH_CHECK_PARAM, UIBUNDLE_PROXY_HEADER, createProxyHandler, injectLivePreviewScript } from "./proxy/handler.js";
|
|
9
10
|
export {
|
|
@@ -19,6 +20,7 @@ export {
|
|
|
19
20
|
getOrgInfo,
|
|
20
21
|
getRecord,
|
|
21
22
|
injectLivePreviewScript,
|
|
23
|
+
loadDevProxyConfig,
|
|
22
24
|
loadManifest,
|
|
23
25
|
refreshOrgAuth,
|
|
24
26
|
resolveMetaTarget,
|
package/dist/package.json.js
CHANGED
package/dist/proxy/handler.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { DevProxyPaths } from './routing';
|
|
2
3
|
import { OrgInfo, UIBundleManifest } from '../app/index';
|
|
3
4
|
/** The URL parameter that triggers the health-check response. */
|
|
4
5
|
export declare const UIBUNDLE_HEALTH_CHECK_PARAM = "sfProxyHealthCheck";
|
|
@@ -10,6 +11,11 @@ export declare const UIBUNDLE_PROXY_HEADER = "X-Salesforce-UIBundle-Proxy";
|
|
|
10
11
|
export interface ProxyOptions {
|
|
11
12
|
debug?: boolean;
|
|
12
13
|
onTokenRefresh?: (updatedOrgInfo: OrgInfo) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Optional dev-only path family from `ui-bundle.dev.json` that extends the
|
|
16
|
+
* hardcoded route allowlist. See {@link DevProxyPaths}.
|
|
17
|
+
*/
|
|
18
|
+
devPaths?: DevProxyPaths;
|
|
13
19
|
/**
|
|
14
20
|
* UI-only preview mode.
|
|
15
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/proxy/handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/proxy/handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAoD,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAGjG,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG9D,iEAAiE;AACjE,eAAO,MAAM,2BAA2B,uBAAuB,CAAC;AAEhE,8DAA8D;AAC9D,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AAuBnE;;GAEG;AACH,MAAM,WAAW,YAAY;IAE5B,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,cAAc,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,KAAK,IAAI,CAAC;IACnD;;;OAGG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,uCAAuC;AACvC,MAAM,MAAM,YAAY,GAAG,CAC1B,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,IAAI,CAAC,EAAE,MAAM,IAAI,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;AAw6BnB;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,CAAC,EAAE,OAAO,EACjB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,YAAY,GACpB,YAAY,CAGd;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5D"}
|
package/dist/proxy/handler.js
CHANGED
|
@@ -58,20 +58,30 @@ class UIBundleProxyHandler {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
pathname,
|
|
61
|
+
const matchPath = (path) => matchRoute(
|
|
62
|
+
path,
|
|
64
63
|
this.basePath,
|
|
65
64
|
this.manifest.routing?.rewrites,
|
|
66
|
-
this.manifest.routing?.redirects
|
|
65
|
+
this.manifest.routing?.redirects,
|
|
66
|
+
this.options?.devPaths
|
|
67
67
|
);
|
|
68
|
+
const originalMatch = matchPath(pathname);
|
|
69
|
+
pathname = applyTrailingSlash(pathname, this.manifest.routing?.trailingSlash);
|
|
70
|
+
const match = originalMatch?.type === "core-asset" ? originalMatch : matchPath(pathname);
|
|
68
71
|
if (match) {
|
|
69
|
-
if (this.options?.uiOnly && (match.type === "api" || match.type === "gql" || match.type === "file-upload" || match.type === "cometd")) {
|
|
72
|
+
if (this.options?.uiOnly && (match.type === "api" || match.type === "gql" || match.type === "file-upload" || match.type === "cometd" || match.type === "core-asset")) {
|
|
70
73
|
this.sendOrgDataDisabled(res);
|
|
71
74
|
return;
|
|
72
75
|
}
|
|
73
76
|
if (match.type === "api") {
|
|
74
|
-
await this.handleSalesforceApi(req, res, match.path, match.myDomain);
|
|
77
|
+
await this.handleSalesforceApi(req, res, match.path, match.myDomain, match.auth);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (match.type === "core-asset") {
|
|
81
|
+
if (this.options?.debug) {
|
|
82
|
+
console.log("[ui-bundle-proxy] core-asset match found → handleCoreAsset");
|
|
83
|
+
}
|
|
84
|
+
await this.handleCoreAsset(req, res, match.path);
|
|
75
85
|
return;
|
|
76
86
|
}
|
|
77
87
|
if (match.type === "gql") {
|
|
@@ -252,7 +262,7 @@ class UIBundleProxyHandler {
|
|
|
252
262
|
const data = await response.json();
|
|
253
263
|
return data.frontdoor_uri ?? null;
|
|
254
264
|
}
|
|
255
|
-
async handleSalesforceApi(req, res, apiPath, myDomain) {
|
|
265
|
+
async handleSalesforceApi(req, res, apiPath, myDomain, auth = "bearer-and-cookie") {
|
|
256
266
|
try {
|
|
257
267
|
if (!this.orgInfo) {
|
|
258
268
|
this.sendNoOrgError(res);
|
|
@@ -266,16 +276,9 @@ class UIBundleProxyHandler {
|
|
|
266
276
|
}
|
|
267
277
|
const response = await this.fetchWithAuthRetry(req, (orgInfo) => ({
|
|
268
278
|
url: `${getApiHost(orgInfo, myDomain)}${apiPath}${url.search}`,
|
|
269
|
-
headers:
|
|
270
|
-
...getFilteredHeaders(req.headers),
|
|
271
|
-
Cookie: `sid=${orgInfo.accessToken}`,
|
|
272
|
-
Accept: req.headers.accept ?? "application/json",
|
|
273
|
-
// Apex requests need this header, because SessionUtil.validateSessionUsage does not
|
|
274
|
-
// accept the OAuth token as the `sid` cookie.
|
|
275
|
-
Authorization: `Bearer ${orgInfo.accessToken}`
|
|
276
|
-
}
|
|
279
|
+
headers: salesforceApiHeaders(req.headers, orgInfo.accessToken, auth)
|
|
277
280
|
}));
|
|
278
|
-
await this.sendResponse(res, response);
|
|
281
|
+
await this.sendResponse(res, response, { injectScript: false });
|
|
279
282
|
} catch (error) {
|
|
280
283
|
console.error("[ui-bundle-proxy] Salesforce API request failed:", error);
|
|
281
284
|
this.sendAuthOrGatewayError(res, error, "Failed to forward request to Salesforce");
|
|
@@ -354,7 +357,7 @@ class UIBundleProxyHandler {
|
|
|
354
357
|
this.sendAuthOrGatewayError(res, error, "Failed to forward GraphQL request to Salesforce");
|
|
355
358
|
}
|
|
356
359
|
}
|
|
357
|
-
async sendResponse(res, response) {
|
|
360
|
+
async sendResponse(res, response, options) {
|
|
358
361
|
const headers = {};
|
|
359
362
|
const skipHeaders = /* @__PURE__ */ new Set(["content-encoding", "content-length", "transfer-encoding"]);
|
|
360
363
|
response.headers.forEach((value, key) => {
|
|
@@ -363,7 +366,7 @@ class UIBundleProxyHandler {
|
|
|
363
366
|
}
|
|
364
367
|
});
|
|
365
368
|
const contentType = response.headers.get("content-type") || "";
|
|
366
|
-
const isHtml = contentType.includes("text/html");
|
|
369
|
+
const isHtml = contentType.includes("text/html") && options?.injectScript !== false;
|
|
367
370
|
if (isHtml && response.body) {
|
|
368
371
|
const chunks = [];
|
|
369
372
|
const reader = response.body.getReader();
|
|
@@ -528,6 +531,73 @@ class UIBundleProxyHandler {
|
|
|
528
531
|
this.sendAuthOrGatewayError(res, error, "Failed to forward CometD request");
|
|
529
532
|
}
|
|
530
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* Proxies a dev-only Core-served UI asset (ui-bundle.dev.json `corePaths`) to
|
|
536
|
+
* Salesforce. Rewrites referer/origin to the org's own origin because
|
|
537
|
+
* Core validates those headers itself and rejects the dev server's localhost
|
|
538
|
+
* origin outright. Never injects the live-preview script into the response
|
|
539
|
+
* — this is Core's own markup, not the UI Bundle's shell.
|
|
540
|
+
*/
|
|
541
|
+
async handleCoreAsset(req, res, apiPath) {
|
|
542
|
+
try {
|
|
543
|
+
if (!this.orgInfo) {
|
|
544
|
+
this.sendNoOrgError(res);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
const { search } = new URL(req.url ?? "/", `http://${req.headers.host}`);
|
|
548
|
+
const buildRequest = (orgInfo) => ({
|
|
549
|
+
url: `${orgInfo.rawInstanceUrl}${apiPath}${search}`,
|
|
550
|
+
headers: this.coreAssetHeaders(req, orgInfo)
|
|
551
|
+
});
|
|
552
|
+
if (this.options?.debug) {
|
|
553
|
+
console.log(
|
|
554
|
+
`[ui-bundle-proxy] Forwarding core asset to Salesforce: ${buildRequest(this.orgInfo).url}`
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
const body = req.method !== "GET" && req.method !== "HEAD" ? await getBody(req) : void 0;
|
|
558
|
+
const execute = (orgInfo) => {
|
|
559
|
+
const { url, headers } = buildRequest(orgInfo);
|
|
560
|
+
return fetch(url, {
|
|
561
|
+
method: req.method,
|
|
562
|
+
headers,
|
|
563
|
+
body
|
|
564
|
+
});
|
|
565
|
+
};
|
|
566
|
+
let response = await execute(this.orgInfo);
|
|
567
|
+
if (response.status === 401) {
|
|
568
|
+
console.warn("[ui-bundle-proxy] Received 401 on core asset, refreshing token...");
|
|
569
|
+
const updatedOrgInfo = await this.refreshToken();
|
|
570
|
+
if (!updatedOrgInfo) {
|
|
571
|
+
console.error("[ui-bundle-proxy] Failed to refresh token - authentication error");
|
|
572
|
+
throw new AuthenticationError("Failed to refresh token");
|
|
573
|
+
}
|
|
574
|
+
response = await execute(updatedOrgInfo);
|
|
575
|
+
}
|
|
576
|
+
await this.sendResponse(res, response, { injectScript: false });
|
|
577
|
+
} catch (error) {
|
|
578
|
+
console.error("[ui-bundle-proxy] Core asset request failed:", error);
|
|
579
|
+
this.sendAuthOrGatewayError(res, error, "Failed to forward core asset request to Salesforce");
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Builds the forwarding headers for a Core-asset request. Rewrites `referer` and
|
|
584
|
+
* `origin` to the org's own origin, but only when the inbound request actually
|
|
585
|
+
* carries the header.
|
|
586
|
+
*/
|
|
587
|
+
coreAssetHeaders(req, orgInfo) {
|
|
588
|
+
const headers = {
|
|
589
|
+
...getFilteredHeaders(req.headers, ["authorization"]),
|
|
590
|
+
Cookie: `sid=${orgInfo.accessToken}`
|
|
591
|
+
};
|
|
592
|
+
const orgOrigin = new URL(orgInfo.rawInstanceUrl).origin;
|
|
593
|
+
if (headers.referer) {
|
|
594
|
+
headers.referer = `${orgOrigin}/`;
|
|
595
|
+
}
|
|
596
|
+
if (headers.origin) {
|
|
597
|
+
headers.origin = orgOrigin;
|
|
598
|
+
}
|
|
599
|
+
return headers;
|
|
600
|
+
}
|
|
531
601
|
}
|
|
532
602
|
function createProxyHandler(manifest, orgInfo, target, basePath, options) {
|
|
533
603
|
const handler = new UIBundleProxyHandler(manifest, orgInfo, target, basePath, options);
|
|
@@ -539,7 +609,16 @@ function injectLivePreviewScript(html) {
|
|
|
539
609
|
function getApiHost(orgInfo, myDomain) {
|
|
540
610
|
return myDomain ? orgInfo.rawInstanceUrl : orgInfo.instanceUrl;
|
|
541
611
|
}
|
|
542
|
-
function
|
|
612
|
+
function salesforceApiHeaders(inbound, accessToken, auth = "bearer-and-cookie") {
|
|
613
|
+
const headers = getFilteredHeaders(inbound, ["cookie"]);
|
|
614
|
+
return {
|
|
615
|
+
...headers,
|
|
616
|
+
Accept: inbound.accept ?? "application/json",
|
|
617
|
+
Authorization: `Bearer ${accessToken}`,
|
|
618
|
+
...auth === "bearer-and-cookie" ? { Cookie: `sid=${accessToken}` } : {}
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function getFilteredHeaders(headers, excluded = []) {
|
|
543
622
|
const filtered = {};
|
|
544
623
|
const hopByHopHeaders = /* @__PURE__ */ new Set([
|
|
545
624
|
"connection",
|
|
@@ -552,8 +631,10 @@ function getFilteredHeaders(headers) {
|
|
|
552
631
|
"upgrade",
|
|
553
632
|
"content-length"
|
|
554
633
|
]);
|
|
634
|
+
const excludedNames = new Set(excluded.map((name) => name.toLowerCase()));
|
|
555
635
|
for (const [key, value] of Object.entries(headers)) {
|
|
556
|
-
|
|
636
|
+
const name = key.toLowerCase();
|
|
637
|
+
if (!hopByHopHeaders.has(name) && !excludedNames.has(name) && value) {
|
|
557
638
|
filtered[key] = Array.isArray(value) ? value.join(", ") : typeof value === "string" ? value : String(value);
|
|
558
639
|
}
|
|
559
640
|
}
|
package/dist/proxy/routing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RedirectRule, RewriteRule } from '../app/index';
|
|
2
|
-
export type RouteMatch = GeneralRouteMatch | OrgPathRouteMatch | ApiRouteMatch | RewriteRouteMatch | RedirectRouteMatch;
|
|
2
|
+
export type RouteMatch = GeneralRouteMatch | OrgPathRouteMatch | ApiRouteMatch | CoreAssetRouteMatch | RewriteRouteMatch | RedirectRouteMatch;
|
|
3
3
|
interface GeneralRouteMatch {
|
|
4
4
|
type: "gql" | "file-upload";
|
|
5
5
|
}
|
|
@@ -17,10 +17,25 @@ interface RedirectRouteMatch {
|
|
|
17
17
|
target: string;
|
|
18
18
|
statusCode: 301 | 302 | 307 | 308;
|
|
19
19
|
}
|
|
20
|
+
/** How a Salesforce API route authenticates the forwarded request. */
|
|
21
|
+
export type ApiAuthMode = "bearer" | "bearer-and-cookie";
|
|
20
22
|
interface ApiRouteMatch {
|
|
21
23
|
type: "api";
|
|
22
24
|
path: string;
|
|
23
25
|
myDomain?: boolean;
|
|
26
|
+
auth: ApiAuthMode;
|
|
27
|
+
}
|
|
28
|
+
interface CoreAssetRouteMatch {
|
|
29
|
+
type: "core-asset";
|
|
30
|
+
path: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Optional dev-only path family from `ui-bundle.dev.json` that extends the
|
|
34
|
+
* hardcoded allowlist. See {@link DevProxyConfig}.
|
|
35
|
+
*/
|
|
36
|
+
export interface DevProxyPaths {
|
|
37
|
+
/** Core-served UI assets, forwarded with same-origin headers and no injection. */
|
|
38
|
+
corePaths?: string[];
|
|
24
39
|
}
|
|
25
40
|
/**
|
|
26
41
|
* Matches a URL path against the routing rules.
|
|
@@ -29,9 +44,10 @@ interface ApiRouteMatch {
|
|
|
29
44
|
* @param basePath - The base path of the Salesforce server.
|
|
30
45
|
* @param rewrites - The rewrite rules.
|
|
31
46
|
* @param redirects - The redirect rules.
|
|
47
|
+
* @param devPaths - The optional dev-only core-asset path globs.
|
|
32
48
|
* @returns The route match, which gives the type and target, or `null` when nothing matches.
|
|
33
49
|
*/
|
|
34
|
-
export declare function matchRoute(pathname: string, basePath?: string, rewrites?: RewriteRule[], redirects?: RedirectRule[]): RouteMatch | null;
|
|
50
|
+
export declare function matchRoute(pathname: string, basePath?: string, rewrites?: RewriteRule[], redirects?: RedirectRule[], devPaths?: DevProxyPaths): RouteMatch | null;
|
|
35
51
|
/**
|
|
36
52
|
* Checks whether a path matches any of the given glob patterns.
|
|
37
53
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/proxy/routing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE9D,MAAM,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/proxy/routing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE9D,MAAM,MAAM,UAAU,GACnB,iBAAiB,GACjB,iBAAiB,GACjB,aAAa,GACb,mBAAmB,GACnB,iBAAiB,GACjB,kBAAkB,CAAC;AAEtB,UAAU,iBAAiB;IAC1B,IAAI,EAAE,KAAK,GAAG,aAAa,CAAC;CAC5B;AAKD,UAAU,iBAAiB;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACb;AAED,UAAU,iBAAiB;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAClC;AAED,sEAAsE;AACtE,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,mBAAmB,CAAC;AAEzD,UAAU,aAAa;IACtB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IAMb,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,IAAI,EAAE,WAAW,CAAC;CAClB;AAED,UAAU,mBAAmB;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AASD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACzB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,WAAW,EAAE,EACxB,SAAS,CAAC,EAAE,YAAY,EAAE,EAC1B,QAAQ,CAAC,EAAE,aAAa,GACtB,UAAU,GAAG,IAAI,CAyInB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAMpF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GACzC,MAAM,CAiBR"}
|
package/dist/proxy/routing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "micromatch";
|
|
1
|
+
import micromatch from "micromatch";
|
|
2
2
|
import { match } from "path-to-regexp";
|
|
3
3
|
function normalizeRoute(route) {
|
|
4
4
|
let wildcardIndex = 0;
|
|
@@ -6,26 +6,49 @@ function normalizeRoute(route) {
|
|
|
6
6
|
return `{*wildcard${wildcardIndex++}}`;
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
|
-
function matchRoute(pathname, basePath, rewrites, redirects) {
|
|
9
|
+
function matchRoute(pathname, basePath, rewrites, redirects, devPaths) {
|
|
10
10
|
const base = (basePath || "").replace(/\/$/, "");
|
|
11
|
+
const relPath = pathname.startsWith(base) ? pathname.slice(base.length) : pathname;
|
|
11
12
|
const versionedDataPrefix = `^${base}/services/data/v\\d{2}\\.\\d`;
|
|
12
13
|
if (pathname.startsWith(`${base}/gql/endpoint`)) {
|
|
13
14
|
return { type: "gql" };
|
|
14
15
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
return { type: "api", path: pathname.slice(base.length), myDomain: true };
|
|
18
|
-
}
|
|
19
|
-
const services = [
|
|
20
|
-
"ui-api",
|
|
16
|
+
const myDomainServices = [
|
|
17
|
+
"graphql",
|
|
21
18
|
"connect/cms/delivery",
|
|
22
19
|
"connect/file/upload/config",
|
|
23
|
-
"connect/proxy/ui-telemetry"
|
|
24
|
-
"chatter/users"
|
|
20
|
+
"connect/proxy/ui-telemetry"
|
|
25
21
|
].join("|");
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
return {
|
|
22
|
+
const myDomainDataRegex = new RegExp(`${versionedDataPrefix}/(${myDomainServices})`);
|
|
23
|
+
if (myDomainDataRegex.test(pathname)) {
|
|
24
|
+
return {
|
|
25
|
+
type: "api",
|
|
26
|
+
path: pathname.slice(base.length),
|
|
27
|
+
myDomain: true,
|
|
28
|
+
auth: "bearer-and-cookie"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const lightningDomainServices = ["ui-api", "chatter/users"].join("|");
|
|
32
|
+
const lightningDomainDataRegex = new RegExp(
|
|
33
|
+
`${versionedDataPrefix}/(${lightningDomainServices})`
|
|
34
|
+
);
|
|
35
|
+
if (lightningDomainDataRegex.test(pathname)) {
|
|
36
|
+
return {
|
|
37
|
+
type: "api",
|
|
38
|
+
path: pathname.slice(base.length),
|
|
39
|
+
auth: "bearer-and-cookie"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (pathname.startsWith(`${base}/services/apexrest`)) {
|
|
43
|
+
return {
|
|
44
|
+
type: "api",
|
|
45
|
+
path: pathname.slice(base.length),
|
|
46
|
+
myDomain: true,
|
|
47
|
+
auth: "bearer"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (matchesPattern(relPath, devPaths?.corePaths)) {
|
|
51
|
+
return { type: "core-asset", path: relPath };
|
|
29
52
|
}
|
|
30
53
|
if (pathname.startsWith(`${base}/chatter/handlers/file/body`)) {
|
|
31
54
|
return { type: "file-upload" };
|
|
@@ -83,6 +106,12 @@ function matchRoute(pathname, basePath, rewrites, redirects) {
|
|
|
83
106
|
}
|
|
84
107
|
return null;
|
|
85
108
|
}
|
|
109
|
+
function matchesPattern(path, patterns) {
|
|
110
|
+
if (!patterns || patterns.length === 0) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return micromatch.isMatch(path, patterns);
|
|
114
|
+
}
|
|
86
115
|
function applyTrailingSlash(pathname, trailingSlash) {
|
|
87
116
|
if (!trailingSlash || trailingSlash === "auto") {
|
|
88
117
|
return pathname;
|
|
@@ -99,5 +128,6 @@ function applyTrailingSlash(pathname, trailingSlash) {
|
|
|
99
128
|
}
|
|
100
129
|
export {
|
|
101
130
|
applyTrailingSlash,
|
|
102
|
-
matchRoute
|
|
131
|
+
matchRoute,
|
|
132
|
+
matchesPattern
|
|
103
133
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/ui-bundle",
|
|
3
3
|
"description": "Core package for Salesforce UI Bundles",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.12.1",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@salesforce/core": "^8.23.4",
|
|
42
|
-
"@salesforce/platform-sdk": "^12.
|
|
42
|
+
"@salesforce/platform-sdk": "^12.12.1",
|
|
43
43
|
"micromatch": "^4.0.8",
|
|
44
44
|
"path-to-regexp": "^8.4.2"
|
|
45
45
|
},
|