@digitraffic/common 2026.10.2-2 → 2026.10.23-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.
|
@@ -32,6 +32,16 @@ describe("acl-builder tests", () => {
|
|
|
32
32
|
.build();
|
|
33
33
|
expect(acl.rules).toHaveLength(1);
|
|
34
34
|
});
|
|
35
|
+
test("geo block", () => {
|
|
36
|
+
const acl = createBuilder().withGeoBlockRule(["C1", "C2"]).build();
|
|
37
|
+
const geoBlockRule = acl.rules[0];
|
|
38
|
+
expect(geoBlockRule.action).toEqual({ block: {} });
|
|
39
|
+
expect(geoBlockRule.statement).toEqual({
|
|
40
|
+
geoMatchStatement: {
|
|
41
|
+
countryCodes: ["C1", "C2"],
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
});
|
|
35
45
|
test("throttle rules", () => {
|
|
36
46
|
for (const aclBuilder of [
|
|
37
47
|
createBuilder().withThrottleDigitrafficUserIp(100),
|
|
@@ -69,6 +79,16 @@ describe("acl-builder tests", () => {
|
|
|
69
79
|
expect(scopeDownStatements).toHaveLength(2);
|
|
70
80
|
expect(regexMatchStatement.regexString).toBe("^\\/roadnetwork\\/");
|
|
71
81
|
});
|
|
82
|
+
test("path throttle rules have unique names", () => {
|
|
83
|
+
const acl = createBuilder()
|
|
84
|
+
.withThrottleAnonymousUserIpByUriPath(100, /^\/first/, "First")
|
|
85
|
+
.withThrottleAnonymousUserIpByUriPath(100, /^\/second/, "Second")
|
|
86
|
+
.build();
|
|
87
|
+
expect(acl.rules.map((rule) => rule.name)).toEqual([
|
|
88
|
+
"ThrottleRuleWithAnonymousUserByPath-First",
|
|
89
|
+
"ThrottleRuleWithAnonymousUserByPath-Second",
|
|
90
|
+
]);
|
|
91
|
+
});
|
|
72
92
|
test("Cannot define two rules with the same name", () => {
|
|
73
93
|
expect(() => createBuilder()
|
|
74
94
|
.withThrottleAnonymousUserIp(10)
|
|
@@ -32,6 +32,10 @@ export declare class AclBuilder {
|
|
|
32
32
|
* Allow access only from the given addresses
|
|
33
33
|
*/
|
|
34
34
|
withIpWhitelistRule(addresses: string[]): this;
|
|
35
|
+
/**
|
|
36
|
+
* Block access from the given ISO 3166-1 alpha-2 country codes.
|
|
37
|
+
*/
|
|
38
|
+
withGeoBlockRule(countryCodes: string[]): this;
|
|
35
39
|
/**
|
|
36
40
|
* Adds a rate-based WAF rule for either blocking or counting requests.
|
|
37
41
|
*
|
|
@@ -48,7 +52,7 @@ export declare class AclBuilder {
|
|
|
48
52
|
withThrottleDigitrafficUserIp(limit: number | undefined): this;
|
|
49
53
|
withThrottleDigitrafficUserIpAndUriPath(limit: number | undefined): this;
|
|
50
54
|
withThrottleAnonymousUserIp(limit: number | undefined): AclBuilder;
|
|
51
|
-
withThrottleAnonymousUserIpByUriPath(limit: number | undefined, path: RegExp | undefined): AclBuilder;
|
|
55
|
+
withThrottleAnonymousUserIpByUriPath(limit: number | undefined, path: RegExp | undefined, ruleId?: string): AclBuilder;
|
|
52
56
|
/**
|
|
53
57
|
* Throttles anonymous requests by IP address and URI path.
|
|
54
58
|
*
|
|
@@ -91,6 +91,29 @@ export class AclBuilder {
|
|
|
91
91
|
});
|
|
92
92
|
return this;
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Block access from the given ISO 3166-1 alpha-2 country codes.
|
|
96
|
+
*/
|
|
97
|
+
withGeoBlockRule(countryCodes) {
|
|
98
|
+
if (countryCodes.length === 0) {
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
this._blockRules.push({
|
|
102
|
+
name: "GeoBlock",
|
|
103
|
+
action: { block: {} },
|
|
104
|
+
statement: {
|
|
105
|
+
geoMatchStatement: {
|
|
106
|
+
countryCodes,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
visibilityConfig: {
|
|
110
|
+
sampledRequestsEnabled: true,
|
|
111
|
+
cloudWatchMetricsEnabled: true,
|
|
112
|
+
metricName: "GeoBlock",
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
94
117
|
/**
|
|
95
118
|
* Adds a rate-based WAF rule for either blocking or counting requests.
|
|
96
119
|
*
|
|
@@ -163,13 +186,14 @@ export class AclBuilder {
|
|
|
163
186
|
this._addThrottleResponseBody(customResponseBodyKey, limit);
|
|
164
187
|
return this.withThrottleRule("ThrottleRuleWithAnonymousUser", limit, false, false, customResponseBodyKey);
|
|
165
188
|
}
|
|
166
|
-
withThrottleAnonymousUserIpByUriPath(limit, path) {
|
|
189
|
+
withThrottleAnonymousUserIpByUriPath(limit, path, ruleId) {
|
|
167
190
|
if (limit === undefined || path === undefined) {
|
|
168
191
|
return this;
|
|
169
192
|
}
|
|
170
193
|
const customResponseBodyKey = `IP_THROTTLE_ANONYMOUS_USER_BY_PATH_${limit}`;
|
|
171
194
|
this._addThrottleResponseBody(customResponseBodyKey, limit);
|
|
172
|
-
|
|
195
|
+
const name = `ThrottleRuleWithAnonymousUserByPath${ruleId ? `-${ruleId}` : ""}`;
|
|
196
|
+
return this.withThrottleRule(name, limit, false, false, customResponseBodyKey, path);
|
|
173
197
|
}
|
|
174
198
|
/**
|
|
175
199
|
* Throttles anonymous requests by IP address and URI path.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitraffic/common",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.23-1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"repository": {
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"@types/geojson-validation": "1.0.3",
|
|
128
128
|
"@types/madge": "5.0.3",
|
|
129
129
|
"@types/node": "24.13.3",
|
|
130
|
-
"@vitest/coverage-v8": "4.1.
|
|
130
|
+
"@vitest/coverage-v8": "4.1.12",
|
|
131
131
|
"aws-cdk-lib": "2.262.2",
|
|
132
132
|
"constructs": "10.7.2",
|
|
133
133
|
"date-fns": "4.4.0",
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"sort-package-json": "4.0.0",
|
|
145
145
|
"typescript": "5.9.3",
|
|
146
146
|
"velocityjs": "2.1.7",
|
|
147
|
-
"vitest": "4.1.
|
|
147
|
+
"vitest": "4.1.12",
|
|
148
148
|
"zod": "4.4.3"
|
|
149
149
|
},
|
|
150
150
|
"peerDependencies": {
|