@stackframe/stack-shared 2.5.3 → 2.5.5
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 +14 -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 -21
- package/dist/interface/clientInterface.d.ts +21 -133
- package/dist/interface/clientInterface.js +92 -118
- 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 +458 -0
- package/dist/interface/crud/projects.js +112 -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 -101
- package/dist/known-errors.d.ts +43 -26
- package/dist/known-errors.js +132 -85
- package/dist/schema-fields.d.ts +53 -4
- package/dist/schema-fields.js +156 -25
- package/dist/sessions.d.ts +1 -0
- package/dist/sessions.js +13 -3
- 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 +17 -4
- package/dist/utils/objects.d.ts +4 -1
- package/dist/utils/objects.js +16 -8
- package/dist/utils/promises.js +6 -1
- 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/strings.js +3 -3
- package/dist/utils/urls.d.ts +1 -0
- package/dist/utils/urls.js +8 -0
- 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,6 +1,7 @@
|
|
|
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
6
|
constructor(options) {
|
|
6
7
|
super(options);
|
|
@@ -15,107 +16,103 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
15
16
|
},
|
|
16
17
|
}, session, requestType);
|
|
17
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
|
+
}
|
|
18
32
|
async getServerUserByToken(session) {
|
|
19
|
-
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;
|
|
20
43
|
const user = await response.json();
|
|
21
44
|
if (!user)
|
|
22
|
-
|
|
23
|
-
return
|
|
45
|
+
throw new StackAssertionError("User endpoint returned null; this should never happen");
|
|
46
|
+
return user;
|
|
24
47
|
}
|
|
25
48
|
async getServerUserById(userId) {
|
|
26
|
-
const response = await this.sendServerRequest(`/users/${userId}
|
|
49
|
+
const response = await this.sendServerRequest(`/users/${userId}`, {}, null);
|
|
27
50
|
const user = await response.json();
|
|
28
51
|
if (!user)
|
|
29
52
|
return Result.error(new Error("Failed to get user"));
|
|
30
53
|
return Result.ok(user);
|
|
31
54
|
}
|
|
32
|
-
async
|
|
33
|
-
const response = await this.sendServerRequest(`/
|
|
34
|
-
const
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
async listServerUserTeams(session) {
|
|
38
|
-
const response = await this.sendServerRequest("/current-user/teams?server=true", {}, session);
|
|
39
|
-
const teams = await response.json();
|
|
40
|
-
return teams;
|
|
41
|
-
}
|
|
42
|
-
async listPermissionDefinitions() {
|
|
43
|
-
const response = await this.sendServerRequest(`/permission-definitions?server=true`, {}, null);
|
|
44
|
-
return await response.json();
|
|
45
|
-
}
|
|
46
|
-
async createPermissionDefinition(data) {
|
|
47
|
-
const response = await this.sendServerRequest("/permission-definitions?server=true", {
|
|
48
|
-
method: "POST",
|
|
49
|
-
headers: {
|
|
50
|
-
"content-type": "application/json",
|
|
51
|
-
},
|
|
52
|
-
body: JSON.stringify({
|
|
53
|
-
...data,
|
|
54
|
-
scope: {
|
|
55
|
-
type: "any-team",
|
|
56
|
-
}
|
|
57
|
-
}),
|
|
58
|
-
}, null);
|
|
59
|
-
return await response.json();
|
|
60
|
-
}
|
|
61
|
-
async updatePermissionDefinition(permissionId, data) {
|
|
62
|
-
await this.sendServerRequest(`/permission-definitions/${permissionId}?server=true`, {
|
|
63
|
-
method: "PUT",
|
|
64
|
-
headers: {
|
|
65
|
-
"content-type": "application/json",
|
|
66
|
-
},
|
|
67
|
-
body: JSON.stringify(data),
|
|
68
|
-
}, 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;
|
|
69
59
|
}
|
|
70
|
-
async
|
|
71
|
-
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;
|
|
72
64
|
}
|
|
73
65
|
async listServerUsers() {
|
|
74
|
-
const response = await this.sendServerRequest("/users
|
|
75
|
-
|
|
66
|
+
const response = await this.sendServerRequest("/users", {}, null);
|
|
67
|
+
const result = await response.json();
|
|
68
|
+
return result.items;
|
|
76
69
|
}
|
|
77
70
|
async listServerTeams() {
|
|
78
|
-
const response = await this.sendServerRequest("/teams
|
|
79
|
-
const
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
async
|
|
83
|
-
const response = await this.sendServerRequest(`/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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", {
|
|
88
83
|
method: "POST",
|
|
89
84
|
headers: {
|
|
90
85
|
"content-type": "application/json",
|
|
91
86
|
},
|
|
92
87
|
body: JSON.stringify(data),
|
|
93
|
-
}, null);
|
|
88
|
+
}, session || null);
|
|
94
89
|
return await response.json();
|
|
95
90
|
}
|
|
96
91
|
async updateServerTeam(teamId, data) {
|
|
97
|
-
await this.sendServerRequest(`/teams/${teamId}
|
|
98
|
-
method: "
|
|
92
|
+
const response = await this.sendServerRequest(`/teams/${teamId}`, {
|
|
93
|
+
method: "PATCH",
|
|
99
94
|
headers: {
|
|
100
95
|
"content-type": "application/json",
|
|
101
96
|
},
|
|
102
97
|
body: JSON.stringify(data),
|
|
103
98
|
}, null);
|
|
99
|
+
return await response.json();
|
|
104
100
|
}
|
|
105
101
|
async deleteServerTeam(teamId) {
|
|
106
|
-
await this.sendServerRequest(`/teams/${teamId}
|
|
102
|
+
await this.sendServerRequest(`/teams/${teamId}`, { method: "DELETE" }, null);
|
|
107
103
|
}
|
|
108
104
|
async addServerUserToTeam(options) {
|
|
109
|
-
await this.sendServerRequest(`/
|
|
105
|
+
const response = await this.sendServerRequest(`/team-memberships/${options.teamId}/${options.userId}`, {
|
|
110
106
|
method: "POST",
|
|
111
107
|
headers: {
|
|
112
108
|
"content-type": "application/json",
|
|
113
109
|
},
|
|
114
110
|
body: JSON.stringify({}),
|
|
115
111
|
}, null);
|
|
112
|
+
return await response.json();
|
|
116
113
|
}
|
|
117
114
|
async removeServerUserFromTeam(options) {
|
|
118
|
-
await this.sendServerRequest(`/
|
|
115
|
+
await this.sendServerRequest(`/team-memberships/${options.teamId}/${options.userId}`, {
|
|
119
116
|
method: "DELETE",
|
|
120
117
|
headers: {
|
|
121
118
|
"content-type": "application/json",
|
|
@@ -123,39 +120,41 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
123
120
|
body: JSON.stringify({}),
|
|
124
121
|
}, null);
|
|
125
122
|
}
|
|
126
|
-
async
|
|
127
|
-
await this.sendServerRequest(`/users/${userId}
|
|
128
|
-
method: "
|
|
123
|
+
async updateServerUser(userId, update) {
|
|
124
|
+
const response = await this.sendServerRequest(`/users/${userId}`, {
|
|
125
|
+
method: "PATCH",
|
|
129
126
|
headers: {
|
|
130
127
|
"content-type": "application/json",
|
|
131
128
|
},
|
|
132
129
|
body: JSON.stringify(update),
|
|
133
130
|
}, null);
|
|
131
|
+
return await response.json();
|
|
134
132
|
}
|
|
135
133
|
async listServerTeamMemberPermissions(options) {
|
|
136
|
-
const response = await this.sendServerRequest(`/
|
|
137
|
-
|
|
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;
|
|
138
137
|
}
|
|
139
|
-
async grantServerTeamUserPermission(teamId, userId, permissionId
|
|
140
|
-
await this.sendServerRequest(`/
|
|
138
|
+
async grantServerTeamUserPermission(teamId, userId, permissionId) {
|
|
139
|
+
await this.sendServerRequest(`/team-permissions/${teamId}/${userId}/${permissionId}`, {
|
|
141
140
|
method: "POST",
|
|
142
141
|
headers: {
|
|
143
142
|
"content-type": "application/json",
|
|
144
143
|
},
|
|
145
|
-
body: JSON.stringify({
|
|
144
|
+
body: JSON.stringify({}),
|
|
146
145
|
}, null);
|
|
147
146
|
}
|
|
148
|
-
async revokeServerTeamUserPermission(teamId, userId, permissionId
|
|
149
|
-
await this.sendServerRequest(`/
|
|
147
|
+
async revokeServerTeamUserPermission(teamId, userId, permissionId) {
|
|
148
|
+
await this.sendServerRequest(`/team-permissions/${teamId}/${userId}/${permissionId}`, {
|
|
150
149
|
method: "DELETE",
|
|
151
150
|
headers: {
|
|
152
151
|
"content-type": "application/json",
|
|
153
152
|
},
|
|
154
|
-
body: JSON.stringify({
|
|
153
|
+
body: JSON.stringify({}),
|
|
155
154
|
}, null);
|
|
156
155
|
}
|
|
157
156
|
async deleteServerServerUser(userId) {
|
|
158
|
-
await this.sendServerRequest(`/users/${userId}
|
|
157
|
+
await this.sendServerRequest(`/users/${userId}`, {
|
|
159
158
|
method: "DELETE",
|
|
160
159
|
headers: {
|
|
161
160
|
"content-type": "application/json",
|
|
@@ -163,30 +162,4 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
163
162
|
body: JSON.stringify({}),
|
|
164
163
|
}, null);
|
|
165
164
|
}
|
|
166
|
-
async listEmailTemplates() {
|
|
167
|
-
const response = await this.sendServerRequest(`/email-templates?server=true`, {}, null);
|
|
168
|
-
return await response.json();
|
|
169
|
-
}
|
|
170
|
-
async updateEmailTemplate(type, data) {
|
|
171
|
-
await this.sendServerRequest(`/email-templates/${type}?server=true`, {
|
|
172
|
-
method: "PUT",
|
|
173
|
-
headers: {
|
|
174
|
-
"content-type": "application/json",
|
|
175
|
-
},
|
|
176
|
-
body: JSON.stringify(data),
|
|
177
|
-
}, null);
|
|
178
|
-
}
|
|
179
|
-
async resetEmailTemplate(type) {
|
|
180
|
-
await this.sendServerRequest(`/email-templates/${type}?server=true`, { method: "DELETE" }, null);
|
|
181
|
-
}
|
|
182
|
-
async createServerTeamForUser(userId, data, session) {
|
|
183
|
-
const response = await this.sendClientRequest(`/users/${userId}/teams?server=true`, {
|
|
184
|
-
method: "POST",
|
|
185
|
-
headers: {
|
|
186
|
-
"content-type": "application/json",
|
|
187
|
-
},
|
|
188
|
-
body: JSON.stringify(data),
|
|
189
|
-
}, session);
|
|
190
|
-
return await response.json();
|
|
191
|
-
}
|
|
192
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 {};
|