@stackframe/stack-shared 2.4.28 → 2.5.1

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,22 @@
1
1
  # @stackframe/stack-shared
2
2
 
3
+ ## 2.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - New backend endpoints
8
+ - @stackframe/stack-sc@2.5.1
9
+
10
+ ## 2.5.0
11
+
12
+ ### Minor Changes
13
+
14
+ - Client teams and many bugfixes
15
+
16
+ ### Patch Changes
17
+
18
+ - @stackframe/stack-sc@2.5.0
19
+
3
20
  ## 2.4.28
4
21
 
5
22
  ### Patch Changes
package/dist/crud.d.ts CHANGED
@@ -1,20 +1,37 @@
1
1
  import * as yup from 'yup';
2
2
  import { NullishCoalesce } from './utils/types';
3
+ export type AccessType = "client" | "server" | "admin";
3
4
  export type CrudOperation = "create" | "read" | "update" | "delete";
5
+ export type AccessTypeXCrudOperation = `${AccessType}${Capitalize<CrudOperation>}`;
4
6
  declare module 'yup' {
5
7
  interface CustomSchemaMetadata {
6
- openapi?: {
8
+ openapiField?: {
7
9
  description?: string;
8
10
  exampleValue?: any;
9
- hide?: boolean;
11
+ hidden?: boolean;
10
12
  };
11
13
  }
12
14
  }
15
+ type ShownEndpointDocumentation = {
16
+ summary: string;
17
+ description: string;
18
+ tags?: string[];
19
+ };
20
+ export type EndpointDocumentation = ({
21
+ hidden: true;
22
+ } & Partial<ShownEndpointDocumentation>) | ({
23
+ hidden?: boolean;
24
+ } & ShownEndpointDocumentation);
13
25
  type InnerCrudSchema<CreateSchema extends yup.Schema<any> | undefined = yup.Schema<any> | undefined, ReadSchema extends yup.Schema<any> | undefined = yup.Schema<any> | undefined, UpdateSchema extends yup.Schema<any> | undefined = yup.Schema<any> | undefined, DeleteSchema extends yup.Schema<any> | undefined = yup.Schema<any> | undefined> = {
14
26
  createSchema: CreateSchema;
27
+ createDocs: EndpointDocumentation | undefined;
15
28
  readSchema: ReadSchema;
29
+ readDocs: EndpointDocumentation | undefined;
30
+ listDocs: EndpointDocumentation | undefined;
16
31
  updateSchema: UpdateSchema;
32
+ updateDocs: EndpointDocumentation | undefined;
17
33
  deleteSchema: DeleteSchema;
34
+ deleteDocs: EndpointDocumentation | undefined;
18
35
  };
19
36
  export type CrudSchema<ClientSchema extends InnerCrudSchema = InnerCrudSchema, ServerSchema extends InnerCrudSchema = InnerCrudSchema, AdminSchema extends InnerCrudSchema = InnerCrudSchema> = {
20
37
  client: ClientSchema;
@@ -26,18 +43,7 @@ export type CrudSchema<ClientSchema extends InnerCrudSchema = InnerCrudSchema, S
26
43
  hasDelete: boolean;
27
44
  };
28
45
  export type CrudSchemaCreationOptions = {
29
- clientCreateSchema?: yup.Schema<any>;
30
- clientReadSchema?: yup.Schema<any>;
31
- clientUpdateSchema?: yup.Schema<any>;
32
- clientDeleteSchema?: yup.Schema<any>;
33
- serverCreateSchema?: yup.Schema<any>;
34
- serverReadSchema?: yup.Schema<any>;
35
- serverUpdateSchema?: yup.Schema<any>;
36
- serverDeleteSchema?: yup.Schema<any>;
37
- adminCreateSchema?: yup.Schema<any>;
38
- adminReadSchema?: yup.Schema<any>;
39
- adminUpdateSchema?: yup.Schema<any>;
40
- adminDeleteSchema?: yup.Schema<any>;
46
+ [K in AccessTypeXCrudOperation as `${K}Schema`]?: yup.Schema<any>;
41
47
  };
42
48
  type FillInOptionalsPrepareStep<O extends CrudSchemaCreationOptions> = {
43
49
  [K in keyof Required<CrudSchemaCreationOptions>]: K extends keyof O ? O[K] : undefined;
@@ -73,5 +79,10 @@ export type CrudTypeOf<S extends CrudSchema> = {
73
79
  Server: InnerCrudTypeOf<S['server']>;
74
80
  Admin: InnerCrudTypeOf<S['admin']>;
75
81
  };
76
- export declare function createCrud<O extends CrudSchemaCreationOptions>(options: O): CrudSchemaFromOptions<O>;
82
+ type CrudDocsCreationOptions<SO extends CrudSchemaCreationOptions> = {
83
+ [X in AccessTypeXCrudOperation as (X extends `${infer A}Read` ? X | `${A}List` : X)]?: EndpointDocumentation;
84
+ };
85
+ export declare function createCrud<SO extends CrudSchemaCreationOptions>(options: SO & {
86
+ docs?: CrudDocsCreationOptions<SO>;
87
+ }): CrudSchemaFromOptions<SO>;
77
88
  export {};
package/dist/crud.js CHANGED
@@ -1,16 +1,27 @@
1
1
  import { filterUndefined } from './utils/objects';
2
2
  export function createCrud(options) {
3
+ const docs = options.docs ?? {};
3
4
  const client = {
4
5
  createSchema: options.clientCreateSchema,
6
+ createDocs: docs.clientCreate,
5
7
  readSchema: options.clientReadSchema,
8
+ readDocs: docs.clientRead,
9
+ listDocs: docs.clientList,
6
10
  updateSchema: options.clientUpdateSchema,
11
+ updateDocs: docs.clientUpdate,
7
12
  deleteSchema: options.clientDeleteSchema,
13
+ deleteDocs: docs.clientDelete,
8
14
  };
9
15
  const serverOverrides = filterUndefined({
10
16
  createSchema: options.serverCreateSchema,
17
+ createDocs: docs.serverCreate,
11
18
  readSchema: options.serverReadSchema,
19
+ readDocs: docs.serverRead,
20
+ listDocs: docs.serverList,
12
21
  updateSchema: options.serverUpdateSchema,
22
+ updateDocs: docs.serverUpdate,
13
23
  deleteSchema: options.serverDeleteSchema,
24
+ deleteDocs: docs.serverDelete,
14
25
  });
15
26
  const server = {
16
27
  ...client,
@@ -18,9 +29,14 @@ export function createCrud(options) {
18
29
  };
19
30
  const adminOverrides = filterUndefined({
20
31
  createSchema: options.adminCreateSchema,
32
+ createDocs: docs.adminCreate,
21
33
  readSchema: options.adminReadSchema,
34
+ readDocs: docs.adminRead,
35
+ listDocs: docs.adminList,
22
36
  updateSchema: options.adminUpdateSchema,
37
+ updateDocs: docs.adminUpdate,
23
38
  deleteSchema: options.adminDeleteSchema,
39
+ deleteDocs: docs.adminDelete,
24
40
  });
25
41
  const admin = {
26
42
  ...server,
@@ -160,13 +160,13 @@ export declare class StackClientInterface {
160
160
  password: string;
161
161
  } | {
162
162
  onlyVerifyCode: boolean;
163
- })): Promise<KnownErrors["PasswordResetError"] | undefined>;
163
+ })): Promise<KnownErrors["VerificationCodeError"] | undefined>;
164
164
  updatePassword(options: {
165
165
  oldPassword: string;
166
166
  newPassword: string;
167
167
  }, session: InternalSession): Promise<KnownErrors["PasswordMismatch"] | KnownErrors["PasswordRequirementsNotMet"] | undefined>;
