@jaypie/constructs 1.2.43 → 1.2.45

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.
@@ -10,7 +10,7 @@ export { JaypieDatadogSecret } from "./JaypieDatadogSecret";
10
10
  export { JaypieDistribution, JaypieDistributionProps, JaypieWafConfig, SecurityHeadersOverrides, } from "./JaypieDistribution";
11
11
  export { JaypieDnsRecord, JaypieDnsRecordProps } from "./JaypieDnsRecord";
12
12
  export { JaypieDynamoDb, JaypieDynamoDbProps } from "./JaypieDynamoDb";
13
- export type { IndexDefinition } from "@jaypie/fabric";
13
+ export type { IndexDefinition } from "./types/IndexDefinition";
14
14
  export { JaypieEnvSecret } from "./JaypieEnvSecret";
15
15
  export { JaypieEventsRule, JaypieEventsRuleProps } from "./JaypieEventsRule";
16
16
  export { JaypieExpressLambda } from "./JaypieExpressLambda";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * GSI index definition for JaypieDynamoDb.
3
+ *
4
+ * Shape mirrors `@jaypie/fabric`'s IndexDefinition so a single object can be
5
+ * shared between CDK provisioning (here) and runtime model code (fabric).
6
+ * The type is owned locally so `@jaypie/constructs` does not take a runtime
7
+ * dependency on the pre-1.0 `@jaypie/fabric` package.
8
+ *
9
+ * - `pk` fields are combined with a separator to form the partition key attribute
10
+ * - `sk` with one field uses that field directly as the GSI sort key
11
+ * - `sk` with multiple fields produces a composite `{indexName}Sk` attribute
12
+ */
13
+ export interface IndexDefinition {
14
+ /** Name of the index (auto-generated from pk fields if not provided) */
15
+ name?: string;
16
+ /** Partition key fields - combined with separator */
17
+ pk: string[];
18
+ /** Sort key fields - combined with separator when composite */
19
+ sk?: string[];
20
+ /** Advisory: index key is only written when all pk/sk fields are present */
21
+ sparse?: boolean;
22
+ }
@@ -9,6 +9,15 @@ import * as wafv2 from "aws-cdk-lib/aws-wafv2";
9
9
  import { Construct } from "constructs";
10
10
  import { HostConfig } from "./helpers";
