@salesforce/ui-bundle 12.4.4 → 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.4";
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;AAqvBnB;;;;;;;;;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();
@@ -206,8 +214,8 @@ class UIBundleProxyHandler {
206
214
  this.sendJson(res, 405, { error: "METHOD_NOT_ALLOWED", message: "Use GET" });
207
215
  return;
208
216
  }
209
- const { rawInstanceUrl, accessToken, orgId } = this.orgInfo;
210
- const frontdoorUrl = await this.fetchLightningOutFrontdoorUrl(rawInstanceUrl, accessToken);
217
+ const { rawInstanceUrl, orgId } = this.orgInfo;
218
+ const frontdoorUrl = await this.fetchLightningOutFrontdoorUrl(req);
211
219
  if (!frontdoorUrl) {
212
220
  this.sendJson(res, 502, {
213
221
  error: "FRONTDOOR_FAILED",
@@ -228,29 +236,15 @@ class UIBundleProxyHandler {
228
236
  });
229
237
  }
230
238
  }
231
- async fetchLightningOutFrontdoorUrl(rawInstanceUrl, accessToken) {
232
- let baseUrl = rawInstanceUrl.replace(/\/$/, "");
233
- let response = await fetch(`${baseUrl}${LIGHTNING_OUT_SINGLE_ACCESS_PATH}`, {
239
+ async fetchLightningOutFrontdoorUrl(req) {
240
+ const response = await this.fetchWithAuthRetry(req, (orgInfo) => ({
241
+ url: `${orgInfo.rawInstanceUrl.replace(/\/$/, "")}${LIGHTNING_OUT_SINGLE_ACCESS_PATH}`,
234
242
  method: "POST",
235
243
  headers: {
236
- Authorization: `Bearer ${accessToken}`,
244
+ Authorization: `Bearer ${orgInfo.accessToken}`,
237
245
  "Content-Type": "application/x-www-form-urlencoded"
238
246
  }
239
- });
240
- if (response.status === 401 || response.status === 403) {
241
- const updatedOrgInfo = await this.refreshToken();
242
- if (!updatedOrgInfo) {
243
- throw new AuthenticationError("Failed to refresh token");
244
- }
245
- baseUrl = updatedOrgInfo.rawInstanceUrl.replace(/\/$/, "");
246
- response = await fetch(`${baseUrl}${LIGHTNING_OUT_SINGLE_ACCESS_PATH}`, {
247
- method: "POST",
248
- headers: {
249
- Authorization: `Bearer ${updatedOrgInfo.accessToken}`,
250
- "Content-Type": "application/x-www-form-urlencoded"
251
- }
252
- });
253
- }
247
+ }));
254
248
  if (!response.ok) {
255
249
  const errorBody = await response.text();
256
250
  throw new Error(`Frontdoor exchange failed: ${response.status} ${errorBody}`);
@@ -265,46 +259,21 @@ class UIBundleProxyHandler {
265
259
  return;
266
260
  }
267
261
  const url = new URL(req.url ?? "/", `http://${req.headers.host}`);
268
- let targetUrl = `${getApiHost(this.orgInfo, myDomain)}${apiPath}${url.search}`;
269
262
  if (this.options?.debug) {
270
- console.log(`[ui-bundle-proxy] Forwarding to Salesforce: ${targetUrl}`);
263
+ console.log(
264
+ `[ui-bundle-proxy] Forwarding to Salesforce: ${getApiHost(this.orgInfo, myDomain)}${apiPath}${url.search}`
265
+ );
271
266
  }
272
- const body = req.method !== "GET" && req.method !== "HEAD" ? await getBody(req) : void 0;
273
- let response = await fetch(targetUrl, {
274
- method: req.method,
267
+ const response = await this.fetchWithAuthRetry(req, (orgInfo) => ({
268
+ url: `${getApiHost(orgInfo, myDomain)}${apiPath}${url.search}`,
275
269
  headers: {
276
270
  ...getFilteredHeaders(req.headers),
277
- Cookie: `sid=${this.orgInfo.accessToken}`,
271
+ Cookie: `sid=${orgInfo.accessToken}`,
278
272
  Accept: req.headers.accept ?? "application/json",
279
273
  // necessary for Apex requests, for which SessionUtil.validateSessionUsage won't accept OAuth token as `sid` cookie
280
- Authorization: `Bearer ${this.orgInfo.accessToken}`
281
- },
282
- body
283
- });
284
- if (response.status === 401 || response.status === 403) {
285
- console.warn(`[ui-bundle-proxy] Received ${response.status}, refreshing token...`);
286
- const updatedOrgInfo = await this.refreshToken();
287
- if (updatedOrgInfo === void 0) {
288
- console.error("[ui-bundle-proxy] Failed to refresh token - authentication error");
289
- this.sendJson(res, 401, AUTH_FAILED_RESPONSE);
290
- return;
291
- }
292
- if (this.options?.debug) {
293
- console.log("[ui-bundle-proxy] Token refreshed, retrying request");
274
+ Authorization: `Bearer ${orgInfo.accessToken}`
294
275
  }
295
- targetUrl = `${getApiHost(updatedOrgInfo, myDomain)}${apiPath}${url.search}`;
296
- response = await fetch(targetUrl, {
297
- method: req.method,
298
- headers: {
299
- ...getFilteredHeaders(req.headers),
300
- Cookie: `sid=${updatedOrgInfo.accessToken}`,
301
- Accept: req.headers.accept ?? "application/json",
302
- // necessary for Apex requests, for which SessionUtil.validateSessionUsage won't accept OAuth token as `sid` cookie
303
- Authorization: `Bearer ${updatedOrgInfo.accessToken}`
304
- },
305
- body
306
- });
307
- }
276
+ }));
308
277
  await this.sendResponse(res, response);
309
278
  } catch (error) {
310
279
  console.error("[ui-bundle-proxy] Salesforce API request failed:", error);
@@ -329,52 +298,55 @@ class UIBundleProxyHandler {
329
298
  }
330
299
  return updatedOrgInfo;
331
300
  }
301
+ async fetchWithAuthRetry(req, createRequest) {
302
+ if (!this.orgInfo) {
303
+ throw new AuthenticationError("No Salesforce org is configured");
304
+ }
305
+ const body = req.method !== "GET" && req.method !== "HEAD" ? await getBody(req) : void 0;
306
+ const execute = (orgInfo) => {
307
+ const { url, headers, method } = createRequest(orgInfo);
308
+ return fetch(url, {
309
+ method: method ?? req.method,
310
+ headers,
311
+ body
312
+ });
313
+ };
314
+ const response = await execute(this.orgInfo);
315
+ if (response.status !== 401 && response.status !== 403) {
316
+ return response;
317
+ }
318
+ console.warn(`[ui-bundle-proxy] Received ${response.status}, refreshing token...`);
319
+ const updatedOrgInfo = await this.refreshToken();
320
+ if (!updatedOrgInfo) {
321
+ console.error("[ui-bundle-proxy] Failed to refresh token - authentication error");
322
+ throw new AuthenticationError("Failed to refresh token");
323
+ }
324
+ if (this.options?.debug) {
325
+ console.log("[ui-bundle-proxy] Token refreshed, retrying request");
326
+ }
327
+ return execute(updatedOrgInfo);
328
+ }
332
329
  async handleGraphQL(req, res) {
333
330
  try {
334
331
  if (!this.orgInfo) {
335
332
  this.sendNoOrgError(res);
336
333
  return;
337
334
  }
338
- const { rawInstanceUrl, apiVersion, accessToken } = this.orgInfo;
339
- let targetUrl = `${rawInstanceUrl}/services/data/v${apiVersion}/graphql`;
340
335
  if (this.options?.debug) {
341
- console.log(`[ui-bundle-proxy] Forwarding GraphQL to Salesforce: ${targetUrl}`);
336
+ console.log(
337
+ `[ui-bundle-proxy] Forwarding GraphQL to Salesforce: ${this.orgInfo.rawInstanceUrl}/services/data/v${this.orgInfo.apiVersion}/graphql`
338
+ );
342
339
  }
343
- const body = await getBody(req);
344
- const headers = {
345
- "Content-Type": "application/json",
346
- Accept: "application/json",
347
- Authorization: `Bearer ${accessToken}`,
348
- "X-Chatter-Entity-Encoding": "false"
349
- };
350
- let response = await fetch(targetUrl, {
340
+ const response = await this.fetchWithAuthRetry(req, (orgInfo) => ({
341
+ url: `${orgInfo.rawInstanceUrl}/services/data/v${orgInfo.apiVersion}/graphql`,
351
342
  method: "POST",
352
- headers,
353
- body
354
- });
355
- if (response.status === 401 || response.status === 403) {
356
- console.warn(`[ui-bundle-proxy] Received ${response.status}, refreshing token...`);
357
- const updatedOrgInfo = await this.refreshToken();
358
- if (updatedOrgInfo !== void 0) {
359
- if (this.options?.debug) {
360
- console.log("[ui-bundle-proxy] Token refreshed, retrying request");
361
- }
362
- const { rawInstanceUrl: rawInstanceUrl2, apiVersion: apiVersion2, accessToken: accessToken2 } = updatedOrgInfo;
363
- targetUrl = `${rawInstanceUrl2}/services/data/v${apiVersion2}/graphql`;
364
- headers.Authorization = `Bearer ${accessToken2}`;
365
- response = await fetch(targetUrl, {
366
- method: "POST",
367
- headers,
368
- body
369
- });
370
- } else {
371
- console.error(
372
- "[ui-bundle-proxy] Failed to refresh token for GraphQL - authentication error"
373
- );
374
- this.sendJson(res, 401, AUTH_FAILED_RESPONSE);
375
- return;
343
+ headers: {
344
+ "Content-Type": "application/json",
345
+ Accept: "application/json",
346
+ Authorization: `Bearer ${orgInfo.accessToken}`,
347
+ "X-Chatter-Entity-Encoding": "false"
376
348
  }
377
- }
349
+ }));
378
350
  await this.sendResponse(res, response);
379
351
  } catch (error) {
380
352
  console.error("[ui-bundle-proxy] GraphQL request failed:", error);
@@ -519,6 +491,43 @@ class UIBundleProxyHandler {
519
491
  );
520
492
  }
521
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
+ }
522
531
  }
523
532
  function createProxyHandler(manifest, orgInfo, target, basePath, options) {
524
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,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,CA2FnB;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"}
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,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,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.4",
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.4",
42
+ "@salesforce/platform-sdk": "^12.5.0",
43
43
  "micromatch": "^4.0.8",
44
44
  "path-to-regexp": "^8.4.2"
45
45
  },