eddev 2.0.0-beta.1 → 2.0.0-beta.100

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 (277) hide show
  1. package/dist/app/entry/HydrationOverlay.d.ts +1 -0
  2. package/dist/app/entry/HydrationOverlay.js +2 -0
  3. package/dist/app/entry/MetaTags.d.ts +7 -0
  4. package/dist/app/entry/MetaTags.js +17 -0
  5. package/dist/app/entry/boot-admin.d.ts +1 -0
  6. package/dist/app/entry/boot-admin.js +13 -0
  7. package/dist/app/entry/hydration-script.d.ts +1 -0
  8. package/dist/app/entry/hydration-script.js +18 -0
  9. package/dist/app/entry/spa-root.d.ts +1 -0
  10. package/dist/app/entry/spa-root.js +8 -0
  11. package/dist/app/entry/ssr-root-client.d.ts +6 -0
  12. package/dist/app/entry/ssr-root-client.js +20 -0
  13. package/dist/app/entry/ssr-root.d.ts +8 -0
  14. package/dist/app/entry/ssr-root.js +22 -0
  15. package/dist/app/lib/admin/index.d.ts +2 -2
  16. package/dist/app/lib/admin/index.js +2 -2
  17. package/dist/app/lib/admin/installFieldTypes.js +1 -1
  18. package/dist/app/lib/admin/runWidgets.js +1 -1
  19. package/dist/app/lib/blocks/ContentBlocks.d.ts +1 -1
  20. package/dist/app/lib/blocks/ContentBlocks.js +5 -5
  21. package/dist/app/lib/blocks/EditableText.d.ts +1 -1
  22. package/dist/app/lib/blocks/EditableText.js +3 -3
  23. package/dist/app/lib/blocks/InnerBlocks.d.ts +13 -3
  24. package/dist/app/lib/blocks/InnerBlocks.js +13 -5
  25. package/dist/app/lib/blocks/block-utils.d.ts +2 -2
  26. package/dist/app/lib/blocks/block-utils.js +2 -2
  27. package/dist/app/lib/blocks/editor/EditorHighlights.d.ts +7 -0
  28. package/dist/app/lib/blocks/editor/EditorHighlights.js +130 -0
  29. package/dist/app/lib/blocks/editor/EditorSupport.js +4 -5
  30. package/dist/app/lib/blocks/editor/editor-config.d.ts +17 -4
  31. package/dist/app/lib/blocks/editor/editor-config.js +21 -9
  32. package/dist/app/lib/blocks/editor/installGutenbergHooks.js +20 -14
  33. package/dist/app/lib/blocks/editor/root-blocks.d.ts +6 -0
  34. package/dist/app/lib/blocks/editor/root-blocks.js +30 -0
  35. package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
  36. package/dist/app/lib/blocks/index.d.ts +9 -9
  37. package/dist/app/lib/blocks/index.js +9 -9
  38. package/dist/app/lib/blocks/inline-editing.d.ts +1 -1
  39. package/dist/app/lib/blocks/inline-editing.js +7 -5
  40. package/dist/app/lib/devtools/components/BreakpointIndicator.js +6 -4
  41. package/dist/app/lib/devtools/components/DevUI.js +4 -3
  42. package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
  43. package/dist/app/lib/devtools/components/GridIndicator.js +29 -0
  44. package/dist/app/lib/devtools/dev-tools-store.d.ts +9 -0
  45. package/dist/app/lib/devtools/dev-tools-store.js +8 -0
  46. package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
  47. package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
  48. package/dist/app/lib/devtools/hooks/useTailwind.d.ts +1102 -1103
  49. package/dist/app/lib/devtools/hooks/useTailwind.js +6 -3
  50. package/dist/app/lib/devtools/index.d.ts +1 -0
  51. package/dist/app/lib/devtools/index.js +1 -1
  52. package/dist/app/lib/devtools/loader.js +8 -7
  53. package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
  54. package/dist/app/lib/devtools/useQueryDebug.js +5 -8
  55. package/dist/app/lib/dynamic/dynamic.d.ts +1 -1
  56. package/dist/app/lib/dynamic/dynamic.js +5 -1
  57. package/dist/app/lib/dynamic/index.d.ts +1 -1
  58. package/dist/app/lib/dynamic/index.js +1 -1
  59. package/dist/app/lib/hooks/index.d.ts +4 -5
  60. package/dist/app/lib/hooks/index.js +4 -5
  61. package/dist/app/lib/hooks/queryUtils.d.ts +41 -4
  62. package/dist/app/lib/hooks/queryUtils.js +74 -37
  63. package/dist/app/lib/hooks/useAppData.js +1 -1
  64. package/dist/app/lib/hooks/useRPC.d.ts +0 -4
  65. package/dist/app/lib/hooks/useRPC.js +1 -8
  66. package/dist/app/lib/internal/finalize-rpc.d.ts +17 -0
  67. package/dist/app/lib/internal/finalize-rpc.js +3 -0
  68. package/dist/app/lib/internal/index.d.ts +5 -4
  69. package/dist/app/lib/internal/index.js +5 -4
  70. package/dist/app/lib/internal/internal-store.d.ts +0 -2
  71. package/dist/app/lib/internal/internal-store.js +1 -3
  72. package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
  73. package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
  74. package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
  75. package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
  76. package/dist/app/lib/legacy-stitches/index.js +1 -1
  77. package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
  78. package/dist/app/lib/routing/components/BackButton.js +47 -0
  79. package/dist/app/lib/routing/components/BrowserRouter.d.ts +4 -1
  80. package/dist/app/lib/routing/components/BrowserRouter.js +95 -19
  81. package/dist/app/lib/routing/components/ClientOnly.js +1 -1
  82. package/dist/app/lib/routing/components/Link.d.ts +1 -0
  83. package/dist/app/lib/routing/components/Link.js +11 -12
  84. package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
  85. package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
  86. package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
  87. package/dist/app/lib/routing/components/SSRRouter.js +5 -6
  88. package/dist/app/lib/routing/components/ScrollRestoration.js +5 -2
  89. package/dist/app/lib/routing/context.d.ts +8 -5
  90. package/dist/app/lib/routing/context.js +13 -96
  91. package/dist/app/lib/routing/hooks/useRestorableState.d.ts +2 -1
  92. package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
  93. package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
  94. package/dist/app/lib/routing/hooks/useRoute.js +22 -1
  95. package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
  96. package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
  97. package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
  98. package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
  99. package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
  100. package/dist/app/lib/routing/hooks/useRouter.js +1 -1
  101. package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
  102. package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
  103. package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
  104. package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
  105. package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
  106. package/dist/app/lib/routing/index.d.ts +14 -13
  107. package/dist/app/lib/routing/index.js +14 -13
  108. package/dist/app/lib/routing/loader.d.ts +2 -2
  109. package/dist/app/lib/routing/loader.js +26 -15
  110. package/dist/app/lib/routing/types.d.ts +36 -10
  111. package/dist/app/lib/routing/utils.d.ts +5 -2
  112. package/dist/app/lib/routing/utils.js +37 -4
  113. package/dist/app/lib/{hooks → runtime}/apiConfig.d.ts +6 -2
  114. package/dist/app/lib/runtime/apiConfig.js +6 -0
  115. package/dist/app/lib/runtime/errorHandling.d.ts +39 -0
  116. package/dist/app/lib/runtime/errorHandling.js +6 -0
  117. package/dist/app/lib/runtime/index.d.ts +2 -0
  118. package/dist/app/lib/runtime/index.js +2 -0
  119. package/dist/app/lib/views/index.d.ts +1 -1
  120. package/dist/app/lib/views/index.js +1 -1
  121. package/dist/app/server/defineRouter.d.ts +2 -0
  122. package/dist/app/server/defineRouter.js +4 -0
  123. package/dist/app/server/index.d.ts +5 -0
  124. package/dist/app/server/index.js +5 -0
  125. package/dist/app/server/proxy-wp-admin.d.ts +2 -0
  126. package/dist/app/server/proxy-wp-admin.js +124 -0
  127. package/dist/app/server/render-ssr-page.d.ts +21 -0
  128. package/dist/app/server/render-ssr-page.js +166 -0
  129. package/dist/app/server/rpc.d.ts +56 -0
  130. package/dist/app/server/rpc.js +18 -0
  131. package/dist/app/server/server-context.d.ts +72 -0
  132. package/dist/app/server/server-context.js +283 -0
  133. package/dist/app/server/utils/headers.d.ts +1 -0
  134. package/dist/app/server/utils/headers.js +17 -0
  135. package/dist/app/server/utils/replace-host.d.ts +6 -4
  136. package/dist/app/server/utils/replace-host.js +66 -11
  137. package/dist/app/server/utils/swr-cache.d.ts +4 -0
  138. package/dist/app/server/utils/swr-cache.js +31 -0
  139. package/dist/app/utils/APIProvider.d.ts +2 -0
  140. package/dist/app/utils/APIProvider.js +5 -0
  141. package/dist/app/utils/BlockErrorBoundary.d.ts +19 -0
  142. package/dist/app/utils/BlockErrorBoundary.js +38 -0
  143. package/dist/app/utils/ErrorMessage.d.ts +5 -0
  144. package/dist/app/utils/ErrorMessage.js +14 -0
  145. package/dist/app/utils/RouteErrorBoundary.d.ts +18 -0
  146. package/dist/app/utils/RouteErrorBoundary.js +38 -0
  147. package/dist/app/utils/asset-capture.d.ts +2 -0
  148. package/dist/app/utils/asset-capture.js +5 -0
  149. package/dist/app/utils/hydration-debugger.d.ts +13 -0
  150. package/dist/app/utils/hydration-debugger.js +11 -0
  151. package/dist/app/utils/query-client.d.ts +2 -0
  152. package/dist/app/utils/query-client.js +5 -1
  153. package/dist/app/utils/trpc-client.d.ts +2 -0
  154. package/dist/app/utils/trpc-client.js +39 -0
  155. package/dist/node/cli/cli-worker.d.ts +1 -1
  156. package/dist/node/cli/cli-worker.js +11 -3
  157. package/dist/node/cli/cli.js +112 -13
  158. package/dist/node/cli/display/CLIApp.d.ts +1 -1
  159. package/dist/node/cli/display/CLIApp.js +4 -7
  160. package/dist/node/cli/display/boot-cli-app.js +1 -1
  161. package/dist/node/cli/display/components/LogEntries.d.ts +1 -1
  162. package/dist/node/cli/display/hooks/useStatefulLog.d.ts +1 -1
  163. package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
  164. package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
  165. package/dist/node/cli/display/tools/cli-tools.js +9 -9
  166. package/dist/node/cli/display/util/colors.d.ts +2 -2
  167. package/dist/node/cli/version.d.ts +1 -1
  168. package/dist/node/cli/version.js +1 -1
  169. package/dist/node/compiler/build-vinxi.d.ts +8 -0
  170. package/dist/node/compiler/build-vinxi.js +38 -0
  171. package/dist/node/compiler/bundler.admin.d.ts +2 -2
  172. package/dist/node/compiler/bundler.admin.js +4 -4
  173. package/dist/node/compiler/bundler.frontend.d.ts +1 -1
  174. package/dist/node/compiler/bundler.frontend.js +4 -4
  175. package/dist/node/compiler/{serverless.dev.d.ts → dev-server.d.ts} +7 -5
  176. package/dist/node/compiler/dev-server.js +107 -0
  177. package/dist/node/compiler/get-vite-config.d.ts +20 -0
  178. package/dist/node/compiler/get-vite-config.js +207 -0
  179. package/dist/node/compiler/vinxi-app.d.ts +22 -0
  180. package/dist/node/compiler/vinxi-app.js +228 -0
  181. package/dist/node/compiler/vinxi-codegen.d.ts +12 -0
  182. package/dist/node/compiler/vinxi-codegen.js +638 -0
  183. package/dist/node/graphql/graphql-codegen.d.ts +12 -2
  184. package/dist/node/graphql/graphql-codegen.js +213 -36
  185. package/dist/node/graphql/graphql-schema-loader.d.ts +2 -1
  186. package/dist/node/graphql/graphql-schema-loader.js +5 -19
  187. package/dist/node/graphql/plugins/gql-plugin-queries.js +1 -1
  188. package/dist/node/graphql/query-files-loader.d.ts +3 -0
  189. package/dist/node/graphql/query-files-loader.js +5 -0
  190. package/dist/node/project/config.d.ts +159 -73
  191. package/dist/node/project/config.js +70 -21
  192. package/dist/node/project/env.d.ts +5 -1
  193. package/dist/node/project/env.js +2 -1
  194. package/dist/node/project/manifest/block-manifest.js +3 -2
  195. package/dist/node/project/manifest/manifest.d.ts +2 -1
  196. package/dist/node/project/manifest/manifest.js +15 -11
  197. package/dist/node/project/manifest/routes-manifest.d.ts +20 -0
  198. package/dist/node/project/manifest/routes-manifest.js +74 -0
  199. package/dist/node/project/manifest/view-manifest.js +2 -2
  200. package/dist/node/project/project.d.ts +11 -2
  201. package/dist/node/project/project.js +49 -20
  202. package/dist/node/project/wp-info.d.ts +1 -0
  203. package/dist/node/project/wp-info.js +13 -3
  204. package/dist/node/types/block-type.d.ts +25 -20
  205. package/dist/node/types/block-type.js +1 -0
  206. package/dist/node/types/view-type.d.ts +7 -7
  207. package/dist/node/types/view-type.js +3 -4
  208. package/dist/node/utils/fetch-wp.d.ts +1 -0
  209. package/dist/node/utils/fetch-wp.js +27 -0
  210. package/dist/node/utils/fs-codegen.d.ts +42 -0
  211. package/dist/node/utils/fs-codegen.js +98 -0
  212. package/dist/node/utils/fs.js +2 -0
  213. package/dist/node/utils/{isDeploying.js → is-deploying.js} +1 -1
  214. package/dist/node/utils/{selfSignedCert.js → self-signed-cert.js} +1 -1
  215. package/dist/node/utils/{statefulLog.js → stateful-log.js} +3 -1
  216. package/dist/node/utils/watch-file-tree.d.ts +25 -0
  217. package/dist/node/utils/{watchFileTree.js → watch-file-tree.js} +12 -5
  218. package/package.json +40 -38
  219. package/types.app.d.ts +4 -2
  220. package/types.app.internal.d.ts +2 -2
  221. package/types.node.d.ts +3 -3
  222. package/dist/app/entry/Root.d.ts +0 -1
  223. package/dist/app/entry/Root.js +0 -9
  224. package/dist/app/entry/main.admin.d.ts +0 -3
  225. package/dist/app/entry/main.admin.js +0 -10
  226. package/dist/app/entry/main.frontend.spa.d.ts +0 -3
  227. package/dist/app/entry/main.frontend.spa.js +0 -13
  228. package/dist/app/entry/main.frontend.ssr.d.ts +0 -21
  229. package/dist/app/entry/main.frontend.ssr.js +0 -79
  230. package/dist/app/entry/main.serverless.dev.d.ts +0 -4
  231. package/dist/app/entry/main.serverless.dev.js +0 -21
  232. package/dist/app/lib/blocks/ErrorBoundaryFrontend.d.ts +0 -15
  233. package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +0 -35
  234. package/dist/app/lib/hooks/apiConfig.js +0 -4
  235. package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
  236. package/dist/app/lib/hooks/usePageLoad.js +0 -5
  237. package/dist/app/server/create-api-builtin-hono.d.ts +0 -8
  238. package/dist/app/server/create-api-builtin-hono.js +0 -80
  239. package/dist/app/server/create-ssr-hono.d.ts +0 -18
  240. package/dist/app/server/create-ssr-hono.js +0 -104
  241. package/dist/app/server/utils/index.html.d.ts +0 -2
  242. package/dist/app/server/utils/index.html.js +0 -14
  243. package/dist/node/compiler/index.html.d.ts +0 -2
  244. package/dist/node/compiler/index.html.js +0 -15
  245. package/dist/node/compiler/serverless.dev.js +0 -215
  246. package/dist/node/compiler/vite/get-vite-config.d.ts +0 -13
  247. package/dist/node/compiler/vite/get-vite-config.js +0 -315
  248. package/dist/node/compiler/vite/plugin-admin.d.ts +0 -4
  249. package/dist/node/compiler/vite/plugin-admin.js +0 -67
  250. package/dist/node/compiler/vite/plugin-blocks.d.ts +0 -4
  251. package/dist/node/compiler/vite/plugin-blocks.js +0 -73
  252. package/dist/node/compiler/vite/plugin-entry.d.ts +0 -6
  253. package/dist/node/compiler/vite/plugin-entry.js +0 -16
  254. package/dist/node/compiler/vite/plugin-resolved-tailwind.d.ts +0 -4
  255. package/dist/node/compiler/vite/plugin-resolved-tailwind.js +0 -29
  256. package/dist/node/compiler/vite/plugin-theme.d.ts +0 -4
  257. package/dist/node/compiler/vite/plugin-theme.js +0 -40
  258. package/dist/node/compiler/vite/plugin-views.d.ts +0 -4
  259. package/dist/node/compiler/vite/plugin-views.js +0 -51
  260. package/dist/node/utils/console.d.ts +0 -21
  261. package/dist/node/utils/console.js +0 -28
  262. package/dist/node/utils/unsafe-fetch.d.ts +0 -2
  263. package/dist/node/utils/unsafe-fetch.js +0 -19
  264. package/dist/node/utils/watchFileTree.d.ts +0 -11
  265. package/tsup.config.ts +0 -40
  266. package/types.manifests.d.ts +0 -22
  267. /package/dist/node/utils/{formatZodError.d.ts → format-zod-error.d.ts} +0 -0
  268. /package/dist/node/utils/{formatZodError.js → format-zod-error.js} +0 -0
  269. /package/dist/node/utils/{getRepoInfo.d.ts → get-repo-info.d.ts} +0 -0
  270. /package/dist/node/utils/{getRepoInfo.js → get-repo-info.js} +0 -0
  271. /package/dist/node/utils/{highlightCode.d.ts → highlight-code.d.ts} +0 -0
  272. /package/dist/node/utils/{highlightCode.js → highlight-code.js} +0 -0
  273. /package/dist/node/utils/{isDeploying.d.ts → is-deploying.d.ts} +0 -0
  274. /package/dist/node/utils/{selfSignedCert.d.ts → self-signed-cert.d.ts} +0 -0
  275. /package/dist/node/utils/{statefulLog.d.ts → stateful-log.d.ts} +0 -0
  276. /package/dist/node/utils/{export-extractor.d.ts → ts-export-extractor.d.ts} +0 -0
  277. /package/dist/node/utils/{export-extractor.js → ts-export-extractor.js} +0 -0
