@salesforce/lds-runtime-aura 1.400.0 → 1.402.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.
@@ -26,21 +26,22 @@ import { GetApexWireAdapterFactory, registerPrefetcher as registerPrefetcher$1 }
26
26
  import { instrument, getRecordAvatarsAdapterFactory, getRecordAdapterFactory, coerceFieldIdArray, getRecordsAdapterFactory, getRecordActionsAdapterFactory, getObjectInfosAdapterFactory, coerceObjectIdArray, getObjectInfoAdapterFactory, coerceObjectId, getRelatedListsActionsAdapterFactory, getRelatedListInfoBatchAdapterFactory, getRelatedListInfoAdapterFactory, getRelatedListRecordsBatchAdapterFactory, getRelatedListRecordsAdapterFactory, getListInfoByNameAdapterFactory, getListInfosByObjectNameAdapterFactory, getListRecordsByNameAdapterFactory, getListObjectInfoAdapterFactory, getRelatedListsInfoAdapterFactory, getRelatedListActionsAdapterFactory, getRecordId18Array, buildRecordRepKeyFromId, configuration, InMemoryRecordRepresentationQueryEvaluator, UiApiNamespace, RecordRepresentationRepresentationType, registerPrefetcher, RecordRepresentationVersion } from 'force/ldsAdaptersUiapi';
27
27
  import { getInstrumentation } from 'o11y/client';
28
28
  import { findExecutableOperation, buildGraphQLInputExtension, addTypenameToDocument } from 'force/luvioGraphqlNormalization';
29
- import { print } from 'force/luvioOnestoreGraphqlParser';
29
+ import { print, wrapConfigAndVerify, resolveAst, validateGraphQLOperations } from 'force/luvioOnestoreGraphqlParser';
30
30
  import { setServices } from 'force/luvioServiceProvisioner1';
31
+ import { assertIsValid, MissingRequiredPropertyError, JsonSchemaViolationError } from 'force/luvioJsonschemaValidate5';
31
32
  import { dispatchGlobalEvent, unstable_loadComponentDefs, executeGlobalControllerRawResponse } from 'aura';
32
33
  import auraNetworkAdapter, { dispatchAuraAction, defaultActionConfig, instrument as instrument$1, forceRecordTransactionsDisabled as forceRecordTransactionsDisabled$1, ldsNetworkAdapterInstrument, CrudEventState, CrudEventType, UIAPI_RECORDS_PATH, UIAPI_RELATED_LIST_RECORDS_BATCH_PATH, UIAPI_RELATED_LIST_RECORDS_PATH } from 'force/ldsNetwork';
33
- import { pageScopedCache } from 'instrumentation/utility';
34
- import { instrument as instrument$2, generateRequestId, setupLexNetworkAdapter, internalRequestTracker } from 'force/ldsNetworkFetch';
35
34
  import { ThirdPartyTracker } from 'instrumentation:thirdPartyTracker';
35
+ import { markStart, markEnd, counter, registerCacheStats, perfStart, perfEnd, registerPeriodicLogger, interaction, timer } from 'instrumentation/service';
36
+ import { pageScopedCache } from 'instrumentation/utility';
37
+ import { instrument as instrument$2, generateRequestId as generateRequestId$1, setupLexNetworkAdapter, internalRequestTracker } from 'force/ldsNetworkFetch';
36
38
  import { REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR, instrument as instrument$3 } from 'force/ldsBindings';
37
- import { counter, registerCacheStats, perfStart, perfEnd, registerPeriodicLogger, interaction, timer } from 'instrumentation/service';
38
- import { LRUCache, instrumentAdapter, instrumentLuvio, setupInstrumentation as setupInstrumentation$1, logObjectInfoChanged as logObjectInfoChanged$1, updatePercentileHistogramMetric, incrementCounterMetric, incrementGetRecordNotifyChangeAllowCount, incrementGetRecordNotifyChangeDropCount, incrementNotifyRecordUpdateAvailableAllowCount, incrementNotifyRecordUpdateAvailableDropCount, setLdsAdaptersUiapiInstrumentation, logError, setLdsNetworkAdapterInstrumentation, incrementStateCreatedCount, executeAsyncActivity, METRIC_KEYS, onIdleDetected } from 'force/ldsInstrumentation';
39
+ import { LRUCache, instrumentAdapter, instrumentLuvio, setupInstrumentation as setupInstrumentation$1, logObjectInfoChanged as logObjectInfoChanged$1, updatePercentileHistogramMetric, incrementCounterMetric, incrementGetRecordNotifyChangeAllowCount, incrementGetRecordNotifyChangeDropCount, incrementNotifyRecordUpdateAvailableAllowCount, incrementNotifyRecordUpdateAvailableDropCount, setLdsAdaptersUiapiInstrumentation, logError as logError$2, setLdsNetworkAdapterInstrumentation, incrementStateCreatedCount, executeAsyncActivity, METRIC_KEYS, onIdleDetected } from 'force/ldsInstrumentation';
39
40
  import { instrument as instrument$4 } from 'force/adsBridge';
40
41
  import { instrument as instrument$5 } from '@lwc/state';
41
42
  import { withRegistration, register, setDefaultLuvio } from 'force/ldsEngine';
42
- import useHotspotLimit from '@salesforce/gate/lds.pdl.useHotspotLimit';
43
43
  import { createStorage, clearStorages } from 'force/ldsStorage';
44
+ import useHotspotLimit from '@salesforce/gate/lds.pdl.useHotspotLimit';
44
45
  import useHttpUiapiOneApp from '@salesforce/gate/lds.useHttpUiapiOneApp';
45
46
  import useHttpUiapiOneRuntime from '@salesforce/gate/lds.useHttpUiapiOneRuntime';
46
47
 
@@ -51,15 +52,16 @@ import useHttpUiapiOneRuntime from '@salesforce/gate/lds.useHttpUiapiOneRuntime'
51
52
  */
52
53
  const { create: create$1, freeze, keys: keys$2, entries: entries$1 } = Object;
53
54
  const { isArray: isArray$3 } = Array;
