@openhi/constructs 0.0.0 → 0.0.2
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/lib/chunk-LZOMFHX3.mjs +38 -0
- package/lib/chunk-LZOMFHX3.mjs.map +1 -0
- package/lib/index.d.mts +788 -0
- package/lib/index.d.ts +869 -3
- package/lib/index.js +1318 -19
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +1303 -0
- package/lib/index.mjs.map +1 -0
- package/lib/rest-api-lambda.handler.d.mts +6 -0
- package/lib/rest-api-lambda.handler.d.ts +6 -0
- package/lib/rest-api-lambda.handler.js +677 -0
- package/lib/rest-api-lambda.handler.js.map +1 -0
- package/lib/rest-api-lambda.handler.mjs +646 -0
- package/lib/rest-api-lambda.handler.mjs.map +1 -0
- package/package.json +37 -28
- package/lib/app/index.d.ts +0 -4
- package/lib/app/index.js +0 -21
- package/lib/app/open-hi-app.d.ts +0 -85
- package/lib/app/open-hi-app.js +0 -127
- package/lib/app/open-hi-environment.d.ts +0 -59
- package/lib/app/open-hi-environment.js +0 -72
- package/lib/app/open-hi-service.d.ts +0 -169
- package/lib/app/open-hi-service.js +0 -195
- package/lib/app/open-hi-stage.d.ts +0 -71
- package/lib/app/open-hi-stage.js +0 -70
- package/lib/components/acm/root-wildcard-certificate.d.ts +0 -15
- package/lib/components/acm/root-wildcard-certificate.js +0 -35
- package/lib/components/api-gateway/core-http-api.d.ts +0 -10
- package/lib/components/api-gateway/core-http-api.js +0 -44
- package/lib/components/api-gateway/http-lambda-integration-no-permissions.d.ts +0 -18
- package/lib/components/api-gateway/http-lambda-integration-no-permissions.js +0 -26
- package/lib/components/app-sync/core-graphql-api.d.ts +0 -12
- package/lib/components/app-sync/core-graphql-api.js +0 -54
- package/lib/components/auth.d.ts +0 -75
- package/lib/components/auth.js +0 -100
- package/lib/components/cognito/core-user-pool-client.d.ts +0 -10
- package/lib/components/cognito/core-user-pool-client.js +0 -47
- package/lib/components/cognito/core-user-pool-domain.d.ts +0 -10
- package/lib/components/cognito/core-user-pool-domain.js +0 -41
- package/lib/components/cognito/core-user-pool-kms-key.d.ts +0 -10
- package/lib/components/cognito/core-user-pool-kms-key.js +0 -37
- package/lib/components/cognito/core-user-pool.d.ts +0 -10
- package/lib/components/cognito/core-user-pool.js +0 -54
- package/lib/components/core.d.ts +0 -102
- package/lib/components/core.js +0 -79
- package/lib/components/dynamodb/dynamo-db-data-store.d.ts +0 -33
- package/lib/components/dynamodb/dynamo-db-data-store.js +0 -107
- package/lib/components/event-bridge/data-event-bus.d.ts +0 -19
- package/lib/components/event-bridge/data-event-bus.js +0 -34
- package/lib/components/event-bridge/ops-event-bus.d.ts +0 -19
- package/lib/components/event-bridge/ops-event-bus.js +0 -34
- package/lib/components/global.d.ts +0 -36
- package/lib/components/global.js +0 -63
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -18
- package/lib/components/route-53/child-hosted-zone.d.ts +0 -20
- package/lib/components/route-53/child-hosted-zone.js +0 -48
- package/lib/components/route-53/root-hosted-zone.d.ts +0 -10
- package/lib/components/route-53/root-hosted-zone.js +0 -20
- package/lib/components/ssm/discoverable-string-parameter.d.ts +0 -59
- package/lib/components/ssm/discoverable-string-parameter.js +0 -50
- package/lib/components/ssm/index.d.ts +0 -1
- package/lib/components/ssm/index.js +0 -18
- package/lib/data/dynamo/ehr/r4/Patient.d.ts +0 -180
- package/lib/data/dynamo/ehr/r4/Patient.js +0 -192
- package/lib/data/dynamo/ehr/r4/ehr-r4-data-service.d.ts +0 -162
- package/lib/data/dynamo/ehr/r4/ehr-r4-data-service.js +0 -37
- package/lib/data/hello-world.d.ts +0 -39
- package/lib/data/hello-world.js +0 -59
- package/lib/data/import-patient-with-dynalite.d.ts +0 -1
- package/lib/data/import-patient-with-dynalite.js +0 -87
- package/lib/data/import-patient.d.ts +0 -47
- package/lib/data/import-patient.js +0 -158
- package/lib/data/lambda/rest-api-lambda.d.ts +0 -13
- package/lib/data/lambda/rest-api-lambda.handler.d.ts +0 -1
- package/lib/data/lambda/rest-api-lambda.handler.js +0 -10
- package/lib/data/lambda/rest-api-lambda.js +0 -22
- package/lib/data/middleware/open-hi-context.d.ts +0 -13
- package/lib/data/middleware/open-hi-context.js +0 -31
- package/lib/data/rest-api/ehr/r4/Patient.d.ts +0 -16
- package/lib/data/rest-api/ehr/r4/Patient.js +0 -234
- package/lib/data/rest-api/rest-api-local.d.ts +0 -1
- package/lib/data/rest-api/rest-api-local.js +0 -8
- package/lib/data/rest-api/rest-api-mockdata.d.ts +0 -7
- package/lib/data/rest-api/rest-api-mockdata.js +0 -585
- package/lib/data/rest-api/rest-api.d.ts +0 -3
- package/lib/data/rest-api/rest-api.js +0 -26
- package/lib/lib/compression.d.ts +0 -27
- package/lib/lib/compression.js +0 -87
- package/lib/services/index.d.ts +0 -5
- package/lib/services/index.js +0 -22
- package/lib/services/open-hi-auth-service.d.ts +0 -31
- package/lib/services/open-hi-auth-service.js +0 -31
- package/lib/services/open-hi-core-service.d.ts +0 -15
- package/lib/services/open-hi-core-service.js +0 -38
- package/lib/services/open-hi-data-service.d.ts +0 -18
- package/lib/services/open-hi-data-service.js +0 -18
- package/lib/services/open-hi-global-service.d.ts +0 -15
- package/lib/services/open-hi-global-service.js +0 -44
- package/lib/services/open-hi-rest-api-service.d.ts +0 -17
- package/lib/services/open-hi-rest-api-service.js +0 -107
package/lib/index.js
CHANGED
|
@@ -1,20 +1,1319 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// ../config/lib/open-hi-config.js
|
|
34
|
+
var require_open_hi_config = __commonJS({
|
|
35
|
+
"../config/lib/open-hi-config.js"(exports2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
38
|
+
exports2.OPEN_HI_DEPLOYMENT_TARGET_ROLE = exports2.OPEN_HI_STAGE = void 0;
|
|
39
|
+
exports2.OPEN_HI_STAGE = {
|
|
40
|
+
/**
|
|
41
|
+
* Development environment, typically used for testing and development.
|
|
42
|
+
*/
|
|
43
|
+
DEV: "dev",
|
|
44
|
+
/**
|
|
45
|
+
* Staging environment, used for pre-production testing.
|
|
46
|
+
*/
|
|
47
|
+
STAGE: "stage",
|
|
48
|
+
/**
|
|
49
|
+
* Production environment, used for live deployments.
|
|
50
|
+
*/
|
|
51
|
+
PROD: "prod"
|
|
52
|
+
};
|
|
53
|
+
exports2.OPEN_HI_DEPLOYMENT_TARGET_ROLE = {
|
|
54
|
+
/**
|
|
55
|
+
* The primary deployment target for this stage (main account/region).
|
|
56
|
+
* For example, the base DynamoDB region for global tables.
|
|
57
|
+
*/
|
|
58
|
+
PRIMARY: "primary",
|
|
59
|
+
/**
|
|
60
|
+
* A secondary deployment target for this stage (additional account/region).
|
|
61
|
+
* For example, a replica region for a global DynamoDB table, or another cell in the same region.
|
|
62
|
+
*/
|
|
63
|
+
SECONDARY: "secondary"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// ../config/lib/index.js
|
|
69
|
+
var require_lib = __commonJS({
|
|
70
|
+
"../config/lib/index.js"(exports2) {
|
|
71
|
+
"use strict";
|
|
72
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
73
|
+
if (k2 === void 0) k2 = k;
|
|
74
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
75
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
76
|
+
desc = { enumerable: true, get: function() {
|
|
77
|
+
return m[k];
|
|
78
|
+
} };
|
|
79
|
+
}
|
|
80
|
+
Object.defineProperty(o, k2, desc);
|
|
81
|
+
}) : (function(o, m, k, k2) {
|
|
82
|
+
if (k2 === void 0) k2 = k;
|
|
83
|
+
o[k2] = m[k];
|
|
84
|
+
}));
|
|
85
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
86
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
87
|
+
};
|
|
88
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
89
|
+
__exportStar(require_open_hi_config(), exports2);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// src/index.ts
|
|
94
|
+
var src_exports = {};
|
|
95
|
+
__export(src_exports, {
|
|
96
|
+
ChildHostedZone: () => ChildHostedZone,
|
|
97
|
+
CognitoUserPool: () => CognitoUserPool,
|
|
98
|
+
CognitoUserPoolClient: () => CognitoUserPoolClient,
|
|
99
|
+
CognitoUserPoolDomain: () => CognitoUserPoolDomain,
|
|
100
|
+
CognitoUserPoolKmsKey: () => CognitoUserPoolKmsKey,
|
|
101
|
+
DataEventBus: () => DataEventBus,
|
|
102
|
+
DiscoverableStringParameter: () => DiscoverableStringParameter,
|
|
103
|
+
DynamoDbDataStore: () => DynamoDbDataStore,
|
|
104
|
+
OpenHiApp: () => OpenHiApp,
|
|
105
|
+
OpenHiAuthService: () => OpenHiAuthService,
|
|
106
|
+
OpenHiDataService: () => OpenHiDataService,
|
|
107
|
+
OpenHiEnvironment: () => OpenHiEnvironment,
|
|
108
|
+
OpenHiGlobalService: () => OpenHiGlobalService,
|
|
109
|
+
OpenHiRestApiService: () => OpenHiRestApiService,
|
|
110
|
+
OpenHiService: () => OpenHiService,
|
|
111
|
+
OpenHiStage: () => OpenHiStage,
|
|
112
|
+
OpsEventBus: () => OpsEventBus,
|
|
113
|
+
REST_API_BASE_URL_SSM_NAME: () => REST_API_BASE_URL_SSM_NAME,
|
|
114
|
+
RootGraphqlApi: () => RootGraphqlApi,
|
|
115
|
+
RootHostedZone: () => RootHostedZone,
|
|
116
|
+
RootHttpApi: () => RootHttpApi,
|
|
117
|
+
RootWildcardCertificate: () => RootWildcardCertificate,
|
|
118
|
+
getDynamoDbDataStoreTableName: () => getDynamoDbDataStoreTableName
|
|
119
|
+
});
|
|
120
|
+
module.exports = __toCommonJS(src_exports);
|
|
121
|
+
|
|
122
|
+
// src/app/open-hi-app.ts
|
|
123
|
+
var import_config2 = __toESM(require_lib());
|
|
124
|
+
var import_aws_cdk_lib3 = require("aws-cdk-lib");
|
|
125
|
+
|
|
126
|
+
// src/app/open-hi-environment.ts
|
|
127
|
+
var import_config = __toESM(require_lib());
|
|
128
|
+
var import_aws_cdk_lib = require("aws-cdk-lib");
|
|
129
|
+
var OPEN_HI_ENVIRONMENT_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
130
|
+
"@openhi/constructs/core.OpenHiEnvironment"
|
|
131
|
+
);
|
|
132
|
+
var OpenHiEnvironment = class _OpenHiEnvironment extends import_aws_cdk_lib.Stage {
|
|
133
|
+
/**
|
|
134
|
+
* Creates a new OpenHiEnvironment.
|
|
135
|
+
*/
|
|
136
|
+
constructor(ohStage, props) {
|
|
137
|
+
if (props.config.account && props.config.region) {
|
|
138
|
+
props = {
|
|
139
|
+
...props,
|
|
140
|
+
env: {
|
|
141
|
+
account: props.config.account,
|
|
142
|
+
region: props.config.region
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const stageName = props.deploymentTargetRole === import_config.OPEN_HI_DEPLOYMENT_TARGET_ROLE.PRIMARY ? props.deploymentTargetRole : [props.deploymentTargetRole, ohStage.environments.length].join("-");
|
|
147
|
+
super(ohStage, stageName, {
|
|
148
|
+
env: props.env ?? ohStage.props.env,
|
|
149
|
+
...props
|
|
150
|
+
});
|
|
151
|
+
this.ohStage = ohStage;
|
|
152
|
+
this.props = props;
|
|
153
|
+
Object.defineProperty(this, OPEN_HI_ENVIRONMENT_SYMBOL, { value: true });
|
|
154
|
+
this.deploymentTargetRole = props.deploymentTargetRole;
|
|
155
|
+
this.config = props.config;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Finds the OpenHiEnvironment that contains the given construct.
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
static of(construct) {
|
|
162
|
+
return construct.node.scopes.reverse().find(_OpenHiEnvironment.isOpenHiEnvironment);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Type guard to check if a value is an OpenHiEnvironment instance.
|
|
166
|
+
*/
|
|
167
|
+
static isOpenHiEnvironment(x) {
|
|
168
|
+
return x !== null && typeof x === "object" && OPEN_HI_ENVIRONMENT_SYMBOL in x;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/app/open-hi-stage.ts
|
|
173
|
+
var import_aws_cdk_lib2 = require("aws-cdk-lib");
|
|
174
|
+
var OPEN_HI_STAGE_SYMBOL = /* @__PURE__ */ Symbol.for("@openhi/constructs/core.OpenHiStage");
|
|
175
|
+
var OpenHiStage = class _OpenHiStage extends import_aws_cdk_lib2.Stage {
|
|
176
|
+
/**
|
|
177
|
+
* Creates a new OpenHiStage instance.
|
|
178
|
+
*/
|
|
179
|
+
constructor(ohApp, props) {
|
|
180
|
+
super(ohApp, props.stageType, props);
|
|
181
|
+
this.ohApp = ohApp;
|
|
182
|
+
this.props = props;
|
|
183
|
+
Object.defineProperty(this, OPEN_HI_STAGE_SYMBOL, { value: true });
|
|
184
|
+
this.stageType = props.stageType;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Finds the OpenHiStage that contains the given construct.
|
|
188
|
+
*/
|
|
189
|
+
static of(construct) {
|
|
190
|
+
return construct.node.scopes.reverse().find(_OpenHiStage.isOpenHiStage);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Type guard to check if a value is an OpenHiStage instance.
|
|
194
|
+
*/
|
|
195
|
+
static isOpenHiStage(x) {
|
|
196
|
+
return x !== null && typeof x === "object" && OPEN_HI_STAGE_SYMBOL in x;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Gets all OpenHiEnvironment instances contained within this stage.
|
|
200
|
+
*/
|
|
201
|
+
get environments() {
|
|
202
|
+
return this.node.children.filter(OpenHiEnvironment.isOpenHiEnvironment);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Gets the primary OpenHiEnvironment for this stage, if one exists.
|
|
206
|
+
*/
|
|
207
|
+
get primaryEnvironment() {
|
|
208
|
+
return this.environments.find(
|
|
209
|
+
(env) => env.deploymentTargetRole === "primary"
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Gets all secondary OpenHiEnvironment instances for this stage.
|
|
214
|
+
*/
|
|
215
|
+
get secondaryEnvironments() {
|
|
216
|
+
return this.environments.filter(
|
|
217
|
+
(env) => env.deploymentTargetRole === "secondary"
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/app/open-hi-app.ts
|
|
223
|
+
var OPEN_HI_APP_SYMBOL = /* @__PURE__ */ Symbol.for("@openhi/constructs/core.OpenHiApp");
|
|
224
|
+
var OpenHiApp = class _OpenHiApp extends import_aws_cdk_lib3.App {
|
|
225
|
+
/**
|
|
226
|
+
* Finds the OpenHiApp instance that contains the given construct in its
|
|
227
|
+
* construct tree.
|
|
228
|
+
*/
|
|
229
|
+
static of(construct) {
|
|
230
|
+
return construct.node.scopes.reverse().find(_OpenHiApp.isOpenHiApp);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Type guard that checks if a value is an OpenHiApp instance.
|
|
234
|
+
*/
|
|
235
|
+
static isOpenHiApp(x) {
|
|
236
|
+
return x !== null && typeof x === "object" && OPEN_HI_APP_SYMBOL in x;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Creates a new OpenHiApp instance.
|
|
240
|
+
*/
|
|
241
|
+
constructor(props) {
|
|
242
|
+
super(props);
|
|
243
|
+
Object.defineProperty(this, OPEN_HI_APP_SYMBOL, { value: true });
|
|
244
|
+
this.appName = props.appName ?? "openhi";
|
|
245
|
+
this.config = props.config;
|
|
246
|
+
Object.values(import_config2.OPEN_HI_STAGE).forEach((stageType) => {
|
|
247
|
+
if (this.config.deploymentTargets?.[stageType]) {
|
|
248
|
+
const stage = new OpenHiStage(this, { stageType });
|
|
249
|
+
if (this.config.deploymentTargets?.[stageType]?.[import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.PRIMARY]) {
|
|
250
|
+
const envConfig = this.config.deploymentTargets[stageType][import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.PRIMARY];
|
|
251
|
+
new OpenHiEnvironment(stage, {
|
|
252
|
+
deploymentTargetRole: import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.PRIMARY,
|
|
253
|
+
config: envConfig,
|
|
254
|
+
env: { account: envConfig.account, region: envConfig.region }
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (this.config.deploymentTargets?.[stageType]?.[import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.SECONDARY]) {
|
|
258
|
+
this.config.deploymentTargets[stageType][import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.SECONDARY].forEach((envConfig) => {
|
|
259
|
+
new OpenHiEnvironment(stage, {
|
|
260
|
+
deploymentTargetRole: import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.SECONDARY,
|
|
261
|
+
config: envConfig,
|
|
262
|
+
env: { account: envConfig.account, region: envConfig.region }
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/*****************************************************************************
|
|
270
|
+
*
|
|
271
|
+
* Stages
|
|
272
|
+
*
|
|
273
|
+
****************************************************************************/
|
|
274
|
+
/**
|
|
275
|
+
* Gets all OpenHiStage instances that are direct children of this app.
|
|
276
|
+
|
|
277
|
+
*/
|
|
278
|
+
get stages() {
|
|
279
|
+
return this.node.children.filter(OpenHiStage.isOpenHiStage);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Gets the development stage, if it exists.
|
|
283
|
+
*/
|
|
284
|
+
get devStage() {
|
|
285
|
+
return this.stages.find((stage) => stage.stageType === import_config2.OPEN_HI_STAGE.DEV);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Gets the staging stage, if it exists.
|
|
289
|
+
*/
|
|
290
|
+
get stageStage() {
|
|
291
|
+
return this.stages.find((stage) => stage.stageType === import_config2.OPEN_HI_STAGE.STAGE);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Gets the production stage, if it exists.
|
|
295
|
+
*/
|
|
296
|
+
get prodStage() {
|
|
297
|
+
return this.stages.find((stage) => stage.stageType === import_config2.OPEN_HI_STAGE.PROD);
|
|
298
|
+
}
|
|
299
|
+
/*****************************************************************************
|
|
300
|
+
*
|
|
301
|
+
* Environments
|
|
302
|
+
*
|
|
303
|
+
****************************************************************************/
|
|
304
|
+
/**
|
|
305
|
+
* Gets all OpenHiEnvironment instances across all stages in this app.
|
|
306
|
+
*/
|
|
307
|
+
get environments() {
|
|
308
|
+
return this.stages.flatMap((stage) => stage.environments);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Gets all primary environments across all stages in this app.
|
|
312
|
+
*/
|
|
313
|
+
get primaryEnvironments() {
|
|
314
|
+
return this.environments.filter(
|
|
315
|
+
(env) => env.deploymentTargetRole === "primary"
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Gets all secondary environments across all stages in this app.
|
|
320
|
+
*/
|
|
321
|
+
get secondaryEnvironments() {
|
|
322
|
+
return this.environments.filter(
|
|
323
|
+
(env) => env.deploymentTargetRole === "secondary"
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/app/open-hi-service.ts
|
|
329
|
+
var import_utils = require("@codedrifters/utils");
|
|
330
|
+
var import_config3 = __toESM(require_lib());
|
|
331
|
+
var import_aws_cdk_lib4 = require("aws-cdk-lib");
|
|
332
|
+
var import_change_case = require("change-case");
|
|
333
|
+
var OpenHiService = class extends import_aws_cdk_lib4.Stack {
|
|
334
|
+
/**
|
|
335
|
+
* Creates a new OpenHI service stack.
|
|
336
|
+
*
|
|
337
|
+
* @param ohEnv - The OpenHI environment (stage) this service belongs to
|
|
338
|
+
* @param id - Unique identifier for this service stack (e.g., "user-service")
|
|
339
|
+
* @param props - Optional properties for configuring the service
|
|
340
|
+
*
|
|
341
|
+
* @throws {Error} If account and region are not defined in props or environment
|
|
342
|
+
*
|
|
343
|
+
*/
|
|
344
|
+
constructor(ohEnv, id, props = {}) {
|
|
345
|
+
const { account, region } = props.env || ohEnv;
|
|
346
|
+
if (!account || !region) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
"Account and region must be defined in OpenHiServiceProps or OpenHiEnvironment"
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
const appName = props.appName ?? ohEnv.ohStage.ohApp.appName ?? "openhi";
|
|
352
|
+
const repoName = props.repoName ?? (0, import_utils.findGitRepoName)();
|
|
353
|
+
const defaultReleaseBranch = props.defaultReleaseBranch ?? "main";
|
|
354
|
+
const branchName = props.branchName ?? (process.env.JEST_WORKER_ID ? "test-branch" : ohEnv.ohStage.stageType === import_config3.OPEN_HI_STAGE.DEV ? (0, import_utils.findGitBranch)() : defaultReleaseBranch);
|
|
355
|
+
const environmentHash = (0, import_utils.hashString)(
|
|
356
|
+
[appName, ohEnv.deploymentTargetRole, account, region].join("-"),
|
|
357
|
+
6
|
|
358
|
+
);
|
|
359
|
+
const branchHash = (0, import_utils.hashString)(
|
|
360
|
+
[appName, ohEnv.deploymentTargetRole, account, region, branchName].join(
|
|
361
|
+
"-"
|
|
362
|
+
),
|
|
363
|
+
6
|
|
364
|
+
);
|
|
365
|
+
const stackHash = (0, import_utils.hashString)(
|
|
366
|
+
[
|
|
367
|
+
appName,
|
|
368
|
+
ohEnv.deploymentTargetRole,
|
|
369
|
+
account,
|
|
370
|
+
region,
|
|
371
|
+
branchName,
|
|
372
|
+
id
|
|
373
|
+
].join("-"),
|
|
374
|
+
6
|
|
375
|
+
);
|
|
376
|
+
const removalPolicy = props.removalPolicy ?? (ohEnv.ohStage.stageType === import_config3.OPEN_HI_STAGE.PROD ? import_aws_cdk_lib4.RemovalPolicy.RETAIN : import_aws_cdk_lib4.RemovalPolicy.DESTROY);
|
|
377
|
+
Object.assign(props, { removalPolicy });
|
|
378
|
+
const description = `OpenHi Service: ${id} [${branchName}] - ${branchHash}`;
|
|
379
|
+
super(ohEnv, [branchHash, id, account, region].join("-"), {
|
|
380
|
+
...props,
|
|
381
|
+
description
|
|
382
|
+
});
|
|
383
|
+
this.ohEnv = ohEnv;
|
|
384
|
+
this.props = props;
|
|
385
|
+
this.serviceId = id;
|
|
386
|
+
this.removalPolicy = removalPolicy;
|
|
387
|
+
this.config = props.config ?? ohEnv.props.config;
|
|
388
|
+
this.deploymentTargetRole = ohEnv.deploymentTargetRole;
|
|
389
|
+
this.repoName = repoName;
|
|
390
|
+
this.appName = appName;
|
|
391
|
+
this.defaultReleaseBranch = defaultReleaseBranch;
|
|
392
|
+
this.branchName = branchName;
|
|
393
|
+
this.environmentHash = environmentHash;
|
|
394
|
+
this.branchHash = branchHash;
|
|
395
|
+
this.stackHash = stackHash;
|
|
396
|
+
import_aws_cdk_lib4.Tags.of(this).add(`${appName}:repo-name`, repoName.slice(0, 255));
|
|
397
|
+
import_aws_cdk_lib4.Tags.of(this).add(`${appName}:branch-name`, branchName.slice(0, 255));
|
|
398
|
+
import_aws_cdk_lib4.Tags.of(this).add(`${appName}:service-type`, id.slice(0, 255));
|
|
399
|
+
import_aws_cdk_lib4.Tags.of(this).add(
|
|
400
|
+
`${appName}:stage-type`,
|
|
401
|
+
ohEnv.ohStage.stageType.slice(0, 255)
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* DNS prefix for this branche's child zone.
|
|
406
|
+
*/
|
|
407
|
+
get childZonePrefix() {
|
|
408
|
+
return (0, import_change_case.paramCase)(this.branchName).slice(0, 200);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// src/components/acm/root-wildcard-certificate.ts
|
|
413
|
+
var import_aws_certificatemanager = require("aws-cdk-lib/aws-certificatemanager");
|
|
414
|
+
var import_aws_ssm = require("aws-cdk-lib/aws-ssm");
|
|
415
|
+
var _RootWildcardCertificate = class _RootWildcardCertificate extends import_aws_certificatemanager.Certificate {
|
|
416
|
+
/**
|
|
417
|
+
* Using a special name here since this will be shared and used among many
|
|
418
|
+
* stacks and services. Use with OpenHiGlobalService.rootWildcardCertificateFromConstruct.
|
|
419
|
+
*/
|
|
420
|
+
static ssmParameterName() {
|
|
421
|
+
return "/" + ["GLOBAL", _RootWildcardCertificate.SSM_PARAM_NAME].join("/").toUpperCase();
|
|
422
|
+
}
|
|
423
|
+
constructor(scope, props) {
|
|
424
|
+
super(scope, "root-wildcard-certificate", { ...props });
|
|
425
|
+
new import_aws_ssm.StringParameter(this, "wildcard-cert-param", {
|
|
426
|
+
parameterName: _RootWildcardCertificate.ssmParameterName(),
|
|
427
|
+
stringValue: this.certificateArn
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* Used when storing the Certificate ARN in SSM.
|
|
433
|
+
*/
|
|
434
|
+
_RootWildcardCertificate.SSM_PARAM_NAME = "ROOT_WILDCARD_CERT_ARN";
|
|
435
|
+
var RootWildcardCertificate = _RootWildcardCertificate;
|
|
436
|
+
|
|
437
|
+
// src/components/api-gateway/root-http-api.ts
|
|
438
|
+
var import_aws_apigatewayv2 = require("aws-cdk-lib/aws-apigatewayv2");
|
|
439
|
+
var RootHttpApi = class extends import_aws_apigatewayv2.HttpApi {
|
|
440
|
+
constructor(scope, props = {}) {
|
|
441
|
+
const stack = OpenHiService.of(scope);
|
|
442
|
+
super(scope, "http-api", {
|
|
443
|
+
/**
|
|
444
|
+
* User provided props
|
|
445
|
+
*/
|
|
446
|
+
...props,
|
|
447
|
+
/**
|
|
448
|
+
* Required
|
|
449
|
+
*/
|
|
450
|
+
apiName: ["root", "http", "api", stack.branchHash].join("-")
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* Used when storing the API ID in SSM.
|
|
456
|
+
*/
|
|
457
|
+
RootHttpApi.SSM_PARAM_NAME = "ROOT_HTTP_API";
|
|
458
|
+
|
|
459
|
+
// src/components/app-sync/root-graphql-api.ts
|
|
460
|
+
var import_aws_appsync = require("aws-cdk-lib/aws-appsync");
|
|
461
|
+
var import_awscdk_appsync_utils = require("awscdk-appsync-utils");
|
|
462
|
+
|
|
463
|
+
// src/components/ssm/discoverable-string-parameter.ts
|
|
464
|
+
var import_aws_cdk_lib5 = require("aws-cdk-lib");
|
|
465
|
+
var import_aws_ssm2 = require("aws-cdk-lib/aws-ssm");
|
|
466
|
+
var _DiscoverableStringParameter = class _DiscoverableStringParameter extends import_aws_ssm2.StringParameter {
|
|
467
|
+
/**
|
|
468
|
+
* Build a param name based on predictable attributes found in services and
|
|
469
|
+
* constructs. Used for storage and retrieval of SSM values across services.
|
|
470
|
+
*/
|
|
471
|
+
static buildParameterName(scope, props) {
|
|
472
|
+
const stack = OpenHiService.of(scope);
|
|
473
|
+
return "/" + [
|
|
474
|
+
_DiscoverableStringParameter.version,
|
|
475
|
+
props.branchHash ?? stack.branchHash,
|
|
476
|
+
props.serviceType ?? stack.serviceType,
|
|
477
|
+
props.account ?? stack.account,
|
|
478
|
+
props.region ?? stack.region,
|
|
479
|
+
props.ssmParamName
|
|
480
|
+
].join("/").toUpperCase();
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Read the string value of an SSM parameter created with DiscoverableStringParameter,
|
|
484
|
+
* using props that include ssmParamName and optional overrides (e.g. serviceType).
|
|
485
|
+
*/
|
|
486
|
+
static valueForLookupName(scope, props) {
|
|
487
|
+
const paramName = _DiscoverableStringParameter.buildParameterName(
|
|
488
|
+
scope,
|
|
489
|
+
props
|
|
490
|
+
);
|
|
491
|
+
return import_aws_ssm2.StringParameter.valueForStringParameter(scope, paramName);
|
|
492
|
+
}
|
|
493
|
+
constructor(scope, id, props) {
|
|
494
|
+
const { ssmParamName, branchHash, serviceType, account, region, ...rest } = props;
|
|
495
|
+
const parameterName = _DiscoverableStringParameter.buildParameterName(
|
|
496
|
+
scope,
|
|
497
|
+
props
|
|
498
|
+
);
|
|
499
|
+
super(scope, id + "-" + _DiscoverableStringParameter.version, {
|
|
500
|
+
...rest,
|
|
501
|
+
parameterName
|
|
502
|
+
});
|
|
503
|
+
const { appName } = OpenHiService.of(scope);
|
|
504
|
+
import_aws_cdk_lib5.Tags.of(this).add(`${appName}:param-name`, ssmParamName);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
/**
|
|
508
|
+
* Version of the parameter name format / discoverability schema.
|
|
509
|
+
* Bump when buildParameterName or tagging semantics change.
|
|
510
|
+
* Also used to drive replacement of parameters during CloudFormation deploys.
|
|
511
|
+
*/
|
|
512
|
+
_DiscoverableStringParameter.version = "v1";
|
|
513
|
+
var DiscoverableStringParameter = _DiscoverableStringParameter;
|
|
514
|
+
|
|
515
|
+
// src/components/app-sync/root-graphql-api.ts
|
|
516
|
+
var _RootGraphqlApi = class _RootGraphqlApi extends import_aws_appsync.GraphqlApi {
|
|
517
|
+
static fromConstruct(scope) {
|
|
518
|
+
const graphqlApiId = DiscoverableStringParameter.valueForLookupName(scope, {
|
|
519
|
+
ssmParamName: _RootGraphqlApi.SSM_PARAM_NAME,
|
|
520
|
+
serviceType: "graphql-api"
|
|
521
|
+
});
|
|
522
|
+
return import_aws_appsync.GraphqlApi.fromGraphqlApiAttributes(scope, "root-graphql-api", {
|
|
523
|
+
graphqlApiId
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
constructor(scope, props) {
|
|
527
|
+
const stack = OpenHiService.of(scope);
|
|
528
|
+
const schema = new import_awscdk_appsync_utils.CodeFirstSchema();
|
|
529
|
+
schema.addType(
|
|
530
|
+
new import_awscdk_appsync_utils.ObjectType("Query", {
|
|
531
|
+
definition: { HelloWorld: import_awscdk_appsync_utils.GraphqlType.string() }
|
|
532
|
+
})
|
|
533
|
+
);
|
|
534
|
+
super(scope, "root-graphql-api", {
|
|
535
|
+
/**
|
|
536
|
+
* Defaults
|
|
537
|
+
*/
|
|
538
|
+
queryDepthLimit: 2,
|
|
539
|
+
resolverCountLimit: 50,
|
|
540
|
+
definition: import_aws_appsync.Definition.fromSchema(schema),
|
|
541
|
+
/**
|
|
542
|
+
* Overrideable props
|
|
543
|
+
*/
|
|
544
|
+
...props,
|
|
545
|
+
/**
|
|
546
|
+
* Required
|
|
547
|
+
*/
|
|
548
|
+
name: ["root", "graphql", "api", stack.branchHash].join("-")
|
|
549
|
+
});
|
|
550
|
+
new DiscoverableStringParameter(this, "graphql-api-param", {
|
|
551
|
+
ssmParamName: _RootGraphqlApi.SSM_PARAM_NAME,
|
|
552
|
+
serviceType: "graphql-api",
|
|
553
|
+
stringValue: this.apiId
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* Used when storing the GraphQl API ID in SSM.
|
|
559
|
+
*/
|
|
560
|
+
_RootGraphqlApi.SSM_PARAM_NAME = "ROOT_GRAPHQL_API";
|
|
561
|
+
var RootGraphqlApi = _RootGraphqlApi;
|
|
562
|
+
|
|
563
|
+
// src/components/cognito/cognito-user-pool.ts
|
|
564
|
+
var import_aws_cognito = require("aws-cdk-lib/aws-cognito");
|
|
565
|
+
var CognitoUserPool = class extends import_aws_cognito.UserPool {
|
|
566
|
+
constructor(scope, props = {}) {
|
|
567
|
+
const service = OpenHiService.of(scope);
|
|
568
|
+
super(scope, "user-pool", {
|
|
569
|
+
/**
|
|
570
|
+
* Defaults
|
|
571
|
+
*/
|
|
572
|
+
selfSignUpEnabled: true,
|
|
573
|
+
signInAliases: {
|
|
574
|
+
email: true
|
|
575
|
+
},
|
|
576
|
+
userVerification: {
|
|
577
|
+
emailSubject: "Verify your email!",
|
|
578
|
+
emailBody: "Your verification code is {####}.",
|
|
579
|
+
emailStyle: import_aws_cognito.VerificationEmailStyle.CODE
|
|
580
|
+
},
|
|
581
|
+
removalPolicy: props.removalPolicy ?? service.removalPolicy,
|
|
582
|
+
/**
|
|
583
|
+
* Over-rideable props
|
|
584
|
+
*/
|
|
585
|
+
...props,
|
|
586
|
+
/**
|
|
587
|
+
* Required
|
|
588
|
+
*/
|
|
589
|
+
userPoolName: ["cognito", "user", "pool", service.branchHash].join("-")
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
/**
|
|
594
|
+
* Used when storing the User Pool ID in SSM.
|
|
595
|
+
*/
|
|
596
|
+
CognitoUserPool.SSM_PARAM_NAME = "COGNITO_USER_POOL";
|
|
597
|
+
|
|
598
|
+
// src/components/cognito/cognito-user-pool-client.ts
|
|
599
|
+
var import_aws_cognito2 = require("aws-cdk-lib/aws-cognito");
|
|
600
|
+
var CognitoUserPoolClient = class extends import_aws_cognito2.UserPoolClient {
|
|
601
|
+
constructor(scope, props) {
|
|
602
|
+
super(scope, "user-pool-client", {
|
|
603
|
+
/**
|
|
604
|
+
* Defaults
|
|
605
|
+
*/
|
|
606
|
+
generateSecret: false,
|
|
607
|
+
oAuth: {
|
|
608
|
+
flows: {
|
|
609
|
+
authorizationCodeGrant: true,
|
|
610
|
+
implicitCodeGrant: true
|
|
611
|
+
},
|
|
612
|
+
callbackUrls: [`https://localhost:3000/oauth/callback`]
|
|
613
|
+
},
|
|
614
|
+
/**
|
|
615
|
+
* Overrideable props
|
|
616
|
+
*/
|
|
617
|
+
...props
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
/**
|
|
622
|
+
* Used when storing the User Pool Client ID in SSM.
|
|
623
|
+
*/
|
|
624
|
+
CognitoUserPoolClient.SSM_PARAM_NAME = "COGNITO_USER_POOL_CLIENT";
|
|
625
|
+
|
|
626
|
+
// src/components/cognito/cognito-user-pool-domain.ts
|
|
627
|
+
var import_aws_cognito3 = require("aws-cdk-lib/aws-cognito");
|
|
628
|
+
var CognitoUserPoolDomain = class extends import_aws_cognito3.UserPoolDomain {
|
|
629
|
+
constructor(scope, props) {
|
|
630
|
+
const id = props.cognitoDomain?.domainPrefix ? "cognito-domain" : "custom-domain";
|
|
631
|
+
super(scope, id, {
|
|
632
|
+
...props
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
/**
|
|
637
|
+
* Used when storing the User Pool Domain in SSM.
|
|
638
|
+
*/
|
|
639
|
+
CognitoUserPoolDomain.SSM_PARAM_NAME = "COGNITO_USER_POOL_DOMAIN";
|
|
640
|
+
|
|
641
|
+
// src/components/cognito/cognito-user-pool-kms-key.ts
|
|
642
|
+
var import_aws_kms = require("aws-cdk-lib/aws-kms");
|
|
643
|
+
var CognitoUserPoolKmsKey = class extends import_aws_kms.Key {
|
|
644
|
+
constructor(scope, props = {}) {
|
|
645
|
+
const service = OpenHiService.of(scope);
|
|
646
|
+
super(scope, "kms-key", {
|
|
647
|
+
...props,
|
|
648
|
+
// alias: ["alias", "cognito", service.branchHash].join("/"),
|
|
649
|
+
description: `KMS Key for Cognito User Pool - ${service.branchHash}`,
|
|
650
|
+
removalPolicy: props.removalPolicy ?? service.removalPolicy
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
/**
|
|
655
|
+
* Used when storing the KMS Key in SSM.
|
|
656
|
+
*/
|
|
657
|
+
CognitoUserPoolKmsKey.SSM_PARAM_NAME = "COGNITO_USER_POOL_KMS_KEY";
|
|
658
|
+
|
|
659
|
+
// src/components/dynamodb/dynamo-db-data-store.ts
|
|
660
|
+
var import_aws_dynamodb = require("aws-cdk-lib/aws-dynamodb");
|
|
661
|
+
function getDynamoDbDataStoreTableName(scope) {
|
|
662
|
+
const stack = OpenHiService.of(scope);
|
|
663
|
+
return `data-store-${stack.branchHash}`;
|
|
664
|
+
}
|
|
665
|
+
var DynamoDbDataStore = class extends import_aws_dynamodb.Table {
|
|
666
|
+
constructor(scope, id, props = {}) {
|
|
667
|
+
const service = OpenHiService.of(scope);
|
|
668
|
+
super(scope, id, {
|
|
669
|
+
...props,
|
|
670
|
+
tableName: getDynamoDbDataStoreTableName(scope),
|
|
671
|
+
partitionKey: {
|
|
672
|
+
name: "PK",
|
|
673
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
674
|
+
},
|
|
675
|
+
sortKey: {
|
|
676
|
+
name: "SK",
|
|
677
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
678
|
+
},
|
|
679
|
+
billingMode: import_aws_dynamodb.BillingMode.PAY_PER_REQUEST,
|
|
680
|
+
removalPolicy: props.removalPolicy ?? service.removalPolicy
|
|
681
|
+
});
|
|
682
|
+
this.addGlobalSecondaryIndex({
|
|
683
|
+
indexName: "GSI1",
|
|
684
|
+
partitionKey: {
|
|
685
|
+
name: "GSI1PK",
|
|
686
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
687
|
+
},
|
|
688
|
+
sortKey: {
|
|
689
|
+
name: "GSI1SK",
|
|
690
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
691
|
+
},
|
|
692
|
+
projectionType: import_aws_dynamodb.ProjectionType.INCLUDE,
|
|
693
|
+
nonKeyAttributes: ["srcType", "srcId", "path", "srcPk", "srcSk", "ts"]
|
|
694
|
+
});
|
|
695
|
+
this.addGlobalSecondaryIndex({
|
|
696
|
+
indexName: "GSI2",
|
|
697
|
+
partitionKey: {
|
|
698
|
+
name: "GSI2PK",
|
|
699
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
700
|
+
},
|
|
701
|
+
sortKey: {
|
|
702
|
+
name: "GSI2SK",
|
|
703
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
704
|
+
},
|
|
705
|
+
projectionType: import_aws_dynamodb.ProjectionType.INCLUDE,
|
|
706
|
+
nonKeyAttributes: ["resourcePk", "resourceSk", "display", "status"]
|
|
707
|
+
});
|
|
708
|
+
this.addGlobalSecondaryIndex({
|
|
709
|
+
indexName: "GSI3",
|
|
710
|
+
partitionKey: {
|
|
711
|
+
name: "GSI3PK",
|
|
712
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
713
|
+
},
|
|
714
|
+
sortKey: {
|
|
715
|
+
name: "GSI3SK",
|
|
716
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
717
|
+
},
|
|
718
|
+
projectionType: import_aws_dynamodb.ProjectionType.INCLUDE,
|
|
719
|
+
nonKeyAttributes: ["resourcePk", "resourceSk"]
|
|
720
|
+
});
|
|
721
|
+
this.addGlobalSecondaryIndex({
|
|
722
|
+
indexName: "GSI4",
|
|
723
|
+
partitionKey: {
|
|
724
|
+
name: "GSI4PK",
|
|
725
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
726
|
+
},
|
|
727
|
+
sortKey: {
|
|
728
|
+
name: "GSI4SK",
|
|
729
|
+
type: import_aws_dynamodb.AttributeType.STRING
|
|
730
|
+
},
|
|
731
|
+
projectionType: import_aws_dynamodb.ProjectionType.ALL
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
// src/components/event-bridge/data-event-bus.ts
|
|
737
|
+
var import_aws_events = require("aws-cdk-lib/aws-events");
|
|
738
|
+
var DataEventBus = class _DataEventBus extends import_aws_events.EventBus {
|
|
739
|
+
/*****************************************************************************
|
|
740
|
+
*
|
|
741
|
+
* Return a name for this EventBus based on the stack environment hash. This
|
|
742
|
+
* name is common across all stacks since it's using the environment hash in
|
|
743
|
+
* it's name.
|
|
744
|
+
*
|
|
745
|
+
****************************************************************************/
|
|
746
|
+
static getEventBusName(scope) {
|
|
747
|
+
const stack = OpenHiService.of(scope);
|
|
748
|
+
return `data${stack.branchHash}`;
|
|
749
|
+
}
|
|
750
|
+
constructor(scope, props) {
|
|
751
|
+
super(scope, "data-event-bus", {
|
|
752
|
+
...props,
|
|
753
|
+
eventBusName: _DataEventBus.getEventBusName(scope)
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
// src/components/event-bridge/ops-event-bus.ts
|
|
759
|
+
var import_aws_events2 = require("aws-cdk-lib/aws-events");
|
|
760
|
+
var OpsEventBus = class _OpsEventBus extends import_aws_events2.EventBus {
|
|
761
|
+
/*****************************************************************************
|
|
762
|
+
*
|
|
763
|
+
* Return a name for this EventBus based on the stack environment hash. This
|
|
764
|
+
* name is common across all stacks since it's using the environment hash in
|
|
765
|
+
* it's name.
|
|
766
|
+
*
|
|
767
|
+
****************************************************************************/
|
|
768
|
+
static getEventBusName(scope) {
|
|
769
|
+
const stack = OpenHiService.of(scope);
|
|
770
|
+
return `ops${stack.branchHash}`;
|
|
771
|
+
}
|
|
772
|
+
constructor(scope, props) {
|
|
773
|
+
super(scope, "ops-event-bus", {
|
|
774
|
+
...props,
|
|
775
|
+
eventBusName: _OpsEventBus.getEventBusName(scope)
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
// src/components/route-53/child-hosted-zone.ts
|
|
781
|
+
var import_aws_cdk_lib6 = require("aws-cdk-lib");
|
|
782
|
+
var import_aws_route53 = require("aws-cdk-lib/aws-route53");
|
|
783
|
+
var ChildHostedZone = class extends import_aws_route53.HostedZone {
|
|
784
|
+
constructor(scope, id, props) {
|
|
785
|
+
super(scope, id, { ...props });
|
|
786
|
+
new import_aws_route53.NsRecord(this, "child-ns-record", {
|
|
787
|
+
zone: props.parentHostedZone,
|
|
788
|
+
recordName: this.zoneName,
|
|
789
|
+
values: this.hostedZoneNameServers || [],
|
|
790
|
+
ttl: import_aws_cdk_lib6.Duration.minutes(5)
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
/**
|
|
795
|
+
* Used when storing the child zone ID in SSM. Use {@link OpenHiGlobalService.childHostedZoneFromConstruct} to look up.
|
|
796
|
+
*/
|
|
797
|
+
ChildHostedZone.SSM_PARAM_NAME = "CHILDHOSTEDZONE";
|
|
798
|
+
|
|
799
|
+
// src/components/route-53/root-hosted-zone.ts
|
|
800
|
+
var import_constructs = require("constructs");
|
|
801
|
+
var RootHostedZone = class extends import_constructs.Construct {
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
// src/services/open-hi-auth-service.ts
|
|
805
|
+
var import_aws_cognito4 = require("aws-cdk-lib/aws-cognito");
|
|
806
|
+
var import_aws_kms2 = require("aws-cdk-lib/aws-kms");
|
|
807
|
+
var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
808
|
+
constructor(ohEnv, props = {}) {
|
|
809
|
+
super(ohEnv, _OpenHiAuthService.SERVICE_TYPE, props);
|
|
810
|
+
this.props = props;
|
|
811
|
+
this.userPoolKmsKey = this.createUserPoolKmsKey();
|
|
812
|
+
this.userPool = this.createUserPool();
|
|
813
|
+
this.userPoolClient = this.createUserPoolClient();
|
|
814
|
+
this.userPoolDomain = this.createUserPoolDomain();
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Returns an IUserPool by looking up the Auth stack's User Pool ID from SSM.
|
|
818
|
+
*/
|
|
819
|
+
static userPoolFromConstruct(scope) {
|
|
820
|
+
const userPoolId = DiscoverableStringParameter.valueForLookupName(scope, {
|
|
821
|
+
ssmParamName: CognitoUserPool.SSM_PARAM_NAME,
|
|
822
|
+
serviceType: _OpenHiAuthService.SERVICE_TYPE
|
|
823
|
+
});
|
|
824
|
+
return import_aws_cognito4.UserPool.fromUserPoolId(scope, "user-pool", userPoolId);
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Returns an IUserPoolClient by looking up the Auth stack's User Pool Client ID from SSM.
|
|
828
|
+
*/
|
|
829
|
+
static userPoolClientFromConstruct(scope) {
|
|
830
|
+
const userPoolClientId = DiscoverableStringParameter.valueForLookupName(
|
|
831
|
+
scope,
|
|
832
|
+
{
|
|
833
|
+
ssmParamName: CognitoUserPoolClient.SSM_PARAM_NAME,
|
|
834
|
+
serviceType: _OpenHiAuthService.SERVICE_TYPE
|
|
835
|
+
}
|
|
836
|
+
);
|
|
837
|
+
return import_aws_cognito4.UserPoolClient.fromUserPoolClientId(
|
|
838
|
+
scope,
|
|
839
|
+
"user-pool-client",
|
|
840
|
+
userPoolClientId
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Returns an IUserPoolDomain by looking up the Auth stack's User Pool Domain from SSM.
|
|
845
|
+
*/
|
|
846
|
+
static userPoolDomainFromConstruct(scope) {
|
|
847
|
+
const domainName = DiscoverableStringParameter.valueForLookupName(scope, {
|
|
848
|
+
ssmParamName: CognitoUserPoolDomain.SSM_PARAM_NAME,
|
|
849
|
+
serviceType: _OpenHiAuthService.SERVICE_TYPE
|
|
850
|
+
});
|
|
851
|
+
return import_aws_cognito4.UserPoolDomain.fromDomainName(scope, "user-pool-domain", domainName);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Returns an IKey (KMS) by looking up the Auth stack's User Pool KMS Key ARN from SSM.
|
|
855
|
+
*/
|
|
856
|
+
static userPoolKmsKeyFromConstruct(scope) {
|
|
857
|
+
const keyArn = DiscoverableStringParameter.valueForLookupName(scope, {
|
|
858
|
+
ssmParamName: CognitoUserPoolKmsKey.SSM_PARAM_NAME,
|
|
859
|
+
serviceType: _OpenHiAuthService.SERVICE_TYPE
|
|
860
|
+
});
|
|
861
|
+
return import_aws_kms2.Key.fromKeyArn(scope, "kms-key", keyArn);
|
|
862
|
+
}
|
|
863
|
+
get serviceType() {
|
|
864
|
+
return _OpenHiAuthService.SERVICE_TYPE;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Creates the KMS key for the Cognito User Pool and exports its ARN to SSM.
|
|
868
|
+
* Look up via {@link OpenHiAuthService.userPoolKmsKeyFromConstruct}.
|
|
869
|
+
* Override to customize.
|
|
870
|
+
*/
|
|
871
|
+
createUserPoolKmsKey() {
|
|
872
|
+
const key = new CognitoUserPoolKmsKey(this);
|
|
873
|
+
new DiscoverableStringParameter(this, "kms-key-param", {
|
|
874
|
+
ssmParamName: CognitoUserPoolKmsKey.SSM_PARAM_NAME,
|
|
875
|
+
stringValue: key.keyArn,
|
|
876
|
+
description: "KMS key ARN for Cognito User Pool (e.g. custom sender); cross-stack reference"
|
|
877
|
+
});
|
|
878
|
+
return key;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Creates the Cognito User Pool and exports its ID to SSM.
|
|
882
|
+
* Look up via {@link OpenHiAuthService.userPoolFromConstruct}.
|
|
883
|
+
* Override to customize.
|
|
884
|
+
*/
|
|
885
|
+
createUserPool() {
|
|
886
|
+
const userPool = new CognitoUserPool(this, {
|
|
887
|
+
...this.props.userPoolProps,
|
|
888
|
+
customSenderKmsKey: this.userPoolKmsKey
|
|
889
|
+
});
|
|
890
|
+
new DiscoverableStringParameter(this, "user-pool-param", {
|
|
891
|
+
ssmParamName: CognitoUserPool.SSM_PARAM_NAME,
|
|
892
|
+
stringValue: userPool.userPoolId,
|
|
893
|
+
description: "Cognito User Pool ID for this Auth stack; cross-stack reference"
|
|
894
|
+
});
|
|
895
|
+
return userPool;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Creates the User Pool Client and exports its ID to SSM (AUTH service type).
|
|
899
|
+
* Look up via {@link OpenHiAuthService.userPoolClientFromConstruct}.
|
|
900
|
+
* Override to customize.
|
|
901
|
+
*/
|
|
902
|
+
createUserPoolClient() {
|
|
903
|
+
const client = new CognitoUserPoolClient(this, {
|
|
904
|
+
userPool: this.userPool
|
|
905
|
+
});
|
|
906
|
+
new DiscoverableStringParameter(this, "user-pool-client-param", {
|
|
907
|
+
ssmParamName: CognitoUserPoolClient.SSM_PARAM_NAME,
|
|
908
|
+
stringValue: client.userPoolClientId,
|
|
909
|
+
description: "Cognito User Pool Client ID for this Auth stack; cross-stack reference"
|
|
910
|
+
});
|
|
911
|
+
return client;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Creates the User Pool Domain (Cognito hosted UI) and exports domain name to SSM.
|
|
915
|
+
* Look up via {@link OpenHiAuthService.userPoolDomainFromConstruct}.
|
|
916
|
+
* Override to customize.
|
|
917
|
+
*/
|
|
918
|
+
createUserPoolDomain() {
|
|
919
|
+
const domain = new CognitoUserPoolDomain(this, {
|
|
920
|
+
userPool: this.userPool,
|
|
921
|
+
cognitoDomain: {
|
|
922
|
+
domainPrefix: `auth-${this.branchHash}`
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
new DiscoverableStringParameter(this, "user-pool-domain-param", {
|
|
926
|
+
ssmParamName: CognitoUserPoolDomain.SSM_PARAM_NAME,
|
|
927
|
+
stringValue: domain.domainName,
|
|
928
|
+
description: "Cognito User Pool Domain (hosted UI) for this Auth stack; cross-stack reference"
|
|
929
|
+
});
|
|
930
|
+
return domain;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
_OpenHiAuthService.SERVICE_TYPE = "auth";
|
|
934
|
+
var OpenHiAuthService = _OpenHiAuthService;
|
|
935
|
+
|
|
936
|
+
// src/services/open-hi-global-service.ts
|
|
937
|
+
var import_aws_certificatemanager2 = require("aws-cdk-lib/aws-certificatemanager");
|
|
938
|
+
var import_aws_route532 = require("aws-cdk-lib/aws-route53");
|
|
939
|
+
var import_aws_ssm3 = require("aws-cdk-lib/aws-ssm");
|
|
940
|
+
var _OpenHiGlobalService = class _OpenHiGlobalService extends OpenHiService {
|
|
941
|
+
/**
|
|
942
|
+
* Returns an IHostedZone from the given attributes (no SSM). Use when the zone is imported from config.
|
|
943
|
+
*/
|
|
944
|
+
static rootHostedZoneFromConstruct(scope, props) {
|
|
945
|
+
return import_aws_route532.HostedZone.fromHostedZoneAttributes(scope, "root-zone", props);
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Returns an ICertificate by looking up the Global stack's wildcard cert ARN from SSM.
|
|
949
|
+
*/
|
|
950
|
+
static rootWildcardCertificateFromConstruct(scope) {
|
|
951
|
+
const certificateArn = import_aws_ssm3.StringParameter.valueForStringParameter(
|
|
952
|
+
scope,
|
|
953
|
+
RootWildcardCertificate.ssmParameterName()
|
|
954
|
+
);
|
|
955
|
+
return import_aws_certificatemanager2.Certificate.fromCertificateArn(
|
|
956
|
+
scope,
|
|
957
|
+
"wildcard-certificate",
|
|
958
|
+
certificateArn
|
|
959
|
+
);
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Returns an IHostedZone by looking up the child hosted zone ID from SSM. Defaults to GLOBAL service type.
|
|
963
|
+
*/
|
|
964
|
+
static childHostedZoneFromConstruct(scope, props) {
|
|
965
|
+
const hostedZoneId = DiscoverableStringParameter.valueForLookupName(scope, {
|
|
966
|
+
ssmParamName: ChildHostedZone.SSM_PARAM_NAME,
|
|
967
|
+
serviceType: props.serviceType ?? _OpenHiGlobalService.SERVICE_TYPE
|
|
968
|
+
});
|
|
969
|
+
return import_aws_route532.HostedZone.fromHostedZoneAttributes(scope, "child-zone", {
|
|
970
|
+
hostedZoneId,
|
|
971
|
+
zoneName: props.zoneName
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
get serviceType() {
|
|
975
|
+
return _OpenHiGlobalService.SERVICE_TYPE;
|
|
976
|
+
}
|
|
977
|
+
constructor(ohEnv, props = {}) {
|
|
978
|
+
super(ohEnv, _OpenHiGlobalService.SERVICE_TYPE, props);
|
|
979
|
+
this.validateConfig(props);
|
|
980
|
+
this.rootHostedZone = this.createRootHostedZone();
|
|
981
|
+
this.childHostedZone = this.createChildHostedZone();
|
|
982
|
+
this.rootWildcardCertificate = this.createRootWildcardCertificate();
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Validates that config required for the Global stack is present.
|
|
986
|
+
*/
|
|
987
|
+
validateConfig(props) {
|
|
988
|
+
const { config } = props;
|
|
989
|
+
if (!config) {
|
|
990
|
+
throw new Error("Config is required");
|
|
991
|
+
}
|
|
992
|
+
if (!config.zoneName) {
|
|
993
|
+
throw new Error("Zone name is required to import the root zone");
|
|
994
|
+
}
|
|
995
|
+
if (!config.hostedZoneId) {
|
|
996
|
+
throw new Error("Hosted zone ID is required to import the root zone");
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Creates the root hosted zone (imported via attributes from config).
|
|
1001
|
+
* Override to customize or create the zone.
|
|
1002
|
+
*/
|
|
1003
|
+
createRootHostedZone() {
|
|
1004
|
+
return _OpenHiGlobalService.rootHostedZoneFromConstruct(this, {
|
|
1005
|
+
zoneName: this.config.zoneName,
|
|
1006
|
+
hostedZoneId: this.config.hostedZoneId
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Creates the optional child hosted zone (e.g. branch subdomain).
|
|
1011
|
+
* Override to create a child zone when config provides childHostedZoneAttributes.
|
|
1012
|
+
* If you create a ChildHostedZone, also create a DiscoverableStringParameter
|
|
1013
|
+
* with ChildHostedZone.SSM_PARAM_NAME and the zone's hostedZoneId.
|
|
1014
|
+
*/
|
|
1015
|
+
createChildHostedZone() {
|
|
1016
|
+
return void 0;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Creates the root wildcard certificate. On main branch, creates a new cert
|
|
1020
|
+
* with DNS validation; otherwise imports from SSM.
|
|
1021
|
+
* Override to customize certificate creation.
|
|
1022
|
+
*/
|
|
1023
|
+
createRootWildcardCertificate() {
|
|
1024
|
+
if (this.branchName === "main") {
|
|
1025
|
+
return new RootWildcardCertificate(this, {
|
|
1026
|
+
domainName: `*.${this.rootHostedZone.zoneName}`,
|
|
1027
|
+
subjectAlternativeNames: [this.rootHostedZone.zoneName],
|
|
1028
|
+
validation: import_aws_certificatemanager2.CertificateValidation.fromDns(this.rootHostedZone)
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
return _OpenHiGlobalService.rootWildcardCertificateFromConstruct(this);
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
_OpenHiGlobalService.SERVICE_TYPE = "global";
|
|
1035
|
+
var OpenHiGlobalService = _OpenHiGlobalService;
|
|
1036
|
+
|
|
1037
|
+
// src/services/open-hi-rest-api-service.ts
|
|
1038
|
+
var import_aws_apigatewayv22 = require("aws-cdk-lib/aws-apigatewayv2");
|
|
1039
|
+
var import_aws_apigatewayv2_integrations = require("aws-cdk-lib/aws-apigatewayv2-integrations");
|
|
1040
|
+
var import_aws_route533 = require("aws-cdk-lib/aws-route53");
|
|
1041
|
+
var import_aws_route53_targets = require("aws-cdk-lib/aws-route53-targets");
|
|
1042
|
+
|
|
1043
|
+
// src/services/open-hi-data-service.ts
|
|
1044
|
+
var import_aws_dynamodb2 = require("aws-cdk-lib/aws-dynamodb");
|
|
1045
|
+
var import_aws_events3 = require("aws-cdk-lib/aws-events");
|
|
1046
|
+
var _OpenHiDataService = class _OpenHiDataService extends OpenHiService {
|
|
1047
|
+
/**
|
|
1048
|
+
* Returns the data event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
|
|
1049
|
+
*/
|
|
1050
|
+
static dataEventBusFromConstruct(scope) {
|
|
1051
|
+
return import_aws_events3.EventBus.fromEventBusName(
|
|
1052
|
+
scope,
|
|
1053
|
+
"data-event-bus",
|
|
1054
|
+
DataEventBus.getEventBusName(scope)
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Returns the ops event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
|
|
1059
|
+
*/
|
|
1060
|
+
static opsEventBusFromConstruct(scope) {
|
|
1061
|
+
return import_aws_events3.EventBus.fromEventBusName(
|
|
1062
|
+
scope,
|
|
1063
|
+
"ops-event-bus",
|
|
1064
|
+
OpsEventBus.getEventBusName(scope)
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Returns the data store table by name. Use from other stacks (e.g. REST API Lambda) to obtain an ITable reference.
|
|
1069
|
+
*/
|
|
1070
|
+
static dynamoDbDataStoreFromConstruct(scope, id = "dynamo-db-data-store") {
|
|
1071
|
+
return import_aws_dynamodb2.Table.fromTableName(scope, id, getDynamoDbDataStoreTableName(scope));
|
|
1072
|
+
}
|
|
1073
|
+
get serviceType() {
|
|
1074
|
+
return _OpenHiDataService.SERVICE_TYPE;
|
|
1075
|
+
}
|
|
1076
|
+
constructor(ohEnv, props = {}) {
|
|
1077
|
+
super(ohEnv, _OpenHiDataService.SERVICE_TYPE, props);
|
|
1078
|
+
this.dataEventBus = this.createDataEventBus();
|
|
1079
|
+
this.opsEventBus = this.createOpsEventBus();
|
|
1080
|
+
this.dataStore = this.createDataStore();
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Creates the data event bus.
|
|
1084
|
+
* Override to customize.
|
|
1085
|
+
*/
|
|
1086
|
+
createDataEventBus() {
|
|
1087
|
+
return new DataEventBus(this);
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Creates the ops event bus.
|
|
1091
|
+
* Override to customize.
|
|
1092
|
+
*/
|
|
1093
|
+
createOpsEventBus() {
|
|
1094
|
+
return new OpsEventBus(this);
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Creates the single-table DynamoDB data store.
|
|
1098
|
+
* Override to customize.
|
|
1099
|
+
*/
|
|
1100
|
+
createDataStore() {
|
|
1101
|
+
return new DynamoDbDataStore(this, "dynamo-db-data-store");
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
_OpenHiDataService.SERVICE_TYPE = "data";
|
|
1105
|
+
var OpenHiDataService = _OpenHiDataService;
|
|
1106
|
+
|
|
1107
|
+
// src/data/lambda/rest-api-lambda.ts
|
|
1108
|
+
var import_path = __toESM(require("path"));
|
|
1109
|
+
var import_aws_lambda = require("aws-cdk-lib/aws-lambda");
|
|
1110
|
+
var import_aws_lambda_nodejs = require("aws-cdk-lib/aws-lambda-nodejs");
|
|
1111
|
+
var import_constructs2 = require("constructs");
|
|
1112
|
+
var RestApiLambda = class extends import_constructs2.Construct {
|
|
1113
|
+
constructor(scope, props) {
|
|
1114
|
+
super(scope, "rest-api-lambda");
|
|
1115
|
+
this.lambda = new import_aws_lambda_nodejs.NodejsFunction(this, "handler", {
|
|
1116
|
+
entry: import_path.default.join(__dirname, "rest-api-lambda.handler.js"),
|
|
1117
|
+
runtime: import_aws_lambda.Runtime.NODEJS_LATEST,
|
|
1118
|
+
environment: {
|
|
1119
|
+
DYNAMO_TABLE_NAME: props.dynamoTableName
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1125
|
+
// src/services/open-hi-rest-api-service.ts
|
|
1126
|
+
var REST_API_BASE_URL_SSM_NAME = "REST_API_BASE_URL";
|
|
1127
|
+
var _OpenHiRestApiService = class _OpenHiRestApiService extends OpenHiService {
|
|
1128
|
+
/**
|
|
1129
|
+
* Returns an IHttpApi by looking up the REST API stack's HTTP API ID from SSM.
|
|
1130
|
+
*/
|
|
1131
|
+
static rootHttpApiFromConstruct(scope) {
|
|
1132
|
+
const httpApiId = DiscoverableStringParameter.valueForLookupName(scope, {
|
|
1133
|
+
ssmParamName: RootHttpApi.SSM_PARAM_NAME,
|
|
1134
|
+
serviceType: _OpenHiRestApiService.SERVICE_TYPE
|
|
1135
|
+
});
|
|
1136
|
+
return import_aws_apigatewayv22.HttpApi.fromHttpApiAttributes(scope, "http-api", { httpApiId });
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Returns the REST API base URL (e.g. https://api.example.com) by looking it up from SSM.
|
|
1140
|
+
* Use in other stacks for E2E, scripts, or config.
|
|
1141
|
+
*/
|
|
1142
|
+
static restApiBaseUrlFromConstruct(scope) {
|
|
1143
|
+
return DiscoverableStringParameter.valueForLookupName(scope, {
|
|
1144
|
+
ssmParamName: REST_API_BASE_URL_SSM_NAME,
|
|
1145
|
+
serviceType: _OpenHiRestApiService.SERVICE_TYPE
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
get serviceType() {
|
|
1149
|
+
return _OpenHiRestApiService.SERVICE_TYPE;
|
|
1150
|
+
}
|
|
1151
|
+
constructor(ohEnv, props = {}) {
|
|
1152
|
+
super(ohEnv, _OpenHiRestApiService.SERVICE_TYPE, props);
|
|
1153
|
+
this.validateConfig(props);
|
|
1154
|
+
const hostedZone = this.createHostedZone();
|
|
1155
|
+
const certificate = this.createCertificate();
|
|
1156
|
+
const apiDomainName = this.createApiDomainNameString(hostedZone);
|
|
1157
|
+
this.createRestApiBaseUrlParameter(apiDomainName);
|
|
1158
|
+
const domainName = this.createDomainName(hostedZone, certificate);
|
|
1159
|
+
this.rootHttpApi = this.createRootHttpApi(domainName);
|
|
1160
|
+
this.createRestApiLambdaAndRoutes(hostedZone, domainName);
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Validates that config required for the REST API stack is present.
|
|
1164
|
+
*/
|
|
1165
|
+
validateConfig(props) {
|
|
1166
|
+
const { config } = props;
|
|
1167
|
+
if (!config) {
|
|
1168
|
+
throw new Error("Config is required");
|
|
1169
|
+
}
|
|
1170
|
+
if (!config.hostedZoneId) {
|
|
1171
|
+
throw new Error("Hosted zone ID is required");
|
|
1172
|
+
}
|
|
1173
|
+
if (!config.zoneName) {
|
|
1174
|
+
throw new Error("Zone name is required");
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Creates the hosted zone reference (imported from config).
|
|
1179
|
+
* Override to customize.
|
|
1180
|
+
*/
|
|
1181
|
+
createHostedZone() {
|
|
1182
|
+
const { config } = this.props;
|
|
1183
|
+
return import_aws_route533.HostedZone.fromHostedZoneAttributes(this, "root-zone", {
|
|
1184
|
+
hostedZoneId: config.hostedZoneId,
|
|
1185
|
+
zoneName: config.zoneName
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Creates the wildcard certificate (imported from Global stack via SSM).
|
|
1190
|
+
* Override to customize.
|
|
1191
|
+
*/
|
|
1192
|
+
createCertificate() {
|
|
1193
|
+
return OpenHiGlobalService.rootWildcardCertificateFromConstruct(this);
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Returns the API domain name string (e.g. api.example.com or api-{prefix}.example.com).
|
|
1197
|
+
* Override to customize.
|
|
1198
|
+
*/
|
|
1199
|
+
createApiDomainNameString(hostedZone) {
|
|
1200
|
+
const apiPrefix = this.branchName === "main" ? `api` : `api-${this.childZonePrefix}`;
|
|
1201
|
+
return [apiPrefix, hostedZone.zoneName].join(".");
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Creates the SSM parameter for the REST API base URL.
|
|
1205
|
+
* Look up via {@link OpenHiRestApiService.restApiBaseUrlFromConstruct}.
|
|
1206
|
+
* Override to customize.
|
|
1207
|
+
*/
|
|
1208
|
+
createRestApiBaseUrlParameter(apiDomainName) {
|
|
1209
|
+
const restApiBaseUrl = `https://${apiDomainName}`;
|
|
1210
|
+
new DiscoverableStringParameter(this, "rest-api-base-url-param", {
|
|
1211
|
+
ssmParamName: REST_API_BASE_URL_SSM_NAME,
|
|
1212
|
+
stringValue: restApiBaseUrl,
|
|
1213
|
+
description: "REST API base URL for this deployment (E2E, scripts)"
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Creates the API Gateway custom domain name resource.
|
|
1218
|
+
* Override to customize.
|
|
1219
|
+
*/
|
|
1220
|
+
createDomainName(_hostedZone, certificate) {
|
|
1221
|
+
const apiDomainName = this.createApiDomainNameString(_hostedZone);
|
|
1222
|
+
return new import_aws_apigatewayv22.DomainName(this, "domain", {
|
|
1223
|
+
domainName: apiDomainName,
|
|
1224
|
+
certificate
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Creates the Lambda integration, HTTP routes, and API DNS record.
|
|
1229
|
+
* Override to customize. Uses {@link rootHttpApi} set by the constructor.
|
|
1230
|
+
*/
|
|
1231
|
+
createRestApiLambdaAndRoutes(hostedZone, domainName) {
|
|
1232
|
+
const dataStoreTable = OpenHiDataService.dynamoDbDataStoreFromConstruct(this);
|
|
1233
|
+
const { lambda } = new RestApiLambda(this, {
|
|
1234
|
+
dynamoTableName: dataStoreTable.tableName
|
|
1235
|
+
});
|
|
1236
|
+
dataStoreTable.grant(
|
|
1237
|
+
lambda,
|
|
1238
|
+
"dynamodb:GetItem",
|
|
1239
|
+
"dynamodb:Query",
|
|
1240
|
+
"dynamodb:BatchGetItem",
|
|
1241
|
+
"dynamodb:ConditionCheckItem",
|
|
1242
|
+
"dynamodb:DescribeTable",
|
|
1243
|
+
"dynamodb:BatchWriteItem",
|
|
1244
|
+
"dynamodb:PutItem",
|
|
1245
|
+
"dynamodb:UpdateItem",
|
|
1246
|
+
"dynamodb:DeleteItem"
|
|
1247
|
+
);
|
|
1248
|
+
const integration = new import_aws_apigatewayv2_integrations.HttpLambdaIntegration("lambda-integration", lambda);
|
|
1249
|
+
new import_aws_apigatewayv22.HttpRoute(this, "proxy-route-root", {
|
|
1250
|
+
httpApi: this.rootHttpApi,
|
|
1251
|
+
routeKey: import_aws_apigatewayv22.HttpRouteKey.with("/", import_aws_apigatewayv22.HttpMethod.ANY),
|
|
1252
|
+
integration
|
|
1253
|
+
});
|
|
1254
|
+
new import_aws_apigatewayv22.HttpRoute(this, "proxy-route", {
|
|
1255
|
+
httpApi: this.rootHttpApi,
|
|
1256
|
+
routeKey: import_aws_apigatewayv22.HttpRouteKey.with("/{proxy+}", import_aws_apigatewayv22.HttpMethod.ANY),
|
|
1257
|
+
integration
|
|
1258
|
+
});
|
|
1259
|
+
const apiPrefix = this.branchName === "main" ? `api` : `api-${this.childZonePrefix}`;
|
|
1260
|
+
new import_aws_route533.ARecord(this, "api-a-record", {
|
|
1261
|
+
zone: hostedZone,
|
|
1262
|
+
recordName: apiPrefix,
|
|
1263
|
+
target: import_aws_route533.RecordTarget.fromAlias(
|
|
1264
|
+
new import_aws_route53_targets.ApiGatewayv2DomainProperties(
|
|
1265
|
+
domainName.regionalDomainName,
|
|
1266
|
+
domainName.regionalHostedZoneId
|
|
1267
|
+
)
|
|
1268
|
+
)
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Creates the Root HTTP API with default domain mapping and exports API ID to SSM.
|
|
1273
|
+
* Look up via {@link OpenHiRestApiService.rootHttpApiFromConstruct}.
|
|
1274
|
+
* Override to customize.
|
|
1275
|
+
*/
|
|
1276
|
+
createRootHttpApi(domainName) {
|
|
1277
|
+
const rootHttpApi = new RootHttpApi(this, {
|
|
1278
|
+
defaultDomainMapping: {
|
|
1279
|
+
domainName,
|
|
1280
|
+
mappingKey: void 0
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1283
|
+
new DiscoverableStringParameter(this, "http-api-url-param", {
|
|
1284
|
+
ssmParamName: RootHttpApi.SSM_PARAM_NAME,
|
|
1285
|
+
stringValue: rootHttpApi.httpApiId,
|
|
1286
|
+
description: "API Gateway HTTP API ID for this REST API stack (cross-stack reference)"
|
|
1287
|
+
});
|
|
1288
|
+
return rootHttpApi;
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
_OpenHiRestApiService.SERVICE_TYPE = "rest-api";
|
|
1292
|
+
var OpenHiRestApiService = _OpenHiRestApiService;
|
|
1293
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1294
|
+
0 && (module.exports = {
|
|
1295
|
+
ChildHostedZone,
|
|
1296
|
+
CognitoUserPool,
|
|
1297
|
+
CognitoUserPoolClient,
|
|
1298
|
+
CognitoUserPoolDomain,
|
|
1299
|
+
CognitoUserPoolKmsKey,
|
|
1300
|
+
DataEventBus,
|
|
1301
|
+
DiscoverableStringParameter,
|
|
1302
|
+
DynamoDbDataStore,
|
|
1303
|
+
OpenHiApp,
|
|
1304
|
+
OpenHiAuthService,
|
|
1305
|
+
OpenHiDataService,
|
|
1306
|
+
OpenHiEnvironment,
|
|
1307
|
+
OpenHiGlobalService,
|
|
1308
|
+
OpenHiRestApiService,
|
|
1309
|
+
OpenHiService,
|
|
1310
|
+
OpenHiStage,
|
|
1311
|
+
OpsEventBus,
|
|
1312
|
+
REST_API_BASE_URL_SSM_NAME,
|
|
1313
|
+
RootGraphqlApi,
|
|
1314
|
+
RootHostedZone,
|
|
1315
|
+
RootHttpApi,
|
|
1316
|
+
RootWildcardCertificate,
|
|
1317
|
+
getDynamoDbDataStoreTableName
|
|
1318
|
+
});
|
|
1319
|
+
//# sourceMappingURL=index.js.map
|