@pattform/api-kit 2.3.0 → 2.5.0

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.
@@ -1,4 +1,5 @@
1
1
  import * as pulumi from "@pulumi/pulumi";
2
+ import * as aws from "@pulumi/aws";
2
3
  export declare class AppComponent extends pulumi.ComponentResource {
3
4
  readonly requiredDnsRecords: pulumi.Output<DnsRecordInstruction[]>;
4
5
  private readonly amplifyApp;
@@ -15,6 +16,11 @@ export interface AppComponentArgs {
15
16
  buildSpec?: string;
16
17
  roleArn?: pulumi.Input<string>;
17
18
  manageDns?: boolean;
19
+ customRules?: aws.types.input.amplify.AppCustomRule[];
20
+ environmentVariables?: {
21
+ [key: string]: pulumi.Input<string>;
22
+ };
23
+ manageValidationRecord?: boolean;
18
24
  }
19
25
  export interface DnsRecordInstruction {
20
26
  name: string;
@@ -7,7 +7,7 @@ const cloudflare = require("@pulumi/cloudflare");
7
7
  const pattformHelper_1 = require("./pattformHelper");
8
8
  class AppComponent extends pulumi.ComponentResource {
9
9
  constructor(name, args, opts) {
10
- var _a, _b;
10
+ var _a, _b, _c, _d;
11
11
  super("custom:pattform:AppComponent", name, args, opts);
12
12
  const awsConfig = new pulumi.Config("aws");
13
13
  const awsRegion = awsConfig.require("region");
@@ -78,7 +78,17 @@ class AppComponent extends pulumi.ComponentResource {
78
78
  }
79
79
  const subDomains = getSubDomains();
80
80
  const isWWW = subDomains.find((subDomain) => subDomain.prefix === "www");
81
- this.amplifyApp = new aws.amplify.App(`${appName}-amplifyApp-${env}`, Object.assign(Object.assign({ name: appName, repository: args.repoUrl, accessToken: githubToken, autoBranchCreationConfig: {
81
+ // Redirect the apex to www (for www sites) plus any caller-supplied
82
+ // rules, e.g. the SPA fallback for single-page apps.
83
+ const customRules = [
84
+ ...(isWWW ? [{
85
+ source: "https://" + args.domain,
86
+ target: "https://www." + args.domain,
87
+ status: "302",
88
+ }] : []),
89
+ ...((_c = args.customRules) !== null && _c !== void 0 ? _c : []),
90
+ ];
91
+ this.amplifyApp = new aws.amplify.App(`${appName}-amplifyApp-${env}`, Object.assign(Object.assign(Object.assign({ name: appName, repository: args.repoUrl, accessToken: githubToken, autoBranchCreationConfig: {
82
92
  enableAutoBuild: true,
83
93
  enableBasicAuth: false,
84
94
  enablePerformanceMode: false,
@@ -88,15 +98,7 @@ class AppComponent extends pulumi.ComponentResource {
88
98
  "feature/*",
89
99
  "bugfix/*",
90
100
  "hotfix/*",
91
- ], enableBranchAutoDeletion: true, enableBranchAutoBuild: true, enableAutoBranchCreation: true }, isWWW && {
92
- customRules: [
93
- {
94
- source: "https://" + args.domain,
95
- target: "https://www." + args.domain,
96
- status: "302",
97
- }
98
- ]
99
- }), { buildSpec: args.buildSpec || `
101
+ ], enableBranchAutoDeletion: true, enableBranchAutoBuild: true, enableAutoBranchCreation: true }, (customRules.length > 0 ? { customRules } : {})), (args.environmentVariables ? { environmentVariables: args.environmentVariables } : {})), { buildSpec: args.buildSpec || `
100
102
  version: 1.0
101
103
  frontend:
102
104
  phases:
@@ -147,15 +149,22 @@ class AppComponent extends pulumi.ComponentResource {
147
149
  }, {
148
150
  provider: cloudFlareProvider,
149
151
  });
150
- this.validationRecord = new cloudflare.Record(`${appName}-cloudflareValidateRecord-${env}`, {
151
- zoneId: cloudflareZone.id,
152
- name: this.domainAssociation.certificateVerificationDnsRecord.apply(record => record.split(' ')[0]),
153
- type: "CNAME",
154
- proxied: false,
155
- content: this.domainAssociation.certificateVerificationDnsRecord.apply(record => record.split(' ')[2]),
156
- }, {
157
- provider: cloudFlareProvider,
158
- });
152
+ // ACM validates domain ownership with one deterministic CNAME per
153
+ // apex, shared across every cert for that domain. When another
154
+ // stack already manages the apex (e.g. the apex/www site while this
155
+ // is a subdomain app), set manageValidationRecord: false to reuse it
156
+ // instead of colliding on an identical record.
157
+ if ((_d = args.manageValidationRecord) !== null && _d !== void 0 ? _d : true) {
158
+ this.validationRecord = new cloudflare.Record(`${appName}-cloudflareValidateRecord-${env}`, {
159
+ zoneId: cloudflareZone.id,
160
+ name: this.domainAssociation.certificateVerificationDnsRecord.apply(record => record.split(' ')[0]),
161
+ type: "CNAME",
162
+ proxied: false,
163
+ content: this.domainAssociation.certificateVerificationDnsRecord.apply(record => record.split(' ')[2]),
164
+ }, {
165
+ provider: cloudFlareProvider,
166
+ });
167
+ }
159
168
  this.subDomainRecords = this.domainAssociation.subDomains.apply(subDomains => {
160
169
  return subDomains.map((subDomain) => {
161
170
  const subDomainName = subDomain.dnsRecord.split(' ')[0];
@@ -0,0 +1,27 @@
1
+ import * as pulumi from "@pulumi/pulumi";
2
+ /**
3
+ * GcpProjectComponent
4
+ * GCP counterpart to ClientAccountComponent: vends a project under a folder,
5
+ * links billing, enables the APIs a backend needs, and creates a per-project
6
+ * deploy service account that Pulumi ESC impersonates via Workload Identity
7
+ * Federation. One of these per client (or internal product) that runs on GCP.
8
+ */
9
+ export declare class GcpProjectComponent extends pulumi.ComponentResource {
10
+ readonly projectId: pulumi.Output<string>;
11
+ readonly projectNumber: pulumi.Output<string>;
12
+ readonly deployServiceAccountEmail: pulumi.Output<string>;
13
+ private readonly project;
14
+ constructor(name: string, args: GcpProjectComponentArgs, opts?: pulumi.ComponentResourceOptions);
15
+ }
16
+ export interface GcpProjectComponentArgs {
17
+ projectId: string;
18
+ folderId?: pulumi.Input<string>;
19
+ orgId?: pulumi.Input<string>;
20
+ billingAccount: pulumi.Input<string>;
21
+ displayName?: string;
22
+ services?: string[];
23
+ deployServiceAccountId?: string;
24
+ deployRoles?: string[];
25
+ workloadIdentityMembers?: pulumi.Input<string>[];
26
+ importProjectId?: string;
27
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GcpProjectComponent = void 0;
4
+ const pulumi = require("@pulumi/pulumi");
5
+ const gcp = require("@pulumi/gcp");
6
+ /**
7
+ * GcpProjectComponent
8
+ * GCP counterpart to ClientAccountComponent: vends a project under a folder,
9
+ * links billing, enables the APIs a backend needs, and creates a per-project
10
+ * deploy service account that Pulumi ESC impersonates via Workload Identity
11
+ * Federation. One of these per client (or internal product) that runs on GCP.
12
+ */
13
+ class GcpProjectComponent extends pulumi.ComponentResource {
14
+ constructor(name, args, opts) {
15
+ var _a, _b, _c, _d, _e;
16
+ super("custom:pattform:GcpProjectComponent", name, args, opts);
17
+ // Set importProjectId to adopt an existing project (e.g. a product that
18
+ // predates this vending) instead of creating a new one.
19
+ this.project = new gcp.organizations.Project(`${name}-project`, Object.assign(Object.assign(Object.assign({ projectId: args.projectId, name: (_a = args.displayName) !== null && _a !== void 0 ? _a : args.projectId }, (args.folderId ? { folderId: args.folderId } : {})), (args.orgId ? { orgId: args.orgId } : {})), { billingAccount: args.billingAccount, deletionPolicy: "PREVENT" }), Object.assign({ parent: this, protect: true }, (args.importProjectId ? { import: args.importProjectId } : {})));
20
+ const services = (_b = args.services) !== null && _b !== void 0 ? _b : DEFAULT_SERVICES;
21
+ const serviceResources = services.map(service => new gcp.projects.Service(`${name}-svc-${service}`, {
22
+ project: this.project.projectId,
23
+ service: service,
24
+ disableOnDestroy: false,
25
+ }, { parent: this.project }));
26
+ // The identity the client's service stacks impersonate to deploy into
27
+ // this project. Distinct from any runtime service account.
28
+ const deploySa = new gcp.serviceaccount.Account(`${name}-deploy-sa`, {
29
+ project: this.project.projectId,
30
+ accountId: (_c = args.deployServiceAccountId) !== null && _c !== void 0 ? _c : "deploy",
31
+ displayName: `${args.projectId} deploy (Pulumi ESC)`,
32
+ }, { parent: this.project, dependsOn: serviceResources });
33
+ const deployRoles = (_d = args.deployRoles) !== null && _d !== void 0 ? _d : DEFAULT_DEPLOY_ROLES;
34
+ for (const role of deployRoles) {
35
+ new gcp.projects.IAMMember(`${name}-deploy-${role}`, {
36
+ project: this.project.projectId,
37
+ role: role,
38
+ member: pulumi.interpolate `serviceAccount:${deploySa.email}`,
39
+ }, { parent: deploySa });
40
+ }
41
+ // Grant the ESC env subjects that may impersonate the deploy SA. Members
42
+ // are WIF principals, e.g.
43
+ // principal://iam.googleapis.com/<pool>/subject/pulumi:environments:org:Pattform:env:<Project>/<env>
44
+ ((_e = args.workloadIdentityMembers) !== null && _e !== void 0 ? _e : []).forEach((member, i) => {
45
+ new gcp.serviceaccount.IAMMember(`${name}-deploy-wif-${i}`, {
46
+ serviceAccountId: deploySa.name,
47
+ role: "roles/iam.workloadIdentityUser",
48
+ member: member,
49
+ }, { parent: deploySa });
50
+ });
51
+ this.projectId = this.project.projectId;
52
+ this.projectNumber = this.project.number;
53
+ this.deployServiceAccountEmail = deploySa.email;
54
+ this.registerOutputs({
55
+ projectId: this.projectId,
56
+ projectNumber: this.projectNumber,
57
+ deployServiceAccountEmail: this.deployServiceAccountEmail,
58
+ });
59
+ }
60
+ }
61
+ exports.GcpProjectComponent = GcpProjectComponent;
62
+ // Backend defaults: Cloud Run + Firestore + Storage + Artifact Registry.
63
+ const DEFAULT_SERVICES = [
64
+ "run.googleapis.com",
65
+ "firestore.googleapis.com",
66
+ "artifactregistry.googleapis.com",
67
+ "storage.googleapis.com",
68
+ "iam.googleapis.com",
69
+ "iamcredentials.googleapis.com",
70
+ ];
71
+ // Project roles the deploy SA needs to create those resources from Pulumi.
72
+ const DEFAULT_DEPLOY_ROLES = [
73
+ "roles/run.admin",
74
+ "roles/datastore.owner",
75
+ "roles/storage.admin",
76
+ "roles/artifactregistry.admin",
77
+ "roles/iam.serviceAccountUser",
78
+ ];
package/dist/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export { ContainerComponent, ContainerComponentArgs } from "./ContainerComponent
2
2
  export { ApiComponent, ApiComponentArgs } from "./ApiComponent";
3
3
  export { AppComponent, AppComponentArgs, DnsRecordInstruction } from "./AppComponent";
4
4
  export { ClientAccountComponent, ClientAccountComponentArgs } from "./ClientAccountComponent";
5
+ export { GcpProjectComponent, GcpProjectComponentArgs } from "./GcpProjectComponent";
5
6
  export { FormComponent, FormComponentArgs, FormFieldSpec, FormDestination } from "./FormComponent";
6
7
  export { getClientRoleArn } from "./pattformHelper";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getClientRoleArn = exports.FormComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
3
+ exports.getClientRoleArn = exports.FormComponent = exports.GcpProjectComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
4
4
  var ContainerComponent_1 = require("./ContainerComponent");
5
5
  Object.defineProperty(exports, "ContainerComponent", { enumerable: true, get: function () { return ContainerComponent_1.ContainerComponent; } });
6
6
  var ApiComponent_1 = require("./ApiComponent");
@@ -9,6 +9,8 @@ var AppComponent_1 = require("./AppComponent");
9
9
  Object.defineProperty(exports, "AppComponent", { enumerable: true, get: function () { return AppComponent_1.AppComponent; } });
10
10
  var ClientAccountComponent_1 = require("./ClientAccountComponent");
11
11
  Object.defineProperty(exports, "ClientAccountComponent", { enumerable: true, get: function () { return ClientAccountComponent_1.ClientAccountComponent; } });
12
+ var GcpProjectComponent_1 = require("./GcpProjectComponent");
13
+ Object.defineProperty(exports, "GcpProjectComponent", { enumerable: true, get: function () { return GcpProjectComponent_1.GcpProjectComponent; } });
12
14
  var FormComponent_1 = require("./FormComponent");
13
15
  Object.defineProperty(exports, "FormComponent", { enumerable: true, get: function () { return FormComponent_1.FormComponent; } });
14
16
  var pattformHelper_1 = require("./pattformHelper");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pattform/api-kit",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "description": "Pulumi infra library for building and deploying an API",
5
5
  "author": "Pattform <contact@pattform.io>",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -29,10 +29,10 @@
29
29
  "@types/node": "^16"
30
30
  },
31
31
  "dependencies": {
32
- "@pulumi/aws": "^6.53.0",
32
+ "@pulumi/aws": "^6.83.4",
33
+ "@pulumi/cloudflare": "^5.39.1",
33
34
  "@pulumi/gcp": "^8.41.1",
34
35
  "@pulumi/pulumi": "^3.0.0",
35
- "@pulumi/cloudflare": "^5.39.1",
36
36
  "typescript": "^5.1.6"
37
37
  }
38
38
  }