@openhi/constructs 0.0.85 → 0.0.86

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.ts CHANGED
@@ -3,7 +3,7 @@ import { Construct, IConstruct } from 'constructs';
3
3
  import { ICertificate, Certificate, CertificateProps } from 'aws-cdk-lib/aws-certificatemanager';
4
4
  import { IHttpApi, HttpApiProps, HttpApi, DomainName } from 'aws-cdk-lib/aws-apigatewayv2';
5
5
  import { IGraphqlApi, GraphqlApi, GraphqlApiProps } from 'aws-cdk-lib/aws-appsync';
6
- import { UserPool, UserPoolProps, UserPoolClient, UserPoolClientProps, UserPoolDomain, UserPoolDomainProps, IUserPool, IUserPoolClient, IUserPoolDomain } from 'aws-cdk-lib/aws-cognito';
6
+ import { UserPoolClient, UserPoolClientProps, IUserPool, UserPool, UserPoolProps, UserPoolDomain, UserPoolDomainProps, IUserPoolClient, IUserPoolDomain } from 'aws-cdk-lib/aws-cognito';
7
7
  import { Key, KeyProps, IKey } from 'aws-cdk-lib/aws-kms';
8
8
  import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
9
9
  import { AttributeValue } from '@aws-sdk/client-dynamodb';
@@ -14,6 +14,8 @@ import * as kinesisfirehose from 'aws-cdk-lib/aws-kinesisfirehose';
14
14
  import * as s3 from 'aws-cdk-lib/aws-s3';
15
15
  import { IBucket, BucketProps } from 'aws-cdk-lib/aws-s3';
16
16
  import { Table, TableProps, ITable } from 'aws-cdk-lib/aws-dynamodb';
17
+ import * as ec2 from 'aws-cdk-lib/aws-ec2';
18
+ import * as rds from 'aws-cdk-lib/aws-rds';
17
19
  import { HostedZone, HostedZoneProps, IHostedZone, HostedZoneAttributes } from 'aws-cdk-lib/aws-route53';
18
20
  import { StringParameterProps, StringParameter } from 'aws-cdk-lib/aws-ssm';
19
21
  import { Distribution, DistributionProps } from 'aws-cdk-lib/aws-cloudfront';
@@ -482,6 +484,47 @@ declare class RootGraphqlApi extends GraphqlApi {
482
484
  constructor(scope: Construct, props?: Omit<RootGraphqlApiProps, "name">);
483
485
  }
484
486
 
487
+ interface CognitoFixtureSeederClientProps extends Partial<Omit<UserPoolClientProps, "userPool" | "generateSecret">> {
488
+ readonly userPool: IUserPool;
489
+ }
490
+ /**
491
+ * Dedicated Cognito app client for the OpenHI fixture-seeder CLI
492
+ * (`@openhi/seed-fixtures`).
493
+ *
494
+ * Why a dedicated client (vs reusing the SPA client):
495
+ * - Tightly scoped: only the seeder consumes tokens issued here, so an
496
+ * audit trail of seeder activity is cleanly separable.
497
+ * - Decoupled from the SPA client's OAuth flows — no risk of breaking
498
+ * web-app sign-in by tweaking auth-flow settings here.
499
+ * - Stage-conditional creation upstream (only provisioned in non-prod
500
+ * environments) means prod stacks never carry a code path that could
501
+ * issue a fixture-seeder token in the first place.
502
+ *
503
+ * Why USER_PASSWORD_AUTH (vs M2M client-credentials):
504
+ * - Cognito's M2M tier has a per-app-client monthly fee plus per-token
505
+ * activity charges. For sporadic non-prod fixture runs the per-client
506
+ * fee dominates the bill, especially if every dev branch spins up
507
+ * its own auth stack.
508
+ * - USER_PASSWORD_AUTH against a service `fixture-seeder` user keeps
509
+ * the cost in MAU territory (free under the 50K MAU tier).
510
+ * - Tradeoff: passwords need rotation and the service user must be
511
+ * provisioned per non-prod environment (manual or scripted post-deploy).
512
+ *
513
+ * No client secret (`generateSecret: false`): USER_PASSWORD_AUTH
514
+ * authenticates with the password directly; a secret would just add
515
+ * another credential to manage without strengthening anything.
516
+ */
517
+ declare class CognitoFixtureSeederClient extends UserPoolClient {
518
+ /**
519
+ * SSM parameter name suffix used to publish this client's ID for
520
+ * cross-stack lookups. Built into a full parameter name via
521
+ * `buildParameterName` with `serviceType` AUTH (since the auth stack
522
+ * owns this resource).
523
+ */
524
+ static readonly SSM_PARAM_NAME = "COGNITO_FIXTURE_SEEDER_CLIENT";
525
+ constructor(scope: Construct, props: CognitoFixtureSeederClientProps);
526
+ }
527
+
485
528
  /**
486
529
  * @see sites/www-docs/content/packages/@openhi/constructs/components/cognito/cognito-user-pool.md
487
530
  */
