@stackframe/stack 2.8.56 → 2.8.59
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.
- package/dist/components/api-key-dialogs.js.map +1 -1
- package/dist/components/api-key-table.js.map +1 -1
- package/dist/components/credential-sign-in.js.map +1 -1
- package/dist/components/credential-sign-up.js.map +1 -1
- package/dist/components/elements/form-warning.js.map +1 -1
- package/dist/components/elements/maybe-full-page.js.map +1 -1
- package/dist/components/elements/separator-with-text.js.map +1 -1
- package/dist/components/elements/sidebar-layout.js.map +1 -1
- package/dist/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/components/elements/user-avatar.js.map +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/magic-link-sign-in.js.map +1 -1
- package/dist/components/message-cards/known-error-message-card.js.map +1 -1
- package/dist/components/message-cards/message-card.js.map +1 -1
- package/dist/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/components/oauth-button-group.js.map +1 -1
- package/dist/components/oauth-button.js.map +1 -1
- package/dist/components/passkey-button.js.map +1 -1
- package/dist/components/profile-image-editor.js.map +1 -1
- package/dist/components/selected-team-switcher.js.map +1 -1
- package/dist/components/team-icon.js.map +1 -1
- package/dist/components/team-switcher.js.map +1 -1
- package/dist/components/use-in-iframe.js.map +1 -1
- package/dist/components/user-button.js.map +1 -1
- package/dist/components-page/account-settings/active-sessions/active-sessions-page.js.map +1 -1
- package/dist/components-page/account-settings/api-keys/api-keys-page.js.map +1 -1
- package/dist/components-page/account-settings/editable-text.js.map +1 -1
- package/dist/components-page/account-settings/email-and-auth/email-and-auth-page.js.map +1 -1
- package/dist/components-page/account-settings/email-and-auth/emails-section.js +4 -3
- package/dist/components-page/account-settings/email-and-auth/emails-section.js.map +1 -1
- package/dist/components-page/account-settings/email-and-auth/mfa-section.js.map +1 -1
- package/dist/components-page/account-settings/email-and-auth/otp-section.js.map +1 -1
- package/dist/components-page/account-settings/email-and-auth/passkey-section.js.map +1 -1
- package/dist/components-page/account-settings/email-and-auth/password-section.js.map +1 -1
- package/dist/components-page/account-settings/notifications/notifications-page.js.map +1 -1
- package/dist/components-page/account-settings/page-layout.js.map +1 -1
- package/dist/components-page/account-settings/payments/payments-page.js +79 -0
- package/dist/components-page/account-settings/payments/payments-page.js.map +1 -0
- package/dist/components-page/account-settings/payments/payments-panel.js +374 -0
- package/dist/components-page/account-settings/payments/payments-panel.js.map +1 -0
- package/dist/components-page/account-settings/profile-page/profile-page.js.map +1 -1
- package/dist/components-page/account-settings/section.js.map +1 -1
- package/dist/components-page/account-settings/settings/delete-account-section.js.map +1 -1
- package/dist/components-page/account-settings/settings/settings-page.js.map +1 -1
- package/dist/components-page/account-settings/settings/sign-out-section.js.map +1 -1
- package/dist/components-page/account-settings/teams/leave-team-section.js.map +1 -1
- package/dist/components-page/account-settings/teams/team-api-keys-section.js.map +1 -1
- package/dist/components-page/account-settings/teams/team-creation-page.js.map +1 -1
- package/dist/components-page/account-settings/teams/team-display-name-section.js.map +1 -1
- package/dist/components-page/account-settings/teams/team-member-invitation-section.js.map +1 -1
- package/dist/components-page/account-settings/teams/team-member-list-section.js.map +1 -1
- package/dist/components-page/account-settings/teams/team-page.js.map +1 -1
- package/dist/components-page/account-settings/teams/team-profile-image-section.js.map +1 -1
- package/dist/components-page/account-settings/teams/team-profile-user-section.js.map +1 -1
- package/dist/components-page/account-settings.js +22 -2
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/cli-auth-confirm.js.map +1 -1
- package/dist/components-page/email-verification.js.map +1 -1
- package/dist/components-page/error-page.js.map +1 -1
- package/dist/components-page/forgot-password.js.map +1 -1
- package/dist/components-page/magic-link-callback.js.map +1 -1
- package/dist/components-page/mfa.js.map +1 -1
- package/dist/components-page/oauth-callback.js.map +1 -1
- package/dist/components-page/onboarding.js +170 -0
- package/dist/components-page/onboarding.js.map +1 -0
- package/dist/components-page/password-reset.js.map +1 -1
- package/dist/components-page/section.js.map +1 -1
- package/dist/components-page/sign-in.js.map +1 -1
- package/dist/components-page/sign-out.js.map +1 -1
- package/dist/components-page/sign-up.js.map +1 -1
- package/dist/components-page/stack-handler-client.js +13 -1
- package/dist/components-page/stack-handler-client.js.map +1 -1
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/components-page/team-creation.js.map +1 -1
- package/dist/components-page/team-invitation.js +15 -1
- package/dist/components-page/team-invitation.js.map +1 -1
- package/dist/esm/components/api-key-dialogs.js.map +1 -1
- package/dist/esm/components/api-key-table.js.map +1 -1
- package/dist/esm/components/credential-sign-in.js.map +1 -1
- package/dist/esm/components/credential-sign-up.js.map +1 -1
- package/dist/esm/components/elements/form-warning.js.map +1 -1
- package/dist/esm/components/elements/maybe-full-page.js.map +1 -1
- package/dist/esm/components/elements/separator-with-text.js.map +1 -1
- package/dist/esm/components/elements/sidebar-layout.js.map +1 -1
- package/dist/esm/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/esm/components/elements/user-avatar.js.map +1 -1
- package/dist/esm/components/link.js.map +1 -1
- package/dist/esm/components/magic-link-sign-in.js.map +1 -1
- package/dist/esm/components/message-cards/known-error-message-card.js.map +1 -1
- package/dist/esm/components/message-cards/message-card.js.map +1 -1
- package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/esm/components/oauth-button-group.js.map +1 -1
- package/dist/esm/components/oauth-button.js.map +1 -1
- package/dist/esm/components/passkey-button.js.map +1 -1
- package/dist/esm/components/profile-image-editor.js.map +1 -1
- package/dist/esm/components/selected-team-switcher.js.map +1 -1
- package/dist/esm/components/team-icon.js.map +1 -1
- package/dist/esm/components/team-switcher.js.map +1 -1
- package/dist/esm/components/use-in-iframe.js.map +1 -1
- package/dist/esm/components/user-button.js.map +1 -1
- package/dist/esm/components-page/account-settings/active-sessions/active-sessions-page.js.map +1 -1
- package/dist/esm/components-page/account-settings/api-keys/api-keys-page.js.map +1 -1
- package/dist/esm/components-page/account-settings/editable-text.js.map +1 -1
- package/dist/esm/components-page/account-settings/email-and-auth/email-and-auth-page.js.map +1 -1
- package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js +4 -3
- package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/email-and-auth/mfa-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/email-and-auth/otp-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/email-and-auth/passkey-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/email-and-auth/password-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/notifications/notifications-page.js.map +1 -1
- package/dist/esm/components-page/account-settings/page-layout.js.map +1 -1
- package/dist/esm/components-page/account-settings/payments/payments-page.js +55 -0
- package/dist/esm/components-page/account-settings/payments/payments-page.js.map +1 -0
- package/dist/esm/components-page/account-settings/payments/payments-panel.js +350 -0
- package/dist/esm/components-page/account-settings/payments/payments-panel.js.map +1 -0
- package/dist/esm/components-page/account-settings/profile-page/profile-page.js.map +1 -1
- package/dist/esm/components-page/account-settings/section.js.map +1 -1
- package/dist/esm/components-page/account-settings/settings/delete-account-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/settings/settings-page.js.map +1 -1
- package/dist/esm/components-page/account-settings/settings/sign-out-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/leave-team-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/team-api-keys-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/team-creation-page.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/team-display-name-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/team-member-invitation-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/team-member-list-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/team-page.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/team-profile-image-section.js.map +1 -1
- package/dist/esm/components-page/account-settings/teams/team-profile-user-section.js.map +1 -1
- package/dist/esm/components-page/account-settings.js +23 -3
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/cli-auth-confirm.js.map +1 -1
- package/dist/esm/components-page/email-verification.js.map +1 -1
- package/dist/esm/components-page/error-page.js.map +1 -1
- package/dist/esm/components-page/forgot-password.js.map +1 -1
- package/dist/esm/components-page/magic-link-callback.js.map +1 -1
- package/dist/esm/components-page/mfa.js.map +1 -1
- package/dist/esm/components-page/oauth-callback.js.map +1 -1
- package/dist/esm/components-page/onboarding.js +146 -0
- package/dist/esm/components-page/onboarding.js.map +1 -0
- package/dist/esm/components-page/password-reset.js.map +1 -1
- package/dist/esm/components-page/section.js.map +1 -1
- package/dist/esm/components-page/sign-in.js.map +1 -1
- package/dist/esm/components-page/sign-out.js.map +1 -1
- package/dist/esm/components-page/sign-up.js.map +1 -1
- package/dist/esm/components-page/stack-handler-client.js +13 -1
- package/dist/esm/components-page/stack-handler-client.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components-page/team-creation.js.map +1 -1
- package/dist/esm/components-page/team-invitation.js +15 -1
- package/dist/esm/components-page/team-invitation.js.map +1 -1
- package/dist/esm/generated/global-css.js +1 -1
- package/dist/esm/generated/global-css.js.map +1 -1
- package/dist/esm/generated/quetzal-translations.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/integrations/convex/component/convex.config.js.map +1 -1
- package/dist/esm/integrations/convex.js.map +1 -1
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/hooks.js.map +1 -1
- package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +235 -0
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +210 -29
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +2 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/index.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +40 -27
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/index.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/common.js.map +1 -1
- package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -1
- package/dist/esm/lib/stack-app/email-templates/index.js.map +1 -1
- package/dist/esm/lib/stack-app/index.js.map +1 -1
- package/dist/esm/lib/stack-app/internal-api-keys/index.js.map +1 -1
- package/dist/esm/lib/stack-app/permissions/index.js.map +1 -1
- package/dist/esm/lib/stack-app/projects/index.js +4 -0
- package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
- package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
- package/dist/esm/lib/stack-app/users/index.js +13 -12
- package/dist/esm/lib/stack-app/users/index.js.map +1 -1
- package/dist/esm/lib/translations.js.map +1 -1
- package/dist/esm/providers/stack-provider-client.js.map +1 -1
- package/dist/esm/providers/stack-provider.js.map +1 -1
- package/dist/esm/providers/theme-provider.js.map +1 -1
- package/dist/esm/providers/translation-provider-client.js.map +1 -1
- package/dist/esm/providers/translation-provider.js.map +1 -1
- package/dist/esm/utils/browser-script.js.map +1 -1
- package/dist/esm/utils/constants.js.map +1 -1
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/generated/global-css.js +1 -1
- package/dist/generated/global-css.js.map +1 -1
- package/dist/generated/quetzal-translations.js.map +1 -1
- package/dist/index.d.mts +306 -17
- package/dist/index.d.ts +306 -17
- package/dist/index.js.map +1 -1
- package/dist/integrations/convex/component/convex.config.js.map +1 -1
- package/dist/integrations/convex.js.map +1 -1
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/stack-app/api-keys/index.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +235 -0
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +208 -27
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +2 -1
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/index.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +38 -25
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/index.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/common.js.map +1 -1
- package/dist/lib/stack-app/connected-accounts/index.js.map +1 -1
- package/dist/lib/stack-app/contact-channels/index.js.map +1 -1
- package/dist/lib/stack-app/customers/index.js.map +1 -1
- package/dist/lib/stack-app/data-vault/index.js.map +1 -1
- package/dist/lib/stack-app/email/index.js.map +1 -1
- package/dist/lib/stack-app/email-templates/index.js.map +1 -1
- package/dist/lib/stack-app/index.js.map +1 -1
- package/dist/lib/stack-app/internal-api-keys/index.js.map +1 -1
- package/dist/lib/stack-app/notification-categories/index.js.map +1 -1
- package/dist/lib/stack-app/permissions/index.js.map +1 -1
- package/dist/lib/stack-app/project-configs/index.js.map +1 -1
- package/dist/lib/stack-app/projects/index.js +4 -0
- package/dist/lib/stack-app/projects/index.js.map +1 -1
- package/dist/lib/stack-app/teams/index.js.map +1 -1
- package/dist/lib/stack-app/users/index.js +15 -14
- package/dist/lib/stack-app/users/index.js.map +1 -1
- package/dist/lib/translations.js.map +1 -1
- package/dist/providers/stack-provider-client.js.map +1 -1
- package/dist/providers/stack-provider.js.map +1 -1
- package/dist/providers/theme-provider.js.map +1 -1
- package/dist/providers/translation-provider-client.js.map +1 -1
- package/dist/providers/translation-provider.js.map +1 -1
- package/dist/utils/browser-script.js.map +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/url.js.map +1 -1
- package/package.json +21 -18
- package/CHANGELOG.md +0 -2072
|
@@ -10,7 +10,7 @@ import { parseJson } from "@stackframe/stack-shared/dist/utils/json";
|
|
|
10
10
|
import { DependenciesMap } from "@stackframe/stack-shared/dist/utils/maps";
|
|
11
11
|
import { deepPlainEquals, omit } from "@stackframe/stack-shared/dist/utils/objects";
|
|
12
12
|
import { neverResolve, runAsynchronously, wait } from "@stackframe/stack-shared/dist/utils/promises";
|
|
13
|
-
import { suspend, suspendIfSsr } from "@stackframe/stack-shared/dist/utils/react";
|
|
13
|
+
import { suspend, suspendIfSsr, use } from "@stackframe/stack-shared/dist/utils/react";
|
|
14
14
|
import { Result } from "@stackframe/stack-shared/dist/utils/results";
|
|
15
15
|
import { Store, storeLock } from "@stackframe/stack-shared/dist/utils/stores";
|
|
16
16
|
import { deindent, mergeScopeStrings } from "@stackframe/stack-shared/dist/utils/strings";
|
|
@@ -27,7 +27,7 @@ import { stackAppInternalsSymbol } from "../../common.js";
|
|
|
27
27
|
import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels/index.js";
|
|
28
28
|
import { adminProjectCreateOptionsToCrud } from "../../projects/index.js";
|
|
29
29
|
import { teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams/index.js";
|
|
30
|
-
import {
|
|
30
|
+
import { userUpdateOptionsToCrud, withUserDestructureGuard } from "../../users/index.js";
|
|
31
31
|
import { clientVersion, createCache, createCacheBySession, createEmptyTokenStore, getBaseUrl, getDefaultExtraRequestHeaders, getDefaultProjectId, getDefaultPublishableClientKey, getUrls, resolveConstructorOptions } from "./common.js";
|
|
32
32
|
import { useAsyncCache } from "./common.js";
|
|
33
33
|
import * as sc from "@stackframe/stack-sc";
|
|
@@ -179,6 +179,11 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
179
179
|
}, session);
|
|
180
180
|
}
|
|
181
181
|
);
|
|
182
|
+
this._customerBillingCache = createCacheBySession(
|
|
183
|
+
async (session, [customerType, customerId]) => {
|
|
184
|
+
return await this._interface.getCustomerBilling(customerType, customerId, session);
|
|
185
|
+
}
|
|
186
|
+
);
|
|
182
187
|
this._convexPartialUserCache = createCache(
|
|
183
188
|
async ([ctx]) => await this._getPartialUserFromConvex(ctx)
|
|
184
189
|
);
|
|
@@ -415,7 +420,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
415
420
|
if (!isBrowserLike()) {
|
|
416
421
|
throw new StackAssertionError("Cannot get browser cookies on the server!");
|
|
417
422
|
}
|
|
418
|
-
return cookie.
|
|
423
|
+
return cookie.parseCookie(document.cookie || "");
|
|
419
424
|
}
|
|
420
425
|
_getRefreshTokenCookieNamePatterns() {
|
|
421
426
|
return {
|
|
@@ -615,7 +620,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
615
620
|
});
|
|
616
621
|
}
|
|
617
622
|
const cookieHeader = tokenStoreInit.headers.get("cookie");
|
|
618
|
-
const parsed = cookie.
|
|
623
|
+
const parsed = cookie.parseCookie(cookieHeader || "");
|
|
619
624
|
const res = new Store(this._getTokensFromCookies(parsed));
|
|
620
625
|
this._requestTokenStores.set(tokenStoreInit, res);
|
|
621
626
|
return res;
|
|
@@ -936,32 +941,92 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
936
941
|
displayName: item.product.display_name,
|
|
937
942
|
customerType: item.product.customer_type,
|
|
938
943
|
isServerOnly: item.product.server_only,
|
|
939
|
-
stackable: item.product.stackable
|
|
944
|
+
stackable: item.product.stackable,
|
|
945
|
+
type: item.type,
|
|
946
|
+
subscription: item.subscription ? {
|
|
947
|
+
currentPeriodEnd: item.subscription.current_period_end ? new Date(item.subscription.current_period_end) : null,
|
|
948
|
+
cancelAtPeriodEnd: item.subscription.cancel_at_period_end,
|
|
949
|
+
isCancelable: item.subscription.is_cancelable
|
|
950
|
+
} : null,
|
|
951
|
+
switchOptions: item.switch_options?.map((option) => ({
|
|
952
|
+
productId: option.product_id,
|
|
953
|
+
displayName: option.product.display_name,
|
|
954
|
+
prices: option.product.prices
|
|
955
|
+
}))
|
|
940
956
|
}));
|
|
941
957
|
return Object.assign(products, { nextCursor: response.pagination.next_cursor ?? null });
|
|
942
958
|
}
|
|
959
|
+
_customerBillingFromResponse(response) {
|
|
960
|
+
return {
|
|
961
|
+
hasCustomer: response.has_customer,
|
|
962
|
+
defaultPaymentMethod: response.default_payment_method
|
|
963
|
+
};
|
|
964
|
+
}
|
|
943
965
|
_createAuth(session) {
|
|
944
966
|
const app = this;
|
|
945
967
|
return {
|
|
946
968
|
_internalSession: session,
|
|
947
969
|
currentSession: {
|
|
948
970
|
async getTokens() {
|
|
949
|
-
const tokens = await session.getOrFetchLikelyValidTokens(2e4);
|
|
971
|
+
const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
|
|
950
972
|
return {
|
|
951
973
|
accessToken: tokens?.accessToken.token ?? null,
|
|
952
974
|
refreshToken: tokens?.refreshToken?.token ?? null
|
|
953
975
|
};
|
|
976
|
+
},
|
|
977
|
+
useTokens() {
|
|
978
|
+
const [_, setCounter] = React.useState(0);
|
|
979
|
+
React.useEffect(() => {
|
|
980
|
+
const { unsubscribe: unsubscribeRefresh } = session.startRefreshingAccessToken(3e4, 6e4);
|
|
981
|
+
const { unsubscribe: unsubscribeInvalidate } = session.onInvalidate(() => setCounter((c) => c + 1));
|
|
982
|
+
const { unsubscribe: unsubscribeAccessTokenChange } = session.onAccessTokenChange(() => setCounter((c) => c + 1));
|
|
983
|
+
return () => {
|
|
984
|
+
unsubscribeRefresh();
|
|
985
|
+
unsubscribeInvalidate();
|
|
986
|
+
unsubscribeAccessTokenChange();
|
|
987
|
+
};
|
|
988
|
+
}, []);
|
|
989
|
+
let accessToken = session.isKnownToBeInvalid() ? null : session.getAccessTokenIfNotExpiredYet(2e4, 75e3);
|
|
990
|
+
if (accessToken === null) {
|
|
991
|
+
accessToken = use(session.getOrFetchLikelyValidTokens(2e4, 75e3))?.accessToken ?? null;
|
|
992
|
+
}
|
|
993
|
+
return {
|
|
994
|
+
accessToken: accessToken?.token ?? null,
|
|
995
|
+
refreshToken: session.getRefreshToken()?.token ?? null
|
|
996
|
+
};
|
|
954
997
|
}
|
|
955
998
|
},
|
|
999
|
+
async getAccessToken() {
|
|
1000
|
+
const tokens = await this.currentSession.getTokens();
|
|
1001
|
+
return tokens.accessToken;
|
|
1002
|
+
},
|
|
1003
|
+
useAccessToken() {
|
|
1004
|
+
return this.currentSession.useTokens().accessToken;
|
|
1005
|
+
},
|
|
1006
|
+
async getRefreshToken() {
|
|
1007
|
+
const tokens = await this.currentSession.getTokens();
|
|
1008
|
+
return tokens.refreshToken;
|
|
1009
|
+
},
|
|
1010
|
+
useRefreshToken() {
|
|
1011
|
+
return this.currentSession.useTokens().refreshToken;
|
|
1012
|
+
},
|
|
956
1013
|
async getAuthHeaders() {
|
|
957
1014
|
return {
|
|
958
1015
|
"x-stack-auth": JSON.stringify(await this.getAuthJson())
|
|
959
1016
|
};
|
|
960
1017
|
},
|
|
1018
|
+
useAuthHeaders() {
|
|
1019
|
+
return {
|
|
1020
|
+
"x-stack-auth": JSON.stringify(this.useAuthJson())
|
|
1021
|
+
};
|
|
1022
|
+
},
|
|
961
1023
|
async getAuthJson() {
|
|
962
1024
|
const tokens = await this.currentSession.getTokens();
|
|
963
1025
|
return tokens;
|
|
964
1026
|
},
|
|
1027
|
+
useAuthJson() {
|
|
1028
|
+
return this.currentSession.useTokens();
|
|
1029
|
+
},
|
|
965
1030
|
signOut(options) {
|
|
966
1031
|
return app._signOut(session, options);
|
|
967
1032
|
}
|
|
@@ -1002,6 +1067,8 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1002
1067
|
passkeyAuthEnabled: crud.passkey_auth_enabled,
|
|
1003
1068
|
isMultiFactorRequired: crud.requires_totp_mfa,
|
|
1004
1069
|
isAnonymous: crud.is_anonymous,
|
|
1070
|
+
isRestricted: crud.is_restricted,
|
|
1071
|
+
restrictedReason: crud.restricted_reason,
|
|
1005
1072
|
toClientJson() {
|
|
1006
1073
|
return crud;
|
|
1007
1074
|
}
|
|
@@ -1032,7 +1099,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1032
1099
|
return this.update({ clientMetadata: metadata });
|
|
1033
1100
|
},
|
|
1034
1101
|
async setSelectedTeam(team) {
|
|
1035
|
-
await this.update({ selectedTeamId: team?.id ?? null });
|
|
1102
|
+
await this.update({ selectedTeamId: typeof team === "string" ? team : team?.id ?? null });
|
|
1036
1103
|
},
|
|
1037
1104
|
getConnectedAccount,
|
|
1038
1105
|
useConnectedAccount,
|
|
@@ -1263,8 +1330,29 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1263
1330
|
}
|
|
1264
1331
|
_createCustomer(userIdOrTeamId, type, session) {
|
|
1265
1332
|
const app = this;
|
|
1333
|
+
const effectiveSession = session ?? app._interface.createSession({ refreshToken: null });
|
|
1266
1334
|
const customerOptions = type === "user" ? { userId: userIdOrTeamId } : { teamId: userIdOrTeamId };
|
|
1267
1335
|
return {
|
|
1336
|
+
async getBilling() {
|
|
1337
|
+
const response = Result.orThrow(await app._customerBillingCache.getOrWait([effectiveSession, type, userIdOrTeamId], "write-only"));
|
|
1338
|
+
return app._customerBillingFromResponse(response);
|
|
1339
|
+
},
|
|
1340
|
+
useBilling() {
|
|
1341
|
+
const response = useAsyncCache(app._customerBillingCache, [effectiveSession, type, userIdOrTeamId], "customer.useBilling()");
|
|
1342
|
+
return app._customerBillingFromResponse(response);
|
|
1343
|
+
},
|
|
1344
|
+
async createPaymentMethodSetupIntent() {
|
|
1345
|
+
const body = await app._interface.createCustomerPaymentMethodSetupIntent(type, userIdOrTeamId, effectiveSession);
|
|
1346
|
+
return {
|
|
1347
|
+
clientSecret: body.client_secret,
|
|
1348
|
+
stripeAccountId: body.stripe_account_id
|
|
1349
|
+
};
|
|
1350
|
+
},
|
|
1351
|
+
async setDefaultPaymentMethodFromSetupIntent(setupIntentId) {
|
|
1352
|
+
const body = await app._interface.setDefaultCustomerPaymentMethodFromSetupIntent(type, userIdOrTeamId, setupIntentId, effectiveSession);
|
|
1353
|
+
await app._customerBillingCache.refresh([effectiveSession, type, userIdOrTeamId]);
|
|
1354
|
+
return body.default_payment_method;
|
|
1355
|
+
},
|
|
1268
1356
|
async getItem(itemId) {
|
|
1269
1357
|
return await app.getItem({ itemId, ...customerOptions });
|
|
1270
1358
|
},
|
|
@@ -1278,7 +1366,23 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1278
1366
|
return app.useProducts({ ...options, ...customerOptions });
|
|
1279
1367
|
},
|
|
1280
1368
|
async createCheckoutUrl(options) {
|
|
1281
|
-
return await app._interface.createCheckoutUrl(type, userIdOrTeamId, options.productId,
|
|
1369
|
+
return await app._interface.createCheckoutUrl(type, userIdOrTeamId, options.productId, effectiveSession, options.returnUrl);
|
|
1370
|
+
},
|
|
1371
|
+
async switchSubscription(options) {
|
|
1372
|
+
await app._interface.switchSubscription({
|
|
1373
|
+
customer_type: type,
|
|
1374
|
+
customer_id: userIdOrTeamId,
|
|
1375
|
+
from_product_id: options.fromProductId,
|
|
1376
|
+
to_product_id: options.toProductId,
|
|
1377
|
+
price_id: options.priceId,
|
|
1378
|
+
quantity: options.quantity
|
|
1379
|
+
}, effectiveSession);
|
|
1380
|
+
await app._customerBillingCache.refresh([effectiveSession, type, userIdOrTeamId]);
|
|
1381
|
+
if (type === "user") {
|
|
1382
|
+
await app._userProductsCache.invalidateWhere(([cachedSession, userId]) => cachedSession === effectiveSession && userId === userIdOrTeamId);
|
|
1383
|
+
} else {
|
|
1384
|
+
await app._teamProductsCache.invalidateWhere(([cachedSession, teamId]) => cachedSession === effectiveSession && teamId === userIdOrTeamId);
|
|
1385
|
+
}
|
|
1282
1386
|
}
|
|
1283
1387
|
};
|
|
1284
1388
|
}
|
|
@@ -1312,6 +1416,25 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1312
1416
|
const response = Result.orThrow(await this._customProductsCache.getOrWait([session, options.customCustomerId, options.cursor ?? null, options.limit ?? null], "write-only"));
|
|
1313
1417
|
return this._customerProductsFromResponse(response);
|
|
1314
1418
|
}
|
|
1419
|
+
async cancelSubscription(options) {
|
|
1420
|
+
const session = await this._getSession();
|
|
1421
|
+
const user = await this.getUser();
|
|
1422
|
+
if (!user) {
|
|
1423
|
+
throw new KnownErrors.UserAuthenticationRequired();
|
|
1424
|
+
}
|
|
1425
|
+
const customerType = "teamId" in options ? "team" : "user";
|
|
1426
|
+
const customerId = "teamId" in options ? options.teamId : user.id;
|
|
1427
|
+
await this._interface.cancelSubscription({
|
|
1428
|
+
customer_type: customerType,
|
|
1429
|
+
customer_id: customerId,
|
|
1430
|
+
product_id: options.productId
|
|
1431
|
+
}, session);
|
|
1432
|
+
if (customerType === "user") {
|
|
1433
|
+
await this._userProductsCache.invalidateWhere(([cachedSession, userId]) => cachedSession === session && userId === customerId);
|
|
1434
|
+
} else {
|
|
1435
|
+
await this._teamProductsCache.invalidateWhere(([cachedSession, teamId]) => cachedSession === session && teamId === customerId);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1315
1438
|
useProducts(options) {
|
|
1316
1439
|
const session = this._useSession();
|
|
1317
1440
|
const cache = "userId" in options ? this._userProductsCache : "teamId" in options ? this._teamProductsCache : this._customProductsCache;
|
|
@@ -1321,15 +1444,13 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1321
1444
|
return this._customerProductsFromResponse(response);
|
|
1322
1445
|
}
|
|
1323
1446
|
_currentUserFromCrud(crud, session) {
|
|
1324
|
-
const currentUser = {
|
|
1447
|
+
const currentUser = withUserDestructureGuard({
|
|
1325
1448
|
...this._createBaseUser(crud),
|
|
1326
1449
|
...this._createAuth(session),
|
|
1327
1450
|
...this._createUserExtraFromCurrent(crud, session),
|
|
1328
1451
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {},
|
|
1329
1452
|
...this._createCustomer(crud.id, "user", session)
|
|
1330
|
-
};
|
|
1331
|
-
attachUserDestructureGuard(currentUser);
|
|
1332
|
-
Object.freeze(currentUser);
|
|
1453
|
+
});
|
|
1333
1454
|
return currentUser;
|
|
1334
1455
|
}
|
|
1335
1456
|
_clientSessionFromCrud(crud) {
|
|
@@ -1417,7 +1538,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1417
1538
|
const queryParams = new URLSearchParams(window.location.search);
|
|
1418
1539
|
url = queryParams.get("after_auth_return_to") || url;
|
|
1419
1540
|
}
|
|
1420
|
-
} else if (handlerName === "signIn" || handlerName === "signUp") {
|
|
1541
|
+
} else if (handlerName === "signIn" || handlerName === "signUp" || handlerName === "onboarding") {
|
|
1421
1542
|
if (isReactServer2 || typeof window === "undefined") {
|
|
1422
1543
|
} else {
|
|
1423
1544
|
const currentUrl = new URL(window.location.href);
|
|
@@ -1466,6 +1587,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1466
1587
|
async redirectToAfterSignUp(options) {
|
|
1467
1588
|
return await this._redirectToHandler("afterSignUp", options);
|
|
1468
1589
|
}
|
|
1590
|
+
async redirectToOnboarding(options) {
|
|
1591
|
+
return await this._redirectToHandler("onboarding", options);
|
|
1592
|
+
}
|
|
1469
1593
|
async redirectToAfterSignOut(options) {
|
|
1470
1594
|
return await this._redirectToHandler("afterSignOut", options);
|
|
1471
1595
|
}
|
|
@@ -1531,16 +1655,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1531
1655
|
return result;
|
|
1532
1656
|
}
|
|
1533
1657
|
async getUser(options) {
|
|
1658
|
+
if (options?.or === "anonymous" && options.includeRestricted === false) {
|
|
1659
|
+
throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
|
|
1660
|
+
}
|
|
1534
1661
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1535
1662
|
const session = await this._getSession(options?.tokenStore);
|
|
1536
1663
|
let crud = Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
if (crud === null) {
|
|
1664
|
+
const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
|
|
1665
|
+
const includeRestricted = options?.includeRestricted === true || includeAnonymous;
|
|
1666
|
+
if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
|
|
1541
1667
|
switch (options?.or) {
|
|
1542
1668
|
case "redirect": {
|
|
1543
|
-
|
|
1669
|
+
if (!crud?.is_anonymous && crud?.is_restricted) {
|
|
1670
|
+
await this.redirectToOnboarding({ replace: true });
|
|
1671
|
+
} else {
|
|
1672
|
+
await this.redirectToSignIn({ replace: true });
|
|
1673
|
+
}
|
|
1544
1674
|
break;
|
|
1545
1675
|
}
|
|
1546
1676
|
case "throw": {
|
|
@@ -1548,7 +1678,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1548
1678
|
}
|
|
1549
1679
|
case "anonymous": {
|
|
1550
1680
|
const tokens = await this._signUpAnonymously();
|
|
1551
|
-
return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]" }) ?? throwErr("Something went wrong while signing up anonymously");
|
|
1681
|
+
return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]", includeRestricted: true }) ?? throwErr("Something went wrong while signing up anonymously");
|
|
1552
1682
|
}
|
|
1553
1683
|
case void 0:
|
|
1554
1684
|
case "anonymous-if-exists[deprecated]":
|
|
@@ -1560,16 +1690,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1560
1690
|
return crud && this._currentUserFromCrud(crud, session);
|
|
1561
1691
|
}
|
|
1562
1692
|
useUser(options) {
|
|
1693
|
+
if (options?.or === "anonymous" && options.includeRestricted === false) {
|
|
1694
|
+
throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
|
|
1695
|
+
}
|
|
1563
1696
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1564
1697
|
const session = this._useSession(options?.tokenStore);
|
|
1565
1698
|
let crud = useAsyncCache(this._currentUserCache, [session], "clientApp.useUser()");
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
if (crud === null) {
|
|
1699
|
+
const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
|
|
1700
|
+
const includeRestricted = options?.includeRestricted === true || includeAnonymous;
|
|
1701
|
+
if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
|
|
1570
1702
|
switch (options?.or) {
|
|
1571
1703
|
case "redirect": {
|
|
1572
|
-
|
|
1704
|
+
if (!crud?.is_anonymous && crud?.is_restricted) {
|
|
1705
|
+
runAsynchronously(this.redirectToOnboarding({ replace: true }));
|
|
1706
|
+
} else {
|
|
1707
|
+
runAsynchronously(this.redirectToSignIn({ replace: true }));
|
|
1708
|
+
}
|
|
1573
1709
|
suspend();
|
|
1574
1710
|
throw new StackAssertionError("suspend should never return");
|
|
1575
1711
|
}
|
|
@@ -1597,7 +1733,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1597
1733
|
}, [crud, session, options?.or]);
|
|
1598
1734
|
}
|
|
1599
1735
|
_getTokenPartialUserFromSession(session, options) {
|
|
1600
|
-
const accessToken = session.getAccessTokenIfNotExpiredYet(0);
|
|
1736
|
+
const accessToken = session.getAccessTokenIfNotExpiredYet(0, null);
|
|
1601
1737
|
if (!accessToken) {
|
|
1602
1738
|
return null;
|
|
1603
1739
|
}
|
|
@@ -1610,7 +1746,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1610
1746
|
primaryEmail: accessToken.payload.email,
|
|
1611
1747
|
displayName: accessToken.payload.name,
|
|
1612
1748
|
primaryEmailVerified: accessToken.payload.email_verified,
|
|
1613
|
-
isAnonymous
|
|
1749
|
+
isAnonymous,
|
|
1750
|
+
isRestricted: accessToken.payload.is_restricted,
|
|
1751
|
+
restrictedReason: accessToken.payload.restricted_reason
|
|
1614
1752
|
};
|
|
1615
1753
|
}
|
|
1616
1754
|
async _getPartialUserFromConvex(ctx) {
|
|
@@ -1623,7 +1761,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1623
1761
|
displayName: auth.name ?? null,
|
|
1624
1762
|
primaryEmail: auth.email ?? null,
|
|
1625
1763
|
primaryEmailVerified: auth.email_verified,
|
|
1626
|
-
isAnonymous: auth.is_anonymous
|
|
1764
|
+
isAnonymous: auth.is_anonymous,
|
|
1765
|
+
isRestricted: auth.is_restricted,
|
|
1766
|
+
restrictedReason: auth.restricted_reason ?? null
|
|
1627
1767
|
};
|
|
1628
1768
|
}
|
|
1629
1769
|
async getPartialUser(options) {
|
|
@@ -1661,7 +1801,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1661
1801
|
return async (args) => {
|
|
1662
1802
|
const session = await this._getSession(options.tokenStore ?? this._tokenStoreInit);
|
|
1663
1803
|
if (!args.forceRefreshToken) {
|
|
1664
|
-
const tokens2 = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1804
|
+
const tokens2 = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
|
|
1665
1805
|
return tokens2?.accessToken.token ?? null;
|
|
1666
1806
|
}
|
|
1667
1807
|
const tokens = await session.fetchNewTokens();
|
|
@@ -1670,7 +1810,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1670
1810
|
}
|
|
1671
1811
|
async getConvexHttpClientAuth(options) {
|
|
1672
1812
|
const session = await this._getSession(options.tokenStore);
|
|
1673
|
-
const tokens = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1813
|
+
const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
|
|
1674
1814
|
return tokens?.accessToken.token ?? "";
|
|
1675
1815
|
}
|
|
1676
1816
|
async _updateClientUser(update, session) {
|
|
@@ -2017,11 +2157,44 @@ ${url}`);
|
|
|
2017
2157
|
await user.signOut({ redirectUrl: options?.redirectUrl });
|
|
2018
2158
|
}
|
|
2019
2159
|
}
|
|
2160
|
+
async getAccessToken(options) {
|
|
2161
|
+
const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
|
|
2162
|
+
if (user) {
|
|
2163
|
+
return await user.getAccessToken();
|
|
2164
|
+
}
|
|
2165
|
+
return null;
|
|
2166
|
+
}
|
|
2167
|
+
useAccessToken(options) {
|
|
2168
|
+
const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
|
|
2169
|
+
if (user) {
|
|
2170
|
+
return user.useAccessToken();
|
|
2171
|
+
}
|
|
2172
|
+
return null;
|
|
2173
|
+
}
|
|
2174
|
+
async getRefreshToken(options) {
|
|
2175
|
+
const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
|
|
2176
|
+
if (user) {
|
|
2177
|
+
return await user.getRefreshToken();
|
|
2178
|
+
}
|
|
2179
|
+
return null;
|
|
2180
|
+
}
|
|
2181
|
+
useRefreshToken(options) {
|
|
2182
|
+
const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
|
|
2183
|
+
if (user) {
|
|
2184
|
+
return user.useRefreshToken();
|
|
2185
|
+
}
|
|
2186
|
+
return null;
|
|
2187
|
+
}
|
|
2020
2188
|
async getAuthHeaders(options) {
|
|
2021
2189
|
return {
|
|
2022
2190
|
"x-stack-auth": JSON.stringify(await this.getAuthJson(options))
|
|
2023
2191
|
};
|
|
2024
2192
|
}
|
|
2193
|
+
useAuthHeaders(options) {
|
|
2194
|
+
return {
|
|
2195
|
+
"x-stack-auth": JSON.stringify(this.useAuthJson(options))
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2025
2198
|
async getAuthJson(options) {
|
|
2026
2199
|
const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
|
|
2027
2200
|
if (user) {
|
|
@@ -2029,6 +2202,13 @@ ${url}`);
|
|
|
2029
2202
|
}
|
|
2030
2203
|
return { accessToken: null, refreshToken: null };
|
|
2031
2204
|
}
|
|
2205
|
+
useAuthJson(options) {
|
|
2206
|
+
const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
|
|
2207
|
+
if (user) {
|
|
2208
|
+
return user.useAuthJson();
|
|
2209
|
+
}
|
|
2210
|
+
return { accessToken: null, refreshToken: null };
|
|
2211
|
+
}
|
|
2032
2212
|
async getProject() {
|
|
2033
2213
|
const crud = Result.orThrow(await this._currentProjectCache.getOrWait([], "write-only"));
|
|
2034
2214
|
return this._clientProjectFromCrud(crud);
|
|
@@ -2065,6 +2245,7 @@ ${url}`);
|
|
|
2065
2245
|
}
|
|
2066
2246
|
async _refreshUser(session) {
|
|
2067
2247
|
await this._refreshSession(session);
|
|
2248
|
+
session.suggestAccessTokenExpired();
|
|
2068
2249
|
}
|
|
2069
2250
|
async _refreshSession(session) {
|
|
2070
2251
|
await this._currentUserCache.refresh([session]);
|