@dvina/sdk 4.0.221 → 4.0.232

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.
Files changed (31) hide show
  1. package/dist/adapters/angular/index.cjs +4 -4
  2. package/dist/adapters/angular/index.d.cts +2 -2
  3. package/dist/adapters/angular/index.d.ts +2 -2
  4. package/dist/adapters/angular/index.js +2 -2
  5. package/dist/billing/index.cjs +5 -5
  6. package/dist/billing/index.js +1 -1
  7. package/dist/{chunk-VDPZQ5F3.cjs → chunk-4Y42KQCH.cjs} +22 -68
  8. package/dist/chunk-4Y42KQCH.cjs.map +1 -0
  9. package/dist/{chunk-ZGGY4WK7.js → chunk-RVXRT5EI.js} +22 -68
  10. package/dist/chunk-RVXRT5EI.js.map +1 -0
  11. package/dist/{chunk-LNQAR2M2.cjs → chunk-SXCZIX2Z.cjs} +187 -35
  12. package/dist/chunk-SXCZIX2Z.cjs.map +1 -0
  13. package/dist/{chunk-I7HS5CQ7.js → chunk-YXGWZRDY.js} +165 -13
  14. package/dist/chunk-YXGWZRDY.js.map +1 -0
  15. package/dist/{client-BAich_Hx.d.cts → client-DI2pYavC.d.cts} +1 -1
  16. package/dist/{client-DW2pRGde.d.ts → client-DRZeTTgS.d.ts} +1 -1
  17. package/dist/{index-DF59UYzN.d.cts → index-Bwe8KY0Z.d.cts} +1 -1
  18. package/dist/{index-Bld5-Yr1.d.ts → index-DqQrAjp3.d.ts} +1 -1
  19. package/dist/index.cjs +390 -390
  20. package/dist/index.d.cts +10 -10
  21. package/dist/index.d.ts +10 -10
  22. package/dist/index.js +2 -2
  23. package/dist/pagination/index.d.cts +2 -2
  24. package/dist/pagination/index.d.ts +2 -2
  25. package/dist/{sync-engine-CZ0U9XBy.d.ts → sync-engine-CYIG5amb.d.ts} +5 -2
  26. package/dist/{sync-engine-DXESBFX0.d.cts → sync-engine-DPVgCDPC.d.cts} +5 -2
  27. package/package.json +1 -1
  28. package/dist/chunk-I7HS5CQ7.js.map +0 -1
  29. package/dist/chunk-LNQAR2M2.cjs.map +0 -1
  30. package/dist/chunk-VDPZQ5F3.cjs.map +0 -1
  31. package/dist/chunk-ZGGY4WK7.js.map +0 -1
@@ -851,44 +851,11 @@ function hasMultilineItems(maybeArray) {
851
851
  }
852
852
 
853
853
  // src/transport/core/token-refresh.ts
854
- var REFRESH_FAILURE_COOLDOWN_MS = 6e4;
855
854
  var inFlightRefreshes = /* @__PURE__ */ new WeakMap();
