@vinext/cloudflare 1.0.0-beta.7 → 1.0.0-beta.9

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 (56) hide show
  1. package/README.md +64 -22
  2. package/dist/cache/cdn-adapter-config.d.ts +16 -8
  3. package/dist/cache/cdn-adapter-config.js +57 -17
  4. package/dist/cache/cdn-adapter.d.ts +25 -24
  5. package/dist/cache/cdn-adapter.js +24 -20
  6. package/dist/cache/cdn-adapter.runtime.d.ts +9 -3
  7. package/dist/cache/cdn-adapter.runtime.js +63 -40
  8. package/dist/cache/cdn-adapter.worker.d.ts +31 -0
  9. package/dist/cache/cdn-adapter.worker.js +373 -0
  10. package/dist/cache/cdn-build-id.d.ts +4 -3
  11. package/dist/cache/cdn-build-id.js +5 -1
  12. package/dist/cache/kv-data-adapter.d.ts +25 -5
  13. package/dist/cache/kv-data-adapter.js +5 -1
  14. package/dist/cache/kv-data-adapter.runtime.d.ts +38 -4
  15. package/dist/cache/kv-data-adapter.runtime.js +115 -41
  16. package/dist/cache/kv-key.d.ts +4 -5
  17. package/dist/cache/response-store-adapter.d.ts +70 -0
  18. package/dist/cache/response-store-adapter.js +45 -0
  19. package/dist/cache/response-store-adapter.self-contained.worker.d.ts +18 -0
  20. package/dist/cache/response-store-adapter.self-contained.worker.js +12 -0
  21. package/dist/cache/response-store-adapter.service-binding.worker.d.ts +16 -0
  22. package/dist/cache/response-store-adapter.service-binding.worker.js +11 -0
  23. package/dist/cache/response-store-adapter.worker.d.ts +14 -0
  24. package/dist/cache/response-store-adapter.worker.js +264 -0
  25. package/dist/cache/response-store-cdn.runtime.d.ts +5 -0
  26. package/dist/cache/response-store-cdn.runtime.js +41 -0
  27. package/dist/cache/response-store-data.runtime.d.ts +34 -0
  28. package/dist/cache/response-store-data.runtime.js +289 -0
  29. package/dist/cacheability-artifact.d.ts +2 -3
  30. package/dist/cacheability-artifact.js +27 -1
  31. package/dist/cacheability-manifest-limits.d.ts +3 -4
  32. package/dist/cacheability-manifest-limits.js +1 -1
  33. package/dist/cacheability-probe.d.ts +8 -9
  34. package/dist/cacheability-probe.js +255 -91
  35. package/dist/cdn-warm.d.ts +31 -25
  36. package/dist/cdn-warm.js +228 -54
  37. package/dist/deploy-config.d.ts +11 -12
  38. package/dist/deploy-config.js +8 -3
  39. package/dist/deploy-help.d.ts +3 -4
  40. package/dist/deploy-help.js +20 -14
  41. package/dist/deploy.d.ts +35 -28
  42. package/dist/deploy.js +204 -95
  43. package/dist/images/images-optimizer.d.ts +3 -4
  44. package/dist/prerender-kv-populate.d.ts +3 -4
  45. package/dist/prerender-kv-populate.js +3 -2
  46. package/dist/tpr.d.ts +26 -74
  47. package/dist/tpr.js +45 -603
  48. package/dist/utils/cache-control-metadata.d.ts +3 -4
  49. package/dist/version-deploy.d.ts +17 -17
  50. package/dist/version-deploy.js +10 -5
  51. package/dist/worker-deployment-url.d.ts +3 -4
  52. package/dist/workers-dev-url.d.ts +2 -3
  53. package/dist/wrangler-config.d.ts +19 -0
  54. package/dist/wrangler-config.js +294 -0
  55. package/dist/wrangler-version-metadata.d.ts +2 -3
  56. package/package.json +13 -11
package/dist/tpr.d.ts CHANGED
@@ -1,71 +1,32 @@
1
+ import { parseWranglerConfig } from "./wrangler-config.js";
1
2
  //#region src/tpr.d.ts