11
11
  export interface JaypieWafConfig {
12
+ /**
13
+ * Unique name for this distribution's WAF resources. Required when passing a
14
+ * WAF config object. Injected into the WebACL name and WAF log bucket name
15
+ * so multiple JaypieDistribution instances can coexist in the same
16
+ * account/env without S3/WAFv2 name collisions.
17
+ *
18
+ * Pass `waf: true` (or omit) to retain the legacy, non-namespaced names.
19
+ */
20
+ name: string;
12
21
  /**
13
22
  * Whether WAF is enabled
14
23
  * @default true
@@ -1,22 +1,24 @@
1
1
  import { Construct } from "constructs";
2
2
  import { RemovalPolicy } from "aws-cdk-lib";
3
3
  import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
- import { type IndexDefinition } from "@jaypie/fabric";
4
+ import type { IndexDefinition } from "./types/IndexDefinition";
5
5
  export interface JaypieDynamoDbProps extends Omit<dynamodb.TablePropsV2, "globalSecondaryIndexes" | "partitionKey" | "sortKey"> {
6
6
  /**
7
- * Configure GSIs for the table using @jaypie/fabric IndexDefinition format.
7
+ * Configure GSIs for the table using the IndexDefinition format.
8
8
  * - `undefined`: No GSIs (default)
9
- * - Array of IndexDefinition: Use the specified indexes (prefer fabricIndex())
9
+ * - Array of IndexDefinition: Use the specified indexes
10
10
  *
11
11
  * @example
12
12
  * // No GSIs (default)
13
13
  * new JaypieDynamoDb(this, "myTable");
14
14
  *
15
15
  * @example
16
- * // With fabricIndex-shaped indexes
17
- * import { fabricIndex } from "@jaypie/fabric";
16
+ * // Inline indexes
18
17
  * new JaypieDynamoDb(this, "myTable", {
19
- * indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
18
+ * indexes: [
19
+ * { name: "indexModel", pk: ["model"], sk: ["scope", "updatedAt"] },
20
+ * { name: "indexModelAlias", pk: ["model", "alias"], sk: ["scope", "updatedAt"], sparse: true },
21
+ * ],
20
22
  * });
21
23
  */
22
24
  indexes?: IndexDefinition[];
@@ -62,11 +64,13 @@ export interface JaypieDynamoDbProps extends Omit<dynamodb.TablePropsV2, "global
62
64
  * const table = new JaypieDynamoDb(this, "myApp");
63
65
  *
64
66
  * @example
65
- * // With fabricIndex() for GSIs
66
- * import { fabricIndex } from "@jaypie/fabric";
67
+ * // With inline IndexDefinition for GSIs
67
68
  * const table = new JaypieDynamoDb(this, "MyTable", {
68
69
  * tableName: "custom-table-name",
69
- * indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
70
+ * indexes: [
71
+ * { name: "indexModel", pk: ["model"], sk: ["scope", "updatedAt"] },
72
+ * { name: "indexModelAlias", pk: ["model", "alias"], sk: ["scope", "updatedAt"], sparse: true },
73
+ * ],
70
74
  * });
71
75
  */
72
76
  export declare class JaypieDynamoDb extends Construct implements dynamodb.ITableV2 {
@@ -10,7 +10,7 @@ export { JaypieDatadogSecret } from "./JaypieDatadogSecret";
10
10
  export { JaypieDistribution, JaypieDistributionProps, JaypieWafConfig, SecurityHeadersOverrides, } from "./JaypieDistribution";
11
11
  export { JaypieDnsRecord, JaypieDnsRecordProps } from "./JaypieDnsRecord";
12
12
  export { JaypieDynamoDb, JaypieDynamoDbProps } from "./JaypieDynamoDb";
13
- export type { IndexDefinition } from "@jaypie/fabric";
13
+ export type { IndexDefinition } from "./types/IndexDefinition";
14
14
  export { JaypieEnvSecret } from "./JaypieEnvSecret";
15
15
  export { JaypieEventsRule, JaypieEventsRuleProps } from "./JaypieEventsRule";
16
16
  export { JaypieExpressLambda } from "./JaypieExpressLambda";
package/dist/esm/index.js CHANGED
@@ -26,7 +26,6 @@ import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
26
26
  import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
27
27
  import * as wafv2 from 'aws-cdk-lib/aws-wafv2';
28
28
  import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
29
- import { getGsiAttributeNames } from '@jaypie/fabric';
30
29
  import * as cr from 'aws-cdk-lib/custom-resources';
31
30
  import { Nextjs } from 'cdk-nextjs-standalone';
32
31
  import * as path from 'path';
@@ -2654,14 +2653,17 @@ class JaypieDistribution extends Construct {
2654
2653
  sampledRequestsEnabled: true,
2655
2654
  },
2656
2655
  });
2656
+ const webAclName = wafConfig.name
2657
+ ? constructEnvName(`${wafConfig.name}-WebAcl`)
2658
+ : constructEnvName("WebAcl");
2657
2659
  const webAcl = new wafv2.CfnWebACL(this, "WebAcl", {
2658
2660
  defaultAction: { allow: {} },
2659
- name: constructEnvName("WebAcl"),
2661
+ name: webAclName,
2660
2662
  rules,
2661
2663
  scope: "CLOUDFRONT",
2662
2664
  visibilityConfig: {
2663
2665
  cloudWatchMetricsEnabled: true,
2664
- metricName: constructEnvName("WebAcl"),
2666
+ metricName: webAclName,
2665
2667
  sampledRequestsEnabled: true,
2666
2668
  },
2667
2669
  });
