@netlify/plugin-nextjs 4.41.3 → 5.0.0-beta.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 (239) hide show
  1. package/README.md +61 -17
  2. package/dist/build/cache.js +15 -0
  3. package/dist/build/content/prerendered.js +16 -0
  4. package/dist/build/content/server.js +18 -0
  5. package/dist/build/content/static.js +20 -0
  6. package/dist/build/functions/edge.js +14 -0
  7. package/dist/build/functions/server.js +16 -0
  8. package/dist/build/plugin-context.js +17 -0
  9. package/dist/esm-chunks/chunk-4AJYXTWN.js +17 -0
  10. package/dist/esm-chunks/chunk-62KDS27E.js +77 -0
  11. package/dist/esm-chunks/chunk-AVWFCGVE.js +5536 -0
  12. package/dist/esm-chunks/chunk-B6QMRLBH.js +255 -0
  13. package/dist/esm-chunks/chunk-G2VRYWGL.js +107 -0
  14. package/dist/esm-chunks/chunk-G3GM7JNF.js +92 -0
  15. package/dist/esm-chunks/chunk-GGHAQM5D.js +28 -0
  16. package/dist/esm-chunks/chunk-HPGTYMVD.js +113 -0
  17. package/dist/esm-chunks/chunk-PEBUKFKH.js +89 -0
  18. package/dist/esm-chunks/chunk-R4NHZWGU.js +32 -0
  19. package/dist/esm-chunks/chunk-RSKIKBZH.js +44 -0
  20. package/dist/esm-chunks/chunk-XD5TSLZO.js +85 -0
  21. package/dist/esm-chunks/chunk-ZBX3SNQG.js +561 -0
  22. package/dist/index.js +66 -0
  23. package/dist/run/config.js +18 -0
  24. package/dist/run/constants.js +15 -0
  25. package/dist/run/handlers/cache.cjs +849 -0
  26. package/dist/run/handlers/server.js +3289 -0
  27. package/dist/run/headers.js +19 -0
  28. package/dist/run/next.cjs +1055 -0
  29. package/dist/run/revalidate.js +13 -0
  30. package/edge-runtime/README.md +29 -0
  31. package/edge-runtime/lib/headers.ts +26 -0
  32. package/edge-runtime/lib/middleware.ts +60 -0
  33. package/edge-runtime/lib/next-request.ts +59 -0
  34. package/edge-runtime/lib/response.ts +145 -0
  35. package/edge-runtime/lib/util.ts +26 -0
  36. package/edge-runtime/middleware.ts +40 -0
  37. package/edge-runtime/shim/index.js +8 -0
  38. package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +1 -1
  39. package/edge-runtime/vendor/import_map.json +13 -0
  40. package/edge-runtime/vendor.ts +18 -0
  41. package/manifest.yml +1 -1
  42. package/package.json +23 -60
  43. package/index.js +0 -1
  44. package/lib/constants.js +0 -56
  45. package/lib/helpers/analysis.js +0 -115
  46. package/lib/helpers/cache.js +0 -46
  47. package/lib/helpers/compiler.js +0 -119
  48. package/lib/helpers/config.js +0 -192
  49. package/lib/helpers/dev.js +0 -20
  50. package/lib/helpers/edge.js +0 -328
  51. package/lib/helpers/files.js +0 -335
  52. package/lib/helpers/flags.js +0 -46
  53. package/lib/helpers/functions.js +0 -437
  54. package/lib/helpers/functionsMetaData.js +0 -46
  55. package/lib/helpers/matchers.js +0 -41
  56. package/lib/helpers/middlewareWatcher.js +0 -12
  57. package/lib/helpers/pack.js +0 -41
  58. package/lib/helpers/redirects.js +0 -246
  59. package/lib/helpers/types.js +0 -2
  60. package/lib/helpers/utils.js +0 -226
  61. package/lib/helpers/verification.js +0 -182
  62. package/lib/index.js +0 -194
  63. package/lib/templates/blobStorage.js +0 -30
  64. package/lib/templates/getApiHandler.js +0 -120
  65. package/lib/templates/getHandler.js +0 -201
  66. package/lib/templates/getPageResolver.js +0 -54
  67. package/lib/templates/handlerUtils.js +0 -268
  68. package/lib/templates/ipx.js +0 -13
  69. package/lib/templates/requireHooks.js +0 -105
  70. package/lib/templates/server.js +0 -159
  71. package/lib/templates/vendor.js +0 -20
  72. package/src/templates/edge/bundle.js +0 -8
  73. package/src/templates/edge/function-runtime.ts +0 -24
  74. package/src/templates/edge/imageconfig.json +0 -3
  75. package/src/templates/edge/ipx.ts +0 -5
  76. package/src/templates/edge/matchers.json +0 -1
  77. package/src/templates/edge/middleware-runtime.ts +0 -62
  78. package/src/templates/edge/next-dev.js +0 -104
  79. package/src/templates/edge/rsc-data.ts +0 -5
  80. package/src/templates/edge/shims.js +0 -77
  81. package/src/templates/edge-shared/next-utils.ts +0 -407
  82. package/src/templates/edge-shared/nextConfig.json +0 -3
  83. package/src/templates/edge-shared/prerender-manifest.json +0 -7
  84. package/src/templates/edge-shared/rsc-data.ts +0 -78
  85. package/src/templates/edge-shared/utils.test.ts +0 -114
  86. package/src/templates/edge-shared/utils.ts +0 -315
  87. package/src/templates/vendor/import_map.json +0 -13
  88. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/fmt/colors.ts +0 -0
  89. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/testing/_diff.ts +0 -0
  90. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/testing/asserts.ts +0 -0
  91. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/_util/asserts.ts +0 -0
  92. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/_util/os.ts +0 -0
  93. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/abortable.ts +0 -0
  94. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/deadline.ts +0 -0
  95. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/debounce.ts +0 -0
  96. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/deferred.ts +0 -0
  97. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/delay.ts +0 -0
  98. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/mod.ts +0 -0
  99. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +0 -0
  100. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/pool.ts +0 -0
  101. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/retry.ts +0 -0
  102. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/tee.ts +0 -0
  103. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +0 -0
  104. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +0 -0
  105. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +0 -0
  106. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/encoding/base64.ts +0 -0
  107. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/encoding/base64url.ts +0 -0
  108. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/flags/mod.ts +0 -0
  109. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/fmt/colors.ts +0 -0
  110. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/fmt/printf.ts +0 -0
  111. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/http/cookie.ts +0 -0
  112. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_core.ts +0 -0
  113. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_events.d.ts +0 -0
  114. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_events.mjs +0 -0
  115. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_global.d.ts +0 -0
  116. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_next_tick.ts +0 -0
  117. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +0 -0
  118. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/process.ts +0 -0
  119. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +0 -0
  120. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +0 -0
  121. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_stream.d.ts +0 -0
  122. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_stream.mjs +0 -0
  123. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +0 -0
  124. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_utils.ts +0 -0
  125. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/assert.ts +0 -0
  126. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/assertion_error.ts +0 -0
  127. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/async_hooks.ts +0 -0
  128. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/buffer.ts +0 -0
  129. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/events.ts +0 -0
  130. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +0 -0
  131. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +0 -0
  132. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +0 -0
  133. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +0 -0
  134. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +0 -0
  135. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/errors.ts +0 -0
  136. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +0 -0
  137. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +0 -0
  138. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/net.ts +0 -0
  139. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +0 -0
  140. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/options.ts +0 -0
  141. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +0 -0
  142. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +0 -0
  143. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +0 -0
  144. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +0 -0
  145. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +0 -0
  146. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +0 -0
  147. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +0 -0
  148. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +0 -0
  149. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +0 -0
  150. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +0 -0
  151. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +0 -0
  152. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util.mjs +0 -0
  153. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +0 -0
  154. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +0 -0
  155. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +0 -0
  156. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +0 -0
  157. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +0 -0
  158. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +0 -0
  159. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +0 -0
  160. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +0 -0
  161. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +0 -0
  162. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +0 -0
  163. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +0 -0
  164. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +0 -0
  165. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +0 -0
  166. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +0 -0
  167. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +0 -0
  168. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +0 -0
  169. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +0 -0
  170. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +0 -0
  171. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +0 -0
  172. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +0 -0
  173. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +0 -0
  174. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +0 -0
  175. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +0 -0
  176. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +0 -0
  177. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +0 -0
  178. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +0 -0
  179. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +0 -0
  180. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +0 -0
  181. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +0 -0
  182. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +0 -0
  183. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +0 -0
  184. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +0 -0
  185. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +0 -0
  186. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +0 -0
  187. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +0 -0
  188. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +0 -0
  189. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +0 -0
  190. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +0 -0
  191. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +0 -0
  192. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +0 -0
  193. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +0 -0
  194. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +0 -0
  195. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +0 -0
  196. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +0 -0
  197. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +0 -0
  198. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +0 -0
  199. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +0 -0
  200. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +0 -0
  201. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +0 -0
  202. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +0 -0
  203. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +0 -0
  204. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +0 -0
  205. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +0 -0
  206. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +0 -0
  207. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +0 -0
  208. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +0 -0
  209. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +0 -0
  210. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +0 -0
  211. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +0 -0
  212. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +0 -0
  213. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/process.ts +0 -0
  214. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/stream.ts +0 -0
  215. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/string_decoder.ts +0 -0
  216. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/util/types.ts +0 -0
  217. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/util.ts +0 -0
  218. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_constants.ts +0 -0
  219. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_interface.ts +0 -0
  220. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_util.ts +0 -0
  221. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/common.ts +0 -0
  222. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/glob.ts +0 -0
  223. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/mod.ts +0 -0
  224. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/posix.ts +0 -0
  225. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/separator.ts +0 -0
  226. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/win32.ts +0 -0
  227. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/streams/write_all.ts +0 -0
  228. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/_diff.ts +0 -0
  229. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/_format.ts +0 -0
  230. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/asserts.ts +0 -0
  231. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/types.d.ts +0 -0
  232. /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +0 -0
  233. /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +0 -0
  234. /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +0 -0
  235. /package/{src/templates → edge-runtime}/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +0 -0
  236. /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +0 -0
  237. /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +0 -0
  238. /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +0 -0
  239. /package/{src/templates → edge-runtime}/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +0 -0
