@webiny/project-aws 6.6.0-alpha.12 → 6.6.0-alpha.14
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/_templates/appTemplates/api/graphql/package.json +2 -2
- package/_templates/appTemplates/api/graphql/src/index.ts +2 -2
- package/_templates/appTemplates/api/graphql/src/web.ts +1 -1
- package/_templates/extensions/OpenSearch/api/graphql/src/index.ts +2 -2
- package/_templates/extensions/OpenSearch/api/graphql/src/web.ts +1 -1
- package/_templates/extensions/Postgres/api/graphql/src/index.ts +3 -6
- package/_templates/extensions/Postgres/api/graphql/src/web.ts +1 -1
- package/_templates/extensions/TenantStorages/ddb/api/graphql/src/index.ts +25 -0
- package/_templates/extensions/TenantStorages/ddb/api/graphql/src/web.ts +17 -0
- package/_templates/extensions/TenantStorages/ddb-os/api/graphql/src/index.ts +25 -0
- package/_templates/extensions/TenantStorages/ddb-os/api/graphql/src/web.ts +17 -0
- package/_templates/extensions/TenantStorages/pg/api/graphql/src/index.ts +25 -0
- package/_templates/extensions/TenantStorages/pg/api/graphql/src/web.ts +16 -0
- package/api.d.ts +6 -6
- package/api.js +3 -2
- package/api.js.map +1 -1
- package/decorators/GetPulumiServiceWithDownloadInfo.d.ts +1 -3
- package/decorators/GetPulumiServiceWithDownloadInfo.js +15 -11
- package/decorators/GetPulumiServiceWithDownloadInfo.js.map +1 -1
- package/extensions/AuroraPostgresCluster.d.ts +12 -0
- package/extensions/{Postgres.js → AuroraPostgresCluster.js} +7 -7
- package/extensions/AuroraPostgresCluster.js.map +1 -0
- package/extensions/OpenSearch/ReplaceApiLambdaFnHandlers.d.ts +3 -2
- package/extensions/OpenSearch/ReplaceApiLambdaFnHandlers.js +7 -3
- package/extensions/OpenSearch/ReplaceApiLambdaFnHandlers.js.map +1 -1
- package/extensions/Postgres/AddCorePostgres.d.ts +1 -1
- package/extensions/Postgres/AddCorePostgres.js +0 -2
- package/extensions/Postgres/AddCorePostgres.js.map +1 -1
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.d.ts +4 -3
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.js.map +1 -1
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.d.ts +6 -5
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.js +6 -2
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.js.map +1 -1
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.d.ts +1 -1
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js +8 -10
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js.map +1 -1
- package/extensions/Postgres/assertPostgresNetwork.d.ts +19 -0
- package/extensions/Postgres/assertPostgresNetwork.js +16 -0
- package/extensions/Postgres/assertPostgresNetwork.js.map +1 -0
- package/extensions/Postgres/copyPgRuntimeModules.d.ts +1 -1
- package/extensions/Postgres/copyPgRuntimeModules.js +2 -2
- package/extensions/Postgres/copyPgRuntimeModules.js.map +1 -1
- package/extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.d.ts +17 -2
- package/extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.js +26 -19
- package/extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.js.map +1 -1
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.d.ts +2 -2
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.js +1 -1
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.js.map +1 -1
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.d.ts +3 -3
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.js +1 -1
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.js.map +1 -1
- package/extensions/ProjectAws/TenantStorages/AddTenantStorages.d.ts +34 -0
- package/extensions/ProjectAws/TenantStorages/AddTenantStorages.js +55 -0
- package/extensions/ProjectAws/TenantStorages/AddTenantStorages.js.map +1 -0
- package/extensions/ProjectAws/TenantStorages/ApplyTenantStoragesApiEntry.d.ts +26 -0
- package/extensions/ProjectAws/TenantStorages/ApplyTenantStoragesApiEntry.js +49 -0
- package/extensions/ProjectAws/TenantStorages/ApplyTenantStoragesApiEntry.js.map +1 -0
- package/extensions/ProjectAws/TenantStorages/CopyPgModulesForTenantStorages.d.ts +17 -0
- package/extensions/ProjectAws/TenantStorages/CopyPgModulesForTenantStorages.js +26 -0
- package/extensions/ProjectAws/TenantStorages/CopyPgModulesForTenantStorages.js.map +1 -0
- package/extensions/ProjectAws/TenantStorages/EnsureStoragesNotRemoved.d.ts +41 -0
- package/extensions/ProjectAws/TenantStorages/EnsureStoragesNotRemoved.js +55 -0
- package/extensions/ProjectAws/TenantStorages/EnsureStoragesNotRemoved.js.map +1 -0
- package/extensions/ProjectAws/TenantStorages/ValidateTenantStoragesBeforeCoreDeploy.d.ts +48 -0
- package/extensions/ProjectAws/TenantStorages/ValidateTenantStoragesBeforeCoreDeploy.js +78 -0
- package/extensions/ProjectAws/TenantStorages/ValidateTenantStoragesBeforeCoreDeploy.js.map +1 -0
- package/extensions/ProjectAws.js +11 -1
- package/extensions/ProjectAws.js.map +1 -1
- package/extensions/definitions.js +2 -4
- package/extensions/definitions.js.map +1 -1
- package/extensions/index.d.ts +3 -3
- package/extensions/index.js +3 -4
- package/extensions/registerExtensionImplementations.js +3 -5
- package/extensions/registerExtensionImplementations.js.map +1 -1
- package/infra.d.ts +13 -8
- package/infra.js +9 -10
- package/infra.js.map +1 -1
- package/package.json +19 -18
- package/project.d.ts +4 -2
- package/pulumi/apps/admin/createAdminPulumiApp.js.map +1 -1
- package/pulumi/apps/api/ApiGraphql.js.map +1 -1
- package/pulumi/apps/api/ApiGraphqlWeb.js.map +1 -1
- package/pulumi/apps/api/ApiOutput.js.map +1 -1
- package/pulumi/apps/api/ApiSchemaSetup.d.ts +35 -13
- package/pulumi/apps/api/ApiSchemaSetup.js +31 -8
- package/pulumi/apps/api/ApiSchemaSetup.js.map +1 -1
- package/pulumi/apps/api/apiDynamoDb.js.map +1 -1
- package/pulumi/apps/api/backgroundTask/types.js.map +1 -1
- package/pulumi/apps/api/createApiPulumiApp.js +14 -7
- package/pulumi/apps/api/createApiPulumiApp.js.map +1 -1
- package/pulumi/apps/common/CoreOutput.d.ts +11 -0
- package/pulumi/apps/common/CoreOutput.js +2 -1
- package/pulumi/apps/common/CoreOutput.js.map +1 -1
- package/pulumi/apps/core/CoreCognito.d.ts +14 -0
- package/pulumi/apps/core/CoreCognito.js +34 -1
- package/pulumi/apps/core/CoreCognito.js.map +1 -1
- package/pulumi/apps/core/CorePostgres.d.ts +6 -4
- package/pulumi/apps/core/CorePostgres.js +26 -20
- package/pulumi/apps/core/CorePostgres.js.map +1 -1
- package/pulumi/apps/core/cognitoIdentityProviders/configure.js +11 -0
- package/pulumi/apps/core/cognitoIdentityProviders/configure.js.map +1 -1
- package/pulumi/apps/core/coreDynamoDb.d.ts +2 -2
- package/pulumi/apps/core/coreDynamoDb.js.map +1 -1
- package/pulumi/apps/core/coreServiceManifests.d.ts +6 -4
- package/pulumi/apps/core/coreServiceManifests.js.map +1 -1
- package/pulumi/apps/core/coreVpcEndpoints.d.ts +9 -2
- package/pulumi/apps/core/coreVpcEndpoints.js +15 -11
- package/pulumi/apps/core/coreVpcEndpoints.js.map +1 -1
- package/pulumi/apps/core/createCorePulumiApp.js +8 -1
- package/pulumi/apps/core/createCorePulumiApp.js.map +1 -1
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.d.ts +4 -2
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.js +4 -3
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.js.map +1 -1
- package/pulumi/apps/extensions/getTenantStoragesFromExtension.d.ts +19 -0
- package/pulumi/apps/extensions/getTenantStoragesFromExtension.js +32 -0
- package/pulumi/apps/extensions/getTenantStoragesFromExtension.js.map +1 -0
- package/pulumi/apps/extensions/projectUsesPostgres.d.ts +1 -1
- package/pulumi/apps/extensions/projectUsesPostgres.js.map +1 -1
- package/pulumi/apps/react/adminSettingsItem.d.ts +1 -1
- package/pulumi/apps/react/adminSettingsItem.js.map +1 -1
- package/pulumi/apps/react/createReactPulumiApp.js.map +1 -1
- package/pulumi/extensions/index.d.ts +8 -0
- package/pulumi/extensions/index.js +2 -1
- package/pulumi/extensions/index.js.map +1 -1
- package/pulumi/types.d.ts +2 -2
- package/pulumi/utils/lambdaEnvVariables.js +2 -2
- package/pulumi/utils/lambdaEnvVariables.js.map +1 -1
- package/pulumi/utils/withServiceManifest.d.ts +2 -2
- package/pulumi/utils/withServiceManifest.js.map +1 -1
- package/services/PulumiGetStackOutputService/mapStackOutput.js +1 -1
- package/services/PulumiGetStackOutputService/mapStackOutput.js.map +1 -1
- package/extensions/Postgres.d.ts +0 -11
- package/extensions/Postgres.js.map +0 -1
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.d.ts +0 -14
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.js +0 -23
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.js.map +0 -1
- package/extensions/RdsProxy.d.ts +0 -9
- package/extensions/RdsProxy.js +0 -31
- package/extensions/RdsProxy.js.map +0 -1
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.d.ts +0 -5
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.js +0 -8
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.js.map +0 -1
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
|
-
import { BuildAppWorkspaceService, GetApp, LoggerService } from "@webiny/project/abstractions/index.js";
|
|
3
|
+
import { BuildAppWorkspaceService, GetApp, GetProjectConfigService, LoggerService } from "@webiny/project/abstractions/index.js";
|
|
4
4
|
import { getTemplatesFolderPath } from "../../utils/index.js";
|
|
5
|
+
import { hasTenantStorages } from "../ProjectAws/TenantStorages/ApplyTenantStoragesApiEntry.js";
|
|
5
6
|
class ReplaceApiLambdaFnHandlersDecorator {
|
|
6
|
-
constructor(getApp, logger, decoratee){
|
|
7
|
+
constructor(getApp, getProjectConfigService, logger, decoratee){
|
|
7
8
|
this.getApp = getApp;
|
|
9
|
+
this.getProjectConfigService = getProjectConfigService;
|
|
8
10
|
this.logger = logger;
|
|
9
11
|
this.decoratee = decoratee;
|
|
10
12
|
}
|
|
11
13
|
async execute(appName, options = {}) {
|
|
12
14
|
const result = await this.decoratee.execute(appName, options);
|
|
13
15
|
if ("api" !== appName) return result;
|
|
16
|
+
if (hasTenantStorages(await this.getProjectConfigService.execute())) return result;
|
|
14
17
|
const app = this.getApp.execute("api");
|
|
15
18
|
const handlersFolderPath = path.join(getTemplatesFolderPath(), "extensions", "Postgres", "api");
|
|
16
19
|
fs.cpSync(handlersFolderPath, app.paths.workspaceFolder.toString(), {
|
|
@@ -25,6 +28,7 @@ const ReplaceApiLambdaFnHandlers = BuildAppWorkspaceService.createDecorator({
|
|
|
25
28
|
decorator: ReplaceApiLambdaFnHandlersDecorator,
|
|
26
29
|
dependencies: [
|
|
27
30
|
GetApp,
|
|
31
|
+
GetProjectConfigService,
|
|
28
32
|
LoggerService
|
|
29
33
|
]
|
|
30
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions/Postgres/ReplaceApiLambdaFnHandlers.js","sources":["../../../src/extensions/Postgres/ReplaceApiLambdaFnHandlers.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport {\n BuildAppWorkspaceService,\n GetApp,\n LoggerService\n} from \"@webiny/project/abstractions/index.js\";\nimport { getTemplatesFolderPath } from \"~/utils/index.js\";\n\n/**\n * With `<Infra.
|
|
1
|
+
{"version":3,"file":"extensions/Postgres/ReplaceApiLambdaFnHandlers.js","sources":["../../../src/extensions/Postgres/ReplaceApiLambdaFnHandlers.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport {\n BuildAppWorkspaceService,\n GetApp,\n GetProjectConfigService,\n LoggerService\n} from \"@webiny/project/abstractions/index.js\";\nimport { getTemplatesFolderPath } from \"~/utils/index.js\";\nimport { hasTenantStorages } from \"~/extensions/ProjectAws/TenantStorages/ApplyTenantStoragesApiEntry.js\";\n\n/**\n * With `<Infra.AuroraPostgres />`, the api workspace gets the Postgres entry file: it exports the\n * handlers from `@webiny/api-composition-aws-pg` instead of the DynamoDB ones. Every API function\n * runs this one bundle, so this puts all of them on Postgres.\n */\nclass ReplaceApiLambdaFnHandlersDecorator implements BuildAppWorkspaceService.Interface {\n constructor(\n private getApp: GetApp.Interface,\n private getProjectConfigService: GetProjectConfigService.Interface,\n private logger: LoggerService.Interface,\n private decoratee: BuildAppWorkspaceService.Interface\n ) {}\n\n async execute(appName: GetApp.AppName, options: BuildAppWorkspaceService.Options = {}) {\n const result = await this.decoratee.execute(appName, options);\n if (appName !== \"api\") {\n return result;\n }\n\n // With tenant storages, `ApplyTenantStoragesApiEntry` puts the entry with them in place.\n if (hasTenantStorages(await this.getProjectConfigService.execute())) {\n return result;\n }\n\n const app = this.getApp.execute(\"api\");\n const handlersFolderPath = path.join(\n getTemplatesFolderPath(),\n \"extensions\",\n \"Postgres\",\n \"api\"\n );\n\n fs.cpSync(handlersFolderPath, app.paths.workspaceFolder.toString(), {\n recursive: true,\n force: true\n });\n\n this.logger.debug(\"Replaced API Lambda function handlers with Postgres versions.\");\n\n return result;\n }\n}\n\nexport const ReplaceApiLambdaFnHandlers = BuildAppWorkspaceService.createDecorator({\n decorator: ReplaceApiLambdaFnHandlersDecorator,\n dependencies: [GetApp, GetProjectConfigService, LoggerService]\n});\n"],"names":["ReplaceApiLambdaFnHandlersDecorator","getApp","getProjectConfigService","logger","decoratee","appName","options","result","hasTenantStorages","app","handlersFolderPath","path","getTemplatesFolderPath","fs","ReplaceApiLambdaFnHandlers","BuildAppWorkspaceService","GetApp","GetProjectConfigService","LoggerService"],"mappings":";;;;;AAgBA,MAAMA;IACF,YACYC,MAAwB,EACxBC,uBAA0D,EAC1DC,MAA+B,EAC/BC,SAA6C,CACvD;aAJUH,MAAM,GAANA;aACAC,uBAAuB,GAAvBA;aACAC,MAAM,GAANA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,OAAuB,EAAEC,UAA4C,CAAC,CAAC,EAAE;QACnF,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF,SAASC;QACrD,IAAID,AAAY,UAAZA,SACA,OAAOE;QAIX,IAAIC,kBAAkB,MAAM,IAAI,CAAC,uBAAuB,CAAC,OAAO,KAC5D,OAAOD;QAGX,MAAME,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,MAAMC,qBAAqBC,KAAK,IAAI,CAChCC,0BACA,cACA,YACA;QAGJC,GAAG,MAAM,CAACH,oBAAoBD,IAAI,KAAK,CAAC,eAAe,CAAC,QAAQ,IAAI;YAChE,WAAW;YACX,OAAO;QACX;QAEA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAElB,OAAOF;IACX;AACJ;AAEO,MAAMO,6BAA6BC,yBAAyB,eAAe,CAAC;IAC/E,WAAWf;IACX,cAAc;QAACgB;QAAQC;QAAyBC;KAAc;AAClE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CoreBeforeDeploy } from "@webiny/project-extensions-aws/abstractions/index.js";
|
|
2
2
|
import { GetProductionEnvironments, GetProjectConfigService, ProjectSdkParamsService } from "@webiny/project/abstractions/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* Stops `deploy core` when `<Infra.
|
|
4
|
+
* Stops `deploy core` when `<Infra.AuroraPostgres />` is combined with settings it can't run with:
|
|
5
5
|
*
|
|
6
6
|
* - no VPC: the database sits in private subnets, and the functions reach Secrets Manager through
|
|
7
7
|
* the VPC's NAT gateway. Production environments get a VPC by default, so this only asks for
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { CoreBeforeDeploy } from "@webiny/project-extensions-aws/abstractions/index.js";
|
|
2
2
|
import { GetProductionEnvironments, GetProjectConfigService, ProjectSdkParamsService } from "@webiny/project/abstractions/index.js";
|
|
3
3
|
import { GracefulError } from "@webiny/project";
|
|
4
|
-
import {
|
|
5
|
-
import { isVpcEnabled } from "../../pulumi/apps/extensions/isVpcEnabled.js";
|
|
4
|
+
import { assertPostgresNetwork } from "./assertPostgresNetwork.js";
|
|
6
5
|
import { getOsConfigFromExtension } from "../../pulumi/apps/extensions/getOsConfigFromExtension.js";
|
|
7
6
|
import { getBgDeploymentsConfigFromExtension } from "../../pulumi/apps/extensions/getBgDeploymentsConfigFromExtension.js";
|
|
8
7
|
const CONFIG_FILE = "webiny.config.tsx";
|
|
@@ -17,15 +16,14 @@ class ValidatePostgresBeforeCoreDeployImpl {
|
|
|
17
16
|
const { env } = this.projectSdkParamsService.get();
|
|
18
17
|
const productionEnvironments = await this.getProductionEnvironments.execute();
|
|
19
18
|
const isProduction = productionEnvironments.includes(env);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (getOsConfigFromExtension(projectConfig)) throw GracefulError.from(new Error("Cannot deploy Postgres with OpenSearch enabled."), "OpenSearch only works with the DynamoDB database setup.\n\nRemove %s, or remove %s, from your %s config file.", "<Infra.OpenSearch enabled />", "<Infra.Postgres />", CONFIG_FILE);
|
|
19
|
+
assertPostgresNetwork({
|
|
20
|
+
projectConfig,
|
|
21
|
+
isProduction,
|
|
22
|
+
component: "<Infra.AuroraPostgres />"
|
|
23
|
+
});
|
|
24
|
+
if (getOsConfigFromExtension(projectConfig)) throw GracefulError.from(new Error("Cannot deploy Postgres with OpenSearch enabled."), "OpenSearch only works with the DynamoDB database setup.\n\nRemove %s, or remove %s, from your %s config file.", "<Infra.OpenSearch enabled />", "<Infra.AuroraPostgres />", CONFIG_FILE);
|
|
27
25
|
const bgDeploymentsConfig = getBgDeploymentsConfigFromExtension(projectConfig);
|
|
28
|
-
if (bgDeploymentsConfig && bgDeploymentsConfig.enabled) throw GracefulError.from(new Error("Cannot deploy Postgres with blue-green deployments."), "Blue-green deployments and the Sync System only work with the DynamoDB database setup.\n\nRemove %s, or remove %s, from your %s config file.", "<Infra.BlueGreenDeployments enabled />", "<Infra.
|
|
26
|
+
if (bgDeploymentsConfig && bgDeploymentsConfig.enabled) throw GracefulError.from(new Error("Cannot deploy Postgres with blue-green deployments."), "Blue-green deployments and the Sync System only work with the DynamoDB database setup.\n\nRemove %s, or remove %s, from your %s config file.", "<Infra.BlueGreenDeployments enabled />", "<Infra.AuroraPostgres />", CONFIG_FILE);
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
const ValidatePostgresBeforeCoreDeploy = CoreBeforeDeploy.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js","sources":["../../../src/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.ts"],"sourcesContent":["import { CoreBeforeDeploy } from \"@webiny/project-extensions-aws/abstractions/index.js\";\nimport {\n GetProductionEnvironments,\n GetProjectConfigService,\n ProjectSdkParamsService\n} from \"@webiny/project/abstractions/index.js\";\nimport { GracefulError } from \"@webiny/project\";\nimport {
|
|
1
|
+
{"version":3,"file":"extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js","sources":["../../../src/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.ts"],"sourcesContent":["import { CoreBeforeDeploy } from \"@webiny/project-extensions-aws/abstractions/index.js\";\nimport {\n GetProductionEnvironments,\n GetProjectConfigService,\n ProjectSdkParamsService\n} from \"@webiny/project/abstractions/index.js\";\nimport { GracefulError } from \"@webiny/project\";\nimport { assertPostgresNetwork } from \"./assertPostgresNetwork.js\";\nimport { getOsConfigFromExtension } from \"~/pulumi/apps/extensions/getOsConfigFromExtension.js\";\nimport { getBgDeploymentsConfigFromExtension } from \"~/pulumi/apps/extensions/getBgDeploymentsConfigFromExtension.js\";\n\nconst CONFIG_FILE = \"webiny.config.tsx\";\n\n/**\n * Stops `deploy core` when `<Infra.AuroraPostgres />` is combined with settings it can't run with:\n *\n * - no VPC: the database sits in private subnets, and the functions reach Secrets Manager through\n * the VPC's NAT gateway. Production environments get a VPC by default, so this only asks for\n * `<Infra.Vpc enabled />` elsewhere. Postgres never turns the VPC on by itself, because the NAT\n * gateway costs money.\n * - an existing VPC without `postgresVpcConfig`: there's no subnet or security group to put the\n * database in.\n * - OpenSearch, and blue-green deployments (which bring the Sync System): both are DynamoDB-only.\n */\nexport class ValidatePostgresBeforeCoreDeployImpl implements CoreBeforeDeploy.Interface {\n constructor(\n private getProjectConfigService: GetProjectConfigService.Interface,\n private projectSdkParamsService: ProjectSdkParamsService.Interface,\n private getProductionEnvironments: GetProductionEnvironments.Interface\n ) {}\n\n async execute() {\n const projectConfig = await this.getProjectConfigService.execute();\n const { env } = this.projectSdkParamsService.get();\n const productionEnvironments = await this.getProductionEnvironments.execute();\n const isProduction = productionEnvironments.includes(env);\n\n assertPostgresNetwork({\n projectConfig,\n isProduction,\n component: \"<Infra.AuroraPostgres />\"\n });\n\n if (getOsConfigFromExtension(projectConfig)) {\n throw GracefulError.from(\n new Error(\"Cannot deploy Postgres with OpenSearch enabled.\"),\n [\n \"OpenSearch only works with the DynamoDB database setup.\",\n \"\",\n \"Remove %s, or remove %s, from your %s config file.\"\n ].join(\"\\n\"),\n \"<Infra.OpenSearch enabled />\",\n \"<Infra.AuroraPostgres />\",\n CONFIG_FILE\n );\n }\n\n const bgDeploymentsConfig = getBgDeploymentsConfigFromExtension(projectConfig);\n if (bgDeploymentsConfig && bgDeploymentsConfig.enabled) {\n throw GracefulError.from(\n new Error(\"Cannot deploy Postgres with blue-green deployments.\"),\n [\n \"Blue-green deployments and the Sync System only work with the DynamoDB database setup.\",\n \"\",\n \"Remove %s, or remove %s, from your %s config file.\"\n ].join(\"\\n\"),\n \"<Infra.BlueGreenDeployments enabled />\",\n \"<Infra.AuroraPostgres />\",\n CONFIG_FILE\n );\n }\n }\n}\n\nexport const ValidatePostgresBeforeCoreDeploy = CoreBeforeDeploy.createImplementation({\n implementation: ValidatePostgresBeforeCoreDeployImpl,\n dependencies: [GetProjectConfigService, ProjectSdkParamsService, GetProductionEnvironments]\n});\n"],"names":["CONFIG_FILE","ValidatePostgresBeforeCoreDeployImpl","getProjectConfigService","projectSdkParamsService","getProductionEnvironments","projectConfig","env","productionEnvironments","isProduction","assertPostgresNetwork","getOsConfigFromExtension","GracefulError","Error","bgDeploymentsConfig","getBgDeploymentsConfigFromExtension","ValidatePostgresBeforeCoreDeploy","CoreBeforeDeploy","GetProjectConfigService","ProjectSdkParamsService","GetProductionEnvironments"],"mappings":";;;;;;AAWA,MAAMA,cAAc;AAab,MAAMC;IACT,YACYC,uBAA0D,EAC1DC,uBAA0D,EAC1DC,yBAA8D,CACxE;aAHUF,uBAAuB,GAAvBA;aACAC,uBAAuB,GAAvBA;aACAC,yBAAyB,GAAzBA;IACT;IAEH,MAAM,UAAU;QACZ,MAAMC,gBAAgB,MAAM,IAAI,CAAC,uBAAuB,CAAC,OAAO;QAChE,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAAC,uBAAuB,CAAC,GAAG;QAChD,MAAMC,yBAAyB,MAAM,IAAI,CAAC,yBAAyB,CAAC,OAAO;QAC3E,MAAMC,eAAeD,uBAAuB,QAAQ,CAACD;QAErDG,sBAAsB;YAClBJ;YACAG;YACA,WAAW;QACf;QAEA,IAAIE,yBAAyBL,gBACzB,MAAMM,cAAc,IAAI,CACpB,IAAIC,MAAM,oDACV,iHAKA,gCACA,4BACAZ;QAIR,MAAMa,sBAAsBC,oCAAoCT;QAChE,IAAIQ,uBAAuBA,oBAAoB,OAAO,EAClD,MAAMF,cAAc,IAAI,CACpB,IAAIC,MAAM,wDACV,gJAKA,0CACA,4BACAZ;IAGZ;AACJ;AAEO,MAAMe,mCAAmCC,iBAAiB,oBAAoB,CAAC;IAClF,gBAAgBf;IAChB,cAAc;QAACgB;QAAyBC;QAAyBC;KAA0B;AAC/F"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type IProjectConfigModel } from "@webiny/project/abstractions/models/index.js";
|
|
2
|
+
export interface AssertPostgresNetworkParams {
|
|
3
|
+
projectConfig: IProjectConfigModel;
|
|
4
|
+
isProduction: boolean;
|
|
5
|
+
/** The component that needs the network, as the messages name it: `<Infra.AuroraPostgres />`. */
|
|
6
|
+
component: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Stops `deploy core` when an Aurora cluster has no network to go into. Shared by
|
|
10
|
+
* `<Infra.AuroraPostgres />` and `<Infra.TenantStorage.AuroraPostgres>`:
|
|
11
|
+
*
|
|
12
|
+
* - no VPC: the database sits in private subnets, and the functions reach it, and Secrets Manager,
|
|
13
|
+
* from inside the VPC. Production environments get a VPC by default, so this only asks for
|
|
14
|
+
* `<Infra.Vpc enabled />` elsewhere. Postgres never turns the VPC on by itself, because the NAT
|
|
15
|
+
* gateway costs money.
|
|
16
|
+
* - an existing VPC without `postgresVpcConfig`: there's no subnet or security group to put the
|
|
17
|
+
* database in.
|
|
18
|
+
*/
|
|
19
|
+
export declare const assertPostgresNetwork: (params: AssertPostgresNetworkParams) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GracefulError } from "@webiny/project";
|
|
2
|
+
import { getVpcConfigFromExtension } from "../../pulumi/apps/extensions/getVpcConfigFromExtension.js";
|
|
3
|
+
import { isVpcEnabled } from "../../pulumi/apps/extensions/isVpcEnabled.js";
|
|
4
|
+
const CONFIG_FILE = "webiny.config.tsx";
|
|
5
|
+
const assertPostgresNetwork = (params)=>{
|
|
6
|
+
const { projectConfig, isProduction, component } = params;
|
|
7
|
+
const vpcConfig = getVpcConfigFromExtension(projectConfig);
|
|
8
|
+
if (!isVpcEnabled(vpcConfig, isProduction)) throw GracefulError.from(new Error("Cannot deploy Postgres without a VPC."), "The database of %s runs in the VPC's private subnets, and the API functions reach it, and Secrets Manager, from inside the VPC.\n\nAdd %s to your %s config file. The VPC adds a NAT gateway, which has its own cost.\nProduction environments use a VPC by default, unless %s turns it off.", component, "<Infra.Vpc enabled />", CONFIG_FILE, "<Infra.Vpc enabled={false} />");
|
|
9
|
+
if ("object" == typeof vpcConfig && vpcConfig.useExistingVpc) {
|
|
10
|
+
const postgresVpcConfig = vpcConfig.useExistingVpc.postgresVpcConfig;
|
|
11
|
+
if (!postgresVpcConfig?.subnetIds?.length) throw GracefulError.from(new Error("Cannot deploy Postgres into an existing VPC without `postgresVpcConfig`."), "With %s, Webiny doesn't know which subnets and security groups the database should use.\n\nAdd %s to %s in your %s config file.\nThe security groups must accept port 5432 from the Lambda functions' security groups.", "useExistingVpc", "postgresVpcConfig: { subnetIds, securityGroupIds }", "<Infra.Vpc useExistingVpc={...} />", CONFIG_FILE);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export { assertPostgresNetwork };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=assertPostgresNetwork.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions/Postgres/assertPostgresNetwork.js","sources":["../../../src/extensions/Postgres/assertPostgresNetwork.ts"],"sourcesContent":["import { GracefulError } from \"@webiny/project\";\nimport { type IProjectConfigModel } from \"@webiny/project/abstractions/models/index.js\";\nimport { getVpcConfigFromExtension } from \"~/pulumi/apps/extensions/getVpcConfigFromExtension.js\";\nimport { isVpcEnabled } from \"~/pulumi/apps/extensions/isVpcEnabled.js\";\n\nconst CONFIG_FILE = \"webiny.config.tsx\";\n\nexport interface AssertPostgresNetworkParams {\n projectConfig: IProjectConfigModel;\n isProduction: boolean;\n /** The component that needs the network, as the messages name it: `<Infra.AuroraPostgres />`. */\n component: string;\n}\n\n/**\n * Stops `deploy core` when an Aurora cluster has no network to go into. Shared by\n * `<Infra.AuroraPostgres />` and `<Infra.TenantStorage.AuroraPostgres>`:\n *\n * - no VPC: the database sits in private subnets, and the functions reach it, and Secrets Manager,\n * from inside the VPC. Production environments get a VPC by default, so this only asks for\n * `<Infra.Vpc enabled />` elsewhere. Postgres never turns the VPC on by itself, because the NAT\n * gateway costs money.\n * - an existing VPC without `postgresVpcConfig`: there's no subnet or security group to put the\n * database in.\n */\nexport const assertPostgresNetwork = (params: AssertPostgresNetworkParams): void => {\n const { projectConfig, isProduction, component } = params;\n\n const vpcConfig = getVpcConfigFromExtension(projectConfig);\n if (!isVpcEnabled(vpcConfig, isProduction)) {\n throw GracefulError.from(\n new Error(\"Cannot deploy Postgres without a VPC.\"),\n [\n \"The database of %s runs in the VPC's private subnets, and the API functions reach it, and Secrets Manager, from inside the VPC.\",\n \"\",\n \"Add %s to your %s config file. The VPC adds a NAT gateway, which has its own cost.\",\n \"Production environments use a VPC by default, unless %s turns it off.\"\n ].join(\"\\n\"),\n component,\n \"<Infra.Vpc enabled />\",\n CONFIG_FILE,\n \"<Infra.Vpc enabled={false} />\"\n );\n }\n\n if (typeof vpcConfig === \"object\" && vpcConfig.useExistingVpc) {\n const postgresVpcConfig = vpcConfig.useExistingVpc.postgresVpcConfig;\n if (!postgresVpcConfig?.subnetIds?.length) {\n throw GracefulError.from(\n new Error(\n \"Cannot deploy Postgres into an existing VPC without `postgresVpcConfig`.\"\n ),\n [\n \"With %s, Webiny doesn't know which subnets and security groups the database should use.\",\n \"\",\n \"Add %s to %s in your %s config file.\",\n \"The security groups must accept port 5432 from the Lambda functions' security groups.\"\n ].join(\"\\n\"),\n \"useExistingVpc\",\n \"postgresVpcConfig: { subnetIds, securityGroupIds }\",\n \"<Infra.Vpc useExistingVpc={...} />\",\n CONFIG_FILE\n );\n }\n }\n};\n"],"names":["CONFIG_FILE","assertPostgresNetwork","params","projectConfig","isProduction","component","vpcConfig","getVpcConfigFromExtension","isVpcEnabled","GracefulError","Error","postgresVpcConfig"],"mappings":";;;AAKA,MAAMA,cAAc;AAoBb,MAAMC,wBAAwB,CAACC;IAClC,MAAM,EAAEC,aAAa,EAAEC,YAAY,EAAEC,SAAS,EAAE,GAAGH;IAEnD,MAAMI,YAAYC,0BAA0BJ;IAC5C,IAAI,CAACK,aAAaF,WAAWF,eACzB,MAAMK,cAAc,IAAI,CACpB,IAAIC,MAAM,0CACV,gSAMAL,WACA,yBACAL,aACA;IAIR,IAAI,AAAqB,YAArB,OAAOM,aAA0BA,UAAU,cAAc,EAAE;QAC3D,MAAMK,oBAAoBL,UAAU,cAAc,CAAC,iBAAiB;QACpE,IAAI,CAACK,mBAAmB,WAAW,QAC/B,MAAMF,cAAc,IAAI,CACpB,IAAIC,MACA,6EAEJ,0NAMA,kBACA,sDACA,sCACAV;IAGZ;AACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The package whose handlers the Postgres api bundle exports; knex and pg are resolved from it. */
|
|
2
|
-
export declare const PG_HANDLER_PACKAGE = "@webiny/api-
|
|
2
|
+
export declare const PG_HANDLER_PACKAGE = "@webiny/api-composition-aws-pg";
|
|
3
3
|
/**
|
|
4
4
|
* What the Postgres bundle loads from `node_modules` at runtime. The bundler keeps knex external
|
|
5
5
|
* (it statically requires a driver for every SQL dialect), and knex loads `pg` by name.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import { createRequire } from "module";
|
|
4
|
-
const PG_HANDLER_PACKAGE = "@webiny/api-
|
|
4
|
+
const PG_HANDLER_PACKAGE = "@webiny/api-composition-aws-pg";
|
|
5
5
|
const PG_RUNTIME_PACKAGES = [
|
|
6
6
|
"knex",
|
|
7
7
|
"pg"
|
|
@@ -78,7 +78,7 @@ const placePackages = (handlerDir, nodeModulesDir)=>{
|
|
|
78
78
|
const copyPgRuntimeModules = async (params)=>{
|
|
79
79
|
const { resolveFrom, buildDir } = params;
|
|
80
80
|
const handlerDir = findPackageDir(PG_HANDLER_PACKAGE, resolveFrom);
|
|
81
|
-
if (!handlerDir) throw new Error(
|
|
81
|
+
if (!handlerDir) throw new Error(`Postgres on AWS (<Infra.AuroraPostgres /> or <Infra.TenantStorage.AuroraPostgres>) needs ${PG_HANDLER_PACKAGE} in the project. Add it to package.json and install it.`);
|
|
82
82
|
const nodeModulesDir = path.join(buildDir, "node_modules");
|
|
83
83
|
const packages = placePackages(handlerDir, nodeModulesDir);
|
|
84
84
|
const byRealDir = new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions/Postgres/copyPgRuntimeModules.js","sources":["../../../src/extensions/Postgres/copyPgRuntimeModules.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport { createRequire } from \"module\";\n\n/** The package whose handlers the Postgres api bundle exports; knex and pg are resolved from it. */\nexport const PG_HANDLER_PACKAGE = \"@webiny/api-event-handler-aws-pg\";\n\n/**\n * What the Postgres bundle loads from `node_modules` at runtime. The bundler keeps knex external\n * (it statically requires a driver for every SQL dialect), and knex loads `pg` by name.\n */\nexport const PG_RUNTIME_PACKAGES = [\"knex\", \"pg\"] as const;\n\nexport interface CopyPgRuntimeModulesParams {\n /** Where module resolution starts: the api app's source folder, as the bundler resolves it. */\n resolveFrom: string;\n /** The api bundle's output folder. The modules go into its `node_modules`. */\n buildDir: string;\n}\n\nexport interface CopyPgRuntimeModulesResult {\n /** Every package copied, as `name@version`, sorted. */\n packages: string[];\n /** How many files were copied. */\n files: number;\n}\n\ninterface PackageJson {\n name: string;\n version: string;\n dependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n}\n\ninterface PlacedPackage {\n name: string;\n version: string;\n /** The package's real folder on disk (symlinks resolved). */\n realDir: string;\n /** Where it goes in the build. */\n destDir: string;\n}\n\nconst readPackageJson = (dir: string): PackageJson => {\n return JSON.parse(fs.readFileSync(path.join(dir, \"package.json\"), \"utf8\"));\n};\n\n/** Finds a package the way Node does from `fromDir`: in each ancestor's `node_modules`. */\nconst findPackageDir = (name: string, fromDir: string): string | null => {\n let dir = path.resolve(fromDir);\n while (true) {\n if (path.basename(dir) !== \"node_modules\") {\n const candidate = path.join(dir, \"node_modules\", name);\n if (fs.existsSync(path.join(candidate, \"package.json\"))) {\n return fs.realpathSync(candidate);\n }\n }\n const parent = path.dirname(dir);\n if (parent === dir) {\n return null;\n }\n dir = parent;\n }\n};\n\n/**\n * Lays out knex, pg and their dependency closure (`dependencies` and installed\n * `optionalDependencies`, never peers) the way an install would: each package at the top of\n * `build/node_modules`, unless a different version of it is already there, in which case it nests\n * under the package that needs it. So `sharp`, `@aws-sdk/*` and the drivers knex can load but the\n * project doesn't use (better-sqlite3, mysql, ...) never get in.\n */\nconst placePackages = (handlerDir: string, nodeModulesDir: string): PlacedPackage[] => {\n // destDir -> placed package\n const placed = new Map<string, PlacedPackage>();\n const queue: PlacedPackage[] = [];\n\n const place = (name: string, realDir: string, destDir: string) => {\n const pkg: PlacedPackage = {\n name,\n version: readPackageJson(realDir).version,\n realDir,\n destDir\n };\n placed.set(destDir, pkg);\n queue.push(pkg);\n };\n\n /* What Node would load for `name` from inside `fromDestDir`, given what is placed so far. */\n const resolvePlaced = (name: string, fromDestDir: string): PlacedPackage | undefined => {\n let dir = fromDestDir;\n while (true) {\n if (path.basename(dir) !== \"node_modules\") {\n const found = placed.get(path.join(dir, \"node_modules\", name));\n if (found) {\n return found;\n }\n }\n if (dir === path.dirname(nodeModulesDir)) {\n return undefined;\n }\n dir = path.dirname(dir);\n }\n };\n\n for (const name of PG_RUNTIME_PACKAGES) {\n const realDir = findPackageDir(name, handlerDir);\n if (!realDir) {\n throw new Error(\n `Could not find \"${name}\", which ${PG_HANDLER_PACKAGE} needs. Reinstall the project's dependencies.`\n );\n }\n place(name, realDir, path.join(nodeModulesDir, name));\n }\n\n while (queue.length) {\n const parent = queue.shift()!;\n const pkgJson = readPackageJson(parent.realDir);\n const deps = [\n ...Object.keys(pkgJson.dependencies || {}).map(name => ({ name, optional: false })),\n ...Object.keys(pkgJson.optionalDependencies || {}).map(name => ({\n name,\n optional: true\n }))\n ];\n\n for (const dep of deps) {\n const realDir = findPackageDir(dep.name, parent.realDir);\n if (!realDir) {\n if (dep.optional) {\n continue;\n }\n throw new Error(\n `Could not find \"${dep.name}\", which \"${parent.name}\" needs. Reinstall the project's dependencies.`\n );\n }\n\n const resolved = resolvePlaced(dep.name, parent.destDir);\n if (resolved?.realDir === realDir) {\n continue;\n }\n // Nothing by that name is reachable: it goes to the top. Otherwise a different version\n // is, so this one nests under the package that needs it.\n const destDir = resolved\n ? path.join(parent.destDir, \"node_modules\", dep.name)\n : path.join(nodeModulesDir, dep.name);\n place(dep.name, realDir, destDir);\n }\n }\n\n return Array.from(placed.values());\n};\n\n/**\n * Copies knex, pg and the files they need into `<buildDir>/node_modules`, so the uploaded api\n * bundle can load them on Lambda. `@vercel/nft` traces the file closure from each package's entry\n * (only the files that can be loaded, no docs, types or CLI), and the closure is limited to the\n * packages `placePackages` chose. pg is plain JavaScript, so a build on any OS runs on Lambda.\n * Nothing is downloaded: the files come from the project's own install.\n */\nexport const copyPgRuntimeModules = async (\n params: CopyPgRuntimeModulesParams\n): Promise<CopyPgRuntimeModulesResult> => {\n const { resolveFrom, buildDir } = params;\n\n const handlerDir = findPackageDir(PG_HANDLER_PACKAGE, resolveFrom);\n if (!handlerDir) {\n throw new Error(\n `<Infra.Postgres /> needs ${PG_HANDLER_PACKAGE} in the project. Add it to package.json and install it.`\n );\n }\n\n const nodeModulesDir = path.join(buildDir, \"node_modules\");\n const packages = placePackages(handlerDir, nodeModulesDir);\n\n // realDir -> every place that package goes (one, unless a version is needed in two places).\n const byRealDir = new Map<string, PlacedPackage[]>();\n for (const pkg of packages) {\n byRealDir.set(pkg.realDir, [...(byRealDir.get(pkg.realDir) || []), pkg]);\n }\n // Longest first, so a file inside a nested node_modules belongs to the inner package.\n const realDirs = Array.from(byRealDir.keys()).sort((a, b) => b.length - a.length);\n\n const entries = PG_RUNTIME_PACKAGES.map(name => {\n const pkg = packages.find(p => p.destDir === path.join(nodeModulesDir, name))!;\n // The CommonJS entry (by `main`), which is what knex loads `pg` through.\n return createRequire(path.join(pkg.realDir, \"package.json\")).resolve(pkg.realDir);\n });\n\n // Loaded only for a Postgres build: every CLI command registers the hook.\n const { nodeFileTrace } = await import(\"@vercel/nft\");\n const base = path.parse(handlerDir).root;\n const { fileList } = await nodeFileTrace(entries, { base });\n\n // Each package.json, always: Node reads it to resolve the package.\n const files = new Set<string>(packages.map(pkg => path.join(pkg.realDir, \"package.json\")));\n for (const relPath of fileList) {\n files.add(path.join(base, relPath));\n }\n\n let copied = 0;\n for (const file of files) {\n const realDir = realDirs.find(dir => file.startsWith(dir + path.sep));\n if (!realDir || !fs.statSync(file, { throwIfNoEntry: false })?.isFile()) {\n continue;\n }\n const relPath = path.relative(realDir, file);\n for (const pkg of byRealDir.get(realDir)!) {\n const dest = path.join(pkg.destDir, relPath);\n fs.mkdirSync(path.dirname(dest), { recursive: true });\n fs.copyFileSync(file, dest);\n copied++;\n }\n }\n\n return {\n packages: Array.from(new Set(packages.map(pkg => `${pkg.name}@${pkg.version}`))).sort(),\n files: copied\n };\n};\n"],"names":["PG_HANDLER_PACKAGE","PG_RUNTIME_PACKAGES","readPackageJson","dir","JSON","fs","path","findPackageDir","name","fromDir","candidate","parent","placePackages","handlerDir","nodeModulesDir","placed","Map","queue","place","realDir","destDir","pkg","resolvePlaced","fromDestDir","found","Error","pkgJson","deps","Object","dep","resolved","Array","copyPgRuntimeModules","params","resolveFrom","buildDir","packages","byRealDir","realDirs","a","b","entries","p","createRequire","nodeFileTrace","base","fileList","files","Set","relPath","copied","file","dest"],"mappings":";;;AAKO,MAAMA,qBAAqB;AAM3B,MAAMC,sBAAsB;IAAC;IAAQ;CAAK;AAgCjD,MAAMC,kBAAkB,CAACC,MACdC,KAAK,KAAK,CAACC,GAAG,YAAY,CAACC,KAAK,IAAI,CAACH,KAAK,iBAAiB;AAItE,MAAMI,iBAAiB,CAACC,MAAcC;IAClC,IAAIN,MAAMG,KAAK,OAAO,CAACG;IACvB,MAAO,KAAM;QACT,IAAIH,AAAuB,mBAAvBA,KAAK,QAAQ,CAACH,MAAyB;YACvC,MAAMO,YAAYJ,KAA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AE,WAAW;YAAK;YACnD/C,GAAG,YAAY,CAAC8C,MAAMC;YACtBF;QACJ;IACJ;IAEA,OAAO;QACH,UAAUnB,MAAM,IAAI,CAAC,IAAIiB,IAAIZ,SAAS,GAAG,CAACf,CAAAA,MAAO,GAAGA,IAAI,IAAI,CAAC,CAAC,EAAEA,IAAI,OAAO,EAAE,IAAI,IAAI;QACrF,OAAO6B;IACX;AACJ"}
|
|
1
|
+
{"version":3,"file":"extensions/Postgres/copyPgRuntimeModules.js","sources":["../../../src/extensions/Postgres/copyPgRuntimeModules.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport { createRequire } from \"module\";\n\n/** The package whose handlers the Postgres api bundle exports; knex and pg are resolved from it. */\nexport const PG_HANDLER_PACKAGE = \"@webiny/api-composition-aws-pg\";\n\n/**\n * What the Postgres bundle loads from `node_modules` at runtime. The bundler keeps knex external\n * (it statically requires a driver for every SQL dialect), and knex loads `pg` by name.\n */\nexport const PG_RUNTIME_PACKAGES = [\"knex\", \"pg\"] as const;\n\nexport interface CopyPgRuntimeModulesParams {\n /** Where module resolution starts: the api app's source folder, as the bundler resolves it. */\n resolveFrom: string;\n /** The api bundle's output folder. The modules go into its `node_modules`. */\n buildDir: string;\n}\n\nexport interface CopyPgRuntimeModulesResult {\n /** Every package copied, as `name@version`, sorted. */\n packages: string[];\n /** How many files were copied. */\n files: number;\n}\n\ninterface PackageJson {\n name: string;\n version: string;\n dependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n}\n\ninterface PlacedPackage {\n name: string;\n version: string;\n /** The package's real folder on disk (symlinks resolved). */\n realDir: string;\n /** Where it goes in the build. */\n destDir: string;\n}\n\nconst readPackageJson = (dir: string): PackageJson => {\n return JSON.parse(fs.readFileSync(path.join(dir, \"package.json\"), \"utf8\"));\n};\n\n/** Finds a package the way Node does from `fromDir`: in each ancestor's `node_modules`. */\nconst findPackageDir = (name: string, fromDir: string): string | null => {\n let dir = path.resolve(fromDir);\n while (true) {\n if (path.basename(dir) !== \"node_modules\") {\n const candidate = path.join(dir, \"node_modules\", name);\n if (fs.existsSync(path.join(candidate, \"package.json\"))) {\n return fs.realpathSync(candidate);\n }\n }\n const parent = path.dirname(dir);\n if (parent === dir) {\n return null;\n }\n dir = parent;\n }\n};\n\n/**\n * Lays out knex, pg and their dependency closure (`dependencies` and installed\n * `optionalDependencies`, never peers) the way an install would: each package at the top of\n * `build/node_modules`, unless a different version of it is already there, in which case it nests\n * under the package that needs it. So `sharp`, `@aws-sdk/*` and the drivers knex can load but the\n * project doesn't use (better-sqlite3, mysql, ...) never get in.\n */\nconst placePackages = (handlerDir: string, nodeModulesDir: string): PlacedPackage[] => {\n // destDir -> placed package\n const placed = new Map<string, PlacedPackage>();\n const queue: PlacedPackage[] = [];\n\n const place = (name: string, realDir: string, destDir: string) => {\n const pkg: PlacedPackage = {\n name,\n version: readPackageJson(realDir).version,\n realDir,\n destDir\n };\n placed.set(destDir, pkg);\n queue.push(pkg);\n };\n\n /* What Node would load for `name` from inside `fromDestDir`, given what is placed so far. */\n const resolvePlaced = (name: string, fromDestDir: string): PlacedPackage | undefined => {\n let dir = fromDestDir;\n while (true) {\n if (path.basename(dir) !== \"node_modules\") {\n const found = placed.get(path.join(dir, \"node_modules\", name));\n if (found) {\n return found;\n }\n }\n if (dir === path.dirname(nodeModulesDir)) {\n return undefined;\n }\n dir = path.dirname(dir);\n }\n };\n\n for (const name of PG_RUNTIME_PACKAGES) {\n const realDir = findPackageDir(name, handlerDir);\n if (!realDir) {\n throw new Error(\n `Could not find \"${name}\", which ${PG_HANDLER_PACKAGE} needs. Reinstall the project's dependencies.`\n );\n }\n place(name, realDir, path.join(nodeModulesDir, name));\n }\n\n while (queue.length) {\n const parent = queue.shift()!;\n const pkgJson = readPackageJson(parent.realDir);\n const deps = [\n ...Object.keys(pkgJson.dependencies || {}).map(name => ({ name, optional: false })),\n ...Object.keys(pkgJson.optionalDependencies || {}).map(name => ({\n name,\n optional: true\n }))\n ];\n\n for (const dep of deps) {\n const realDir = findPackageDir(dep.name, parent.realDir);\n if (!realDir) {\n if (dep.optional) {\n continue;\n }\n throw new Error(\n `Could not find \"${dep.name}\", which \"${parent.name}\" needs. Reinstall the project's dependencies.`\n );\n }\n\n const resolved = resolvePlaced(dep.name, parent.destDir);\n if (resolved?.realDir === realDir) {\n continue;\n }\n // Nothing by that name is reachable: it goes to the top. Otherwise a different version\n // is, so this one nests under the package that needs it.\n const destDir = resolved\n ? path.join(parent.destDir, \"node_modules\", dep.name)\n : path.join(nodeModulesDir, dep.name);\n place(dep.name, realDir, destDir);\n }\n }\n\n return Array.from(placed.values());\n};\n\n/**\n * Copies knex, pg and the files they need into `<buildDir>/node_modules`, so the uploaded api\n * bundle can load them on Lambda. `@vercel/nft` traces the file closure from each package's entry\n * (only the files that can be loaded, no docs, types or CLI), and the closure is limited to the\n * packages `placePackages` chose. pg is plain JavaScript, so a build on any OS runs on Lambda.\n * Nothing is downloaded: the files come from the project's own install.\n */\nexport const copyPgRuntimeModules = async (\n params: CopyPgRuntimeModulesParams\n): Promise<CopyPgRuntimeModulesResult> => {\n const { resolveFrom, buildDir } = params;\n\n const handlerDir = findPackageDir(PG_HANDLER_PACKAGE, resolveFrom);\n if (!handlerDir) {\n throw new Error(\n `Postgres on AWS (<Infra.AuroraPostgres /> or <Infra.TenantStorage.AuroraPostgres>) needs ${PG_HANDLER_PACKAGE} in the project. Add it to package.json and install it.`\n );\n }\n\n const nodeModulesDir = path.join(buildDir, \"node_modules\");\n const packages = placePackages(handlerDir, nodeModulesDir);\n\n // realDir -> every place that package goes (one, unless a version is needed in two places).\n const byRealDir = new Map<string, PlacedPackage[]>();\n for (const pkg of packages) {\n byRealDir.set(pkg.realDir, [...(byRealDir.get(pkg.realDir) || []), pkg]);\n }\n // Longest first, so a file inside a nested node_modules belongs to the inner package.\n const realDirs = Array.from(byRealDir.keys()).sort((a, b) => b.length - a.length);\n\n const entries = PG_RUNTIME_PACKAGES.map(name => {\n const pkg = packages.find(p => p.destDir === path.join(nodeModulesDir, name))!;\n // The CommonJS entry (by `main`), which is what knex loads `pg` through.\n return createRequire(path.join(pkg.realDir, \"package.json\")).resolve(pkg.realDir);\n });\n\n // Loaded only for a Postgres build: every CLI command registers the hook.\n const { nodeFileTrace } = await import(\"@vercel/nft\");\n const base = path.parse(handlerDir).root;\n const { fileList } = await nodeFileTrace(entries, { base });\n\n // Each package.json, always: Node reads it to resolve the package.\n const files = new Set<string>(packages.map(pkg => path.join(pkg.realDir, \"package.json\")));\n for (const relPath of fileList) {\n files.add(path.join(base, relPath));\n }\n\n let copied = 0;\n for (const file of files) {\n const realDir = realDirs.find(dir => file.startsWith(dir + path.sep));\n if (!realDir || !fs.statSync(file, { throwIfNoEntry: false })?.isFile()) {\n continue;\n }\n const relPath = path.relative(realDir, file);\n for (const pkg of byRealDir.get(realDir)!) {\n const dest = path.join(pkg.destDir, relPath);\n fs.mkdirSync(path.dirname(dest), { recursive: true });\n fs.copyFileSync(file, dest);\n copied++;\n }\n }\n\n return {\n packages: Array.from(new Set(packages.map(pkg => `${pkg.name}@${pkg.version}`))).sort(),\n files: copied\n };\n};\n"],"names":["PG_HANDLER_PACKAGE","PG_RUNTIME_PACKAGES","readPackageJson","dir","JSON","fs","path","findPackageDir","name","fromDir","candidate","parent","placePackages","handlerDir","nodeModulesDir","placed","Map","queue","place","realDir","destDir","pkg","resolvePlaced","fromDestDir","found","Error","pkgJson","deps","Object","dep","resolved","Array","copyPgRuntimeModules","params","resolveFrom","buildDir","packages","byRealDir","realDirs","a","b","entries","p","createRequire","nodeFileTrace","base","fileList","files","Set","relPath","copied","file","dest"],"mappings":";;;AAKO,MAAMA,qBAAqB;AAM3B,MAAMC,sBAAsB;IAAC;IAAQ;CAAK;AAgCjD,MAAMC,kBAAkB,CAACC,MACdC,KAAK,KAAK,CAACC,GAAG,YAAY,CAACC,KAAK,IAAI,CAACH,KAAK,iBAAiB;AAItE,MAAMI,iBAAiB,CAACC,MAAcC;IAClC,IAAIN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,SAAW;YACvC,MAAMiC,OAAO9C,KAAK,IAAI,CAACe,IAAI,OAAO,EAAE4B;YACpC5C,GAAG,SAAS,CAACC,KAAK,OAAO,CAAC8C,OAAO;gBAAE,WAAW;YAAK;YACnD/C,GAAG,YAAY,CAAC8C,MAAMC;YACtBF;QACJ;IACJ;IAEA,OAAO;QACH,UAAUnB,MAAM,IAAI,CAAC,IAAIiB,IAAIZ,SAAS,GAAG,CAACf,CAAAA,MAAO,GAAGA,IAAI,IAAI,CAAC,CAAC,EAAEA,IAAI,OAAO,EAAE,IAAI,IAAI;QACrF,OAAO6B;IACX;AACJ"}
|
|
@@ -3,7 +3,23 @@ import { UiService } from "@webiny/project/abstractions/services/UiService.js";
|
|
|
3
3
|
import { LoggerService } from "@webiny/project/abstractions/services/LoggerService.js";
|
|
4
4
|
import { GetProjectConfigService } from "@webiny/project/abstractions/index.js";
|
|
5
5
|
import { ApiGqlClient } from "@webiny/project-extensions-aws/abstractions/ApiGqlClient.js";
|
|
6
|
-
|
|
6
|
+
export interface AutoInstallAdminUser {
|
|
7
|
+
firstName: string;
|
|
8
|
+
lastName: string;
|
|
9
|
+
email: string;
|
|
10
|
+
password: string;
|
|
11
|
+
}
|
|
12
|
+
export interface InstallationInputItem {
|
|
13
|
+
app: string;
|
|
14
|
+
data: AutoInstallAdminUser;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Builds the `installSystem` input. A user is created only when the IdP has a user installer
|
|
18
|
+
* and `adminUser` is given; with neither, only the always-run installers run. Any other
|
|
19
|
+
* combination is a config mistake, and throws a `GracefulError`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const buildInstallationInput: (installerApp: string | undefined, adminUser: AutoInstallAdminUser | undefined) => InstallationInputItem[];
|
|
22
|
+
export declare class AutoInstallAfterApiDeployImpl implements ApiAfterDeploy.Interface {
|
|
7
23
|
private apiGqlClient;
|
|
8
24
|
private ui;
|
|
9
25
|
private getProjectConfig;
|
|
@@ -14,4 +30,3 @@ declare class AutoInstallAfterApiDeployImpl implements ApiAfterDeploy.Interface
|
|
|
14
30
|
export declare const AutoInstallAfterApiDeploy: typeof AutoInstallAfterApiDeployImpl & {
|
|
15
31
|
__abstraction: import("@webiny/di").Abstraction<import("@webiny/project-extensions-aws/abstractions/index.js").IApiAfterDeploy>;
|
|
16
32
|
};
|
|
17
|
-
export {};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { ApiAfterDeploy } from "@webiny/project-extensions-aws/abstractions/index.js";
|
|
2
|
+
import { AutoInstall } from "@webiny/project-extensions-aws/extensions/index.js";
|
|
3
|
+
import { EnvVar } from "@webiny/project/extensions/index.js";
|
|
4
|
+
import { GracefulError } from "@webiny/project";
|
|
2
5
|
import { UiService } from "@webiny/project/abstractions/services/UiService.js";
|
|
3
6
|
import { LoggerService } from "@webiny/project/abstractions/services/LoggerService.js";
|
|
4
7
|
import { GetProjectConfigService } from "@webiny/project/abstractions/index.js";
|
|
5
8
|
import { ApiGqlClient } from "@webiny/project-extensions-aws/abstractions/ApiGqlClient.js";
|
|
9
|
+
const AUTH_INSTALLER_APP_NAME_VAR = "REACT_APP_AUTH_INSTALLER_APP_NAME";
|
|
10
|
+
const CONFIG_FILE = "webiny.config.tsx";
|
|
6
11
|
const IS_INSTALLED_QUERY = `
|
|
7
12
|
query IsSystemInstalled {
|
|
8
13
|
system {
|
|
@@ -29,6 +34,17 @@ const INSTALL_MUTATION = `
|
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
`;
|
|
37
|
+
const buildInstallationInput = (installerApp, adminUser)=>{
|
|
38
|
+
if (installerApp && adminUser) return [
|
|
39
|
+
{
|
|
40
|
+
app: installerApp,
|
|
41
|
+
data: adminUser
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
if (installerApp) throw GracefulError.from(new Error(`Cannot auto-install without an admin user for "${installerApp}".`), "The %s identity provider creates the first admin user at install.\n\nAdd %s to %s in your %s config file.", installerApp, "adminUser", "<Project.AutoInstall />", CONFIG_FILE);
|
|
45
|
+
if (adminUser) throw GracefulError.from(new Error("Cannot auto-install with an admin user for this identity provider."), "The project's identity provider doesn't create users at install: they are created on first login.\n\nRemove %s from %s in your %s config file.", "adminUser", "<Project.AutoInstall />", CONFIG_FILE);
|
|
46
|
+
return [];
|
|
47
|
+
};
|
|
32
48
|
class AutoInstallAfterApiDeployImpl {
|
|
33
49
|
constructor(apiGqlClient, ui, getProjectConfig, logger){
|
|
34
50
|
this.apiGqlClient = apiGqlClient;
|
|
@@ -39,9 +55,11 @@ class AutoInstallAfterApiDeployImpl {
|
|
|
39
55
|
async execute(params) {
|
|
40
56
|
if (params.preview) return;
|
|
41
57
|
const projectConfig = await this.getProjectConfig.execute();
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
58
|
+
const [autoInstall] = projectConfig.extensionsByType(AutoInstall);
|
|
59
|
+
if (!autoInstall) return;
|
|
60
|
+
const installerApp = projectConfig.extensionsByType(EnvVar).find((ext)=>ext.params.varName === AUTH_INSTALLER_APP_NAME_VAR)?.params.value;
|
|
61
|
+
const adminUser = autoInstall.params.adminUser;
|
|
62
|
+
const installationInput = buildInstallationInput(installerApp, adminUser);
|
|
45
63
|
this.ui.info("Checking if system is already installed...");
|
|
46
64
|
try {
|
|
47
65
|
const isInstalledResponse = await this.apiGqlClient.query({
|
|
@@ -56,23 +74,11 @@ class AutoInstallAfterApiDeployImpl {
|
|
|
56
74
|
return;
|
|
57
75
|
}
|
|
58
76
|
this.ui.info("Auto-installing...");
|
|
59
|
-
const adminUser = config.adminUser || {
|
|
60
|
-
firstName: "John",
|
|
61
|
-
lastName: "Smith",
|
|
62
|
-
email: "admin@webiny.com",
|
|
63
|
-
password: "12345678"
|
|
64
|
-
};
|
|
65
|
-
const variables = {
|
|
66
|
-
installationInput: [
|
|
67
|
-
{
|
|
68
|
-
app: "Cognito",
|
|
69
|
-
data: adminUser
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
};
|
|
73
77
|
const installResponse = await this.apiGqlClient.mutation({
|
|
74
78
|
mutation: INSTALL_MUTATION,
|
|
75
|
-
variables
|
|
79
|
+
variables: {
|
|
80
|
+
installationInput
|
|
81
|
+
}
|
|
76
82
|
});
|
|
77
83
|
if (installResponse.data?.system.installSystem.error) {
|
|
78
84
|
const { message, code } = installResponse.data.system.installSystem.error;
|
|
@@ -84,6 +90,7 @@ class AutoInstallAfterApiDeployImpl {
|
|
|
84
90
|
throw new Error(message);
|
|
85
91
|
}
|
|
86
92
|
this.ui.success("System installed successfully!");
|
|
93
|
+
if (!adminUser) return void this.ui.info("Users are created on first login through your identity provider.");
|
|
87
94
|
this.ui.info("Admin credentials:");
|
|
88
95
|
this.ui.info(` Email: ${adminUser.email}`);
|
|
89
96
|
this.ui.info(` Password: ${adminUser.password}`);
|
|
@@ -98,6 +105,6 @@ const AutoInstallAfterApiDeploy = ApiAfterDeploy.createImplementation({
|
|
|
98
105
|
LoggerService
|
|
99
106
|
]
|
|
100
107
|
});
|
|
101
|
-
export { AutoInstallAfterApiDeploy };
|
|
108
|
+
export { AutoInstallAfterApiDeploy, AutoInstallAfterApiDeployImpl, buildInstallationInput };
|
|
102
109
|
|
|
103
110
|
//# sourceMappingURL=AutoInstallAfterApiDeploy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.js","sources":["../../../../src/extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.ts"],"sourcesContent":["import { ApiAfterDeploy } from \"@webiny/project-extensions-aws/abstractions/index.js\";\nimport { UiService } from \"@webiny/project/abstractions/services/UiService.js\";\nimport { LoggerService } from \"@webiny/project/abstractions/services/LoggerService.js\";\nimport { GetProjectConfigService } from \"@webiny/project/abstractions/index.js\";\nimport { ApiGqlClient } from \"@webiny/project-extensions-aws/abstractions/ApiGqlClient.js\";\n\nconst IS_INSTALLED_QUERY = `\n query IsSystemInstalled {\n system {\n isSystemInstalled {\n data\n error {\n message\n code\n }\n }\n }\n }\n`;\n\nconst INSTALL_MUTATION = `\n mutation InstallSystem($installationInput: JSON!) {\n system {\n installSystem(installationInput: $installationInput) {\n data\n error {\n message\n code\n }\n }\n }\n }\n`;\n\ninterface IsInstalledResponse {\n system: {\n isSystemInstalled: {\n data: boolean;\n error?: {\n message: string;\n code: string;\n };\n };\n };\n}\n\ninterface InstallResponse {\n system: {\n installSystem: {\n data: boolean;\n error?: {\n message: string;\n code: string;\n };\n };\n };\n}\n\
|
|
1
|
+
{"version":3,"file":"extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.js","sources":["../../../../src/extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.ts"],"sourcesContent":["import { ApiAfterDeploy } from \"@webiny/project-extensions-aws/abstractions/index.js\";\nimport { AutoInstall } from \"@webiny/project-extensions-aws/extensions/index.js\";\nimport { EnvVar } from \"@webiny/project/extensions/index.js\";\nimport { GracefulError } from \"@webiny/project\";\nimport { UiService } from \"@webiny/project/abstractions/services/UiService.js\";\nimport { LoggerService } from \"@webiny/project/abstractions/services/LoggerService.js\";\nimport { GetProjectConfigService } from \"@webiny/project/abstractions/index.js\";\nimport { ApiGqlClient } from \"@webiny/project-extensions-aws/abstractions/ApiGqlClient.js\";\n\n/**\n * Set by an IdP that creates the first admin user at install (Cognito, SelfHostedAuth), naming\n * its API-side `AppInstaller`. External IdPs (Okta, Auth0) don't set it: their users are created\n * on first login.\n */\nconst AUTH_INSTALLER_APP_NAME_VAR = \"REACT_APP_AUTH_INSTALLER_APP_NAME\";\n\nconst CONFIG_FILE = \"webiny.config.tsx\";\n\nconst IS_INSTALLED_QUERY = `\n query IsSystemInstalled {\n system {\n isSystemInstalled {\n data\n error {\n message\n code\n }\n }\n }\n }\n`;\n\nconst INSTALL_MUTATION = `\n mutation InstallSystem($installationInput: JSON!) {\n system {\n installSystem(installationInput: $installationInput) {\n data\n error {\n message\n code\n }\n }\n }\n }\n`;\n\ninterface IsInstalledResponse {\n system: {\n isSystemInstalled: {\n data: boolean;\n error?: {\n message: string;\n code: string;\n };\n };\n };\n}\n\ninterface InstallResponse {\n system: {\n installSystem: {\n data: boolean;\n error?: {\n message: string;\n code: string;\n };\n };\n };\n}\n\nexport interface AutoInstallAdminUser {\n firstName: string;\n lastName: string;\n email: string;\n password: string;\n}\n\nexport interface InstallationInputItem {\n app: string;\n data: AutoInstallAdminUser;\n}\n\n/**\n * Builds the `installSystem` input. A user is created only when the IdP has a user installer\n * and `adminUser` is given; with neither, only the always-run installers run. Any other\n * combination is a config mistake, and throws a `GracefulError`.\n */\nexport const buildInstallationInput = (\n installerApp: string | undefined,\n adminUser: AutoInstallAdminUser | undefined\n): InstallationInputItem[] => {\n if (installerApp && adminUser) {\n return [{ app: installerApp, data: adminUser }];\n }\n\n if (installerApp) {\n throw GracefulError.from(\n new Error(`Cannot auto-install without an admin user for \"${installerApp}\".`),\n [\n \"The %s identity provider creates the first admin user at install.\",\n \"\",\n \"Add %s to %s in your %s config file.\"\n ].join(\"\\n\"),\n installerApp,\n \"adminUser\",\n \"<Project.AutoInstall />\",\n CONFIG_FILE\n );\n }\n\n if (adminUser) {\n throw GracefulError.from(\n new Error(\"Cannot auto-install with an admin user for this identity provider.\"),\n [\n \"The project's identity provider doesn't create users at install: they are created on first login.\",\n \"\",\n \"Remove %s from %s in your %s config file.\"\n ].join(\"\\n\"),\n \"adminUser\",\n \"<Project.AutoInstall />\",\n CONFIG_FILE\n );\n }\n\n return [];\n};\n\nexport class AutoInstallAfterApiDeployImpl implements ApiAfterDeploy.Interface {\n constructor(\n private apiGqlClient: ApiGqlClient.Interface,\n private ui: UiService.Interface,\n private getProjectConfig: GetProjectConfigService.Interface,\n private logger: LoggerService.Interface\n ) {}\n\n async execute(params: ApiAfterDeploy.Params): Promise<void> {\n if (params.preview) {\n // Skip auto-install on preview deployments\n return;\n }\n\n const projectConfig = await this.getProjectConfig.execute();\n const [autoInstall] = projectConfig.extensionsByType(AutoInstall);\n\n if (!autoInstall) {\n return;\n }\n\n const installerApp = projectConfig\n .extensionsByType(EnvVar)\n .find(ext => ext.params.varName === AUTH_INSTALLER_APP_NAME_VAR)?.params.value;\n const adminUser = autoInstall.params.adminUser;\n\n // Built before any API call, so a config mistake fails without touching the system.\n const installationInput = buildInstallationInput(installerApp, adminUser);\n\n // Check if system is already installed\n this.ui.info(\"Checking if system is already installed...\");\n\n try {\n const isInstalledResponse = await this.apiGqlClient.query<IsInstalledResponse>({\n query: IS_INSTALLED_QUERY\n });\n\n if (isInstalledResponse.data?.system.isSystemInstalled.data === true) {\n this.ui.info(\"System is already installed, skipping auto-install.\");\n return;\n }\n } catch (error: any) {\n this.logger.error(\"Failed to check installation status\", { error });\n this.ui.warning(`Could not check installation status: ${error.message}`);\n return;\n }\n\n this.ui.info(\"Auto-installing...\");\n\n const installResponse = await this.apiGqlClient.mutation<InstallResponse>({\n mutation: INSTALL_MUTATION,\n variables: { installationInput }\n });\n\n if (installResponse.data?.system.installSystem.error) {\n const { message, code } = installResponse.data.system.installSystem.error;\n this.logger.error(\"Installation failed\", { message, code });\n this.ui.error(`Installation failed: ${message} (${code})`);\n throw new Error(message);\n }\n\n this.ui.success(\"System installed successfully!\");\n\n if (!adminUser) {\n this.ui.info(\"Users are created on first login through your identity provider.\");\n return;\n }\n\n this.ui.info(\"Admin credentials:\");\n this.ui.info(` Email: ${adminUser.email}`);\n this.ui.info(` Password: ${adminUser.password}`);\n }\n}\n\nexport const AutoInstallAfterApiDeploy = ApiAfterDeploy.createImplementation({\n implementation: AutoInstallAfterApiDeployImpl,\n dependencies: [ApiGqlClient, UiService, GetProjectConfigService, LoggerService]\n});\n"],"names":["AUTH_INSTALLER_APP_NAME_VAR","CONFIG_FILE","IS_INSTALLED_QUERY","INSTALL_MUTATION","buildInstallationInput","installerApp","adminUser","GracefulError","Error","AutoInstallAfterApiDeployImpl","apiGqlClient","ui","getProjectConfig","logger","params","projectConfig","autoInstall","AutoInstall","EnvVar","ext","installationInput","isInstalledResponse","error","installResponse","message","code","AutoInstallAfterApiDeploy","ApiAfterDeploy","ApiGqlClient","UiService","GetProjectConfigService","LoggerService"],"mappings":";;;;;;;;AAcA,MAAMA,8BAA8B;AAEpC,MAAMC,cAAc;AAEpB,MAAMC,qBAAqB,CAAC;;;;;;;;;;;;AAY5B,CAAC;AAED,MAAMC,mBAAmB,CAAC;;;;;;;;;;;;AAY1B,CAAC;AA2CM,MAAMC,yBAAyB,CAClCC,cACAC;IAEA,IAAID,gBAAgBC,WAChB,OAAO;QAAC;YAAE,KAAKD;YAAc,MAAMC;QAAU;KAAE;IAGnD,IAAID,cACA,MAAME,cAAc,IAAI,CACpB,IAAIC,MAAM,CAAC,+CAA+C,EAAEH,aAAa,EAAE,CAAC,GAC5E,6GAKAA,cACA,aACA,2BACAJ;IAIR,IAAIK,WACA,MAAMC,cAAc,IAAI,CACpB,IAAIC,MAAM,uEACV,kJAKA,aACA,2BACAP;IAIR,OAAO,EAAE;AACb;AAEO,MAAMQ;IACT,YACYC,YAAoC,EACpCC,EAAuB,EACvBC,gBAAmD,EACnDC,MAA+B,CACzC;aAJUH,YAAY,GAAZA;aACAC,EAAE,GAAFA;aACAC,gBAAgB,GAAhBA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,QAAQC,MAA6B,EAAiB;QACxD,IAAIA,OAAO,OAAO,EAEd;QAGJ,MAAMC,gBAAgB,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO;QACzD,MAAM,CAACC,YAAY,GAAGD,cAAc,gBAAgB,CAACE;QAErD,IAAI,CAACD,aACD;QAGJ,MAAMX,eAAeU,cAChB,gBAAgB,CAACG,QACjB,IAAI,CAACC,CAAAA,MAAOA,IAAI,MAAM,CAAC,OAAO,KAAKnB,8BAA8B,OAAO;QAC7E,MAAMM,YAAYU,YAAY,MAAM,CAAC,SAAS;QAG9C,MAAMI,oBAAoBhB,uBAAuBC,cAAcC;QAG/D,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;QAEb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AAMoB,4BAA4BC,eAAe,oBAAoB,CAAC;IACzE,gBAAgBlB;IAChB,cAAc;QAACmB;QAAcC;QAAWC;QAAyBC;KAAc;AACnF"}
|
|
@@ -6,8 +6,8 @@ import { GetProjectConfigService } from "@webiny/project/abstractions/index.js";
|
|
|
6
6
|
* lives in a different database. Compares the database setup the core was deployed with (its stack
|
|
7
7
|
* output) with the one the project config now asks for. A first deploy has nothing to compare.
|
|
8
8
|
*
|
|
9
|
-
* Rendered by `ProjectAws`, not by `<Infra.
|
|
10
|
-
* is removed from a project that was deployed with it.
|
|
9
|
+
* Rendered by `ProjectAws`, not by `<Infra.AuroraPostgres />`, so it also runs when
|
|
10
|
+
* `<Infra.AuroraPostgres />` is removed from a project that was deployed with it.
|
|
11
11
|
*/
|
|
12
12
|
export declare class EnsurePostgresSetupUnchangedImpl implements CoreBeforeDeploy.Interface {
|
|
13
13
|
private coreStackOutputService;
|
|
@@ -19,7 +19,7 @@ class EnsurePostgresSetupUnchangedImpl {
|
|
|
19
19
|
const isPostgres = configuredSetup === POSTGRES;
|
|
20
20
|
if (wasPostgres === isPostgres) return;
|
|
21
21
|
const error = isPostgres ? new Error(`Cannot deploy with Postgres. The Core application was deployed with the "${deployedSetup}" database setup.`) : new Error(`Cannot deploy without Postgres. The Core application was deployed with the "${POSTGRES}" database setup.`);
|
|
22
|
-
throw GracefulError.from(error, "Once a project is deployed, it can't switch between %s and %s.\n\nYour options:\n• To switch, destroy the project and deploy it again from scratch.\n• To keep the current database, change your %s config file back (%s).", "DynamoDB", "Postgres", "webiny.config.tsx", isPostgres ? "remove <Infra.
|
|
22
|
+
throw GracefulError.from(error, "Once a project is deployed, it can't switch between %s and %s.\n\nYour options:\n• To switch, destroy the project and deploy it again from scratch.\n• To keep the current database, change your %s config file back (%s).", "DynamoDB", "Postgres", "webiny.config.tsx", isPostgres ? "remove <Infra.AuroraPostgres />" : "add <Infra.AuroraPostgres />");
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
const EnsurePostgresSetupUnchanged = CoreBeforeDeploy.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions/ProjectAws/EnsurePostgresSetupUnchanged.js","sources":["../../../src/extensions/ProjectAws/EnsurePostgresSetupUnchanged.ts"],"sourcesContent":["import { CoreBeforeDeploy } from \"@webiny/project-extensions-aws/abstractions/index.js\";\nimport { CoreStackOutputService } from \"@webiny/project-extensions-aws/abstractions/index.js\";\nimport { GetProjectConfigService } from \"@webiny/project/abstractions/index.js\";\nimport { DatabaseSetup } from \"@webiny/project/extensions/index.js\";\nimport { GracefulError } from \"@webiny/project\";\n\nconst POSTGRES = \"pg\";\n\n/**\n * A core deployed with DynamoDB can't move to Postgres in place, nor the other way round: the data\n * lives in a different database. Compares the database setup the core was deployed with (its stack\n * output) with the one the project config now asks for. A first deploy has nothing to compare.\n *\n * Rendered by `ProjectAws`, not by `<Infra.
|
|
1
|
+
{"version":3,"file":"extensions/ProjectAws/EnsurePostgresSetupUnchanged.js","sources":["../../../src/extensions/ProjectAws/EnsurePostgresSetupUnchanged.ts"],"sourcesContent":["import { CoreBeforeDeploy } from \"@webiny/project-extensions-aws/abstractions/index.js\";\nimport { CoreStackOutputService } from \"@webiny/project-extensions-aws/abstractions/index.js\";\nimport { GetProjectConfigService } from \"@webiny/project/abstractions/index.js\";\nimport { DatabaseSetup } from \"@webiny/project/extensions/index.js\";\nimport { GracefulError } from \"@webiny/project\";\n\nconst POSTGRES = \"pg\";\n\n/**\n * A core deployed with DynamoDB can't move to Postgres in place, nor the other way round: the data\n * lives in a different database. Compares the database setup the core was deployed with (its stack\n * output) with the one the project config now asks for. A first deploy has nothing to compare.\n *\n * Rendered by `ProjectAws`, not by `<Infra.AuroraPostgres />`, so it also runs when\n * `<Infra.AuroraPostgres />` is removed from a project that was deployed with it.\n */\nexport class EnsurePostgresSetupUnchangedImpl implements CoreBeforeDeploy.Interface {\n constructor(\n private coreStackOutputService: CoreStackOutputService.Interface,\n private getProjectConfigService: GetProjectConfigService.Interface\n ) {}\n\n async execute() {\n const output = await this.coreStackOutputService.execute();\n const deployedSetup = output?.databaseSetup;\n if (!deployedSetup) {\n return;\n }\n\n const projectConfig = await this.getProjectConfigService.execute();\n const [databaseSetupExtension] = projectConfig.extensionsByType(DatabaseSetup);\n const configuredSetup = databaseSetupExtension?.params.setupName ?? \"ddb\";\n\n const wasPostgres = deployedSetup === POSTGRES;\n const isPostgres = configuredSetup === POSTGRES;\n if (wasPostgres === isPostgres) {\n return;\n }\n\n const error = isPostgres\n ? new Error(\n `Cannot deploy with Postgres. The Core application was deployed with the \"${deployedSetup}\" database setup.`\n )\n : new Error(\n `Cannot deploy without Postgres. The Core application was deployed with the \"${POSTGRES}\" database setup.`\n );\n\n throw GracefulError.from(\n error,\n [\n \"Once a project is deployed, it can't switch between %s and %s.\",\n \"\",\n \"Your options:\",\n \"• To switch, destroy the project and deploy it again from scratch.\",\n \"• To keep the current database, change your %s config file back (%s).\"\n ].join(\"\\n\"),\n \"DynamoDB\",\n \"Postgres\",\n \"webiny.config.tsx\",\n isPostgres ? \"remove <Infra.AuroraPostgres />\" : \"add <Infra.AuroraPostgres />\"\n );\n }\n}\n\nexport const EnsurePostgresSetupUnchanged = CoreBeforeDeploy.createImplementation({\n implementation: EnsurePostgresSetupUnchangedImpl,\n dependencies: [CoreStackOutputService, GetProjectConfigService]\n});\n"],"names":["POSTGRES","EnsurePostgresSetupUnchangedImpl","coreStackOutputService","getProjectConfigService","output","deployedSetup","projectConfig","databaseSetupExtension","DatabaseSetup","configuredSetup","wasPostgres","isPostgres","error","Error","GracefulError","EnsurePostgresSetupUnchanged","CoreBeforeDeploy","CoreStackOutputService","GetProjectConfigService"],"mappings":";;;;AAMA,MAAMA,WAAW;AAUV,MAAMC;IACT,YACYC,sBAAwD,EACxDC,uBAA0D,CACpE;aAFUD,sBAAsB,GAAtBA;aACAC,uBAAuB,GAAvBA;IACT;IAEH,MAAM,UAAU;QACZ,MAAMC,SAAS,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO;QACxD,MAAMC,gBAAgBD,QAAQ;QAC9B,IAAI,CAACC,eACD;QAGJ,MAAMC,gBAAgB,MAAM,IAAI,CAAC,uBAAuB,CAAC,OAAO;QAChE,MAAM,CAACC,uBAAuB,GAAGD,cAAc,gBAAgB,CAACE;QAChE,MAAMC,kBAAkBF,wBAAwB,OAAO,aAAa;QAEpE,MAAMG,cAAcL,kBAAkBL;QACtC,MAAMW,aAAaF,oBAAoBT;QACvC,IAAIU,gBAAgBC,YAChB;QAGJ,MAAMC,QAAQD,aACR,IAAIE,MACA,CAAC,yEAAyE,EAAER,cAAc,iBAAiB,CAAC,IAEhH,IAAIQ,MACA,CAAC,4EAA4E,EAAEb,SAAS,iBAAiB,CAAC;QAGpH,MAAMc,cAAc,IAAI,CACpBF,OACA,8NAOA,YACA,YACA,qBACAD,aAAa,oCAAoC;IAEzD;AACJ;AAEO,MAAMI,+BAA+BC,iBAAiB,oBAAoB,CAAC;IAC9E,gBAAgBf;IAChB,cAAc;QAACgB;QAAwBC;KAAwB;AACnE"}
|
|
@@ -3,9 +3,9 @@ import { GetProjectConfigService } from "@webiny/project/abstractions/index.js";
|
|
|
3
3
|
import { ProjectSdkParamsService } from "@webiny/project/abstractions/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Watching the API on AWS replaces the deployed functions with forwarders and runs every request
|
|
6
|
-
* on the developer's machine, with the deployed function's env. With `<Infra.
|
|
7
|
-
* points at Aurora in the VPC's private subnets, which the machine can't reach, so every
|
|
8
|
-
* would time out. Watch is refused before anything is built or replaced.
|
|
6
|
+
* on the developer's machine, with the deployed function's env. With `<Infra.AuroraPostgres />`
|
|
7
|
+
* that env points at Aurora in the VPC's private subnets, which the machine can't reach, so every
|
|
8
|
+
* request would time out. Watch is refused before anything is built or replaced.
|
|
9
9
|
*
|
|
10
10
|
* Unconditional: `--no-deployment-checks` doesn't skip it, because watch can't work at all.
|
|
11
11
|
*/
|
|
@@ -12,7 +12,7 @@ class RefuseApiWatchWithPostgresImpl {
|
|
|
12
12
|
const error = new Error("Cannot watch the API of a project that uses Postgres on AWS.");
|
|
13
13
|
const sdkParams = this.projectSdkParamsService.get();
|
|
14
14
|
const cmd = `yarn webiny deploy api --env ${sdkParams.env}`;
|
|
15
|
-
throw GracefulError.from(error, "Watch isn't supported with %s on AWS: the database is in the VPC's private subnets, which your machine can't reach. To try your changes, deploy them instead by running: %s.", "<Infra.
|
|
15
|
+
throw GracefulError.from(error, "Watch isn't supported with %s on AWS: the database is in the VPC's private subnets, which your machine can't reach. To try your changes, deploy them instead by running: %s.", "<Infra.AuroraPostgres />", cmd);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
const RefuseApiWatchWithPostgres = ApiBeforeWatch.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions/ProjectAws/RefuseApiWatchWithPostgres.js","sources":["../../../src/extensions/ProjectAws/RefuseApiWatchWithPostgres.ts"],"sourcesContent":["import { ApiBeforeWatch } from \"@webiny/project/abstractions/index.js\";\nimport { GetProjectConfigService } from \"@webiny/project/abstractions/index.js\";\nimport { ProjectSdkParamsService } from \"@webiny/project/abstractions/index.js\";\nimport { GracefulError } from \"@webiny/project\";\nimport { getPostgresConfigFromExtension } from \"~/pulumi/apps/extensions/getPostgresConfigFromExtension.js\";\n\n/**\n * Watching the API on AWS replaces the deployed functions with forwarders and runs every request\n * on the developer's machine, with the deployed function's env. With `<Infra.
|
|
1
|
+
{"version":3,"file":"extensions/ProjectAws/RefuseApiWatchWithPostgres.js","sources":["../../../src/extensions/ProjectAws/RefuseApiWatchWithPostgres.ts"],"sourcesContent":["import { ApiBeforeWatch } from \"@webiny/project/abstractions/index.js\";\nimport { GetProjectConfigService } from \"@webiny/project/abstractions/index.js\";\nimport { ProjectSdkParamsService } from \"@webiny/project/abstractions/index.js\";\nimport { GracefulError } from \"@webiny/project\";\nimport { getPostgresConfigFromExtension } from \"~/pulumi/apps/extensions/getPostgresConfigFromExtension.js\";\n\n/**\n * Watching the API on AWS replaces the deployed functions with forwarders and runs every request\n * on the developer's machine, with the deployed function's env. With `<Infra.AuroraPostgres />`\n * that env points at Aurora in the VPC's private subnets, which the machine can't reach, so every\n * request would time out. Watch is refused before anything is built or replaced.\n *\n * Unconditional: `--no-deployment-checks` doesn't skip it, because watch can't work at all.\n */\nexport class RefuseApiWatchWithPostgresImpl implements ApiBeforeWatch.Interface {\n constructor(\n private getProjectConfigService: GetProjectConfigService.Interface,\n private projectSdkParamsService: ProjectSdkParamsService.Interface\n ) {}\n\n async execute() {\n const projectConfig = await this.getProjectConfigService.execute();\n if (!getPostgresConfigFromExtension(projectConfig)) {\n return;\n }\n\n const error = new Error(`Cannot watch the API of a project that uses Postgres on AWS.`);\n const sdkParams = this.projectSdkParamsService.get();\n const cmd = `yarn webiny deploy api --env ${sdkParams.env}`;\n\n throw GracefulError.from(\n error,\n [\n \"Watch isn't supported with %s on AWS: the database is in the VPC's private\",\n \"subnets, which your machine can't reach. To try your changes, deploy them\",\n \"instead by running: %s.\"\n ].join(\" \"),\n \"<Infra.AuroraPostgres />\",\n cmd\n );\n }\n}\n\nexport const RefuseApiWatchWithPostgres = ApiBeforeWatch.createImplementation({\n implementation: RefuseApiWatchWithPostgresImpl,\n dependencies: [GetProjectConfigService, ProjectSdkParamsService]\n});\n"],"names":["RefuseApiWatchWithPostgresImpl","getProjectConfigService","projectSdkParamsService","projectConfig","getPostgresConfigFromExtension","error","Error","sdkParams","cmd","GracefulError","RefuseApiWatchWithPostgres","ApiBeforeWatch","GetProjectConfigService","ProjectSdkParamsService"],"mappings":";;;AAcO,MAAMA;IACT,YACYC,uBAA0D,EAC1DC,uBAA0D,CACpE;aAFUD,uBAAuB,GAAvBA;aACAC,uBAAuB,GAAvBA;IACT;IAEH,MAAM,UAAU;QACZ,MAAMC,gBAAgB,MAAM,IAAI,CAAC,uBAAuB,CAAC,OAAO;QAChE,IAAI,CAACC,+BAA+BD,gBAChC;QAGJ,MAAME,QAAQ,IAAIC,MAAM;QACxB,MAAMC,YAAY,IAAI,CAAC,uBAAuB,CAAC,GAAG;QAClD,MAAMC,MAAM,CAAC,6BAA6B,EAAED,UAAU,GAAG,EAAE;QAE3D,MAAME,cAAc,IAAI,CACpBJ,OACA,gLAKA,4BACAG;IAER;AACJ;AAEO,MAAME,6BAA6BC,eAAe,oBAAoB,CAAC;IAC1E,gBAAgBX;IAChB,cAAc;QAACY;QAAyBC;KAAwB;AACpE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
2
|
+
import { GetProjectConfigService } from "@webiny/project/abstractions/index.js";
|
|
3
|
+
import { type IProjectConfigModel } from "@webiny/project/abstractions/models/index.js";
|
|
4
|
+
import { CorePulumi } from "@webiny/project-extensions-aws/abstractions/features/pulumi/index.js";
|
|
5
|
+
import type { CorePulumiApp } from "../../../pulumi/apps/core/createCorePulumiApp.js";
|
|
6
|
+
/** The prefix of a storage's resource names. Part of their Pulumi names: it never changes. */
|
|
7
|
+
export declare const tenantStorageNamePrefix: (id: string) => string;
|
|
8
|
+
export interface AddTenantStorageClustersOptions {
|
|
9
|
+
getEngineVersion?: () => pulumi.Input<string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Adds a cluster to the core app for every `<Infra.TenantStorage.AuroraPostgres>`, retired ones
|
|
13
|
+
* included (a retired storage keeps its database), and writes the `storages` output: each storage's
|
|
14
|
+
* id, label and `retired`, and its cluster's connection outputs. Without declarations it writes an
|
|
15
|
+
* empty list.
|
|
16
|
+
*
|
|
17
|
+
* Each cluster is `CorePostgres` with the resource names prefixed by the storage's id, in the same
|
|
18
|
+
* network as `<Infra.AuroraPostgres />` would use, and with the same production protections: Pulumi
|
|
19
|
+
* `protect`, deletion protection, 35 days of backups that outlive the cluster with a final snapshot,
|
|
20
|
+
* and the secret's 7-day recovery window.
|
|
21
|
+
*/
|
|
22
|
+
export declare const addTenantStorageClusters: (app: CorePulumiApp, projectConfig: IProjectConfigModel, options?: AddTenantStorageClustersOptions) => void;
|
|
23
|
+
/**
|
|
24
|
+
* The core app's tenant storages (`addTenantStorageClusters`). Rendered by `ProjectAws`, so the
|
|
25
|
+
* `storages` output is written on every deploy, declarations or not.
|
|
26
|
+
*/
|
|
27
|
+
export declare class AddTenantStoragesImpl implements CorePulumi.Interface {
|
|
28
|
+
private getProjectConfigService;
|
|
29
|
+
constructor(getProjectConfigService: GetProjectConfigService.Interface);
|
|
30
|
+
execute(app: CorePulumiApp): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare const AddTenantStorages: typeof AddTenantStoragesImpl & {
|
|
33
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/project-extensions-aws/abstractions").ICorePulumi>;
|
|
34
|
+
};
|