@salesforce/lds-runtime-webruntime 1.440.0 → 1.442.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.
@@ -1520,9 +1520,12 @@ const _FetchNetworkCommand = class _FetchNetworkCommand extends NetworkCommand {
1520
1520
  this.services = services;
1521
1521
  this.additionalNullResponses = [];
1522
1522
  }
1523
- fetch() {
1523
+ fetch(contextSeed) {
1524
1524
  try {
1525
- return this.convertFetchResponseToData(this.services.fetch(...this.fetchParams));
1525
+ const [input, init] = this.fetchParams;
1526
+ const initWithSeed = contextSeed === void 0 ? init : { ...init, __contextSeed: contextSeed };
1527
+ const fetchCall = initWithSeed === void 0 ? this.services.fetch(input) : this.services.fetch(input, initWithSeed);
1528
+ return this.convertFetchResponseToData(fetchCall);
1526
1529
  } catch (reason) {
1527
1530
  return resolvedPromiseLike$2(err$1(toError(reason)));
1528
1531
  }
@@ -3227,7 +3230,7 @@ function buildServiceDescriptor$9(luvio) {
3227
3230
  },
3228
3231
  };
3229
3232
  }
3230
- // version: 1.440.0-267427df73
3233
+ // version: 1.442.0-e47893165a
3231
3234
 
3232
3235
  /**
3233
3236
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3253,7 +3256,7 @@ function buildServiceDescriptor$8(notifyRecordUpdateAvailable, getNormalizedLuvi
3253
3256
  },
3254
3257
  };
3255
3258
  }
3256
- // version: 1.440.0-267427df73
3259
+ // version: 1.442.0-e47893165a
3257
3260
 
3258
3261
  class JsonSchemaViolationError extends Error {
3259
3262
  constructor(message, validationErrors) {
@@ -4555,11 +4558,13 @@ class JwtToken {
4555
4558
  * @param _token - The JWT string.
4556
4559
  * @param _decodedInfo - The decoded information from the JWT.
4557
4560
  * @param _extraInfo - Any additional information associated with the JWT.
4561
+ * @param _mintParams - The parameters used to mint this token. Undefined for legacy parameterless tokens.
4558
4562
  */
4559
- constructor(_token, _decodedInfo, _extraInfo) {
4563
+ constructor(_token, _decodedInfo, _extraInfo, _mintParams) {
4560
4564
  this._token = _token;
4561
4565
  this._decodedInfo = _decodedInfo;
4562
4566
  this._extraInfo = _extraInfo;
4567
+ this._mintParams = _mintParams;
4563
4568
  }
4564
4569
  /**
4565
4570
  * Get the JWT string.
@@ -4585,6 +4590,14 @@ class JwtToken {
4585
4590
  get decodedInfo() {
4586
4591
  return this._decodedInfo;
4587
4592
  }
4593
+ /**
4594
+ * Get the mint parameters used to produce this token.
4595
+ *
4596
+ * @returns The mint parameters, or undefined for legacy parameterless tokens.
4597
+ */
4598
+ get mintParams() {
4599
+ return this._mintParams;
4600
+ }
4588
4601
  /**
4589
4602
  * Get the remaining time in seconds until the JWT expires.
4590
4603
  *
@@ -4602,6 +4615,12 @@ class JwtToken {
4602
4615
  return this.tokenRemainingSeconds <= 0;
4603
4616
  }
4604
4617
  }
4618
+ function cacheKeyFor(params) {
4619
+ if (params === void 0) {
4620
+ return "jwt:";
4621
+ }
4622
+ return `jwt:${stableJSONStringify(params) ?? ""}`;
4623
+ }
4605
4624
  let defaultLogger = {
4606
4625
  trace: () => {
4607
4626
  },
@@ -4635,85 +4654,146 @@ class JwtRepository {
4635
4654
  this.limitInSeconds = limitInSeconds;
4636
4655
  this.defaultTokenTTLInSeconds = defaultTokenTTLInSeconds;
4637
4656
  this.logger = logger;
4657
+ this._tokens = /* @__PURE__ */ new Map();
4658
+ this.timeoutHandlers = /* @__PURE__ */ new Map();
4638
4659
  this.observers = [];
4639
4660
  }