@@ -619,13 +662,25 @@ interface DynamoDbDataStoreProps extends Omit<TableProps, "tableName" | "removal
619
662
  readonly removalPolicy?: RemovalPolicy;
620
663
  }
621
664
  /**
622
- * DynamoDB table implementing the single-table design for app data (e.g. FHIR
623
- * resources and configuration).
665
+ * DynamoDB table implementing the single-table design for app data (FHIR
666
+ * resources data plane and platform control plane), per planning ADR-011 and
667
+ * DR-004.
624
668
  *
625
669
  * @see {@link https://github.com/codedrifters/openhi/blob/main/sites/www-docs/content/architecture/dynamodb-single-table-design.md | DynamoDB Single-Table Design}
626
670
  *
627
671
  * Primary key: PK (String), SK (String).
628
- * GSIs: GSI1 (reverse reference), GSI2 (identifier lookup), GSI3 (facility ops), GSI4 (resource type list).
672
+ *
673
+ * GSIs:
674
+ * - **GSI1 — Unified Sharded List** (`GSI1PK`/`GSI1SK`, INCLUDE projection per
675
+ * DR-004). Primary list/lookup index for both data-plane FHIR resources and
676
+ * control-plane entities (User, Tenant, Workspace, Membership, Role,
677
+ * RoleAssignment, Configuration). PK shape:
678
+ * `TID#<tid>#WID#<wid>#RT#<Type>#SHARD#<n>` with 4 shards
679
+ * (`n = hash(id) mod 4`). SK shape per `extractSortKey`: labeled types use
680
+ * `<normalizedLabel>#<id>`; unlabeled use `<ISO-8601 lastUpdated>#<id>`.
681
+ * - **GSI2 — Sub-Lookup** (`GSI2PK`/`GSI2SK`, INCLUDE projection). Resolves
682
+ * `UserEntity` from a Cognito `sub` for the Pre Token Generation Lambda.
683
+ * PK shape: `USER#SUB#<cognitoSub>`. SK shape: `CURRENT`.
629
684
  *
630
685
  * For historical archive to S3, pass `kinesisStream` and `stream` (e.g.
631
686
  * `StreamViewType.NEW_AND_OLD_IMAGES`) on the table props per ADR 2026-03-11-02.
@@ -664,6 +719,111 @@ declare class OpsEventBus extends EventBus {
664
719
  constructor(scope: Construct, props?: EventBusProps);
665
720
  }
666
721
 
722
+ /**
723
+ * SSM parameter names that publish the Postgres replica's coordinates so other
724
+ * stacks (notably the REST API stack) can discover them without a direct CDK
725
+ * cross-stack reference. The schema name is intentionally NOT published — it
726
+ * is a deterministic function of `branchHash` and consumers compute it locally
727
+ * via {@link getPostgresReplicaSchemaName}.
728
+ */
729
+ declare const POSTGRES_REPLICA_CLUSTER_ARN_SSM_NAME = "POSTGRES_REPLICA_CLUSTER_ARN";
730
+ declare const POSTGRES_REPLICA_SECRET_ARN_SSM_NAME = "POSTGRES_REPLICA_SECRET_ARN";
731
+ declare const POSTGRES_REPLICA_DATABASE_NAME_SSM_NAME = "POSTGRES_REPLICA_DATABASE_NAME";
732
+ /**
733
+ * Derive the per-branch Postgres schema name from a branch hash. The `b_`
734
+ * prefix guarantees a leading letter (Postgres identifier rule). Branch hashes
735
+ * are 6 hex chars from {@link OpenHiService.branchHash} so the resulting
736
+ * `b_xxxxxx` is well within the 63-byte identifier limit.
737
+ */
738
+ declare function getPostgresReplicaSchemaName(branchHash: string): string;
739
+ interface DataStorePostgresReplicaProps {
740
+ /**
741
+ * Kinesis stream that receives DynamoDB item-level changes (the same stream
742
+ * that backs {@link DataStoreHistoricalArchive}). The replication Lambda is
743
+ * registered as a parallel consumer.
744
+ */
745
+ readonly kinesisStream: kinesis.IStream;
746
+ /**
747
+ * Removal policy for the cluster, secret, and dependent resources.
748
+ */
749
+ readonly removalPolicy: RemovalPolicy;
750
+ /**
751
+ * Short hash unique to the stack — used in the cluster identifier.
752
+ */
753
+ readonly stackHash: string;
754
+ /**
755
+ * Short hash unique to the branch — used to derive the per-branch schema
756
+ * name (`b_<branchHash>`) inside the Postgres database.
757
+ */
758
+ readonly branchHash: string;
759
+ /**
760
+ * Optional VPC override. If absent, the construct creates a minimal isolated
761
+ * VPC (2 AZs, no NAT gateways) just for the cluster and replication Lambda.
762
+ */
763
+ readonly vpc?: ec2.IVpc;
764
+ /**
765
+ * Optional database name override.
766
+ * @default "openhi"
767
+ */
768
+ readonly databaseName?: string;
769
+ /**
770
+ * Aurora Serverless v2 minimum capacity in ACUs. Defaults to 1 so the
771
+ * writer stays warm — avoids the ~10–20s scale-up wait that a cold
772
+ * (0 ACU) cluster imposes on the next request. Set explicitly to 0 to
773
+ * opt back into scale-to-zero if idle cost becomes the dominant concern.
774
+ */
775
+ readonly minCapacity?: number;
776
+ /**
777
+ * Aurora Serverless v2 maximum capacity in ACUs. Defaults to 2 — adequate
778
+ * for the PoC's replication-only workload.
779
+ */
780
+ readonly maxCapacity?: number;
781
+ }
782
+ /**
783
+ * DynamoDB change stream → Postgres replication tier (ADR 2026-04-17-01,
784
+ * phase 1). Provisions an Aurora Serverless v2 PostgreSQL cluster and a
785
+ * Lambda consumer on the existing change-stream that projects each current
786
+ * FHIR resource into a JSONB `resources` table under a per-branch schema.
787
+ *
788
+ * Phase 1 is replication-only; query routing and SearchParameter-specific
789
+ * indexes are intentionally deferred. Per-branch *clusters* (rather than the
790
+ * shared cluster suggested by the ADR) are an explicit PoC simplification —
791
+ * see the ADR's "Operational notes" section for the long-term direction.
792
+ *
793
+ * @see sites/www-docs/content/architecture/adr/2026-04-17-01-ad-hoc-query-support-fhir-api.md
794
+ */
795
+ declare class DataStorePostgresReplica extends Construct {
796
+ /**
797
+ * Resolve the cluster ARN published by an upstream {@link DataStorePostgresReplica}.
798
+ * Use from any stack that needs to grant `rds-data:ExecuteStatement` against
799
+ * the cluster.
800
+ */
801
+ static clusterArnFromConstruct(scope: Construct): string;
802
+ /**
803
+ * Resolve the credentials secret ARN published by an upstream
804
+ * {@link DataStorePostgresReplica}. Use from any stack that needs to grant
805
+ * `secretsmanager:GetSecretValue` against the secret.
806
+ */
807
+ static secretArnFromConstruct(scope: Construct): string;
808
+ /**
809
+ * Resolve the database name published by an upstream
810
+ * {@link DataStorePostgresReplica}.
811
+ */
812
+ static databaseNameFromConstruct(scope: Construct): string;
813
+ readonly vpc: ec2.IVpc;
814
+ readonly cluster: rds.DatabaseCluster;
815
+ readonly replicationFunction: NodejsFunction;
816
+ readonly databaseName: string;
817
+ readonly schemaName: string;
818
+ constructor(scope: Construct, id: string, props: DataStorePostgresReplicaProps);
819
+ /**
820
+ * Publishes the cluster ARN, secret ARN, and database name as discoverable
821
+ * SSM parameters so the REST API stack (and any future read-side consumer)
822
+ * can wire RDS Data API access without a direct CDK cross-stack reference.
823
+ */
824
+ private publishCoordinatesToSsm;
825
+ }
826
+
667
827
  /**
668
828
  * @see sites/www-docs/content/packages/@openhi/constructs/components/route-53/child-hosted-zone.md
669
829
  */
