@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.
@@ -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 {
@@ -23,7 +23,6 @@ var cloudfront = require('aws-cdk-lib/aws-cloudfront');
23
23
  var origins = require('aws-cdk-lib/aws-cloudfront-origins');
24
24
  var wafv2 = require('aws-cdk-lib/aws-wafv2');
25
25
  var dynamodb = require('aws-cdk-lib/aws-dynamodb');
26
- var fabric = require('@jaypie/fabric');
27
26
  var cr = require('aws-cdk-lib/custom-resources');
28
27
  var cdkNextjsStandalone = require('cdk-nextjs-standalone');
29
28
  var path = require('path');
@@ -2690,14 +2689,17 @@ class JaypieDistribution extends constructs.Construct {
2690
2689
  sampledRequestsEnabled: true,
2691
2690
  },
2692
2691
  });
2692
+ const webAclName = wafConfig.name
2693
+ ? constructEnvName(`${wafConfig.name}-WebAcl`)
2694
+ : constructEnvName("WebAcl");
2693
2695
  const webAcl = new wafv2__namespace.CfnWebACL(this, "WebAcl", {
2694
2696
  defaultAction: { allow: {} },
2695
- name: constructEnvName("WebAcl"),
2697
+ name: webAclName,
2696
2698
  rules,
2697
2699
  scope: "CLOUDFRONT",
2698
2700
  visibilityConfig: {
2699
2701
  cloudWatchMetricsEnabled: true,
2700
- metricName: constructEnvName("WebAcl"),
2702
+ metricName: webAclName,
2701
2703
  sampledRequestsEnabled: true,
2702
2704
  },
2703
2705
  });
@@ -2713,8 +2715,14 @@ class JaypieDistribution extends constructs.Construct {
2713
2715
  let wafLogBucket;
2714
2716
  if (wafLogBucketProp === true) {
2715
2717
  // Create inline WAF logging bucket with Datadog forwarding
2716
- const createdBucket = new s3__namespace.Bucket(this, constructEnvName("WafLogBucket"), {
2717
- bucketName: `aws-waf-logs-${constructEnvName("waf").toLowerCase()}`,
2718
+ const wafLogBucketId = wafConfig.name
2719
+ ? constructEnvName(`${wafConfig.name}-WafLogBucket`)
2720
+ : constructEnvName("WafLogBucket");
2721
+ const wafLogBucketName = wafConfig.name
2722
+ ? `aws-waf-logs-${constructEnvName(`${wafConfig.name}-waf`).toLowerCase()}`
2723
+ : `aws-waf-logs-${constructEnvName("waf").toLowerCase()}`;
2724
+ const createdBucket = new s3__namespace.Bucket(this, wafLogBucketId, {
2725
+ bucketName: wafLogBucketName,
2718
2726
  lifecycleRules: [
2719
2727
  {
2720
2728
  expiration: cdk.Duration.days(90),
@@ -2936,17 +2944,43 @@ class JaypieDnsRecord extends constructs.Construct {
2936
2944
  // Helper Functions
2937
2945
  //
2938
2946
  /**
2939
- * Convert IndexDefinition[] from @jaypie/fabric to CDK GlobalSecondaryIndexPropsV2[].
2947
+ * Derive GSI attribute names for an index definition.
2940
2948
  *
2941
- * Uses `getGsiAttributeNames` as the single source of truth so runtime writes
2942
- * and CDK provisioning agree on attribute names. Composite sk indexes
2943
- * (sk.length > 1) get a dedicated STRING `{indexName}Sk` attribute; single-field
2944
- * sk indexes reference the field directly (STRING in the general case, NUMBER
2945
- * for the legacy `sequence` name).
2949
+ * Mirrors `@jaypie/fabric`'s `getGsiAttributeNames` so CDK provisioning and
2950
+ * any runtime write path agree on the attribute names. Kept local to avoid
2951
+ * a runtime dependency on the pre-1.0 `@jaypie/fabric` package.
2952
+ *
2953
+ * - `pk` is always the index name (`index.name` or generated from `index.pk`)
2954
+ * - `sk` is the single sk field name when `sk.length === 1`, or
2955
+ * `{indexName}Sk` when `sk.length > 1` (composite sk attribute)
2956
+ */
2957
+ function getGsiAttributeNames(index) {
2958
+ const name = index.name ?? generateIndexName(index.pk);
2959
+ let sk;
2960
+ if (index.sk && index.sk.length > 1) {
2961
+ sk = `${name}Sk`;
2962
+ }
2963
+ else if (index.sk && index.sk.length === 1) {
2964
+ sk = index.sk[0];
2965
+ }
2966
+ return { pk: name, sk };
2967
+ }
2968
+ function generateIndexName(pk) {
2969
+ const suffix = pk
2970
+ .map((field) => field.charAt(0).toUpperCase() + field.slice(1))
2971
+ .join("");
2972
+ return `index${suffix}`;
2973
+ }
2974
+ /**
2975
+ * Convert IndexDefinition[] to CDK GlobalSecondaryIndexPropsV2[].
2976
+ *
2977
+ * Composite sk indexes (sk.length > 1) get a dedicated STRING `{indexName}Sk`
2978
+ * attribute; single-field sk indexes reference the field directly (STRING in
2979
+ * the general case, NUMBER for the legacy `sequence` name).
2946
2980
  */
2947
2981
  function indexesToGsi(indexes) {
2948
2982
  return indexes.map((index) => {
2949
- const { pk, sk } = fabric.getGsiAttributeNames(index);
2983
+ const { pk, sk } = getGsiAttributeNames(index);
2950
2984
  let sortKey;
2951
2985
  if (sk) {
2952
2986
  if (sk === "sequence") {
@@ -2986,11 +3020,13 @@ function indexesToGsi(indexes) {
2986
3020
  * const table = new JaypieDynamoDb(this, "myApp");
2987
3021
  *
2988
3022
  * @example
2989
- * // With fabricIndex() for GSIs
2990
- * import { fabricIndex } from "@jaypie/fabric";
3023
+ * // With inline IndexDefinition for GSIs
2991
3024
  * const table = new JaypieDynamoDb(this, "MyTable", {
2992
3025
  * tableName: "custom-table-name",
2993
- * indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
3026
+ * indexes: [
3027
+ * { name: "indexModel", pk: ["model"], sk: ["scope", "updatedAt"] },
3028
+ * { name: "indexModelAlias", pk: ["model", "alias"], sk: ["scope", "updatedAt"], sparse: true },
3029
+ * ],
2994
3030
  * });
2995
3031
  */
2996
3032
  class JaypieDynamoDb extends constructs.Construct {