@salesforce/lds-runtime-webruntime 1.428.0-dev10 → 1.428.0-dev12

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.
@@ -1588,9 +1588,12 @@ const _FetchNetworkCommand = class _FetchNetworkCommand extends NetworkCommand {
1588
1588
  this.services = services;
1589
1589
  this.additionalNullResponses = [];
1590
1590
  }
1591
- fetch() {
1591
+ fetch(contextSeed) {
1592
1592
  try {
1593
- return this.convertFetchResponseToData(this.services.fetch(...this.fetchParams));
1593
+ const [input, init] = this.fetchParams;
1594
+ const initWithSeed = contextSeed === void 0 ? init : { ...init, __contextSeed: contextSeed };
1595
+ const fetchCall = initWithSeed === void 0 ? this.services.fetch(input) : this.services.fetch(input, initWithSeed);
1596
+ return this.convertFetchResponseToData(fetchCall);
1594
1597
  } catch (reason) {
1595
1598
  return resolvedPromiseLike$2(err$1(toError(reason)));
1596
1599
  }
@@ -3379,7 +3382,7 @@ function buildServiceDescriptor$9(luvio) {
3379
3382
  },
3380
3383
  };
3381
3384
  }
3382
- // version: 1.428.0-dev10-109bf232e1
3385
+ // version: 1.428.0-dev12-f80887e01b
3383
3386
 
3384
3387
  /**
3385
3388
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3405,7 +3408,7 @@ function buildServiceDescriptor$8(notifyRecordUpdateAvailable, getNormalizedLuvi
3405
3408
  },
3406
3409
  };
3407
3410
  }
3408
- // version: 1.428.0-dev10-109bf232e1
3411
+ // version: 1.428.0-dev12-f80887e01b
3409
3412
 
3410
3413
  /*!
3411
3414
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -4732,11 +4735,13 @@ class JwtToken {
4732
4735
  * @param _token - The JWT string.
4733
4736
  * @param _decodedInfo - The decoded information from the JWT.
4734
4737
  * @param _extraInfo - Any additional information associated with the JWT.
4738
+ * @param _mintParams - The parameters used to mint this token. Undefined for legacy parameterless tokens.
4735
4739
  */
4736
- constructor(_token, _decodedInfo, _extraInfo) {
4740
+ constructor(_token, _decodedInfo, _extraInfo, _mintParams) {
4737
4741
  this._token = _token;
4738
4742
  this._decodedInfo = _decodedInfo;
4739
4743
  this._extraInfo = _extraInfo;
4744
+ this._mintParams = _mintParams;
4740
4745
  }
4741
4746
  /**
4742
4747
  * Get the JWT string.
@@ -4762,6 +4767,14 @@ class JwtToken {
4762
4767
  get decodedInfo() {
4763
4768
  return this._decodedInfo;
4764
4769
  }
4770
+ /**
4771
+ * Get the mint parameters used to produce this token.
4772
+ *
4773
+ * @returns The mint parameters, or undefined for legacy parameterless tokens.
4774
+ */
4775
+ get mintParams() {
4776
+ return this._mintParams;
4777
+ }
4765
4778
  /**
4766
4779
  * Get the remaining time in seconds until the JWT expires.
4767
4780
  *
@@ -4779,6 +4792,12 @@ class JwtToken {
4779
4792
  return this.tokenRemainingSeconds <= 0;
4780
4793
  }
4781
4794
  }
4795
+ function cacheKeyFor(params) {
4796
+ if (params === void 0) {
4797
+ return "jwt:";
4798
+ }
4799
+ return `jwt:${stableJSONStringify(params) ?? ""}`;
4800
+ }
4782
4801
  let defaultLogger = {
4783
4802
  trace: () => {
4784
4803
  },
@@ -4812,85 +4831,146 @@ class JwtRepository {
4812
4831
  this.limitInSeconds = limitInSeconds;
4813
4832
  this.defaultTokenTTLInSeconds = defaultTokenTTLInSeconds;
4814
4833
  this.logger = logger;
4834
+ this._tokens = /* @__PURE__ */ new Map();
4835
+ this.timeoutHandlers = /* @__PURE__ */ new Map();
4815
4836
  this.observers = [];
4816
4837
  }
