@stackframe/stack-shared 2.6.21 → 2.6.24

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.
@@ -3,11 +3,11 @@ import * as schemaFields from "../../schema-fields";
3
3
  import { yupMixed, yupObject } from "../../schema-fields";
4
4
  // =============== Team permissions =================
5
5
  export const teamPermissionsCrudClientReadSchema = yupObject({
6
- id: schemaFields.teamPermissionDefinitionIdSchema.required(),
7
- user_id: schemaFields.userIdSchema.required(),
8
- team_id: schemaFields.teamIdSchema.required(),
9
- }).required();
10
- export const teamPermissionsCrudServerCreateSchema = yupObject({}).required();
6
+ id: schemaFields.teamPermissionDefinitionIdSchema.defined(),
7
+ user_id: schemaFields.userIdSchema.defined(),
8
+ team_id: schemaFields.teamIdSchema.defined(),
9
+ }).defined();
10
+ export const teamPermissionsCrudServerCreateSchema = yupObject({}).defined();
11
11
  export const teamPermissionsCrudServerDeleteSchema = yupMixed();
12
12
  export const teamPermissionsCrud = createCrud({
13
13
  clientReadSchema: teamPermissionsCrudClientReadSchema,
@@ -38,20 +38,20 @@ export const teamPermissionsCrud = createCrud({
38
38
  });
39
39
  // =============== Team permission definitions =================
40
40
  export const teamPermissionDefinitionsCrudAdminReadSchema = yupObject({
41
- id: schemaFields.teamPermissionDefinitionIdSchema.required(),
41
+ id: schemaFields.teamPermissionDefinitionIdSchema.defined(),
42
42
  description: schemaFields.teamPermissionDescriptionSchema.optional(),
43
- contained_permission_ids: schemaFields.containedPermissionIdsSchema.required()
44
- }).required();
43
+ contained_permission_ids: schemaFields.containedPermissionIdsSchema.defined()
44
+ }).defined();
45
45
  export const teamPermissionDefinitionsCrudAdminCreateSchema = yupObject({
46
- id: schemaFields.customTeamPermissionDefinitionIdSchema.required(),
46
+ id: schemaFields.customTeamPermissionDefinitionIdSchema.defined(),
47
47
  description: schemaFields.teamPermissionDescriptionSchema.optional(),
48
48
  contained_permission_ids: schemaFields.containedPermissionIdsSchema.optional()
49
- }).required();
49
+ }).defined();
50
50
  export const teamPermissionDefinitionsCrudAdminUpdateSchema = yupObject({
51
51
  id: schemaFields.customTeamPermissionDefinitionIdSchema.optional(),
52
52
  description: schemaFields.teamPermissionDescriptionSchema.optional(),
53
53
  contained_permission_ids: schemaFields.containedPermissionIdsSchema.optional()
54
- }).required();
54
+ }).defined();
55
55
  export const teamPermissionDefinitionsCrudAdminDeleteSchema = yupMixed();
56
56
  export const teamPermissionDefinitionsCrud = createCrud({
57
57
  adminReadSchema: teamPermissionDefinitionsCrudAdminReadSchema,
@@ -3,35 +3,35 @@ import * as fieldSchema from "../../schema-fields";
3
3
  import { yupObject } from "../../schema-fields";
4
4
  // Read
5
5
  export const teamsCrudClientReadSchema = yupObject({
6
- id: fieldSchema.teamIdSchema.required(),
7
- display_name: fieldSchema.teamDisplayNameSchema.required(),
6
+ id: fieldSchema.teamIdSchema.defined(),
7
+ display_name: fieldSchema.teamDisplayNameSchema.defined(),
8
8
  profile_image_url: fieldSchema.teamProfileImageUrlSchema.nullable().defined(),
9
9
  client_metadata: fieldSchema.teamClientMetadataSchema.optional(),
10
10
  client_read_only_metadata: fieldSchema.teamClientReadOnlyMetadataSchema.optional(),
11
- }).required();
11
+ }).defined();
12
12
  export const teamsCrudServerReadSchema = teamsCrudClientReadSchema.concat(yupObject({
13
- created_at_millis: fieldSchema.teamCreatedAtMillisSchema.required(),
13
+ created_at_millis: fieldSchema.teamCreatedAtMillisSchema.defined(),
14
14
  server_metadata: fieldSchema.teamServerMetadataSchema.optional(),
15
- }).required());
15
+ }).defined());
16
16
  // Update
17
17
  export const teamsCrudClientUpdateSchema = yupObject({
18
18
  display_name: fieldSchema.teamDisplayNameSchema.optional(),
19
19
  profile_image_url: fieldSchema.teamProfileImageUrlSchema.nullable().optional(),
20
20
  client_metadata: fieldSchema.teamClientMetadataSchema.optional(),
21
- }).required();
21
+ }).defined();
22
22
  export const teamsCrudServerUpdateSchema = teamsCrudClientUpdateSchema.concat(yupObject({
23
23
  client_read_only_metadata: fieldSchema.teamClientReadOnlyMetadataSchema.optional(),
24
24
  server_metadata: fieldSchema.teamServerMetadataSchema.optional(),
25
- }).required());
25
+ }).defined());
26
26
  // Create
