@openhi/constructs 0.0.91 → 0.0.92

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/index.mjs CHANGED
@@ -699,13 +699,13 @@ var PostAuthenticationLambda = class extends Construct {
699
699
  }
700
700
  };
701
701
 
702
- // src/components/cognito/pre-token-generation-lambda.ts
702
+ // src/components/cognito/post-confirmation-lambda.ts
703
703
  import fs2 from "fs";
704
704
  import path2 from "path";
705
705
  import { Runtime as Runtime2 } from "aws-cdk-lib/aws-lambda";
706
706
  import { NodejsFunction as NodejsFunction2 } from "aws-cdk-lib/aws-lambda-nodejs";
707
707
  import { Construct as Construct2 } from "constructs";
708
- var HANDLER_NAME2 = "pre-token-generation.handler.js";
708
+ var HANDLER_NAME2 = "post-confirmation.handler.js";
709
709
  function resolveHandlerEntry2(dirname) {
710
710
  const sameDir = path2.join(dirname, HANDLER_NAME2);
711
711
  if (fs2.existsSync(sameDir)) {
@@ -714,35 +714,64 @@ function resolveHandlerEntry2(dirname) {
714
714
  const fromLib = path2.join(dirname, "..", "..", "..", "lib", HANDLER_NAME2);
715
715
  return fromLib;
716
716
  }
717
- var PreTokenGenerationLambda = class extends Construct2 {
718
- constructor(scope) {
719
- super(scope, "pre-token-generation-lambda");
717
+ var PostConfirmationLambda = class extends Construct2 {
718
+ constructor(scope, props) {
719
+ super(scope, "post-confirmation-lambda");
720
720
  this.lambda = new NodejsFunction2(this, "handler", {
721
721
  entry: resolveHandlerEntry2(__dirname),
722
722
  runtime: Runtime2.NODEJS_LATEST,
723
- memorySize: 1024
723
+ memorySize: 1024,
724
+ environment: {
725
+ DYNAMO_TABLE_NAME: props.dynamoTableName
726
+ }
724
727
  });
725
728
  }
726
729
  };
727
730
 
728
- // src/components/dynamodb/data-store-historical-archive.ts
731
+ // src/components/cognito/pre-token-generation-lambda.ts
729
732
  import fs3 from "fs";
730
733
  import path3 from "path";
731
- import { Duration as Duration2, RemovalPolicy as RemovalPolicy2, Size } from "aws-cdk-lib";
732
- import * as kinesisfirehose from "aws-cdk-lib/aws-kinesisfirehose";
733
734
  import { Runtime as Runtime3 } from "aws-cdk-lib/aws-lambda";
734
735
  import { NodejsFunction as NodejsFunction3 } from "aws-cdk-lib/aws-lambda-nodejs";
735
- import * as s3 from "aws-cdk-lib/aws-s3";
736
736
  import { Construct as Construct3 } from "constructs";
737
- var HANDLER_NAME3 = "firehose-archive-transform.handler.js";
737
+ var HANDLER_NAME3 = "pre-token-generation.handler.js";
738
738
  function resolveHandlerEntry3(dirname) {
739
739
  const sameDir = path3.join(dirname, HANDLER_NAME3);
740
740
  if (fs3.existsSync(sameDir)) {
741
741
  return sameDir;
742
742
  }
743
- return path3.join(dirname, "..", "..", "..", "lib", HANDLER_NAME3);
743
+ const fromLib = path3.join(dirname, "..", "..", "..", "lib", HANDLER_NAME3);
744
+ return fromLib;
744
745
  }
745
- var DataStoreHistoricalArchive = class extends Construct3 {
746
+ var PreTokenGenerationLambda = class extends Construct3 {
747
+ constructor(scope) {
748
+ super(scope, "pre-token-generation-lambda");
749
+ this.lambda = new NodejsFunction3(this, "handler", {
750
+ entry: resolveHandlerEntry3(__dirname),
751
+ runtime: Runtime3.NODEJS_LATEST,
752
+ memorySize: 1024
753
+ });
754
+ }
755
+ };
756
+
757
+ // src/components/dynamodb/data-store-historical-archive.ts
758
+ import fs4 from "fs";
759
+ import path4 from "path";
760
+ import { Duration as Duration2, RemovalPolicy as RemovalPolicy2, Size } from "aws-cdk-lib";
761
+ import * as kinesisfirehose from "aws-cdk-lib/aws-kinesisfirehose";
762
+ import { Runtime as Runtime4 } from "aws-cdk-lib/aws-lambda";
763
+ import { NodejsFunction as NodejsFunction4 } from "aws-cdk-lib/aws-lambda-nodejs";
764
+ import * as s3 from "aws-cdk-lib/aws-s3";
765
+ import { Construct as Construct4 } from "constructs";
766
+ var HANDLER_NAME4 = "firehose-archive-transform.handler.js";
767
+ function resolveHandlerEntry4(dirname) {
768
+ const sameDir = path4.join(dirname, HANDLER_NAME4);
769
+ if (fs4.existsSync(sameDir)) {
770
+ return sameDir;
771
+ }
772
+ return path4.join(dirname, "..", "..", "..", "lib", HANDLER_NAME4);
773
+ }
774
+ var DataStoreHistoricalArchive = class extends Construct4 {
746
775
  constructor(scope, id, props) {
747
776
  super(scope, id);
748
777
  this.archiveBucket = new s3.Bucket(this, "ArchiveBucket", {
@@ -762,9 +791,9 @@ var DataStoreHistoricalArchive = class extends Construct3 {
762
791
  versioned: false
763
792
  }) : void 0;
764
793
  this.putEventsFailureDlqBucket = putEventsFailureDlqBucket;
765
- this.transformFunction = new NodejsFunction3(this, "FirehoseTransform", {
766
- entry: resolveHandlerEntry3(__dirname),
767
- runtime: Runtime3.NODEJS_LATEST,
794
+ this.transformFunction = new NodejsFunction4(this, "FirehoseTransform", {
795
+ entry: resolveHandlerEntry4(__dirname),
796
+ runtime: Runtime4.NODEJS_LATEST,
768
797
  memorySize: 512,
769
798
  timeout: Duration2.minutes(1),
770
799
  description: "Firehose transform: filter CURRENT resource rows, S3 keys, EventBridge PutEvents",
@@ -947,27 +976,27 @@ var OpsEventBus = class _OpsEventBus extends EventBus2 {
947
976
  };
948
977
 
949
978
  // src/components/postgres/data-store-postgres-replica.ts
950
- import fs4 from "fs";
951
- import path4 from "path";
979
+ import fs5 from "fs";
980
+ import path5 from "path";
952
981
  import { Duration as Duration3, Stack as Stack2 } from "aws-cdk-lib";
953
982
  import * as ec2 from "aws-cdk-lib/aws-ec2";
954
- import { Runtime as Runtime4, StartingPosition } from "aws-cdk-lib/aws-lambda";
983
+ import { Runtime as Runtime5, StartingPosition } from "aws-cdk-lib/aws-lambda";
955
984
  import { KinesisEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
956
- import { NodejsFunction as NodejsFunction4 } from "aws-cdk-lib/aws-lambda-nodejs";
985
+ import { NodejsFunction as NodejsFunction5 } from "aws-cdk-lib/aws-lambda-nodejs";
957
986
  import * as rds from "aws-cdk-lib/aws-rds";
958
- import { Construct as Construct4 } from "constructs";
959
- var HANDLER_NAME4 = "data-store-postgres-replication.handler.js";
987
+ import { Construct as Construct5 } from "constructs";
988
+ var HANDLER_NAME5 = "data-store-postgres-replication.handler.js";
960
989
  var DEFAULT_DATABASE_NAME = "openhi";
961
990
  var SCHEMA_NAME_PATTERN = /^[a-z_][a-z0-9_]{0,62}$/;
962
991
  var POSTGRES_REPLICA_CLUSTER_ARN_SSM_NAME = "POSTGRES_REPLICA_CLUSTER_ARN";
963
992
  var POSTGRES_REPLICA_SECRET_ARN_SSM_NAME = "POSTGRES_REPLICA_SECRET_ARN";
964
993
  var POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME = "POSTGRES_REPLICA_DATABASE_NAME";
965
- function resolveHandlerEntry4(dirname) {
966
- const sameDir = path4.join(dirname, HANDLER_NAME4);
967
- if (fs4.existsSync(sameDir)) {
994
+ function resolveHandlerEntry5(dirname) {
995
+ const sameDir = path5.join(dirname, HANDLER_NAME5);
996
+ if (fs5.existsSync(sameDir)) {
968
997
  return sameDir;
969
998
  }
970
- return path4.join(dirname, "..", "..", "..", "lib", HANDLER_NAME4);
999
+ return path5.join(dirname, "..", "..", "..", "lib", HANDLER_NAME5);
971
1000
  }
972
1001
  function getPostgresReplicaSchemaName(branchHash) {
973
1002
  const candidate = `b_${branchHash.toLowerCase()}`;
@@ -978,7 +1007,7 @@ function getPostgresReplicaSchemaName(branchHash) {
978
1007
  }
979
1008
  return candidate;
980
1009
  }
981
- var DataStorePostgresReplica = class extends Construct4 {
1010
+ var DataStorePostgresReplica = class extends Construct5 {
982
1011
  /**
983
1012
  * Resolve the cluster ARN published by an upstream {@link DataStorePostgresReplica}.
984
1013
  * Use from any stack that needs to grant `rds-data:ExecuteStatement` against
@@ -1047,9 +1076,9 @@ var DataStorePostgresReplica = class extends Construct4 {
1047
1076
  enableDataApi: true
1048
1077
  });
1049
1078
  this.publishCoordinatesToSsm();
1050
- this.replicationFunction = new NodejsFunction4(this, "ReplicationFunction", {
1051
- entry: resolveHandlerEntry4(__dirname),
1052
- runtime: Runtime4.NODEJS_LATEST,
1079
+ this.replicationFunction = new NodejsFunction5(this, "ReplicationFunction", {
1080
+ entry: resolveHandlerEntry5(__dirname),
1081
+ runtime: Runtime5.NODEJS_LATEST,
1053
1082
  memorySize: 512,
1054
1083
  timeout: Duration3.minutes(1),
1055
1084
  vpc: this.vpc,
@@ -1133,8 +1162,8 @@ var ChildHostedZone = class extends HostedZone {
1133
1162
  ChildHostedZone.SSM_PARAM_NAME = "CHILDHOSTEDZONE";
1134
1163
 
1135
1164
  // src/components/route-53/root-hosted-zone.ts
1136
- import { Construct as Construct5 } from "constructs";
1137
- var RootHostedZone = class extends Construct5 {
1165
+ import { Construct as Construct6 } from "constructs";
1166
+ var RootHostedZone = class extends Construct6 {
1138
1167
  };
1139
1168
 
1140
1169
  // src/components/static-hosting/static-hosting.ts
@@ -1145,9 +1174,9 @@ import {
1145
1174
  import { S3BucketOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
1146
1175
  import { Bucket as Bucket2 } from "aws-cdk-lib/aws-s3";
1147
1176
  import { Duration as Duration5 } from "aws-cdk-lib/core";
1148
- import { Construct as Construct6 } from "constructs";
1177
+ import { Construct as Construct7 } from "constructs";
1149
1178
  var STATIC_HOSTING_SERVICE_TYPE = "website";
1150
- var _StaticHosting = class _StaticHosting extends Construct6 {
1179
+ var _StaticHosting = class _StaticHosting extends Construct7 {
1151
1180
  constructor(scope, id, props = {}) {
1152
1181
  super(scope, id);
1153
1182
  const stack = OpenHiService.of(scope);
@@ -1207,10 +1236,134 @@ import {
1207
1236
  UserPoolDomain as UserPoolDomain2,
1208
1237
  UserPoolOperation
1209
1238
  } from "aws-cdk-lib/aws-cognito";
1210
- import { PolicyStatement } from "aws-cdk-lib/aws-iam";
1239
+ import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
1211
1240
  import { Key as Key2 } from "aws-cdk-lib/aws-kms";
1212
1241
  import { Stack as Stack3 } from "aws-cdk-lib/core";
1242
+
1243
+ // src/services/open-hi-data-service.ts
1244
+ import { StreamViewType, Table as Table2 } from "aws-cdk-lib/aws-dynamodb";
1245
+ import { EventBus as EventBus3 } from "aws-cdk-lib/aws-events";
1246
+ import * as kinesis from "aws-cdk-lib/aws-kinesis";
1247
+ var _OpenHiDataService = class _OpenHiDataService extends OpenHiService {
1248
+ /**
1249
+ * Returns the data event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
1250
+ */
1251
+ static dataEventBusFromConstruct(scope) {
1252
+ return EventBus3.fromEventBusName(
1253
+ scope,
1254
+ "data-event-bus",
1255
+ DataEventBus.getEventBusName(scope)
1256
+ );
1257
+ }
1258
+ /**
1259
+ * Returns the ops event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
1260
+ */
1261
+ static opsEventBusFromConstruct(scope) {
1262
+ return EventBus3.fromEventBusName(
1263
+ scope,
1264
+ "ops-event-bus",
1265
+ OpsEventBus.getEventBusName(scope)
1266
+ );
1267
+ }
1268
+ /**
1269
+ * Returns the data store table by name. Use from other stacks (e.g. REST API Lambda) to obtain an ITable reference.
1270
+ */
1271
+ static dynamoDbDataStoreFromConstruct(scope, id = "dynamo-db-data-store") {
1272
+ return Table2.fromTableName(scope, id, getDynamoDbDataStoreTableName(scope));
1273
+ }
1274
+ get serviceType() {
1275
+ return _OpenHiDataService.SERVICE_TYPE;
1276
+ }
1277
+ constructor(ohEnv, props = {}) {
1278
+ super(ohEnv, _OpenHiDataService.SERVICE_TYPE, props);
1279
+ this.props = props;
1280
+ this.dataEventBus = this.createDataEventBus();
1281
+ this.opsEventBus = this.createOpsEventBus();
1282
+ this.dataStoreChangeStream = new kinesis.Stream(
1283
+ this,
1284
+ "data-store-change-stream",
1285
+ {
1286
+ streamName: `openhi-dstore-cdc-${this.branchHash}`,
1287
+ streamMode: kinesis.StreamMode.ON_DEMAND,
1288
+ // CDK default for kinesis.Stream is RETAIN, which strands the stream
1289
+ // when a non-prod stack is destroyed. Use the service's policy so
1290
+ // non-prod tears down cleanly while prod retains.
1291
+ removalPolicy: this.removalPolicy
1292
+ }
1293
+ );
1294
+ this.dataStore = this.createDataStore();
1295
+ this.dataStoreHistoricalArchive = new DataStoreHistoricalArchive(
1296
+ this,
1297
+ "data-store-historical-archive",
1298
+ {
1299
+ kinesisStream: this.dataStoreChangeStream,
1300
+ removalPolicy: this.removalPolicy,
1301
+ stackHash: this.stackHash,
1302
+ dataEventBus: this.dataEventBus
1303
+ }
1304
+ );
1305
+ this.dataStorePostgresReplica = new DataStorePostgresReplica(
1306
+ this,
1307
+ "data-store-postgres-replica",
1308
+ {
1309
+ kinesisStream: this.dataStoreChangeStream,
1310
+ removalPolicy: this.removalPolicy,
1311
+ stackHash: this.stackHash,
1312
+ branchHash: this.branchHash
1313
+ }
1314
+ );
1315
+ }
1316
+ /**
1317
+ * Creates the data event bus.
1318
+ * Override to customize.
1319
+ */
1320
+ createDataEventBus() {
1321
+ return new DataEventBus(this);
1322
+ }
1323
+ /**
1324
+ * Creates the ops event bus.
1325
+ * Override to customize.
1326
+ */
1327
+ createOpsEventBus() {
1328
+ return new OpsEventBus(this);
1329
+ }
1330
+ /**
1331
+ * Creates the single-table DynamoDB data store.
1332
+ * Override to customize.
1333
+ */
1334
+ createDataStore() {
1335
+ return new DynamoDbDataStore(this, "dynamo-db-data-store", {
1336
+ kinesisStream: this.dataStoreChangeStream,
1337
+ stream: StreamViewType.NEW_AND_OLD_IMAGES
1338
+ });
1339
+ }
1340
+ };
1341
+ _OpenHiDataService.SERVICE_TYPE = "data";
1342
+ var OpenHiDataService = _OpenHiDataService;
1343
+
1344
+ // src/services/open-hi-auth-service.ts
1213
1345
  var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1346
+ constructor(ohEnv, props = {}) {
1347
+ super(ohEnv, _OpenHiAuthService.SERVICE_TYPE, props);
1348
+ /**
1349
+ * Cross-stack reference to the data store table. Cached so repeated
1350
+ * lookups share a single CDK construct id ("dynamo-db-data-store") in
1351
+ * this stack — a second `Table.fromTableName` call under the same scope
1352
+ * would collide.
1353
+ */
1354
+ this._dataStoreTable = null;
1355
+ this.props = props;
1356
+ this.userPoolKmsKey = this.createUserPoolKmsKey();
1357
+ this.preTokenGenerationLambda = this.createPreTokenGenerationLambda();
1358
+ this.postAuthenticationLambda = this.createPostAuthenticationLambda();
1359
+ this.postConfirmationLambda = this.createPostConfirmationLambda();
1360
+ this.userPool = this.createUserPool();
1361
+ this.grantPostAuthenticationPermissions();
1362
+ this.grantPostConfirmationPermissions();
1363
+ this.userPoolClient = this.createUserPoolClient();
1364
+ this.userPoolDomain = this.createUserPoolDomain();
1365
+ this.fixtureSeederClient = this.createFixtureSeederClient();
1366
+ }
1214
1367
  /**
1215
1368
  * Returns an IUserPool by looking up the Auth stack's User Pool ID from SSM.
1216
1369
  */
@@ -1282,18 +1435,6 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1282
1435
  get serviceType() {
1283
1436
  return _OpenHiAuthService.SERVICE_TYPE;
1284
1437
  }
1285
- constructor(ohEnv, props = {}) {
1286
- super(ohEnv, _OpenHiAuthService.SERVICE_TYPE, props);
1287
- this.props = props;
1288
- this.userPoolKmsKey = this.createUserPoolKmsKey();
1289
- this.preTokenGenerationLambda = this.createPreTokenGenerationLambda();
1290
- this.postAuthenticationLambda = this.createPostAuthenticationLambda();
1291
- this.userPool = this.createUserPool();
1292
- this.grantPostAuthenticationPermissions();
1293
- this.userPoolClient = this.createUserPoolClient();
1294
- this.userPoolDomain = this.createUserPoolDomain();
1295
- this.fixtureSeederClient = this.createFixtureSeederClient();
1296
- }
1297
1438
  /**
1298
1439
  * Creates the KMS key for the Cognito User Pool and exports its ARN to SSM.
1299
1440
  * Look up via {@link OpenHiAuthService.userPoolKmsKeyFromConstruct}.
@@ -1325,6 +1466,25 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1325
1466
  const construct = new PostAuthenticationLambda(this);
1326
1467
  return construct.lambda;
1327
1468
  }
1469
+ /**
1470
+ * Creates the Post Confirmation Lambda (Cognito trigger). On sign-up
1471
+ * confirmation, writes the new user's default Tenant, Workspace,
1472
+ * Memberships, and `tenant-user` RoleAssignment, plus a User record
1473
+ * carrying the Cognito `sub` and current tenant/workspace pointers
1474
+ * (ADR 2026-03-17-01 invariants).
1475
+ */
1476
+ createPostConfirmationLambda() {
1477
+ const construct = new PostConfirmationLambda(this, {
1478
+ dynamoTableName: this.dataStoreTable().tableName
1479
+ });
1480
+ return construct.lambda;
1481
+ }
1482
+ dataStoreTable() {
1483
+ if (this._dataStoreTable === null) {
1484
+ this._dataStoreTable = OpenHiDataService.dynamoDbDataStoreFromConstruct(this);
1485
+ }
1486
+ return this._dataStoreTable;
1487
+ }
1328
1488
  /**
1329
1489
  * Creates the Cognito User Pool and exports its ID to SSM.
1330
1490
  * Look up via {@link OpenHiAuthService.userPoolFromConstruct}.
@@ -1344,6 +1504,10 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1344
1504
  UserPoolOperation.POST_AUTHENTICATION,
1345
1505
  this.postAuthenticationLambda
1346
1506
  );
1507
+ userPool.addTrigger(
1508
+ UserPoolOperation.POST_CONFIRMATION,
1509
+ this.postConfirmationLambda
1510
+ );
1347
1511
  new DiscoverableStringParameter(this, "user-pool-param", {
1348
1512
  ssmParamName: CognitoUserPool.SSM_PARAM_NAME,
1349
1513
  stringValue: userPool.userPoolId,
@@ -1378,6 +1542,28 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1378
1542
  })
1379
1543
  );
1380
1544
  }
1545
+ /**
1546
+ * Grants the Post Confirmation Lambda write access to the data store
1547
+ * table (and its GSIs) so it can seed the new user's Tenant, Workspace,
1548
+ * Memberships, RoleAssignment, and User records on sign-up confirmation.
1549
+ */
1550
+ grantPostConfirmationPermissions() {
1551
+ const dataStoreTable = this.dataStoreTable();
1552
+ const dynamoActions = [
1553
+ "dynamodb:PutItem",
1554
+ "dynamodb:UpdateItem",
1555
+ "dynamodb:BatchWriteItem",
1556
+ "dynamodb:DescribeTable"
1557
+ ];
1558
+ dataStoreTable.grant(this.postConfirmationLambda, ...dynamoActions);
1559
+ this.postConfirmationLambda.addToRolePolicy(
1560
+ new PolicyStatement({
1561
+ effect: Effect.ALLOW,
1562
+ actions: [...dynamoActions],
1563
+ resources: [`${dataStoreTable.tableArn}/index/*`]
1564
+ })
1565
+ );
1566
+ }
1381
1567
  /**
1382
1568
  * Creates the User Pool Client and exports its ID to SSM (AUTH service type).
1383
1569
  * Look up via {@link OpenHiAuthService.userPoolClientFromConstruct}.
@@ -1562,7 +1748,7 @@ import {
1562
1748
  } from "aws-cdk-lib/aws-apigatewayv2";
1563
1749
  import { HttpUserPoolAuthorizer } from "aws-cdk-lib/aws-apigatewayv2-authorizers";
1564
1750
  import { HttpLambdaIntegration } from "aws-cdk-lib/aws-apigatewayv2-integrations";
1565
- import { Effect, PolicyStatement as PolicyStatement2 } from "aws-cdk-lib/aws-iam";
1751
+ import { Effect as Effect2, PolicyStatement as PolicyStatement2 } from "aws-cdk-lib/aws-iam";
1566
1752
  import {
1567
1753
  ARecord,
1568
1754
  HostedZone as HostedZone3,
@@ -1571,154 +1757,53 @@ import {
1571
1757
  import { ApiGatewayv2DomainProperties } from "aws-cdk-lib/aws-route53-targets";
1572
1758
  import { Duration as Duration6 } from "aws-cdk-lib/core";
1573
1759
 
1574
- // src/services/open-hi-data-service.ts
1575
- import { StreamViewType, Table as Table2 } from "aws-cdk-lib/aws-dynamodb";
1576
- import { EventBus as EventBus3 } from "aws-cdk-lib/aws-events";
1577
- import * as kinesis from "aws-cdk-lib/aws-kinesis";
1578
- var _OpenHiDataService = class _OpenHiDataService extends OpenHiService {
1579
- /**
1580
- * Returns the data event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
1581
- */
1582
- static dataEventBusFromConstruct(scope) {
1583
- return EventBus3.fromEventBusName(
1584
- scope,
1585
- "data-event-bus",
1586
- DataEventBus.getEventBusName(scope)
1587
- );
1588
- }
1589
- /**
1590
- * Returns the ops event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
1591
- */
1592
- static opsEventBusFromConstruct(scope) {
1593
- return EventBus3.fromEventBusName(
1594
- scope,
1595
- "ops-event-bus",
1596
- OpsEventBus.getEventBusName(scope)
1597
- );
1598
- }
1599
- /**
1600
- * Returns the data store table by name. Use from other stacks (e.g. REST API Lambda) to obtain an ITable reference.
1601
- */
1602
- static dynamoDbDataStoreFromConstruct(scope, id = "dynamo-db-data-store") {
1603
- return Table2.fromTableName(scope, id, getDynamoDbDataStoreTableName(scope));
1604
- }
1605
- get serviceType() {
1606
- return _OpenHiDataService.SERVICE_TYPE;
1607
- }
1608
- constructor(ohEnv, props = {}) {
1609
- super(ohEnv, _OpenHiDataService.SERVICE_TYPE, props);
1610
- this.props = props;
1611
- this.dataEventBus = this.createDataEventBus();
1612
- this.opsEventBus = this.createOpsEventBus();
1613
- this.dataStoreChangeStream = new kinesis.Stream(
1614
- this,
1615
- "data-store-change-stream",
1616
- {
1617
- streamName: `openhi-dstore-cdc-${this.branchHash}`,
1618
- streamMode: kinesis.StreamMode.ON_DEMAND,
1619
- // CDK default for kinesis.Stream is RETAIN, which strands the stream
1620
- // when a non-prod stack is destroyed. Use the service's policy so
1621
- // non-prod tears down cleanly while prod retains.
1622
- removalPolicy: this.removalPolicy
1623
- }
1624
- );
1625
- this.dataStore = this.createDataStore();
1626
- this.dataStoreHistoricalArchive = new DataStoreHistoricalArchive(
1627
- this,
1628
- "data-store-historical-archive",
1629
- {
1630
- kinesisStream: this.dataStoreChangeStream,
1631
- removalPolicy: this.removalPolicy,
1632
- stackHash: this.stackHash,
1633
- dataEventBus: this.dataEventBus
1634
- }
1635
- );
1636
- this.dataStorePostgresReplica = new DataStorePostgresReplica(
1637
- this,
1638
- "data-store-postgres-replica",
1639
- {
1640
- kinesisStream: this.dataStoreChangeStream,
1641
- removalPolicy: this.removalPolicy,
1642
- stackHash: this.stackHash,
1643
- branchHash: this.branchHash
1644
- }
1645
- );
1646
- }
1647
- /**
1648
- * Creates the data event bus.
1649
- * Override to customize.
1650
- */
1651
- createDataEventBus() {
1652
- return new DataEventBus(this);
1653
- }
1654
- /**
1655
- * Creates the ops event bus.
1656
- * Override to customize.
1657
- */
1658
- createOpsEventBus() {
1659
- return new OpsEventBus(this);
1660
- }
1661
- /**
1662
- * Creates the single-table DynamoDB data store.
1663
- * Override to customize.
1664
- */
1665
- createDataStore() {
1666
- return new DynamoDbDataStore(this, "dynamo-db-data-store", {
1667
- kinesisStream: this.dataStoreChangeStream,
1668
- stream: StreamViewType.NEW_AND_OLD_IMAGES
1669
- });
1670
- }
1671
- };
1672
- _OpenHiDataService.SERVICE_TYPE = "data";
1673
- var OpenHiDataService = _OpenHiDataService;
1674
-
1675
1760
  // src/data/lambda/cors-options-lambda.ts
1676
- import fs5 from "fs";
1677
- import path5 from "path";
1678
- import { Runtime as Runtime5 } from "aws-cdk-lib/aws-lambda";
1679
- import { NodejsFunction as NodejsFunction5 } from "aws-cdk-lib/aws-lambda-nodejs";
1680
- import { Construct as Construct7 } from "constructs";
1681
- var HANDLER_NAME5 = "cors-options-lambda.handler.js";
1682
- function resolveHandlerEntry5(dirname) {
1683
- const sameDir = path5.join(dirname, HANDLER_NAME5);
1684
- if (fs5.existsSync(sameDir)) {
1761
+ import fs6 from "fs";
1762
+ import path6 from "path";
1763
+ import { Runtime as Runtime6 } from "aws-cdk-lib/aws-lambda";
1764
+ import { NodejsFunction as NodejsFunction6 } from "aws-cdk-lib/aws-lambda-nodejs";
1765
+ import { Construct as Construct8 } from "constructs";
1766
+ var HANDLER_NAME6 = "cors-options-lambda.handler.js";
1767
+ function resolveHandlerEntry6(dirname) {
1768
+ const sameDir = path6.join(dirname, HANDLER_NAME6);
1769
+ if (fs6.existsSync(sameDir)) {
1685
1770
  return sameDir;
1686
1771
  }
1687
- const fromLib = path5.join(dirname, "..", "..", "..", "lib", HANDLER_NAME5);
1772
+ const fromLib = path6.join(dirname, "..", "..", "..", "lib", HANDLER_NAME6);
1688
1773
  return fromLib;
1689
1774
  }
1690
- var CorsOptionsLambda = class extends Construct7 {
1775
+ var CorsOptionsLambda = class extends Construct8 {
1691
1776
  constructor(scope, id = "cors-options-lambda") {
1692
1777
  super(scope, id);
1693
- this.lambda = new NodejsFunction5(this, "handler", {
1694
- entry: resolveHandlerEntry5(__dirname),
1695
- runtime: Runtime5.NODEJS_LATEST,
1778
+ this.lambda = new NodejsFunction6(this, "handler", {
1779
+ entry: resolveHandlerEntry6(__dirname),
1780
+ runtime: Runtime6.NODEJS_LATEST,
1696
1781
  memorySize: 128
1697
1782
  });
1698
1783
  }
1699
1784
  };
1700
1785
 
1701
1786
  // src/data/lambda/rest-api-lambda.ts
1702
- import fs6 from "fs";
1703
- import path6 from "path";
1704
- import { Runtime as Runtime6 } from "aws-cdk-lib/aws-lambda";
1705
- import { NodejsFunction as NodejsFunction6 } from "aws-cdk-lib/aws-lambda-nodejs";
1706
- import { Construct as Construct8 } from "constructs";
1707
- var HANDLER_NAME6 = "rest-api-lambda.handler.js";
1708
- function resolveHandlerEntry6(dirname) {
1709
- const sameDir = path6.join(dirname, HANDLER_NAME6);
1710
- if (fs6.existsSync(sameDir)) {
1787
+ import fs7 from "fs";
1788
+ import path7 from "path";
1789
+ import { Runtime as Runtime7 } from "aws-cdk-lib/aws-lambda";
1790
+ import { NodejsFunction as NodejsFunction7 } from "aws-cdk-lib/aws-lambda-nodejs";
1791
+ import { Construct as Construct9 } from "constructs";
1792
+ var HANDLER_NAME7 = "rest-api-lambda.handler.js";
1793
+ function resolveHandlerEntry7(dirname) {
1794
+ const sameDir = path7.join(dirname, HANDLER_NAME7);
1795
+ if (fs7.existsSync(sameDir)) {
1711
1796
  return sameDir;
1712
1797
  }
1713
- const fromLib = path6.join(dirname, "..", "..", "..", "lib", HANDLER_NAME6);
1798
+ const fromLib = path7.join(dirname, "..", "..", "..", "lib", HANDLER_NAME7);
1714
1799
  return fromLib;
1715
1800
  }
1716
- var RestApiLambda = class extends Construct8 {
1801
+ var RestApiLambda = class extends Construct9 {
1717
1802
  constructor(scope, props) {
1718
1803
  super(scope, "rest-api-lambda");
1719
- this.lambda = new NodejsFunction6(this, "handler", {
1720
- entry: resolveHandlerEntry6(__dirname),
1721
- runtime: Runtime6.NODEJS_LATEST,
1804
+ this.lambda = new NodejsFunction7(this, "handler", {
1805
+ entry: resolveHandlerEntry7(__dirname),
1806
+ runtime: Runtime7.NODEJS_LATEST,
1722
1807
  memorySize: 1024,
1723
1808
  environment: {
1724
1809
  DYNAMO_TABLE_NAME: props.dynamoTableName,
@@ -1861,7 +1946,7 @@ var _OpenHiRestApiService = class _OpenHiRestApiService extends OpenHiService {
1861
1946
  });
1862
1947
  lambda.addToRolePolicy(
1863
1948
  new PolicyStatement2({
1864
- effect: Effect.ALLOW,
1949
+ effect: Effect2.ALLOW,
1865
1950
  actions: [
1866
1951
  "rds-data:ExecuteStatement",
1867
1952
  "rds-data:BatchExecuteStatement"
@@ -1871,7 +1956,7 @@ var _OpenHiRestApiService = class _OpenHiRestApiService extends OpenHiService {
1871
1956
  );
1872
1957
  lambda.addToRolePolicy(
1873
1958
  new PolicyStatement2({
1874
- effect: Effect.ALLOW,
1959
+ effect: Effect2.ALLOW,
1875
1960
  actions: ["secretsmanager:GetSecretValue"],
1876
1961
  resources: [postgresSecretArn]
1877
1962
  })
@@ -1890,14 +1975,14 @@ var _OpenHiRestApiService = class _OpenHiRestApiService extends OpenHiService {
1890
1975
  dataStoreTable.grant(lambda, ...dynamoActions);
1891
1976
  lambda.addToRolePolicy(
1892
1977
  new PolicyStatement2({
1893
- effect: Effect.ALLOW,
1978
+ effect: Effect2.ALLOW,
1894
1979
  actions: [...dynamoActions],
1895
1980
  resources: [`${dataStoreTable.tableArn}/index/*`]
1896
1981
  })
1897
1982
  );
1898
1983
  lambda.addToRolePolicy(
1899
1984
  new PolicyStatement2({
1900
- effect: Effect.ALLOW,
1985
+ effect: Effect2.ALLOW,
1901
1986
  actions: [
1902
1987
  "ssm:GetParameter",
1903
1988
  "ssm:GetParameters",
@@ -2076,6 +2161,7 @@ export {
2076
2161
  POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME,
2077
2162
  POSTGRES_REPLICA_SECRET_ARN_SSM_NAME,
2078
2163
  PostAuthenticationLambda,
2164
+ PostConfirmationLambda,
2079
2165
  PreTokenGenerationLambda,
2080
2166
  REST_API_BASE_URL_SSM_NAME,
2081
2167
  RootGraphqlApi,