@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.mjs CHANGED
@@ -576,6 +576,7 @@ CognitoFixtureSeederClient.SSM_PARAM_NAME = "COGNITO_FIXTURE_SEEDER_CLIENT";
576
576
 
577
577
  // src/components/cognito/cognito-user-pool.ts
578
578
  import {
579
+ FeaturePlan,
579
580
  UserPool,
580
581
  VerificationEmailStyle
581
582
  } from "aws-cdk-lib/aws-cognito";
@@ -596,6 +597,10 @@ var CognitoUserPool = class extends UserPool {
596
597
  emailStyle: VerificationEmailStyle.CODE
597
598
  },
598
599
  removalPolicy: props.removalPolicy ?? service.removalPolicy,
600
+ // Plus is required for access-token V2 claim customization in the
601
+ // pre-token-generation Lambda. Essentials silently drops
602
+ // claimsAndScopeOverrideDetails.accessTokenGeneration.claimsToAddOrOverride.
603
+ featurePlan: FeaturePlan.PLUS,
599
604
  /**
600
605
  * Over-rideable props
601
606
  */
@@ -744,12 +749,15 @@ function resolveHandlerEntry3(dirname) {
744
749
  return fromLib;
745
750
  }
746
751
  var PreTokenGenerationLambda = class extends Construct3 {
747
- constructor(scope) {
752
+ constructor(scope, props) {
748
753
  super(scope, "pre-token-generation-lambda");
749
754
  this.lambda = new NodejsFunction3(this, "handler", {
750
755
  entry: resolveHandlerEntry3(__dirname),
751
756
  runtime: Runtime3.NODEJS_LATEST,
752
- memorySize: 1024
757
+ memorySize: 1024,
758
+ environment: {
759
+ DYNAMO_TABLE_NAME: props.dynamoTableName
760
+ }
753
761
  });
754
762
  }
755
763
  };
@@ -1358,6 +1366,7 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1358
1366
  this.postAuthenticationLambda = this.createPostAuthenticationLambda();
1359
1367
  this.postConfirmationLambda = this.createPostConfirmationLambda();
1360
1368
  this.userPool = this.createUserPool();
1369
+ this.grantPreTokenGenerationPermissions();
1361
1370
  this.grantPostAuthenticationPermissions();
1362
1371
  this.grantPostConfirmationPermissions();
1363
1372
  this.userPoolClient = this.createUserPoolClient();
@@ -1450,11 +1459,15 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1450
1459
  return key;
1451
1460
  }
1452
1461
  /**
1453
- * Creates the Pre Token Generation Lambda (Cognito trigger). Phase 2 will add
1454
- * openhi_* claims to the access token only; trigger version V2_0 may be required.
1462
+ * Creates the Pre Token Generation Lambda (Cognito trigger). On every
1463
+ * sign-in and token refresh the Lambda resolves the User by Cognito `sub`
1464
+ * (GSI2) and injects `ohi_tid`, `ohi_wid`, `ohi_uid`, `ohi_uname` into
1465
+ * both the ID token and the access token (ADR 2026-03-17-01).
1455
1466
  */
1456
1467
  createPreTokenGenerationLambda() {
1457
- const construct = new PreTokenGenerationLambda(this);
1468
+ const construct = new PreTokenGenerationLambda(this, {
1469
+ dynamoTableName: this.dataStoreTable().tableName
1470
+ });
1458
1471
  return construct.lambda;
1459
1472
  }
1460
1473
  /**
@@ -1515,6 +1528,27 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
1515
1528
  });
1516
1529
  return userPool;
1517
1530
  }
1531
+ /**
1532
+ * Grants the Pre Token Generation Lambda read-only access on the data
1533
+ * store table and its GSIs. The Lambda only needs:
1534
+ * - `Query` on GSI2 to resolve a User by Cognito `sub`
1535
+ * - `GetItem` on the base table for direct User reads
1536
+ *
1537
+ * No write or scan access: a User missing `currentTenant`/`currentWorkspace`
1538
+ * falls into the absent-claims path; repair belongs in a separate backfill.
1539
+ */
1540
+ grantPreTokenGenerationPermissions() {
1541
+ const dataStoreTable = this.dataStoreTable();
1542
+ const dynamoActions = ["dynamodb:GetItem", "dynamodb:Query"];
1543
+ dataStoreTable.grant(this.preTokenGenerationLambda, ...dynamoActions);
1544
+ this.preTokenGenerationLambda.addToRolePolicy(
1545
+ new PolicyStatement({
1546
+ effect: Effect.ALLOW,
1547
+ actions: [...dynamoActions],
1548
+ resources: [`${dataStoreTable.tableArn}/index/*`]
1549
+ })
1550
+ );
1551
+ }
1518
1552
  /**
1519
1553
  * Grants the Post Authentication Lambda permission to call
1520
1554
  * `cognito-idp:AdminUserGlobalSignOut`.