@salesforce/ui-bundle 12.4.3 → 12.4.5
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/package.json.js +1 -1
- package/dist/proxy/handler.d.ts.map +1 -1
- package/dist/proxy/handler.js +54 -90
- package/package.json +2 -2
package/dist/package.json.js
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/proxy/handler.js
CHANGED
|
@@ -206,8 +206,8 @@ class UIBundleProxyHandler {
|
|
|
206
206
|
this.sendJson(res, 405, { error: "METHOD_NOT_ALLOWED", message: "Use GET" });
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
|
-
const { rawInstanceUrl,
|
|
210
|
-
const frontdoorUrl = await this.fetchLightningOutFrontdoorUrl(
|
|
209
|
+
const { rawInstanceUrl, orgId } = this.orgInfo;
|
|
210
|
+
const frontdoorUrl = await this.fetchLightningOutFrontdoorUrl(req);
|
|
211
211
|
if (!frontdoorUrl) {
|
|
212
212
|
this.sendJson(res, 502, {
|
|
213
213
|
error: "FRONTDOOR_FAILED",
|
|
@@ -228,29 +228,15 @@ class UIBundleProxyHandler {
|
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
async fetchLightningOutFrontdoorUrl(
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
async fetchLightningOutFrontdoorUrl(req) {
|
|
232
|
+
const response = await this.fetchWithAuthRetry(req, (orgInfo) => ({
|
|
233
|
+
url: `${orgInfo.rawInstanceUrl.replace(/\/$/, "")}${LIGHTNING_OUT_SINGLE_ACCESS_PATH}`,
|
|
234
234
|
method: "POST",
|
|
235
235
|
headers: {
|
|
236
|
-
Authorization: `Bearer ${accessToken}`,
|
|
236
|
+
Authorization: `Bearer ${orgInfo.accessToken}`,
|
|
237
237
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
238
238
|
}
|
|
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
|
-
}
|
|
239
|
+
}));
|
|
254
240
|
if (!response.ok) {
|
|
255
241
|
const errorBody = await response.text();
|
|
256
242
|
throw new Error(`Frontdoor exchange failed: ${response.status} ${errorBody}`);
|
|
@@ -265,46 +251,21 @@ class UIBundleProxyHandler {
|
|
|
265
251
|
return;
|
|
266
252
|
}
|
|
267
253
|
const url = new URL(req.url ?? "/", `http://${req.headers.host}`);
|
|
268
|
-
let targetUrl = `${getApiHost(this.orgInfo, myDomain)}${apiPath}${url.search}`;
|
|
269
254
|
if (this.options?.debug) {
|
|
270
|
-
console.log(
|
|
255
|
+
console.log(
|
|
256
|
+
`[ui-bundle-proxy] Forwarding to Salesforce: ${getApiHost(this.orgInfo, myDomain)}${apiPath}${url.search}`
|
|
257
|
+
);
|
|
271
258
|
}
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
method: req.method,
|
|
259
|
+
const response = await this.fetchWithAuthRetry(req, (orgInfo) => ({
|
|
260
|
+
url: `${getApiHost(orgInfo, myDomain)}${apiPath}${url.search}`,
|
|
275
261
|
headers: {
|
|
276
262
|
...getFilteredHeaders(req.headers),
|
|
277
|
-
Cookie: `sid=${
|
|
263
|
+
Cookie: `sid=${orgInfo.accessToken}`,
|
|
278
264
|
Accept: req.headers.accept ?? "application/json",
|
|
279
265
|
// necessary for Apex requests, for which SessionUtil.validateSessionUsage won't accept OAuth token as `sid` cookie
|
|
280
|
-
Authorization: `Bearer ${
|
|
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");
|
|
266
|
+
Authorization: `Bearer ${orgInfo.accessToken}`
|
|
294
267
|
}
|
|
295
|
-
|
|
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
|
-
}
|
|
268
|
+
}));
|
|
308
269
|
await this.sendResponse(res, response);
|
|
309
270
|
} catch (error) {
|
|
310
271
|
console.error("[ui-bundle-proxy] Salesforce API request failed:", error);
|
|
@@ -329,52 +290,55 @@ class UIBundleProxyHandler {
|
|
|
329
290
|
}
|
|
330
291
|
return updatedOrgInfo;
|
|
331
292
|
}
|
|
293
|
+
async fetchWithAuthRetry(req, createRequest) {
|
|
294
|
+
if (!this.orgInfo) {
|
|
295
|
+
throw new AuthenticationError("No Salesforce org is configured");
|
|
296
|
+
}
|
|
297
|
+
const body = req.method !== "GET" && req.method !== "HEAD" ? await getBody(req) : void 0;
|
|
298
|
+
const execute = (orgInfo) => {
|
|
299
|
+
const { url, headers, method } = createRequest(orgInfo);
|
|
300
|
+
return fetch(url, {
|
|
301
|
+
method: method ?? req.method,
|
|
302
|
+
headers,
|
|
303
|
+
body
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
const response = await execute(this.orgInfo);
|
|
307
|
+
if (response.status !== 401 && response.status !== 403) {
|
|
308
|
+
return response;
|
|
309
|
+
}
|
|
310
|
+
console.warn(`[ui-bundle-proxy] Received ${response.status}, refreshing token...`);
|
|
311
|
+
const updatedOrgInfo = await this.refreshToken();
|
|
312
|
+
if (!updatedOrgInfo) {
|
|
313
|
+
console.error("[ui-bundle-proxy] Failed to refresh token - authentication error");
|
|
314
|
+
throw new AuthenticationError("Failed to refresh token");
|
|
315
|
+
}
|
|
316
|
+
if (this.options?.debug) {
|
|
317
|
+
console.log("[ui-bundle-proxy] Token refreshed, retrying request");
|
|
318
|
+
}
|
|
319
|
+
return execute(updatedOrgInfo);
|
|
320
|
+
}
|
|
332
321
|
async handleGraphQL(req, res) {
|
|
333
322
|
try {
|
|
334
323
|
if (!this.orgInfo) {
|
|
335
324
|
this.sendNoOrgError(res);
|
|
336
325
|
return;
|
|
337
326
|
}
|
|
338
|
-
const { rawInstanceUrl, apiVersion, accessToken } = this.orgInfo;
|
|
339
|
-
let targetUrl = `${rawInstanceUrl}/services/data/v${apiVersion}/graphql`;
|
|
340
327
|
if (this.options?.debug) {
|
|
341
|
-
console.log(
|
|
328
|
+
console.log(
|
|
329
|
+
`[ui-bundle-proxy] Forwarding GraphQL to Salesforce: ${this.orgInfo.rawInstanceUrl}/services/data/v${this.orgInfo.apiVersion}/graphql`
|
|
330
|
+
);
|
|
342
331
|
}
|
|
343
|
-
const
|
|
344
|
-
|
|
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, {
|
|
332
|
+
const response = await this.fetchWithAuthRetry(req, (orgInfo) => ({
|
|
333
|
+
url: `${orgInfo.rawInstanceUrl}/services/data/v${orgInfo.apiVersion}/graphql`,
|
|
351
334
|
method: "POST",
|
|
352
|
-
headers
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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;
|
|
335
|
+
headers: {
|
|
336
|
+
"Content-Type": "application/json",
|
|
337
|
+
Accept: "application/json",
|
|
338
|
+
Authorization: `Bearer ${orgInfo.accessToken}`,
|
|
339
|
+
"X-Chatter-Entity-Encoding": "false"
|
|
376
340
|
}
|
|
377
|
-
}
|
|
341
|
+
}));
|
|
378
342
|
await this.sendResponse(res, response);
|
|
379
343
|
} catch (error) {
|
|
380
344
|
console.error("[ui-bundle-proxy] GraphQL request failed:", error);
|
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
|
+
"version": "12.4.5",
|
|
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.
|
|
42
|
+
"@salesforce/platform-sdk": "^12.4.5",
|
|
43
43
|
"micromatch": "^4.0.8",
|
|
44
44
|
"path-to-regexp": "^8.4.2"
|
|
45
45
|
},
|