@stackframe/react 2.8.41 → 2.8.44
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/CHANGELOG.md +29 -0
- package/dist/esm/integrations/convex/component/convex.config.js +8 -0
- package/dist/esm/integrations/convex/component/convex.config.js.map +1 -0
- package/dist/esm/integrations/convex.js +5 -4
- package/dist/esm/integrations/convex.js.map +1 -1
- package/dist/esm/lib/hooks.js +3 -0
- package/dist/esm/lib/hooks.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +31 -42
- 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 +106 -31
- 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 +16 -2
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +119 -60
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.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/projects/index.js.map +1 -1
- package/dist/esm/lib/stack-app/users/index.js +16 -0
- package/dist/esm/lib/stack-app/users/index.js.map +1 -1
- package/dist/esm/providers/stack-provider.js +2 -6
- package/dist/esm/providers/stack-provider.js.map +1 -1
- package/dist/index.d.mts +86 -23
- package/dist/index.d.ts +86 -23
- package/dist/integrations/convex/component/convex.config.d.mts +5 -0
- package/dist/integrations/convex/component/convex.config.d.ts +5 -0
- package/dist/integrations/convex/component/convex.config.js +29 -0
- package/dist/integrations/convex/component/convex.config.js.map +1 -0
- package/dist/integrations/convex.js +4 -3
- package/dist/integrations/convex.js.map +1 -1
- package/dist/lib/hooks.js +3 -0
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +30 -41
- 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 +104 -29
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +17 -1
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +117 -58
- package/dist/lib/stack-app/apps/implementations/server-app-impl.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/customers/index.js.map +1 -1
- package/dist/lib/stack-app/projects/index.js.map +1 -1
- package/dist/lib/stack-app/users/index.js +17 -0
- package/dist/lib/stack-app/users/index.js.map +1 -1
- package/dist/providers/stack-provider.js +1 -5
- package/dist/providers/stack-provider.js.map +1 -1
- package/package.json +16 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/stack-app/projects/index.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { ProductionModeError } from \"@stackframe/stack-shared/dist/helpers/production-mode\";\nimport { AdminUserProjectsCrud, ProjectsCrud } from \"@stackframe/stack-shared/dist/interface/crud/projects\";\n\nimport { CompleteConfig, EnvironmentConfigOverrideOverride } from \"@stackframe/stack-shared/dist/config/schema\";\nimport { CurrentUser } from \"..\";\nimport { StackAdminApp } from \"../apps/interfaces/admin-app\";\nimport { AdminProjectConfig, AdminProjectConfigUpdateOptions, ProjectConfig } from \"../project-configs\";\n\n\nexport type Project = {\n readonly id: string,\n readonly displayName: string,\n readonly config: ProjectConfig,\n};\n\nexport type AdminProject = {\n readonly id: string,\n readonly displayName: string,\n readonly description: string | null,\n readonly createdAt: Date,\n readonly isProductionMode: boolean,\n readonly ownerTeamId: string | null,\n readonly logoUrl: string | null | undefined,\n readonly fullLogoUrl: string | null | undefined,\n\n readonly config: AdminProjectConfig,\n\n update(this: AdminProject, update: AdminProjectUpdateOptions): Promise<void>,\n delete(this: AdminProject): Promise<void>,\n
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/stack-app/projects/index.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { ProductionModeError } from \"@stackframe/stack-shared/dist/helpers/production-mode\";\nimport { AdminUserProjectsCrud, ProjectsCrud } from \"@stackframe/stack-shared/dist/interface/crud/projects\";\n\nimport { CompleteConfig, EnvironmentConfigOverrideOverride } from \"@stackframe/stack-shared/dist/config/schema\";\nimport { CurrentUser } from \"..\";\nimport { StackAdminApp } from \"../apps/interfaces/admin-app\";\nimport { AdminProjectConfig, AdminProjectConfigUpdateOptions, ProjectConfig } from \"../project-configs\";\n\n\nexport type Project = {\n readonly id: string,\n readonly displayName: string,\n readonly config: ProjectConfig,\n};\n\nexport type AdminProject = {\n readonly id: string,\n readonly displayName: string,\n readonly description: string | null,\n readonly createdAt: Date,\n readonly isProductionMode: boolean,\n readonly ownerTeamId: string | null,\n readonly logoUrl: string | null | undefined,\n readonly fullLogoUrl: string | null | undefined,\n\n readonly config: AdminProjectConfig,\n\n update(this: AdminProject, update: AdminProjectUpdateOptions): Promise<void>,\n delete(this: AdminProject): Promise<void>,\n\n getConfig(this: AdminProject): Promise<CompleteConfig>,\n useConfig(this: AdminProject): CompleteConfig,\n updateConfig(this: AdminProject, config: EnvironmentConfigOverrideOverride): Promise<void>,\n\n getProductionModeErrors(this: AdminProject): Promise<ProductionModeError[]>,\n useProductionModeErrors(this: AdminProject): ProductionModeError[],\n} & Project;\n\nexport type AdminOwnedProject = {\n readonly app: StackAdminApp<false>,\n} & AdminProject;\n\nexport type AdminProjectUpdateOptions = {\n displayName?: string,\n description?: string,\n isProductionMode?: boolean,\n logoUrl?: string | null,\n fullLogoUrl?: string | null,\n config?: AdminProjectConfigUpdateOptions,\n};\nexport function adminProjectUpdateOptionsToCrud(options: AdminProjectUpdateOptions): ProjectsCrud[\"Admin\"][\"Update\"] {\n return {\n display_name: options.displayName,\n description: options.description,\n is_production_mode: options.isProductionMode,\n logo_url: options.logoUrl,\n full_logo_url: options.fullLogoUrl,\n config: {\n domains: options.config?.domains?.map((d) => ({\n domain: d.domain,\n handler_path: d.handlerPath\n })),\n oauth_providers: options.config?.oauthProviders?.map((p) => ({\n id: p.id as any,\n type: p.type,\n ...(p.type === 'standard' && {\n client_id: p.clientId,\n client_secret: p.clientSecret,\n facebook_config_id: p.facebookConfigId,\n microsoft_tenant_id: p.microsoftTenantId,\n }),\n })),\n email_config: options.config?.emailConfig && (\n options.config.emailConfig.type === 'shared' ? {\n type: 'shared',\n } : {\n type: 'standard',\n host: options.config.emailConfig.host,\n port: options.config.emailConfig.port,\n username: options.config.emailConfig.username,\n password: options.config.emailConfig.password,\n sender_name: options.config.emailConfig.senderName,\n sender_email: options.config.emailConfig.senderEmail,\n }\n ),\n email_theme: options.config?.emailTheme,\n sign_up_enabled: options.config?.signUpEnabled,\n credential_enabled: options.config?.credentialEnabled,\n magic_link_enabled: options.config?.magicLinkEnabled,\n passkey_enabled: options.config?.passkeyEnabled,\n allow_localhost: options.config?.allowLocalhost,\n create_team_on_sign_up: options.config?.createTeamOnSignUp,\n client_team_creation_enabled: options.config?.clientTeamCreationEnabled,\n client_user_deletion_enabled: options.config?.clientUserDeletionEnabled,\n team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,\n team_member_default_permissions: options.config?.teamMemberDefaultPermissions,\n user_default_permissions: options.config?.userDefaultPermissions,\n oauth_account_merge_strategy: options.config?.oauthAccountMergeStrategy,\n allow_user_api_keys: options.config?.allowUserApiKeys,\n allow_team_api_keys: options.config?.allowTeamApiKeys,\n },\n };\n}\n\nexport type AdminProjectCreateOptions = Omit<AdminProjectUpdateOptions, 'displayName'> & {\n displayName: string,\n teamId: string,\n};\nexport function adminProjectCreateOptionsToCrud(options: AdminProjectCreateOptions): AdminUserProjectsCrud[\"Server\"][\"Create\"] {\n return {\n ...adminProjectUpdateOptionsToCrud(options),\n display_name: options.displayName,\n owner_team_id: options.teamId,\n };\n}\n"],"mappings":";AAsDO,SAAS,gCAAgC,SAAqE;AACnH,SAAO;AAAA,IACL,cAAc,QAAQ;AAAA,IACtB,aAAa,QAAQ;AAAA,IACrB,oBAAoB,QAAQ;AAAA,IAC5B,UAAU,QAAQ;AAAA,IAClB,eAAe,QAAQ;AAAA,IACvB,QAAQ;AAAA,MACN,SAAS,QAAQ,QAAQ,SAAS,IAAI,CAAC,OAAO;AAAA,QAC5C,QAAQ,EAAE;AAAA,QACV,cAAc,EAAE;AAAA,MAClB,EAAE;AAAA,MACF,iBAAiB,QAAQ,QAAQ,gBAAgB,IAAI,CAAC,OAAO;AAAA,QAC3D,IAAI,EAAE;AAAA,QACN,MAAM,EAAE;AAAA,QACR,GAAI,EAAE,SAAS,cAAc;AAAA,UAC3B,WAAW,EAAE;AAAA,UACb,eAAe,EAAE;AAAA,UACjB,oBAAoB,EAAE;AAAA,UACtB,qBAAqB,EAAE;AAAA,QACzB;AAAA,MACF,EAAE;AAAA,MACF,cAAc,QAAQ,QAAQ,gBAC5B,QAAQ,OAAO,YAAY,SAAS,WAAW;AAAA,QAC7C,MAAM;AAAA,MACR,IAAI;AAAA,QACF,MAAM;AAAA,QACN,MAAM,QAAQ,OAAO,YAAY;AAAA,QACjC,MAAM,QAAQ,OAAO,YAAY;AAAA,QACjC,UAAU,QAAQ,OAAO,YAAY;AAAA,QACrC,UAAU,QAAQ,OAAO,YAAY;AAAA,QACrC,aAAa,QAAQ,OAAO,YAAY;AAAA,QACxC,cAAc,QAAQ,OAAO,YAAY;AAAA,MAC3C;AAAA,MAEF,aAAa,QAAQ,QAAQ;AAAA,MAC7B,iBAAiB,QAAQ,QAAQ;AAAA,MACjC,oBAAoB,QAAQ,QAAQ;AAAA,MACpC,oBAAoB,QAAQ,QAAQ;AAAA,MACpC,iBAAiB,QAAQ,QAAQ;AAAA,MACjC,iBAAiB,QAAQ,QAAQ;AAAA,MACjC,wBAAwB,QAAQ,QAAQ;AAAA,MACxC,8BAA8B,QAAQ,QAAQ;AAAA,MAC9C,8BAA8B,QAAQ,QAAQ;AAAA,MAC9C,kCAAkC,QAAQ,QAAQ;AAAA,MAClD,iCAAiC,QAAQ,QAAQ;AAAA,MACjD,0BAA0B,QAAQ,QAAQ;AAAA,MAC1C,8BAA8B,QAAQ,QAAQ;AAAA,MAC9C,qBAAqB,QAAQ,QAAQ;AAAA,MACrC,qBAAqB,QAAQ,QAAQ;AAAA,IACvC;AAAA,EACF;AACF;AAMO,SAAS,gCAAgC,SAA+E;AAC7H,SAAO;AAAA,IACL,GAAG,gCAAgC,OAAO;AAAA,IAC1C,cAAc,QAAQ;AAAA,IACtB,eAAe,QAAQ;AAAA,EACzB;AACF;","names":[]}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
// src/lib/stack-app/users/index.ts
|
|
2
2
|
import { encodeBase64 } from "@stackframe/stack-shared/dist/utils/bytes";
|
|
3
|
+
var userGetterErrorMessage = "Stack Auth: useUser() already returns the user object. Use `const user = useUser()` (or `const user = await app.getUser()`) instead of destructuring it like `const { user } = ...`.";
|
|
4
|
+
function attachUserDestructureGuard(target) {
|
|
5
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, "user");
|
|
6
|
+
if (descriptor?.get === guardGetter) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(target, "user", {
|
|
10
|
+
get: guardGetter,
|
|
11
|
+
configurable: false,
|
|
12
|
+
enumerable: false
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function guardGetter() {
|
|
16
|
+
throw new Error(userGetterErrorMessage);
|
|
17
|
+
}
|
|
3
18
|
function userUpdateOptionsToCrud(options) {
|
|
4
19
|
return {
|
|
5
20
|
display_name: options.displayName,
|
|
@@ -40,6 +55,7 @@ function serverUserCreateOptionsToCrud(options) {
|
|
|
40
55
|
};
|
|
41
56
|
}
|
|
42
57
|
export {
|
|
58
|
+
attachUserDestructureGuard,
|
|
43
59
|
serverUserCreateOptionsToCrud,
|
|
44
60
|
serverUserUpdateOptionsToCrud,
|
|
45
61
|
userUpdateOptionsToCrud
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/stack-app/users/index.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { KnownErrors } from \"@stackframe/stack-shared\";\nimport { CurrentUserCrud } from \"@stackframe/stack-shared/dist/interface/crud/current-user\";\nimport { UsersCrud } from \"@stackframe/stack-shared/dist/interface/crud/users\";\nimport { InternalSession } from \"@stackframe/stack-shared/dist/sessions\";\nimport { encodeBase64 } from \"@stackframe/stack-shared/dist/utils/bytes\";\nimport { GeoInfo } from \"@stackframe/stack-shared/dist/utils/geo\";\nimport { ReadonlyJson } from \"@stackframe/stack-shared/dist/utils/json\";\nimport { ProviderType } from \"@stackframe/stack-shared/dist/utils/oauth\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport { ApiKeyCreationOptions, UserApiKey, UserApiKeyFirstView } from \"../api-keys\";\nimport { AsyncStoreProperty } from \"../common\";\nimport { OAuthConnection } from \"../connected-accounts\";\nimport { ContactChannel, ContactChannelCreateOptions, ServerContactChannel, ServerContactChannelCreateOptions } from \"../contact-channels\";\nimport { Customer } from \"../customers\";\nimport { NotificationCategory } from \"../notification-categories\";\nimport { AdminTeamPermission, TeamPermission } from \"../permissions\";\nimport { AdminOwnedProject, AdminProjectCreateOptions } from \"../projects\";\nimport { EditableTeamMemberProfile, ServerTeam, ServerTeamCreateOptions, Team, TeamCreateOptions } from \"../teams\";\n\nexport type OAuthProvider = {\n readonly id: string,\n readonly type: string,\n readonly userId: string,\n readonly accountId?: string,\n readonly email?: string,\n readonly allowSignIn: boolean,\n readonly allowConnectedAccounts: boolean,\n update(data: { allowSignIn?: boolean, allowConnectedAccounts?: boolean }): Promise<Result<void,\n InstanceType<typeof KnownErrors.OAuthProviderAccountIdAlreadyUsedForSignIn>\n >>,\n delete(): Promise<void>,\n};\n\nexport type ServerOAuthProvider = {\n readonly id: string,\n readonly type: string,\n readonly userId: string,\n readonly accountId: string,\n readonly email?: string,\n readonly allowSignIn: boolean,\n readonly allowConnectedAccounts: boolean,\n update(data: { accountId?: string, email?: string, allowSignIn?: boolean, allowConnectedAccounts?: boolean }): Promise<Result<void,\n InstanceType<typeof KnownErrors.OAuthProviderAccountIdAlreadyUsedForSignIn>\n >>,\n delete(): Promise<void>,\n};\n\n\nexport type Session = {\n getTokens(): Promise<{ accessToken: string | null, refreshToken: string | null }>,\n};\n\n/**\n * Contains everything related to the current user session.\n */\nexport type Auth = {\n readonly _internalSession: InternalSession,\n readonly currentSession: Session,\n signOut(options?: { redirectUrl?: URL | string }): Promise<void>,\n\n /**\n * Returns headers for sending authenticated HTTP requests to external servers. Most commonly used in cross-origin\n * requests. Similar to `getAuthJson`, but specifically for HTTP requests.\n *\n * If you are using `tokenStore: \"cookie\"`, you don't need this for same-origin requests. However, most\n * browsers now disable third-party cookies by default, so we must pass authentication tokens by header instead\n * if the client and server are on different origins.\n *\n * This function returns a header object that can be used with `fetch` or other HTTP request libraries to send\n * authenticated requests.\n *\n * On the server, you can then pass in the `Request` object to the `tokenStore` option\n * of your Stack app. Please note that CORS does not allow most headers by default, so you\n * must include `x-stack-auth` in the [`Access-Control-Allow-Headers` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers)\n * of the CORS preflight response.\n *\n * If you are not using HTTP (and hence cannot set headers), you will need to use the `getAuthJson()` function\n * instead.\n *\n * Example:\n *\n * ```ts\n * // client\n * const res = await fetch(\"https://api.example.com\", {\n * headers: {\n * ...await stackApp.getAuthHeaders()\n * // you can also add your own headers here\n * },\n * });\n *\n * // server\n * function handleRequest(req: Request) {\n * const user = await stackServerApp.getUser({ tokenStore: req });\n * return new Response(\"Welcome, \" + user.displayName);\n * }\n * ```\n */\n getAuthHeaders(): Promise<{ \"x-stack-auth\": string }>,\n\n /**\n * Creates a JSON-serializable object containing the information to authenticate a user on an external server.\n * Similar to `getAuthHeaders`, but returns an object that can be sent over any protocol instead of just\n * HTTP headers.\n *\n * While `getAuthHeaders` is the recommended way to send authentication tokens over HTTP, your app may use\n * a different protocol, for example WebSockets or gRPC. This function returns a token object that can be JSON-serialized and sent to the server in any way you like.\n *\n * On the server, you can pass in this token object into the `tokenStore` option to fetch user details.\n *\n * Example:\n *\n * ```ts\n * // client\n * const res = await rpcCall(rpcEndpoint, {\n * data: {\n * auth: await stackApp.getAuthJson(),\n * },\n * });\n *\n * // server\n * function handleRequest(data) {\n * const user = await stackServerApp.getUser({ tokenStore: data.auth });\n * return new Response(\"Welcome, \" + user.displayName);\n * }\n * ```\n */\n getAuthJson(): Promise<{ accessToken: string | null, refreshToken: string | null }>,\n registerPasskey(options?: { hostname?: string }): Promise<Result<undefined, KnownErrors[\"PasskeyRegistrationFailed\"] | KnownErrors[\"PasskeyWebAuthnError\"]>>,\n};\n\n/**\n * ```\n * +----------+-------------+-------------------+\n * | \\ | !Server | Server |\n * +----------+-------------+-------------------+\n * | !Session | User | ServerUser |\n * | Session | CurrentUser | CurrentServerUser |\n * +----------+-------------+-------------------+\n * ```\n *\n * The fields on each of these types are available iff:\n * BaseUser: true\n * Auth: Session\n * ServerBaseUser: Server\n * UserExtra: Session OR Server\n *\n * The types are defined as follows (in the typescript manner):\n * User = BaseUser\n * CurrentUser = BaseUser & Auth & UserExtra\n * ServerUser = BaseUser & ServerBaseUser & UserExtra\n * CurrentServerUser = BaseUser & ServerBaseUser & Auth & UserExtra\n **/\n\nexport type BaseUser = {\n readonly id: string,\n\n readonly displayName: string | null,\n\n /**\n * The user's email address.\n *\n * Note: This might NOT be unique across multiple users, so always use `id` for unique identification.\n */\n readonly primaryEmail: string | null,\n readonly primaryEmailVerified: boolean,\n readonly profileImageUrl: string | null,\n\n readonly signedUpAt: Date,\n\n readonly clientMetadata: any,\n readonly clientReadOnlyMetadata: any,\n\n /**\n * Whether the user has a password set.\n */\n readonly hasPassword: boolean,\n readonly otpAuthEnabled: boolean,\n readonly passkeyAuthEnabled: boolean,\n\n readonly isMultiFactorRequired: boolean,\n readonly isAnonymous: boolean,\n toClientJson(): CurrentUserCrud[\"Client\"][\"Read\"],\n\n /**\n * @deprecated, use contact channel's usedForAuth instead\n */\n readonly emailAuthEnabled: boolean,\n /**\n * @deprecated\n */\n readonly oauthProviders: readonly { id: string }[],\n}\n\nexport type UserExtra = {\n setDisplayName(displayName: string): Promise<void>,\n /** @deprecated Use contact channel's sendVerificationEmail instead */\n sendVerificationEmail(): Promise<KnownErrors[\"EmailAlreadyVerified\"] | void>,\n setClientMetadata(metadata: any): Promise<void>,\n updatePassword(options: { oldPassword: string, newPassword: string}): Promise<KnownErrors[\"PasswordConfirmationMismatch\"] | KnownErrors[\"PasswordRequirementsNotMet\"] | void>,\n setPassword(options: { password: string }): Promise<KnownErrors[\"PasswordRequirementsNotMet\"] | void>,\n\n /**\n * A shorthand method to update multiple fields of the user at once.\n */\n update(update: UserUpdateOptions): Promise<void>,\n\n useContactChannels(): ContactChannel[], // THIS_LINE_PLATFORM react-like\n listContactChannels(): Promise<ContactChannel[]>,\n createContactChannel(data: ContactChannelCreateOptions): Promise<ContactChannel>,\n\n useNotificationCategories(): NotificationCategory[], // THIS_LINE_PLATFORM react-like\n listNotificationCategories(): Promise<NotificationCategory[]>,\n\n delete(): Promise<void>,\n\n getConnectedAccount(id: ProviderType, options: { or: 'redirect', scopes?: string[] }): Promise<OAuthConnection>,\n getConnectedAccount(id: ProviderType, options?: { or?: 'redirect' | 'throw' | 'return-null', scopes?: string[] }): Promise<OAuthConnection | null>,\n\n useConnectedAccount(id: ProviderType, options: { or: 'redirect', scopes?: string[] }): OAuthConnection,\n useConnectedAccount(id: ProviderType, options?: { or?: 'redirect' | 'throw' | 'return-null', scopes?: string[] }): OAuthConnection | null,\n\n hasPermission(scope: Team, permissionId: string): Promise<boolean>,\n hasPermission(permissionId: string): Promise<boolean>,\n\n getPermission(scope: Team, permissionId: string): Promise<TeamPermission | null>,\n getPermission(permissionId: string): Promise<TeamPermission | null>,\n\n listPermissions(scope: Team, options?: { recursive?: boolean }): Promise<TeamPermission[]>,\n listPermissions(options?: { recursive?: boolean }): Promise<TeamPermission[]>,\n\n usePermissions(scope: Team, options?: { recursive?: boolean }): TeamPermission[],\n usePermissions(options?: { recursive?: boolean }): TeamPermission[],\n\n usePermission(scope: Team, permissionId: string): TeamPermission | null,\n usePermission(permissionId: string): TeamPermission | null,\n\n readonly selectedTeam: Team | null,\n setSelectedTeam(team: Team | null): Promise<void>,\n createTeam(data: TeamCreateOptions): Promise<Team>,\n leaveTeam(team: Team): Promise<void>,\n\n getActiveSessions(): Promise<ActiveSession[]>,\n revokeSession(sessionId: string): Promise<void>,\n getTeamProfile(team: Team): Promise<EditableTeamMemberProfile>,\n useTeamProfile(team: Team): EditableTeamMemberProfile, // THIS_LINE_PLATFORM react-like\n\n createApiKey(options: ApiKeyCreationOptions<\"user\">): Promise<UserApiKeyFirstView>,\n\n useOAuthProviders(): OAuthProvider[], // THIS_LINE_PLATFORM react-like\n listOAuthProviders(): Promise<OAuthProvider[]>,\n\n useOAuthProvider(id: string): OAuthProvider | null, // THIS_LINE_PLATFORM react-like\n getOAuthProvider(id: string): Promise<OAuthProvider | null>,\n}\n& AsyncStoreProperty<\"apiKeys\", [], UserApiKey[], true>\n& AsyncStoreProperty<\"team\", [id: string], Team | null, false>\n& AsyncStoreProperty<\"teams\", [], Team[], true>\n& AsyncStoreProperty<\"permission\", [scope: Team, permissionId: string, options?: { recursive?: boolean }], TeamPermission | null, false>\n& AsyncStoreProperty<\"permissions\", [scope: Team, options?: { recursive?: boolean }], TeamPermission[], true>;\n\nexport type InternalUserExtra =\n & {\n createProject(newProject: AdminProjectCreateOptions): Promise<AdminOwnedProject>,\n }\n & AsyncStoreProperty<\"ownedProjects\", [], AdminOwnedProject[], true>\n\nexport type User = BaseUser;\n\nexport type CurrentUser = BaseUser & Auth & UserExtra & Customer;\n\nexport type CurrentInternalUser = CurrentUser & InternalUserExtra;\n\nexport type ProjectCurrentUser<ProjectId> = ProjectId extends \"internal\" ? CurrentInternalUser : CurrentUser;\n\nexport type TokenPartialUser = Pick<\n User,\n | \"id\"\n | \"displayName\"\n | \"primaryEmail\"\n | \"primaryEmailVerified\"\n | \"isAnonymous\"\n>\n\nexport type SyncedPartialUser = TokenPartialUser & Pick<\n User,\n | \"id\"\n | \"displayName\"\n | \"primaryEmail\"\n | \"primaryEmailVerified\"\n | \"profileImageUrl\"\n | \"signedUpAt\"\n | \"clientMetadata\"\n | \"clientReadOnlyMetadata\"\n | \"isAnonymous\"\n | \"hasPassword\"\n>;\n\n\nexport type ActiveSession = {\n id: string,\n userId: string,\n createdAt: Date,\n isImpersonation: boolean,\n lastUsedAt: Date | undefined,\n isCurrentSession: boolean,\n geoInfo?: GeoInfo,\n};\n\nexport type UserUpdateOptions = {\n displayName?: string,\n clientMetadata?: ReadonlyJson,\n selectedTeamId?: string | null,\n totpMultiFactorSecret?: Uint8Array | null,\n profileImageUrl?: string | null,\n otpAuthEnabled?: boolean,\n passkeyAuthEnabled?:boolean,\n}\nexport function userUpdateOptionsToCrud(options: UserUpdateOptions): CurrentUserCrud[\"Client\"][\"Update\"] {\n return {\n display_name: options.displayName,\n client_metadata: options.clientMetadata,\n selected_team_id: options.selectedTeamId,\n totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,\n profile_image_url: options.profileImageUrl,\n otp_auth_enabled: options.otpAuthEnabled,\n passkey_auth_enabled: options.passkeyAuthEnabled,\n };\n}\n\n\nexport type ServerBaseUser = {\n setPrimaryEmail(email: string | null, options?: { verified?: boolean | undefined }): Promise<void>,\n\n readonly lastActiveAt: Date,\n\n readonly serverMetadata: any,\n setServerMetadata(metadata: any): Promise<void>,\n setClientReadOnlyMetadata(metadata: any): Promise<void>,\n\n createTeam(data: Omit<ServerTeamCreateOptions, \"creatorUserId\">): Promise<ServerTeam>,\n\n useContactChannels(): ServerContactChannel[], // THIS_LINE_PLATFORM react-like\n listContactChannels(): Promise<ServerContactChannel[]>,\n createContactChannel(data: ServerContactChannelCreateOptions): Promise<ServerContactChannel>,\n\n update(user: ServerUserUpdateOptions): Promise<void>,\n\n grantPermission(scope: Team, permissionId: string): Promise<void>,\n grantPermission(permissionId: string): Promise<void>,\n\n revokePermission(scope: Team, permissionId: string): Promise<void>,\n revokePermission(permissionId: string): Promise<void>,\n\n getPermission(scope: Team, permissionId: string): Promise<TeamPermission | null>,\n getPermission(permissionId: string): Promise<TeamPermission | null>,\n\n hasPermission(scope: Team, permissionId: string): Promise<boolean>,\n hasPermission(permissionId: string): Promise<boolean>,\n\n listPermissions(scope: Team, options?: { recursive?: boolean }): Promise<TeamPermission[]>,\n listPermissions(options?: { recursive?: boolean }): Promise<TeamPermission[]>,\n\n usePermissions(scope: Team, options?: { recursive?: boolean }): TeamPermission[],\n usePermissions(options?: { recursive?: boolean }): TeamPermission[],\n\n usePermission(scope: Team, permissionId: string): TeamPermission | null,\n usePermission(permissionId: string): TeamPermission | null,\n\n useOAuthProviders(): ServerOAuthProvider[], // THIS_LINE_PLATFORM react-like\n listOAuthProviders(): Promise<ServerOAuthProvider[]>,\n\n useOAuthProvider(id: string): ServerOAuthProvider | null, // THIS_LINE_PLATFORM react-like\n getOAuthProvider(id: string): Promise<ServerOAuthProvider | null>,\n\n /**\n * Creates a new session object with a refresh token for this user. Can be used to impersonate them.\n */\n createSession(options?: { expiresInMillis?: number, isImpersonation?: boolean }): Promise<Session>,\n}\n& AsyncStoreProperty<\"team\", [id: string], ServerTeam | null, false>\n& AsyncStoreProperty<\"teams\", [], ServerTeam[], true>\n& AsyncStoreProperty<\"permission\", [scope: Team, permissionId: string, options?: { direct?: boolean }], AdminTeamPermission | null, false>\n& AsyncStoreProperty<\"permissions\", [scope: Team, options?: { direct?: boolean }], AdminTeamPermission[], true>;\n\n/**\n * A user including sensitive fields that should only be used on the server, never sent to the client\n * (such as sensitive information and serverMetadata).\n */\nexport type ServerUser = ServerBaseUser & BaseUser & UserExtra & Customer<true>;\n\nexport type CurrentServerUser = Auth & ServerUser;\n\nexport type CurrentInternalServerUser = CurrentServerUser & InternalUserExtra;\n\nexport type ProjectCurrentServerUser<ProjectId> = ProjectId extends \"internal\" ? CurrentInternalServerUser : CurrentServerUser;\n\nexport type SyncedPartialServerUser = SyncedPartialUser & Pick<\n ServerUser,\n | \"serverMetadata\"\n>;\n\nexport type ServerUserUpdateOptions = {\n primaryEmail?: string | null,\n primaryEmailVerified?: boolean,\n primaryEmailAuthEnabled?: boolean,\n clientReadOnlyMetadata?: ReadonlyJson,\n serverMetadata?: ReadonlyJson,\n password?: string,\n} & UserUpdateOptions;\nexport function serverUserUpdateOptionsToCrud(options: ServerUserUpdateOptions): CurrentUserCrud[\"Server\"][\"Update\"] {\n return {\n display_name: options.displayName,\n primary_email: options.primaryEmail,\n client_metadata: options.clientMetadata,\n client_read_only_metadata: options.clientReadOnlyMetadata,\n server_metadata: options.serverMetadata,\n selected_team_id: options.selectedTeamId,\n primary_email_auth_enabled: options.primaryEmailAuthEnabled,\n primary_email_verified: options.primaryEmailVerified,\n password: options.password,\n profile_image_url: options.profileImageUrl,\n totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,\n };\n}\n\n\nexport type ServerUserCreateOptions = {\n primaryEmail?: string | null,\n primaryEmailAuthEnabled?: boolean,\n password?: string,\n otpAuthEnabled?: boolean,\n displayName?: string,\n primaryEmailVerified?: boolean,\n clientMetadata?: any,\n clientReadOnlyMetadata?: any,\n serverMetadata?: any,\n}\nexport function serverUserCreateOptionsToCrud(options: ServerUserCreateOptions): UsersCrud[\"Server\"][\"Create\"] {\n return {\n primary_email: options.primaryEmail,\n password: options.password,\n otp_auth_enabled: options.otpAuthEnabled,\n primary_email_auth_enabled: options.primaryEmailAuthEnabled,\n display_name: options.displayName,\n primary_email_verified: options.primaryEmailVerified,\n client_metadata: options.clientMetadata,\n client_read_only_metadata: options.clientReadOnlyMetadata,\n server_metadata: options.serverMetadata,\n };\n}\n"],"mappings":";AAQA,SAAS,oBAAoB;AAyTtB,SAAS,wBAAwB,SAAiE;AACvG,SAAO;AAAA,IACL,cAAc,QAAQ;AAAA,IACtB,iBAAiB,QAAQ;AAAA,IACzB,kBAAkB,QAAQ;AAAA,IAC1B,oBAAoB,QAAQ,yBAAyB,OAAO,aAAa,QAAQ,qBAAqB,IAAI,QAAQ;AAAA,IAClH,mBAAmB,QAAQ;AAAA,IAC3B,kBAAkB,QAAQ;AAAA,IAC1B,sBAAsB,QAAQ;AAAA,EAChC;AACF;AAkFO,SAAS,8BAA8B,SAAuE;AACnH,SAAO;AAAA,IACL,cAAc,QAAQ;AAAA,IACtB,eAAe,QAAQ;AAAA,IACvB,iBAAiB,QAAQ;AAAA,IACzB,2BAA2B,QAAQ;AAAA,IACnC,iBAAiB,QAAQ;AAAA,IACzB,kBAAkB,QAAQ;AAAA,IAC1B,4BAA4B,QAAQ;AAAA,IACpC,wBAAwB,QAAQ;AAAA,IAChC,UAAU,QAAQ;AAAA,IAClB,mBAAmB,QAAQ;AAAA,IAC3B,oBAAoB,QAAQ,yBAAyB,OAAO,aAAa,QAAQ,qBAAqB,IAAI,QAAQ;AAAA,EACpH;AACF;AAcO,SAAS,8BAA8B,SAAiE;AAC7G,SAAO;AAAA,IACL,eAAe,QAAQ;AAAA,IACvB,UAAU,QAAQ;AAAA,IAClB,kBAAkB,QAAQ;AAAA,IAC1B,4BAA4B,QAAQ;AAAA,IACpC,cAAc,QAAQ;AAAA,IACtB,wBAAwB,QAAQ;AAAA,IAChC,iBAAiB,QAAQ;AAAA,IACzB,2BAA2B,QAAQ;AAAA,IACnC,iBAAiB,QAAQ;AAAA,EAC3B;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/stack-app/users/index.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { KnownErrors } from \"@stackframe/stack-shared\";\nimport { CurrentUserCrud } from \"@stackframe/stack-shared/dist/interface/crud/current-user\";\nimport { UsersCrud } from \"@stackframe/stack-shared/dist/interface/crud/users\";\nimport { InternalSession } from \"@stackframe/stack-shared/dist/sessions\";\nimport { encodeBase64 } from \"@stackframe/stack-shared/dist/utils/bytes\";\nimport { GeoInfo } from \"@stackframe/stack-shared/dist/utils/geo\";\nimport { ReadonlyJson } from \"@stackframe/stack-shared/dist/utils/json\";\nimport { ProviderType } from \"@stackframe/stack-shared/dist/utils/oauth\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport { ApiKeyCreationOptions, UserApiKey, UserApiKeyFirstView } from \"../api-keys\";\nimport { AsyncStoreProperty } from \"../common\";\nimport { OAuthConnection } from \"../connected-accounts\";\nimport { ContactChannel, ContactChannelCreateOptions, ServerContactChannel, ServerContactChannelCreateOptions } from \"../contact-channels\";\nimport { Customer } from \"../customers\";\nimport { NotificationCategory } from \"../notification-categories\";\nimport { AdminTeamPermission, TeamPermission } from \"../permissions\";\nimport { AdminOwnedProject, AdminProjectCreateOptions } from \"../projects\";\nimport { EditableTeamMemberProfile, ServerTeam, ServerTeamCreateOptions, Team, TeamCreateOptions } from \"../teams\";\n\nconst userGetterErrorMessage = \"Stack Auth: useUser() already returns the user object. Use `const user = useUser()` (or `const user = await app.getUser()`) instead of destructuring it like `const { user } = ...`.\";\n\nexport function attachUserDestructureGuard(target: object): void {\n const descriptor = Object.getOwnPropertyDescriptor(target, \"user\");\n if (descriptor?.get === guardGetter) {\n return;\n }\n\n Object.defineProperty(target, \"user\", {\n get: guardGetter,\n configurable: false,\n enumerable: false,\n });\n}\n\nfunction guardGetter(): never {\n throw new Error(userGetterErrorMessage);\n}\n\nexport type OAuthProvider = {\n readonly id: string,\n readonly type: string,\n readonly userId: string,\n readonly accountId?: string,\n readonly email?: string,\n readonly allowSignIn: boolean,\n readonly allowConnectedAccounts: boolean,\n update(data: { allowSignIn?: boolean, allowConnectedAccounts?: boolean }): Promise<Result<void,\n InstanceType<typeof KnownErrors.OAuthProviderAccountIdAlreadyUsedForSignIn>\n >>,\n delete(): Promise<void>,\n};\n\nexport type ServerOAuthProvider = {\n readonly id: string,\n readonly type: string,\n readonly userId: string,\n readonly accountId: string,\n readonly email?: string,\n readonly allowSignIn: boolean,\n readonly allowConnectedAccounts: boolean,\n update(data: { accountId?: string, email?: string, allowSignIn?: boolean, allowConnectedAccounts?: boolean }): Promise<Result<void,\n InstanceType<typeof KnownErrors.OAuthProviderAccountIdAlreadyUsedForSignIn>\n >>,\n delete(): Promise<void>,\n};\n\n\nexport type Session = {\n getTokens(): Promise<{ accessToken: string | null, refreshToken: string | null }>,\n};\n\n/**\n * Contains everything related to the current user session.\n */\nexport type Auth = {\n readonly _internalSession: InternalSession,\n readonly currentSession: Session,\n signOut(options?: { redirectUrl?: URL | string }): Promise<void>,\n\n /**\n * Returns headers for sending authenticated HTTP requests to external servers. Most commonly used in cross-origin\n * requests. Similar to `getAuthJson`, but specifically for HTTP requests.\n *\n * If you are using `tokenStore: \"cookie\"`, you don't need this for same-origin requests. However, most\n * browsers now disable third-party cookies by default, so we must pass authentication tokens by header instead\n * if the client and server are on different origins.\n *\n * This function returns a header object that can be used with `fetch` or other HTTP request libraries to send\n * authenticated requests.\n *\n * On the server, you can then pass in the `Request` object to the `tokenStore` option\n * of your Stack app. Please note that CORS does not allow most headers by default, so you\n * must include `x-stack-auth` in the [`Access-Control-Allow-Headers` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers)\n * of the CORS preflight response.\n *\n * If you are not using HTTP (and hence cannot set headers), you will need to use the `getAuthJson()` function\n * instead.\n *\n * Example:\n *\n * ```ts\n * // client\n * const res = await fetch(\"https://api.example.com\", {\n * headers: {\n * ...await stackApp.getAuthHeaders()\n * // you can also add your own headers here\n * },\n * });\n *\n * // server\n * function handleRequest(req: Request) {\n * const user = await stackServerApp.getUser({ tokenStore: req });\n * return new Response(\"Welcome, \" + user.displayName);\n * }\n * ```\n */\n getAuthHeaders(): Promise<{ \"x-stack-auth\": string }>,\n\n /**\n * Creates a JSON-serializable object containing the information to authenticate a user on an external server.\n * Similar to `getAuthHeaders`, but returns an object that can be sent over any protocol instead of just\n * HTTP headers.\n *\n * While `getAuthHeaders` is the recommended way to send authentication tokens over HTTP, your app may use\n * a different protocol, for example WebSockets or gRPC. This function returns a token object that can be JSON-serialized and sent to the server in any way you like.\n *\n * On the server, you can pass in this token object into the `tokenStore` option to fetch user details.\n *\n * Example:\n *\n * ```ts\n * // client\n * const res = await rpcCall(rpcEndpoint, {\n * data: {\n * auth: await stackApp.getAuthJson(),\n * },\n * });\n *\n * // server\n * function handleRequest(data) {\n * const user = await stackServerApp.getUser({ tokenStore: data.auth });\n * return new Response(\"Welcome, \" + user.displayName);\n * }\n * ```\n */\n getAuthJson(): Promise<{ accessToken: string | null, refreshToken: string | null }>,\n registerPasskey(options?: { hostname?: string }): Promise<Result<undefined, KnownErrors[\"PasskeyRegistrationFailed\"] | KnownErrors[\"PasskeyWebAuthnError\"]>>,\n};\n\n/**\n * ```\n * +----------+-------------+-------------------+\n * | \\ | !Server | Server |\n * +----------+-------------+-------------------+\n * | !Session | User | ServerUser |\n * | Session | CurrentUser | CurrentServerUser |\n * +----------+-------------+-------------------+\n * ```\n *\n * The fields on each of these types are available iff:\n * BaseUser: true\n * Auth: Session\n * ServerBaseUser: Server\n * UserExtra: Session OR Server\n *\n * The types are defined as follows (in the typescript manner):\n * User = BaseUser\n * CurrentUser = BaseUser & Auth & UserExtra\n * ServerUser = BaseUser & ServerBaseUser & UserExtra\n * CurrentServerUser = BaseUser & ServerBaseUser & Auth & UserExtra\n **/\n\nexport type BaseUser = {\n readonly id: string,\n\n readonly displayName: string | null,\n\n /**\n * The user's email address.\n *\n * Note: This might NOT be unique across multiple users, so always use `id` for unique identification.\n */\n readonly primaryEmail: string | null,\n readonly primaryEmailVerified: boolean,\n readonly profileImageUrl: string | null,\n\n readonly signedUpAt: Date,\n\n readonly clientMetadata: any,\n readonly clientReadOnlyMetadata: any,\n\n /**\n * Whether the user has a password set.\n */\n readonly hasPassword: boolean,\n readonly otpAuthEnabled: boolean,\n readonly passkeyAuthEnabled: boolean,\n\n readonly isMultiFactorRequired: boolean,\n readonly isAnonymous: boolean,\n toClientJson(): CurrentUserCrud[\"Client\"][\"Read\"],\n\n /**\n * @deprecated, use contact channel's usedForAuth instead\n */\n readonly emailAuthEnabled: boolean,\n /**\n * @deprecated\n */\n readonly oauthProviders: readonly { id: string }[],\n}\n\nexport type UserExtra = {\n setDisplayName(displayName: string): Promise<void>,\n /** @deprecated Use contact channel's sendVerificationEmail instead */\n sendVerificationEmail(): Promise<KnownErrors[\"EmailAlreadyVerified\"] | void>,\n setClientMetadata(metadata: any): Promise<void>,\n updatePassword(options: { oldPassword: string, newPassword: string}): Promise<KnownErrors[\"PasswordConfirmationMismatch\"] | KnownErrors[\"PasswordRequirementsNotMet\"] | void>,\n setPassword(options: { password: string }): Promise<KnownErrors[\"PasswordRequirementsNotMet\"] | void>,\n\n /**\n * A shorthand method to update multiple fields of the user at once.\n */\n update(update: UserUpdateOptions): Promise<void>,\n\n useContactChannels(): ContactChannel[], // THIS_LINE_PLATFORM react-like\n listContactChannels(): Promise<ContactChannel[]>,\n createContactChannel(data: ContactChannelCreateOptions): Promise<ContactChannel>,\n\n useNotificationCategories(): NotificationCategory[], // THIS_LINE_PLATFORM react-like\n listNotificationCategories(): Promise<NotificationCategory[]>,\n\n delete(): Promise<void>,\n\n getConnectedAccount(id: ProviderType, options: { or: 'redirect', scopes?: string[] }): Promise<OAuthConnection>,\n getConnectedAccount(id: ProviderType, options?: { or?: 'redirect' | 'throw' | 'return-null', scopes?: string[] }): Promise<OAuthConnection | null>,\n\n useConnectedAccount(id: ProviderType, options: { or: 'redirect', scopes?: string[] }): OAuthConnection,\n useConnectedAccount(id: ProviderType, options?: { or?: 'redirect' | 'throw' | 'return-null', scopes?: string[] }): OAuthConnection | null,\n\n hasPermission(scope: Team, permissionId: string): Promise<boolean>,\n hasPermission(permissionId: string): Promise<boolean>,\n\n getPermission(scope: Team, permissionId: string): Promise<TeamPermission | null>,\n getPermission(permissionId: string): Promise<TeamPermission | null>,\n\n listPermissions(scope: Team, options?: { recursive?: boolean }): Promise<TeamPermission[]>,\n listPermissions(options?: { recursive?: boolean }): Promise<TeamPermission[]>,\n\n usePermissions(scope: Team, options?: { recursive?: boolean }): TeamPermission[],\n usePermissions(options?: { recursive?: boolean }): TeamPermission[],\n\n usePermission(scope: Team, permissionId: string): TeamPermission | null,\n usePermission(permissionId: string): TeamPermission | null,\n\n readonly selectedTeam: Team | null,\n setSelectedTeam(team: Team | null): Promise<void>,\n createTeam(data: TeamCreateOptions): Promise<Team>,\n leaveTeam(team: Team): Promise<void>,\n\n getActiveSessions(): Promise<ActiveSession[]>,\n revokeSession(sessionId: string): Promise<void>,\n getTeamProfile(team: Team): Promise<EditableTeamMemberProfile>,\n useTeamProfile(team: Team): EditableTeamMemberProfile, // THIS_LINE_PLATFORM react-like\n\n createApiKey(options: ApiKeyCreationOptions<\"user\">): Promise<UserApiKeyFirstView>,\n\n useOAuthProviders(): OAuthProvider[], // THIS_LINE_PLATFORM react-like\n listOAuthProviders(): Promise<OAuthProvider[]>,\n\n useOAuthProvider(id: string): OAuthProvider | null, // THIS_LINE_PLATFORM react-like\n getOAuthProvider(id: string): Promise<OAuthProvider | null>,\n}\n& AsyncStoreProperty<\"apiKeys\", [], UserApiKey[], true>\n& AsyncStoreProperty<\"team\", [id: string], Team | null, false>\n& AsyncStoreProperty<\"teams\", [], Team[], true>\n& AsyncStoreProperty<\"permission\", [scope: Team, permissionId: string, options?: { recursive?: boolean }], TeamPermission | null, false>\n& AsyncStoreProperty<\"permissions\", [scope: Team, options?: { recursive?: boolean }], TeamPermission[], true>;\n\nexport type InternalUserExtra =\n & {\n createProject(newProject: AdminProjectCreateOptions): Promise<AdminOwnedProject>,\n transferProject(projectIdToTransfer: string, newTeamId: string): Promise<void>,\n }\n & AsyncStoreProperty<\"ownedProjects\", [], AdminOwnedProject[], true>\n\nexport type User = BaseUser;\n\nexport type CurrentUser = BaseUser & Auth & UserExtra & Customer;\n\nexport type CurrentInternalUser = CurrentUser & InternalUserExtra;\n\nexport type ProjectCurrentUser<ProjectId> = ProjectId extends \"internal\" ? CurrentInternalUser : CurrentUser;\n\nexport type TokenPartialUser = Pick<\n User,\n | \"id\"\n | \"displayName\"\n | \"primaryEmail\"\n | \"primaryEmailVerified\"\n | \"isAnonymous\"\n>\n\nexport type SyncedPartialUser = TokenPartialUser & Pick<\n User,\n | \"id\"\n | \"displayName\"\n | \"primaryEmail\"\n | \"primaryEmailVerified\"\n | \"profileImageUrl\"\n | \"signedUpAt\"\n | \"clientMetadata\"\n | \"clientReadOnlyMetadata\"\n | \"isAnonymous\"\n | \"hasPassword\"\n>;\n\n\nexport type ActiveSession = {\n id: string,\n userId: string,\n createdAt: Date,\n isImpersonation: boolean,\n lastUsedAt: Date | undefined,\n isCurrentSession: boolean,\n geoInfo?: GeoInfo,\n};\n\nexport type UserUpdateOptions = {\n displayName?: string,\n clientMetadata?: ReadonlyJson,\n selectedTeamId?: string | null,\n totpMultiFactorSecret?: Uint8Array | null,\n profileImageUrl?: string | null,\n otpAuthEnabled?: boolean,\n passkeyAuthEnabled?:boolean,\n}\nexport function userUpdateOptionsToCrud(options: UserUpdateOptions): CurrentUserCrud[\"Client\"][\"Update\"] {\n return {\n display_name: options.displayName,\n client_metadata: options.clientMetadata,\n selected_team_id: options.selectedTeamId,\n totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,\n profile_image_url: options.profileImageUrl,\n otp_auth_enabled: options.otpAuthEnabled,\n passkey_auth_enabled: options.passkeyAuthEnabled,\n };\n}\n\n\nexport type ServerBaseUser = {\n setPrimaryEmail(email: string | null, options?: { verified?: boolean | undefined }): Promise<void>,\n\n readonly lastActiveAt: Date,\n\n readonly serverMetadata: any,\n setServerMetadata(metadata: any): Promise<void>,\n setClientReadOnlyMetadata(metadata: any): Promise<void>,\n\n createTeam(data: Omit<ServerTeamCreateOptions, \"creatorUserId\">): Promise<ServerTeam>,\n\n useContactChannels(): ServerContactChannel[], // THIS_LINE_PLATFORM react-like\n listContactChannels(): Promise<ServerContactChannel[]>,\n createContactChannel(data: ServerContactChannelCreateOptions): Promise<ServerContactChannel>,\n\n update(user: ServerUserUpdateOptions): Promise<void>,\n\n grantPermission(scope: Team, permissionId: string): Promise<void>,\n grantPermission(permissionId: string): Promise<void>,\n\n revokePermission(scope: Team, permissionId: string): Promise<void>,\n revokePermission(permissionId: string): Promise<void>,\n\n getPermission(scope: Team, permissionId: string): Promise<TeamPermission | null>,\n getPermission(permissionId: string): Promise<TeamPermission | null>,\n\n hasPermission(scope: Team, permissionId: string): Promise<boolean>,\n hasPermission(permissionId: string): Promise<boolean>,\n\n listPermissions(scope: Team, options?: { recursive?: boolean }): Promise<TeamPermission[]>,\n listPermissions(options?: { recursive?: boolean }): Promise<TeamPermission[]>,\n\n usePermissions(scope: Team, options?: { recursive?: boolean }): TeamPermission[],\n usePermissions(options?: { recursive?: boolean }): TeamPermission[],\n\n usePermission(scope: Team, permissionId: string): TeamPermission | null,\n usePermission(permissionId: string): TeamPermission | null,\n\n useOAuthProviders(): ServerOAuthProvider[], // THIS_LINE_PLATFORM react-like\n listOAuthProviders(): Promise<ServerOAuthProvider[]>,\n\n useOAuthProvider(id: string): ServerOAuthProvider | null, // THIS_LINE_PLATFORM react-like\n getOAuthProvider(id: string): Promise<ServerOAuthProvider | null>,\n\n /**\n * Creates a new session object with a refresh token for this user. Can be used to impersonate them.\n */\n createSession(options?: { expiresInMillis?: number, isImpersonation?: boolean }): Promise<Session>,\n}\n& AsyncStoreProperty<\"team\", [id: string], ServerTeam | null, false>\n& AsyncStoreProperty<\"teams\", [], ServerTeam[], true>\n& AsyncStoreProperty<\"permission\", [scope: Team, permissionId: string, options?: { direct?: boolean }], AdminTeamPermission | null, false>\n& AsyncStoreProperty<\"permissions\", [scope: Team, options?: { direct?: boolean }], AdminTeamPermission[], true>;\n\n/**\n * A user including sensitive fields that should only be used on the server, never sent to the client\n * (such as sensitive information and serverMetadata).\n */\nexport type ServerUser = ServerBaseUser & BaseUser & UserExtra & Customer<true>;\n\nexport type CurrentServerUser = Auth & ServerUser;\n\nexport type CurrentInternalServerUser = CurrentServerUser & InternalUserExtra;\n\nexport type ProjectCurrentServerUser<ProjectId> = ProjectId extends \"internal\" ? CurrentInternalServerUser : CurrentServerUser;\n\nexport type SyncedPartialServerUser = SyncedPartialUser & Pick<\n ServerUser,\n | \"serverMetadata\"\n>;\n\nexport type ServerUserUpdateOptions = {\n primaryEmail?: string | null,\n primaryEmailVerified?: boolean,\n primaryEmailAuthEnabled?: boolean,\n clientReadOnlyMetadata?: ReadonlyJson,\n serverMetadata?: ReadonlyJson,\n password?: string,\n} & UserUpdateOptions;\nexport function serverUserUpdateOptionsToCrud(options: ServerUserUpdateOptions): CurrentUserCrud[\"Server\"][\"Update\"] {\n return {\n display_name: options.displayName,\n primary_email: options.primaryEmail,\n client_metadata: options.clientMetadata,\n client_read_only_metadata: options.clientReadOnlyMetadata,\n server_metadata: options.serverMetadata,\n selected_team_id: options.selectedTeamId,\n primary_email_auth_enabled: options.primaryEmailAuthEnabled,\n primary_email_verified: options.primaryEmailVerified,\n password: options.password,\n profile_image_url: options.profileImageUrl,\n totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,\n };\n}\n\n\nexport type ServerUserCreateOptions = {\n primaryEmail?: string | null,\n primaryEmailAuthEnabled?: boolean,\n password?: string,\n otpAuthEnabled?: boolean,\n displayName?: string,\n primaryEmailVerified?: boolean,\n clientMetadata?: any,\n clientReadOnlyMetadata?: any,\n serverMetadata?: any,\n}\nexport function serverUserCreateOptionsToCrud(options: ServerUserCreateOptions): UsersCrud[\"Server\"][\"Create\"] {\n return {\n primary_email: options.primaryEmail,\n password: options.password,\n otp_auth_enabled: options.otpAuthEnabled,\n primary_email_auth_enabled: options.primaryEmailAuthEnabled,\n display_name: options.displayName,\n primary_email_verified: options.primaryEmailVerified,\n client_metadata: options.clientMetadata,\n client_read_only_metadata: options.clientReadOnlyMetadata,\n server_metadata: options.serverMetadata,\n };\n}\n"],"mappings":";AAQA,SAAS,oBAAoB;AAe7B,IAAM,yBAAyB;AAExB,SAAS,2BAA2B,QAAsB;AAC/D,QAAM,aAAa,OAAO,yBAAyB,QAAQ,MAAM;AACjE,MAAI,YAAY,QAAQ,aAAa;AACnC;AAAA,EACF;AAEA,SAAO,eAAe,QAAQ,QAAQ;AAAA,IACpC,KAAK;AAAA,IACL,cAAc;AAAA,IACd,YAAY;AAAA,EACd,CAAC;AACH;AAEA,SAAS,cAAqB;AAC5B,QAAM,IAAI,MAAM,sBAAsB;AACxC;AA6SO,SAAS,wBAAwB,SAAiE;AACvG,SAAO;AAAA,IACL,cAAc,QAAQ;AAAA,IACtB,iBAAiB,QAAQ;AAAA,IACzB,kBAAkB,QAAQ;AAAA,IAC1B,oBAAoB,QAAQ,yBAAyB,OAAO,aAAa,QAAQ,qBAAqB,IAAI,QAAQ;AAAA,IAClH,mBAAmB,QAAQ;AAAA,IAC3B,kBAAkB,QAAQ;AAAA,IAC1B,sBAAsB,QAAQ;AAAA,EAChC;AACF;AAkFO,SAAS,8BAA8B,SAAuE;AACnH,SAAO;AAAA,IACL,cAAc,QAAQ;AAAA,IACtB,eAAe,QAAQ;AAAA,IACvB,iBAAiB,QAAQ;AAAA,IACzB,2BAA2B,QAAQ;AAAA,IACnC,iBAAiB,QAAQ;AAAA,IACzB,kBAAkB,QAAQ;AAAA,IAC1B,4BAA4B,QAAQ;AAAA,IACpC,wBAAwB,QAAQ;AAAA,IAChC,UAAU,QAAQ;AAAA,IAClB,mBAAmB,QAAQ;AAAA,IAC3B,oBAAoB,QAAQ,yBAAyB,OAAO,aAAa,QAAQ,qBAAqB,IAAI,QAAQ;AAAA,EACpH;AACF;AAcO,SAAS,8BAA8B,SAAiE;AAC7G,SAAO;AAAA,IACL,eAAe,QAAQ;AAAA,IACvB,UAAU,QAAQ;AAAA,IAClB,kBAAkB,QAAQ;AAAA,IAC1B,4BAA4B,QAAQ;AAAA,IACpC,cAAc,QAAQ;AAAA,IACtB,wBAAwB,QAAQ;AAAA,IAChC,iBAAiB,QAAQ;AAAA,IACzB,2BAA2B,QAAQ;AAAA,IACnC,iBAAiB,QAAQ;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
// src/providers/stack-provider.tsx
|
|
2
2
|
import { Suspense } from "react";
|
|
3
|
-
import { StackProviderClient
|
|
3
|
+
import { StackProviderClient } from "./stack-provider-client.js";
|
|
4
4
|
import { TranslationProvider } from "./translation-provider.js";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
function UserFetcher(props) {
|
|
7
|
-
const userPromise = props.app.getUser({ or: "anonymous-if-exists[deprecated]" }).then((user) => user?.toClientJson() ?? null);
|
|
8
|
-
return /* @__PURE__ */ jsx(UserSetter, { userJsonPromise: userPromise });
|
|
9
|
-
}
|
|
10
6
|
function ReactStackProvider({
|
|
11
7
|
children,
|
|
12
8
|
app,
|
|
@@ -14,7 +10,7 @@ function ReactStackProvider({
|
|
|
14
10
|
translationOverrides
|
|
15
11
|
}) {
|
|
16
12
|
return /* @__PURE__ */ jsxs(StackProviderClient, { app, serialized: false, children: [
|
|
17
|
-
/* @__PURE__ */ jsx(Suspense, { fallback: null
|
|
13
|
+
/* @__PURE__ */ jsx(Suspense, { fallback: null }),
|
|
18
14
|
/* @__PURE__ */ jsx(TranslationProvider, { lang, translationOverrides, children })
|
|
19
15
|
] });
|
|
20
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/providers/stack-provider.tsx"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport React, { Suspense } from 'react';\nimport { StackAdminApp, StackClientApp, StackServerApp, stackAppInternalsSymbol } from '../lib/stack-app';\nimport { StackProviderClient
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/stack-provider.tsx"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport React, { Suspense } from 'react';\nimport { StackAdminApp, StackClientApp, StackServerApp, stackAppInternalsSymbol } from '../lib/stack-app';\nimport { StackProviderClient } from './stack-provider-client';\nimport { TranslationProvider } from './translation-provider';\n\nfunction ReactStackProvider({\n children,\n app,\n lang,\n translationOverrides,\n}: {\n lang?: React.ComponentProps<typeof TranslationProvider>['lang'],\n /**\n * A mapping of English translations to translated equivalents.\n *\n * These will take priority over the translations from the language specified in the `lang` property. Note that the\n * keys are case-sensitive.\n */\n translationOverrides?: Record<string, string>,\n children: React.ReactNode,\n // list all three types of apps even though server and admin are subclasses of client so it's clear that you can pass any\n app: StackClientApp<true>,\n}) {\n return (\n <StackProviderClient app={app as any} serialized={false}>\n <Suspense fallback={null} />\n <TranslationProvider lang={lang} translationOverrides={translationOverrides}>\n {children}\n </TranslationProvider>\n </StackProviderClient>\n );\n}\n\nexport default ReactStackProvider;\n"],"mappings":";AAIA,SAAgB,gBAAgB;AAEhC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AAqBhC,SACE,KADF;AAnBJ,SAAS,mBAAmB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAYG;AACD,SACE,qBAAC,uBAAoB,KAAiB,YAAY,OAChD;AAAA,wBAAC,YAAS,UAAU,MAAM;AAAA,IAC1B,oBAAC,uBAAoB,MAAY,sBAC9B,UACH;AAAA,KACF;AAEJ;AAEA,IAAO,yBAAQ;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { CurrentUserCrud } from '@stackframe/stack-shared/dist/interface/crud/cu
|
|
|
3
3
|
import { Result } from '@stackframe/stack-shared/dist/utils/results';
|
|
4
4
|
import { ProviderType } from '@stackframe/stack-shared/dist/utils/oauth';
|
|
5
5
|
import { GenericQueryCtx, UserIdentity } from 'convex/server';
|
|
6
|
-
import {
|
|
6
|
+
import { inlineProductSchema } from '@stackframe/stack-shared/dist/schema-fields';
|
|
7
7
|
import * as yup from 'yup';
|
|
8
8
|
import { ProductionModeError } from '@stackframe/stack-shared/dist/helpers/production-mode';
|
|
9
9
|
import { CompleteConfig, EnvironmentConfigOverrideOverride } from '@stackframe/stack-shared/dist/config/schema';
|
|
@@ -95,7 +95,7 @@ type OAuthScopesOnSignIn = {
|
|
|
95
95
|
/** @internal */
|
|
96
96
|
declare const stackAppInternalsSymbol: unique symbol;
|
|
97
97
|
|
|
98
|
-
type
|
|
98
|
+
type InlineProduct = yup.InferType<typeof inlineProductSchema>;
|
|
99
99
|
type Item = {
|
|
100
100
|
displayName: string;
|
|
101
101
|
/**
|
|
@@ -122,16 +122,50 @@ type ServerItem = Item & {
|
|
|
122
122
|
*/
|
|
123
123
|
tryDecreaseQuantity(amount: number): Promise<boolean>;
|
|
124
124
|
};
|
|
125
|
+
type CustomerProduct = {
|
|
126
|
+
id: string | null;
|
|
127
|
+
quantity: number;
|
|
128
|
+
displayName: string;
|
|
129
|
+
customerType: "user" | "team" | "custom";
|
|
130
|
+
isServerOnly: boolean;
|
|
131
|
+
stackable: boolean;
|
|
132
|
+
};
|
|
133
|
+
type CustomerProductsList = CustomerProduct[] & {
|
|
134
|
+
nextCursor: string | null;
|
|
135
|
+
};
|
|
136
|
+
type CustomerProductsListOptions = {
|
|
137
|
+
cursor?: string;
|
|
138
|
+
limit?: number;
|
|
139
|
+
};
|
|
140
|
+
type CustomerProductsRequestOptions = ({
|
|
141
|
+
userId: string;
|
|
142
|
+
} & CustomerProductsListOptions) | ({
|
|
143
|
+
teamId: string;
|
|
144
|
+
} & CustomerProductsListOptions) | ({
|
|
145
|
+
customCustomerId: string;
|
|
146
|
+
} & CustomerProductsListOptions);
|
|
125
147
|
type Customer<IsServer extends boolean = false> = {
|
|
126
148
|
readonly id: string;
|
|
127
149
|
createCheckoutUrl(options: ({
|
|
128
|
-
|
|
150
|
+
productId: string;
|
|
151
|
+
returnUrl?: string;
|
|
129
152
|
} | (IsServer extends true ? {
|
|
130
|
-
|
|
153
|
+
product: InlineProduct;
|
|
154
|
+
returnUrl?: string;
|
|
131
155
|
} : never))): Promise<string>;
|
|
132
156
|
} & AsyncStoreProperty<"item", [
|
|
133
157
|
itemId: string
|
|
134
|
-
], IsServer extends true ? ServerItem : Item, false
|
|
158
|
+
], IsServer extends true ? ServerItem : Item, false> & AsyncStoreProperty<"products", [
|
|
159
|
+
options?: CustomerProductsListOptions
|
|
160
|
+
], CustomerProductsList, true> & (IsServer extends true ? {
|
|
161
|
+
grantProduct(product: {
|
|
162
|
+
productId: string;
|
|
163
|
+
quantity?: number;
|
|
164
|
+
} | {
|
|
165
|
+
product: InlineProduct;
|
|
166
|
+
quantity?: number;
|
|
167
|
+
}): Promise<void>;
|
|
168
|
+
} : {});
|
|
135
169
|
|
|
136
170
|
type AdminSentEmail = {
|
|
137
171
|
id: string;
|
|
@@ -589,6 +623,7 @@ type UserExtra = {
|
|
|
589
623
|
}], TeamPermission[], true>;
|
|
590
624
|
type InternalUserExtra = {
|
|
591
625
|
createProject(newProject: AdminProjectCreateOptions): Promise<AdminOwnedProject>;
|
|
626
|
+
transferProject(projectIdToTransfer: string, newTeamId: string): Promise<void>;
|
|
592
627
|
} & AsyncStoreProperty<"ownedProjects", [], AdminOwnedProject[], true>;
|
|
593
628
|
type User = BaseUser;
|
|
594
629
|
type CurrentUser = BaseUser & Auth & UserExtra & Customer;
|
|
@@ -790,6 +825,19 @@ type StackServerApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
790
825
|
*/
|
|
791
826
|
getServerUser(): Promise<ProjectCurrentServerUser<ProjectId> | null>;
|
|
792
827
|
createUser(options: ServerUserCreateOptions): Promise<ServerUser>;
|
|
828
|
+
grantProduct(options: (({
|
|
829
|
+
userId: string;
|
|
830
|
+
} | {
|
|
831
|
+
teamId: string;
|
|
832
|
+
} | {
|
|
833
|
+
customCustomerId: string;
|
|
834
|
+
}) & ({
|
|
835
|
+
productId: string;
|
|
836
|
+
} | {
|
|
837
|
+
product: InlineProduct;
|
|
838
|
+
}) & {
|
|
839
|
+
quantity?: number;
|
|
840
|
+
})): Promise<void>;
|
|
793
841
|
useUser(options: GetCurrentUserOptions<HasTokenStore> & {
|
|
794
842
|
or: 'redirect';
|
|
795
843
|
}): ProjectCurrentServerUser<ProjectId>;
|
|
@@ -878,14 +926,15 @@ type StackServerApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
878
926
|
itemId: string;
|
|
879
927
|
customCustomerId: string;
|
|
880
928
|
}
|
|
881
|
-
], ServerItem, false> &
|
|
929
|
+
], ServerItem, false> & AsyncStoreProperty<"products", [
|
|
930
|
+
options: CustomerProductsRequestOptions
|
|
931
|
+
], CustomerProductsList, true> & StackClientApp<HasTokenStore, ProjectId>);
|
|
882
932
|
declare const StackServerApp: StackServerAppConstructor;
|
|
883
933
|
|
|
884
|
-
type StackAdminAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = (
|
|
934
|
+
type StackAdminAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = (StackServerAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
885
935
|
superSecretAdminKey?: string;
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
}));
|
|
936
|
+
projectOwnerSession?: InternalSession;
|
|
937
|
+
});
|
|
889
938
|
type StackAdminAppConstructor = {
|
|
890
939
|
new <HasTokenStore extends boolean, ProjectId extends string>(options: StackAdminAppConstructorOptions<HasTokenStore, ProjectId>): StackAdminApp<HasTokenStore, ProjectId>;
|
|
891
940
|
new (options: StackAdminAppConstructorOptions<boolean, string>): StackAdminApp<boolean, string>;
|
|
@@ -1002,11 +1051,6 @@ type StackAdminApp<HasTokenStore extends boolean = boolean, ProjectId extends st
|
|
|
1002
1051
|
expiresAt?: string;
|
|
1003
1052
|
description?: string;
|
|
1004
1053
|
})): Promise<void>;
|
|
1005
|
-
testModePurchase(options: {
|
|
1006
|
-
priceId: string;
|
|
1007
|
-
fullCode: string;
|
|
1008
|
-
quantity?: number;
|
|
1009
|
-
}): Promise<void>;
|
|
1010
1054
|
} & StackServerApp<HasTokenStore, ProjectId>);
|
|
1011
1055
|
declare const StackAdminApp: StackAdminAppConstructor;
|
|
1012
1056
|
|
|
@@ -1117,7 +1161,6 @@ type AdminProject = {
|
|
|
1117
1161
|
readonly config: AdminProjectConfig;
|
|
1118
1162
|
update(this: AdminProject, update: AdminProjectUpdateOptions): Promise<void>;
|
|
1119
1163
|
delete(this: AdminProject): Promise<void>;
|
|
1120
|
-
transfer(this: AdminProject, user: CurrentUser, newTeamId: string): Promise<void>;
|
|
1121
1164
|
getConfig(this: AdminProject): Promise<CompleteConfig>;
|
|
1122
1165
|
useConfig(this: AdminProject): CompleteConfig;
|
|
1123
1166
|
updateConfig(this: AdminProject, config: EnvironmentConfigOverrideOverride): Promise<void>;
|
|
@@ -1150,16 +1193,28 @@ type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId e
|
|
|
1150
1193
|
publishableClientKey?: string;
|
|
1151
1194
|
urls?: Partial<HandlerUrls>;
|
|
1152
1195
|
oauthScopesOnSignIn?: Partial<OAuthScopesOnSignIn>;
|
|
1153
|
-
tokenStore
|
|
1196
|
+
tokenStore?: TokenStoreInit<HasTokenStore>;
|
|
1154
1197
|
redirectMethod?: RedirectMethod;
|
|
1198
|
+
inheritsFrom?: StackClientApp<any, any>;
|
|
1155
1199
|
/**
|
|
1156
1200
|
* By default, the Stack app will automatically prefetch some data from Stack's server when this app is first
|
|
1157
1201
|
* constructed. This improves the performance of your app, but will create network requests that are unnecessary if
|
|
1158
1202
|
* the app is never used or disposed of immediately. To disable this behavior, set this option to true.
|
|
1159
1203
|
*/
|
|
1160
1204
|
noAutomaticPrefetch?: boolean;
|
|
1161
|
-
}
|
|
1205
|
+
} & ({
|
|
1206
|
+
tokenStore: TokenStoreInit<HasTokenStore>;
|
|
1207
|
+
} | {
|
|
1208
|
+
tokenStore?: undefined;
|
|
1209
|
+
inheritsFrom: StackClientApp<HasTokenStore, any>;
|
|
1210
|
+
}) & (string extends ProjectId ? unknown : ({
|
|
1211
|
+
projectId: ProjectId;
|
|
1212
|
+
} | {
|
|
1213
|
+
inheritsFrom: StackClientApp<any, ProjectId>;
|
|
1214
|
+
}));
|
|
1162
1215
|
type StackClientAppJson<HasTokenStore extends boolean, ProjectId extends string> = StackClientAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
1216
|
+
inheritsFrom?: undefined;
|
|
1217
|
+
} & {
|
|
1163
1218
|
uniqueIdentifier: string;
|
|
1164
1219
|
};
|
|
1165
1220
|
type StackClientAppConstructor = {
|
|
@@ -1218,8 +1273,10 @@ type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
1218
1273
|
noRedirect?: boolean;
|
|
1219
1274
|
}): Promise<Result<undefined, KnownErrors["VerificationCodeError"] | KnownErrors["InvalidTotpCode"]>>;
|
|
1220
1275
|
redirectToOAuthCallback(): Promise<void>;
|
|
1221
|
-
getConvexClientAuth(options: {
|
|
1276
|
+
getConvexClientAuth(options: HasTokenStore extends false ? {
|
|
1222
1277
|
tokenStore: TokenStoreInit;
|
|
1278
|
+
} : {
|
|
1279
|
+
tokenStore?: TokenStoreInit;
|
|
1223
1280
|
}): (args: {
|
|
1224
1281
|
forceRefreshToken: boolean;
|
|
1225
1282
|
}) => Promise<string | null>;
|
|
@@ -1264,6 +1321,9 @@ type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
1264
1321
|
[stackAppInternalsSymbol]: {
|
|
1265
1322
|
toClientJson(): StackClientAppJson<HasTokenStore, ProjectId>;
|
|
1266
1323
|
setCurrentUser(userJsonPromise: Promise<CurrentUserCrud['Client']['Read'] | null>): void;
|
|
1324
|
+
getConstructorOptions(): StackClientAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
1325
|
+
inheritsFrom?: undefined;
|
|
1326
|
+
};
|
|
1267
1327
|
};
|
|
1268
1328
|
} & AsyncStoreProperty<"project", [], Project, false> & AsyncStoreProperty<"item", [
|
|
1269
1329
|
{
|
|
@@ -1276,17 +1336,20 @@ type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
1276
1336
|
itemId: string;
|
|
1277
1337
|
customCustomerId: string;
|
|
1278
1338
|
}
|
|
1279
|
-
], Item, false> &
|
|
1339
|
+
], Item, false> & AsyncStoreProperty<"products", [
|
|
1340
|
+
options: CustomerProductsRequestOptions
|
|
1341
|
+
], CustomerProductsList, true> & {
|
|
1280
1342
|
[K in `redirectTo${Capitalize<keyof Omit<HandlerUrls, 'handler' | 'oauthCallback'>>}`]: (options?: RedirectToOptions) => Promise<void>;
|
|
1281
1343
|
});
|
|
1282
1344
|
declare const StackClientApp: StackClientAppConstructor;
|
|
1283
1345
|
|
|
1284
1346
|
declare function getConvexProvidersConfig(options: {
|
|
1285
|
-
|
|
1347
|
+
baseUrl?: string;
|
|
1348
|
+
projectId: string;
|
|
1286
1349
|
}): {
|
|
1287
1350
|
type: string;
|
|
1288
|
-
issuer:
|
|
1289
|
-
jwks:
|
|
1351
|
+
issuer: URL;
|
|
1352
|
+
jwks: URL;
|
|
1290
1353
|
algorithm: string;
|
|
1291
1354
|
}[];
|
|
1292
1355
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CurrentUserCrud } from '@stackframe/stack-shared/dist/interface/crud/cu
|
|
|
3
3
|
import { Result } from '@stackframe/stack-shared/dist/utils/results';
|
|
4
4
|
import { ProviderType } from '@stackframe/stack-shared/dist/utils/oauth';
|
|
5
5
|
import { GenericQueryCtx, UserIdentity } from 'convex/server';
|
|
6
|
-
import {
|
|
6
|
+
import { inlineProductSchema } from '@stackframe/stack-shared/dist/schema-fields';
|
|
7
7
|
import * as yup from 'yup';
|
|
8
8
|
import { ProductionModeError } from '@stackframe/stack-shared/dist/helpers/production-mode';
|
|
9
9
|
import { CompleteConfig, EnvironmentConfigOverrideOverride } from '@stackframe/stack-shared/dist/config/schema';
|
|
@@ -95,7 +95,7 @@ type OAuthScopesOnSignIn = {
|
|
|
95
95
|
/** @internal */
|
|
96
96
|
declare const stackAppInternalsSymbol: unique symbol;
|
|
97
97
|
|
|
98
|
-
type
|
|
98
|
+
type InlineProduct = yup.InferType<typeof inlineProductSchema>;
|
|
99
99
|
type Item = {
|
|
100
100
|
displayName: string;
|
|
101
101
|
/**
|
|
@@ -122,16 +122,50 @@ type ServerItem = Item & {
|
|
|
122
122
|
*/
|
|
123
123
|
tryDecreaseQuantity(amount: number): Promise<boolean>;
|
|
124
124
|
};
|
|
125
|
+
type CustomerProduct = {
|
|
126
|
+
id: string | null;
|
|
127
|
+
quantity: number;
|
|
128
|
+
displayName: string;
|
|
129
|
+
customerType: "user" | "team" | "custom";
|
|
130
|
+
isServerOnly: boolean;
|
|
131
|
+
stackable: boolean;
|
|
132
|
+
};
|
|
133
|
+
type CustomerProductsList = CustomerProduct[] & {
|
|
134
|
+
nextCursor: string | null;
|
|
135
|
+
};
|
|
136
|
+
type CustomerProductsListOptions = {
|
|
137
|
+
cursor?: string;
|
|
138
|
+
limit?: number;
|
|
139
|
+
};
|
|
140
|
+
type CustomerProductsRequestOptions = ({
|
|
141
|
+
userId: string;
|
|
142
|
+
} & CustomerProductsListOptions) | ({
|
|
143
|
+
teamId: string;
|
|
144
|
+
} & CustomerProductsListOptions) | ({
|
|
145
|
+
customCustomerId: string;
|
|
146
|
+
} & CustomerProductsListOptions);
|
|
125
147
|
type Customer<IsServer extends boolean = false> = {
|
|
126
148
|
readonly id: string;
|
|
127
149
|
createCheckoutUrl(options: ({
|
|
128
|
-
|
|
150
|
+
productId: string;
|
|
151
|
+
returnUrl?: string;
|
|
129
152
|
} | (IsServer extends true ? {
|
|
130
|
-
|
|
153
|
+
product: InlineProduct;
|
|
154
|
+
returnUrl?: string;
|
|
131
155
|
} : never))): Promise<string>;
|
|
132
156
|
} & AsyncStoreProperty<"item", [
|
|
133
157
|
itemId: string
|
|
134
|
-
], IsServer extends true ? ServerItem : Item, false
|
|
158
|
+
], IsServer extends true ? ServerItem : Item, false> & AsyncStoreProperty<"products", [
|
|
159
|
+
options?: CustomerProductsListOptions
|
|
160
|
+
], CustomerProductsList, true> & (IsServer extends true ? {
|
|
161
|
+
grantProduct(product: {
|
|
162
|
+
productId: string;
|
|
163
|
+
quantity?: number;
|
|
164
|
+
} | {
|
|
165
|
+
product: InlineProduct;
|
|
166
|
+
quantity?: number;
|
|
167
|
+
}): Promise<void>;
|
|
168
|
+
} : {});
|
|
135
169
|
|
|
136
170
|
type AdminSentEmail = {
|
|
137
171
|
id: string;
|
|
@@ -589,6 +623,7 @@ type UserExtra = {
|
|
|
589
623
|
}], TeamPermission[], true>;
|
|
590
624
|
type InternalUserExtra = {
|
|
591
625
|
createProject(newProject: AdminProjectCreateOptions): Promise<AdminOwnedProject>;
|
|
626
|
+
transferProject(projectIdToTransfer: string, newTeamId: string): Promise<void>;
|
|
592
627
|
} & AsyncStoreProperty<"ownedProjects", [], AdminOwnedProject[], true>;
|
|
593
628
|
type User = BaseUser;
|
|
594
629
|
type CurrentUser = BaseUser & Auth & UserExtra & Customer;
|
|
@@ -790,6 +825,19 @@ type StackServerApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
790
825
|
*/
|
|
791
826
|
getServerUser(): Promise<ProjectCurrentServerUser<ProjectId> | null>;
|
|
792
827
|
createUser(options: ServerUserCreateOptions): Promise<ServerUser>;
|
|
828
|
+
grantProduct(options: (({
|
|
829
|
+
userId: string;
|
|
830
|
+
} | {
|
|
831
|
+
teamId: string;
|
|
832
|
+
} | {
|
|
833
|
+
customCustomerId: string;
|
|
834
|
+
}) & ({
|
|
835
|
+
productId: string;
|
|
836
|
+
} | {
|
|
837
|
+
product: InlineProduct;
|
|
838
|
+
}) & {
|
|
839
|
+
quantity?: number;
|
|
840
|
+
})): Promise<void>;
|
|
793
841
|
useUser(options: GetCurrentUserOptions<HasTokenStore> & {
|
|
794
842
|
or: 'redirect';
|
|
795
843
|
}): ProjectCurrentServerUser<ProjectId>;
|
|
@@ -878,14 +926,15 @@ type StackServerApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
878
926
|
itemId: string;
|
|
879
927
|
customCustomerId: string;
|
|
880
928
|
}
|
|
881
|
-
], ServerItem, false> &
|
|
929
|
+
], ServerItem, false> & AsyncStoreProperty<"products", [
|
|
930
|
+
options: CustomerProductsRequestOptions
|
|
931
|
+
], CustomerProductsList, true> & StackClientApp<HasTokenStore, ProjectId>);
|
|
882
932
|
declare const StackServerApp: StackServerAppConstructor;
|
|
883
933
|
|
|
884
|
-
type StackAdminAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = (
|
|
934
|
+
type StackAdminAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = (StackServerAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
885
935
|
superSecretAdminKey?: string;
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
}));
|
|
936
|
+
projectOwnerSession?: InternalSession;
|
|
937
|
+
});
|
|
889
938
|
type StackAdminAppConstructor = {
|
|
890
939
|
new <HasTokenStore extends boolean, ProjectId extends string>(options: StackAdminAppConstructorOptions<HasTokenStore, ProjectId>): StackAdminApp<HasTokenStore, ProjectId>;
|
|
891
940
|
new (options: StackAdminAppConstructorOptions<boolean, string>): StackAdminApp<boolean, string>;
|
|
@@ -1002,11 +1051,6 @@ type StackAdminApp<HasTokenStore extends boolean = boolean, ProjectId extends st
|
|
|
1002
1051
|
expiresAt?: string;
|
|
1003
1052
|
description?: string;
|
|
1004
1053
|
})): Promise<void>;
|
|
1005
|
-
testModePurchase(options: {
|
|
1006
|
-
priceId: string;
|
|
1007
|
-
fullCode: string;
|
|
1008
|
-
quantity?: number;
|
|
1009
|
-
}): Promise<void>;
|
|
1010
1054
|
} & StackServerApp<HasTokenStore, ProjectId>);
|
|
1011
1055
|
declare const StackAdminApp: StackAdminAppConstructor;
|
|
1012
1056
|
|
|
@@ -1117,7 +1161,6 @@ type AdminProject = {
|
|
|
1117
1161
|
readonly config: AdminProjectConfig;
|
|
1118
1162
|
update(this: AdminProject, update: AdminProjectUpdateOptions): Promise<void>;
|
|
1119
1163
|
delete(this: AdminProject): Promise<void>;
|
|
1120
|
-
transfer(this: AdminProject, user: CurrentUser, newTeamId: string): Promise<void>;
|
|
1121
1164
|
getConfig(this: AdminProject): Promise<CompleteConfig>;
|
|
1122
1165
|
useConfig(this: AdminProject): CompleteConfig;
|
|
1123
1166
|
updateConfig(this: AdminProject, config: EnvironmentConfigOverrideOverride): Promise<void>;
|
|
@@ -1150,16 +1193,28 @@ type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId e
|
|
|
1150
1193
|
publishableClientKey?: string;
|
|
1151
1194
|
urls?: Partial<HandlerUrls>;
|
|
1152
1195
|
oauthScopesOnSignIn?: Partial<OAuthScopesOnSignIn>;
|
|
1153
|
-
tokenStore
|
|
1196
|
+
tokenStore?: TokenStoreInit<HasTokenStore>;
|
|
1154
1197
|
redirectMethod?: RedirectMethod;
|
|
1198
|
+
inheritsFrom?: StackClientApp<any, any>;
|
|
1155
1199
|
/**
|
|
1156
1200
|
* By default, the Stack app will automatically prefetch some data from Stack's server when this app is first
|
|
1157
1201
|
* constructed. This improves the performance of your app, but will create network requests that are unnecessary if
|
|
1158
1202
|
* the app is never used or disposed of immediately. To disable this behavior, set this option to true.
|
|
1159
1203
|
*/
|
|
1160
1204
|
noAutomaticPrefetch?: boolean;
|
|
1161
|
-
}
|
|
1205
|
+
} & ({
|
|
1206
|
+
tokenStore: TokenStoreInit<HasTokenStore>;
|
|
1207
|
+
} | {
|
|
1208
|
+
tokenStore?: undefined;
|
|
1209
|
+
inheritsFrom: StackClientApp<HasTokenStore, any>;
|
|
1210
|
+
}) & (string extends ProjectId ? unknown : ({
|
|
1211
|
+
projectId: ProjectId;
|
|
1212
|
+
} | {
|
|
1213
|
+
inheritsFrom: StackClientApp<any, ProjectId>;
|
|
1214
|
+
}));
|
|
1162
1215
|
type StackClientAppJson<HasTokenStore extends boolean, ProjectId extends string> = StackClientAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
1216
|
+
inheritsFrom?: undefined;
|
|
1217
|
+
} & {
|
|
1163
1218
|
uniqueIdentifier: string;
|
|
1164
1219
|
};
|
|
1165
1220
|
type StackClientAppConstructor = {
|
|
@@ -1218,8 +1273,10 @@ type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
1218
1273
|
noRedirect?: boolean;
|
|
1219
1274
|
}): Promise<Result<undefined, KnownErrors["VerificationCodeError"] | KnownErrors["InvalidTotpCode"]>>;
|
|
1220
1275
|
redirectToOAuthCallback(): Promise<void>;
|
|
1221
|
-
getConvexClientAuth(options: {
|
|
1276
|
+
getConvexClientAuth(options: HasTokenStore extends false ? {
|
|
1222
1277
|
tokenStore: TokenStoreInit;
|
|
1278
|
+
} : {
|
|
1279
|
+
tokenStore?: TokenStoreInit;
|
|
1223
1280
|
}): (args: {
|
|
1224
1281
|
forceRefreshToken: boolean;
|
|
1225
1282
|
}) => Promise<string | null>;
|
|
@@ -1264,6 +1321,9 @@ type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
1264
1321
|
[stackAppInternalsSymbol]: {
|
|
1265
1322
|
toClientJson(): StackClientAppJson<HasTokenStore, ProjectId>;
|
|
1266
1323
|
setCurrentUser(userJsonPromise: Promise<CurrentUserCrud['Client']['Read'] | null>): void;
|
|
1324
|
+
getConstructorOptions(): StackClientAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
1325
|
+
inheritsFrom?: undefined;
|
|
1326
|
+
};
|
|
1267
1327
|
};
|
|
1268
1328
|
} & AsyncStoreProperty<"project", [], Project, false> & AsyncStoreProperty<"item", [
|
|
1269
1329
|
{
|
|
@@ -1276,17 +1336,20 @@ type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
1276
1336
|
itemId: string;
|
|
1277
1337
|
customCustomerId: string;
|
|
1278
1338
|
}
|
|
1279
|
-
], Item, false> &
|
|
1339
|
+
], Item, false> & AsyncStoreProperty<"products", [
|
|
1340
|
+
options: CustomerProductsRequestOptions
|
|
1341
|
+
], CustomerProductsList, true> & {
|
|
1280
1342
|
[K in `redirectTo${Capitalize<keyof Omit<HandlerUrls, 'handler' | 'oauthCallback'>>}`]: (options?: RedirectToOptions) => Promise<void>;
|
|
1281
1343
|
});
|
|
1282
1344
|
declare const StackClientApp: StackClientAppConstructor;
|
|
1283
1345
|
|
|
1284
1346
|
declare function getConvexProvidersConfig(options: {
|
|
1285
|
-
|
|
1347
|
+
baseUrl?: string;
|
|
1348
|
+
projectId: string;
|
|
1286
1349
|
}): {
|
|
1287
1350
|
type: string;
|
|
1288
|
-
issuer:
|
|
1289
|
-
jwks:
|
|
1351
|
+
issuer: URL;
|
|
1352
|
+
jwks: URL;
|
|
1290
1353
|
algorithm: string;
|
|
1291
1354
|
}[];
|
|
1292
1355
|
|