@libreflare/worker-runtime 0.4.7 → 0.4.8

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.
Files changed (34) hide show
  1. package/README.md +4 -0
  2. package/dist/rule-evaluator/field-availability.d.ts +39 -0
  3. package/dist/rule-evaluator/field-availability.d.ts.map +1 -0
  4. package/dist/rule-evaluator/field-availability.js +149 -0
  5. package/dist/rule-evaluator/field-availability.js.map +1 -0
  6. package/dist/rule-evaluator/field-descriptions.d.ts +86 -0
  7. package/dist/rule-evaluator/field-descriptions.d.ts.map +1 -0
  8. package/dist/rule-evaluator/field-descriptions.generated.d.ts +1201 -0
  9. package/dist/rule-evaluator/field-descriptions.generated.d.ts.map +1 -0
  10. package/dist/rule-evaluator/field-descriptions.generated.js +2858 -0
  11. package/dist/rule-evaluator/field-descriptions.generated.js.map +1 -0
  12. package/dist/rule-evaluator/field-descriptions.js +107 -0
  13. package/dist/rule-evaluator/field-descriptions.js.map +1 -0
  14. package/dist/rule-evaluator/fields.d.ts +1 -0
  15. package/dist/rule-evaluator/fields.d.ts.map +1 -1
  16. package/dist/rule-evaluator/fields.js +1 -0
  17. package/dist/rule-evaluator/fields.js.map +1 -1
  18. package/dist/rule-evaluator/function-descriptions.d.ts +75 -0
  19. package/dist/rule-evaluator/function-descriptions.d.ts.map +1 -0
  20. package/dist/rule-evaluator/function-descriptions.generated.d.ts +498 -0
  21. package/dist/rule-evaluator/function-descriptions.generated.d.ts.map +1 -0
  22. package/dist/rule-evaluator/function-descriptions.generated.js +866 -0
  23. package/dist/rule-evaluator/function-descriptions.generated.js.map +1 -0
  24. package/dist/rule-evaluator/function-descriptions.js +25 -0
  25. package/dist/rule-evaluator/function-descriptions.js.map +1 -0
  26. package/dist/rule-evaluator/validation.d.ts +2 -6
  27. package/dist/rule-evaluator/validation.d.ts.map +1 -1
  28. package/dist/rule-evaluator/validation.js +12 -141
  29. package/dist/rule-evaluator/validation.js.map +1 -1
  30. package/dist/rule-evaluator.d.ts +4 -0
  31. package/dist/rule-evaluator.d.ts.map +1 -1
  32. package/dist/rule-evaluator.js +2 -0
  33. package/dist/rule-evaluator.js.map +1 -1
  34. package/package.json +7 -1
package/README.md CHANGED
@@ -7,6 +7,8 @@ Shared runtime utilities for Libreflare-managed Cloudflare Workers.
7
7
  - `handleRequest`: batched logging request handler for managed logging Workers.
8
8
  - `handleLibreflareRequest`: generated-config route/logging request handler. Pass `runtimeConfig` from a generated JSON import, or rely on the legacy `LIBREFLARE_CONFIG` env binding. For route-only v2 config, pass `apiURL`, `getSourceKey`, `apiAuthHeaders`, and related options to keep logging owned by the Worker repository.
9
9
  - `evaluateExpression`: Cloudflare Rules expression evaluator for Worker-side diagnostics. Unresolved Cloudflare list references are inferred as matches by default and can be disabled via options.
10
+ - `getRuleExpressionFieldDescriptions`: field descriptions filtered by the same preset and field availability override shape used by rule expression validation.
11
+ - `getRuleExpressionFunctionDescriptions`: function reference metadata for dashboard editors, including signatures, return types, parameter roles, and evaluator support notes.
10
12
  - `minifyRuleExpression`: whitespace minifier for Cloudflare Rules expressions before Rewrite Rule deployment.
