@openhi/constructs 0.0.92 → 0.0.94
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.d.mts +28 -5
- package/lib/index.d.ts +28 -5
- package/lib/index.js +38 -5
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +39 -5
- package/lib/index.mjs.map +1 -1
- 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/package.json +1 -1
package/lib/index.d.mts
CHANGED
|
@@ -500,12 +500,23 @@ declare class PostConfirmationLambda extends Construct {
|
|
|
500
500
|
constructor(scope: Construct, props: PostConfirmationLambdaProps);
|
|
501
501
|
}
|
|
502
502
|
|
|
503
|
+
interface PreTokenGenerationLambdaProps {
|
|
504
|
+
/**
|
|
505
|
+
* DynamoDB data store table name. Passed to the Lambda as DYNAMO_TABLE_NAME
|
|
506
|
+
* so the control-plane ElectroDB service reads the User by Cognito `sub`
|
|
507
|
+
* (GSI2) and the user's first active Membership (fallback path).
|
|
508
|
+
*/
|
|
509
|
+
readonly dynamoTableName: string;
|
|
510
|
+
}
|
|
503
511
|
/**
|
|
504
|
-
* Lambda used as Cognito Pre Token Generation trigger.
|
|
512
|
+
* Lambda used as Cognito Pre Token Generation trigger. Resolves the OpenHI
|
|
513
|
+
* User from the request's Cognito `sub` and injects `ohi_tid`, `ohi_wid`,
|
|
514
|
+
* `ohi_uid`, `ohi_uname` into both the ID token and the access token
|
|
515
|
+
* (ADR 2026-03-17-01).
|
|
505
516
|
*/
|
|
506
517
|
declare class PreTokenGenerationLambda extends Construct {
|
|
507
518
|
readonly lambda: NodejsFunction;
|
|
508
|
-
constructor(scope: Construct);
|
|
519
|
+
constructor(scope: Construct, props: PreTokenGenerationLambdaProps);
|
|
509
520
|
}
|
|
510
521
|
|
|
511
522
|
/**
|
|
@@ -983,8 +994,10 @@ declare class OpenHiAuthService extends OpenHiService {
|
|
|
983
994
|
*/
|
|
984
995
|
protected createUserPoolKmsKey(): IKey;
|
|
985
996
|
/**
|
|
986
|
-
* Creates the Pre Token Generation Lambda (Cognito trigger).
|
|
987
|
-
*
|
|
997
|
+
* Creates the Pre Token Generation Lambda (Cognito trigger). On every
|
|
998
|
+
* sign-in and token refresh the Lambda resolves the User by Cognito `sub`
|
|
999
|
+
* (GSI2) and injects `ohi_tid`, `ohi_wid`, `ohi_uid`, `ohi_uname` into
|
|
1000
|
+
* both the ID token and the access token (ADR 2026-03-17-01).
|
|
988
1001
|
*/
|
|
989
1002
|
protected createPreTokenGenerationLambda(): IFunction;
|
|
990
1003
|
/**
|
|
@@ -1008,6 +1021,16 @@ declare class OpenHiAuthService extends OpenHiService {
|
|
|
1008
1021
|
* Override to customize.
|
|
1009
1022
|
*/
|
|
1010
1023
|
protected createUserPool(): IUserPool;
|
|
1024
|
+
/**
|
|
1025
|
+
* Grants the Pre Token Generation Lambda read-only access on the data
|
|
1026
|
+
* store table and its GSIs. The Lambda only needs:
|
|
1027
|
+
* - `Query` on GSI2 to resolve a User by Cognito `sub`
|
|
1028
|
+
* - `GetItem` on the base table for direct User reads
|
|
1029
|
+
*
|
|
1030
|
+
* No write or scan access: a User missing `currentTenant`/`currentWorkspace`
|
|
1031
|
+
* falls into the absent-claims path; repair belongs in a separate backfill.
|
|
1032
|
+
*/
|
|
1033
|
+
protected grantPreTokenGenerationPermissions(): void;
|
|
1011
1034
|
/**
|
|
1012
1035
|
* Grants the Post Authentication Lambda permission to call
|
|
1013
1036
|
* `cognito-idp:AdminUserGlobalSignOut`.
|
|
@@ -1289,4 +1312,4 @@ declare class OpenHiGraphqlService extends OpenHiService {
|
|
|
1289
1312
|
protected createRootGraphqlApi(): RootGraphqlApi;
|
|
1290
1313
|
}
|
|
1291
1314
|
|
|
1292
|
-
export { type BuildParameterNameProps, ChildHostedZone, type ChildHostedZoneProps, CognitoFixtureSeederClient, type CognitoFixtureSeederClientProps, CognitoUserPool, CognitoUserPoolClient, CognitoUserPoolDomain, CognitoUserPoolKmsKey, DATA_STORE_CHANGE_DETAIL_MAX_UTF8_BYTES, DATA_STORE_CHANGE_DETAIL_TYPE, DATA_STORE_CHANGE_EVENT_SOURCE, DataEventBus, DataStoreHistoricalArchive, type DataStoreHistoricalArchiveProps, DataStorePostgresReplica, type DataStorePostgresReplicaProps, DiscoverableStringParameter, type DiscoverableStringParameterProps, DynamoDbDataStore, type DynamoDbDataStoreProps, type FhirCurrentResourceChangeDetail, OpenHiApp, type OpenHiAppProps, OpenHiAuthService, type OpenHiAuthServiceProps, OpenHiDataService, type OpenHiDataServiceProps, OpenHiEnvironment, type OpenHiEnvironmentProps, OpenHiGlobalService, type OpenHiGlobalServiceProps, OpenHiGraphqlService, type OpenHiGraphqlServiceProps, OpenHiRestApiService, type OpenHiRestApiServiceProps, OpenHiService, type OpenHiServiceProps, type OpenHiServiceType, OpenHiStage, type OpenHiStageProps, OpsEventBus, POSTGRES_REPLICA_CLUSTER_ARN_SSM_NAME, POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME, POSTGRES_REPLICA_SECRET_ARN_SSM_NAME, PostAuthenticationLambda, PostConfirmationLambda, type PostConfirmationLambdaProps, PreTokenGenerationLambda, REST_API_BASE_URL_SSM_NAME, RootGraphqlApi, type RootGraphqlApiProps, RootHostedZone, RootHttpApi, type RootHttpApiProps, RootWildcardCertificate, STATIC_HOSTING_SERVICE_TYPE, StaticHosting, type StaticHostingProps, buildFhirCurrentResourceChangeDetail, getDynamoDbDataStoreTableName, getPostgresReplicaSchemaName };
|
|
1315
|
+
export { type BuildParameterNameProps, ChildHostedZone, type ChildHostedZoneProps, CognitoFixtureSeederClient, type CognitoFixtureSeederClientProps, CognitoUserPool, CognitoUserPoolClient, CognitoUserPoolDomain, CognitoUserPoolKmsKey, DATA_STORE_CHANGE_DETAIL_MAX_UTF8_BYTES, DATA_STORE_CHANGE_DETAIL_TYPE, DATA_STORE_CHANGE_EVENT_SOURCE, DataEventBus, DataStoreHistoricalArchive, type DataStoreHistoricalArchiveProps, DataStorePostgresReplica, type DataStorePostgresReplicaProps, DiscoverableStringParameter, type DiscoverableStringParameterProps, DynamoDbDataStore, type DynamoDbDataStoreProps, type FhirCurrentResourceChangeDetail, OpenHiApp, type OpenHiAppProps, OpenHiAuthService, type OpenHiAuthServiceProps, OpenHiDataService, type OpenHiDataServiceProps, OpenHiEnvironment, type OpenHiEnvironmentProps, OpenHiGlobalService, type OpenHiGlobalServiceProps, OpenHiGraphqlService, type OpenHiGraphqlServiceProps, OpenHiRestApiService, type OpenHiRestApiServiceProps, OpenHiService, type OpenHiServiceProps, type OpenHiServiceType, OpenHiStage, type OpenHiStageProps, OpsEventBus, POSTGRES_REPLICA_CLUSTER_ARN_SSM_NAME, POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME, POSTGRES_REPLICA_SECRET_ARN_SSM_NAME, PostAuthenticationLambda, PostConfirmationLambda, type PostConfirmationLambdaProps, PreTokenGenerationLambda, type PreTokenGenerationLambdaProps, REST_API_BASE_URL_SSM_NAME, RootGraphqlApi, type RootGraphqlApiProps, RootHostedZone, RootHttpApi, type RootHttpApiProps, RootWildcardCertificate, STATIC_HOSTING_SERVICE_TYPE, StaticHosting, type StaticHostingProps, buildFhirCurrentResourceChangeDetail, getDynamoDbDataStoreTableName, getPostgresReplicaSchemaName };
|
package/lib/index.d.ts
CHANGED
|
@@ -595,12 +595,23 @@ declare class PostConfirmationLambda extends Construct {
|
|
|
595
595
|
constructor(scope: Construct, props: PostConfirmationLambdaProps);
|
|
596
596
|
}
|
|
597
597
|
|
|
598
|
+
interface PreTokenGenerationLambdaProps {
|
|
599
|
+
/**
|
|
600
|
+
* DynamoDB data store table name. Passed to the Lambda as DYNAMO_TABLE_NAME
|
|
601
|
+
* so the control-plane ElectroDB service reads the User by Cognito `sub`
|
|
602
|
+
* (GSI2) and the user's first active Membership (fallback path).
|
|
603
|
+
*/
|
|
604
|
+
readonly dynamoTableName: string;
|
|
605
|
+
}
|
|
598
606
|
/**
|
|
599
|
-
* Lambda used as Cognito Pre Token Generation trigger.
|
|
607
|
+
* Lambda used as Cognito Pre Token Generation trigger. Resolves the OpenHI
|
|
608
|
+
* User from the request's Cognito `sub` and injects `ohi_tid`, `ohi_wid`,
|
|
609
|
+
* `ohi_uid`, `ohi_uname` into both the ID token and the access token
|
|
610
|
+
* (ADR 2026-03-17-01).
|
|
600
611
|
*/
|
|
601
612
|
declare class PreTokenGenerationLambda extends Construct {
|
|
602
613
|
readonly lambda: NodejsFunction;
|
|
603
|
-
constructor(scope: Construct);
|
|
614
|
+
constructor(scope: Construct, props: PreTokenGenerationLambdaProps);
|
|
604
615
|
}
|
|
605
616
|
|
|
606
617
|
/**
|
|
@@ -1078,8 +1089,10 @@ declare class OpenHiAuthService extends OpenHiService {
|
|
|
1078
1089
|
*/
|
|
1079
1090
|
protected createUserPoolKmsKey(): IKey;
|
|
1080
1091
|
/**
|
|
1081
|
-
* Creates the Pre Token Generation Lambda (Cognito trigger).
|
|
1082
|
-
*
|
|
1092
|
+
* Creates the Pre Token Generation Lambda (Cognito trigger). On every
|
|
1093
|
+
* sign-in and token refresh the Lambda resolves the User by Cognito `sub`
|
|
1094
|
+
* (GSI2) and injects `ohi_tid`, `ohi_wid`, `ohi_uid`, `ohi_uname` into
|
|
1095
|
+
* both the ID token and the access token (ADR 2026-03-17-01).
|
|
1083
1096
|
*/
|
|
1084
1097
|
protected createPreTokenGenerationLambda(): IFunction;
|
|
1085
1098
|
/**
|
|
@@ -1103,6 +1116,16 @@ declare class OpenHiAuthService extends OpenHiService {
|
|
|
1103
1116
|
* Override to customize.
|
|
1104
1117
|
*/
|
|
1105
1118
|
protected createUserPool(): IUserPool;
|
|
1119
|
+
/**
|
|
1120
|
+
* Grants the Pre Token Generation Lambda read-only access on the data
|
|
1121
|
+
* store table and its GSIs. The Lambda only needs:
|
|
1122
|
+
* - `Query` on GSI2 to resolve a User by Cognito `sub`
|
|
1123
|
+
* - `GetItem` on the base table for direct User reads
|
|
1124
|
+
*
|
|
1125
|
+
* No write or scan access: a User missing `currentTenant`/`currentWorkspace`
|
|
1126
|
+
* falls into the absent-claims path; repair belongs in a separate backfill.
|
|
1127
|
+
*/
|
|
1128
|
+
protected grantPreTokenGenerationPermissions(): void;
|
|
1106
1129
|
/**
|
|
1107
1130
|
* Grants the Post Authentication Lambda permission to call
|
|
1108
1131
|
* `cognito-idp:AdminUserGlobalSignOut`.
|
|
@@ -1385,4 +1408,4 @@ declare class OpenHiGraphqlService extends OpenHiService {
|
|
|
1385
1408
|
}
|
|
1386
1409
|
|
|
1387
1410
|
export { ChildHostedZone, CognitoFixtureSeederClient, CognitoUserPool, CognitoUserPoolClient, CognitoUserPoolDomain, CognitoUserPoolKmsKey, DATA_STORE_CHANGE_DETAIL_MAX_UTF8_BYTES, DATA_STORE_CHANGE_DETAIL_TYPE, DATA_STORE_CHANGE_EVENT_SOURCE, DataEventBus, DataStoreHistoricalArchive, DataStorePostgresReplica, DiscoverableStringParameter, DynamoDbDataStore, OpenHiApp, OpenHiAuthService, OpenHiDataService, OpenHiEnvironment, OpenHiGlobalService, OpenHiGraphqlService, OpenHiRestApiService, OpenHiService, OpenHiStage, OpsEventBus, POSTGRES_REPLICA_CLUSTER_ARN_SSM_NAME, POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME, POSTGRES_REPLICA_SECRET_ARN_SSM_NAME, PostAuthenticationLambda, PostConfirmationLambda, PreTokenGenerationLambda, REST_API_BASE_URL_SSM_NAME, RootGraphqlApi, RootHostedZone, RootHttpApi, RootWildcardCertificate, STATIC_HOSTING_SERVICE_TYPE, StaticHosting, buildFhirCurrentResourceChangeDetail, getDynamoDbDataStoreTableName, getPostgresReplicaSchemaName };
|
|
1388
|
-
export type { BuildParameterNameProps, ChildHostedZoneProps, CognitoFixtureSeederClientProps, DataStoreHistoricalArchiveProps, DataStorePostgresReplicaProps, DiscoverableStringParameterProps, DynamoDbDataStoreProps, FhirCurrentResourceChangeDetail, OpenHiAppProps, OpenHiAuthServiceProps, OpenHiDataServiceProps, OpenHiEnvironmentProps, OpenHiGlobalServiceProps, OpenHiGraphqlServiceProps, OpenHiRestApiServiceProps, OpenHiServiceProps, OpenHiServiceType, OpenHiStageProps, PostConfirmationLambdaProps, RootGraphqlApiProps, RootHttpApiProps, StaticHostingProps };
|
|
1411
|
+
export type { BuildParameterNameProps, ChildHostedZoneProps, CognitoFixtureSeederClientProps, DataStoreHistoricalArchiveProps, DataStorePostgresReplicaProps, DiscoverableStringParameterProps, DynamoDbDataStoreProps, FhirCurrentResourceChangeDetail, OpenHiAppProps, OpenHiAuthServiceProps, OpenHiDataServiceProps, OpenHiEnvironmentProps, OpenHiGlobalServiceProps, OpenHiGraphqlServiceProps, OpenHiRestApiServiceProps, OpenHiServiceProps, OpenHiServiceType, OpenHiStageProps, PostConfirmationLambdaProps, PreTokenGenerationLambdaProps, RootGraphqlApiProps, RootHttpApiProps, StaticHostingProps };
|
package/lib/index.js
CHANGED
|
@@ -647,6 +647,10 @@ var CognitoUserPool = class extends import_aws_cognito2.UserPool {
|
|
|
647
647
|
emailStyle: import_aws_cognito2.VerificationEmailStyle.CODE
|
|
648
648
|
},
|
|
649
649
|
removalPolicy: props.removalPolicy ?? service.removalPolicy,
|
|
650
|
+
// Plus is required for access-token V2 claim customization in the
|
|
651
|
+
// pre-token-generation Lambda. Essentials silently drops
|
|
652
|
+
// claimsAndScopeOverrideDetails.accessTokenGeneration.claimsToAddOrOverride.
|
|
653
|
+
featurePlan: import_aws_cognito2.FeaturePlan.PLUS,
|
|
650
654
|
/**
|
|
651
655
|
* Over-rideable props
|
|
652
656
|
*/
|
|
@@ -795,12 +799,15 @@ function resolveHandlerEntry3(dirname) {
|
|
|
795
799
|
return fromLib;
|
|
796
800
|
}
|
|
797
801
|
var PreTokenGenerationLambda = class extends import_constructs3.Construct {
|
|
798
|
-
constructor(scope) {
|
|
802
|
+
constructor(scope, props) {
|
|
799
803
|
super(scope, "pre-token-generation-lambda");
|
|
800
804
|
this.lambda = new import_aws_lambda_nodejs3.NodejsFunction(this, "handler", {
|
|
801
805
|
entry: resolveHandlerEntry3(__dirname),
|
|
802
806
|
runtime: import_aws_lambda3.Runtime.NODEJS_LATEST,
|
|
803
|
-
memorySize: 1024
|
|
807
|
+
memorySize: 1024,
|
|
808
|
+
environment: {
|
|
809
|
+
DYNAMO_TABLE_NAME: props.dynamoTableName
|
|
810
|
+
}
|
|
804
811
|
});
|
|
805
812
|
}
|
|
806
813
|
};
|
|
@@ -1513,6 +1520,7 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1513
1520
|
this.postAuthenticationLambda = this.createPostAuthenticationLambda();
|
|
1514
1521
|
this.postConfirmationLambda = this.createPostConfirmationLambda();
|
|
1515
1522
|
this.userPool = this.createUserPool();
|
|
1523
|
+
this.grantPreTokenGenerationPermissions();
|
|
1516
1524
|
this.grantPostAuthenticationPermissions();
|
|
1517
1525
|
this.grantPostConfirmationPermissions();
|
|
1518
1526
|
this.userPoolClient = this.createUserPoolClient();
|
|
@@ -1605,11 +1613,15 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1605
1613
|
return key;
|
|
1606
1614
|
}
|
|
1607
1615
|
/**
|
|
1608
|
-
* Creates the Pre Token Generation Lambda (Cognito trigger).
|
|
1609
|
-
*
|
|
1616
|
+
* Creates the Pre Token Generation Lambda (Cognito trigger). On every
|
|
1617
|
+
* sign-in and token refresh the Lambda resolves the User by Cognito `sub`
|
|
1618
|
+
* (GSI2) and injects `ohi_tid`, `ohi_wid`, `ohi_uid`, `ohi_uname` into
|
|
1619
|
+
* both the ID token and the access token (ADR 2026-03-17-01).
|
|
1610
1620
|
*/
|
|
1611
1621
|
createPreTokenGenerationLambda() {
|
|
1612
|
-
const construct = new PreTokenGenerationLambda(this
|
|
1622
|
+
const construct = new PreTokenGenerationLambda(this, {
|
|
1623
|
+
dynamoTableName: this.dataStoreTable().tableName
|
|
1624
|
+
});
|
|
1613
1625
|
return construct.lambda;
|
|
1614
1626
|
}
|
|
1615
1627
|
/**
|
|
@@ -1670,6 +1682,27 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1670
1682
|
});
|
|
1671
1683
|
return userPool;
|
|
1672
1684
|
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Grants the Pre Token Generation Lambda read-only access on the data
|
|
1687
|
+
* store table and its GSIs. The Lambda only needs:
|
|
1688
|
+
* - `Query` on GSI2 to resolve a User by Cognito `sub`
|
|
1689
|
+
* - `GetItem` on the base table for direct User reads
|
|
1690
|
+
*
|
|
1691
|
+
* No write or scan access: a User missing `currentTenant`/`currentWorkspace`
|
|
1692
|
+
* falls into the absent-claims path; repair belongs in a separate backfill.
|
|
1693
|
+
*/
|
|
1694
|
+
grantPreTokenGenerationPermissions() {
|
|
1695
|
+
const dataStoreTable = this.dataStoreTable();
|
|
1696
|
+
const dynamoActions = ["dynamodb:GetItem", "dynamodb:Query"];
|
|
1697
|
+
dataStoreTable.grant(this.preTokenGenerationLambda, ...dynamoActions);
|
|
1698
|
+
this.preTokenGenerationLambda.addToRolePolicy(
|
|
1699
|
+
new import_aws_iam.PolicyStatement({
|
|
1700
|
+
effect: import_aws_iam.Effect.ALLOW,
|
|
1701
|
+
actions: [...dynamoActions],
|
|
1702
|
+
resources: [`${dataStoreTable.tableArn}/index/*`]
|
|
1703
|
+
})
|
|
1704
|
+
);
|
|
1705
|
+
}
|
|
1673
1706
|
/**
|
|
1674
1707
|
* Grants the Post Authentication Lambda permission to call
|
|
1675
1708
|
* `cognito-idp:AdminUserGlobalSignOut`.
|