@@ -0,0 +1,283 @@
1
+ import { parseURL, stringifyParsedURL, withQuery, withTrailingSlash } from "ufo";
2
+ import { fetchWP } from "../../node/utils/fetch-wp.js";
3
+ import { filterHeader } from "./utils/headers.js";
4
+ import { createUrlReplacer } from "./utils/replace-host.js";
5
+ import { pageCache, queryCache, swr } from "./utils/swr-cache.js";
6
+ const PROXY_RESPONSE_HEADERS = ["content-type", "set-cookie", /^x-/, "cache-control", /woocommerce/, "location"];
7
+ const PROXY_REQUEST_HEADERS = [
8
+ "content-type",
9
+ "accept",
10
+ "accept-encoding",
11
+ "accept-language",
12
+ "origin",
13
+ "referer",
14
+ "user-agent",
15
+ "authorization",
16
+ "woocommerce-session",
17
+ ];
18
+ const VARIES_HEADERS = ["Authorization", "woocommerce-session"];
19
+ let runtime;
20
+ export class ServerContext {
21
+ dev;
22
+ origin;
23
+ _urlReplacer;
24
+ rpcBases = [];
25
+ config;
26
+ static main;
27
+ constructor(conf) {
28
+ this.dev = conf.dev;
29
+ this.origin = conf.origin;
30
+ this.rpcBases = conf.rpcBases ?? [];
31
+ this.config = conf.config;
32
+ if (conf.replaceUrls) {
33
+ this._urlReplacer = createUrlReplacer(conf.replaceUrls);
34
+ }
35
+ ServerContext.main = this;
36
+ }
37
+ replaceUrls(text, origin) {
38
+ if (this._urlReplacer) {
39
+ return this._urlReplacer(text, origin);
40
+ }
41
+ return text;
42
+ }
43
+ get runtime() {
44
+ return runtime;
45
+ }
46
+ static setRuntime(rt) {
47
+ runtime = rt;
48
+ }
49
+ getOriginUrl(url) {
50
+ const parsed = parseURL(url);
51
+ const parsedOrigin = parseURL(this.origin);
52
+ parsed.host = parsedOrigin.host;
53
+ parsed.protocol = parsedOrigin.protocol;
54
+ return stringifyParsedURL(parsed);
55
+ }
56
+ async fetchOrigin(url, opts) {
57
+ url = this.getOriginUrl(url);
58
+ const response = await fetchWP(url, {
59
+ ...opts,
60
+ headers: {
61
+ "Content-Type": "application/json",
62
+ Accept: "application/json",
63
+ ...opts?.headers,
64
+ },
65
+ });
66
+ if (!response.ok) {
67
+ return response;
68
+ }
69
+ const headers = {};
70
+ response.headers.forEach((value, key) => {
71
+ if (filterHeader(key, PROXY_RESPONSE_HEADERS)) {
72
+ headers[key] = value;
73
+ }
74
+ });
75
+ let text = await response.text();
76
+ if (opts?.replaceUrls) {
77
+ text = this.replaceUrls(text, opts.newOrigin);
78
+ }
79
+ return new Response(text, {
80
+ status: response.status,
81
+ statusText: response.statusText,
82
+ headers,
83
+ });
84
+ }
85
+ async fetchRouteData(req) {
86
+ /**
87
+ * Calculcate the cache key.
88
+ * For route data, the cache key is the pathname.
89
+ * TODO: Potential support for Vercel draft mode.
90
+ */
91
+ let cacheKey = "fetchRouteData:" + req.pathname;
92
+ const result = await swr({
93
+ key: cacheKey,
94
+ cache: pageCache,
95
+ forceFresh: this.dev,
96
+ getFreshValue: async (ctx) => {
97
+ ctx.metadata.createdTime;
98
+ const fetchUrl = withQuery(withTrailingSlash(req.pathname), {
99
+ _props: "1",
100
+ _ssr: "1",
101
+ _debug: this.dev ? "1" : undefined,
102
+ });
103
+ const result = await this.fetchOrigin(fetchUrl, {
104
+ cache: "no-cache",
105
+ replaceUrls: true,
106
+ newOrigin: req.newOrigin,
107
+ headers: {
108
+ "Content-Type": "application/json",
109
+ Accept: "application/json",
110
+ },
111
+ redirect: "manual",
112
+ });
113
+ const preferredCacheDuration = parseInt(result.headers.get("x-ed-cache-duration") ?? "");
114
+ if (isFinite(preferredCacheDuration)) {
115
+ ctx.metadata.ttl = preferredCacheDuration * 1000;
116
+ }
117
+ let resultStatus = result.status;
118
+ let resultHeaders = new Headers(result.headers);
119
+ let resultData = {};
120
+ // Special case for redirects
121
+ if (result.headers.get("location")) {
122
+ let location = result.headers.get("location");
123
+ let status = result.status;
124
+ if (this.replaceUrls) {
125
+ location = this.replaceUrls(location);
126
+ }
127
+ resultHeaders.delete("location");
128
+ return {
129
+ status: 200,
130
+ headers: resultHeaders,
131
+ data: JSON.stringify({ redirect: location, status: status }),
132
+ };
133
+ }
134
+ resultData = await result.json();
135
+ if (resultData && typeof resultData === "object") {
136
+ resultData.__generated = new Date().toISOString();
137
+ }
138
+ return {
139
+ status: resultStatus,
140
+ headers: resultHeaders,
141
+ data: JSON.stringify(resultData),
142
+ };
143
+ },
144
+ });
145
+ return new Response(result.data, {
146
+ status: result.status,
147
+ headers: result.headers,
148
+ });
149
+ }
150
+ async fetchAppData() {
151
+ const data = await swr({
152
+ key: "fetchAppData",
153
+ cache: pageCache,
154
+ getFreshValue: async (ctx) => {
155
+ const response = await this.fetchOrigin("/_appdata", {
156
+ cache: "no-cache",
157
+ replaceUrls: true,
158
+ headers: {
159
+ "Content-Type": "application/json",
160
+ Accept: "application/json",
161
+ },
162
+ });
163
+ const result = await response.json();
164
+ const preferredCacheDuration = parseInt(response.headers.get("x-ed-cache-duration") ?? "");
165
+ if (isFinite(preferredCacheDuration)) {
166
+ ctx.metadata.ttl = preferredCacheDuration * 1000;
167
+ }
168
+ result.__generated = new Date().toISOString();
169
+ return result;
170
+ },
171
+ forceFresh: this.dev,
172
+ });
173
+ return data;
174
+ }
175
+ extractRequestHeaders(req) {
176
+ const headers = {};
177
+ if (req) {
178
+ for (let key of PROXY_REQUEST_HEADERS) {
179
+ if (req[key]) {
180
+ headers[key] = req[key];
181
+ }
182
+ }
183
+ }
184
+ return headers;
185
+ }
186
+ async fetchNamedQuery(req) {
187
+ const url = `/wp-json/ed/v1/query/${req.name}?params=${encodeURIComponent(JSON.stringify(req.params))}`;
188
+ const key = `fetchNamedQuery:${req.name}:${JSON.stringify(req.params)}`;
189
+ const fetch = async () => {
190
+ const result = await this.fetchOrigin(url, {
191
+ cache: "no-cache",
192
+ replaceUrls: true,
193
+ headers: {
194
+ ...this.extractRequestHeaders(req.headers),
195
+ "Content-Type": "application/json",
196
+ Accept: "application/json",
197
+ },
198
+ });
199
+ const preferredCacheDuration = parseInt(result.headers.get("x-ed-cache-duration") ?? "");
200
+ let resultStatus = result.status;
201
+ let resultHeaders = result.headers;
202
+ let resultData = await result.json();
203
+ if (resultData && typeof resultData === "object") {
204
+ resultData.__generated = new Date().toISOString();
205
+ }
206
+ return {
207
+ status: resultStatus,
208
+ headers: resultHeaders,
209
+ data: JSON.stringify(resultData),
210
+ cacheTime: isFinite(preferredCacheDuration) ? preferredCacheDuration * 1000 : undefined,
211
+ };
212
+ };
213
+ // If headers like 'Authorization' are set, then we shouldn't cache.
214
+ const hasVariedHeaders = VARIES_HEADERS.some((key) => !!req.headers[key]);
215
+ // Get the result, either from cache or by fetching.
216
+ const result = hasVariedHeaders
217
+ ? await fetch()
218
+ : await swr({
219
+ key,
220
+ cache: queryCache,
221
+ forceFresh: this.dev,
222
+ getFreshValue: async (ctx) => {
223
+ const result = await fetch();
224
+ ctx.metadata.ttl = result.cacheTime;
225
+ return result;
226
+ },
227
+ });
228
+ return new Response(result.data, {
229
+ status: result.status,
230
+ headers: result.headers,
231
+ });
232
+ }
233
+ async fetchMutation(req) {
234
+ const url = `/wp-json/ed/v1/mutation/${req.name}`;
235
+ return this.fetchOrigin(url, {
236
+ method: "POST",
237
+ cache: "no-cache",
238
+ replaceUrls: true,
239
+ headers: {
240
+ ...this.extractRequestHeaders(req.headers),
241
+ "Content-Type": "application/json",
242
+ Accept: "application/json",
243
+ },
244
+ body: JSON.stringify(req.body),
245
+ });
246
+ }
247
+ get allowedCorsOrigins() {
248
+ let result = [];
249
+ if (this.config.serverless.endpoints) {
250
+ result.push(...Object.keys(this.config.serverless.endpoints));
251
+ result.push(...Object.values(this.config.serverless.endpoints));
252
+ result = result.filter((origin) => origin !== "*");
253
+ }
254
+ if (this.config.serverless.cors?.origins) {
255
+ result.push(...this.config.serverless.cors.origins);
256
+ }
257
+ return result;
258
+ }
259
+ getCorsOrigin(originHeader) {
260
+ const parsed = parseURL(originHeader);
261
+ if (this.allowedCorsOrigins.includes(parsed.host)) {
262
+ return originHeader;
263
+ }
264
+ if (this.allowedCorsOrigins.includes("*")) {
265
+ return "*";
266
+ }
267
+ }
268
+ getCorsHeaders(origin) {
269
+ if (!origin)
270
+ return {};
271
+ const allowedOrigin = this.getCorsOrigin(origin);
272
+ if (allowedOrigin) {
273
+ return {
274
+ "Access-Control-Allow-Methods": "OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE",
275
+ "Access-Control-Allow-Origin": allowedOrigin,
276
+ "Access-Control-Allow-Credentials": "true",
277
+ "Access-Control-Allow-Headers": "*",
278
+ "Access-Control-Expose-Headers": "*",
279
+ };
280
+ }
281
+ return {};
282
+ }
283
+ }
@@ -2,3 +2,4 @@ export declare function filterHeader(key: string, allowed: (string | RegExp)[]):
2
2
  export declare const BRANDED_HEADERS: {
3
3
  "X-Powered-By": string;
4
4
  };
