@stackframe/stack-shared 2.8.2 → 2.8.3

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,11 @@
1
1
  # @stackframe/stack-shared
2
2
 
3
+ ## 2.8.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Various changes
8
+
3
9
  ## 2.8.2
4
10
 
5
11
  ### Patch Changes
@@ -1,7 +1,7 @@
1
1
  import { InternalSession } from "../sessions";
2
- import { ApiKeysCrud } from "./crud/api-keys";
3
2
  import { EmailTemplateCrud, EmailTemplateType } from "./crud/email-templates";
4
3
  import { InternalEmailsCrud } from "./crud/emails";
4
+ import { InternalApiKeysCrud } from "./crud/internal-api-keys";
5
5
  import { ProjectPermissionDefinitionsCrud } from "./crud/project-permissions";
6
6
  import { ProjectsCrud } from "./crud/projects";
7
7
  import { SvixTokenCrud } from "./crud/svix-token";
@@ -12,14 +12,14 @@ export type AdminAuthApplicationOptions = ServerAuthApplicationOptions & ({
12
12
  } | {
13
13
  projectOwnerSession: InternalSession;
14
14
  });
15
- export type ApiKeyCreateCrudRequest = {
15
+ export type InternalApiKeyCreateCrudRequest = {
16
16
  has_publishable_client_key: boolean;
17
17
  has_secret_server_key: boolean;
18
18
  has_super_secret_admin_key: boolean;
19
19
  expires_at_millis: number;
20
20
  description: string;
21
21
  };
22
- export type ApiKeyCreateCrudResponse = ApiKeysCrud["Admin"]["Read"] & {
22
+ export type InternalApiKeyCreateCrudResponse = InternalApiKeysCrud["Admin"]["Read"] & {
23
23
  publishable_client_key?: string;
24
24
  secret_server_key?: string;
25
25
  super_secret_admin_key?: string;
@@ -35,10 +35,10 @@ export declare class StackAdminInterface extends StackServerInterface {
35
35
  }>;
36
36
  getProject(): Promise<ProjectsCrud["Admin"]["Read"]>;
37
37
  updateProject(update: ProjectsCrud["Admin"]["Update"]): Promise<ProjectsCrud["Admin"]["Read"]>;
38
- createApiKey(options: ApiKeyCreateCrudRequest): Promise<ApiKeyCreateCrudResponse>;
39
- listApiKeys(): Promise<ApiKeysCrud["Admin"]["Read"][]>;
40
- revokeApiKeyById(id: string): Promise<void>;
41
- getApiKey(id: string, session: InternalSession): Promise<ApiKeysCrud["Admin"]["Read"]>;
38
+ createInternalApiKey(options: InternalApiKeyCreateCrudRequest): Promise<InternalApiKeyCreateCrudResponse>;
39
+ listInternalApiKeys(): Promise<InternalApiKeysCrud["Admin"]["Read"][]>;
40
+ revokeInternalApiKeyById(id: string): Promise<void>;
41
+ getInternalApiKey(id: string, session: InternalSession): Promise<InternalApiKeysCrud["Admin"]["Read"]>;
42
42
  listEmailTemplates(): Promise<EmailTemplateCrud['Admin']['Read'][]>;
43
43
  updateEmailTemplate(type: EmailTemplateType, data: EmailTemplateCrud['Admin']['Update']): Promise<EmailTemplateCrud['Admin']['Read']>;
44
44
  resetEmailTemplate(type: EmailTemplateType): Promise<void>;
@@ -29,7 +29,7 @@ export class StackAdminInterface extends StackServerInterface {
29
29
  }, null);
30
30
  return await response.json();
31
31
  }
32
- async createApiKey(options) {
32
+ async createInternalApiKey(options) {
33
33
  const response = await this.sendAdminRequest("/internal/api-keys", {
34
34
  method: "POST",
35
35
  headers: {
@@ -39,12 +39,12 @@ export class StackAdminInterface extends StackServerInterface {
39
39
  }, null);
40
40
  return await response.json();
41
41
  }
42
- async listApiKeys() {
42
+ async listInternalApiKeys() {
43
43
  const response = await this.sendAdminRequest("/internal/api-keys", {}, null);
44
44
  const result = await response.json();
45
45
  return result.items;
46
46
  }
47
- async revokeApiKeyById(id) {
47
+ async revokeInternalApiKeyById(id) {
48
48
  await this.sendAdminRequest(`/internal/api-keys/${id}`, {
49
49
  method: "PATCH",
50
50
  headers: {
@@ -55,7 +55,7 @@ export class StackAdminInterface extends StackServerInterface {
55
55
  }),
56
56
  }, null);
57
57
  }
58
- async getApiKey(id, session) {
58
+ async getInternalApiKey(id, session) {
59
59
  const response = await this.sendAdminRequest(`/internal/api-keys/${id}`, {}, session);
60
60
  return await response.json();
61
61
  }
@@ -1,3 +1,4 @@
1
+ import * as yup from 'yup';
1
2
  import { KnownErrors } from '../known-errors';
2
3
  import { AccessToken, InternalSession, RefreshToken } from '../sessions';
3
4
  import { ReadonlyJson } from '../utils/json';
@@ -6,6 +7,7 @@ import { Result } from "../utils/results";
6
7
  import { ContactChannelsCrud } from './crud/contact-channels';
7
8
  import { CurrentUserCrud } from './crud/current-user';
8
9
  import { ConnectedAccountAccessTokenCrud } from './crud/oauth';
10
+ import { TeamApiKeysCrud, UserApiKeysCrud, teamApiKeysCreateInputSchema, teamApiKeysCreateOutputSchema, userApiKeysCreateInputSchema, userApiKeysCreateOutputSchema } from './crud/project-api-keys';
9
11
  import { ProjectPermissionsCrud } from './crud/project-permissions';
10
12
  import { InternalProjectsCrud, ProjectsCrud } from './crud/projects';
11
13
  import { SessionsCrud } from './crud/sessions';
@@ -208,4 +210,44 @@ export declare class StackClientInterface {
208
210
  listClientContactChannels(session: InternalSession): Promise<ContactChannelsCrud['Client']['Read'][]>;
209
211
  sendCurrentUserContactChannelVerificationEmail(contactChannelId: string, callbackUrl: string, session: InternalSession): Promise<Result<undefined, KnownErrors["EmailAlreadyVerified"]>>;
210
212
  cliLogin(loginCode: string, refreshToken: string, session: InternalSession): Promise<Result<undefined, KnownErrors["SchemaError"]>>;
213
+ private _getApiKeyRequestInfo;
214
+ listProjectApiKeys(options: {
215
+ user_id: string;
216
+ }, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<UserApiKeysCrud['Client']['Read'][]>;
217
+ listProjectApiKeys(options: {
218
+ team_id: string;
219
+ }, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<TeamApiKeysCrud['Client']['Read'][]>;
220
+ listProjectApiKeys(options: {
221
+ user_id: string;
222
+ } | {
223
+ team_id: string;
224
+ }, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<(UserApiKeysCrud['Client']['Read'] | TeamApiKeysCrud['Client']['Read'])[]>;
225
+ createProjectApiKey(data: yup.InferType<typeof userApiKeysCreateInputSchema>, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<yup.InferType<typeof userApiKeysCreateOutputSchema>>;
226
+ createProjectApiKey(data: yup.InferType<typeof teamApiKeysCreateInputSchema>, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<yup.InferType<typeof teamApiKeysCreateOutputSchema>>;
227
+ createProjectApiKey(data: yup.InferType<typeof userApiKeysCreateInputSchema> | yup.InferType<typeof teamApiKeysCreateInputSchema>, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<yup.InferType<typeof userApiKeysCreateOutputSchema> | yup.InferType<typeof teamApiKeysCreateOutputSchema>>;
228
+ getProjectApiKey(options: {
229
+ user_id: string | null;
230
+ }, keyId: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<UserApiKeysCrud['Client']['Read']>;
231
+ getProjectApiKey(options: {
232
+ team_id: string;
233
+ }, keyId: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<TeamApiKeysCrud['Client']['Read']>;
234
+ getProjectApiKey(options: {
235
+ user_id: string | null;
236
+ } | {
237
+ team_id: string;
238
+ }, keyId: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<UserApiKeysCrud['Client']['Read'] | TeamApiKeysCrud['Client']['Read']>;
239
+ updateProjectApiKey(options: {
240
+ user_id: string;
241
+ }, keyId: string, data: UserApiKeysCrud['Client']['Update'], session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<UserApiKeysCrud['Client']['Read']>;
242
+ updateProjectApiKey(options: {
243
+ team_id: string;
244
+ }, keyId: string, data: TeamApiKeysCrud['Client']['Update'], session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<TeamApiKeysCrud['Client']['Read']>;
245
+ updateProjectApiKey(options: {
246
+ user_id: string;
247
+ } | {
248
+ team_id: string;
249
+ }, keyId: string, data: UserApiKeysCrud['Client']['Update'] | TeamApiKeysCrud['Client']['Update'], session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<UserApiKeysCrud['Client']['Read'] | TeamApiKeysCrud['Client']['Read']>;
250
+ checkProjectApiKey(type: "user", apiKey: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<UserApiKeysCrud['Client']['Read'] | null>;
251
+ checkProjectApiKey(type: "team", apiKey: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<TeamApiKeysCrud['Client']['Read'] | null>;
252
+ checkProjectApiKey(type: "user" | "team", apiKey: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<UserApiKeysCrud['Client']['Read'] | TeamApiKeysCrud['Client']['Read'] | null>;
211
253
  }
@@ -5,7 +5,7 @@ import { generateSecureRandomString } from '../utils/crypto';
5
5
  import { StackAssertionError, throwErr } from '../utils/errors';
6
6
  import { globalVar } from '../utils/globals';
7
7
  import { HTTP_METHODS } from '../utils/http';
8
- import { filterUndefined } from '../utils/objects';
8
+ import { filterUndefined, filterUndefinedOrNull } from '../utils/objects';
9
9
  import { wait } from '../utils/promises';
10
10
  import { Result } from "../utils/results";
11
11
  import { deindent } from '../utils/strings';
@@ -173,7 +173,7 @@ export class StackClientInterface {
173
173
  }
174
174
  const params = {
175
175
  /**
176
- * This fetch may be cross-origin, in which case we don't want to send cookies of the
176
+ * This fetch may be cross-origin, in which case we don't want to send cookies of the
177
177
  * original origin (this is the default behavior of `credentials`).
178
178
  *
179
179
  * To help debugging, also omit cookies on same-origin, so we don't accidentally
@@ -942,4 +942,68 @@ export class StackClientInterface {
942
942
  }
943
943
  return Result.ok(undefined);
944
944
  }
945
+ async _getApiKeyRequestInfo(options) {
946
+ if ("user_id" in options && "team_id" in options) {
947
+ throw new StackAssertionError("Cannot specify both user_id and team_id in _getApiKeyRequestInfo");
948
+ }
949
+ return {
950
+ endpoint: "team_id" in options ? "/team-api-keys" : "/user-api-keys",
951
+ queryParams: new URLSearchParams(filterUndefinedOrNull(options)),
952
+ };
953
+ }
954
+ async listProjectApiKeys(options, session, requestType) {
955
+ const sendRequest = (requestType === "client" ? this.sendClientRequest : this.sendServerRequest).bind(this);
956
+ const { endpoint, queryParams } = await this._getApiKeyRequestInfo(options);
957
+ const response = await sendRequest(`${endpoint}?${queryParams.toString()}`, {
958
+ method: "GET",
959
+ }, session, requestType);
960
+ const json = await response.json();
961
+ return json.items;
962
+ }
963
+ async createProjectApiKey(data, session, requestType) {
964
+ const sendRequest = (requestType === "client" ? this.sendClientRequest : this.sendServerRequest).bind(this);
965
+ const { endpoint } = await this._getApiKeyRequestInfo(data);
966
+ const response = await sendRequest(`${endpoint}`, {
967
+ method: "POST",
968
+ headers: {
969
+ "content-type": "application/json",
970
+ },
971
+ body: JSON.stringify(data),
972
+ }, session, requestType);
973
+ return await response.json();
974
+ }
975
+ async getProjectApiKey(options, keyId, session, requestType) {
976
+ const sendRequest = (requestType === "client" ? this.sendClientRequest : this.sendServerRequest).bind(this);
977
+ const { endpoint, queryParams } = await this._getApiKeyRequestInfo(options);
978
+ const response = await sendRequest(`${endpoint}/${keyId}?${queryParams.toString()}`, {
979
+ method: "GET",
980
+ }, session, requestType);
981
+ return await response.json();
982
+ }
983
+ async updateProjectApiKey(options, keyId, data, session, requestType) {
984
+ const sendRequest = (requestType === "client" ? this.sendClientRequest : this.sendServerRequest).bind(this);
985
+ const { endpoint, queryParams } = await this._getApiKeyRequestInfo(options);
986
+ const response = await sendRequest(`${endpoint}/${keyId}?${queryParams.toString()}`, {
987
+ method: "PATCH",
988
+ headers: {
989
+ "content-type": "application/json",
990
+ },
991
+ body: JSON.stringify(data),
992
+ }, session, requestType);
993
+ return await response.json();
994
+ }
995
+ async checkProjectApiKey(type, apiKey, session, requestType) {
996
+ const sendRequest = (requestType === "client" ? this.sendClientRequestAndCatchKnownError : this.sendServerRequestAndCatchKnownError).bind(this);
997
+ const result = await sendRequest(`/${type}-api-keys/check`, {
998
+ method: "POST",
999
+ headers: {
1000
+ "content-type": "application/json",
1001
+ },
1002
+ body: JSON.stringify({ api_key: apiKey }),
1003
+ }, session, [KnownErrors.ApiKeyNotValid]);
1004
+ if (result.status === "error") {
1005
+ return null;
1006
+ }
1007
+ return await result.data.json();
1008
+ }
945
1009
  }
@@ -68,8 +68,8 @@ export declare const currentUserCrud: import("../../crud").CrudSchemaFromOptions
68
68
  client_read_only_metadata?: {} | null | undefined;
69
69
  server_metadata?: {} | null | undefined;
70
70
  id: string;
71
- created_at_millis: number;
72
71
  display_name: string;
72
+ created_at_millis: number;
73
73
  profile_image_url: string | null;
74
74
  } | null;
75
75
  selected_team_id: string | null;
@@ -1,5 +1,5 @@
1
1
  import { CrudTypeOf } from "../../crud";
2
- export declare const apiKeysCreateInputSchema: import("yup").ObjectSchema<{
2
+ export declare const internalApiKeysCreateInputSchema: import("yup").ObjectSchema<{
3
3
  description: string;
4
4
  expires_at_millis: number;
5
5
  has_publishable_client_key: boolean;
@@ -12,7 +12,7 @@ export declare const apiKeysCreateInputSchema: import("yup").ObjectSchema<{
12
12
  has_secret_server_key: undefined;
13
13
  has_super_secret_admin_key: undefined;
14
14
  }, "">;
15
- export declare const apiKeysCreateOutputSchema: import("yup").ObjectSchema<{
15
+ export declare const internalApiKeysCreateOutputSchema: import("yup").ObjectSchema<{
16
16
  id: string;
17
17
  description: string;
18
18
  expires_at_millis: number;
@@ -32,7 +32,7 @@ export declare const apiKeysCreateOutputSchema: import("yup").ObjectSchema<{
32
32
  secret_server_key: undefined;
33
33
  super_secret_admin_key: undefined;
34
34
  }, "">;
35
- export declare const apiKeysCrudAdminObfuscatedReadSchema: import("yup").ObjectSchema<{
35
+ export declare const internalApiKeysCrudAdminObfuscatedReadSchema: import("yup").ObjectSchema<{
36
36
  id: string;
37
37
  description: string;
38
38
  expires_at_millis: number;
@@ -64,15 +64,15 @@ export declare const apiKeysCrudAdminObfuscatedReadSchema: import("yup").ObjectS
64
64
  last_four: undefined;
65
65
  };
66
66
  }, "">;
67
- export declare const apiKeysCrudAdminUpdateSchema: import("yup").ObjectSchema<{
67
+ export declare const internalApiKeysCrudAdminUpdateSchema: import("yup").ObjectSchema<{
68
68
  description: string | undefined;
69
69
  revoked: boolean | undefined;
70
70
  }, import("yup").AnyObject, {
71
71
  description: undefined;
72
72
  revoked: undefined;
73
73
  }, "">;
74
- export declare const apiKeysCrudAdminDeleteSchema: import("yup").MixedSchema<{} | undefined, import("yup").AnyObject, undefined, "">;
75
- export declare const apiKeysCrud: import("../../crud").CrudSchemaFromOptions<{
74
+ export declare const internalApiKeysCrudAdminDeleteSchema: import("yup").MixedSchema<{} | undefined, import("yup").AnyObject, undefined, "">;
75
+ export declare const internalApiKeysCrud: import("../../crud").CrudSchemaFromOptions<{
76
76
  adminReadSchema: import("yup").ObjectSchema<{
77
77
  id: string;
78
78
  description: string;
@@ -131,4 +131,4 @@ export declare const apiKeysCrud: import("../../crud").CrudSchemaFromOptions<{
131
131
  };
132
132
  };
133
133
  }>;
134
- export type ApiKeysCrud = CrudTypeOf<typeof apiKeysCrud>;
134
+ export type InternalApiKeysCrud = CrudTypeOf<typeof internalApiKeysCrud>;
@@ -1,6 +1,6 @@
1
1
  import { createCrud } from "../../crud";
2
2
  import { yupBoolean, yupMixed, yupNumber, yupObject, yupString } from "../../schema-fields";
3
- const baseApiKeysReadSchema = yupObject({
3
+ const baseInternalApiKeysReadSchema = yupObject({
4
4
  id: yupString().defined(),
5
5
  description: yupString().defined(),
6
6
  expires_at_millis: yupNumber().defined(),
@@ -8,20 +8,20 @@ const baseApiKeysReadSchema = yupObject({
8
8
  created_at_millis: yupNumber().defined(),
9
9
  });
10
10
  // Used for the result of the create endpoint
11
- export const apiKeysCreateInputSchema = yupObject({
11
+ export const internalApiKeysCreateInputSchema = yupObject({
12
12
  description: yupString().defined(),
13
13
  expires_at_millis: yupNumber().defined(),
14
14
  has_publishable_client_key: yupBoolean().defined(),
15
15
  has_secret_server_key: yupBoolean().defined(),
16
16
  has_super_secret_admin_key: yupBoolean().defined(),
17
17
  });
18
- export const apiKeysCreateOutputSchema = baseApiKeysReadSchema.concat(yupObject({
18
+ export const internalApiKeysCreateOutputSchema = baseInternalApiKeysReadSchema.concat(yupObject({
19
19
  publishable_client_key: yupString().optional(),
20
20
  secret_server_key: yupString().optional(),
21
21
  super_secret_admin_key: yupString().optional(),
22
22
  }).defined());
23
23
  // Used for list, read and update endpoints after the initial creation
24
- export const apiKeysCrudAdminObfuscatedReadSchema = baseApiKeysReadSchema.concat(yupObject({
24
+ export const internalApiKeysCrudAdminObfuscatedReadSchema = baseInternalApiKeysReadSchema.concat(yupObject({
25
25
  publishable_client_key: yupObject({
26
26
  last_four: yupString().defined(),
27
27
  }).optional(),
@@ -32,15 +32,15 @@ export const apiKeysCrudAdminObfuscatedReadSchema = baseApiKeysReadSchema.concat
32
32
  last_four: yupString().defined(),
33
33
  }).optional(),
34
34
  }));
35
- export const apiKeysCrudAdminUpdateSchema = yupObject({
35
+ export const internalApiKeysCrudAdminUpdateSchema = yupObject({
36
36
  description: yupString().optional(),
37
37
  revoked: yupBoolean().oneOf([true]).optional(),
38
38
  }).defined();
39
- export const apiKeysCrudAdminDeleteSchema = yupMixed();
40
- export const apiKeysCrud = createCrud({
41
- adminReadSchema: apiKeysCrudAdminObfuscatedReadSchema,
42
- adminUpdateSchema: apiKeysCrudAdminUpdateSchema,
43
- adminDeleteSchema: apiKeysCrudAdminDeleteSchema,
39
+ export const internalApiKeysCrudAdminDeleteSchema = yupMixed();
40
+ export const internalApiKeysCrud = createCrud({
41
+ adminReadSchema: internalApiKeysCrudAdminObfuscatedReadSchema,
42
+ adminUpdateSchema: internalApiKeysCrudAdminUpdateSchema,
43
+ adminDeleteSchema: internalApiKeysCrudAdminDeleteSchema,
44
44
  docs: {
45
45
  adminList: {
46
46
  hidden: true,
@@ -0,0 +1,188 @@
1
+ import * as yup from "yup";
2
+ import { CrudTypeOf } from "../../crud";
3
+ export declare const userApiKeysCrud: import("../../crud").CrudSchemaFromOptions<{
4
+ clientReadSchema: yup.ObjectSchema<{
5
+ id: string;
6
+ description: string;
7
+ expires_at_millis: number | undefined;
8
+ manually_revoked_at_millis: number | undefined;
9
+ created_at_millis: number;
10
+ is_public: boolean;
11
+ value: {
12
+ last_four: string;
13
+ };
14
+ type: "user";
15
+ user_id: string;
16
+ }, yup.AnyObject, {
17
+ id: undefined;
18
+ description: undefined;
19
+ expires_at_millis: undefined;
20
+ manually_revoked_at_millis: undefined;
21
+ created_at_millis: undefined;
22
+ is_public: undefined;
23
+ value: {
24
+ last_four: undefined;
25
+ };
26
+ type: undefined;
27
+ user_id: undefined;
28
+ }, "">;
29
+ clientUpdateSchema: yup.ObjectSchema<{
30
+ description: string | undefined;
31
+ revoked: boolean | undefined;
32
+ }, yup.AnyObject, {
33
+ description: undefined;
34
+ revoked: undefined;
35
+ }, "">;
36
+ docs: {
37
+ clientCreate: {
38
+ description: string;
39
+ displayName: string;
40
+ summary: string;
41
+ };
42
+ clientList: {
43
+ description: string;
44
+ displayName: string;
45
+ summary: string;
46
+ };
47
+ clientRead: {
48
+ description: string;
49
+ displayName: string;
50
+ summary: string;
51
+ };
52
+ clientUpdate: {
53
+ description: string;
54
+ displayName: string;
55
+ summary: string;
56
+ };
57
+ serverDelete: {
58
+ description: string;
59
+ displayName: string;
60
+ summary: string;
61
+ };
62
+ };
63
+ }>, userApiKeysCreateInputSchema: yup.ObjectSchema<{
64
+ description: string;
65
+ expires_at_millis: number | null;
66
+ is_public: boolean | undefined;
67
+ user_id: string;
68
+ }, yup.AnyObject, {
69
+ description: undefined;
70
+ expires_at_millis: undefined;
71
+ is_public: undefined;
72
+ user_id: undefined;
73
+ }, "">, userApiKeysCreateOutputSchema: yup.ObjectSchema<{
74
+ type: "user";
75
+ user_id: string;
76
+ description: string;
77
+ id: string;
78
+ created_at_millis: number;
79
+ expires_at_millis: number | undefined;
80
+ manually_revoked_at_millis: number | undefined;
81
+ is_public: boolean;
82
+ } & {
83
+ value: string;
84
+ }, yup.AnyObject, {
85
+ id: undefined;
86
+ description: undefined;
87
+ expires_at_millis: undefined;
88
+ manually_revoked_at_millis: undefined;
89
+ created_at_millis: undefined;
90
+ is_public: undefined;
91
+ value: undefined;
92
+ type: undefined;
93
+ user_id: undefined;
94
+ }, "">;
95
+ export type UserApiKeysCrud = CrudTypeOf<typeof userApiKeysCrud>;
96
+ export declare const teamApiKeysCrud: import("../../crud").CrudSchemaFromOptions<{
97
+ clientReadSchema: yup.ObjectSchema<{
98
+ id: string;
99
+ description: string;
100
+ expires_at_millis: number | undefined;
101
+ manually_revoked_at_millis: number | undefined;
102
+ created_at_millis: number;
103
+ is_public: boolean;
104
+ value: {
105
+ last_four: string;
106
+ };
107
+ type: "team";
108
+ team_id: string;
109
+ }, yup.AnyObject, {
110
+ id: undefined;
111
+ description: undefined;
112
+ expires_at_millis: undefined;
113
+ manually_revoked_at_millis: undefined;
114
+ created_at_millis: undefined;
115
+ is_public: undefined;
116
+ value: {
117
+ last_four: undefined;
118
+ };
119
+ type: undefined;
120
+ team_id: undefined;
121
+ }, "">;
122
+ clientUpdateSchema: yup.ObjectSchema<{
123
+ description: string | undefined;
124
+ revoked: boolean | undefined;
125
+ }, yup.AnyObject, {
126
+ description: undefined;
127
+ revoked: undefined;
128
+ }, "">;
129
+ docs: {
130
+ clientCreate: {
131
+ description: string;
132
+ displayName: string;
133
+ summary: string;
134
+ };
135
+ clientList: {
136
+ description: string;
137
+ displayName: string;
138
+ summary: string;
139
+ };
140
+ clientRead: {
141
+ description: string;
142
+ displayName: string;
143
+ summary: string;
144
+ };
145
+ clientUpdate: {
146
+ description: string;
147
+ displayName: string;
148
+ summary: string;
149
+ };
150
+ serverDelete: {
151
+ description: string;
152
+ displayName: string;
153
+ summary: string;
154
+ };
155
+ };
156
+ }>, teamApiKeysCreateInputSchema: yup.ObjectSchema<{
157
+ description: string;
158
+ expires_at_millis: number | null;
159
+ is_public: boolean | undefined;
160
+ team_id: string;
161
+ }, yup.AnyObject, {
162
+ description: undefined;
163
+ expires_at_millis: undefined;
164
+ is_public: undefined;
165
+ team_id: undefined;
166
+ }, "">, teamApiKeysCreateOutputSchema: yup.ObjectSchema<{
167
+ type: "team";
168
+ team_id: string;
169
+ description: string;
170
+ id: string;
171
+ created_at_millis: number;
172
+ expires_at_millis: number | undefined;
173
+ manually_revoked_at_millis: number | undefined;
174
+ is_public: boolean;
175
+ } & {
176
+ value: string;
177
+ }, yup.AnyObject, {
178
+ id: undefined;
179
+ description: undefined;
180
+ expires_at_millis: undefined;
181
+ manually_revoked_at_millis: undefined;
182
+ created_at_millis: undefined;
183
+ is_public: undefined;
184
+ value: undefined;
185
+ type: undefined;
186
+ team_id: undefined;
187
+ }, "">;
188
+ export type TeamApiKeysCrud = CrudTypeOf<typeof teamApiKeysCrud>;
@@ -0,0 +1,76 @@
1
+ import { createCrud } from "../../crud";
2
+ import { userIdOrMeSchema, yupBoolean, yupNumber, yupObject, yupString } from "../../schema-fields";
3
+ import { typedFromEntries } from "../../utils/objects";
4
+ function createApiKeyCrud(type, idFieldName, idSchema) {
5
+ const projectApiKeysReadSchema = yupObject({
6
+ id: yupString().defined(),
7
+ description: yupString().defined(),
8
+ expires_at_millis: yupNumber().optional(),
9
+ manually_revoked_at_millis: yupNumber().optional(),
10
+ created_at_millis: yupNumber().defined(),
11
+ is_public: yupBoolean().defined(),
12
+ value: yupObject({
13
+ last_four: yupString().defined(),
14
+ }).defined(),
15
+ type: yupString().oneOf([type]).defined(),
16
+ ...typedFromEntries([[idFieldName, idSchema]]),
17
+ });
18
+ const projectApiKeysUpdateSchema = yupObject({
19
+ description: yupString().optional(),
20
+ revoked: yupBoolean().oneOf([true]).optional(),
21
+ }).defined();
22
+ const projectApiKeysCrud = createCrud({
23
+ clientReadSchema: projectApiKeysReadSchema,
24
+ clientUpdateSchema: projectApiKeysUpdateSchema,
25
+ docs: {
26
+ clientCreate: {
27
+ description: "Create a new API key",
28
+ displayName: "Create API Key",
29
+ summary: "Create API key",
30
+ },
31
+ clientList: {
32
+ description: "List all API keys for the project",
33
+ displayName: "List API Keys",
34
+ summary: "List API keys",
35
+ },
36
+ clientRead: {
37
+ description: "Get details of a specific API key",
38
+ displayName: "Get API Key",
39
+ summary: "Get API key details",
40
+ },
41
+ clientUpdate: {
42
+ description: "Update an API key",
43
+ displayName: "Update API Key",
44
+ summary: "Update API key",
45
+ },
46
+ serverDelete: {
47
+ description: "Delete an API key",
48
+ displayName: "Delete API Key",
49
+ summary: "Delete API key",
50
+ },
51
+ },
52
+ });
53
+ // Used for the result of the create endpoint
54
+ const projectApiKeysCreateInputSchema = yupObject({
55
+ description: yupString().defined(),
56
+ expires_at_millis: yupNumber().nullable().defined(),
57
+ is_public: yupBoolean().optional(),
58
+ /*
59
+ prefix: yupString().optional().nonEmpty().test("prefix", "Prefix must contain only alphanumeric characters and underscores", (value) => {
60
+ if (!value) return true;
61
+ return /^[a-zA-Z0-9_]+$/.test(value);
62
+ }),
63
+ */
64
+ ...typedFromEntries([[idFieldName, idSchema]]),
65
+ });
66
+ const projectApiKeysCreateOutputSchema = projectApiKeysReadSchema.omit(["value"]).concat(yupObject({
67
+ value: yupString().defined(),
68
+ }));
69
+ return {
70
+ crud: projectApiKeysCrud,
71
+ createInputSchema: projectApiKeysCreateInputSchema,
72
+ createOutputSchema: projectApiKeysCreateOutputSchema,
73
+ };
74
+ }
75
+ export const { crud: userApiKeysCrud, createInputSchema: userApiKeysCreateInputSchema, createOutputSchema: userApiKeysCreateOutputSchema, } = createApiKeyCrud("user", "user_id", userIdOrMeSchema.defined());
76
+ export const { crud: teamApiKeysCrud, createInputSchema: teamApiKeysCreateInputSchema, createOutputSchema: teamApiKeysCreateOutputSchema, } = createApiKeyCrud("team", "team_id", yupString().defined());