@stackframe/stack-shared 2.4.1 → 2.4.4
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/crud.d.ts +68 -0
- package/dist/crud.js +38 -0
- package/dist/interface/adminInterface.d.ts +2 -0
- package/dist/interface/clientInterface.d.ts +27 -23
- package/dist/interface/clientInterface.js +6 -1
- package/dist/interface/crud/current-user.d.ts +143 -0
- package/dist/interface/crud/current-user.js +28 -0
- package/dist/interface/crud/users.d.ts +149 -0
- package/dist/interface/crud/users.js +33 -0
- package/dist/interface/serverInterface.d.ts +4 -4
- package/dist/known-errors.d.ts +3 -0
- package/dist/known-errors.js +6 -1
- package/dist/utils/arrays.d.ts +1 -0
- package/dist/utils/arrays.js +3 -0
- package/dist/utils/dom.d.ts +0 -3
- package/dist/utils/dom.js +0 -3
- package/dist/utils/errors.d.ts +0 -1
- package/dist/utils/errors.js +3 -5
- package/dist/utils/objects.d.ts +6 -3
- package/dist/utils/types.d.ts +2 -0
- package/package.json +2 -2
package/dist/crud.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { NullishCoalesce } from './utils/types';
|
|
3
|
+
export type CrudOperation = "create" | "read" | "update" | "delete";
|
|
4
|
+
type InnerCrudSchema<CreateSchema extends yup.Schema<any> | undefined = yup.Schema<any> | undefined, ReadSchema extends yup.Schema<any> | undefined = yup.Schema<any> | undefined, UpdateSchema extends yup.Schema<any> | undefined = yup.Schema<any> | undefined, DeleteSchema extends yup.Schema<any> | undefined = yup.Schema<any> | undefined> = {
|
|
5
|
+
createSchema: CreateSchema;
|
|
6
|
+
readSchema: ReadSchema;
|
|
7
|
+
updateSchema: UpdateSchema;
|
|
8
|
+
deleteSchema: DeleteSchema;
|
|
9
|
+
};
|
|
10
|
+
export type CrudSchema<ClientSchema extends InnerCrudSchema = InnerCrudSchema, ServerSchema extends InnerCrudSchema = InnerCrudSchema, AdminSchema extends InnerCrudSchema = InnerCrudSchema> = {
|
|
11
|
+
client: ClientSchema;
|
|
12
|
+
server: ServerSchema;
|
|
13
|
+
admin: AdminSchema;
|
|
14
|
+
hasCreate: boolean;
|
|
15
|
+
hasRead: boolean;
|
|
16
|
+
hasUpdate: boolean;
|
|
17
|
+
hasDelete: boolean;
|
|
18
|
+
};
|
|
19
|
+
type CrudSchemaCreationOptions = {
|
|
20
|
+
clientCreateSchema?: yup.Schema<any>;
|
|
21
|
+
clientReadSchema?: yup.Schema<any>;
|
|
22
|
+
clientUpdateSchema?: yup.Schema<any>;
|
|
23
|
+
clientDeleteSchema?: yup.Schema<any>;
|
|
24
|
+
serverCreateSchema?: yup.Schema<any>;
|
|
25
|
+
serverReadSchema?: yup.Schema<any>;
|
|
26
|
+
serverUpdateSchema?: yup.Schema<any>;
|
|
27
|
+
serverDeleteSchema?: yup.Schema<any>;
|
|
28
|
+
adminCreateSchema?: yup.Schema<any>;
|
|
29
|
+
adminReadSchema?: yup.Schema<any>;
|
|
30
|
+
adminUpdateSchema?: yup.Schema<any>;
|
|
31
|
+
adminDeleteSchema?: yup.Schema<any>;
|
|
32
|
+
};
|
|
33
|
+
type FillInOptionalsPrepareStep<O extends CrudSchemaCreationOptions> = {
|
|
34
|
+
[K in keyof Required<CrudSchemaCreationOptions>]: K extends keyof O ? O[K] : undefined;
|
|
35
|
+
};
|
|
36
|
+
type FillInOptionalsStep<O extends FillInOptionalsPrepareStep<CrudSchemaCreationOptions>> = {
|
|
37
|
+
clientCreateSchema: NullishCoalesce<O['clientCreateSchema'], undefined>;
|
|
38
|
+
clientReadSchema: NullishCoalesce<O['clientReadSchema'], undefined>;
|
|
39
|
+
clientUpdateSchema: NullishCoalesce<O['clientUpdateSchema'], undefined>;
|
|
40
|
+
clientDeleteSchema: NullishCoalesce<O['clientDeleteSchema'], undefined>;
|
|
41
|
+
serverCreateSchema: NullishCoalesce<O['serverCreateSchema'], O['clientCreateSchema']>;
|
|
42
|
+
serverReadSchema: NullishCoalesce<O['serverReadSchema'], O['clientReadSchema']>;
|
|
43
|
+
serverUpdateSchema: NullishCoalesce<O['serverUpdateSchema'], O['clientUpdateSchema']>;
|
|
44
|
+
serverDeleteSchema: NullishCoalesce<O['serverDeleteSchema'], O['clientDeleteSchema']>;
|
|
45
|
+
adminCreateSchema: NullishCoalesce<O['adminCreateSchema'], O['serverCreateSchema']>;
|
|
46
|
+
adminReadSchema: NullishCoalesce<O['adminReadSchema'], O['serverReadSchema']>;
|
|
47
|
+
adminUpdateSchema: NullishCoalesce<O['adminUpdateSchema'], O['serverUpdateSchema']>;
|
|
48
|
+
adminDeleteSchema: NullishCoalesce<O['adminDeleteSchema'], O['serverDeleteSchema']>;
|
|
49
|
+
};
|
|
50
|
+
type FillInOptionals<O extends CrudSchemaCreationOptions> = FillInOptionalsStep<FillInOptionalsStep<FillInOptionalsStep<FillInOptionalsPrepareStep<O>>>>;
|
|
51
|
+
type CrudSchemaFromOptionsInner<O extends FillInOptionals<any>> = CrudSchema<InnerCrudSchema<O['clientCreateSchema'], O['clientReadSchema'], O['clientUpdateSchema'], O['clientDeleteSchema']>, InnerCrudSchema<O['serverCreateSchema'], O['serverReadSchema'], O['serverUpdateSchema'], O['serverDeleteSchema']>, InnerCrudSchema<O['adminCreateSchema'], O['adminReadSchema'], O['adminUpdateSchema'], O['adminDeleteSchema']>>;
|
|
52
|
+
type CrudSchemaFromOptions<O extends CrudSchemaCreationOptions> = CrudSchemaFromOptionsInner<FillInOptionals<O>>;
|
|
53
|
+
type InnerCrudTypeOf<S extends InnerCrudSchema> = (S['createSchema'] extends {} ? {
|
|
54
|
+
Create: yup.InferType<S['createSchema']>;
|
|
55
|
+
} : {}) & (S['readSchema'] extends {} ? {
|
|
56
|
+
Read: yup.InferType<S['readSchema']>;
|
|
57
|
+
} : {}) & (S['updateSchema'] extends {} ? {
|
|
58
|
+
Update: yup.InferType<S['updateSchema']>;
|
|
59
|
+
} : {}) & (S['deleteSchema'] extends {} ? {
|
|
60
|
+
Delete: yup.InferType<S['deleteSchema']>;
|
|
61
|
+
} : {});
|
|
62
|
+
export type CrudTypeOf<S extends CrudSchema> = {
|
|
63
|
+
Client: InnerCrudTypeOf<S['client']>;
|
|
64
|
+
Server: InnerCrudTypeOf<S['server']>;
|
|
65
|
+
Admin: InnerCrudTypeOf<S['admin']>;
|
|
66
|
+
};
|
|
67
|
+
export declare function createCrud<O extends CrudSchemaCreationOptions>(options: O): CrudSchemaFromOptions<O>;
|
|
68
|
+
export {};
|
package/dist/crud.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { filterUndefined } from './utils/objects';
|
|
2
|
+
export function createCrud(options) {
|
|
3
|
+
const client = {
|
|
4
|
+
createSchema: options.clientCreateSchema,
|
|
5
|
+
readSchema: options.clientReadSchema,
|
|
6
|
+
updateSchema: options.clientUpdateSchema,
|
|
7
|
+
deleteSchema: options.clientDeleteSchema,
|
|
8
|
+
};
|
|
9
|
+
const serverOverrides = filterUndefined({
|
|
10
|
+
createSchema: options.serverCreateSchema,
|
|
11
|
+
readSchema: options.serverReadSchema,
|
|
12
|
+
updateSchema: options.serverUpdateSchema,
|
|
13
|
+
deleteSchema: options.serverDeleteSchema,
|
|
14
|
+
});
|
|
15
|
+
const server = {
|
|
16
|
+
...client,
|
|
17
|
+
...serverOverrides,
|
|
18
|
+
};
|
|
19
|
+
const adminOverrides = filterUndefined({
|
|
20
|
+
createSchema: options.adminCreateSchema,
|
|
21
|
+
readSchema: options.adminReadSchema,
|
|
22
|
+
updateSchema: options.adminUpdateSchema,
|
|
23
|
+
deleteSchema: options.adminDeleteSchema,
|
|
24
|
+
});
|
|
25
|
+
const admin = {
|
|
26
|
+
...server,
|
|
27
|
+
...adminOverrides,
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
client: client,
|
|
31
|
+
server: server,
|
|
32
|
+
admin: admin,
|
|
33
|
+
hasCreate: !!admin.createSchema,
|
|
34
|
+
hasRead: !!admin.readSchema,
|
|
35
|
+
hasUpdate: !!admin.updateSchema,
|
|
36
|
+
hasDelete: !!admin.deleteSchema,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -3,44 +3,46 @@ import { Result } from "../utils/results";
|
|
|
3
3
|
import { ReadonlyJson } from '../utils/json';
|
|
4
4
|
import { AsyncStore, ReadonlyAsyncStore } from '../utils/stores';
|
|
5
5
|
import { KnownErrors } from '../known-errors';
|
|
6
|
+
import { ProjectUpdateOptions } from './adminInterface';
|
|
6
7
|
type UserCustomizableJson = {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
displayName: string | null;
|
|
9
|
+
clientMetadata: ReadonlyJson;
|
|
9
10
|
};
|
|
10
11
|
export type UserJson = UserCustomizableJson & {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
projectId: string;
|
|
13
|
+
id: string;
|
|
14
|
+
primaryEmail: string | null;
|
|
15
|
+
primaryEmailVerified: boolean;
|
|
16
|
+
displayName: string | null;
|
|
17
|
+
clientMetadata: ReadonlyJson;
|
|
18
|
+
profileImageUrl: string | null;
|
|
19
|
+
signedUpAtMillis: number;
|
|
19
20
|
/**
|
|
20
21
|
* not used anymore, for backwards compatibility
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
authMethod: "credential" | "oauth";
|
|
24
|
+
hasPassword: boolean;
|
|
25
|
+
authWithEmail: boolean;
|
|
26
|
+
oauthProviders: string[];
|
|
26
27
|
};
|
|
27
28
|
export type UserUpdateJson = Partial<UserCustomizableJson>;
|
|
28
29
|
export type ClientProjectJson = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
id: string;
|
|
31
|
+
credentialEnabled: boolean;
|
|
32
|
+
magicLinkEnabled: boolean;
|
|
33
|
+
oauthProviders: {
|
|
33
34
|
id: string;
|
|
34
35
|
enabled: boolean;
|
|
35
36
|
}[];
|
|
36
37
|
};
|
|
37
38
|
export type ClientInterfaceOptions = {
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
clientVersion: string;
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
projectId: string;
|
|
40
42
|
} & ({
|
|
41
|
-
|
|
43
|
+
publishableClientKey: string;
|
|
42
44
|
} | {
|
|
43
|
-
|
|
45
|
+
projectOwnerTokens: ReadonlyTokenStore;
|
|
44
46
|
});
|
|
45
47
|
export type SharedProvider = "shared-github" | "shared-google" | "shared-facebook" | "shared-microsoft";
|
|
46
48
|
export declare const sharedProviders: readonly ["shared-github", "shared-google", "shared-facebook", "shared-microsoft"];
|
|
@@ -179,7 +181,9 @@ export declare class StackClientInterface {
|
|
|
179
181
|
getClientProject(): Promise<Result<ClientProjectJson>>;
|
|
180
182
|
setClientUserCustomizableData(update: UserUpdateJson, tokenStore: TokenStore): Promise<void>;
|
|
181
183
|
listProjects(tokenStore: TokenStore): Promise<ProjectJson[]>;
|
|
182
|
-
createProject(project:
|
|
184
|
+
createProject(project: ProjectUpdateOptions & {
|
|
185
|
+
displayName: string;
|
|
186
|
+
}, tokenStore: TokenStore): Promise<ProjectJson>;
|
|
183
187
|
}
|
|
184
188
|
export declare function getProductionModeErrors(project: ProjectJson): ProductionModeError[];
|
|
185
189
|
export {};
|
|
@@ -143,8 +143,13 @@ export class StackClientInterface {
|
|
|
143
143
|
"X-Stack-Override-Error-Status": "true",
|
|
144
144
|
"X-Stack-Project-Id": this.projectId,
|
|
145
145
|
"X-Stack-Request-Type": requestType,
|
|
146
|
+
"X-Stack-Client-Version": this.options.clientVersion,
|
|
146
147
|
...tokenObj.accessToken ? {
|
|
147
148
|
"Authorization": "StackSession " + tokenObj.accessToken,
|
|
149
|
+
"X-Stack-Access-Token": tokenObj.accessToken,
|
|
150
|
+
} : {},
|
|
151
|
+
...tokenObj.refreshToken ? {
|
|
152
|
+
"X-Stack-Refresh-Token": tokenObj.refreshToken,
|
|
148
153
|
} : {},
|
|
149
154
|
...'publishableClientKey' in this.options ? {
|
|
150
155
|
"X-Stack-Publishable-Client-Key": this.options.publishableClientKey,
|
|
@@ -490,7 +495,7 @@ export class StackClientInterface {
|
|
|
490
495
|
}
|
|
491
496
|
export function getProductionModeErrors(project) {
|
|
492
497
|
const errors = [];
|
|
493
|
-
const fixUrlRelative = `/projects/${project.id}/
|
|
498
|
+
const fixUrlRelative = `/projects/${project.id}/urls-and-callbacks`;
|
|
494
499
|
if (project.evaluatedConfig.allowLocalhost) {
|
|
495
500
|
errors.push({
|
|
496
501
|
errorMessage: "Localhost is not allowed in production mode, turn off 'Allow localhost' in project settings",
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { CrudTypeOf } from "../../crud";
|
|
2
|
+
import * as yup from "yup";
|
|
3
|
+
export declare const currentUserCrud: {
|
|
4
|
+
client: {
|
|
5
|
+
createSchema: undefined;
|
|
6
|
+
readSchema: yup.ObjectSchema<{
|
|
7
|
+
displayName: string | null;
|
|
8
|
+
id: string;
|
|
9
|
+
projectId: string;
|
|
10
|
+
clientMetadata: {} | null;
|
|
11
|
+
primaryEmail: string | null;
|
|
12
|
+
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
13
|
+
profileImageUrl: string | null;
|
|
14
|
+
signedUpAtMillis: number;
|
|
15
|
+
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
16
|
+
hasPassword: NonNullable<boolean | undefined>;
|
|
17
|
+
authWithEmail: NonNullable<boolean | undefined>;
|
|
18
|
+
oauthProviders: string[];
|
|
19
|
+
} | null, yup.AnyObject, {
|
|
20
|
+
projectId: undefined;
|
|
21
|
+
id: undefined;
|
|
22
|
+
primaryEmail: undefined;
|
|
23
|
+
primaryEmailVerified: undefined;
|
|
24
|
+
displayName: undefined;
|
|
25
|
+
clientMetadata: {};
|
|
26
|
+
profileImageUrl: undefined;
|
|
27
|
+
signedUpAtMillis: undefined;
|
|
28
|
+
authMethod: undefined;
|
|
29
|
+
hasPassword: undefined;
|
|
30
|
+
authWithEmail: undefined;
|
|
31
|
+
oauthProviders: undefined;
|
|
32
|
+
serverMetadata: {};
|
|
33
|
+
}, "">;
|
|
34
|
+
updateSchema: yup.ObjectSchema<{
|
|
35
|
+
displayName: string | undefined;
|
|
36
|
+
clientMetadata: {} | undefined;
|
|
37
|
+
}, yup.AnyObject, {
|
|
38
|
+
displayName: undefined;
|
|
39
|
+
clientMetadata: {};
|
|
40
|
+
serverMetadata: {};
|
|
41
|
+
primaryEmail: undefined;
|
|
42
|
+
primaryEmailVerified: undefined;
|
|
43
|
+
}, "">;
|
|
44
|
+
deleteSchema: undefined;
|
|
45
|
+
};
|
|
46
|
+
server: {
|
|
47
|
+
createSchema: undefined;
|
|
48
|
+
readSchema: yup.ObjectSchema<{
|
|
49
|
+
projectId: string;
|
|
50
|
+
id: string;
|
|
51
|
+
primaryEmail: string | null;
|
|
52
|
+
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
53
|
+
displayName: string | null;
|
|
54
|
+
clientMetadata: {} | null;
|
|
55
|
+
profileImageUrl: string | null;
|
|
56
|
+
signedUpAtMillis: number;
|
|
57
|
+
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
58
|
+
hasPassword: NonNullable<boolean | undefined>;
|
|
59
|
+
authWithEmail: NonNullable<boolean | undefined>;
|
|
60
|
+
oauthProviders: string[];
|
|
61
|
+
serverMetadata: {} | null;
|
|
62
|
+
} | null, yup.AnyObject, {
|
|
63
|
+
projectId: undefined;
|
|
64
|
+
id: undefined;
|
|
65
|
+
primaryEmail: undefined;
|
|
66
|
+
primaryEmailVerified: undefined;
|
|
67
|
+
displayName: undefined;
|
|
68
|
+
clientMetadata: {};
|
|
69
|
+
profileImageUrl: undefined;
|
|
70
|
+
signedUpAtMillis: undefined;
|
|
71
|
+
authMethod: undefined;
|
|
72
|
+
hasPassword: undefined;
|
|
73
|
+
authWithEmail: undefined;
|
|
74
|
+
oauthProviders: undefined;
|
|
75
|
+
serverMetadata: {};
|
|
76
|
+
}, "">;
|
|
77
|
+
updateSchema: yup.ObjectSchema<{
|
|
78
|
+
displayName: string | undefined;
|
|
79
|
+
clientMetadata: {} | undefined;
|
|
80
|
+
serverMetadata: {} | undefined;
|
|
81
|
+
primaryEmail: string | undefined;
|
|
82
|
+
primaryEmailVerified: boolean | undefined;
|
|
83
|
+
}, yup.AnyObject, {
|
|
84
|
+
displayName: undefined;
|
|
85
|
+
clientMetadata: {};
|
|
86
|
+
serverMetadata: {};
|
|
87
|
+
primaryEmail: undefined;
|
|
88
|
+
primaryEmailVerified: undefined;
|
|
89
|
+
}, "">;
|
|
90
|
+
deleteSchema: undefined;
|
|
91
|
+
};
|
|
92
|
+
admin: {
|
|
93
|
+
createSchema: undefined;
|
|
94
|
+
readSchema: yup.ObjectSchema<{
|
|
95
|
+
projectId: string;
|
|
96
|
+
id: string;
|
|
97
|
+
primaryEmail: string | null;
|
|
98
|
+
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
99
|
+
displayName: string | null;
|
|
100
|
+
clientMetadata: {} | null;
|
|
101
|
+
profileImageUrl: string | null;
|
|
102
|
+
signedUpAtMillis: number;
|
|
103
|
+
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
104
|
+
hasPassword: NonNullable<boolean | undefined>;
|
|
105
|
+
authWithEmail: NonNullable<boolean | undefined>;
|
|
106
|
+
oauthProviders: string[];
|
|
107
|
+
serverMetadata: {} | null;
|
|
108
|
+
} | null, yup.AnyObject, {
|
|
109
|
+
projectId: undefined;
|
|
110
|
+
id: undefined;
|
|
111
|
+
primaryEmail: undefined;
|
|
112
|
+
primaryEmailVerified: undefined;
|
|
113
|
+
displayName: undefined;
|
|
114
|
+
clientMetadata: {};
|
|
115
|
+
profileImageUrl: undefined;
|
|
116
|
+
signedUpAtMillis: undefined;
|
|
117
|
+
authMethod: undefined;
|
|
118
|
+
hasPassword: undefined;
|
|
119
|
+
authWithEmail: undefined;
|
|
120
|
+
oauthProviders: undefined;
|
|
121
|
+
serverMetadata: {};
|
|
122
|
+
}, "">;
|
|
123
|
+
updateSchema: yup.ObjectSchema<{
|
|
124
|
+
displayName: string | undefined;
|
|
125
|
+
clientMetadata: {} | undefined;
|
|
126
|
+
serverMetadata: {} | undefined;
|
|
127
|
+
primaryEmail: string | undefined;
|
|
128
|
+
primaryEmailVerified: boolean | undefined;
|
|
129
|
+
}, yup.AnyObject, {
|
|
130
|
+
displayName: undefined;
|
|
131
|
+
clientMetadata: {};
|
|
132
|
+
serverMetadata: {};
|
|
133
|
+
primaryEmail: undefined;
|
|
134
|
+
primaryEmailVerified: undefined;
|
|
135
|
+
}, "">;
|
|
136
|
+
deleteSchema: undefined;
|
|
137
|
+
};
|
|
138
|
+
hasCreate: boolean;
|
|
139
|
+
hasRead: boolean;
|
|
140
|
+
hasUpdate: boolean;
|
|
141
|
+
hasDelete: boolean;
|
|
142
|
+
};
|
|
143
|
+
export type CurrentUserCrud = CrudTypeOf<typeof currentUserCrud>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createCrud } from "../../crud";
|
|
2
|
+
import { usersCrudServerReadSchema, usersCrudServerUpdateSchema } from "./users";
|
|
3
|
+
const clientUpdateSchema = usersCrudServerUpdateSchema.pick([
|
|
4
|
+
"displayName",
|
|
5
|
+
"clientMetadata",
|
|
6
|
+
]).required();
|
|
7
|
+
const serverUpdateSchema = usersCrudServerUpdateSchema;
|
|
8
|
+
const clientReadSchema = usersCrudServerReadSchema.pick([
|
|
9
|
+
"projectId",
|
|
10
|
+
"id",
|
|
11
|
+
"primaryEmail",
|
|
12
|
+
"primaryEmailVerified",
|
|
13
|
+
"displayName",
|
|
14
|
+
"clientMetadata",
|
|
15
|
+
"profileImageUrl",
|
|
16
|
+
"signedUpAtMillis",
|
|
17
|
+
"authMethod",
|
|
18
|
+
"hasPassword",
|
|
19
|
+
"authWithEmail",
|
|
20
|
+
"oauthProviders",
|
|
21
|
+
]).nullable().defined();
|
|
22
|
+
const serverReadSchema = usersCrudServerReadSchema.nullable().defined();
|
|
23
|
+
export const currentUserCrud = createCrud({
|
|
24
|
+
clientReadSchema,
|
|
25
|
+
serverReadSchema,
|
|
26
|
+
clientUpdateSchema,
|
|
27
|
+
serverUpdateSchema,
|
|
28
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { CrudTypeOf } from "../../crud";
|
|
2
|
+
import * as yup from "yup";
|
|
3
|
+
export declare const usersCrudServerUpdateSchema: yup.ObjectSchema<{
|
|
4
|
+
displayName: string | undefined;
|
|
5
|
+
clientMetadata: {} | undefined;
|
|
6
|
+
serverMetadata: {} | undefined;
|
|
7
|
+
primaryEmail: string | undefined;
|
|
8
|
+
primaryEmailVerified: boolean | undefined;
|
|
9
|
+
}, yup.AnyObject, {
|
|
10
|
+
displayName: undefined;
|
|
11
|
+
clientMetadata: {};
|
|
12
|
+
serverMetadata: {};
|
|
13
|
+
primaryEmail: undefined;
|
|
14
|
+
primaryEmailVerified: undefined;
|
|
15
|
+
}, "">;
|
|
16
|
+
export declare const usersCrudServerReadSchema: yup.ObjectSchema<{
|
|
17
|
+
projectId: string;
|
|
18
|
+
id: string;
|
|
19
|
+
primaryEmail: string | null;
|
|
20
|
+
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
21
|
+
displayName: string | null;
|
|
22
|
+
clientMetadata: {} | null;
|
|
23
|
+
profileImageUrl: string | null;
|
|
24
|
+
signedUpAtMillis: number;
|
|
25
|
+
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
26
|
+
hasPassword: NonNullable<boolean | undefined>;
|
|
27
|
+
authWithEmail: NonNullable<boolean | undefined>;
|
|
28
|
+
oauthProviders: string[];
|
|
29
|
+
serverMetadata: {} | null;
|
|
30
|
+
}, yup.AnyObject, {
|
|
31
|
+
projectId: undefined;
|
|
32
|
+
id: undefined;
|
|
33
|
+
primaryEmail: undefined;
|
|
34
|
+
primaryEmailVerified: undefined;
|
|
35
|
+
displayName: undefined;
|
|
36
|
+
clientMetadata: {};
|
|
37
|
+
profileImageUrl: undefined;
|
|
38
|
+
signedUpAtMillis: undefined;
|
|
39
|
+
authMethod: undefined;
|
|
40
|
+
hasPassword: undefined;
|
|
41
|
+
authWithEmail: undefined;
|
|
42
|
+
oauthProviders: undefined;
|
|
43
|
+
serverMetadata: {};
|
|
44
|
+
}, "">;
|
|
45
|
+
export declare const usersCrud: {
|
|
46
|
+
client: {
|
|
47
|
+
createSchema: undefined;
|
|
48
|
+
readSchema: undefined;
|
|
49
|
+
updateSchema: undefined;
|
|
50
|
+
deleteSchema: undefined;
|
|
51
|
+
};
|
|
52
|
+
server: {
|
|
53
|
+
createSchema: undefined;
|
|
54
|
+
readSchema: yup.ObjectSchema<{
|
|
55
|
+
projectId: string;
|
|
56
|
+
id: string;
|
|
57
|
+
primaryEmail: string | null;
|
|
58
|
+
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
59
|
+
displayName: string | null;
|
|
60
|
+
clientMetadata: {} | null;
|
|
61
|
+
profileImageUrl: string | null;
|
|
62
|
+
signedUpAtMillis: number;
|
|
63
|
+
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
64
|
+
hasPassword: NonNullable<boolean | undefined>;
|
|
65
|
+
authWithEmail: NonNullable<boolean | undefined>;
|
|
66
|
+
oauthProviders: string[];
|
|
67
|
+
serverMetadata: {} | null;
|
|
68
|
+
}, yup.AnyObject, {
|
|
69
|
+
projectId: undefined;
|
|
70
|
+
id: undefined;
|
|
71
|
+
primaryEmail: undefined;
|
|
72
|
+
primaryEmailVerified: undefined;
|
|
73
|
+
displayName: undefined;
|
|
74
|
+
clientMetadata: {};
|
|
75
|
+
profileImageUrl: undefined;
|
|
76
|
+
signedUpAtMillis: undefined;
|
|
77
|
+
authMethod: undefined;
|
|
78
|
+
hasPassword: undefined;
|
|
79
|
+
authWithEmail: undefined;
|
|
80
|
+
oauthProviders: undefined;
|
|
81
|
+
serverMetadata: {};
|
|
82
|
+
}, "">;
|
|
83
|
+
updateSchema: yup.ObjectSchema<{
|
|
84
|
+
displayName: string | undefined;
|
|
85
|
+
clientMetadata: {} | undefined;
|
|
86
|
+
serverMetadata: {} | undefined;
|
|
87
|
+
primaryEmail: string | undefined;
|
|
88
|
+
primaryEmailVerified: boolean | undefined;
|
|
89
|
+
}, yup.AnyObject, {
|
|
90
|
+
displayName: undefined;
|
|
91
|
+
clientMetadata: {};
|
|
92
|
+
serverMetadata: {};
|
|
93
|
+
primaryEmail: undefined;
|
|
94
|
+
primaryEmailVerified: undefined;
|
|
95
|
+
}, "">;
|
|
96
|
+
deleteSchema: yup.MixedSchema<{} | undefined, yup.AnyObject, undefined, "">;
|
|
97
|
+
};
|
|
98
|
+
admin: {
|
|
99
|
+
createSchema: undefined;
|
|
100
|
+
readSchema: yup.ObjectSchema<{
|
|
101
|
+
projectId: string;
|
|
102
|
+
id: string;
|
|
103
|
+
primaryEmail: string | null;
|
|
104
|
+
primaryEmailVerified: NonNullable<boolean | undefined>;
|
|
105
|
+
displayName: string | null;
|
|
106
|
+
clientMetadata: {} | null;
|
|
107
|
+
profileImageUrl: string | null;
|
|
108
|
+
signedUpAtMillis: number;
|
|
109
|
+
authMethod: NonNullable<"credential" | "oauth" | undefined>;
|
|
110
|
+
hasPassword: NonNullable<boolean | undefined>;
|
|
111
|
+
authWithEmail: NonNullable<boolean | undefined>;
|
|
112
|
+
oauthProviders: string[];
|
|
113
|
+
serverMetadata: {} | null;
|
|
114
|
+
}, yup.AnyObject, {
|
|
115
|
+
projectId: undefined;
|
|
116
|
+
id: undefined;
|
|
117
|
+
primaryEmail: undefined;
|
|
118
|
+
primaryEmailVerified: undefined;
|
|
119
|
+
displayName: undefined;
|
|
120
|
+
clientMetadata: {};
|
|
121
|
+
profileImageUrl: undefined;
|
|
122
|
+
signedUpAtMillis: undefined;
|
|
123
|
+
authMethod: undefined;
|
|
124
|
+
hasPassword: undefined;
|
|
125
|
+
authWithEmail: undefined;
|
|
126
|
+
oauthProviders: undefined;
|
|
127
|
+
serverMetadata: {};
|
|
128
|
+
}, "">;
|
|
129
|
+
updateSchema: yup.ObjectSchema<{
|
|
130
|
+
displayName: string | undefined;
|
|
131
|
+
clientMetadata: {} | undefined;
|
|
132
|
+
serverMetadata: {} | undefined;
|
|
133
|
+
primaryEmail: string | undefined;
|
|
134
|
+
primaryEmailVerified: boolean | undefined;
|
|
135
|
+
}, yup.AnyObject, {
|
|
136
|
+
displayName: undefined;
|
|
137
|
+
clientMetadata: {};
|
|
138
|
+
serverMetadata: {};
|
|
139
|
+
primaryEmail: undefined;
|
|
140
|
+
primaryEmailVerified: undefined;
|
|
141
|
+
}, "">;
|
|
142
|
+
deleteSchema: yup.MixedSchema<{} | undefined, yup.AnyObject, undefined, "">;
|
|
143
|
+
};
|
|
144
|
+
hasCreate: boolean;
|
|
145
|
+
hasRead: boolean;
|
|
146
|
+
hasUpdate: boolean;
|
|
147
|
+
hasDelete: boolean;
|
|
148
|
+
};
|
|
149
|
+
export type UsersCrud = CrudTypeOf<typeof usersCrud>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createCrud } from "../../crud";
|
|
2
|
+
import * as yup from "yup";
|
|
3
|
+
export const usersCrudServerUpdateSchema = yup.object({
|
|
4
|
+
displayName: yup.string().optional(),
|
|
5
|
+
clientMetadata: yup.object().optional(),
|
|
6
|
+
serverMetadata: yup.object().optional(),
|
|
7
|
+
primaryEmail: yup.string().optional(),
|
|
8
|
+
primaryEmailVerified: yup.boolean().optional(),
|
|
9
|
+
}).required();
|
|
10
|
+
export const usersCrudServerReadSchema = yup.object({
|
|
11
|
+
projectId: yup.string().required(),
|
|
12
|
+
id: yup.string().required(),
|
|
13
|
+
primaryEmail: yup.string().nullable().defined(),
|
|
14
|
+
primaryEmailVerified: yup.boolean().required(),
|
|
15
|
+
displayName: yup.string().nullable().defined(),
|
|
16
|
+
clientMetadata: yup.object().nullable().defined().transform((value) => JSON.parse(JSON.stringify(value))),
|
|
17
|
+
profileImageUrl: yup.string().nullable().defined(),
|
|
18
|
+
signedUpAtMillis: yup.number().required(),
|
|
19
|
+
/**
|
|
20
|
+
* not used anymore, for backwards compatibility
|
|
21
|
+
*/
|
|
22
|
+
authMethod: yup.string().oneOf(["credential", "oauth"]).required(),
|
|
23
|
+
hasPassword: yup.boolean().required(),
|
|
24
|
+
authWithEmail: yup.boolean().required(),
|
|
25
|
+
oauthProviders: yup.array(yup.string().required()).required(),
|
|
26
|
+
serverMetadata: yup.object().nullable().defined().transform((value) => JSON.parse(JSON.stringify(value))),
|
|
27
|
+
}).required();
|
|
28
|
+
const serverDeleteSchema = yup.mixed();
|
|
29
|
+
export const usersCrud = createCrud({
|
|
30
|
+
serverReadSchema: usersCrudServerReadSchema,
|
|
31
|
+
serverUpdateSchema: usersCrudServerUpdateSchema,
|
|
32
|
+
serverDeleteSchema,
|
|
33
|
+
});
|
|
@@ -2,12 +2,12 @@ import { ClientInterfaceOptions, UserJson, TokenStore, StackClientInterface, Rea
|
|
|
2
2
|
import { Result } from "../utils/results";
|
|
3
3
|
import { ReadonlyJson } from "../utils/json";
|
|
4
4
|
export type ServerUserJson = UserJson & {
|
|
5
|
-
|
|
5
|
+
serverMetadata: ReadonlyJson;
|
|
6
6
|
};
|
|
7
7
|
export type ServerUserUpdateJson = UserUpdateJson & {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
serverMetadata?: ReadonlyJson;
|
|
9
|
+
primaryEmail?: string | null;
|
|
10
|
+
primaryEmailVerified?: boolean;
|
|
11
11
|
};
|
|
12
12
|
export type ServerOrglikeCustomizableJson = Pick<ServerOrglikeJson, "displayName">;
|
|
13
13
|
export type ServerOrglikeJson = OrglikeJson & {};
|
package/dist/known-errors.d.ts
CHANGED
|
@@ -47,6 +47,9 @@ export declare const KnownErrors: {
|
|
|
47
47
|
UnsupportedError: KnownErrorConstructor<KnownError & KnownErrorBrand<"UNSUPPORTED_ERROR">, [originalErrorCode: string]> & {
|
|
48
48
|
errorCode: "UNSUPPORTED_ERROR";
|
|
49
49
|
};
|
|
50
|
+
BodyParsingError: KnownErrorConstructor<KnownError & KnownErrorBrand<"BODY_PARSING_ERROR">, [string]> & {
|
|
51
|
+
errorCode: "BODY_PARSING_ERROR";
|
|
52
|
+
};
|
|
50
53
|
SchemaError: KnownErrorConstructor<KnownError & KnownErrorBrand<"SCHEMA_ERROR">, [string]> & {
|
|
51
54
|
errorCode: "SCHEMA_ERROR";
|
|
52
55
|
};
|
package/dist/known-errors.js
CHANGED
|
@@ -75,6 +75,10 @@ const UnsupportedError = createKnownErrorConstructor(KnownError, "UNSUPPORTED_ER
|
|
|
75
75
|
], (json) => [
|
|
76
76
|
json.details?.originalErrorCode ?? throwErr("originalErrorCode not found in UnsupportedError details"),
|
|
77
77
|
]);
|
|
78
|
+
const BodyParsingError = createKnownErrorConstructor(KnownError, "BODY_PARSING_ERROR", (message) => [
|
|
79
|
+
400,
|
|
80
|
+
message,
|
|
81
|
+
], (json) => [json.message]);
|
|
78
82
|
const SchemaError = createKnownErrorConstructor(KnownError, "SCHEMA_ERROR", (message) => [
|
|
79
83
|
400,
|
|
80
84
|
message,
|
|
@@ -89,7 +93,7 @@ const AllOverloadsFailed = createKnownErrorConstructor(KnownError, "ALL_OVERLOAD
|
|
|
89
93
|
`).join("\n\n")}
|
|
90
94
|
`,
|
|
91
95
|
{
|
|
92
|
-
|
|
96
|
+
overloadErrors,
|
|
93
97
|
},
|
|
94
98
|
], (json) => [
|
|
95
99
|
json.details?.overloadErrors ?? throwErr("overloadErrors not found in AllOverloadsFailed details"),
|
|
@@ -335,6 +339,7 @@ const TeamNotFound = createKnownErrorConstructor(KnownError, "TEAM_NOT_FOUND", (
|
|
|
335
339
|
], (json) => [json.details.teamId]);
|
|
336
340
|
export const KnownErrors = {
|
|
337
341
|
UnsupportedError,
|
|
342
|
+
BodyParsingError,
|
|
338
343
|
SchemaError,
|
|
339
344
|
AllOverloadsFailed,
|
|
340
345
|
ProjectAuthenticationError,
|
package/dist/utils/arrays.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export declare function range(startInclusive: number, endExclusive: number, step
|
|
|
8
8
|
export declare function rotateLeft(arr: readonly any[], n: number): any[];
|
|
9
9
|
export declare function rotateRight(arr: readonly any[], n: number): any[];
|
|
10
10
|
export declare function shuffle<T>(arr: readonly T[]): T[];
|
|
11
|
+
export declare function outerProduct<T, U>(arr1: readonly T[], arr2: readonly U[]): [T, U][];
|
package/dist/utils/arrays.js
CHANGED
package/dist/utils/dom.d.ts
CHANGED
package/dist/utils/dom.js
CHANGED
package/dist/utils/errors.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export declare function throwErr(error: Error): never;
|
|
|
4
4
|
export declare function throwErr(...args: StatusErrorConstructorParameters): never;
|
|
5
5
|
export declare class StackAssertionError extends Error {
|
|
6
6
|
readonly extraData?: Record<string, any> | undefined;
|
|
7
|
-
name: string;
|
|
8
7
|
constructor(message: string, extraData?: Record<string, any> | undefined, options?: ErrorOptions);
|
|
9
8
|
}
|
|
10
9
|
export declare function throwStackErr(message: string, extraData?: any): never;
|
package/dist/utils/errors.js
CHANGED
|
@@ -12,12 +12,13 @@ export function throwErr(...args) {
|
|
|
12
12
|
}
|
|
13
13
|
export class StackAssertionError extends Error {
|
|
14
14
|
extraData;
|
|
15
|
-
name = "StackAssertionError";
|
|
16
15
|
constructor(message, extraData, options) {
|
|
17
|
-
|
|
16
|
+
const disclaimer = `\n\nThis is likely an error in Stack. Please report it.`;
|
|
17
|
+
super(`${message}${message.endsWith(disclaimer) ? "" : disclaimer}`, options);
|
|
18
18
|
this.extraData = extraData;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
StackAssertionError.prototype.name = "StackAssertionError";
|
|
21
22
|
export function throwStackErr(message, extraData) {
|
|
22
23
|
throw new StackAssertionError(message, extraData);
|
|
23
24
|
}
|
|
@@ -30,9 +31,6 @@ export function registerErrorSink(sink) {
|
|
|
30
31
|
}
|
|
31
32
|
registerErrorSink((location, ...args) => {
|
|
32
33
|
console.error(`Error in ${location}:`, ...args);
|
|
33
|
-
if (process.env.NODE_ENV === "development") {
|
|
34
|
-
debugger;
|
|
35
|
-
}
|
|
36
34
|
});
|
|
37
35
|
export function captureError(location, error) {
|
|
38
36
|
for (const sink of errorSinks) {
|
package/dist/utils/objects.d.ts
CHANGED
|
@@ -12,12 +12,15 @@ export declare function typedFromEntries<K extends PropertyKey, V>(entries: [K,
|
|
|
12
12
|
export declare function typedKeys<T extends {}>(obj: T): (keyof T)[];
|
|
13
13
|
export declare function typedValues<T extends {}>(obj: T): T[keyof T][];
|
|
14
14
|
export declare function typedAssign<T extends {}, U extends {}>(target: T, source: U): asserts target is T & U;
|
|
15
|
+
export type FilterUndefined<T> = {
|
|
16
|
+
[k in keyof T as (undefined extends T[k] ? (T[k] extends undefined | void ? never : k) : never)]+?: T[k] & ({} | null);
|
|
17
|
+
} & {
|
|
18
|
+
[k in keyof T as (undefined extends T[k] ? never : k)]: T[k] & ({} | null);
|
|
19
|
+
};
|
|
15
20
|
/**
|
|
16
21
|
* Returns a new object with all undefined values removed. Useful when spreading optional parameters on an object, as
|
|
17
22
|
* TypeScript's `Partial<XYZ>` type allows `undefined` values.
|
|
18
23
|
*/
|
|
19
|
-
export declare function filterUndefined<T extends {}>(obj: T):
|
|
20
|
-
[k in keyof T]+?: T[k] & ({} | null);
|
|
21
|
-
};
|
|
24
|
+
export declare function filterUndefined<T extends {}>(obj: T): FilterUndefined<T>;
|
|
22
25
|
export declare function pick<T extends {}, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
23
26
|
export declare function omit<T extends {}, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
package/dist/utils/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackframe/stack-shared",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"jose": "^5.2.2",
|
|
25
25
|
"oauth4webapi": "^2.10.3",
|
|
26
26
|
"uuid": "^9.0.1",
|
|
27
|
-
"@stackframe/stack-sc": "1.5.
|
|
27
|
+
"@stackframe/stack-sc": "1.5.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/bcrypt": "^5.0.2",
|