5
+ export declare function extractHeaders(rawHeaders: Headers): Record<string, string>;
@@ -9,3 +9,20 @@ export function filterHeader(key, allowed) {
9
9
  export const BRANDED_HEADERS = {
10
10
  "X-Powered-By": "ed.studio",
11
11
  };
12
+ const IGNORE_REQUEST_HEADERS = [
13
+ "host",
14
+ "connection",
15
+ "accept-encoding",
16
+ "accept-language",
17
+ "origin",
18
+ "referer",
19
+ "user-agent",
20
+ ];
21
+ export function extractHeaders(rawHeaders) {
22
+ const headers = {};
23
+ rawHeaders.forEach((value, key) => {
24
+ headers[key] = value;
25
+ });
26
+ IGNORE_REQUEST_HEADERS.forEach((key) => delete headers[key]);
27
+ return headers;
28
+ }
@@ -1,8 +1,10 @@
1
1
  export type UrlReplacerConf = {
2
2
  from: string;
3
3
  to: string;
4
- https: boolean;
5
- ignoreUploads: boolean;
6
- ignorePlugins: boolean;
4
+ /** A dictionary of prefixes (eg /wp-content), and whether to replace them (true/false) */
5
+ prefixes: {
6
+ prefix: string;
7
+ replace: boolean;
8
+ }[];
7
9
  };
8
- export declare function createUrlReplacer(conf: UrlReplacerConf): (value: string) => string;
10
+ export declare function createUrlReplacer(conf: UrlReplacerConf): (text: string, newOrigin?: string) => string;
@@ -1,14 +1,69 @@
1
1
  export function createUrlReplacer(conf) {
2
- const from = conf.from;
3
- const to = conf.to;
4
- const https = conf.https;
5
- const ignoreUploads = conf.ignoreUploads;
6
- const ignorePlugins = conf.ignorePlugins;
7
- const replaceTargetString = from.replaceAll(/https?:/g, "https?:").replaceAll("/", "\\/");
8
- const replaceTargetEscapedString = from.replaceAll(/https?:/g, "https?:").replaceAll("/", "\\\\/");
9
- const replaceTarget = new RegExp(replaceTargetString, "g");
10
- const replaceTargetEscaped = new RegExp(replaceTargetEscapedString, "g");
11
- return (value) => {
12
- return value.replaceAll(replaceTarget, to).replace(replaceTargetEscaped, to.replaceAll("/", "\\/"));
2
+ // Create a regular expression to match the URL
3
+ // Note that that the regex doesn't necessarily match the entire URL
4
+ const lookup = new RegExp(conf.from.replace(/https?[:\\\/]+/, "https?[:\\/\\\\]+") + "([a-z0-9\\-_/\\\\]+)", "ig");
5
+ return (text, newOrigin) => {
6
+ return text.replace(lookup, (url) => {
7
+ // Strip out the origin, to create a relative path
8
+ const path = url.replace(/https?:[\/\\]+[^\/\\]+/, "");
9
+ const isEscaped = url.includes(":\\/\\/");
10
+ const key = "/" +
11
+ path
12
+ .split(/[\/\\]+/g)
13
+ .filter((v) => v)
14
+ .join("/");
15
+ for (let item of conf.prefixes) {
16
+ if (key.startsWith(item.prefix)) {
17
+ if (item.replace) {
18
+ return url;
19
+ }
20
+ else {
21
+ break;
22
+ }
23
+ }
24
+ }
25
+ if (newOrigin) {
26
+ if (isEscaped) {
27
+ return newOrigin.replace(/\//g, "\\/") + path;
28
+ }
29
+ else {
30
+ return newOrigin + path;
31
+ }
32
+ }
33
+ return path;
34
+ // if (path.startsWith("/wp-content/uploads/")) {
35
+ // if (!conf.ignoreUploads) {
36
+ // return path
37
+ // } else {
38
+ // return url
39
+ // }
40
+ // // } else if (path.startsWith("/wp-content/themes/")) {
41
+ // // if (settings?.uploads === "proxy") {
42
+ // // return path
43
+ // // } else if (settings?.uploads === "remote") {
44
+ // // return url
45
+ // // }
46
+ // // } else if (path.startsWith("/wp-content/plugins/")) {
47
+ // // if (settings?.uploads === "proxy") {
48
+ // // return path
49
+ // // } else if (settings?.uploads === "remote") {
50
+ // // return url
51
+ // // }
52
+ // } else {
53
+ // return path
54
+ // }
55
+ });
13
56
  };
57
+ // const from = conf.from
58
+ // const to = conf.to
59
+ // const https = conf.https
60
+ // const ignoreUploads = conf.ignoreUploads
61
+ // const ignorePlugins = conf.ignorePlugins
62
+ // const replaceTargetString = from.replaceAll(/https?:/g, "https?:").replaceAll("/", "\\/")
63
+ // const replaceTargetEscapedString = from.replaceAll(/https?:/g, "https?:").replaceAll("/", "\\\\/")
64
+ // const replaceTarget = new RegExp(replaceTargetString, "g")
65
+ // const replaceTargetEscaped = new RegExp(replaceTargetEscapedString, "g")
66
+ // return (value: string) => {
67
+ // return value.replaceAll(replaceTarget, to).replace(replaceTargetEscaped, to.replaceAll("/", "\\/"))
68
+ // }
14
69
  }
@@ -0,0 +1,4 @@
1
+ import { Cache, CachifiedOptions } from "@epic-web/cachified";
2
+ export declare const pageCache: Cache<any>;
3
+ export declare const queryCache: Cache<any>;
4
+ export declare function swr<T>(args: CachifiedOptions<T>): Promise<T>;
@@ -0,0 +1,31 @@
1
+ import { LRUCache } from "lru-cache";
2
+ import { cachified, totalTtl } from "@epic-web/cachified";
3
+ function createCache() {
4
+ const lruInstance = new LRUCache({ max: 1000 });
5
+ const lru = {
6
+ set(key, value) {
7
+ const ttl = totalTtl(value?.metadata);
8
+ return lruInstance.set(key, value, {
9
+ ttl: ttl === Infinity ? undefined : ttl,
10
+ start: value?.metadata?.createdTime,
11
+ });
12
+ },
13
+ get(key) {
14
+ return lruInstance.get(key);
15
+ },
16
+ delete(key) {
17
+ return lruInstance.delete(key);
18
+ },
19
+ };
20
+ return lru;
21
+ }
22
+ export const pageCache = createCache();
23
+ export const queryCache = createCache();
24
+ export function swr(args) {
25
+ return cachified({
26
+ ttl: args.ttl ?? 10_000,
27
+ swr: 3600_000,
28
+ fallbackToCache: 15_000,
29
+ ...args,
30
+ });
31
+ }
@@ -0,0 +1,2 @@
1
+ import { PropsWithChildren } from "react";
2
+ export declare function APIProvider(props: PropsWithChildren<{}>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { QueryProvider } from "./query-client.js";
3
+ export function APIProvider(props) {
4
+ return _jsx(QueryProvider, { children: props.children });
5
+ }
@@ -0,0 +1,19 @@
1
+ import { Component, ErrorInfo, ReactNode } from "react";
2
+ import { BlocksContext, ContentBlock } from "../lib/blocks/ContentBlocks.js";
3
+ interface Props {
4
+ block: ContentBlock;
5
+ blockContext: BlocksContext;
6
+ children: ReactNode;
7
+ }
8
+ interface State {
9
+ hasError: boolean;
10
+ error?: Error;
11
+ errorInfo?: ErrorInfo;
12
+ }
13
+ export declare class BlockErrorBoundary extends Component<Props, State> {
14
+ state: State;
15
+ static getDerivedStateFromError(error: Error): State;
16
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
17
+ render(): ReactNode;
18
+ }
19
+ export {};
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Component } from "react";
3
+ import { errorHandling } from "../lib/runtime/errorHandling.js";
4
+ import { ErrorMessage } from "./ErrorMessage.js";
5
+ export class BlockErrorBoundary extends Component {
6
+ state = {
7
+ hasError: false,
8
+ };
9
+ static getDerivedStateFromError(error) {
10
+ // Update state so the next render will show the fallback UI.
11
+ return { hasError: true, error: error };
12
+ }
13
+ componentDidCatch(error, errorInfo) {
14
+ if (errorHandling.onReactError) {
15
+ errorHandling.onReactError({
16
+ type: "block",
17
+ block: this.props.block,
18
+ error,
19
+ componentStack: errorInfo.componentStack,
20
+ });
21
+ }
22
+ }
23
+ render() {
24
+ if (this.state.hasError) {
25
+ const err = this.state.error;
26
+ let display = env.dev ? _jsx(ErrorMessage, { error: err }) : null;
27
+ if (errorHandling.renderFallback) {
28
+ display = errorHandling.renderFallback({
29
+ type: "block",
30
+ block: this.props.block,
31
+ error: err,
32
+ }, display);
33
+ }
34
+ return display;
35
+ }
36
+ return this.props.children;
37
+ }
38
+ }
@@ -0,0 +1,5 @@
1
+ type Props = {
2
+ error: Error;
3
+ };
4
+ export declare function ErrorMessage({ error }: Props): import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function ErrorMessage({ error }) {
3
+ return (_jsx("pre", { style: {
4
+ backgroundColor: "#060309",
5
+ fontSize: "12px",
6
+ color: "#d92a0b",
7
+ outline: "1px solid #d92a0b",
8
+ outlineOffset: "-4px",
9
+ borderRadius: "6px",
10
+ padding: "12px 16px",
11
+ overflowX: "auto",
12
+ fontFamily: '"Roboto Mono", Menlo, monospace',
13
+ }, children: error.stack ?? String(error) }));
14
+ }
@@ -0,0 +1,18 @@
1
+ import { Component, ErrorInfo, ReactNode } from "react";
2
+ import { RouteState } from "../lib/routing/types.js";
3
+ interface Props {
4
+ route: RouteState;
5
+ children: ReactNode;
6
+ }
7
+ interface State {
8
+ hasError: boolean;
9
+ error?: Error;
10
+ errorInfo?: ErrorInfo;
11
+ }
12
+ export declare class RouteErrorBoundary extends Component<Props, State> {
13
+ state: State;
14
+ static getDerivedStateFromError(error: Error): State;
15
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
16
+ render(): ReactNode;
17
+ }
18
+ export {};
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Component } from "react";
3
+ import { errorHandling } from "../lib/runtime/errorHandling.js";
4
+ import { ErrorMessage } from "./ErrorMessage.js";
5
+ export class RouteErrorBoundary extends Component {
6
+ state = {
7
+ hasError: false,
8
+ };
9
+ static getDerivedStateFromError(error) {
10
+ // Update state so the next render will show the fallback UI.
11
+ return { hasError: true, error: error };
12
+ }
13
+ componentDidCatch(error, errorInfo) {
14
+ if (errorHandling.onReactError) {
15
+ errorHandling.onReactError({
16
+ type: "route",
17
+ route: this.props.route,
18
+ error,
19
+ componentStack: errorInfo.componentStack,
20
+ });
21
+ }
22
+ }
23
+ render() {
24
+ if (this.state.hasError) {
25
+ const err = this.state.error;
26
+ let display = env.dev ? _jsx(ErrorMessage, { error: err }) : null;
27
+ if (errorHandling.renderFallback) {
28
+ display = errorHandling.renderFallback({
29
+ type: "route",
30
+ route: this.props.route,
31
+ error: err,
32
+ }, display);
33
+ }
34
+ return display;
35
+ }
36
+ return this.props.children;
37
+ }
38
+ }
@@ -0,0 +1,2 @@
1
+ export declare const AssetCaptureContext: import("react").Context<Set<string>>;
2
+ export declare const useAssetCapture: () => Set<string>;
@@ -0,0 +1,5 @@
1
+ import { createContext, useContext } from "react";
2
+ export const AssetCaptureContext = createContext(new Set());
3
+ export const useAssetCapture = () => {
4
+ return useContext(AssetCaptureContext);
5
+ };
@@ -0,0 +1,13 @@
1
+ export type HydrationErrorSnapshot = {
2
+ html: string;
3
+ error: Error;
4
+ info: any;
5
+ };
6
+ export declare const hydrationDebug: {
7
+ initialHTML: string;
8
+ events: HydrationErrorSnapshot[];
9
+ add(item: {
10
+ error: Error;
11
+ info: any;
12
+ }): void;
13
+ };
@@ -0,0 +1,11 @@
1
+ import { proxy } from "valtio";
2
+ export const hydrationDebug = proxy({
3
+ initialHTML: "",
4
+ events: [],
5
+ add(item) {
6
+ hydrationDebug.events.push({
7
+ html: document.querySelector("#_app")?.innerHTML ?? "",
8
+ ...item,
9
+ });
10
+ },
11
+ });
@@ -1,2 +1,4 @@
1
1
  import { QueryClient } from "@tanstack/react-query";
2
+ import { PropsWithChildren } from "react";
2
3
  export declare function getQueryClient(): QueryClient;
4
+ export declare function QueryProvider(props: PropsWithChildren<{}>): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,5 @@
1
- import { QueryClient } from "@tanstack/react-query";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
2
3
  let queryClient = null;
3
4
  export function getQueryClient() {
4
5
  if (!queryClient) {
@@ -14,3 +15,6 @@ export function getQueryClient() {
14
15
  }
15
16
  return queryClient;
16
17
  }
18
+ export function QueryProvider(props) {
19
+ return _jsx(QueryClientProvider, { client: getQueryClient(), children: props.children });
20
+ }
@@ -0,0 +1,2 @@
1
+ import { TRPCUntypedClient } from "@trpc/client";
2
+ export declare function getRPCClient(): TRPCUntypedClient<any>;