@stackframe/stack-shared 2.4.4 → 2.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/interface/adminInterface.d.ts +2 -1
- package/dist/interface/clientInterface.d.ts +3 -3
- package/dist/interface/clientInterface.js +2 -9
- package/dist/interface/crud/current-user.d.ts +12 -0
- package/dist/interface/crud/current-user.js +2 -0
- package/dist/interface/crud/users.d.ts +12 -0
- package/dist/interface/crud/users.js +2 -0
- package/dist/utils/crypto.js +1 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ServerAuthApplicationOptions, StackServerInterface } from "./serverInterface";
|
|
2
|
-
import { ProjectJson, ReadonlyTokenStore, SharedProvider, StandardProvider, TokenStore } from "./clientInterface";
|
|
2
|
+
import { EmailConfigJson, ProjectJson, ReadonlyTokenStore, SharedProvider, StandardProvider, TokenStore } from "./clientInterface";
|
|
3
3
|
export type AdminAuthApplicationOptions = Readonly<ServerAuthApplicationOptions & ({
|
|
4
4
|
superSecretAdminKey: string;
|
|
5
5
|
} | {
|
|
@@ -30,6 +30,7 @@ export type ProjectUpdateOptions = {
|
|
|
30
30
|
magicLinkEnabled?: boolean;
|
|
31
31
|
allowLocalhost?: boolean;
|
|
32
32
|
createTeamOnSignUp?: boolean;
|
|
33
|
+
emailConfig?: EmailConfigJson;
|
|
33
34
|
};
|
|
34
35
|
};
|
|
35
36
|
export type ApiKeySetBaseJson = {
|
|
@@ -7,6 +7,7 @@ import { ProjectUpdateOptions } from './adminInterface';
|
|
|
7
7
|
type UserCustomizableJson = {
|
|
8
8
|
displayName: string | null;
|
|
9
9
|
clientMetadata: ReadonlyJson;
|
|
10
|
+
selectedTeamId: string | null;
|
|
10
11
|
};
|
|
11
12
|
export type UserJson = UserCustomizableJson & {
|
|
12
13
|
projectId: string;
|
|
@@ -24,6 +25,7 @@ export type UserJson = UserCustomizableJson & {
|
|
|
24
25
|
hasPassword: boolean;
|
|
25
26
|
authWithEmail: boolean;
|
|
26
27
|
oauthProviders: string[];
|
|
28
|
+
selectedTeamId: string | null;
|
|
27
29
|
};
|
|
28
30
|
export type UserUpdateJson = Partial<UserCustomizableJson>;
|
|
29
31
|
export type ClientProjectJson = {
|
|
@@ -95,7 +97,6 @@ export type EmailConfigJson = ({
|
|
|
95
97
|
password: string;
|
|
96
98
|
} | {
|
|
97
99
|
type: "shared";
|
|
98
|
-
senderName: string;
|
|
99
100
|
});
|
|
100
101
|
export type DomainConfigJson = {
|
|
101
102
|
domain: string;
|
|
@@ -133,7 +134,6 @@ export declare class StackClientInterface {
|
|
|
133
134
|
readonly options: ClientInterfaceOptions;
|
|
134
135
|
constructor(options: ClientInterfaceOptions);
|
|
135
136
|
get projectId(): string;
|
|
136
|
-
getSessionCookieName(): string;
|
|
137
137
|
getApiUrl(): string;
|
|
138
138
|
protected refreshAccessToken(tokenStore: TokenStore): Promise<void>;
|
|
139
139
|
protected sendClientRequest(path: string, requestOptions: RequestInit, tokenStoreOrNull: TokenStore | null, requestType?: "client" | "server" | "admin"): Promise<Response & {
|
|
@@ -164,7 +164,7 @@ export declare class StackClientInterface {
|
|
|
164
164
|
verifyPasswordResetCode(code: string): Promise<KnownErrors["PasswordResetCodeError"] | undefined>;
|
|
165
165
|
verifyEmail(code: string): Promise<KnownErrors["EmailVerificationError"] | undefined>;
|
|
166
166
|
signInWithCredential(email: string, password: string, tokenStore: TokenStore): Promise<KnownErrors["EmailPasswordMismatch"] | undefined>;
|
|
167
|
-
signUpWithCredential(email: string, password: string, emailVerificationRedirectUrl: string, tokenStore: TokenStore): Promise<KnownErrors["UserEmailAlreadyExists"] | undefined>;
|
|
167
|
+
signUpWithCredential(email: string, password: string, emailVerificationRedirectUrl: string, tokenStore: TokenStore): Promise<KnownErrors["UserEmailAlreadyExists"] | KnownErrors["PasswordRequirementsNotMet"] | undefined>;
|
|
168
168
|
signInWithMagicLink(code: string, tokenStore: TokenStore): Promise<KnownErrors["MagicLinkError"] | {
|
|
169
169
|
newUser: boolean;
|
|
170
170
|
}>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as oauth from 'oauth4webapi';
|
|
2
|
-
import crypto from "crypto";
|
|
3
2
|
import { Result } from "../utils/results";
|
|
4
3
|
import { AsyncStore } from '../utils/stores';
|
|
5
4
|
import { KnownError, KnownErrors } from '../known-errors';
|
|
@@ -24,9 +23,6 @@ export function toStandardProvider(provider) {
|
|
|
24
23
|
export function toSharedProvider(provider) {
|
|
25
24
|
return "shared-" + provider;
|
|
26
25
|
}
|
|
27
|
-
function getSessionCookieName(projectId) {
|
|
28
|
-
return "__stack-token-" + crypto.createHash("sha256").update(projectId).digest("hex");
|
|
29
|
-
}
|
|
30
26
|
export class StackClientInterface {
|
|
31
27
|
options;
|
|
32
28
|
constructor(options) {
|
|
@@ -36,9 +32,6 @@ export class StackClientInterface {
|
|
|
36
32
|
get projectId() {
|
|
37
33
|
return this.options.projectId;
|
|
38
34
|
}
|
|
39
|
-
getSessionCookieName() {
|
|
40
|
-
return getSessionCookieName(this.projectId);
|
|
41
|
-
}
|
|
42
35
|
getApiUrl() {
|
|
43
36
|
return this.options.baseUrl + "/api/v1";
|
|
44
37
|
}
|
|
@@ -330,7 +323,7 @@ export class StackClientInterface {
|
|
|
330
323
|
password,
|
|
331
324
|
emailVerificationRedirectUrl,
|
|
332
325
|
}),
|
|
333
|
-
}, tokenStore, [KnownErrors.UserEmailAlreadyExists]);
|
|
326
|
+
}, tokenStore, [KnownErrors.UserEmailAlreadyExists, KnownErrors.PasswordRequirementsNotMet]);
|
|
334
327
|
if (res.status === "error") {
|
|
335
328
|
return res.error;
|
|
336
329
|
}
|
|
@@ -495,7 +488,7 @@ export class StackClientInterface {
|
|
|
495
488
|
}
|
|
496
489
|
export function getProductionModeErrors(project) {
|
|
497
490
|
const errors = [];
|
|
498
|
-
const fixUrlRelative = `/projects/${project.id}/
|
|
491
|
+
const fixUrlRelative = `/projects/${project.id}/domains`;
|
|
499
492
|
if (project.evaluatedConfig.allowLocalhost) {
|
|
500
493
|
errors.push({
|
|
501
494
|
errorMessage: "Localhost is not allowed in production mode, turn off 'Allow localhost' in project settings",
|
|
@@ -10,6 +10,7 @@ export declare const currentUserCrud: {
|
|
|
10
10
|
clientMetadata: {} | null;
|
|
11
11
|
primaryEmail: string | null;
|
|
12
12
|
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
13
|
+
selectedTeamId: string | null;
|
|
13
14
|
profileImageUrl: string | null;
|
|
14
15
|
signedUpAtMillis: number;
|
|
15
16
|
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
@@ -23,6 +24,7 @@ export declare const currentUserCrud: {
|
|
|
23
24
|
primaryEmailVerified: undefined;
|
|
24
25
|
displayName: undefined;
|
|
25
26
|
clientMetadata: {};
|
|
27
|
+
selectedTeamId: undefined;
|
|
26
28
|
profileImageUrl: undefined;
|
|
27
29
|
signedUpAtMillis: undefined;
|
|
28
30
|
authMethod: undefined;
|
|
@@ -34,12 +36,14 @@ export declare const currentUserCrud: {
|
|
|
34
36
|
updateSchema: yup.ObjectSchema<{
|
|
35
37
|
displayName: string | undefined;
|
|
36
38
|
clientMetadata: {} | undefined;
|
|
39
|
+
selectedTeamId: string | null | undefined;
|
|
37
40
|
}, yup.AnyObject, {
|
|
38
41
|
displayName: undefined;
|
|
39
42
|
clientMetadata: {};
|
|
40
43
|
serverMetadata: {};
|
|
41
44
|
primaryEmail: undefined;
|
|
42
45
|
primaryEmailVerified: undefined;
|
|
46
|
+
selectedTeamId: undefined;
|
|
43
47
|
}, "">;
|
|
44
48
|
deleteSchema: undefined;
|
|
45
49
|
};
|
|
@@ -52,6 +56,7 @@ export declare const currentUserCrud: {
|
|
|
52
56
|
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
53
57
|
displayName: string | null;
|
|
54
58
|
clientMetadata: {} | null;
|
|
59
|
+
selectedTeamId: string | null;
|
|
55
60
|
profileImageUrl: string | null;
|
|
56
61
|
signedUpAtMillis: number;
|
|
57
62
|
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
@@ -66,6 +71,7 @@ export declare const currentUserCrud: {
|
|
|
66
71
|
primaryEmailVerified: undefined;
|
|
67
72
|
displayName: undefined;
|
|
68
73
|
clientMetadata: {};
|
|
74
|
+
selectedTeamId: undefined;
|
|
69
75
|
profileImageUrl: undefined;
|
|
70
76
|
signedUpAtMillis: undefined;
|
|
71
77
|
authMethod: undefined;
|
|
@@ -80,12 +86,14 @@ export declare const currentUserCrud: {
|
|
|
80
86
|
serverMetadata: {} | undefined;
|
|
81
87
|
primaryEmail: string | undefined;
|
|
82
88
|
primaryEmailVerified: boolean | undefined;
|
|
89
|
+
selectedTeamId: string | null | undefined;
|
|
83
90
|
}, yup.AnyObject, {
|
|
84
91
|
displayName: undefined;
|
|
85
92
|
clientMetadata: {};
|
|
86
93
|
serverMetadata: {};
|
|
87
94
|
primaryEmail: undefined;
|
|
88
95
|
primaryEmailVerified: undefined;
|
|
96
|
+
selectedTeamId: undefined;
|
|
89
97
|
}, "">;
|
|
90
98
|
deleteSchema: undefined;
|
|
91
99
|
};
|
|
@@ -98,6 +106,7 @@ export declare const currentUserCrud: {
|
|
|
98
106
|
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
99
107
|
displayName: string | null;
|
|
100
108
|
clientMetadata: {} | null;
|
|
109
|
+
selectedTeamId: string | null;
|
|
101
110
|
profileImageUrl: string | null;
|
|
102
111
|
signedUpAtMillis: number;
|
|
103
112
|
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
@@ -112,6 +121,7 @@ export declare const currentUserCrud: {
|
|
|
112
121
|
primaryEmailVerified: undefined;
|
|
113
122
|
displayName: undefined;
|
|
114
123
|
clientMetadata: {};
|
|
124
|
+
selectedTeamId: undefined;
|
|
115
125
|
profileImageUrl: undefined;
|
|
116
126
|
signedUpAtMillis: undefined;
|
|
117
127
|
authMethod: undefined;
|
|
@@ -126,12 +136,14 @@ export declare const currentUserCrud: {
|
|
|
126
136
|
serverMetadata: {} | undefined;
|
|
127
137
|
primaryEmail: string | undefined;
|
|
128
138
|
primaryEmailVerified: boolean | undefined;
|
|
139
|
+
selectedTeamId: string | null | undefined;
|
|
129
140
|
}, yup.AnyObject, {
|
|
130
141
|
displayName: undefined;
|
|
131
142
|
clientMetadata: {};
|
|
132
143
|
serverMetadata: {};
|
|
133
144
|
primaryEmail: undefined;
|
|
134
145
|
primaryEmailVerified: undefined;
|
|
146
|
+
selectedTeamId: undefined;
|
|
135
147
|
}, "">;
|
|
136
148
|
deleteSchema: undefined;
|
|
137
149
|
};
|
|
@@ -3,6 +3,7 @@ import { usersCrudServerReadSchema, usersCrudServerUpdateSchema } from "./users"
|
|
|
3
3
|
const clientUpdateSchema = usersCrudServerUpdateSchema.pick([
|
|
4
4
|
"displayName",
|
|
5
5
|
"clientMetadata",
|
|
6
|
+
"selectedTeamId",
|
|
6
7
|
]).required();
|
|
7
8
|
const serverUpdateSchema = usersCrudServerUpdateSchema;
|
|
8
9
|
const clientReadSchema = usersCrudServerReadSchema.pick([
|
|
@@ -18,6 +19,7 @@ const clientReadSchema = usersCrudServerReadSchema.pick([
|
|
|
18
19
|
"hasPassword",
|
|
19
20
|
"authWithEmail",
|
|
20
21
|
"oauthProviders",
|
|
22
|
+
"selectedTeamId",
|
|
21
23
|
]).nullable().defined();
|
|
22
24
|
const serverReadSchema = usersCrudServerReadSchema.nullable().defined();
|
|
23
25
|
export const currentUserCrud = createCrud({
|
|
@@ -6,12 +6,14 @@ export declare const usersCrudServerUpdateSchema: yup.ObjectSchema<{
|
|
|
6
6
|
serverMetadata: {} | undefined;
|
|
7
7
|
primaryEmail: string | undefined;
|
|
8
8
|
primaryEmailVerified: boolean | undefined;
|
|
9
|
+
selectedTeamId: string | null | undefined;
|
|
9
10
|
}, yup.AnyObject, {
|
|
10
11
|
displayName: undefined;
|
|
11
12
|
clientMetadata: {};
|
|
12
13
|
serverMetadata: {};
|
|
13
14
|
primaryEmail: undefined;
|
|
14
15
|
primaryEmailVerified: undefined;
|
|
16
|
+
selectedTeamId: undefined;
|
|
15
17
|
}, "">;
|
|
16
18
|
export declare const usersCrudServerReadSchema: yup.ObjectSchema<{
|
|
17
19
|
projectId: string;
|
|
@@ -20,6 +22,7 @@ export declare const usersCrudServerReadSchema: yup.ObjectSchema<{
|
|
|
20
22
|
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
21
23
|
displayName: string | null;
|
|
22
24
|
clientMetadata: {} | null;
|
|
25
|
+
selectedTeamId: string | null;
|
|
23
26
|
profileImageUrl: string | null;
|
|
24
27
|
signedUpAtMillis: number;
|
|
25
28
|
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
@@ -34,6 +37,7 @@ export declare const usersCrudServerReadSchema: yup.ObjectSchema<{
|
|
|
34
37
|
primaryEmailVerified: undefined;
|
|
35
38
|
displayName: undefined;
|
|
36
39
|
clientMetadata: {};
|
|
40
|
+
selectedTeamId: undefined;
|
|
37
41
|
profileImageUrl: undefined;
|
|
38
42
|
signedUpAtMillis: undefined;
|
|
39
43
|
authMethod: undefined;
|
|
@@ -58,6 +62,7 @@ export declare const usersCrud: {
|
|
|
58
62
|
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
59
63
|
displayName: string | null;
|
|
60
64
|
clientMetadata: {} | null;
|
|
65
|
+
selectedTeamId: string | null;
|
|
61
66
|
profileImageUrl: string | null;
|
|
62
67
|
signedUpAtMillis: number;
|
|
63
68
|
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
@@ -72,6 +77,7 @@ export declare const usersCrud: {
|
|
|
72
77
|
primaryEmailVerified: undefined;
|
|
73
78
|
displayName: undefined;
|
|
74
79
|
clientMetadata: {};
|
|
80
|
+
selectedTeamId: undefined;
|
|
75
81
|
profileImageUrl: undefined;
|
|
76
82
|
signedUpAtMillis: undefined;
|
|
77
83
|
authMethod: undefined;
|
|
@@ -86,12 +92,14 @@ export declare const usersCrud: {
|
|
|
86
92
|
serverMetadata: {} | undefined;
|
|
87
93
|
primaryEmail: string | undefined;
|
|
88
94
|
primaryEmailVerified: boolean | undefined;
|
|
95
|
+
selectedTeamId: string | null | undefined;
|
|
89
96
|
}, yup.AnyObject, {
|
|
90
97
|
displayName: undefined;
|
|
91
98
|
clientMetadata: {};
|
|
92
99
|
serverMetadata: {};
|
|
93
100
|
primaryEmail: undefined;
|
|
94
101
|
primaryEmailVerified: undefined;
|
|
102
|
+
selectedTeamId: undefined;
|
|
95
103
|
}, "">;
|
|
96
104
|
deleteSchema: yup.MixedSchema<{} | undefined, yup.AnyObject, undefined, "">;
|
|
97
105
|
};
|
|
@@ -104,6 +112,7 @@ export declare const usersCrud: {
|
|
|
104
112
|
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
105
113
|
displayName: string | null;
|
|
106
114
|
clientMetadata: {} | null;
|
|
115
|
+
selectedTeamId: string | null;
|
|
107
116
|
profileImageUrl: string | null;
|
|
108
117
|
signedUpAtMillis: number;
|
|
109
118
|
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
@@ -118,6 +127,7 @@ export declare const usersCrud: {
|
|
|
118
127
|
primaryEmailVerified: undefined;
|
|
119
128
|
displayName: undefined;
|
|
120
129
|
clientMetadata: {};
|
|
130
|
+
selectedTeamId: undefined;
|
|
121
131
|
profileImageUrl: undefined;
|
|
122
132
|
signedUpAtMillis: undefined;
|
|
123
133
|
authMethod: undefined;
|
|
@@ -132,12 +142,14 @@ export declare const usersCrud: {
|
|
|
132
142
|
serverMetadata: {} | undefined;
|
|
133
143
|
primaryEmail: string | undefined;
|
|
134
144
|
primaryEmailVerified: boolean | undefined;
|
|
145
|
+
selectedTeamId: string | null | undefined;
|
|
135
146
|
}, yup.AnyObject, {
|
|
136
147
|
displayName: undefined;
|
|
137
148
|
clientMetadata: {};
|
|
138
149
|
serverMetadata: {};
|
|
139
150
|
primaryEmail: undefined;
|
|
140
151
|
primaryEmailVerified: undefined;
|
|
152
|
+
selectedTeamId: undefined;
|
|
141
153
|
}, "">;
|
|
142
154
|
deleteSchema: yup.MixedSchema<{} | undefined, yup.AnyObject, undefined, "">;
|
|
143
155
|
};
|
|
@@ -6,6 +6,7 @@ export const usersCrudServerUpdateSchema = yup.object({
|
|
|
6
6
|
serverMetadata: yup.object().optional(),
|
|
7
7
|
primaryEmail: yup.string().optional(),
|
|
8
8
|
primaryEmailVerified: yup.boolean().optional(),
|
|
9
|
+
selectedTeamId: yup.string().nullable().optional(),
|
|
9
10
|
}).required();
|
|
10
11
|
export const usersCrudServerReadSchema = yup.object({
|
|
11
12
|
projectId: yup.string().required(),
|
|
@@ -14,6 +15,7 @@ export const usersCrudServerReadSchema = yup.object({
|
|
|
14
15
|
primaryEmailVerified: yup.boolean().required(),
|
|
15
16
|
displayName: yup.string().nullable().defined(),
|
|
16
17
|
clientMetadata: yup.object().nullable().defined().transform((value) => JSON.parse(JSON.stringify(value))),
|
|
18
|
+
selectedTeamId: yup.string().nullable().defined(),
|
|
17
19
|
profileImageUrl: yup.string().nullable().defined(),
|
|
18
20
|
signedUpAtMillis: yup.number().required(),
|
|
19
21
|
/**
|
package/dist/utils/crypto.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import crypto from "crypto";
|
|
2
1
|
import { encodeBase32 } from "./bytes";
|
|
3
2
|
/**
|
|
4
3
|
* Generates a secure alphanumeric string using the system's cryptographically secure
|
|
@@ -7,7 +6,7 @@ import { encodeBase32 } from "./bytes";
|
|
|
7
6
|
export function generateSecureRandomString(minBitsOfEntropy = 224) {
|
|
8
7
|
const base32CharactersCount = Math.ceil(minBitsOfEntropy / 5);
|
|
9
8
|
const bytesCount = Math.ceil(base32CharactersCount * 5 / 8);
|
|
10
|
-
const randomBytes = crypto.
|
|
9
|
+
const randomBytes = globalThis.crypto.getRandomValues(new Uint8Array(bytesCount));
|
|
11
10
|
const str = encodeBase32(randomBytes);
|
|
12
11
|
return str.slice(str.length - base32CharactersCount).toLowerCase();
|
|
13
12
|
}
|