@hexclave/js 1.0.73 → 1.0.74

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 (108) hide show
  1. package/dist/{admin-app-impl-BVMjDLZU.d.ts → admin-app-impl-BgUMxiV3.d.ts} +10 -4
  2. package/dist/admin-app-impl-BgUMxiV3.d.ts.map +1 -0
  3. package/dist/clickmap/clickmap-core.d.ts +1 -1
  4. package/dist/clickmap/index.d.ts +1 -1
  5. package/dist/{client-app-D0wv_Di-.d.ts → client-app-WOX3pOo1.d.ts} +11 -3
  6. package/dist/{client-app-D0wv_Di-.d.ts.map → client-app-WOX3pOo1.d.ts.map} +1 -1
  7. package/dist/dev-tool/dev-tool-core.d.ts +1 -1
  8. package/dist/dev-tool/index.d.ts +1 -1
  9. package/dist/esm/lib/auth.d.ts.map +1 -1
  10. package/dist/esm/lib/auth.js +1 -1
  11. package/dist/esm/lib/auth.js.map +1 -1
  12. package/dist/esm/lib/auth.test.js +2 -2
  13. package/dist/esm/lib/auth.test.js.map +1 -1
  14. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +3 -0
  15. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
  16. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.d.ts +1 -0
  17. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.js +102 -0
  18. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.js.map +1 -0
  19. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +57 -1
  20. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
  21. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +5 -2
  22. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts.map +1 -1
  23. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js +44 -12
  24. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
  25. package/dist/esm/lib/hexclave-app/apps/implementations/common.js +2 -2
  26. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.d.ts +13 -1
  27. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.d.ts.map +1 -1
  28. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.js +15 -1
  29. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.js.map +1 -1
  30. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.test.js +25 -1
  31. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.test.js.map +1 -1
  32. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.d.ts +1 -0
  33. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.d.ts.map +1 -1
  34. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.js +67 -12
  35. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.js.map +1 -1
  36. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.test.d.ts +1 -0
  37. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.test.js +87 -0
  38. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.test.js.map +1 -0
  39. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.d.ts +9 -1
  40. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.d.ts.map +1 -1
  41. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.js.map +1 -1
  42. package/dist/esm/utils/url.js +10 -2
  43. package/dist/esm/utils/url.js.map +1 -1
  44. package/dist/esm/utils/url.test.d.ts +1 -0
  45. package/dist/esm/utils/url.test.js +28 -0
  46. package/dist/esm/utils/url.test.js.map +1 -0
  47. package/dist/index.d.ts +1 -1
  48. package/dist/lib/auth.d.ts.map +1 -1
  49. package/dist/lib/auth.js +1 -1
  50. package/dist/lib/auth.js.map +1 -1
  51. package/dist/lib/auth.test.js +2 -2
  52. package/dist/lib/auth.test.js.map +1 -1
  53. package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +1 -1
  54. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.d.ts +1 -0
  55. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.js +101 -0
  56. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.js.map +1 -0
  57. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +57 -1
  58. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
  59. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +1 -1
  60. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js +43 -11
  61. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
  62. package/dist/lib/hexclave-app/apps/implementations/common.js +2 -2
  63. package/dist/lib/hexclave-app/apps/implementations/index.d.ts +1 -1
  64. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.d.ts +13 -1
  65. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.d.ts.map +1 -1
  66. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.js +15 -0
  67. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.js.map +1 -1
  68. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.test.js +24 -0
  69. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.test.js.map +1 -1
  70. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.d.ts +1 -1
  71. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.js +67 -12
  72. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.js.map +1 -1
  73. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.test.d.ts +1 -0
  74. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.test.js +86 -0
  75. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.test.js.map +1 -0
  76. package/dist/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -1
  77. package/dist/lib/hexclave-app/apps/index.d.ts +1 -1
  78. package/dist/lib/hexclave-app/apps/interfaces/admin-app.d.ts +1 -1
  79. package/dist/lib/hexclave-app/apps/interfaces/client-app.d.ts +1 -1
  80. package/dist/lib/hexclave-app/apps/interfaces/client-app.js.map +1 -1
  81. package/dist/lib/hexclave-app/apps/interfaces/server-app.d.ts +1 -1
  82. package/dist/lib/hexclave-app/index.d.ts +1 -1
  83. package/dist/lib/hexclave-app/projects/index.d.ts +1 -1
  84. package/dist/lib/hexclave-app/teams/index.d.ts +1 -1
  85. package/dist/lib/hexclave-app/users/index.d.ts +1 -1
  86. package/dist/pushed-config-error-overlay/index.d.ts +1 -1
  87. package/dist/{redirect-page-urls-elbPx2J1.d.ts → redirect-page-urls-Cu5BRQwm.d.ts} +2 -1
  88. package/dist/redirect-page-urls-Cu5BRQwm.d.ts.map +1 -0
  89. package/dist/utils/url.js +10 -2
  90. package/dist/utils/url.js.map +1 -1
  91. package/dist/utils/url.test.d.ts +1 -0
  92. package/dist/utils/url.test.js +27 -0
  93. package/dist/utils/url.test.js.map +1 -0
  94. package/package.json +2 -2
  95. package/src/lib/auth.test.ts +2 -2
  96. package/src/lib/auth.ts +3 -1
  97. package/src/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.ts +126 -0
  98. package/src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts +75 -0
  99. package/src/lib/hexclave-app/apps/implementations/client-app-impl.ts +73 -16
  100. package/src/lib/hexclave-app/apps/implementations/redirect-back-state.test.ts +29 -1
  101. package/src/lib/hexclave-app/apps/implementations/redirect-back-state.ts +17 -0
  102. package/src/lib/hexclave-app/apps/implementations/redirect-page-urls.test.ts +119 -0
  103. package/src/lib/hexclave-app/apps/implementations/redirect-page-urls.ts +104 -12
  104. package/src/lib/hexclave-app/apps/interfaces/client-app.ts +12 -2
  105. package/src/utils/url.test.ts +54 -0
  106. package/src/utils/url.ts +12 -3
  107. package/dist/admin-app-impl-BVMjDLZU.d.ts.map +0 -1
  108. package/dist/redirect-page-urls-elbPx2J1.d.ts.map +0 -1
