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.
- package/LICENSE +21 -0
- package/README.md +702 -0
- package/dist/browser.d.ts +10 -0
- package/dist/browser.js +10544 -0
- package/dist/csrf-protection.d.ts +10 -0
- package/dist/diagnostics.d.ts +11 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10435 -0
- package/dist/node-loader.d.ts +3 -0
- package/dist/platform-browser.d.ts +2 -0
- package/dist/platform-node.d.ts +2 -0
- package/dist/platform.d.ts +48 -0
- package/dist/runtime/browser.d.ts +49 -0
- package/dist/runtime/pipeline.d.ts +49 -0
- package/dist/utils.d.ts +7 -0
- package/dist/vcl-accept.d.ts +8 -0
- package/dist/vcl-acl.d.ts +19 -0
- package/dist/vcl-address.d.ts +8 -0
- package/dist/vcl-binary.d.ts +5 -0
- package/dist/vcl-builtin-types.d.ts +10 -0
- package/dist/vcl-compiler.d.ts +513 -0
- package/dist/vcl-digest.d.ts +87 -0
- package/dist/vcl-esi.d.ts +32 -0
- package/dist/vcl-fetch.d.ts +6 -0
- package/dist/vcl-header.d.ts +18 -0
- package/dist/vcl-limits.d.ts +10 -0
- package/dist/vcl-math.d.ts +45 -0
- package/dist/vcl-misc.d.ts +29 -0
- package/dist/vcl-node.d.ts +2 -0
- package/dist/vcl-parser-impl.d.ts +126 -0
- package/dist/vcl-parser.d.ts +320 -0
- package/dist/vcl-querystring.d.ts +46 -0
- package/dist/vcl-ratelimit.d.ts +39 -0
- package/dist/vcl-security.d.ts +23 -0
- package/dist/vcl-std.d.ts +43 -0
- package/dist/vcl-strings.d.ts +47 -0
- package/dist/vcl-table.d.ts +27 -0
- package/dist/vcl-testing.d.ts +60 -0
- package/dist/vcl-time.d.ts +60 -0
- package/dist/vcl-utf8.d.ts +6 -0
- package/dist/vcl-uuid.d.ts +38 -0
- package/dist/vcl-value.d.ts +96 -0
- package/dist/vcl-waf.d.ts +14 -0
- package/dist/vcl.d.ts +7 -0
- package/package.json +90 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { type VCLPlatform } from "./platform.js";
|
|
2
|
+
import type { VCLProgram } from "./vcl-parser.js";
|
|
3
|
+
export interface VCLBackend {
|
|
4
|
+
name: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
ssl: boolean;
|
|
8
|
+
connect_timeout: number;
|
|
9
|
+
first_byte_timeout: number;
|
|
10
|
+
between_bytes_timeout: number;
|
|
11
|
+
/** Total fetch bound in seconds; 0 or unset falls back to first_byte_timeout. */
|
|
12
|
+
fetch_timeout?: number;
|
|
13
|
+
max_connections: number;
|
|
14
|
+
ssl_cert_hostname?: string;
|
|
15
|
+
ssl_sni_hostname?: string;
|
|
16
|
+
ssl_check_cert?: boolean;
|
|
17
|
+
probe?: VCLProbe;
|
|
18
|
+
is_healthy?: boolean;
|
|
19
|
+
/** True for the built-in placeholder backend a fresh context starts with. */
|
|
20
|
+
builtin?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface VCLProbe {
|
|
23
|
+
request: string;
|
|
24
|
+
expected_response: number;
|
|
25
|
+
interval: number;
|
|
26
|
+
timeout: number;
|
|
27
|
+
window: number;
|
|
28
|
+
threshold: number;
|
|
29
|
+
initial: number;
|
|
30
|
+
}
|
|
31
|
+
export interface VCLDirector {
|
|
32
|
+
name: string;
|
|
33
|
+
type: "random" | "hash" | "client" | "fallback" | "chash";
|
|
34
|
+
backends: Array<{
|
|
35
|
+
backend: VCLBackend;
|
|
36
|
+
weight: number;
|
|
37
|
+
}>;
|
|
38
|
+
quorum: number;
|
|
39
|
+
retries: number;
|
|
40
|
+
}
|
|
41
|
+
export interface VCLACLEntry {
|
|
42
|
+
ip: string;
|
|
43
|
+
subnet?: number;
|
|
44
|
+
negated?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface VCLACL {
|
|
47
|
+
name: string;
|
|
48
|
+
entries: VCLACLEntry[];
|
|
49
|
+
}
|
|
50
|
+
export interface VCLTable {
|
|
51
|
+
name: string;
|
|
52
|
+
valueType?: string;
|
|
53
|
+
entries: Record<string, string | number | boolean | RegExp>;
|
|
54
|
+
}
|
|
55
|
+
export interface VCLContext {
|
|
56
|
+
req: {
|
|
57
|
+
url: string;
|
|
58
|
+
method: string;
|
|
59
|
+
http: Record<string, string>;
|
|
60
|
+
backend?: string;
|
|
61
|
+
restarts?: number;
|
|
62
|
+
};
|
|
63
|
+
bereq: {
|
|
64
|
+
url: string;
|
|
65
|
+
method: string;
|
|
66
|
+
http: Record<string, string>;
|
|
67
|
+
};
|
|
68
|
+
beresp: {
|
|
69
|
+
status: number;
|
|
70
|
+
statusText: string;
|
|
71
|
+
http: Record<string, string>;
|
|
72
|
+
ttl: number;
|
|
73
|
+
grace?: number;
|
|
74
|
+
stale_while_revalidate?: number;
|
|
75
|
+
do_esi?: boolean;
|
|
76
|
+
/** Whether beresp.pci / beresp.hipaa was set on this response. */
|
|
77
|
+
pci?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The backend that answered this pass's request, captured when the
|
|
80
|
+
* response was obtained.
|
|
81
|
+
* Absent when no backend request was made (e.g. a cache hit), which
|
|
82
|
+
* makes beresp.backend.* read as not set.
|
|
83
|
+
*/
|
|
84
|
+
backend?: {
|
|
85
|
+
name: string;
|
|
86
|
+
host: string;
|
|
87
|
+
port: number;
|
|
88
|
+
ip: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
resp: {
|
|
92
|
+
status: number;
|
|
93
|
+
statusText: string;
|
|
94
|
+
http: Record<string, string>;
|
|
95
|
+
};
|
|
96
|
+
obj: {
|
|
97
|
+
status: number;
|
|
98
|
+
/** Response reason phrase; undefined until a synthetic/error body sets it. */
|
|
99
|
+
response?: string;
|
|
100
|
+
http: Record<string, string>;
|
|
101
|
+
hits: number;
|
|
102
|
+
};
|
|
103
|
+
cache: Map<string, any>;
|
|
104
|
+
hashData?: string[];
|
|
105
|
+
backends: Record<string, VCLBackend>;
|
|
106
|
+
directors: Record<string, VCLDirector>;
|
|
107
|
+
current_backend?: VCLBackend;
|
|
108
|
+
acls: Record<string, VCLACL>;
|
|
109
|
+
tables: Record<string, VCLTable>;
|
|
110
|
+
client?: {
|
|
111
|
+
ip: string;
|
|
112
|
+
};
|
|
113
|
+
re?: {
|
|
114
|
+
groups?: Record<number, string>;
|
|
115
|
+
};
|
|
116
|
+
platform: VCLPlatform;
|
|
117
|
+
locals: Record<string, any>;
|
|
118
|
+
localTypes?: Record<string, string>;
|
|
119
|
+
workspaceBytes?: number;
|
|
120
|
+
fastly?: {
|
|
121
|
+
error?: string;
|
|
122
|
+
state?: string;
|
|
123
|
+
};
|
|
124
|
+
addr?: {
|
|
125
|
+
is_ipv4: (address: string) => boolean;
|
|
126
|
+
is_ipv6: (address: string) => boolean;
|
|
127
|
+
is_unix: (address: string) => boolean;
|
|
128
|
+
extract_bits: (address: string, offset: number, length: number) => number;
|
|
129
|
+
};
|
|
130
|
+
accept?: {
|
|
131
|
+
language_lookup: (availableLanguages: string, defaultLanguage: string, acceptLanguageHeader: string) => string;
|
|
132
|
+
charset_lookup: (availableCharsets: string, defaultCharset: string, acceptCharsetHeader: string) => string;
|
|
133
|
+
encoding_lookup: (availableEncodings: string, defaultEncoding: string, acceptEncodingHeader: string) => string;
|
|
134
|
+
media_lookup: (availableMediaTypes: string, defaultMediaType: string, mediaTypePatterns: string, acceptHeader: string) => string;
|
|
135
|
+
language_filter_basic: (availableLanguages: string, defaultLanguage: string, acceptLanguageHeader: string, nmatches: number) => string;
|
|
136
|
+
};
|
|
137
|
+
bin?: {
|
|
138
|
+
base64_to_hex: (base64: string) => string;
|
|
139
|
+
hex_to_base64: (hex: string) => string;
|
|
140
|
+
data_convert: (input: string, inputEncoding: string, outputEncoding: string) => string;
|
|
141
|
+
};
|
|
142
|
+
querystring?: {
|
|
143
|
+
get: (queryString: string, paramName: string) => string | null;
|
|
144
|
+
set: (queryString: string, paramName: string, paramValue: string) => string;
|
|
145
|
+
add: (queryString: string, paramName: string, paramValue: string) => string;
|
|
146
|
+
remove: (queryString: string) => string;
|
|
147
|
+
clean: (queryString: string) => string;
|
|
148
|
+
filter: (queryString: string, paramNames: string) => string;
|
|
149
|
+
filter_except: (queryString: string, paramNames: string) => string;
|
|
150
|
+
filtersep: () => string;
|
|
151
|
+
sort: (queryString: string) => string;
|
|
152
|
+
globfilter: (queryString: string, pattern: string) => string;
|
|
153
|
+
globfilter_except: (queryString: string, pattern: string) => string;
|
|
154
|
+
regfilter: (queryString: string, pattern: string) => string;
|
|
155
|
+
regfilter_except: (queryString: string, pattern: string) => string;
|
|
156
|
+
[key: string]: any;
|
|
157
|
+
};
|
|
158
|
+
uuid?: {
|
|
159
|
+
version3: (namespace: string, name: string) => string | null;
|
|
160
|
+
version4: () => string;
|
|
161
|
+
version5: (namespace: string, name: string) => string | null;
|
|
162
|
+
version7: () => string;
|
|
163
|
+
dns: () => string;
|
|
164
|
+
url: () => string;
|
|
165
|
+
oid: () => string;
|
|
166
|
+
x500: () => string;
|
|
167
|
+
is_valid: (uuid: string) => boolean;
|
|
168
|
+
is_version3: (uuid: string) => boolean;
|
|
169
|
+
is_version4: (uuid: string) => boolean;
|
|
170
|
+
is_version5: (uuid: string) => boolean;
|
|
171
|
+
is_version7: (uuid: string) => boolean;
|
|
172
|
+
decode: (uuid: string) => Uint8Array | null;
|
|
173
|
+
encode: (binary: Uint8Array) => string;
|
|
174
|
+
[key: string]: any;
|
|
175
|
+
};
|
|
176
|
+
utf8?: {
|
|
177
|
+
is_valid: (s: string) => boolean;
|
|
178
|
+
codepoint_count: (s: string) => number;
|
|
179
|
+
substr: (s: string, offset: number, length?: number) => string | null;
|
|
180
|
+
strpad: (s: string, width: number, pad: string) => string | null;
|
|
181
|
+
};
|
|
182
|
+
waf?: Record<string, any>;
|
|
183
|
+
error?: (status: number, message: string) => string;
|
|
184
|
+
std?: Record<string, any> & {
|
|
185
|
+
log?: (message: string) => void;
|
|
186
|
+
strftime?: (format: string, time: number) => string;
|
|
187
|
+
time?: (s: string, fallback: any) => Date;
|
|
188
|
+
integer2time?: (n: number) => Date;
|
|
189
|
+
backend?: {
|
|
190
|
+
add: (name: string, host: string, port: number, ssl?: boolean, options?: any) => boolean;
|
|
191
|
+
remove: (name: string) => boolean;
|
|
192
|
+
get: (name: string) => VCLBackend | null;
|
|
193
|
+
set_current: (name: string) => boolean;
|
|
194
|
+
is_healthy: (name: string) => boolean;
|
|
195
|
+
add_probe: (backendName: string, options: any) => boolean;
|
|
196
|
+
};
|
|
197
|
+
director?: {
|
|
198
|
+
add: (name: string, type: string, options?: any) => boolean;
|
|
199
|
+
remove: (name: string) => boolean;
|
|
200
|
+
add_backend: (directorName: string, backendName: string, weight?: number) => boolean;
|
|
201
|
+
remove_backend: (directorName: string, backendName: string) => boolean;
|
|
202
|
+
select_backend: (directorName: string) => VCLBackend | null;
|
|
203
|
+
};
|
|
204
|
+
tolower: (str: string) => string;
|
|
205
|
+
toupper: (str: string) => string;
|
|
206
|
+
strlen: (str: string) => number;
|
|
207
|
+
strstr: (haystack: string, needle: string) => string | null;
|
|
208
|
+
substr: (str: string, offset: number, length?: number) => string;
|
|
209
|
+
prefixof: (str: string, prefix: string) => boolean;
|
|
210
|
+
suffixof: (str: string, suffix: string) => boolean;
|
|
211
|
+
replace: (str: string, search: string, replacement: string) => string;
|
|
212
|
+
replaceall: (str: string, search: string, replacement: string) => string;
|
|
213
|
+
regsub: (str: string, regex: string, replacement: string) => string;
|
|
214
|
+
regsuball: (str: string, regex: string, replacement: string) => string;
|
|
215
|
+
integer: (value: any) => number;
|
|
216
|
+
real: (value: any) => number;
|
|
217
|
+
math: {
|
|
218
|
+
round: (num: number) => number;
|
|
219
|
+
floor: (num: number) => number;
|
|
220
|
+
ceil: (num: number) => number;
|
|
221
|
+
pow: (base: number, exponent: number) => number;
|
|
222
|
+
log: (num: number) => number;
|
|
223
|
+
min: (a: number, b: number) => number;
|
|
224
|
+
max: (a: number, b: number) => number;
|
|
225
|
+
abs: (num: number) => number;
|
|
226
|
+
};
|
|
227
|
+
base64: (str: string) => string;
|
|
228
|
+
base64_decode: (str: string) => string;
|
|
229
|
+
base64url: (str: string) => string;
|
|
230
|
+
base64url_decode: (str: string) => string;
|
|
231
|
+
digest: {
|
|
232
|
+
hash_md5: (str: string) => string;
|
|
233
|
+
hash_sha1: (str: string) => string;
|
|
234
|
+
hash_sha256: (str: string) => string;
|
|
235
|
+
hash_sha512: (str: string) => string;
|
|
236
|
+
hash_xxh32: (str: string) => string;
|
|
237
|
+
hash_xxh64: (str: string) => string;
|
|
238
|
+
hmac_md5: (key: string, message: string) => string | null;
|
|
239
|
+
hmac_sha1: (key: string, message: string) => string | null;
|
|
240
|
+
hmac_sha256: (key: string, message: string) => string | null;
|
|
241
|
+
hmac_sha512: (key: string, message: string) => string | null;
|
|
242
|
+
hmac_md5_base64: (key: string, message: string) => string | null;
|
|
243
|
+
hmac_sha1_base64: (key: string, message: string) => string | null;
|
|
244
|
+
hmac_sha256_base64: (key: string, message: string) => string | null;
|
|
245
|
+
hmac_sha512_base64: (key: string, message: string) => string | null;
|
|
246
|
+
secure_is_equal: (a: string, b: string) => boolean;
|
|
247
|
+
base64: (str: string) => string;
|
|
248
|
+
base64_decode: (str: string) => string;
|
|
249
|
+
base64url: (str: string) => string;
|
|
250
|
+
base64url_decode: (str: string) => string;
|
|
251
|
+
base64url_nopad: (str: string) => string;
|
|
252
|
+
base64url_nopad_decode: (str: string) => string;
|
|
253
|
+
[key: string]: any;
|
|
254
|
+
};
|
|
255
|
+
header: {
|
|
256
|
+
get: (headers: Record<string, string>, name: string) => string | null;
|
|
257
|
+
set: (headers: Record<string, string>, name: string, value: string) => void;
|
|
258
|
+
remove: (headers: Record<string, string>, name: string) => void;
|
|
259
|
+
filter: (headers: Record<string, string>, pattern: string) => void;
|
|
260
|
+
filter_except: (headers: Record<string, string>, pattern: string) => void;
|
|
261
|
+
};
|
|
262
|
+
http: {
|
|
263
|
+
status_matches: (status: number, pattern: string) => boolean;
|
|
264
|
+
};
|
|
265
|
+
synthetic: (content: string) => void;
|
|
266
|
+
error: (status: number, message?: string) => void;
|
|
267
|
+
querystring: {
|
|
268
|
+
get: (url: string, name: string) => string | null;
|
|
269
|
+
set: (url: string, name: string, value: string) => string;
|
|
270
|
+
remove: (url: string, name: string) => string;
|
|
271
|
+
filter: (url: string, names: string[]) => string;
|
|
272
|
+
filter_except: (url: string, names: string[]) => string;
|
|
273
|
+
[key: string]: any;
|
|
274
|
+
};
|
|
275
|
+
strrev?: (s: string) => string;
|
|
276
|
+
strrep?: (s: string, count: number) => string;
|
|
277
|
+
strpad?: (s: string, width: number, pad: string) => string;
|
|
278
|
+
strcasecmp?: (s1: string, s2: string) => number;
|
|
279
|
+
replace_prefix?: (s: string, prefix: string, replacement: string) => string;
|
|
280
|
+
replace_suffix?: (s: string, suffix: string, replacement: string) => string;
|
|
281
|
+
basename?: (s: string) => string;
|
|
282
|
+
dirname?: (s: string) => string;
|
|
283
|
+
atoi?: (s: string) => number;
|
|
284
|
+
atof?: (s: string) => number;
|
|
285
|
+
strtol?: (s: string, base: number) => number;
|
|
286
|
+
strtof?: (s: string) => number;
|
|
287
|
+
itoa?: (n: number, base?: number) => string;
|
|
288
|
+
itoa_charset?: (n: number, charset: string) => string;
|
|
289
|
+
ip?: (s: string, fallback: string) => string;
|
|
290
|
+
ip2str?: (ip: string) => string;
|
|
291
|
+
str2ip?: (s: string) => string;
|
|
292
|
+
anystr2ip?: (s: string, fallback: string) => string;
|
|
293
|
+
collect?: (header: string[], separator?: string) => string;
|
|
294
|
+
count?: (header: string[]) => number;
|
|
295
|
+
acl?: {
|
|
296
|
+
add: (name: string) => boolean;
|
|
297
|
+
remove: (name: string) => boolean;
|
|
298
|
+
add_entry: (aclName: string, ip: string, subnet?: number, negated?: boolean) => boolean;
|
|
299
|
+
remove_entry: (aclName: string, ip: string, subnet?: number) => boolean;
|
|
300
|
+
check: (ip: string, aclName: string) => boolean;
|
|
301
|
+
};
|
|
302
|
+
random?: {
|
|
303
|
+
randombool: (probability: number) => boolean;
|
|
304
|
+
randombool_seeded: (probability: number, seed: string) => boolean;
|
|
305
|
+
randomint: (from: number, to: number) => number;
|
|
306
|
+
randomint_seeded: (from: number, to: number, seed: string) => number;
|
|
307
|
+
randomstr: (length: number, charset?: string) => string;
|
|
308
|
+
bool?: (numerator: number, denominator: number) => boolean;
|
|
309
|
+
};
|
|
310
|
+
table?: {
|
|
311
|
+
add: (name: string) => boolean;
|
|
312
|
+
remove: (name: string) => boolean;
|
|
313
|
+
add_entry: (tableName: string, key: string, value: string | number | boolean | RegExp) => boolean;
|
|
314
|
+
remove_entry: (tableName: string, key: string) => boolean;
|
|
315
|
+
lookup: (tableName: string, key: string, defaultValue?: string) => string;
|
|
316
|
+
lookup_bool: (tableName: string, key: string, defaultValue?: boolean) => boolean;
|
|
317
|
+
lookup_integer: (tableName: string, key: string, defaultValue?: number) => number;
|
|
318
|
+
lookup_float: (tableName: string, key: string, defaultValue?: number) => number;
|
|
319
|
+
lookup_regex: (tableName: string, key: string, defaultValue?: string) => RegExp;
|
|
320
|
+
contains: (tableName: string, key: string) => boolean;
|
|
321
|
+
};
|
|
322
|
+
ratelimit?: Record<string, any>;
|
|
323
|
+
[key: string]: any;
|
|
324
|
+
};
|
|
325
|
+
math?: Record<string, any> & {
|
|
326
|
+
sin?: (x: number) => number;
|
|
327
|
+
cos?: (x: number) => number;
|
|
328
|
+
tan?: (x: number) => number;
|
|
329
|
+
asin?: (x: number) => number;
|
|
330
|
+
acos?: (x: number) => number;
|
|
331
|
+
atan?: (x: number) => number;
|
|
332
|
+
atan2?: (y: number, x: number) => number;
|
|
333
|
+
sinh?: (x: number) => number;
|
|
334
|
+
cosh?: (x: number) => number;
|
|
335
|
+
tanh?: (x: number) => number;
|
|
336
|
+
asinh?: (x: number) => number;
|
|
337
|
+
acosh?: (x: number) => number;
|
|
338
|
+
atanh?: (x: number) => number;
|
|
339
|
+
exp: (x: number) => number;
|
|
340
|
+
exp2: (x: number) => number;
|
|
341
|
+
log: (x: number) => number;
|
|
342
|
+
log2: (x: number) => number;
|
|
343
|
+
log10: (x: number) => number;
|
|
344
|
+
pow: (base: number, exp: number) => number;
|
|
345
|
+
sqrt: (x: number) => number;
|
|
346
|
+
ceil: (x: number) => number;
|
|
347
|
+
floor: (x: number) => number;
|
|
348
|
+
round: (x: number) => number;
|
|
349
|
+
roundeven: (x: number) => number;
|
|
350
|
+
roundhalfdown: (x: number) => number;
|
|
351
|
+
roundhalfup: (x: number) => number;
|
|
352
|
+
trunc: (x: number) => number;
|
|
353
|
+
abs: (x: number) => number;
|
|
354
|
+
min: (a: number, b: number) => number;
|
|
355
|
+
max: (a: number, b: number) => number;
|
|
356
|
+
fmod: (x: number, y: number) => number;
|
|
357
|
+
is_finite: (x: number) => boolean;
|
|
358
|
+
is_infinite: (x: number) => boolean;
|
|
359
|
+
is_nan: (x: number) => boolean;
|
|
360
|
+
is_normal: (x: number) => boolean;
|
|
361
|
+
is_subnormal: (x: number) => boolean;
|
|
362
|
+
};
|
|
363
|
+
table?: Record<string, any> & {
|
|
364
|
+
lookup?: (tables: any, tableName: string, key: string, defaultValue?: string) => string | null;
|
|
365
|
+
lookup_bool: (tables: any, tableName: string, key: string, defaultValue?: boolean) => boolean;
|
|
366
|
+
lookup_integer: (tables: any, tableName: string, key: string, defaultValue?: number) => number;
|
|
367
|
+
lookup_float: (tables: any, tableName: string, key: string, defaultValue?: number) => number;
|
|
368
|
+
lookup_ip: (tables: any, tableName: string, key: string, defaultValue?: string) => string;
|
|
369
|
+
lookup_rtime: (tables: any, tableName: string, key: string, defaultValue?: number) => number;
|
|
370
|
+
lookup_acl: (tables: any, tableName: string, key: string) => string | null;
|
|
371
|
+
lookup_backend: (tables: any, tableName: string, key: string) => string | null;
|
|
372
|
+
lookup_regex: (tables: any, tableName: string, key: string) => RegExp | null;
|
|
373
|
+
contains: (tables: any, tableName: string, key: string) => boolean;
|
|
374
|
+
};
|
|
375
|
+
time?: {
|
|
376
|
+
now: () => Date;
|
|
377
|
+
add: (time: any, duration?: any) => any;
|
|
378
|
+
sub: (time: any, duration?: any) => any;
|
|
379
|
+
is_after: (time1: any, time2?: any) => boolean;
|
|
380
|
+
hex_to_time: (divisor: any, hex?: any) => any;
|
|
381
|
+
units: (unit: any, time?: any) => any;
|
|
382
|
+
runits: (unit: any, rtime?: any) => any;
|
|
383
|
+
interval_elapsed_ratio: (start: Date, interval: number) => number;
|
|
384
|
+
};
|
|
385
|
+
header?: {
|
|
386
|
+
get: (headers: any, name: string) => string;
|
|
387
|
+
set: (headers: any, name: string, value: string) => void;
|
|
388
|
+
unset: (headers: any, name: string) => void;
|
|
389
|
+
filter: (headers: any, filterNames: string[]) => any;
|
|
390
|
+
filter_except: (headers: any, keepNames: string[]) => any;
|
|
391
|
+
};
|
|
392
|
+
strftime?: (format: string, time: Date) => string;
|
|
393
|
+
parse_time_delta?: (delta: string) => number;
|
|
394
|
+
rateLimitModule?: any;
|
|
395
|
+
results?: Record<string, any>;
|
|
396
|
+
ratelimit?: {
|
|
397
|
+
counters: Record<string, any>;
|
|
398
|
+
penaltyboxes: Record<string, any>;
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
export interface VCLSubroutines {
|
|
402
|
+
vcl_recv?: (context: VCLContext) => string;
|
|
403
|
+
vcl_hash?: (context: VCLContext) => string;
|
|
404
|
+
vcl_hit?: (context: VCLContext) => string;
|
|
405
|
+
vcl_miss?: (context: VCLContext) => string;
|
|
406
|
+
vcl_pass?: (context: VCLContext) => string;
|
|
407
|
+
vcl_fetch?: (context: VCLContext) => string;
|
|
408
|
+
vcl_deliver?: (context: VCLContext) => string;
|
|
409
|
+
vcl_error?: (context: VCLContext) => string;
|
|
410
|
+
vcl_pipe?: (context: VCLContext) => string;
|
|
411
|
+
vcl_init?: (context: VCLContext) => string;
|
|
412
|
+
vcl_synth?: (context: VCLContext) => string;
|
|
413
|
+
vcl_log?: (context: VCLContext) => void;
|
|
414
|
+
[key: string]: ((context: VCLContext) => string | void) | undefined;
|
|
415
|
+
}
|
|
416
|
+
export declare const VCLStdLib: {
|
|
417
|
+
log: (message: string) => void;
|
|
418
|
+
time: {
|
|
419
|
+
parse: (timeStr: string) => number;
|
|
420
|
+
format: (time: number, _format: string) => string;
|
|
421
|
+
};
|
|
422
|
+
string: {
|
|
423
|
+
tolower: (str: string) => string;
|
|
424
|
+
toupper: (str: string) => string;
|
|
425
|
+
match: (str: string, pattern: string) => boolean;
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
export declare class VCLCompiler {
|
|
429
|
+
private program;
|
|
430
|
+
private currentSubroutine;
|
|
431
|
+
/** Nesting depth of functional (typed) subroutine calls being evaluated. */
|
|
432
|
+
private functionalSubDepth;
|
|
433
|
+
/** Typed (functional) subroutines by name, for expression-call dispatch. */
|
|
434
|
+
private functionalSubs;
|
|
435
|
+
/** Header record of the req/bereq/beresp/resp/obj scope, if valid. */
|
|
436
|
+
private httpHeadersOf;
|
|
437
|
+
constructor(program: VCLProgram);
|
|
438
|
+
compile(): VCLSubroutines;
|
|
439
|
+
/**
|
|
440
|
+
* Goto is forward-only in Fastly VCL: every goto must name a label that
|
|
441
|
+
* appears after it. A backward or undefined destination is a load error.
|
|
442
|
+
*/
|
|
443
|
+
private validateGotos;
|
|
444
|
+
private compileSubroutine;
|
|
445
|
+
/**
|
|
446
|
+
* Statement scope guard: some statements are only legal while executing a
|
|
447
|
+
* specific built-in subroutine (dynamically — custom subs inherit their
|
|
448
|
+
* caller's scope). Throws a runtime error like Fastly does.
|
|
449
|
+
*/
|
|
450
|
+
private requireScope;
|
|
451
|
+
/** Merge the compile-time declaration context into a runtime context. */
|
|
452
|
+
private mergeDeclarations;
|
|
453
|
+
private executeStatement;
|
|
454
|
+
/** Coerce a value assigned to a local to its declared VCL type. */
|
|
455
|
+
private coerceLocalValue;
|
|
456
|
+
private executeDeclareStatement;
|
|
457
|
+
private executeIfStatement;
|
|
458
|
+
private executeReturnStatement;
|
|
459
|
+
private executeErrorStatement;
|
|
460
|
+
private resolveForCompound;
|
|
461
|
+
private applyCompoundOperator;
|
|
462
|
+
private getTargetValue;
|
|
463
|
+
private executeSetStatement;
|
|
464
|
+
private executeUnsetStatement;
|
|
465
|
+
/** Resolve any runtime value to the string VCL would produce in an output sink (log, synthetic). */
|
|
466
|
+
private stringifyForOutput;
|
|
467
|
+
private executeLogStatement;
|
|
468
|
+
private executeSyntheticStatement;
|
|
469
|
+
private executeSyntheticBase64Statement;
|
|
470
|
+
private executeEsiStatement;
|
|
471
|
+
private executeAddStatement;
|
|
472
|
+
private chargeRequestWorkspace;
|
|
473
|
+
/** Execute a typed subroutine invoked as an expression and return its value. */
|
|
474
|
+
private executeFunctionalSub;
|
|
475
|
+
private executeCallStatement;
|
|
476
|
+
private executeSwitchStatement;
|
|
477
|
+
private executeHashDataStatement;
|
|
478
|
+
private executeGotoStatement;
|
|
479
|
+
private executeRestartStatement;
|
|
480
|
+
private evaluateExpression;
|
|
481
|
+
/**
|
|
482
|
+
* Fastly condition truthiness: a STRING is true when it is set — even when
|
|
483
|
+
* empty — and false only when notset. Other types use plain truthiness.
|
|
484
|
+
*/
|
|
485
|
+
private isTruthyCondition;
|
|
486
|
+
private evaluateTernaryExpression;
|
|
487
|
+
private evaluateFunctionCall;
|
|
488
|
+
private evaluateFunctionCallInner;
|
|
489
|
+
private evaluateIdentifier;
|
|
490
|
+
private evaluateIdentifierInner;
|
|
491
|
+
private resolveVariable;
|
|
492
|
+
private evaluateUnaryExpression;
|
|
493
|
+
private evaluateBinaryExpression;
|
|
494
|
+
/**
|
|
495
|
+
* Equality for the == and != operators.
|
|
496
|
+
* A STRING left operand drives the comparison: the right side is
|
|
497
|
+
* stringified per its VCL type and compared byte-wise, matching how
|
|
498
|
+
* Fastly compiles string equality to VRT_strcmp with the right operand
|
|
499
|
+
* rendered through the type's to-string conversion.
|
|
500
|
+
* NOTSET values compare using their display string "(null)".
|
|
501
|
+
*/
|
|
502
|
+
private vclEquals;
|
|
503
|
+
private regexMatch;
|
|
504
|
+
private isIpInAcl;
|
|
505
|
+
/** Parse header name with optional subfield: "VARS:VALUE" → ["VARS", "VALUE"] */
|
|
506
|
+
private parseSubfield;
|
|
507
|
+
/** Get a subfield value from a comma-separated key=value dictionary */
|
|
508
|
+
private dictGet;
|
|
509
|
+
/** Set a subfield in a comma-separated key=value dictionary */
|
|
510
|
+
private dictSet;
|
|
511
|
+
/** Remove a subfield from a comma-separated key=value dictionary */
|
|
512
|
+
private dictUnset;
|
|
513
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type VCLPlatform } from "./platform.js";
|
|
2
|
+
export declare function createDigestModule(boundPlatform?: VCLPlatform): {
|
|
3
|
+
hash_md5: (input: string) => string;
|
|
4
|
+
hash_sha1: (input: string) => string;
|
|
5
|
+
hash_sha224: (input: string) => string;
|
|
6
|
+
hash_sha256: (input: string) => string;
|
|
7
|
+
hash_sha384: (input: string) => string;
|
|
8
|
+
hash_sha512: (input: string) => string;
|
|
9
|
+
hash_crc32: (input: string) => string;
|
|
10
|
+
hash_crc32b: (input: string) => string;
|
|
11
|
+
hash_xxh32: (input: string) => string;
|
|
12
|
+
hash_xxh64: (input: string) => string;
|
|
13
|
+
hash_sha1_from_base64: (input: string) => string;
|
|
14
|
+
hash_sha256_from_base64: (input: string) => string;
|
|
15
|
+
hash_sha512_from_base64: (input: string) => string;
|
|
16
|
+
hash_xxh32_from_base64: (input: string) => string;
|
|
17
|
+
hash_xxh64_from_base64: (input: string) => string;
|
|
18
|
+
hmac_md5: (key: string, input: string) => string | null;
|
|
19
|
+
hmac_sha1: (key: string, input: string) => string | null;
|
|
20
|
+
hmac_sha256: (key: string, input: string) => string | null;
|
|
21
|
+
hmac_sha512: (key: string, input: string) => string | null;
|
|
22
|
+
hmac_md5_base64: (key: string, input: string) => string | null;
|
|
23
|
+
hmac_sha1_base64: (key: string, input: string) => string | null;
|
|
24
|
+
hmac_sha256_base64: (key: string, input: string) => string | null;
|
|
25
|
+
hmac_sha512_base64: (key: string, input: string) => string | null;
|
|
26
|
+
time_hmac_md5: (key: string, interval: number, _offset: number) => string;
|
|
27
|
+
time_hmac_sha1: (key: string, interval: number, _offset: number) => string;
|
|
28
|
+
time_hmac_sha256: (key: string, interval: number, _offset: number) => string;
|
|
29
|
+
time_hmac_sha512: (key: string, interval: number, _offset: number) => string;
|
|
30
|
+
hmac_sha256_with_base64_key: (base64Key: string, input: string) => string | null;
|
|
31
|
+
secure_is_equal: (a: string, b: string) => boolean;
|
|
32
|
+
base64: (input: string) => string;
|
|
33
|
+
base64_decode: (input: string) => string;
|
|
34
|
+
base64url: (input: string) => string;
|
|
35
|
+
base64url_decode: (input: string) => string;
|
|
36
|
+
base64url_nopad: (input: string) => string;
|
|
37
|
+
base64url_nopad_decode: (input: string) => string;
|
|
38
|
+
awsv4_hmac: (key: string, dateStamp: string, region: string, service: string, stringToSign: string) => string;
|
|
39
|
+
rsa_verify: (hashMethod: string, publicKey: string, payload: string, signature: string, base64Method?: string) => boolean;
|
|
40
|
+
ecdsa_verify: (hashMethod: string, publicKey: string, payload: string, signature: string, digestFormat?: string, base64Method?: string) => boolean;
|
|
41
|
+
};
|
|
42
|
+
export declare const DigestModule: {
|
|
43
|
+
hash_md5: (input: string) => string;
|
|
44
|
+
hash_sha1: (input: string) => string;
|
|
45
|
+
hash_sha224: (input: string) => string;
|
|
46
|
+
hash_sha256: (input: string) => string;
|
|
47
|
+
hash_sha384: (input: string) => string;
|
|
48
|
+
hash_sha512: (input: string) => string;
|
|
49
|
+
hash_crc32: (input: string) => string;
|
|
50
|
+
hash_crc32b: (input: string) => string;
|
|
51
|
+
hash_xxh32: (input: string) => string;
|
|
52
|
+
hash_xxh64: (input: string) => string;
|
|
53
|
+
hash_sha1_from_base64: (input: string) => string;
|
|
54
|
+
hash_sha256_from_base64: (input: string) => string;
|
|
55
|
+
hash_sha512_from_base64: (input: string) => string;
|
|
56
|
+
hash_xxh32_from_base64: (input: string) => string;
|
|
57
|
+
hash_xxh64_from_base64: (input: string) => string;
|
|
58
|
+
hmac_md5: (key: string, input: string) => string | null;
|
|
59
|
+
hmac_sha1: (key: string, input: string) => string | null;
|
|
60
|
+
hmac_sha256: (key: string, input: string) => string | null;
|
|
61
|
+
hmac_sha512: (key: string, input: string) => string | null;
|
|
62
|
+
hmac_md5_base64: (key: string, input: string) => string | null;
|
|
63
|
+
hmac_sha1_base64: (key: string, input: string) => string | null;
|
|
64
|
+
hmac_sha256_base64: (key: string, input: string) => string | null;
|
|
65
|
+
hmac_sha512_base64: (key: string, input: string) => string | null;
|
|
66
|
+
time_hmac_md5: (key: string, interval: number, _offset: number) => string;
|
|
67
|
+
time_hmac_sha1: (key: string, interval: number, _offset: number) => string;
|
|
68
|
+
time_hmac_sha256: (key: string, interval: number, _offset: number) => string;
|
|
69
|
+
time_hmac_sha512: (key: string, interval: number, _offset: number) => string;
|
|
70
|
+
hmac_sha256_with_base64_key: (base64Key: string, input: string) => string | null;
|
|
71
|
+
secure_is_equal: (a: string, b: string) => boolean;
|
|
72
|
+
base64: (input: string) => string;
|
|
73
|
+
base64_decode: (input: string) => string;
|
|
74
|
+
base64url: (input: string) => string;
|
|
75
|
+
base64url_decode: (input: string) => string;
|
|
76
|
+
base64url_nopad: (input: string) => string;
|
|
77
|
+
base64url_nopad_decode: (input: string) => string;
|
|
78
|
+
awsv4_hmac: (key: string, dateStamp: string, region: string, service: string, stringToSign: string) => string;
|
|
79
|
+
rsa_verify: (hashMethod: string, publicKey: string, payload: string, signature: string, base64Method?: string) => boolean;
|
|
80
|
+
ecdsa_verify: (hashMethod: string, publicKey: string, payload: string, signature: string, digestFormat?: string, base64Method?: string) => boolean;
|
|
81
|
+
};
|
|
82
|
+
export declare const CryptoModule: {
|
|
83
|
+
encrypt_base64: (cipher: string, mode: string, padding: string, key: string, iv: string, plaintext: string) => string;
|
|
84
|
+
decrypt_base64: (cipher: string, mode: string, padding: string, key: string, iv: string, ciphertext: string) => string;
|
|
85
|
+
encrypt_hex: (cipher: string, mode: string, padding: string, key: string, iv: string, plaintext: string) => string;
|
|
86
|
+
decrypt_hex: (cipher: string, mode: string, padding: string, key: string, iv: string, ciphertext: string) => string;
|
|
87
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VCL ESI (Edge Side Includes) Module
|
|
3
|
+
* Parses and processes ESI tags in HTML content per the Fastly VCL specification.
|
|
4
|
+
*/
|
|
5
|
+
import type { VCLContext } from "./vcl.js";
|
|
6
|
+
export declare enum ESITagType {
|
|
7
|
+
INCLUDE = "include",
|
|
8
|
+
REMOVE = "remove",
|
|
9
|
+
COMMENT = "comment",
|
|
10
|
+
CHOOSE = "choose",
|
|
11
|
+
WHEN = "when",
|
|
12
|
+
OTHERWISE = "otherwise",
|
|
13
|
+
VARS = "vars"
|
|
14
|
+
}
|
|
15
|
+
export interface ESITag {
|
|
16
|
+
type: ESITagType;
|
|
17
|
+
content?: string;
|
|
18
|
+
attributes?: Record<string, string>;
|
|
19
|
+
children?: ESITag[];
|
|
20
|
+
parent?: ESITag;
|
|
21
|
+
}
|
|
22
|
+
export declare class ESIParser {
|
|
23
|
+
private content;
|
|
24
|
+
private position;
|
|
25
|
+
private tags;
|
|
26
|
+
constructor(content: string);
|
|
27
|
+
parse(): ESITag[];
|
|
28
|
+
private parseTag;
|
|
29
|
+
private getTagType;
|
|
30
|
+
private parseAttributes;
|
|
31
|
+
}
|
|
32
|
+
export declare function processESI(content: string, context: VCLContext): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VCL Header Functions Module
|
|
3
|
+
*
|
|
4
|
+
* Implements all header.* functions from Fastly VCL.
|
|
5
|
+
* Reference: https://developer.fastly.com/reference/vcl/functions/headers/
|
|
6
|
+
*/
|
|
7
|
+
export interface Headers {
|
|
8
|
+
[name: string]: string | string[] | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface HeaderModule {
|
|
11
|
+
get: (headers: Headers, name: string) => string;
|
|
12
|
+
set: (headers: Headers, name: string, value: string) => void;
|
|
13
|
+
unset: (headers: Headers, name: string) => void;
|
|
14
|
+
filter: (headers: Headers, filterNames: string[]) => Headers;
|
|
15
|
+
filter_except: (headers: Headers, keepNames: string[]) => Headers;
|
|
16
|
+
}
|
|
17
|
+
export declare function createHeaderModule(): HeaderModule;
|
|
18
|
+
export declare function httpStatusMatches(status: number, ...patterns: string[]): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { VCLSubroutine } from "./vcl-parser.js";
|
|
2
|
+
export declare const MAX_REQUEST_WORKSPACE_SIZE: number;
|
|
3
|
+
export declare const BASE_REQUEST_WORKSPACE_OVERHEAD: number;
|
|
4
|
+
export declare function headerWorkspaceCost(name: string, value: string): number;
|
|
5
|
+
export declare function seedRequestWorkspace(httpHeaders: Record<string, string>): number;
|
|
6
|
+
export declare const MAX_SUBROUTINE_CALL_TREE = 25000;
|
|
7
|
+
export declare class VCLLimitExceededError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare function checkCallTreeLimit(subroutines: VCLSubroutine[]): void;
|