@stackframe/stack-shared 2.6.11 → 2.6.12

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @stackframe/stack-shared
2
2
 
3
+ ## 2.6.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated account settings page
8
+ - Updated dependencies
9
+ - @stackframe/stack-sc@2.6.12
10
+
3
11
  ## 2.6.11
4
12
 
5
13
  ### Patch Changes
@@ -2,6 +2,7 @@ import { KnownErrors } from '../known-errors';
2
2
  import { AccessToken, InternalSession, RefreshToken } from '../sessions';
3
3
  import { ReadonlyJson } from '../utils/json';
4
4
  import { Result } from "../utils/results";
5
+ import { ContactChannelsCrud } from './crud/contact-channels';
5
6
  import { CurrentUserCrud } from './crud/current-user';
6
7
  import { ConnectedAccountAccessTokenCrud } from './crud/oauth';
7
8
  import { InternalProjectsCrud, ProjectsCrud } from './crud/projects';
@@ -67,6 +68,9 @@ export declare class StackClientInterface {
67
68
  oldPassword: string;
68
69
  newPassword: string;
69
70
  }, session: InternalSession): Promise<KnownErrors["PasswordConfirmationMismatch"] | KnownErrors["PasswordRequirementsNotMet"] | undefined>;
71
+ setPassword(options: {
72
+ password: string;
73
+ }, session: InternalSession): Promise<KnownErrors["PasswordRequirementsNotMet"] | undefined>;
70
74
  verifyPasswordResetCode(code: string): Promise<Result<undefined, KnownErrors["VerificationCodeError"]>>;
71
75
  verifyEmail(code: string): Promise<Result<undefined, KnownErrors["VerificationCodeError"]>>;
72
76
  sendTeamInvitation(options: {
@@ -158,4 +162,9 @@ export declare class StackClientInterface {
158
162
  createProviderAccessToken(provider: string, scope: string, session: InternalSession): Promise<ConnectedAccountAccessTokenCrud['Client']['Read']>;
159
163
  createClientTeam(data: TeamsCrud['Client']['Create'], session: InternalSession): Promise<TeamsCrud['Client']['Read']>;
160
164
  deleteCurrentUser(session: InternalSession): Promise<void>;
165
+ createClientContactChannel(data: ContactChannelsCrud['Client']['Create'], session: InternalSession): Promise<ContactChannelsCrud['Client']['Read']>;
166
+ updateClientContactChannel(id: string, data: ContactChannelsCrud['Client']['Update'], session: InternalSession): Promise<ContactChannelsCrud['Client']['Read']>;
167
+ deleteClientContactChannel(id: string, session: InternalSession): Promise<void>;
168
+ listClientContactChannels(session: InternalSession): Promise<ContactChannelsCrud['Client']['Read'][]>;
169
+ sendCurrentUserContactChannelVerificationEmail(contactChannelId: string, callbackUrl: string, session: InternalSession): Promise<Result<undefined, KnownErrors["EmailAlreadyVerified"]>>;
161
170
  }
@@ -375,6 +375,18 @@ export class StackClientInterface {
375
375
  return res.error;
376
376
  }
377
377
  }
378
+ async setPassword(options, session) {
379
+ const res = await this.sendClientRequestAndCatchKnownError("/auth/password/set", {
380
+ method: "POST",
381
+ headers: {
382
+ "Content-Type": "application/json"
383
+ },
384
+ body: JSON.stringify(options),
385
+ }, session, [KnownErrors.PasswordRequirementsNotMet]);
386
+ if (res.status === "error") {
387
+ return res.error;
388
+ }
389
+ }
378
390
  async verifyPasswordResetCode(code) {
379
391
  const res = await this.resetPassword({ code, onlyVerifyCode: true });
380
392
  if (res.status === "error") {
@@ -747,4 +759,49 @@ export class StackClientInterface {
747
759
  method: "DELETE",
748
760
  }, session);
749
761
  }
762
+ async createClientContactChannel(data, session) {
763
+ const response = await this.sendClientRequest("/contact-channels", {
764
+ method: "POST",
765
+ headers: {
766
+ "content-type": "application/json",
767
+ },
768
+ body: JSON.stringify(data),
769
+ }, session);
770
+ return await response.json();
771
+ }
772
+ async updateClientContactChannel(id, data, session) {
773
+ const response = await this.sendClientRequest(`/contact-channels/me/${id}`, {
774
+ method: "PATCH",
775
+ headers: {
776
+ "content-type": "application/json",
777
+ },
778
+ body: JSON.stringify(data),
779
+ }, session);
780
+ return await response.json();
781
+ }
782
+ async deleteClientContactChannel(id, session) {
783
+ await this.sendClientRequest(`/contact-channels/me/${id}`, {
784
+ method: "DELETE",
785
+ }, session);
786
+ }
787
+ async listClientContactChannels(session) {
788
+ const response = await this.sendClientRequest("/contact-channels?user_id=me", {
789
+ method: "GET",
790
+ }, session);
791
+ const json = await response.json();
792
+ return json.items;
793
+ }
794
+ async sendCurrentUserContactChannelVerificationEmail(contactChannelId, callbackUrl, session) {
795
+ const responseOrError = await this.sendClientRequestAndCatchKnownError(`/contact-channels/me/${contactChannelId}/send-verification-code`, {
796
+ method: "POST",
797
+ headers: {
798
+ "content-type": "application/json",
799
+ },
800
+ body: JSON.stringify({ callback_url: callbackUrl }),
801
+ }, session, [KnownErrors.EmailAlreadyVerified]);
802
+ if (responseOrError.status === "error") {
803
+ return Result.error(responseOrError.error);
804
+ }
805
+ return Result.ok(undefined);
806
+ }
750
807
  }