27
27
  export const teamsCrudClientCreateSchema = teamsCrudClientUpdateSchema.concat(yupObject({
28
- display_name: fieldSchema.teamDisplayNameSchema.required(),
28
+ display_name: fieldSchema.teamDisplayNameSchema.defined(),
29
29
  creator_user_id: fieldSchema.teamCreatorUserIdSchema.optional(),
30
- }).required());
30
+ }).defined());
31
31
  export const teamsCrudServerCreateSchema = teamsCrudServerUpdateSchema.concat(yupObject({
32
- display_name: fieldSchema.teamDisplayNameSchema.required(),
32
+ display_name: fieldSchema.teamDisplayNameSchema.defined(),
33
33
  creator_user_id: fieldSchema.teamCreatorUserIdSchema.optional(),
34
- }).required());
34
+ }).defined());
35
35
  // Delete
36
36
  export const teamsCrudClientDeleteSchema = fieldSchema.yupMixed();
37
37
  export const teamsCrudServerDeleteSchema = teamsCrudClientDeleteSchema;
@@ -118,8 +118,8 @@ export const teamUpdatedWebhookEvent = {
118
118
  },
119
119
  };
120
120
  const webhookTeamDeletedSchema = fieldSchema.yupObject({
121
- id: fieldSchema.userIdSchema.required(),
122
- }).required();
121
+ id: fieldSchema.userIdSchema.defined(),
122
+ }).defined();
123
123
  export const teamDeletedWebhookEvent = {
124
124
  type: "team.deleted",
125
125
  schema: webhookTeamDeletedSchema,
@@ -31,8 +31,8 @@ export declare const usersCrudServerUpdateSchema: import("yup").ObjectSchema<{
31
31
  export declare const usersCrudServerReadSchema: import("yup").ObjectSchema<{
32
32
  id: string;
33
33
  primary_email: string | null;
34
- primary_email_verified: NonNullable<boolean | undefined>;
35
- primary_email_auth_enabled: NonNullable<boolean | undefined>;
34
+ primary_email_verified: boolean;
35
+ primary_email_auth_enabled: boolean;
36
36
  display_name: string | null;
37
37
  selected_team: {
38
38
  client_metadata?: {} | null | undefined;
@@ -46,9 +46,9 @@ export declare const usersCrudServerReadSchema: import("yup").ObjectSchema<{
46
46
  selected_team_id: string | null;
47
47
  profile_image_url: string | null;
48
48
  signed_up_at_millis: number;
49
- has_password: NonNullable<boolean | undefined>;
50
- otp_auth_enabled: NonNullable<boolean | undefined>;
51
- passkey_auth_enabled: NonNullable<boolean | undefined>;
49
+ has_password: boolean;
50
+ otp_auth_enabled: boolean;
51
+ passkey_auth_enabled: boolean;
52
52
  client_metadata: {} | null;
53
53
  client_read_only_metadata: {} | null;
54
54
  server_metadata: {} | null;
@@ -58,8 +58,8 @@ export declare const usersCrudServerReadSchema: import("yup").ObjectSchema<{
58
58
  id: string;
59
59
  account_id: string;
60
60
  }[];
61
- auth_with_email: NonNullable<boolean | undefined>;
62
- requires_totp_mfa: NonNullable<boolean | undefined>;
61
+ auth_with_email: boolean;
62
+ requires_totp_mfa: boolean;
63
63
  }, import("yup").AnyObject, {
64
64
  id: undefined;
65
65
  primary_email: undefined;
@@ -129,8 +129,8 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
129
129
  serverReadSchema: import("yup").ObjectSchema<{
130
130
  id: string;
131
131
  primary_email: string | null;
132
- primary_email_verified: NonNullable<boolean | undefined>;
133
- primary_email_auth_enabled: NonNullable<boolean | undefined>;
132
+ primary_email_verified: boolean;
133
+ primary_email_auth_enabled: boolean;
134
134
  display_name: string | null;
135
135
  selected_team: {
136
136
  client_metadata?: {} | null | undefined;
@@ -144,9 +144,9 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
144
144
  selected_team_id: string | null;
145
145
  profile_image_url: string | null;
146
146
  signed_up_at_millis: number;
147
- has_password: NonNullable<boolean | undefined>;
148
- otp_auth_enabled: NonNullable<boolean | undefined>;
149
- passkey_auth_enabled: NonNullable<boolean | undefined>;
147
+ has_password: boolean;
148
+ otp_auth_enabled: boolean;
149
+ passkey_auth_enabled: boolean;
150
150
  client_metadata: {} | null;
151
151
  client_read_only_metadata: {} | null;
152
152
  server_metadata: {} | null;
@@ -156,8 +156,8 @@ export declare const usersCrud: import("../../crud").CrudSchemaFromOptions<{
156
156
  id: string;
157
157
  account_id: string;
158
158
  }[];
159
- auth_with_email: NonNullable<boolean | undefined>;
160
- requires_totp_mfa: NonNullable<boolean | undefined>;
159
+ auth_with_email: boolean;
160
+ requires_totp_mfa: boolean;
161
161
  }, import("yup").AnyObject, {
162
162
  id: undefined;
163
163
  primary_email: undefined;
@@ -286,8 +286,8 @@ export declare const userCreatedWebhookEvent: {
286
286
  schema: import("yup").ObjectSchema<{
287
287
  id: string;
288
288
  primary_email: string | null;
289
- primary_email_verified: NonNullable<boolean | undefined>;
290
- primary_email_auth_enabled: NonNullable<boolean | undefined>;
289
+ primary_email_verified: boolean;
290
+ primary_email_auth_enabled: boolean;
291
291
  display_name: string | null;
292
292
  selected_team: {
293
293
  client_metadata?: {} | null | undefined;
@@ -301,9 +301,9 @@ export declare const userCreatedWebhookEvent: {
301
301
  selected_team_id: string | null;
302
302
  profile_image_url: string | null;
303
303
  signed_up_at_millis: number;
304
- has_password: NonNullable<boolean | undefined>;
305
- otp_auth_enabled: NonNullable<boolean | undefined>;
306
- passkey_auth_enabled: NonNullable<boolean | undefined>;
304
+ has_password: boolean;
305
+ otp_auth_enabled: boolean;
306
+ passkey_auth_enabled: boolean;
307
307
  client_metadata: {} | null;
308
308
  client_read_only_metadata: {} | null;
309
309
  server_metadata: {} | null;
@@ -313,8 +313,8 @@ export declare const userCreatedWebhookEvent: {
313
313
  id: string;
314
314
  account_id: string;
315
315
  }[];
316
- auth_with_email: NonNullable<boolean | undefined>;
317
- requires_totp_mfa: NonNullable<boolean | undefined>;
316
+ auth_with_email: boolean;
317
+ requires_totp_mfa: boolean;
318
318
  }, import("yup").AnyObject, {
319
319
  id: undefined;
320
320
  primary_email: undefined;
@@ -355,8 +355,8 @@ export declare const userUpdatedWebhookEvent: {
355
355
  schema: import("yup").ObjectSchema<{
356
356
  id: string;
357
357
  primary_email: string | null;
358
- primary_email_verified: NonNullable<boolean | undefined>;
359
- primary_email_auth_enabled: NonNullable<boolean | undefined>;
358
+ primary_email_verified: boolean;
359
+ primary_email_auth_enabled: boolean;
360
360
  display_name: string | null;
361
361
  selected_team: {
362
362
  client_metadata?: {} | null | undefined;
@@ -370,9 +370,9 @@ export declare const userUpdatedWebhookEvent: {
370
370
  selected_team_id: string | null;
371
371
  profile_image_url: string | null;
372
372
  signed_up_at_millis: number;
373
- has_password: NonNullable<boolean | undefined>;
374
- otp_auth_enabled: NonNullable<boolean | undefined>;
375
- passkey_auth_enabled: NonNullable<boolean | undefined>;
373
+ has_password: boolean;
374
+ otp_auth_enabled: boolean;
375
+ passkey_auth_enabled: boolean;
376
376
  client_metadata: {} | null;
377
377
  client_read_only_metadata: {} | null;
378
378
  server_metadata: {} | null;
@@ -382,8 +382,8 @@ export declare const userUpdatedWebhookEvent: {
382
382
  id: string;
383
383
  account_id: string;
384
384
  }[];
385
- auth_with_email: NonNullable<boolean | undefined>;
386
- requires_totp_mfa: NonNullable<boolean | undefined>;
385
+ auth_with_email: boolean;
386
+ requires_totp_mfa: boolean;
387
387
  }, import("yup").AnyObject, {
388
388
  id: undefined;
389
389
  primary_email: undefined;
@@ -15,45 +15,45 @@ export const usersCrudServerUpdateSchema = fieldSchema.yupObject({
15
15
  otp_auth_enabled: fieldSchema.userOtpAuthEnabledMutationSchema.optional(),
16
16
  totp_secret_base64: fieldSchema.userTotpSecretMutationSchema.optional(),
17
17
  selected_team_id: fieldSchema.selectedTeamIdSchema.nullable().optional(),
18
- }).required();
18
+ }).defined();
19
19
  export const usersCrudServerReadSchema = fieldSchema.yupObject({
20
- id: fieldSchema.userIdSchema.required(),
20
+ id: fieldSchema.userIdSchema.defined(),
21
21
  primary_email: fieldSchema.primaryEmailSchema.nullable().defined(),
22
- primary_email_verified: fieldSchema.primaryEmailVerifiedSchema.required(),
23
- primary_email_auth_enabled: fieldSchema.primaryEmailAuthEnabledSchema.required(),
22
+ primary_email_verified: fieldSchema.primaryEmailVerifiedSchema.defined(),
23
+ primary_email_auth_enabled: fieldSchema.primaryEmailAuthEnabledSchema.defined(),
24
24
  display_name: fieldSchema.userDisplayNameSchema.nullable().defined(),
25
25
  selected_team: teamsCrudServerReadSchema.nullable().defined(),
26
26
  selected_team_id: fieldSchema.selectedTeamIdSchema.nullable().defined(),
27
27
  profile_image_url: fieldSchema.profileImageUrlSchema.nullable().defined(),
28
- signed_up_at_millis: fieldSchema.signedUpAtMillisSchema.required(),
29
- has_password: fieldSchema.userHasPasswordSchema.required(),
30
- otp_auth_enabled: fieldSchema.userOtpAuthEnabledSchema.required(),
31
- passkey_auth_enabled: fieldSchema.userOtpAuthEnabledSchema.required(),
28
+ signed_up_at_millis: fieldSchema.signedUpAtMillisSchema.defined(),
29
+ has_password: fieldSchema.userHasPasswordSchema.defined(),
30
+ otp_auth_enabled: fieldSchema.userOtpAuthEnabledSchema.defined(),
31
+ passkey_auth_enabled: fieldSchema.userOtpAuthEnabledSchema.defined(),
32
32
  client_metadata: fieldSchema.userClientMetadataSchema,
33
33
  client_read_only_metadata: fieldSchema.userClientReadOnlyMetadataSchema,
34
34
  server_metadata: fieldSchema.userServerMetadataSchema,
35
- last_active_at_millis: fieldSchema.userLastActiveAtMillisSchema.required(),
35
+ last_active_at_millis: fieldSchema.userLastActiveAtMillisSchema.nonNullable().defined(),
36
36
  oauth_providers: fieldSchema.yupArray(fieldSchema.yupObject({
37
- id: fieldSchema.yupString().required(),
38
- account_id: fieldSchema.yupString().required(),
37
+ id: fieldSchema.yupString().defined(),
38
+ account_id: fieldSchema.yupString().defined(),
39
39
  email: fieldSchema.yupString().nullable(),
40
- }).required()).required().meta({ openapiField: { hidden: true } }),
40
+ }).defined()).defined().meta({ openapiField: { hidden: true } }),
41
41
  /**
42
42
  * @deprecated
43
43
  */
44
- auth_with_email: fieldSchema.yupBoolean().required().meta({ openapiField: { hidden: true, description: 'Whether the user can authenticate with their primary e-mail. If set to true, the user can log-in with credentials and/or magic link, if enabled in the project settings.', exampleValue: true } }),
44
+ auth_with_email: fieldSchema.yupBoolean().defined().meta({ openapiField: { hidden: true, description: 'Whether the user can authenticate with their primary e-mail. If set to true, the user can log-in with credentials and/or magic link, if enabled in the project settings.', exampleValue: true } }),
45
45
  /**
46
46
  * @deprecated
47
47
  */
48
- requires_totp_mfa: fieldSchema.yupBoolean().required().meta({ openapiField: { hidden: true, description: 'Whether the user is required to use TOTP MFA to sign in', exampleValue: false } }),
49
- }).required();
48
+ requires_totp_mfa: fieldSchema.yupBoolean().defined().meta({ openapiField: { hidden: true, description: 'Whether the user is required to use TOTP MFA to sign in', exampleValue: false } }),
49
+ }).defined();
50
50
  export const usersCrudServerCreateSchema = usersCrudServerUpdateSchema.omit(['selected_team_id']).concat(fieldSchema.yupObject({
51
51
  oauth_providers: fieldSchema.yupArray(fieldSchema.yupObject({
52
- id: fieldSchema.yupString().required(),
53
- account_id: fieldSchema.yupString().required(),
52
+ id: fieldSchema.yupString().defined(),
53
+ account_id: fieldSchema.yupString().defined(),
54
54
  email: fieldSchema.yupString().nullable().defined().default(null),
55
- }).required()).optional().meta({ openapiField: { hidden: true } }),
56
- }).required());
55
+ }).defined()).optional().meta({ openapiField: { hidden: true } }),
56
+ }).defined());
57
57
  export const usersCrudServerDeleteSchema = fieldSchema.yupMixed();
58
58
  export const usersCrud = createCrud({
59
59
  serverReadSchema: usersCrudServerReadSchema,
@@ -107,11 +107,11 @@ export const userUpdatedWebhookEvent = {
107
107
  },
108
108
  };
109
109
  const webhookUserDeletedSchema = fieldSchema.yupObject({
110
- id: fieldSchema.userIdSchema.required(),
110
+ id: fieldSchema.userIdSchema.defined(),
111
111
  teams: fieldSchema.yupArray(fieldSchema.yupObject({
112
- id: fieldSchema.yupString().required(),
113
- })).required(),
114
- }).required();
112
+ id: fieldSchema.yupString().defined(),
113
+ })).defined(),
114
+ }).defined();
115
115
  export const userDeletedWebhookEvent = {
116
116
  type: "user.deleted",
117
117
  schema: webhookUserDeletedSchema,
@@ -13,8 +13,8 @@ export declare const webhookEvents: readonly [{
13
13
  schema: yup.ObjectSchema<{
14
14
  id: string;
15
15
  primary_email: string | null;
16
- primary_email_verified: NonNullable<boolean | undefined>;
17
- primary_email_auth_enabled: NonNullable<boolean | undefined>;
16
+ primary_email_verified: boolean;
17
+ primary_email_auth_enabled: boolean;
18
18
  display_name: string | null;
19
19
  selected_team: {
20
20
  client_metadata?: {} | null | undefined;
@@ -28,9 +28,9 @@ export declare const webhookEvents: readonly [{
28
28
  selected_team_id: string | null;
29
29
  profile_image_url: string | null;
30
30
  signed_up_at_millis: number;
31
- has_password: NonNullable<boolean | undefined>;
32
- otp_auth_enabled: NonNullable<boolean | undefined>;
33
- passkey_auth_enabled: NonNullable<boolean | undefined>;
31
+ has_password: boolean;
32
+ otp_auth_enabled: boolean;
33
+ passkey_auth_enabled: boolean;
34
34
  client_metadata: {} | null;
35
35
  client_read_only_metadata: {} | null;
36
36
  server_metadata: {} | null;
@@ -40,8 +40,8 @@ export declare const webhookEvents: readonly [{
40
40
  id: string;
41
41
  account_id: string;
42
42
  }[];
43
- auth_with_email: NonNullable<boolean | undefined>;
44
- requires_totp_mfa: NonNullable<boolean | undefined>;
43
+ auth_with_email: boolean;
44
+ requires_totp_mfa: boolean;
45
45
  }, yup.AnyObject, {
46
46
  id: undefined;
47
47
  primary_email: undefined;
@@ -81,8 +81,8 @@ export declare const webhookEvents: readonly [{
81
81
  schema: yup.ObjectSchema<{
82
82
  id: string;
83
83
  primary_email: string | null;
84
- primary_email_verified: NonNullable<boolean | undefined>;
85
- primary_email_auth_enabled: NonNullable<boolean | undefined>;
84
+ primary_email_verified: boolean;
85
+ primary_email_auth_enabled: boolean;
86
86
  display_name: string | null;
87
87
  selected_team: {
88
88
  client_metadata?: {} | null | undefined;
@@ -96,9 +96,9 @@ export declare const webhookEvents: readonly [{
96
96
  selected_team_id: string | null;
97
97
  profile_image_url: string | null;
98
98
  signed_up_at_millis: number;
99
- has_password: NonNullable<boolean | undefined>;
100
- otp_auth_enabled: NonNullable<boolean | undefined>;
101
- passkey_auth_enabled: NonNullable<boolean | undefined>;
99
+ has_password: boolean;
100
+ otp_auth_enabled: boolean;
101
+ passkey_auth_enabled: boolean;
102
102
  client_metadata: {} | null;
103
103
  client_read_only_metadata: {} | null;
104
104
  server_metadata: {} | null;
@@ -108,8 +108,8 @@ export declare const webhookEvents: readonly [{
108
108
  id: string;
109
109
  account_id: string;
110
110
  }[];
111
- auth_with_email: NonNullable<boolean | undefined>;
112
- requires_totp_mfa: NonNullable<boolean | undefined>;
111
+ auth_with_email: boolean;
112
+ requires_totp_mfa: boolean;
113
113
  }, yup.AnyObject, {
114
114
  id: undefined;
115
115
  primary_email: undefined;
@@ -338,7 +338,7 @@ const EmailPasswordMismatch = createKnownErrorConstructor(KnownError, "EMAIL_PAS
338
338
  ], () => []);
339
339
  const RedirectUrlNotWhitelisted = createKnownErrorConstructor(KnownError, "REDIRECT_URL_NOT_WHITELISTED", () => [
340
340
  400,
341
- "Redirect URL not whitelisted.",
341
+ "Redirect URL not whitelisted. Did you forget to add this domain to the trusted domains list on the Stack Auth dashboard?",
342
342
  ], () => []);
343
343
  const PasswordRequirementsNotMet = createKnownErrorConstructor(KnownError, "PASSWORD_REQUIREMENTS_NOT_MET", "inherit", "inherit");
344
344
  const PasswordTooShort = createKnownErrorConstructor(PasswordRequirementsNotMet, "PASSWORD_TOO_SHORT", (minLength) => [
@@ -1,4 +1,9 @@
1
1
  import * as yup from "yup";
2
+ declare module "yup" {
3
+ interface StringSchema<TType, TContext, TDefault, TFlags> {
4
+ nonEmpty(message?: string): StringSchema<TType, TContext, TDefault, TFlags>;
5
+ }
6
+ }
2
7
  export declare function yupValidate<S extends yup.ISchema<any>>(schema: S, obj: unknown, options?: yup.ValidateOptions & {
3
8
  currentUserId?: string | null;
4
9
  }): Promise<yup.InferType<S>>;
@@ -15,6 +20,9 @@ export declare function yupMixed<A extends {}>(...args: Parameters<typeof yup.mi
15
20
  export declare function yupArray<A extends yup.Maybe<yup.AnyObject> = yup.AnyObject, B = any>(...args: Parameters<typeof yup.array<A, B>>): yup.ArraySchema<B[] | undefined, A, undefined, "">;
16
21
  export declare function yupTuple<T extends [unknown, ...unknown[]]>(...args: Parameters<typeof yup.tuple<T>>): yup.TupleSchema<T | undefined, yup.AnyObject, undefined, "">;
17
22
  export declare function yupObject<A extends yup.Maybe<yup.AnyObject>, B extends yup.ObjectShape>(...args: Parameters<typeof yup.object<A, B>>): yup.ObjectSchema<yup.TypeFromShape<B, yup.AnyObject> extends infer T ? T extends yup.TypeFromShape<B, yup.AnyObject> ? T extends {} ? { [k in keyof T]: T[k]; } : T : never : never, yup.AnyObject, yup.DefaultFromShape<B> extends infer T_1 ? T_1 extends yup.DefaultFromShape<B> ? T_1 extends {} ? { [k_1 in keyof T_1]: T_1[k_1]; } : T_1 : never : never, "">;
23
+ /**
24
+ * Note that the .defined() on unions is implicit.
25
+ */
18
26
  export declare function yupUnion<T extends yup.ISchema<any>[]>(...args: T): yup.ISchema<yup.InferType<T[number]>>;
19
27
  export declare const adaptSchema: yup.MixedSchema<typeof StackAdaptSentinel | undefined, yup.AnyObject, undefined, "">;
20
28
  /**
@@ -76,7 +84,7 @@ export declare const userClientReadOnlyMetadataSchema: yup.MixedSchema<{} | null
76
84
  export declare const userServerMetadataSchema: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
77
85
  export declare const userOAuthProviderSchema: yup.ObjectSchema<{
78
86
  id: string;
79
- type: NonNullable<"google" | "github" | "microsoft" | "spotify" | "facebook" | "discord" | "gitlab" | "bitbucket" | "linkedin" | "apple" | "x" | undefined>;
87
+ type: "google" | "github" | "microsoft" | "spotify" | "facebook" | "discord" | "gitlab" | "bitbucket" | "linkedin" | "apple" | "x";
80
88
  provider_user_id: string;
81
89
  }, yup.AnyObject, {
82
90
  id: undefined;
@@ -98,7 +106,7 @@ export declare const refreshTokenResponseSchema: yup.StringSchema<string | undef
98
106
  export declare const signInResponseSchema: yup.ObjectSchema<{
99
107
  refresh_token: string;
100
108
  access_token: string;
101
- is_new_user: NonNullable<boolean | undefined>;
109
+ is_new_user: boolean;
102
110
  user_id: string;
103
111
  }, yup.AnyObject, {
104
112
  refresh_token: undefined;
@@ -129,5 +137,5 @@ export declare const contactChannelValueSchema: yup.StringSchema<string | undefi
129
137
  export declare const contactChannelUsedForAuthSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
130
138
  export declare const contactChannelIsVerifiedSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
131
139
  export declare const contactChannelIsPrimarySchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
132
- export declare function yupRequiredWhen<S extends yup.AnyObject>(schema: S, triggerName: string, isValue: any): S;
140
+ export declare function yupDefinedWhen<S extends yup.AnyObject>(schema: S, triggerName: string, isValue: any): S;
133
141
  export {};
@@ -5,6 +5,12 @@ import { StackAssertionError } from "./utils/errors";
5
5
  import { allProviders } from "./utils/oauth";
6
6
  import { deepPlainClone, omit } from "./utils/objects";
7
7
  import { isUuid } from "./utils/uuids";
8
+ // eslint-disable-next-line no-restricted-syntax
9
+ yup.addMethod(yup.string, "nonEmpty", function (message) {
10
+ return this.test("non-empty", message ?? "String must not be empty", (value) => {
11
+ return value !== "";
12
+ });
13
+ });
8
14
  export async function yupValidate(schema, obj, options) {
9
15
  try {
10
16
  return await schema.validate(obj, {
@@ -64,32 +70,39 @@ const _createdAtMillisDescription = (identify) => `The time the ${identify} was
64
70
  const _signedUpAtMillisDescription = `The time the user signed up ${_atMillisDescription}`;
65
71
  const _lastActiveAtMillisDescription = `The time the user was last active ${_atMillisDescription}`;
66
72
  // Built-in replacements
67
- /* eslint-disable no-restricted-syntax */
68
73
  export function yupString(...args) {
74
+ // eslint-disable-next-line no-restricted-syntax
69
75
  return yup.string(...args);
70
76
  }
71
77
  export function yupNumber(...args) {
78
+ // eslint-disable-next-line no-restricted-syntax
72
79
  return yup.number(...args);
73
80
  }
74
81
  export function yupBoolean(...args) {
82
+ // eslint-disable-next-line no-restricted-syntax
75
83
  return yup.boolean(...args);
76
84
  }
77
85
  /**
78
86
  * @deprecated, use number of milliseconds since epoch instead
79
87
  */
80
88
  export function yupDate(...args) {
89
+ // eslint-disable-next-line no-restricted-syntax
81
90
  return yup.date(...args);
82
91
  }
83
92
  export function yupMixed(...args) {
93
+ // eslint-disable-next-line no-restricted-syntax
84
94
  return yup.mixed(...args);
85
95
  }
86
96
  export function yupArray(...args) {
97
+ // eslint-disable-next-line no-restricted-syntax
87
98
  return yup.array(...args);
88
99
  }
89
100
  export function yupTuple(...args) {
101
+ // eslint-disable-next-line no-restricted-syntax
90
102
  return yup.tuple(...args);
91
103
  }
92
104
  export function yupObject(...args) {
105
+ // eslint-disable-next-line no-restricted-syntax
93
106
  const object = yup.object(...args).test('no-unknown-object-properties', ({ path }) => `${path} contains unknown properties`, (value, context) => {
94
107
  if (context.options.context?.noUnknownPathPrefixes?.some((prefix) => context.path.startsWith(prefix))) {
95
108
  if (context.schema.spec.noUnknown !== false) {
@@ -110,7 +123,9 @@ export function yupObject(...args) {
110
123
  // we don't want to update the type of `object` to have a default flag
111
124
  return object.default(undefined);
112
125
  }
113
- /* eslint-enable no-restricted-syntax */
126
+ /**
127
+ * Note that the .defined() on unions is implicit.
128
+ */
114
129
  export function yupUnion(...args) {
115
130
  if (args.length === 0)
116
131
  throw new Error('yupUnion must have at least one schema');
@@ -121,7 +136,7 @@ export function yupUnion(...args) {
121
136
  if (desc.type !== firstDesc.type)
122
137
  throw new StackAssertionError(`yupUnion must have schemas of the same type (got: ${firstDesc.type} and ${desc.type})`, { first, schema, firstDesc, desc });
123
138
  }
124
- return yupMixed().required().test('is-one-of', 'Invalid value', async (value, context) => {
139
+ return yupMixed().defined().test('is-one-of', 'Invalid value', async (value, context) => {
125
140
  const errors = [];
126
141
  for (const schema of args) {
127
142
  try {
@@ -259,9 +274,9 @@ export const userClientMetadataSchema = jsonSchema.meta({ openapiField: { descri
259
274
  export const userClientReadOnlyMetadataSchema = jsonSchema.meta({ openapiField: { description: _clientReadOnlyMetaDataDescription('user'), exampleValue: { key: 'value' } } });
260
275
  export const userServerMetadataSchema = jsonSchema.meta({ openapiField: { description: _serverMetaDataDescription('user'), exampleValue: { key: 'value' } } });
261
276
  export const userOAuthProviderSchema = yupObject({
262
- id: yupString().required(),
263
- type: yupString().oneOf(allProviders).required(),
264
- provider_user_id: yupString().required(),
277
+ id: yupString().defined(),
278
+ type: yupString().oneOf(allProviders).defined(),
279
+ provider_user_id: yupString().defined(),
265
280
  });
266
281
  export const userLastActiveAtMillisSchema = yupNumber().nullable().meta({ openapiField: { description: _lastActiveAtMillisDescription, exampleValue: 1630000000000 } });
267
282
  export const userPasskeyAuthEnabledSchema = yupBoolean().meta({ openapiField: { hidden: true, description: 'Whether the user has passkeys enabled', exampleValue: false } });
@@ -277,10 +292,10 @@ export const emailVerificationCallbackUrlSchema = urlSchema.meta({ openapiField:
277
292
  export const accessTokenResponseSchema = yupString().meta({ openapiField: { description: 'Short-lived access token that can be used to authenticate the user', exampleValue: 'eyJhmMiJB2TO...diI4QT' } });
278
293
  export const refreshTokenResponseSchema = yupString().meta({ openapiField: { description: 'Long-lived refresh token that can be used to obtain a new access token', exampleValue: 'i8ns3aq2...14y' } });
279
294
  export const signInResponseSchema = yupObject({
280
- refresh_token: refreshTokenResponseSchema.required(),
281
- access_token: accessTokenResponseSchema.required(),
282
- is_new_user: yupBoolean().meta({ openapiField: { description: 'Whether the user is a new user', exampleValue: true } }).required(),
283
- user_id: userIdSchema.required(),
295
+ refresh_token: refreshTokenResponseSchema.defined(),
296
+ access_token: accessTokenResponseSchema.defined(),
297
+ is_new_user: yupBoolean().meta({ openapiField: { description: 'Whether the user is a new user', exampleValue: true } }).defined(),
298
+ user_id: userIdSchema.defined(),
284
299
  });
285
300
  // Permissions
286
301
  export const teamSystemPermissions = [
@@ -305,7 +320,7 @@ export const customTeamPermissionDefinitionIdSchema = yupString()
305
320
  .matches(/^[a-z0-9_:]+$/, 'Only lowercase letters, numbers, ":", "_" are allowed')
306
321
  .meta({ openapiField: { description: 'The permission ID used to uniquely identify a permission. Can only contain lowercase letters, numbers, ":", and "_" characters', exampleValue: 'read_secret_info' } });
307
322
  export const teamPermissionDescriptionSchema = yupString().meta({ openapiField: { description: 'A human-readable description of the permission', exampleValue: 'Read secret information' } });
308
- export const containedPermissionIdsSchema = yupArray(teamPermissionDefinitionIdSchema.required()).meta({ openapiField: { description: 'The IDs of the permissions that are contained in this permission', exampleValue: ['read_public_info'] } });
323
+ export const containedPermissionIdsSchema = yupArray(teamPermissionDefinitionIdSchema.defined()).meta({ openapiField: { description: 'The IDs of the permissions that are contained in this permission', exampleValue: ['read_public_info'] } });
309
324
  // Teams
310
325
  export const teamIdSchema = yupString().uuid().meta({ openapiField: { description: _idDescription('team'), exampleValue: 'ad962777-8244-496a-b6a2-e0c6a449c79e' } });
311
326
  export const teamDisplayNameSchema = yupString().meta({ openapiField: { description: _displayNameDescription('team'), exampleValue: 'My Team' } });
@@ -331,10 +346,10 @@ export const contactChannelUsedForAuthSchema = yupBoolean().meta({ openapiField:
331
346
  export const contactChannelIsVerifiedSchema = yupBoolean().meta({ openapiField: { description: 'Whether the contact channel has been verified. If this is set to `true`, the contact channel has been verified to belong to the user.', exampleValue: true } });
332
347
  export const contactChannelIsPrimarySchema = yupBoolean().meta({ openapiField: { description: 'Whether the contact channel is the primary contact channel. If this is set to `true`, it will be used for authentication and notifications by default.', exampleValue: true } });
333
348
  // Utils
334
- export function yupRequiredWhen(schema, triggerName, isValue) {
349
+ export function yupDefinedWhen(schema, triggerName, isValue) {
335
350
  return schema.when(triggerName, {
336
351
  is: isValue,
337
- then: (schema) => schema.required(),
352
+ then: (schema) => schema.defined(),
338
353
  otherwise: (schema) => schema.optional()
339
354
  });
340
355
  }
@@ -0,0 +1,4 @@
1
+ export type Ipv4Address = `${number}.${number}.${number}.${number}`;
2
+ export type Ipv6Address = string;
3
+ export declare function isIpAddress(ip: string): ip is Ipv4Address | Ipv6Address;
4
+ export declare function assertIpAddress(ip: string): asserts ip is Ipv4Address | Ipv6Address;
@@ -0,0 +1,9 @@
1
+ import ipRegex from "ip-regex";
2
+ export function isIpAddress(ip) {
3
+ return ipRegex({ exact: true }).test(ip);
4
+ }
5
+ export function assertIpAddress(ip) {
6
+ if (!isIpAddress(ip)) {
7
+ throw new Error(`Invalid IP address: ${ip}`);
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackframe/stack-shared",
3
- "version": "2.6.21",
3
+ "version": "2.6.24",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -20,11 +20,11 @@
20
20
  }
21
21
  },
22
22
  "peerDependencies": {
23
- "react": ">=18.2",
24
- "react-dom": ">=18.2",
25
- "@types/react": ">=18.2",
26
- "@types/react-dom": ">=18.2",
27
- "next": ">=14.1.0",
23
+ "react": ">=18.2 || >=19.0.0-rc.0",
24
+ "react-dom": ">=18.2 || >=19.0.0-rc.0",
25
+ "@types/react": ">=18.2 || >=19.0.0-rc.0",
26
+ "@types/react-dom": ">=18.2 || >=19.0.0-rc.0",
27
+ "next": ">=14.1.0 || >=15.0.0-rc.0",
28
28
  "yup": "^1.4.0"
29
29
  },
30
30
  "peerDependenciesMeta": {
@@ -46,10 +46,11 @@
46
46
  "bcrypt": "^5.1.1",
47
47
  "elliptic": "^6.5.7",
48
48
  "jose": "^5.2.2",
49
+ "ip-regex": "^5.0.0",
49
50
  "oauth4webapi": "^2.10.3",
50
51
  "semver": "^7.6.3",
51
52
  "uuid": "^9.0.1",
52
- "@stackframe/stack-sc": "2.6.21"
53
+ "@stackframe/stack-sc": "2.6.24"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@simplewebauthn/types": "^11.0.0",