@stackframe/stack 1.0.0
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/LICENSE +7 -0
- package/dist/components/EmailVerification.d.ts +5 -0
- package/dist/components/EmailVerification.js +29 -0
- package/dist/components/ForgotPassword.d.ts +3 -0
- package/dist/components/ForgotPassword.js +22 -0
- package/dist/components/OauthCallback.d.ts +1 -0
- package/dist/components/OauthCallback.js +20 -0
- package/dist/components/PasswordReset.d.ts +4 -0
- package/dist/components/PasswordReset.js +36 -0
- package/dist/components/SignIn.d.ts +4 -0
- package/dist/components/SignIn.js +18 -0
- package/dist/components/SignOut.d.ts +3 -0
- package/dist/components/SignOut.js +12 -0
- package/dist/components/SignUp.d.ts +4 -0
- package/dist/components/SignUp.js +18 -0
- package/dist/components/StackHandler.d.ts +8 -0
- package/dist/components/StackHandler.js +58 -0
- package/dist/elements/Button.d.ts +10 -0
- package/dist/elements/Button.js +18 -0
- package/dist/elements/CardFrame.d.ts +5 -0
- package/dist/elements/CardFrame.js +10 -0
- package/dist/elements/CardHeader.d.ts +5 -0
- package/dist/elements/CardHeader.js +4 -0
- package/dist/elements/CredentialSignIn.d.ts +3 -0
- package/dist/elements/CredentialSignIn.js +57 -0
- package/dist/elements/CredentialSignUp.d.ts +3 -0
- package/dist/elements/CredentialSignUp.js +73 -0
- package/dist/elements/DividerWithText.d.ts +3 -0
- package/dist/elements/DividerWithText.js +5 -0
- package/dist/elements/ForgotPassword.d.ts +3 -0
- package/dist/elements/ForgotPassword.js +32 -0
- package/dist/elements/FormWarning.d.ts +3 -0
- package/dist/elements/FormWarning.js +7 -0
- package/dist/elements/MessageCard.d.ts +6 -0
- package/dist/elements/MessageCard.js +5 -0
- package/dist/elements/OauthButton.d.ts +5 -0
- package/dist/elements/OauthButton.js +67 -0
- package/dist/elements/OauthGroup.d.ts +4 -0
- package/dist/elements/OauthGroup.js +11 -0
- package/dist/elements/PasswordField.d.ts +2 -0
- package/dist/elements/PasswordField.js +27 -0
- package/dist/elements/PasswordResetInner.d.ts +4 -0
- package/dist/elements/PasswordResetInner.js +61 -0
- package/dist/elements/RedirectMessageCard.d.ts +4 -0
- package/dist/elements/RedirectMessageCard.js +49 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +12 -0
- package/dist/lib/auth.d.ts +19 -0
- package/dist/lib/auth.js +85 -0
- package/dist/lib/cookie.d.ts +12 -0
- package/dist/lib/cookie.js +60 -0
- package/dist/lib/hooks.d.ts +21 -0
- package/dist/lib/hooks.js +21 -0
- package/dist/lib/stack-app.d.ts +172 -0
- package/dist/lib/stack-app.js +575 -0
- package/dist/providers/StackProvider.d.ts +6 -0
- package/dist/providers/StackProvider.js +6 -0
- package/dist/providers/StackProviderClient.d.ts +9 -0
- package/dist/providers/StackProviderClient.js +14 -0
- package/dist/tailwind.css +1293 -0
- package/dist/utils/email.d.ts +1 -0
- package/dist/utils/email.js +7 -0
- package/dist/utils/next.d.ts +1 -0
- package/dist/utils/next.js +4 -0
- package/dist/utils/react.d.ts +1 -0
- package/dist/utils/react.js +6 -0
- package/dist/utils/results.d.ts +24 -0
- package/dist/utils/results.js +46 -0
- package/dist/utils/types.d.ts +3 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/url.d.ts +2 -0
- package/dist/utils/url.js +16 -0
- package/package.json +50 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { OauthProviderConfigJson, ServerUserCustomizableJson, ServerUserJson } from "@stackframe/stack-shared";
|
|
2
|
+
import { ClientProjectJson, UserCustomizableJson, UserJson, EmailConfigJson, DomainConfigJson } from "@stackframe/stack-shared/dist/interface/clientInterface";
|
|
3
|
+
import { ReadonlyJson } from "../utils/types";
|
|
4
|
+
import { EmailVerificationLinkErrorCode, PasswordResetLinkErrorCode, SignInErrorCode, SignUpErrorCode } from "@stackframe/stack-shared/dist/utils/types";
|
|
5
|
+
export type TokenStoreOptions<HasTokenStore extends boolean = boolean> = HasTokenStore extends true ? "cookie" | "nextjs-cookie" | "memory" : HasTokenStore extends false ? null : TokenStoreOptions<true> | TokenStoreOptions<false>;
|
|
6
|
+
export type HandlerUrls = {
|
|
7
|
+
handler: string;
|
|
8
|
+
signIn: string;
|
|
9
|
+
signUp: string;
|
|
10
|
+
signOut: string;
|
|
11
|
+
emailVerification: string;
|
|
12
|
+
passwordReset: string;
|
|
13
|
+
forgotPassword: string;
|
|
14
|
+
home: string;
|
|
15
|
+
userHome: string;
|
|
16
|
+
oauthCallback: string;
|
|
17
|
+
};
|
|
18
|
+
export type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = {
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
projectId?: ProjectId;
|
|
21
|
+
publishableClientKey?: string;
|
|
22
|
+
urls?: Partial<HandlerUrls>;
|
|
23
|
+
tokenStore: TokenStoreOptions<HasTokenStore>;
|
|
24
|
+
};
|
|
25
|
+
export type StackServerAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = StackClientAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
26
|
+
secretServerKey?: string;
|
|
27
|
+
};
|
|
28
|
+
export type StackAdminAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = StackServerAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
29
|
+
superSecretAdminKey?: string;
|
|
30
|
+
};
|
|
31
|
+
export type StackClientAppJson<HasTokenStore extends boolean, ProjectId extends string> = StackClientAppConstructorOptions<HasTokenStore, ProjectId> & {
|
|
32
|
+
uniqueIdentifier: string;
|
|
33
|
+
};
|
|
34
|
+
export declare const stackAppInternalsSymbol: unique symbol;
|
|
35
|
+
type Auth<T, C> = {
|
|
36
|
+
readonly accessToken: string | null;
|
|
37
|
+
readonly refreshToken: string | null;
|
|
38
|
+
update(this: T, user: Partial<C>): Promise<void>;
|
|
39
|
+
signOut(this: T, redirectUrl?: string): Promise<never>;
|
|
40
|
+
};
|
|
41
|
+
export type User = {
|
|
42
|
+
readonly projectId: string;
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly displayName: string | null;
|
|
45
|
+
/**
|
|
46
|
+
* The user's email address.
|
|
47
|
+
*
|
|
48
|
+
* Note: This might NOT be unique across multiple users, so always use `id` for unique identification.
|
|
49
|
+
*/
|
|
50
|
+
readonly primaryEmail: string | null;
|
|
51
|
+
readonly primaryEmailVerified: boolean;
|
|
52
|
+
readonly profileImageUrl: string | null;
|
|
53
|
+
readonly signedUpAt: Date;
|
|
54
|
+
readonly clientMetadata: ReadonlyJson;
|
|
55
|
+
toJson(this: CurrentUser): UserJson;
|
|
56
|
+
};
|
|
57
|
+
export type CurrentUser = Auth<User, UserCustomizableJson> & User;
|
|
58
|
+
/**
|
|
59
|
+
* A user including sensitive fields that should only be used on the server, never sent to the client
|
|
60
|
+
* (such as sensitive information and serverMetadata).
|
|
61
|
+
*/
|
|
62
|
+
export type ServerUser = Omit<User, "toJson"> & {
|
|
63
|
+
readonly serverMetadata: ReadonlyJson;
|
|
64
|
+
/**
|
|
65
|
+
* Returns a new user object with the sensitive fields removed.
|
|
66
|
+
*/
|
|
67
|
+
getClientUser(this: ServerUser): User;
|
|
68
|
+
toJson(this: ServerUser): ServerUserJson;
|
|
69
|
+
update(this: ServerUser, user: Partial<ServerUserCustomizableJson>): Promise<void>;
|
|
70
|
+
delete(this: ServerUser): Promise<void>;
|
|
71
|
+
};
|
|
72
|
+
export type CurrentServerUser = Auth<ServerUser, ServerUserCustomizableJson> & Omit<ServerUser, "getClientUser"> & {
|
|
73
|
+
getClientUser(this: CurrentServerUser): CurrentUser;
|
|
74
|
+
};
|
|
75
|
+
export type Project = Readonly<{
|
|
76
|
+
id: string;
|
|
77
|
+
displayName: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
createdAt: Date;
|
|
80
|
+
userCount: number;
|
|
81
|
+
isProductionMode: boolean;
|
|
82
|
+
evaluatedConfig: {
|
|
83
|
+
id: string;
|
|
84
|
+
allowLocalhost: boolean;
|
|
85
|
+
oauthProviders: OauthProviderConfig[];
|
|
86
|
+
emailConfig?: EmailConfig;
|
|
87
|
+
domains: DomainConfig[];
|
|
88
|
+
};
|
|
89
|
+
}>;
|
|
90
|
+
export type EmailConfig = EmailConfigJson;
|
|
91
|
+
export type DomainConfig = DomainConfigJson;
|
|
92
|
+
export type OauthProviderConfig = OauthProviderConfigJson;
|
|
93
|
+
export type GetUserOptions = {
|
|
94
|
+
or?: 'redirect' | 'throw';
|
|
95
|
+
};
|
|
96
|
+
type AsyncStoreProperty<Name extends string, Value> = {
|
|
97
|
+
[key in `get${Capitalize<Name>}`]: () => Promise<Value>;
|
|
98
|
+
} & {
|
|
99
|
+
[key in `on${Capitalize<Name>}Change`]: (callback: (value: Value) => void) => void;
|
|
100
|
+
} & {
|
|
101
|
+
[key in `use${Capitalize<Name>}`]: () => Value;
|
|
102
|
+
};
|
|
103
|
+
export type StackClientApp<HasTokenStore extends boolean, ProjectId extends string = string> = ({
|
|
104
|
+
readonly projectId: ProjectId;
|
|
105
|
+
readonly urls: Readonly<HandlerUrls>;
|
|
106
|
+
signInWithOauth(provider: string): Promise<void>;
|
|
107
|
+
signInWithCredential(options: {
|
|
108
|
+
email: string;
|
|
109
|
+
password: string;
|
|
110
|
+
redirectUrl?: string;
|
|
111
|
+
}): Promise<SignInErrorCode | undefined>;
|
|
112
|
+
signUpWithCredential(options: {
|
|
113
|
+
email: string;
|
|
114
|
+
password: string;
|
|
115
|
+
redirectUrl?: string;
|
|
116
|
+
}): Promise<SignUpErrorCode | undefined>;
|
|
117
|
+
callOauthCallback(options?: {
|
|
118
|
+
redirectUrl?: string;
|
|
119
|
+
}): Promise<void>;
|
|
120
|
+
sendForgotPasswordEmail(email: string): Promise<void>;
|
|
121
|
+
resetPassword(options: {
|
|
122
|
+
code: string;
|
|
123
|
+
password: string;
|
|
124
|
+
}): Promise<PasswordResetLinkErrorCode | undefined>;
|
|
125
|
+
verifyPasswordResetCode(code: string): Promise<PasswordResetLinkErrorCode | undefined>;
|
|
126
|
+
verifyEmail(code: string): Promise<EmailVerificationLinkErrorCode | undefined>;
|
|
127
|
+
[stackAppInternalsSymbol]: {
|
|
128
|
+
toClientJson(): Promise<StackClientAppJson<HasTokenStore, ProjectId>>;
|
|
129
|
+
};
|
|
130
|
+
} & AsyncStoreProperty<"project", ClientProjectJson> & {
|
|
131
|
+
[K in `redirectTo${Capitalize<keyof HandlerUrls>}`]: () => Promise<never>;
|
|
132
|
+
} & (HasTokenStore extends false ? {} : {
|
|
133
|
+
useUser(options: GetUserOptions & {
|
|
134
|
+
or: 'redirect';
|
|
135
|
+
}): CurrentUser;
|
|
136
|
+
useUser(options: GetUserOptions & {
|
|
137
|
+
or: 'throw';
|
|
138
|
+
}): CurrentUser;
|
|
139
|
+
useUser(options?: GetUserOptions): CurrentUser | null;
|
|
140
|
+
getUser(options: GetUserOptions & {
|
|
141
|
+
or: 'redirect';
|
|
142
|
+
}): Promise<CurrentUser>;
|
|
143
|
+
getUser(options: GetUserOptions & {
|
|
144
|
+
or: 'throw';
|
|
145
|
+
}): Promise<CurrentUser>;
|
|
146
|
+
getUser(options?: GetUserOptions): Promise<CurrentUser | null>;
|
|
147
|
+
onUserChange: AsyncStoreProperty<"user", CurrentUser | null>["onUserChange"];
|
|
148
|
+
}) & (ProjectId extends "internal" ? {
|
|
149
|
+
listOwnedProjects(): Promise<Project[]>;
|
|
150
|
+
createProject(project: Pick<Project, "displayName" | "description">): Promise<Project>;
|
|
151
|
+
} : {}));
|
|
152
|
+
type StackClientAppConstructor = {
|
|
153
|
+
new <TokenStoreType extends string, HasTokenStore extends (TokenStoreType extends {} ? true : boolean), ProjectId extends string>(options: StackClientAppConstructorOptions<HasTokenStore, ProjectId>): StackClientApp<HasTokenStore, ProjectId>;
|
|
154
|
+
new (options: StackClientAppConstructorOptions<boolean, string>): StackClientApp<boolean, string>;
|
|
155
|
+
[stackAppInternalsSymbol]: {
|
|
156
|
+
fromClientJson<HasTokenStore extends boolean, ProjectId extends string>(json: StackClientAppJson<HasTokenStore, ProjectId>): StackClientApp<HasTokenStore, ProjectId>;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
export declare const StackClientApp: StackClientAppConstructor;
|
|
160
|
+
export type StackServerApp<HasTokenStore extends boolean, ProjectId extends string = string> = (StackClientApp<HasTokenStore, ProjectId> & AsyncStoreProperty<"serverUser", CurrentServerUser | null> & {});
|
|
161
|
+
type StackServerAppConstructor = {
|
|
162
|
+
new <TokenStoreType extends string, HasTokenStore extends (TokenStoreType extends {} ? true : boolean), ProjectId extends string>(options: StackServerAppConstructorOptions<HasTokenStore, ProjectId>): StackServerApp<HasTokenStore, ProjectId>;
|
|
163
|
+
new (options: StackServerAppConstructorOptions<boolean, string>): StackServerApp<boolean, string>;
|
|
164
|
+
};
|
|
165
|
+
export declare const StackServerApp: StackServerAppConstructor;
|
|
166
|
+
export type StackAdminApp<HasTokenStore extends boolean, ProjectId extends string = string> = (StackServerApp<HasTokenStore, ProjectId> & AsyncStoreProperty<"projectAdmin", Project>);
|
|
167
|
+
type StackAdminAppConstructor = {
|
|
168
|
+
new <TokenStoreType extends string, HasTokenStore extends (TokenStoreType extends {} ? true : boolean), ProjectId extends string>(options: StackAdminAppConstructorOptions<HasTokenStore, ProjectId>): StackAdminApp<HasTokenStore, ProjectId>;
|
|
169
|
+
new (options: StackAdminAppConstructorOptions<boolean, string>): StackAdminApp<boolean, string>;
|
|
170
|
+
};
|
|
171
|
+
export declare const StackAdminApp: StackAdminAppConstructor;
|
|
172
|
+
export {};
|