@@ -13,6 +13,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
13
13
  client_metadata: {} | null;
14
14
  client_read_only_metadata: {} | null;
15
15
  primary_email_verified: NonNullable<boolean | undefined>;
16
+ otp_auth_enabled: NonNullable<boolean | undefined>;
16
17
  selected_team_id: string | null;
17
18
  signed_up_at_millis: number;
18
19
  has_password: NonNullable<boolean | undefined>;
@@ -30,6 +31,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
30
31
  id: undefined;
31
32
  primary_email: undefined;
32
33
  primary_email_verified: undefined;
34
+ primary_email_auth_enabled: undefined;
33
35
  display_name: undefined;
34
36
  selected_team: {
35
37
  id: undefined;
@@ -42,6 +44,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
42
44
  profile_image_url: undefined;
43
45
  signed_up_at_millis: undefined;
44
46
  has_password: undefined;
47
+ otp_auth_enabled: undefined;
45
48
  client_metadata: undefined;
46
49
  client_read_only_metadata: undefined;
47
50
  server_metadata: undefined;
@@ -54,6 +57,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
54
57
  id: string;
55
58
  primary_email: string | null;
56
59
  primary_email_verified: NonNullable<boolean | undefined>;
60
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
57
61
  display_name: string | null;
58
62
  selected_team: {
59
63
  client_metadata?: {} | null | undefined;
@@ -68,6 +72,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
68
72
  profile_image_url: string | null;
69
73
  signed_up_at_millis: number;
70
74
  has_password: NonNullable<boolean | undefined>;
75
+ otp_auth_enabled: NonNullable<boolean | undefined>;
71
76
  client_metadata: {} | null;
72
77
  client_read_only_metadata: {} | null;
73
78
  server_metadata: {} | null;
@@ -83,6 +88,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
83
88
  id: undefined;
84
89
  primary_email: undefined;
85
90
  primary_email_verified: undefined;
91
+ primary_email_auth_enabled: undefined;
86
92
  display_name: undefined;
87
93
  selected_team: {
88
94
  id: undefined;
@@ -97,6 +103,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
97
103
  profile_image_url: undefined;
98
104
  signed_up_at_millis: undefined;
99
105
  has_password: undefined;
106
+ otp_auth_enabled: undefined;
100
107
  client_metadata: undefined;
101
108
  client_read_only_metadata: undefined;
102
109
  server_metadata: undefined;
@@ -109,6 +116,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
109
116
  display_name: string | null | undefined;
110
117
  profile_image_url: string | null | undefined;
111
118
  client_metadata: {} | null | undefined;
119
+ otp_auth_enabled: boolean | undefined;
112
120
  totp_secret_base64: string | null | undefined;
113
121
  selected_team_id: string | null | undefined;
114
122
  }, import("yup").AnyObject, {
@@ -121,6 +129,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
121
129
  primary_email_verified: undefined;
122
130
  primary_email_auth_enabled: undefined;
123
131
  password: undefined;
132
+ otp_auth_enabled: undefined;
124
133
  totp_secret_base64: undefined;
125
134
  selected_team_id: undefined;
126
135
  }, "">;
@@ -134,6 +143,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
134
143
  primary_email_verified: boolean | undefined;
135
144
  primary_email_auth_enabled: boolean | undefined;
136
145
  password: string | null | undefined;
146
+ otp_auth_enabled: boolean | undefined;
137
147
  totp_secret_base64: string | null | undefined;
138
148
  selected_team_id: string | null | undefined;
139
149
  }, import("yup").AnyObject, {
@@ -146,6 +156,7 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
146
156
  primary_email_verified: undefined;
147
157
  primary_email_auth_enabled: undefined;
148
158
  password: undefined;
159
+ otp_auth_enabled: undefined;
149
160
  totp_secret_base64: undefined;
150
161
  selected_team_id: undefined;
151
162
  }, "">;
@@ -8,6 +8,7 @@ const clientUpdateSchema = usersCrudServerUpdateSchema.pick([
8
8
  "client_metadata",
9
9
  "selected_team_id",
10
10
  "totp_secret_base64",
11
+ "otp_auth_enabled",
11
12
  ]).required();
12
13
  const serverUpdateSchema = usersCrudServerUpdateSchema;
13
14
  const clientReadSchema = usersCrudServerReadSchema.pick([
@@ -24,6 +25,7 @@ const clientReadSchema = usersCrudServerReadSchema.pick([
24
25
  "oauth_providers",
25
26
  "selected_team_id",
26
27
  "requires_totp_mfa",
28
+ "otp_auth_enabled",
27
29
  ]).concat(yupObject({
28
30
  selected_team: teamsCrudClientReadSchema.nullable().defined(),
29
31
  })).nullable().defined(); // TODO: next-release: make required
@@ -30,6 +30,8 @@ export declare const teamMemberProfilesCrudServerReadSchema: import("yup").Objec
30
30
  client_read_only_metadata: {} | null;
31
31
  server_metadata: {} | null;
32
32
  primary_email_verified: NonNullable<boolean | undefined>;
33
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
34
+ otp_auth_enabled: NonNullable<boolean | undefined>;
33
35
  selected_team_id: string | null;
34
36
  selected_team: {
35
37
  client_metadata?: {} | null | undefined;
@@ -55,6 +57,7 @@ export declare const teamMemberProfilesCrudServerReadSchema: import("yup").Objec
55
57
  id: undefined;
56
58
  primary_email: undefined;
57
59
  primary_email_verified: undefined;
60
+ primary_email_auth_enabled: undefined;
58
61
  display_name: undefined;
59
62
  selected_team: {
60
63
  id: undefined;
@@ -69,6 +72,7 @@ export declare const teamMemberProfilesCrudServerReadSchema: import("yup").Objec
69
72
  profile_image_url: undefined;
70
73
  signed_up_at_millis: undefined;
71
74
  has_password: undefined;
75
+ otp_auth_enabled: undefined;
72
76
  client_metadata: undefined;
73
77
  client_read_only_metadata: undefined;
74
78
  server_metadata: undefined;
@@ -117,6 +121,8 @@ export declare const teamMemberProfilesCrud: import("../../crud").CrudSchemaFrom
117
121
  client_read_only_metadata: {} | null;
118
122
  server_metadata: {} | null;
119
123
  primary_email_verified: NonNullable<boolean | undefined>;
124
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
125
+ otp_auth_enabled: NonNullable<boolean | undefined>;
120
126
  selected_team_id: string | null;
121
127
  selected_team: {
122
128
  client_metadata?: {} | null | undefined;
@@ -142,6 +148,7 @@ export declare const teamMemberProfilesCrud: import("../../crud").CrudSchemaFrom
142
148
  id: undefined;
143
149
  primary_email: undefined;
144
150
  primary_email_verified: undefined;
151
+ primary_email_auth_enabled: undefined;
145
152
  display_name: undefined;
146
153
  selected_team: {
147
154
  id: undefined;
@@ -156,6 +163,7 @@ export declare const teamMemberProfilesCrud: import("../../crud").CrudSchemaFrom
156
163
  profile_image_url: undefined;
157
164
  signed_up_at_millis: undefined;
158
165
  has_password: undefined;
166
+ otp_auth_enabled: undefined;
159
167
  client_metadata: undefined;
160
168
  client_read_only_metadata: undefined;
161
169
  server_metadata: undefined;
@@ -9,6 +9,7 @@ export declare const usersCrudServerUpdateSchema: import("yup").ObjectSchema<{
9
9
  primary_email_verified: boolean | undefined;
10
10
  primary_email_auth_enabled: boolean | undefined;
11
11
  password: string | null | undefined;
12
+ otp_auth_enabled: boolean | undefined;
12
13
  totp_secret_base64: string | null | undefined;
13
14
  selected_team_id: string | null | undefined;
14
15
  }, import("yup").AnyObject, {
@@ -21,6 +22,7 @@ export declare const usersCrudServerUpdateSchema: import("yup").ObjectSchema<{
21
22
  primary_email_verified: undefined;
22
23
  primary_email_auth_enabled: undefined;
23
24
  password: undefined;
25
+ otp_auth_enabled: undefined;
24
26
  totp_secret_base64: undefined;
25
27
  selected_team_id: undefined;
26
28
  }, "">;
@@ -28,6 +30,7 @@ export declare const usersCrudServerReadSchema: import("yup").ObjectSchema<{
28
30
  id: string;
29
31
  primary_email: string | null;
30
32
  primary_email_verified: NonNullable<boolean | undefined>;
33
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
31
34
  display_name: string | null;
32
35
  selected_team: {
33
36
  client_metadata?: {} | null | undefined;
@@ -42,6 +45,7 @@ export declare const usersCrudServerReadSchema: import("yup").ObjectSchema<{
42
45
  profile_image_url: string | null;
43
46
  signed_up_at_millis: number;
44
47
  has_password: NonNullable<boolean | undefined>;
48
+ otp_auth_enabled: NonNullable<boolean | undefined>;
45
49
  client_metadata: {} | null;
46
50
  client_read_only_metadata: {} | null;
47
51
  server_metadata: {} | null;
@@ -57,6 +61,7 @@ export declare const usersCrudServerReadSchema: import("yup").ObjectSchema<{
57
61
  id: undefined;
58
62
  primary_email: undefined;
59
63
  primary_email_verified: undefined;
64
+ primary_email_auth_enabled: undefined;
60
65
  display_name: undefined;
61
66
  selected_team: {
62
67
  id: undefined;
@@ -71,6 +76,7 @@ export declare const usersCrudServerReadSchema: import("yup").ObjectSchema<{
71
76
  profile_image_url: undefined;
72
77
  signed_up_at_millis: undefined;
73
78
  has_password: undefined;
79
+ otp_auth_enabled: undefined;
74
80
  client_metadata: undefined;
75
81
  client_read_only_metadata: undefined;
76
82
  server_metadata: undefined;
@@ -89,6 +95,7 @@ export declare const usersCrudServerCreateSchema: import("yup").ObjectSchema<{
89
95
  server_metadata: {} | null | undefined;
90
96
  primary_email_verified: boolean | undefined;
91
97
  primary_email_auth_enabled: boolean | undefined;
98
+ otp_auth_enabled: boolean | undefined;
92
99
  totp_secret_base64: string | null | undefined;
93
100
  } & {
94
101
  oauth_providers: {
@@ -106,6 +113,7 @@ export declare const usersCrudServerCreateSchema: import("yup").ObjectSchema<{
106
113
  primary_email_verified: undefined;
107
114
  primary_email_auth_enabled: undefined;
108
115
  password: undefined;
116
+ otp_auth_enabled: undefined;
109
117
  totp_secret_base64: undefined;
110
118
  selected_team_id: undefined;
111
119
  oauth_providers: undefined;
@@ -116,6 +124,7 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
116
124
  id: string;
117
125
  primary_email: string | null;
118
126
  primary_email_verified: NonNullable<boolean | undefined>;
127
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
119
128
  display_name: string | null;
120
129
  selected_team: {
121
130
  client_metadata?: {} | null | undefined;
@@ -130,6 +139,7 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
130
139
  profile_image_url: string | null;
131
140
  signed_up_at_millis: number;
132
141
  has_password: NonNullable<boolean | undefined>;
142
+ otp_auth_enabled: NonNullable<boolean | undefined>;
133
143
  client_metadata: {} | null;
134
144
  client_read_only_metadata: {} | null;
135
145
  server_metadata: {} | null;
@@ -145,6 +155,7 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
145
155
  id: undefined;
146
156
  primary_email: undefined;
147
157
  primary_email_verified: undefined;
158
+ primary_email_auth_enabled: undefined;
148
159
  display_name: undefined;
149
160
  selected_team: {
150
161
  id: undefined;
@@ -159,6 +170,7 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
159
170
  profile_image_url: undefined;
160
171
  signed_up_at_millis: undefined;
161
172
  has_password: undefined;
173
+ otp_auth_enabled: undefined;
162
174
  client_metadata: undefined;
163
175
  client_read_only_metadata: undefined;
164
176
  server_metadata: undefined;
@@ -177,6 +189,7 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
177
189
  primary_email_verified: boolean | undefined;
178
190
  primary_email_auth_enabled: boolean | undefined;
179
191
  password: string | null | undefined;
192
+ otp_auth_enabled: boolean | undefined;
180
193
  totp_secret_base64: string | null | undefined;
181
194
  selected_team_id: string | null | undefined;
182
195
  }, import("yup").AnyObject, {
@@ -189,6 +202,7 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
189
202
  primary_email_verified: undefined;
190
203
  primary_email_auth_enabled: undefined;
191
204
  password: undefined;
205
+ otp_auth_enabled: undefined;
192
206
  totp_secret_base64: undefined;
193
207
  selected_team_id: undefined;
194
208
  }, "">;
@@ -202,6 +216,7 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
202
216
  server_metadata: {} | null | undefined;
203
217
  primary_email_verified: boolean | undefined;
204
218
  primary_email_auth_enabled: boolean | undefined;
219
+ otp_auth_enabled: boolean | undefined;
205
220
  totp_secret_base64: string | null | undefined;
206
221
  } & {
207
222
  oauth_providers: {
@@ -219,6 +234,7 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
219
234
  primary_email_verified: undefined;
220
235
  primary_email_auth_enabled: undefined;
221
236
  password: undefined;
237
+ otp_auth_enabled: undefined;
222
238
  totp_secret_base64: undefined;
223
239
  selected_team_id: undefined;
224
240
  oauth_providers: undefined;
@@ -259,6 +275,7 @@ export declare const userCreatedWebhookEvent: {
259
275
  id: string;
260
276
  primary_email: string | null;
261
277
  primary_email_verified: NonNullable<boolean | undefined>;
278
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
262
279
  display_name: string | null;
263
280
  selected_team: {
264
281
  client_metadata?: {} | null | undefined;
@@ -273,6 +290,7 @@ export declare const userCreatedWebhookEvent: {
273
290
  profile_image_url: string | null;
274
291
  signed_up_at_millis: number;
275
292
  has_password: NonNullable<boolean | undefined>;
293
+ otp_auth_enabled: NonNullable<boolean | undefined>;
276
294
  client_metadata: {} | null;
277
295
  client_read_only_metadata: {} | null;
278
296
  server_metadata: {} | null;
@@ -288,6 +306,7 @@ export declare const userCreatedWebhookEvent: {
288
306
  id: undefined;
289
307
  primary_email: undefined;
290
308
  primary_email_verified: undefined;
309
+ primary_email_auth_enabled: undefined;
291
310
  display_name: undefined;
292
311
  selected_team: {
293
312
  id: undefined;
@@ -302,6 +321,7 @@ export declare const userCreatedWebhookEvent: {
302
321
  profile_image_url: undefined;
303
322
  signed_up_at_millis: undefined;
304
323
  has_password: undefined;
324
+ otp_auth_enabled: undefined;
305
325
  client_metadata: undefined;
306
326
  client_read_only_metadata: undefined;
307
327
  server_metadata: undefined;
@@ -322,6 +342,7 @@ export declare const userUpdatedWebhookEvent: {
322
342
  id: string;
323
343
  primary_email: string | null;
324
344
  primary_email_verified: NonNullable<boolean | undefined>;
345
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
325
346
  display_name: string | null;
326
347
  selected_team: {
327
348
  client_metadata?: {} | null | undefined;
@@ -336,6 +357,7 @@ export declare const userUpdatedWebhookEvent: {
336
357
  profile_image_url: string | null;
337
358
  signed_up_at_millis: number;
338
359
  has_password: NonNullable<boolean | undefined>;
360
+ otp_auth_enabled: NonNullable<boolean | undefined>;
339
361
  client_metadata: {} | null;
340
362
  client_read_only_metadata: {} | null;
341
363
  server_metadata: {} | null;
@@ -351,6 +373,7 @@ export declare const userUpdatedWebhookEvent: {
351
373
  id: undefined;
352
374
  primary_email: undefined;
353
375
  primary_email_verified: undefined;
376
+ primary_email_auth_enabled: undefined;
354
377
  display_name: undefined;
355
378
  selected_team: {
356
379
  id: undefined;
@@ -365,6 +388,7 @@ export declare const userUpdatedWebhookEvent: {
365
388
  profile_image_url: undefined;
366
389
  signed_up_at_millis: undefined;
367
390
  has_password: undefined;
391
+ otp_auth_enabled: undefined;
368
392
  client_metadata: undefined;
369
393
  client_read_only_metadata: undefined;
370
394
  server_metadata: undefined;
@@ -9,29 +9,24 @@ export const usersCrudServerUpdateSchema = fieldSchema.yupObject({
9
9
  server_metadata: fieldSchema.userServerMetadataSchema.optional(),
10
10
  primary_email: fieldSchema.primaryEmailSchema.nullable().optional(),
11
11
  primary_email_verified: fieldSchema.primaryEmailVerifiedSchema.optional(),
12
- 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 } }),
13
- password: fieldSchema.yupString().nullable().meta({ openapiField: { description: 'A new password for the user, overwriting the old one (if it exists). Specifying this option revokes all current sessions.', exampleValue: 'my-new-password' } }),
14
- totp_secret_base64: fieldSchema.base64Schema.nullable().meta({ openapiField: { description: 'A TOTP secret for the user, overwriting the old one (if it exists). Set to null to disable 2FA.', exampleValue: 'dG90cC1zZWNyZXQ=' } }),
12
+ primary_email_auth_enabled: fieldSchema.primaryEmailAuthEnabledSchema.optional(),
13
+ password: fieldSchema.userPasswordMutationSchema.optional(),
14
+ otp_auth_enabled: fieldSchema.userOtpAuthEnabledMutationSchema.optional(),
15
+ totp_secret_base64: fieldSchema.userTotpSecretMutationSchema.optional(),
15
16
  selected_team_id: fieldSchema.selectedTeamIdSchema.nullable().optional(),
16
17
  }).required();
17
- const contactChannelSchema = fieldSchema.yupObject({
18
- id: fieldSchema.yupString().required(),
19
- type: fieldSchema.yupString().required(),
20
- value: fieldSchema.yupString().required(),
21
- is_primary: fieldSchema.yupBoolean().required(),
22
- is_verified: fieldSchema.yupBoolean().required(),
23
- used_for_auth: fieldSchema.yupBoolean().required(),
24
- }).required();
25
18
  export const usersCrudServerReadSchema = fieldSchema.yupObject({
26
19
  id: fieldSchema.userIdSchema.required(),
27
20
  primary_email: fieldSchema.primaryEmailSchema.nullable().defined(),
28
21
  primary_email_verified: fieldSchema.primaryEmailVerifiedSchema.required(),
22
+ primary_email_auth_enabled: fieldSchema.primaryEmailAuthEnabledSchema.required(),
29
23
  display_name: fieldSchema.userDisplayNameSchema.nullable().defined(),
30
24
  selected_team: teamsCrudServerReadSchema.nullable().defined(),
31
25
  selected_team_id: fieldSchema.selectedTeamIdSchema.nullable().defined(),
32
26
  profile_image_url: fieldSchema.profileImageUrlSchema.nullable().defined(),
33
27
  signed_up_at_millis: fieldSchema.signedUpAtMillisSchema.required(),
34
- has_password: fieldSchema.yupBoolean().required().meta({ openapiField: { description: 'Whether the user has a password associated with their account', exampleValue: true } }),
28
+ has_password: fieldSchema.userHasPasswordSchema.required(),
29
+ otp_auth_enabled: fieldSchema.userOtpAuthEnabledSchema.required(),
35
30
  client_metadata: fieldSchema.userClientMetadataSchema,
36
31
  client_read_only_metadata: fieldSchema.userClientReadOnlyMetadataSchema,
37
32
  server_metadata: fieldSchema.userServerMetadataSchema,
@@ -2,6 +2,7 @@ import { KnownErrors } from "../known-errors";
2
2
  import { AccessToken, InternalSession, RefreshToken } from "../sessions";
3
3
  import { Result } from "../utils/results";
4
4
  import { ClientInterfaceOptions, StackClientInterface } from "./clientInterface";
5
+ import { ContactChannelsCrud } from "./crud/contact-channels";
5
6
  import { CurrentUserCrud } from "./crud/current-user";
6
7
  import { ConnectedAccountAccessTokenCrud } from "./crud/oauth";
7
8
  import { TeamMemberProfilesCrud } from "./crud/team-member-profiles";
@@ -73,4 +74,9 @@ export declare class StackServerInterface extends StackClientInterface {
73
74
  grantServerTeamUserPermission(teamId: string, userId: string, permissionId: string): Promise<void>;
74
75
  revokeServerTeamUserPermission(teamId: string, userId: string, permissionId: string): Promise<void>;
75
76
  deleteServerServerUser(userId: string): Promise<void>;
77
+ createServerContactChannel(data: ContactChannelsCrud['Server']['Create']): Promise<ContactChannelsCrud['Server']['Read']>;
78
+ updateServerContactChannel(userId: string, contactChannelId: string, data: ContactChannelsCrud['Server']['Update']): Promise<ContactChannelsCrud['Server']['Read']>;
79
+ deleteServerContactChannel(userId: string, contactChannelId: string): Promise<void>;
80
+ listServerContactChannels(userId: string): Promise<ContactChannelsCrud['Server']['Read'][]>;
81
+ sendServerContactChannelVerificationEmail(userId: string, contactChannelId: string, callbackUrl: string): Promise<Result<undefined, KnownErrors["EmailAlreadyVerified"]>>;
76
82
  }
@@ -214,4 +214,49 @@ export class StackServerInterface extends StackClientInterface {
214
214
  body: JSON.stringify({}),
215
215
  }, null);
216
216
  }
217
+ async createServerContactChannel(data) {
218
+ const response = await this.sendServerRequest("/contact-channels", {
219
+ method: "POST",
220
+ headers: {
221
+ "content-type": "application/json",
222
+ },
223
+ body: JSON.stringify(data),
224
+ }, null);
225
+ return await response.json();
226
+ }
227
+ async updateServerContactChannel(userId, contactChannelId, data) {
228
+ const response = await this.sendServerRequest(`/contact-channels/${userId}/${contactChannelId}`, {
229
+ method: "PATCH",
230
+ headers: {
231
+ "content-type": "application/json",
232
+ },
233
+ body: JSON.stringify(data),
234
+ }, null);
235
+ return await response.json();
236
+ }
237
+ async deleteServerContactChannel(userId, contactChannelId) {
238
+ await this.sendServerRequest(`/contact-channels/${userId}/${contactChannelId}`, {
239
+ method: "DELETE",
240
+ }, null);
241
+ }
242
+ async listServerContactChannels(userId) {
243
+ const response = await this.sendServerRequest(`/contact-channels?user_id=${userId}`, {
244
+ method: "GET",
245
+ }, null);
246
+ const json = await response.json();
247
+ return json.items;
248
+ }
249
+ async sendServerContactChannelVerificationEmail(userId, contactChannelId, callbackUrl) {
250
+ const responseOrError = await this.sendServerRequestAndCatchKnownError(`/contact-channels/${userId}/${contactChannelId}/send-verification-code`, {
251
+ method: "POST",
252
+ headers: {
253
+ "content-type": "application/json",
254
+ },
255
+ body: JSON.stringify({ callback_url: callbackUrl }),
256
+ }, null, [KnownErrors.EmailAlreadyVerified]);
257
+ if (responseOrError.status === "error") {
258
+ return Result.error(responseOrError.error);
259
+ }
260
+ return Result.ok(undefined);
261
+ }
217
262
  }
@@ -14,6 +14,7 @@ export declare const webhookEvents: readonly [{
14
14
  id: string;
15
15
  primary_email: string | null;
16
16
  primary_email_verified: NonNullable<boolean | undefined>;
17
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
17
18
  display_name: string | null;
18
19
  selected_team: {
19
20
  client_metadata?: {} | null | undefined;
@@ -28,6 +29,7 @@ export declare const webhookEvents: readonly [{
28
29
  profile_image_url: string | null;
29
30
  signed_up_at_millis: number;
30
31
  has_password: NonNullable<boolean | undefined>;
32
+ otp_auth_enabled: NonNullable<boolean | undefined>;
31
33
  client_metadata: {} | null;
32
34
  client_read_only_metadata: {} | null;
33
35
  server_metadata: {} | null;
@@ -43,6 +45,7 @@ export declare const webhookEvents: readonly [{
43
45
  id: undefined;
44
46
  primary_email: undefined;
45
47
  primary_email_verified: undefined;
48
+ primary_email_auth_enabled: undefined;
46
49
  display_name: undefined;
47
50
  selected_team: {
48
51
  id: undefined;
@@ -57,6 +60,7 @@ export declare const webhookEvents: readonly [{
57
60
  profile_image_url: undefined;
58
61
  signed_up_at_millis: undefined;
59
62
  has_password: undefined;
63
+ otp_auth_enabled: undefined;
60
64
  client_metadata: undefined;
61
65
  client_read_only_metadata: undefined;
62
66
  server_metadata: undefined;
@@ -76,6 +80,7 @@ export declare const webhookEvents: readonly [{
76
80
  id: string;
77
81
  primary_email: string | null;
78
82
  primary_email_verified: NonNullable<boolean | undefined>;
83
+ primary_email_auth_enabled: NonNullable<boolean | undefined>;
79
84
  display_name: string | null;
80
85
  selected_team: {
81
86
  client_metadata?: {} | null | undefined;
@@ -90,6 +95,7 @@ export declare const webhookEvents: readonly [{
90
95
  profile_image_url: string | null;
91
96
  signed_up_at_millis: number;
92
97
  has_password: NonNullable<boolean | undefined>;
98
+ otp_auth_enabled: NonNullable<boolean | undefined>;
93
99
  client_metadata: {} | null;
94
100
  client_read_only_metadata: {} | null;
95
101
  server_metadata: {} | null;
@@ -105,6 +111,7 @@ export declare const webhookEvents: readonly [{
105
111
  id: undefined;
106
112
  primary_email: undefined;
107
113
  primary_email_verified: undefined;
114
+ primary_email_auth_enabled: undefined;
108
115
  display_name: undefined;
109
116
  selected_team: {
110
117
  id: undefined;
@@ -119,6 +126,7 @@ export declare const webhookEvents: readonly [{
119
126
  profile_image_url: undefined;
120
127
  signed_up_at_millis: undefined;
121
128
  has_password: undefined;
129
+ otp_auth_enabled: undefined;
122
130
  client_metadata: undefined;
123
131
  client_read_only_metadata: undefined;
124
132
  server_metadata: undefined;
@@ -64,6 +64,7 @@ export declare class ReplaceFieldWithOwnUserId extends Error {
64
64
  export declare const userIdOrMeSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
65
65
  export declare const userIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
66
66
  export declare const primaryEmailSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
67
+ export declare const primaryEmailAuthEnabledSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
67
68
  export declare const primaryEmailVerifiedSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
68
69
  export declare const userDisplayNameSchema: yup.StringSchema<string | null | undefined, yup.AnyObject, undefined, "">;
69
70
  export declare const selectedTeamIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
@@ -82,6 +83,11 @@ export declare const userOAuthProviderSchema: yup.ObjectSchema<{
82
83
  provider_user_id: undefined;
83
84
  }, "">;
84
85
  export declare const userLastActiveAtMillisSchema: yup.NumberSchema<number | null | undefined, yup.AnyObject, undefined, "">;
86
+ export declare const userOtpAuthEnabledSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
87
+ export declare const userOtpAuthEnabledMutationSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
88
+ export declare const userHasPasswordSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
89
+ export declare const userPasswordMutationSchema: yup.StringSchema<string | null | undefined, yup.AnyObject, undefined, "">;
90
+ export declare const userTotpSecretMutationSchema: yup.StringSchema<string | null | undefined, yup.AnyObject, undefined, "">;
85
91
  export declare const signInEmailSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
86
92
  export declare const emailOtpSignInCallbackUrlSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
87
93
  export declare const emailVerificationCallbackUrlSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
@@ -248,6 +248,7 @@ export const userIdOrMeSchema = yupString().uuid().transform(v => {
248
248
  }).meta({ openapiField: { description: 'The ID of the user, or the special value `me` for the currently authenticated user', exampleValue: '3241a285-8329-4d69-8f3d-316e08cf140c' } });
249
249
  export const userIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('user'), exampleValue: '3241a285-8329-4d69-8f3d-316e08cf140c' } });
250
250
  export const primaryEmailSchema = emailSchema.meta({ openapiField: { description: 'Primary email', exampleValue: 'johndoe@example.com' } });
251
+ export const primaryEmailAuthEnabledSchema = yupBoolean().meta({ openapiField: { description: 'Whether the primary email is used for authentication. If this is set to `false`, the user will not be able to sign in with the primary email with password or OTP', exampleValue: true } });
251
252
  export const primaryEmailVerifiedSchema = yupBoolean().meta({ openapiField: { description: 'Whether the primary email has been verified to belong to this user', exampleValue: true } });
252
253
  export const userDisplayNameSchema = yupString().nullable().meta({ openapiField: { description: _displayNameDescription('user'), exampleValue: 'John Doe' } });
253
254
  export const selectedTeamIdSchema = yupString().uuid().meta({ openapiField: { description: 'ID of the team currently selected by the user', exampleValue: 'team-id' } });
@@ -262,6 +263,11 @@ export const userOAuthProviderSchema = yupObject({
262
263
  provider_user_id: yupString().required(),
263
264
  });
264
265
  export const userLastActiveAtMillisSchema = yupNumber().nullable().meta({ openapiField: { description: _lastActiveAtMillisDescription, exampleValue: 1630000000000 } });
266
+ export const userOtpAuthEnabledSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has OTP/magic link enabled. ', exampleValue: true } });
267
+ export const userOtpAuthEnabledMutationSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has OTP/magic link enabled. Note that only accounts with verified emails can sign-in with OTP.', exampleValue: true } });
268
+ export const userHasPasswordSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has a password set. If the user does not have a password set, they will not be able to sign in with email/password.', exampleValue: true } });
269
+ export const userPasswordMutationSchema = yupString().nullable().meta({ openapiField: { description: 'Sets the user\'s password. Doing so revokes all current sessions.', exampleValue: 'my-new-password' } });
270
+ export const userTotpSecretMutationSchema = base64Schema.nullable().meta({ openapiField: { description: 'Enables 2FA and sets a TOTP secret for the user. Set to null to disable 2FA.', exampleValue: 'dG90cC1zZWNyZXQ=' } });
265
271
  // Auth
266
272
  export const signInEmailSchema = emailSchema.meta({ openapiField: { description: 'The email to sign in with.', exampleValue: 'johndoe@example.com' } });
267
273
  export const emailOtpSignInCallbackUrlSchema = urlSchema.meta({ openapiField: { description: 'The base callback URL to construct the magic link from. A query parameter `code` with the verification code will be appended to it. The page should then make a request to the `/auth/otp/sign-in` endpoint.', exampleValue: 'https://example.com/handler/magic-link-callback' } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackframe/stack-shared",
3
- "version": "2.6.11",
3
+ "version": "2.6.12",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -38,7 +38,7 @@
38
38
  "oauth4webapi": "^2.10.3",
39
39
  "semver": "^7.6.3",
40
40
  "uuid": "^9.0.1",
41
- "@stackframe/stack-sc": "2.6.11"
41
+ "@stackframe/stack-sc": "2.6.12"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/bcrypt": "^5.0.2",