@@ -13,6 +13,7 @@ import { hexclaveAppInternalsSymbol } from "../../common.js";
13
13
  import { adminProjectCreateOptionsToCrud } from "../../projects/index.js";
14
14
  import { InternalSession } from "@hexclave/shared/dist/sessions";
15
15
  import { Store, storeLock } from "@hexclave/shared/dist/utils/stores";
16
+ import { crossDomainAuthQueryParams, getCrossDomainHandoffParamsFromCurrentUrl, planRedirectToHandler } from "./redirect-page-urls.js";
16
17
  import { parseJson } from "@hexclave/shared/dist/utils/json";
17
18
  import { DependenciesMap } from "@hexclave/shared/dist/utils/maps";
18
19
  import { BotChallengeExecutionFailedError, BotChallengeUserCancelledError, withBotChallengeFlow } from "@hexclave/shared/dist/utils/turnstile-flow";
@@ -27,18 +28,18 @@ import { apiKeyCreationOptionsToCrud } from "../../api-keys/index.js";
27
28
  import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels/index.js";
28
29
  import { teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams/index.js";
29
30
  import { buildCliAuthConfirmUrl, getHostedHandlerUrl, isHostedHandlerUrlForProject, resolveHandlerUrls } from "../../url-targets.js";
30
- import { augmentUrlWithPersistedRedirectBackState, saveRedirectBackStateFromUrl } from "./redirect-back-state.js";
31
+ import { augmentUrlWithPersistedRedirectBackState, getRawAfterAuthReturnTo, saveRedirectBackStateFromUrl } from "./redirect-back-state.js";
31
32
  import { recordRedirectAndThrowIfLoopDetected } from "./redirect-loop-breaker.js";
32
33
  import { scopePasskeyAuthenticationToHostname, scopePasskeyRegistrationToHostname } from "../../passkey-rp-id.js";
33
34
  import { userUpdateOptionsToCrud, withUserDestructureGuard } from "../../users/index.js";
34
35
  import { EventTracker } from "./event-tracker.js";
35
- import { crossDomainAuthQueryParams, getCrossDomainHandoffParamsFromCurrentUrl, planRedirectToHandler } from "./redirect-page-urls.js";
36
36
  import { SessionRecorder, analyticsOptionsFromJson, analyticsOptionsToJson, getSessionReplayOptions } from "./session-replay.js";
37
37
  import { mountClickmapOverlay } from "../../../../clickmap/index.js";
38
38
  import { mountDevTool } from "../../../../dev-tool/index.js";
39
39
  import { mountPushedConfigErrorOverlay } from "../../../../pushed-config-error-overlay/index.js";
40
40
  //#region src/lib/hexclave-app/apps/implementations/client-app-impl.ts
41
41
  const prefetchedCrossDomainHandoffTtlMs = 3300 * 1e3;
42
+ const oauthAfterCallbackRedirectUrlQueryParam = "after_callback_redirect_url";
42
43
  const nestedCrossDomainAuthQueryParams = {
43
44
  refreshTokenId: "stack_nested_cross_domain_auth_refresh_token_id",
44
45
  callbackUrl: "stack_nested_cross_domain_auth_callback_url",
@@ -46,7 +47,7 @@ const nestedCrossDomainAuthQueryParams = {
46
47
  state: "state",
47
48
  codeChallenge: "code_challenge",
48
49
  codeChallengeMethod: "code_challenge_method",
49
- afterCallbackRedirectUrl: "after_callback_redirect_url"
50
+ afterCallbackRedirectUrl: oauthAfterCallbackRedirectUrlQueryParam
50
51
  };
51
52
  function getRedirectHelperInstruction(handlerName) {
52
53
  if (handlerName === "handler") return "Use a page-specific redirect helper such as app.redirectToSignIn() instead.";
@@ -383,15 +384,17 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
383
384
  this._redirectMethod = resolvedOptions.redirectMethod || (isBrowserLike() ? "window" : "none");
384
385
  this._urlOptions = resolvedOptions.urls ?? {};
385
386
  this._oauthScopesOnSignIn = resolvedOptions.oauthScopesOnSignIn ?? {};
387
+ this._analyticsOptions = resolvedOptions.analytics;
388
+ if (extraOptions?.uniqueIdentifier !== void 0) this._uniqueIdentifier = extraOptions.uniqueIdentifier;
389
+ if (resolvedOptions.automaticSideEffects === false) return;
390
+ this._initializeAutomaticSideEffects(resolvedOptions);
391
+ }
392
+ _initializeAutomaticSideEffects(resolvedOptions) {
386
393
  if (isBrowserLike() && (resolvedOptions.tokenStore === "cookie" || resolvedOptions.tokenStore === "nextjs-cookie")) {
387
394
  runAsynchronously(this._trustedParentDomainCache.getOrWait([window.location.hostname], "write-only"));
388
395
  this._ensureCrossSubdomainCookieExists();
389
396
  }
390
- if (extraOptions && extraOptions.uniqueIdentifier) {
391
- this._uniqueIdentifier = extraOptions.uniqueIdentifier;
392
- this._initUniqueIdentifier();
393
- }
394
- this._analyticsOptions = resolvedOptions.analytics;
397
+ if (this._uniqueIdentifier !== void 0) this._initUniqueIdentifier();
395
398
  const getAnalyticsSession = async () => {
396
399
  this._ensurePersistentTokenStore();
397
400
  if (await this.getPartialUser({
@@ -502,9 +505,24 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
502
505
  }
503
506
  async _redirectToOAuthCallbackError(error) {
504
507
  const errorUrl = new URL(this._getUrls().error, window.location.href);
508
+ const callbackUrl = augmentUrlWithPersistedRedirectBackState({
509
+ currentUrl: new URL(window.location.href),
510
+ projectId: this.projectId
511
+ });
505
512
  errorUrl.searchParams.set("errorCode", error.errorCode);
506
513
  errorUrl.searchParams.set("message", error.message);
507
514
  errorUrl.searchParams.set("details", JSON.stringify(error.details ?? {}));
515
+ for (const paramName of [
516
+ "after_auth_return_to",
517
+ crossDomainAuthQueryParams.state,
518
+ crossDomainAuthQueryParams.codeChallenge,
519
+ crossDomainAuthQueryParams.afterCallbackRedirectUrl
520
+ ]) {
521
+ const value = callbackUrl.searchParams.get(paramName);
522
+ if (value != null) errorUrl.searchParams.set(paramName, value);
523
+ }
524
+ const afterCallbackRedirectUrl = callbackUrl.searchParams.get(oauthAfterCallbackRedirectUrlQueryParam);
525
+ if (afterCallbackRedirectUrl != null) errorUrl.searchParams.set(oauthAfterCallbackRedirectUrlQueryParam, afterCallbackRedirectUrl);
508
526
  await this._redirectIfTrusted(errorUrl.toString(), { replace: true });
509
527
  }
510
528
  async _handleHostedOAuthCallbackDuringStartup() {
@@ -1724,7 +1742,8 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
1724
1742
  projectId: forProjectId,
1725
1743
  tokenStore: null,
1726
1744
  projectOwnerSession: session,
1727
- noAutomaticPrefetch: true
1745
+ noAutomaticPrefetch: true,
1746
+ automaticSideEffects: false
1728
1747
  }));
1729
1748
  return this._ownedAdminApps.get([session, forProjectId]);
1730
1749
  }
@@ -1934,10 +1953,12 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
1934
1953
  });
1935
1954
  }
