@pattform/api-kit 2.1.1 → 2.2.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.
package/README.md CHANGED
@@ -98,6 +98,21 @@ const app = new AppComponent("app", {
98
98
  });
99
99
  ```
100
100
 
101
+ ### getClientRoleArn
102
+ Client website stacks (in separate repos) look up their deploy role by client name instead of referencing the account component directly:
103
+
104
+ ```typescript
105
+ import { AppComponent, getClientRoleArn } from '@pattform/api-kit';
106
+
107
+ const app = new AppComponent("app", {
108
+ domain: domain,
109
+ repoUrl: repoUrl,
110
+ roleArn: getClientRoleArn("kaloblock"), // name from the pattform-infrastructure clients registry
111
+ });
112
+ ```
113
+
114
+ Fails with the list of known clients if the name isn't in the registry. An optional second argument overrides the infrastructure stack (defaults to `Pattform/pattform-infrastructure/prod`).
115
+
101
116
  Notes:
102
117
  * The account resource is `protect: true` and `closeOnDeletion: false` - a `pulumi destroy` will not close a client's AWS account.
103
118
  * AWS limits account closures to 10% of the org per 30 days; closed accounts stay suspended for 90 days.
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ 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 { 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.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
3
+ exports.getClientRoleArn = 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,3 +9,5 @@ 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 pattformHelper_1 = require("./pattformHelper");
13
+ Object.defineProperty(exports, "getClientRoleArn", { enumerable: true, get: function () { return pattformHelper_1.getClientRoleArn; } });
@@ -1 +1,3 @@
1
+ import * as pulumi from "@pulumi/pulumi";
2
+ export declare function getClientRoleArn(client: string, infrastructureStack?: string): pulumi.Output<string>;
1
3
  export declare function verifyRegion(awsRegion: string): any;
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyRegion = void 0;
3
+ exports.verifyRegion = exports.getClientRoleArn = void 0;
4
+ const pulumi = require("@pulumi/pulumi");
4
5
  const aws = require("@pulumi/aws");
6
+ const DEFAULT_INFRASTRUCTURE_STACK = "Pattform/pattform-infrastructure/prod";
7
+ // StackReferences are resources, so creating the same one twice in a program
8
+ // would collide on its URN; memoise per stack name.
9
+ const stackReferences = {};
10
+ // Looks up a client's deploy role from the pattform-infrastructure stack.
11
+ // Pass the result straight to AppComponent's roleArn:
12
+ // roleArn: getClientRoleArn("kaloblock")
13
+ function getClientRoleArn(client, infrastructureStack = DEFAULT_INFRASTRUCTURE_STACK) {
14
+ if (!stackReferences[infrastructureStack]) {
15
+ stackReferences[infrastructureStack] = new pulumi.StackReference(infrastructureStack);
16
+ }
17
+ return stackReferences[infrastructureStack].requireOutput("clientDeployRoleArns").apply(roles => {
18
+ const arn = roles[client];
19
+ if (!arn) {
20
+ const known = Object.keys(roles).join(", ") || "<none>";
21
+ throw new Error(`Client "${client}" has no deploy role in ${infrastructureStack} (known clients: ${known}). ` +
22
+ `Add it to the clients registry in pattform-infrastructure and deploy that stack first.`);
23
+ }
24
+ return arn;
25
+ });
26
+ }
27
+ exports.getClientRoleArn = getClientRoleArn;
5
28
  function verifyRegion(awsRegion) {
6
29
  for (const [key, value] of Object.entries(aws.Region)) {
7
30
  if (value == awsRegion) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pattform/api-kit",
3
- "version": "2.1.1",
3
+ "version": "2.2.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",