@openhi/constructs 0.0.91 → 0.0.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chunk-MLTYFMSE.mjs +807 -0
- package/lib/chunk-MLTYFMSE.mjs.map +1 -0
- package/lib/index.d.mts +69 -5
- package/lib/index.d.ts +70 -6
- package/lib/index.js +299 -183
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +299 -184
- package/lib/index.mjs.map +1 -1
- package/lib/post-confirmation.handler.d.mts +5 -0
- package/lib/post-confirmation.handler.d.ts +5 -0
- package/lib/post-confirmation.handler.js +949 -0
- package/lib/post-confirmation.handler.js.map +1 -0
- package/lib/post-confirmation.handler.mjs +128 -0
- package/lib/post-confirmation.handler.mjs.map +1 -0
- package/lib/pre-token-generation.handler.d.mts +0 -7
- package/lib/pre-token-generation.handler.d.ts +0 -7
- package/lib/pre-token-generation.handler.js +885 -11
- package/lib/pre-token-generation.handler.js.map +1 -1
- package/lib/pre-token-generation.handler.mjs +87 -11
- package/lib/pre-token-generation.handler.mjs.map +1 -1
- package/lib/rest-api-lambda.handler.mjs +12 -804
- package/lib/rest-api-lambda.handler.mjs.map +1 -1
- package/package.json +1 -1
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/
|
|
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 = "
|
|
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,13 +765,45 @@ function resolveHandlerEntry2(dirname) {
|
|
|
764
765
|
const fromLib = import_node_path2.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME2);
|
|
765
766
|
return fromLib;
|
|
766
767
|
}
|
|
767
|
-
var
|
|
768
|
-
constructor(scope) {
|
|
769
|
-
super(scope, "
|
|
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,
|
|
773
|
-
memorySize: 1024
|
|
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, props) {
|
|
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,
|
|
803
|
+
memorySize: 1024,
|
|
804
|
+
environment: {
|
|
805
|
+
DYNAMO_TABLE_NAME: props.dynamoTableName
|
|
806
|
+
}
|
|
774
807
|
});
|
|
775
808
|
}
|
|
776
809
|
};
|
|
@@ -897,23 +930,23 @@ function buildFhirCurrentResourceChangeDetail(record, keys) {
|
|
|
897
930
|
}
|
|
898
931
|
|
|
899
932
|
// src/components/dynamodb/data-store-historical-archive.ts
|
|
900
|
-
var
|
|
901
|
-
var
|
|
933
|
+
var import_node_fs4 = __toESM(require("fs"));
|
|
934
|
+
var import_node_path4 = __toESM(require("path"));
|
|
902
935
|
var import_aws_cdk_lib7 = require("aws-cdk-lib");
|
|
903
936
|
var kinesisfirehose = __toESM(require("aws-cdk-lib/aws-kinesisfirehose"));
|
|
904
|
-
var
|
|
905
|
-
var
|
|
937
|
+
var import_aws_lambda4 = require("aws-cdk-lib/aws-lambda");
|
|
938
|
+
var import_aws_lambda_nodejs4 = require("aws-cdk-lib/aws-lambda-nodejs");
|
|
906
939
|
var s3 = __toESM(require("aws-cdk-lib/aws-s3"));
|
|
907
|
-
var
|
|
908
|
-
var
|
|
909
|
-
function
|
|
910
|
-
const sameDir =
|
|
911
|
-
if (
|
|
940
|
+
var import_constructs4 = require("constructs");
|
|
941
|
+
var HANDLER_NAME4 = "firehose-archive-transform.handler.js";
|
|
942
|
+
function resolveHandlerEntry4(dirname) {
|
|
943
|
+
const sameDir = import_node_path4.default.join(dirname, HANDLER_NAME4);
|
|
944
|
+
if (import_node_fs4.default.existsSync(sameDir)) {
|
|
912
945
|
return sameDir;
|
|
913
946
|
}
|
|
914
|
-
return
|
|
947
|
+
return import_node_path4.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME4);
|
|
915
948
|
}
|
|
916
|
-
var DataStoreHistoricalArchive = class extends
|
|
949
|
+
var DataStoreHistoricalArchive = class extends import_constructs4.Construct {
|
|
917
950
|
constructor(scope, id, props) {
|
|
918
951
|
super(scope, id);
|
|
919
952
|
this.archiveBucket = new s3.Bucket(this, "ArchiveBucket", {
|
|
@@ -933,9 +966,9 @@ var DataStoreHistoricalArchive = class extends import_constructs3.Construct {
|
|
|
933
966
|
versioned: false
|
|
934
967
|
}) : void 0;
|
|
935
968
|
this.putEventsFailureDlqBucket = putEventsFailureDlqBucket;
|
|
936
|
-
this.transformFunction = new
|
|
937
|
-
entry:
|
|
938
|
-
runtime:
|
|
969
|
+
this.transformFunction = new import_aws_lambda_nodejs4.NodejsFunction(this, "FirehoseTransform", {
|
|
970
|
+
entry: resolveHandlerEntry4(__dirname),
|
|
971
|
+
runtime: import_aws_lambda4.Runtime.NODEJS_LATEST,
|
|
939
972
|
memorySize: 512,
|
|
940
973
|
timeout: import_aws_cdk_lib7.Duration.minutes(1),
|
|
941
974
|
description: "Firehose transform: filter CURRENT resource rows, S3 keys, EventBridge PutEvents",
|
|
@@ -1113,27 +1146,27 @@ var OpsEventBus = class _OpsEventBus extends import_aws_events2.EventBus {
|
|
|
1113
1146
|
};
|
|
1114
1147
|
|
|
1115
1148
|
// src/components/postgres/data-store-postgres-replica.ts
|
|
1116
|
-
var
|
|
1117
|
-
var
|
|
1149
|
+
var import_node_fs5 = __toESM(require("fs"));
|
|
1150
|
+
var import_node_path5 = __toESM(require("path"));
|
|
1118
1151
|
var import_aws_cdk_lib8 = require("aws-cdk-lib");
|
|
1119
1152
|
var ec2 = __toESM(require("aws-cdk-lib/aws-ec2"));
|
|
1120
|
-
var
|
|
1153
|
+
var import_aws_lambda5 = require("aws-cdk-lib/aws-lambda");
|
|
1121
1154
|
var import_aws_lambda_event_sources = require("aws-cdk-lib/aws-lambda-event-sources");
|
|
1122
|
-
var
|
|
1155
|
+
var import_aws_lambda_nodejs5 = require("aws-cdk-lib/aws-lambda-nodejs");
|
|
1123
1156
|
var rds = __toESM(require("aws-cdk-lib/aws-rds"));
|
|
1124
|
-
var
|
|
1125
|
-
var
|
|
1157
|
+
var import_constructs5 = require("constructs");
|
|
1158
|
+
var HANDLER_NAME5 = "data-store-postgres-replication.handler.js";
|
|
1126
1159
|
var DEFAULT_DATABASE_NAME = "openhi";
|
|
1127
1160
|
var SCHEMA_NAME_PATTERN = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
1128
1161
|
var POSTGRES_REPLICA_CLUSTER_ARN_SSM_NAME = "POSTGRES_REPLICA_CLUSTER_ARN";
|
|
1129
1162
|
var POSTGRES_REPLICA_SECRET_ARN_SSM_NAME = "POSTGRES_REPLICA_SECRET_ARN";
|
|
1130
1163
|
var POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME = "POSTGRES_REPLICA_DATABASE_NAME";
|
|
1131
|
-
function
|
|
1132
|
-
const sameDir =
|
|
1133
|
-
if (
|
|
1164
|
+
function resolveHandlerEntry5(dirname) {
|
|
1165
|
+
const sameDir = import_node_path5.default.join(dirname, HANDLER_NAME5);
|
|
1166
|
+
if (import_node_fs5.default.existsSync(sameDir)) {
|
|
1134
1167
|
return sameDir;
|
|
1135
1168
|
}
|
|
1136
|
-
return
|
|
1169
|
+
return import_node_path5.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME5);
|
|
1137
1170
|
}
|
|
1138
1171
|
function getPostgresReplicaSchemaName(branchHash) {
|
|
1139
1172
|
const candidate = `b_${branchHash.toLowerCase()}`;
|
|
@@ -1144,7 +1177,7 @@ function getPostgresReplicaSchemaName(branchHash) {
|
|
|
1144
1177
|
}
|
|
1145
1178
|
return candidate;
|
|
1146
1179
|
}
|
|
1147
|
-
var DataStorePostgresReplica = class extends
|
|
1180
|
+
var DataStorePostgresReplica = class extends import_constructs5.Construct {
|
|
1148
1181
|
/**
|
|
1149
1182
|
* Resolve the cluster ARN published by an upstream {@link DataStorePostgresReplica}.
|
|
1150
1183
|
* Use from any stack that needs to grant `rds-data:ExecuteStatement` against
|
|
@@ -1213,9 +1246,9 @@ var DataStorePostgresReplica = class extends import_constructs4.Construct {
|
|
|
1213
1246
|
enableDataApi: true
|
|
1214
1247
|
});
|
|
1215
1248
|
this.publishCoordinatesToSsm();
|
|
1216
|
-
this.replicationFunction = new
|
|
1217
|
-
entry:
|
|
1218
|
-
runtime:
|
|
1249
|
+
this.replicationFunction = new import_aws_lambda_nodejs5.NodejsFunction(this, "ReplicationFunction", {
|
|
1250
|
+
entry: resolveHandlerEntry5(__dirname),
|
|
1251
|
+
runtime: import_aws_lambda5.Runtime.NODEJS_LATEST,
|
|
1219
1252
|
memorySize: 512,
|
|
1220
1253
|
timeout: import_aws_cdk_lib8.Duration.minutes(1),
|
|
1221
1254
|
vpc: this.vpc,
|
|
@@ -1242,7 +1275,7 @@ var DataStorePostgresReplica = class extends import_constructs4.Construct {
|
|
|
1242
1275
|
this.cluster.connections.allowDefaultPortFrom(this.replicationFunction);
|
|
1243
1276
|
this.replicationFunction.addEventSource(
|
|
1244
1277
|
new import_aws_lambda_event_sources.KinesisEventSource(props.kinesisStream, {
|
|
1245
|
-
startingPosition:
|
|
1278
|
+
startingPosition: import_aws_lambda5.StartingPosition.LATEST,
|
|
1246
1279
|
batchSize: 100,
|
|
1247
1280
|
maxBatchingWindow: import_aws_cdk_lib8.Duration.seconds(5),
|
|
1248
1281
|
retryAttempts: 10,
|
|
@@ -1296,8 +1329,8 @@ var ChildHostedZone = class extends import_aws_route53.HostedZone {
|
|
|
1296
1329
|
ChildHostedZone.SSM_PARAM_NAME = "CHILDHOSTEDZONE";
|
|
1297
1330
|
|
|
1298
1331
|
// src/components/route-53/root-hosted-zone.ts
|
|
1299
|
-
var
|
|
1300
|
-
var RootHostedZone = class extends
|
|
1332
|
+
var import_constructs6 = require("constructs");
|
|
1333
|
+
var RootHostedZone = class extends import_constructs6.Construct {
|
|
1301
1334
|
};
|
|
1302
1335
|
|
|
1303
1336
|
// src/components/static-hosting/static-hosting.ts
|
|
@@ -1305,9 +1338,9 @@ var import_aws_cloudfront = require("aws-cdk-lib/aws-cloudfront");
|
|
|
1305
1338
|
var import_aws_cloudfront_origins = require("aws-cdk-lib/aws-cloudfront-origins");
|
|
1306
1339
|
var import_aws_s3 = require("aws-cdk-lib/aws-s3");
|
|
1307
1340
|
var import_core = require("aws-cdk-lib/core");
|
|
1308
|
-
var
|
|
1341
|
+
var import_constructs7 = require("constructs");
|
|
1309
1342
|
var STATIC_HOSTING_SERVICE_TYPE = "website";
|
|
1310
|
-
var _StaticHosting = class _StaticHosting extends
|
|
1343
|
+
var _StaticHosting = class _StaticHosting extends import_constructs7.Construct {
|
|
1311
1344
|
constructor(scope, id, props = {}) {
|
|
1312
1345
|
super(scope, id);
|
|
1313
1346
|
const stack = OpenHiService.of(scope);
|
|
@@ -1364,7 +1397,132 @@ var import_aws_cognito5 = require("aws-cdk-lib/aws-cognito");
|
|
|
1364
1397
|
var import_aws_iam = require("aws-cdk-lib/aws-iam");
|
|
1365
1398
|
var import_aws_kms2 = require("aws-cdk-lib/aws-kms");
|
|
1366
1399
|
var import_core2 = require("aws-cdk-lib/core");
|
|
1400
|
+
|
|
1401
|
+
// src/services/open-hi-data-service.ts
|
|
1402
|
+
var import_aws_dynamodb2 = require("aws-cdk-lib/aws-dynamodb");
|
|
1403
|
+
var import_aws_events3 = require("aws-cdk-lib/aws-events");
|
|
1404
|
+
var kinesis = __toESM(require("aws-cdk-lib/aws-kinesis"));
|
|
1405
|
+
var _OpenHiDataService = class _OpenHiDataService extends OpenHiService {
|
|
1406
|
+
/**
|
|
1407
|
+
* Returns the data event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
|
|
1408
|
+
*/
|
|
1409
|
+
static dataEventBusFromConstruct(scope) {
|
|
1410
|
+
return import_aws_events3.EventBus.fromEventBusName(
|
|
1411
|
+
scope,
|
|
1412
|
+
"data-event-bus",
|
|
1413
|
+
DataEventBus.getEventBusName(scope)
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Returns the ops event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
|
|
1418
|
+
*/
|
|
1419
|
+
static opsEventBusFromConstruct(scope) {
|
|
1420
|
+
return import_aws_events3.EventBus.fromEventBusName(
|
|
1421
|
+
scope,
|
|
1422
|
+
"ops-event-bus",
|
|
1423
|
+
OpsEventBus.getEventBusName(scope)
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Returns the data store table by name. Use from other stacks (e.g. REST API Lambda) to obtain an ITable reference.
|
|
1428
|
+
*/
|
|
1429
|
+
static dynamoDbDataStoreFromConstruct(scope, id = "dynamo-db-data-store") {
|
|
1430
|
+
return import_aws_dynamodb2.Table.fromTableName(scope, id, getDynamoDbDataStoreTableName(scope));
|
|
1431
|
+
}
|
|
1432
|
+
get serviceType() {
|
|
1433
|
+
return _OpenHiDataService.SERVICE_TYPE;
|
|
1434
|
+
}
|
|
1435
|
+
constructor(ohEnv, props = {}) {
|
|
1436
|
+
super(ohEnv, _OpenHiDataService.SERVICE_TYPE, props);
|
|
1437
|
+
this.props = props;
|
|
1438
|
+
this.dataEventBus = this.createDataEventBus();
|
|
1439
|
+
this.opsEventBus = this.createOpsEventBus();
|
|
1440
|
+
this.dataStoreChangeStream = new kinesis.Stream(
|
|
1441
|
+
this,
|
|
1442
|
+
"data-store-change-stream",
|
|
1443
|
+
{
|
|
1444
|
+
streamName: `openhi-dstore-cdc-${this.branchHash}`,
|
|
1445
|
+
streamMode: kinesis.StreamMode.ON_DEMAND,
|
|
1446
|
+
// CDK default for kinesis.Stream is RETAIN, which strands the stream
|
|
1447
|
+
// when a non-prod stack is destroyed. Use the service's policy so
|
|
1448
|
+
// non-prod tears down cleanly while prod retains.
|
|
1449
|
+
removalPolicy: this.removalPolicy
|
|
1450
|
+
}
|
|
1451
|
+
);
|
|
1452
|
+
this.dataStore = this.createDataStore();
|
|
1453
|
+
this.dataStoreHistoricalArchive = new DataStoreHistoricalArchive(
|
|
1454
|
+
this,
|
|
1455
|
+
"data-store-historical-archive",
|
|
1456
|
+
{
|
|
1457
|
+
kinesisStream: this.dataStoreChangeStream,
|
|
1458
|
+
removalPolicy: this.removalPolicy,
|
|
1459
|
+
stackHash: this.stackHash,
|
|
1460
|
+
dataEventBus: this.dataEventBus
|
|
1461
|
+
}
|
|
1462
|
+
);
|
|
1463
|
+
this.dataStorePostgresReplica = new DataStorePostgresReplica(
|
|
1464
|
+
this,
|
|
1465
|
+
"data-store-postgres-replica",
|
|
1466
|
+
{
|
|
1467
|
+
kinesisStream: this.dataStoreChangeStream,
|
|
1468
|
+
removalPolicy: this.removalPolicy,
|
|
1469
|
+
stackHash: this.stackHash,
|
|
1470
|
+
branchHash: this.branchHash
|
|
1471
|
+
}
|
|
1472
|
+
);
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Creates the data event bus.
|
|
1476
|
+
* Override to customize.
|
|
1477
|
+
*/
|
|
1478
|
+
createDataEventBus() {
|
|
1479
|
+
return new DataEventBus(this);
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Creates the ops event bus.
|
|
1483
|
+
* Override to customize.
|
|
1484
|
+
*/
|
|
1485
|
+
createOpsEventBus() {
|
|
1486
|
+
return new OpsEventBus(this);
|
|
1487
|
+
}
|
|
1488
|
+
/**
|
|
1489
|
+
* Creates the single-table DynamoDB data store.
|
|
1490
|
+
* Override to customize.
|
|
1491
|
+
*/
|
|
1492
|
+
createDataStore() {
|
|
1493
|
+
return new DynamoDbDataStore(this, "dynamo-db-data-store", {
|
|
1494
|
+
kinesisStream: this.dataStoreChangeStream,
|
|
1495
|
+
stream: import_aws_dynamodb2.StreamViewType.NEW_AND_OLD_IMAGES
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
_OpenHiDataService.SERVICE_TYPE = "data";
|
|
1500
|
+
var OpenHiDataService = _OpenHiDataService;
|
|
1501
|
+
|
|
1502
|
+
// src/services/open-hi-auth-service.ts
|
|
1367
1503
|
var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
1504
|
+
constructor(ohEnv, props = {}) {
|
|
1505
|
+
super(ohEnv, _OpenHiAuthService.SERVICE_TYPE, props);
|
|
1506
|
+
/**
|
|
1507
|
+
* Cross-stack reference to the data store table. Cached so repeated
|
|
1508
|
+
* lookups share a single CDK construct id ("dynamo-db-data-store") in
|
|
1509
|
+
* this stack — a second `Table.fromTableName` call under the same scope
|
|
1510
|
+
* would collide.
|
|
1511
|
+
*/
|
|
1512
|
+
this._dataStoreTable = null;
|
|
1513
|
+
this.props = props;
|
|
1514
|
+
this.userPoolKmsKey = this.createUserPoolKmsKey();
|
|
1515
|
+
this.preTokenGenerationLambda = this.createPreTokenGenerationLambda();
|
|
1516
|
+
this.postAuthenticationLambda = this.createPostAuthenticationLambda();
|
|
1517
|
+
this.postConfirmationLambda = this.createPostConfirmationLambda();
|
|
1518
|
+
this.userPool = this.createUserPool();
|
|
1519
|
+
this.grantPreTokenGenerationPermissions();
|
|
1520
|
+
this.grantPostAuthenticationPermissions();
|
|
1521
|
+
this.grantPostConfirmationPermissions();
|
|
1522
|
+
this.userPoolClient = this.createUserPoolClient();
|
|
1523
|
+
this.userPoolDomain = this.createUserPoolDomain();
|
|
1524
|
+
this.fixtureSeederClient = this.createFixtureSeederClient();
|
|
1525
|
+
}
|
|
1368
1526
|
/**
|
|
1369
1527
|
* Returns an IUserPool by looking up the Auth stack's User Pool ID from SSM.
|
|
1370
1528
|
*/
|
|
@@ -1436,18 +1594,6 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1436
1594
|
get serviceType() {
|
|
1437
1595
|
return _OpenHiAuthService.SERVICE_TYPE;
|
|
1438
1596
|
}
|
|
1439
|
-
constructor(ohEnv, props = {}) {
|
|
1440
|
-
super(ohEnv, _OpenHiAuthService.SERVICE_TYPE, props);
|
|
1441
|
-
this.props = props;
|
|
1442
|
-
this.userPoolKmsKey = this.createUserPoolKmsKey();
|
|
1443
|
-
this.preTokenGenerationLambda = this.createPreTokenGenerationLambda();
|
|
1444
|
-
this.postAuthenticationLambda = this.createPostAuthenticationLambda();
|
|
1445
|
-
this.userPool = this.createUserPool();
|
|
1446
|
-
this.grantPostAuthenticationPermissions();
|
|
1447
|
-
this.userPoolClient = this.createUserPoolClient();
|
|
1448
|
-
this.userPoolDomain = this.createUserPoolDomain();
|
|
1449
|
-
this.fixtureSeederClient = this.createFixtureSeederClient();
|
|
1450
|
-
}
|
|
1451
1597
|
/**
|
|
1452
1598
|
* Creates the KMS key for the Cognito User Pool and exports its ARN to SSM.
|
|
1453
1599
|
* Look up via {@link OpenHiAuthService.userPoolKmsKeyFromConstruct}.
|
|
@@ -1463,11 +1609,15 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1463
1609
|
return key;
|
|
1464
1610
|
}
|
|
1465
1611
|
/**
|
|
1466
|
-
* Creates the Pre Token Generation Lambda (Cognito trigger).
|
|
1467
|
-
*
|
|
1612
|
+
* Creates the Pre Token Generation Lambda (Cognito trigger). On every
|
|
1613
|
+
* sign-in and token refresh the Lambda resolves the User by Cognito `sub`
|
|
1614
|
+
* (GSI2) and injects `ohi_tid`, `ohi_wid`, `ohi_uid`, `ohi_uname` into
|
|
1615
|
+
* both the ID token and the access token (ADR 2026-03-17-01).
|
|
1468
1616
|
*/
|
|
1469
1617
|
createPreTokenGenerationLambda() {
|
|
1470
|
-
const construct = new PreTokenGenerationLambda(this
|
|
1618
|
+
const construct = new PreTokenGenerationLambda(this, {
|
|
1619
|
+
dynamoTableName: this.dataStoreTable().tableName
|
|
1620
|
+
});
|
|
1471
1621
|
return construct.lambda;
|
|
1472
1622
|
}
|
|
1473
1623
|
/**
|
|
@@ -1479,6 +1629,25 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1479
1629
|
const construct = new PostAuthenticationLambda(this);
|
|
1480
1630
|
return construct.lambda;
|
|
1481
1631
|
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Creates the Post Confirmation Lambda (Cognito trigger). On sign-up
|
|
1634
|
+
* confirmation, writes the new user's default Tenant, Workspace,
|
|
1635
|
+
* Memberships, and `tenant-user` RoleAssignment, plus a User record
|
|
1636
|
+
* carrying the Cognito `sub` and current tenant/workspace pointers
|
|
1637
|
+
* (ADR 2026-03-17-01 invariants).
|
|
1638
|
+
*/
|
|
1639
|
+
createPostConfirmationLambda() {
|
|
1640
|
+
const construct = new PostConfirmationLambda(this, {
|
|
1641
|
+
dynamoTableName: this.dataStoreTable().tableName
|
|
1642
|
+
});
|
|
1643
|
+
return construct.lambda;
|
|
1644
|
+
}
|
|
1645
|
+
dataStoreTable() {
|
|
1646
|
+
if (this._dataStoreTable === null) {
|
|
1647
|
+
this._dataStoreTable = OpenHiDataService.dynamoDbDataStoreFromConstruct(this);
|
|
1648
|
+
}
|
|
1649
|
+
return this._dataStoreTable;
|
|
1650
|
+
}
|
|
1482
1651
|
/**
|
|
1483
1652
|
* Creates the Cognito User Pool and exports its ID to SSM.
|
|
1484
1653
|
* Look up via {@link OpenHiAuthService.userPoolFromConstruct}.
|
|
@@ -1498,6 +1667,10 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1498
1667
|
import_aws_cognito5.UserPoolOperation.POST_AUTHENTICATION,
|
|
1499
1668
|
this.postAuthenticationLambda
|
|
1500
1669
|
);
|
|
1670
|
+
userPool.addTrigger(
|
|
1671
|
+
import_aws_cognito5.UserPoolOperation.POST_CONFIRMATION,
|
|
1672
|
+
this.postConfirmationLambda
|
|
1673
|
+
);
|
|
1501
1674
|
new DiscoverableStringParameter(this, "user-pool-param", {
|
|
1502
1675
|
ssmParamName: CognitoUserPool.SSM_PARAM_NAME,
|
|
1503
1676
|
stringValue: userPool.userPoolId,
|
|
@@ -1505,6 +1678,27 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1505
1678
|
});
|
|
1506
1679
|
return userPool;
|
|
1507
1680
|
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Grants the Pre Token Generation Lambda read-only access on the data
|
|
1683
|
+
* store table and its GSIs. The Lambda only needs:
|
|
1684
|
+
* - `Query` on GSI2 to resolve a User by Cognito `sub`
|
|
1685
|
+
* - `GetItem` on the base table for direct User reads
|
|
1686
|
+
*
|
|
1687
|
+
* No write or scan access: a User missing `currentTenant`/`currentWorkspace`
|
|
1688
|
+
* falls into the absent-claims path; repair belongs in a separate backfill.
|
|
1689
|
+
*/
|
|
1690
|
+
grantPreTokenGenerationPermissions() {
|
|
1691
|
+
const dataStoreTable = this.dataStoreTable();
|
|
1692
|
+
const dynamoActions = ["dynamodb:GetItem", "dynamodb:Query"];
|
|
1693
|
+
dataStoreTable.grant(this.preTokenGenerationLambda, ...dynamoActions);
|
|
1694
|
+
this.preTokenGenerationLambda.addToRolePolicy(
|
|
1695
|
+
new import_aws_iam.PolicyStatement({
|
|
1696
|
+
effect: import_aws_iam.Effect.ALLOW,
|
|
1697
|
+
actions: [...dynamoActions],
|
|
1698
|
+
resources: [`${dataStoreTable.tableArn}/index/*`]
|
|
1699
|
+
})
|
|
1700
|
+
);
|
|
1701
|
+
}
|
|
1508
1702
|
/**
|
|
1509
1703
|
* Grants the Post Authentication Lambda permission to call
|
|
1510
1704
|
* `cognito-idp:AdminUserGlobalSignOut`.
|
|
@@ -1532,6 +1726,28 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1532
1726
|
})
|
|
1533
1727
|
);
|
|
1534
1728
|
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Grants the Post Confirmation Lambda write access to the data store
|
|
1731
|
+
* table (and its GSIs) so it can seed the new user's Tenant, Workspace,
|
|
1732
|
+
* Memberships, RoleAssignment, and User records on sign-up confirmation.
|
|
1733
|
+
*/
|
|
1734
|
+
grantPostConfirmationPermissions() {
|
|
1735
|
+
const dataStoreTable = this.dataStoreTable();
|
|
1736
|
+
const dynamoActions = [
|
|
1737
|
+
"dynamodb:PutItem",
|
|
1738
|
+
"dynamodb:UpdateItem",
|
|
1739
|
+
"dynamodb:BatchWriteItem",
|
|
1740
|
+
"dynamodb:DescribeTable"
|
|
1741
|
+
];
|
|
1742
|
+
dataStoreTable.grant(this.postConfirmationLambda, ...dynamoActions);
|
|
1743
|
+
this.postConfirmationLambda.addToRolePolicy(
|
|
1744
|
+
new import_aws_iam.PolicyStatement({
|
|
1745
|
+
effect: import_aws_iam.Effect.ALLOW,
|
|
1746
|
+
actions: [...dynamoActions],
|
|
1747
|
+
resources: [`${dataStoreTable.tableArn}/index/*`]
|
|
1748
|
+
})
|
|
1749
|
+
);
|
|
1750
|
+
}
|
|
1535
1751
|
/**
|
|
1536
1752
|
* Creates the User Pool Client and exports its ID to SSM (AUTH service type).
|
|
1537
1753
|
* Look up via {@link OpenHiAuthService.userPoolClientFromConstruct}.
|
|
@@ -1708,154 +1924,53 @@ var import_aws_route533 = require("aws-cdk-lib/aws-route53");
|
|
|
1708
1924
|
var import_aws_route53_targets = require("aws-cdk-lib/aws-route53-targets");
|
|
1709
1925
|
var import_core3 = require("aws-cdk-lib/core");
|
|
1710
1926
|
|
|
1711
|
-
// src/services/open-hi-data-service.ts
|
|
1712
|
-
var import_aws_dynamodb2 = require("aws-cdk-lib/aws-dynamodb");
|
|
1713
|
-
var import_aws_events3 = require("aws-cdk-lib/aws-events");
|
|
1714
|
-
var kinesis = __toESM(require("aws-cdk-lib/aws-kinesis"));
|
|
1715
|
-
var _OpenHiDataService = class _OpenHiDataService extends OpenHiService {
|
|
1716
|
-
/**
|
|
1717
|
-
* Returns the data event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
|
|
1718
|
-
*/
|
|
1719
|
-
static dataEventBusFromConstruct(scope) {
|
|
1720
|
-
return import_aws_events3.EventBus.fromEventBusName(
|
|
1721
|
-
scope,
|
|
1722
|
-
"data-event-bus",
|
|
1723
|
-
DataEventBus.getEventBusName(scope)
|
|
1724
|
-
);
|
|
1725
|
-
}
|
|
1726
|
-
/**
|
|
1727
|
-
* Returns the ops event bus by name (deterministic per branch). Use from other stacks to obtain an IEventBus reference.
|
|
1728
|
-
*/
|
|
1729
|
-
static opsEventBusFromConstruct(scope) {
|
|
1730
|
-
return import_aws_events3.EventBus.fromEventBusName(
|
|
1731
|
-
scope,
|
|
1732
|
-
"ops-event-bus",
|
|
1733
|
-
OpsEventBus.getEventBusName(scope)
|
|
1734
|
-
);
|
|
1735
|
-
}
|
|
1736
|
-
/**
|
|
1737
|
-
* Returns the data store table by name. Use from other stacks (e.g. REST API Lambda) to obtain an ITable reference.
|
|
1738
|
-
*/
|
|
1739
|
-
static dynamoDbDataStoreFromConstruct(scope, id = "dynamo-db-data-store") {
|
|
1740
|
-
return import_aws_dynamodb2.Table.fromTableName(scope, id, getDynamoDbDataStoreTableName(scope));
|
|
1741
|
-
}
|
|
1742
|
-
get serviceType() {
|
|
1743
|
-
return _OpenHiDataService.SERVICE_TYPE;
|
|
1744
|
-
}
|
|
1745
|
-
constructor(ohEnv, props = {}) {
|
|
1746
|
-
super(ohEnv, _OpenHiDataService.SERVICE_TYPE, props);
|
|
1747
|
-
this.props = props;
|
|
1748
|
-
this.dataEventBus = this.createDataEventBus();
|
|
1749
|
-
this.opsEventBus = this.createOpsEventBus();
|
|
1750
|
-
this.dataStoreChangeStream = new kinesis.Stream(
|
|
1751
|
-
this,
|
|
1752
|
-
"data-store-change-stream",
|
|
1753
|
-
{
|
|
1754
|
-
streamName: `openhi-dstore-cdc-${this.branchHash}`,
|
|
1755
|
-
streamMode: kinesis.StreamMode.ON_DEMAND,
|
|
1756
|
-
// CDK default for kinesis.Stream is RETAIN, which strands the stream
|
|
1757
|
-
// when a non-prod stack is destroyed. Use the service's policy so
|
|
1758
|
-
// non-prod tears down cleanly while prod retains.
|
|
1759
|
-
removalPolicy: this.removalPolicy
|
|
1760
|
-
}
|
|
1761
|
-
);
|
|
1762
|
-
this.dataStore = this.createDataStore();
|
|
1763
|
-
this.dataStoreHistoricalArchive = new DataStoreHistoricalArchive(
|
|
1764
|
-
this,
|
|
1765
|
-
"data-store-historical-archive",
|
|
1766
|
-
{
|
|
1767
|
-
kinesisStream: this.dataStoreChangeStream,
|
|
1768
|
-
removalPolicy: this.removalPolicy,
|
|
1769
|
-
stackHash: this.stackHash,
|
|
1770
|
-
dataEventBus: this.dataEventBus
|
|
1771
|
-
}
|
|
1772
|
-
);
|
|
1773
|
-
this.dataStorePostgresReplica = new DataStorePostgresReplica(
|
|
1774
|
-
this,
|
|
1775
|
-
"data-store-postgres-replica",
|
|
1776
|
-
{
|
|
1777
|
-
kinesisStream: this.dataStoreChangeStream,
|
|
1778
|
-
removalPolicy: this.removalPolicy,
|
|
1779
|
-
stackHash: this.stackHash,
|
|
1780
|
-
branchHash: this.branchHash
|
|
1781
|
-
}
|
|
1782
|
-
);
|
|
1783
|
-
}
|
|
1784
|
-
/**
|
|
1785
|
-
* Creates the data event bus.
|
|
1786
|
-
* Override to customize.
|
|
1787
|
-
*/
|
|
1788
|
-
createDataEventBus() {
|
|
1789
|
-
return new DataEventBus(this);
|
|
1790
|
-
}
|
|
1791
|
-
/**
|
|
1792
|
-
* Creates the ops event bus.
|
|
1793
|
-
* Override to customize.
|
|
1794
|
-
*/
|
|
1795
|
-
createOpsEventBus() {
|
|
1796
|
-
return new OpsEventBus(this);
|
|
1797
|
-
}
|
|
1798
|
-
/**
|
|
1799
|
-
* Creates the single-table DynamoDB data store.
|
|
1800
|
-
* Override to customize.
|
|
1801
|
-
*/
|
|
1802
|
-
createDataStore() {
|
|
1803
|
-
return new DynamoDbDataStore(this, "dynamo-db-data-store", {
|
|
1804
|
-
kinesisStream: this.dataStoreChangeStream,
|
|
1805
|
-
stream: import_aws_dynamodb2.StreamViewType.NEW_AND_OLD_IMAGES
|
|
1806
|
-
});
|
|
1807
|
-
}
|
|
1808
|
-
};
|
|
1809
|
-
_OpenHiDataService.SERVICE_TYPE = "data";
|
|
1810
|
-
var OpenHiDataService = _OpenHiDataService;
|
|
1811
|
-
|
|
1812
1927
|
// src/data/lambda/cors-options-lambda.ts
|
|
1813
|
-
var
|
|
1814
|
-
var
|
|
1815
|
-
var
|
|
1816
|
-
var
|
|
1817
|
-
var
|
|
1818
|
-
var
|
|
1819
|
-
function
|
|
1820
|
-
const sameDir =
|
|
1821
|
-
if (
|
|
1928
|
+
var import_node_fs6 = __toESM(require("fs"));
|
|
1929
|
+
var import_node_path6 = __toESM(require("path"));
|
|
1930
|
+
var import_aws_lambda6 = require("aws-cdk-lib/aws-lambda");
|
|
1931
|
+
var import_aws_lambda_nodejs6 = require("aws-cdk-lib/aws-lambda-nodejs");
|
|
1932
|
+
var import_constructs8 = require("constructs");
|
|
1933
|
+
var HANDLER_NAME6 = "cors-options-lambda.handler.js";
|
|
1934
|
+
function resolveHandlerEntry6(dirname) {
|
|
1935
|
+
const sameDir = import_node_path6.default.join(dirname, HANDLER_NAME6);
|
|
1936
|
+
if (import_node_fs6.default.existsSync(sameDir)) {
|
|
1822
1937
|
return sameDir;
|
|
1823
1938
|
}
|
|
1824
|
-
const fromLib =
|
|
1939
|
+
const fromLib = import_node_path6.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME6);
|
|
1825
1940
|
return fromLib;
|
|
1826
1941
|
}
|
|
1827
|
-
var CorsOptionsLambda = class extends
|
|
1942
|
+
var CorsOptionsLambda = class extends import_constructs8.Construct {
|
|
1828
1943
|
constructor(scope, id = "cors-options-lambda") {
|
|
1829
1944
|
super(scope, id);
|
|
1830
|
-
this.lambda = new
|
|
1831
|
-
entry:
|
|
1832
|
-
runtime:
|
|
1945
|
+
this.lambda = new import_aws_lambda_nodejs6.NodejsFunction(this, "handler", {
|
|
1946
|
+
entry: resolveHandlerEntry6(__dirname),
|
|
1947
|
+
runtime: import_aws_lambda6.Runtime.NODEJS_LATEST,
|
|
1833
1948
|
memorySize: 128
|
|
1834
1949
|
});
|
|
1835
1950
|
}
|
|
1836
1951
|
};
|
|
1837
1952
|
|
|
1838
1953
|
// src/data/lambda/rest-api-lambda.ts
|
|
1839
|
-
var
|
|
1840
|
-
var
|
|
1841
|
-
var
|
|
1842
|
-
var
|
|
1843
|
-
var
|
|
1844
|
-
var
|
|
1845
|
-
function
|
|
1846
|
-
const sameDir =
|
|
1847
|
-
if (
|
|
1954
|
+
var import_node_fs7 = __toESM(require("fs"));
|
|
1955
|
+
var import_node_path7 = __toESM(require("path"));
|
|
1956
|
+
var import_aws_lambda7 = require("aws-cdk-lib/aws-lambda");
|
|
1957
|
+
var import_aws_lambda_nodejs7 = require("aws-cdk-lib/aws-lambda-nodejs");
|
|
1958
|
+
var import_constructs9 = require("constructs");
|
|
1959
|
+
var HANDLER_NAME7 = "rest-api-lambda.handler.js";
|
|
1960
|
+
function resolveHandlerEntry7(dirname) {
|
|
1961
|
+
const sameDir = import_node_path7.default.join(dirname, HANDLER_NAME7);
|
|
1962
|
+
if (import_node_fs7.default.existsSync(sameDir)) {
|
|
1848
1963
|
return sameDir;
|
|
1849
1964
|
}
|
|
1850
|
-
const fromLib =
|
|
1965
|
+
const fromLib = import_node_path7.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME7);
|
|
1851
1966
|
return fromLib;
|
|
1852
1967
|
}
|
|
1853
|
-
var RestApiLambda = class extends
|
|
1968
|
+
var RestApiLambda = class extends import_constructs9.Construct {
|
|
1854
1969
|
constructor(scope, props) {
|
|
1855
1970
|
super(scope, "rest-api-lambda");
|
|
1856
|
-
this.lambda = new
|
|
1857
|
-
entry:
|
|
1858
|
-
runtime:
|
|
1971
|
+
this.lambda = new import_aws_lambda_nodejs7.NodejsFunction(this, "handler", {
|
|
1972
|
+
entry: resolveHandlerEntry7(__dirname),
|
|
1973
|
+
runtime: import_aws_lambda7.Runtime.NODEJS_LATEST,
|
|
1859
1974
|
memorySize: 1024,
|
|
1860
1975
|
environment: {
|
|
1861
1976
|
DYNAMO_TABLE_NAME: props.dynamoTableName,
|
|
@@ -2211,6 +2326,7 @@ var OpenHiGraphqlService = _OpenHiGraphqlService;
|
|
|
2211
2326
|
POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME,
|
|
2212
2327
|
POSTGRES_REPLICA_SECRET_ARN_SSM_NAME,
|
|
2213
2328
|
PostAuthenticationLambda,
|
|
2329
|
+
PostConfirmationLambda,
|
|
2214
2330
|
PreTokenGenerationLambda,
|
|
2215
2331
|
REST_API_BASE_URL_SSM_NAME,
|
|
2216
2332
|
RootGraphqlApi,
|