2
- /**
3
- * TPR: Traffic-aware Pre-Rendering
4
- *
5
- * Uses Cloudflare zone analytics to determine which pages actually get
6
- * traffic, and pre-renders only those during deploy. The pre-rendered
7
- * HTML is uploaded to KV in the same format ISR uses at runtime — no
8
- * runtime changes needed.
9
- *
10
- * Flow:
11
- * 1. Parse wrangler config to find custom domain and KV namespace
12
- * 2. Resolve the Cloudflare zone for the custom domain
13
- * 3. Query zone analytics (GraphQL) for top pages by request count
14
- * 4. Walk ranked list until coverage threshold is met
15
- * 5. Start the built production server locally
16
- * 6. Fetch each hot route to produce HTML
17
- * 7. Upload pre-rendered HTML to KV (same KVCacheEntry format ISR reads)
18
- *
19
- * TPR is an experimental feature enabled via --experimental-tpr. It
20
- * gracefully skips when no custom domain, no API token, no traffic data,
21
- * or no KV namespace is configured.
22
- */
23
- type TPROptions = {
3
+ export type TPROptions = {
24
4
  /** Project root directory. */
25
5
  root: string;
26
6
  /** Wrangler config path, relative to root unless absolute. */
27
7
  config?: string;
28
- /** Traffic coverage percentage (0–100). Default: 90. */
29
- coverage: number;
30
- /** Hard cap on number of pages to pre-render. Default: 1000. */
31
- limit: number;
8
+ /** Wrangler environment whose custom domain should be analyzed. */
9
+ env?: string;
10
+ /** Explicit domain used to resolve the analytics zone, overriding Wrangler routes. */
11
+ hostname?: string;
32
12
  /** Analytics lookback window in hours. Default: 24. */
33
13
  window: number;
34
14
  };
35
- type TPRResult = {
36
- /** Total unique page paths found in analytics. */
37
- totalPaths: number;
38
- /** Number of pages successfully pre-rendered and uploaded. */
39
- prerenderedCount: number;
40
- /** Actual traffic coverage achieved (percentage). */
41
- coverageAchieved: number;
42
- /** Wall-clock duration of the TPR step in milliseconds. */
43
- durationMs: number;
15
+ export type TPRRouteResult = {
16
+ routes: TrafficEntry[];
44
17
  /** If TPR was skipped, the reason. */
45
18
  skipped?: string;
46
19
  };
47
- type PrerenderResult = {
48
- html: string;
49
- status: number;
50
- headers: Record<string, string>;
20
+ export type TrafficEntry = {
21
+ path: string;
22
+ requests: number;
51
23
  };
52
- type WranglerConfig = {
53
- accountId?: string;
54
- kvNamespaceId?: string;
55
- customDomain?: string;
56
- name?: string;
57
- legacyEnv?: boolean;
58
- env?: Record<string, WranglerEnvironmentConfig>;
24
+ export type SelectedRoutes = {
25
+ routes: TrafficEntry[];
26
+ totalRequests: number;
27
+ coveredRequests: number;
28
+ coveragePercent: number;
59
29
  };
60
- type WranglerEnvironmentConfig = {
61
- customDomain?: string;
62
- name?: string;
63
- };
64
- /**
65
- * Parse wrangler config (JSONC or TOML) to extract the fields TPR needs:
66
- * account_id, VINEXT_KV_CACHE KV namespace ID, and custom domain.
67
- */
68
- declare function parseWranglerConfig(root: string, configPath?: string): WranglerConfig | null;
69
30
  /**
70
31
  * Generate zone lookup candidates from shortest (2-part) to longest.
71
32
  * Tries the most common case first (e.g., "example.com") and progressively
@@ -75,27 +36,18 @@ declare function parseWranglerConfig(root: string, configPath?: string): Wrangle
75
36
  * "shop.example.co.uk" → ["co.uk", "example.co.uk", "shop.example.co.uk"]
76
37
  * "example.com" → ["example.com"]
77
38
  */
78
- declare function domainCandidates(domain: string): string[];
79
- declare function resolveVinextProdServerPath(root: string): string;
39
+ export declare function domainCandidates(domain: string): string[];
40
+ /** Filter out non-page requests (static assets, API routes, internal routes). */
41
+ export declare function filterTrafficPaths(entries: TrafficEntry[]): TrafficEntry[];
80
42
  /**
81
- * Build KV bulk API pairs from pre-rendered entries.
82
- *
83
- * Key format matches the runtime KVCacheHandler exactly:
84
- * createKvKeySpace().entryKey(isrCacheKey("app", pathname, buildId) + ":html")
85
- * → "cache:app:<buildId>:<pathname>:html"
43
+ * Walk the ranked traffic list, accumulating request counts until the
44
+ * coverage target is met or the hard cap is reached.
86
45
  */
87
- declare function buildTprKVPairs(entries: Map<string, PrerenderResult>, buildId: string | undefined, defaultRevalidateSeconds: number): Array<{
88
- key: string;
89
- value: string;
90
- expiration_ttl: number;
91
- }>;
46
+ export declare function selectRoutes(traffic: TrafficEntry[], coverageTarget: number, limit: number): SelectedRoutes;
92
47
  /**
93
- * Run the TPR pipeline: query traffic, select routes, pre-render, upload.
94
- *
95
- * Designed to be called between the build step and wrangler deploy in the
96
- * `vinext-cloudflare deploy` pipeline. Gracefully skips (never errors) when
97
- * the prerequisites aren't met.
48
+ * Resolve ranked traffic paths. The standard CDN pre-warming flow owns route
49
+ * matching, coverage selection, rendering, and cache admission.
98
50
  */
99
- declare function runTPR(options: TPROptions): Promise<TPRResult>;
51
+ export declare function resolveTPRRoutes(options: TPROptions): Promise<TPRRouteResult>;
100
52
  //#endregion
101
- export { TPROptions, TPRResult, WranglerEnvironmentConfig, buildTprKVPairs, domainCandidates, parseWranglerConfig, resolveVinextProdServerPath, runTPR };
53
+ export { parseWranglerConfig };