1936
1955
  async _getRedirectToHandlerUrl(handlerName, options, internalOptions) {
1937
- const rawHandlerUrl = getUrls(this._urlOptions, { projectId: this.projectId })[handlerName];
1956
+ const rawUrls = getUrls(this._urlOptions, { projectId: this.projectId });
1957
+ const rawHandlerUrl = rawUrls[handlerName];
1938
1958
  if (!rawHandlerUrl) throw new Error(`No URL for handler name ${handlerName}`);
1939
1959
  let currentUrl = typeof window === "undefined" ? null : new URL(window.location.href);
1940
- if (currentUrl != null && options?.noRedirectBack !== true && (handlerName === "afterSignIn" || handlerName === "afterSignUp")) currentUrl = augmentUrlWithPersistedRedirectBackState({
1960
+ const shouldRestorePersistedRedirectBackState = options?.noRedirectBack !== true && (handlerName === "afterSignIn" || handlerName === "afterSignUp") || handlerName === "forgotPassword" || handlerName === "passwordReset" || handlerName === "signIn" && options?.noRedirectBack === true;
1961
+ if (currentUrl != null && shouldRestorePersistedRedirectBackState) currentUrl = augmentUrlWithPersistedRedirectBackState({
1941
1962
  currentUrl,
1942
1963
  projectId: this.projectId
1943
1964
  });
@@ -1947,6 +1968,7 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
1947
1968
  noRedirectBack: options?.noRedirectBack === true,
1948
1969
  currentUrl,
1949
1970
  localOAuthCallbackUrl: this._getLocalOAuthCallbackHandlerUrl(),
1971
+ rawHomeUrl: rawUrls.home,
1950
1972
  getCrossDomainHandoffParams: async (href) => await this._getCrossDomainHandoffParamsForRedirect(href)
1951
1973
  });
1952
1974
  if (plan.type === "cross-domain-authorize") return await this._createCrossDomainAuthRedirectUrl({
@@ -2558,13 +2580,15 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2558
2580
  return clientApp;
2559
2581
  }
2560
2582
  const { analytics, ...restJson } = omit(json, ["uniqueIdentifier"]);
2561
- return new _HexclaveClientAppImplIncomplete({
2583
+ const app = new _HexclaveClientAppImplIncomplete({
2562
2584
  ...restJson,
2563
2585
  analytics: analyticsOptionsFromJson(analytics)
2564
2586
  }, {
2565
2587
  uniqueIdentifier: json.uniqueIdentifier,
2566
2588
  checkString: providedCheckString
2567
2589
  });
2590
+ if (json.automaticSideEffects === false) app._initUniqueIdentifier();
2591
+ return app;
2568
2592
  } };
2569
2593
  }
2570
2594
  get [hexclaveAppInternalsSymbol]() {
@@ -2583,6 +2607,7 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2583
2607
  redirectMethod: this._redirectMethod,
2584
2608
  extraRequestHeaders: this._options.extraRequestHeaders,
2585
2609
  devTool: this._options.devTool,
2610
+ automaticSideEffects: this._options.automaticSideEffects,
2586
2611
  analytics: analyticsOptionsToJson(this._analyticsOptions)
2587
2612
  };
2588
2613
  },
@@ -2618,6 +2643,13 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2618
2643
  redirectToHandler: async (handlerName, options) => {
2619
2644
  await this._redirectToHandler(handlerName, options);
2620
2645
  },
2646
+ getRawAfterAuthReturnTo: () => {
2647
+ if (typeof window === "undefined") return null;
2648
+ return getRawAfterAuthReturnTo({
2649
+ currentUrl: new URL(window.location.href),
2650
+ projectId: this.projectId
2651
+ });
2652
+ },
2621
2653
  refreshOwnedProjects: async () => {
2622
2654
  await this._refreshOwnedProjects(await this._getSession());
2623
2655
  },