@@ -2677,8 +2679,14 @@ class JaypieDistribution extends Construct {
2677
2679
  let wafLogBucket;
2678
2680
  if (wafLogBucketProp === true) {
2679
2681
  // Create inline WAF logging bucket with Datadog forwarding
2680
- const createdBucket = new s3.Bucket(this, constructEnvName("WafLogBucket"), {
2681
- bucketName: `aws-waf-logs-${constructEnvName("waf").toLowerCase()}`,
2682
+ const wafLogBucketId = wafConfig.name
2683
+ ? constructEnvName(`${wafConfig.name}-WafLogBucket`)
2684
+ : constructEnvName("WafLogBucket");
2685
+ const wafLogBucketName = wafConfig.name
2686
+ ? `aws-waf-logs-${constructEnvName(`${wafConfig.name}-waf`).toLowerCase()}`
2687
+ : `aws-waf-logs-${constructEnvName("waf").toLowerCase()}`;
2688
+ const createdBucket = new s3.Bucket(this, wafLogBucketId, {
2689
+ bucketName: wafLogBucketName,
2682
2690
  lifecycleRules: [
2683
2691
  {
2684
2692
  expiration: Duration.days(90),
@@ -2900,13 +2908,39 @@ class JaypieDnsRecord extends Construct {
2900
2908
  // Helper Functions
2901
2909
  //
2902
2910
  /**
2903
- * Convert IndexDefinition[] from @jaypie/fabric to CDK GlobalSecondaryIndexPropsV2[].
2911
+ * Derive GSI attribute names for an index definition.
2904
2912
  *
2905
- * Uses `getGsiAttributeNames` as the single source of truth so runtime writes
2906
- * and CDK provisioning agree on attribute names. Composite sk indexes
2907
- * (sk.length > 1) get a dedicated STRING `{indexName}Sk` attribute; single-field
2908
- * sk indexes reference the field directly (STRING in the general case, NUMBER
2909
- * for the legacy `sequence` name).
2913
+ * Mirrors `@jaypie/fabric`'s `getGsiAttributeNames` so CDK provisioning and
2914
+ * any runtime write path agree on the attribute names. Kept local to avoid
2915
+ * a runtime dependency on the pre-1.0 `@jaypie/fabric` package.
2916
+ *
2917
+ * - `pk` is always the index name (`index.name` or generated from `index.pk`)
2918
+ * - `sk` is the single sk field name when `sk.length === 1`, or
2919
+ * `{indexName}Sk` when `sk.length > 1` (composite sk attribute)
2920
+ */
2921
+ function getGsiAttributeNames(index) {
2922
+ const name = index.name ?? generateIndexName(index.pk);
2923
+ let sk;
2924
+ if (index.sk && index.sk.length > 1) {
2925
+ sk = `${name}Sk`;
2926
+ }
2927
+ else if (index.sk && index.sk.length === 1) {
2928
+ sk = index.sk[0];
2929
+ }
2930
+ return { pk: name, sk };
2931
+ }
2932
+ function generateIndexName(pk) {
2933
+ const suffix = pk
2934
+ .map((field) => field.charAt(0).toUpperCase() + field.slice(1))
2935
+ .join("");
2936
+ return `index${suffix}`;
2937
+ }
2938
+ /**
2939
+ * Convert IndexDefinition[] to CDK GlobalSecondaryIndexPropsV2[].
2940
+ *
2941
+ * Composite sk indexes (sk.length > 1) get a dedicated STRING `{indexName}Sk`
2942
+ * attribute; single-field sk indexes reference the field directly (STRING in
2943
+ * the general case, NUMBER for the legacy `sequence` name).
2910
2944
  */
2911
2945
  function indexesToGsi(indexes) {
2912
2946
  return indexes.map((index) => {
@@ -2950,11 +2984,13 @@ function indexesToGsi(indexes) {
2950
2984
  * const table = new JaypieDynamoDb(this, "myApp");
2951
2985
  *
2952
2986
  * @example
2953
- * // With fabricIndex() for GSIs
2954
- * import { fabricIndex } from "@jaypie/fabric";
2987
+ * // With inline IndexDefinition for GSIs
2955
2988
  * const table = new JaypieDynamoDb(this, "MyTable", {
2956
2989
  * tableName: "custom-table-name",
2957
- * indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
2990
+ * indexes: [
2991
+ * { name: "indexModel", pk: ["model"], sk: ["scope", "updatedAt"] },
2992
+ * { name: "indexModelAlias", pk: ["model", "alias"], sk: ["scope", "updatedAt"], sparse: true },
2993
+ * ],
2958
2994
  * });
2959
2995
  */
2960
2996
  class JaypieDynamoDb extends Construct {