@openhi/constructs 0.0.0 → 0.0.1

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.
Files changed (101) hide show
  1. package/lib/chunk-LZOMFHX3.mjs +38 -0
  2. package/lib/chunk-LZOMFHX3.mjs.map +1 -0
  3. package/lib/index.d.mts +664 -0
  4. package/lib/index.d.ts +745 -3
  5. package/lib/index.js +1133 -19
  6. package/lib/index.js.map +1 -0
  7. package/lib/index.mjs +1120 -0
  8. package/lib/index.mjs.map +1 -0
  9. package/lib/rest-api-lambda.handler.d.mts +6 -0
  10. package/lib/rest-api-lambda.handler.d.ts +6 -0
  11. package/lib/rest-api-lambda.handler.js +677 -0
  12. package/lib/rest-api-lambda.handler.js.map +1 -0
  13. package/lib/rest-api-lambda.handler.mjs +646 -0
  14. package/lib/rest-api-lambda.handler.mjs.map +1 -0
  15. package/package.json +37 -28
  16. package/lib/app/index.d.ts +0 -4
  17. package/lib/app/index.js +0 -21
  18. package/lib/app/open-hi-app.d.ts +0 -85
  19. package/lib/app/open-hi-app.js +0 -127
  20. package/lib/app/open-hi-environment.d.ts +0 -59
  21. package/lib/app/open-hi-environment.js +0 -72
  22. package/lib/app/open-hi-service.d.ts +0 -169
  23. package/lib/app/open-hi-service.js +0 -195
  24. package/lib/app/open-hi-stage.d.ts +0 -71
  25. package/lib/app/open-hi-stage.js +0 -70
  26. package/lib/components/acm/root-wildcard-certificate.d.ts +0 -15
  27. package/lib/components/acm/root-wildcard-certificate.js +0 -35
  28. package/lib/components/api-gateway/core-http-api.d.ts +0 -10
  29. package/lib/components/api-gateway/core-http-api.js +0 -44
  30. package/lib/components/api-gateway/http-lambda-integration-no-permissions.d.ts +0 -18
  31. package/lib/components/api-gateway/http-lambda-integration-no-permissions.js +0 -26
  32. package/lib/components/app-sync/core-graphql-api.d.ts +0 -12
  33. package/lib/components/app-sync/core-graphql-api.js +0 -54
  34. package/lib/components/auth.d.ts +0 -75
  35. package/lib/components/auth.js +0 -100
  36. package/lib/components/cognito/core-user-pool-client.d.ts +0 -10
  37. package/lib/components/cognito/core-user-pool-client.js +0 -47
  38. package/lib/components/cognito/core-user-pool-domain.d.ts +0 -10
  39. package/lib/components/cognito/core-user-pool-domain.js +0 -41
  40. package/lib/components/cognito/core-user-pool-kms-key.d.ts +0 -10
  41. package/lib/components/cognito/core-user-pool-kms-key.js +0 -37
  42. package/lib/components/cognito/core-user-pool.d.ts +0 -10
  43. package/lib/components/cognito/core-user-pool.js +0 -54
  44. package/lib/components/core.d.ts +0 -102
  45. package/lib/components/core.js +0 -79
  46. package/lib/components/dynamodb/dynamo-db-data-store.d.ts +0 -33
  47. package/lib/components/dynamodb/dynamo-db-data-store.js +0 -107
  48. package/lib/components/event-bridge/data-event-bus.d.ts +0 -19
  49. package/lib/components/event-bridge/data-event-bus.js +0 -34
  50. package/lib/components/event-bridge/ops-event-bus.d.ts +0 -19
  51. package/lib/components/event-bridge/ops-event-bus.js +0 -34
  52. package/lib/components/global.d.ts +0 -36
  53. package/lib/components/global.js +0 -63
  54. package/lib/components/index.d.ts +0 -1
  55. package/lib/components/index.js +0 -18
  56. package/lib/components/route-53/child-hosted-zone.d.ts +0 -20
  57. package/lib/components/route-53/child-hosted-zone.js +0 -48
  58. package/lib/components/route-53/root-hosted-zone.d.ts +0 -10
  59. package/lib/components/route-53/root-hosted-zone.js +0 -20
  60. package/lib/components/ssm/discoverable-string-parameter.d.ts +0 -59
  61. package/lib/components/ssm/discoverable-string-parameter.js +0 -50
  62. package/lib/components/ssm/index.d.ts +0 -1
  63. package/lib/components/ssm/index.js +0 -18
  64. package/lib/data/dynamo/ehr/r4/Patient.d.ts +0 -180
  65. package/lib/data/dynamo/ehr/r4/Patient.js +0 -192
  66. package/lib/data/dynamo/ehr/r4/ehr-r4-data-service.d.ts +0 -162
  67. package/lib/data/dynamo/ehr/r4/ehr-r4-data-service.js +0 -37
  68. package/lib/data/hello-world.d.ts +0 -39
  69. package/lib/data/hello-world.js +0 -59
  70. package/lib/data/import-patient-with-dynalite.d.ts +0 -1
  71. package/lib/data/import-patient-with-dynalite.js +0 -87
  72. package/lib/data/import-patient.d.ts +0 -47
  73. package/lib/data/import-patient.js +0 -158
  74. package/lib/data/lambda/rest-api-lambda.d.ts +0 -13
  75. package/lib/data/lambda/rest-api-lambda.handler.d.ts +0 -1
  76. package/lib/data/lambda/rest-api-lambda.handler.js +0 -10
  77. package/lib/data/lambda/rest-api-lambda.js +0 -22
  78. package/lib/data/middleware/open-hi-context.d.ts +0 -13
  79. package/lib/data/middleware/open-hi-context.js +0 -31
  80. package/lib/data/rest-api/ehr/r4/Patient.d.ts +0 -16
  81. package/lib/data/rest-api/ehr/r4/Patient.js +0 -234
  82. package/lib/data/rest-api/rest-api-local.d.ts +0 -1
  83. package/lib/data/rest-api/rest-api-local.js +0 -8
  84. package/lib/data/rest-api/rest-api-mockdata.d.ts +0 -7
  85. package/lib/data/rest-api/rest-api-mockdata.js +0 -585
  86. package/lib/data/rest-api/rest-api.d.ts +0 -3
  87. package/lib/data/rest-api/rest-api.js +0 -26
  88. package/lib/lib/compression.d.ts +0 -27
  89. package/lib/lib/compression.js +0 -87
  90. package/lib/services/index.d.ts +0 -5
  91. package/lib/services/index.js +0 -22
  92. package/lib/services/open-hi-auth-service.d.ts +0 -31
  93. package/lib/services/open-hi-auth-service.js +0 -31
  94. package/lib/services/open-hi-core-service.d.ts +0 -15
  95. package/lib/services/open-hi-core-service.js +0 -38
  96. package/lib/services/open-hi-data-service.d.ts +0 -18
  97. package/lib/services/open-hi-data-service.js +0 -18
  98. package/lib/services/open-hi-global-service.d.ts +0 -15
  99. package/lib/services/open-hi-global-service.js +0 -44
  100. package/lib/services/open-hi-rest-api-service.d.ts +0 -17
  101. package/lib/services/open-hi-rest-api-service.js +0 -107
