fastly.js 0.9.0

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +702 -0
  3. package/dist/browser.d.ts +10 -0
  4. package/dist/browser.js +10544 -0
  5. package/dist/csrf-protection.d.ts +10 -0
  6. package/dist/diagnostics.d.ts +11 -0
  7. package/dist/index.d.ts +10 -0
  8. package/dist/index.js +10435 -0
  9. package/dist/node-loader.d.ts +3 -0
  10. package/dist/platform-browser.d.ts +2 -0
  11. package/dist/platform-node.d.ts +2 -0
  12. package/dist/platform.d.ts +48 -0
  13. package/dist/runtime/browser.d.ts +49 -0
  14. package/dist/runtime/pipeline.d.ts +49 -0
  15. package/dist/utils.d.ts +7 -0
  16. package/dist/vcl-accept.d.ts +8 -0
  17. package/dist/vcl-acl.d.ts +19 -0
  18. package/dist/vcl-address.d.ts +8 -0
  19. package/dist/vcl-binary.d.ts +5 -0
  20. package/dist/vcl-builtin-types.d.ts +10 -0
  21. package/dist/vcl-compiler.d.ts +513 -0
  22. package/dist/vcl-digest.d.ts +87 -0
  23. package/dist/vcl-esi.d.ts +32 -0
  24. package/dist/vcl-fetch.d.ts +6 -0
  25. package/dist/vcl-header.d.ts +18 -0
  26. package/dist/vcl-limits.d.ts +10 -0
  27. package/dist/vcl-math.d.ts +45 -0
  28. package/dist/vcl-misc.d.ts +29 -0
  29. package/dist/vcl-node.d.ts +2 -0
  30. package/dist/vcl-parser-impl.d.ts +126 -0
  31. package/dist/vcl-parser.d.ts +320 -0
  32. package/dist/vcl-querystring.d.ts +46 -0
  33. package/dist/vcl-ratelimit.d.ts +39 -0
  34. package/dist/vcl-security.d.ts +23 -0
  35. package/dist/vcl-std.d.ts +43 -0
  36. package/dist/vcl-strings.d.ts +47 -0
  37. package/dist/vcl-table.d.ts +27 -0
  38. package/dist/vcl-testing.d.ts +60 -0
  39. package/dist/vcl-time.d.ts +60 -0
  40. package/dist/vcl-utf8.d.ts +6 -0
  41. package/dist/vcl-uuid.d.ts +38 -0
  42. package/dist/vcl-value.d.ts +96 -0
  43. package/dist/vcl-waf.d.ts +14 -0
  44. package/dist/vcl.d.ts +7 -0
  45. package/package.json +90 -0