168
- verifyPasswordResetCode(code: string): Promise<KnownErrors["PasswordResetCodeError"] | undefined>;
169
- verifyEmail(code: string): Promise<KnownErrors["EmailVerificationError"] | undefined>;
168
+ verifyPasswordResetCode(code: string): Promise<KnownErrors["VerificationCodeError"] | undefined>;
169
+ verifyEmail(code: string): Promise<KnownErrors["VerificationCodeError"] | undefined>;
170
170
  signInWithCredential(email: string, password: string, session: InternalSession): Promise<KnownErrors["EmailPasswordMismatch"] | {
171
171
  accessToken: string;
172
172
  refreshToken: string;
@@ -175,7 +175,7 @@ export declare class StackClientInterface {
175
175
  accessToken: string;
176
176
  refreshToken: string;
177
177
  }>;
178
- signInWithMagicLink(code: string, session: InternalSession): Promise<KnownErrors["MagicLinkError"] | {
178
+ signInWithMagicLink(code: string, session: InternalSession): Promise<KnownErrors["VerificationCodeError"] | {
179
179
  newUser: boolean;
180
180
  accessToken: string;
181
181
  refreshToken: string;
@@ -292,7 +292,7 @@ export class StackClientInterface {
292
292
  "Content-Type": "application/json"
293
293
  },
294
294
  body: JSON.stringify(options),
295
- }, null, [KnownErrors.PasswordResetError]);
295
+ }, null, [KnownErrors.VerificationCodeError]);
296
296
  if (res.status === "error") {
297
297
  return res.error;
298
298
  }