@@ -842,6 +1002,17 @@ declare class OpenHiAuthService extends OpenHiService {
842
1002
  * Returns an IUserPoolClient by looking up the Auth stack's User Pool Client ID from SSM.
843
1003
  */
844
1004
  static userPoolClientFromConstruct(scope: Construct): IUserPoolClient;
1005
+ /**
1006
+ * Returns the dedicated fixture-seeder IUserPoolClient by looking up
1007
+ * its ID from SSM. Only non-prod auth stacks publish this parameter
1008
+ * (per the conditional in {@link createFixtureSeederClient}); calling
1009
+ * this against a prod-deployed stack will fail at lookup time.
1010
+ *
1011
+ * Consumed by `OpenHiRestApiService` (in non-prod) so the authorizer
1012
+ * accepts tokens issued by this client, and by the seed-fixtures CLI
1013
+ * to drive USER_PASSWORD_AUTH against this client's ID.
1014
+ */
1015
+ static fixtureSeederClientFromConstruct(scope: Construct): IUserPoolClient;
845
1016
  /**
846
1017
  * Returns an IUserPoolDomain by looking up the Auth stack's User Pool Domain from SSM.
847
1018
  */
@@ -858,6 +1029,12 @@ declare class OpenHiAuthService extends OpenHiService {
858
1029
  readonly userPool: IUserPool;
859
1030
  readonly userPoolClient: IUserPoolClient;
860
1031
  readonly userPoolDomain: IUserPoolDomain;
1032
+ /**
1033
+ * Dedicated USER_PASSWORD_AUTH client for the seed-fixtures CLI.
1034
+ * Only created in non-prod environments (see
1035
+ * {@link createFixtureSeederClient}). `undefined` in prod.
1036
+ */
1037
+ readonly fixtureSeederClient?: IUserPoolClient;
861
1038
  constructor(ohEnv: OpenHiEnvironment, props?: OpenHiAuthServiceProps);
862
1039
  /**
863
1040
  * Creates the KMS key for the Cognito User Pool and exports its ARN to SSM.
@@ -882,6 +1059,18 @@ declare class OpenHiAuthService extends OpenHiService {
882
1059
  * Override to customize.
883
1060
  */
884
1061
  protected createUserPoolClient(): IUserPoolClient;
1062
+ /**
1063
+ * Creates the dedicated USER_PASSWORD_AUTH app client for the
1064
+ * `@openhi/seed-fixtures` CLI, **only** in non-prod environments.
1065
+ * Returns `undefined` when this stack is being deployed to a prod
1066
+ * stage so the prod auth stack carries no fixture-seeder code path.
1067
+ *
1068
+ * Operator post-deploy: create a `fixture-seeder` Cognito user with
1069
+ * a service password (manually via console or scripted with
1070
+ * `aws cognito-idp admin-create-user`); the CLI consumes those creds
1071
+ * via env vars to drive `InitiateAuth`.
1072
+ */
1073
+ protected createFixtureSeederClient(): IUserPoolClient | undefined;
885
1074
  /**
886
1075
  * Creates the User Pool Domain (Cognito hosted UI) and exports domain name to SSM.
887
1076
  * Look up via {@link OpenHiAuthService.userPoolDomainFromConstruct}.
@@ -1078,6 +1267,13 @@ declare class OpenHiDataService extends OpenHiService {
1078
1267
  * notifications for current FHIR resources (ADRs 2026-03-11-02, 2026-03-02-01).
1079
1268
  */
1080
1269
  readonly dataStoreHistoricalArchive: DataStoreHistoricalArchive;
1270
+ /**
1271
+ * Postgres replication tier (ADR 2026-04-17-01, phase 1). A second consumer
1272
+ * on the change stream that projects current FHIR resources into a JSONB
1273
+ * `resources` table on Aurora Serverless v2. Phase 1 is replication-only;
1274
+ * the read path is not wired up yet.
1275
+ */
1276
+ readonly dataStorePostgresReplica: DataStorePostgresReplica;
1081
1277
  constructor(ohEnv: OpenHiEnvironment, props?: OpenHiDataServiceProps);
1082
1278
  /**
1083
1279
  * Creates the data event bus.
@@ -1118,5 +1314,5 @@ declare class OpenHiGraphqlService extends OpenHiService {
1118
1314
  protected createRootGraphqlApi(): RootGraphqlApi;
1119
1315
  }
1120
1316
 
1121
- export { ChildHostedZone, CognitoUserPool, CognitoUserPoolClient, CognitoUserPoolDomain, CognitoUserPoolKmsKey, DATA_STORE_CHANGE_DETAIL_MAX_UTF8_BYTES, DATA_STORE_CHANGE_DETAIL_TYPE, DATA_STORE_CHANGE_EVENT_SOURCE, DataEventBus, DataStoreHistoricalArchive, DiscoverableStringParameter, DynamoDbDataStore, OpenHiApp, OpenHiAuthService, OpenHiDataService, OpenHiEnvironment, OpenHiGlobalService, OpenHiGraphqlService, OpenHiRestApiService, OpenHiService, OpenHiStage, OpsEventBus, PreTokenGenerationLambda, REST_API_BASE_URL_SSM_NAME, RootGraphqlApi, RootHostedZone, RootHttpApi, RootWildcardCertificate, STATIC_HOSTING_SERVICE_TYPE, StaticHosting, buildFhirCurrentResourceChangeDetail, getDynamoDbDataStoreTableName };
1122
- export type { BuildParameterNameProps, ChildHostedZoneProps, DataStoreHistoricalArchiveProps, DiscoverableStringParameterProps, DynamoDbDataStoreProps, FhirCurrentResourceChangeDetail, OpenHiAppProps, OpenHiAuthServiceProps, OpenHiDataServiceProps, OpenHiEnvironmentProps, OpenHiGlobalServiceProps, OpenHiGraphqlServiceProps, OpenHiRestApiServiceProps, OpenHiServiceProps, OpenHiServiceType, OpenHiStageProps, RootGraphqlApiProps, RootHttpApiProps, StaticHostingProps };
1317
+ 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, PreTokenGenerationLambda, REST_API_BASE_URL_SSM_NAME, RootGraphqlApi, RootHostedZone, RootHttpApi, RootWildcardCertificate, STATIC_HOSTING_SERVICE_TYPE, StaticHosting, buildFhirCurrentResourceChangeDetail, getDynamoDbDataStoreTableName, getPostgresReplicaSchemaName };
1318
+ export type { BuildParameterNameProps, ChildHostedZoneProps, CognitoFixtureSeederClientProps, DataStoreHistoricalArchiveProps, DataStorePostgresReplicaProps, DiscoverableStringParameterProps, DynamoDbDataStoreProps, FhirCurrentResourceChangeDetail, OpenHiAppProps, OpenHiAuthServiceProps, OpenHiDataServiceProps, OpenHiEnvironmentProps, OpenHiGlobalServiceProps, OpenHiGraphqlServiceProps, OpenHiRestApiServiceProps, OpenHiServiceProps, OpenHiServiceType, OpenHiStageProps, RootGraphqlApiProps, RootHttpApiProps, StaticHostingProps };