4640
4661
  /**
4641
- * Get the current token.
4662
+ * Get the legacy (parameterless) token. Equivalent to `getToken()` with
4663
+ * no args. Preserved for backward compatibility with code that reads the
4664
+ * `token` property directly.
4642
4665
  */
4643
4666
  get token() {
4644
- return this._token;
4667
+ return this.getToken();
4645
4668
  }
4646
4669
  /**
4647
- * Set the current token.
4670
+ * Get the cached token for the given mint params.
4671
+ *
4672
+ * @param params - The mint params identifying the token. Omit for the legacy global token.
4673
+ */
4674
+ getToken(params) {
4675
+ return this._tokens.get(cacheKeyFor(params));
4676
+ }
4677
+ /**
4678
+ * Set the cached token for the given mint params.
4648
4679
  *
4649
4680
  * @param token - JWT token as a string.
4650
4681
  * @param extraInfo - Optional extra information.
4682
+ * @param params - The mint params identifying the token. Omit for the legacy global token.
4651
4683
  */
4652
- setToken(token, extraInfo) {
4684
+ setToken(token, extraInfo, params) {
4653
4685
  const decodedInfo = computeDecodedInfo(
4654
4686
  token,
4655
4687
  this.defaultTokenTTLInSeconds,
4656
4688
  this.logger
4657
4689
  );
4658
- this._token = new JwtToken(token, decodedInfo, extraInfo);
4659
- this.observeTokenExpiration();
4660
- return this._token;
4690
+ const key = cacheKeyFor(params);
4691
+ const jwtToken = new JwtToken(token, decodedInfo, extraInfo, params);
4692
+ this._tokens.set(key, jwtToken);
4693
+ this.observeTokenExpiration(key);
4694
+ return jwtToken;
4661
4695
  }
4662
4696
  /**
4663
- * Remove the current token.
4697
+ * Remove the cached token for the given mint params.
4698
+ *
4699
+ * @param params - The mint params identifying the token. Omit to remove
4700
+ * only the legacy global-key entry (matches today's behavior of "remove
4701
+ * the only token there is").
4664
4702
  */
4665
- removeToken() {
4666
- this._token = void 0;
4667
- this.clearTimeoutHandler();
4703
+ removeToken(params) {
4704
+ const key = cacheKeyFor(params);
4705
+ this._tokens.delete(key);
4706
+ this.clearTimeoutHandler(key);
4668
4707
  }
4669
4708
  /**
4670
- * Subscribe to the token nearing its expiration.
4709
+ * Remove every cached token and clear every near-expiry timer. Used by
4710
+ * test teardown and full auth-reset paths that previously called
4711
+ * `removeToken()` to clear the single token.
4712
+ */
4713
+ clearAllTokens() {
4714
+ for (const key of Array.from(this.timeoutHandlers.keys())) {
4715
+ this.clearTimeoutHandler(key);
4716
+ }
4717
+ this._tokens.clear();
4718
+ }
4719
+ /**
4720
+ * Subscribe to any cached token nearing its expiration.
4721
+ *
4722
+ * The callback receives the specific token whose timer fired. Use
4723
+ * `token.mintParams` to determine which token-set the expiry belongs to.
4724
+ *
4725
+ * Already-cached tokens are armed at subscribe time. Tokens added later
4726
+ * via `setToken` arm their own timers from inside `setToken`, so this
4727
+ * loop only needs to cover the existing entries.
4671
4728
  *
4672
- * @param cb - Callback function to execute when token is nearing expiration.
4729
+ * @param cb - Callback function to execute when a token is nearing expiration.
4673
4730
  */
4674
4731
  subscribeToTokenNearExpiration(cb) {
4675
4732
  this.observers.push(cb);
4676
- this.observeTokenExpiration();
4733
+ for (const key of this._tokens.keys()) {
4734
+ this.observeTokenExpiration(key);
4735
+ }
4677
4736
  return () => {
4678
4737
  this.observers = this.observers.filter((observer) => observer !== cb);
4738
+ if (this.observers.length === 0) {
4739
+ for (const key of Array.from(this.timeoutHandlers.keys())) {
4740
+ this.clearTimeoutHandler(key);
4741
+ }
4742
+ }
4679
4743
  };
4680
4744
  }
4681
4745
  /**
4682
- * Clear the timeout handler.
4746
+ * Number of currently cached tokens. Exposed for size observability so
4747
+ * runtime callers can emit a metric on cache growth and detect adapters
4748
+ * that misuse `dynamicParams` for per-request values.
4749
+ */
4750
+ get size() {
4751
+ return this._tokens.size;
4752
+ }
4753
+ /**
4754
+ * Clear the timeout handler for a specific cache key.
4683
4755
  */
4684
- clearTimeoutHandler() {
4685
- if (this.timeoutHandler !== void 0) {
4686
- clearTimeout(this.timeoutHandler);
4756
+ clearTimeoutHandler(key) {
4757
+ const handler = this.timeoutHandlers.get(key);
4758
+ if (handler !== void 0) {
4759
+ clearTimeout(handler);
4760
+ this.timeoutHandlers.delete(key);
4687
4761
  }
4688
4762
  }
4689
4763
  /**
4690
- * Observe and handle token expiration.
4764
+ * Observe and handle expiration of the token at the given cache key.
4691
4765
  */
4692
- observeTokenExpiration() {
4693
- this.clearTimeoutHandler();
4694
- if (this.observers.length === 0 || this.token === void 0) {
4766
+ observeTokenExpiration(key) {
4767
+ this.clearTimeoutHandler(key);
4768
+ const token = this._tokens.get(key);
4769
+ if (this.observers.length === 0 || token === void 0) {
4695
4770
  return;
4696
4771
  }
4697
- this.timeoutHandler = setTimeout(
4698
- () => this.notifyTokenIsExpiring(),
4699
- this.computeTimeoutTimeInMs()
4772
+ const handler = setTimeout(
4773
+ () => this.notifyTokenIsExpiring(key),
4774
+ this.computeTimeoutTimeInMs(token)
4700
4775
  );
4776
+ this.timeoutHandlers.set(key, handler);
4701
4777
  }
4702
4778
  /**
4703
- * Compute the timeout time in milliseconds.
4779
+ * Compute the timeout time in milliseconds for the given token.
4704
4780
  */
4705
- computeTimeoutTimeInMs() {
4706
- const remainingSeconds = this.token.tokenRemainingSeconds;
4707
- let timeoutTimeInSeconds = remainingSeconds - this.limitInSeconds;
4781
+ computeTimeoutTimeInMs(token) {
4782
+ const remainingSeconds = token.tokenRemainingSeconds;
4783
+ const timeoutTimeInSeconds = remainingSeconds - this.limitInSeconds;
4708
4784
  return timeoutTimeInSeconds < 0 ? 0 : timeoutTimeInSeconds * 1e3;
4709
4785
  }
4710
4786
  /**
4711
- * Notify all observers that the token is expiring.
4787
+ * Notify all observers that the token at the given cache key is expiring.
4712
4788
  */
4713
- notifyTokenIsExpiring() {
4789
+ notifyTokenIsExpiring(key) {
4790
+ const token = this._tokens.get(key);
4791
+ if (token === void 0) {
4792
+ return;
4793
+ }
4714
4794
  this.observers.forEach((cb) => {
4715
4795
  try {
4716
- cb.call(void 0, this.token);
4796
+ cb.call(void 0, token);
4717
4797
  } catch (e2) {
4718
4798
  this.logger.error(e2.message);
4719
4799
  }
@@ -4731,57 +4811,68 @@ class JwtManager {
4731
4811
  constructor(jwtRepository, resolver, options) {
4732
4812
  this.jwtRepository = jwtRepository;
4733
4813
  this.resolver = resolver;
4814
+ this.inflightPromises = /* @__PURE__ */ new Map();
4734
4815
  if (options?.keepTokenUpdated) {
4735
- jwtRepository.subscribeToTokenNearExpiration(() => this.refreshToken());
4816
+ jwtRepository.subscribeToTokenNearExpiration(
4817
+ (token) => this.refreshToken(token.mintParams)
4818
+ );
4736
4819
  }
4737
4820
  }
4738
4821
  /**
4739
- * Method to get a JWT token.
4740
- * If there's a token request in progress, it will return the Promise of this request.
4741
- * If the current token is undefined or expired, it will initiate a token refresh.
4742
- * Otherwise, it will return the current token.
4822
+ * Method to get a JWT token for the given mint params.
4823
+ *
4824
+ * If a request for the same params is in flight, returns its promise. If
4825
+ * a cached token for those params exists and is not expired, returns it
4826
+ * synchronously. Otherwise initiates a refresh.
4743
4827
  *
4744
- * @returns {JwtToken<T, ExtraInfo> | Promise<JwtToken<T, ExtraInfo>>} The current token or the Promise of a token request.
4828
+ * @param params - Optional mint parameters. Omit for the legacy parameterless token.
4829
+ * @returns The cached token (sync) or a promise that resolves to the refreshed token.
4745
4830
  */
4746
- getJwt() {
4747
- if (this.inflightPromise) {
4748
- return this.inflightPromise;
4831
+ getJwt(params) {
4832
+ const key = cacheKeyFor(params);
4833
+ const inflight = this.inflightPromises.get(key);
4834
+ if (inflight) {
4835
+ return inflight;
4749
4836
  }
4750
- const token = this.jwtRepository.token;
4837
+ const token = this.jwtRepository.getToken(params);
4751
4838
  if (token === void 0 || token.isExpired) {
4752
- return this.refreshToken();
4839
+ return this.refreshToken(params);
4753
4840
  }
4754
4841
  return token;
4755
4842
  }
4756
4843
  /**
4757
- * Method to refresh a JWT token.
4758
- * If a refresh request is already in progress, it will return the Promise of this request.
4759
- * Otherwise, it will start a new refresh request and return its Promise.
4844
+ * Method to refresh a JWT token for the given mint params.
4760
4845
  *
4761
- * @returns {Promise<JwtToken<T, ExtraInfo>>} Promise of the refreshed token.
4846
+ * @param params - Optional mint parameters. Omit for the legacy parameterless token.
4847
+ * @returns Promise of the refreshed token.
4762
4848
  */
4763
- refreshToken() {
4764
- if (this.inflightPromise === void 0) {
4765
- this.inflightPromise = new Promise((resolve, reject) => {
4766
- this.resolver.getJwt().then(({ jwt, extraInfo }) => {
4767
- this.inflightPromise = void 0;
4768
- const token = this.jwtRepository.setToken(jwt, extraInfo);
4769
- resolve(token);
4770
- }).catch((reason) => {
4771
- this.inflightPromise = void 0;
4772
- reject(reason);
4773
- });
4849
+ refreshToken(params) {
4850
+ const key = cacheKeyFor(params);
4851
+ const existing = this.inflightPromises.get(key);
4852
+ if (existing !== void 0) {
4853
+ return existing;
4854
+ }
4855
+ const resolverPromise = params === void 0 ? this.resolver.getJwt() : this.resolver.getJwt(params);
4856
+ const promise = new Promise((resolve, reject) => {
4857
+ resolverPromise.then(({ jwt, extraInfo }) => {
4858
+ this.inflightPromises.delete(key);
4859
+ const token = this.jwtRepository.setToken(jwt, extraInfo, params);
4860
+ resolve(token);
4861
+ }).catch((reason) => {
4862
+ this.inflightPromises.delete(key);
4863
+ reject(reason);
4774
4864
  });
4775
- }
4776
- return this.inflightPromise;
4865
+ });
4866
+ this.inflightPromises.set(key, promise);
4867
+ return promise;
4777
4868
  }
4778
4869
  /**
4779
- * Method to check if a token refresh is in progress.
4870
+ * Method to check if any token refresh is in progress.
4780
4871
  *
4781
- * @returns {boolean} true if a token refresh is in progress, false otherwise.
4872
+ * @returns {boolean} true if at least one refresh is in flight, false otherwise.
4782
4873
  */
4783
4874
  get isRefreshingToken() {
4784
- return this.inflightPromise !== void 0;
4875
+ return this.inflightPromises.size > 0;
4785
4876
  }
4786
4877
  }
4787
4878
 
@@ -4794,8 +4885,17 @@ function buildServiceDescriptor(interceptors = {
4794
4885
  return {
4795
4886
  type: "fetch",
4796
4887
  version: "1.0",
4797
- service: function(...args) {
4798
- const context = interceptors.createContext?.();
4888
+ service: function(input, init) {
4889
+ let contextSeed;
4890
+ let cleanInit = init;
4891
+ if (init !== void 0 && "__contextSeed" in init) {
4892
+ const { __contextSeed, ...initWithoutSeed } = init;
4893
+ contextSeed = __contextSeed;
4894
+ cleanInit = Object.keys(initWithoutSeed).length === 0 ? void 0 : initWithoutSeed;
4895
+ }
4896
+ const fetchArgs = cleanInit === void 0 ? [input] : [input, cleanInit];
4897
+ const baseContext = interceptors.createContext?.();
4898
+ const context = contextSeed === void 0 ? baseContext : { ...baseContext, ...contextSeed };
4799
4899
  const {
4800
4900
  request: requestInterceptors = [],
4801
4901
  retry: retryInterceptor = void 0,
@@ -4803,17 +4903,17 @@ function buildServiceDescriptor(interceptors = {
4803
4903
  finally: finallyInterceptors = []
4804
4904
  } = interceptors;
4805
4905
  const pending = requestInterceptors.reduce(
4806
- (previousPromise, interceptor) => previousPromise.then((args2) => interceptor(args2, context)),
4807
- resolvedPromiseLike$2(args)
4906
+ (previousPromise, interceptor) => previousPromise.then((args) => interceptor(args, context)),
4907
+ resolvedPromiseLike$2(fetchArgs)
4808
4908
  );
4809
- return Promise.resolve(pending).then((args2) => {
4909
+ return Promise.resolve(pending).then((args) => {
4810
4910
  if (retryInterceptor) {
4811
- return retryInterceptor(args2, retryService, context);
4911
+ return retryInterceptor(args, retryService, context);
4812
4912
  } else {
4813
4913
  if (retryService) {
4814
- return retryService.applyRetry(() => fetch(...args2));
4914
+ return retryService.applyRetry(() => fetch(...args));
4815
4915
  }
4816
- return fetch(...args2);
4916
+ return fetch(...args);
4817
4917
  }
4818
4918
  }).then((response) => {
4819
4919
  return responseInterceptors.reduce(
@@ -5146,4 +5246,4 @@ withDefaultLuvio((luvio) => {
5146
5246
  ];
5147
5247
  setServices(services);
5148
5248
  });
5149
- // version: 1.440.0-267427df73
5249
+ // version: 1.442.0-e47893165a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-webruntime",
3
- "version": "1.440.0",
3
+ "version": "1.442.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Webruntime runtime",
6
6
  "main": "dist/ldsWebruntimeOneStoreInit.js",
@@ -35,38 +35,38 @@
35
35
  "ready": "yarn build && jest --collectCoverage && yarn test:size && yarn release:corejar"
36
36
  },
37
37
  "devDependencies": {
38
- "@conduit-client/service-provisioner": "3.20.5",
39
- "@conduit-client/tools-core": "3.20.5",
38
+ "@conduit-client/service-provisioner": "3.21.0",
39
+ "@conduit-client/tools-core": "3.21.0",
40
40
  "jwt-encode": "1.0.1"
41
41
  },
42
42
  "dependencies": {
43
- "@conduit-client/command-aura-network": "3.20.5",
44
- "@conduit-client/command-aura-normalized-cache-control": "3.20.5",
45
- "@conduit-client/command-aura-resource-cache-control": "3.20.5",
46
- "@conduit-client/command-fetch-network": "3.20.5",
47
- "@conduit-client/command-http-normalized-cache-control": "3.20.5",
48
- "@conduit-client/command-ndjson": "3.20.5",
49
- "@conduit-client/command-network": "3.20.5",
50
- "@conduit-client/command-sse": "3.20.5",
51
- "@conduit-client/command-streaming": "3.20.5",
52
- "@conduit-client/jwt-manager": "3.20.5",
53
- "@conduit-client/service-aura-network": "3.20.5",
54
- "@conduit-client/service-bindings-imperative": "3.20.5",
55
- "@conduit-client/service-bindings-lwc": "3.20.5",
56
- "@conduit-client/service-cache": "3.20.5",
57
- "@conduit-client/service-cache-control": "3.20.5",
58
- "@conduit-client/service-cache-inclusion-policy": "3.20.5",
59
- "@conduit-client/service-fetch-network": "3.20.5",
60
- "@conduit-client/service-instrument-command": "3.20.5",
61
- "@conduit-client/service-pubsub": "3.20.5",
62
- "@conduit-client/service-store": "3.20.5",
63
- "@conduit-client/utils": "3.20.5",
43
+ "@conduit-client/command-aura-network": "3.21.0",
44
+ "@conduit-client/command-aura-normalized-cache-control": "3.21.0",
45
+ "@conduit-client/command-aura-resource-cache-control": "3.21.0",
46
+ "@conduit-client/command-fetch-network": "3.21.0",
47
+ "@conduit-client/command-http-normalized-cache-control": "3.21.0",
48
+ "@conduit-client/command-ndjson": "3.21.0",
49
+ "@conduit-client/command-network": "3.21.0",
50
+ "@conduit-client/command-sse": "3.21.0",
51
+ "@conduit-client/command-streaming": "3.21.0",
52
+ "@conduit-client/jwt-manager": "3.21.0",
53
+ "@conduit-client/service-aura-network": "3.21.0",
54
+ "@conduit-client/service-bindings-imperative": "3.21.0",
55
+ "@conduit-client/service-bindings-lwc": "3.21.0",
56
+ "@conduit-client/service-cache": "3.21.0",
57
+ "@conduit-client/service-cache-control": "3.21.0",
58
+ "@conduit-client/service-cache-inclusion-policy": "3.21.0",
59
+ "@conduit-client/service-fetch-network": "3.21.0",
60
+ "@conduit-client/service-instrument-command": "3.21.0",
61
+ "@conduit-client/service-pubsub": "3.21.0",
62
+ "@conduit-client/service-store": "3.21.0",
63
+ "@conduit-client/utils": "3.21.0",
64
64
  "@luvio/network-adapter-composable": "0.160.5",
65
65
  "@luvio/network-adapter-fetch": "0.160.5",
66
66
  "@salesforce/lds-adapters-uiapi-lex": "^1.415.0",
67
- "@salesforce/lds-default-luvio": "^1.440.0",
68
- "@salesforce/lds-luvio-service": "^1.440.0",
69
- "@salesforce/lds-luvio-uiapi-records-service": "^1.440.0"
67
+ "@salesforce/lds-default-luvio": "^1.442.0",
68
+ "@salesforce/lds-luvio-service": "^1.442.0",
69
+ "@salesforce/lds-luvio-uiapi-records-service": "^1.442.0"
70
70
  },
71
71
  "luvioBundlesize": [
72
72
  {
@@ -74,7 +74,7 @@
74
74
  "maxSize": {
75
75
  "none": "163 kB",
76
76
  "min": "85 kB",
77
- "compressed": "25.5 kB"
77
+ "compressed": "26 kB"
78
78
  }
79
79
  }
80
80
  ],