@@ -0,0 +1,45 @@
1
+ /**
2
+ * VCL Math Functions Module
3
+ *
4
+ * Implements all math.* functions from Fastly VCL.
5
+ * Reference: https://developer.fastly.com/reference/vcl/functions/math-trig/
6
+ */
7
+ export interface MathModule {
8
+ sin: (x: number) => number;
9
+ cos: (x: number) => number;
10
+ tan: (x: number) => number;
11
+ asin: (x: number) => number;
12
+ acos: (x: number) => number;
13
+ atan: (x: number) => number;
14
+ atan2: (y: number, x: number) => number;
15
+ sinh: (x: number) => number;
16
+ cosh: (x: number) => number;
17
+ tanh: (x: number) => number;
18
+ asinh: (x: number) => number;
19
+ acosh: (x: number) => number;
20
+ atanh: (x: number) => number;
21
+ exp: (x: number) => number;
22
+ exp2: (x: number) => number;
23
+ log: (x: number) => number;
24
+ log2: (x: number) => number;
25
+ log10: (x: number) => number;
26
+ pow: (base: number, exp: number) => number;
27
+ sqrt: (x: number) => number;
28
+ ceil: (x: number) => number;
29
+ floor: (x: number) => number;
30
+ round: (x: number) => number;
31
+ roundeven: (x: number) => number;
32
+ roundhalfdown: (x: number) => number;
33
+ roundhalfup: (x: number) => number;
34
+ trunc: (x: number) => number;
35
+ abs: (x: number) => number;
36
+ min: (a: number, b: number) => number;
37
+ max: (a: number, b: number) => number;
38
+ fmod: (x: number, y: number) => number;
39
+ is_finite: (x: number) => boolean;
40
+ is_infinite: (x: number) => boolean;
41
+ is_nan: (x: number) => boolean;
42
+ is_normal: (x: number) => boolean;
43
+ is_subnormal: (x: number) => boolean;
44
+ }
45
+ export declare function createMathModule(): MathModule;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * VCL Miscellaneous Functions Module
3
+ *
4
+ * Implements various utility functions from Fastly VCL.
5
+ */
6
+ export declare function boltsortSort(url: string): string;
7
+ export declare function cstrEscape(s: string): string;
8
+ export declare function jsonEscape(s: string): string;
9
+ export declare function xmlEscape(s: string): string;
10
+ export declare function urlencode(s: string): string;
11
+ export declare function urldecode(s: string): string;
12
+ export declare function subfield(s: string, name: string, separator?: string): string;
13
+ export declare const random: {
14
+ bool: () => boolean;
15
+ bool_seeded: (_seed: number) => boolean;
16
+ int: (from: number, to: number) => number;
17
+ int_seeded: (_seed: number, from: number, to: number) => number;
18
+ str: (length: number) => string;
19
+ };
20
+ export declare const setcookie: {
21
+ get_value_by_name: (setCookieHeader: string, name: string) => string;
22
+ delete_by_name: (setCookieHeader: string, name: string) => string;
23
+ };
24
+ export declare const fastly: {
25
+ hash: (input: string) => Promise<string>;
26
+ try_select_shield: () => boolean;
27
+ };
28
+ export declare function respTarpit(_duration: number): void;
29
+ export declare function earlyHints(_header: string): void;
@@ -0,0 +1,2 @@
1
+ import "./platform-node.js";
2
+ export * from "./vcl.js";
@@ -0,0 +1,126 @@
1
+ import { type Token, type VCLProgram } from "./vcl-parser.js";
2
+ export declare class VCLParser {
3
+ private tokens;
4
+ private current;
5
+ private source;
6
+ constructor(tokens: Token[], source: string);
7
+ parse(): VCLProgram;
8
+ /**
9
+ * Strip the delimiters from a STRING token value: plain quotes, or the
10
+ * long-string forms {"..."} and {DELIM"..."DELIM}.
11
+ */
12
+ private unquoteStringToken;
13
+ private isValidIPv4;
14
+ private isValidIPv6;
15
+ private isValidCIDR;
16
+ private parseACL;
17
+ private parseIncludeStatement;
18
+ private parseImportStatement;
19
+ private parseTableDeclaration;
20
+ private parseBackendDeclaration;
21
+ private parseComment;
22
+ private parseSubroutine;
23
+ private parseStatement;
24
+ private parseDeclareStatement;
25
+ private parseStatementBlock;
26
+ private parseElseClause;
27
+ private parseIfStatement;
28
+ private parseReturnStatement;
29
+ /**
30
+ * Parses an error statement.
31
+ * Supports: `error;`, `error <code>;`, `error <code> <response-expr>;`
32
+ * where <code> is an integer literal, identifier, or function call and the
33
+ * response is a full expression (including concatenations).
34
+ *
35
+ * @returns The parsed error statement
36
+ */
37
+ private parseErrorStatement;
38
+ /**
39
+ * Parses a set statement
40
+ *
41
+ * @returns The parsed set statement
42
+ */
43
+ private parseSetStatement;
44
+ /**
45
+ * Parses an unset statement
46
+ *
47
+ * @returns The parsed unset statement
48
+ */
49
+ private parseUnsetStatement;
50
+ /**
51
+ * Parses a log statement
52
+ *
53
+ * @returns The parsed log statement
54
+ */
55
+ private parseLogStatement;
56
+ /**
57
+ * Parses a synthetic statement
58
+ *
59
+ * @returns The parsed synthetic statement
60
+ */
61
+ private parseSyntheticBase64Statement;
62
+ private parseSyntheticStatement;
63
+ /**
64
+ * Parses a hash_data statement
65
+ *
66
+ * @returns The parsed hash_data statement
67
+ */
68
+ private parseHashDataStatement;
69
+ /**
70
+ * Parses a goto statement
71
+ *
72
+ * @returns The parsed goto statement
73
+ */
74
+ private parseGotoStatement;
75
+ /**
76
+ * Parses a restart statement
77
+ *
78
+ * @returns The parsed restart statement
79
+ */
80
+ private parseRestartStatement;
81
+ private parseAddStatement;
82
+ private parseRemoveStatement;
83
+ private parseCallStatement;
84
+ private parseBareLogStatement;
85
+ private parseEsiStatement;
86
+ private parseSwitchStatement;
87
+ /** Parse a case/default body; it must end with `break;` or `fallthrough;`. */
88
+ private parseSwitchCaseBody;
89
+ private parseDirectorDeclaration;
90
+ private parsePenaltyboxDeclaration;
91
+ private parseRatecounterDeclaration;
92
+ private parseExpression;
93
+ private parseTernary;
94
+ private parseLogicalOr;
95
+ private parseLogicalAnd;
96
+ private parseEquality;
97
+ private parseComparison;
98
+ private parseRegex;
99
+ private parseTerm;
100
+ private parseFactor;
101
+ /**
102
+ * Handles implicit string concatenation in VCL
103
+ * e.g., "S" time.start.sec "." time.start.usec_frac
104
+ * Adjacent values without operators are concatenated
105
+ */
106
+ private parseImplicitConcat;
107
+ /**
108
+ * Checks if the current token can start an implicit concatenation
109
+ * Returns true if the token is STRING, IDENTIFIER, NUMBER, or if() function
110
+ * and not preceded by an operator
111
+ */
112
+ private canStartImplicitConcat;
113
+ private parsePrimary;
114
+ /** Build a NumberLiteral or RTimeLiteral (unit-suffixed) from a NUMBER token. */
115
+ private numberLiteralFromToken;
116
+ private match;
117
+ private consume;
118
+ private consumeName;
119
+ private check;
120
+ private advance;
121
+ private isAtEnd;
122
+ private peek;
123
+ private previous;
124
+ private error;
125
+ private parseFunctionCall;
126
+ }
@@ -0,0 +1,320 @@
1
+ export type VCLNodeType = "Program" | "Subroutine" | "Statement" | "Assignment" | "IfStatement" | "ReturnStatement" | "ErrorStatement" | "SetStatement" | "UnsetStatement" | "AddStatement" | "RemoveStatement" | "CallStatement" | "LogStatement" | "SyntheticStatement" | "SyntheticBase64Statement" | "EsiStatement" | "SwitchStatement" | "HashDataStatement" | "GotoStatement" | "LabelStatement" | "RestartStatement" | "DeclareStatement" | "ExpressionStatement" | "BlockStatement" | "IncludeStatement" | "ImportStatement" | "BackendDeclaration" | "DirectorDeclaration" | "PenaltyboxDeclaration" | "RatecounterDeclaration" | "TableDeclaration" | "BinaryExpression" | "UnaryExpression" | "TernaryExpression" | "FunctionCall" | "Identifier" | "StringLiteral" | "NumberLiteral" | "RTimeLiteral" | "BoolLiteral" | "RegexLiteral" | "MemberAccess" | "Comment" | "ACL" | "ACLEntry";
2
+ export interface VCLNode {
3
+ type: VCLNodeType;
4
+ location?: {
5
+ line: number;
6
+ column: number;
7
+ };
8
+ }
9
+ export interface VCLProgram extends VCLNode {
10
+ type: "Program";
11
+ subroutines: VCLSubroutine[];
12
+ comments: VCLComment[];
13
+ acls: VCLACL[];
14
+ includes: VCLIncludeStatement[];
15
+ imports: VCLImportStatement[];
16
+ tables: VCLTableDeclaration[];
17
+ backends: VCLBackendDeclaration[];
18
+ directors: VCLDirectorDeclaration[];
19
+ penaltyboxes: VCLPenaltyboxDeclaration[];
20
+ ratecounters: VCLRatecounterDeclaration[];
21
+ }
22
+ export interface VCLACL extends VCLNode {
23
+ type: "ACL";
24
+ name: string;
25
+ entries: VCLACLEntry[];
26
+ }
27
+ export interface VCLACLEntry extends VCLNode {
28
+ type: "ACLEntry";
29
+ ip: string;
30
+ subnet?: number;
31
+ negated?: boolean;
32
+ }
33
+ export interface VCLSubroutineParam {
34
+ name: string;
35
+ paramType: string;
36
+ }
37
+ export interface VCLSubroutine extends VCLNode {
38
+ type: "Subroutine";
39
+ name: string;
40
+ params?: VCLSubroutineParam[];
41
+ body: VCLStatement[];
42
+ raw?: string;
43
+ statements?: VCLStatement[];
44
+ returnType?: string;
45
+ }
46
+ export interface VCLBaseStatement extends VCLNode {
47
+ type: VCLStatementType;
48
+ }
49
+ export type VCLStatementType = "Statement" | "Assignment" | "IfStatement" | "ReturnStatement" | "ErrorStatement" | "SetStatement" | "UnsetStatement" | "AddStatement" | "RemoveStatement" | "CallStatement" | "LogStatement" | "SyntheticStatement" | "SyntheticBase64Statement" | "EsiStatement" | "SwitchStatement" | "HashDataStatement" | "GotoStatement" | "LabelStatement" | "RestartStatement" | "DeclareStatement" | "ExpressionStatement" | "BlockStatement";
50
+ export interface VCLEmptyStatement extends VCLNode {
51
+ type: "Statement";
52
+ }
53
+ export interface VCLAssignment extends VCLNode {
54
+ type: "Assignment";
55
+ left: VCLIdentifier;
56
+ right: VCLExpression;
57
+ }
58
+ export interface VCLIfStatement extends VCLNode {
59
+ type: "IfStatement";
60
+ test: VCLExpression;
61
+ consequent: VCLStatement[];
62
+ alternate?: VCLStatement[];
63
+ condition?: VCLExpression;
64
+ }
65
+ export interface VCLReturnStatement extends VCLNode {
66
+ type: "ReturnStatement";
67
+ argument: string;
68
+ value?: VCLExpression;
69
+ }
70
+ export interface VCLErrorStatement extends VCLNode {
71
+ type: "ErrorStatement";
72
+ /** Status code expression; absent for a bare `error;` re-raise. */
73
+ status?: VCLExpression;
74
+ /** Response text expression (may be a concatenation). */
75
+ message?: VCLExpression;
76
+ }
77
+ export interface VCLSetStatement extends VCLNode {
78
+ type: "SetStatement";
79
+ target: string;
80
+ value: VCLExpression;
81
+ operator?: string;
82
+ }
83
+ export interface VCLUnsetStatement extends VCLNode {
84
+ type: "UnsetStatement";
85
+ target: string;
86
+ }
87
+ export interface VCLAddStatement extends VCLNode {
88
+ type: "AddStatement";
89
+ target: string;
90
+ value: VCLExpression;
91
+ }
92
+ export interface VCLRemoveStatement extends VCLNode {
93
+ type: "RemoveStatement";
94
+ target: string;
95
+ }
96
+ export interface VCLCallStatement extends VCLNode {
97
+ type: "CallStatement";
98
+ subroutineName: string;
99
+ arguments: VCLExpression[];
100
+ }
101
+ export interface VCLSyntheticBase64Statement extends VCLNode {
102
+ type: "SyntheticBase64Statement";
103
+ content: VCLExpression;
104
+ }
105
+ export interface VCLEsiStatement extends VCLNode {
106
+ type: "EsiStatement";
107
+ }
108
+ export interface VCLSwitchCase extends VCLNode {
109
+ test: VCLExpression | null;
110
+ /** True for `case ~"pattern":` regex-match cases. */
111
+ regex?: boolean;
112
+ body: VCLStatement[];
113
+ fallthrough: boolean;
114
+ }
115
+ export interface VCLSwitchStatement extends VCLNode {
116
+ type: "SwitchStatement";
117
+ subject: VCLExpression;
118
+ cases: VCLSwitchCase[];
119
+ }
120
+ export interface VCLLogStatement extends VCLNode {
121
+ type: "LogStatement";
122
+ message: VCLExpression;
123
+ }
124
+ export interface VCLSyntheticStatement extends VCLNode {
125
+ type: "SyntheticStatement";
126
+ content: string;
127
+ expression?: VCLExpression;
128
+ }
129
+ export interface VCLExpressionStatement extends VCLNode {
130
+ type: "ExpressionStatement";
131
+ expression: VCLExpression;
132
+ }
133
+ export interface VCLHashDataStatement extends VCLNode {
134
+ type: "HashDataStatement";
135
+ value: VCLExpression;
136
+ }
137
+ export interface VCLGotoStatement extends VCLNode {
138
+ type: "GotoStatement";
139
+ label: string;
140
+ }
141
+ export interface VCLLabelStatement extends VCLNode {
142
+ type: "LabelStatement";
143
+ name: string;
144
+ }
145
+ export interface VCLRestartStatement extends VCLNode {
146
+ type: "RestartStatement";
147
+ }
148
+ /** A bare `{ ... }` group of statements. */
149
+ export interface VCLBlockStatement extends VCLNode {
150
+ type: "BlockStatement";
151
+ body: VCLStatement[];
152
+ }
153
+ export type VCLStatement = VCLEmptyStatement | VCLAssignment | VCLIfStatement | VCLReturnStatement | VCLErrorStatement | VCLSetStatement | VCLUnsetStatement | VCLAddStatement | VCLRemoveStatement | VCLCallStatement | VCLLogStatement | VCLSyntheticStatement | VCLSyntheticBase64Statement | VCLEsiStatement | VCLSwitchStatement | VCLHashDataStatement | VCLGotoStatement | VCLLabelStatement | VCLRestartStatement | VCLDeclareStatement | VCLExpressionStatement | VCLBlockStatement;
154
+ export interface VCLIncludeStatement extends VCLNode {
155
+ type: "IncludeStatement";
156
+ module: string;
157
+ }
158
+ export interface VCLImportStatement extends VCLNode {
159
+ type: "ImportStatement";
160
+ module: string;
161
+ }
162
+ export interface VCLTableDeclaration extends VCLNode {
163
+ type: "TableDeclaration";
164
+ name: string;
165
+ valueType?: string;
166
+ entries: VCLTableEntry[];
167
+ }
168
+ export interface VCLTableEntry {
169
+ key: string;
170
+ value: string;
171
+ }
172
+ export interface VCLBackendDeclaration extends VCLNode {
173
+ type: "BackendDeclaration";
174
+ name: string;
175
+ properties: VCLBackendProperty[];
176
+ }
177
+ export interface VCLBackendProperty {
178
+ name: string;
179
+ value: string | number | VCLBackendProbe;
180
+ }
181
+ export interface VCLBackendProbe {
182
+ type: "probe";
183
+ properties: VCLBackendProperty[];
184
+ }
185
+ export interface VCLDeclareStatement extends VCLNode {
186
+ type: "DeclareStatement";
187
+ variableName: string;
188
+ variableType: string;
189
+ initialValue?: VCLExpression;
190
+ }
191
+ export interface VCLDirectorDeclaration extends VCLNode {
192
+ type: "DirectorDeclaration";
193
+ name: string;
194
+ directorType: string;
195
+ properties: VCLBackendProperty[];
196
+ backends: Array<{
197
+ name: string;
198
+ weight?: number;
199
+ }>;
200
+ }
201
+ export interface VCLPenaltyboxDeclaration extends VCLNode {
202
+ type: "PenaltyboxDeclaration";
203
+ name: string;
204
+ }
205
+ export interface VCLRatecounterDeclaration extends VCLNode {
206
+ type: "RatecounterDeclaration";
207
+ name: string;
208
+ }
209
+ export interface VCLMemberAccess extends VCLNode {
210
+ type: "MemberAccess";
211
+ object: VCLExpression;
212
+ property: string;
213
+ }
214
+ export type VCLExpression = VCLBinaryExpression | VCLUnaryExpression | VCLTernaryExpression | VCLFunctionCall | VCLIdentifier | VCLStringLiteral | VCLNumberLiteral | VCLRTimeLiteral | VCLBoolLiteral | VCLRegexLiteral | VCLMemberAccess;
215
+ export interface VCLBinaryExpression extends VCLNode {
216
+ type: "BinaryExpression";
217
+ operator: string;
218
+ left: VCLExpression;
219
+ right: VCLExpression;
220
+ }
221
+ export interface VCLUnaryExpression extends VCLNode {
222
+ type: "UnaryExpression";
223
+ operator: string;
224
+ operand: VCLExpression;
225
+ }
226
+ export interface VCLTernaryExpression extends VCLNode {
227
+ type: "TernaryExpression";
228
+ condition: VCLExpression;
229
+ trueExpr: VCLExpression;
230
+ falseExpr: VCLExpression;
231
+ }
232
+ export interface VCLFunctionCall extends VCLNode {
233
+ type: "FunctionCall";
234
+ name: string;
235
+ arguments: VCLExpression[];
236
+ }
237
+ export interface VCLIdentifier extends VCLNode {
238
+ type: "Identifier";
239
+ name: string;
240
+ }
241
+ export interface VCLStringLiteral extends VCLNode {
242
+ type: "StringLiteral";
243
+ value: string;
244
+ }
245
+ export interface VCLNumberLiteral extends VCLNode {
246
+ type: "NumberLiteral";
247
+ value: number;
248
+ /** True when the literal was written with a decimal point (VCL FLOAT). */
249
+ isFloat?: boolean;
250
+ }
251
+ export interface VCLBoolLiteral extends VCLNode {
252
+ type: "BoolLiteral";
253
+ value: boolean;
254
+ }
255
+ export interface VCLRTimeLiteral extends VCLNode {
256
+ type: "RTimeLiteral";
257
+ /** Duration in seconds. */
258
+ seconds: number;
259
+ /** Original literal text, e.g. "10s", "1.5h". */
260
+ raw: string;
261
+ }
262
+ export interface VCLRegexLiteral extends VCLNode {
263
+ type: "RegexLiteral";
264
+ pattern: string;
265
+ flags: string;
266
+ }
267
+ export interface VCLComment extends VCLNode {
268
+ type: "Comment";
269
+ value: string;
270
+ multiline: boolean;
271
+ }
272
+ export declare enum TokenType {
273
+ KEYWORD = "KEYWORD",
274
+ IDENTIFIER = "IDENTIFIER",
275
+ STRING = "STRING",
276
+ NUMBER = "NUMBER",
277
+ REGEX = "REGEX",
278
+ OPERATOR = "OPERATOR",
279
+ PUNCTUATION = "PUNCTUATION",
280
+ COMMENT = "COMMENT",
281
+ WHITESPACE = "WHITESPACE",
282
+ EOF = "EOF"
283
+ }
284
+ export interface Token {
285
+ type: TokenType;
286
+ value: string;
287
+ line: number;
288
+ column: number;
289
+ position?: number;
290
+ /**
291
+ * RTIME unit suffix for NUMBER tokens ("ms", "s", "m", "h", "d", "w", "y").
292
+ * The unit may be attached ("60s") or whitespace-separated ("60 s"), as on
293
+ * Fastly, where the unit is a separate token bound by the duration parser.
294
+ * `value` holds the normalized form without whitespace ("60s").
295
+ */
296
+ unit?: string;
297
+ }
298
+ export declare class VCLLexer {
299
+ private input;
300
+ private position;
301
+ private line;
302
+ private column;
303
+ private tokens;
304
+ constructor(input: string);
305
+ tokenize(): Token[];
306
+ private peek;
307
+ private tokenizeWhitespace;
308
+ private tokenizeComment;
309
+ private tokenizeBlockComment;
310
+ private tokenizeString;
311
+ private tokenizeLongString;
312
+ private tokenizeSyntheticBlock;
313
+ private tokenizeNumber;
314
+ private tokenizeIdentifier;
315
+ private tokenizeOperator;
316
+ private tokenizePunctuation;
317
+ private advance;
318
+ private advanceTrackingLine;
319
+ }
320
+ export declare function parseVCL(input: string): VCLProgram;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * VCL Query String Module - query string manipulation functionality
3
+ *
4
+ * Mirrors Fastly's behavior:
5
+ *
6
+ * - Everything before "?" is preserved verbatim as a prefix.
7
+ * - The query string is parsed into an ordered list of parameters. Parameter
8
+ * names and values are percent-decoded on parse ("+" decodes to space).
9
+ * - Parameters without "=" are "not set" and serialized as a bare name.
10
+ * - Parameters with values sharing the same name are grouped at the position
11
+ * of the first occurrence.
12
+ * - On serialization, names are written raw (decoded) while values are
13
+ * re-encoded like Go's url.QueryEscape (space becomes "+", unreserved
14
+ * characters are A-Z a-z 0-9 "-" "_" "." "~", everything else is %XX).
15
+ * - If the serialized query is empty, the "?" is dropped.
16
+ */
17
+ export declare const QueryStringModule: {
18
+ /**
19
+ * Returns the raw (undecoded) value of the first parameter whose
20
+ * percent-encoded name matches the canonically re-encoded argument.
21
+ * Returns null (not set) when the parameter is absent or has no "=".
22
+ */
23
+ get(url: string, name: string): string | null;
24
+ set(url: string, paramName: string, paramValue: string): string;
25
+ add(url: string, paramName: string, paramValue: string): string;
26
+ /** Removes the entire query string (including the "?"). */
27
+ remove(url: string): string;
28
+ /** Removes parameters with an empty name (keeps empty values). */
29
+ clean(url: string): string;
30
+ /** Removes parameters whose name is in the 0xFF-separated name list. */
31
+ filter(url: string, paramNames: string): string;
32
+ /** Keeps only parameters whose name is in the 0xFF-separated name list. */
33
+ filter_except(url: string, paramNames: string): string;
34
+ /** Returns the separator (a single 0xFF byte) used by filter/filter_except. */
35
+ filtersep(): string;
36
+ /** Sorts parameters by name (byte order), keeping values grouped. */
37
+ sort(url: string): string;
38
+ /** Removes parameters whose name matches the glob pattern. */
39
+ globfilter(url: string, pattern: string): string;
40
+ /** Keeps only parameters whose name matches the glob pattern. */
41
+ globfilter_except(url: string, pattern: string): string;
42
+ /** Removes parameters whose name matches the regex (unanchored). */
43
+ regfilter(url: string, pattern: string): string;
44
+ /** Keeps only parameters whose name matches the regex (unanchored). */
45
+ regfilter_except(url: string, pattern: string): string;
46
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * VCL Rate Limiting Module - rate counters, penalty boxes, and multi-window rate limiting
3
+ *
4
+ * Fastly VCL signatures:
5
+ * ratelimit.check_rate(STRING, ID, INTEGER, INTEGER, INTEGER, ID, RTIME) -> BOOL
6
+ * ratelimit.check_rates(STRING, ID, INTEGER, INTEGER, INTEGER, ID, INTEGER, INTEGER, INTEGER, ID, RTIME) -> BOOL
7
+ * ratelimit.ratecounter_increment(ID, STRING, INTEGER) -> INTEGER
8
+ * ratelimit.penaltybox_add(ID, STRING, RTIME) -> void
9
+ * ratelimit.penaltybox_has(ID, STRING) -> BOOL
10
+ */
11
+ export declare const RateLimitModule: {
12
+ init(): void;
13
+ open_window(windowSeconds: number): string;
14
+ /**
15
+ * ratelimit.ratecounter_increment(ratecounter_name, entry, delta)
16
+ * VCL: (ID, STRING, INTEGER) -> INTEGER
17
+ */
18
+ ratecounter_increment(counterName: string, entry: string, delta: number): number;
19
+ /**
20
+ * ratelimit.check_rate(entry, ratecounter, threshold, window, delta, penaltybox, ttl)
21
+ * VCL: (STRING, ID, INTEGER, INTEGER, INTEGER, ID, RTIME) -> BOOL
22
+ */
23
+ check_rate(entry: string, ratecounterName: string, threshold: number, windowSec: number, delta: number, penaltyboxName: string, ttl: number): boolean;
24
+ /**
25
+ * ratelimit.check_rates(entry, rc1, threshold1, window1, delta1, pb1, threshold2, window2, delta2, pb2, ttl)
26
+ * VCL: (STRING, ID, INTEGER, INTEGER, INTEGER, ID, INTEGER, INTEGER, INTEGER, ID, RTIME) -> BOOL
27
+ */
28
+ check_rates(entry: string, rc1: string, threshold1: number, window1: number, delta1: number, pb1: string, threshold2: number, window2: number, delta2: number, pb2: string, ttl: number): boolean;
29
+ /**
30
+ * ratelimit.penaltybox_add(penaltybox_name, entry, duration)
31
+ * VCL: (ID, STRING, RTIME) -> void
32
+ */
33
+ penaltybox_add(penaltyboxName: string, identifier: string, duration: number): void;
34
+ /**
35
+ * ratelimit.penaltybox_has(penaltybox_name, entry)
36
+ * VCL: (ID, STRING) -> BOOL
37
+ */
38
+ penaltybox_has(penaltyboxName: string, identifier: string): boolean;
39
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * VCL Security Module
3
+ * Provides WAF (Web Application Firewall) and rate limiting capabilities.
4
+ */
5
+ export declare const SecurityModule: {
6
+ init: () => void;
7
+ waf: {
8
+ allow: (context: any) => void;
9
+ block: (context: any, status: number, message: string) => any;
10
+ log: (_context: any, message: string) => void;
11
+ rate_limit: (_context: any, key: string, limit: number, window: number) => boolean;
12
+ detect_attack: (_context: any, requestData: string, attackType: string) => boolean;
13
+ rate_limit_tokens: (_context: any, key: string) => number;
14
+ };
15
+ ratelimit: {
16
+ open_window: (_context: any, windowSeconds: number) => string;
17
+ ratecounter_increment: (_context: any, counterName: string, incrementBy?: number) => void;
18
+ check_rate: (_context: any, counterName: string, ratePerSecond: number) => boolean;
19
+ check_rates: (_context: any, counterName: string, rates: string) => boolean;
20
+ penaltybox_add: (_context: any, penaltyboxName: string, identifier: string, duration: number) => void;
21
+ penaltybox_has: (_context: any, penaltyboxName: string, identifier: string) => boolean;
22
+ };
23
+ };
@@ -0,0 +1,43 @@
1
+ export interface StdModule {
2
+ strlen: (s: string) => number;
3
+ tolower: (s: string) => string;
4
+ toupper: (s: string) => string;
5
+ strstr: (haystack: string, needle: string) => string | null;
6
+ strrev: (s: string) => string | null;
7
+ strrep: (s: string, count: number) => string;
8
+ strpad: (s: string, width: number, pad: string) => string;
9
+ strcasecmp: (s1: string, s2: string) => boolean;
10
+ prefixof: (s: string, prefix: string) => boolean;
11
+ suffixof: (s: string, suffix: string) => boolean;
12
+ replace: (s: string, target: string, replacement: string) => string;
13
+ replaceall: (s: string, target: string, replacement: string) => string;
14
+ replace_prefix: (s: string, prefix: string, replacement: string) => string;
15
+ replace_suffix: (s: string, suffix: string, replacement: string) => string;
16
+ basename: (s: string) => string;
17
+ dirname: (s: string) => string;
18
+ atoi: (s: string) => number | null;
19
+ atof: (s: string) => number | null;
20
+ strtol: (s: string, base: number) => number | null;
21
+ strtof: (s: string, base: number) => number | null;
22
+ itoa: (n: number, base?: number) => string | null;
23
+ itoa_charset: (n: number, charset: string) => string;
24
+ ip: (s: string, fallback: string) => string | null;
25
+ ip2str: (ip: string) => string;
26
+ str2ip: (s: string, fallback: string) => string | null;
27
+ anystr2ip: (s: string, fallback: string) => string | null;
28
+ collect: (header: string[], separator?: string) => string;
29
+ count: (header: string[]) => number;
30
+ time: (s: string, fallback: any) => Date;
31
+ integer2time: (n: number) => Date;
32
+ log: (message: string) => void;
33
+ substr: (s: string, offset: number, length?: number) => string;
34
+ regsub: (s: string, pattern: string, replacement: string) => string;
35
+ regsuball: (s: string, pattern: string, replacement: string) => string;
36
+ urlencode: (s: string) => string | null;
37
+ urldecode: (s: string) => string | null;
38
+ cstr_escape: (s: string) => string;
39
+ json_escape: (s: string) => string;
40
+ xml_escape: (s: string) => string;
41
+ subfield: (header: string, name: string, separator?: string) => string | null;
42
+ }
43
+ export declare function createStdModule(): StdModule;