11
13
  - `validateRuleExpressionSyntax`: syntax, length, and field availability validation for Cloudflare URL Rewrite Rule filter expressions by default. Pass an explicit config object for minification, length, preset, field availability, deprecated-field notices, and list-reference policy. With minification enabled it validates the minified expression against Cloudflare's 4096-character rule limit by default; when minification is disabled, the result omits `minifiedExpression` and `minifiedLength`.
12
14
 
@@ -19,6 +21,8 @@ URL.
19
21
 
20
22
  ```powershell
21
23
  npm install
24
+ npm run build:field-descriptions
25
+ npm run build:function-descriptions
22
26
  npm run build
23
27
  npm run typecheck
24
28
  npm test
@@ -0,0 +1,39 @@
1
+ import type { RuleExpressionValidationPreset } from './validation.js';
2
+ export interface RuleExpressionFieldAvailabilityConfig {
3
+ allowedFields?: readonly string[];
4
+ allowedPrefixes?: readonly string[];
5
+ disallowedFields?: readonly string[];
6
+ disallowedPrefixes?: readonly string[];
7
+ }
8
+ export interface RuleExpressionFieldAvailabilityRules {
9
+ preset: RuleExpressionValidationPreset;
10
+ allowedFields: ReadonlySet<string>;
11
+ allowedPrefixes: readonly string[];
12
+ disallowedFields: ReadonlySet<string>;
13
+ disallowedPrefixes: readonly string[];
14
+ }
15
+ export interface RuleExpressionFieldAvailabilityTarget {
16
+ name: string;
17
+ map?: boolean;
18
+ }
19
+ interface RuleExpressionFieldAvailabilityResolverOptions {
20
+ onUnknownField?: (configPath: string, field: string) => void;
21
+ onUnknownPrefix?: (configPath: string, prefix: string) => void;
22
+ }
23
+ export declare const RULE_EXPRESSION_FIELD_AVAILABILITY_PRESETS: {
24
+ readonly 'url-rewrite-filter': {
25
+ readonly allowedFields: readonly ["cf.edge.server_ip", "cf.edge.server_port", "cf.edge.client_port", "cf.edge.client_tcp", "cf.edge.l4.delivery_rate", "cf.hostname.metadata", "cf.zone.name", "cf.random_seed", "cf.ray_id", "cf.timings.client_quic_rtt_msec", "cf.timings.client_tcp_rtt_msec", "cf.tls_version", "cf.tls_cipher", "cf.tls_client_hello_length", "cf.tls_client_random", "cf.tls_client_extensions_sha1", "cf.tls_client_extensions_sha1_le", "cf.tls_client_ciphers_sha1", "cf.tls_ciphers_sha1", "cf.worker.upstream_zone", "http.cookie", "http.host", "http.referer", "http.request.accepted_languages", "http.request.cookies", "http.request.headers", "http.request.method", "http.request.timestamp.sec", "http.request.timestamp.msec", "http.request.full_uri", "http.request.uri", "http.request.version", "raw.http.request.full_uri", "raw.http.request.headers", "raw.http.request.uri", "http.user_agent", "http.x_forwarded_for", "ip.src", "ip.src.lat", "ip.src.lon", "ip.src.asnum", "ip.src.city", "ip.src.country", "ip.src.continent", "ip.src.metro_code", "ip.src.postal_code", "ip.src.region", "ip.src.region_code", "ip.src.is_in_european_union", "ip.src.subdivision_1_iso_code", "ip.src.subdivision_2_iso_code", ...string[], "ssl"];
26
+ readonly allowedPrefixes: readonly ["cf.tls_client_auth.", "http.request.headers.", "http.request.uri.", "raw.http.request.headers.", "raw.http.request.uri."];
27
+ };
28
+ readonly 'url-rewrite-target': {
29
+ readonly allowedFields: readonly ["http.request.accepted_languages"];
30
+ readonly allowedPrefixes: readonly ["http.request.uri.", "http.request.headers."];
31
+ };
32
+ };
33
+ export declare const KNOWN_RULE_EXPRESSION_FIELD_NAMES: string[];
34
+ export declare function resolveRuleExpressionFieldAvailability(preset: RuleExpressionValidationPreset, config: false | RuleExpressionFieldAvailabilityConfig | undefined, options?: RuleExpressionFieldAvailabilityResolverOptions): RuleExpressionFieldAvailabilityRules | null;
35
+ export declare function isRuleExpressionFieldAvailable(target: RuleExpressionFieldAvailabilityTarget, rules: RuleExpressionFieldAvailabilityRules): boolean;
36
+ export declare function isKnownRuleExpressionFieldName(field: string): boolean;
37
+ export declare function isKnownRuleExpressionFieldPrefix(prefix: string): boolean;
38
+ export {};
39
+ //# sourceMappingURL=field-availability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-availability.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/field-availability.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAOtE,MAAM,WAAW,qCAAqC;IACrD,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,oCAAoC;IACpD,MAAM,EAAE,8BAA8B,CAAC;IACvC,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACnC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,qCAAqC;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;CACd;AAED,UAAU,8CAA8C;IACvD,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7D,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/D;AA2ED,eAAO,MAAM,0CAA0C;;;;;;;;;CAS2D,CAAC;AAInH,eAAO,MAAM,iCAAiC,UACI,CAAC;AAInD,wBAAgB,sCAAsC,CACrD,MAAM,EAAE,8BAA8B,EACtC,MAAM,EAAE,KAAK,GAAG,qCAAqC,GAAG,SAAS,EACjE,OAAO,GAAE,8CAAmD,GAC1D,oCAAoC,GAAG,IAAI,CAqB7C;AAED,wBAAgB,8BAA8B,CAC7C,MAAM,EAAE,qCAAqC,EAC7C,KAAK,EAAE,oCAAoC,GACzC,OAAO,CAGT;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErE;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAIxE"}
@@ -0,0 +1,149 @@
1
+ import { KNOWN_AVAILABLE_FIELDS, KNOWN_DEPRECATED_FIELDS, KNOWN_UNAVAILABLE_FIELDS, } from './fields.js';
2
+ const URL_REWRITE_FILTER_ALLOWED_FIELDS = [
3
+ 'cf.edge.server_ip',
4
+ 'cf.edge.server_port',
5
+ 'cf.edge.client_port',
6
+ 'cf.edge.client_tcp',
7
+ 'cf.edge.l4.delivery_rate',
8
+ 'cf.hostname.metadata',
9
+ 'cf.zone.name',
10
+ 'cf.random_seed',
11
+ 'cf.ray_id',
12
+ 'cf.timings.client_quic_rtt_msec',
13
+ 'cf.timings.client_tcp_rtt_msec',
14
+ 'cf.tls_version',
15
+ 'cf.tls_cipher',
16
+ 'cf.tls_client_hello_length',
17
+ 'cf.tls_client_random',
18
+ 'cf.tls_client_extensions_sha1',
19
+ 'cf.tls_client_extensions_sha1_le',
20
+ 'cf.tls_client_ciphers_sha1',
21
+ 'cf.tls_ciphers_sha1',
22
+ 'cf.worker.upstream_zone',
23
+ 'http.cookie',
24
+ 'http.host',
25
+ 'http.referer',
26
+ 'http.request.accepted_languages',
27
+ 'http.request.cookies',
28
+ 'http.request.headers',
29
+ 'http.request.method',
30
+ 'http.request.timestamp.sec',
31
+ 'http.request.timestamp.msec',
32
+ 'http.request.full_uri',
33
+ 'http.request.uri',
34
+ 'http.request.version',
35
+ 'raw.http.request.full_uri',
36
+ 'raw.http.request.headers',
37
+ 'raw.http.request.uri',
38
+ 'http.user_agent',
39
+ 'http.x_forwarded_for',
40
+ 'ip.src',
41
+ 'ip.src.lat',
42
+ 'ip.src.lon',
43
+ 'ip.src.asnum',
44
+ 'ip.src.city',
45
+ 'ip.src.country',
46
+ 'ip.src.continent',
47
+ 'ip.src.metro_code',
48
+ 'ip.src.postal_code',
49
+ 'ip.src.region',
50
+ 'ip.src.region_code',
51
+ 'ip.src.is_in_european_union',
52
+ 'ip.src.subdivision_1_iso_code',
53
+ 'ip.src.subdivision_2_iso_code',
54
+ ...KNOWN_DEPRECATED_FIELDS,
55
+ 'ssl',
56
+ ];
57
+ const URL_REWRITE_FILTER_ALLOWED_PREFIXES = [
58
+ 'cf.tls_client_auth.',
59
+ 'http.request.headers.',
60
+ 'http.request.uri.',
61
+ 'raw.http.request.headers.',
62
+ 'raw.http.request.uri.',
63
+ ];
64
+ const URL_REWRITE_TARGET_ALLOWED_FIELDS = [
65
+ 'http.request.accepted_languages',
66
+ ];
67
+ const URL_REWRITE_TARGET_ALLOWED_PREFIXES = [
68
+ 'http.request.uri.',
69
+ 'http.request.headers.',
70
+ ];
71
+ export const RULE_EXPRESSION_FIELD_AVAILABILITY_PRESETS = {
72
+ 'url-rewrite-filter': {
73
+ allowedFields: URL_REWRITE_FILTER_ALLOWED_FIELDS,
74
+ allowedPrefixes: URL_REWRITE_FILTER_ALLOWED_PREFIXES,
75
+ },
76
+ 'url-rewrite-target': {
77
+ allowedFields: URL_REWRITE_TARGET_ALLOWED_FIELDS,
78
+ allowedPrefixes: URL_REWRITE_TARGET_ALLOWED_PREFIXES,
79
+ },
80
+ };
81
+ const ROOT_FIELD_PREFIXES = new Set(['cf.', 'http.', 'ip.', 'raw.']);
82
+ export const KNOWN_RULE_EXPRESSION_FIELD_NAMES = [...new Set([...KNOWN_AVAILABLE_FIELDS, ...KNOWN_UNAVAILABLE_FIELDS])]
83
+ .sort((left, right) => left.localeCompare(right));
84
+ const KNOWN_RULE_EXPRESSION_FIELDS = new Set(KNOWN_RULE_EXPRESSION_FIELD_NAMES);
85
+ export function resolveRuleExpressionFieldAvailability(preset, config, options = {}) {
86
+ if (config === false)
87
+ return null;
88
+ const base = RULE_EXPRESSION_FIELD_AVAILABILITY_PRESETS[preset];
89
+ const allowedFields = normalizeFieldNames(config?.allowedFields);
90
+ const allowedPrefixes = normalizeFieldPrefixes(config?.allowedPrefixes);
91
+ const disallowedFields = normalizeFieldNames(config?.disallowedFields);
92
+ const disallowedPrefixes = normalizeFieldPrefixes(config?.disallowedPrefixes);
93
+ reportUnknownFields('fieldAvailability.allowedFields', allowedFields, options);
94
+ reportUnknownPrefixes('fieldAvailability.allowedPrefixes', allowedPrefixes, options);
95
+ reportUnknownFields('fieldAvailability.disallowedFields', disallowedFields, options);
96
+ reportUnknownPrefixes('fieldAvailability.disallowedPrefixes', disallowedPrefixes, options);
97
+ return {
98
+ preset,
99
+ allowedFields: new Set([...base.allowedFields, ...allowedFields.filter(isKnownRuleExpressionFieldName)]),
100
+ allowedPrefixes: [...base.allowedPrefixes, ...allowedPrefixes.filter(isKnownRuleExpressionFieldPrefix)],
101
+ disallowedFields: new Set(disallowedFields.filter(isKnownRuleExpressionFieldName)),
102
+ disallowedPrefixes: disallowedPrefixes.filter(isKnownRuleExpressionFieldPrefix),
103
+ };
104
+ }
105
+ export function isRuleExpressionFieldAvailable(target, rules) {
106
+ return fieldMatchesAvailabilityRules(target, rules.allowedFields, rules.allowedPrefixes) &&
107
+ !fieldMatchesAvailabilityRules(target, rules.disallowedFields, rules.disallowedPrefixes);
108
+ }
109
+ export function isKnownRuleExpressionFieldName(field) {
110
+ return KNOWN_RULE_EXPRESSION_FIELDS.has(field);
111
+ }
112
+ export function isKnownRuleExpressionFieldPrefix(prefix) {
113
+ return prefix.endsWith('.') &&
114
+ !ROOT_FIELD_PREFIXES.has(prefix) &&
115
+ KNOWN_RULE_EXPRESSION_FIELD_NAMES.some(field => field.startsWith(prefix));
116
+ }
117
+ function normalizeFieldNames(fields) {
118
+ return fields?.map(field => field.trim()) ?? [];
119
+ }
120
+ function normalizeFieldPrefixes(prefixes) {
121
+ return prefixes?.map((prefix) => {
122
+ const trimmed = prefix.trim();
123
+ return trimmed.endsWith('*') ? trimmed.slice(0, -1) : trimmed;
124
+ }) ?? [];
125
+ }
126
+ function reportUnknownFields(configPath, fields, options) {
127
+ for (const field of fields) {
128
+ if (isKnownRuleExpressionFieldName(field))
129
+ continue;
130
+ options.onUnknownField?.(configPath, field);
131
+ }
132
+ }
133
+ function reportUnknownPrefixes(configPath, prefixes, options) {
134
+ for (const prefix of prefixes) {
135
+ if (isKnownRuleExpressionFieldPrefix(prefix))
136
+ continue;
137
+ options.onUnknownPrefix?.(configPath, prefix);
138
+ }
139
+ }
140
+ function fieldMatchesAvailabilityRules(target, fields, prefixes) {
141
+ if (fields.has(target.name))
142
+ return true;
143
+ if (prefixes.some(prefix => target.name.startsWith(prefix)))
144
+ return true;
145
+ if (target.map && prefixes.some(prefix => prefix === `${target.name}.`))
146
+ return true;
147
+ return false;
148
+ }
149
+ //# sourceMappingURL=field-availability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-availability.js","sourceRoot":"","sources":["../../src/rule-evaluator/field-availability.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,GACxB,MAAM,aAAa,CAAC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@
1
+ import { RULE_EXPRESSION_FIELD_DESCRIPTIONS as GENERATED_RULE_EXPRESSION_FIELD_DESCRIPTIONS, RULE_EXPRESSION_FIELD_REFERENCE_URL } from './field-descriptions.generated.js';
2
+ import { type RuleExpressionFieldAvailabilityConfig } from './field-availability.js';
3
+ import { type RuleExpressionValidationPreset } from './validation.js';
4
+ /**
5
+ * Editor-facing metadata for a Cloudflare Rules language field.
6
+ */
7
+ export interface RuleExpressionFieldDescription {
8
+ /** Short field summary from the Cloudflare fields reference. */
9
+ summary: string;
10
+ /** Cloudflare Rules language data type label. */
11
+ dataType?: string;
12
+ /** Cloudflare fields reference category labels. */
13
+ categories: readonly string[];
14
+ /** Search keywords from the Cloudflare fields reference. */
15
+ keywords: readonly string[];
16
+ /** Cloudflare plan label, such as "Enterprise add-on", when documented. */
17
+ planInfoLabel?: string;
18
+ /** Marks generated descriptions for deprecated field aliases. */
19
+ deprecated?: boolean;
20
+ /** Preferred replacement field for a deprecated alias. */
21
+ replacement?: string;
22
+ }
23
+ export type RuleExpressionFieldDataType = {
24
+ kind: 'scalar';
25
+ name: string;
26
+ } | {
27
+ kind: 'array';
28
+ element: RuleExpressionFieldDataType;
29
+ } | {
30
+ kind: 'map';
31
+ value: RuleExpressionFieldDataType;
32
+ };
33
+ export type RuleExpressionFieldUsageKind = 'scalar' | 'array' | 'map' | 'map-array';
34
+ export interface RuleExpressionFieldSyntax {
35
+ /** Bare field expression, such as `http.host`. */
36
+ field: string;
37
+ /** Array wildcard expression, such as `http.request.headers.names[*]`. */
38
+ wildcard?: string;
39
+ /** Array index expression, such as `http.request.headers.names[0]`. */
40
+ index?: string;
41
+ /** Map key expression, such as `http.request.headers["key"]`. */
42
+ keyed?: string;
43
+ /** Map key wildcard expression, such as `http.request.headers["key"][*]`. */
44
+ keyedWildcard?: string;
45
+ /** Map key index expression, such as `http.request.headers["key"][0]`. */
46
+ keyedIndex?: string;
47
+ }
48
+ export interface RuleExpressionFieldUsage {
49
+ /** Broad field access shape derived from `dataType`. */
50
+ kind: RuleExpressionFieldUsageKind;
51
+ /** Parsed Cloudflare Rules language data type. */
52
+ dataType: RuleExpressionFieldDataType;
53
+ /** Leaf scalar type, such as `String` for `Map<Array<String>>`. */
54
+ valueType: string;
55
+ /** Supported expression syntax forms for this field. */
56
+ syntax: RuleExpressionFieldSyntax;
57
+ }
58
+ type RuleExpressionFieldDescriptions = typeof GENERATED_RULE_EXPRESSION_FIELD_DESCRIPTIONS;
59
+ export type RuleExpressionFieldName = keyof RuleExpressionFieldDescriptions & string;
60
+ /**
61
+ * Named editor-facing metadata for a Cloudflare Rules language field.
62
+ */
63
+ export type RuleExpressionFieldDescriptionEntry<Name extends RuleExpressionFieldName = RuleExpressionFieldName> = {
64
+ [Field in Name]: RuleExpressionFieldDescriptions[Field] & {
65
+ /** Cloudflare Rules language field name. */
66
+ name: Field;
67
+ /** Field access metadata derived from `dataType`. */
68
+ usage: RuleExpressionFieldUsage;
69
+ };
70
+ }[Name];
71
+ export interface RuleExpressionFieldDescriptionConfig {
72
+ /** Field availability preset. Defaults to URL rewrite filter expressions. */
73
+ preset?: RuleExpressionValidationPreset;
74
+ /**
75
+ * Field availability overrides. Pass `false` to return every known field
76
+ * description without preset filtering.
77
+ */
78
+ fieldAvailability?: false | RuleExpressionFieldAvailabilityConfig;
79
+ }
80
+ /**
81
+ * Returns field descriptions filtered through the same preset and field
82
+ * availability override shape accepted by `validateRuleExpressionSyntax()`.
83
+ */
84
+ export declare function getRuleExpressionFieldDescriptions(config?: RuleExpressionFieldDescriptionConfig): readonly RuleExpressionFieldDescriptionEntry[];
85
+ export { RULE_EXPRESSION_FIELD_REFERENCE_URL };
86
+ //# sourceMappingURL=field-descriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-descriptions.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/field-descriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kCAAkC,IAAI,4CAA4C,EAClF,mCAAmC,EACnC,MAA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