@stackframe/stack-shared 2.5.12 → 2.5.15
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 +21 -0
- package/dist/interface/adminInterface.d.ts +2 -0
- package/dist/interface/adminInterface.js +10 -0
- package/dist/interface/clientInterface.d.ts +2 -2
- package/dist/interface/clientInterface.js +1 -1
- package/dist/interface/crud/oauth.d.ts +9 -4
- package/dist/interface/crud/oauth.js +10 -5
- package/dist/interface/crud/svix-token.d.ts +21 -0
- package/dist/interface/crud/svix-token.js +15 -0
- package/dist/interface/crud/team-memberships.d.ts +5 -0
- package/dist/interface/crud/team-memberships.js +5 -0
- package/dist/interface/crud/teams.d.ts +63 -0
- package/dist/interface/crud/teams.js +42 -2
- package/dist/interface/crud/users.d.ts +115 -0
- package/dist/interface/crud/users.js +30 -0
- package/dist/interface/serverInterface.d.ts +8 -4
- package/dist/interface/serverInterface.js +21 -9
- package/dist/interface/webhooks.d.ts +173 -0
- package/dist/interface/webhooks.js +10 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @stackframe/stack-shared
|
|
2
2
|
|
|
3
|
+
## 2.5.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Webhooks
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @stackframe/stack-sc@2.5.15
|
|
10
|
+
|
|
11
|
+
## 2.5.14
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- @stackframe/stack-sc@2.5.14
|
|
16
|
+
|
|
17
|
+
## 2.5.13
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Add server side get connected account
|
|
22
|
+
- @stackframe/stack-sc@2.5.13
|
|
23
|
+
|
|
3
24
|
## 2.5.12
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -2,6 +2,7 @@ import { InternalSession } from "../sessions";
|
|
|
2
2
|
import { ApiKeysCrud } from "./crud/api-keys";
|
|
3
3
|
import { EmailTemplateCrud, EmailTemplateType } from "./crud/email-templates";
|
|
4
4
|
import { ProjectsCrud } from "./crud/projects";
|
|
5
|
+
import { SvixTokenCrud } from "./crud/svix-token";
|
|
5
6
|
import { TeamPermissionDefinitionsCrud } from "./crud/team-permissions";
|
|
6
7
|
import { ServerAuthApplicationOptions, StackServerInterface } from "./serverInterface";
|
|
7
8
|
export type AdminAuthApplicationOptions = ServerAuthApplicationOptions & ({
|
|
@@ -43,4 +44,5 @@ export declare class StackAdminInterface extends StackServerInterface {
|
|
|
43
44
|
createPermissionDefinition(data: TeamPermissionDefinitionsCrud['Admin']['Create']): Promise<TeamPermissionDefinitionsCrud['Admin']['Read']>;
|
|
44
45
|
updatePermissionDefinition(permissionId: string, data: TeamPermissionDefinitionsCrud['Admin']['Update']): Promise<TeamPermissionDefinitionsCrud['Admin']['Read']>;
|
|
45
46
|
deletePermissionDefinition(permissionId: string): Promise<void>;
|
|
47
|
+
getSvixToken(): Promise<SvixTokenCrud["Admin"]["Read"]>;
|
|
46
48
|
}
|
|
@@ -105,4 +105,14 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
105
105
|
async deletePermissionDefinition(permissionId) {
|
|
106
106
|
await this.sendAdminRequest(`/team-permission-definitions/${permissionId}`, { method: "DELETE" }, null);
|
|
107
107
|
}
|
|
108
|
+
async getSvixToken() {
|
|
109
|
+
const response = await this.sendAdminRequest("/webhooks/svix-token", {
|
|
110
|
+
method: "POST",
|
|
111
|
+
headers: {
|
|
112
|
+
"content-type": "application/json",
|
|
113
|
+
},
|
|
114
|
+
body: JSON.stringify({}),
|
|
115
|
+
}, null);
|
|
116
|
+
return await response.json();
|
|
117
|
+
}
|
|
108
118
|
}
|
|
@@ -3,7 +3,7 @@ import { AccessToken, InternalSession, RefreshToken } from '../sessions';
|
|
|
3
3
|
import { ReadonlyJson } from '../utils/json';
|
|
4
4
|
import { Result } from "../utils/results";
|
|
5
5
|
import { CurrentUserCrud } from './crud/current-user';
|
|
6
|
-
import {
|
|
6
|
+
import { ConnectedAccountAccessTokenCrud } from './crud/oauth';
|
|
7
7
|
import { InternalProjectsCrud, ProjectsCrud } from './crud/projects';
|
|
8
8
|
import { TeamPermissionsCrud } from './crud/team-permissions';
|
|
9
9
|
import { TeamsCrud } from './crud/teams';
|
|
@@ -113,6 +113,6 @@ export declare class StackClientInterface {
|
|
|
113
113
|
updateClientUser(update: CurrentUserCrud["Client"]["Update"], session: InternalSession): Promise<void>;
|
|
114
114
|
listProjects(session: InternalSession): Promise<InternalProjectsCrud['Client']['Read'][]>;
|
|
115
115
|
createProject(project: InternalProjectsCrud['Client']['Create'], session: InternalSession): Promise<InternalProjectsCrud['Client']['Read']>;
|
|
116
|
-
createProviderAccessToken(provider: string, scope: string, session: InternalSession): Promise<
|
|
116
|
+
createProviderAccessToken(provider: string, scope: string, session: InternalSession): Promise<ConnectedAccountAccessTokenCrud['Client']['Read']>;
|
|
117
117
|
createTeamForCurrentUser(data: TeamsCrud['Client']['Create'], session: InternalSession): Promise<TeamsCrud['Client']['Read']>;
|
|
118
118
|
}
|
|
@@ -601,7 +601,7 @@ export class StackClientInterface {
|
|
|
601
601
|
return json;
|
|
602
602
|
}
|
|
603
603
|
async createProviderAccessToken(provider, scope, session) {
|
|
604
|
-
const response = await this.sendClientRequest(`/
|
|
604
|
+
const response = await this.sendClientRequest(`/connected-accounts/me/${provider}/access-token`, {
|
|
605
605
|
method: "POST",
|
|
606
606
|
headers: {
|
|
607
607
|
"content-type": "application/json",
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { CrudTypeOf } from "../../crud";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const connectedAccountAccessTokenReadSchema: import("yup").ObjectSchema<{
|
|
3
3
|
access_token: string;
|
|
4
4
|
}, import("yup").AnyObject, {
|
|
5
5
|
access_token: undefined;
|
|
6
6
|
}, "">;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const connectedAccountAccessTokenCreateSchema: import("yup").ObjectSchema<{
|
|
8
8
|
scope: string | undefined;
|
|
9
9
|
}, import("yup").AnyObject, {
|
|
10
10
|
scope: undefined;
|
|
11
11
|
}, "">;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const connectedAccountAccessTokenCrud: import("../../crud").CrudSchemaFromOptions<{
|
|
13
13
|
clientReadSchema: import("yup").ObjectSchema<{
|
|
14
14
|
access_token: string;
|
|
15
15
|
}, import("yup").AnyObject, {
|
|
@@ -20,5 +20,10 @@ export declare const providerAccessTokenCrud: import("../../crud").CrudSchemaFro
|
|
|
20
20
|
}, import("yup").AnyObject, {
|
|
21
21
|
scope: undefined;
|
|
22
22
|
}, "">;
|
|
23
|
+
docs: {
|
|
24
|
+
clientCreate: {
|
|
25
|
+
hidden: true;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
23
28
|
}>;
|
|
24
|
-
export type
|
|
29
|
+
export type ConnectedAccountAccessTokenCrud = CrudTypeOf<typeof connectedAccountAccessTokenCrud>;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { createCrud } from "../../crud";
|
|
2
2
|
import { yupObject, yupString } from "../../schema-fields";
|
|
3
|
-
export const
|
|
3
|
+
export const connectedAccountAccessTokenReadSchema = yupObject({
|
|
4
4
|
access_token: yupString().required(),
|
|
5
5
|
}).required();
|
|
6
|
-
export const
|
|
6
|
+
export const connectedAccountAccessTokenCreateSchema = yupObject({
|
|
7
7
|
scope: yupString().optional(),
|
|
8
8
|
}).required();
|
|
9
|
-
export const
|
|
10
|
-
clientReadSchema:
|
|
11
|
-
clientCreateSchema:
|
|
9
|
+
export const connectedAccountAccessTokenCrud = createCrud({
|
|
10
|
+
clientReadSchema: connectedAccountAccessTokenReadSchema,
|
|
11
|
+
clientCreateSchema: connectedAccountAccessTokenCreateSchema,
|
|
12
|
+
docs: {
|
|
13
|
+
clientCreate: {
|
|
14
|
+
hidden: true,
|
|
15
|
+
}
|
|
16
|
+
},
|
|
12
17
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CrudTypeOf } from "../../crud";
|
|
2
|
+
export declare const svixTokenAdminReadSchema: import("yup").ObjectSchema<{
|
|
3
|
+
token: string;
|
|
4
|
+
}, import("yup").AnyObject, {
|
|
5
|
+
token: undefined;
|
|
6
|
+
}, "">;
|
|
7
|
+
export declare const svixTokenAdminCreateSchema: import("yup").ObjectSchema<{}, import("yup").AnyObject, {}, "">;
|
|
8
|
+
export declare const svixTokenCrud: import("../../crud").CrudSchemaFromOptions<{
|
|
9
|
+
adminReadSchema: import("yup").ObjectSchema<{
|
|
10
|
+
token: string;
|
|
11
|
+
}, import("yup").AnyObject, {
|
|
12
|
+
token: undefined;
|
|
13
|
+
}, "">;
|
|
14
|
+
adminCreateSchema: import("yup").ObjectSchema<{}, import("yup").AnyObject, {}, "">;
|
|
15
|
+
docs: {
|
|
16
|
+
adminCreate: {
|
|
17
|
+
hidden: true;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
export type SvixTokenCrud = CrudTypeOf<typeof svixTokenCrud>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createCrud } from "../../crud";
|
|
2
|
+
import { yupObject, yupString } from "../../schema-fields";
|
|
3
|
+
export const svixTokenAdminReadSchema = yupObject({
|
|
4
|
+
token: yupString().required(),
|
|
5
|
+
}).required();
|
|
6
|
+
export const svixTokenAdminCreateSchema = yupObject({}).required();
|
|
7
|
+
export const svixTokenCrud = createCrud({
|
|
8
|
+
adminReadSchema: svixTokenAdminReadSchema,
|
|
9
|
+
adminCreateSchema: svixTokenAdminCreateSchema,
|
|
10
|
+
docs: {
|
|
11
|
+
adminCreate: {
|
|
12
|
+
hidden: true,
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
});
|
|
@@ -12,6 +12,11 @@ export declare const teamMembershipsCrud: import("../../crud").CrudSchemaFromOpt
|
|
|
12
12
|
description: string;
|
|
13
13
|
tags: string[];
|
|
14
14
|
};
|
|
15
|
+
clientDelete: {
|
|
16
|
+
summary: string;
|
|
17
|
+
description: string;
|
|
18
|
+
tags: string[];
|
|
19
|
+
};
|
|
15
20
|
serverDelete: {
|
|
16
21
|
summary: string;
|
|
17
22
|
description: string;
|
|
@@ -15,6 +15,11 @@ export const teamMembershipsCrud = createCrud({
|
|
|
15
15
|
description: "",
|
|
16
16
|
tags: ["Teams"],
|
|
17
17
|
},
|
|
18
|
+
clientDelete: {
|
|
19
|
+
summary: "Remove a user from a team",
|
|
20
|
+
description: "All the users are allowed to remove themselves from a team (`user_id=me`). Only the users who have the `$remove_members` permission are allowed to remove other users from a team. `team_id` is must an ID of a team that the user is a member of.",
|
|
21
|
+
tags: ["Teams"],
|
|
22
|
+
},
|
|
18
23
|
serverDelete: {
|
|
19
24
|
summary: "Remove a user from a team",
|
|
20
25
|
description: "",
|
|
@@ -126,6 +126,16 @@ export declare const teamsCrud: import("../../crud").CrudSchemaFromOptions<{
|
|
|
126
126
|
description: string;
|
|
127
127
|
tags: string[];
|
|
128
128
|
};
|
|
129
|
+
clientUpdate: {
|
|
130
|
+
summary: string;
|
|
131
|
+
description: string;
|
|
132
|
+
tags: string[];
|
|
133
|
+
};
|
|
134
|
+
clientDelete: {
|
|
135
|
+
summary: string;
|
|
136
|
+
description: string;
|
|
137
|
+
tags: string[];
|
|
138
|
+
};
|
|
129
139
|
serverCreate: {
|
|
130
140
|
summary: string;
|
|
131
141
|
description: string;
|
|
@@ -154,3 +164,56 @@ export declare const teamsCrud: import("../../crud").CrudSchemaFromOptions<{
|
|
|
154
164
|
};
|
|
155
165
|
}>;
|
|
156
166
|
export type TeamsCrud = CrudTypeOf<typeof teamsCrud>;
|
|
167
|
+
export declare const teamCreatedWebhookEvent: {
|
|
168
|
+
type: string;
|
|
169
|
+
schema: import("yup").ObjectSchema<{
|
|
170
|
+
id: string;
|
|
171
|
+
display_name: string;
|
|
172
|
+
profile_image_url: string | null;
|
|
173
|
+
} & {
|
|
174
|
+
created_at_millis: number;
|
|
175
|
+
}, import("yup").AnyObject, {
|
|
176
|
+
id: undefined;
|
|
177
|
+
display_name: undefined;
|
|
178
|
+
profile_image_url: undefined;
|
|
179
|
+
created_at_millis: undefined;
|
|
180
|
+
}, "">;
|
|
181
|
+
metadata: {
|
|
182
|
+
summary: string;
|
|
183
|
+
description: string;
|
|
184
|
+
tags: string[];
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
export declare const teamUpdatedWebhookEvent: {
|
|
188
|
+
type: string;
|
|
189
|
+
schema: import("yup").ObjectSchema<{
|
|
190
|
+
id: string;
|
|
191
|
+
display_name: string;
|
|
192
|
+
profile_image_url: string | null;
|
|
193
|
+
} & {
|
|
194
|
+
created_at_millis: number;
|
|
195
|
+
}, import("yup").AnyObject, {
|
|
196
|
+
id: undefined;
|
|
197
|
+
display_name: undefined;
|
|
198
|
+
profile_image_url: undefined;
|
|
199
|
+
created_at_millis: undefined;
|
|
200
|
+
}, "">;
|
|
201
|
+
metadata: {
|
|
202
|
+
summary: string;
|
|
203
|
+
description: string;
|
|
204
|
+
tags: string[];
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
export declare const teamDeletedWebhookEvent: {
|
|
208
|
+
type: string;
|
|
209
|
+
schema: import("yup").ObjectSchema<{
|
|
210
|
+
id: string;
|
|
211
|
+
}, import("yup").AnyObject, {
|
|
212
|
+
id: undefined;
|
|
213
|
+
}, "">;
|
|
214
|
+
metadata: {
|
|
215
|
+
summary: string;
|
|
216
|
+
description: string;
|
|
217
|
+
tags: string[];
|
|
218
|
+
};
|
|
219
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createCrud } from "../../crud";
|
|
2
2
|
import * as fieldSchema from "../../schema-fields";
|
|
3
|
-
import {
|
|
3
|
+
import { yupObject } from "../../schema-fields";
|
|
4
4
|
// Read
|
|
5
5
|
export const teamsCrudClientReadSchema = yupObject({
|
|
6
6
|
id: fieldSchema.teamIdSchema.required(),
|
|
@@ -24,7 +24,7 @@ export const teamsCrudServerCreateSchema = teamsCrudServerUpdateSchema.concat(yu
|
|
|
24
24
|
display_name: fieldSchema.teamDisplayNameSchema.required(),
|
|
25
25
|
}).required());
|
|
26
26
|
// Delete
|
|
27
|
-
export const teamsCrudClientDeleteSchema = yupMixed();
|
|
27
|
+
export const teamsCrudClientDeleteSchema = fieldSchema.yupMixed();
|
|
28
28
|
export const teamsCrudServerDeleteSchema = teamsCrudClientDeleteSchema;
|
|
29
29
|
export const teamsCrud = createCrud({
|
|
30
30
|
// Client
|
|
@@ -53,6 +53,16 @@ export const teamsCrud = createCrud({
|
|
|
53
53
|
description: "Get a team that the current user is a member of.",
|
|
54
54
|
tags: ["Teams"],
|
|
55
55
|
},
|
|
56
|
+
clientUpdate: {
|
|
57
|
+
summary: "Update a team",
|
|
58
|
+
description: "Update the team information. Only allowed if the current user is a member of the team and has the `$update_team` permission.",
|
|
59
|
+
tags: ["Teams"],
|
|
60
|
+
},
|
|
61
|
+
clientDelete: {
|
|
62
|
+
summary: "Delete a team",
|
|
63
|
+
description: "Delete a team. Only allowed if the current user is a member of the team and has the `$delete_team` permission.",
|
|
64
|
+
tags: ["Teams"],
|
|
65
|
+
},
|
|
56
66
|
serverCreate: {
|
|
57
67
|
summary: "Create a team",
|
|
58
68
|
description: "Create a new team and optionally add the current user as a member.",
|
|
@@ -80,3 +90,33 @@ export const teamsCrud = createCrud({
|
|
|
80
90
|
},
|
|
81
91
|
},
|
|
82
92
|
});
|
|
93
|
+
export const teamCreatedWebhookEvent = {
|
|
94
|
+
type: "team.created",
|
|
95
|
+
schema: teamsCrud.server.readSchema,
|
|
96
|
+
metadata: {
|
|
97
|
+
summary: "Team Created",
|
|
98
|
+
description: "This event is triggered when a team is created.",
|
|
99
|
+
tags: ["Teams"],
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
export const teamUpdatedWebhookEvent = {
|
|
103
|
+
type: "team.updated",
|
|
104
|
+
schema: teamsCrud.server.readSchema,
|
|
105
|
+
metadata: {
|
|
106
|
+
summary: "Team Updated",
|
|
107
|
+
description: "This event is triggered when a team is updated.",
|
|
108
|
+
tags: ["Teams"],
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
const webhookTeamDeletedSchema = fieldSchema.yupObject({
|
|
112
|
+
id: fieldSchema.userIdSchema.required(),
|
|
113
|
+
}).required();
|
|
114
|
+
export const teamDeletedWebhookEvent = {
|
|
115
|
+
type: "team.deleted",
|
|
116
|
+
schema: webhookTeamDeletedSchema,
|
|
117
|
+
metadata: {
|
|
118
|
+
summary: "Team Deleted",
|
|
119
|
+
description: "This event is triggered when a team is deleted.",
|
|
120
|
+
tags: ["Teams"],
|
|
121
|
+
},
|
|
122
|
+
};
|
|
@@ -215,3 +215,118 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
|
|
|
215
215
|
};
|
|
216
216
|
}>;
|
|
217
217
|
export type UsersCrud = CrudTypeOf<typeof usersCrud>;
|
|
218
|
+
export declare const userCreatedWebhookEvent: {
|
|
219
|
+
type: string;
|
|
220
|
+
schema: import("yup").ObjectSchema<{
|
|
221
|
+
id: string;
|
|
222
|
+
primary_email: string | null;
|
|
223
|
+
primary_email_verified: NonNullable<boolean | undefined>;
|
|
224
|
+
display_name: string | null;
|
|
225
|
+
selected_team: {
|
|
226
|
+
id: string;
|
|
227
|
+
created_at_millis: number;
|
|
228
|
+
display_name: string;
|
|
229
|
+
profile_image_url: string | null;
|
|
230
|
+
} | null;
|
|
231
|
+
selected_team_id: string | null;
|
|
232
|
+
profile_image_url: string | null;
|
|
233
|
+
signed_up_at_millis: number;
|
|
234
|
+
has_password: NonNullable<boolean | undefined>;
|
|
235
|
+
auth_with_email: NonNullable<boolean | undefined>;
|
|
236
|
+
oauth_providers: {
|
|
237
|
+
email?: string | null | undefined;
|
|
238
|
+
id: string;
|
|
239
|
+
account_id: string;
|
|
240
|
+
}[];
|
|
241
|
+
client_metadata: {} | null;
|
|
242
|
+
server_metadata: {} | null;
|
|
243
|
+
}, import("yup").AnyObject, {
|
|
244
|
+
id: undefined;
|
|
245
|
+
primary_email: undefined;
|
|
246
|
+
primary_email_verified: undefined;
|
|
247
|
+
display_name: undefined;
|
|
248
|
+
selected_team: {
|
|
249
|
+
id: undefined;
|
|
250
|
+
display_name: undefined;
|
|
251
|
+
profile_image_url: undefined;
|
|
252
|
+
created_at_millis: undefined;
|
|
253
|
+
};
|
|
254
|
+
selected_team_id: undefined;
|
|
255
|
+
profile_image_url: undefined;
|
|
256
|
+
signed_up_at_millis: undefined;
|
|
257
|
+
has_password: undefined;
|
|
258
|
+
auth_with_email: undefined;
|
|
259
|
+
oauth_providers: undefined;
|
|
260
|
+
client_metadata: undefined;
|
|
261
|
+
server_metadata: undefined;
|
|
262
|
+
}, "">;
|
|
263
|
+
metadata: {
|
|
264
|
+
summary: string;
|
|
265
|
+
description: string;
|
|
266
|
+
tags: string[];
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
export declare const userUpdatedWebhookEvent: {
|
|
270
|
+
type: string;
|
|
271
|
+
schema: import("yup").ObjectSchema<{
|
|
272
|
+
id: string;
|
|
273
|
+
primary_email: string | null;
|
|
274
|
+
primary_email_verified: NonNullable<boolean | undefined>;
|
|
275
|
+
display_name: string | null;
|
|
276
|
+
selected_team: {
|
|
277
|
+
id: string;
|
|
278
|
+
created_at_millis: number;
|
|
279
|
+
display_name: string;
|
|
280
|
+
profile_image_url: string | null;
|
|
281
|
+
} | null;
|
|
282
|
+
selected_team_id: string | null;
|
|
283
|
+
profile_image_url: string | null;
|
|
284
|
+
signed_up_at_millis: number;
|
|
285
|
+
has_password: NonNullable<boolean | undefined>;
|
|
286
|
+
auth_with_email: NonNullable<boolean | undefined>;
|
|
287
|
+
oauth_providers: {
|
|
288
|
+
email?: string | null | undefined;
|
|
289
|
+
id: string;
|
|
290
|
+
account_id: string;
|
|
291
|
+
}[];
|
|
292
|
+
client_metadata: {} | null;
|
|
293
|
+
server_metadata: {} | null;
|
|
294
|
+
}, import("yup").AnyObject, {
|
|
295
|
+
id: undefined;
|
|
296
|
+
primary_email: undefined;
|
|
297
|
+
primary_email_verified: undefined;
|
|
298
|
+
display_name: undefined;
|
|
299
|
+
selected_team: {
|
|
300
|
+
id: undefined;
|
|
301
|
+
display_name: undefined;
|
|
302
|
+
profile_image_url: undefined;
|
|
303
|
+
created_at_millis: undefined;
|
|
304
|
+
};
|
|
305
|
+
selected_team_id: undefined;
|
|
306
|
+
profile_image_url: undefined;
|
|
307
|
+
signed_up_at_millis: undefined;
|
|
308
|
+
has_password: undefined;
|
|
309
|
+
auth_with_email: undefined;
|
|
310
|
+
oauth_providers: undefined;
|
|
311
|
+
client_metadata: undefined;
|
|
312
|
+
server_metadata: undefined;
|
|
313
|
+
}, "">;
|
|
314
|
+
metadata: {
|
|
315
|
+
summary: string;
|
|
316
|
+
description: string;
|
|
317
|
+
tags: string[];
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
export declare const userDeletedWebhookEvent: {
|
|
321
|
+
type: string;
|
|
322
|
+
schema: import("yup").ObjectSchema<{
|
|
323
|
+
id: string;
|
|
324
|
+
}, import("yup").AnyObject, {
|
|
325
|
+
id: undefined;
|
|
326
|
+
}, "">;
|
|
327
|
+
metadata: {
|
|
328
|
+
summary: string;
|
|
329
|
+
description: string;
|
|
330
|
+
tags: string[];
|
|
331
|
+
};
|
|
332
|
+
};
|
|
@@ -72,3 +72,33 @@ export const usersCrud = createCrud({
|
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
74
|
});
|
|
75
|
+
export const userCreatedWebhookEvent = {
|
|
76
|
+
type: "user.created",
|
|
77
|
+
schema: usersCrud.server.readSchema,
|
|
78
|
+
metadata: {
|
|
79
|
+
summary: "User Created",
|
|
80
|
+
description: "This event is triggered when a user is created.",
|
|
81
|
+
tags: ["Users"],
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
export const userUpdatedWebhookEvent = {
|
|
85
|
+
type: "user.updated",
|
|
86
|
+
schema: usersCrud.server.readSchema,
|
|
87
|
+
metadata: {
|
|
88
|
+
summary: "User Updated",
|
|
89
|
+
description: "This event is triggered when a user is updated.",
|
|
90
|
+
tags: ["Users"],
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const webhookUserDeletedSchema = fieldSchema.yupObject({
|
|
94
|
+
id: fieldSchema.userIdSchema.required(),
|
|
95
|
+
}).required();
|
|
96
|
+
export const userDeletedWebhookEvent = {
|
|
97
|
+
type: "user.deleted",
|
|
98
|
+
schema: webhookUserDeletedSchema,
|
|
99
|
+
metadata: {
|
|
100
|
+
summary: "User Deleted",
|
|
101
|
+
description: "This event is triggered when a user is deleted.",
|
|
102
|
+
tags: ["Users"],
|
|
103
|
+
},
|
|
104
|
+
};
|
|
@@ -3,6 +3,7 @@ import { AccessToken, InternalSession, RefreshToken } from "../sessions";
|
|
|
3
3
|
import { Result } from "../utils/results";
|
|
4
4
|
import { ClientInterfaceOptions, StackClientInterface } from "./clientInterface";
|
|
5
5
|
import { CurrentUserCrud } from "./crud/current-user";
|
|
6
|
+
import { ConnectedAccountAccessTokenCrud } from "./crud/oauth";
|
|
6
7
|
import { TeamMembershipsCrud } from "./crud/team-memberships";
|
|
7
8
|
import { TeamPermissionsCrud } from "./crud/team-permissions";
|
|
8
9
|
import { TeamsCrud } from "./crud/teams";
|
|
@@ -29,13 +30,15 @@ export declare class StackServerInterface extends StackClientInterface {
|
|
|
29
30
|
}, InstanceType<E>>>;
|
|
30
31
|
getServerUserByToken(session: InternalSession): Promise<CurrentUserCrud['Server']['Read'] | null>;
|
|
31
32
|
getServerUserById(userId: string): Promise<Result<UsersCrud['Server']['Read']>>;
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
listServerTeamPermissions(options: {
|
|
34
|
+
userId?: string;
|
|
35
|
+
teamId?: string;
|
|
34
36
|
recursive: boolean;
|
|
35
37
|
}, session: InternalSession): Promise<TeamPermissionsCrud['Server']['Read'][]>;
|
|
36
|
-
listServerCurrentUserTeams(session: InternalSession): Promise<TeamsCrud['Server']['Read'][]>;
|
|
37
38
|
listServerUsers(): Promise<UsersCrud['Server']['Read'][]>;
|
|
38
|
-
listServerTeams(
|
|
39
|
+
listServerTeams(options?: {
|
|
40
|
+
userId?: string;
|
|
41
|
+
}): Promise<TeamsCrud['Server']['Read'][]>;
|
|
39
42
|
listServerTeamUsers(teamId: string): Promise<UsersCrud['Server']['Read'][]>;
|
|
40
43
|
createServerTeam(data: TeamsCrud['Server']['Create'], session?: InternalSession): Promise<TeamsCrud['Server']['Read']>;
|
|
41
44
|
updateServerTeam(teamId: string, data: TeamsCrud['Server']['Update']): Promise<TeamsCrud['Server']['Read']>;
|
|
@@ -49,6 +52,7 @@ export declare class StackServerInterface extends StackClientInterface {
|
|
|
49
52
|
teamId: string;
|
|
50
53
|
}): Promise<void>;
|
|
51
54
|
updateServerUser(userId: string, update: UsersCrud['Server']['Update']): Promise<UsersCrud['Server']['Read']>;
|
|
55
|
+
createServerProviderAccessToken(userId: string, provider: string, scope: string): Promise<ConnectedAccountAccessTokenCrud['Server']['Read']>;
|
|
52
56
|
createServerUserSession(userId: string, expiresInMillis: number): Promise<{
|
|
53
57
|
accessToken: string;
|
|
54
58
|
refreshToken: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { KnownErrors } from "../known-errors";
|
|
2
2
|
import { StackAssertionError } from "../utils/errors";
|
|
3
|
+
import { filterUndefined } from "../utils/objects";
|
|
3
4
|
import { Result } from "../utils/results";
|
|
4
5
|
import { StackClientInterface } from "./clientInterface";
|
|
5
6
|
export class StackServerInterface extends StackClientInterface {
|
|
@@ -52,13 +53,12 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
52
53
|
return Result.error(new Error("Failed to get user"));
|
|
53
54
|
return Result.ok(user);
|
|
54
55
|
}
|
|
55
|
-
async
|
|
56
|
-
const response = await this.sendServerRequest(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const response = await this.sendServerRequest("/teams?user_id=me", {}, session);
|
|
56
|
+
async listServerTeamPermissions(options, session) {
|
|
57
|
+
const response = await this.sendServerRequest("/team-permissions?" + new URLSearchParams(filterUndefined({
|
|
58
|
+
user_id: options.userId,
|
|
59
|
+
team_id: options.teamId,
|
|
60
|
+
recursive: options.recursive.toString(),
|
|
61
|
+
})), {}, session);
|
|
62
62
|
const result = await response.json();
|
|
63
63
|
return result.items;
|
|
64
64
|
}
|
|
@@ -67,8 +67,10 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
67
67
|
const result = await response.json();
|
|
68
68
|
return result.items;
|
|
69
69
|
}
|
|
70
|
-
async listServerTeams() {
|
|
71
|
-
const response = await this.sendServerRequest("/teams"
|
|
70
|
+
async listServerTeams(options) {
|
|
71
|
+
const response = await this.sendServerRequest("/teams?" + new URLSearchParams(filterUndefined({
|
|
72
|
+
user_id: options?.userId,
|
|
73
|
+
})), {}, null);
|
|
72
74
|
const result = await response.json();
|
|
73
75
|
return result.items;
|
|
74
76
|
}
|
|
@@ -130,6 +132,16 @@ export class StackServerInterface extends StackClientInterface {
|
|
|
130
132
|
}, null);
|
|
131
133
|
return await response.json();
|
|
132
134
|
}
|
|
135
|
+
async createServerProviderAccessToken(userId, provider, scope) {
|
|
136
|
+
const response = await this.sendServerRequest(`/connected-accounts/${userId}/${provider}/access-token`, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
headers: {
|
|
139
|
+
"content-type": "application/json",
|
|
140
|
+
},
|
|
141
|
+
body: JSON.stringify({ scope }),
|
|
142
|
+
}, null);
|
|
143
|
+
return await response.json();
|
|
144
|
+
}
|
|
133
145
|
async createServerUserSession(userId, expiresInMillis) {
|
|
134
146
|
const response = await this.sendServerRequest("/auth/sessions", {
|
|
135
147
|
method: "POST",
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import * as yup from "yup";
|
|
2
|
+
export type WebhookEvent<S extends yup.Schema> = {
|
|
3
|
+
type: string;
|
|
4
|
+
schema: S;
|
|
5
|
+
metadata: {
|
|
6
|
+
summary: string;
|
|
7
|
+
description: string;
|
|
8
|
+
tags?: string[];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const webhookEvents: readonly [{
|
|
12
|
+
type: string;
|
|
13
|
+
schema: yup.ObjectSchema<{
|
|
14
|
+
id: string;
|
|
15
|
+
primary_email: string | null;
|
|
16
|
+
primary_email_verified: NonNullable<boolean | undefined>;
|
|
17
|
+
display_name: string | null;
|
|
18
|
+
selected_team: {
|
|
19
|
+
id: string;
|
|
20
|
+
created_at_millis: number;
|
|
21
|
+
display_name: string;
|
|
22
|
+
profile_image_url: string | null;
|
|
23
|
+
} | null;
|
|
24
|
+
selected_team_id: string | null;
|
|
25
|
+
profile_image_url: string | null;
|
|
26
|
+
signed_up_at_millis: number;
|
|
27
|
+
has_password: NonNullable<boolean | undefined>;
|
|
28
|
+
auth_with_email: NonNullable<boolean | undefined>;
|
|
29
|
+
oauth_providers: {
|
|
30
|
+
email?: string | null | undefined;
|
|
31
|
+
id: string;
|
|
32
|
+
account_id: string;
|
|
33
|
+
}[];
|
|
34
|
+
client_metadata: {} | null;
|
|
35
|
+
server_metadata: {} | null;
|
|
36
|
+
}, yup.AnyObject, {
|
|
37
|
+
id: undefined;
|
|
38
|
+
primary_email: undefined;
|
|
39
|
+
primary_email_verified: undefined;
|
|
40
|
+
display_name: undefined;
|
|
41
|
+
selected_team: {
|
|
42
|
+
id: undefined;
|
|
43
|
+
display_name: undefined;
|
|
44
|
+
profile_image_url: undefined;
|
|
45
|
+
created_at_millis: undefined;
|
|
46
|
+
};
|
|
47
|
+
selected_team_id: undefined;
|
|
48
|
+
profile_image_url: undefined;
|
|
49
|
+
signed_up_at_millis: undefined;
|
|
50
|
+
has_password: undefined;
|
|
51
|
+
auth_with_email: undefined;
|
|
52
|
+
oauth_providers: undefined;
|
|
53
|
+
client_metadata: undefined;
|
|
54
|
+
server_metadata: undefined;
|
|
55
|
+
}, "">;
|
|
56
|
+
metadata: {
|
|
57
|
+
summary: string;
|
|
58
|
+
description: string;
|
|
59
|
+
tags: string[];
|
|
60
|
+
};
|
|
61
|
+
}, {
|
|
62
|
+
type: string;
|
|
63
|
+
schema: yup.ObjectSchema<{
|
|
64
|
+
id: string;
|
|
65
|
+
primary_email: string | null;
|
|
66
|
+
primary_email_verified: NonNullable<boolean | undefined>;
|
|
67
|
+
display_name: string | null;
|
|
68
|
+
selected_team: {
|
|
69
|
+
id: string;
|
|
70
|
+
created_at_millis: number;
|
|
71
|
+
display_name: string;
|
|
72
|
+
profile_image_url: string | null;
|
|
73
|
+
} | null;
|
|
74
|
+
selected_team_id: string | null;
|
|
75
|
+
profile_image_url: string | null;
|
|
76
|
+
signed_up_at_millis: number;
|
|
77
|
+
has_password: NonNullable<boolean | undefined>;
|
|
78
|
+
auth_with_email: NonNullable<boolean | undefined>;
|
|
79
|
+
oauth_providers: {
|
|
80
|
+
email?: string | null | undefined;
|
|
81
|
+
id: string;
|
|
82
|
+
account_id: string;
|
|
83
|
+
}[];
|
|
84
|
+
client_metadata: {} | null;
|
|
85
|
+
server_metadata: {} | null;
|
|
86
|
+
}, yup.AnyObject, {
|
|
87
|
+
id: undefined;
|
|
88
|
+
primary_email: undefined;
|
|
89
|
+
primary_email_verified: undefined;
|
|
90
|
+
display_name: undefined;
|
|
91
|
+
selected_team: {
|
|
92
|
+
id: undefined;
|
|
93
|
+
display_name: undefined;
|
|
94
|
+
profile_image_url: undefined;
|
|
95
|
+
created_at_millis: undefined;
|
|
96
|
+
};
|
|
97
|
+
selected_team_id: undefined;
|
|
98
|
+
profile_image_url: undefined;
|
|
99
|
+
signed_up_at_millis: undefined;
|
|
100
|
+
has_password: undefined;
|
|
101
|
+
auth_with_email: undefined;
|
|
102
|
+
oauth_providers: undefined;
|
|
103
|
+
client_metadata: undefined;
|
|
104
|
+
server_metadata: undefined;
|
|
105
|
+
}, "">;
|
|
106
|
+
metadata: {
|
|
107
|
+
summary: string;
|
|
108
|
+
description: string;
|
|
109
|
+
tags: string[];
|
|
110
|
+
};
|
|
111
|
+
}, {
|
|
112
|
+
type: string;
|
|
113
|
+
schema: yup.ObjectSchema<{
|
|
114
|
+
id: string;
|
|
115
|
+
}, yup.AnyObject, {
|
|
116
|
+
id: undefined;
|
|
117
|
+
}, "">;
|
|
118
|
+
metadata: {
|
|
119
|
+
summary: string;
|
|
120
|
+
description: string;
|
|
121
|
+
tags: string[];
|
|
122
|
+
};
|
|
123
|
+
}, {
|
|
124
|
+
type: string;
|
|
125
|
+
schema: yup.ObjectSchema<{
|
|
126
|
+
id: string;
|
|
127
|
+
display_name: string;
|
|
128
|
+
profile_image_url: string | null;
|
|
129
|
+
} & {
|
|
130
|
+
created_at_millis: number;
|
|
131
|
+
}, yup.AnyObject, {
|
|
132
|
+
id: undefined;
|
|
133
|
+
display_name: undefined;
|
|
134
|
+
profile_image_url: undefined;
|
|
135
|
+
created_at_millis: undefined;
|
|
136
|
+
}, "">;
|
|
137
|
+
metadata: {
|
|
138
|
+
summary: string;
|
|
139
|
+
description: string;
|
|
140
|
+
tags: string[];
|
|
141
|
+
};
|
|
142
|
+
}, {
|
|
143
|
+
type: string;
|
|
144
|
+
schema: yup.ObjectSchema<{
|
|
145
|
+
id: string;
|
|
146
|
+
display_name: string;
|
|
147
|
+
profile_image_url: string | null;
|
|
148
|
+
} & {
|
|
149
|
+
created_at_millis: number;
|
|
150
|
+
}, yup.AnyObject, {
|
|
151
|
+
id: undefined;
|
|
152
|
+
display_name: undefined;
|
|
153
|
+
profile_image_url: undefined;
|
|
154
|
+
created_at_millis: undefined;
|
|
155
|
+
}, "">;
|
|
156
|
+
metadata: {
|
|
157
|
+
summary: string;
|
|
158
|
+
description: string;
|
|
159
|
+
tags: string[];
|
|
160
|
+
};
|
|
161
|
+
}, {
|
|
162
|
+
type: string;
|
|
163
|
+
schema: yup.ObjectSchema<{
|
|
164
|
+
id: string;
|
|
165
|
+
}, yup.AnyObject, {
|
|
166
|
+
id: undefined;
|
|
167
|
+
}, "">;
|
|
168
|
+
metadata: {
|
|
169
|
+
summary: string;
|
|
170
|
+
description: string;
|
|
171
|
+
tags: string[];
|
|
172
|
+
};
|
|
173
|
+
}];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { teamCreatedWebhookEvent, teamDeletedWebhookEvent, teamUpdatedWebhookEvent } from "./crud/teams";
|
|
2
|
+
import { userCreatedWebhookEvent, userDeletedWebhookEvent, userUpdatedWebhookEvent } from "./crud/users";
|
|
3
|
+
export const webhookEvents = [
|
|
4
|
+
userCreatedWebhookEvent,
|
|
5
|
+
userUpdatedWebhookEvent,
|
|
6
|
+
userDeletedWebhookEvent,
|
|
7
|
+
teamCreatedWebhookEvent,
|
|
8
|
+
teamUpdatedWebhookEvent,
|
|
9
|
+
teamDeletedWebhookEvent,
|
|
10
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackframe/stack-shared",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.15",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"jose": "^5.2.2",
|
|
37
37
|
"oauth4webapi": "^2.10.3",
|
|
38
38
|
"uuid": "^9.0.1",
|
|
39
|
-
"@stackframe/stack-sc": "2.5.
|
|
39
|
+
"@stackframe/stack-sc": "2.5.15"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"rimraf": "^5.0.5",
|