@digitraffic/common 2025.5.5-1 → 2025.6.16-1

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/README.md CHANGED
@@ -17,6 +17,10 @@ Format code
17
17
  pnpm run:format-changed # Formats stagged files
18
18
  pnpm run:format # Format all files
19
19
 
20
+ ## Reinstall lefthook git hooks
21
+
22
+ pnpm prepare
23
+
20
24
  ## How to use
21
25
 
22
26
  In package.json dependencies:
@@ -21,8 +21,13 @@ describe("acl-builder tests", () => {
21
21
  ]).build();
22
22
  expect(acl.rules).toHaveLength(2);
23
23
  });
24
- test("ip restriction", () => {
25
- const acl = createBuilder().withIpRestrictionRule(["1.2.3.4", "1.2.6.6"])
24
+ test("ip blacklist", () => {
25
+ const acl = createBuilder().withIpBlacklistRule(["1.2.3.4", "1.2.6.6"])
26
+ .build();
27
+ expect(acl.rules).toHaveLength(1);
28
+ });
29
+ test("ip whitelist", () => {
30
+ const acl = createBuilder().withIpWhitelistRule(["1.2.3.4", "1.2.6.6"])
26
31
  .build();
27
32
  expect(acl.rules).toHaveLength(1);
28
33
  });
@@ -12,7 +12,7 @@ export type CfnWebAclRuleProperty = {
12
12
  *
13
13
  * Currently supports:
14
14
  * * Some AWS managed WAF rules
15
- * * IP blacklisting
15
+ * * IP blacklisting/whitelisting
16
16
  */
17
17
  export declare class AclBuilder {
18
18
  readonly _construct: Construct;
@@ -23,18 +23,25 @@ export declare class AclBuilder {
23
23
  _customResponseBodies: Record<string, CfnWebACL.CustomResponseBodyProperty>;
24
24
  constructor(construct: Construct, name?: string);
25
25
  isRuleDefined(rules: AWSManagedWafRule[] | "all", rule: AWSManagedWafRule): boolean;
26
- withAWSManagedRules(rules?: AWSManagedWafRule[] | "all", excludedRules?: ExcludedAWSRules): AclBuilder;
27
- withIpRestrictionRule(addresses: string[]): AclBuilder;
28
- withThrottleRule(name: string, limit: number, isHeaderRequired: boolean, isBasedOnIpAndUriPath: boolean, customResponseBodyKey?: string): AclBuilder;
29
- withCustomResponseBody(key: string, customResponseBody: CfnWebACL.CustomResponseBodyProperty): AclBuilder;
30
- withThrottleDigitrafficUserIp(limit: number | undefined): AclBuilder;
31
- withThrottleDigitrafficUserIpAndUriPath(limit: number | undefined): AclBuilder;
26
+ withAWSManagedRules(rules?: AWSManagedWafRule[] | "all", excludedRules?: ExcludedAWSRules): this;
27
+ /**
28
+ * Block access from given addresses
29
+ */
30
+ withIpBlacklistRule(addresses: string[]): this;
31
+ /**
32
+ * Allow access only from the given addresses
33
+ */
34
+ withIpWhitelistRule(addresses: string[]): this;
35
+ withThrottleRule(name: string, limit: number, isHeaderRequired: boolean, isBasedOnIpAndUriPath: boolean, customResponseBodyKey?: string): this;
36
+ withCustomResponseBody(key: string, customResponseBody: CfnWebACL.CustomResponseBodyProperty): this;
37
+ withThrottleDigitrafficUserIp(limit: number | undefined): this;
38
+ withThrottleDigitrafficUserIpAndUriPath(limit: number | undefined): this;
32
39
  withThrottleAnonymousUserIp(limit: number | undefined): AclBuilder;
33
- withThrottleAnonymousUserIpAndUriPath(limit: number | undefined): AclBuilder;
34
- withCountDigitrafficUserIp(limit: number | undefined): AclBuilder;
35
- withCountDigitrafficUserIpAndUriPath(limit: number | undefined): AclBuilder;
36
- withCountAnonymousUserIp(limit: number | undefined): AclBuilder;
37
- withCountAnonymousUserIpAndUriPath(limit: number | undefined): AclBuilder;
40
+ withThrottleAnonymousUserIpAndUriPath(limit: number | undefined): this;
41
+ withCountDigitrafficUserIp(limit: number | undefined): this;
42
+ withCountDigitrafficUserIpAndUriPath(limit: number | undefined): this;
43
+ withCountAnonymousUserIp(limit: number | undefined): this;
44
+ withCountAnonymousUserIpAndUriPath(limit: number | undefined): this;
38
45
  _isCustomResponseBodyKeySet(key: string): boolean;
39
46
  _addThrottleResponseBody(customResponseBodyKey: string, limit: number): void;
40
47
  build(): CfnWebACL;
@@ -6,7 +6,7 @@ import { concat, range, zipWith } from "lodash-es";
6
6
  *
7
7
  * Currently supports:
8
8
  * * Some AWS managed WAF rules
9
- * * IP blacklisting
9
+ * * IP blacklisting/whitelisting
10
10
  */
11
11
  export class AclBuilder {
12
12
  _construct;
@@ -37,7 +37,10 @@ export class AclBuilder {
37
37
  }
38
38
  return this;
39
39
  }
40
- withIpRestrictionRule(addresses) {
40
+ /**
41
+ * Block access from given addresses
42
+ */
43
+ withIpBlacklistRule(addresses) {
41
44
  const blocklistIpSet = new CfnIPSet(this._construct, "BlocklistIpSet", {
42
45
  ipAddressVersion: "IPV4",
43
46
  scope: this._scope,
@@ -59,6 +62,35 @@ export class AclBuilder {
59
62
  });
60
63
  return this;
61
64
  }
65
+ /**
66
+ * Allow access only from the given addresses
67
+ */
68
+ withIpWhitelistRule(addresses) {
69
+ const blocklistIpSet = new CfnIPSet(this._construct, "AllowlistIpSet", {
70
+ ipAddressVersion: "IPV4",
71
+ scope: this._scope,
72
+ addresses,
73
+ });
74
+ this._blockRules.push({
75
+ name: "IpAllowlist",
76
+ action: { block: {} },
77
+ statement: {
78
+ notStatement: {
79
+ statement: {
80
+ ipSetReferenceStatement: {
81
+ arn: blocklistIpSet.attrArn,
82
+ },
83
+ },
84
+ },
85
+ },
86
+ visibilityConfig: {
87
+ sampledRequestsEnabled: false,
88
+ cloudWatchMetricsEnabled: true,
89
+ metricName: "IpAllowlist",
90
+ },
91
+ });
92
+ return this;
93
+ }
62
94
  withThrottleRule(name, limit, isHeaderRequired, isBasedOnIpAndUriPath, customResponseBodyKey) {
63
95
  const isBlockRule = !!customResponseBodyKey;
64
96
  const rules = isBlockRule ? this._blockRules : this._countRules;