package/lib/index.js CHANGED
@@ -1,20 +1,1134 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./app"), exports);
18
- __exportStar(require("./components"), exports);
19
- __exportStar(require("./services"), exports);
20
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLHdDQUFzQjtBQUN0QiwrQ0FBNkI7QUFDN0IsNkNBQTJCIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSBcIi4vYXBwXCI7XG5leHBvcnQgKiBmcm9tIFwiLi9jb21wb25lbnRzXCI7XG5leHBvcnQgKiBmcm9tIFwiLi9zZXJ2aWNlc1wiO1xuIl19
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
+ DiscoverableStringParameter: () => DiscoverableStringParameter,
97
+ OPEN_HI_SERVICE_TYPE: () => OPEN_HI_SERVICE_TYPE,
98
+ OpenHiApp: () => OpenHiApp,
99
+ OpenHiAuthService: () => OpenHiAuthService,
100
+ OpenHiCoreService: () => OpenHiCoreService,
101
+ OpenHiDataService: () => OpenHiDataService,
102
+ OpenHiEnvironment: () => OpenHiEnvironment,
103
+ OpenHiGlobalService: () => OpenHiGlobalService,
104
+ OpenHiRestApiService: () => OpenHiRestApiService,
105
+ OpenHiService: () => OpenHiService,
106
+ OpenHiStage: () => OpenHiStage,
107
+ REST_API_BASE_URL_SSM_NAME: () => REST_API_BASE_URL_SSM_NAME
108
+ });
109
+ module.exports = __toCommonJS(src_exports);
110
+
111
+ // src/app/open-hi-app.ts
112
+ var import_config2 = __toESM(require_lib());
113
+ var import_aws_cdk_lib3 = require("aws-cdk-lib");
114
+
115
+ // src/app/open-hi-environment.ts
116
+ var import_config = __toESM(require_lib());
117
+ var import_aws_cdk_lib = require("aws-cdk-lib");
118
+ var OPEN_HI_ENVIRONMENT_SYMBOL = /* @__PURE__ */ Symbol.for(
119
+ "@openhi/constructs/core.OpenHiEnvironment"
120
+ );
121
+ var OpenHiEnvironment = class _OpenHiEnvironment extends import_aws_cdk_lib.Stage {
122
+ /**
123
+ * Creates a new OpenHiEnvironment.
124
+ */
125
+ constructor(ohStage, props) {
126
+ if (props.config.account && props.config.region) {
127
+ props = {
128
+ ...props,
129
+ env: {
130
+ account: props.config.account,
131
+ region: props.config.region
132
+ }
133
+ };
134
+ }
135
+ const stageName = props.deploymentTargetRole === import_config.OPEN_HI_DEPLOYMENT_TARGET_ROLE.PRIMARY ? props.deploymentTargetRole : [props.deploymentTargetRole, ohStage.environments.length].join("-");
136
+ super(ohStage, stageName, {
137
+ env: props.env ?? ohStage.props.env,
138
+ ...props
139
+ });
140
+ this.ohStage = ohStage;
141
+ this.props = props;
142
+ Object.defineProperty(this, OPEN_HI_ENVIRONMENT_SYMBOL, { value: true });
143
+ this.deploymentTargetRole = props.deploymentTargetRole;
144
+ this.config = props.config;
145
+ }
146
+ /**
147
+ * Finds the OpenHiEnvironment that contains the given construct.
148
+ * ```
149
+ */
150
+ static of(construct) {
151
+ return construct.node.scopes.reverse().find(_OpenHiEnvironment.isOpenHiEnvironment);
152
+ }
153
+ /**
154
+ * Type guard to check if a value is an OpenHiEnvironment instance.
155
+ */
156
+ static isOpenHiEnvironment(x) {
157
+ return x !== null && typeof x === "object" && OPEN_HI_ENVIRONMENT_SYMBOL in x;
158
+ }
159
+ };
160
+
161
+ // src/app/open-hi-stage.ts
162
+ var import_aws_cdk_lib2 = require("aws-cdk-lib");
163
+ var OPEN_HI_STAGE_SYMBOL = /* @__PURE__ */ Symbol.for("@openhi/constructs/core.OpenHiStage");
164
+ var OpenHiStage = class _OpenHiStage extends import_aws_cdk_lib2.Stage {
165
+ /**
166
+ * Creates a new OpenHiStage instance.
167
+ */
168
+ constructor(ohApp, props) {
169
+ super(ohApp, props.stageType, props);
170
+ this.ohApp = ohApp;
171
+ this.props = props;
172
+ Object.defineProperty(this, OPEN_HI_STAGE_SYMBOL, { value: true });
173
+ this.stageType = props.stageType;
174
+ }
175
+ /**
176
+ * Finds the OpenHiStage that contains the given construct.
177
+ */
178
+ static of(construct) {
179
+ return construct.node.scopes.reverse().find(_OpenHiStage.isOpenHiStage);
180
+ }
181
+ /**
182
+ * Type guard to check if a value is an OpenHiStage instance.
183
+ */
184
+ static isOpenHiStage(x) {
185
+ return x !== null && typeof x === "object" && OPEN_HI_STAGE_SYMBOL in x;
186
+ }
187
+ /**
188
+ * Gets all OpenHiEnvironment instances contained within this stage.
189
+ */
190
+ get environments() {
191
+ return this.node.children.filter(OpenHiEnvironment.isOpenHiEnvironment);
192
+ }
193
+ /**
194
+ * Gets the primary OpenHiEnvironment for this stage, if one exists.
195
+ */
196
+ get primaryEnvironment() {
197
+ return this.environments.find(
198
+ (env) => env.deploymentTargetRole === "primary"
199
+ );
200
+ }
201
+ /**
202
+ * Gets all secondary OpenHiEnvironment instances for this stage.
203
+ */
204
+ get secondaryEnvironments() {
205
+ return this.environments.filter(
206
+ (env) => env.deploymentTargetRole === "secondary"
207
+ );
208
+ }
209
+ };
210
+
211
+ // src/app/open-hi-app.ts
212
+ var OPEN_HI_APP_SYMBOL = /* @__PURE__ */ Symbol.for("@openhi/constructs/core.OpenHiApp");
213
+ var OpenHiApp = class _OpenHiApp extends import_aws_cdk_lib3.App {
214
+ /**
215
+ * Finds the OpenHiApp instance that contains the given construct in its
216
+ * construct tree.
217
+ */
218
+ static of(construct) {
219
+ return construct.node.scopes.reverse().find(_OpenHiApp.isOpenHiApp);
220
+ }
221
+ /**
222
+ * Type guard that checks if a value is an OpenHiApp instance.
223
+ */
224
+ static isOpenHiApp(x) {
225
+ return x !== null && typeof x === "object" && OPEN_HI_APP_SYMBOL in x;
226
+ }
227
+ /**
228
+ * Creates a new OpenHiApp instance.
229
+ */
230
+ constructor(props) {
231
+ super(props);
232
+ Object.defineProperty(this, OPEN_HI_APP_SYMBOL, { value: true });
233
+ this.appName = props.appName ?? "openhi";
234
+ this.config = props.config;
235
+ Object.values(import_config2.OPEN_HI_STAGE).forEach((stageType) => {
236
+ if (this.config.deploymentTargets?.[stageType]) {
237
+ const stage = new OpenHiStage(this, { stageType });
238
+ if (this.config.deploymentTargets?.[stageType]?.[import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.PRIMARY]) {
239
+ const envConfig = this.config.deploymentTargets[stageType][import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.PRIMARY];
240
+ new OpenHiEnvironment(stage, {
241
+ deploymentTargetRole: import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.PRIMARY,
242
+ config: envConfig,
243
+ env: { account: envConfig.account, region: envConfig.region }
244
+ });
245
+ }
246
+ if (this.config.deploymentTargets?.[stageType]?.[import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.SECONDARY]) {
247
+ this.config.deploymentTargets[stageType][import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.SECONDARY].forEach((envConfig) => {
248
+ new OpenHiEnvironment(stage, {
249
+ deploymentTargetRole: import_config2.OPEN_HI_DEPLOYMENT_TARGET_ROLE.SECONDARY,
250
+ config: envConfig,
251
+ env: { account: envConfig.account, region: envConfig.region }
252
+ });
253
+ });
254
+ }
255
+ }
256
+ });
257
+ }
258
+ /*****************************************************************************
259
+ *
260
+ * Stages
261
+ *
262
+ ****************************************************************************/
263
+ /**
264
+ * Gets all OpenHiStage instances that are direct children of this app.
265
+
266
+ */
267
+ get stages() {
268
+ return this.node.children.filter(OpenHiStage.isOpenHiStage);
269
+ }
270
+ /**
271
+ * Gets the development stage, if it exists.
272
+ */
273
+ get devStage() {
274
+ return this.stages.find((stage) => stage.stageType === import_config2.OPEN_HI_STAGE.DEV);
275
+ }
276
+ /**
277
+ * Gets the staging stage, if it exists.
278
+ */
279
+ get stageStage() {
280
+ return this.stages.find((stage) => stage.stageType === import_config2.OPEN_HI_STAGE.STAGE);
281
+ }
282
+ /**
283
+ * Gets the production stage, if it exists.
284
+ */
285
+ get prodStage() {
286
+ return this.stages.find((stage) => stage.stageType === import_config2.OPEN_HI_STAGE.PROD);
287
+ }
288
+ /*****************************************************************************
289
+ *
290
+ * Environments
291
+ *
292
+ ****************************************************************************/
293
+ /**
294
+ * Gets all OpenHiEnvironment instances across all stages in this app.
295
+ */
296
+ get environments() {
297
+ return this.stages.flatMap((stage) => stage.environments);
298
+ }
299
+ /**
300
+ * Gets all primary environments across all stages in this app.
301
+ */
302
+ get primaryEnvironments() {
303
+ return this.environments.filter(
304
+ (env) => env.deploymentTargetRole === "primary"
305
+ );
306
+ }
307
+ /**
308
+ * Gets all secondary environments across all stages in this app.
309
+ */
310
+ get secondaryEnvironments() {
311
+ return this.environments.filter(
312
+ (env) => env.deploymentTargetRole === "secondary"
313
+ );
314
+ }
315
+ };
316
+
317
+ // src/app/open-hi-service.ts
318
+ var import_utils = require("@codedrifters/utils");
319
+ var import_config3 = __toESM(require_lib());
320
+ var import_aws_cdk_lib4 = require("aws-cdk-lib");
321
+ var import_change_case = require("change-case");
322
+ var OPEN_HI_SERVICE_TYPE = {
323
+ /**
324
+ * Authentication service.
325
+ * *
326
+ * Only one instance of the auth service should exist per environment.
327
+ */
328
+ AUTH: "auth",
329
+ /**
330
+ * Root shared core services.
331
+ *
332
+ * Only one instance of the core service should exist per environment.
333
+ */
334
+ CORE: "core",
335
+ /**
336
+ * Rest API service.
337
+ */
338
+ REST_API: "rest-api",
339
+ /**
340
+ * Global Infrastructure stack (Route53, ACM).
341
+ */
342
+ GLOBAL: "global",
343
+ /**
344
+ * Data service (DynamoDB, S3, persistence).
345
+ */
346
+ DATA: "data"
347
+ };
348
+ var OpenHiService = class extends import_aws_cdk_lib4.Stack {
349
+ /**
350
+ * Core construct containing shared infrastructure.
351
+ */
352
+ // public core: Core;
353
+ /**
354
+ * Creates a new OpenHI service stack.
355
+ *
356
+ * @param ohEnv - The OpenHI environment (stage) this service belongs to
357
+ * @param id - Unique identifier for this service stack (e.g., "user-service")
358
+ * @param props - Optional properties for configuring the service
359
+ *
360
+ * @throws {Error} If account and region are not defined in props or environment
361
+ *
362
+ */
363
+ constructor(ohEnv, id, props = {}) {
364
+ const { account, region } = props.env || ohEnv;
365
+ if (!account || !region) {
366
+ throw new Error(
367
+ "Account and region must be defined in OpenHiServiceProps or OpenHiEnvironment"
368
+ );
369
+ }
370
+ const appName = props.appName ?? ohEnv.ohStage.ohApp.appName ?? "openhi";
371
+ const repoName = props.repoName ?? (0, import_utils.findGitRepoName)();
372
+ const defaultReleaseBranch = props.defaultReleaseBranch ?? "main";
373
+ 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);
374
+ const environmentHash = (0, import_utils.hashString)(
375
+ [appName, ohEnv.deploymentTargetRole, account, region].join("-"),
376
+ 6
377
+ );
378
+ const branchHash = (0, import_utils.hashString)(
379
+ [appName, ohEnv.deploymentTargetRole, account, region, branchName].join(
380
+ "-"
381
+ ),
382
+ 6
383
+ );
384
+ const stackHash = (0, import_utils.hashString)(
385
+ [
386
+ appName,
387
+ ohEnv.deploymentTargetRole,
388
+ account,
389
+ region,
390
+ branchName,
391
+ id
392
+ ].join("-"),
393
+ 6
394
+ );
395
+ 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);
396
+ Object.assign(props, { removalPolicy });
397
+ const description = `OpenHi Service: ${id} [${branchName}] - ${branchHash}`;
398
+ const hostedZoneId = ohEnv.props.config.hostedZoneId;
399
+ const zoneName = ohEnv.props.config.zoneName;
400
+ if (hostedZoneId && zoneName) {
401
+ props = {
402
+ ...props,
403
+ coreProps: {
404
+ ...props.coreProps
405
+ }
406
+ };
407
+ }
408
+ super(ohEnv, [branchHash, id, account, region].join("-"), {
409
+ ...props,
410
+ description
411
+ });
412
+ this.ohEnv = ohEnv;
413
+ this.props = props;
414
+ this.serviceId = id;
415
+ this.removalPolicy = removalPolicy;
416
+ this.config = props.config ?? ohEnv.props.config;
417
+ this.serviceType = props.serviceType ?? id;
418
+ this.deploymentTargetRole = ohEnv.deploymentTargetRole;
419
+ this.repoName = repoName;
420
+ this.appName = appName;
421
+ this.defaultReleaseBranch = defaultReleaseBranch;
422
+ this.branchName = branchName;
423
+ this.environmentHash = environmentHash;
424
+ this.branchHash = branchHash;
425
+ this.stackHash = stackHash;
426
+ import_aws_cdk_lib4.Tags.of(this).add(`${appName}:repo-name`, repoName.slice(0, 255));
427
+ import_aws_cdk_lib4.Tags.of(this).add(`${appName}:branch-name`, branchName.slice(0, 255));
428
+ import_aws_cdk_lib4.Tags.of(this).add(
429
+ `${appName}:service-type`,
430
+ this.serviceType.slice(0, 255)
431
+ );
432
+ import_aws_cdk_lib4.Tags.of(this).add(
433
+ `${appName}:stage-type`,
434
+ ohEnv.ohStage.stageType.slice(0, 255)
435
+ );
436
+ }
437
+ /**
438
+ * Creates or returns the core construct for shared infrastructure.
439
+ */
440
+ /*
441
+ protected createCore(props: OpenHiServiceProps = {}): Core {
442
+ if (!this.core) {
443
+ return new Core(this, props.coreProps);
444
+ }
445
+ return this.core;
446
+ }
447
+ */
448
+ /**
449
+ * DNS prefix for this branche's child zone.
450
+ */
451
+ get childZonePrefix() {
452
+ return (0, import_change_case.paramCase)(this.branchName).slice(0, 200);
453
+ }
454
+ };
455
+
456
+ // src/components/ssm/discoverable-string-parameter.ts
457
+ var import_aws_cdk_lib5 = require("aws-cdk-lib");
458
+ var import_aws_ssm = require("aws-cdk-lib/aws-ssm");
459
+ var DiscoverableStringParameter = class _DiscoverableStringParameter extends import_aws_ssm.StringParameter {
460
+ /**
461
+ * Build a param name based on predictable attributes found in services and
462
+ * constructs. Used for storage and retrieval of SSM values across services.
463
+ */
464
+ static buildParameterName(scope, props) {
465
+ const stack = OpenHiService.of(scope);
466
+ return "/" + [
467
+ props.branchHash ?? stack.branchHash,
468
+ props.serviceType ?? stack.serviceType,
469
+ props.account ?? stack.account,
470
+ props.region ?? stack.region,
471
+ props.ssmParamName
472
+ ].join("/").toUpperCase();
473
+ }
474
+ /**
475
+ * Read the string value of an SSM parameter created with DiscoverableStringParameter,
476
+ * using props that include ssmParamName and optional overrides (e.g. serviceType).
477
+ */
478
+ static valueForLookupName(scope, props) {
479
+ const paramName = _DiscoverableStringParameter.buildParameterName(
480
+ scope,
481
+ props
482
+ );
483
+ return import_aws_ssm.StringParameter.valueForStringParameter(scope, paramName);
484
+ }
485
+ constructor(scope, id, props) {
486
+ const { ssmParamName, branchHash, serviceType, account, region, ...rest } = props;
487
+ const parameterName = _DiscoverableStringParameter.buildParameterName(
488
+ scope,
489
+ props
490
+ );
491
+ super(scope, id, {
492
+ ...rest,
493
+ parameterName
494
+ });
495
+ const { appName } = OpenHiService.of(scope);
496
+ import_aws_cdk_lib5.Tags.of(this).add(`${appName}:param-name`, ssmParamName);
497
+ }
498
+ };
499
+
500
+ // src/services/open-hi-core-service.ts
501
+ var import_aws_lambda = require("aws-cdk-lib/aws-lambda");
502
+ var OpenHiCoreService = class extends OpenHiService {
503
+ constructor(ohEnv, props = {}) {
504
+ props = {
505
+ ...props
506
+ };
507
+ super(ohEnv, OPEN_HI_SERVICE_TYPE.CORE, props);
508
+ this.props = props;
509
+ new import_aws_lambda.Function(this, "test-fn", {
510
+ runtime: import_aws_lambda.Runtime.NODEJS_LATEST,
511
+ handler: "index.handler",
512
+ code: import_aws_lambda.Code.fromInline(
513
+ 'exports.handler = async () => { return {statusCode:200, body:"ok"} }'
514
+ )
515
+ });
516
+ }
517
+ };
518
+
519
+ // src/components/auth.ts
520
+ var import_constructs = require("constructs");
521
+
522
+ // src/components/cognito/core-user-pool.ts
523
+ var import_aws_cognito = require("aws-cdk-lib/aws-cognito");
524
+ var _CoreUserPool = class _CoreUserPool extends import_aws_cognito.UserPool {
525
+ static fromConstruct(scope) {
526
+ const userPoolId = DiscoverableStringParameter.valueForLookupName(scope, {
527
+ ssmParamName: _CoreUserPool.SSM_PARAM_NAME,
528
+ serviceType: OPEN_HI_SERVICE_TYPE.AUTH
529
+ });
530
+ return import_aws_cognito.UserPool.fromUserPoolId(scope, "user-pool", userPoolId);
531
+ }
532
+ constructor(scope, props = {}) {
533
+ const service = OpenHiService.of(scope);
534
+ super(scope, "user-pool", {
535
+ /**
536
+ * Defaults
537
+ */
538
+ selfSignUpEnabled: true,
539
+ signInAliases: {
540
+ email: true
541
+ },
542
+ userVerification: {
543
+ emailSubject: "Verify your email!",
544
+ emailBody: "Your verification code is {####}.",
545
+ emailStyle: import_aws_cognito.VerificationEmailStyle.CODE
546
+ },
547
+ removalPolicy: props.removalPolicy ?? service.removalPolicy,
548
+ /**
549
+ * Over-rideable props
550
+ */
551
+ ...props,
552
+ /**
553
+ * Required
554
+ */
555
+ userPoolName: ["core", "user", "pool", service.branchHash].join("-")
556
+ });
557
+ new DiscoverableStringParameter(this, "user-pool-param", {
558
+ ssmParamName: _CoreUserPool.SSM_PARAM_NAME,
559
+ stringValue: this.userPoolId
560
+ });
561
+ }
562
+ };
563
+ /**
564
+ * Used when storing the User Pool ID in SSM.
565
+ */
566
+ _CoreUserPool.SSM_PARAM_NAME = "CORE_USER_POOL";
567
+ var CoreUserPool = _CoreUserPool;
568
+
569
+ // src/components/cognito/core-user-pool-client.ts
570
+ var import_aws_cognito2 = require("aws-cdk-lib/aws-cognito");
571
+ var _CoreUserPoolClient = class _CoreUserPoolClient extends import_aws_cognito2.UserPoolClient {
572
+ static fromConstruct(scope) {
573
+ const userPoolClientId = DiscoverableStringParameter.valueForLookupName(
574
+ scope,
575
+ {
576
+ ssmParamName: _CoreUserPoolClient.SSM_PARAM_NAME,
577
+ serviceType: OPEN_HI_SERVICE_TYPE.AUTH
578
+ }
579
+ );
580
+ return import_aws_cognito2.UserPoolClient.fromUserPoolClientId(
581
+ scope,
582
+ "user-pool-client",
583
+ userPoolClientId
584
+ );
585
+ }
586
+ constructor(scope, props) {
587
+ super(scope, "user-pool-client", {
588
+ /**
589
+ * Defaults
590
+ */
591
+ generateSecret: false,
592
+ oAuth: {
593
+ flows: {
594
+ authorizationCodeGrant: true,
595
+ implicitCodeGrant: true
596
+ },
597
+ callbackUrls: [`https://localhost:3000/oauth/callback`]
598
+ },
599
+ /**
600
+ * Overrideable props
601
+ */
602
+ ...props
603
+ });
604
+ new DiscoverableStringParameter(this, "user-pool-client-param", {
605
+ ssmParamName: _CoreUserPoolClient.SSM_PARAM_NAME,
606
+ stringValue: this.userPoolClientId
607
+ });
608
+ }
609
+ };
610
+ /**
611
+ * Used when storing the User Pool Client ID in SSM.
612
+ */
613
+ _CoreUserPoolClient.SSM_PARAM_NAME = "CORE_USER_POOL_CLIENT";
614
+ var CoreUserPoolClient = _CoreUserPoolClient;
615
+
616
+ // src/components/cognito/core-user-pool-domain.ts
617
+ var import_aws_cognito3 = require("aws-cdk-lib/aws-cognito");
618
+ var _CoreUserPoolDomain = class _CoreUserPoolDomain extends import_aws_cognito3.UserPoolDomain {
619
+ static fromConstruct(scope) {
620
+ const userPoolDomain = DiscoverableStringParameter.valueForLookupName(
621
+ scope,
622
+ {
623
+ ssmParamName: _CoreUserPoolDomain.SSM_PARAM_NAME,
624
+ serviceType: OPEN_HI_SERVICE_TYPE.AUTH
625
+ }
626
+ );
627
+ return import_aws_cognito3.UserPoolDomain.fromDomainName(
628
+ scope,
629
+ "user-pool-domain",
630
+ userPoolDomain
631
+ );
632
+ }
633
+ constructor(scope, props) {
634
+ const id = props.cognitoDomain?.domainPrefix ? "cognito-domain" : "custom-domain";
635
+ super(scope, id, {
636
+ ...props
637
+ });
638
+ new DiscoverableStringParameter(this, "user-pool-domain-param", {
639
+ ssmParamName: _CoreUserPoolDomain.SSM_PARAM_NAME,
640
+ stringValue: this.domainName
641
+ });
642
+ }
643
+ };
644
+ /**
645
+ * Used when storing the User Pool Domain in SSM.
646
+ */
647
+ _CoreUserPoolDomain.SSM_PARAM_NAME = "CORE_USER_POOL_DOMAIN";
648
+ var CoreUserPoolDomain = _CoreUserPoolDomain;
649
+
650
+ // src/components/cognito/core-user-pool-kms-key.ts
651
+ var import_aws_kms = require("aws-cdk-lib/aws-kms");
652
+ var _CoreUserPoolKmsKey = class _CoreUserPoolKmsKey extends import_aws_kms.Key {
653
+ static fromConstruct(scope) {
654
+ const keyArn = DiscoverableStringParameter.valueForLookupName(scope, {
655
+ ssmParamName: _CoreUserPoolKmsKey.SSM_PARAM_NAME,
656
+ serviceType: OPEN_HI_SERVICE_TYPE.AUTH
657
+ });
658
+ return import_aws_kms.Key.fromKeyArn(scope, "kms-key", keyArn);
659
+ }
660
+ constructor(scope, props = {}) {
661
+ const service = OpenHiService.of(scope);
662
+ super(scope, "kms-key", {
663
+ ...props,
664
+ // alias: ["alias", "cognito", service.branchHash].join("/"),
665
+ description: `KMS Key for Cognito User Pool - ${service.branchHash}`,
666
+ removalPolicy: props.removalPolicy ?? service.removalPolicy
667
+ });
668
+ new DiscoverableStringParameter(this, "kms-key-param", {
669
+ ssmParamName: _CoreUserPoolKmsKey.SSM_PARAM_NAME,
670
+ stringValue: this.keyArn
671
+ });
672
+ }
673
+ };
674
+ /**
675
+ * Used when storing the KMS Key in SSM.
676
+ */
677
+ _CoreUserPoolKmsKey.SSM_PARAM_NAME = "CORE_USER_POOL_KMS_KEY";
678
+ var CoreUserPoolKmsKey = _CoreUserPoolKmsKey;
679
+
680
+ // src/components/auth.ts
681
+ var Auth = class _Auth extends import_constructs.Construct {
682
+ /**
683
+ * Returns an Auth instance that uses resources imported from AUTH SSM
684
+ * parameters. Use this when creating Core or other stacks that consume
685
+ * auth resources; the Auth stack must be deployed first.
686
+ *
687
+ * @param scope - Construct scope (e.g. Core); must be in a stack that has
688
+ * access to the same account/region as the deployed Auth stack.
689
+ */
690
+ static fromConstruct(scope) {
691
+ return new _Auth(scope, {});
692
+ }
693
+ constructor(scope, props = {}) {
694
+ super(scope, "auth");
695
+ const service = OpenHiService.of(this);
696
+ this.isAuthService = service.serviceType === OPEN_HI_SERVICE_TYPE.AUTH;
697
+ this.userPoolKmsKey = this.createUserPoolKmsKey();
698
+ this.userPool = this.createUserPool({
699
+ ...props.userPoolProps,
700
+ customSenderKmsKey: this.userPoolKmsKey
701
+ });
702
+ this.userPoolClient = this.createUserPoolClient({
703
+ userPool: this.userPool
704
+ });
705
+ this.userPoolDomain = this.createUserPoolDomain({
706
+ userPool: this.userPool
707
+ });
708
+ }
709
+ /*****************************************************************************
710
+ *
711
+ * Auth Support
712
+ *
713
+ ****************************************************************************/
714
+ createUserPoolKmsKey() {
715
+ return this.isAuthService ? new CoreUserPoolKmsKey(this) : CoreUserPoolKmsKey.fromConstruct(this);
716
+ }
717
+ createUserPool(props) {
718
+ return this.isAuthService ? new CoreUserPool(this, props) : CoreUserPool.fromConstruct(this);
719
+ }
720
+ createUserPoolClient(props) {
721
+ return this.isAuthService ? new CoreUserPoolClient(this, { userPool: props.userPool }) : CoreUserPoolClient.fromConstruct(this);
722
+ }
723
+ createUserPoolDomain(props) {
724
+ const service = OpenHiService.of(this);
725
+ return this.isAuthService ? new CoreUserPoolDomain(this, {
726
+ userPool: props.userPool,
727
+ cognitoDomain: {
728
+ domainPrefix: `auth-${service.branchHash}`
729
+ }
730
+ }) : CoreUserPoolDomain.fromConstruct(this);
731
+ }
732
+ };
733
+
734
+ // src/services/open-hi-auth-service.ts
735
+ var OpenHiAuthService = class extends OpenHiService {
736
+ constructor(ohEnv, props = {}) {
737
+ super(ohEnv, OPEN_HI_SERVICE_TYPE.AUTH, props);
738
+ this.props = props;
739
+ this.auth = new Auth(this, props.authProps);
740
+ }
741
+ };
742
+
743
+ // src/components/global.ts
744
+ var import_aws_certificatemanager2 = require("aws-cdk-lib/aws-certificatemanager");
745
+ var import_constructs3 = require("constructs");
746
+
747
+ // src/components/acm/root-wildcard-certificate.ts
748
+ var import_aws_certificatemanager = require("aws-cdk-lib/aws-certificatemanager");
749
+ var import_aws_ssm2 = require("aws-cdk-lib/aws-ssm");
750
+ var _RootWildcardCertificate = class _RootWildcardCertificate extends import_aws_certificatemanager.Certificate {
751
+ /**
752
+ * Using a special name here since this will be shared and used among many
753
+ * stacks and services.
754
+ */
755
+ static ssmParameterName() {
756
+ return "/" + ["GLOBAL", _RootWildcardCertificate.SSM_PARAM_NAME].join("/").toUpperCase();
757
+ }
758
+ static fromConstruct(scope) {
759
+ const certificateArn = import_aws_ssm2.StringParameter.valueForStringParameter(
760
+ scope,
761
+ _RootWildcardCertificate.ssmParameterName()
762
+ );
763
+ return import_aws_certificatemanager.Certificate.fromCertificateArn(
764
+ scope,
765
+ "wildcard-certificate",
766
+ certificateArn
767
+ );
768
+ }
769
+ constructor(scope, props) {
770
+ super(scope, "root-wildcard-certificate", { ...props });
771
+ new import_aws_ssm2.StringParameter(this, "wildcard-cert-param", {
772
+ parameterName: _RootWildcardCertificate.ssmParameterName(),
773
+ stringValue: this.certificateArn
774
+ });
775
+ }
776
+ };
777
+ /**
778
+ * Used when storing the Certificate ARN in SSM.
779
+ */
780
+ _RootWildcardCertificate.SSM_PARAM_NAME = "ROOT_WILDCARD_CERT_ARN";
781
+ var RootWildcardCertificate = _RootWildcardCertificate;
782
+
783
+ // src/components/route-53/child-hosted-zone.ts
784
+ var import_aws_cdk_lib6 = require("aws-cdk-lib");
785
+ var import_aws_route53 = require("aws-cdk-lib/aws-route53");
786
+ var _ChildHostedZone = class _ChildHostedZone extends import_aws_route53.HostedZone {
787
+ static fromConstruct(scope, props) {
788
+ const hostedZoneId = DiscoverableStringParameter.valueForLookupName(scope, {
789
+ ssmParamName: _ChildHostedZone.SSM_PARAM_NAME,
790
+ serviceType: props.serviceType ?? OPEN_HI_SERVICE_TYPE.GLOBAL
791
+ });
792
+ return import_aws_route53.HostedZone.fromHostedZoneAttributes(scope, "child-zone", {
793
+ hostedZoneId,
794
+ zoneName: props.zoneName
795
+ });
796
+ }
797
+ constructor(scope, id, props) {
798
+ super(scope, id, { ...props });
799
+ new import_aws_route53.NsRecord(this, "child-ns-record", {
800
+ zone: props.parentHostedZone,
801
+ recordName: this.zoneName,
802
+ values: this.hostedZoneNameServers || [],
803
+ ttl: import_aws_cdk_lib6.Duration.minutes(5)
804
+ });
805
+ new DiscoverableStringParameter(this, "child-zone-param", {
806
+ ssmParamName: _ChildHostedZone.SSM_PARAM_NAME,
807
+ stringValue: this.hostedZoneId,
808
+ description: "Route53 child hosted zone ID."
809
+ });
810
+ }
811
+ };
812
+ /**
813
+ * Used when storing the API ID in SSM.
814
+ */
815
+ _ChildHostedZone.SSM_PARAM_NAME = "CHILDHOSTEDZONE";
816
+ var ChildHostedZone = _ChildHostedZone;
817
+
818
+ // src/components/route-53/root-hosted-zone.ts
819
+ var import_aws_route532 = require("aws-cdk-lib/aws-route53");
820
+ var import_constructs2 = require("constructs");
821
+ var RootHostedZone = class extends import_constructs2.Construct {
822
+ static fromConstruct(scope, props) {
823
+ return import_aws_route532.HostedZone.fromHostedZoneAttributes(scope, "root-zone", {
824
+ hostedZoneId: props.hostedZoneId,
825
+ zoneName: props.zoneName
826
+ });
827
+ }
828
+ };
829
+
830
+ // src/components/global.ts
831
+ var Global = class extends import_constructs3.Construct {
832
+ constructor(scope, id, props) {
833
+ super(scope, id);
834
+ this.props = props;
835
+ const { rootHostedZoneAttributes, childHostedZoneAttributes } = props;
836
+ const service = OpenHiService.of(this);
837
+ this.rootHostedZone = RootHostedZone.fromConstruct(
838
+ this,
839
+ rootHostedZoneAttributes
840
+ );
841
+ if (childHostedZoneAttributes) {
842
+ this.childHostedZone = new ChildHostedZone(this, "child-zone", {
843
+ parentHostedZone: this.rootHostedZone,
844
+ zoneName: childHostedZoneAttributes.zoneName
845
+ });
846
+ }
847
+ if (service.branchName === "main") {
848
+ this.rootWildcardCertificate = new RootWildcardCertificate(this, {
849
+ domainName: `*.${this.rootHostedZone.zoneName}`,
850
+ subjectAlternativeNames: [this.rootHostedZone.zoneName],
851
+ validation: import_aws_certificatemanager2.CertificateValidation.fromDns(this.rootHostedZone)
852
+ });
853
+ } else {
854
+ this.rootWildcardCertificate = RootWildcardCertificate.fromConstruct(this);
855
+ }
856
+ }
857
+ };
858
+
859
+ // src/services/open-hi-global-service.ts
860
+ var OpenHiGlobalService = class extends OpenHiService {
861
+ constructor(ohEnv, props = {}) {
862
+ super(ohEnv, OPEN_HI_SERVICE_TYPE.GLOBAL, props);
863
+ const { config } = props;
864
+ if (!config) {
865
+ throw new Error("Config is required");
866
+ }
867
+ if (!config.zoneName) {
868
+ throw new Error("Zone name is required to import the root zone");
869
+ }
870
+ if (!config.hostedZoneId) {
871
+ throw new Error("Hosted zone ID is required to import the root zone");
872
+ }
873
+ this.global = new Global(this, "global", {
874
+ rootHostedZoneAttributes: {
875
+ zoneName: config.zoneName,
876
+ hostedZoneId: config.hostedZoneId
877
+ }
878
+ /*
879
+ childHostedZoneAttributes: {
880
+ zoneName: `${this.childZonePrefix}.${config.zoneName}`,
881
+ hostedZoneId: config.hostedZoneId,
882
+ },
883
+ */
884
+ });
885
+ }
886
+ };
887
+
888
+ // src/services/open-hi-rest-api-service.ts
889
+ var import_aws_apigatewayv22 = require("aws-cdk-lib/aws-apigatewayv2");
890
+ var import_aws_apigatewayv2_integrations = require("aws-cdk-lib/aws-apigatewayv2-integrations");
891
+ var import_aws_route533 = require("aws-cdk-lib/aws-route53");
892
+ var import_aws_route53_targets = require("aws-cdk-lib/aws-route53-targets");
893
+
894
+ // src/components/api-gateway/core-http-api.ts
895
+ var import_aws_apigatewayv2 = require("aws-cdk-lib/aws-apigatewayv2");
896
+ var _CoreHttpApi = class _CoreHttpApi extends import_aws_apigatewayv2.HttpApi {
897
+ static fromConstruct(scope) {
898
+ const httpApiId = DiscoverableStringParameter.valueForLookupName(scope, {
899
+ ssmParamName: _CoreHttpApi.SSM_PARAM_NAME,
900
+ serviceType: OPEN_HI_SERVICE_TYPE.REST_API
901
+ });
902
+ return import_aws_apigatewayv2.HttpApi.fromHttpApiAttributes(scope, "http-api", {
903
+ httpApiId
904
+ });
905
+ }
906
+ constructor(scope, props = {}) {
907
+ const stack = OpenHiService.of(scope);
908
+ super(scope, "http-api", {
909
+ /**
910
+ * User provided props
911
+ */
912
+ ...props,
913
+ /**
914
+ * Required
915
+ */
916
+ apiName: ["core", "http", "api", stack.branchHash].join("-")
917
+ });
918
+ new DiscoverableStringParameter(this, "http-api-url-param", {
919
+ ssmParamName: _CoreHttpApi.SSM_PARAM_NAME,
920
+ serviceType: OPEN_HI_SERVICE_TYPE.REST_API,
921
+ stringValue: this.httpApiId
922
+ });
923
+ }
924
+ };
925
+ /**
926
+ * Used when storing the API ID in SSM.
927
+ */
928
+ _CoreHttpApi.SSM_PARAM_NAME = "CORE_HTTP_API";
929
+ var CoreHttpApi = _CoreHttpApi;
930
+
931
+ // src/components/dynamodb/dynamo-db-data-store.ts
932
+ var import_aws_dynamodb = require("aws-cdk-lib/aws-dynamodb");
933
+ function getDynamoDbDataStoreTableName(scope) {
934
+ const stack = OpenHiService.of(scope);
935
+ return `data-store-${stack.branchHash}`;
936
+ }
937
+ var DynamoDbDataStore = class extends import_aws_dynamodb.Table {
938
+ /**
939
+ * Import the data store table by name for use in another stack (e.g. data
940
+ * service or Lambda). Uses the same naming as {@link getDynamoDbDataStoreTableName}.
941
+ */
942
+ static fromConstruct(scope, id = "dynamo-db-data-store") {
943
+ return import_aws_dynamodb.Table.fromTableName(scope, id, getDynamoDbDataStoreTableName(scope));
944
+ }
945
+ constructor(scope, id, props = {}) {
946
+ const service = OpenHiService.of(scope);
947
+ super(scope, id, {
948
+ ...props,
949
+ tableName: getDynamoDbDataStoreTableName(scope),
950
+ partitionKey: {
951
+ name: "PK",
952
+ type: import_aws_dynamodb.AttributeType.STRING
953
+ },
954
+ sortKey: {
955
+ name: "SK",
956
+ type: import_aws_dynamodb.AttributeType.STRING
957
+ },
958
+ billingMode: import_aws_dynamodb.BillingMode.PAY_PER_REQUEST,
959
+ removalPolicy: props.removalPolicy ?? service.removalPolicy
960
+ });
961
+ this.addGlobalSecondaryIndex({
962
+ indexName: "GSI1",
963
+ partitionKey: {
964
+ name: "GSI1PK",
965
+ type: import_aws_dynamodb.AttributeType.STRING
966
+ },
967
+ sortKey: {
968
+ name: "GSI1SK",
969
+ type: import_aws_dynamodb.AttributeType.STRING
970
+ },
971
+ projectionType: import_aws_dynamodb.ProjectionType.INCLUDE,
972
+ nonKeyAttributes: ["srcType", "srcId", "path", "srcPk", "srcSk", "ts"]
973
+ });
974
+ this.addGlobalSecondaryIndex({
975
+ indexName: "GSI2",
976
+ partitionKey: {
977
+ name: "GSI2PK",
978
+ type: import_aws_dynamodb.AttributeType.STRING
979
+ },
980
+ sortKey: {
981
+ name: "GSI2SK",
982
+ type: import_aws_dynamodb.AttributeType.STRING
983
+ },
984
+ projectionType: import_aws_dynamodb.ProjectionType.INCLUDE,
985
+ nonKeyAttributes: ["resourcePk", "resourceSk", "display", "status"]
986
+ });
987
+ this.addGlobalSecondaryIndex({
988
+ indexName: "GSI3",
989
+ partitionKey: {
990
+ name: "GSI3PK",
991
+ type: import_aws_dynamodb.AttributeType.STRING
992
+ },
993
+ sortKey: {
994
+ name: "GSI3SK",
995
+ type: import_aws_dynamodb.AttributeType.STRING
996
+ },
997
+ projectionType: import_aws_dynamodb.ProjectionType.INCLUDE,
998
+ nonKeyAttributes: ["resourcePk", "resourceSk"]
999
+ });
1000
+ this.addGlobalSecondaryIndex({
1001
+ indexName: "GSI4",
1002
+ partitionKey: {
1003
+ name: "GSI4PK",
1004
+ type: import_aws_dynamodb.AttributeType.STRING
1005
+ },
1006
+ sortKey: {
1007
+ name: "GSI4SK",
1008
+ type: import_aws_dynamodb.AttributeType.STRING
1009
+ },
1010
+ projectionType: import_aws_dynamodb.ProjectionType.ALL
1011
+ });
1012
+ }
1013
+ };
1014
+
1015
+ // src/data/lambda/rest-api-lambda.ts
1016
+ var import_path = __toESM(require("path"));
1017
+ var import_aws_lambda2 = require("aws-cdk-lib/aws-lambda");
1018
+ var import_aws_lambda_nodejs = require("aws-cdk-lib/aws-lambda-nodejs");
1019
+ var import_constructs4 = require("constructs");
1020
+ var RestApiLambda = class extends import_constructs4.Construct {
1021
+ constructor(scope, props) {
1022
+ super(scope, "rest-api-lambda");
1023
+ this.lambda = new import_aws_lambda_nodejs.NodejsFunction(this, "handler", {
1024
+ entry: import_path.default.join(__dirname, "rest-api-lambda.handler.js"),
1025
+ runtime: import_aws_lambda2.Runtime.NODEJS_LATEST,
1026
+ environment: {
1027
+ DYNAMO_TABLE_NAME: props.dynamoTableName
1028
+ }
1029
+ });
1030
+ }
1031
+ };
1032
+
1033
+ // src/services/open-hi-rest-api-service.ts
1034
+ var REST_API_BASE_URL_SSM_NAME = "REST_API_BASE_URL";
1035
+ var OpenHiRestApiService = class extends OpenHiService {
1036
+ constructor(ohEnv, props = {}) {
1037
+ super(ohEnv, OPEN_HI_SERVICE_TYPE.REST_API, props);
1038
+ const { config } = props;
1039
+ if (!config) {
1040
+ throw new Error("Config is required");
1041
+ }
1042
+ if (!config.hostedZoneId) {
1043
+ throw new Error("Hosted zone ID is required");
1044
+ }
1045
+ if (!config.zoneName) {
1046
+ throw new Error("Zone name is required");
1047
+ }
1048
+ const hostedZone = import_aws_route533.HostedZone.fromHostedZoneAttributes(this, "root-zone", {
1049
+ hostedZoneId: config.hostedZoneId,
1050
+ zoneName: config.zoneName
1051
+ });
1052
+ const certificate = RootWildcardCertificate.fromConstruct(this);
1053
+ const apiPrefix = this.branchName === "main" ? `api` : `api-${this.childZonePrefix}`;
1054
+ const apiDomainName = [apiPrefix, hostedZone.zoneName].join(".");
1055
+ const restApiBaseUrl = `https://${apiDomainName}`;
1056
+ new DiscoverableStringParameter(this, "rest-api-base-url-param", {
1057
+ ssmParamName: REST_API_BASE_URL_SSM_NAME,
1058
+ stringValue: restApiBaseUrl,
1059
+ description: "REST API base URL for this deployment (E2E, scripts)"
1060
+ });
1061
+ const domainName = new import_aws_apigatewayv22.DomainName(this, "domain", {
1062
+ domainName: apiDomainName,
1063
+ certificate
1064
+ });
1065
+ this.coreHttpApi = new CoreHttpApi(this, {
1066
+ defaultDomainMapping: {
1067
+ domainName,
1068
+ mappingKey: void 0
1069
+ // serve at root of domain
1070
+ }
1071
+ });
1072
+ const dataStoreTable = DynamoDbDataStore.fromConstruct(this);
1073
+ const { lambda } = new RestApiLambda(this, {
1074
+ dynamoTableName: dataStoreTable.tableName
1075
+ });
1076
+ dataStoreTable.grant(
1077
+ lambda,
1078
+ "dynamodb:GetItem",
1079
+ "dynamodb:Query",
1080
+ "dynamodb:BatchGetItem",
1081
+ "dynamodb:ConditionCheckItem",
1082
+ "dynamodb:DescribeTable",
1083
+ "dynamodb:BatchWriteItem",
1084
+ "dynamodb:PutItem",
1085
+ "dynamodb:UpdateItem",
1086
+ "dynamodb:DeleteItem"
1087
+ );
1088
+ const integration = new import_aws_apigatewayv2_integrations.HttpLambdaIntegration("lambda-integration", lambda);
1089
+ new import_aws_apigatewayv22.HttpRoute(this, "proxy-route-root", {
1090
+ httpApi: this.coreHttpApi,
1091
+ routeKey: import_aws_apigatewayv22.HttpRouteKey.with("/", import_aws_apigatewayv22.HttpMethod.ANY),
1092
+ integration
1093
+ });
1094
+ new import_aws_apigatewayv22.HttpRoute(this, "proxy-route", {
1095
+ httpApi: this.coreHttpApi,
1096
+ routeKey: import_aws_apigatewayv22.HttpRouteKey.with("/{proxy+}", import_aws_apigatewayv22.HttpMethod.ANY),
1097
+ integration
1098
+ });
1099
+ new import_aws_route533.ARecord(this, "api-a-record", {
1100
+ zone: hostedZone,
1101
+ recordName: apiPrefix,
1102
+ target: import_aws_route533.RecordTarget.fromAlias(
1103
+ new import_aws_route53_targets.ApiGatewayv2DomainProperties(
1104
+ domainName.regionalDomainName,
1105
+ domainName.regionalHostedZoneId
1106
+ )
1107
+ )
1108
+ });
1109
+ }
1110
+ };
1111
+
1112
+ // src/services/open-hi-data-service.ts
1113
+ var OpenHiDataService = class extends OpenHiService {
1114
+ constructor(ohEnv, props = {}) {
1115
+ super(ohEnv, OPEN_HI_SERVICE_TYPE.DATA, props);
1116
+ this.dataStore = new DynamoDbDataStore(this, "dynamo-db-data-store");
1117
+ }
1118
+ };
1119
+ // Annotate the CommonJS export names for ESM import in node:
1120
+ 0 && (module.exports = {
1121
+ DiscoverableStringParameter,
1122
+ OPEN_HI_SERVICE_TYPE,
1123
+ OpenHiApp,
1124
+ OpenHiAuthService,
1125
+ OpenHiCoreService,
1126
+ OpenHiDataService,
1127
+ OpenHiEnvironment,
1128
+ OpenHiGlobalService,
1129
+ OpenHiRestApiService,
1130
+ OpenHiService,
1131
+ OpenHiStage,
1132
+ REST_API_BASE_URL_SSM_NAME
1133
+ });
1134
+ //# sourceMappingURL=index.js.map