856
- var recentRefreshFailures = /* @__PURE__ */ new WeakMap();
857
- function getBlockedRefreshError(getToken) {
858
- const recentFailure = recentRefreshFailures.get(getToken);
859
- if (!recentFailure) {
860
- return void 0;
861
- }
862
- if (recentFailure.retryAt <= Date.now()) {
863
- recentRefreshFailures.delete(getToken);
864
- return void 0;
865
- }
866
- return recentFailure.error;
867
- }
868
- function rememberRefreshFailure(getToken, error) {
869
- const normalizedError = error instanceof Error ? error : new DvinaAuthenticationError("Token refresh failed unexpectedly");
870
- recentRefreshFailures.set(getToken, {
871
- error: normalizedError,
872
- retryAt: Date.now() + REFRESH_FAILURE_COOLDOWN_MS
873
- });
874
- return normalizedError;
875
- }
876
- function clearRefreshFailure(getToken) {
877
- recentRefreshFailures.delete(getToken);
878
- }
879
855
  async function refreshTokenSingleFlight(getToken, failedToken) {
880
- const blockedError = getBlockedRefreshError(getToken);
881
- if (blockedError) {
882
- throw blockedError;
883
- }
884
856
  let inFlight = inFlightRefreshes.get(getToken);
885
857
  if (!inFlight) {
886
- const refreshPromise = getToken({ forceRefresh: true }).then((token) => {
887
- clearRefreshFailure(getToken);
888
- return token;
889
- }).catch((error) => {
890
- throw rememberRefreshFailure(getToken, error);
891
- }).finally(() => {
858
+ const refreshPromise = getToken({ forceRefresh: true }).finally(() => {
892
859
  if (inFlightRefreshes.get(getToken) === refreshPromise) {
893
860
  inFlightRefreshes.delete(getToken);
894
861
  }
@@ -898,12 +865,8 @@ async function refreshTokenSingleFlight(getToken, failedToken) {
898
865
  }
899
866
  const refreshedToken = await inFlight;
900
867
  if (failedToken && refreshedToken === failedToken) {
901
- throw rememberRefreshFailure(
902
- getToken,
903
- new DvinaAuthenticationError("Token refresh did not produce a new token", failedToken)
904
- );
868
+ throw new DvinaAuthenticationError("Token refresh did not produce a new token", failedToken);
905
869
  }
906
- clearRefreshFailure(getToken);
907
870
  return refreshedToken;
908
871
  }
909
872
 
@@ -984,17 +947,13 @@ async function doFetch(options, document, variables) {
984
947
  var MAX_RETRIES = 4;
985
948
  var RETRY_DELAY_MS = 1e3;
986
949
  function createHttpTransport(options) {
987
- const refreshState = {
988
- isRefreshing: false,
989
- pendingRequests: []
990
- };
991
950
  async function requestWithRetry(document, variables, attempt = 0) {
992
951
  let fetchResult;
993
952
  try {
994
953
  fetchResult = await doFetch(options, document, variables);
995
954
  } catch (error) {
996
955
  if (error instanceof DvinaAuthenticationError) {
997
- return handleAuthRefresh(document, variables, refreshState, options, error.failedToken);
956
+ return handleAuthRefresh(document, variables, options, error.failedToken);
998
957
  }
999
958
  if (error instanceof DvinaNetworkError && error.status === 0 && attempt < MAX_RETRIES) {
1000
959
  await sleep(RETRY_DELAY_MS * (attempt + 1));
@@ -1005,7 +964,7 @@ function createHttpTransport(options) {
1005
964
  }
1006
965
  const { response: result, usedToken } = fetchResult;
1007
966
  if (isAuthError(result.errors)) {
1008
- return handleAuthRefresh(document, variables, refreshState, options, usedToken);
967
+ return handleAuthRefresh(document, variables, options, usedToken);
1009
968
  }
1010
969
  if (result.errors?.length && !result.data) {
1011
970
  const error = createGraphQLError(result.errors, printDocument(document), variables);
@@ -1027,27 +986,14 @@ function createHttpTransport(options) {
1027
986
  request: (document, variables) => requestWithRetry(document, variables)
1028
987
  };
1029
988
  }
1030
- async function handleAuthRefresh(document, variables, refreshState, options, failedToken) {
1031
- if (!refreshState.isRefreshing) {
1032
- refreshState.isRefreshing = true;
1033
- try {
1034
- await refreshTokenSingleFlight(options.getToken, failedToken);
1035
- refreshState.pendingRequests.forEach((req) => req.resolve());
1036
- refreshState.pendingRequests = [];
1037
- refreshState.isRefreshing = false;
1038
- } catch {
1039
- const error = new DvinaAuthenticationError("Token refresh failed");
1040
- options.onError?.(error);
1041
- refreshState.pendingRequests.forEach((req) => req.reject(error));
1042
- refreshState.pendingRequests = [];
1043
- refreshState.isRefreshing = false;
1044
- throw error;
1045
- }
1046
- return retryAfterRefresh(options, document, variables);
989
+ async function handleAuthRefresh(document, variables, options, failedToken) {
990
+ try {
991
+ await refreshTokenSingleFlight(options.getToken, failedToken);
992
+ } catch {
993
+ const error = new DvinaAuthenticationError("Token refresh failed");
994
+ options.onError?.(error);
995
+ throw error;
1047
996
  }
1048
- await new Promise((resolve, reject) => {
1049
- refreshState.pendingRequests.push({ resolve, reject });
1050
- });
1051
997
  return retryAfterRefresh(options, document, variables);
1052
998
  }
1053
999
  async function retryAfterRefresh(options, document, variables) {
@@ -1221,6 +1167,14 @@ var ConnectionSupervisor = class {
1221
1167
  }
1222
1168
  handleFailure(error) {
1223
1169
  this.lastError = error;
1170
+ if (error instanceof DvinaAuthenticationError) {
1171
+ this.shouldRun = false;
1172
+ this.clearReconnectTimer();
1173
+ this.clearStaleTimer();
1174
+ this.setState("failed");
1175
+ this.options.onFatalError?.(error);
1176
+ return;
1177
+ }
1224
1178
  const isAuthError2 = this.options.isAuthError?.(error) ?? false;
1225
1179
  if (isAuthError2) {
1226
1180
  this.consecutiveAuthFailures += 1;
@@ -1351,7 +1305,7 @@ async function consumeSseStream(body, signal, handlers) {
1351
1305
  var INITIAL_RECONNECT_DELAY_MS = 1e3;
1352
1306
  var MAX_RECONNECT_DELAY_MS = 3e4;
1353
1307
  var MAX_CONSECUTIVE_AUTH_FAILURES = 3;
1354
- var STALE_CONNECTION_TIMEOUT_MS = 6e4;
1308
+ var STALE_CONNECTION_TIMEOUT_MS = 35e3;
1355
1309
  var BillingAuthStreamError = class extends Error {
1356
1310
  constructor(status) {
1357
1311
  super(`Billing SSE auth failed: ${status}`);
@@ -1638,5 +1592,5 @@ var BillingClient = class {
1638
1592
  };
1639
1593
 
1640
1594
  export { BillingClient, EntitlementTier, Kind, SubscriptionCycle, SubscriptionProvider, createHttpTransport, print, refreshTokenSingleFlight };
1641
- //# sourceMappingURL=chunk-ZGGY4WK7.js.map
1642
- //# sourceMappingURL=chunk-ZGGY4WK7.js.map
1595
+ //# sourceMappingURL=chunk-RVXRT5EI.js.map
1596
+ //# sourceMappingURL=chunk-RVXRT5EI.js.map