54
- const { stringify: stringify$2, parse: parse$1 } = JSON;
55
- const LogLevelMap$1 = {
55
+ const { stringify: stringify$3, parse: parse$2 } = JSON;
56
+ const WeakSetConstructor = WeakSet;
57
+ const LogLevelMap = {
56
58
  TRACE: 4,
57
59
  DEBUG: 3,
58
60
  INFO: 2,
59
61
  WARN: 1,
60
62
  ERROR: 0
61
63
  };
62
- let ConsoleLogger$1 = class ConsoleLogger {
64
+ class ConsoleLogger {
63
65
  constructor(level = "WARN", printer = console.log, formatter = (level2, message) => `${level2}: ${message}`) {
64
66
  this.level = level;
65
67
  this.printer = printer;
@@ -82,12 +84,15 @@ let ConsoleLogger$1 = class ConsoleLogger {
82
84
  this.log("ERROR", message);
83
85
  }
84
86
  log(level, message) {
85
- if (LogLevelMap$1[level] > LogLevelMap$1[this.level]) {
87
+ if (LogLevelMap[level] > LogLevelMap[this.level]) {
86
88
  return;
87
89
  }
88
90
  this.printer(this.formatter(level, message));
89
91
  }
90
- };
92
+ }
93
+ function loggerService(level, printer, formatter) {
94
+ return new ConsoleLogger(level, printer, formatter);
95
+ }
91
96
  let Ok$2 = class Ok {
92
97
  constructor(value) {
93
98
  this.value = value;
@@ -131,41 +136,41 @@ function buildSubscribableResult$1(result, subscribe, refresh) {
131
136
  return err$1({ failure: result.error, subscribe, refresh });
132
137
  }
133
138
  }
134
- function resolvedPromiseLike$3(result) {
135
- if (isPromiseLike$3(result)) {
139
+ function resolvedPromiseLike$2(result) {
140
+ if (isPromiseLike$2(result)) {
136
141
  return result.then((nextResult) => nextResult);
137
142
  }
138
143
  return {
139
144
  then: (onFulfilled, _onRejected) => {
140
145
  try {
141
- return resolvedPromiseLike$3(onFulfilled(result));
146
+ return resolvedPromiseLike$2(onFulfilled(result));
142
147
  } catch (e) {
143
148
  if (onFulfilled === void 0) {
144
- return resolvedPromiseLike$3(result);
149
+ return resolvedPromiseLike$2(result);
145
150
  }
146
- return rejectedPromiseLike$3(e);
151
+ return rejectedPromiseLike$2(e);
147
152
  }
148
153
  }
149
154
  };
150
155
  }
151
- function rejectedPromiseLike$3(reason) {
152
- if (isPromiseLike$3(reason)) {
156
+ function rejectedPromiseLike$2(reason) {
157
+ if (isPromiseLike$2(reason)) {
153
158
  return reason.then((nextResult) => nextResult);
154
159
  }
155
160
  return {
156
161
  then: (_onFulfilled, onRejected) => {
157
162
  if (typeof onRejected === "function") {
158
163
  try {
159
- return resolvedPromiseLike$3(onRejected(reason));
164
+ return resolvedPromiseLike$2(onRejected(reason));
160
165
  } catch (e) {
161
- return rejectedPromiseLike$3(e);
166
+ return rejectedPromiseLike$2(e);
162
167
  }
163
168
  }
164
- return rejectedPromiseLike$3(reason);
169
+ return rejectedPromiseLike$2(reason);
165
170
  }
166
171
  };
167
172
  }
168
- function isPromiseLike$3(x) {
173
+ function isPromiseLike$2(x) {
169
174
  return typeof (x == null ? void 0 : x.then) === "function";
170
175
  }
171
176
  function stableJSONStringify$2(node) {
@@ -179,7 +184,7 @@ function stableJSONStringify$2(node) {
179
184
  return isFinite(node) ? "" + node : "null";
180
185
  }
181
186
  if (typeof node !== "object") {
182
- return stringify$2(node);
187
+ return stringify$3(node);
183
188
  }
184
189
  let i;
185
190
  let out;
@@ -207,7 +212,7 @@ function stableJSONStringify$2(node) {
207
212
  if (out) {
208
213
  out += ",";
209
214
  }
210
- out += stringify$2(key) + ":" + value;
215
+ out += stringify$3(key) + ":" + value;
211
216
  }
212
217
  return "{" + out + "}";
213
218
  }
@@ -271,6 +276,24 @@ class FetchResponse extends Error {
271
276
  this.statusText = getStatusText(status);
272
277
  }
273
278
  }
279
+ const deeplyFrozen = new WeakSetConstructor();
280
+ function deepFreeze(value) {
281
+ if (typeof value !== "object" || value === null || deeplyFrozen.has(value)) {
282
+ return;
283
+ }
284
+ deeplyFrozen.add(value);
285
+ if (isArray$3(value)) {
286
+ for (let i = 0, len = value.length; i < len; i += 1) {
287
+ deepFreeze(value[i]);
288
+ }
289
+ } else {
290
+ const keys$1 = keys$2(value);
291
+ for (let i = 0, len = keys$1.length; i < len; i += 1) {
292
+ deepFreeze(value[keys$1[i]]);
293
+ }
294
+ }
295
+ freeze(value);
296
+ }
274
297
  class InternalError extends Error {
275
298
  constructor(data) {
276
299
  super();
@@ -285,6 +308,15 @@ class UserVisibleError extends Error {
285
308
  this.type = "user-visible";
286
309
  }
287
310
  }
311
+ function isUserVisibleError$1(error) {
312
+ return error instanceof Error && "type" in error && error.type === "user-visible";
313
+ }
314
+ function logError$1(error) {
315
+ if (isUserVisibleError$1(error)) {
316
+ return;
317
+ }
318
+ console.error("OneStore Command threw an error that we did not expect", error);
319
+ }
288
320
 
289
321
  /*!
290
322
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -341,7 +373,7 @@ let NetworkCommand$1 = class NetworkCommand extends BaseCommand {
341
373
  async afterRequestHooks(_options) {
342
374
  }
343
375
  };
344
- function buildServiceDescriptor$j() {
376
+ function buildServiceDescriptor$r() {
345
377
  return {
346
378
  type: "networkCommandBaseClass",
347
379
  version: "1.0",
@@ -440,10 +472,10 @@ class AuraNetworkCommand extends NetworkCommand$1 {
440
472
  } else if (this.shouldUseFetch()) {
441
473
  return this.convertFetchResponseToData(this.services.fetch(...this.fetchParams));
442
474
  }
443
- return resolvedPromiseLike$3(err$1(toError("Aura/Fetch network services not found")));
475
+ return resolvedPromiseLike$2(err$1(toError("Aura/Fetch network services not found")));
444
476
  }
445
477
  }
446
- function buildServiceDescriptor$i() {
478
+ function buildServiceDescriptor$q() {
447
479
  return {
448
480
  type: "auraNetworkCommandBaseClass",
449
481
  version: "1.0",
@@ -493,41 +525,41 @@ function buildSubscribableResult(result, subscribe, refresh) {
493
525
  return err({ failure: result.error, subscribe, refresh });
494
526
  }
495
527
  }
496
- function resolvedPromiseLike$2(result) {
497
- if (isPromiseLike$2(result)) {
528
+ function resolvedPromiseLike$1(result) {
529
+ if (isPromiseLike$1(result)) {
498
530
  return result.then((nextResult) => nextResult);
499
531
  }
500
532
  return {
501
533
  then: (onFulfilled, _onRejected) => {
502
534
  try {
503
- return resolvedPromiseLike$2(onFulfilled(result));
535
+ return resolvedPromiseLike$1(onFulfilled(result));
504
536
  } catch (e) {
505
537
  if (onFulfilled === void 0) {
506
- return resolvedPromiseLike$2(result);
538
+ return resolvedPromiseLike$1(result);
507
539
  }
508
- return rejectedPromiseLike$2(e);
540
+ return rejectedPromiseLike$1(e);
509
541
  }
510
542
  }
511
543
  };
512
544
  }
513
- function rejectedPromiseLike$2(reason) {
514
- if (isPromiseLike$2(reason)) {
545
+ function rejectedPromiseLike$1(reason) {
546
+ if (isPromiseLike$1(reason)) {
515
547
  return reason.then((nextResult) => nextResult);
516
548
  }
517
549
  return {
518
550
  then: (_onFulfilled, onRejected) => {
519
551
  if (typeof onRejected === "function") {
520
552
  try {
521
- return resolvedPromiseLike$2(onRejected(reason));
553
+ return resolvedPromiseLike$1(onRejected(reason));
522
554
  } catch (e) {
523
- return rejectedPromiseLike$2(e);
555
+ return rejectedPromiseLike$1(e);
524
556
  }
525
557
  }
526
- return rejectedPromiseLike$2(reason);
558
+ return rejectedPromiseLike$1(reason);
527
559
  }
528
560
  };
529
561
  }
530
- function isPromiseLike$2(x) {
562
+ function isPromiseLike$1(x) {
531
563
  return typeof (x == null ? void 0 : x.then) === "function";
532
564
  }
533
565
  function deepEquals$1(x, y) {
@@ -762,7 +794,7 @@ class CacheControlCommand extends BaseCommand {
762
794
  });
763
795
  }
764
796
  }
765
- return resolvedPromiseLike$2(void 0);
797
+ return resolvedPromiseLike$1(void 0);
766
798
  }
767
799
  get operationType() {
768
800
  return "query";
@@ -1038,7 +1070,7 @@ let AuraCacheControlCommand$1 = class AuraCacheControlCommand extends CacheContr
1038
1070
  } else if (this.shouldUseFetch()) {
1039
1071
  return this.convertFetchResponseToData(this.services.fetch(...this.fetchParams));
1040
1072
  }
1041
- return resolvedPromiseLike$3(err$1(toError("Aura/Fetch network services not found")));
1073
+ return resolvedPromiseLike$2(err$1(toError("Aura/Fetch network services not found")));
1042
1074
  }
1043
1075
  coerceAuraErrors(auraErrors) {
1044
1076
  return toError(auraErrors[0]);
@@ -1112,9 +1144,9 @@ class AuraResourceCacheControlCommand extends AuraCacheControlCommand$1 {
1112
1144
  var _a;
1113
1145
  const data = (_a = cache.get(this.buildKey())) == null ? void 0 : _a.value;
1114
1146
  if (data === void 0) {
1115
- return resolvedPromiseLike$3(err$1(new Error("Failed to find data in cache")));
1147
+ return resolvedPromiseLike$2(err$1(new Error("Failed to find data in cache")));
1116
1148
  }
1117
- return resolvedPromiseLike$3(ok$2(data));
1149
+ return resolvedPromiseLike$2(ok$2(data));
1118
1150
  }
1119
1151
  writeToCache(cache, networkResult) {
1120
1152
  if (networkResult.isOk()) {
@@ -1125,13 +1157,13 @@ class AuraResourceCacheControlCommand extends AuraCacheControlCommand$1 {
1125
1157
  }
1126
1158
  });
1127
1159
  }
1128
- return resolvedPromiseLike$3(void 0);
1160
+ return resolvedPromiseLike$2(void 0);
1129
1161
  }
1130
1162
  buildKey() {
1131
1163
  return `{"endpoint":${this.endpoint},"params":${stableJSONStringify$2(this.auraParams)}}`;
1132
1164
  }
1133
1165
  }
1134
- function buildServiceDescriptor$h() {
1166
+ function buildServiceDescriptor$p() {
1135
1167
  return {
1136
1168
  type: "auraResourceCacheControlCommand",
1137
1169
  version: "1.0",
@@ -1181,7 +1213,7 @@ class AuraCacheControlCommand extends CacheControlCommand {
1181
1213
  } else if (this.shouldUseFetch()) {
1182
1214
  return this.convertFetchResponseToData(this.services.fetch(...this.fetchParams));
1183
1215
  }
1184
- return resolvedPromiseLike$3(err$1(toError("Aura/Fetch network services not found")));
1216
+ return resolvedPromiseLike$2(err$1(toError("Aura/Fetch network services not found")));
1185
1217
  }
1186
1218
  coerceAuraErrors(auraErrors) {
1187
1219
  return toError(auraErrors[0]);
@@ -1254,11 +1286,11 @@ class AuraNormalizedCacheControlCommand extends AuraCacheControlCommand {
1254
1286
  readFromCache(cache) {
1255
1287
  const data = this.buildResultType().query(cache, this.buildQuery());
1256
1288
  if (data.isErr()) {
1257
- return resolvedPromiseLike$3(
1258
- err$1(new Error(`Failed to build data from type: ${stringify$2(data.error)}`))
1289
+ return resolvedPromiseLike$2(
1290
+ err$1(new Error(`Failed to build data from type: ${stringify$3(data.error)}`))
1259
1291
  );
1260
1292
  }
1261
- return resolvedPromiseLike$3(ok$2(data.value));
1293
+ return resolvedPromiseLike$2(ok$2(data.value));
1262
1294
  }
1263
1295
  writeToCache(cache, networkResult) {
1264
1296
  if (networkResult.isOk()) {
@@ -1267,10 +1299,10 @@ class AuraNormalizedCacheControlCommand extends AuraCacheControlCommand {
1267
1299
  this.buildWriteInput(networkResult.value)
1268
1300
  );
1269
1301
  }
1270
- return resolvedPromiseLike$3(void 0);
1302
+ return resolvedPromiseLike$2(void 0);
1271
1303
  }
1272
1304
  }
1273
- function buildServiceDescriptor$g() {
1305
+ function buildServiceDescriptor$o() {
1274
1306
  return {
1275
1307
  type: "auraNormalizedCacheControlCommand",
1276
1308
  version: "1.0",
@@ -1343,11 +1375,11 @@ class HttpNormalizedCacheControlCommand extends HttpCacheControlCommand {
1343
1375
  readFromCache(cache) {
1344
1376
  const data = this.buildResultType().query(cache, this.buildQuery());
1345
1377
  if (data.isErr()) {
1346
- return resolvedPromiseLike$3(
1347
- err$1(new Error(`Failed to build data from type: ${stringify$2(data.error)}`))
1378
+ return resolvedPromiseLike$2(
1379
+ err$1(new Error(`Failed to build data from type: ${stringify$3(data.error)}`))
1348
1380
  );
1349
1381
  }
1350
- return resolvedPromiseLike$3(ok$2(data.value));
1382
+ return resolvedPromiseLike$2(ok$2(data.value));
1351
1383
  }
1352
1384
  writeToCache(cache, networkResult) {
1353
1385
  if (networkResult.isOk()) {
@@ -1356,10 +1388,10 @@ class HttpNormalizedCacheControlCommand extends HttpCacheControlCommand {
1356
1388
  this.buildWriteInput(networkResult.value)
1357
1389
  );
1358
1390
  }
1359
- return resolvedPromiseLike$3(void 0);
1391
+ return resolvedPromiseLike$2(void 0);
1360
1392
  }
1361
1393
  }
1362
- function buildServiceDescriptor$f() {
1394
+ function buildServiceDescriptor$n() {
1363
1395
  return {
1364
1396
  type: "httpNormalizedCacheControlCommand",
1365
1397
  version: "1.0",
@@ -1537,7 +1569,7 @@ _FetchNetworkCommand.availableDecorators = {
1537
1569
  abortable: createAbortableDecorator
1538
1570
  };
1539
1571
  let FetchNetworkCommand = _FetchNetworkCommand;
1540
- function buildServiceDescriptor$e() {
1572
+ function buildServiceDescriptor$m() {
1541
1573
  return {
1542
1574
  type: "fetchNetworkCommandBaseClass",
1543
1575
  version: "1.0",
@@ -1573,7 +1605,7 @@ class StreamingCommand extends BaseCommand {
1573
1605
  );
1574
1606
  }
1575
1607
  }
1576
- function buildServiceDescriptor$d() {
1608
+ function buildServiceDescriptor$l() {
1577
1609
  return {
1578
1610
  type: "streamingCommandBaseClass",
1579
1611
  version: "1.0",
@@ -1656,7 +1688,7 @@ class SSEParsingStream extends TransformStream {
1656
1688
  });
1657
1689
  }
1658
1690
  }
1659
- function buildServiceDescriptor$c() {
1691
+ function buildServiceDescriptor$k() {
1660
1692
  return {
1661
1693
  type: "SSECommandBaseClass",
1662
1694
  version: "1.0",
@@ -1707,7 +1739,7 @@ function buildInstrumentCommand(services) {
1707
1739
  };
1708
1740
  };
1709
1741
  }
1710
- function buildServiceDescriptor$b(instrumentation) {
1742
+ function buildServiceDescriptor$j(instrumentation) {
1711
1743
  return {
1712
1744
  type: "instrumentCommand",
1713
1745
  version: "1.0",
@@ -1977,7 +2009,7 @@ class O11yInstrumentation {
1977
2009
  this.metrics = new O11yOTelMetricsAPI(this.services);
1978
2010
  }
1979
2011
  }
1980
- function buildServiceDescriptor$a(logger) {
2012
+ function buildServiceDescriptor$i(logger) {
1981
2013
  return {
1982
2014
  type: "instrumentation",
1983
2015
  version: "1.0",
@@ -1995,12 +2027,12 @@ function buildServiceDescriptor$a(logger) {
1995
2027
  * All rights reserved.
1996
2028
  * For full license text, see the LICENSE.txt file
1997
2029
  */
1998
- const { stringify: stringify$1, parse } = JSON;
1999
- function deepCopy(x) {
2000
- const stringified = stringify$1(x);
2001
- return stringified ? parse(stringified) : void 0;
2030
+ const { stringify: stringify$2, parse: parse$1 } = JSON;
2031
+ function deepCopy$1(x) {
2032
+ const stringified = stringify$2(x);
2033
+ return stringified ? parse$1(stringified) : void 0;
2002
2034
  }
2003
- class DefaultRecordableCache {
2035
+ let DefaultRecordableCache$1 = class DefaultRecordableCache {
2004
2036
  constructor(baseCache) {
2005
2037
  this.baseCache = baseCache;
2006
2038
  this.keysRead = /* @__PURE__ */ new Set();
@@ -2019,7 +2051,7 @@ class DefaultRecordableCache {
2019
2051
  this.missingKeysRead.add(key);
2020
2052
  }
2021
2053
  if (options == null ? void 0 : options.copy) {
2022
- return deepCopy(value);
2054
+ return deepCopy$1(value);
2023
2055
  }
2024
2056
  return value;
2025
2057
  }
@@ -2045,13 +2077,13 @@ class DefaultRecordableCache {
2045
2077
  return new DefaultRecordableCache(this);
2046
2078
  }
2047
2079
  filter(predicate) {
2048
- return new DefaultFilteredCache(this, predicate);
2080
+ return new DefaultFilteredCache$1(this, predicate);
2049
2081
  }
2050
2082
  buildFixedTimeWritableCache(generatedTime) {
2051
- return new FixedTimeWritableCache(this, generatedTime);
2083
+ return new FixedTimeWritableCache$1(this, generatedTime);
2052
2084
  }
2053
- }
2054
- class DefaultFilteredCache {
2085
+ };
2086
+ let DefaultFilteredCache$1 = class DefaultFilteredCache {
2055
2087
  constructor(baseCache, predicate) {
2056
2088
  this.baseCache = baseCache;
2057
2089
  this.predicate = predicate;
@@ -2063,7 +2095,7 @@ class DefaultFilteredCache {
2063
2095
  const result = this.baseCache.get(key);
2064
2096
  if (result && this.predicate(key, result)) {
2065
2097
  if (options == null ? void 0 : options.copy) {
2066
- return deepCopy(result);
2098
+ return deepCopy$1(result);
2067
2099
  }
2068
2100
  return result;
2069
2101
  }
@@ -2085,7 +2117,7 @@ class DefaultFilteredCache {
2085
2117
  return this.getFilteredEntries();
2086
2118
  }
2087
2119
  record() {
2088
- return new DefaultRecordableCache(this);
2120
+ return new DefaultRecordableCache$1(this);
2089
2121
  }
2090
2122
  filter(predicate) {
2091
2123
  return new DefaultFilteredCache(this, predicate);
@@ -2105,10 +2137,10 @@ class DefaultFilteredCache {
2105
2137
  return filteredKeySet;
2106
2138
  }
2107
2139
  buildFixedTimeWritableCache(generatedTime) {
2108
- return new FixedTimeWritableCache(this, generatedTime);
2140
+ return new FixedTimeWritableCache$1(this, generatedTime);
2109
2141
  }
2110
- }
2111
- class FixedTimeWritableCache {
2142
+ };
2143
+ let FixedTimeWritableCache$1 = class FixedTimeWritableCache {
2112
2144
  constructor(baseCache, generatedTime) {
2113
2145
  this.baseCache = baseCache;
2114
2146
  this.generatedTime = generatedTime;
@@ -2144,22 +2176,22 @@ class FixedTimeWritableCache {
2144
2176
  return this.baseCache.entries();
2145
2177
  }
2146
2178
  record() {
2147
- return new DefaultRecordableCache(this);
2179
+ return new DefaultRecordableCache$1(this);
2148
2180
  }
2149
2181
  filter(predicate) {
2150
- return new DefaultFilteredCache(this, predicate);
2182
+ return new DefaultFilteredCache$1(this, predicate);
2151
2183
  }
2152
2184
  buildFixedTimeWritableCache(generatedTime) {
2153
2185
  return new FixedTimeWritableCache(this, generatedTime);
2154
2186
  }
2155
- }
2156
- class DefaultCache {
2187
+ };
2188
+ let DefaultCache$1 = class DefaultCache {
2157
2189
  constructor() {
2158
2190
  this.data = {};
2159
2191
  }
2160
2192
  get(key, options) {
2161
2193
  if (options == null ? void 0 : options.copy) {
2162
- return deepCopy(this.data[key]);
2194
+ return deepCopy$1(this.data[key]);
2163
2195
  }
2164
2196
  return this.data[key];
2165
2197
  }
@@ -2221,20 +2253,20 @@ class DefaultCache {
2221
2253
  return Object.entries(this.data);
2222
2254
  }
2223
2255
  record() {
2224
- return new DefaultRecordableCache(this);
2256
+ return new DefaultRecordableCache$1(this);
2225
2257
  }
2226
2258
  filter(predicate) {
2227
- return new DefaultFilteredCache(this, predicate);
2259
+ return new DefaultFilteredCache$1(this, predicate);
2228
2260
  }
2229
2261
  buildFixedTimeWritableCache(generatedTime) {
2230
- return new FixedTimeWritableCache(this, generatedTime);
2262
+ return new FixedTimeWritableCache$1(this, generatedTime);
2231
2263
  }
2232
- }
2233
- function buildServiceDescriptor$9() {
2264
+ };
2265
+ function buildServiceDescriptor$h() {
2234
2266
  return {
2235
2267
  type: "cache",
2236
2268
  version: "1.0",
2237
- service: new DefaultCache()
2269
+ service: new DefaultCache$1()
2238
2270
  };
2239
2271
  }
2240
2272
 
@@ -2453,7 +2485,7 @@ class CacheController {
2453
2485
  yield* this.services.cacheInclusionPolicy.findAndModify(query, cacheUpdate);
2454
2486
  }
2455
2487
  }
2456
- function buildServiceDescriptor$8(cache, cacheInclusionPolicy, instrumentation) {
2488
+ function buildServiceDescriptor$g(cache, cacheInclusionPolicy, instrumentation) {
2457
2489
  return {
2458
2490
  type: "cacheController",
2459
2491
  version: "1.0",
@@ -2466,48 +2498,6 @@ function buildServiceDescriptor$8(cache, cacheInclusionPolicy, instrumentation)
2466
2498
  * All rights reserved.
2467
2499
  * For full license text, see the LICENSE.txt file
2468
2500
  */
2469
- /*!
2470
- * Copyright (c) 2022, Salesforce, Inc.,
2471
- * All rights reserved.
2472
- * For full license text, see the LICENSE.txt file
2473
- */
2474
- function resolvedPromiseLike$1(result) {
2475
- if (isPromiseLike$1(result)) {
2476
- return result.then((nextResult) => nextResult);
2477
- }
2478
- return {
2479
- then: (onFulfilled, _onRejected) => {
2480
- try {
2481
- return resolvedPromiseLike$1(onFulfilled(result));
2482
- } catch (e) {
2483
- if (onFulfilled === void 0) {
2484
- return resolvedPromiseLike$1(result);
2485
- }
2486
- return rejectedPromiseLike$1(e);
2487
- }
2488
- }
2489
- };
2490
- }
2491
- function rejectedPromiseLike$1(reason) {
2492
- if (isPromiseLike$1(reason)) {
2493
- return reason.then((nextResult) => nextResult);
2494
- }
2495
- return {
2496
- then: (_onFulfilled, onRejected) => {
2497
- if (typeof onRejected === "function") {
2498
- try {
2499
- return resolvedPromiseLike$1(onRejected(reason));
2500
- } catch (e) {
2501
- return rejectedPromiseLike$1(e);
2502
- }
2503
- }
2504
- return rejectedPromiseLike$1(reason);
2505
- }
2506
- };
2507
- }
2508
- function isPromiseLike$1(x) {
2509
- return typeof (x == null ? void 0 : x.then) === "function";
2510
- }
2511
2501
  const EventTypeWildcard = Symbol("EventTypeWildcard");
2512
2502
  class DefaultPubSubService {
2513
2503
  constructor() {
@@ -2535,14 +2525,14 @@ class DefaultPubSubService {
2535
2525
  return;
2536
2526
  }
2537
2527
  const returnVal = subscription.callback.call(subscription, event);
2538
- if (isPromiseLike$1(returnVal)) {
2528
+ if (isPromiseLike$2(returnVal)) {
2539
2529
  promises.push(returnVal);
2540
2530
  }
2541
2531
  });
2542
2532
  if (promises.length > 0) {
2543
2533
  return Promise.all(promises).then(() => void 0);
2544
2534
  }
2545
- return resolvedPromiseLike$1(void 0);
2535
+ return resolvedPromiseLike$2(void 0);
2546
2536
  }
2547
2537
  getSubscriptions(event) {
2548
2538
  const eventTypeSubscriptions = this.subscriptions.get(event.type);
@@ -2563,7 +2553,7 @@ class DefaultPubSubService {
2563
2553
  return matchingSubscriptions;
2564
2554
  }
2565
2555
  }
2566
- function buildServiceDescriptor$7() {
2556
+ function buildServiceDescriptor$f() {
2567
2557
  return {
2568
2558
  type: "pubSub",
2569
2559
  version: "1.0",
@@ -2626,7 +2616,7 @@ class NDJSONParsingStream extends TransformStream {
2626
2616
  });
2627
2617
  }
2628
2618
  }
2629
- function buildServiceDescriptor$6() {
2619
+ function buildServiceDescriptor$e() {
2630
2620
  return {
2631
2621
  type: "NDJSONCommandBaseClass",
2632
2622
  version: "1.0",
@@ -2667,7 +2657,7 @@ function buildServiceDescriptor$6() {
2667
2657
  * };
2668
2658
  * ```
2669
2659
  */
2670
- function buildServiceDescriptor$5(luvio) {
2660
+ function buildServiceDescriptor$d(luvio) {
2671
2661
  return {
2672
2662
  type: 'luvio',
2673
2663
  version: '1.0',
@@ -2676,7 +2666,7 @@ function buildServiceDescriptor$5(luvio) {
2676
2666
  },
2677
2667
  };
2678
2668
  }
2679
- // version: 1.400.0-3c7514a502
2669
+ // version: 1.402.0-566b6c5389
2680
2670
 
2681
2671
  /*!
2682
2672
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -2798,7 +2788,7 @@ class AuraGraphQLNormalizedCacheControlCommand extends AuraNormalizedCacheContro
2798
2788
  return buildSubscribableResult$1(result, this.buildSubscribe(), () => this.refresh());
2799
2789
  });
2800
2790
  }
2801
- return resolvedPromiseLike$3(
2791
+ return resolvedPromiseLike$2(
2802
2792
  buildSubscribableResult$1(
2803
2793
  err$1(toError("Aura/Fetch network services not found")),
2804
2794
  this.buildSubscribe(),
@@ -2840,7 +2830,7 @@ class AuraGraphQLNormalizedCacheControlCommand extends AuraNormalizedCacheContro
2840
2830
  });
2841
2831
  }
2842
2832
  }
2843
- function buildServiceDescriptor$4() {
2833
+ function buildServiceDescriptor$c() {
2844
2834
  return {
2845
2835
  type: "auraGraphQLNormalizedCacheControlCommand",
2846
2836
  version: "1.0",
@@ -2958,7 +2948,7 @@ class HttpGraphQLNormalizedCacheControlCommand extends HttpNormalizedCacheContro
2958
2948
  });
2959
2949
  }
2960
2950
  }
2961
- function buildServiceDescriptor$3() {
2951
+ function buildServiceDescriptor$b() {
2962
2952
  return {
2963
2953
  type: "httpGraphQLNormalizedCacheControlCommand",
2964
2954
  version: "1.0",
@@ -2982,7 +2972,7 @@ class FeatureFlagsService {
2982
2972
  return this.flags.get(flagName) || defaultValue;
2983
2973
  }
2984
2974
  }
2985
- function buildServiceDescriptor$2() {
2975
+ function buildServiceDescriptor$a() {
2986
2976
  return {
2987
2977
  version: "1.0",
2988
2978
  service: new FeatureFlagsService(),
@@ -3004,7 +2994,7 @@ function buildServiceDescriptor$2() {
3004
2994
  * *******************************************************************************************
3005
2995
  */
3006
2996
  /* proxy-compat-disable */
3007
- function buildServiceDescriptor$1(notifyRecordUpdateAvailable, getNormalizedLuvioRecord) {
2997
+ function buildServiceDescriptor$9(notifyRecordUpdateAvailable, getNormalizedLuvioRecord) {
3008
2998
  return {
3009
2999
  type: 'luvioUiapiRecords',
3010
3000
  version: '1.0',
@@ -3014,7 +3004,7 @@ function buildServiceDescriptor$1(notifyRecordUpdateAvailable, getNormalizedLuvi
3014
3004
  },
3015
3005
  };
3016
3006
  }
3017
- // version: 1.400.0-3c7514a502
3007
+ // version: 1.402.0-566b6c5389
3018
3008
 
3019
3009
  /*!
3020
3010
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3037,9 +3027,12 @@ class RetryService {
3037
3027
  totalElapsedMs: Date.now() - startTime,
3038
3028
  lastResult: result
3039
3029
  };
3040
- while (policy.shouldRetry(result, context)) {
3041
- const delay = policy.calculateDelay(result, context);
3030
+ while (await policy.shouldRetry(result, context)) {
3031
+ const delay = await policy.calculateDelay(result, context);
3042
3032
  await this.delay(delay);
3033
+ if (policy.prepareRetry) {
3034
+ await policy.prepareRetry(result, context);
3035
+ }
3043
3036
  attempt++;
3044
3037
  result = await operation();
3045
3038
  context = {
@@ -3058,7 +3051,109 @@ class RetryService {
3058
3051
  }
3059
3052
  class RetryPolicy {
3060
3053
  }
3061
- function buildServiceDescriptor(defaultRetryPolicy) {
3054
+ class ComposedRetryPolicy extends RetryPolicy {
3055
+ constructor(policies) {
3056
+ super();
3057
+ this.policies = policies;
3058
+ }
3059
+ /**
3060
+ * Returns true if any of the composed policies want to retry.
3061
+ *
3062
+ * Uses OR logic: if ANY policy returns true, this returns true.
3063
+ * Policies are checked in order and evaluation short-circuits on the first match.
3064
+ */
3065
+ async shouldRetry(result, context) {
3066
+ for (const policy of this.policies) {
3067
+ if (await policy.shouldRetry(result, context)) {
3068
+ return true;
3069
+ }
3070
+ }
3071
+ return false;
3072
+ }
3073
+ /**
3074
+ * Returns the delay from the first policy that wants to retry.
3075
+ *
3076
+ * If multiple policies want to retry, only the FIRST policy's delay is used.
3077
+ * Policy order in the constructor array determines priority.
3078
+ * If no policy wants to retry, returns 0.
3079
+ *
3080
+ * @example
3081
+ * ```typescript
3082
+ * // If both PolicyA (1000ms) and PolicyB (5000ms) want to retry:
3083
+ * const composed = new ComposedRetryPolicy([policyA, policyB]);
3084
+ * composed.calculateDelay(result, context); // Returns 1000ms (PolicyA wins)
3085
+ * ```
3086
+ */
3087
+ async calculateDelay(result, context) {
3088
+ for (const policy of this.policies) {
3089
+ if (await policy.shouldRetry(result, context)) {
3090
+ return policy.calculateDelay(result, context);
3091
+ }
3092
+ }
3093
+ return 0;
3094
+ }
3095
+ /**
3096
+ * Calls prepareRetry on policies that both:
3097
+ * 1. Implement the prepareRetry hook, AND
3098
+ * 2. Returned true from shouldRetry for this result
3099
+ *
3100
+ * This allows only the matching policies to perform preparation work (e.g., token refresh).
3101
+ * All matching prepareRetry calls run in parallel for efficiency.
3102
+ *
3103
+ * **Important**: prepareRetry only runs on policies that matched shouldRetry. This ensures
3104
+ * you don't perform unnecessary work or side effects for unrelated retry conditions.
3105
+ *
3106
+ * **Note**: If multiple policies match and have prepareRetry, ensure they don't have
3107
+ * conflicting side effects since they run in parallel.
3108
+ *
3109
+ * @example
3110
+ * ```typescript
3111
+ * // Status 401 occurs
3112
+ * const composed = new ComposedRetryPolicy([
3113
+ * authPolicy, // shouldRetry(401) → true, has prepareRetry
3114
+ * throttlePolicy, // shouldRetry(401) → false, has prepareRetry
3115
+ * ]);
3116
+ *
3117
+ * await composed.prepareRetry(result, context);
3118
+ * // → Only authPolicy.prepareRetry() runs (because it matched)
3119
+ * // → throttlePolicy.prepareRetry() does NOT run (didn't match)
3120
+ * ```
3121
+ */
3122
+ async prepareRetry(result, context) {
3123
+ const matchingPolicies = [];
3124
+ for (const policy of this.policies) {
3125
+ if (policy.prepareRetry !== void 0 && await policy.shouldRetry(result, context)) {
3126
+ matchingPolicies.push(policy);
3127
+ }
3128
+ }
3129
+ if (matchingPolicies.length > 0) {
3130
+ await Promise.all(
3131
+ matchingPolicies.map((policy) => policy.prepareRetry(result, context))
3132
+ );
3133
+ }
3134
+ }
3135
+ /**
3136
+ * Returns all composed policies.
3137
+ * Useful for accessing or configuring individual policies after composition.
3138
+ */
3139
+ getPolicies() {
3140
+ return this.policies;
3141
+ }
3142
+ /**
3143
+ * Helper to get a specific policy by type.
3144
+ * Useful for calling policy-specific methods after composition.
3145
+ *
3146
+ * @example
3147
+ * ```typescript
3148
+ * const csrfPolicy = composedPolicy.getPolicyByType(CsrfTokenRetryPolicy);
3149
+ * csrfPolicy?.setRequestContext(mutableRequest);
3150
+ * ```
3151
+ */
3152
+ getPolicyByType(policyType) {
3153
+ return this.policies.find((policy) => policy instanceof policyType);
3154
+ }
3155
+ }
3156
+ function buildServiceDescriptor$8(defaultRetryPolicy) {
3062
3157
  return {
3063
3158
  version: "1.0",
3064
3159
  service: new RetryService(defaultRetryPolicy),
@@ -3071,98 +3166,828 @@ function buildServiceDescriptor(defaultRetryPolicy) {
3071
3166
  * All rights reserved.
3072
3167
  * For full license text, see the LICENSE.txt file
3073
3168
  */
3074
- function e$1(e2) {
3075
- this.message = e2;
3169
+ function isUserVisibleError(error) {
3170
+ return error instanceof Error && "type" in error && error.type === "user-visible";
3076
3171
  }
3077
- e$1.prototype = new Error(), e$1.prototype.name = "InvalidCharacterError";
3078
- var r = "undefined" != typeof window && window.atob && window.atob.bind(window) || function(r2) {
3079
- var t2 = String(r2).replace(/=+$/, "");
3080
- if (t2.length % 4 == 1) throw new e$1("'atob' failed: The string to be decoded is not correctly encoded.");
3081
- for (var n2, o2, a = 0, i = 0, c = ""; o2 = t2.charAt(i++); ~o2 && (n2 = a % 4 ? 64 * n2 + o2 : o2, a++ % 4) ? c += String.fromCharCode(255 & n2 >> (-2 * a & 6)) : 0) o2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o2);
3082
- return c;
3083
- };
3084
- function t(e2) {
3085
- var t2 = e2.replace(/-/g, "+").replace(/_/g, "/");
3086
- switch (t2.length % 4) {
3087
- case 0:
3088
- break;
3089
- case 2:
3090
- t2 += "==";
3091
- break;
3092
- case 3:
3093
- t2 += "=";
3094
- break;
3095
- default:
3096
- throw "Illegal base64url string!";
3097
- }
3098
- try {
3099
- return (function(e3) {
3100
- return decodeURIComponent(r(e3).replace(/(.)/g, (function(e4, r2) {
3101
- var t3 = r2.charCodeAt(0).toString(16).toUpperCase();
3102
- return t3.length < 2 && (t3 = "0" + t3), "%" + t3;
3103
- })));
3104
- })(t2);
3105
- } catch (e3) {
3106
- return r(t2);
3107
- }
3172
+ function throwUserlandError(error) {
3173
+ logError(error);
3174
+ throw buildUserlandError(error);
3108
3175
  }
3109
- function n$1(e2) {
3110
- this.message = e2;
3176
+ function emitError(callback, error) {
3177
+ logError(error);
3178
+ callback({ data: void 0, error: buildUserlandError(error) });
3111
3179
  }
3112
- function o(e2, r2) {
3113
- if ("string" != typeof e2) throw new n$1("Invalid token specified");
3114
- var o2 = true === (r2 = r2 || {}).header ? 0 : 1;
3115
- try {
3116
- return JSON.parse(t(e2.split(".")[o2]));
3117
- } catch (e3) {
3118
- throw new n$1("Invalid token specified: " + e3.message);
3180
+ function buildUserlandError(error) {
3181
+ if (isUserVisibleError(error)) {
3182
+ return error.data;
3119
3183
  }
3184
+ return new Error("Internal error in Lightning Data Service adapter occurred.");
3120
3185
  }
3121
- n$1.prototype = new Error(), n$1.prototype.name = "InvalidTokenError";
3186
+ function logError(error) {
3187
+ if (isUserVisibleError(error)) {
3188
+ return;
3189
+ }
3190
+ console.error("OneStore Command threw an error that we did not expect", error);
3191
+ }
3192
+
3122
3193
  /*!
3123
3194
  * Copyright (c) 2022, Salesforce, Inc.,
3124
3195
  * All rights reserved.
3125
3196
  * For full license text, see the LICENSE.txt file
3126
3197
  */
3127
- const LogLevelMap = {
3128
- TRACE: 4,
3129
- DEBUG: 3,
3130
- INFO: 2,
3131
- WARN: 1,
3132
- ERROR: 0
3133
- };
3134
- class ConsoleLogger {
3135
- constructor(level = "WARN", printer = console.log, formatter = (level2, message) => `${level2}: ${message}`) {
3136
- this.level = level;
3137
- this.printer = printer;
3138
- this.formatter = formatter;
3139
- this.messages = [];
3198
+ function buildBaseImperativeInvoker(getCommand, transformResult) {
3199
+ return async (...params) => {
3200
+ const command = getCommand({ params, assertIsValid });
3201
+ try {
3202
+ return command.execute().then((result) => transformResult(result));
3203
+ } catch (error) {
3204
+ throwUserlandError(error);
3205
+ }
3206
+ };
3207
+ }
3208
+ const supportedCachePolicyTypes = ["no-cache", "only-if-cached"];
3209
+ function requestContextIsSupportedCachePolicy(requestContext) {
3210
+ return typeof requestContext === "object" && requestContext !== null && "cachePolicy" in requestContext && typeof requestContext.cachePolicy === "object" && requestContext.cachePolicy !== null && "type" in requestContext.cachePolicy && typeof requestContext.cachePolicy.type === "string" && supportedCachePolicyTypes.includes(
3211
+ requestContext.cachePolicy.type
3212
+ );
3213
+ }
3214
+ function getOverridesForLegacyRequestContext(requestContext) {
3215
+ if (requestContextIsSupportedCachePolicy(requestContext)) {
3216
+ return { cacheControlConfig: { type: requestContext.cachePolicy.type } };
3140
3217
  }
3141
- trace(message) {
3142
- this.log("TRACE", message);
3218
+ return {};
3219
+ }
3220
+ function handleEmit(res, callback) {
3221
+ const consumerEmittedData = {
3222
+ data: void 0,
3223
+ errors: void 0
3224
+ };
3225
+ if (res.isOk()) {
3226
+ consumerEmittedData.data = res.value.data;
3227
+ } else {
3228
+ const { data, errors } = toGraphQLResponseFromFailure$1(res.error);
3229
+ consumerEmittedData.data = data;
3230
+ consumerEmittedData.errors = errors;
3143
3231
  }
3144
- debug(message) {
3145
- this.log("DEBUG", message);
3232
+ callback(consumerEmittedData);
3233
+ }
3234
+ function toGraphQLResponseFromFailure$1(failure) {
3235
+ if (isUserVisibleError$1(failure)) {
3236
+ return {
3237
+ data: failure.data.data,
3238
+ errors: failure.data.errors
3239
+ };
3146
3240
  }
3147
- info(message) {
3148
- this.log("INFO", message);
3241
+ logError$1(failure);
3242
+ return {
3243
+ data: void 0,
3244
+ errors: [{ message: "Internal error in GraphQL adapter occurred", locations: [] }]
3245
+ };
3246
+ }
3247
+ class DefaultImperativeBindingsService {
3248
+ bind(getCommand) {
3249
+ return buildBaseImperativeInvoker(getCommand, (result) => {
3250
+ if (result.isOk()) {
3251
+ deepFreeze(result.value);
3252
+ return isSubscribableResult(result) ? result.value.data : result.value;
3253
+ }
3254
+ throw toError(isSubscribableResult(result) ? result.error.failure : result.error);
3255
+ });
3149
3256
  }
3150
- warn(message) {
3151
- this.log("WARN", message);
3257
+ }
3258
+ function buildServiceDescriptor$6() {
3259
+ return {
3260
+ type: "defaultImperativeBindings",
3261
+ version: "1.0",
3262
+ service: new DefaultImperativeBindingsService()
3263
+ };
3264
+ }
3265
+ class QueryImperativeBindingsService {
3266
+ bind(getCommand) {
3267
+ return buildBaseImperativeInvoker(getCommand, (result) => {
3268
+ if (result.isOk()) {
3269
+ deepFreeze(result.value);
3270
+ return isSubscribableResult(result) ? { data: result.value.data } : { data: result.value };
3271
+ }
3272
+ throw toError(isSubscribableResult(result) ? result.error.failure : result.error);
3273
+ });
3152
3274
  }
3153
- error(message) {
3154
- this.log("ERROR", message);
3275
+ }
3276
+ function buildServiceDescriptor$5() {
3277
+ return {
3278
+ type: "queryImperativeBindings",
3279
+ version: "1.0",
3280
+ service: new QueryImperativeBindingsService()
3281
+ };
3282
+ }
3283
+ class SubscribableImperativeBindingsService {
3284
+ bind(getCommand, exposeRefresh = false) {
3285
+ return buildBaseImperativeInvoker(
3286
+ getCommand,
3287
+ (result) => this.transformResult(result, exposeRefresh)
3288
+ );
3155
3289
  }
3156
- log(level, message) {
3157
- if (LogLevelMap[level] > LogLevelMap[this.level]) {
3290
+ transformResult(result, exposeRefresh = false) {
3291
+ if (!isSubscribableResult(result)) {
3292
+ console.error(
3293
+ "Non-subscribable result encountered - please use correct operation type"
3294
+ );
3295
+ throw new Error("Internal error in Lightning Data Service adapter occurred");
3296
+ }
3297
+ if (result.isOk()) {
3298
+ deepFreeze(result.value.data);
3299
+ const api = {
3300
+ data: result.value.data,
3301
+ subscribe: (cb) => {
3302
+ result.value.subscribe((result2) => {
3303
+ if (result2.isErr()) {
3304
+ return cb({ data: void 0, error: toError(result2.error) });
3305
+ }
3306
+ return cb({ data: result2.value, error: void 0 });
3307
+ });
3308
+ }
3309
+ };
3310
+ if (exposeRefresh) {
3311
+ return {
3312
+ ...api,
3313
+ refresh: () => {
3314
+ return result.value.refresh().then((res) => {
3315
+ if (res.isOk()) {
3316
+ return void 0;
3317
+ }
3318
+ throw res.error;
3319
+ });
3320
+ }
3321
+ };
3322
+ } else {
3323
+ return api;
3324
+ }
3325
+ } else {
3326
+ throw toError(result.error.failure);
3327
+ }
3328
+ }
3329
+ }
3330
+ function buildServiceDescriptor$4() {
3331
+ return {
3332
+ type: "subscribableImperativeBindings",
3333
+ version: "1.0",
3334
+ service: new SubscribableImperativeBindingsService()
3335
+ };
3336
+ }
3337
+ class LegacyImperativeBindingsService {
3338
+ bind(getCommand) {
3339
+ const invoke = async (config, requestContext, callback) => {
3340
+ const command = getCommand({ config, assertIsValid });
3341
+ try {
3342
+ const overrides = getOverridesForLegacyRequestContext(requestContext);
3343
+ const result = await command.execute(overrides);
3344
+ if (result.isOk()) {
3345
+ deepFreeze(result.value);
3346
+ callback({ data: result.value.data, error: void 0 });
3347
+ } else {
3348
+ callback({ data: void 0, error: toError(result.error.failure) });
3349
+ }
3350
+ } catch (error) {
3351
+ emitError(callback, error);
3352
+ }
3353
+ };
3354
+ const subscribe = (config, requestContext, callback) => {
3355
+ const command = getCommand({ config, assertIsValid });
3356
+ let unsubscribe = () => {
3357
+ };
3358
+ try {
3359
+ const overrides = getOverridesForLegacyRequestContext(requestContext);
3360
+ command.execute(overrides).then(
3361
+ (result) => {
3362
+ if (!result.isOk()) {
3363
+ callback({ data: void 0, error: toError(result.error.failure) });
3364
+ return;
3365
+ }
3366
+ unsubscribe = result.value.subscribe((res) => {
3367
+ if (res.isOk()) {
3368
+ callback({ data: res.value, error: void 0 });
3369
+ } else {
3370
+ callback({ data: void 0, error: toError(res.error) });
3371
+ }
3372
+ });
3373
+ callback({ data: result.value.data, error: void 0 });
3374
+ },
3375
+ (e) => {
3376
+ emitError(callback, e);
3377
+ }
3378
+ );
3379
+ } catch (e) {
3380
+ emitError(callback, e);
3381
+ }
3382
+ return () => {
3383
+ unsubscribe();
3384
+ };
3385
+ };
3386
+ return { invoke, subscribe };
3387
+ }
3388
+ }
3389
+ function buildServiceDescriptor$3() {
3390
+ return {
3391
+ type: "legacyImperativeBindings",
3392
+ version: "1.0",
3393
+ service: new LegacyImperativeBindingsService()
3394
+ };
3395
+ }
3396
+ class GraphQLImperativeBindingsService {
3397
+ bind(getCommand, exposeRefresh = false) {
3398
+ return async (...params) => {
3399
+ try {
3400
+ if (params.length) {
3401
+ params[0] = wrapConfigAndVerify(params[0]);
3402
+ }
3403
+ return await buildBaseImperativeInvoker(getCommand, (result) => this.transformResult(result, exposeRefresh))(...params);
3404
+ } catch (error) {
3405
+ logError$1(error);
3406
+ return {
3407
+ data: void 0,
3408
+ errors: [
3409
+ { message: "Internal error in GraphQL adapter occurred", locations: [] }
3410
+ ]
3411
+ };
3412
+ }
3413
+ };
3414
+ }
3415
+ transformResult(result, exposeRefresh = false) {
3416
+ const consumerEmittedData = {
3417
+ data: void 0,
3418
+ errors: void 0
3419
+ };
3420
+ if (result.isOk()) {
3421
+ deepFreeze(result.value);
3422
+ consumerEmittedData.data = result.value.data.data;
3423
+ consumerEmittedData.subscribe = (cb) => {
3424
+ result.value.subscribe((res) => {
3425
+ const consumerEmittedData2 = {
3426
+ data: void 0,
3427
+ errors: void 0
3428
+ };
3429
+ if (res.isOk()) {
3430
+ consumerEmittedData2.data = res.value.data;
3431
+ } else {
3432
+ if (isUserVisibleError$1(res.error)) {
3433
+ consumerEmittedData2.data = res.error.data.data;
3434
+ consumerEmittedData2.errors = res.error.data.errors;
3435
+ } else {
3436
+ logError$1(res.error);
3437
+ consumerEmittedData2.errors = [
3438
+ {
3439
+ message: "Internal error in GraphQL adapter occurred",
3440
+ locations: []
3441
+ }
3442
+ ];
3443
+ }
3444
+ }
3445
+ cb(consumerEmittedData2);
3446
+ });
3447
+ };
3448
+ if (exposeRefresh) {
3449
+ consumerEmittedData.refresh = () => {
3450
+ return new Promise((resolve, reject) => {
3451
+ try {
3452
+ result.value.refresh().then((res) => {
3453
+ if (res.isOk()) {
3454
+ resolve();
3455
+ } else {
3456
+ reject(
3457
+ new Error(
3458
+ "Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data"
3459
+ )
3460
+ );
3461
+ }
3462
+ });
3463
+ } catch (error) {
3464
+ logError$1(error);
3465
+ reject(
3466
+ new Error(
3467
+ "Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data"
3468
+ )
3469
+ );
3470
+ }
3471
+ });
3472
+ };
3473
+ }
3474
+ } else {
3475
+ const resp = toGraphQLResponseFromFailure$1(result.error.failure);
3476
+ consumerEmittedData.data = resp.data;
3477
+ consumerEmittedData.errors = resp.errors;
3478
+ }
3479
+ return consumerEmittedData;
3480
+ }
3481
+ }
3482
+ function buildServiceDescriptor$2$1() {
3483
+ return {
3484
+ type: "graphQLImperativeBindings",
3485
+ version: "1.0",
3486
+ service: new GraphQLImperativeBindingsService()
3487
+ };
3488
+ }
3489
+ class GraphQLLegacyImperativeBindingsService {
3490
+ bind(getCommand) {
3491
+ const invoke = async (config, requestContext, callback) => {
3492
+ config = wrapConfigAndVerify(config);
3493
+ const command = getCommand({ config, assertIsValid });
3494
+ try {
3495
+ const overrides = getOverridesForLegacyRequestContext(requestContext);
3496
+ const result = await command.execute(overrides);
3497
+ const consumerEmittedData = {
3498
+ data: void 0,
3499
+ errors: void 0
3500
+ };
3501
+ if (result.isOk()) {
3502
+ deepFreeze(result.value);
3503
+ consumerEmittedData.data = result.value.data.data;
3504
+ } else {
3505
+ const { data, errors } = toGraphQLResponseFromFailure$1(result.error.failure);
3506
+ consumerEmittedData.data = data;
3507
+ consumerEmittedData.errors = errors;
3508
+ }
3509
+ callback(consumerEmittedData);
3510
+ } catch (error) {
3511
+ logError$1(error);
3512
+ callback({
3513
+ data: void 0,
3514
+ errors: [
3515
+ { message: "Internal error in GraphQL adapter occurred", locations: [] }
3516
+ ]
3517
+ });
3518
+ }
3519
+ };
3520
+ const subscribe = (config, requestContext, callback) => {
3521
+ config = wrapConfigAndVerify(config);
3522
+ const command = getCommand({ config, assertIsValid });
3523
+ let unsubscribe = () => {
3524
+ };
3525
+ const overrides = getOverridesForLegacyRequestContext(requestContext);
3526
+ command.execute(overrides).then((result) => {
3527
+ const consumerEmittedData = {
3528
+ data: void 0,
3529
+ errors: void 0
3530
+ };
3531
+ if (result.isOk()) {
3532
+ deepFreeze(result.value);
3533
+ consumerEmittedData.data = result.value.data.data;
3534
+ unsubscribe = result.value.subscribe(
3535
+ (res) => {
3536
+ handleEmit(res, callback);
3537
+ }
3538
+ );
3539
+ } else {
3540
+ const { data, errors } = toGraphQLResponseFromFailure$1(result.error.failure);
3541
+ consumerEmittedData.data = data;
3542
+ consumerEmittedData.errors = errors;
3543
+ unsubscribe = result.error.subscribe(
3544
+ (res) => {
3545
+ handleEmit(res, callback);
3546
+ }
3547
+ );
3548
+ }
3549
+ callback(consumerEmittedData);
3550
+ });
3551
+ return () => {
3552
+ unsubscribe();
3553
+ };
3554
+ };
3555
+ return { invoke, subscribe };
3556
+ }
3557
+ }
3558
+ function buildServiceDescriptor$1$1() {
3559
+ return {
3560
+ type: "graphQLLegacyImperativeBindings",
3561
+ version: "1.0",
3562
+ service: new GraphQLLegacyImperativeBindingsService()
3563
+ };
3564
+ }
3565
+ class GraphQLMutationBindingsService {
3566
+ bind(getCommand) {
3567
+ return async (...params) => {
3568
+ try {
3569
+ if (params.length) {
3570
+ params[0] = wrapConfigAndVerify(params[0], {
3571
+ acceptedOperations: ["mutation"]
3572
+ });
3573
+ }
3574
+ const command = getCommand({ params, assertIsValid });
3575
+ const result = await command.execute({ cacheControlConfig: { type: "no-cache" } });
3576
+ if (result.isOk()) {
3577
+ deepFreeze(result.value);
3578
+ return result.value.data;
3579
+ } else {
3580
+ return toGraphQLResponseFromFailure$1(result.error.failure);
3581
+ }
3582
+ } catch (error) {
3583
+ logError$1(error);
3584
+ return {
3585
+ data: void 0,
3586
+ errors: [
3587
+ { message: "Internal error in GraphQL adapter occurred", locations: [] }
3588
+ ]
3589
+ };
3590
+ }
3591
+ };
3592
+ }
3593
+ }
3594
+ function buildServiceDescriptor$7() {
3595
+ return {
3596
+ type: "graphQLMutationBindings",
3597
+ version: "1.0",
3598
+ service: new GraphQLMutationBindingsService()
3599
+ };
3600
+ }
3601
+
3602
+ /*!
3603
+ * Copyright (c) 2022, Salesforce, Inc.,
3604
+ * All rights reserved.
3605
+ * For full license text, see the LICENSE.txt file
3606
+ */
3607
+ class Sanitizer {
3608
+ constructor(obj) {
3609
+ this.obj = obj;
3610
+ this.copy = {};
3611
+ this.currentPath = {
3612
+ key: "",
3613
+ value: obj,
3614
+ parent: null,
3615
+ data: this.copy
3616
+ };
3617
+ }
3618
+ sanitize() {
3619
+ const sanitizer = this;
3620
+ JSON.stringify(this.obj, function(key, value) {
3621
+ if (key === "") {
3622
+ return value;
3623
+ }
3624
+ const parent = this;
3625
+ if (parent !== sanitizer.currentPath.value) {
3626
+ sanitizer.exit(parent);
3627
+ }
3628
+ if (typeof value === "object" && value !== null) {
3629
+ sanitizer.enter(key, value);
3630
+ return value;
3631
+ }
3632
+ sanitizer.currentPath.data[key] = value;
3633
+ return value;
3634
+ });
3635
+ return this.copy;
3636
+ }
3637
+ enter(key, value) {
3638
+ const { currentPath: parentPath } = this;
3639
+ const data = parentPath.data[key] = Array.isArray(value) ? [] : {};
3640
+ this.currentPath = {
3641
+ key,
3642
+ value,
3643
+ parent: parentPath,
3644
+ data
3645
+ };
3646
+ }
3647
+ exit(parent) {
3648
+ while (this.currentPath.value !== parent) {
3649
+ this.currentPath = this.currentPath.parent || this.currentPath;
3650
+ }
3651
+ }
3652
+ }
3653
+ function sanitize(obj) {
3654
+ return new Sanitizer(obj).sanitize();
3655
+ }
3656
+ function isIncompleteConfigError(err) {
3657
+ return err instanceof MissingRequiredPropertyError || err instanceof JsonSchemaViolationError && err.validationErrors.find(
3658
+ (validationError) => validationError instanceof MissingRequiredPropertyError
3659
+ ) !== void 0;
3660
+ }
3661
+ class CommandWireAdapterConstructor {
3662
+ constructor(callback, sourceContext, options) {
3663
+ this.callback = callback;
3664
+ this.connected = false;
3665
+ this.exposeRefresh = false;
3666
+ if (!(options == null ? void 0 : options.skipEmptyEmit)) {
3667
+ this.emit();
3668
+ }
3669
+ }
3670
+ connect() {
3671
+ this.connected = true;
3672
+ this.invokeAdapter();
3673
+ }
3674
+ disconnect() {
3675
+ this.unsubscribe();
3676
+ this.connected = false;
3677
+ }
3678
+ update(config, _context) {
3679
+ this.unsubscribe();
3680
+ this.config = sanitize(config);
3681
+ this.invokeAdapter();
3682
+ }
3683
+ emit(result) {
3684
+ try {
3685
+ if (result === void 0) {
3686
+ this.callback({ data: void 0, error: void 0 });
3687
+ } else {
3688
+ const consumerEmittedRefresh = () => {
3689
+ if (!this.refresh) {
3690
+ return Promise.resolve();
3691
+ }
3692
+ return new Promise((resolve, reject) => {
3693
+ if (!this.refresh) {
3694
+ resolve();
3695
+ return;
3696
+ }
3697
+ this.refresh().then((res) => {
3698
+ if (res.isOk()) {
3699
+ resolve();
3700
+ } else {
3701
+ reject(
3702
+ new Error(
3703
+ "Internal error in Lightning Data Service adapter occurred: Failed to refresh data"
3704
+ )
3705
+ );
3706
+ }
3707
+ });
3708
+ });
3709
+ };
3710
+ let consumerEmittedData = {
3711
+ data: void 0,
3712
+ error: void 0
3713
+ };
3714
+ if (this.exposeRefresh && this.refresh) {
3715
+ consumerEmittedData.refresh = consumerEmittedRefresh;
3716
+ }
3717
+ if (result.isErr()) {
3718
+ if (isSubscribableResult(result)) {
3719
+ consumerEmittedData.error = result.error.failure;
3720
+ } else {
3721
+ consumerEmittedData.error = result.error;
3722
+ }
3723
+ } else {
3724
+ if (isSubscribableResult(result)) {
3725
+ deepFreeze(result.value.data);
3726
+ consumerEmittedData.data = result.value.data;
3727
+ } else {
3728
+ deepFreeze(result.value);
3729
+ consumerEmittedData.data = result.value;
3730
+ }
3731
+ }
3732
+ this.callback(consumerEmittedData);
3733
+ }
3734
+ } catch (e) {
3735
+ this.handleExecutionThrow(e);
3736
+ }
3737
+ }
3738
+ invokeAdapter() {
3739
+ if (!this.connected || this.config === void 0) {
3158
3740
  return;
3159
3741
  }
3160
- this.printer(this.formatter(level, message));
3742
+ if (this.configSchema) {
3743
+ try {
3744
+ assertIsValid(this.config, this.configSchema);
3745
+ } catch (err) {
3746
+ if (isIncompleteConfigError(err)) {
3747
+ return;
3748
+ }
3749
+ throw err;
3750
+ }
3751
+ }
3752
+ const initialConfig = this.config;
3753
+ const command = this.getCommand();
3754
+ try {
3755
+ command.execute().then((result) => {
3756
+ if (!this.connected || this.config !== initialConfig) {
3757
+ return;
3758
+ }
3759
+ this.refresh = void 0;
3760
+ if (result.isOk()) {
3761
+ if (isSubscribableResult(result)) {
3762
+ const value = result.value;
3763
+ this.unsubscriber = value.subscribe((updatedResult) => {
3764
+ if (!this.connected || this.config !== initialConfig) {
3765
+ this.unsubscribe();
3766
+ return;
3767
+ }
3768
+ this.emit(updatedResult);
3769
+ });
3770
+ this.refresh = value.refresh;
3771
+ this.emit(ok$2(value.data));
3772
+ } else {
3773
+ this.emit(result);
3774
+ }
3775
+ } else {
3776
+ if (isSubscribableResult(result)) {
3777
+ const value = result.error;
3778
+ this.unsubscriber = value.subscribe((updatedResult) => {
3779
+ if (!this.connected || this.config !== initialConfig) {
3780
+ this.unsubscribe();
3781
+ return;
3782
+ }
3783
+ this.emit(updatedResult);
3784
+ });
3785
+ this.refresh = value.refresh;
3786
+ this.emit(result);
3787
+ } else {
3788
+ this.unsubscriber = () => {
3789
+ };
3790
+ this.emit(result);
3791
+ }
3792
+ }
3793
+ });
3794
+ } catch (e) {
3795
+ this.handleExecutionThrow(e);
3796
+ }
3797
+ }
3798
+ handleExecutionThrow(error) {
3799
+ emitError(this.callback, error);
3800
+ }
3801
+ unsubscribe() {
3802
+ if (this.unsubscriber) {
3803
+ this.unsubscriber();
3804
+ delete this.unsubscriber;
3805
+ }
3161
3806
  }
3162
3807
  }
3163
- function loggerService(level, printer, formatter) {
3164
- return new ConsoleLogger(level, printer, formatter);
3808
+ function toGraphQLResponseFromFailure(failure) {
3809
+ if (isUserVisibleError$1(failure)) {
3810
+ return {
3811
+ data: failure.data.data,
3812
+ errors: failure.data.errors
3813
+ };
3814
+ }
3815
+ logError$1(failure);
3816
+ return {
3817
+ data: void 0,
3818
+ errors: [{ message: "Internal error in GraphQL adapter occurred", locations: [] }]
3819
+ };
3820
+ }
3821
+ class LWCWireBindingsService {
3822
+ bind(getCommand, configSchema, exposeRefresh = false) {
3823
+ return class extends CommandWireAdapterConstructor {
3824
+ constructor() {
3825
+ super(...arguments);
3826
+ this.configSchema = configSchema;
3827
+ this.exposeRefresh = exposeRefresh;
3828
+ }
3829
+ getCommand() {
3830
+ return getCommand(this.config);
3831
+ }
3832
+ };
3833
+ }
3834
+ }
3835
+ function buildServiceDescriptor$1() {
3836
+ return {
3837
+ type: "lwcWireBindings",
3838
+ version: "1.0",
3839
+ service: new LWCWireBindingsService()
3840
+ };
3841
+ }
3842
+ class GraphQLCommandWireAdapterConstructor extends CommandWireAdapterConstructor {
3843
+ emit(result) {
3844
+ try {
3845
+ if (result === void 0) {
3846
+ this.callback({ data: void 0, errors: void 0 });
3847
+ } else {
3848
+ const consumerEmittedRefresh = () => {
3849
+ if (!this.refresh) {
3850
+ return Promise.resolve();
3851
+ }
3852
+ return new Promise((resolve, reject) => {
3853
+ if (!this.refresh) {
3854
+ resolve();
3855
+ return;
3856
+ }
3857
+ this.refresh().then((res) => {
3858
+ if (res.isOk()) {
3859
+ resolve();
3860
+ } else {
3861
+ reject(
3862
+ new Error(
3863
+ "Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data"
3864
+ )
3865
+ );
3866
+ }
3867
+ });
3868
+ });
3869
+ };
3870
+ let consumerEmittedData = {
3871
+ data: void 0,
3872
+ errors: void 0
3873
+ };
3874
+ if (this.exposeRefresh && this.refresh) {
3875
+ consumerEmittedData.refresh = consumerEmittedRefresh;
3876
+ }
3877
+ if (result.isErr()) {
3878
+ const failure = isSubscribableResult(result) ? result.error.failure : result.error;
3879
+ const resp = toGraphQLResponseFromFailure(failure);
3880
+ consumerEmittedData.data = resp.data;
3881
+ consumerEmittedData.errors = resp.errors;
3882
+ } else {
3883
+ consumerEmittedData.data = result.value.data;
3884
+ }
3885
+ deepFreeze(consumerEmittedData);
3886
+ this.callback(consumerEmittedData);
3887
+ }
3888
+ } catch (e) {
3889
+ logError$1(e);
3890
+ this.handleExecutionThrow(e);
3891
+ }
3892
+ }
3893
+ handleExecutionThrow(e) {
3894
+ logError$1(e);
3895
+ this.callback({
3896
+ data: void 0,
3897
+ errors: [{ message: "Internal error in GraphQL adapter occurred", locations: [] }]
3898
+ });
3899
+ }
3900
+ update(config, _context) {
3901
+ this.unsubscribe();
3902
+ const resolvedQuery = resolveAst(config.query);
3903
+ if (resolvedQuery) {
3904
+ validateGraphQLOperations(
3905
+ { query: resolvedQuery, operationName: config == null ? void 0 : config.operationName },
3906
+ { acceptedOperations: ["query"] }
3907
+ );
3908
+ }
3909
+ this.config = {
3910
+ ...sanitize(config),
3911
+ query: resolvedQuery
3912
+ };
3913
+ this.invokeAdapter();
3914
+ }
3915
+ }
3916
+ class LWCGraphQLWireBindingsService {
3917
+ bind(getCommand, configSchema, exposeRefresh = false) {
3918
+ return class extends GraphQLCommandWireAdapterConstructor {
3919
+ constructor() {
3920
+ super(...arguments);
3921
+ this.configSchema = configSchema;
3922
+ this.exposeRefresh = exposeRefresh;
3923
+ }
3924
+ getCommand() {
3925
+ return getCommand(this.config);
3926
+ }
3927
+ };
3928
+ }
3165
3929
  }
3930
+ function buildServiceDescriptor$2() {
3931
+ return {
3932
+ type: "lwcGraphQLWireBindings",
3933
+ version: "1.0",
3934
+ service: new LWCGraphQLWireBindingsService()
3935
+ };
3936
+ }
3937
+
3938
+ /*!
3939
+ * Copyright (c) 2022, Salesforce, Inc.,
3940
+ * All rights reserved.
3941
+ * For full license text, see the LICENSE.txt file
3942
+ */
3943
+ function e$1(e2) {
3944
+ this.message = e2;
3945
+ }
3946
+ e$1.prototype = new Error(), e$1.prototype.name = "InvalidCharacterError";
3947
+ var r = "undefined" != typeof window && window.atob && window.atob.bind(window) || function(r2) {
3948
+ var t2 = String(r2).replace(/=+$/, "");
3949
+ if (t2.length % 4 == 1) throw new e$1("'atob' failed: The string to be decoded is not correctly encoded.");
3950
+ for (var n2, o2, a = 0, i = 0, c = ""; o2 = t2.charAt(i++); ~o2 && (n2 = a % 4 ? 64 * n2 + o2 : o2, a++ % 4) ? c += String.fromCharCode(255 & n2 >> (-2 * a & 6)) : 0) o2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o2);
3951
+ return c;
3952
+ };
3953
+ function t(e2) {
3954
+ var t2 = e2.replace(/-/g, "+").replace(/_/g, "/");
3955
+ switch (t2.length % 4) {
3956
+ case 0:
3957
+ break;
3958
+ case 2:
3959
+ t2 += "==";
3960
+ break;
3961
+ case 3:
3962
+ t2 += "=";
3963
+ break;
3964
+ default:
3965
+ throw "Illegal base64url string!";
3966
+ }
3967
+ try {
3968
+ return (function(e3) {
3969
+ return decodeURIComponent(r(e3).replace(/(.)/g, (function(e4, r2) {
3970
+ var t3 = r2.charCodeAt(0).toString(16).toUpperCase();
3971
+ return t3.length < 2 && (t3 = "0" + t3), "%" + t3;
3972
+ })));
3973
+ })(t2);
3974
+ } catch (e3) {
3975
+ return r(t2);
3976
+ }
3977
+ }
3978
+ function n$1(e2) {
3979
+ this.message = e2;
3980
+ }
3981
+ function o(e2, r2) {
3982
+ if ("string" != typeof e2) throw new n$1("Invalid token specified");
3983
+ var o2 = true === (r2 = r2 || {}).header ? 0 : 1;
3984
+ try {
3985
+ return JSON.parse(t(e2.split(".")[o2]));
3986
+ } catch (e3) {
3987
+ throw new n$1("Invalid token specified: " + e3.message);
3988
+ }
3989
+ }
3990
+ n$1.prototype = new Error(), n$1.prototype.name = "InvalidTokenError";
3166
3991
  class JwtToken {
3167
3992
  /**
3168
3993
  * Create a new JwtToken.
@@ -3445,7 +4270,7 @@ function setHeaderAuthorization({ token }, fetchParams) {
3445
4270
  }
3446
4271
  function buildJwtRequestHeaderInterceptor(jwtManager, jwtRequestModifier = (_e, fetchArgs) => fetchArgs) {
3447
4272
  return (args) => {
3448
- return resolvedPromiseLike$3(jwtManager.getJwt()).then((token) => {
4273
+ return resolvedPromiseLike$2(jwtManager.getJwt()).then((token) => {
3449
4274
  const fetchArgsWithRequestHeaderAuthorization = setHeaderAuthorization(token, args);
3450
4275
  return token.extraInfo ? jwtRequestModifier(token.extraInfo, fetchArgsWithRequestHeaderAuthorization) : fetchArgsWithRequestHeaderAuthorization;
3451
4276
  });
@@ -3653,6 +4478,7 @@ function generateHeaders(headers) {
3653
4478
  }
3654
4479
 
3655
4480
  const SALESFORCE_API_BASE_URI_FLAG = 'api.salesforce.com';
4481
+ const X_REQUEST_ID_HEADER = 'x-request-id';
3656
4482
  const SFAPController = 'SalesforceApiPlatformController';
3657
4483
  const SFAPJwtMethod = 'getSFAPLightningJwtService';
3658
4484
  /**
@@ -3733,6 +4559,8 @@ const modifySfapResourceRequest = function (resourceRequest, jwtToken) {
3733
4559
  baseUri,
3734
4560
  };
3735
4561
  };
4562
+ // used for instrumentation and tracking
4563
+ let sfapRequestCount = 0;
3736
4564
  const sfapNetworkAdapter = async (resourceRequest, resourceRequestContext) => {
3737
4565
  let jwtToken;
3738
4566
  try {
@@ -3746,7 +4574,32 @@ const sfapNetworkAdapter = async (resourceRequest, resourceRequestContext) => {
3746
4574
  }
3747
4575
  let authenticatedRequest = authenticateRequest(resourceRequest, jwtToken);
3748
4576
  authenticatedRequest = modifySfapResourceRequest(authenticatedRequest, jwtToken);
3749
- return fetchNetworkAdapter(authenticatedRequest);
4577
+ // --- instrumentation block --- start
4578
+ const uniqueRequestTaskIdentifier = 'sfap-' + sfapRequestCount++;
4579
+ const uniqueRequestGuid = generateRequestId();
4580
+ // request id header allows logging the request id and searching for the request logs
4581
+ authenticatedRequest.headers[X_REQUEST_ID_HEADER] = uniqueRequestGuid;
4582
+ let fetchComplete = false;
4583
+ ThirdPartyTracker.registerHandler(uniqueRequestTaskIdentifier, 'sfap-request', () => fetchComplete);
4584
+ markStart('transport', 'request', {
4585
+ auraXHRId: uniqueRequestTaskIdentifier,
4586
+ requestLength: -1,
4587
+ background: false,
4588
+ actionDefs: ['sfap'],
4589
+ requestId: uniqueRequestGuid,
4590
+ });
4591
+ // --- instrumentation block --- end
4592
+ const fetchNetworkAdapterPromise = fetchNetworkAdapter(authenticatedRequest);
4593
+ // --- instrumentation block --- start
4594
+ fetchNetworkAdapterPromise.finally(function requestCompleteTracker() {
4595
+ ThirdPartyTracker.markLoaded(uniqueRequestTaskIdentifier);
4596
+ fetchComplete = true;
4597
+ markEnd('transport', 'request', {
4598
+ auraXHRId: uniqueRequestTaskIdentifier,
4599
+ });
4600
+ });
4601
+ // --- instrumentation block --- end
4602
+ return fetchNetworkAdapterPromise;
3750
4603
  };
3751
4604
  class LdsNetworkAdapterErrorResponse extends Error {
3752
4605
  constructor(message, _error) {
@@ -3762,6 +4615,17 @@ const composedNetworkAdapter$1 = {
3762
4615
  },
3763
4616
  adapter: sfapNetworkAdapter,
3764
4617
  };
4618
+ function generateRequestId() {
4619
+ if (typeof crypto !== 'undefined' && crypto.randomUUID) {
4620
+ // as nov. 2025 caniuse says this has 93.5% support (all modern browsers)
4621
+ return crypto.randomUUID();
4622
+ }
4623
+ else {
4624
+ // fallback to Math.random() if crypto.randomUUID is not available (unlikely)
4625
+ return (Math.random().toString(36).substring(2, 15) +
4626
+ Math.random().toString(36).substring(2, 15));
4627
+ }
4628
+ }
3765
4629
 
3766
4630
  function e(e){this.message=e;}e.prototype=new Error,e.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function n(e){this.message=e;}n.prototype=new Error,n.prototype.name="InvalidTokenError";
3767
4631
 
@@ -3959,7 +4823,7 @@ function buildPageScopedCacheRequestInterceptor() {
3959
4823
  Object.entries(pageScopedCacheHeaders).forEach(([key, value]) => {
3960
4824
  returnedFetchArgs = setHeader(key, value, returnedFetchArgs);
3961
4825
  });
3962
- return resolvedPromiseLike$3(returnedFetchArgs);
4826
+ return resolvedPromiseLike$2(returnedFetchArgs);
3963
4827
  };
3964
4828
  }
3965
4829
 
@@ -4001,7 +4865,7 @@ function getEnvironmentSetting(name) {
4001
4865
  }
4002
4866
  return undefined;
4003
4867
  }
4004
- // version: 1.400.0-3c7514a502
4868
+ // version: 1.402.0-566b6c5389
4005
4869
 
4006
4870
  /**
4007
4871
  * Observability / Critical Availability Program (230+)
@@ -4051,7 +4915,7 @@ const TOTAL_ADAPTER_REQUEST_SUCCESS_COUNT = {
4051
4915
 
4052
4916
  const { create, keys, hasOwnProperty, entries } = Object;
4053
4917
  const { isArray, from } = Array;
4054
- const { stringify } = JSON;
4918
+ const { stringify: stringify$1 } = JSON;
4055
4919
 
4056
4920
  /**
4057
4921
  * A deterministic JSON stringify implementation. Heavily adapted from https://github.com/epoberezkin/fast-json-stable-stringify.
@@ -4077,7 +4941,7 @@ function stableJSONStringify$1(node) {
4077
4941
  return isFinite(node) ? '' + node : 'null';
4078
4942
  }
4079
4943
  if (typeof node !== 'object') {
4080
- return stringify(node);
4944
+ return stringify$1(node);
4081
4945
  }
4082
4946
  let i;
4083
4947
  let out;
@@ -4108,7 +4972,7 @@ function stableJSONStringify$1(node) {
4108
4972
  if (out) {
4109
4973
  out += ',';
4110
4974
  }
4111
- out += stringify(key) + ':' + value;
4975
+ out += stringify$1(key) + ':' + value;
4112
4976
  }
4113
4977
  return '{' + out + '}';
4114
4978
  }
@@ -4526,7 +5390,7 @@ function setAuraInstrumentationHooks() {
4526
5390
  networkResponse: incrementRequestResponseCount,
4527
5391
  });
4528
5392
  instrument$2({
4529
- error: logError,
5393
+ error: logError$2,
4530
5394
  });
4531
5395
  instrument$3({
4532
5396
  refreshCalled: instrumentation.handleRefreshApiCall.bind(instrumentation),
@@ -4821,28 +5685,217 @@ function buildLuvioPageScopedCacheRequestInterceptor() {
4821
5685
  }
4822
5686
  // Pass the headers to pageScopedCache which will mutate them
4823
5687
  pageScopedCache.addHeader(resourceRequest.headers);
4824
- return resolvedPromiseLike$3(resourceRequest);
5688
+ return resolvedPromiseLike$2(resourceRequest);
4825
5689
  };
4826
5690
  }
4827
5691
 
4828
5692
  const REQUEST_ID_KEY = 'X-SFDC-Request-Id';
4829
5693
  function buildRequestIdInterceptor() {
4830
5694
  return async (fetchArgs) => {
4831
- fetchArgs = setHeader(REQUEST_ID_KEY, generateRequestId(), fetchArgs);
4832
- return resolvedPromiseLike$3(fetchArgs);
5695
+ fetchArgs = setHeader(REQUEST_ID_KEY, generateRequestId$1(), fetchArgs);
5696
+ return resolvedPromiseLike$2(fetchArgs);
5697
+ };
5698
+ }
5699
+ function buildLuvioRequestIdInterceptor() {
5700
+ return (resourceRequest) => {
5701
+ // Ensure headers object exists
5702
+ if (!resourceRequest.headers) {
5703
+ resourceRequest.headers = {};
5704
+ }
5705
+ // Don't overwrite request id header if it already exists
5706
+ if (!resourceRequest.headers[REQUEST_ID_KEY]) {
5707
+ resourceRequest.headers[REQUEST_ID_KEY] = generateRequestId$1();
5708
+ }
5709
+ return resolvedPromiseLike$2(resourceRequest);
5710
+ };
5711
+ }
5712
+
5713
+ const CSRF_TOKEN_KEY = 'salesforce_csrf_token';
5714
+ const CSRF_STORAGE_NAME = 'ldsCSRFToken';
5715
+ const CSRF_STORAGE_CONFIG = {
5716
+ name: CSRF_STORAGE_NAME,
5717
+ persistent: true,
5718
+ secure: true,
5719
+ maxSize: 1024,
5720
+ expiration: 24 * 60 * 60,
5721
+ clearOnInit: false,
5722
+ debugLogging: false,
5723
+ };
5724
+ /**
5725
+ * Manages CSRF token fetching and caching for secure requests.
5726
+ * Implements a singleton pattern to ensure consistent token management across the application.
5727
+ */
5728
+ class CsrfTokenManager {
5729
+ constructor() {
5730
+ // Initialize AuraStorage
5731
+ this.storage = createStorage(CSRF_STORAGE_CONFIG);
5732
+ // Try to load token from AuraStorage on initialization
5733
+ this.tokenPromise = this.loadOrFetchToken();
5734
+ }
5735
+ static getInstance() {
5736
+ if (!CsrfTokenManager.instance) {
5737
+ CsrfTokenManager.instance = new CsrfTokenManager();
5738
+ }
5739
+ return CsrfTokenManager.instance;
5740
+ }
5741
+ /**
5742
+ * Obtain a CSRF token, either from AuraStorage or by fetching a fresh one.
5743
+ *
5744
+ * @private
5745
+ */
5746
+ async loadOrFetchToken() {
5747
+ // First try to get token from AuraStorage
5748
+ if (this.storage) {
5749
+ try {
5750
+ const cachedToken = await this.storage.get(CSRF_TOKEN_KEY);
5751
+ if (typeof cachedToken === 'string' && cachedToken) {
5752
+ return cachedToken;
5753
+ }
5754
+ }
5755
+ catch {
5756
+ // If storage read fails, continue to fetch
5757
+ }
5758
+ }
5759
+ // No cached token, fetch from server
5760
+ return this.fetchFreshToken();
5761
+ }
5762
+ /**
5763
+ * Call API endpoint to acquire a CSRF token and cache it.
5764
+ *
5765
+ * @private
5766
+ */
5767
+ async fetchFreshToken() {
5768
+ try {
5769
+ const response = await fetch('/session/csrf', {
5770
+ method: 'GET',
5771
+ credentials: 'same-origin',
5772
+ });
5773
+ if (!response.ok) {
5774
+ return undefined;
5775
+ }
5776
+ const data = await response.json();
5777
+ const token = data.csrfToken;
5778
+ if (token && this.storage) {
5779
+ // Cache the token in AuraStorage
5780
+ try {
5781
+ await this.storage.set(CSRF_TOKEN_KEY, token);
5782
+ }
5783
+ catch {
5784
+ // Non-fatal: token is still available even if caching fails
5785
+ }
5786
+ }
5787
+ return token;
5788
+ }
5789
+ catch {
5790
+ return undefined;
5791
+ }
5792
+ }
5793
+ /**
5794
+ * Returns the current token value as a Promise.
5795
+ */
5796
+ async getToken() {
5797
+ return this.tokenPromise;
5798
+ }
5799
+ /**
5800
+ * Obtains and returns a new token value as a promise.
5801
+ * This will clear the cached token and fetch a fresh one.
5802
+ */
5803
+ async refreshToken() {
5804
+ // Clear cached token
5805
+ if (this.storage) {
5806
+ try {
5807
+ await this.storage.remove(CSRF_TOKEN_KEY);
5808
+ }
5809
+ catch {
5810
+ // Non-fatal: continue with refresh even if clear fails
5811
+ }
5812
+ }
5813
+ // Fetch (and cache) fresh token
5814
+ this.tokenPromise = this.fetchFreshToken();
5815
+ return this.tokenPromise;
5816
+ }
5817
+ /**
5818
+ * Reset the singleton instance (useful for testing).
5819
+ * @internal
5820
+ */
5821
+ static resetInstance() {
5822
+ CsrfTokenManager.instance = null;
5823
+ }
5824
+ }
5825
+ CsrfTokenManager.instance = null;
5826
+
5827
+ const CSRF_TOKEN_HEADER = 'X-CSRF-Token';
5828
+ /**
5829
+ * Determines if the HTTP method requires CSRF protection.
5830
+ * Only mutating operations (POST, PUT, PATCH, DELETE) require CSRF tokens.
5831
+ *
5832
+ * @param method - The HTTP method to check
5833
+ * @returns true if the method requires CSRF protection
5834
+ */
5835
+ function isCsrfMethod(method) {
5836
+ if (!method) {
5837
+ return false;
5838
+ }
5839
+ const normalizedMethod = method.toLowerCase();
5840
+ return (normalizedMethod === 'post' ||
5841
+ normalizedMethod === 'put' ||
5842
+ normalizedMethod === 'patch' ||
5843
+ normalizedMethod === 'delete');
5844
+ }
5845
+ /**
5846
+ * Builds a request interceptor that adds CSRF token headers to mutating requests.
5847
+ * The CSRF token is fetched once and cached for subsequent requests.
5848
+ * Only POST, PUT, PATCH, and DELETE requests will have the CSRF token added.
5849
+ *
5850
+ * @returns A RequestInterceptor function for FetchParameters
5851
+ */
5852
+ function buildCsrfTokenInterceptor() {
5853
+ const csrfTokenManager = CsrfTokenManager.getInstance();
5854
+ return async (fetchArgs) => {
5855
+ const [urlOrRequest, options] = fetchArgs;
5856
+ // Determine the method from either Request object or options
5857
+ let method;
5858
+ if (typeof urlOrRequest !== 'string' && 'method' in urlOrRequest) {
5859
+ method = urlOrRequest.method;
5860
+ }
5861
+ else if (options && 'method' in options) {
5862
+ method = options.method;
5863
+ }
5864
+ // Only add CSRF token for mutating operations
5865
+ if (isCsrfMethod(method)) {
5866
+ const token = await csrfTokenManager.getToken();
5867
+ if (token) {
5868
+ fetchArgs = setHeader(CSRF_TOKEN_HEADER, token, fetchArgs);
5869
+ }
5870
+ }
5871
+ return resolvedPromiseLike$2(fetchArgs);
4833
5872
  };
4834
5873
  }
4835
- function buildLuvioRequestIdInterceptor() {
4836
- return (resourceRequest) => {
5874
+ /**
5875
+ * Builds a Luvio request interceptor that adds CSRF token headers to mutating requests.
5876
+ * The CSRF token is fetched once and cached for subsequent requests.
5877
+ * Only POST, PUT, PATCH, and DELETE requests will have the CSRF token added.
5878
+ *
5879
+ * @returns A request interceptor function for Luvio ResourceRequest objects
5880
+ */
5881
+ function buildLuvioCsrfTokenInterceptor() {
5882
+ const csrfTokenManager = CsrfTokenManager.getInstance();
5883
+ return async (resourceRequest) => {
4837
5884
  // Ensure headers object exists
4838
5885
  if (!resourceRequest.headers) {
4839
5886
  resourceRequest.headers = {};
4840
5887
  }
4841
- // Don't overwrite request id header if it already exists
4842
- if (!resourceRequest.headers[REQUEST_ID_KEY]) {
4843
- resourceRequest.headers[REQUEST_ID_KEY] = generateRequestId();
5888
+ // Only add CSRF token for mutating operations
5889
+ if (isCsrfMethod(resourceRequest.method)) {
5890
+ // Don't overwrite existing CSRF token header if it already exists
5891
+ if (!resourceRequest.headers[CSRF_TOKEN_HEADER]) {
5892
+ const token = await csrfTokenManager.getToken();
5893
+ if (token) {
5894
+ resourceRequest.headers[CSRF_TOKEN_HEADER] = token;
5895
+ }
5896
+ }
4844
5897
  }
4845
- return resolvedPromiseLike$3(resourceRequest);
5898
+ return resolvedPromiseLike$2(resourceRequest);
4846
5899
  };
4847
5900
  }
4848
5901
 
@@ -4907,7 +5960,11 @@ const composedFetchNetworkAdapter = {
4907
5960
  return API_PATH_MATCHERS.some((matcher) => matcher.test(path));
4908
5961
  },
4909
5962
  adapter: setupLexNetworkAdapter(requestTracker, requestLogger, {
4910
- request: [buildLuvioPageScopedCacheRequestInterceptor(), buildLuvioRequestIdInterceptor()],
5963
+ request: [
5964
+ buildLuvioPageScopedCacheRequestInterceptor(),
5965
+ buildLuvioRequestIdInterceptor(),
5966
+ buildLuvioCsrfTokenInterceptor(),
5967
+ ],
4911
5968
  response: [
4912
5969
  buildLexRuntimeLuvio5xxStatusResponseInterceptor(),
4913
5970
  buildLexRuntimeLuvioAuthExpirationRedirectResponseInterceptor(),
@@ -4915,9 +5972,114 @@ const composedFetchNetworkAdapter = {
4915
5972
  }),
4916
5973
  };
4917
5974
 
5975
+ const DEFAULT_CONFIG$1 = {
5976
+ maxRetries: 1, // Only retry once after token refresh
5977
+ };
5978
+ /**
5979
+ * Retry policy that handles CSRF token expiration errors.
5980
+ *
5981
+ * When a request fails with a CSRF token error this policy will:
5982
+ * 1. Detect the error condition in shouldRetry
5983
+ * 2. Refresh the CSRF token in prepareRetry hook
5984
+ * 3. Update the request headers with the new token via mutable context
5985
+ * 4. Retry the request once (maxRetries = 1)
5986
+ *
5987
+ */
5988
+ class CsrfTokenRetryPolicy extends RetryPolicy {
5989
+ constructor(config = DEFAULT_CONFIG$1) {
5990
+ super();
5991
+ this.config = config;
5992
+ this.csrfTokenManager = CsrfTokenManager.getInstance();
5993
+ }
5994
+ /**
5995
+ * Allows the fetch service to pass mutable request context.
5996
+ * This is a side-channel that enables request modification between retries.
5997
+ *
5998
+ * @param context - Mutable container holding fetch arguments
5999
+ */
6000
+ setRequestContext(context) {
6001
+ this.requestContext = context;
6002
+ }
6003
+ /**
6004
+ * Determines if a failed request should be retried due to CSRF token issues.
6005
+ */
6006
+ async shouldRetry(result, context) {
6007
+ // Only retry once
6008
+ if (context.attempt >= this.config.maxRetries) {
6009
+ return false;
6010
+ }
6011
+ // Only retry on 400 status
6012
+ if (result.status !== 400) {
6013
+ return false;
6014
+ }
6015
+ // Check if this is a CSRF error by examining the response body
6016
+ // This avoids retrying all 400s (validation errors, bad requests, etc.)
6017
+ return await isCsrfError(result);
6018
+ }
6019
+ /**
6020
+ * CSRF token refresh should happen immediately with no delay.
6021
+ */
6022
+ async calculateDelay(_result, _context) {
6023
+ return 0; // No delay - retry immediately after token refresh
6024
+ }
6025
+ /**
6026
+ * Called by retry service before each retry attempt.
6027
+ *
6028
+ * This hook is supported by the Conduit retry service (with prepareRetry support).
6029
+ * It performs token refresh and request update:
6030
+ * 1. Refreshes the CSRF token from the server
6031
+ * 2. Updates the mutable request context with the new token
6032
+ *
6033
+ * Note: We already validated this is a CSRF error in shouldRetry,
6034
+ * so we can proceed directly to token refresh.
6035
+ *
6036
+ * The fetch service must call setRequestContext() to provide the mutable args container.
6037
+ * When the retry service re-executes the operation, it will use the updated args.
6038
+ *
6039
+ * @param _result - The failed response that triggered the retry (unused, already validated)
6040
+ * @param _context - Current retry context (unused but part of interface)
6041
+ */
6042
+ async prepareRetry(_result, _context) {
6043
+ // Refresh the CSRF token (we already know this is a CSRF error from shouldRetry)
6044
+ const newToken = await this.csrfTokenManager.refreshToken();
6045
+ if (!newToken || !this.requestContext) {
6046
+ // If we can't get a new token or don't have request context,
6047
+ // the retry will fail again but that's expected
6048
+ return;
6049
+ }
6050
+ // Update the fetch arguments with the new token using the setHeader utility
6051
+ this.requestContext.args = setHeader('X-CSRF-Token', newToken, this.requestContext.args);
6052
+ }
6053
+ }
6054
+ /**
6055
+ * Helper to check if a response indicates a CSRF token error.
6056
+ *
6057
+ * @param response - The response to check
6058
+ * @returns true if the response indicates a CSRF token error (INVALID_ACCESS_TOKEN)
6059
+ */
6060
+ async function isCsrfError(response) {
6061
+ try {
6062
+ // Clone to avoid consuming the original response
6063
+ const cloned = response.clone();
6064
+ const body = await cloned.json();
6065
+ // Check the error array format: data[0].errorCode
6066
+ const errorCode = body?.data?.[0]?.errorCode;
6067
+ return errorCode === 'INVALID_ACCESS_TOKEN';
6068
+ }
6069
+ catch {
6070
+ // If we can't parse the body (network error, non-JSON response, etc.),
6071
+ // assume it's not a CSRF error
6072
+ return false;
6073
+ }
6074
+ }
6075
+
4918
6076
  function buildLexRuntimeDefaultFetchServiceDescriptor(logger, retryService) {
4919
6077
  const fetchService = buildLexConnectFetchServiceDescriptor({
4920
- request: [buildPageScopedCacheRequestInterceptor(), buildRequestIdInterceptor()],
6078
+ request: [
6079
+ buildPageScopedCacheRequestInterceptor(),
6080
+ buildRequestIdInterceptor(),
6081
+ buildCsrfTokenInterceptor(),
6082
+ ],
4921
6083
  response: [
4922
6084
  buildLexRuntime5xxStatusResponseInterceptor(logger),
4923
6085
  buildLexRuntimeAuthExpirationRedirectResponseInterceptor(logger),
@@ -4929,7 +6091,11 @@ function buildLexRuntimeDefaultFetchServiceDescriptor(logger, retryService) {
4929
6091
  }
4930
6092
  function buildLexRuntimeAllow5xxFetchServiceDescriptor(logger, retryService) {
4931
6093
  const fetchService = buildLexConnectFetchServiceDescriptor({
4932
- request: [buildPageScopedCacheRequestInterceptor(), buildRequestIdInterceptor()],
6094
+ request: [
6095
+ buildPageScopedCacheRequestInterceptor(),
6096
+ buildRequestIdInterceptor(),
6097
+ buildCsrfTokenInterceptor(),
6098
+ ],
4933
6099
  response: [buildLexRuntimeAuthExpirationRedirectResponseInterceptor(logger)],
4934
6100
  }, retryService);
4935
6101
  return {
@@ -4943,21 +6109,39 @@ function buildLexConnectFetchServiceDescriptor(interceptors = { request: [], res
4943
6109
  version: '1.0',
4944
6110
  service: function (...args) {
4945
6111
  const { request: requestInterceptors = [], response: responseInterceptors = [] } = interceptors;
4946
- const pending = requestInterceptors.reduce((previousPromise, interceptor) => previousPromise.then(interceptor), resolvedPromiseLike$3(args));
4947
- const trackerId = generateRequestId();
6112
+ const pending = requestInterceptors.reduce((previousPromise, interceptor) => previousPromise.then(interceptor), resolvedPromiseLike$2(args));
6113
+ const trackerId = generateRequestId$1();
4948
6114
  instrumentationTracker.registerHandler(trackerId, 'onestore-inflight-network-request', () => {
4949
6115
  // return false until we signal we are finished
4950
6116
  return false;
4951
6117
  });
4952
6118
  return Promise.resolve(pending)
4953
- .then((args) => {
6119
+ .then((interceptedArgs) => {
4954
6120
  if (retryService) {
4955
- return retryService.applyRetry(() => fetch(...args));
6121
+ // Create mutable context for CSRF retry policy
6122
+ const mutableRequest = { args: interceptedArgs };
6123
+ // Pass context to CSRF policy if it's being used
6124
+ const policy = retryService.defaultRetryPolicy;
6125
+ // Handle both direct CSRF policy and composed policy
6126
+ if (policy instanceof CsrfTokenRetryPolicy) {
6127
+ policy.setRequestContext(mutableRequest);
6128
+ }
6129
+ else if (policy instanceof ComposedRetryPolicy) {
6130
+ // Extract CSRF policy from composed policy
6131
+ const csrfPolicy = policy.getPolicyByType(CsrfTokenRetryPolicy);
6132
+ if (csrfPolicy) {
6133
+ csrfPolicy.setRequestContext(mutableRequest);
6134
+ }
6135
+ }
6136
+ // Retry service will call prepareRetry hook which updates mutableRequest.args
6137
+ return retryService.applyRetry(async () => {
6138
+ return await fetch(...mutableRequest.args);
6139
+ });
4956
6140
  }
4957
- return fetch(...args);
6141
+ return fetch(...interceptedArgs);
4958
6142
  })
4959
6143
  .then((response) => {
4960
- return responseInterceptors.reduce((previousPromise, interceptor) => previousPromise.then(interceptor), resolvedPromiseLike$3(response));
6144
+ return responseInterceptors.reduce((previousPromise, interceptor) => previousPromise.then(interceptor), resolvedPromiseLike$2(response));
4961
6145
  })
4962
6146
  .finally(() => {
4963
6147
  instrumentationTracker.markFinished(trackerId);
@@ -5003,9 +6187,9 @@ function buildCopilotFetchServiceDescriptor(logger) {
5003
6187
  requestInit.method !== 'POST' ||
5004
6188
  !requestInit.body ||
5005
6189
  typeof requestInit.body !== 'string') {
5006
- return resolvedPromiseLike$3(args);
6190
+ return resolvedPromiseLike$2(args);
5007
6191
  }
5008
- return resolvedPromiseLike$3(sfapJwtManager.getJwt()).then((token) => {
6192
+ return resolvedPromiseLike$2(sfapJwtManager.getJwt()).then((token) => {
5009
6193
  // replace the body's instanceConfig.endpoint with the JWT's iss value
5010
6194
  const body = JSON.parse(requestInit.body);
5011
6195
  if (!body || !token.decodedInfo || !token.decodedInfo.iss) {
@@ -6001,7 +7185,7 @@ function stableJSONStringify(node) {
6001
7185
  return isFinite(node) ? '' + node : 'null';
6002
7186
  }
6003
7187
  if (typeof node !== 'object') {
6004
- return stringify(node);
7188
+ return stringify$1(node);
6005
7189
  }
6006
7190
  let i;
6007
7191
  let out;
@@ -6029,7 +7213,7 @@ function stableJSONStringify(node) {
6029
7213
  if (out) {
6030
7214
  out += ',';
6031
7215
  }
6032
- out += stringify(key) + ':' + value;
7216
+ out += stringify$1(key) + ':' + value;
6033
7217
  }
6034
7218
  return '{' + out + '}';
6035
7219
  }
@@ -7295,50 +8479,356 @@ class Ok {
7295
8479
  constructor(value) {
7296
8480
  this.value = value;
7297
8481
  }
7298
- isOk() {
7299
- return true;
8482
+ isOk() {
8483
+ return true;
8484
+ }
8485
+ isErr() {
8486
+ return !this.isOk();
8487
+ }
8488
+ }
8489
+ const ok = (value) => new Ok(value);
8490
+ function setDifference(setA, setB) {
8491
+ const differenceSet = /* @__PURE__ */ new Set();
8492
+ for (const element of setA) {
8493
+ if (!setB.has(element)) {
8494
+ differenceSet.add(element);
8495
+ }
8496
+ }
8497
+ return differenceSet;
8498
+ }
8499
+ function resolvedPromiseLike(result) {
8500
+ if (isPromiseLike(result)) {
8501
+ return result.then((nextResult) => nextResult);
8502
+ }
8503
+ return {
8504
+ then: (onFulfilled, _onRejected) => {
8505
+ try {
8506
+ return resolvedPromiseLike(onFulfilled(result));
8507
+ } catch (e) {
8508
+ if (onFulfilled === void 0) {
8509
+ return resolvedPromiseLike(result);
8510
+ }
8511
+ return rejectedPromiseLike(e);
8512
+ }
8513
+ }
8514
+ };
8515
+ }
8516
+ function rejectedPromiseLike(reason) {
8517
+ if (isPromiseLike(reason)) {
8518
+ return reason.then((nextResult) => nextResult);
8519
+ }
8520
+ return {
8521
+ then: (_onFulfilled, onRejected) => {
8522
+ if (typeof onRejected === "function") {
8523
+ try {
8524
+ return resolvedPromiseLike(onRejected(reason));
8525
+ } catch (e) {
8526
+ return rejectedPromiseLike(e);
8527
+ }
8528
+ }
8529
+ return rejectedPromiseLike(reason);
8530
+ }
8531
+ };
8532
+ }
8533
+ function isPromiseLike(x) {
8534
+ return typeof (x == null ? void 0 : x.then) === "function";
8535
+ }
8536
+ /*!
8537
+ * Copyright (c) 2022, Salesforce, Inc.,
8538
+ * All rights reserved.
8539
+ * For full license text, see the LICENSE.txt file
8540
+ */
8541
+ /*!
8542
+ * Copyright (c) 2022, Salesforce, Inc.,
8543
+ * All rights reserved.
8544
+ * For full license text, see the LICENSE.txt file
8545
+ */
8546
+ const { stringify, parse } = JSON;
8547
+ function deepCopy(x) {
8548
+ const stringified = stringify(x);
8549
+ return stringified ? parse(stringified) : void 0;
8550
+ }
8551
+ class DefaultRecordableCache {
8552
+ constructor(baseCache) {
8553
+ this.baseCache = baseCache;
8554
+ this.keysRead = /* @__PURE__ */ new Set();
8555
+ this.missingKeysRead = /* @__PURE__ */ new Set();
8556
+ this.keysUpdated = /* @__PURE__ */ new Set();
8557
+ this.metadataKeysUpdated = /* @__PURE__ */ new Set();
8558
+ }
8559
+ delete(key) {
8560
+ this.keysUpdated.add(key);
8561
+ this.baseCache.delete(key);
8562
+ }
8563
+ get(key, options) {
8564
+ this.keysRead.add(key);
8565
+ const value = this.baseCache.get(key);
8566
+ if (value === void 0) {
8567
+ this.missingKeysRead.add(key);
8568
+ }
8569
+ if (options == null ? void 0 : options.copy) {
8570
+ return deepCopy(value);
8571
+ }
8572
+ return value;
8573
+ }
8574
+ set(key, value) {
8575
+ this.keysUpdated.add(key);
8576
+ this.metadataKeysUpdated.add(key);
8577
+ this.baseCache.set(key, value);
8578
+ }
8579
+ setMetadata(key, cacheControlMetadata) {
8580
+ this.metadataKeysUpdated.add(key);
8581
+ this.baseCache.setMetadata(key, cacheControlMetadata);
8582
+ }
8583
+ length() {
8584
+ return this.baseCache.length();
8585
+ }
8586
+ keys() {
8587
+ return this.baseCache.keys();
8588
+ }
8589
+ entries() {
8590
+ return this.baseCache.entries();
8591
+ }
8592
+ record() {
8593
+ return new DefaultRecordableCache(this);
8594
+ }
8595
+ filter(predicate) {
8596
+ return new DefaultFilteredCache(this, predicate);
8597
+ }
8598
+ buildFixedTimeWritableCache(generatedTime) {
8599
+ return new FixedTimeWritableCache(this, generatedTime);
8600
+ }
8601
+ }
8602
+ class DefaultFilteredCache {
8603
+ constructor(baseCache, predicate) {
8604
+ this.baseCache = baseCache;
8605
+ this.predicate = predicate;
8606
+ }
8607
+ delete(key) {
8608
+ this.baseCache.delete(key);
8609
+ }
8610
+ get(key, options) {
8611
+ const result = this.baseCache.get(key);
8612
+ if (result && this.predicate(key, result)) {
8613
+ if (options == null ? void 0 : options.copy) {
8614
+ return deepCopy(result);
8615
+ }
8616
+ return result;
8617
+ }
8618
+ return void 0;
8619
+ }
8620
+ set(key, value) {
8621
+ this.baseCache.set(key, value);
8622
+ }
8623
+ setMetadata(key, cacheControlMetadata) {
8624
+ this.baseCache.setMetadata(key, cacheControlMetadata);
8625
+ }
8626
+ length() {
8627
+ return this.getFilteredKeys().size;
8628
+ }
8629
+ keys() {
8630
+ return this.getFilteredKeys();
8631
+ }
8632
+ entries() {
8633
+ return this.getFilteredEntries();
8634
+ }
8635
+ record() {
8636
+ return new DefaultRecordableCache(this);
8637
+ }
8638
+ filter(predicate) {
8639
+ return new DefaultFilteredCache(this, predicate);
8640
+ }
8641
+ getFilteredEntries() {
8642
+ return this.baseCache.entries().filter(([key, _value]) => {
8643
+ return this.get(key);
8644
+ });
8645
+ }
8646
+ getFilteredKeys() {
8647
+ const filteredKeySet = /* @__PURE__ */ new Set();
8648
+ this.baseCache.keys().forEach((key) => {
8649
+ if (this.get(key)) {
8650
+ filteredKeySet.add(key);
8651
+ }
8652
+ });
8653
+ return filteredKeySet;
8654
+ }
8655
+ buildFixedTimeWritableCache(generatedTime) {
8656
+ return new FixedTimeWritableCache(this, generatedTime);
8657
+ }
8658
+ }
8659
+ class FixedTimeWritableCache {
8660
+ constructor(baseCache, generatedTime) {
8661
+ this.baseCache = baseCache;
8662
+ this.generatedTime = generatedTime;
8663
+ }
8664
+ delete(key) {
8665
+ this.baseCache.delete(key);
8666
+ }
8667
+ get(key, options) {
8668
+ return this.baseCache.get(key, options);
8669
+ }
8670
+ set(key, value) {
8671
+ this.baseCache.set(key, {
8672
+ ...value,
8673
+ metadata: {
8674
+ ...value.metadata,
8675
+ cacheControl: { ...value.metadata.cacheControl, generatedTime: this.generatedTime }
8676
+ }
8677
+ });
8678
+ }
8679
+ setMetadata(key, cacheControlMetadata) {
8680
+ this.baseCache.setMetadata(key, {
8681
+ ...cacheControlMetadata,
8682
+ generatedTime: this.generatedTime
8683
+ });
8684
+ }
8685
+ length() {
8686
+ return this.baseCache.length();
7300
8687
  }
7301
- isErr() {
7302
- return !this.isOk();
8688
+ keys() {
8689
+ return this.baseCache.keys();
8690
+ }
8691
+ entries() {
8692
+ return this.baseCache.entries();
8693
+ }
8694
+ record() {
8695
+ return new DefaultRecordableCache(this);
8696
+ }
8697
+ filter(predicate) {
8698
+ return new DefaultFilteredCache(this, predicate);
8699
+ }
8700
+ buildFixedTimeWritableCache(generatedTime) {
8701
+ return new FixedTimeWritableCache(this, generatedTime);
7303
8702
  }
7304
8703
  }
7305
- const ok = (value) => new Ok(value);
7306
- function resolvedPromiseLike(result) {
7307
- if (isPromiseLike(result)) {
7308
- return result.then((nextResult) => nextResult);
8704
+ class DefaultCache {
8705
+ constructor() {
8706
+ this.data = {};
7309
8707
  }
7310
- return {
7311
- then: (onFulfilled, _onRejected) => {
7312
- try {
7313
- return resolvedPromiseLike(onFulfilled(result));
7314
- } catch (e) {
7315
- if (onFulfilled === void 0) {
7316
- return resolvedPromiseLike(result);
7317
- }
7318
- return rejectedPromiseLike(e);
7319
- }
8708
+ get(key, options) {
8709
+ if (options == null ? void 0 : options.copy) {
8710
+ return deepCopy(this.data[key]);
7320
8711
  }
7321
- };
7322
- }
7323
- function rejectedPromiseLike(reason) {
7324
- if (isPromiseLike(reason)) {
7325
- return reason.then((nextResult) => nextResult);
8712
+ return this.data[key];
7326
8713
  }
7327
- return {
7328
- then: (_onFulfilled, onRejected) => {
7329
- if (typeof onRejected === "function") {
7330
- try {
7331
- return resolvedPromiseLike(onRejected(reason));
7332
- } catch (e) {
7333
- return rejectedPromiseLike(e);
8714
+ /**
8715
+ * Adds the specified key/value to the cache.
8716
+ *
8717
+ * @param key key at which to store value
8718
+ * @param entry value to be stored
8719
+ */
8720
+ set(key, entry) {
8721
+ if (entry.metadata.cacheControl.type === "no-store") {
8722
+ return;
8723
+ }
8724
+ this.data[key] = {
8725
+ ...entry,
8726
+ metadata: {
8727
+ ...entry.metadata,
8728
+ type: entry.metadata.type || {
8729
+ namespace: "OneStore:Internal",
8730
+ name: "UnknownType"
8731
+ },
8732
+ cacheControl: {
8733
+ generatedTime: Date.now() / 1e3,
8734
+ ...entry.metadata.cacheControl
7334
8735
  }
7335
8736
  }
7336
- return rejectedPromiseLike(reason);
8737
+ };
8738
+ }
8739
+ /**
8740
+ * Removes the cache entry associated with the specified key.
8741
+ *
8742
+ * @param key key to be removed from the store
8743
+ */
8744
+ delete(key) {
8745
+ delete this.data[key];
8746
+ }
8747
+ /**
8748
+ * Sets the metadata for the specified key if the key is in cache.
8749
+ * If the key doesn't exist, it does nothing.
8750
+ *
8751
+ * @param key key at which to store metadata
8752
+ * @param cacheControlMetadata metadata to be stored
8753
+ */
8754
+ setMetadata(key, cacheControlMetadata) {
8755
+ if (key in this.data) {
8756
+ this.data[key].metadata.cacheControl = {
8757
+ generatedTime: Date.now() / 1e3,
8758
+ ...cacheControlMetadata
8759
+ };
7337
8760
  }
8761
+ }
8762
+ length() {
8763
+ return this.keys().size;
8764
+ }
8765
+ keys() {
8766
+ return new Set(Object.keys(this.data));
8767
+ }
8768
+ entries() {
8769
+ return Object.entries(this.data);
8770
+ }
8771
+ record() {
8772
+ return new DefaultRecordableCache(this);
8773
+ }
8774
+ filter(predicate) {
8775
+ return new DefaultFilteredCache(this, predicate);
8776
+ }
8777
+ buildFixedTimeWritableCache(generatedTime) {
8778
+ return new FixedTimeWritableCache(this, generatedTime);
8779
+ }
8780
+ }
8781
+ function buildServiceDescriptor() {
8782
+ return {
8783
+ type: "cache",
8784
+ version: "1.0",
8785
+ service: new DefaultCache()
7338
8786
  };
7339
8787
  }
7340
- function isPromiseLike(x) {
7341
- return typeof (x == null ? void 0 : x.then) === "function";
8788
+ class DurableCacheInclusionPolicy extends CacheInclusionPolicyService {
8789
+ /**
8790
+ * Reads data out of a 2 level inclusive store.
8791
+ */
8792
+ read(options) {
8793
+ const { l1, readFromL1, alreadyRevivedKeys } = options;
8794
+ const recordableCache = l1.record();
8795
+ return readFromL1(recordableCache).then((readResult) => {
8796
+ if (readResult.isOk()) {
8797
+ return readResult;
8798
+ }
8799
+ const keysToRevive = recordableCache.keysRead;
8800
+ if (alreadyRevivedKeys && setDifference(keysToRevive, alreadyRevivedKeys).size === 0) {
8801
+ return readResult;
8802
+ }
8803
+ return this.revive(keysToRevive, l1).then((revivedKeys) => {
8804
+ if (setDifference(keysToRevive, revivedKeys).size > 0) {
8805
+ return readResult;
8806
+ }
8807
+ return this.read({ l1, readFromL1, alreadyRevivedKeys: revivedKeys });
8808
+ });
8809
+ });
8810
+ }
8811
+ /**
8812
+ * Writes data to a 2 level inclusive store.
8813
+ */
8814
+ write(options) {
8815
+ const { l1, writeToL1 } = options;
8816
+ const tempL1 = buildServiceDescriptor().service.record();
8817
+ return writeToL1(tempL1).then(() => {
8818
+ const keysToReviveRecordableCache = l1.record();
8819
+ tempL1.keysUpdated.forEach((key) => keysToReviveRecordableCache.get(key));
8820
+ tempL1.missingKeysRead.forEach((key) => keysToReviveRecordableCache.get(key));
8821
+ const missingKeys = keysToReviveRecordableCache.missingKeysRead;
8822
+ const revivePromiseLike = missingKeys.size > 0 ? this.revive(missingKeys, l1).then(() => void 0) : resolvedPromiseLike(void 0);
8823
+ return revivePromiseLike.then(() => {
8824
+ const recordableCache = l1.record();
8825
+ return writeToL1(recordableCache).then((result) => {
8826
+ this.syncToL2Cache(recordableCache.keysUpdated, l1);
8827
+ return result;
8828
+ });
8829
+ });
8830
+ });
8831
+ }
7342
8832
  }
7343
8833
  const isAndQuery = (query) => "$and" in query;
7344
8834
  const isOrQuery = (query) => "$or" in query;
@@ -7479,12 +8969,12 @@ class FetchThrottlingRetryPolicy extends RetryPolicy {
7479
8969
  super();
7480
8970
  this.config = config;
7481
8971
  }
7482
- shouldRetry(result, context) {
8972
+ async shouldRetry(result, context) {
7483
8973
  return ((result.status === 429 || result.status === 503) &&
7484
8974
  context.attempt < this.config.maxRetries &&
7485
8975
  context.totalElapsedMs <= this.config.maxTimeToRetry);
7486
8976
  }
7487
- calculateDelay(result, context) {
8977
+ async calculateDelay(result, context) {
7488
8978
  let delay;
7489
8979
  // If retry-after header is present and valid, use it
7490
8980
  const retryAfterHeader = this.parseRetryAfterHeader(result);
@@ -7533,6 +9023,314 @@ class FetchThrottlingRetryPolicy extends RetryPolicy {
7533
9023
  }
7534
9024
  }
7535
9025
 
9026
+ /**
9027
+ * Default storage configuration for the durable cache
9028
+ */
9029
+ const DEFAULT_STORAGE_CONFIG = {
9030
+ name: 'ldsDurableCache',
9031
+ persistent: true,
9032
+ secure: true,
9033
+ maxSize: 10 * 1024 * 1024,
9034
+ expiration: 30 * 24 * 60 * 60,
9035
+ clearOnInit: false,
9036
+ debugLogging: false,
9037
+ };
9038
+ /**
9039
+ * Durable cache inclusion policy that uses AuraStorage for persistent L2 cache
9040
+ */
9041
+ class AuraDurableCacheInclusionPolicy extends DurableCacheInclusionPolicy {
9042
+ constructor(config = {}) {
9043
+ super();
9044
+ // Create storage with merged configuration
9045
+ const storageConfig = {
9046
+ ...DEFAULT_STORAGE_CONFIG,
9047
+ ...config,
9048
+ };
9049
+ this.storage = createStorage(storageConfig);
9050
+ if (!this.storage) {
9051
+ console.warn('Failed to create durable storage for cache inclusion policy');
9052
+ }
9053
+ }
9054
+ /**
9055
+ * Revive cache entries from AuraStorage into L1 cache
9056
+ * @param keys - Set of keys to revive
9057
+ * @param l1 - L1 cache instance
9058
+ * @returns Set of keys that were successfully revived
9059
+ */
9060
+ async revive(keys, l1) {
9061
+ if (keys.size === 0 || !this.storage) {
9062
+ return new Set();
9063
+ }
9064
+ const revivedKeys = new Set();
9065
+ try {
9066
+ // Convert keys to array of strings for getAll()
9067
+ const keysArray = Array.from(keys).map((key) => key);
9068
+ // Get only the requested entries using getAll() with specific keys
9069
+ const storedData = (await this.storage.getAll(keysArray));
9070
+ // Process the retrieved cache entries
9071
+ for (const [storageKey, storedEntry] of Object.entries(storedData)) {
9072
+ const key = storageKey;
9073
+ const entry = storedEntry;
9074
+ if (entry) {
9075
+ l1.set(key, entry);
9076
+ revivedKeys.add(key);
9077
+ }
9078
+ }
9079
+ }
9080
+ catch (error) {
9081
+ // Log error but don't fail the operation
9082
+ console.warn('Failed to revive cache entries from AuraStorage:', error);
9083
+ }
9084
+ return revivedKeys;
9085
+ }
9086
+ /**
9087
+ * Sync changed keys from L1 cache to AuraStorage (L2 cache)
9088
+ * @param changedKeys - Set of keys that have changed
9089
+ * @param l1 - L1 cache instance
9090
+ */
9091
+ async syncToL2Cache(changedKeys, l1) {
9092
+ if (changedKeys.size === 0 || !this.storage) {
9093
+ return;
9094
+ }
9095
+ const promises = [];
9096
+ for (const key of changedKeys) {
9097
+ const storageKey = key;
9098
+ const entry = l1.get(key);
9099
+ if (entry) {
9100
+ // Add or update the entry
9101
+ promises.push(this.storage.set(storageKey, entry).catch((error) => {
9102
+ console.warn(`Failed to persist cache entry: ${storageKey}`, error);
9103
+ }));
9104
+ }
9105
+ else {
9106
+ // Remove the entry if it doesn't exist in L1
9107
+ promises.push(this.storage
9108
+ .remove(storageKey)
9109
+ .catch((error) => {
9110
+ console.warn(`Failed to remove cache entry: ${storageKey}`, error);
9111
+ })
9112
+ .then(() => { }));
9113
+ }
9114
+ }
9115
+ await Promise.all(promises);
9116
+ }
9117
+ /**
9118
+ * Find entries matching a query
9119
+ * @param query - Cache query to match entries
9120
+ */
9121
+ async *find(query) {
9122
+ if (!this.storage) {
9123
+ return;
9124
+ }
9125
+ try {
9126
+ // Need to get all entries to search through them with the query
9127
+ // Cannot pass specific keys since we don't know which entries match the query
9128
+ const allStoredData = (await this.storage.getAll());
9129
+ // Iterate through all cache entries and yield those matching the query
9130
+ for (const [storageKey, storedEntry] of Object.entries(allStoredData)) {
9131
+ const entry = storedEntry;
9132
+ const key = storageKey;
9133
+ if (entry && this.matchesQuery(key, entry, query)) {
9134
+ yield [key, entry];
9135
+ }
9136
+ }
9137
+ }
9138
+ catch (error) {
9139
+ console.warn('Failed to find cache entries in AuraStorage:', error);
9140
+ }
9141
+ }
9142
+ /**
9143
+ * Find and modify entries matching a query
9144
+ * @param query - Cache query to match entries
9145
+ * @param cacheUpdate - Update to apply to matching entries
9146
+ */
9147
+ async *findAndModify(query, cacheUpdate) {
9148
+ if (!this.storage) {
9149
+ return;
9150
+ }
9151
+ try {
9152
+ // Need to get all entries to search through them with the query
9153
+ // Cannot pass specific keys since we don't know which entries match the query
9154
+ const allStoredData = (await this.storage.getAll());
9155
+ const modifiedEntries = [];
9156
+ // Find and modify matching entries
9157
+ for (const [storageKey, storedEntry] of Object.entries(allStoredData)) {
9158
+ const entry = storedEntry;
9159
+ const key = storageKey;
9160
+ if (entry && this.matchesQuery(key, entry, query)) {
9161
+ // Apply the update to the entry
9162
+ const updatedEntry = this.applyUpdate(entry, cacheUpdate);
9163
+ if (updatedEntry) {
9164
+ modifiedEntries.push({ storageKey, entry: updatedEntry, modifiedKey: key });
9165
+ }
9166
+ }
9167
+ }
9168
+ // Save all modified entries back to storage
9169
+ if (modifiedEntries.length > 0 && this.storage) {
9170
+ const promises = modifiedEntries.map(({ storageKey, entry }) => this.storage.set(storageKey, entry).catch((error) => {
9171
+ console.warn(`Failed to update cache entry: ${storageKey}`, error);
9172
+ }));
9173
+ await Promise.all(promises);
9174
+ // Yield all modified keys
9175
+ for (const { modifiedKey } of modifiedEntries) {
9176
+ yield modifiedKey;
9177
+ }
9178
+ }
9179
+ }
9180
+ catch (error) {
9181
+ console.warn('Failed to find and modify cache entries in AuraStorage:', error);
9182
+ }
9183
+ }
9184
+ /**
9185
+ * Check if an entry matches a cache query
9186
+ * @param key - Cache key to check
9187
+ * @param entry - Cache entry to check
9188
+ * @param query - Query to match against
9189
+ * @returns true if the entry matches the query
9190
+ */
9191
+ matchesQuery(key, entry, query) {
9192
+ if (!query)
9193
+ return true;
9194
+ // Handle logical operators
9195
+ if (this.isAndQuery(query)) {
9196
+ return query.$and.every((subQuery) => this.matchesQuery(key, entry, subQuery));
9197
+ }
9198
+ if (this.isOrQuery(query)) {
9199
+ return query.$or.some((subQuery) => this.matchesQuery(key, entry, subQuery));
9200
+ }
9201
+ if (this.isNotQuery(query)) {
9202
+ return !this.matchesQuery(key, entry, query.$not);
9203
+ }
9204
+ // Handle specific query types
9205
+ if ('key' in query) {
9206
+ return this.matchesKey(query.key, key);
9207
+ }
9208
+ if ('metadata' in query) {
9209
+ return this.matchesMetadata(query.metadata, entry.metadata.cacheControl);
9210
+ }
9211
+ if ('value' in query) {
9212
+ return false; // Value-based querying not implemented
9213
+ }
9214
+ return false; // Unknown query type
9215
+ }
9216
+ isAndQuery(query) {
9217
+ return '$and' in query;
9218
+ }
9219
+ isOrQuery(query) {
9220
+ return '$or' in query;
9221
+ }
9222
+ isNotQuery(query) {
9223
+ return '$not' in query;
9224
+ }
9225
+ matchesKey(keyQuery, key) {
9226
+ if ('$regex' in keyQuery) {
9227
+ const keyString = typeof key === 'string' ? key : JSON.stringify(key);
9228
+ return keyQuery.$regex.test(keyString);
9229
+ }
9230
+ return false;
9231
+ }
9232
+ matchesMetadata(metadataQuery, cacheControl) {
9233
+ if ('cacheControlType' in metadataQuery &&
9234
+ cacheControl.type !== metadataQuery.cacheControlType.$eq) {
9235
+ return false;
9236
+ }
9237
+ if ('maxAge' in metadataQuery && cacheControl.type === 'max-age') {
9238
+ const maxAge = cacheControl.maxAge ?? 0;
9239
+ if ((metadataQuery.maxAge.$gte !== undefined && maxAge < metadataQuery.maxAge.$gte) ||
9240
+ (metadataQuery.maxAge.$lte !== undefined && maxAge > metadataQuery.maxAge.$lte)) {
9241
+ return false;
9242
+ }
9243
+ }
9244
+ return true;
9245
+ }
9246
+ /**
9247
+ * Apply an update to a cache entry
9248
+ * @param entry - Original cache entry
9249
+ * @param update - Update to apply
9250
+ * @returns Updated entry or null if no update needed
9251
+ */
9252
+ applyUpdate(entry, update) {
9253
+ try {
9254
+ const updateResult = this.buildUpdate(update, entry);
9255
+ switch (updateResult.type) {
9256
+ case 'entry':
9257
+ return updateResult.entry;
9258
+ case 'metadata':
9259
+ // Create a new entry with updated metadata
9260
+ return {
9261
+ ...entry,
9262
+ metadata: {
9263
+ ...entry.metadata,
9264
+ cacheControl: updateResult.metadata,
9265
+ },
9266
+ };
9267
+ case 'no-op':
9268
+ return null; // No changes needed
9269
+ default:
9270
+ return null;
9271
+ }
9272
+ }
9273
+ catch (error) {
9274
+ console.warn('Failed to apply update to cache entry:', error);
9275
+ return null;
9276
+ }
9277
+ }
9278
+ /**
9279
+ * Build an update for a cache entry
9280
+ * @param update - The cache update operation to apply
9281
+ * @param existing - The existing cache entry being modified
9282
+ * @returns An object indicating the type of update
9283
+ */
9284
+ buildUpdate(update, existing) {
9285
+ switch (update.type) {
9286
+ case 'invalidate':
9287
+ const updatedCacheControl = this.buildInvalidatedCacheControl(existing.metadata.cacheControl);
9288
+ return updatedCacheControl !== undefined
9289
+ ? { type: 'metadata', metadata: updatedCacheControl }
9290
+ : { type: 'no-op' };
9291
+ default:
9292
+ throw new Error(`Invalid update operation: ${update.type}`);
9293
+ }
9294
+ }
9295
+ /**
9296
+ * Build an invalidated cache control metadata
9297
+ * @param existingCacheControl - The current CacheControlMetadata
9298
+ * @returns A new CacheControlMetadata object with maxAge set to 0, or undefined if no changes needed
9299
+ */
9300
+ buildInvalidatedCacheControl(existingCacheControl) {
9301
+ switch (existingCacheControl.type) {
9302
+ case 'max-age':
9303
+ case 'stale-while-revalidate':
9304
+ if (existingCacheControl.maxAge !== 0) {
9305
+ return {
9306
+ ...existingCacheControl,
9307
+ maxAge: 0,
9308
+ };
9309
+ }
9310
+ return undefined; // Already invalidated
9311
+ case 'no-cache':
9312
+ case 'no-store':
9313
+ // These types don't need invalidation
9314
+ return undefined;
9315
+ default:
9316
+ return undefined;
9317
+ }
9318
+ }
9319
+ }
9320
+ /**
9321
+ * Factory function to create an AuraDurableCacheInclusionPolicy service descriptor
9322
+ * @param config - Optional configuration for the storage
9323
+ * @returns Service descriptor for the cache inclusion policy
9324
+ */
9325
+ function buildAuraDurableCacheInclusionPolicyService(config) {
9326
+ return {
9327
+ service: new AuraDurableCacheInclusionPolicy(config),
9328
+ type: 'cacheInclusionPolicy',
9329
+ version: '1.0',
9330
+ tags: { storage: 'durable' },
9331
+ };
9332
+ }
9333
+
7536
9334
  // This code *should* be in lds-network-adapter, but when combined with the Aura
7537
9335
  // component test workaround in lds-default-luvio it creates a circular dependecy
7538
9336
  // between lds-default-luvio and lds-network-adapter. We do the register on behalf
@@ -7793,13 +9591,18 @@ function initializeLDS() {
7793
9591
  }
7794
9592
  // Initializes OneStore in LEX
7795
9593
  function initializeOneStore(luvio) {
7796
- const loggerService = new ConsoleLogger$1('ERROR');
7797
- const cacheServiceDescriptor = buildServiceDescriptor$9();
7798
- const instrumentationServiceDescriptor = buildServiceDescriptor$a(loggerService);
9594
+ const loggerService = new ConsoleLogger('ERROR');
9595
+ const cacheServiceDescriptor = buildServiceDescriptor$h();
9596
+ const instrumentationServiceDescriptor = buildServiceDescriptor$i(loggerService);
7799
9597
  const inMemoryCacheInclusionPolicyServiceDescriptor = buildInMemoryCacheInclusionPolicyService(cacheServiceDescriptor.service);
7800
- const featureFlagsServiceDescriptor = buildServiceDescriptor$2();
9598
+ const durableCacheInclusionPolicyServiceDescriptor = buildAuraDurableCacheInclusionPolicyService();
9599
+ const durableCacheControlService = {
9600
+ ...buildServiceDescriptor$g(cacheServiceDescriptor.service, durableCacheInclusionPolicyServiceDescriptor.service, instrumentationServiceDescriptor.service),
9601
+ tags: { storage: 'durable' },
9602
+ };
9603
+ const featureFlagsServiceDescriptor = buildServiceDescriptor$a();
7801
9604
  const featureFlagsService = featureFlagsServiceDescriptor.service;
7802
- const luvioUiapiRecordsServiceDescriptor = buildServiceDescriptor$1((configs) => {
9605
+ const luvioUiapiRecordsServiceDescriptor = buildServiceDescriptor$9((configs) => {
7803
9606
  return notifyUpdateAvailableFactory(luvio)(configs);
7804
9607
  }, (recordId, reader) => {
7805
9608
  const recordKey = buildRecordRepKeyFromId(recordId);
@@ -7818,8 +9621,11 @@ function initializeOneStore(luvio) {
7818
9621
  reader.unMarkMissing();
7819
9622
  return linkedData.data;
7820
9623
  });
7821
- const retryPolicy = new FetchThrottlingRetryPolicy();
7822
- const retryServiceDescriptor = buildServiceDescriptor(retryPolicy);
9624
+ // Compose both throttling and CSRF retry policies
9625
+ const throttlingPolicy = new FetchThrottlingRetryPolicy();
9626
+ const csrfPolicy = new CsrfTokenRetryPolicy();
9627
+ const retryPolicy = new ComposedRetryPolicy([throttlingPolicy, csrfPolicy]);
9628
+ const retryServiceDescriptor = buildServiceDescriptor$8(retryPolicy);
7823
9629
  const retryService = retryServiceDescriptor.service;
7824
9630
  // set flags based on gates
7825
9631
  featureFlagsService.set('useOneStoreGraphQL', useOneStoreGraphql.isOpen({ fallback: false }));
@@ -7830,25 +9636,36 @@ function initializeOneStore(luvio) {
7830
9636
  buildJwtAuthorizedSfapFetchServiceDescriptor(loggerService),
7831
9637
  buildCopilotFetchServiceDescriptor(loggerService),
7832
9638
  buildAuraNetworkService(),
7833
- buildServiceDescriptor$b(instrumentationServiceDescriptor.service),
7834
- buildServiceDescriptor$8(cacheServiceDescriptor.service, inMemoryCacheInclusionPolicyServiceDescriptor.service, instrumentationServiceDescriptor.service),
7835
- buildServiceDescriptor$i(),
7836
- buildServiceDescriptor$6(),
9639
+ buildServiceDescriptor$j(instrumentationServiceDescriptor.service),
9640
+ // Ordering of services matters - L1 only CacheControlService must come before durable
9641
+ buildServiceDescriptor$g(cacheServiceDescriptor.service, inMemoryCacheInclusionPolicyServiceDescriptor.service, instrumentationServiceDescriptor.service),
9642
+ durableCacheControlService,
9643
+ buildServiceDescriptor$q(),
7837
9644
  buildServiceDescriptor$e(),
7838
- buildServiceDescriptor$j(),
7839
- buildServiceDescriptor$d(),
7840
- buildServiceDescriptor$c(),
7841
- buildServiceDescriptor$h(),
7842
- buildServiceDescriptor$g(),
9645
+ buildServiceDescriptor$m(),
9646
+ buildServiceDescriptor$r(),
9647
+ buildServiceDescriptor$l(),
9648
+ buildServiceDescriptor$k(),
9649
+ buildServiceDescriptor$p(),
9650
+ buildServiceDescriptor$o(),
9651
+ buildServiceDescriptor$n(),
7843
9652
  buildServiceDescriptor$f(),
7844
- buildServiceDescriptor$7(),
7845
9653
  buildLexRuntimeAllow5xxFetchServiceDescriptor(loggerService, retryService),
7846
- buildServiceDescriptor$5(luvio),
9654
+ buildServiceDescriptor$d(luvio),
7847
9655
  luvioUiapiRecordsServiceDescriptor,
7848
- buildServiceDescriptor$4(),
7849
- buildServiceDescriptor$3(),
9656
+ buildServiceDescriptor$c(),
9657
+ buildServiceDescriptor$b(),
7850
9658
  featureFlagsServiceDescriptor,
7851
9659
  retryServiceDescriptor,
9660
+ buildServiceDescriptor$6(),
9661
+ buildServiceDescriptor$5(),
9662
+ buildServiceDescriptor$4(),
9663
+ buildServiceDescriptor$3(),
9664
+ buildServiceDescriptor$2$1(),
9665
+ buildServiceDescriptor$1$1(),
9666
+ buildServiceDescriptor$7(),
9667
+ buildServiceDescriptor$1(),
9668
+ buildServiceDescriptor$2(),
7852
9669
  ];
7853
9670
  setServices(services);
7854
9671
  }
@@ -7868,4 +9685,4 @@ function ldsEngineCreator() {
7868
9685
  }
7869
9686
 
7870
9687
  export { LexRequestStrategy, PdlRequestPriority, buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore, notifyUpdateAvailableFactory, registerRequestStrategy, saveRequestAsPrediction, unregisterRequestStrategy, whenPredictionsReady };
7871
- // version: 1.400.0-8bade3324c
9688
+ // version: 1.402.0-bf9ae185ef