@stackframe/stack-shared 2.4.13 → 2.4.14
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 +6 -0
- package/dist/hooks/use-trigger.d.ts +1 -0
- package/dist/hooks/use-trigger.js +10 -0
- package/dist/interface/adminInterface.d.ts +9 -8
- package/dist/interface/adminInterface.js +4 -4
- package/dist/interface/clientInterface.d.ts +39 -31
- package/dist/interface/clientInterface.js +108 -120
- package/dist/interface/serverInterface.d.ts +11 -10
- package/dist/interface/serverInterface.js +8 -8
- package/dist/sessions.d.ts +75 -0
- package/dist/sessions.js +127 -0
- package/dist/utils/crypto.js +2 -1
- package/dist/utils/dom.js +1 -1
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/env.js +4 -1
- package/dist/utils/errors.js +5 -0
- package/dist/utils/globals.js +2 -2
- package/dist/utils/promises.d.ts +3 -1
- package/dist/utils/promises.js +11 -1
- package/dist/utils/proxies.d.ts +1 -0
- package/dist/utils/proxies.js +59 -0
- package/dist/utils/react.js +2 -1
- package/dist/utils/results.d.ts +3 -3
- package/dist/utils/results.js +10 -2
- package/dist/utils/stores.d.ts +23 -0
- package/dist/utils/stores.js +36 -0
- package/dist/utils/strings.d.ts +3 -0
- package/dist/utils/strings.js +46 -0
- package/dist/utils/uuids.d.ts +1 -1
- package/dist/utils/uuids.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useTrigger(callback: () => void): () => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export function useTrigger(callback) {
|
|
3
|
+
const [hasTriggered, setHasTriggered] = React.useState(false);
|
|
4
|
+
React.useEffect(() => {
|
|
5
|
+
if (hasTriggered) {
|
|
6
|
+
callback();
|
|
7
|
+
}
|
|
8
|
+
}, [hasTriggered]);
|
|
9
|
+
return () => setHasTriggered(true);
|
|
10
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ServerAuthApplicationOptions, StackServerInterface } from "./serverInterface";
|
|
2
|
-
import { EmailConfigJson, ProjectJson,
|
|
2
|
+
import { EmailConfigJson, ProjectJson, SharedProvider, StandardProvider } from "./clientInterface";
|
|
3
|
+
import { Session } from "../sessions";
|
|
3
4
|
export type AdminAuthApplicationOptions = Readonly<ServerAuthApplicationOptions & ({
|
|
4
5
|
superSecretAdminKey: string;
|
|
5
6
|
} | {
|
|
6
|
-
|
|
7
|
+
projectOwnerSession: Session;
|
|
7
8
|
})>;
|
|
8
9
|
export type OAuthProviderUpdateOptions = {
|
|
9
10
|
id: string;
|
|
@@ -66,11 +67,11 @@ export type ApiKeySetCreateOptions = {
|
|
|
66
67
|
export declare class StackAdminInterface extends StackServerInterface {
|
|
67
68
|
readonly options: AdminAuthApplicationOptions;
|
|
68
69
|
constructor(options: AdminAuthApplicationOptions);
|
|
69
|
-
protected sendAdminRequest(path: string, options: RequestInit,
|
|
70
|
-
usedTokens:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
70
|
+
protected sendAdminRequest(path: string, options: RequestInit, session: Session | null, requestType?: "admin"): Promise<Response & {
|
|
71
|
+
usedTokens: {
|
|
72
|
+
accessToken: import("../sessions").AccessToken;
|
|
73
|
+
refreshToken: import("../sessions").RefreshToken | null;
|
|
74
|
+
} | null;
|
|
74
75
|
}>;
|
|
75
76
|
getProject(options?: {
|
|
76
77
|
showDisabledOAuth?: boolean;
|
|
@@ -79,5 +80,5 @@ export declare class StackAdminInterface extends StackServerInterface {
|
|
|
79
80
|
createApiKeySet(options: ApiKeySetCreateOptions): Promise<ApiKeySetFirstViewJson>;
|
|
80
81
|
listApiKeySets(): Promise<ApiKeySetJson[]>;
|
|
81
82
|
revokeApiKeySetById(id: string): Promise<void>;
|
|
82
|
-
getApiKeySet(id: string,
|
|
83
|
+
getApiKeySet(id: string, session: Session): Promise<ApiKeySetJson>;
|
|
83
84
|
}
|
|
@@ -5,14 +5,14 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
5
5
|
super(options);
|
|
6
6
|
this.options = options;
|
|
7
7
|
}
|
|
8
|
-
async sendAdminRequest(path, options,
|
|
8
|
+
async sendAdminRequest(path, options, session, requestType = "admin") {
|
|
9
9
|
return await this.sendServerRequest(path, {
|
|
10
10
|
...options,
|
|
11
11
|
headers: {
|
|
12
12
|
"x-stack-super-secret-admin-key": "superSecretAdminKey" in this.options ? this.options.superSecretAdminKey : "",
|
|
13
13
|
...options.headers,
|
|
14
14
|
},
|
|
15
|
-
},
|
|
15
|
+
}, session, requestType);
|
|
16
16
|
}
|
|
17
17
|
async getProject(options) {
|
|
18
18
|
const response = await this.sendAdminRequest("/projects/" + encodeURIComponent(this.projectId), {
|
|
@@ -60,8 +60,8 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
60
60
|
}),
|
|
61
61
|
}, null);
|
|
62
62
|
}
|
|
63
|
-
async getApiKeySet(id,
|
|
64
|
-
const response = await this.sendAdminRequest(`/api-keys/${id}`, {},
|
|
63
|
+
async getApiKeySet(id, session) {
|
|
64
|
+
const response = await this.sendAdminRequest(`/api-keys/${id}`, {}, session);
|
|
65
65
|
return await response.json();
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import * as oauth from 'oauth4webapi';
|
|
2
1
|
import { Result } from "../utils/results";
|
|
3
2
|
import { ReadonlyJson } from '../utils/json';
|
|
4
|
-
import { AsyncStore, ReadonlyAsyncStore } from '../utils/stores';
|
|
5
3
|
import { KnownErrors } from '../known-errors';
|
|
6
4
|
import { ProjectUpdateOptions } from './adminInterface';
|
|
5
|
+
import { AccessToken, RefreshToken, Session } from '../sessions';
|
|
7
6
|
type UserCustomizableJson = {
|
|
8
7
|
displayName: string | null;
|
|
9
8
|
clientMetadata: ReadonlyJson;
|
|
@@ -44,8 +43,7 @@ export type ClientInterfaceOptions = {
|
|
|
44
43
|
} & ({
|
|
45
44
|
publishableClientKey: string;
|
|
46
45
|
} | {
|
|
47
|
-
|
|
48
|
-
refreshProjectOwnerTokens: () => Promise<void>;
|
|
46
|
+
projectOwnerSession: Session;
|
|
49
47
|
});
|
|
50
48
|
export type SharedProvider = "shared-github" | "shared-google" | "shared-facebook" | "shared-microsoft" | "shared-spotify";
|
|
51
49
|
export declare const sharedProviders: readonly ["shared-github", "shared-google", "shared-facebook", "shared-microsoft", "shared-spotify"];
|
|
@@ -53,12 +51,6 @@ export type StandardProvider = "github" | "facebook" | "google" | "microsoft" |
|
|
|
53
51
|
export declare const standardProviders: readonly ["github", "facebook", "google", "microsoft", "spotify"];
|
|
54
52
|
export declare function toStandardProvider(provider: SharedProvider | StandardProvider): StandardProvider;
|
|
55
53
|
export declare function toSharedProvider(provider: SharedProvider | StandardProvider): SharedProvider;
|
|
56
|
-
export type ReadonlyTokenStore = ReadonlyAsyncStore<TokenObject>;
|
|
57
|
-
export type TokenStore = AsyncStore<TokenObject>;
|
|
58
|
-
export type TokenObject = Readonly<{
|
|
59
|
-
refreshToken: string | null;
|
|
60
|
-
accessToken: string | null;
|
|
61
|
-
}>;
|
|
62
54
|
export type ProjectJson = {
|
|
63
55
|
id: string;
|
|
64
56
|
displayName: string;
|
|
@@ -136,20 +128,24 @@ export declare class StackClientInterface {
|
|
|
136
128
|
constructor(options: ClientInterfaceOptions);
|
|
137
129
|
get projectId(): string;
|
|
138
130
|
getApiUrl(): string;
|
|
139
|
-
|
|
140
|
-
protected sendClientRequest(path: string, requestOptions: RequestInit,
|
|
141
|
-
usedTokens:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
131
|
+
fetchNewAccessToken(refreshToken: RefreshToken): Promise<AccessToken | null>;
|
|
132
|
+
protected sendClientRequest(path: string, requestOptions: RequestInit, session: Session | null, requestType?: "client" | "server" | "admin"): Promise<Response & {
|
|
133
|
+
usedTokens: {
|
|
134
|
+
accessToken: AccessToken;
|
|
135
|
+
refreshToken: RefreshToken | null;
|
|
136
|
+
} | null;
|
|
145
137
|
}>;
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
createSession(options: Omit<ConstructorParameters<typeof Session>[0], "refreshAccessTokenCallback">): Session;
|
|
139
|
+
protected sendClientRequestAndCatchKnownError<E extends typeof KnownErrors[keyof KnownErrors]>(path: string, requestOptions: RequestInit, tokenStoreOrNull: Session | null, errorsToCatch: readonly E[]): Promise<Result<Response & {
|
|
140
|
+
usedTokens: {
|
|
141
|
+
accessToken: AccessToken;
|
|
142
|
+
refreshToken: RefreshToken | null;
|
|
143
|
+
} | null;
|
|
148
144
|
}, InstanceType<E>>>;
|
|
149
145
|
private sendClientRequestInner;
|
|
150
146
|
private _processResponse;
|
|
151
147
|
sendForgotPasswordEmail(email: string, redirectUrl: string): Promise<KnownErrors["UserNotFound"] | undefined>;
|
|
152
|
-
sendVerificationEmail(emailVerificationRedirectUrl: string,
|
|
148
|
+
sendVerificationEmail(emailVerificationRedirectUrl: string, session: Session): Promise<KnownErrors["EmailAlreadyVerified"] | undefined>;
|
|
153
149
|
sendMagicLinkEmail(email: string, redirectUrl: string): Promise<KnownErrors["RedirectUrlNotWhitelisted"] | undefined>;
|
|
154
150
|
resetPassword(options: {
|
|
155
151
|
code: string;
|
|
@@ -161,30 +157,42 @@ export declare class StackClientInterface {
|
|
|
161
157
|
updatePassword(options: {
|
|
162
158
|
oldPassword: string;
|
|
163
159
|
newPassword: string;
|
|
164
|
-
},
|
|
160
|
+
}, session: Session): Promise<KnownErrors["PasswordMismatch"] | KnownErrors["PasswordRequirementsNotMet"] | undefined>;
|
|
165
161
|
verifyPasswordResetCode(code: string): Promise<KnownErrors["PasswordResetCodeError"] | undefined>;
|
|
166
162
|
verifyEmail(code: string): Promise<KnownErrors["EmailVerificationError"] | undefined>;
|
|
167
|
-
signInWithCredential(email: string, password: string,
|
|
168
|
-
|
|
169
|
-
|
|
163
|
+
signInWithCredential(email: string, password: string, session: Session): Promise<KnownErrors["EmailPasswordMismatch"] | {
|
|
164
|
+
accessToken: string;
|
|
165
|
+
refreshToken: string;
|
|
166
|
+
}>;
|
|
167
|
+
signUpWithCredential(email: string, password: string, emailVerificationRedirectUrl: string, session: Session): Promise<KnownErrors["UserEmailAlreadyExists"] | KnownErrors["PasswordRequirementsNotMet"] | {
|
|
168
|
+
accessToken: string;
|
|
169
|
+
refreshToken: string;
|
|
170
|
+
}>;
|
|
171
|
+
signInWithMagicLink(code: string, session: Session): Promise<KnownErrors["MagicLinkError"] | {
|
|
170
172
|
newUser: boolean;
|
|
173
|
+
accessToken: string;
|
|
174
|
+
refreshToken: string;
|
|
171
175
|
}>;
|
|
172
176
|
getOAuthUrl(provider: string, redirectUrl: string, codeChallenge: string, state: string): Promise<string>;
|
|
173
|
-
callOAuthCallback(oauthParams: URLSearchParams, redirectUri: string, codeVerifier: string, state: string
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
callOAuthCallback(oauthParams: URLSearchParams, redirectUri: string, codeVerifier: string, state: string): Promise<{
|
|
178
|
+
newUser: boolean;
|
|
179
|
+
accessToken: string;
|
|
180
|
+
refreshToken: string;
|
|
181
|
+
}>;
|
|
182
|
+
signOut(session: Session): Promise<void>;
|
|
183
|
+
getClientUserByToken(tokenStore: Session): Promise<Result<UserJson>>;
|
|
176
184
|
listClientUserTeamPermissions(options: {
|
|
177
185
|
teamId: string;
|
|
178
186
|
type: 'global' | 'team';
|
|
179
187
|
direct: boolean;
|
|
180
|
-
},
|
|
181
|
-
listClientUserTeams(
|
|
188
|
+
}, session: Session): Promise<PermissionDefinitionJson[]>;
|
|
189
|
+
listClientUserTeams(session: Session): Promise<TeamJson[]>;
|
|
182
190
|
getClientProject(): Promise<Result<ClientProjectJson>>;
|
|
183
|
-
setClientUserCustomizableData(update: UserUpdateJson,
|
|
184
|
-
listProjects(
|
|
191
|
+
setClientUserCustomizableData(update: UserUpdateJson, session: Session): Promise<void>;
|
|
192
|
+
listProjects(session: Session): Promise<ProjectJson[]>;
|
|
185
193
|
createProject(project: ProjectUpdateOptions & {
|
|
186
194
|
displayName: string;
|
|
187
|
-
},
|
|
195
|
+
}, session: Session): Promise<ProjectJson>;
|
|
188
196
|
}
|
|
189
197
|
export declare function getProductionModeErrors(project: ProjectJson): ProductionModeError[];
|
|
190
198
|
export {};
|