@fy-stack/storage-construct 0.0.143 → 0.0.145

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.
@@ -12,6 +12,8 @@ import type { StorageConstructProps } from './types';
12
12
  export declare class StorageConstruct extends Construct implements Attachable, Grantable, CDNResource {
13
13
  bucket: s3.IBucket;
14
14
  table: dynamo.Table | undefined;
15
+ private cdnLink;
16
+ private readonly keyGroup;
15
17
  constructor(scope: Construct, id: string, props: StorageConstructProps);
16
18
  cloudfront(path: string): {
17
19
  [x: string]: cdk.aws_cloudfront.BehaviorOptions;
@@ -19,8 +21,11 @@ export declare class StorageConstruct extends Construct implements Attachable, G
19
21
  cloudfrontPolicy(distributionId: string): any;
20
22
  attachable(): {
21
23
  NAME: string;
24
+ DOMAIN: string;
22
25
  ARN: string;
23
26
  LOG_TABLE: string;
27
+ KEY_PAIR_ID: string;
28
+ CDN_LINK: string;
24
29
  };
25
30
  grantable(grant: iam.IGrantable): void;
26
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"storage-construct.d.ts","sourceRoot":"","sources":["../../src/lib/storage-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD;;;GAGG;AACH,qBAAa,gBACX,SAAQ,SACR,YAAW,UAAU,EAAE,SAAS,EAAE,WAAW;IAEtC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,CAA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ports, "__esModule", { value: true });
3
3
  exports.StorageConstruct = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("node:fs"));
5
6
  const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
6
7
  const aws_cdk_lib_1 = require("aws-cdk-lib");
7
8
  const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
@@ -17,6 +18,8 @@ const storage_cdn_stack_1 = require("./storage-cdn-stack");
17
18
  class StorageConstruct extends constructs_1.Construct {
18
19
  bucket;
19
20
  table;
21
+ cdnLink = false;
22
+ keyGroup;
20
23
  constructor(scope, id, props) {
21
24
  super(scope, id);
22
25
  const bucketProps = {
@@ -29,8 +32,8 @@ class StorageConstruct extends constructs_1.Construct {
29
32
  s3.HttpMethods.PUT,
30
33
  s3.HttpMethods.DELETE,
31
34
  ],
32
- allowedHeaders: ["*"],
33
- exposedHeaders: ["ETag"]
35
+ allowedHeaders: ['*'],
36
+ exposedHeaders: ['ETag'],
34
37
  },
35
38
  ],
36
39
  };
@@ -46,6 +49,17 @@ class StorageConstruct extends constructs_1.Construct {
46
49
  },
47
50
  });
48
51
  }
52
+ if (props.keys?.length) {
53
+ const keys = [];
54
+ for (const i in props.keys) {
55
+ keys.push(new cloudfront.PublicKey(this, `CDNPublicKey${i}`, {
56
+ encodedKey: fs.readFileSync(props.keys[i]).toString(),
57
+ }));
58
+ }
59
+ this.keyGroup = new cloudfront.KeyGroup(this, 'CDNKeyGroup', {
60
+ items: keys,
61
+ });
62
+ }
49
63
  }
50
64
  cloudfront(path) {
51
65
  const storageOriginStack = new storage_cdn_stack_1.StorageCdnStack(this, 'StorageCDNStack', {
@@ -58,7 +72,9 @@ class StorageConstruct extends constructs_1.Construct {
58
72
  allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
59
73
  cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
60
74
  viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
75
+ trustedKeyGroups: this.keyGroup ? [this.keyGroup] : undefined,
61
76
  };
77
+ this.cdnLink = true;
62
78
  return { [`${path}/*`]: storageBehavior };
63
79
  }
64
80
  cloudfrontPolicy(distributionId) {
@@ -81,8 +97,11 @@ class StorageConstruct extends constructs_1.Construct {
81
97
  attachable() {
82
98
  return {
83
99
  NAME: this.bucket.bucketName,
100
+ DOMAIN: this.bucket.bucketDomainName,
84
101
  ARN: this.bucket.bucketArn,
85
102
  LOG_TABLE: this.table?.tableName ?? '',
103
+ KEY_PAIR_ID: this.keyGroup?.keyGroupId ?? '',
104
+ CDN_LINK: `${this.cdnLink}`,
86
105
  };
87
106
  }
88
107
  grantable(grant) {
@@ -6,6 +6,7 @@ export interface StorageConstructProps {
6
6
  /** Retain bucket when stack is deleted */
7
7
  retainOnDelete?: boolean;
8
8
  logTable?: boolean;
9
+ keys?: string[];
9
10
  }
10
11
  /**
11
12
  * Interface representing the properties required for configuring a storage stack in CDK.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAA;CAClB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAA;CAClB"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fy-stack/storage-construct",
3
- "version": "0.0.143",
3
+ "version": "0.0.145",
4
4
  "repository": "https://github.com/festusyuma/fy-stack",
5
5
  "dependencies": {
6
- "@fy-stack/types": "0.0.143",
6
+ "@fy-stack/types": "0.0.145",
7
7
  "tslib": "^2.3.0"
8
8
  },
9
9
  "peerDependencies": {