4817
4838
  /**
4818
- * Get the current token.
4839
+ * Get the legacy (parameterless) token. Equivalent to `getToken()` with
4840
+ * no args. Preserved for backward compatibility with code that reads the
4841
+ * `token` property directly.
4819
4842
  */
4820
4843
  get token() {
4821
- return this._token;
4844
+ return this.getToken();
4822
4845
  }
4823
4846
  /**
4824
- * Set the current token.
4847
+ * Get the cached token for the given mint params.
4848
+ *
4849
+ * @param params - The mint params identifying the token. Omit for the legacy global token.
4850
+ */
4851
+ getToken(params) {
4852
+ return this._tokens.get(cacheKeyFor(params));
4853
+ }
4854
+ /**
4855
+ * Set the cached token for the given mint params.
4825
4856
  *
4826
4857
  * @param token - JWT token as a string.
4827
4858
  * @param extraInfo - Optional extra information.
4859
+ * @param params - The mint params identifying the token. Omit for the legacy global token.
4828
4860
  */
4829
- setToken(token, extraInfo) {
4861
+ setToken(token, extraInfo, params) {
4830
4862
  const decodedInfo = computeDecodedInfo(
4831
4863
  token,
4832
4864
  this.defaultTokenTTLInSeconds,
4833
4865
  this.logger
4834
4866
  );
4835
- this._token = new JwtToken(token, decodedInfo, extraInfo);
4836
- this.observeTokenExpiration();
4837
- return this._token;
4867
+ const key = cacheKeyFor(params);
4868
+ const jwtToken = new JwtToken(token, decodedInfo, extraInfo, params);
4869
+ this._tokens.set(key, jwtToken);
4870
+ this.observeTokenExpiration(key);
4871
+ return jwtToken;
4838
4872
  }
4839
4873
  /**
4840
- * Remove the current token.
4874
+ * Remove the cached token for the given mint params.
4875
+ *
4876
+ * @param params - The mint params identifying the token. Omit to remove
4877
+ * only the legacy global-key entry (matches today's behavior of "remove
4878
+ * the only token there is").
4841
4879
  */
4842
- removeToken() {
4843
- this._token = void 0;
4844
- this.clearTimeoutHandler();
4880
+ removeToken(params) {
4881
+ const key = cacheKeyFor(params);
4882
+ this._tokens.delete(key);
4883
+ this.clearTimeoutHandler(key);
4845
4884
  }
4846
4885
  /**
4847
- * Subscribe to the token nearing its expiration.
4886
+ * Remove every cached token and clear every near-expiry timer. Used by
4887
+ * test teardown and full auth-reset paths that previously called
4888
+ * `removeToken()` to clear the single token.
4889
+ */
4890
+ clearAllTokens() {
4891
+ for (const key of Array.from(this.timeoutHandlers.keys())) {
4892
+ this.clearTimeoutHandler(key);
4893
+ }
4894
+ this._tokens.clear();
4895
+ }
4896
+ /**
4897
+ * Subscribe to any cached token nearing its expiration.
4898
+ *
4899
+ * The callback receives the specific token whose timer fired. Use
4900
+ * `token.mintParams` to determine which token-set the expiry belongs to.
4901
+ *
4902
+ * Already-cached tokens are armed at subscribe time. Tokens added later
4903
+ * via `setToken` arm their own timers from inside `setToken`, so this
4904
+ * loop only needs to cover the existing entries.
4848
4905
  *
4849
- * @param cb - Callback function to execute when token is nearing expiration.
4906
+ * @param cb - Callback function to execute when a token is nearing expiration.
4850
4907
  */
4851
4908
  subscribeToTokenNearExpiration(cb) {
4852
4909
  this.observers.push(cb);
4853
- this.observeTokenExpiration();
4910
+ for (const key of this._tokens.keys()) {
4911
+ this.observeTokenExpiration(key);
4912
+ }
4854
4913
  return () => {
4855
4914
  this.observers = this.observers.filter((observer) => observer !== cb);
4915
+ if (this.observers.length === 0) {
4916
+ for (const key of Array.from(this.timeoutHandlers.keys())) {
4917
+ this.clearTimeoutHandler(key);
4918
+ }
4919
+ }
4856
4920
  };
4857
4921
  }
4858
4922
  /**
4859
- * Clear the timeout handler.
4923
+ * Number of currently cached tokens. Exposed for size observability so
4924
+ * runtime callers can emit a metric on cache growth and detect adapters
4925
+ * that misuse `dynamicParams` for per-request values.
4926
+ */
4927
+ get size() {
4928
+ return this._tokens.size;
4929
+ }
4930
+ /**
4931
+ * Clear the timeout handler for a specific cache key.
4860
4932
  */
4861
- clearTimeoutHandler() {
4862
- if (this.timeoutHandler !== void 0) {
4863
- clearTimeout(this.timeoutHandler);
4933
+ clearTimeoutHandler(key) {
4934
+ const handler = this.timeoutHandlers.get(key);
4935
+ if (handler !== void 0) {
4936
+ clearTimeout(handler);
4937
+ this.timeoutHandlers.delete(key);
4864
4938
  }
4865
4939
  }
4866
4940
  /**
4867
- * Observe and handle token expiration.
4941
+ * Observe and handle expiration of the token at the given cache key.
4868
4942
  */
4869
- observeTokenExpiration() {
4870
- this.clearTimeoutHandler();
4871
- if (this.observers.length === 0 || this.token === void 0) {
4943
+ observeTokenExpiration(key) {
4944
+ this.clearTimeoutHandler(key);
4945
+ const token = this._tokens.get(key);
4946
+ if (this.observers.length === 0 || token === void 0) {
4872
4947
  return;
4873
4948
  }
4874
- this.timeoutHandler = setTimeout(
4875
- () => this.notifyTokenIsExpiring(),
4876
- this.computeTimeoutTimeInMs()
4949
+ const handler = setTimeout(
4950
+ () => this.notifyTokenIsExpiring(key),
4951
+ this.computeTimeoutTimeInMs(token)
4877
4952
  );
4953
+ this.timeoutHandlers.set(key, handler);
4878
4954
  }
4879
4955
  /**
4880
- * Compute the timeout time in milliseconds.
4956
+ * Compute the timeout time in milliseconds for the given token.
4881
4957
  */
4882
- computeTimeoutTimeInMs() {
4883
- const remainingSeconds = this.token.tokenRemainingSeconds;
4884
- let timeoutTimeInSeconds = remainingSeconds - this.limitInSeconds;
4958
+ computeTimeoutTimeInMs(token) {
4959
+ const remainingSeconds = token.tokenRemainingSeconds;
4960
+ const timeoutTimeInSeconds = remainingSeconds - this.limitInSeconds;
4885
4961
  return timeoutTimeInSeconds < 0 ? 0 : timeoutTimeInSeconds * 1e3;
4886
4962
  }
4887
4963
  /**
4888
- * Notify all observers that the token is expiring.
4964
+ * Notify all observers that the token at the given cache key is expiring.
4889
4965
  */
4890
- notifyTokenIsExpiring() {
4966
+ notifyTokenIsExpiring(key) {
4967
+ const token = this._tokens.get(key);
4968
+ if (token === void 0) {
4969
+ return;
4970
+ }
4891
4971
  this.observers.forEach((cb) => {
4892
4972
  try {
4893
- cb.call(void 0, this.token);
4973
+ cb.call(void 0, token);
4894
4974
  } catch (e2) {
4895
4975
  this.logger.error(e2.message);
4896
4976
  }
@@ -4908,57 +4988,68 @@ class JwtManager {
4908
4988
  constructor(jwtRepository, resolver, options) {
4909
4989
  this.jwtRepository = jwtRepository;
4910
4990
  this.resolver = resolver;
4991
+ this.inflightPromises = /* @__PURE__ */ new Map();
4911
4992
  if (options == null ? void 0 : options.keepTokenUpdated) {
4912
- jwtRepository.subscribeToTokenNearExpiration(() => this.refreshToken());
4993
+ jwtRepository.subscribeToTokenNearExpiration(
4994
+ (token) => this.refreshToken(token.mintParams)
4995
+ );
4913
4996
  }
4914
4997
  }
4915
4998
  /**
4916
- * Method to get a JWT token.
4917
- * If there's a token request in progress, it will return the Promise of this request.
4918
- * If the current token is undefined or expired, it will initiate a token refresh.
4919
- * Otherwise, it will return the current token.
4999
+ * Method to get a JWT token for the given mint params.
5000
+ *
5001
+ * If a request for the same params is in flight, returns its promise. If
5002
+ * a cached token for those params exists and is not expired, returns it
5003
+ * synchronously. Otherwise initiates a refresh.
4920
5004
  *
4921
- * @returns {JwtToken<T, ExtraInfo> | Promise<JwtToken<T, ExtraInfo>>} The current token or the Promise of a token request.
5005
+ * @param params - Optional mint parameters. Omit for the legacy parameterless token.
5006
+ * @returns The cached token (sync) or a promise that resolves to the refreshed token.
4922
5007
  */
4923
- getJwt() {
4924
- if (this.inflightPromise) {
4925
- return this.inflightPromise;
5008
+ getJwt(params) {
5009
+ const key = cacheKeyFor(params);
5010
+ const inflight = this.inflightPromises.get(key);
5011
+ if (inflight) {
5012
+ return inflight;
4926
5013
  }
4927
- const token = this.jwtRepository.token;
5014
+ const token = this.jwtRepository.getToken(params);
4928
5015
  if (token === void 0 || token.isExpired) {
4929
- return this.refreshToken();
5016
+ return this.refreshToken(params);
4930
5017
  }
4931
5018
  return token;
4932
5019
  }
4933
5020
  /**
4934
- * Method to refresh a JWT token.
4935
- * If a refresh request is already in progress, it will return the Promise of this request.
4936
- * Otherwise, it will start a new refresh request and return its Promise.
5021
+ * Method to refresh a JWT token for the given mint params.
4937
5022
  *
4938
- * @returns {Promise<JwtToken<T, ExtraInfo>>} Promise of the refreshed token.
5023
+ * @param params - Optional mint parameters. Omit for the legacy parameterless token.
5024
+ * @returns Promise of the refreshed token.
4939
5025
  */
4940
- refreshToken() {
4941
- if (this.inflightPromise === void 0) {
4942
- this.inflightPromise = new Promise((resolve, reject) => {
4943
- this.resolver.getJwt().then(({ jwt, extraInfo }) => {
4944
- this.inflightPromise = void 0;
4945
- const token = this.jwtRepository.setToken(jwt, extraInfo);
4946
- resolve(token);
4947
- }).catch((reason) => {
4948
- this.inflightPromise = void 0;
4949
- reject(reason);
4950
- });
5026
+ refreshToken(params) {
5027
+ const key = cacheKeyFor(params);
5028
+ const existing = this.inflightPromises.get(key);
5029
+ if (existing !== void 0) {
5030
+ return existing;
5031
+ }
5032
+ const resolverPromise = params === void 0 ? this.resolver.getJwt() : this.resolver.getJwt(params);
5033
+ const promise = new Promise((resolve, reject) => {
5034
+ resolverPromise.then(({ jwt, extraInfo }) => {
5035
+ this.inflightPromises.delete(key);
5036
+ const token = this.jwtRepository.setToken(jwt, extraInfo, params);
5037
+ resolve(token);
5038
+ }).catch((reason) => {
5039
+ this.inflightPromises.delete(key);
5040
+ reject(reason);
4951
5041
  });
4952
- }
4953
- return this.inflightPromise;
5042
+ });
5043
+ this.inflightPromises.set(key, promise);
5044
+ return promise;
4954
5045
  }
4955
5046
  /**
4956
- * Method to check if a token refresh is in progress.
5047
+ * Method to check if any token refresh is in progress.
4957
5048
  *
4958
- * @returns {boolean} true if a token refresh is in progress, false otherwise.
5049
+ * @returns {boolean} true if at least one refresh is in flight, false otherwise.
4959
5050
  */
4960
5051
  get isRefreshingToken() {
4961
- return this.inflightPromise !== void 0;
5052
+ return this.inflightPromises.size > 0;
4962
5053
  }
4963
5054
  }
4964
5055
 
@@ -4976,9 +5067,18 @@ function buildServiceDescriptor(interceptors = {
4976
5067
  return {
4977
5068
  type: "fetch",
4978
5069
  version: "1.0",
4979
- service: function(...args) {
5070
+ service: function(input, init) {
4980
5071
  var _a;
4981
- const context = (_a = interceptors.createContext) == null ? void 0 : _a.call(interceptors);
5072
+ let contextSeed;
5073
+ let cleanInit = init;
5074
+ if (init !== void 0 && "__contextSeed" in init) {
5075
+ const { __contextSeed, ...initWithoutSeed } = init;
5076
+ contextSeed = __contextSeed;
5077
+ cleanInit = Object.keys(initWithoutSeed).length === 0 ? void 0 : initWithoutSeed;
5078
+ }
5079
+ const fetchArgs = cleanInit === void 0 ? [input] : [input, cleanInit];
5080
+ const baseContext = (_a = interceptors.createContext) == null ? void 0 : _a.call(interceptors);
5081
+ const context = contextSeed === void 0 ? baseContext : { ...baseContext, ...contextSeed };
4982
5082
  const {
4983
5083
  request: requestInterceptors = [],
4984
5084
  retry: retryInterceptor = void 0,
@@ -4986,17 +5086,17 @@ function buildServiceDescriptor(interceptors = {
4986
5086
  finally: finallyInterceptors = []
4987
5087
  } = interceptors;
4988
5088
  const pending = requestInterceptors.reduce(
4989
- (previousPromise, interceptor) => previousPromise.then((args2) => interceptor(args2, context)),
4990
- resolvedPromiseLike$2(args)
5089
+ (previousPromise, interceptor) => previousPromise.then((args) => interceptor(args, context)),
5090
+ resolvedPromiseLike$2(fetchArgs)
4991
5091
  );
4992
- return Promise.resolve(pending).then((args2) => {
5092
+ return Promise.resolve(pending).then((args) => {
4993
5093
  if (retryInterceptor) {
4994
- return retryInterceptor(args2, retryService, context);
5094
+ return retryInterceptor(args, retryService, context);
4995
5095
  } else {
4996
5096
  if (retryService) {
4997
- return retryService.applyRetry(() => fetch(...args2));
5097
+ return retryService.applyRetry(() => fetch(...args));
4998
5098
  }
4999
- return fetch(...args2);
5099
+ return fetch(...args);
5000
5100
  }
5001
5101
  }).then((response) => {
5002
5102
  return responseInterceptors.reduce(
@@ -5329,4 +5429,4 @@ withDefaultLuvio((luvio) => {
5329
5429
  ];
5330
5430
  setServices(services);
5331
5431
  });
5332
- // version: 1.428.0-dev10-1e665d263f
5432
+ // version: 1.428.0-dev12-1c6599e2b3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-webruntime",
3
- "version": "1.428.0-dev10",
3
+ "version": "1.428.0-dev12",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Webruntime runtime",
6
6
  "main": "dist/ldsWebruntimeOneStoreInit.js",
@@ -35,46 +35,46 @@
35
35
  "ready": "yarn build && jest --collectCoverage && yarn test:size && yarn release:corejar"
36
36
  },
37
37
  "devDependencies": {
38
- "@conduit-client/service-provisioner": "3.18.1-dev2",
39
- "@conduit-client/tools-core": "3.18.1-dev2",
38
+ "@conduit-client/service-provisioner": "3.19.0-dev3",
39
+ "@conduit-client/tools-core": "3.19.0-dev3",
40
40
  "jwt-encode": "1.0.1"
41
41
  },
42
42
  "dependencies": {
43
- "@conduit-client/command-aura-network": "3.18.1-dev2",
44
- "@conduit-client/command-aura-normalized-cache-control": "3.18.1-dev2",
45
- "@conduit-client/command-aura-resource-cache-control": "3.18.1-dev2",
46
- "@conduit-client/command-fetch-network": "3.18.1-dev2",
47
- "@conduit-client/command-http-normalized-cache-control": "3.18.1-dev2",
48
- "@conduit-client/command-ndjson": "3.18.1-dev2",
49
- "@conduit-client/command-network": "3.18.1-dev2",
50
- "@conduit-client/command-sse": "3.18.1-dev2",
51
- "@conduit-client/command-streaming": "3.18.1-dev2",
52
- "@conduit-client/jwt-manager": "3.18.1-dev2",
53
- "@conduit-client/service-aura-network": "3.18.1-dev2",
54
- "@conduit-client/service-bindings-imperative": "3.18.1-dev2",
55
- "@conduit-client/service-bindings-lwc": "3.18.1-dev2",
56
- "@conduit-client/service-cache": "3.18.1-dev2",
57
- "@conduit-client/service-cache-control": "3.18.1-dev2",
58
- "@conduit-client/service-cache-inclusion-policy": "3.18.1-dev2",
59
- "@conduit-client/service-fetch-network": "3.18.1-dev2",
60
- "@conduit-client/service-instrument-command": "3.18.1-dev2",
61
- "@conduit-client/service-pubsub": "3.18.1-dev2",
62
- "@conduit-client/service-store": "3.18.1-dev2",
63
- "@conduit-client/utils": "3.18.1-dev2",
43
+ "@conduit-client/command-aura-network": "3.19.0-dev3",
44
+ "@conduit-client/command-aura-normalized-cache-control": "3.19.0-dev3",
45
+ "@conduit-client/command-aura-resource-cache-control": "3.19.0-dev3",
46
+ "@conduit-client/command-fetch-network": "3.19.0-dev3",
47
+ "@conduit-client/command-http-normalized-cache-control": "3.19.0-dev3",
48
+ "@conduit-client/command-ndjson": "3.19.0-dev3",
49
+ "@conduit-client/command-network": "3.19.0-dev3",
50
+ "@conduit-client/command-sse": "3.19.0-dev3",
51
+ "@conduit-client/command-streaming": "3.19.0-dev3",
52
+ "@conduit-client/jwt-manager": "3.19.0-dev3",
53
+ "@conduit-client/service-aura-network": "3.19.0-dev3",
54
+ "@conduit-client/service-bindings-imperative": "3.19.0-dev3",
55
+ "@conduit-client/service-bindings-lwc": "3.19.0-dev3",
56
+ "@conduit-client/service-cache": "3.19.0-dev3",
57
+ "@conduit-client/service-cache-control": "3.19.0-dev3",
58
+ "@conduit-client/service-cache-inclusion-policy": "3.19.0-dev3",
59
+ "@conduit-client/service-fetch-network": "3.19.0-dev3",
60
+ "@conduit-client/service-instrument-command": "3.19.0-dev3",
61
+ "@conduit-client/service-pubsub": "3.19.0-dev3",
62
+ "@conduit-client/service-store": "3.19.0-dev3",
63
+ "@conduit-client/utils": "3.19.0-dev3",
64
64
  "@luvio/network-adapter-composable": "0.160.3",
65
65
  "@luvio/network-adapter-fetch": "0.160.3",
66
66
  "@salesforce/lds-adapters-uiapi-lex": "^1.415.0",
67
- "@salesforce/lds-default-luvio": "^1.428.0-dev10",
68
- "@salesforce/lds-luvio-service": "^1.428.0-dev10",
69
- "@salesforce/lds-luvio-uiapi-records-service": "^1.428.0-dev10"
67
+ "@salesforce/lds-default-luvio": "^1.428.0-dev12",
68
+ "@salesforce/lds-luvio-service": "^1.428.0-dev12",
69
+ "@salesforce/lds-luvio-uiapi-records-service": "^1.428.0-dev12"
70
70
  },
71
71
  "luvioBundlesize": [
72
72
  {
73
73
  "path": "./dist/ldsWebruntimeOneStoreInit.js",
74
74
  "maxSize": {
75
- "none": "165.00 kB",
76
- "min": "85 kB",
77
- "compressed": "25.50 kB"
75
+ "none": "167.00 kB",
76
+ "min": "86 kB",
77
+ "compressed": "27 kB"
78
78
  }
79
79
  }
80
80
  ],