@@ -311,7 +311,7 @@ export class StackClientInterface {
311
311
  }
312
312
  async verifyPasswordResetCode(code) {
313
313
  const res = await this.resetPassword({ code, onlyVerifyCode: true });
314
- if (res && !(res instanceof KnownErrors.PasswordResetCodeError)) {
314
+ if (res && !(res instanceof KnownErrors.VerificationCodeError)) {
315
315
  throw res;
316
316
  }
317
317
  return res;
@@ -325,7 +325,7 @@ export class StackClientInterface {
325
325
  body: JSON.stringify({
326
326
  code,
327
327
  }),
328
- }, null, [KnownErrors.EmailVerificationError]);
328
+ }, null, [KnownErrors.VerificationCodeError]);
329
329
  if (res.status === "error") {
330
330
  return res.error;
331
331
  }
@@ -380,7 +380,7 @@ export class StackClientInterface {
380
380
  body: JSON.stringify({
381
381
  code,
382
382
  }),
383
- }, null, [KnownErrors.MagicLinkError]);
383
+ }, null, [KnownErrors.VerificationCodeError]);
384
384
  if (res.status === "error") {
385
385
  return res.error;
386
386
  }
@@ -1,97 +1,110 @@
1
1
  import { CrudTypeOf } from "../../crud";
