@stackframe/stack-shared 2.5.2 → 2.5.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/CHANGELOG.md +16 -0
- package/dist/crud.d.ts +10 -3
- package/dist/helpers/production-mode.d.ts +6 -0
- package/dist/helpers/production-mode.js +43 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/interface/adminInterface.d.ts +28 -67
- package/dist/interface/adminInterface.js +63 -22
- package/dist/interface/clientInterface.d.ts +21 -133
- package/dist/interface/clientInterface.js +92 -119
- package/dist/interface/crud/api-keys.d.ts +134 -0
- package/dist/interface/crud/api-keys.js +61 -0
- package/dist/interface/crud/current-user.d.ts +47 -11
- package/dist/interface/crud/current-user.js +7 -3
- package/dist/interface/crud/email-templates.d.ts +53 -34
- package/dist/interface/crud/email-templates.js +37 -24
- package/dist/interface/crud/oauth.d.ts +8 -9
- package/dist/interface/crud/oauth.js +5 -5
- package/dist/interface/crud/projects.d.ts +446 -0
- package/dist/interface/crud/projects.js +110 -0
- package/dist/interface/crud/team-memberships.d.ts +22 -0
- package/dist/interface/crud/team-memberships.js +22 -0
- package/dist/interface/crud/team-permissions.d.ts +129 -0
- package/dist/interface/crud/team-permissions.js +83 -0
- package/dist/interface/crud/teams.d.ts +148 -0
- package/dist/interface/crud/teams.js +80 -0
- package/dist/interface/crud/users.d.ts +88 -33
- package/dist/interface/crud/users.js +22 -14
- package/dist/interface/crud-deprecated/api-keys.d.ts +134 -0
- package/dist/interface/crud-deprecated/api-keys.js +61 -0
- package/dist/interface/crud-deprecated/current-user.d.ts +127 -0
- package/dist/interface/crud-deprecated/current-user.js +49 -0
- package/dist/interface/crud-deprecated/email-templates.d.ts +75 -0
- package/dist/interface/crud-deprecated/email-templates.js +41 -0
- package/dist/interface/crud-deprecated/oauth.d.ts +24 -0
- package/dist/interface/crud-deprecated/oauth.js +12 -0
- package/dist/interface/crud-deprecated/projects.d.ts +440 -0
- package/dist/interface/crud-deprecated/projects.js +109 -0
- package/dist/interface/crud-deprecated/team-memberships.d.ts +22 -0
- package/dist/interface/crud-deprecated/team-memberships.js +22 -0
- package/dist/interface/crud-deprecated/team-permissions.d.ts +129 -0
- package/dist/interface/crud-deprecated/team-permissions.js +83 -0
- package/dist/interface/crud-deprecated/teams.d.ts +126 -0
- package/dist/interface/crud-deprecated/teams.js +78 -0
- package/dist/interface/crud-deprecated/users.d.ts +201 -0
- package/dist/interface/crud-deprecated/users.js +75 -0
- package/dist/interface/serverInterface.d.ts +33 -60
- package/dist/interface/serverInterface.js +74 -102
- package/dist/known-errors.d.ts +43 -26
- package/dist/known-errors.js +135 -92
- package/dist/schema-fields.d.ts +53 -4
- package/dist/schema-fields.js +156 -26
- package/dist/sessions.d.ts +1 -0
- package/dist/sessions.js +20 -26
- package/dist/utils/arrays.d.ts +4 -0
- package/dist/utils/arrays.js +10 -0
- package/dist/utils/caches.js +11 -18
- package/dist/utils/compile-time.d.ts +3 -1
- package/dist/utils/compile-time.js +3 -1
- package/dist/utils/errors.d.ts +8 -1
- package/dist/utils/errors.js +58 -47
- package/dist/utils/globals.js +3 -0
- package/dist/utils/maps.js +8 -5
- package/dist/utils/numbers.js +5 -5
- package/dist/utils/objects.d.ts +4 -1
- package/dist/utils/objects.js +16 -8
- package/dist/utils/promises.js +6 -2
- package/dist/utils/proxies.d.ts +1 -0
- package/dist/utils/proxies.js +65 -0
- package/dist/utils/react.d.ts +1 -1
- package/dist/utils/react.js +2 -2
- package/dist/utils/results.js +0 -1
- package/dist/utils/stores.js +7 -10
- package/dist/utils/strings.js +7 -2
- package/dist/utils/urls.d.ts +1 -0
- package/dist/utils/urls.js +8 -0
- package/dist/utils/uuids.d.ts +1 -1
- package/dist/utils/uuids.js +2 -1
- package/package.json +2 -2
- package/dist/utils/yup.d.ts +0 -3
- package/dist/utils/yup.js +0 -13
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createCrud } from "../../crud";
|
|
2
|
+
import * as fieldSchema from "../../schema-fields";
|
|
3
|
+
export const usersCrudServerUpdateSchema = fieldSchema.yupObject({
|
|
4
|
+
display_name: fieldSchema.userDisplayNameSchema.optional(),
|
|
5
|
+
profile_image_url: fieldSchema.profileImageUrlSchema.optional(),
|
|
6
|
+
client_metadata: fieldSchema.userClientMetadataSchema.optional(),
|
|
7
|
+
server_metadata: fieldSchema.userServerMetadataSchema.optional(),
|
|
8
|
+
primary_email: fieldSchema.primaryEmailSchema.nullable().optional(),
|
|
9
|
+
primary_email_verified: fieldSchema.primaryEmailVerifiedSchema.optional(),
|
|
10
|
+
primary_email_auth_enabled: fieldSchema.yupBoolean().optional().meta({ openapiField: { description: "Whether the primary email can be used to sign into this user's account", exampleValue: true } }),
|
|
11
|
+
password: fieldSchema.yupString().nullable().meta({ openapiField: { description: 'A new password for the user, overwriting the old one (if it exists).', exampleValue: 'password' } }),
|
|
12
|
+
selected_team_id: fieldSchema.selectedTeamIdSchema.nullable().optional(),
|
|
13
|
+
}).required();
|
|
14
|
+
export const usersCrudServerReadSchema = fieldSchema.yupObject({
|
|
15
|
+
project_id: fieldSchema.projectIdSchema.required(),
|
|
16
|
+
id: fieldSchema.userIdSchema.required(),
|
|
17
|
+
primary_email: fieldSchema.primaryEmailSchema.nullable().defined(),
|
|
18
|
+
primary_email_verified: fieldSchema.primaryEmailVerifiedSchema.required(),
|
|
19
|
+
display_name: fieldSchema.userDisplayNameSchema.nullable().defined(),
|
|
20
|
+
// TODO give this one the type of an actual team
|
|
21
|
+
selected_team: fieldSchema.yupMixed().nullable().defined(),
|
|
22
|
+
selected_team_id: fieldSchema.selectedTeamIdSchema.nullable().defined(),
|
|
23
|
+
profile_image_url: fieldSchema.profileImageUrlSchema.nullable().defined(),
|
|
24
|
+
signed_up_at_millis: fieldSchema.signedUpAtMillisSchema.required(),
|
|
25
|
+
has_password: fieldSchema.yupBoolean().required().meta({ openapiField: { description: 'Whether the user has a password associated with their account', exampleValue: true } }),
|
|
26
|
+
auth_with_email: fieldSchema.yupBoolean().required().meta({ openapiField: { description: 'Whether the user can authenticate with their primary e-mail. If set to true, the user can log-in with credentials and/or magic link, if enabled in the project settings.', exampleValue: true } }),
|
|
27
|
+
oauth_providers: fieldSchema.yupArray(fieldSchema.yupObject({
|
|
28
|
+
provider_id: fieldSchema.yupString().required(),
|
|
29
|
+
account_id: fieldSchema.yupString().required(),
|
|
30
|
+
email: fieldSchema.yupString().nullable(),
|
|
31
|
+
}).required()).required().meta({ openapiField: { description: 'A list of OAuth providers connected to this account', exampleValue: ['google', 'github'] } }),
|
|
32
|
+
client_metadata: fieldSchema.userClientMetadataSchema,
|
|
33
|
+
server_metadata: fieldSchema.userServerMetadataSchema,
|
|
34
|
+
}).required();
|
|
35
|
+
export const usersCrudServerCreateSchema = usersCrudServerUpdateSchema.concat(fieldSchema.yupObject({
|
|
36
|
+
oauth_providers: fieldSchema.yupArray(fieldSchema.yupObject({
|
|
37
|
+
provider_id: fieldSchema.yupString().required(),
|
|
38
|
+
account_id: fieldSchema.yupString().required(),
|
|
39
|
+
email: fieldSchema.yupString().nullable().defined().default(null),
|
|
40
|
+
}).required()).optional(),
|
|
41
|
+
}).required());
|
|
42
|
+
export const usersCrudServerDeleteSchema = fieldSchema.yupMixed();
|
|
43
|
+
export const usersCrud = createCrud({
|
|
44
|
+
serverReadSchema: usersCrudServerReadSchema,
|
|
45
|
+
serverUpdateSchema: usersCrudServerUpdateSchema,
|
|
46
|
+
serverCreateSchema: usersCrudServerCreateSchema,
|
|
47
|
+
serverDeleteSchema: usersCrudServerDeleteSchema,
|
|
48
|
+
docs: {
|
|
49
|
+
serverCreate: {
|
|
50
|
+
tags: ["Users"],
|
|
51
|
+
summary: 'Create user',
|
|
52
|
+
description: 'Creates a new user. E-mail authentication is always enabled, and no password is set, meaning the only way to authenticate the newly created user is through magic link.',
|
|
53
|
+
},
|
|
54
|
+
serverRead: {
|
|
55
|
+
tags: ["Users"],
|
|
56
|
+
summary: 'Get user',
|
|
57
|
+
description: 'Gets a user by user ID.',
|
|
58
|
+
},
|
|
59
|
+
serverUpdate: {
|
|
60
|
+
tags: ["Users"],
|
|
61
|
+
summary: 'Update user',
|
|
62
|
+
description: 'Updates a user. Only the values provided will be updated.',
|
|
63
|
+
},
|
|
64
|
+
serverDelete: {
|
|
65
|
+
tags: ["Users"],
|
|
66
|
+
summary: 'Delete user',
|
|
67
|
+
description: 'Deletes a user. Use this with caution.',
|
|
68
|
+
},
|
|
69
|
+
serverList: {
|
|
70
|
+
tags: ["Users"],
|
|
71
|
+
summary: 'List users',
|
|
72
|
+
description: 'Lists all the users in the project.',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
@@ -1,87 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KnownErrors } from "../known-errors";
|
|
2
|
+
import { AccessToken, InternalSession, RefreshToken } from "../sessions";
|
|
2
3
|
import { Result } from "../utils/results";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export type ServerUserUpdateJson = UserUpdateJson & {
|
|
10
|
-
serverMetadata?: ReadonlyJson;
|
|
11
|
-
primaryEmail?: string | null;
|
|
12
|
-
primaryEmailVerified?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export type ServerOrglikeCustomizableJson = Pick<ServerOrglikeJson, "displayName" | "profileImageUrl">;
|
|
15
|
-
export type ServerOrglikeJson = OrglikeJson & {};
|
|
16
|
-
export type ServerTeamCustomizableJson = ServerOrglikeCustomizableJson;
|
|
17
|
-
export type ServerTeamJson = ServerOrglikeJson;
|
|
18
|
-
export type ServerTeamMemberJson = TeamMemberJson & {
|
|
19
|
-
user: ServerUserJson;
|
|
20
|
-
};
|
|
21
|
-
export type ServerPermissionDefinitionCustomizableJson = {
|
|
22
|
-
readonly id: string;
|
|
23
|
-
readonly description?: string;
|
|
24
|
-
readonly scope: PermissionDefinitionScopeJson;
|
|
25
|
-
readonly containPermissionIds: string[];
|
|
26
|
-
};
|
|
27
|
-
export type ServerPermissionDefinitionJson = PermissionDefinitionJson & ServerPermissionDefinitionCustomizableJson & {
|
|
28
|
-
readonly __databaseUniqueId: string;
|
|
29
|
-
readonly scope: PermissionDefinitionScopeJson;
|
|
30
|
-
};
|
|
4
|
+
import { ClientInterfaceOptions, StackClientInterface } from "./clientInterface";
|
|
5
|
+
import { CurrentUserCrud } from "./crud/current-user";
|
|
6
|
+
import { TeamMembershipsCrud } from "./crud/team-memberships";
|
|
7
|
+
import { TeamPermissionsCrud } from "./crud/team-permissions";
|
|
8
|
+
import { TeamsCrud } from "./crud/teams";
|
|
9
|
+
import { UsersCrud } from "./crud/users";
|
|
31
10
|
export type ServerAuthApplicationOptions = (ClientInterfaceOptions & ({
|
|
32
11
|
readonly secretServerKey: string;
|
|
33
12
|
} | {
|
|
34
13
|
readonly projectOwnerSession: InternalSession;
|
|
35
14
|
}));
|
|
36
|
-
export declare const emailTemplateTypes: readonly ["EMAIL_VERIFICATION", "PASSWORD_RESET", "MAGIC_LINK"];
|
|
37
|
-
export type EmailTemplateType = typeof emailTemplateTypes[number];
|
|
38
15
|
export declare class StackServerInterface extends StackClientInterface {
|
|
39
16
|
options: ServerAuthApplicationOptions;
|
|
40
17
|
constructor(options: ServerAuthApplicationOptions);
|
|
41
18
|
protected sendServerRequest(path: string, options: RequestInit, session: InternalSession | null, requestType?: "server" | "admin"): Promise<Response & {
|
|
42
19
|
usedTokens: {
|
|
43
|
-
accessToken:
|
|
44
|
-
refreshToken:
|
|
20
|
+
accessToken: AccessToken;
|
|
21
|
+
refreshToken: RefreshToken | null;
|
|
45
22
|
} | null;
|
|
46
23
|
}>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
24
|
+
protected sendServerRequestAndCatchKnownError<E extends typeof KnownErrors[keyof KnownErrors]>(path: string, requestOptions: RequestInit, tokenStoreOrNull: InternalSession | null, errorsToCatch: readonly E[]): Promise<Result<Response & {
|
|
25
|
+
usedTokens: {
|
|
26
|
+
accessToken: AccessToken;
|
|
27
|
+
refreshToken: RefreshToken | null;
|
|
28
|
+
} | null;
|
|
29
|
+
}, InstanceType<E>>>;
|
|
30
|
+
getServerUserByToken(session: InternalSession): Promise<CurrentUserCrud['Server']['Read'] | null>;
|
|
31
|
+
getServerUserById(userId: string): Promise<Result<UsersCrud['Server']['Read']>>;
|
|
32
|
+
listServerCurrentUserTeamPermissions(options: {
|
|
50
33
|
teamId: string;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
listServerUsers(): Promise<ServerUserJson[]>;
|
|
60
|
-
listServerTeams(): Promise<ServerTeamJson[]>;
|
|
61
|
-
listServerTeamMembers(teamId: string): Promise<ServerTeamMemberJson[]>;
|
|
62
|
-
createServerTeam(data: ServerTeamCustomizableJson): Promise<ServerTeamJson>;
|
|
63
|
-
updateServerTeam(teamId: string, data: Partial<ServerTeamCustomizableJson>): Promise<void>;
|
|
34
|
+
recursive: boolean;
|
|
35
|
+
}, session: InternalSession): Promise<TeamPermissionsCrud['Server']['Read'][]>;
|
|
36
|
+
listServerCurrentUserTeams(session: InternalSession): Promise<TeamsCrud['Server']['Read'][]>;
|
|
37
|
+
listServerUsers(): Promise<UsersCrud['Server']['Read'][]>;
|
|
38
|
+
listServerTeams(): Promise<TeamsCrud['Server']['Read'][]>;
|
|
39
|
+
listServerTeamUsers(teamId: string): Promise<UsersCrud['Server']['Read'][]>;
|
|
40
|
+
createServerTeam(data: TeamsCrud['Server']['Create'], session?: InternalSession): Promise<TeamsCrud['Server']['Read']>;
|
|
41
|
+
updateServerTeam(teamId: string, data: TeamsCrud['Server']['Update']): Promise<TeamsCrud['Server']['Read']>;
|
|
64
42
|
deleteServerTeam(teamId: string): Promise<void>;
|
|
65
43
|
addServerUserToTeam(options: {
|
|
66
44
|
userId: string;
|
|
67
45
|
teamId: string;
|
|
68
|
-
}): Promise<
|
|
46
|
+
}): Promise<TeamMembershipsCrud['Server']['Read']>;
|
|
69
47
|
removeServerUserFromTeam(options: {
|
|
70
48
|
userId: string;
|
|
71
49
|
teamId: string;
|
|
72
50
|
}): Promise<void>;
|
|
73
|
-
|
|
51
|
+
updateServerUser(userId: string, update: UsersCrud['Server']['Update']): Promise<UsersCrud['Server']['Read']>;
|
|
74
52
|
listServerTeamMemberPermissions(options: {
|
|
75
53
|
teamId: string;
|
|
76
54
|
userId: string;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
revokeServerTeamUserPermission(teamId: string, userId: string, permissionId: string, type: 'global' | 'team'): Promise<void>;
|
|
55
|
+
recursive: boolean;
|
|
56
|
+
}): Promise<TeamPermissionsCrud['Server']['Read'][]>;
|
|
57
|
+
grantServerTeamUserPermission(teamId: string, userId: string, permissionId: string): Promise<void>;
|
|
58
|
+
revokeServerTeamUserPermission(teamId: string, userId: string, permissionId: string): Promise<void>;
|
|
82
59
|
deleteServerServerUser(userId: string): Promise<void>;
|
|
83
|
-
listEmailTemplates(): Promise<ListEmailTemplatesCrud['Server']['Read']>;
|
|
84
|
-
updateEmailTemplate(type: EmailTemplateType, data: EmailTemplateCrud['Server']['Update']): Promise<void>;
|
|
85
|
-
resetEmailTemplate(type: EmailTemplateType): Promise<void>;
|
|
86
|
-
createServerTeamForUser(userId: string, data: ServerTeamCustomizableJson, session: InternalSession): Promise<ServerTeamJson>;
|
|
87
60
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KnownErrors } from "../known-errors";
|
|
2
|
+
import { StackAssertionError } from "../utils/errors";
|
|
2
3
|
import { Result } from "../utils/results";
|
|
3
|
-
|
|
4
|
+
import { StackClientInterface } from "./clientInterface";
|
|
4
5
|
export class StackServerInterface extends StackClientInterface {
|
|
5
|
-
options;
|
|
6
6
|
constructor(options) {
|
|
7
7
|
super(options);
|
|
8
8
|
this.options = options;
|
|
@@ -16,107 +16,103 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
16
16
|
},
|
|
17
17
|
}, session, requestType);
|
|
18
18
|
}
|
|
19
|
+
async sendServerRequestAndCatchKnownError(path, requestOptions, tokenStoreOrNull, errorsToCatch) {
|
|
20
|
+
try {
|
|
21
|
+
return Result.ok(await this.sendServerRequest(path, requestOptions, tokenStoreOrNull));
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
for (const errorType of errorsToCatch) {
|
|
25
|
+
if (e instanceof errorType) {
|
|
26
|
+
return Result.error(e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
19
32
|
async getServerUserByToken(session) {
|
|
20
|
-
const
|
|
33
|
+
const responseOrError = await this.sendServerRequestAndCatchKnownError("/users/me", {}, session, [KnownErrors.CannotGetOwnUserWithoutUser]);
|
|
34
|
+
if (responseOrError.status === "error") {
|
|
35
|
+
if (responseOrError.error instanceof KnownErrors.CannotGetOwnUserWithoutUser) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new StackAssertionError("Unexpected uncaught error", { cause: responseOrError.error });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const response = responseOrError.data;
|
|
21
43
|
const user = await response.json();
|
|
22
44
|
if (!user)
|
|
23
|
-
|
|
24
|
-
return
|
|
45
|
+
throw new StackAssertionError("User endpoint returned null; this should never happen");
|
|
46
|
+
return user;
|
|
25
47
|
}
|
|
26
48
|
async getServerUserById(userId) {
|
|
27
|
-
const response = await this.sendServerRequest(`/users/${userId}
|
|
49
|
+
const response = await this.sendServerRequest(`/users/${userId}`, {}, null);
|
|
28
50
|
const user = await response.json();
|
|
29
51
|
if (!user)
|
|
30
52
|
return Result.error(new Error("Failed to get user"));
|
|
31
53
|
return Result.ok(user);
|
|
32
54
|
}
|
|
33
|
-
async
|
|
34
|
-
const response = await this.sendServerRequest(`/
|
|
35
|
-
const
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
async listServerUserTeams(session) {
|
|
39
|
-
const response = await this.sendServerRequest("/current-user/teams?server=true", {}, session);
|
|
40
|
-
const teams = await response.json();
|
|
41
|
-
return teams;
|
|
42
|
-
}
|
|
43
|
-
async listPermissionDefinitions() {
|
|
44
|
-
const response = await this.sendServerRequest(`/permission-definitions?server=true`, {}, null);
|
|
45
|
-
return await response.json();
|
|
46
|
-
}
|
|
47
|
-
async createPermissionDefinition(data) {
|
|
48
|
-
const response = await this.sendServerRequest("/permission-definitions?server=true", {
|
|
49
|
-
method: "POST",
|
|
50
|
-
headers: {
|
|
51
|
-
"content-type": "application/json",
|
|
52
|
-
},
|
|
53
|
-
body: JSON.stringify({
|
|
54
|
-
...data,
|
|
55
|
-
scope: {
|
|
56
|
-
type: "any-team",
|
|
57
|
-
}
|
|
58
|
-
}),
|
|
59
|
-
}, null);
|
|
60
|
-
return await response.json();
|
|
61
|
-
}
|
|
62
|
-
async updatePermissionDefinition(permissionId, data) {
|
|
63
|
-
await this.sendServerRequest(`/permission-definitions/${permissionId}?server=true`, {
|
|
64
|
-
method: "PUT",
|
|
65
|
-
headers: {
|
|
66
|
-
"content-type": "application/json",
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify(data),
|
|
69
|
-
}, null);
|
|
55
|
+
async listServerCurrentUserTeamPermissions(options, session) {
|
|
56
|
+
const response = await this.sendServerRequest(`/team-permissions?team_id=${options.teamId}&user_id=me&recursive=${options.recursive}`, {}, session);
|
|
57
|
+
const result = await response.json();
|
|
58
|
+
return result.items;
|
|
70
59
|
}
|
|
71
|
-
async
|
|
72
|
-
await this.sendServerRequest(
|
|
60
|
+
async listServerCurrentUserTeams(session) {
|
|
61
|
+
const response = await this.sendServerRequest("/teams?user_id=me", {}, session);
|
|
62
|
+
const result = await response.json();
|
|
63
|
+
return result.items;
|
|
73
64
|
}
|
|
74
65
|
async listServerUsers() {
|
|
75
|
-
const response = await this.sendServerRequest("/users
|
|
76
|
-
|
|
66
|
+
const response = await this.sendServerRequest("/users", {}, null);
|
|
67
|
+
const result = await response.json();
|
|
68
|
+
return result.items;
|
|
77
69
|
}
|
|
78
70
|
async listServerTeams() {
|
|
79
|
-
const response = await this.sendServerRequest("/teams
|
|
80
|
-
const
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
async
|
|
84
|
-
const response = await this.sendServerRequest(`/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
const response = await this.sendServerRequest("/teams", {}, null);
|
|
72
|
+
const result = await response.json();
|
|
73
|
+
return result.items;
|
|
74
|
+
}
|
|
75
|
+
async listServerTeamUsers(teamId) {
|
|
76
|
+
const response = await this.sendServerRequest(`/users?team_id=${teamId}`, {}, null);
|
|
77
|
+
const result = await response.json();
|
|
78
|
+
return result.items;
|
|
79
|
+
}
|
|
80
|
+
/* when passing a session, the user will be added to the team */
|
|
81
|
+
async createServerTeam(data, session) {
|
|
82
|
+
const response = await this.sendServerRequest("/teams", {
|
|
89
83
|
method: "POST",
|
|
90
84
|
headers: {
|
|
91
85
|
"content-type": "application/json",
|
|
92
86
|
},
|
|
93
87
|
body: JSON.stringify(data),
|
|
94
|
-
}, null);
|
|
88
|
+
}, session || null);
|
|
95
89
|
return await response.json();
|
|
96
90
|
}
|
|
97
91
|
async updateServerTeam(teamId, data) {
|
|
98
|
-
await this.sendServerRequest(`/teams/${teamId}
|
|
99
|
-
method: "
|
|
92
|
+
const response = await this.sendServerRequest(`/teams/${teamId}`, {
|
|
93
|
+
method: "PATCH",
|
|
100
94
|
headers: {
|
|
101
95
|
"content-type": "application/json",
|
|
102
96
|
},
|
|
103
97
|
body: JSON.stringify(data),
|
|
104
98
|
}, null);
|
|
99
|
+
return await response.json();
|
|
105
100
|
}
|
|
106
101
|
async deleteServerTeam(teamId) {
|
|
107
|
-
await this.sendServerRequest(`/teams/${teamId}
|
|
102
|
+
await this.sendServerRequest(`/teams/${teamId}`, { method: "DELETE" }, null);
|
|
108
103
|
}
|
|
109
104
|
async addServerUserToTeam(options) {
|
|
110
|
-
await this.sendServerRequest(`/
|
|
105
|
+
const response = await this.sendServerRequest(`/team-memberships/${options.teamId}/${options.userId}`, {
|
|
111
106
|
method: "POST",
|
|
112
107
|
headers: {
|
|
113
108
|
"content-type": "application/json",
|
|
114
109
|
},
|
|
115
110
|
body: JSON.stringify({}),
|
|
116
111
|
}, null);
|
|
112
|
+
return await response.json();
|
|
117
113
|
}
|
|
118
114
|
async removeServerUserFromTeam(options) {
|
|
119
|
-
await this.sendServerRequest(`/
|
|
115
|
+
await this.sendServerRequest(`/team-memberships/${options.teamId}/${options.userId}`, {
|
|
120
116
|
method: "DELETE",
|
|
121
117
|
headers: {
|
|
122
118
|
"content-type": "application/json",
|
|
@@ -124,39 +120,41 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
124
120
|
body: JSON.stringify({}),
|
|
125
121
|
}, null);
|
|
126
122
|
}
|
|
127
|
-
async
|
|
128
|
-
await this.sendServerRequest(`/users/${userId}
|
|
129
|
-
method: "
|
|
123
|
+
async updateServerUser(userId, update) {
|
|
124
|
+
const response = await this.sendServerRequest(`/users/${userId}`, {
|
|
125
|
+
method: "PATCH",
|
|
130
126
|
headers: {
|
|
131
127
|
"content-type": "application/json",
|
|
132
128
|
},
|
|
133
129
|
body: JSON.stringify(update),
|
|
134
130
|
}, null);
|
|
131
|
+
return await response.json();
|
|
135
132
|
}
|
|
136
133
|
async listServerTeamMemberPermissions(options) {
|
|
137
|
-
const response = await this.sendServerRequest(`/
|
|
138
|
-
|
|
134
|
+
const response = await this.sendServerRequest(`/team-permissions?team_id=${options.teamId}&user_id=${options.userId}&recursive=${options.recursive}`, {}, null);
|
|
135
|
+
const result = await response.json();
|
|
136
|
+
return result.items;
|
|
139
137
|
}
|
|
140
|
-
async grantServerTeamUserPermission(teamId, userId, permissionId
|
|
141
|
-
await this.sendServerRequest(`/
|
|
138
|
+
async grantServerTeamUserPermission(teamId, userId, permissionId) {
|
|
139
|
+
await this.sendServerRequest(`/team-permissions/${teamId}/${userId}/${permissionId}`, {
|
|
142
140
|
method: "POST",
|
|
143
141
|
headers: {
|
|
144
142
|
"content-type": "application/json",
|
|
145
143
|
},
|
|
146
|
-
body: JSON.stringify({
|
|
144
|
+
body: JSON.stringify({}),
|
|
147
145
|
}, null);
|
|
148
146
|
}
|
|
149
|
-
async revokeServerTeamUserPermission(teamId, userId, permissionId
|
|
150
|
-
await this.sendServerRequest(`/
|
|
147
|
+
async revokeServerTeamUserPermission(teamId, userId, permissionId) {
|
|
148
|
+
await this.sendServerRequest(`/team-permissions/${teamId}/${userId}/${permissionId}`, {
|
|
151
149
|
method: "DELETE",
|
|
152
150
|
headers: {
|
|
153
151
|
"content-type": "application/json",
|
|
154
152
|
},
|
|
155
|
-
body: JSON.stringify({
|
|
153
|
+
body: JSON.stringify({}),
|
|
156
154
|
}, null);
|
|
157
155
|
}
|
|
158
156
|
async deleteServerServerUser(userId) {
|
|
159
|
-
await this.sendServerRequest(`/users/${userId}
|
|
157
|
+
await this.sendServerRequest(`/users/${userId}`, {
|
|
160
158
|
method: "DELETE",
|
|
161
159
|
headers: {
|
|
162
160
|
"content-type": "application/json",
|
|
@@ -164,30 +162,4 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
164
162
|
body: JSON.stringify({}),
|
|
165
163
|
}, null);
|
|
166
164
|
}
|
|
167
|
-
async listEmailTemplates() {
|
|
168
|
-
const response = await this.sendServerRequest(`/email-templates?server=true`, {}, null);
|
|
169
|
-
return await response.json();
|
|
170
|
-
}
|
|
171
|
-
async updateEmailTemplate(type, data) {
|
|
172
|
-
await this.sendServerRequest(`/email-templates/${type}?server=true`, {
|
|
173
|
-
method: "PUT",
|
|
174
|
-
headers: {
|
|
175
|
-
"content-type": "application/json",
|
|
176
|
-
},
|
|
177
|
-
body: JSON.stringify(data),
|
|
178
|
-
}, null);
|
|
179
|
-
}
|
|
180
|
-
async resetEmailTemplate(type) {
|
|
181
|
-
await this.sendServerRequest(`/email-templates/${type}?server=true`, { method: "DELETE" }, null);
|
|
182
|
-
}
|
|
183
|
-
async createServerTeamForUser(userId, data, session) {
|
|
184
|
-
const response = await this.sendClientRequest(`/users/${userId}/teams?server=true`, {
|
|
185
|
-
method: "POST",
|
|
186
|
-
headers: {
|
|
187
|
-
"content-type": "application/json",
|
|
188
|
-
},
|
|
189
|
-
body: JSON.stringify(data),
|
|
190
|
-
}, session);
|
|
191
|
-
return await response.json();
|
|
192
|
-
}
|
|
193
165
|
}
|
package/dist/known-errors.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PermissionDefinitionScopeJson } from "./interface/clientInterface";
|
|
2
1
|
import { StatusError } from "./utils/errors";
|
|
3
2
|
import { Json } from "./utils/json";
|
|
4
3
|
export type KnownErrorJson = {
|
|
@@ -24,6 +23,7 @@ export declare abstract class KnownError extends StatusError {
|
|
|
24
23
|
constructor(statusCode: number, humanReadableMessage: string, details?: Json | undefined);
|
|
25
24
|
getBody(): Uint8Array;
|
|
26
25
|
getHeaders(): Record<string, string[]>;
|
|
26
|
+
toDescriptiveJson(): Json;
|
|
27
27
|
get errorCode(): string;
|
|
28
28
|
static constructorArgsFromJson(json: KnownErrorJson): ConstructorParameters<typeof KnownError>;
|
|
29
29
|
static fromJson(json: KnownErrorJson): KnownError;
|
|
@@ -49,10 +49,10 @@ export declare const KnownErrors: {
|
|
|
49
49
|
UnsupportedError: KnownErrorConstructor<KnownError & KnownErrorBrand<"UNSUPPORTED_ERROR">, [originalErrorCode: string]> & {
|
|
50
50
|
errorCode: "UNSUPPORTED_ERROR";
|
|
51
51
|
};
|
|
52
|
-
BodyParsingError: KnownErrorConstructor<KnownError & KnownErrorBrand<"BODY_PARSING_ERROR">, [string]> & {
|
|
52
|
+
BodyParsingError: KnownErrorConstructor<KnownError & KnownErrorBrand<"BODY_PARSING_ERROR">, [message: string]> & {
|
|
53
53
|
errorCode: "BODY_PARSING_ERROR";
|
|
54
54
|
};
|
|
55
|
-
SchemaError: KnownErrorConstructor<KnownError & KnownErrorBrand<"SCHEMA_ERROR">, [string]> & {
|
|
55
|
+
SchemaError: KnownErrorConstructor<KnownError & KnownErrorBrand<"SCHEMA_ERROR">, [message: string]> & {
|
|
56
56
|
errorCode: "SCHEMA_ERROR";
|
|
57
57
|
};
|
|
58
58
|
AllOverloadsFailed: KnownErrorConstructor<KnownError & KnownErrorBrand<"ALL_OVERLOADS_FAILED">, [overloadErrors: Json[]]> & {
|
|
@@ -88,12 +88,12 @@ export declare const KnownErrors: {
|
|
|
88
88
|
};
|
|
89
89
|
InvalidAccessType: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & {
|
|
90
90
|
constructorArgs: [statusCode: number, humanReadableMessage: string, details?: Json | undefined];
|
|
91
|
-
} & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ACCESS_TYPE">, [
|
|
91
|
+
} & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ACCESS_TYPE">, [accessType: string]> & {
|
|
92
92
|
errorCode: "INVALID_ACCESS_TYPE";
|
|
93
93
|
};
|
|
94
94
|
AccessTypeWithoutProjectId: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & {
|
|
95
95
|
constructorArgs: [statusCode: number, humanReadableMessage: string, details?: Json | undefined];
|
|
96
|
-
} & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"ACCESS_TYPE_WITHOUT_PROJECT_ID">, [
|
|
96
|
+
} & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"ACCESS_TYPE_WITHOUT_PROJECT_ID">, [accessType: "client" | "server" | "admin"]> & {
|
|
97
97
|
errorCode: "ACCESS_TYPE_WITHOUT_PROJECT_ID";
|
|
98
98
|
};
|
|
99
99
|
AccessTypeRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & {
|
|
@@ -217,28 +217,18 @@ export declare const KnownErrors: {
|
|
|
217
217
|
} & KnownErrorBrand<"INVALID_SESSION_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ACCESS_TOKEN"> & KnownErrorBrand<"INVALID_PROJECT_FOR_ACCESS_TOKEN">, []> & {
|
|
218
218
|
errorCode: "INVALID_PROJECT_FOR_ACCESS_TOKEN";
|
|
219
219
|
};
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
} & KnownErrorBrand<"INVALID_SESSION_AUTHENTICATION"> & KnownErrorBrand<"SESSION_USER_EMAIL_NOT_VERIFIED">, []> & {
|
|
223
|
-
errorCode: "SESSION_USER_EMAIL_NOT_VERIFIED";
|
|
224
|
-
};
|
|
225
|
-
SessionAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR"> & {
|
|
226
|
-
constructorArgs: [statusCode: number, humanReadableMessage: string, details?: Json | undefined];
|
|
227
|
-
} & KnownErrorBrand<"SESSION_AUTHENTICATION_REQUIRED">, []> & {
|
|
228
|
-
errorCode: "SESSION_AUTHENTICATION_REQUIRED";
|
|
229
|
-
};
|
|
230
|
-
RefreshTokenError: KnownErrorConstructor<KnownError & KnownErrorBrand<"INVALID_REFRESH_TOKEN">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
|
|
231
|
-
errorCode: "INVALID_REFRESH_TOKEN";
|
|
220
|
+
RefreshTokenError: KnownErrorConstructor<KnownError & KnownErrorBrand<"REFRESH_TOKEN_ERROR">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
|
|
221
|
+
errorCode: "REFRESH_TOKEN_ERROR";
|
|
232
222
|
};
|
|
233
|
-
ProviderRejected: KnownErrorConstructor<KnownError & KnownErrorBrand<"
|
|
223
|
+
ProviderRejected: KnownErrorConstructor<KnownError & KnownErrorBrand<"REFRESH_TOKEN_ERROR"> & {
|
|
234
224
|
constructorArgs: [statusCode: number, humanReadableMessage: string, details?: Json | undefined];
|
|
235
225
|
} & KnownErrorBrand<"PROVIDER_REJECTED">, []> & {
|
|
236
226
|
errorCode: "PROVIDER_REJECTED";
|
|
237
227
|
};
|
|
238
|
-
|
|
228
|
+
RefreshTokenNotFoundOrExpired: KnownErrorConstructor<KnownError & KnownErrorBrand<"REFRESH_TOKEN_ERROR"> & {
|
|
239
229
|
constructorArgs: [statusCode: number, humanReadableMessage: string, details?: Json | undefined];
|
|
240
|
-
} & KnownErrorBrand<"
|
|
241
|
-
errorCode: "
|
|
230
|
+
} & KnownErrorBrand<"REFRESH_TOKEN_NOT_FOUND_OR_EXPIRED">, []> & {
|
|
231
|
+
errorCode: "REFRESH_TOKEN_NOT_FOUND_OR_EXPIRED";
|
|
242
232
|
};
|
|
243
233
|
UserEmailAlreadyExists: KnownErrorConstructor<KnownError & KnownErrorBrand<"USER_EMAIL_ALREADY_EXISTS">, []> & {
|
|
244
234
|
errorCode: "USER_EMAIL_ALREADY_EXISTS";
|
|
@@ -249,9 +239,12 @@ export declare const KnownErrors: {
|
|
|
249
239
|
ApiKeyNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"API_KEY_NOT_FOUND">, []> & {
|
|
250
240
|
errorCode: "API_KEY_NOT_FOUND";
|
|
251
241
|
};
|
|
252
|
-
ProjectNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_NOT_FOUND">, []> & {
|
|
242
|
+
ProjectNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_NOT_FOUND">, [projectId: string]> & {
|
|
253
243
|
errorCode: "PROJECT_NOT_FOUND";
|
|
254
244
|
};
|
|
245
|
+
PasswordAuthenticationNotEnabled: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_AUTHENTICATION_NOT_ENABLED">, []> & {
|
|
246
|
+
errorCode: "PASSWORD_AUTHENTICATION_NOT_ENABLED";
|
|
247
|
+
};
|
|
255
248
|
EmailPasswordMismatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_PASSWORD_MISMATCH">, []> & {
|
|
256
249
|
errorCode: "EMAIL_PASSWORD_MISMATCH";
|
|
257
250
|
};
|
|
@@ -271,6 +264,9 @@ export declare const KnownErrors: {
|
|
|
271
264
|
} & KnownErrorBrand<"PASSWORD_TOO_LONG">, [maxLength: number]> & {
|
|
272
265
|
errorCode: "PASSWORD_TOO_LONG";
|
|
273
266
|
};
|
|
267
|
+
UserDoesNotHavePassword: KnownErrorConstructor<KnownError & KnownErrorBrand<"USER_DOES_NOT_HAVE_PASSWORD">, []> & {
|
|
268
|
+
errorCode: "USER_DOES_NOT_HAVE_PASSWORD";
|
|
269
|
+
};
|
|
274
270
|
VerificationCodeError: KnownErrorConstructor<KnownError & KnownErrorBrand<"VERIFICATION_ERROR">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
|
|
275
271
|
errorCode: "VERIFICATION_ERROR";
|
|
276
272
|
};
|
|
@@ -289,21 +285,30 @@ export declare const KnownErrors: {
|
|
|
289
285
|
} & KnownErrorBrand<"VERIFICATION_CODE_ALREADY_USED">, []> & {
|
|
290
286
|
errorCode: "VERIFICATION_CODE_ALREADY_USED";
|
|
291
287
|
};
|
|
292
|
-
|
|
293
|
-
errorCode: "
|
|
288
|
+
PasswordConfirmationMismatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_CONFIRMATION_MISMATCH">, []> & {
|
|
289
|
+
errorCode: "PASSWORD_CONFIRMATION_MISMATCH";
|
|
294
290
|
};
|
|
295
291
|
EmailAlreadyVerified: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_ALREADY_VERIFIED">, []> & {
|
|
296
292
|
errorCode: "EMAIL_ALREADY_VERIFIED";
|
|
297
293
|
};
|
|
294
|
+
EmailNotAssociatedWithUser: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_NOT_ASSOCIATED_WITH_USER">, []> & {
|
|
295
|
+
errorCode: "EMAIL_NOT_ASSOCIATED_WITH_USER";
|
|
296
|
+
};
|
|
297
|
+
EmailIsNotPrimaryEmail: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_IS_NOT_PRIMARY_EMAIL">, [email: string, primaryEmail: string | null]> & {
|
|
298
|
+
errorCode: "EMAIL_IS_NOT_PRIMARY_EMAIL";
|
|
299
|
+
};
|
|
298
300
|
PermissionNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"PERMISSION_NOT_FOUND">, [permissionId: string]> & {
|
|
299
301
|
errorCode: "PERMISSION_NOT_FOUND";
|
|
300
302
|
};
|
|
301
|
-
|
|
302
|
-
errorCode: "
|
|
303
|
+
ContainedPermissionNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"CONTAINED_PERMISSION_NOT_FOUND">, [permissionId: string]> & {
|
|
304
|
+
errorCode: "CONTAINED_PERMISSION_NOT_FOUND";
|
|
303
305
|
};
|
|
304
306
|
TeamNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"TEAM_NOT_FOUND">, [teamId: string]> & {
|
|
305
307
|
errorCode: "TEAM_NOT_FOUND";
|
|
306
308
|
};
|
|
309
|
+
TeamMembershipNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"TEAM_MEMBERSHIP_NOT_FOUND">, [teamId: string, userId: string]> & {
|
|
310
|
+
errorCode: "TEAM_MEMBERSHIP_NOT_FOUND";
|
|
311
|
+
};
|
|
307
312
|
EmailTemplateAlreadyExists: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_TEMPLATE_ALREADY_EXISTS">, []> & {
|
|
308
313
|
errorCode: "EMAIL_TEMPLATE_ALREADY_EXISTS";
|
|
309
314
|
};
|
|
@@ -322,11 +327,23 @@ export declare const KnownErrors: {
|
|
|
322
327
|
OAuthAccessTokenNotAvailableWithSharedOAuthKeys: KnownErrorConstructor<KnownError & KnownErrorBrand<"OAUTH_ACCESS_TOKEN_NOT_AVAILABLE_WITH_SHARED_OAUTH_KEYS">, []> & {
|
|
323
328
|
errorCode: "OAUTH_ACCESS_TOKEN_NOT_AVAILABLE_WITH_SHARED_OAUTH_KEYS";
|
|
324
329
|
};
|
|
330
|
+
InvalidOAuthClientIdOrSecret: KnownErrorConstructor<KnownError & KnownErrorBrand<"INVALID_OAUTH_CLIENT_ID_OR_SECRET">, [clientId?: string | undefined]> & {
|
|
331
|
+
errorCode: "INVALID_OAUTH_CLIENT_ID_OR_SECRET";
|
|
332
|
+
};
|
|
333
|
+
InvalidScope: KnownErrorConstructor<KnownError & KnownErrorBrand<"INVALID_SCOPE">, [scope: string]> & {
|
|
334
|
+
errorCode: "INVALID_SCOPE";
|
|
335
|
+
};
|
|
325
336
|
UserAlreadyConnectedToAnotherOAuthConnection: KnownErrorConstructor<KnownError & KnownErrorBrand<"USER_ALREADY_CONNECTED_TO_ANOTHER_OAUTH_CONNECTION">, []> & {
|
|
326
337
|
errorCode: "USER_ALREADY_CONNECTED_TO_ANOTHER_OAUTH_CONNECTION";
|
|
327
338
|
};
|
|
328
339
|
OuterOAuthTimeout: KnownErrorConstructor<KnownError & KnownErrorBrand<"OUTER_OAUTH_TIMEOUT">, []> & {
|
|
329
340
|
errorCode: "OUTER_OAUTH_TIMEOUT";
|
|
330
341
|
};
|
|
342
|
+
OAuthProviderNotFoundOrNotEnabled: KnownErrorConstructor<KnownError & KnownErrorBrand<"OAUTH_PROVIDER_NOT_FOUND_OR_NOT_ENABLED">, []> & {
|
|
343
|
+
errorCode: "OAUTH_PROVIDER_NOT_FOUND_OR_NOT_ENABLED";
|
|
344
|
+
};
|
|
345
|
+
UserAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"USER_AUTHENTICATION_REQUIRED">, []> & {
|
|
346
|
+
errorCode: "USER_AUTHENTICATION_REQUIRED";
|
|
347
|
+
};
|
|
331
348
|
};
|
|
332
349
|
export {};
|