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,3 @@
1
+ import "./platform-node.js";
2
+ import type { VCLSubroutines } from "./vcl-compiler.js";
3
+ export declare function loadVCL(filePath: string): VCLSubroutines;
@@ -0,0 +1,2 @@
1
+ import { type VCLPlatform } from "./platform.js";
2
+ export declare const browserPlatform: VCLPlatform;
@@ -0,0 +1,2 @@
1
+ import type { VCLPlatform } from "./platform.js";
2
+ export declare const nodePlatform: VCLPlatform;
@@ -0,0 +1,48 @@
1
+ export type HashAlgorithm = "md5" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512";
2
+ export interface CryptoProvider {
3
+ hash(algorithm: HashAlgorithm, data: Uint8Array): Uint8Array;
4
+ hmac(algorithm: HashAlgorithm, key: Uint8Array, data: Uint8Array): Uint8Array;
5
+ timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
6
+ encrypt(algorithm: string, key: Uint8Array, iv: Uint8Array, data: Uint8Array, noPadding: boolean): Uint8Array | null;
7
+ decrypt(algorithm: string, key: Uint8Array, iv: Uint8Array, data: Uint8Array, noPadding: boolean): Uint8Array | null;
8
+ verifySignature(algorithm: string, publicKeyPem: string, data: Uint8Array, signature: Uint8Array): boolean;
9
+ }
10
+ export declare class UnsupportedFeatureError extends Error {
11
+ readonly feature: string;
12
+ constructor(feature: string, detail?: string);
13
+ }
14
+ export type LogLevel = "debug" | "info" | "warn" | "error";
15
+ export interface LogRecord {
16
+ level: LogLevel;
17
+ message: string;
18
+ fields?: Record<string, unknown>;
19
+ }
20
+ export interface TraceEvent {
21
+ phase: string;
22
+ subroutine: string;
23
+ statement?: {
24
+ line: number;
25
+ column: number;
26
+ };
27
+ returnAction?: string;
28
+ error?: string;
29
+ }
30
+ export interface VCLPlatform {
31
+ crypto: CryptoProvider;
32
+ now(): number;
33
+ randomBytes(length: number): Uint8Array;
34
+ hostname(): string;
35
+ env(name: string): string | undefined;
36
+ log(record: LogRecord): void;
37
+ onTrace?(event: TraceEvent): void;
38
+ }
39
+ export declare function setDefaultPlatform(platform: VCLPlatform): void;
40
+ export declare function getPlatform(): VCLPlatform;
41
+ export declare function getCrypto(): CryptoProvider;
42
+ export declare function randomFloat(platform: VCLPlatform): number;
43
+ export declare function hashHex(algorithm: HashAlgorithm, data: Uint8Array): string;
44
+ export declare function generateWindowId(platform: VCLPlatform): string;
45
+ export declare function consoleLog(record: LogRecord): void;
46
+ export declare function logInfo(message: string, detail?: unknown): void;
47
+ export declare function logWarn(message: string, detail?: unknown): void;
48
+ export declare function logError(message: string, detail?: unknown): void;
@@ -0,0 +1,49 @@
1
+ import { type VCLDiagnostic } from "../diagnostics.js";
2
+ import { type TraceEvent } from "../platform.js";
3
+ import { type CacheDecision, type CacheEntry } from "./pipeline.js";
4
+ export interface SimRequest {
5
+ method?: string;
6
+ url: string;
7
+ headers?: Record<string, string>;
8
+ }
9
+ export interface SimBackendResponse {
10
+ status: number;
11
+ statusText?: string;
12
+ headers?: Record<string, string>;
13
+ body?: string;
14
+ }
15
+ export interface SimPlatformOptions {
16
+ now?: number;
17
+ randomSeed?: number;
18
+ hostname?: string;
19
+ env?: Record<string, string>;
20
+ }
21
+ export interface SimulationOptions {
22
+ vcl: string;
23
+ request: SimRequest;
24
+ backendResponse: SimBackendResponse;
25
+ cacheState?: Map<string, CacheEntry>;
26
+ platformOptions?: SimPlatformOptions;
27
+ maxRestarts?: number;
28
+ }
29
+ export interface SimResponse {
30
+ status: number;
31
+ statusText: string;
32
+ headers: Record<string, string>;
33
+ body: string;
34
+ }
35
+ export type SimErrorKind = "compile" | "unsupported" | "runtime";
36
+ export interface SimulationResult {
37
+ ok: boolean;
38
+ diagnostics: VCLDiagnostic[];
39
+ trace: TraceEvent[];
40
+ logs: string[];
41
+ response?: SimResponse;
42
+ cacheDecision?: CacheDecision;
43
+ cacheState: Map<string, CacheEntry>;
44
+ error?: {
45
+ kind: SimErrorKind;
46
+ message: string;
47
+ };
48
+ }
49
+ export declare function runBrowserSimulation(options: SimulationOptions): Promise<SimulationResult>;
@@ -0,0 +1,49 @@
1
+ import type { VCLContext, VCLSubroutines } from "../vcl-compiler.js";
2
+ export interface BackendResponse {
3
+ status: number;
4
+ statusText?: string;
5
+ headers: Record<string, string>;
6
+ body: Uint8Array | ArrayBuffer | string;
7
+ }
8
+ export interface CacheEntry {
9
+ resp: {
10
+ status: number;
11
+ statusText: string;
12
+ http: Record<string, string>;
13
+ };
14
+ body: Uint8Array;
15
+ created: number;
16
+ expires: number;
17
+ staleUntil: number;
18
+ beresp: VCLContext["beresp"];
19
+ }
20
+ export type CacheOutcome = "hit" | "hit-stale" | "miss" | "pass" | "uncacheable" | "error" | "upgrade";
21
+ export interface PipelineResponse {
22
+ status: number;
23
+ statusText: string;
24
+ headers: Record<string, string>;
25
+ body: Uint8Array;
26
+ }
27
+ export interface CacheDecision {
28
+ outcome: CacheOutcome;
29
+ key: string;
30
+ ttl?: number;
31
+ grace?: number;
32
+ staleWhileRevalidate?: number;
33
+ ageSeconds?: number;
34
+ stored: boolean;
35
+ }
36
+ export interface PipelineResult {
37
+ response: PipelineResponse;
38
+ action: string;
39
+ restarts: number;
40
+ cache: CacheDecision;
41
+ }
42
+ export interface PipelineOptions {
43
+ subroutines: VCLSubroutines;
44
+ context: VCLContext;
45
+ cache: Map<string, CacheEntry>;
46
+ maxRestarts: number;
47
+ getBackendResponse: (context: VCLContext) => Promise<BackendResponse>;
48
+ }
49
+ export declare function runPipeline(opts: PipelineOptions): Promise<PipelineResult>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Utility functions for the VCL parser and executor
3
+ */
4
+ export declare function assert(condition: boolean, message: string): {
5
+ success: boolean;
6
+ message: string;
7
+ };
@@ -0,0 +1,8 @@
1
+ export declare function language_filter_basic(lookup: string, defaultValue: string, acceptLanguage: any, nmatches: number): string;
2
+ export declare const AcceptModule: {
3
+ language_lookup: (available: string, defaultLang: string, header: string) => string;
4
+ language_filter_basic: typeof language_filter_basic;
5
+ charset_lookup: (available: string, defaultCharset: string, header: string) => string;
6
+ encoding_lookup: (available: string, defaultEncoding: string, header: string) => string;
7
+ media_lookup: (available: string, defaultMedia: string, patterns: string, header: string) => string;
8
+ };
@@ -0,0 +1,19 @@
1
+ export interface AclEntry {
2
+ ip: string;
3
+ subnet?: number;
4
+ negated?: boolean;
5
+ }
6
+ type Family = "ipv4" | "ipv6";
7
+ export declare function getIPType(ip: string): Family | null;
8
+ /**
9
+ * True when `ip` matches the ACL.
10
+ * The most-specific containing entry wins; its negation flag decides the
11
+ * result. A value that does not parse as an IP matches nothing.
12
+ */
13
+ export declare function aclMatch(ip: string, entries: AclEntry[]): boolean;
14
+ /**
15
+ * Reject an ACL whose entries name the same network both as-is and negated,
16
+ * the way Fastly's compiler does. Exact duplicates (same negation) are allowed.
17
+ */
18
+ export declare function validateAclEntries(aclName: string, entries: AclEntry[]): void;
19
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare function parseIPv4(ip: string): Uint8Array | null;
2
+ export declare function parseIPv6(ip: string): Uint8Array | null;
3
+ export declare const AddressModule: {
4
+ is_ipv4: (address: string) => boolean;
5
+ is_ipv6: (address: string) => boolean;
6
+ is_unix: (address: string) => boolean;
7
+ extract_bits: (address: string, startBit: number, bitCount: number) => number;
8
+ };
@@ -0,0 +1,5 @@
1
+ export declare const BinaryModule: {
2
+ base64_to_hex: (base64: string) => string;
3
+ hex_to_base64: (hex: string) => string;
4
+ data_convert: (input: string, inputEncoding: string, outputEncoding: string) => string;
5
+ };
@@ -0,0 +1,10 @@
1
+ export interface BuiltinSignature {
2
+ args: string[][];
3
+ ret: string | null;
4
+ }
5
+ export declare const BUILTIN_SIGNATURES: Record<string, BuiltinSignature>;
6
+ export interface VariableSignature {
7
+ get: string | null;
8
+ set: string | null;
9
+ }
10
+ export declare const VARIABLE_TYPES: Record<string, VariableSignature>;