@stackframe/js 2.8.2 → 2.8.5
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 +29 -0
- package/dist/esm/lib/stack-app/api-keys/index.js +14 -6
- package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +23 -20
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +161 -0
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +106 -3
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/index.js.map +1 -1
- package/dist/esm/lib/stack-app/internal-api-keys/index.js +14 -0
- package/dist/esm/lib/stack-app/internal-api-keys/index.js.map +1 -0
- package/dist/esm/lib/stack-app/projects/index.js +3 -1
- package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
- package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
- package/dist/esm/lib/stack-app/users/index.js.map +1 -1
- package/dist/index.d.mts +94 -34
- package/dist/index.d.ts +94 -34
- package/dist/lib/stack-app/api-keys/index.js +16 -7
- package/dist/lib/stack-app/api-keys/index.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +22 -19
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +161 -0
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +106 -3
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/index.js.map +1 -1
- package/dist/lib/stack-app/internal-api-keys/index.js +39 -0
- package/dist/lib/stack-app/internal-api-keys/index.js.map +1 -0
- package/dist/lib/stack-app/project-configs/index.js.map +1 -1
- package/dist/lib/stack-app/projects/index.js +3 -1
- package/dist/lib/stack-app/projects/index.js.map +1 -1
- package/dist/lib/stack-app/teams/index.js.map +1 -1
- package/dist/lib/stack-app/users/index.js.map +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @stackframe/stack
|
|
2
2
|
|
|
3
|
+
## 2.8.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Various changes
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @stackframe/stack-shared@2.8.5
|
|
10
|
+
- @stackframe/stack-ui@2.8.5
|
|
11
|
+
- @stackframe/stack-sc@2.8.5
|
|
12
|
+
|
|
13
|
+
## 2.8.4
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- @stackframe/stack-shared@2.8.4
|
|
19
|
+
- @stackframe/stack-ui@2.8.4
|
|
20
|
+
- @stackframe/stack-sc@2.8.4
|
|
21
|
+
|
|
22
|
+
## 2.8.3
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Various changes
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- @stackframe/stack-shared@2.8.3
|
|
29
|
+
- @stackframe/stack-ui@2.8.3
|
|
30
|
+
- @stackframe/stack-sc@2.8.3
|
|
31
|
+
|
|
3
32
|
## 2.8.2
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
// src/lib/stack-app/api-keys/index.ts
|
|
2
|
-
|
|
2
|
+
import { filterUndefined } from "@stackframe/stack-shared/dist/utils/objects";
|
|
3
|
+
async function apiKeyCreationOptionsToCrud(type, userIdOrTeamId, options) {
|
|
3
4
|
return {
|
|
4
5
|
description: options.description,
|
|
5
|
-
expires_at_millis: options.expiresAt.getTime(),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
has_super_secret_admin_key: options.hasSuperSecretAdminKey
|
|
6
|
+
expires_at_millis: options.expiresAt == null ? options.expiresAt : options.expiresAt.getTime(),
|
|
7
|
+
is_public: options.isPublic,
|
|
8
|
+
...type === "user" ? { user_id: userIdOrTeamId } : { team_id: userIdOrTeamId }
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
async function apiKeyUpdateOptionsToCrud(type, options) {
|
|
12
|
+
return filterUndefined({
|
|
13
|
+
description: options.description,
|
|
14
|
+
expires_at_millis: options.expiresAt == null ? options.expiresAt : options.expiresAt.getTime(),
|
|
15
|
+
revoked: options.revoked
|
|
16
|
+
});
|
|
17
|
+
}
|
|
11
18
|
export {
|
|
12
|
-
|
|
19
|
+
apiKeyCreationOptionsToCrud,
|
|
20
|
+
apiKeyUpdateOptionsToCrud
|
|
13
21
|
};
|
|
14
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/stack-app/api-keys/index.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/stack-app/api-keys/index.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { TeamApiKeysCrud, UserApiKeysCrud, teamApiKeysCreateInputSchema, userApiKeysCreateInputSchema } from \"@stackframe/stack-shared/dist/interface/crud/project-api-keys\";\nimport { filterUndefined } from \"@stackframe/stack-shared/dist/utils/objects\";\nimport { IfAndOnlyIf, PrettifyType } from \"@stackframe/stack-shared/dist/utils/types\";\nimport type * as yup from \"yup\";\n\nexport type ApiKeyType = \"user\" | \"team\";\n\nexport type ApiKey<Type extends ApiKeyType = ApiKeyType, IsFirstView extends boolean = false> =\n & {\n id: string,\n description: string,\n expiresAt?: Date,\n manuallyRevokedAt?: Date | null,\n createdAt: Date,\n value: IfAndOnlyIf<IsFirstView, true, string, { lastFour: string }>,\n update(options: ApiKeyUpdateOptions<Type>): Promise<void>,\n revoke: () => Promise<void>,\n isValid: () => boolean,\n whyInvalid: () => \"manually-revoked\" | \"expired\" | null,\n }\n & (\n | (\"user\" extends Type ? { type: \"user\", userId: string } : never)\n | (\"team\" extends Type ? { type: \"team\", teamId: string } : never)\n );\n\nexport type UserApiKeyFirstView = PrettifyType<ApiKey<\"user\", true>>;\nexport type UserApiKey = PrettifyType<ApiKey<\"user\", false>>;\n\nexport type TeamApiKeyFirstView = PrettifyType<ApiKey<\"team\", true>>;\nexport type TeamApiKey = PrettifyType<ApiKey<\"team\", false>>;\n\nexport type ApiKeyCreationOptions<Type extends ApiKeyType = ApiKeyType> =\n & {\n description: string,\n expiresAt: Date | null,\n /**\n * Whether the API key should be considered public. A public API key will not be detected by the secret scanner, which\n * automatically revokes API keys when it detects that they may have been exposed to the public.\n */\n isPublic?: boolean,\n };\nexport function apiKeyCreationOptionsToCrud(type: \"user\", userId: string, options: ApiKeyCreationOptions<\"user\">): Promise<yup.InferType<typeof userApiKeysCreateInputSchema>>;\nexport function apiKeyCreationOptionsToCrud(type: \"team\", teamId: string, options: ApiKeyCreationOptions<\"team\">): Promise<yup.InferType<typeof teamApiKeysCreateInputSchema>>;\nexport function apiKeyCreationOptionsToCrud(type: ApiKeyType, userIdOrTeamId: string, options: ApiKeyCreationOptions): Promise<yup.InferType<typeof userApiKeysCreateInputSchema> | yup.InferType<typeof teamApiKeysCreateInputSchema>>;\nexport async function apiKeyCreationOptionsToCrud(type: ApiKeyType, userIdOrTeamId: string, options: ApiKeyCreationOptions): Promise<yup.InferType<typeof userApiKeysCreateInputSchema> | yup.InferType<typeof teamApiKeysCreateInputSchema>> {\n return {\n description: options.description,\n expires_at_millis: options.expiresAt == null ? options.expiresAt : options.expiresAt.getTime(),\n is_public: options.isPublic,\n ...(type === \"user\" ? { user_id: userIdOrTeamId } : { team_id: userIdOrTeamId }),\n };\n}\n\n\nexport type ApiKeyUpdateOptions<Type extends ApiKeyType = ApiKeyType> = {\n description?: string,\n expiresAt?: Date | null,\n revoked?: boolean,\n};\nexport function apiKeyUpdateOptionsToCrud(type: \"user\", options: ApiKeyUpdateOptions<\"user\">): Promise<UserApiKeysCrud[\"Client\"][\"Update\"]>;\nexport function apiKeyUpdateOptionsToCrud(type: \"team\", options: ApiKeyUpdateOptions<\"team\">): Promise<TeamApiKeysCrud[\"Client\"][\"Update\"]>;\nexport function apiKeyUpdateOptionsToCrud(type: ApiKeyType, options: ApiKeyUpdateOptions): Promise<UserApiKeysCrud[\"Client\"][\"Update\"] | TeamApiKeysCrud[\"Client\"][\"Update\"]>;\nexport async function apiKeyUpdateOptionsToCrud(type: ApiKeyType, options: ApiKeyUpdateOptions): Promise<UserApiKeysCrud[\"Client\"][\"Update\"] | TeamApiKeysCrud[\"Client\"][\"Update\"]> {\n return filterUndefined({\n description: options.description,\n expires_at_millis: options.expiresAt == null ? options.expiresAt : options.expiresAt.getTime(),\n revoked: options.revoked,\n });\n}\n"],"mappings":";AAKA,SAAS,uBAAuB;AA2ChC,eAAsB,4BAA4B,MAAkB,gBAAwB,SAAkJ;AAC5O,SAAO;AAAA,IACL,aAAa,QAAQ;AAAA,IACrB,mBAAmB,QAAQ,aAAa,OAAO,QAAQ,YAAY,QAAQ,UAAU,QAAQ;AAAA,IAC7F,WAAW,QAAQ;AAAA,IACnB,GAAI,SAAS,SAAS,EAAE,SAAS,eAAe,IAAI,EAAE,SAAS,eAAe;AAAA,EAChF;AACF;AAWA,eAAsB,0BAA0B,MAAkB,SAAkH;AAClL,SAAO,gBAAgB;AAAA,IACrB,aAAa,QAAQ;AAAA,IACrB,mBAAmB,QAAQ,aAAa,OAAO,QAAQ,YAAY,QAAQ,UAAU,QAAQ;AAAA,IAC7F,SAAS,QAAQ;AAAA,EACnB,CAAC;AACH;","names":[]}
|
|
@@ -4,10 +4,10 @@ import { getProductionModeErrors } from "@stackframe/stack-shared/dist/helpers/p
|
|
|
4
4
|
import { StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
|
|
5
5
|
import { pick } from "@stackframe/stack-shared/dist/utils/objects";
|
|
6
6
|
import { Result } from "@stackframe/stack-shared/dist/utils/results";
|
|
7
|
-
import { apiKeyCreateOptionsToCrud } from "../../api-keys";
|
|
8
7
|
import { stackAppInternalsSymbol } from "../../common";
|
|
9
8
|
import { adminEmailTemplateUpdateOptionsToCrud } from "../../email-templates";
|
|
10
|
-
import {
|
|
9
|
+
import { internalApiKeyCreateOptionsToCrud } from "../../internal-api-keys";
|
|
10
|
+
import { adminProjectPermissionDefinitionCreateOptionsToCrud, adminProjectPermissionDefinitionUpdateOptionsToCrud, adminTeamPermissionDefinitionCreateOptionsToCrud, adminTeamPermissionDefinitionUpdateOptionsToCrud } from "../../permissions";
|
|
11
11
|
import { adminProjectUpdateOptionsToCrud } from "../../projects";
|
|
12
12
|
import { clientVersion, createCache, getBaseUrl, getDefaultProjectId, getDefaultPublishableClientKey, getDefaultSecretServerKey, getDefaultSuperSecretAdminKey } from "./common";
|
|
13
13
|
import { _StackServerAppImplIncomplete } from "./server-app-impl";
|
|
@@ -38,8 +38,9 @@ var _StackAdminAppImplIncomplete = class extends _StackServerAppImplIncomplete {
|
|
|
38
38
|
this._adminProjectCache = createCache(async () => {
|
|
39
39
|
return await this._interface.getProject();
|
|
40
40
|
});
|
|
41
|
-
this.
|
|
42
|
-
|
|
41
|
+
this._internalApiKeysCache = createCache(async () => {
|
|
42
|
+
const res = await this._interface.listInternalApiKeys();
|
|
43
|
+
return res;
|
|
43
44
|
});
|
|
44
45
|
this._adminEmailTemplatesCache = createCache(async () => {
|
|
45
46
|
return await this._interface.listEmailTemplates();
|
|
@@ -89,6 +90,8 @@ var _StackAdminAppImplIncomplete = class extends _StackServerAppImplIncomplete {
|
|
|
89
90
|
clientUserDeletionEnabled: data.config.client_user_deletion_enabled,
|
|
90
91
|
allowLocalhost: data.config.allow_localhost,
|
|
91
92
|
oauthAccountMergeStrategy: data.config.oauth_account_merge_strategy,
|
|
93
|
+
allowUserApiKeys: data.config.allow_user_api_keys,
|
|
94
|
+
allowTeamApiKeys: data.config.allow_team_api_keys,
|
|
92
95
|
oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
|
|
93
96
|
id: p.id,
|
|
94
97
|
enabled: p.enabled,
|
|
@@ -151,7 +154,7 @@ var _StackAdminAppImplIncomplete = class extends _StackServerAppImplIncomplete {
|
|
|
151
154
|
() => this._refreshProject()
|
|
152
155
|
);
|
|
153
156
|
}
|
|
154
|
-
|
|
157
|
+
_createInternalApiKeyBaseFromCrud(data) {
|
|
155
158
|
const app = this;
|
|
156
159
|
return {
|
|
157
160
|
id: data.id,
|
|
@@ -168,36 +171,36 @@ var _StackAdminAppImplIncomplete = class extends _StackServerAppImplIncomplete {
|
|
|
168
171
|
return null;
|
|
169
172
|
},
|
|
170
173
|
async revoke() {
|
|
171
|
-
const res = await app._interface.
|
|
172
|
-
await app.
|
|
174
|
+
const res = await app._interface.revokeInternalApiKeyById(data.id);
|
|
175
|
+
await app._refreshInternalApiKeys();
|
|
173
176
|
return res;
|
|
174
177
|
}
|
|
175
178
|
};
|
|
176
179
|
}
|
|
177
|
-
|
|
180
|
+
_createInternalApiKeyFromCrud(data) {
|
|
178
181
|
return {
|
|
179
|
-
...this.
|
|
182
|
+
...this._createInternalApiKeyBaseFromCrud(data),
|
|
180
183
|
publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,
|
|
181
184
|
secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,
|
|
182
185
|
superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null
|
|
183
186
|
};
|
|
184
187
|
}
|
|
185
|
-
|
|
188
|
+
_createInternalApiKeyFirstViewFromCrud(data) {
|
|
186
189
|
return {
|
|
187
|
-
...this.
|
|
190
|
+
...this._createInternalApiKeyBaseFromCrud(data),
|
|
188
191
|
publishableClientKey: data.publishable_client_key,
|
|
189
192
|
secretServerKey: data.secret_server_key,
|
|
190
193
|
superSecretAdminKey: data.super_secret_admin_key
|
|
191
194
|
};
|
|
192
195
|
}
|
|
193
|
-
async
|
|
194
|
-
const crud = Result.orThrow(await this.
|
|
195
|
-
return crud.map((j) => this.
|
|
196
|
+
async listInternalApiKeys() {
|
|
197
|
+
const crud = Result.orThrow(await this._internalApiKeysCache.getOrWait([], "write-only"));
|
|
198
|
+
return crud.map((j) => this._createInternalApiKeyFromCrud(j));
|
|
196
199
|
}
|
|
197
|
-
async
|
|
198
|
-
const crud = await this._interface.
|
|
199
|
-
await this.
|
|
200
|
-
return this.
|
|
200
|
+
async createInternalApiKey(options) {
|
|
201
|
+
const crud = await this._interface.createInternalApiKey(internalApiKeyCreateOptionsToCrud(options));
|
|
202
|
+
await this._refreshInternalApiKeys();
|
|
203
|
+
return this._createInternalApiKeyFirstViewFromCrud(crud);
|
|
201
204
|
}
|
|
202
205
|
async listEmailTemplates() {
|
|
203
206
|
const crud = Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], "write-only"));
|
|
@@ -251,8 +254,8 @@ var _StackAdminAppImplIncomplete = class extends _StackServerAppImplIncomplete {
|
|
|
251
254
|
this._adminProjectCache.refresh([])
|
|
252
255
|
]);
|
|
253
256
|
}
|
|
254
|
-
async
|
|
255
|
-
await this.
|
|
257
|
+
async _refreshInternalApiKeys() {
|
|
258
|
+
await this._internalApiKeysCache.refresh([]);
|
|
256
259
|
}
|
|
257
260
|
get [stackAppInternalsSymbol]() {
|
|
258
261
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/lib/stack-app/apps/implementations/admin-app-impl.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { StackAdminInterface } from \"@stackframe/stack-shared\";\nimport { getProductionModeErrors } from \"@stackframe/stack-shared/dist/helpers/production-mode\";\nimport { ApiKeyCreateCrudResponse } from \"@stackframe/stack-shared/dist/interface/adminInterface\";\nimport { ApiKeysCrud } from \"@stackframe/stack-shared/dist/interface/crud/api-keys\";\nimport { EmailTemplateCrud, EmailTemplateType } from \"@stackframe/stack-shared/dist/interface/crud/email-templates\";\nimport { InternalProjectsCrud } from \"@stackframe/stack-shared/dist/interface/crud/projects\";\nimport { StackAssertionError, throwErr } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { pick } from \"@stackframe/stack-shared/dist/utils/objects\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport { AdminSentEmail } from \"../..\";\nimport { ApiKey, ApiKeyBase, ApiKeyBaseCrudRead, ApiKeyCreateOptions, ApiKeyFirstView, apiKeyCreateOptionsToCrud } from \"../../api-keys\";\nimport { EmailConfig, stackAppInternalsSymbol } from \"../../common\";\nimport { AdminEmailTemplate, AdminEmailTemplateUpdateOptions, adminEmailTemplateUpdateOptionsToCrud } from \"../../email-templates\";\nimport { AdminTeamPermission, AdminTeamPermissionDefinition, AdminTeamPermissionDefinitionCreateOptions, AdminTeamPermissionDefinitionUpdateOptions, AdminProjectPermission, AdminProjectPermissionDefinition, AdminProjectPermissionDefinitionCreateOptions, AdminProjectPermissionDefinitionUpdateOptions, adminTeamPermissionDefinitionCreateOptionsToCrud, adminTeamPermissionDefinitionUpdateOptionsToCrud, adminProjectPermissionDefinitionCreateOptionsToCrud, adminProjectPermissionDefinitionUpdateOptionsToCrud } from \"../../permissions\";\nimport { AdminOwnedProject, AdminProject, AdminProjectUpdateOptions, adminProjectUpdateOptionsToCrud } from \"../../projects\";\nimport { StackAdminApp, StackAdminAppConstructorOptions } from \"../interfaces/admin-app\";\nimport { clientVersion, createCache, getBaseUrl, getDefaultProjectId, getDefaultPublishableClientKey, getDefaultSecretServerKey, getDefaultSuperSecretAdminKey } from \"./common\";\nimport { _StackServerAppImplIncomplete } from \"./server-app-impl\";\n\n\nexport class _StackAdminAppImplIncomplete<HasTokenStore extends boolean, ProjectId extends string> extends _StackServerAppImplIncomplete<HasTokenStore, ProjectId> implements StackAdminApp<HasTokenStore, ProjectId>\n{\n declare protected _interface: StackAdminInterface;\n\n private readonly _adminProjectCache = createCache(async () => {\n return await this._interface.getProject();\n });\n private readonly _apiKeysCache = createCache(async () => {\n return await this._interface.listApiKeys();\n });\n private readonly _adminEmailTemplatesCache = createCache(async () => {\n return await this._interface.listEmailTemplates();\n });\n private readonly _adminTeamPermissionDefinitionsCache = createCache(async () => {\n return await this._interface.listTeamPermissionDefinitions();\n });\n private readonly _adminProjectPermissionDefinitionsCache = createCache(async () => {\n return await this._interface.listProjectPermissionDefinitions();\n });\n private readonly _svixTokenCache = createCache(async () => {\n return await this._interface.getSvixToken();\n });\n private readonly _metricsCache = createCache(async () => {\n return await this._interface.getMetrics();\n });\n\n constructor(options: StackAdminAppConstructorOptions<HasTokenStore, ProjectId>) {\n super({\n interface: new StackAdminInterface({\n getBaseUrl: () => getBaseUrl(options.baseUrl),\n projectId: options.projectId ?? getDefaultProjectId(),\n extraRequestHeaders: options.extraRequestHeaders ?? {},\n clientVersion,\n ...\"projectOwnerSession\" in options ? {\n projectOwnerSession: options.projectOwnerSession,\n } : {\n publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),\n secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),\n superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey(),\n },\n }),\n baseUrl: options.baseUrl,\n extraRequestHeaders: options.extraRequestHeaders,\n projectId: options.projectId,\n tokenStore: options.tokenStore,\n urls: options.urls,\n oauthScopesOnSignIn: options.oauthScopesOnSignIn,\n redirectMethod: options.redirectMethod,\n });\n }\n\n _adminOwnedProjectFromCrud(data: InternalProjectsCrud['Admin']['Read'], onRefresh: () => Promise<void>): AdminOwnedProject {\n if (this._tokenStoreInit !== null) {\n throw new StackAssertionError(\"Owned apps must always have tokenStore === null — did you not create this project with app._createOwnedApp()?\");;\n }\n return {\n ...this._adminProjectFromCrud(data, onRefresh),\n app: this as StackAdminApp<false>,\n };\n }\n\n _adminProjectFromCrud(data: InternalProjectsCrud['Admin']['Read'], onRefresh: () => Promise<void>): AdminProject {\n if (data.id !== this.projectId) {\n throw new StackAssertionError(`The project ID of the provided project JSON (${data.id}) does not match the project ID of the app (${this.projectId})!`);\n }\n\n const app = this;\n return {\n id: data.id,\n displayName: data.display_name,\n description: data.description,\n createdAt: new Date(data.created_at_millis),\n userCount: data.user_count,\n isProductionMode: data.is_production_mode,\n config: {\n id: data.config.id,\n signUpEnabled: data.config.sign_up_enabled,\n credentialEnabled: data.config.credential_enabled,\n magicLinkEnabled: data.config.magic_link_enabled,\n passkeyEnabled: data.config.passkey_enabled,\n clientTeamCreationEnabled: data.config.client_team_creation_enabled,\n clientUserDeletionEnabled: data.config.client_user_deletion_enabled,\n allowLocalhost: data.config.allow_localhost,\n oauthAccountMergeStrategy: data.config.oauth_account_merge_strategy,\n oauthProviders: data.config.oauth_providers.map((p) => ((p.type === 'shared' ? {\n id: p.id,\n enabled: p.enabled,\n type: 'shared',\n } as const : {\n id: p.id,\n enabled: p.enabled,\n type: 'standard',\n clientId: p.client_id ?? throwErr(\"Client ID is missing\"),\n clientSecret: p.client_secret ?? throwErr(\"Client secret is missing\"),\n facebookConfigId: p.facebook_config_id,\n microsoftTenantId: p.microsoft_tenant_id,\n } as const))),\n emailConfig: data.config.email_config.type === 'shared' ? {\n type: 'shared'\n } : {\n type: 'standard',\n host: data.config.email_config.host ?? throwErr(\"Email host is missing\"),\n port: data.config.email_config.port ?? throwErr(\"Email port is missing\"),\n username: data.config.email_config.username ?? throwErr(\"Email username is missing\"),\n password: data.config.email_config.password ?? throwErr(\"Email password is missing\"),\n senderName: data.config.email_config.sender_name ?? throwErr(\"Email sender name is missing\"),\n senderEmail: data.config.email_config.sender_email ?? throwErr(\"Email sender email is missing\"),\n },\n domains: data.config.domains.map((d) => ({\n domain: d.domain,\n handlerPath: d.handler_path,\n })),\n createTeamOnSignUp: data.config.create_team_on_sign_up,\n teamCreatorDefaultPermissions: data.config.team_creator_default_permissions,\n teamMemberDefaultPermissions: data.config.team_member_default_permissions,\n userDefaultPermissions: data.config.user_default_permissions,\n },\n\n async update(update: AdminProjectUpdateOptions) {\n await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));\n await onRefresh();\n },\n async delete() {\n await app._interface.deleteProject();\n },\n async getProductionModeErrors() {\n return getProductionModeErrors(data);\n },\n useProductionModeErrors() {\n return getProductionModeErrors(data);\n },\n };\n }\n\n _adminEmailTemplateFromCrud(data: EmailTemplateCrud['Admin']['Read']): AdminEmailTemplate {\n return {\n type: data.type,\n subject: data.subject,\n content: data.content,\n isDefault: data.is_default,\n };\n }\n\n override async getProject(): Promise<AdminProject> {\n return this._adminProjectFromCrud(\n Result.orThrow(await this._adminProjectCache.getOrWait([], \"write-only\")),\n () => this._refreshProject()\n );\n }\n\n\n protected _createApiKeyBaseFromCrud(data: ApiKeyBaseCrudRead): ApiKeyBase {\n const app = this;\n return {\n id: data.id,\n description: data.description,\n expiresAt: new Date(data.expires_at_millis),\n manuallyRevokedAt: data.manually_revoked_at_millis ? new Date(data.manually_revoked_at_millis) : null,\n createdAt: new Date(data.created_at_millis),\n isValid() {\n return this.whyInvalid() === null;\n },\n whyInvalid() {\n if (this.expiresAt.getTime() < Date.now()) return \"expired\";\n if (this.manuallyRevokedAt) return \"manually-revoked\";\n return null;\n },\n async revoke() {\n const res = await app._interface.revokeApiKeyById(data.id);\n await app._refreshApiKeys();\n return res;\n }\n };\n }\n\n protected _createApiKeyFromCrud(data: ApiKeysCrud[\"Admin\"][\"Read\"]): ApiKey {\n return {\n ...this._createApiKeyBaseFromCrud(data),\n publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,\n secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,\n superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null,\n };\n }\n\n protected _createApiKeyFirstViewFromCrud(data: ApiKeyCreateCrudResponse): ApiKeyFirstView {\n return {\n ...this._createApiKeyBaseFromCrud(data),\n publishableClientKey: data.publishable_client_key,\n secretServerKey: data.secret_server_key,\n superSecretAdminKey: data.super_secret_admin_key,\n };\n }\n\n async listApiKeys(): Promise<ApiKey[]> {\n const crud = Result.orThrow(await this._apiKeysCache.getOrWait([], \"write-only\"));\n return crud.map((j) => this._createApiKeyFromCrud(j));\n }\n\n\n async createApiKey(options: ApiKeyCreateOptions): Promise<ApiKeyFirstView> {\n const crud = await this._interface.createApiKey(apiKeyCreateOptionsToCrud(options));\n await this._refreshApiKeys();\n return this._createApiKeyFirstViewFromCrud(crud);\n }\n\n async listEmailTemplates(): Promise<AdminEmailTemplate[]> {\n const crud = Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], \"write-only\"));\n return crud.map((j) => this._adminEmailTemplateFromCrud(j));\n }\n\n async updateEmailTemplate(type: EmailTemplateType, data: AdminEmailTemplateUpdateOptions): Promise<void> {\n await this._interface.updateEmailTemplate(type, adminEmailTemplateUpdateOptionsToCrud(data));\n await this._adminEmailTemplatesCache.refresh([]);\n }\n\n async resetEmailTemplate(type: EmailTemplateType) {\n await this._interface.resetEmailTemplate(type);\n await this._adminEmailTemplatesCache.refresh([]);\n }\n\n async createTeamPermissionDefinition(data: AdminTeamPermissionDefinitionCreateOptions): Promise<AdminTeamPermission>{\n const crud = await this._interface.createTeamPermissionDefinition(adminTeamPermissionDefinitionCreateOptionsToCrud(data));\n await this._adminTeamPermissionDefinitionsCache.refresh([]);\n return this._serverTeamPermissionDefinitionFromCrud(crud);\n }\n\n async updateTeamPermissionDefinition(permissionId: string, data: AdminTeamPermissionDefinitionUpdateOptions) {\n await this._interface.updateTeamPermissionDefinition(permissionId, adminTeamPermissionDefinitionUpdateOptionsToCrud(data));\n await this._adminTeamPermissionDefinitionsCache.refresh([]);\n }\n\n async deleteTeamPermissionDefinition(permissionId: string): Promise<void> {\n await this._interface.deleteTeamPermissionDefinition(permissionId);\n await this._adminTeamPermissionDefinitionsCache.refresh([]);\n }\n\n async listTeamPermissionDefinitions(): Promise<AdminTeamPermissionDefinition[]> {\n const crud = Result.orThrow(await this._adminTeamPermissionDefinitionsCache.getOrWait([], \"write-only\"));\n return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));\n }\n\n\n async createProjectPermissionDefinition(data: AdminProjectPermissionDefinitionCreateOptions): Promise<AdminProjectPermission> {\n const crud = await this._interface.createProjectPermissionDefinition(adminProjectPermissionDefinitionCreateOptionsToCrud(data));\n await this._adminProjectPermissionDefinitionsCache.refresh([]);\n return this._serverProjectPermissionDefinitionFromCrud(crud);\n }\n\n async updateProjectPermissionDefinition(permissionId: string, data: AdminProjectPermissionDefinitionUpdateOptions) {\n await this._interface.updateProjectPermissionDefinition(permissionId, adminProjectPermissionDefinitionUpdateOptionsToCrud(data));\n await this._adminProjectPermissionDefinitionsCache.refresh([]);\n }\n\n async deleteProjectPermissionDefinition(permissionId: string): Promise<void> {\n await this._interface.deleteProjectPermissionDefinition(permissionId);\n await this._adminProjectPermissionDefinitionsCache.refresh([]);\n }\n\n async listProjectPermissionDefinitions(): Promise<AdminProjectPermissionDefinition[]> {\n const crud = Result.orThrow(await this._adminProjectPermissionDefinitionsCache.getOrWait([], \"write-only\"));\n return crud.map((p) => this._serverProjectPermissionDefinitionFromCrud(p));\n }\n\n\n protected override async _refreshProject() {\n await Promise.all([\n super._refreshProject(),\n this._adminProjectCache.refresh([]),\n ]);\n }\n\n protected async _refreshApiKeys() {\n await this._apiKeysCache.refresh([]);\n }\n\n get [stackAppInternalsSymbol]() {\n return {\n ...super[stackAppInternalsSymbol],\n };\n }\n\n async sendTestEmail(options: {\n recipientEmail: string,\n emailConfig: EmailConfig,\n }): Promise<Result<undefined, { errorMessage: string }>> {\n const response = await this._interface.sendTestEmail({\n recipient_email: options.recipientEmail,\n email_config: {\n ...(pick(options.emailConfig, ['host', 'port', 'username', 'password'])),\n sender_email: options.emailConfig.senderEmail,\n sender_name: options.emailConfig.senderName,\n },\n });\n\n if (response.success) {\n return Result.ok(undefined);\n } else {\n return Result.error({ errorMessage: response.error_message ?? throwErr(\"Email test error not specified\") });\n }\n }\n\n async listSentEmails(): Promise<AdminSentEmail[]> {\n const response = await this._interface.listSentEmails();\n return response.items.map((email) => ({\n id: email.id,\n to: email.to ?? [],\n subject: email.subject,\n recipient: email.to?.[0] ?? \"\",\n sentAt: new Date(email.sent_at_millis),\n error: email.error,\n }));\n }\n}\n"],"mappings":";AAIA,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AAKxC,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,YAAY;AACrB,SAAS,cAAc;AAEvB,SAAuF,iCAAiC;AACxH,SAAsB,+BAA+B;AACrD,SAA8D,6CAA6C;AAC3G,SAA6S,kDAAkD,kDAAkD,qDAAqD,2DAA2D;AACjgB,SAAqE,uCAAuC;AAE5G,SAAS,eAAe,aAAa,YAAY,qBAAqB,gCAAgC,2BAA2B,qCAAqC;AACtK,SAAS,qCAAqC;AAGvC,IAAM,+BAAN,cAAoG,8BAC3G;AAAA,EAyBE,YAAY,SAAoE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,CAAC;AAAA,EACrC;AAAA,EAEA,KAAK,uBAAuB,IAAI;AAC9B,WAAO;AAAA,MACL,GAAG,MAAM,uBAAuB;AAAA,IAClC;AAAA,EACF;AAAA,EAEA,MAAM,cAAc,SAGqC;AACvD,UAAM,WAAW,MAAM,KAAK,WAAW,cAAc;AAAA,MACnD,iBAAiB,QAAQ;AAAA,MACzB,cAAc;AAAA,QACZ,GAAI,KAAK,QAAQ,aAAa,CAAC,QAAQ,QAAQ,YAAY,UAAU,CAAC;AAAA,QACtE,cAAc,QAAQ,YAAY;AAAA,QAClC,aAAa,QAAQ,YAAY;AAAA,MACnC;AAAA,IACF,CAAC;AAED,QAAI,SAAS,SAAS;AACpB,aAAO,OAAO,GAAG,MAAS;AAAA,IAC5B,OAAO;AACL,aAAO,OAAO,MAAM,EAAE,cAAc,SAAS,iBAAiB,SAAS,gCAAgC,EAAE,CAAC;AAAA,IAC5G;AAAA,EACF;AAAA,EAEA,MAAM,iBAA4C;AAChD,UAAM,WAAW,MAAM,KAAK,WAAW,eAAe;AACtD,WAAO,SAAS,MAAM,IAAI,CAAC,WAAW;AAAA,MACpC,IAAI,MAAM;AAAA,MACV,IAAI,MAAM,MAAM,CAAC;AAAA,MACjB,SAAS,MAAM;AAAA,MACf,WAAW,MAAM,KAAK,CAAC,KAAK;AAAA,MAC5B,QAAQ,IAAI,KAAK,MAAM,cAAc;AAAA,MACrC,OAAO,MAAM;AAAA,IACf,EAAE;AAAA,EACJ;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/lib/stack-app/apps/implementations/admin-app-impl.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { StackAdminInterface } from \"@stackframe/stack-shared\";\nimport { getProductionModeErrors } from \"@stackframe/stack-shared/dist/helpers/production-mode\";\nimport { InternalApiKeyCreateCrudResponse } from \"@stackframe/stack-shared/dist/interface/adminInterface\";\nimport { EmailTemplateCrud, EmailTemplateType } from \"@stackframe/stack-shared/dist/interface/crud/email-templates\";\nimport { InternalApiKeysCrud } from \"@stackframe/stack-shared/dist/interface/crud/internal-api-keys\";\nimport { ProjectsCrud } from \"@stackframe/stack-shared/dist/interface/crud/projects\";\nimport { StackAssertionError, throwErr } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { pick } from \"@stackframe/stack-shared/dist/utils/objects\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport { AdminSentEmail } from \"../..\";\nimport { EmailConfig, stackAppInternalsSymbol } from \"../../common\";\nimport { AdminEmailTemplate, AdminEmailTemplateUpdateOptions, adminEmailTemplateUpdateOptionsToCrud } from \"../../email-templates\";\nimport { InternalApiKey, InternalApiKeyBase, InternalApiKeyBaseCrudRead, InternalApiKeyCreateOptions, InternalApiKeyFirstView, internalApiKeyCreateOptionsToCrud } from \"../../internal-api-keys\";\nimport { AdminProjectPermission, AdminProjectPermissionDefinition, AdminProjectPermissionDefinitionCreateOptions, AdminProjectPermissionDefinitionUpdateOptions, AdminTeamPermission, AdminTeamPermissionDefinition, AdminTeamPermissionDefinitionCreateOptions, AdminTeamPermissionDefinitionUpdateOptions, adminProjectPermissionDefinitionCreateOptionsToCrud, adminProjectPermissionDefinitionUpdateOptionsToCrud, adminTeamPermissionDefinitionCreateOptionsToCrud, adminTeamPermissionDefinitionUpdateOptionsToCrud } from \"../../permissions\";\nimport { AdminOwnedProject, AdminProject, AdminProjectUpdateOptions, adminProjectUpdateOptionsToCrud } from \"../../projects\";\nimport { StackAdminApp, StackAdminAppConstructorOptions } from \"../interfaces/admin-app\";\nimport { clientVersion, createCache, getBaseUrl, getDefaultProjectId, getDefaultPublishableClientKey, getDefaultSecretServerKey, getDefaultSuperSecretAdminKey } from \"./common\";\nimport { _StackServerAppImplIncomplete } from \"./server-app-impl\";\n\n\nexport class _StackAdminAppImplIncomplete<HasTokenStore extends boolean, ProjectId extends string> extends _StackServerAppImplIncomplete<HasTokenStore, ProjectId> implements StackAdminApp<HasTokenStore, ProjectId>\n{\n declare protected _interface: StackAdminInterface;\n\n private readonly _adminProjectCache = createCache(async () => {\n return await this._interface.getProject();\n });\n private readonly _internalApiKeysCache = createCache(async () => {\n const res = await this._interface.listInternalApiKeys();\n return res;\n });\n private readonly _adminEmailTemplatesCache = createCache(async () => {\n return await this._interface.listEmailTemplates();\n });\n private readonly _adminTeamPermissionDefinitionsCache = createCache(async () => {\n return await this._interface.listTeamPermissionDefinitions();\n });\n private readonly _adminProjectPermissionDefinitionsCache = createCache(async () => {\n return await this._interface.listProjectPermissionDefinitions();\n });\n private readonly _svixTokenCache = createCache(async () => {\n return await this._interface.getSvixToken();\n });\n private readonly _metricsCache = createCache(async () => {\n return await this._interface.getMetrics();\n });\n\n constructor(options: StackAdminAppConstructorOptions<HasTokenStore, ProjectId>) {\n super({\n interface: new StackAdminInterface({\n getBaseUrl: () => getBaseUrl(options.baseUrl),\n projectId: options.projectId ?? getDefaultProjectId(),\n extraRequestHeaders: options.extraRequestHeaders ?? {},\n clientVersion,\n ...\"projectOwnerSession\" in options ? {\n projectOwnerSession: options.projectOwnerSession,\n } : {\n publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),\n secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),\n superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey(),\n },\n }),\n baseUrl: options.baseUrl,\n extraRequestHeaders: options.extraRequestHeaders,\n projectId: options.projectId,\n tokenStore: options.tokenStore,\n urls: options.urls,\n oauthScopesOnSignIn: options.oauthScopesOnSignIn,\n redirectMethod: options.redirectMethod,\n });\n }\n\n _adminOwnedProjectFromCrud(data: ProjectsCrud['Admin']['Read'], onRefresh: () => Promise<void>): AdminOwnedProject {\n if (this._tokenStoreInit !== null) {\n throw new StackAssertionError(\"Owned apps must always have tokenStore === null — did you not create this project with app._createOwnedApp()?\");;\n }\n return {\n ...this._adminProjectFromCrud(data, onRefresh),\n app: this as StackAdminApp<false>,\n };\n }\n\n _adminProjectFromCrud(data: ProjectsCrud['Admin']['Read'], onRefresh: () => Promise<void>): AdminProject {\n if (data.id !== this.projectId) {\n throw new StackAssertionError(`The project ID of the provided project JSON (${data.id}) does not match the project ID of the app (${this.projectId})!`);\n }\n\n const app = this;\n return {\n id: data.id,\n displayName: data.display_name,\n description: data.description,\n createdAt: new Date(data.created_at_millis),\n userCount: data.user_count,\n isProductionMode: data.is_production_mode,\n config: {\n id: data.config.id,\n signUpEnabled: data.config.sign_up_enabled,\n credentialEnabled: data.config.credential_enabled,\n magicLinkEnabled: data.config.magic_link_enabled,\n passkeyEnabled: data.config.passkey_enabled,\n clientTeamCreationEnabled: data.config.client_team_creation_enabled,\n clientUserDeletionEnabled: data.config.client_user_deletion_enabled,\n allowLocalhost: data.config.allow_localhost,\n oauthAccountMergeStrategy: data.config.oauth_account_merge_strategy,\n allowUserApiKeys: data.config.allow_user_api_keys,\n allowTeamApiKeys: data.config.allow_team_api_keys,\n oauthProviders: data.config.oauth_providers.map((p) => ((p.type === 'shared' ? {\n id: p.id,\n enabled: p.enabled,\n type: 'shared',\n } as const : {\n id: p.id,\n enabled: p.enabled,\n type: 'standard',\n clientId: p.client_id ?? throwErr(\"Client ID is missing\"),\n clientSecret: p.client_secret ?? throwErr(\"Client secret is missing\"),\n facebookConfigId: p.facebook_config_id,\n microsoftTenantId: p.microsoft_tenant_id,\n } as const))),\n emailConfig: data.config.email_config.type === 'shared' ? {\n type: 'shared'\n } : {\n type: 'standard',\n host: data.config.email_config.host ?? throwErr(\"Email host is missing\"),\n port: data.config.email_config.port ?? throwErr(\"Email port is missing\"),\n username: data.config.email_config.username ?? throwErr(\"Email username is missing\"),\n password: data.config.email_config.password ?? throwErr(\"Email password is missing\"),\n senderName: data.config.email_config.sender_name ?? throwErr(\"Email sender name is missing\"),\n senderEmail: data.config.email_config.sender_email ?? throwErr(\"Email sender email is missing\"),\n },\n domains: data.config.domains.map((d) => ({\n domain: d.domain,\n handlerPath: d.handler_path,\n })),\n createTeamOnSignUp: data.config.create_team_on_sign_up,\n teamCreatorDefaultPermissions: data.config.team_creator_default_permissions,\n teamMemberDefaultPermissions: data.config.team_member_default_permissions,\n userDefaultPermissions: data.config.user_default_permissions,\n },\n\n async update(update: AdminProjectUpdateOptions) {\n await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));\n await onRefresh();\n },\n async delete() {\n await app._interface.deleteProject();\n },\n async getProductionModeErrors() {\n return getProductionModeErrors(data);\n },\n useProductionModeErrors() {\n return getProductionModeErrors(data);\n },\n };\n }\n\n _adminEmailTemplateFromCrud(data: EmailTemplateCrud['Admin']['Read']): AdminEmailTemplate {\n return {\n type: data.type,\n subject: data.subject,\n content: data.content,\n isDefault: data.is_default,\n };\n }\n\n override async getProject(): Promise<AdminProject> {\n return this._adminProjectFromCrud(\n Result.orThrow(await this._adminProjectCache.getOrWait([], \"write-only\")),\n () => this._refreshProject()\n );\n }\n\n\n protected _createInternalApiKeyBaseFromCrud(data: InternalApiKeyBaseCrudRead): InternalApiKeyBase {\n const app = this;\n return {\n id: data.id,\n description: data.description,\n expiresAt: new Date(data.expires_at_millis),\n manuallyRevokedAt: data.manually_revoked_at_millis ? new Date(data.manually_revoked_at_millis) : null,\n createdAt: new Date(data.created_at_millis),\n isValid() {\n return this.whyInvalid() === null;\n },\n whyInvalid() {\n if (this.expiresAt.getTime() < Date.now()) return \"expired\";\n if (this.manuallyRevokedAt) return \"manually-revoked\";\n return null;\n },\n async revoke() {\n const res = await app._interface.revokeInternalApiKeyById(data.id);\n await app._refreshInternalApiKeys();\n return res;\n }\n };\n }\n\n protected _createInternalApiKeyFromCrud(data: InternalApiKeysCrud[\"Admin\"][\"Read\"]): InternalApiKey {\n return {\n ...this._createInternalApiKeyBaseFromCrud(data),\n publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,\n secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,\n superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null,\n };\n }\n\n protected _createInternalApiKeyFirstViewFromCrud(data: InternalApiKeyCreateCrudResponse): InternalApiKeyFirstView {\n return {\n ...this._createInternalApiKeyBaseFromCrud(data),\n publishableClientKey: data.publishable_client_key,\n secretServerKey: data.secret_server_key,\n superSecretAdminKey: data.super_secret_admin_key,\n };\n }\n\n async listInternalApiKeys(): Promise<InternalApiKey[]> {\n const crud = Result.orThrow(await this._internalApiKeysCache.getOrWait([], \"write-only\"));\n return crud.map((j) => this._createInternalApiKeyFromCrud(j));\n }\n\n\n async createInternalApiKey(options: InternalApiKeyCreateOptions): Promise<InternalApiKeyFirstView> {\n const crud = await this._interface.createInternalApiKey(internalApiKeyCreateOptionsToCrud(options));\n await this._refreshInternalApiKeys();\n return this._createInternalApiKeyFirstViewFromCrud(crud);\n }\n\n async listEmailTemplates(): Promise<AdminEmailTemplate[]> {\n const crud = Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], \"write-only\"));\n return crud.map((j) => this._adminEmailTemplateFromCrud(j));\n }\n\n async updateEmailTemplate(type: EmailTemplateType, data: AdminEmailTemplateUpdateOptions): Promise<void> {\n await this._interface.updateEmailTemplate(type, adminEmailTemplateUpdateOptionsToCrud(data));\n await this._adminEmailTemplatesCache.refresh([]);\n }\n\n async resetEmailTemplate(type: EmailTemplateType) {\n await this._interface.resetEmailTemplate(type);\n await this._adminEmailTemplatesCache.refresh([]);\n }\n\n async createTeamPermissionDefinition(data: AdminTeamPermissionDefinitionCreateOptions): Promise<AdminTeamPermission>{\n const crud = await this._interface.createTeamPermissionDefinition(adminTeamPermissionDefinitionCreateOptionsToCrud(data));\n await this._adminTeamPermissionDefinitionsCache.refresh([]);\n return this._serverTeamPermissionDefinitionFromCrud(crud);\n }\n\n async updateTeamPermissionDefinition(permissionId: string, data: AdminTeamPermissionDefinitionUpdateOptions) {\n await this._interface.updateTeamPermissionDefinition(permissionId, adminTeamPermissionDefinitionUpdateOptionsToCrud(data));\n await this._adminTeamPermissionDefinitionsCache.refresh([]);\n }\n\n async deleteTeamPermissionDefinition(permissionId: string): Promise<void> {\n await this._interface.deleteTeamPermissionDefinition(permissionId);\n await this._adminTeamPermissionDefinitionsCache.refresh([]);\n }\n\n async listTeamPermissionDefinitions(): Promise<AdminTeamPermissionDefinition[]> {\n const crud = Result.orThrow(await this._adminTeamPermissionDefinitionsCache.getOrWait([], \"write-only\"));\n return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));\n }\n\n\n async createProjectPermissionDefinition(data: AdminProjectPermissionDefinitionCreateOptions): Promise<AdminProjectPermission> {\n const crud = await this._interface.createProjectPermissionDefinition(adminProjectPermissionDefinitionCreateOptionsToCrud(data));\n await this._adminProjectPermissionDefinitionsCache.refresh([]);\n return this._serverProjectPermissionDefinitionFromCrud(crud);\n }\n\n async updateProjectPermissionDefinition(permissionId: string, data: AdminProjectPermissionDefinitionUpdateOptions) {\n await this._interface.updateProjectPermissionDefinition(permissionId, adminProjectPermissionDefinitionUpdateOptionsToCrud(data));\n await this._adminProjectPermissionDefinitionsCache.refresh([]);\n }\n\n async deleteProjectPermissionDefinition(permissionId: string): Promise<void> {\n await this._interface.deleteProjectPermissionDefinition(permissionId);\n await this._adminProjectPermissionDefinitionsCache.refresh([]);\n }\n\n async listProjectPermissionDefinitions(): Promise<AdminProjectPermissionDefinition[]> {\n const crud = Result.orThrow(await this._adminProjectPermissionDefinitionsCache.getOrWait([], \"write-only\"));\n return crud.map((p) => this._serverProjectPermissionDefinitionFromCrud(p));\n }\n\n\n protected override async _refreshProject() {\n await Promise.all([\n super._refreshProject(),\n this._adminProjectCache.refresh([]),\n ]);\n }\n\n protected async _refreshInternalApiKeys() {\n await this._internalApiKeysCache.refresh([]);\n }\n\n get [stackAppInternalsSymbol]() {\n return {\n ...super[stackAppInternalsSymbol],\n };\n }\n\n async sendTestEmail(options: {\n recipientEmail: string,\n emailConfig: EmailConfig,\n }): Promise<Result<undefined, { errorMessage: string }>> {\n const response = await this._interface.sendTestEmail({\n recipient_email: options.recipientEmail,\n email_config: {\n ...(pick(options.emailConfig, ['host', 'port', 'username', 'password'])),\n sender_email: options.emailConfig.senderEmail,\n sender_name: options.emailConfig.senderName,\n },\n });\n\n if (response.success) {\n return Result.ok(undefined);\n } else {\n return Result.error({ errorMessage: response.error_message ?? throwErr(\"Email test error not specified\") });\n }\n }\n\n async listSentEmails(): Promise<AdminSentEmail[]> {\n const response = await this._interface.listSentEmails();\n return response.items.map((email) => ({\n id: email.id,\n to: email.to ?? [],\n subject: email.subject,\n recipient: email.to?.[0] ?? \"\",\n sentAt: new Date(email.sent_at_millis),\n error: email.error,\n }));\n }\n}\n"],"mappings":";AAIA,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AAKxC,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,YAAY;AACrB,SAAS,cAAc;AAEvB,SAAsB,+BAA+B;AACrD,SAA8D,6CAA6C;AAC3G,SAA+H,yCAAyC;AACxK,SAA6S,qDAAqD,qDAAqD,kDAAkD,wDAAwD;AACjgB,SAAqE,uCAAuC;AAE5G,SAAS,eAAe,aAAa,YAAY,qBAAqB,gCAAgC,2BAA2B,qCAAqC;AACtK,SAAS,qCAAqC;AAGvC,IAAM,+BAAN,cAAoG,8BAC3G;AAAA,EA0BE,YAAY,SAAoE;AAC9E,UAAM;AAAA,MACJ,WAAW,IAAI,oBAAoB;AAAA,QACjC,YAAY,MAAM,WAAW,QAAQ,OAAO;AAAA,QAC5C,WAAW,QAAQ,aAAa,oBAAoB;AAAA,QACpD,qBAAqB,QAAQ,uBAAuB,CAAC;AAAA,QACrD;AAAA,QACA,GAAG,yBAAyB,UAAU;AAAA,UACpC,qBAAqB,QAAQ;AAAA,QAC/B,IAAI;AAAA,UACF,sBAAsB,QAAQ,wBAAwB,+BAA+B;AAAA,UACrF,iBAAiB,QAAQ,mBAAmB,0BAA0B;AAAA,UACtE,qBAAqB,QAAQ,uBAAuB,8BAA8B;AAAA,Q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U,CAAC;AAAA,QACtE,cAAc,QAAQ,YAAY;AAAA,QAClC,aAAa,QAAQ,YAAY;AAAA,MACnC;AAAA,IACF,CAAC;AAED,QAAI,SAAS,SAAS;AACpB,aAAO,OAAO,GAAG,MAAS;AAAA,IAC5B,OAAO;AACL,aAAO,OAAO,MAAM,EAAE,cAAc,SAAS,iBAAiB,SAAS,gCAAgC,EAAE,CAAC;AAAA,IAC5G;AAAA,EACF;AAAA,EAEA,MAAM,iBAA4C;AAChD,UAAM,WAAW,MAAM,KAAK,WAAW,eAAe;AACtD,WAAO,SAAS,MAAM,IAAI,CAAC,WAAW;AAAA,MACpC,IAAI,MAAM;AAAA,MACV,IAAI,MAAM,MAAM,CAAC;AAAA,MACjB,SAAS,MAAM;AAAA,MACf,WAAW,MAAM,KAAK,CAAC,KAAK;AAAA,MAC5B,QAAQ,IAAI,KAAK,MAAM,cAAc;AAAA,MACrC,OAAO,MAAM;AAAA,IACf,EAAE;AAAA,EACJ;AACF;","names":[]}
|
|
@@ -16,6 +16,7 @@ import * as cookie from "cookie";
|
|
|
16
16
|
import { constructRedirectUrl } from "../../../../utils/url";
|
|
17
17
|
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "../../../auth";
|
|
18
18
|
import { createCookieHelper, createPlaceholderCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "../../../cookie";
|
|
19
|
+
import { apiKeyCreationOptionsToCrud } from "../../api-keys";
|
|
19
20
|
import { stackAppInternalsSymbol } from "../../common";
|
|
20
21
|
import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels";
|
|
21
22
|
import { adminProjectCreateOptionsToCrud } from "../../projects";
|
|
@@ -100,6 +101,18 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
100
101
|
return await this._interface.listClientContactChannels(session);
|
|
101
102
|
}
|
|
102
103
|
);
|
|
104
|
+
this._userApiKeysCache = createCacheBySession(
|
|
105
|
+
async (session) => {
|
|
106
|
+
const results = await this._interface.listProjectApiKeys({ user_id: "me" }, session, "client");
|
|
107
|
+
return results;
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
this._teamApiKeysCache = createCacheBySession(
|
|
111
|
+
async (session, [teamId]) => {
|
|
112
|
+
const results = await this._interface.listProjectApiKeys({ team_id: teamId }, session, "client");
|
|
113
|
+
return results;
|
|
114
|
+
}
|
|
115
|
+
);
|
|
103
116
|
this._anonymousSignUpInProgress = null;
|
|
104
117
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
105
118
|
this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
|
|
@@ -410,6 +423,8 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
410
423
|
passkeyEnabled: crud.config.passkey_enabled,
|
|
411
424
|
clientTeamCreationEnabled: crud.config.client_team_creation_enabled,
|
|
412
425
|
clientUserDeletionEnabled: crud.config.client_user_deletion_enabled,
|
|
426
|
+
allowTeamApiKeys: crud.config.allow_team_api_keys,
|
|
427
|
+
allowUserApiKeys: crud.config.allow_user_api_keys,
|
|
413
428
|
oauthProviders: crud.config.enabled_oauth_providers.map((p) => ({
|
|
414
429
|
id: p.id
|
|
415
430
|
}))
|
|
@@ -441,6 +456,47 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
441
456
|
}
|
|
442
457
|
};
|
|
443
458
|
}
|
|
459
|
+
_baseApiKeyFromCrud(crud) {
|
|
460
|
+
return {
|
|
461
|
+
id: crud.id,
|
|
462
|
+
description: crud.description,
|
|
463
|
+
expiresAt: crud.expires_at_millis ? new Date(crud.expires_at_millis) : void 0,
|
|
464
|
+
manuallyRevokedAt: crud.manually_revoked_at_millis ? new Date(crud.manually_revoked_at_millis) : null,
|
|
465
|
+
createdAt: new Date(crud.created_at_millis),
|
|
466
|
+
...crud.type === "team" ? { type: "team", teamId: crud.team_id } : { type: "user", userId: crud.user_id },
|
|
467
|
+
value: typeof crud.value === "string" ? crud.value : {
|
|
468
|
+
lastFour: crud.value.last_four
|
|
469
|
+
},
|
|
470
|
+
isValid: function() {
|
|
471
|
+
return this.whyInvalid() === null;
|
|
472
|
+
},
|
|
473
|
+
whyInvalid: function() {
|
|
474
|
+
if (this.manuallyRevokedAt) {
|
|
475
|
+
return "manually-revoked";
|
|
476
|
+
}
|
|
477
|
+
if (this.expiresAt && this.expiresAt < /* @__PURE__ */ new Date()) {
|
|
478
|
+
return "expired";
|
|
479
|
+
}
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
_clientApiKeyFromCrud(session, crud) {
|
|
485
|
+
return {
|
|
486
|
+
...this._baseApiKeyFromCrud(crud),
|
|
487
|
+
async revoke() {
|
|
488
|
+
await this.update({ revoked: true });
|
|
489
|
+
},
|
|
490
|
+
update: async (options) => {
|
|
491
|
+
await this._interface.updateProjectApiKey(crud.type === "team" ? { team_id: crud.team_id } : { user_id: crud.user_id }, crud.id, options, session, "client");
|
|
492
|
+
if (crud.type === "team") {
|
|
493
|
+
await this._teamApiKeysCache.refresh([session, crud.team_id]);
|
|
494
|
+
} else {
|
|
495
|
+
await this._userApiKeysCache.refresh([session]);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
444
500
|
_clientTeamFromCrud(crud, session) {
|
|
445
501
|
const app = this;
|
|
446
502
|
return {
|
|
@@ -473,6 +529,19 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
473
529
|
async delete() {
|
|
474
530
|
await app._interface.deleteTeam(crud.id, session);
|
|
475
531
|
await app._currentUserTeamsCache.refresh([session]);
|
|
532
|
+
},
|
|
533
|
+
async listApiKeys() {
|
|
534
|
+
const results = Result.orThrow(await app._teamApiKeysCache.getOrWait([session, crud.id], "write-only"));
|
|
535
|
+
return results.map((crud2) => app._clientApiKeyFromCrud(session, crud2));
|
|
536
|
+
},
|
|
537
|
+
async createApiKey(options) {
|
|
538
|
+
const result = await app._interface.createProjectApiKey(
|
|
539
|
+
await apiKeyCreationOptionsToCrud("team", crud.id, options),
|
|
540
|
+
session,
|
|
541
|
+
"client"
|
|
542
|
+
);
|
|
543
|
+
await app._teamApiKeysCache.refresh([session, crud.id]);
|
|
544
|
+
return app._clientApiKeyFromCrud(session, result);
|
|
476
545
|
}
|
|
477
546
|
};
|
|
478
547
|
}
|
|
@@ -712,6 +781,19 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
712
781
|
const crud2 = await app._interface.createClientContactChannel(contactChannelCreateOptionsToCrud("me", data), session);
|
|
713
782
|
await app._clientContactChannelsCache.refresh([session]);
|
|
714
783
|
return app._clientContactChannelFromCrud(crud2, session);
|
|
784
|
+
},
|
|
785
|
+
async listApiKeys() {
|
|
786
|
+
const results = await app._interface.listProjectApiKeys({ user_id: "me" }, session, "client");
|
|
787
|
+
return results.map((crud2) => app._clientApiKeyFromCrud(session, crud2));
|
|
788
|
+
},
|
|
789
|
+
async createApiKey(options) {
|
|
790
|
+
const result = await app._interface.createProjectApiKey(
|
|
791
|
+
await apiKeyCreationOptionsToCrud("user", "me", options),
|
|
792
|
+
session,
|
|
793
|
+
"client"
|
|
794
|
+
);
|
|
795
|
+
await app._userApiKeysCache.refresh([session]);
|
|
796
|
+
return app._clientApiKeyFromCrud(session, result);
|
|
715
797
|
}
|
|
716
798
|
};
|
|
717
799
|
}
|
|
@@ -1092,6 +1174,85 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1092
1174
|
return Result.error(result.error);
|
|
1093
1175
|
}
|
|
1094
1176
|
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Initiates a CLI authentication process that allows a command line application
|
|
1179
|
+
* to get a refresh token for a user's account.
|
|
1180
|
+
*
|
|
1181
|
+
* This process works as follows:
|
|
1182
|
+
* 1. The CLI app calls this method, which initiates the auth process with the server
|
|
1183
|
+
* 2. The server returns a polling code and a login code
|
|
1184
|
+
* 3. The CLI app opens a browser window to the appUrl with the login code as a parameter
|
|
1185
|
+
* 4. The user logs in through the browser and confirms the authorization
|
|
1186
|
+
* 5. The CLI app polls for the refresh token using the polling code
|
|
1187
|
+
*
|
|
1188
|
+
* @param options Options for the CLI login
|
|
1189
|
+
* @param options.appUrl The URL of the app that will handle the CLI auth confirmation
|
|
1190
|
+
* @param options.expiresInMillis Optional duration in milliseconds before the auth attempt expires (default: 2 hours)
|
|
1191
|
+
* @param options.maxAttempts Optional maximum number of polling attempts (default: Infinity)
|
|
1192
|
+
* @param options.waitTimeMillis Optional time to wait between polling attempts (default: 2 seconds)
|
|
1193
|
+
* @param options.promptLink Optional function to call with the login URL to prompt the user to open the browser
|
|
1194
|
+
* @returns Result containing either the refresh token or an error
|
|
1195
|
+
*/
|
|
1196
|
+
async promptCliLogin(options) {
|
|
1197
|
+
const response = await this._interface.sendClientRequest(
|
|
1198
|
+
"/auth/cli",
|
|
1199
|
+
{
|
|
1200
|
+
method: "POST",
|
|
1201
|
+
headers: {
|
|
1202
|
+
"Content-Type": "application/json"
|
|
1203
|
+
},
|
|
1204
|
+
body: JSON.stringify({
|
|
1205
|
+
expires_in_millis: options.expiresInMillis
|
|
1206
|
+
})
|
|
1207
|
+
},
|
|
1208
|
+
null
|
|
1209
|
+
);
|
|
1210
|
+
if (!response.ok) {
|
|
1211
|
+
return Result.error(new KnownErrors.CliAuthError(`Failed to initiate CLI auth: ${response.status} ${await response.text()}`));
|
|
1212
|
+
}
|
|
1213
|
+
const initResult = await response.json();
|
|
1214
|
+
const pollingCode = initResult.polling_code;
|
|
1215
|
+
const loginCode = initResult.login_code;
|
|
1216
|
+
const url = `${options.appUrl}/handler/cli-auth-confirm?login_code=${encodeURIComponent(loginCode)}`;
|
|
1217
|
+
if (options.promptLink) {
|
|
1218
|
+
options.promptLink(url);
|
|
1219
|
+
} else {
|
|
1220
|
+
console.log(`Please visit the following URL to authenticate:
|
|
1221
|
+
${url}`);
|
|
1222
|
+
}
|
|
1223
|
+
let attempts = 0;
|
|
1224
|
+
while (attempts < (options.maxAttempts ?? Infinity)) {
|
|
1225
|
+
attempts++;
|
|
1226
|
+
const pollResponse = await this._interface.sendClientRequest("/auth/cli/poll", {
|
|
1227
|
+
method: "POST",
|
|
1228
|
+
headers: {
|
|
1229
|
+
"Content-Type": "application/json"
|
|
1230
|
+
},
|
|
1231
|
+
body: JSON.stringify({
|
|
1232
|
+
polling_code: pollingCode
|
|
1233
|
+
})
|
|
1234
|
+
}, null);
|
|
1235
|
+
if (!pollResponse.ok) {
|
|
1236
|
+
return Result.error(new KnownErrors.CliAuthError(`Failed to initiate CLI auth: ${pollResponse.status} ${await pollResponse.text()}`));
|
|
1237
|
+
}
|
|
1238
|
+
const pollResult = await pollResponse.json();
|
|
1239
|
+
if (pollResponse.status === 201 && pollResult.status === "success") {
|
|
1240
|
+
return Result.ok(pollResult.refresh_token);
|
|
1241
|
+
}
|
|
1242
|
+
if (pollResult.status === "waiting") {
|
|
1243
|
+
await wait(options.waitTimeMillis ?? 2e3);
|
|
1244
|
+
continue;
|
|
1245
|
+
}
|
|
1246
|
+
if (pollResult.status === "expired") {
|
|
1247
|
+
return Result.error(new KnownErrors.CliAuthExpiredError("CLI authentication request expired. Please try again."));
|
|
1248
|
+
}
|
|
1249
|
+
if (pollResult.status === "used") {
|
|
1250
|
+
return Result.error(new KnownErrors.CliAuthUsedError("This authentication token has already been used."));
|
|
1251
|
+
}
|
|
1252
|
+
return Result.error(new KnownErrors.CliAuthError(`Unexpected status from CLI auth polling: ${pollResult.status}`));
|
|
1253
|
+
}
|
|
1254
|
+
return Result.error(new KnownErrors.CliAuthError("Timed out waiting for CLI authentication."));
|
|
1255
|
+
}
|
|
1095
1256
|
async signInWithPasskey() {
|
|
1096
1257
|
this._ensurePersistentTokenStore();
|
|
1097
1258
|
const session = await this._getSession();
|