@@ -0,0 +1,849 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // node_modules/is-promise/index.js
34
+ var require_is_promise = __commonJS({
35
+ "node_modules/is-promise/index.js"(exports2, module2) {
36
+ module2.exports = isPromise;
37
+ module2.exports.default = isPromise;
38
+ function isPromise(obj) {
39
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
40
+ }
41
+ }
42
+ });
43
+
44
+ // node_modules/@netlify/functions/dist/lib/consts.js
45
+ var require_consts = __commonJS({
46
+ "node_modules/@netlify/functions/dist/lib/consts.js"(exports2) {
47
+ "use strict";
48
+ Object.defineProperty(exports2, "__esModule", { value: true });
49
+ exports2.METADATA_VERSION = exports2.HTTP_STATUS_OK = exports2.HTTP_STATUS_METHOD_NOT_ALLOWED = exports2.BUILDER_FUNCTIONS_FLAG = void 0;
50
+ var BUILDER_FUNCTIONS_FLAG = true;
51
+ exports2.BUILDER_FUNCTIONS_FLAG = BUILDER_FUNCTIONS_FLAG;
52
+ var HTTP_STATUS_METHOD_NOT_ALLOWED = 405;
53
+ exports2.HTTP_STATUS_METHOD_NOT_ALLOWED = HTTP_STATUS_METHOD_NOT_ALLOWED;
54
+ var HTTP_STATUS_OK = 200;
55
+ exports2.HTTP_STATUS_OK = HTTP_STATUS_OK;
56
+ var METADATA_VERSION = 1;
57
+ exports2.METADATA_VERSION = METADATA_VERSION;
58
+ }
59
+ });
60
+
61
+ // node_modules/@netlify/functions/dist/lib/builder.js
62
+ var require_builder = __commonJS({
63
+ "node_modules/@netlify/functions/dist/lib/builder.js"(exports2) {
64
+ "use strict";
65
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
66
+ return mod && mod.__esModule ? mod : { "default": mod };
67
+ };
68
+ Object.defineProperty(exports2, "__esModule", { value: true });
69
+ exports2.builder = void 0;
70
+ var is_promise_1 = __importDefault(require_is_promise());
71
+ var consts_js_1 = require_consts();
72
+ var augmentResponse = (response) => {
73
+ if (!response) {
74
+ return response;
75
+ }
76
+ const metadata = { version: consts_js_1.METADATA_VERSION, builder_function: consts_js_1.BUILDER_FUNCTIONS_FLAG, ttl: response.ttl || 0 };
77
+ return {
78
+ ...response,
79
+ metadata
80
+ };
81
+ };
82
+ var wrapHandler = (handler) => (
83
+ // eslint-disable-next-line promise/prefer-await-to-callbacks
84
+ (event, context, callback) => {
85
+ if (event.httpMethod !== "GET" && event.httpMethod !== "HEAD") {
86
+ return Promise.resolve({
87
+ body: "Method Not Allowed",
88
+ statusCode: consts_js_1.HTTP_STATUS_METHOD_NOT_ALLOWED
89
+ });
90
+ }
91
+ const modifiedEvent = {
92
+ ...event,
93
+ multiValueQueryStringParameters: {},
94
+ queryStringParameters: {}
95
+ };
96
+ const wrappedCallback = (error, response) => (
97
+ // eslint-disable-next-line promise/prefer-await-to-callbacks
98
+ callback ? callback(error, augmentResponse(response)) : null
99
+ );
100
+ const execution = handler(modifiedEvent, context, wrappedCallback);
101
+ if ((0, is_promise_1.default)(execution)) {
102
+ return execution.then(augmentResponse);
103
+ }
104
+ return execution;
105
+ }
106
+ );
107
+ exports2.builder = wrapHandler;
108
+ }
109
+ });
110
+
111
+ // node_modules/@netlify/functions/dist/lib/purge_cache.js
112
+ var require_purge_cache = __commonJS({
113
+ "node_modules/@netlify/functions/dist/lib/purge_cache.js"(exports2) {
114
+ "use strict";
115
+ Object.defineProperty(exports2, "__esModule", { value: true });
116
+ exports2.purgeCache = void 0;
117
+ var process_1 = require("process");
118
+ var purgeCache2 = async (options = {}) => {
119
+ if (globalThis.fetch === void 0) {
120
+ throw new Error("`fetch` is not available. Please ensure you're using Node.js version 18.0.0 or above. Refer to https://ntl.fyi/functions-runtime for more information.");
121
+ }
122
+ const payload = {
123
+ cache_tags: options.tags,
124
+ deploy_alias: options.deployAlias
125
+ };
126
+ const token = process_1.env.NETLIFY_PURGE_API_TOKEN || options.token;
127
+ if ("siteSlug" in options) {
128
+ payload.site_slug = options.siteSlug;
129
+ } else if ("domain" in options) {
130
+ payload.domain = options.domain;
131
+ } else {
132
+ const siteID = options.siteID || process_1.env.SITE_ID;
133
+ if (!siteID) {
134
+ throw new Error("The Netlify site ID was not found in the execution environment. Please supply it manually using the `siteID` property.");
135
+ }
136
+ payload.site_id = siteID;
137
+ }
138
+ if (!token) {
139
+ throw new Error("The cache purge API token was not found in the execution environment. Please supply it manually using the `token` property.");
140
+ }
141
+ const apiURL = options.apiURL || "https://api.netlify.com";
142
+ const response = await fetch(`${apiURL}/api/v1/purge`, {
143
+ method: "POST",
144
+ headers: {
145
+ "Content-Type": "application/json; charset=utf8",
146
+ Authorization: `Bearer ${token}`
147
+ },
148
+ body: JSON.stringify(payload)
149
+ });
150
+ if (!response.ok) {
151
+ throw new Error(`Cache purge API call returned an unexpected status code: ${response.status}`);
152
+ }
153
+ };
154
+ exports2.purgeCache = purgeCache2;
155
+ }
156
+ });
157
+
158
+ // node_modules/@netlify/functions/dist/lib/schedule.js
159
+ var require_schedule = __commonJS({
160
+ "node_modules/@netlify/functions/dist/lib/schedule.js"(exports2) {
161
+ "use strict";
162
+ Object.defineProperty(exports2, "__esModule", { value: true });
163
+ exports2.schedule = void 0;
164
+ var schedule = (cron, handler) => handler;
165
+ exports2.schedule = schedule;
166
+ }
167
+ });
168
+
169
+ // node_modules/@netlify/functions/dist/lib/stream.js
170
+ var require_stream = __commonJS({
171
+ "node_modules/@netlify/functions/dist/lib/stream.js"(exports2) {
172
+ "use strict";
173
+ Object.defineProperty(exports2, "__esModule", { value: true });
174
+ exports2.stream = void 0;
175
+ var node_stream_1 = require("node:stream");
176
+ var node_util_1 = require("node:util");
177
+ var pipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
178
+ var stream = (handler) => awslambda.streamifyResponse(async (event, responseStream, context) => {
179
+ const { body, ...httpResponseMetadata } = await handler(event, context);
180
+ const responseBody = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata);
181
+ if (typeof body === "undefined") {
182
+ responseBody.end();
183
+ } else if (typeof body === "string") {
184
+ responseBody.write(body);
185
+ responseBody.end();
186
+ } else {
187
+ await pipeline(body, responseBody);
188
+ }
189
+ });
190
+ exports2.stream = stream;
191
+ }
192
+ });
193
+
194
+ // node_modules/@netlify/functions/dist/function/index.js
195
+ var require_function = __commonJS({
196
+ "node_modules/@netlify/functions/dist/function/index.js"(exports2) {
197
+ "use strict";
198
+ Object.defineProperty(exports2, "__esModule", { value: true });
199
+ }
200
+ });
201
+
202
+ // node_modules/@netlify/functions/dist/main.js
203
+ var require_main = __commonJS({
204
+ "node_modules/@netlify/functions/dist/main.js"(exports2) {
205
+ "use strict";
206
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
207
+ if (k2 === void 0)
208
+ k2 = k;
209
+ var desc = Object.getOwnPropertyDescriptor(m, k);
210
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
211
+ desc = { enumerable: true, get: function() {
212
+ return m[k];
213
+ } };
214
+ }
215
+ Object.defineProperty(o, k2, desc);
216
+ } : function(o, m, k, k2) {
217
+ if (k2 === void 0)
218
+ k2 = k;
219
+ o[k2] = m[k];
220
+ });
221
+ var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
222
+ for (var p in m)
223
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p))
224
+ __createBinding(exports3, m, p);
225
+ };
226
+ Object.defineProperty(exports2, "__esModule", { value: true });
227
+ exports2.stream = exports2.schedule = exports2.purgeCache = exports2.builder = void 0;
228
+ var builder_js_1 = require_builder();
229
+ Object.defineProperty(exports2, "builder", { enumerable: true, get: function() {
230
+ return builder_js_1.builder;
231
+ } });
232
+ var purge_cache_js_1 = require_purge_cache();
233
+ Object.defineProperty(exports2, "purgeCache", { enumerable: true, get: function() {
234
+ return purge_cache_js_1.purgeCache;
235
+ } });
236
+ var schedule_js_1 = require_schedule();
237
+ Object.defineProperty(exports2, "schedule", { enumerable: true, get: function() {
238
+ return schedule_js_1.schedule;
239
+ } });
240
+ var stream_js_1 = require_stream();
241
+ Object.defineProperty(exports2, "stream", { enumerable: true, get: function() {
242
+ return stream_js_1.stream;
243
+ } });
244
+ __exportStar(require_function(), exports2);
245
+ }
246
+ });
247
+
248
+ // src/run/handlers/cache.cts
249
+ var cache_exports = {};
250
+ __export(cache_exports, {
251
+ NetlifyCacheHandler: () => NetlifyCacheHandler,
252
+ blobStore: () => blobStore,
253
+ default: () => cache_default
254
+ });
255
+ module.exports = __toCommonJS(cache_exports);
256
+ var import_node_buffer = require("node:buffer");
257
+ var import_node_fs = require("node:fs");
258
+ var import_posix = require("node:path/posix");
259
+
260
+ // node_modules/@netlify/blobs/dist/main.js
261
+ var import_buffer = require("buffer");
262
+ var import_process = require("process");
263
+ var import_buffer2 = require("buffer");
264
+ var import_buffer3 = require("buffer");
265
+ var getEnvironmentContext = () => {
266
+ const context = globalThis.netlifyBlobsContext || import_process.env.NETLIFY_BLOBS_CONTEXT;
267
+ if (typeof context !== "string" || !context) {
268
+ return {};
269
+ }
270
+ const data = import_buffer.Buffer.from(context, "base64").toString();
271
+ try {
272
+ return JSON.parse(data);
273
+ } catch {
274
+ }
275
+ return {};
276
+ };
277
+ var MissingBlobsEnvironmentError = class extends Error {
278
+ constructor(requiredProperties) {
279
+ super(
280
+ `The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: ${requiredProperties.join(
281
+ ", "
282
+ )}`
283
+ );
284
+ this.name = "MissingBlobsEnvironmentError";
285
+ }
286
+ };
287
+ var BASE64_PREFIX = "b64;";
288
+ var METADATA_HEADER_INTERNAL = "x-amz-meta-user";
289
+ var METADATA_HEADER_EXTERNAL = "netlify-blobs-metadata";
290
+ var METADATA_MAX_SIZE = 2 * 1024;
291
+ var encodeMetadata = (metadata) => {
292
+ if (!metadata) {
293
+ return null;
294
+ }
295
+ const encodedObject = import_buffer2.Buffer.from(JSON.stringify(metadata)).toString("base64");
296
+ const payload = `b64;${encodedObject}`;
297
+ if (METADATA_HEADER_EXTERNAL.length + payload.length > METADATA_MAX_SIZE) {
298
+ throw new Error("Metadata object exceeds the maximum size");
299
+ }
300
+ return payload;
301
+ };
302
+ var decodeMetadata = (header) => {
303
+ if (!header || !header.startsWith(BASE64_PREFIX)) {
304
+ return {};
305
+ }
306
+ const encodedData = header.slice(BASE64_PREFIX.length);
307
+ const decodedData = import_buffer2.Buffer.from(encodedData, "base64").toString();
308
+ const metadata = JSON.parse(decodedData);
309
+ return metadata;
310
+ };
311
+ var getMetadataFromResponse = (response) => {
312
+ if (!response.headers) {
313
+ return {};
314
+ }
315
+ const value = response.headers.get(METADATA_HEADER_EXTERNAL) || response.headers.get(METADATA_HEADER_INTERNAL);
316
+ try {
317
+ return decodeMetadata(value);
318
+ } catch {
319
+ throw new Error(
320
+ "An internal error occurred while trying to retrieve the metadata for an entry. Please try updating to the latest version of the Netlify Blobs client."
321
+ );
322
+ }
323
+ };
324
+ var DEFAULT_RETRY_DELAY = 5e3;
325
+ var MIN_RETRY_DELAY = 1e3;
326
+ var MAX_RETRY = 5;
327
+ var RATE_LIMIT_HEADER = "X-RateLimit-Reset";
328
+ var fetchAndRetry = async (fetch2, url, options, attemptsLeft = MAX_RETRY) => {
329
+ try {
330
+ const res = await fetch2(url, options);
331
+ if (attemptsLeft > 0 && (res.status === 429 || res.status >= 500)) {
332
+ const delay = getDelay(res.headers.get(RATE_LIMIT_HEADER));
333
+ await sleep(delay);
334
+ return fetchAndRetry(fetch2, url, options, attemptsLeft - 1);
335
+ }
336
+ return res;
337
+ } catch (error) {
338
+ if (attemptsLeft === 0) {
339
+ throw error;
340
+ }
341
+ const delay = getDelay();
342
+ await sleep(delay);
343
+ return fetchAndRetry(fetch2, url, options, attemptsLeft - 1);
344
+ }
345
+ };
346
+ var getDelay = (rateLimitReset) => {
347
+ if (!rateLimitReset) {
348
+ return DEFAULT_RETRY_DELAY;
349
+ }
350
+ return Math.max(Number(rateLimitReset) * 1e3 - Date.now(), MIN_RETRY_DELAY);
351
+ };
352
+ var sleep = (ms) => new Promise((resolve2) => {
353
+ setTimeout(resolve2, ms);
354
+ });
355
+ var Client = class {
356
+ constructor({ apiURL, edgeURL, fetch: fetch2, siteID, token }) {
357
+ this.apiURL = apiURL;
358
+ this.edgeURL = edgeURL;
359
+ this.fetch = fetch2 ?? globalThis.fetch;
360
+ this.siteID = siteID;
361
+ this.token = token;
362
+ if (!this.fetch) {
363
+ throw new Error(
364
+ "Netlify Blobs could not find a `fetch` client in the global scope. You can either update your runtime to a version that includes `fetch` (like Node.js 18.0.0 or above), or you can supply your own implementation using the `fetch` property."
365
+ );
366
+ }
367
+ }
368
+ async getFinalRequest({ key, metadata, method, parameters = {}, storeName }) {
369
+ const encodedMetadata = encodeMetadata(metadata);
370
+ if (this.edgeURL) {
371
+ const headers = {
372
+ authorization: `Bearer ${this.token}`
373
+ };
374
+ if (encodedMetadata) {
375
+ headers[METADATA_HEADER_INTERNAL] = encodedMetadata;
376
+ }
377
+ const path = key ? `/${this.siteID}/${storeName}/${key}` : `/${this.siteID}/${storeName}`;
378
+ const url2 = new URL(path, this.edgeURL);
379
+ for (const key2 in parameters) {
380
+ url2.searchParams.set(key2, parameters[key2]);
381
+ }
382
+ return {
383
+ headers,
384
+ url: url2.toString()
385
+ };
386
+ }
387
+ const apiHeaders = { authorization: `Bearer ${this.token}` };
388
+ const url = new URL(`/api/v1/sites/${this.siteID}/blobs`, this.apiURL ?? "https://api.netlify.com");
389
+ for (const key2 in parameters) {
390
+ url.searchParams.set(key2, parameters[key2]);
391
+ }
392
+ url.searchParams.set("context", storeName);
393
+ if (key === void 0) {
394
+ return {
395
+ headers: apiHeaders,
396
+ url: url.toString()
397
+ };
398
+ }
399
+ url.pathname += `/${key}`;
400
+ if (encodedMetadata) {
401
+ apiHeaders[METADATA_HEADER_EXTERNAL] = encodedMetadata;
402
+ }
403
+ if (method === "head") {
404
+ return {
405
+ headers: apiHeaders,
406
+ url: url.toString()
407
+ };
408
+ }
409
+ const res = await this.fetch(url.toString(), { headers: apiHeaders, method });
410
+ if (res.status !== 200) {
411
+ throw new Error(`Netlify Blobs has generated an internal error: ${res.status} response`);
412
+ }
413
+ const { url: signedURL } = await res.json();
414
+ const userHeaders = encodedMetadata ? { [METADATA_HEADER_INTERNAL]: encodedMetadata } : void 0;
415
+ return {
416
+ headers: userHeaders,
417
+ url: signedURL
418
+ };
419
+ }
420
+ async makeRequest({
421
+ body,
422
+ headers: extraHeaders,
423
+ key,
424
+ metadata,
425
+ method,
426
+ parameters,
427
+ storeName
428
+ }) {
429
+ const { headers: baseHeaders = {}, url } = await this.getFinalRequest({
430
+ key,
431
+ metadata,
432
+ method,
433
+ parameters,
434
+ storeName
435
+ });
436
+ const headers = {
437
+ ...baseHeaders,
438
+ ...extraHeaders
439
+ };
440
+ if (method === "put") {
441
+ headers["cache-control"] = "max-age=0, stale-while-revalidate=60";
442
+ }
443
+ const options = {
444
+ body,
445
+ headers,
446
+ method
447
+ };
448
+ if (body instanceof ReadableStream) {
449
+ options.duplex = "half";
450
+ }
451
+ return fetchAndRetry(this.fetch, url, options);
452
+ }
453
+ };
454
+ var getClientOptions = (options, contextOverride) => {
455
+ const context = contextOverride ?? getEnvironmentContext();
456
+ const siteID = context.siteID ?? options.siteID;
457
+ const token = context.token ?? options.token;
458
+ if (!siteID || !token) {
459
+ throw new MissingBlobsEnvironmentError(["siteID", "token"]);
460
+ }
461
+ const clientOptions = {
462
+ apiURL: context.apiURL ?? options.apiURL,
463
+ edgeURL: context.edgeURL ?? options.edgeURL,
464
+ fetch: options.fetch,
465
+ siteID,
466
+ token
467
+ };
468
+ return clientOptions;
469
+ };
470
+ var BlobsInternalError = class extends Error {
471
+ constructor(statusCode) {
472
+ super(`Netlify Blobs has generated an internal error: ${statusCode} response`);
473
+ this.name = "BlobsInternalError";
474
+ }
475
+ };
476
+ var collectIterator = async (iterator) => {
477
+ const result = [];
478
+ for await (const item of iterator) {
479
+ result.push(item);
480
+ }
481
+ return result;
482
+ };
483
+ var Store = class _Store {
484
+ constructor(options) {
485
+ this.client = options.client;
486
+ if ("deployID" in options) {
487
+ _Store.validateDeployID(options.deployID);
488
+ this.name = `deploy:${options.deployID}`;
489
+ } else {
490
+ _Store.validateStoreName(options.name);
491
+ this.name = options.name;
492
+ }
493
+ }
494
+ async delete(key) {
495
+ const res = await this.client.makeRequest({ key, method: "delete", storeName: this.name });
496
+ if (![200, 204, 404].includes(res.status)) {
497
+ throw new BlobsInternalError(res.status);
498
+ }
499
+ }
500
+ async get(key, options) {
501
+ const { type } = options ?? {};
502
+ const res = await this.client.makeRequest({ key, method: "get", storeName: this.name });
503
+ if (res.status === 404) {
504
+ return null;
505
+ }
506
+ if (res.status !== 200) {
507
+ throw new BlobsInternalError(res.status);
508
+ }
509
+ if (type === void 0 || type === "text") {
510
+ return res.text();
511
+ }
512
+ if (type === "arrayBuffer") {
513
+ return res.arrayBuffer();
514
+ }
515
+ if (type === "blob") {
516
+ return res.blob();
517
+ }
518
+ if (type === "json") {
519
+ return res.json();
520
+ }
521
+ if (type === "stream") {
522
+ return res.body;
523
+ }
524
+ throw new BlobsInternalError(res.status);
525
+ }
526
+ async getMetadata(key) {
527
+ const res = await this.client.makeRequest({ key, method: "head", storeName: this.name });
528
+ if (res.status === 404) {
529
+ return null;
530
+ }
531
+ if (res.status !== 200 && res.status !== 304) {
532
+ throw new BlobsInternalError(res.status);
533
+ }
534
+ const etag = res?.headers.get("etag") ?? void 0;
535
+ const metadata = getMetadataFromResponse(res);
536
+ const result = {
537
+ etag,
538
+ metadata
539
+ };
540
+ return result;
541
+ }
542
+ async getWithMetadata(key, options) {
543
+ const { etag: requestETag, type } = options ?? {};
544
+ const headers = requestETag ? { "if-none-match": requestETag } : void 0;
545
+ const res = await this.client.makeRequest({ headers, key, method: "get", storeName: this.name });
546
+ if (res.status === 404) {
547
+ return null;
548
+ }
549
+ if (res.status !== 200 && res.status !== 304) {
550
+ throw new BlobsInternalError(res.status);
551
+ }
552
+ const responseETag = res?.headers.get("etag") ?? void 0;
553
+ const metadata = getMetadataFromResponse(res);
554
+ const result = {
555
+ etag: responseETag,
556
+ metadata
557
+ };
558
+ if (res.status === 304 && requestETag) {
559
+ return { data: null, ...result };
560
+ }
561
+ if (type === void 0 || type === "text") {
562
+ return { data: await res.text(), ...result };
563
+ }
564
+ if (type === "arrayBuffer") {
565
+ return { data: await res.arrayBuffer(), ...result };
566
+ }
567
+ if (type === "blob") {
568
+ return { data: await res.blob(), ...result };
569
+ }
570
+ if (type === "json") {
571
+ return { data: await res.json(), ...result };
572
+ }
573
+ if (type === "stream") {
574
+ return { data: res.body, ...result };
575
+ }
576
+ throw new Error(`Invalid 'type' property: ${type}. Expected: arrayBuffer, blob, json, stream, or text.`);
577
+ }
578
+ list(options = {}) {
579
+ const iterator = this.getListIterator(options);
580
+ if (options.paginate) {
581
+ return iterator;
582
+ }
583
+ return collectIterator(iterator).then(
584
+ (items) => items.reduce(
585
+ (acc, item) => ({
586
+ blobs: [...acc.blobs, ...item.blobs],
587
+ directories: [...acc.directories, ...item.directories]
588
+ }),
589
+ { blobs: [], directories: [] }
590
+ )
591
+ );
592
+ }
593
+ async set(key, data, { metadata } = {}) {
594
+ _Store.validateKey(key);
595
+ const res = await this.client.makeRequest({
596
+ body: data,
597
+ key,
598
+ metadata,
599
+ method: "put",
600
+ storeName: this.name
601
+ });
602
+ if (res.status !== 200) {
603
+ throw new BlobsInternalError(res.status);
604
+ }
605
+ }
606
+ async setJSON(key, data, { metadata } = {}) {
607
+ _Store.validateKey(key);
608
+ const payload = JSON.stringify(data);
609
+ const headers = {
610
+ "content-type": "application/json"
611
+ };
612
+ const res = await this.client.makeRequest({
613
+ body: payload,
614
+ headers,
615
+ key,
616
+ metadata,
617
+ method: "put",
618
+ storeName: this.name
619
+ });
620
+ if (res.status !== 200) {
621
+ throw new BlobsInternalError(res.status);
622
+ }
623
+ }
624
+ static formatListResultBlob(result) {
625
+ if (!result.key) {
626
+ return null;
627
+ }
628
+ return {
629
+ etag: result.etag,
630
+ key: result.key
631
+ };
632
+ }
633
+ static validateKey(key) {
634
+ if (key.startsWith("/") || key.startsWith("%2F")) {
635
+ throw new Error("Blob key must not start with forward slash (/).");
636
+ }
637
+ if (import_buffer3.Buffer.byteLength(key, "utf8") > 600) {
638
+ throw new Error(
639
+ "Blob key must be a sequence of Unicode characters whose UTF-8 encoding is at most 600 bytes long."
640
+ );
641
+ }
642
+ }
643
+ static validateDeployID(deployID) {
644
+ if (!/^\w{1,24}$/.test(deployID)) {
645
+ throw new Error(`'${deployID}' is not a valid Netlify deploy ID.`);
646
+ }
647
+ }
648
+ static validateStoreName(name) {
649
+ if (name.startsWith("deploy:") || name.startsWith("deploy%3A1")) {
650
+ throw new Error("Store name must not start with the `deploy:` reserved keyword.");
651
+ }
652
+ if (name.includes("/") || name.includes("%2F")) {
653
+ throw new Error("Store name must not contain forward slashes (/).");
654
+ }
655
+ if (import_buffer3.Buffer.byteLength(name, "utf8") > 64) {
656
+ throw new Error(
657
+ "Store name must be a sequence of Unicode characters whose UTF-8 encoding is at most 64 bytes long."
658
+ );
659
+ }
660
+ }
661
+ getListIterator(options) {
662
+ const { client, name: storeName } = this;
663
+ const parameters = {};
664
+ if (options?.prefix) {
665
+ parameters.prefix = options.prefix;
666
+ }
667
+ if (options?.directories) {
668
+ parameters.directories = "true";
669
+ }
670
+ return {
671
+ [Symbol.asyncIterator]() {
672
+ let currentCursor = null;
673
+ let done = false;
674
+ return {
675
+ async next() {
676
+ if (done) {
677
+ return { done: true, value: void 0 };
678
+ }
679
+ const nextParameters = { ...parameters };
680
+ if (currentCursor !== null) {
681
+ nextParameters.cursor = currentCursor;
682
+ }
683
+ const res = await client.makeRequest({
684
+ method: "get",
685
+ parameters: nextParameters,
686
+ storeName
687
+ });
688
+ const page = await res.json();
689
+ if (page.next_cursor) {
690
+ currentCursor = page.next_cursor;
691
+ } else {
692
+ done = true;
693
+ }
694
+ const blobs = (page.blobs ?? []).map(_Store.formatListResultBlob).filter(Boolean);
695
+ return {
696
+ done: false,
697
+ value: {
698
+ blobs,
699
+ directories: page.directories ?? []
700
+ }
701
+ };
702
+ }
703
+ };
704
+ }
705
+ };
706
+ }
707
+ };
708
+ var getDeployStore = (options = {}) => {
709
+ const context = getEnvironmentContext();
710
+ const deployID = options.deployID ?? context.deployID;
711
+ if (!deployID) {
712
+ throw new MissingBlobsEnvironmentError(["deployID"]);
713
+ }
714
+ const clientOptions = getClientOptions(options, context);
715
+ const client = new Client(clientOptions);
716
+ return new Store({ client, deployID });
717
+ };
718
+
719
+ // src/run/handlers/cache.cts
720
+ var import_functions = __toESM(require_main());
721
+ var import_constants = require("next/dist/lib/constants.js");
722
+ var blobStore = getDeployStore();
723
+ var prerenderManifest = JSON.parse(
724
+ (0, import_node_fs.readFileSync)((0, import_posix.join)(process.cwd(), ".next/prerender-manifest.json"), "utf-8")
725
+ );
726
+ function toRoute(cacheKey) {
727
+ return cacheKey.replace(/\/$/, "").replace(/\/index$/, "") || "/";
728
+ }
729
+ function encodeBlobKey(key) {
730
+ return import_node_buffer.Buffer.from(key.replace(/^\//, "")).toString("base64");
731
+ }
732
+ var NetlifyCacheHandler = class {
733
+ options;
734
+ revalidatedTags;
735
+ constructor(options) {
736
+ this.options = options;
737
+ this.revalidatedTags = options.revalidatedTags;
738
+ }
739
+ async get(...args) {
740
+ const [key, ctx = {}] = args;
741
+ console.debug(`[NetlifyCacheHandler.get]: ${key}`);
742
+ const blob = await blobStore.get(encodeBlobKey(key), {
743
+ type: "json"
744
+ });
745
+ if (!blob) {
746
+ return null;
747
+ }
748
+ const revalidateAfter = this.calculateRevalidate(key, blob.lastModified, ctx);
749
+ const isStale = revalidateAfter !== false && revalidateAfter < Date.now();
750
+ const staleByTags = await this.checkCacheEntryStaleByTags(blob, ctx.softTags);
751
+ if (staleByTags || isStale) {
752
+ return null;
753
+ }
754
+ switch (blob.value.kind) {
755
+ case "FETCH":
756
+ return {
757
+ lastModified: blob.lastModified,
758
+ value: {
759
+ kind: blob.value.kind,
760
+ data: blob.value.data,
761
+ revalidate: ctx.revalidate || 1
762
+ }
763
+ };
764
+ case "ROUTE":
765
+ return {
766
+ lastModified: blob.lastModified,
767
+ value: {
768
+ body: import_node_buffer.Buffer.from(blob.value.body),
769
+ kind: blob.value.kind,
770
+ status: blob.value.status,
771
+ headers: blob.value.headers
772
+ }
773
+ };
774
+ case "PAGE":
775
+ return {
776
+ lastModified: blob.lastModified,
777
+ value: blob.value
778
+ };
779
+ default:
780
+ }
781
+ return null;
782
+ }
783
+ async set(...args) {
784
+ const [key, data] = args;
785
+ console.debug(`[NetlifyCacheHandler.set]: ${key}`);
786
+ await blobStore.setJSON(encodeBlobKey(key), {
787
+ lastModified: Date.now(),
788
+ value: data
789
+ });
790
+ }
791
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
792
+ async revalidateTag(tag, ...args) {
793
+ console.debug("NetlifyCacheHandler.revalidateTag", tag, args);
794
+ const data = {
795
+ revalidatedAt: Date.now()
796
+ };
797
+ try {
798
+ await blobStore.setJSON(encodeBlobKey(tag), data);
799
+ } catch (error) {
800
+ console.warn(`Failed to update tag manifest for ${tag}`, error);
801
+ }
802
+ (0, import_functions.purgeCache)({ tags: [tag] }).catch((error) => {
803
+ console.error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`, error);
804
+ });
805
+ }
806
+ /**
807
+ * Checks if a page is stale through on demand revalidated tags
808
+ */
809
+ async checkCacheEntryStaleByTags(cacheEntry, softTags = []) {
810
+ const tags = "headers" in cacheEntry.value ? cacheEntry.value.headers?.[import_constants.NEXT_CACHE_TAGS_HEADER]?.split(",") || [] : [];
811
+ const cacheTags = [...tags, ...softTags];
812
+ const allManifests = await Promise.all(
813
+ cacheTags.map(async (tag) => {
814
+ const res = await blobStore.get(encodeBlobKey(tag), { type: "json" }).then((value) => ({ [tag]: value })).catch(console.error);
815
+ return res || { [tag]: null };
816
+ })
817
+ );
818
+ const tagsManifest = Object.assign({}, ...allManifests);
819
+ const isStale = cacheTags.some((tag) => {
820
+ if (this.revalidatedTags?.includes(tag)) {
821
+ return true;
822
+ }
823
+ const { revalidatedAt } = tagsManifest[tag] || {};
824
+ return revalidatedAt && revalidatedAt >= (cacheEntry.lastModified || Date.now());
825
+ });
826
+ return isStale;
827
+ }
828
+ /**
829
+ * Retrieves the milliseconds since midnight, January 1, 1970 when it should revalidate for a path.
830
+ */
831
+ calculateRevalidate(cacheKey, fromTime, ctx, dev) {
832
+ if (dev)
833
+ return Date.now() - 1e3;
834
+ if (ctx?.revalidate && typeof ctx.revalidate === "number") {
835
+ return fromTime + ctx.revalidate * 1e3;
836
+ }
837
+ const { initialRevalidateSeconds } = prerenderManifest.routes[toRoute(cacheKey)] || {
838
+ initialRevalidateSeconds: 0
839
+ };
840
+ const revalidateAfter = typeof initialRevalidateSeconds === "number" ? initialRevalidateSeconds * 1e3 + fromTime : initialRevalidateSeconds;
841
+ return revalidateAfter;
842
+ }
843
+ };
844
+ var cache_default = NetlifyCacheHandler;
845
+ // Annotate the CommonJS export names for ESM import in node:
846
+ 0 && (module.exports = {
847
+ NetlifyCacheHandler,
848
+ blobStore
849
+ });