@salesforce/ui-bundle 12.4.5 → 12.5.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.
@@ -1,4 +1,4 @@
1
- const version = "12.4.5";
1
+ const version = "12.5.0";
2
2
  export {
3
3
  version
4
4
  };
@@ -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;AAIjE,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG9D;;GAEG;AACH,eAAO,MAAM,2BAA2B,uBAAuB,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AAyBnE;;GAEG;AACH,MAAM,WAAW,YAAY;IAE5B,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,cAAc,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,KAAK,IAAI,CAAC;IACnD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAC1B,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,IAAI,CAAC,EAAE,MAAM,IAAI,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;AAmtBnB;;;;;;;;;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"}
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;AAKjE,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG9D;;GAEG;AACH,eAAO,MAAM,2BAA2B,uBAAuB,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AAyBnE;;GAEG;AACH,MAAM,WAAW,YAAY;IAE5B,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,cAAc,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,KAAK,IAAI,CAAC;IACnD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAC1B,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,IAAI,CAAC,EAAE,MAAM,IAAI,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;AAwxBnB;;;;;;;;;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"}
@@ -1,5 +1,6 @@
1
1
  import { LIVE_PREVIEW_SCRIPT_MARKER, getLivePreviewScriptContent } from "./livePreviewScript.js";
2
2
  import { applyTrailingSlash, matchRoute } from "./routing.js";
3
+ import { sendCometDResponse, isTransientLongPollDrop } from "./utils/cometD.js";
3
4
  import { version } from "../package.json.js";
4
5
  import { refreshOrgAuth } from "../app/org.js";
5
6
  import "node:fs/promises";
@@ -65,7 +66,7 @@ class UIBundleProxyHandler {
65
66
  this.manifest.routing?.redirects
66
67
  );
67
68
  if (match) {
68
- if (this.options?.uiOnly && (match.type === "api" || match.type === "gql" || match.type === "file-upload")) {
69
+ if (this.options?.uiOnly && (match.type === "api" || match.type === "gql" || match.type === "file-upload" || match.type === "cometd")) {
69
70
  this.sendOrgDataDisabled(res);
70
71
  return;
71
72
  }
@@ -101,6 +102,13 @@ class UIBundleProxyHandler {
101
102
  await this.handleFileUpload(req, res);
102
103
  return;
103
104
  }
105
+ if (match.type === "cometd") {
106
+ if (this.options?.debug) {
107
+ console.log("[ui-bundle-proxy] cometd match found → handleCometD");
108
+ }
109
+ await this.handleCometD(req, res, match.path);
110
+ return;
111
+ }
104
112
  }
105
113
  if (next) {
106
114
  next();
@@ -483,6 +491,43 @@ class UIBundleProxyHandler {
483
491
  );
484
492
  }
485
493
  }
494
+ /**
495
+ * Proxy CometD long-poll requests (/cometd/<version>) and shared worker scripts
496
+ * (/jslibrary/<hash>/streaming-v2/CometdWorkerJs.js) to Salesforce using session cookies.
497
+ */
498
+ async handleCometD(req, res, apiPath) {
499
+ try {
500
+ if (!this.orgInfo) {
501
+ this.sendNoOrgError(res);
502
+ return;
503
+ }
504
+ const { search } = new URL(req.url ?? "/", `http://${req.headers.host}`);
505
+ if (this.options?.debug) {
506
+ console.log(
507
+ `[ui-bundle-proxy] Forwarding to Salesforce: ${this.orgInfo.rawInstanceUrl}${apiPath}${search}`
508
+ );
509
+ }
510
+ const response = await this.fetchWithAuthRetry(req, (orgInfo) => ({
511
+ url: `${orgInfo.rawInstanceUrl}${apiPath}${search}`,
512
+ headers: {
513
+ ...getFilteredHeaders(req.headers),
514
+ Cookie: `sid=${orgInfo.accessToken}`
515
+ }
516
+ }));
517
+ await sendCometDResponse(res, response);
518
+ } catch (error) {
519
+ if (isTransientLongPollDrop(error)) {
520
+ console.warn(
521
+ "[ui-bundle-proxy] CometD long-poll dropped by upstream, client will reconnect:",
522
+ error
523
+ );
524
+ res.destroy();
525
+ return;
526
+ }
527
+ console.error("[ui-bundle-proxy] CometD proxy failed:", error);
528
+ this.sendAuthOrGatewayError(res, error, "Failed to forward CometD request");
529
+ }
530
+ }
486
531
  }