2
- import * as yup from "yup";
3
2
  export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions<{
4
- clientReadSchema: yup.ObjectSchema<{
5
- projectId: string;
6
- displayName: string | null;
3
+ clientReadSchema: import("yup").ObjectSchema<{
4
+ project_id: string;
7
5
  id: string;
8
- clientMetadata: {} | null;
9
- primaryEmail: string | null;
10
- primaryEmailVerified: NonNullable<boolean | undefined>;
11
- selectedTeamId: string | null;
12
- selectedTeam: {} | null;
13
- profileImageUrl: string | null;
14
- signedUpAtMillis: number;
15
- authMethod: NonNullable<"credential" | "oauth" | undefined>;
16
- hasPassword: NonNullable<boolean | undefined>;
17
- authWithEmail: NonNullable<boolean | undefined>;
18
- oauthProviders: string[];
19
- } | null, yup.AnyObject, {
20
- projectId: undefined;
6
+ display_name: string | null;
7
+ client_metadata: {} | null;
8
+ primary_email: string | null;
9
+ primary_email_verified: NonNullable<boolean | undefined>;
10
+ selected_team_id: string | null;
11
+ selected_team: {} | null;
12
+ profile_image_url: string | null;
13
+ signed_up_at_millis: number;
14
+ has_password: NonNullable<boolean | undefined>;
15
+ auth_with_email: NonNullable<boolean | undefined>;
16
+ oauth_providers: string[];
17
+ } | null, import("yup").AnyObject, {
18
+ project_id: undefined;
21
19
  id: undefined;
22
- primaryEmail: undefined;
23
- primaryEmailVerified: undefined;
24
- displayName: undefined;
25
- selectedTeam: undefined;
26
- selectedTeamId: undefined;
27
- profileImageUrl: undefined;
28
- signedUpAtMillis: undefined;
29
- authMethod: undefined;
30
- hasPassword: undefined;
31
- authWithEmail: undefined;
32
- oauthProviders: undefined;
33
- clientMetadata: undefined;
34
- serverMetadata: undefined;
20
+ primary_email: undefined;
21
+ primary_email_verified: undefined;
22
+ display_name: undefined;
23
+ selected_team: undefined;
24
+ selected_team_id: undefined;
25
+ profile_image_url: undefined;
26
+ signed_up_at_millis: undefined;
27
+ has_password: undefined;
28
+ auth_with_email: undefined;
29
+ oauth_providers: undefined;
30
+ client_metadata: undefined;
31
+ server_metadata: undefined;
35
32
  }, "">;
36
- serverReadSchema: yup.ObjectSchema<{
37
- projectId: string;
33
+ serverReadSchema: import("yup").ObjectSchema<{
34
+ project_id: string;
38
35
  id: string;
39
- primaryEmail: string | null;
40
- primaryEmailVerified: NonNullable<boolean | undefined>;
41
- displayName: string | null;
42
- selectedTeam: {} | null;
43
- selectedTeamId: string | null;
44
- profileImageUrl: string | null;
45
- signedUpAtMillis: number;
46
- authMethod: NonNullable<"credential" | "oauth" | undefined>;
47
- hasPassword: NonNullable<boolean | undefined>;
48
- authWithEmail: NonNullable<boolean | undefined>;
49
- oauthProviders: string[];
50
- clientMetadata: {} | null;
51
- serverMetadata: {} | null;
52
- } | null, yup.AnyObject, {
53
- projectId: undefined;
36
+ primary_email: string | null;
37
+ primary_email_verified: NonNullable<boolean | undefined>;
38
+ display_name: string | null;
39
+ selected_team: {} | null;
40
+ selected_team_id: string | null;
41
+ profile_image_url: string | null;
42
+ signed_up_at_millis: number;
43
+ has_password: NonNullable<boolean | undefined>;
44
+ auth_with_email: NonNullable<boolean | undefined>;
45
+ oauth_providers: string[];
46
+ client_metadata: {} | null;
47
+ server_metadata: {} | null;
48
+ } | null, import("yup").AnyObject, {
49
+ project_id: undefined;
54
50
  id: undefined;
55
- primaryEmail: undefined;
56
- primaryEmailVerified: undefined;
57
- displayName: undefined;
58
- selectedTeam: undefined;
59
- selectedTeamId: undefined;
60
- profileImageUrl: undefined;
61
- signedUpAtMillis: undefined;
62
- authMethod: undefined;
63
- hasPassword: undefined;
64
- authWithEmail: undefined;
65
- oauthProviders: undefined;
66
- clientMetadata: undefined;
67
- serverMetadata: undefined;
51
+ primary_email: undefined;
52
+ primary_email_verified: undefined;
53
+ display_name: undefined;
54
+ selected_team: undefined;
55
+ selected_team_id: undefined;
56
+ profile_image_url: undefined;
57
+ signed_up_at_millis: undefined;
58
+ has_password: undefined;
59
+ auth_with_email: undefined;
60
+ oauth_providers: undefined;
61
+ client_metadata: undefined;
62
+ server_metadata: undefined;
68
63
  }, "">;
69
- clientUpdateSchema: yup.ObjectSchema<{
70
- displayName: string | undefined;
71
- clientMetadata: {} | null | undefined;
72
- selectedTeamId: string | null | undefined;
73
- }, yup.AnyObject, {
74
- displayName: undefined;
75
- clientMetadata: undefined;
76
- serverMetadata: undefined;
77
- primaryEmail: undefined;
78
- primaryEmailVerified: undefined;
79
- selectedTeamId: undefined;
64
+ clientUpdateSchema: import("yup").ObjectSchema<{
65
+ display_name: string | null | undefined;
66
+ client_metadata: {} | null | undefined;
67
+ selected_team_id: string | null | undefined;
68
+ }, import("yup").AnyObject, {
69
+ display_name: undefined;
70
+ client_metadata: undefined;
71
+ server_metadata: undefined;
72
+ primary_email: undefined;
73
+ primary_email_verified: undefined;
74
+ selected_team_id: undefined;
80
75
  }, "">;
81
- serverUpdateSchema: yup.ObjectSchema<{
82
- displayName: string | undefined;
83
- clientMetadata: {} | null | undefined;
84
- serverMetadata: {} | null | undefined;
85
- primaryEmail: string | null | undefined;
86
- primaryEmailVerified: boolean | undefined;
87
- selectedTeamId: string | null | undefined;
88
- }, yup.AnyObject, {
89
- displayName: undefined;
90
- clientMetadata: undefined;
91
- serverMetadata: undefined;
92
- primaryEmail: undefined;
93
- primaryEmailVerified: undefined;
94
- selectedTeamId: undefined;
76
+ serverUpdateSchema: import("yup").ObjectSchema<{
77
+ display_name: string | null | undefined;
78
+ client_metadata: {} | null | undefined;
79
+ server_metadata: {} | null | undefined;
80
+ primary_email: string | null | undefined;
81
+ primary_email_verified: boolean | undefined;
82
+ selected_team_id: string | null | undefined;
83
+ }, import("yup").AnyObject, {
84
+ display_name: undefined;
85
+ client_metadata: undefined;
86
+ server_metadata: undefined;
87
+ primary_email: undefined;
88
+ primary_email_verified: undefined;
89
+ selected_team_id: undefined;
95
90
  }, "">;
91
+ serverDeleteSchema: import("yup").MixedSchema<{} | undefined, import("yup").AnyObject, undefined, "">;
92
+ docs: {
93
+ clientRead: {
94
+ summary: string;
95
+ description: string;
96
+ tags: string[];
97
+ };
98
+ clientUpdate: {
99
+ summary: string;
100
+ description: string;
101
+ tags: string[];
102
+ };
103
+ clientDelete: {
104
+ summary: string;
105
+ description: string;
106
+ tags: string[];
107
+ };
108
+ };
96
109
  }>;
97
110
  export type CurrentUserCrud = CrudTypeOf<typeof currentUserCrud>;
@@ -1,31 +1,49 @@
1
1
  import { createCrud } from "../../crud";
2
- import { usersCrudServerReadSchema, usersCrudServerUpdateSchema } from "./users";
2
+ import { usersCrudServerReadSchema, usersCrudServerUpdateSchema, usersCrudServerDeleteSchema } from "./users";
3
3
  const clientUpdateSchema = usersCrudServerUpdateSchema.pick([
4
- "displayName",
5
- "clientMetadata",
6
- "selectedTeamId",
4
+ "display_name",
5
+ "client_metadata",
6
+ "selected_team_id",
7
7
  ]).required();
8
8
  const serverUpdateSchema = usersCrudServerUpdateSchema;
9
9
  const clientReadSchema = usersCrudServerReadSchema.pick([
10
- "projectId",
10
+ "project_id",
11
11
  "id",
12
- "primaryEmail",
13
- "primaryEmailVerified",
14
- "displayName",
15
- "clientMetadata",
16
- "profileImageUrl",
17
- "signedUpAtMillis",
18
- "authMethod",
19
- "hasPassword",
20
- "authWithEmail",
21
- "oauthProviders",
22
- "selectedTeamId",
23
- "selectedTeam",
12
+ "primary_email",
13
+ "primary_email_verified",
14
+ "display_name",
15
+ "client_metadata",
16
+ "profile_image_url",
17
+ "signed_up_at_millis",
18
+ "has_password",
19
+ "auth_with_email",
20
+ "oauth_providers",
21
+ "selected_team_id",
22
+ "selected_team",
24
23
  ]).nullable().defined();
25
24
  const serverReadSchema = usersCrudServerReadSchema.nullable().defined();
25
+ const serverDeleteSchema = usersCrudServerDeleteSchema;
26
26
  export const currentUserCrud = createCrud({
27
27
  clientReadSchema,
28
28
  serverReadSchema,
29
29
  clientUpdateSchema,
30
30
  serverUpdateSchema,
31
+ serverDeleteSchema,
32
+ docs: {
33
+ clientRead: {
34
+ summary: 'Get current user',
35
+ description: 'Gets the currently authenticated user.',
36
+ tags: ['Users'],
37
+ },
38
+ clientUpdate: {
39
+ summary: 'Update current user',
40
+ description: 'Updates the currently authenticated user. Only the values provided will be updated.',
41
+ tags: ['Users'],
42
+ },
43
+ clientDelete: {
44
+ summary: 'Delete current user',
45
+ description: 'Deletes the currently authenticated user. Use this with caution.',
46
+ tags: ['Users'],
47
+ },
48
+ },
31
49
  });
@@ -1,9 +1,9 @@
1
1
  import { CrudTypeOf } from "../../crud";
2
2
  import * as yup from "yup";
3
3
  export declare const accessTokenReadSchema: yup.ObjectSchema<{
4
- accessToken: string;
4
+ access_token: string;
5
5
  }, yup.AnyObject, {
6
- accessToken: undefined;
6
+ access_token: undefined;
7
7
  }, "">;
8
8
  export declare const accessTokenCreateSchema: yup.ObjectSchema<{
9
9
  scope: string | undefined;
@@ -12,9 +12,9 @@ export declare const accessTokenCreateSchema: yup.ObjectSchema<{
12
12
  }, "">;
13
13
  export declare const accessTokenCrud: import("../../crud").CrudSchemaFromOptions<{
14
14
  clientReadSchema: yup.ObjectSchema<{
15
- accessToken: string;
15
+ access_token: string;
16
16
  }, yup.AnyObject, {
17
- accessToken: undefined;
17
+ access_token: undefined;
18
18
  }, "">;
19
19
  clientCreateSchema: yup.ObjectSchema<{
20
20
  scope: string | undefined;
@@ -1,7 +1,7 @@
1
1
  import { createCrud } from "../../crud";
2
2
  import * as yup from "yup";
3
3
  export const accessTokenReadSchema = yup.object({
4
- accessToken: yup.string().required(),
4
+ access_token: yup.string().required(),
5
5
  }).required();
6
6
  export const accessTokenCreateSchema = yup.object({
7
7
  scope: yup.string().optional(),