@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @stackframe/stack-shared
|
|
2
2
|
|
|
3
|
+
## 2.5.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Backend rework
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @stackframe/stack-sc@2.5.4
|
|
10
|
+
|
|
11
|
+
## 2.5.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Bugfixes
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @stackframe/stack-sc@2.5.3
|
|
18
|
+
|
|
3
19
|
## 2.5.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/crud.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import * as yup from 'yup';
|
|
|
2
2
|
import { NullishCoalesce } from './utils/types';
|
|
3
3
|
export type AccessType = "client" | "server" | "admin";
|
|
4
4
|
export type CrudOperation = "create" | "read" | "update" | "delete";
|
|
5
|
+
export type CrudlOperation = "create" | "read" | "update" | "delete" | "list";
|
|
5
6
|
export type AccessTypeXCrudOperation = `${AccessType}${Capitalize<CrudOperation>}`;
|
|
7
|
+
export type AccessTypeXCrudlOperation = `${AccessType}${Capitalize<CrudlOperation>}`;
|
|
6
8
|
declare module 'yup' {
|
|
7
9
|
interface CustomSchemaMetadata {
|
|
8
10
|
openapiField?: {
|
|
@@ -22,7 +24,7 @@ export type EndpointDocumentation = ({
|
|
|
22
24
|
} & Partial<ShownEndpointDocumentation>) | ({
|
|
23
25
|
hidden?: boolean;
|
|
24
26
|
} & ShownEndpointDocumentation);
|
|
25
|
-
type InnerCrudSchema<CreateSchema extends yup.
|
|
27
|
+
type InnerCrudSchema<CreateSchema extends yup.AnySchema | undefined = yup.AnySchema | undefined, ReadSchema extends yup.AnySchema | undefined = yup.AnySchema | undefined, UpdateSchema extends yup.AnySchema | undefined = yup.AnySchema | undefined, DeleteSchema extends yup.AnySchema | undefined = yup.AnySchema | undefined> = {
|
|
26
28
|
createSchema: CreateSchema;
|
|
27
29
|
createDocs: EndpointDocumentation | undefined;
|
|
28
30
|
readSchema: ReadSchema;
|
|
@@ -43,7 +45,7 @@ export type CrudSchema<ClientSchema extends InnerCrudSchema = InnerCrudSchema, S
|
|
|
43
45
|
hasDelete: boolean;
|
|
44
46
|
};
|
|
45
47
|
export type CrudSchemaCreationOptions = {
|
|
46
|
-
[K in AccessTypeXCrudOperation as `${K}Schema`]?: yup.
|
|
48
|
+
[K in AccessTypeXCrudOperation as `${K}Schema`]?: yup.AnySchema;
|
|
47
49
|
};
|
|
48
50
|
type FillInOptionalsPrepareStep<O extends CrudSchemaCreationOptions> = {
|
|
49
51
|
[K in keyof Required<CrudSchemaCreationOptions>]: K extends keyof O ? O[K] : undefined;
|
|
@@ -73,6 +75,11 @@ type InnerCrudTypeOf<S extends InnerCrudSchema> = (S['createSchema'] extends {}
|
|
|
73
75
|
Update: yup.InferType<S['updateSchema']>;
|
|
74
76
|
} : {}) & (S['deleteSchema'] extends {} ? {
|
|
75
77
|
Delete: yup.InferType<S['deleteSchema']>;
|
|
78
|
+
} : {}) & (S['readSchema'] extends {} ? {
|
|
79
|
+
List: {
|
|
80
|
+
items: yup.InferType<S['readSchema']>[];
|
|
81
|
+
is_paginated: boolean;
|
|
82
|
+
};
|
|
76
83
|
} : {});
|
|
77
84
|
export type CrudTypeOf<S extends CrudSchema> = {
|
|
78
85
|
Client: InnerCrudTypeOf<S['client']>;
|
|
@@ -80,7 +87,7 @@ export type CrudTypeOf<S extends CrudSchema> = {
|
|
|
80
87
|
Admin: InnerCrudTypeOf<S['admin']>;
|
|
81
88
|
};
|
|
82
89
|
type CrudDocsCreationOptions<SO extends CrudSchemaCreationOptions> = {
|
|
83
|
-
[X in
|
|
90
|
+
[X in AccessTypeXCrudlOperation]?: EndpointDocumentation;
|
|
84
91
|
};
|
|
85
92
|
export declare function createCrud<SO extends CrudSchemaCreationOptions>(options: SO & {
|
|
86
93
|
docs?: CrudDocsCreationOptions<SO>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { StackAssertionError } from "../utils/errors";
|
|
2
|
+
import { isLocalhost } from "../utils/urls";
|
|
3
|
+
export function getProductionModeErrors(project) {
|
|
4
|
+
const errors = [];
|
|
5
|
+
const domainsFixUrl = `/projects/${project.id}/domains`;
|
|
6
|
+
if (project.config.allow_localhost) {
|
|
7
|
+
errors.push({
|
|
8
|
+
message: "Localhost is not allowed in production mode, turn off 'Allow localhost' in project settings",
|
|
9
|
+
relativeFixUrl: domainsFixUrl,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
for (const { domain } of project.config.domains) {
|
|
13
|
+
let url;
|
|
14
|
+
try {
|
|
15
|
+
url = new URL(domain);
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
throw new StackAssertionError("Domain was somehow not a valid URL; we should've caught this when setting the domain in the first place", {
|
|
19
|
+
domain,
|
|
20
|
+
projectId: project
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (isLocalhost(url)) {
|
|
24
|
+
errors.push({
|
|
25
|
+
message: "Localhost domains are not allowed to be trusted in production mode: " + domain,
|
|
26
|
+
relativeFixUrl: domainsFixUrl,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else if (url.hostname.match(/^\d+(\.\d+)*$/)) {
|
|
30
|
+
errors.push({
|
|
31
|
+
message: "Direct IPs are not valid for trusted domains in production mode: " + domain,
|
|
32
|
+
relativeFixUrl: domainsFixUrl,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else if (url.protocol !== "https:") {
|
|
36
|
+
errors.push({
|
|
37
|
+
message: "Trusted domains should be HTTPS: " + domain,
|
|
38
|
+
relativeFixUrl: domainsFixUrl,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return errors;
|
|
43
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { KnownError, KnownErrors
|
|
1
|
+
export { StackAdminInterface } from "./interface/adminInterface";
|
|
2
|
+
export { StackClientInterface } from "./interface/clientInterface";
|
|
3
|
+
export { StackServerInterface } from "./interface/serverInterface";
|
|
4
|
+
export { KnownError, KnownErrors } from "./known-errors";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { KnownError, KnownErrors
|
|
1
|
+
export { StackAdminInterface } from "./interface/adminInterface";
|
|
2
|
+
export { StackClientInterface } from "./interface/clientInterface";
|
|
3
|
+
export { StackServerInterface } from "./interface/serverInterface";
|
|
4
|
+
export { KnownError, KnownErrors } from "./known-errors";
|
|
@@ -1,69 +1,25 @@
|
|
|
1
|
-
import { ServerAuthApplicationOptions, StackServerInterface } from "./serverInterface";
|
|
2
|
-
import { EmailConfigJson, ProjectJson, SharedProvider, StandardProvider } from "./clientInterface";
|
|
3
1
|
import { InternalSession } from "../sessions";
|
|
4
|
-
|
|
2
|
+
import { ApiKeysCrud } from "./crud/api-keys";
|
|
3
|
+
import { EmailTemplateCrud, EmailTemplateType } from "./crud/email-templates";
|
|
4
|
+
import { ProjectsCrud } from "./crud/projects";
|
|
5
|
+
import { TeamPermissionDefinitionsCrud } from "./crud/team-permissions";
|
|
6
|
+
import { ServerAuthApplicationOptions, StackServerInterface } from "./serverInterface";
|
|
7
|
+
export type AdminAuthApplicationOptions = ServerAuthApplicationOptions & ({
|
|
5
8
|
superSecretAdminKey: string;
|
|
6
9
|
} | {
|
|
7
10
|
projectOwnerSession: InternalSession;
|
|
8
|
-
})>;
|
|
9
|
-
export type OAuthProviderUpdateOptions = {
|
|
10
|
-
id: string;
|
|
11
|
-
enabled: boolean;
|
|
12
|
-
} & ({
|
|
13
|
-
type: SharedProvider;
|
|
14
|
-
} | {
|
|
15
|
-
type: StandardProvider;
|
|
16
|
-
clientId: string;
|
|
17
|
-
clientSecret: string;
|
|
18
11
|
});
|
|
19
|
-
export type
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
domains?: {
|
|
25
|
-
domain: string;
|
|
26
|
-
handlerPath: string;
|
|
27
|
-
}[];
|
|
28
|
-
oauthProviders?: OAuthProviderUpdateOptions[];
|
|
29
|
-
credentialEnabled?: boolean;
|
|
30
|
-
magicLinkEnabled?: boolean;
|
|
31
|
-
allowLocalhost?: boolean;
|
|
32
|
-
createTeamOnSignUp?: boolean;
|
|
33
|
-
emailConfig?: EmailConfigJson;
|
|
34
|
-
teamCreatorDefaultPermissionIds?: string[];
|
|
35
|
-
teamMemberDefaultPermissionIds?: string[];
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
export type ApiKeySetBaseJson = {
|
|
39
|
-
id: string;
|
|
12
|
+
export type ApiKeyCreateCrudRequest = {
|
|
13
|
+
has_publishable_client_key: boolean;
|
|
14
|
+
has_secret_server_key: boolean;
|
|
15
|
+
has_super_secret_admin_key: boolean;
|
|
16
|
+
expires_at_millis: number;
|
|
40
17
|
description: string;
|
|
41
|
-
expiresAtMillis: number;
|
|
42
|
-
manuallyRevokedAtMillis: number | null;
|
|
43
|
-
createdAtMillis: number;
|
|
44
18
|
};
|
|
45
|
-
export type
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
export type ApiKeySetJson = ApiKeySetBaseJson & {
|
|
51
|
-
publishableClientKey: null | {
|
|
52
|
-
lastFour: string;
|
|
53
|
-
};
|
|
54
|
-
secretServerKey: null | {
|
|
55
|
-
lastFour: string;
|
|
56
|
-
};
|
|
57
|
-
superSecretAdminKey: null | {
|
|
58
|
-
lastFour: string;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export type ApiKeySetCreateOptions = {
|
|
62
|
-
hasPublishableClientKey: boolean;
|
|
63
|
-
hasSecretServerKey: boolean;
|
|
64
|
-
hasSuperSecretAdminKey: boolean;
|
|
65
|
-
expiresAt: Date;
|
|
66
|
-
description: string;
|
|
19
|
+
export type ApiKeyCreateCrudResponse = ApiKeysCrud["Admin"]["Read"] & {
|
|
20
|
+
publishable_client_key?: string;
|
|
21
|
+
secret_server_key?: string;
|
|
22
|
+
super_secret_admin_key?: string;
|
|
67
23
|
};
|
|
68
24
|
export declare class StackAdminInterface extends StackServerInterface {
|
|
69
25
|
readonly options: AdminAuthApplicationOptions;
|
|
@@ -74,12 +30,17 @@ export declare class StackAdminInterface extends StackServerInterface {
|
|
|
74
30
|
refreshToken: import("../sessions").RefreshToken | null;
|
|
75
31
|
} | null;
|
|
76
32
|
}>;
|
|
77
|
-
getProject(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
33
|
+
getProject(): Promise<ProjectsCrud["Admin"]["Read"]>;
|
|
34
|
+
updateProject(update: ProjectsCrud["Admin"]["Update"]): Promise<ProjectsCrud["Admin"]["Read"]>;
|
|
35
|
+
createApiKey(options: ApiKeyCreateCrudRequest): Promise<ApiKeyCreateCrudResponse>;
|
|
36
|
+
listApiKeys(): Promise<ApiKeysCrud["Admin"]["Read"][]>;
|
|
37
|
+
revokeApiKeyById(id: string): Promise<void>;
|
|
38
|
+
getApiKey(id: string, session: InternalSession): Promise<ApiKeysCrud["Admin"]["Read"]>;
|
|
39
|
+
listEmailTemplates(): Promise<EmailTemplateCrud['Admin']['Read'][]>;
|
|
40
|
+
updateEmailTemplate(type: EmailTemplateType, data: EmailTemplateCrud['Admin']['Update']): Promise<EmailTemplateCrud['Admin']['Read']>;
|
|
41
|
+
resetEmailTemplate(type: EmailTemplateType): Promise<void>;
|
|
42
|
+
listPermissionDefinitions(): Promise<TeamPermissionDefinitionsCrud['Admin']['Read'][]>;
|
|
43
|
+
createPermissionDefinition(data: TeamPermissionDefinitionsCrud['Admin']['Create']): Promise<TeamPermissionDefinitionsCrud['Admin']['Read']>;
|
|
44
|
+
updatePermissionDefinition(permissionId: string, data: TeamPermissionDefinitionsCrud['Admin']['Update']): Promise<TeamPermissionDefinitionsCrud['Admin']['Read']>;
|
|
45
|
+
deletePermissionDefinition(permissionId: string): Promise<void>;
|
|
85
46
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { StackServerInterface } from "./serverInterface";
|
|
2
2
|
export class StackAdminInterface extends StackServerInterface {
|
|
3
|
-
options;
|
|
4
3
|
constructor(options) {
|
|
5
4
|
super(options);
|
|
6
5
|
this.options = options;
|
|
@@ -14,19 +13,15 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
14
13
|
},
|
|
15
14
|
}, session, requestType);
|
|
16
15
|
}
|
|
17
|
-
async getProject(
|
|
18
|
-
const response = await this.sendAdminRequest("/projects/"
|
|
19
|
-
method: "
|
|
20
|
-
headers: {
|
|
21
|
-
"content-type": "application/json",
|
|
22
|
-
},
|
|
23
|
-
body: JSON.stringify(options ?? {}),
|
|
16
|
+
async getProject() {
|
|
17
|
+
const response = await this.sendAdminRequest("/projects/current", {
|
|
18
|
+
method: "GET",
|
|
24
19
|
}, null);
|
|
25
20
|
return await response.json();
|
|
26
21
|
}
|
|
27
22
|
async updateProject(update) {
|
|
28
|
-
const response = await this.sendAdminRequest("/projects/"
|
|
29
|
-
method: "
|
|
23
|
+
const response = await this.sendAdminRequest("/projects/current", {
|
|
24
|
+
method: "PATCH",
|
|
30
25
|
headers: {
|
|
31
26
|
"content-type": "application/json",
|
|
32
27
|
},
|
|
@@ -34,8 +29,8 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
34
29
|
}, null);
|
|
35
30
|
return await response.json();
|
|
36
31
|
}
|
|
37
|
-
async
|
|
38
|
-
const response = await this.sendServerRequest("/api-keys", {
|
|
32
|
+
async createApiKey(options) {
|
|
33
|
+
const response = await this.sendServerRequest("/internal/api-keys", {
|
|
39
34
|
method: "POST",
|
|
40
35
|
headers: {
|
|
41
36
|
"content-type": "application/json",
|
|
@@ -44,24 +39,70 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
44
39
|
}, null);
|
|
45
40
|
return await response.json();
|
|
46
41
|
}
|
|
47
|
-
async
|
|
48
|
-
const response = await this.sendAdminRequest("/api-keys", {}, null);
|
|
49
|
-
const
|
|
50
|
-
return
|
|
42
|
+
async listApiKeys() {
|
|
43
|
+
const response = await this.sendAdminRequest("/internal/api-keys", {}, null);
|
|
44
|
+
const result = await response.json();
|
|
45
|
+
return result.items;
|
|
51
46
|
}
|
|
52
|
-
async
|
|
53
|
-
await this.sendAdminRequest(`/api-keys/${id}`, {
|
|
54
|
-
method: "
|
|
47
|
+
async revokeApiKeyById(id) {
|
|
48
|
+
await this.sendAdminRequest(`/internal/api-keys/${id}`, {
|
|
49
|
+
method: "PATCH",
|
|
55
50
|
headers: {
|
|
56
51
|
"content-type": "application/json",
|
|
57
52
|
},
|
|
58
53
|
body: JSON.stringify({
|
|
59
|
-
|
|
54
|
+
revoked: true,
|
|
60
55
|
}),
|
|
61
56
|
}, null);
|
|
62
57
|
}
|
|
63
|
-
async
|
|
64
|
-
const response = await this.sendAdminRequest(`/api-keys/${id}`, {}, session);
|
|
58
|
+
async getApiKey(id, session) {
|
|
59
|
+
const response = await this.sendAdminRequest(`/internal/api-keys/${id}`, {}, session);
|
|
60
|
+
return await response.json();
|
|
61
|
+
}
|
|
62
|
+
async listEmailTemplates() {
|
|
63
|
+
const response = await this.sendAdminRequest(`/email-templates`, {}, null);
|
|
64
|
+
const result = await response.json();
|
|
65
|
+
return result.items;
|
|
66
|
+
}
|
|
67
|
+
async updateEmailTemplate(type, data) {
|
|
68
|
+
const result = await this.sendAdminRequest(`/email-templates/${type}`, {
|
|
69
|
+
method: "PATCH",
|
|
70
|
+
headers: {
|
|
71
|
+
"content-type": "application/json",
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(data),
|
|
74
|
+
}, null);
|
|
75
|
+
return await result.json();
|
|
76
|
+
}
|
|
77
|
+
async resetEmailTemplate(type) {
|
|
78
|
+
await this.sendAdminRequest(`/email-templates/${type}`, { method: "DELETE" }, null);
|
|
79
|
+
}
|
|
80
|
+
async listPermissionDefinitions() {
|
|
81
|
+
const response = await this.sendAdminRequest(`/team-permission-definitions`, {}, null);
|
|
82
|
+
const result = await response.json();
|
|
83
|
+
return result.items;
|
|
84
|
+
}
|
|
85
|
+
async createPermissionDefinition(data) {
|
|
86
|
+
const response = await this.sendAdminRequest("/team-permission-definitions", {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: {
|
|
89
|
+
"content-type": "application/json",
|
|
90
|
+
},
|
|
91
|
+
body: JSON.stringify(data),
|
|
92
|
+
}, null);
|
|
93
|
+
return await response.json();
|
|
94
|
+
}
|
|
95
|
+
async updatePermissionDefinition(permissionId, data) {
|
|
96
|
+
const response = await this.sendAdminRequest(`/team-permission-definitions/${permissionId}`, {
|
|
97
|
+
method: "PATCH",
|
|
98
|
+
headers: {
|
|
99
|
+
"content-type": "application/json",
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify(data),
|
|
102
|
+
}, null);
|
|
65
103
|
return await response.json();
|
|
66
104
|
}
|
|
105
|
+
async deletePermissionDefinition(permissionId) {
|
|
106
|
+
await this.sendAdminRequest(`/team-permission-definitions/${permissionId}`, { method: "DELETE" }, null);
|
|
107
|
+
}
|
|
67
108
|
}
|
|
@@ -1,42 +1,11 @@
|
|
|
1
|
-
import { Result } from "../utils/results";
|
|
2
|
-
import { ReadonlyJson } from '../utils/json';
|
|
3
1
|
import { KnownErrors } from '../known-errors';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
export type UserJson = UserCustomizableJson & {
|
|
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;
|
|
20
|
-
/**
|
|
21
|
-
* not used anymore, for backwards compatibility
|
|
22
|
-
*/
|
|
23
|
-
authMethod: "credential" | "oauth";
|
|
24
|
-
hasPassword: boolean;
|
|
25
|
-
authWithEmail: boolean;
|
|
26
|
-
oauthProviders: string[];
|
|
27
|
-
selectedTeamId: string | null;
|
|
28
|
-
selectedTeam: TeamJson | null;
|
|
29
|
-
};
|
|
30
|
-
export type UserUpdateJson = Partial<UserCustomizableJson>;
|
|
31
|
-
export type ClientProjectJson = {
|
|
32
|
-
id: string;
|
|
33
|
-
credentialEnabled: boolean;
|
|
34
|
-
magicLinkEnabled: boolean;
|
|
35
|
-
oauthProviders: {
|
|
36
|
-
id: string;
|
|
37
|
-
enabled: boolean;
|
|
38
|
-
}[];
|
|
39
|
-
};
|
|
2
|
+
import { AccessToken, InternalSession, RefreshToken } from '../sessions';
|
|
3
|
+
import { ReadonlyJson } from '../utils/json';
|
|
4
|
+
import { Result } from "../utils/results";
|
|
5
|
+
import { CurrentUserCrud } from './crud/current-user';
|
|
6
|
+
import { InternalProjectsCrud, ProjectsCrud } from './crud/projects';
|
|
7
|
+
import { TeamPermissionsCrud } from './crud/team-permissions';
|
|
8
|
+
import { TeamsCrud } from './crud/teams';
|
|
40
9
|
export type ClientInterfaceOptions = {
|
|
41
10
|
clientVersion: string;
|
|
42
11
|
baseUrl: string;
|
|
@@ -52,82 +21,6 @@ export type StandardProvider = "github" | "facebook" | "google" | "microsoft" |
|
|
|
52
21
|
export declare const standardProviders: readonly ["github", "facebook", "google", "microsoft", "spotify"];
|
|
53
22
|
export declare function toStandardProvider(provider: SharedProvider | StandardProvider): StandardProvider;
|
|
54
23
|
export declare function toSharedProvider(provider: SharedProvider | StandardProvider): SharedProvider;
|
|
55
|
-
export type ProjectJson = {
|
|
56
|
-
id: string;
|
|
57
|
-
displayName: string;
|
|
58
|
-
description?: string;
|
|
59
|
-
createdAtMillis: number;
|
|
60
|
-
userCount: number;
|
|
61
|
-
isProductionMode: boolean;
|
|
62
|
-
evaluatedConfig: {
|
|
63
|
-
id: string;
|
|
64
|
-
allowLocalhost: boolean;
|
|
65
|
-
credentialEnabled: boolean;
|
|
66
|
-
magicLinkEnabled: boolean;
|
|
67
|
-
oauthProviders: OAuthProviderConfigJson[];
|
|
68
|
-
emailConfig?: EmailConfigJson;
|
|
69
|
-
domains: DomainConfigJson[];
|
|
70
|
-
createTeamOnSignUp: boolean;
|
|
71
|
-
teamCreatorDefaultPermissions: PermissionDefinitionJson[];
|
|
72
|
-
teamMemberDefaultPermissions: PermissionDefinitionJson[];
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
export type OAuthProviderConfigJson = {
|
|
76
|
-
id: string;
|
|
77
|
-
enabled: boolean;
|
|
78
|
-
} & ({
|
|
79
|
-
type: SharedProvider;
|
|
80
|
-
} | {
|
|
81
|
-
type: StandardProvider;
|
|
82
|
-
clientId: string;
|
|
83
|
-
clientSecret: string;
|
|
84
|
-
});
|
|
85
|
-
export type EmailConfigJson = ({
|
|
86
|
-
type: "standard";
|
|
87
|
-
senderName: string;
|
|
88
|
-
senderEmail: string;
|
|
89
|
-
host: string;
|
|
90
|
-
port: number;
|
|
91
|
-
username: string;
|
|
92
|
-
password: string;
|
|
93
|
-
} | {
|
|
94
|
-
type: "shared";
|
|
95
|
-
});
|
|
96
|
-
export type DomainConfigJson = {
|
|
97
|
-
domain: string;
|
|
98
|
-
handlerPath: string;
|
|
99
|
-
};
|
|
100
|
-
export type ProductionModeError = {
|
|
101
|
-
errorMessage: string;
|
|
102
|
-
fixUrlRelative: string;
|
|
103
|
-
};
|
|
104
|
-
export type OrglikeJson = {
|
|
105
|
-
id: string;
|
|
106
|
-
displayName: string;
|
|
107
|
-
profileImageUrl?: string;
|
|
108
|
-
createdAtMillis: number;
|
|
109
|
-
};
|
|
110
|
-
export type TeamJson = OrglikeJson;
|
|
111
|
-
export type OrganizationJson = OrglikeJson;
|
|
112
|
-
export type OrglikeCustomizableJson = Pick<OrglikeJson, "displayName" | "profileImageUrl">;
|
|
113
|
-
export type TeamCustomizableJson = OrglikeCustomizableJson;
|
|
114
|
-
export type TeamMemberJson = {
|
|
115
|
-
userId: string;
|
|
116
|
-
teamId: string;
|
|
117
|
-
displayName: string | null;
|
|
118
|
-
};
|
|
119
|
-
export type PermissionDefinitionScopeJson = {
|
|
120
|
-
type: "global";
|
|
121
|
-
} | {
|
|
122
|
-
type: "any-team";
|
|
123
|
-
} | {
|
|
124
|
-
type: "specific-team";
|
|
125
|
-
teamId: string;
|
|
126
|
-
};
|
|
127
|
-
export type PermissionDefinitionJson = {
|
|
128
|
-
id: string;
|
|
129
|
-
scope: PermissionDefinitionScopeJson;
|
|
130
|
-
};
|
|
131
24
|
export declare class StackClientInterface {
|
|
132
25
|
readonly options: ClientInterfaceOptions;
|
|
133
26
|
constructor(options: ClientInterfaceOptions);
|
|
@@ -152,9 +45,9 @@ export declare class StackClientInterface {
|
|
|
152
45
|
checkFeatureSupport(options: {
|
|
153
46
|
featureName?: string;
|
|
154
47
|
} & ReadonlyJson): Promise<never>;
|
|
155
|
-
sendForgotPasswordEmail(email: string,
|
|
48
|
+
sendForgotPasswordEmail(email: string, callbackUrl: string): Promise<KnownErrors["UserNotFound"] | undefined>;
|
|
156
49
|
sendVerificationEmail(emailVerificationRedirectUrl: string, session: InternalSession): Promise<KnownErrors["EmailAlreadyVerified"] | undefined>;
|
|
157
|
-
sendMagicLinkEmail(email: string,
|
|
50
|
+
sendMagicLinkEmail(email: string, callbackUrl: string): Promise<KnownErrors["RedirectUrlNotWhitelisted"] | undefined>;
|
|
158
51
|
resetPassword(options: {
|
|
159
52
|
code: string;
|
|
160
53
|
} & ({
|
|
@@ -165,7 +58,7 @@ export declare class StackClientInterface {
|
|
|
165
58
|
updatePassword(options: {
|
|
166
59
|
oldPassword: string;
|
|
167
60
|
newPassword: string;
|
|
168
|
-
}, session: InternalSession): Promise<KnownErrors["
|
|
61
|
+
}, session: InternalSession): Promise<KnownErrors["PasswordConfirmationMismatch"] | KnownErrors["PasswordRequirementsNotMet"] | undefined>;
|
|
169
62
|
verifyPasswordResetCode(code: string): Promise<KnownErrors["VerificationCodeError"] | undefined>;
|
|
170
63
|
verifyEmail(code: string): Promise<KnownErrors["VerificationCodeError"] | undefined>;
|
|
171
64
|
signInWithCredential(email: string, password: string, session: InternalSession): Promise<KnownErrors["EmailPasswordMismatch"] | {
|
|
@@ -176,7 +69,7 @@ export declare class StackClientInterface {
|
|
|
176
69
|
accessToken: string;
|
|
177
70
|
refreshToken: string;
|
|
178
71
|
}>;
|
|
179
|
-
signInWithMagicLink(code: string
|
|
72
|
+
signInWithMagicLink(code: string): Promise<KnownErrors["VerificationCodeError"] | {
|
|
180
73
|
newUser: boolean;
|
|
181
74
|
accessToken: string;
|
|
182
75
|
refreshToken: string;
|
|
@@ -208,23 +101,18 @@ export declare class StackClientInterface {
|
|
|
208
101
|
refreshToken: string;
|
|
209
102
|
}>;
|
|
210
103
|
signOut(session: InternalSession): Promise<void>;
|
|
211
|
-
getClientUserByToken(
|
|
212
|
-
|
|
104
|
+
getClientUserByToken(session: InternalSession): Promise<CurrentUserCrud["Client"]["Read"] | null>;
|
|
105
|
+
listCurrentUserTeamPermissions(options: {
|
|
213
106
|
teamId: string;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
createProject(project: ProjectUpdateOptions & {
|
|
222
|
-
displayName: string;
|
|
223
|
-
}, session: InternalSession): Promise<ProjectJson>;
|
|
107
|
+
recursive: boolean;
|
|
108
|
+
}, session: InternalSession): Promise<TeamPermissionsCrud['Client']['Read'][]>;
|
|
109
|
+
listCurrentUserTeams(session: InternalSession): Promise<TeamsCrud["Client"]["Read"][]>;
|
|
110
|
+
getClientProject(): Promise<Result<ProjectsCrud['Client']['Read'], KnownErrors["ProjectNotFound"]>>;
|
|
111
|
+
updateClientUser(update: CurrentUserCrud["Client"]["Update"], session: InternalSession): Promise<void>;
|
|
112
|
+
listProjects(session: InternalSession): Promise<InternalProjectsCrud['Client']['Read'][]>;
|
|
113
|
+
createProject(project: InternalProjectsCrud['Client']['Create'], session: InternalSession): Promise<InternalProjectsCrud['Client']['Read']>;
|
|
224
114
|
getAccessToken(provider: string, scope: string, session: InternalSession): Promise<{
|
|
225
115
|
accessToken: string;
|
|
226
116
|
}>;
|
|
227
|
-
createTeamForCurrentUser(data:
|
|
117
|
+
createTeamForCurrentUser(data: TeamsCrud['Client']['Create'], session: InternalSession): Promise<TeamsCrud['Client']['Read']>;
|
|
228
118
|
}
|
|
229
|
-
export declare function getProductionModeErrors(project: ProjectJson): ProductionModeError[];
|
|
230
|
-
export {};
|