@vinext/cloudflare 1.0.0-beta.8 → 1.0.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 (59) hide show
  1. package/README.md +174 -37
  2. package/dist/cache/cdn-adapter-config.d.ts +2 -1
  3. package/dist/cache/cdn-adapter-config.js +13 -5
  4. package/dist/cache/cdn-adapter.d.ts +5 -56
  5. package/dist/cache/cdn-adapter.js +3 -61
  6. package/dist/cache/cdn-adapter.runtime.d.ts +1 -0
  7. package/dist/cache/cdn-adapter.runtime.js +17 -3
  8. package/dist/cache/cdn-adapter.worker.d.ts +1 -0
  9. package/dist/cache/cdn-adapter.worker.js +6 -4
  10. package/dist/cache/cdn-build-id.d.ts +1 -1
  11. package/dist/cache/cdn-build-id.js +1 -1
  12. package/dist/cache/config.d.ts +137 -0
  13. package/dist/cache/config.js +87 -0
  14. package/dist/cache/kv-data-adapter.d.ts +5 -1
  15. package/dist/cache/kv-data-adapter.js +6 -2
  16. package/dist/cache/kv-data-adapter.runtime.js +13 -9
  17. package/dist/cache/kv-key.d.ts +7 -4
  18. package/dist/cache/kv-key.js +16 -5
  19. package/dist/cache/response-store-adapter.d.ts +36 -0
  20. package/dist/cache/response-store-adapter.js +26 -1
  21. package/dist/cache/response-store-adapter.self-contained.worker.d.ts +1 -0
  22. package/dist/cache/response-store-adapter.self-contained.worker.js +3 -1
  23. package/dist/cache/response-store-adapter.service-binding.worker.d.ts +1 -0
  24. package/dist/cache/response-store-adapter.service-binding.worker.js +3 -1
  25. package/dist/cache/response-store-adapter.worker.d.ts +1 -1
  26. package/dist/cache/response-store-adapter.worker.js +148 -81
  27. package/dist/cache/response-store-cdn.runtime.js +1 -0
  28. package/dist/cache/response-store-data.runtime.js +53 -31
  29. package/dist/cache/static-assets-adapter.build.d.ts +6 -0
  30. package/dist/cache/static-assets-adapter.build.js +65 -0
  31. package/dist/cache/static-assets-adapter.d.ts +27 -0
  32. package/dist/cache/static-assets-adapter.js +26 -0
  33. package/dist/cache/static-assets-adapter.runtime.d.ts +26 -0
  34. package/dist/cache/static-assets-adapter.runtime.js +77 -0
  35. package/dist/cache/static-assets-adapter.shared.d.ts +12 -0
  36. package/dist/cache/static-assets-adapter.shared.js +4 -0
  37. package/dist/cache/workers-cache-cdn-adapter.d.ts +58 -0
  38. package/dist/cache/workers-cache-cdn-adapter.js +65 -0
  39. package/dist/cacheability-artifact.d.ts +7 -1
  40. package/dist/cacheability-artifact.js +60 -21
  41. package/dist/cacheability-probe.d.ts +2 -0
  42. package/dist/cacheability-probe.js +107 -13
  43. package/dist/cdn-warm.d.ts +2 -1
  44. package/dist/cdn-warm.js +25 -8
  45. package/dist/deploy-config.d.ts +3 -8
  46. package/dist/deploy-config.js +5 -23
  47. package/dist/deploy-help.js +58 -47
  48. package/dist/deploy.d.ts +31 -21
  49. package/dist/deploy.js +501 -286
  50. package/dist/tpr.d.ts +29 -72
  51. package/dist/tpr.js +52 -601
  52. package/dist/version-deploy.d.ts +27 -0
  53. package/dist/version-deploy.js +125 -5
  54. package/dist/wrangler-config.d.ts +19 -0
  55. package/dist/wrangler-config.js +294 -0
  56. package/dist/wrangler-version-metadata.js +1 -1
  57. package/package.json +16 -9
  58. package/dist/prerender-kv-populate.d.ts +0 -24
  59. package/dist/prerender-kv-populate.js +0 -153
package/dist/tpr.d.ts CHANGED
@@ -1,71 +1,36 @@
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
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;
12
+ /** Read domains from generated Build Output instead of a Wrangler config. */
13
+ typedConfig?: boolean;
32
14
  /** Analytics lookback window in hours. Default: 24. */
33
15
  window: number;
34
16
  };
35
- export 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;
17
+ export type TPRRouteResult = {
18
+ routes: TrafficEntry[];
19
+ /** Custom-domain origin from typed Build Output for staged pre-warming. */
20
+ targetUrl?: string;
44
21
  /** If TPR was skipped, the reason. */
45
22
  skipped?: string;
46
23
  };
47
- type PrerenderResult = {
48
- html: string;
49
- status: number;
50
- headers: Record<string, string>;
24
+ export type TrafficEntry = {
25
+ path: string;
26
+ requests: number;
51
27
  };
52
- type WranglerConfig = {
53
- accountId?: string;
54
- kvNamespaceId?: string;
55
- customDomain?: string;
56
- name?: string;
57
- legacyEnv?: boolean;
58
- env?: Record<string, WranglerEnvironmentConfig>;
28
+ export type SelectedRoutes = {
29
+ routes: TrafficEntry[];
30
+ totalRequests: number;
31
+ coveredRequests: number;
32
+ coveragePercent: number;
59
33
  };
60
- export 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
- export declare function parseWranglerConfig(root: string, configPath?: string): WranglerConfig | null;
69
34
  /**
70
35
  * Generate zone lookup candidates from shortest (2-part) to longest.
71
36
  * Tries the most common case first (e.g., "example.com") and progressively
@@ -76,25 +41,17 @@ export declare function parseWranglerConfig(root: string, configPath?: string):
76
41
  * "example.com" → ["example.com"]
77
42
  */
78
43
  export declare function domainCandidates(domain: string): string[];
79
- export declare function resolveVinextProdServerPath(root: string): string;
44
+ /** Filter out non-page requests (static assets, API routes, internal routes). */
45
+ export declare function filterTrafficPaths(entries: TrafficEntry[]): TrafficEntry[];
80
46
  /**
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"
47
+ * Walk the ranked traffic list, accumulating request counts until the
48
+ * coverage target is met or the hard cap is reached.
86
49
  */
87
- export declare function buildTprKVPairs(entries: Map<string, PrerenderResult>, buildId: string | undefined, defaultRevalidateSeconds: number): Array<{
88
- key: string;
89
- value: string;
90
- expiration_ttl: number;
91
- }>;
50
+ export declare function selectRoutes(traffic: TrafficEntry[], coverageTarget: number, limit: number): SelectedRoutes;
92
51
  /**
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.
52
+ * Resolve ranked traffic paths. The standard CDN pre-warming flow owns route
53
+ * matching, coverage selection, rendering, and cache admission.
98
54
  */
99
- export declare function runTPR(options: TPROptions): Promise<TPRResult>;
100
- //#endregion
55
+ export declare function resolveTPRRoutes(options: TPROptions): Promise<TPRRouteResult>;
56
+ //#endregion
57
+ export { parseWranglerConfig };