@openhi/constructs 0.0.90 → 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.js CHANGED
@@ -121,6 +121,7 @@ __export(src_exports, {
121
121
  POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME: () => POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME,
122
122
  POSTGRES_REPLICA_SECRET_ARN_SSM_NAME: () => POSTGRES_REPLICA_SECRET_ARN_SSM_NAME,
123
123
  PostAuthenticationLambda: () => PostAuthenticationLambda,
124
+ PostConfirmationLambda: () => PostConfirmationLambda,
124
125
  PreTokenGenerationLambda: () => PreTokenGenerationLambda,
125
126
  REST_API_BASE_URL_SSM_NAME: () => REST_API_BASE_URL_SSM_NAME,
126
127
  RootGraphqlApi: () => RootGraphqlApi,
@@ -749,13 +750,13 @@ var PostAuthenticationLambda = class extends import_constructs.Construct {
749
750
  }
750
751
  };
751
752
 
752
- // src/components/cognito/pre-token-generation-lambda.ts
753
+ // src/components/cognito/post-confirmation-lambda.ts
753
754
  var import_node_fs2 = __toESM(require("fs"));
754
755
  var import_node_path2 = __toESM(require("path"));
755
756
  var import_aws_lambda2 = require("aws-cdk-lib/aws-lambda");
756
757
  var import_aws_lambda_nodejs2 = require("aws-cdk-lib/aws-lambda-nodejs");
757
758
  var import_constructs2 = require("constructs");
758
- var HANDLER_NAME2 = "pre-token-generation.handler.js";
759
+ var HANDLER_NAME2 = "post-confirmation.handler.js";
759
760
  function resolveHandlerEntry2(dirname) {
760
761
  const sameDir = import_node_path2.default.join(dirname, HANDLER_NAME2);
761
762
  if (import_node_fs2.default.existsSync(sameDir)) {
@@ -764,12 +765,41 @@ function resolveHandlerEntry2(dirname) {
764
765
  const fromLib = import_node_path2.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME2);
765
766
  return fromLib;
766
767
  }
767
- var PreTokenGenerationLambda = class extends import_constructs2.Construct {
768
- constructor(scope) {
769
- super(scope, "pre-token-generation-lambda");
768
+ var PostConfirmationLambda = class extends import_constructs2.Construct {
769
+ constructor(scope, props) {
770
+ super(scope, "post-confirmation-lambda");
770
771
  this.lambda = new import_aws_lambda_nodejs2.NodejsFunction(this, "handler", {
771
772
  entry: resolveHandlerEntry2(__dirname),
772
773
  runtime: import_aws_lambda2.Runtime.NODEJS_LATEST,
774
+ memorySize: 1024,
775
+ environment: {
776
+ DYNAMO_TABLE_NAME: props.dynamoTableName
777
+ }
778
+ });
779
+ }
780
+ };
781
+
782
+ // src/components/cognito/pre-token-generation-lambda.ts
783
+ var import_node_fs3 = __toESM(require("fs"));
784
+ var import_node_path3 = __toESM(require("path"));
785
+ var import_aws_lambda3 = require("aws-cdk-lib/aws-lambda");
786
+ var import_aws_lambda_nodejs3 = require("aws-cdk-lib/aws-lambda-nodejs");
787
+ var import_constructs3 = require("constructs");
788
+ var HANDLER_NAME3 = "pre-token-generation.handler.js";
789
+ function resolveHandlerEntry3(dirname) {
790
+ const sameDir = import_node_path3.default.join(dirname, HANDLER_NAME3);
791
+ if (import_node_fs3.default.existsSync(sameDir)) {
792
+ return sameDir;
793
+ }
794
+ const fromLib = import_node_path3.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME3);
795
+ return fromLib;
796
+ }
797
+ var PreTokenGenerationLambda = class extends import_constructs3.Construct {
798
+ constructor(scope) {
799
+ super(scope, "pre-token-generation-lambda");
800
+ this.lambda = new import_aws_lambda_nodejs3.NodejsFunction(this, "handler", {
801
+ entry: resolveHandlerEntry3(__dirname),
802
+ runtime: import_aws_lambda3.Runtime.NODEJS_LATEST,
773
803
  memorySize: 1024
774
804
  });
775
805
  }
@@ -897,23 +927,23 @@ function buildFhirCurrentResourceChangeDetail(record, keys) {
897
927
  }
898
928
 
899
929
  // src/components/dynamodb/data-store-historical-archive.ts
900
- var import_node_fs3 = __toESM(require("fs"));
901
- var import_node_path3 = __toESM(require("path"));
930
+ var import_node_fs4 = __toESM(require("fs"));
931
+ var import_node_path4 = __toESM(require("path"));
902
932
  var import_aws_cdk_lib7 = require("aws-cdk-lib");
903
933
  var kinesisfirehose = __toESM(require("aws-cdk-lib/aws-kinesisfirehose"));
904
- var import_aws_lambda3 = require("aws-cdk-lib/aws-lambda");
905
- var import_aws_lambda_nodejs3 = require("aws-cdk-lib/aws-lambda-nodejs");
934
+ var import_aws_lambda4 = require("aws-cdk-lib/aws-lambda");
935
+ var import_aws_lambda_nodejs4 = require("aws-cdk-lib/aws-lambda-nodejs");
906
936
  var s3 = __toESM(require("aws-cdk-lib/aws-s3"));
907
- var import_constructs3 = require("constructs");
908
- var HANDLER_NAME3 = "firehose-archive-transform.handler.js";
909
- function resolveHandlerEntry3(dirname) {
910
- const sameDir = import_node_path3.default.join(dirname, HANDLER_NAME3);
911
- if (import_node_fs3.default.existsSync(sameDir)) {
937
+ var import_constructs4 = require("constructs");
938
+ var HANDLER_NAME4 = "firehose-archive-transform.handler.js";
939
+ function resolveHandlerEntry4(dirname) {
940
+ const sameDir = import_node_path4.default.join(dirname, HANDLER_NAME4);
941
+ if (import_node_fs4.default.existsSync(sameDir)) {
912
942
  return sameDir;
913
943
  }
914
- return import_node_path3.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME3);
944
+ return import_node_path4.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME4);
915
945
  }
916
- var DataStoreHistoricalArchive = class extends import_constructs3.Construct {
946
+ var DataStoreHistoricalArchive = class extends import_constructs4.Construct {
917
947
  constructor(scope, id, props) {
918
948
  super(scope, id);
919
949
  this.archiveBucket = new s3.Bucket(this, "ArchiveBucket", {
@@ -933,9 +963,9 @@ var DataStoreHistoricalArchive = class extends import_constructs3.Construct {
933
963
  versioned: false
934
964
  }) : void 0;
935
965
  this.putEventsFailureDlqBucket = putEventsFailureDlqBucket;
936
- this.transformFunction = new import_aws_lambda_nodejs3.NodejsFunction(this, "FirehoseTransform", {
937
- entry: resolveHandlerEntry3(__dirname),
938
- runtime: import_aws_lambda3.Runtime.NODEJS_LATEST,
966
+ this.transformFunction = new import_aws_lambda_nodejs4.NodejsFunction(this, "FirehoseTransform", {
967
+ entry: resolveHandlerEntry4(__dirname),
968
+ runtime: import_aws_lambda4.Runtime.NODEJS_LATEST,
939
969
  memorySize: 512,
940
970
  timeout: import_aws_cdk_lib7.Duration.minutes(1),
941
971
  description: "Firehose transform: filter CURRENT resource rows, S3 keys, EventBridge PutEvents",
@@ -1026,13 +1056,20 @@ var DynamoDbDataStore = class extends import_aws_dynamodb.Table {
1026
1056
  },
1027
1057
  projectionType: import_aws_dynamodb.ProjectionType.INCLUDE,
1028
1058
  nonKeyAttributes: [
1059
+ "id",
1029
1060
  "summary",
1030
1061
  "vid",
1031
1062
  "lastUpdated",
1032
1063
  "createdDate",
1033
1064
  "modifiedDate",
1034
1065
  "createdById",
1035
- "modifiedById"
1066
+ "modifiedById",
1067
+ // ElectroDB filters every query result through `ownsItem`, which
1068
+ // verifies `__edb_e__` (entity name) and `__edb_v__` (version) match
1069
+ // the entity. Without these projected, every GSI1 query returns 0
1070
+ // results — list endpoints silently return empty bundles.
1071
+ "__edb_e__",
1072
+ "__edb_v__"
1036
1073
  ]
1037
1074
  });
1038
1075
  this.addGlobalSecondaryIndex({
@@ -1050,7 +1087,12 @@ var DynamoDbDataStore = class extends import_aws_dynamodb.Table {
1050
1087
  "id",
1051
1088
  "currentTenant",
1052
1089
  "currentWorkspace",
1053
- "displayName"
1090
+ "displayName",
1091
+ // See GSI1 above: ElectroDB's `ownsItem` filter rejects items
1092
+ // without these, so any query against GSI2 returns 0 results
1093
+ // unless they're projected.
1094
+ "__edb_e__",
1095
+ "__edb_v__"
1054
1096
  ]
1055
1097
  });
1056
1098
  }
@@ -1101,27 +1143,27 @@ var OpsEventBus = class _OpsEventBus extends import_aws_events2.EventBus {
1101
1143
  };
1102
1144
 
1103
1145
  // src/components/postgres/data-store-postgres-replica.ts
1104
- var import_node_fs4 = __toESM(require("fs"));
1105
- var import_node_path4 = __toESM(require("path"));
1146
+ var import_node_fs5 = __toESM(require("fs"));
1147
+ var import_node_path5 = __toESM(require("path"));
1106
1148
  var import_aws_cdk_lib8 = require("aws-cdk-lib");
1107
1149
  var ec2 = __toESM(require("aws-cdk-lib/aws-ec2"));
1108
- var import_aws_lambda4 = require("aws-cdk-lib/aws-lambda");
1150
+ var import_aws_lambda5 = require("aws-cdk-lib/aws-lambda");
1109
1151
  var import_aws_lambda_event_sources = require("aws-cdk-lib/aws-lambda-event-sources");
1110
- var import_aws_lambda_nodejs4 = require("aws-cdk-lib/aws-lambda-nodejs");
1152
+ var import_aws_lambda_nodejs5 = require("aws-cdk-lib/aws-lambda-nodejs");
1111
1153
  var rds = __toESM(require("aws-cdk-lib/aws-rds"));
1112
- var import_constructs4 = require("constructs");
1113
- var HANDLER_NAME4 = "data-store-postgres-replication.handler.js";
1154
+ var import_constructs5 = require("constructs");
1155
+ var HANDLER_NAME5 = "data-store-postgres-replication.handler.js";
1114
1156
  var DEFAULT_DATABASE_NAME = "openhi";
1115
1157
  var SCHEMA_NAME_PATTERN = /^[a-z_][a-z0-9_]{0,62}$/;
1116
1158
  var POSTGRES_REPLICA_CLUSTER_ARN_SSM_NAME = "POSTGRES_REPLICA_CLUSTER_ARN";
1117
1159
  var POSTGRES_REPLICA_SECRET_ARN_SSM_NAME = "POSTGRES_REPLICA_SECRET_ARN";
1118
1160
  var POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME = "POSTGRES_REPLICA_DATABASE_NAME";
1119
- function resolveHandlerEntry4(dirname) {
1120
- const sameDir = import_node_path4.default.join(dirname, HANDLER_NAME4);
1121
- if (import_node_fs4.default.existsSync(sameDir)) {
1161
+ function resolveHandlerEntry5(dirname) {
1162
+ const sameDir = import_node_path5.default.join(dirname, HANDLER_NAME5);
1163
+ if (import_node_fs5.default.existsSync(sameDir)) {
1122
1164
  return sameDir;
1123
1165
  }
1124
- return import_node_path4.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME4);
1166
+ return import_node_path5.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME5);
1125
1167
  }
1126
1168
  function getPostgresReplicaSchemaName(branchHash) {
1127
1169
  const candidate = `b_${branchHash.toLowerCase()}`;
@@ -1132,7 +1174,7 @@ function getPostgresReplicaSchemaName(branchHash) {
1132
1174
  }
1133
1175
  return candidate;
1134
1176
  }
1135
- var DataStorePostgresReplica = class extends import_constructs4.Construct {
1177
+ var DataStorePostgresReplica = class extends import_constructs5.Construct {
1136
1178
  /**
1137
1179
  * Resolve the cluster ARN published by an upstream {@link DataStorePostgresReplica}.
1138
1180
  * Use from any stack that needs to grant `rds-data:ExecuteStatement` against
@@ -1201,9 +1243,9 @@ var DataStorePostgresReplica = class extends import_constructs4.Construct {
1201
1243
  enableDataApi: true
1202
1244
  });
1203
1245
  this.publishCoordinatesToSsm();
1204
- this.replicationFunction = new import_aws_lambda_nodejs4.NodejsFunction(this, "ReplicationFunction", {
1205
- entry: resolveHandlerEntry4(__dirname),
1206
- runtime: import_aws_lambda4.Runtime.NODEJS_LATEST,
1246
+ this.replicationFunction = new import_aws_lambda_nodejs5.NodejsFunction(this, "ReplicationFunction", {
1247
+ entry: resolveHandlerEntry5(__dirname),
1248
+ runtime: import_aws_lambda5.Runtime.NODEJS_LATEST,
1207
1249
  memorySize: 512,
1208
1250
  timeout: import_aws_cdk_lib8.Duration.minutes(1),
1209
1251
  vpc: this.vpc,
@@ -1230,7 +1272,7 @@ var DataStorePostgresReplica = class extends import_constructs4.Construct {
1230
1272
  this.cluster.connections.allowDefaultPortFrom(this.replicationFunction);
1231
1273
  this.replicationFunction.addEventSource(
1232
1274
  new import_aws_lambda_event_sources.KinesisEventSource(props.kinesisStream, {
1233
- startingPosition: import_aws_lambda4.StartingPosition.LATEST,
1275
+ startingPosition: import_aws_lambda5.StartingPosition.LATEST,
1234
1276
  batchSize: 100,
1235
1277
  maxBatchingWindow: import_aws_cdk_lib8.Duration.seconds(5),
1236
1278
  retryAttempts: 10,
@@ -1284,8 +1326,8 @@ var ChildHostedZone = class extends import_aws_route53.HostedZone {
1284
1326
  ChildHostedZone.SSM_PARAM_NAME = "CHILDHOSTEDZONE";
1285
1327
 
1286
1328
  // src/components/route-53/root-hosted-zone.ts
1287
- var import_constructs5 = require("constructs");
1288
- var RootHostedZone = class extends import_constructs5.Construct {
1329
+ var import_constructs6 = require("constructs");
1330
+ var RootHostedZone = class extends import_constructs6.Construct {
1289
1331
  };
1290
1332
 
1291
1333
  // src/components/static-hosting/static-hosting.ts
@@ -1293,9 +1335,9 @@ var import_aws_cloudfront = require("aws-cdk-lib/aws-cloudfront");
1293
1335
  var import_aws_cloudfront_origins = require("aws-cdk-lib/aws-cloudfront-origins");
1294
1336
  var import_aws_s3 = require("aws-cdk-lib/aws-s3");
1295
1337
  var import_core = require("aws-cdk-lib/core");
1296
- var import_constructs6 = require("constructs");
1338
+ var import_constructs7 = require("constructs");
1297
1339
  var STATIC_HOSTING_SERVICE_TYPE = "website";
1298
- var _StaticHosting = class _StaticHosting extends import_constructs6.Construct {
1340
+ var _StaticHosting = class _StaticHosting extends import_constructs7.Construct {
1299
1341
  constructor(scope, id, props = {}) {
1300
1342
  super(scope, id);
1301
1343
  const stack = OpenHiService.of(scope);
@@ -1352,7 +1394,131 @@ var import_aws_cognito5 = require("aws-cdk-lib/aws-cognito");
1352
1394
  var import_aws_iam = require("aws-cdk-lib/aws-iam");
1353
1395
  var import_aws_kms2 = require("aws-cdk-lib/aws-kms");
1354
1396
  var import_core2 = require("aws-cdk-lib/core");
1397
+
1398
+ // src/services/open-hi-data-service.ts
1399
+ var import_aws_dynamodb2 = require("aws-cdk-lib/aws-dynamodb");
1400
+ var import_aws_events3 = require("aws-cdk-lib/aws-events");
1401
+ var kinesis = __toESM(require("aws-cdk-lib/aws-kinesis"));
1402
+ var _OpenHiDataService = class _OpenHiDataService extends OpenHiService {
1403
+ /**
1404
+ * Returns the data event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
1405
+ */
1406
+ static dataEventBusFromConstruct(scope) {
1407
+ return import_aws_events3.EventBus.fromEventBusName(
1408
+ scope,
1409
+ "data-event-bus",
1410
+ DataEventBus.getEventBusName(scope)
1411
+ );
1412
+ }
1413
+ /**
1414
+ * Returns the ops event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
1415
+ */
1416
+ static opsEventBusFromConstruct(scope) {
1417
+ return import_aws_events3.EventBus.fromEventBusName(
1418
+ scope,
1419
+ "ops-event-bus",
1420
+ OpsEventBus.getEventBusName(scope)
1421
+ );
1422
+ }
1423
+ /**
1424
+ * Returns the data store table by name. Use from other stacks (e.g. REST API Lambda) to obtain an ITable reference.
1425
+ */
1426
+ static dynamoDbDataStoreFromConstruct(scope, id = "dynamo-db-data-store") {
1427
+ return import_aws_dynamodb2.Table.fromTableName(scope, id, getDynamoDbDataStoreTableName(scope));
1428
+ }
1429
+ get serviceType() {
1430
+ return _OpenHiDataService.SERVICE_TYPE;
1431
+ }
1432
+ constructor(ohEnv, props = {}) {
1433
+ super(ohEnv, _OpenHiDataService.SERVICE_TYPE, props);
1434
+ this.props = props;
1435
+ this.dataEventBus = this.createDataEventBus();
1436
+ this.opsEventBus = this.createOpsEventBus();
1437
+ this.dataStoreChangeStream = new kinesis.Stream(
1438
+ this,
1439
+ "data-store-change-stream",
1440
+ {
1441
+ streamName: `openhi-dstore-cdc-${this.branchHash}`,
1442
+ streamMode: kinesis.StreamMode.ON_DEMAND,
1443
+ // CDK default for kinesis.Stream is RETAIN, which strands the stream
1444
+ // when a non-prod stack is destroyed. Use the service's policy so
1445
+ // non-prod tears down cleanly while prod retains.
1446
+ removalPolicy: this.removalPolicy
1447
+ }
1448
+ );
1449
+ this.dataStore = this.createDataStore();
1450
+ this.dataStoreHistoricalArchive = new DataStoreHistoricalArchive(
1451
+ this,
1452
+ "data-store-historical-archive",
1453
+ {
1454
+ kinesisStream: this.dataStoreChangeStream,
1455
+ removalPolicy: this.removalPolicy,
1456
+ stackHash: this.stackHash,
1457
+ dataEventBus: this.dataEventBus
1458
+ }
1459
+ );
1460
+ this.dataStorePostgresReplica = new DataStorePostgresReplica(
1461
+ this,
1462
+ "data-store-postgres-replica",
1463
+ {
1464
+ kinesisStream: this.dataStoreChangeStream,
1465
+ removalPolicy: this.removalPolicy,
1466
+ stackHash: this.stackHash,
1467
+ branchHash: this.branchHash
1468
+ }
1469
+ );
1470
+ }
1471
+ /**
1472
+ * Creates the data event bus.
1473
+ * Override to customize.
1474
+ */
1475
+ createDataEventBus() {
1476
+ return new DataEventBus(this);
1477
+ }
1478
+ /**
1479
+ * Creates the ops event bus.
1480
+ * Override to customize.
1481
+ */
1482
+ createOpsEventBus() {
1483
+ return new OpsEventBus(this);
1484
+ }
1485
+ /**
1486
+ * Creates the single-table DynamoDB data store.
1487
+ * Override to customize.
1488
+ */
1489
+ createDataStore() {
1490
+ return new DynamoDbDataStore(this, "dynamo-db-data-store", {
1491
+ kinesisStream: this.dataStoreChangeStream,
1492
+ stream: import_aws_dynamodb2.StreamViewType.NEW_AND_OLD_IMAGES
1493
+ });
1494
+ }
1495
+ };
1496
+ _OpenHiDataService.SERVICE_TYPE = "data";
1497
+ var OpenHiDataService = _OpenHiDataService;
1498
+
1499
+ // src/services/open-hi-auth-service.ts
1355
1500
  var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1501
+ constructor(ohEnv, props = {}) {
1502
+ super(ohEnv, _OpenHiAuthService.SERVICE_TYPE, props);
1503
+ /**
1504
+ * Cross-stack reference to the data store table. Cached so repeated
1505
+ * lookups share a single CDK construct id ("dynamo-db-data-store") in
1506
+ * this stack — a second `Table.fromTableName` call under the same scope
1507
+ * would collide.
1508
+ */
1509
+ this._dataStoreTable = null;
1510
+ this.props = props;
1511
+ this.userPoolKmsKey = this.createUserPoolKmsKey();
1512
+ this.preTokenGenerationLambda = this.createPreTokenGenerationLambda();
1513
+ this.postAuthenticationLambda = this.createPostAuthenticationLambda();
1514
+ this.postConfirmationLambda = this.createPostConfirmationLambda();
1515
+ this.userPool = this.createUserPool();
1516
+ this.grantPostAuthenticationPermissions();
1517
+ this.grantPostConfirmationPermissions();
1518
+ this.userPoolClient = this.createUserPoolClient();
1519
+ this.userPoolDomain = this.createUserPoolDomain();
1520
+ this.fixtureSeederClient = this.createFixtureSeederClient();
1521
+ }
1356
1522
  /**
1357
1523
  * Returns an IUserPool by looking up the Auth stack's User Pool ID from SSM.
1358
1524
  */
@@ -1424,18 +1590,6 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1424
1590
  get serviceType() {
1425
1591
  return _OpenHiAuthService.SERVICE_TYPE;
1426
1592
  }
1427
- constructor(ohEnv, props = {}) {
1428
- super(ohEnv, _OpenHiAuthService.SERVICE_TYPE, props);
1429
- this.props = props;
1430
- this.userPoolKmsKey = this.createUserPoolKmsKey();
1431
- this.preTokenGenerationLambda = this.createPreTokenGenerationLambda();
1432
- this.postAuthenticationLambda = this.createPostAuthenticationLambda();
1433
- this.userPool = this.createUserPool();
1434
- this.grantPostAuthenticationPermissions();
1435
- this.userPoolClient = this.createUserPoolClient();
1436
- this.userPoolDomain = this.createUserPoolDomain();
1437
- this.fixtureSeederClient = this.createFixtureSeederClient();
1438
- }
1439
1593
  /**
1440
1594
  * Creates the KMS key for the Cognito User Pool and exports its ARN to SSM.
1441
1595
  * Look up via {@link OpenHiAuthService.userPoolKmsKeyFromConstruct}.
@@ -1467,6 +1621,25 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1467
1621
  const construct = new PostAuthenticationLambda(this);
1468
1622
  return construct.lambda;
1469
1623
  }
1624
+ /**
1625
+ * Creates the Post Confirmation Lambda (Cognito trigger). On sign-up
1626
+ * confirmation, writes the new user's default Tenant, Workspace,
1627
+ * Memberships, and `tenant-user` RoleAssignment, plus a User record
1628
+ * carrying the Cognito `sub` and current tenant/workspace pointers
1629
+ * (ADR 2026-03-17-01 invariants).
1630
+ */
1631
+ createPostConfirmationLambda() {
1632
+ const construct = new PostConfirmationLambda(this, {
1633
+ dynamoTableName: this.dataStoreTable().tableName
1634
+ });
1635
+ return construct.lambda;
1636
+ }
1637
+ dataStoreTable() {
1638
+ if (this._dataStoreTable === null) {
1639
+ this._dataStoreTable = OpenHiDataService.dynamoDbDataStoreFromConstruct(this);
1640
+ }
1641
+ return this._dataStoreTable;
1642
+ }
1470
1643
  /**
1471
1644
  * Creates the Cognito User Pool and exports its ID to SSM.
1472
1645
  * Look up via {@link OpenHiAuthService.userPoolFromConstruct}.
@@ -1486,6 +1659,10 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1486
1659
  import_aws_cognito5.UserPoolOperation.POST_AUTHENTICATION,
1487
1660
  this.postAuthenticationLambda
1488
1661
  );
1662
+ userPool.addTrigger(
1663
+ import_aws_cognito5.UserPoolOperation.POST_CONFIRMATION,
1664
+ this.postConfirmationLambda
1665
+ );
1489
1666
  new DiscoverableStringParameter(this, "user-pool-param", {
1490
1667
  ssmParamName: CognitoUserPool.SSM_PARAM_NAME,
1491
1668
  stringValue: userPool.userPoolId,
@@ -1520,6 +1697,28 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1520
1697
  })
1521
1698
  );
1522
1699
  }
1700
+ /**
1701
+ * Grants the Post Confirmation Lambda write access to the data store
1702
+ * table (and its GSIs) so it can seed the new user's Tenant, Workspace,
1703
+ * Memberships, RoleAssignment, and User records on sign-up confirmation.
1704
+ */
1705
+ grantPostConfirmationPermissions() {
1706
+ const dataStoreTable = this.dataStoreTable();
1707
+ const dynamoActions = [
1708
+ "dynamodb:PutItem",
1709
+ "dynamodb:UpdateItem",
1710
+ "dynamodb:BatchWriteItem",
1711
+ "dynamodb:DescribeTable"
1712
+ ];
1713
+ dataStoreTable.grant(this.postConfirmationLambda, ...dynamoActions);
1714
+ this.postConfirmationLambda.addToRolePolicy(
1715
+ new import_aws_iam.PolicyStatement({
1716
+ effect: import_aws_iam.Effect.ALLOW,
1717
+ actions: [...dynamoActions],
1718
+ resources: [`${dataStoreTable.tableArn}/index/*`]
1719
+ })
1720
+ );
1721
+ }
1523
1722
  /**
1524
1723
  * Creates the User Pool Client and exports its ID to SSM (AUTH service type).
1525
1724
  * Look up via {@link OpenHiAuthService.userPoolClientFromConstruct}.
@@ -1696,154 +1895,53 @@ var import_aws_route533 = require("aws-cdk-lib/aws-route53");
1696
1895
  var import_aws_route53_targets = require("aws-cdk-lib/aws-route53-targets");
1697
1896
  var import_core3 = require("aws-cdk-lib/core");
1698
1897
 
1699
- // src/services/open-hi-data-service.ts
1700
- var import_aws_dynamodb2 = require("aws-cdk-lib/aws-dynamodb");
1701
- var import_aws_events3 = require("aws-cdk-lib/aws-events");
1702
- var kinesis = __toESM(require("aws-cdk-lib/aws-kinesis"));
1703
- var _OpenHiDataService = class _OpenHiDataService extends OpenHiService {
1704
- /**
1705
- * Returns the data event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
1706
- */
1707
- static dataEventBusFromConstruct(scope) {
1708
- return import_aws_events3.EventBus.fromEventBusName(
1709
- scope,
1710
- "data-event-bus",
1711
- DataEventBus.getEventBusName(scope)
1712
- );
1713
- }
1714
- /**
1715
- * Returns the ops event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
1716
- */
1717
- static opsEventBusFromConstruct(scope) {
1718
- return import_aws_events3.EventBus.fromEventBusName(
1719
- scope,
1720
- "ops-event-bus",
1721
- OpsEventBus.getEventBusName(scope)
1722
- );
1723
- }
1724
- /**
1725
- * Returns the data store table by name. Use from other stacks (e.g. REST API Lambda) to obtain an ITable reference.
1726
- */
1727
- static dynamoDbDataStoreFromConstruct(scope, id = "dynamo-db-data-store") {
1728
- return import_aws_dynamodb2.Table.fromTableName(scope, id, getDynamoDbDataStoreTableName(scope));
1729
- }
1730
- get serviceType() {
1731
- return _OpenHiDataService.SERVICE_TYPE;
1732
- }
1733
- constructor(ohEnv, props = {}) {
1734
- super(ohEnv, _OpenHiDataService.SERVICE_TYPE, props);
1735
- this.props = props;
1736
- this.dataEventBus = this.createDataEventBus();
1737
- this.opsEventBus = this.createOpsEventBus();
1738
- this.dataStoreChangeStream = new kinesis.Stream(
1739
- this,
1740
- "data-store-change-stream",
1741
- {
1742
- streamName: `openhi-dstore-cdc-${this.branchHash}`,
1743
- streamMode: kinesis.StreamMode.ON_DEMAND,
1744
- // CDK default for kinesis.Stream is RETAIN, which strands the stream
1745
- // when a non-prod stack is destroyed. Use the service's policy so
1746
- // non-prod tears down cleanly while prod retains.
1747
- removalPolicy: this.removalPolicy
1748
- }
1749
- );
1750
- this.dataStore = this.createDataStore();
1751
- this.dataStoreHistoricalArchive = new DataStoreHistoricalArchive(
1752
- this,
1753
- "data-store-historical-archive",
1754
- {
1755
- kinesisStream: this.dataStoreChangeStream,
1756
- removalPolicy: this.removalPolicy,
1757
- stackHash: this.stackHash,
1758
- dataEventBus: this.dataEventBus
1759
- }
1760
- );
1761
- this.dataStorePostgresReplica = new DataStorePostgresReplica(
1762
- this,
1763
- "data-store-postgres-replica",
1764
- {
1765
- kinesisStream: this.dataStoreChangeStream,
1766
- removalPolicy: this.removalPolicy,
1767
- stackHash: this.stackHash,
1768
- branchHash: this.branchHash
1769
- }
1770
- );
1771
- }
1772
- /**
1773
- * Creates the data event bus.
1774
- * Override to customize.
1775
- */
1776
- createDataEventBus() {
1777
- return new DataEventBus(this);
1778
- }
1779
- /**
1780
- * Creates the ops event bus.
1781
- * Override to customize.
1782
- */
1783
- createOpsEventBus() {
1784
- return new OpsEventBus(this);
1785
- }
1786
- /**
1787
- * Creates the single-table DynamoDB data store.
1788
- * Override to customize.
1789
- */
1790
- createDataStore() {
1791
- return new DynamoDbDataStore(this, "dynamo-db-data-store", {
1792
- kinesisStream: this.dataStoreChangeStream,
1793
- stream: import_aws_dynamodb2.StreamViewType.NEW_AND_OLD_IMAGES
1794
- });
1795
- }
1796
- };
1797
- _OpenHiDataService.SERVICE_TYPE = "data";
1798
- var OpenHiDataService = _OpenHiDataService;
1799
-
1800
1898
  // src/data/lambda/cors-options-lambda.ts
1801
- var import_node_fs5 = __toESM(require("fs"));
1802
- var import_node_path5 = __toESM(require("path"));
1803
- var import_aws_lambda5 = require("aws-cdk-lib/aws-lambda");
1804
- var import_aws_lambda_nodejs5 = require("aws-cdk-lib/aws-lambda-nodejs");
1805
- var import_constructs7 = require("constructs");
1806
- var HANDLER_NAME5 = "cors-options-lambda.handler.js";
1807
- function resolveHandlerEntry5(dirname) {
1808
- const sameDir = import_node_path5.default.join(dirname, HANDLER_NAME5);
1809
- if (import_node_fs5.default.existsSync(sameDir)) {
1899
+ var import_node_fs6 = __toESM(require("fs"));
1900
+ var import_node_path6 = __toESM(require("path"));
1901
+ var import_aws_lambda6 = require("aws-cdk-lib/aws-lambda");
1902
+ var import_aws_lambda_nodejs6 = require("aws-cdk-lib/aws-lambda-nodejs");
1903
+ var import_constructs8 = require("constructs");
1904
+ var HANDLER_NAME6 = "cors-options-lambda.handler.js";
1905
+ function resolveHandlerEntry6(dirname) {
1906
+ const sameDir = import_node_path6.default.join(dirname, HANDLER_NAME6);
1907
+ if (import_node_fs6.default.existsSync(sameDir)) {
1810
1908
  return sameDir;
1811
1909
  }
1812
- const fromLib = import_node_path5.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME5);
1910
+ const fromLib = import_node_path6.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME6);
1813
1911
  return fromLib;
1814
1912
  }
1815
- var CorsOptionsLambda = class extends import_constructs7.Construct {
1913
+ var CorsOptionsLambda = class extends import_constructs8.Construct {
1816
1914
  constructor(scope, id = "cors-options-lambda") {
1817
1915
  super(scope, id);
1818
- this.lambda = new import_aws_lambda_nodejs5.NodejsFunction(this, "handler", {
1819
- entry: resolveHandlerEntry5(__dirname),
1820
- runtime: import_aws_lambda5.Runtime.NODEJS_LATEST,
1916
+ this.lambda = new import_aws_lambda_nodejs6.NodejsFunction(this, "handler", {
1917
+ entry: resolveHandlerEntry6(__dirname),
1918
+ runtime: import_aws_lambda6.Runtime.NODEJS_LATEST,
1821
1919
  memorySize: 128
1822
1920
  });
1823
1921
  }
1824
1922
  };
1825
1923
 
1826
1924
  // src/data/lambda/rest-api-lambda.ts
1827
- var import_node_fs6 = __toESM(require("fs"));
1828
- var import_node_path6 = __toESM(require("path"));
1829
- var import_aws_lambda6 = require("aws-cdk-lib/aws-lambda");
1830
- var import_aws_lambda_nodejs6 = require("aws-cdk-lib/aws-lambda-nodejs");
1831
- var import_constructs8 = require("constructs");
1832
- var HANDLER_NAME6 = "rest-api-lambda.handler.js";
1833
- function resolveHandlerEntry6(dirname) {
1834
- const sameDir = import_node_path6.default.join(dirname, HANDLER_NAME6);
1835
- if (import_node_fs6.default.existsSync(sameDir)) {
1925
+ var import_node_fs7 = __toESM(require("fs"));
1926
+ var import_node_path7 = __toESM(require("path"));
1927
+ var import_aws_lambda7 = require("aws-cdk-lib/aws-lambda");
1928
+ var import_aws_lambda_nodejs7 = require("aws-cdk-lib/aws-lambda-nodejs");
1929
+ var import_constructs9 = require("constructs");
1930
+ var HANDLER_NAME7 = "rest-api-lambda.handler.js";
1931
+ function resolveHandlerEntry7(dirname) {
1932
+ const sameDir = import_node_path7.default.join(dirname, HANDLER_NAME7);
1933
+ if (import_node_fs7.default.existsSync(sameDir)) {
1836
1934
  return sameDir;
1837
1935
  }
1838
- const fromLib = import_node_path6.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME6);
1936
+ const fromLib = import_node_path7.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME7);
1839
1937
  return fromLib;
1840
1938
  }
1841
- var RestApiLambda = class extends import_constructs8.Construct {
1939
+ var RestApiLambda = class extends import_constructs9.Construct {
1842
1940
  constructor(scope, props) {
1843
1941
  super(scope, "rest-api-lambda");
1844
- this.lambda = new import_aws_lambda_nodejs6.NodejsFunction(this, "handler", {
1845
- entry: resolveHandlerEntry6(__dirname),
1846
- runtime: import_aws_lambda6.Runtime.NODEJS_LATEST,
1942
+ this.lambda = new import_aws_lambda_nodejs7.NodejsFunction(this, "handler", {
1943
+ entry: resolveHandlerEntry7(__dirname),
1944
+ runtime: import_aws_lambda7.Runtime.NODEJS_LATEST,
1847
1945
  memorySize: 1024,
1848
1946
  environment: {
1849
1947
  DYNAMO_TABLE_NAME: props.dynamoTableName,
@@ -2199,6 +2297,7 @@ var OpenHiGraphqlService = _OpenHiGraphqlService;
2199
2297
  POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME,
2200
2298
  POSTGRES_REPLICA_SECRET_ARN_SSM_NAME,
2201
2299
  PostAuthenticationLambda,
2300
+ PostConfirmationLambda,
2202
2301
  PreTokenGenerationLambda,
2203
2302
  REST_API_BASE_URL_SSM_NAME,
2204
2303
  RootGraphqlApi,