487
532
  function createProxyHandler(manifest, orgInfo, target, basePath, options) {
488
533
  const handler = new UIBundleProxyHandler(manifest, orgInfo, target, basePath, options);
@@ -1,8 +1,12 @@
1
1
  import { RedirectRule, RewriteRule } from '../app/index';
2
- export type RouteMatch = GeneralRouteMatch | ApiRouteMatch | RewriteRouteMatch | RedirectRouteMatch;
2
+ export type RouteMatch = GeneralRouteMatch | OrgPathRouteMatch | ApiRouteMatch | RewriteRouteMatch | RedirectRouteMatch;
3
3
  interface GeneralRouteMatch {
4
4
  type: "gql" | "file-upload";
5
5
  }
6
+ interface OrgPathRouteMatch {
7
+ type: "cometd";
8
+ path: string;
9
+ }
6
10
  interface RewriteRouteMatch {
7
11
  type: "rewrite";
8
12
  target: string;
@@ -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,GAAG,iBAAiB,GAAG,aAAa,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AAEpG,UAAU,iBAAiB;IAC1B,IAAI,EAAE,KAAK,GAAG,aAAa,CAAC;CAC5B;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,UAAU,aAAa;IACtB,IA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AAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAClC;AAED,UAAU,aAAa;IACtB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IAIb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AASD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACzB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,WAAW,EAAE,EACxB,SAAS,CAAC,EAAE,YAAY,EAAE,GACxB,UAAU,GAAG,IAAI,CA0GnB;AAED;;;;;;;GAOG;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"}
@@ -30,6 +30,15 @@ function matchRoute(pathname, basePath, rewrites, redirects) {
30
30
  if (pathname.startsWith(`${base}/chatter/handlers/file/body`)) {
31
31
  return { type: "file-upload" };
32
32
  }
33
+ if (pathname.startsWith(`${base}/cometd/`)) {
34
+ return { type: "cometd", path: pathname.slice(base.length) };
35
+ }
36
+ const jslibraryWorkerRegex = new RegExp(
37
+ `^${base}/jslibrary/[^/]+/streaming-v2/CometdWorkerJs\\.js/?$`
38
+ );
39
+ if (jslibraryWorkerRegex.test(pathname)) {
40
+ return { type: "cometd", path: pathname.slice(base.length).replace(/\/$/, "") };
41
+ }
33
42
  if (redirects) {
34
43
  for (const redirect of redirects) {
35
44
  const normalizedRoute = normalizeRoute(redirect.route);
@@ -0,0 +1,4 @@
1
+ import { ServerResponse } from 'node:http';
2
+ export declare function sendCometDResponse(res: ServerResponse, response: Response): Promise<void>;
3
+ export declare function isTransientLongPollDrop(error: unknown): boolean;
4
+ //# sourceMappingURL=cometD.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cometD.d.ts","sourceRoot":"","sources":["../../../src/proxy/utils/cometD.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAKhD,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC/F;AAYD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAK/D"}
@@ -0,0 +1,69 @@
1
+ async function sendCometDResponse(res, response) {
2
+ const headers = {};
3
+ const skipHeaders = /* @__PURE__ */ new Set([
4
+ "content-encoding",
5
+ "content-length",
6
+ "transfer-encoding",
7
+ "set-cookie"
8
+ ]);
9
+ response.headers.forEach((value, key) => {
10
+ if (!skipHeaders.has(key.toLowerCase())) {
11
+ headers[key] = value;
12
+ }
13
+ });
14
+ if (typeof response.headers.getSetCookie === "function") {
15
+ const setCookies = response.headers.getSetCookie();
16
+ if (setCookies.length > 0) {
17
+ headers["set-cookie"] = setCookies.map(rewriteSetCookieForLocalDev);
18
+ }
19
+ }
20
+ res.writeHead(response.status, headers);
21
+ if (response.body) {
22
+ const reader = response.body.getReader();
23
+ while (true) {
24
+ const { done, value } = await reader.read();
25
+ if (done) break;
26
+ res.write(value);
27
+ }
28
+ }
29
+ res.end();
30
+ }
31
+ const TRANSIENT_FETCH_ERROR_CODES = /* @__PURE__ */ new Set([
32
+ "UND_ERR_SOCKET",
33
+ // "other side closed" — upstream closed the held long-poll socket
34
+ "UND_ERR_HEADERS_TIMEOUT",
35
+ "UND_ERR_BODY_TIMEOUT",
36
+ "ECONNRESET"
37
+ ]);
38
+ function isTransientLongPollDrop(error) {
39
+ if (!(error instanceof Error)) return false;
40
+ const cause = error.cause;
41
+ const code = cause && typeof cause === "object" ? cause.code : void 0;
42
+ return typeof code === "string" && TRANSIENT_FETCH_ERROR_CODES.has(code);
43
+ }
44
+ function rewriteSetCookieForLocalDev(cookie) {
45
+ const rewritten = [];
46
+ cookie.split(";").forEach((segment, index) => {
47
+ if (index === 0) {
48
+ rewritten.push(segment);
49
+ return;
50
+ }
51
+ const lower = segment.trim().toLowerCase();
52
+ if (lower.startsWith("domain=")) {
53
+ return;
54
+ }
55
+ if (lower === "secure") {
56
+ return;
57
+ }
58
+ if (lower === "samesite=none") {
59
+ rewritten.push(segment.replace(/none/i, "Lax"));
60
+ return;
61
+ }
62
+ rewritten.push(segment);
63
+ });
64
+ return rewritten.join(";");
65
+ }
66
+ export {
67
+ isTransientLongPollDrop,
68
+ sendCometDResponse
69
+ };
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.5",
4
+ "version": "12.5.0",
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.4.5",
42
+ "@salesforce/platform-sdk": "^12.5.0",
43
43
  "micromatch": "^4.0.8",
44
44
  "path-to-regexp": "^8.4.2"
45
45
  },