@makeswift/runtime 0.14.4 → 0.15.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.
- package/dist/cjs/api/react.js +3 -17
- package/dist/cjs/api/react.js.map +1 -1
- package/dist/cjs/api/resource-types.js +24 -0
- package/dist/cjs/api/resource-types.js.map +1 -0
- package/dist/cjs/components/builtin/Box/Box.js +1 -0
- package/dist/cjs/components/builtin/Box/Box.js.map +1 -1
- package/dist/cjs/components/builtin/Box/animations.js +1 -0
- package/dist/cjs/components/builtin/Box/animations.js.map +1 -1
- package/dist/cjs/components/builtin/Box/register.js +2 -3
- package/dist/cjs/components/builtin/Box/register.js.map +1 -1
- package/dist/cjs/components/builtin/Button/register.js +2 -3
- package/dist/cjs/components/builtin/Button/register.js.map +1 -1
- package/dist/cjs/components/builtin/Carousel/Carousel.js +1 -0
- package/dist/cjs/components/builtin/Carousel/Carousel.js.map +1 -1
- package/dist/cjs/components/builtin/Carousel/register.js +2 -3
- package/dist/cjs/components/builtin/Carousel/register.js.map +1 -1
- package/dist/cjs/components/builtin/Countdown/Countdown.js +1 -0
- package/dist/cjs/components/builtin/Countdown/Countdown.js.map +1 -1
- package/dist/cjs/components/builtin/Countdown/register.js +2 -3
- package/dist/cjs/components/builtin/Countdown/register.js.map +1 -1
- package/dist/cjs/components/builtin/Divider/register.js +2 -3
- package/dist/cjs/components/builtin/Divider/register.js.map +1 -1
- package/dist/cjs/components/builtin/Embed/Embed.js +1 -0
- package/dist/cjs/components/builtin/Embed/Embed.js.map +1 -1
- package/dist/cjs/components/builtin/Embed/register.js +2 -3
- package/dist/cjs/components/builtin/Embed/register.js.map +1 -1
- package/dist/cjs/components/builtin/Form/Form.js +3 -2
- package/dist/cjs/components/builtin/Form/Form.js.map +1 -1
- package/dist/cjs/components/builtin/Form/context/FormContext.js +1 -0
- package/dist/cjs/components/builtin/Form/context/FormContext.js.map +1 -1
- package/dist/cjs/components/builtin/Form/register.js +2 -3
- package/dist/cjs/components/builtin/Form/register.js.map +1 -1
- package/dist/cjs/components/builtin/Image/Image.js +1 -0
- package/dist/cjs/components/builtin/Image/Image.js.map +1 -1
- package/dist/cjs/components/builtin/Image/register.js +2 -3
- package/dist/cjs/components/builtin/Image/register.js.map +1 -1
- package/dist/cjs/components/builtin/Navigation/Navigation.js +1 -0
- package/dist/cjs/components/builtin/Navigation/Navigation.js.map +1 -1
- package/dist/cjs/components/builtin/Navigation/register.js +2 -3
- package/dist/cjs/components/builtin/Navigation/register.js.map +1 -1
- package/dist/cjs/components/builtin/Root/register.js +2 -3
- package/dist/cjs/components/builtin/Root/register.js.map +1 -1
- package/dist/cjs/components/builtin/SocialLinks/register.js +2 -3
- package/dist/cjs/components/builtin/SocialLinks/register.js.map +1 -1
- package/dist/cjs/components/builtin/Text/register.js +2 -3
- package/dist/cjs/components/builtin/Text/register.js.map +1 -1
- package/dist/cjs/components/builtin/Video/Video.js +1 -0
- package/dist/cjs/components/builtin/Video/Video.js.map +1 -1
- package/dist/cjs/components/builtin/Video/register.js +2 -3
- package/dist/cjs/components/builtin/Video/register.js.map +1 -1
- package/dist/cjs/components/hooks/usePageSnippets.js +93 -0
- package/dist/cjs/components/hooks/usePageSnippets.js.map +1 -0
- package/dist/cjs/components/hooks/useRouterLocaleSync.js +49 -0
- package/dist/cjs/components/hooks/useRouterLocaleSync.js.map +1 -0
- package/dist/cjs/components/page/BodySnippet.js +1 -1
- package/dist/cjs/components/page/BodySnippet.js.map +1 -1
- package/dist/cjs/components/page/HeadSnippet.js +134 -0
- package/dist/cjs/components/page/HeadSnippet.js.map +1 -0
- package/dist/cjs/components/page/Page.js +9 -178
- package/dist/cjs/components/page/Page.js.map +1 -1
- package/dist/cjs/components/page/PageHead.js +109 -0
- package/dist/cjs/components/page/PageHead.js.map +1 -0
- package/dist/cjs/components/shared/BackgroundsContainer/index.js +1 -0
- package/dist/cjs/components/shared/BackgroundsContainer/index.js.map +1 -1
- package/dist/cjs/components/shared/Link/index.js +5 -1
- package/dist/cjs/components/shared/Link/index.js.map +1 -1
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/element-tree.js +17 -8
- package/dist/cjs/next/api-handler/handlers/element-tree.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/fonts.js +7 -2
- package/dist/cjs/next/api-handler/handlers/fonts.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/manifest.js +20 -8
- package/dist/cjs/next/api-handler/handlers/manifest.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/merge-translated-data.js +17 -6
- package/dist/cjs/next/api-handler/handlers/merge-translated-data.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js +69 -0
- package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js.map +1 -0
- package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js +55 -44
- package/dist/cjs/next/api-handler/handlers/proxy-preview-mode.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/revalidate.js +27 -16
- package/dist/cjs/next/api-handler/handlers/revalidate.js.map +1 -1
- package/dist/cjs/next/api-handler/handlers/translatable-data.js +16 -5
- package/dist/cjs/next/api-handler/handlers/translatable-data.js.map +1 -1
- package/dist/cjs/next/api-handler/index.js +68 -34
- package/dist/cjs/next/api-handler/index.js.map +1 -1
- package/dist/cjs/next/client.js +3 -2
- package/dist/cjs/next/client.js.map +1 -1
- package/dist/cjs/next/components/head-tags.js +77 -0
- package/dist/cjs/next/components/head-tags.js.map +1 -0
- package/dist/cjs/next/components/page.js +56 -0
- package/dist/cjs/next/components/page.js.map +1 -0
- package/dist/cjs/next/context/makeswift-host-api-client.js +46 -0
- package/dist/cjs/next/context/makeswift-host-api-client.js.map +1 -0
- package/dist/cjs/next/context/react-runtime.js +44 -0
- package/dist/cjs/next/context/react-runtime.js.map +1 -0
- package/dist/cjs/next/draft-mode/draft-mode-script.js +123 -0
- package/dist/cjs/next/draft-mode/draft-mode-script.js.map +1 -0
- package/dist/cjs/next/draft-mode/index.js +56 -0
- package/dist/cjs/next/draft-mode/index.js.map +1 -0
- package/dist/cjs/next/hooks/use-is-pages-router.js +37 -0
- package/dist/cjs/next/hooks/use-is-pages-router.js.map +1 -0
- package/dist/cjs/next/index.js +10 -36
- package/dist/cjs/next/index.js.map +1 -1
- package/dist/cjs/next/preview-mode.js +4 -2
- package/dist/cjs/next/preview-mode.js.map +1 -1
- package/dist/cjs/next/root-style-registry.js +90 -0
- package/dist/cjs/next/root-style-registry.js.map +1 -0
- package/dist/cjs/next/server.js +8 -2
- package/dist/cjs/next/server.js.map +1 -1
- package/dist/cjs/runtimes/react/components/Element.js +1 -0
- package/dist/cjs/runtimes/react/components/Element.js.map +1 -1
- package/dist/cjs/runtimes/react/components/LiveProvider.js +6 -13
- package/dist/cjs/runtimes/react/components/LiveProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/components/PreviewProvider.js +6 -8
- package/dist/cjs/runtimes/react/components/PreviewProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js +3 -3
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/link.js +1 -1
- package/dist/cjs/runtimes/react/controls/link.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js +2 -4
- package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js +4 -11
- package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/makeswift-api.js +11 -10
- package/dist/cjs/runtimes/react/hooks/makeswift-api.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-document-key.js +1 -0
- package/dist/cjs/runtimes/react/hooks/use-document-key.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-page-id.js +1 -0
- package/dist/cjs/runtimes/react/hooks/use-page-id.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-store.js +1 -0
- package/dist/cjs/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/cjs/runtimes/react/use-global-style.js +15 -10
- package/dist/cjs/runtimes/react/use-global-style.js.map +1 -1
- package/dist/cjs/runtimes/react/use-style.js +7 -6
- package/dist/cjs/runtimes/react/use-style.js.map +1 -1
- package/dist/cjs/state/actions.js +0 -25
- package/dist/cjs/state/actions.js.map +1 -1
- package/dist/cjs/state/react-builder-preview.js +1 -24
- package/dist/cjs/state/react-builder-preview.js.map +1 -1
- package/dist/esm/api/react.js +2 -14
- package/dist/esm/api/react.js.map +1 -1
- package/dist/esm/api/resource-types.js +8 -0
- package/dist/esm/api/resource-types.js.map +1 -0
- package/dist/esm/components/builtin/Box/Box.js +1 -0
- package/dist/esm/components/builtin/Box/Box.js.map +1 -1
- package/dist/esm/components/builtin/Box/animations.js +1 -0
- package/dist/esm/components/builtin/Box/animations.js.map +1 -1
- package/dist/esm/components/builtin/Box/register.js +2 -3
- package/dist/esm/components/builtin/Box/register.js.map +1 -1
- package/dist/esm/components/builtin/Button/register.js +2 -3
- package/dist/esm/components/builtin/Button/register.js.map +1 -1
- package/dist/esm/components/builtin/Carousel/Carousel.js +1 -0
- package/dist/esm/components/builtin/Carousel/Carousel.js.map +1 -1
- package/dist/esm/components/builtin/Carousel/register.js +2 -3
- package/dist/esm/components/builtin/Carousel/register.js.map +1 -1
- package/dist/esm/components/builtin/Countdown/Countdown.js +1 -0
- package/dist/esm/components/builtin/Countdown/Countdown.js.map +1 -1
- package/dist/esm/components/builtin/Countdown/register.js +2 -3
- package/dist/esm/components/builtin/Countdown/register.js.map +1 -1
- package/dist/esm/components/builtin/Divider/register.js +2 -3
- package/dist/esm/components/builtin/Divider/register.js.map +1 -1
- package/dist/esm/components/builtin/Embed/Embed.js +1 -0
- package/dist/esm/components/builtin/Embed/Embed.js.map +1 -1
- package/dist/esm/components/builtin/Embed/register.js +2 -3
- package/dist/esm/components/builtin/Embed/register.js.map +1 -1
- package/dist/esm/components/builtin/Form/Form.js +3 -2
- package/dist/esm/components/builtin/Form/Form.js.map +1 -1
- package/dist/esm/components/builtin/Form/context/FormContext.js +1 -0
- package/dist/esm/components/builtin/Form/context/FormContext.js.map +1 -1
- package/dist/esm/components/builtin/Form/register.js +2 -3
- package/dist/esm/components/builtin/Form/register.js.map +1 -1
- package/dist/esm/components/builtin/Image/Image.js +1 -0
- package/dist/esm/components/builtin/Image/Image.js.map +1 -1
- package/dist/esm/components/builtin/Image/register.js +2 -3
- package/dist/esm/components/builtin/Image/register.js.map +1 -1
- package/dist/esm/components/builtin/Navigation/Navigation.js +1 -0
- package/dist/esm/components/builtin/Navigation/Navigation.js.map +1 -1
- package/dist/esm/components/builtin/Navigation/register.js +2 -3
- package/dist/esm/components/builtin/Navigation/register.js.map +1 -1
- package/dist/esm/components/builtin/Root/register.js +2 -3
- package/dist/esm/components/builtin/Root/register.js.map +1 -1
- package/dist/esm/components/builtin/SocialLinks/register.js +2 -3
- package/dist/esm/components/builtin/SocialLinks/register.js.map +1 -1
- package/dist/esm/components/builtin/Text/register.js +2 -3
- package/dist/esm/components/builtin/Text/register.js.map +1 -1
- package/dist/esm/components/builtin/Video/Video.js +1 -0
- package/dist/esm/components/builtin/Video/Video.js.map +1 -1
- package/dist/esm/components/builtin/Video/register.js +2 -3
- package/dist/esm/components/builtin/Video/register.js.map +1 -1
- package/dist/esm/components/hooks/usePageSnippets.js +59 -0
- package/dist/esm/components/hooks/usePageSnippets.js.map +1 -0
- package/dist/esm/components/hooks/useRouterLocaleSync.js +25 -0
- package/dist/esm/components/hooks/useRouterLocaleSync.js.map +1 -0
- package/dist/esm/components/page/BodySnippet.js +1 -1
- package/dist/esm/components/page/BodySnippet.js.map +1 -1
- package/dist/esm/components/page/HeadSnippet.js +100 -0
- package/dist/esm/components/page/HeadSnippet.js.map +1 -0
- package/dist/esm/components/page/Page.js +7 -166
- package/dist/esm/components/page/Page.js.map +1 -1
- package/dist/esm/components/page/PageHead.js +85 -0
- package/dist/esm/components/page/PageHead.js.map +1 -0
- package/dist/esm/components/shared/BackgroundsContainer/index.js +1 -0
- package/dist/esm/components/shared/BackgroundsContainer/index.js.map +1 -1
- package/dist/esm/components/shared/Link/index.js +5 -1
- package/dist/esm/components/shared/Link/index.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/element-tree.js +17 -8
- package/dist/esm/next/api-handler/handlers/element-tree.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/fonts.js +7 -2
- package/dist/esm/next/api-handler/handlers/fonts.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/manifest.js +20 -8
- package/dist/esm/next/api-handler/handlers/manifest.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/merge-translated-data.js +17 -6
- package/dist/esm/next/api-handler/handlers/merge-translated-data.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js +49 -0
- package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js.map +1 -0
- package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js +55 -44
- package/dist/esm/next/api-handler/handlers/proxy-preview-mode.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/revalidate.js +27 -16
- package/dist/esm/next/api-handler/handlers/revalidate.js.map +1 -1
- package/dist/esm/next/api-handler/handlers/translatable-data.js +16 -5
- package/dist/esm/next/api-handler/handlers/translatable-data.js.map +1 -1
- package/dist/esm/next/api-handler/index.js +68 -34
- package/dist/esm/next/api-handler/index.js.map +1 -1
- package/dist/esm/next/client.js +3 -2
- package/dist/esm/next/client.js.map +1 -1
- package/dist/esm/next/components/head-tags.js +40 -0
- package/dist/esm/next/components/head-tags.js.map +1 -0
- package/dist/esm/next/components/page.js +32 -0
- package/dist/esm/next/components/page.js.map +1 -0
- package/dist/esm/next/context/makeswift-host-api-client.js +21 -0
- package/dist/esm/next/context/makeswift-host-api-client.js.map +1 -0
- package/dist/esm/next/context/react-runtime.js +19 -0
- package/dist/esm/next/context/react-runtime.js.map +1 -0
- package/dist/esm/next/draft-mode/draft-mode-script.js +99 -0
- package/dist/esm/next/draft-mode/draft-mode-script.js.map +1 -0
- package/dist/esm/next/draft-mode/index.js +30 -0
- package/dist/esm/next/draft-mode/index.js.map +1 -0
- package/dist/esm/next/hooks/use-is-pages-router.js +13 -0
- package/dist/esm/next/hooks/use-is-pages-router.js.map +1 -0
- package/dist/esm/next/index.js +5 -32
- package/dist/esm/next/index.js.map +1 -1
- package/dist/esm/next/preview-mode.js +2 -1
- package/dist/esm/next/preview-mode.js.map +1 -1
- package/dist/esm/next/root-style-registry.js +55 -0
- package/dist/esm/next/root-style-registry.js.map +1 -0
- package/dist/esm/next/server.js +5 -1
- package/dist/esm/next/server.js.map +1 -1
- package/dist/esm/runtimes/react/components/Element.js +1 -0
- package/dist/esm/runtimes/react/components/Element.js.map +1 -1
- package/dist/esm/runtimes/react/components/LiveProvider.js +6 -13
- package/dist/esm/runtimes/react/components/LiveProvider.js.map +1 -1
- package/dist/esm/runtimes/react/components/PreviewProvider.js +6 -8
- package/dist/esm/runtimes/react/components/PreviewProvider.js.map +1 -1
- package/dist/esm/runtimes/react/components/RuntimeProvider.js +3 -3
- package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/esm/runtimes/react/controls/link.js +1 -1
- package/dist/esm/runtimes/react/controls/link.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text/rich-text.js +3 -5
- package/dist/esm/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js +4 -11
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/makeswift-api.js +11 -10
- package/dist/esm/runtimes/react/hooks/makeswift-api.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-document-key.js +1 -0
- package/dist/esm/runtimes/react/hooks/use-document-key.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-page-id.js +1 -0
- package/dist/esm/runtimes/react/hooks/use-page-id.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-store.js +1 -0
- package/dist/esm/runtimes/react/hooks/use-store.js.map +1 -1
- package/dist/esm/runtimes/react/use-global-style.js +8 -3
- package/dist/esm/runtimes/react/use-global-style.js.map +1 -1
- package/dist/esm/runtimes/react/use-style.js +2 -1
- package/dist/esm/runtimes/react/use-style.js.map +1 -1
- package/dist/esm/state/actions.js +0 -22
- package/dist/esm/state/actions.js.map +1 -1
- package/dist/esm/state/react-builder-preview.js +2 -28
- package/dist/esm/state/react-builder-preview.js.map +1 -1
- package/dist/types/api/react.d.ts +1 -9
- package/dist/types/api/react.d.ts.map +1 -1
- package/dist/types/api/resource-types.d.ts +20 -0
- package/dist/types/api/resource-types.d.ts.map +1 -0
- package/dist/types/components/builtin/Box/Box.d.ts.map +1 -1
- package/dist/types/components/builtin/Box/animations.d.ts.map +1 -1
- package/dist/types/components/builtin/Box/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Button/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Carousel/Carousel.d.ts.map +1 -1
- package/dist/types/components/builtin/Carousel/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Countdown/Countdown.d.ts.map +1 -1
- package/dist/types/components/builtin/Countdown/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Divider/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Embed/Embed.d.ts.map +1 -1
- package/dist/types/components/builtin/Embed/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Form/Form.d.ts.map +1 -1
- package/dist/types/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
- package/dist/types/components/builtin/Form/context/FormContext.d.ts.map +1 -1
- package/dist/types/components/builtin/Form/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Image/Image.d.ts.map +1 -1
- package/dist/types/components/builtin/Image/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Navigation/Navigation.d.ts.map +1 -1
- package/dist/types/components/builtin/Navigation/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Root/register.d.ts.map +1 -1
- package/dist/types/components/builtin/SocialLinks/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Text/register.d.ts.map +1 -1
- package/dist/types/components/builtin/Video/Video.d.ts.map +1 -1
- package/dist/types/components/builtin/Video/register.d.ts.map +1 -1
- package/dist/types/components/hooks/usePageSnippets.d.ts +36 -0
- package/dist/types/components/hooks/usePageSnippets.d.ts.map +1 -0
- package/dist/types/components/hooks/useRouterLocaleSync.d.ts +2 -0
- package/dist/types/components/hooks/useRouterLocaleSync.d.ts.map +1 -0
- package/dist/types/components/page/BodySnippet.d.ts.map +1 -1
- package/dist/types/components/page/HeadSnippet.d.ts +7 -0
- package/dist/types/components/page/HeadSnippet.d.ts.map +1 -0
- package/dist/types/components/page/Page.d.ts.map +1 -1
- package/dist/types/components/page/PageHead.d.ts +8 -0
- package/dist/types/components/page/PageHead.d.ts.map +1 -0
- package/dist/types/components/shared/BackgroundsContainer/index.d.ts.map +1 -1
- package/dist/types/components/shared/Link/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/element-tree.d.ts +9 -1
- package/dist/types/next/api-handler/handlers/element-tree.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/fonts.d.ts +10 -1
- package/dist/types/next/api-handler/handlers/fonts.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/manifest.d.ts +9 -0
- package/dist/types/next/api-handler/handlers/manifest.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/merge-translated-data.d.ts +7 -0
- package/dist/types/next/api-handler/handlers/merge-translated-data.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/proxy-draft-mode.d.ts +20 -0
- package/dist/types/next/api-handler/handlers/proxy-draft-mode.d.ts.map +1 -0
- package/dist/types/next/api-handler/handlers/proxy-preview-mode.d.ts +14 -2
- package/dist/types/next/api-handler/handlers/proxy-preview-mode.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/revalidate.d.ts +9 -0
- package/dist/types/next/api-handler/handlers/revalidate.d.ts.map +1 -1
- package/dist/types/next/api-handler/handlers/translatable-data.d.ts +7 -0
- package/dist/types/next/api-handler/handlers/translatable-data.d.ts.map +1 -1
- package/dist/types/next/api-handler/index.d.ts +11 -3
- package/dist/types/next/api-handler/index.d.ts.map +1 -1
- package/dist/types/next/client.d.ts.map +1 -1
- package/dist/types/next/components/head-tags.d.ts +19 -0
- package/dist/types/next/components/head-tags.d.ts.map +1 -0
- package/dist/types/next/components/page.d.ts +7 -0
- package/dist/types/next/components/page.d.ts.map +1 -0
- package/dist/types/next/context/makeswift-host-api-client.d.ts +8 -0
- package/dist/types/next/context/makeswift-host-api-client.d.ts.map +1 -0
- package/dist/types/next/context/react-runtime.d.ts +8 -0
- package/dist/types/next/context/react-runtime.d.ts.map +1 -0
- package/dist/types/next/draft-mode/draft-mode-script.d.ts +6 -0
- package/dist/types/next/draft-mode/draft-mode-script.d.ts.map +1 -0
- package/dist/types/next/draft-mode/index.d.ts +15 -0
- package/dist/types/next/draft-mode/index.d.ts.map +1 -0
- package/dist/types/next/hooks/use-is-pages-router.d.ts +2 -0
- package/dist/types/next/hooks/use-is-pages-router.d.ts.map +1 -0
- package/dist/types/next/index.d.ts +4 -9
- package/dist/types/next/index.d.ts.map +1 -1
- package/dist/types/next/preview-mode.d.ts +1 -1
- package/dist/types/next/preview-mode.d.ts.map +1 -1
- package/dist/types/next/root-style-registry.d.ts +7 -0
- package/dist/types/next/root-style-registry.d.ts.map +1 -0
- package/dist/types/next/server.d.ts +2 -0
- package/dist/types/next/server.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/Element.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/LiveProvider.d.ts +3 -5
- package/dist/types/runtimes/react/components/LiveProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/PreviewProvider.d.ts +3 -5
- package/dist/types/runtimes/react/components/PreviewProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts +2 -2
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/link.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text/rich-text.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/makeswift-api.d.ts +2 -1
- package/dist/types/runtimes/react/hooks/makeswift-api.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-document-key.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-page-id.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
- package/dist/types/runtimes/react/use-global-style.d.ts.map +1 -1
- package/dist/types/runtimes/react/use-style.d.ts.map +1 -1
- package/dist/types/state/actions.d.ts +1 -19
- package/dist/types/state/actions.d.ts.map +1 -1
- package/dist/types/state/react-builder-preview.d.ts +3 -3
- package/dist/types/state/react-builder-preview.d.ts.map +1 -1
- package/next/plugin/package.json +1 -0
- package/package.json +6 -10
- package/slate/package.json +1 -1
- package/dist/cjs/next/dynamic.js +0 -52
- package/dist/cjs/next/dynamic.js.map +0 -1
- package/dist/esm/next/dynamic.js +0 -31
- package/dist/esm/next/dynamic.js.map +0 -1
- package/dist/types/next/dynamic.d.ts +0 -13
- package/dist/types/next/dynamic.d.ts.map +0 -1
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type { Action, SetBreakpointsAction } from './state/actions'\nexport {\n ActionTypes,\n changeDocument,\n changeDocumentElementScrollTop,\n cleanUp,\n init,\n messageHostPropController,\n changeApiResource,\n evictApiResource,\n registerDocument,\n scrollDocumentElement,\n unregisterDocument,\n setBuilderEditMode,\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type { Action, SetBreakpointsAction } from './state/actions'\nexport {\n ActionTypes,\n changeDocument,\n changeDocumentElementScrollTop,\n cleanUp,\n init,\n messageHostPropController,\n changeApiResource,\n evictApiResource,\n registerDocument,\n scrollDocumentElement,\n unregisterDocument,\n setBuilderEditMode,\n builderPointerMove,\n setBreakpoints,\n setLocale,\n setLocalizedResourceId,\n} from './state/actions'\nexport type { Operation } from './state/modules/read-write-documents'\nexport type { ComponentMeta } from './state/modules/components-meta'\nexport { ComponentIcon } from './state/modules/components-meta'\nexport type {\n PropControllerDescriptor,\n PropControllerDescriptorValueType,\n} from './prop-controllers'\nexport type { Element } from './state/react-page'\nexport { createDocument } from './state/react-page'\nexport { MakeswiftComponentType } from './components/builtin/constants'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAiBO;AAGP,6BAA8B;AAM9B,wBAA+B;AAC/B,uBAAuC;","names":[]}
|
|
@@ -21,18 +21,27 @@ __export(element_tree_exports, {
|
|
|
21
21
|
default: () => elementTree
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(element_tree_exports);
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
var import_server = require("next/server");
|
|
25
|
+
var import_ts_pattern = require("ts-pattern");
|
|
26
|
+
const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
27
|
+
const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
28
|
+
async function elementTree(...args) {
|
|
29
|
+
const [, , runtime] = args;
|
|
30
|
+
const body = await (0, import_ts_pattern.match)(args).with(routeHandlerPattern, ([request]) => request.json()).with(apiRoutePattern, ([req]) => req.body).exhaustive();
|
|
31
|
+
const elementTree2 = body.elementTree;
|
|
32
|
+
const replacementContext = body.replacementContext;
|
|
28
33
|
if (elementTree2 == null) {
|
|
29
|
-
|
|
34
|
+
const status = 400;
|
|
35
|
+
const body2 = { message: "elementTree must be defined" };
|
|
36
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body2)).exhaustive();
|
|
30
37
|
}
|
|
31
38
|
if (replacementContext == null) {
|
|
32
|
-
|
|
39
|
+
const status = 400;
|
|
40
|
+
const body2 = { message: "replacementContext must be defined" };
|
|
41
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body2)).exhaustive();
|
|
33
42
|
}
|
|
34
|
-
const generatedElementTree =
|
|
43
|
+
const generatedElementTree = runtime.copyElementTree(elementTree2, replacementContext);
|
|
35
44
|
const response = { elementTree: generatedElementTree };
|
|
36
|
-
return res.json(response);
|
|
45
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(response)).with(apiRoutePattern, ([, res]) => res.json(response)).exhaustive();
|
|
37
46
|
}
|
|
38
47
|
//# sourceMappingURL=element-tree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/element-tree.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { ReactRuntime } from '../../../react'\nimport { Element } from '../../../state/react-page'\n\ntype ElementTreeResult = { elementTree: Element }\n\ntype ElementTreeError = { message: string }\n\nexport type ElementTreeResponse = ElementTreeResult | ElementTreeError\n\nexport default async function elementTree(\n req: NextApiRequest,\n res: NextApiResponse<ElementTreeResponse>,\n): Promise<void> {\n const
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/element-tree.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { ReactRuntime } from '../../../react'\nimport { Element } from '../../../state/react-page'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ElementTreeResult = { elementTree: Element }\n\ntype ElementTreeError = { message: string }\n\nexport type ElementTreeResponse = ElementTreeResult | ElementTreeError\n\ntype ElementTreeHandlerArgs =\n | [request: NextRequest, context: Context, runtime: ReactRuntime]\n | [req: NextApiRequest, res: NextApiResponse<ElementTreeResponse>, runtime: ReactRuntime]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function elementTree(\n request: NextRequest,\n context: Context,\n runtime: ReactRuntime,\n): Promise<NextResponse<ElementTreeResponse>>\nexport default async function elementTree(\n req: NextApiRequest,\n res: NextApiResponse<ElementTreeResponse>,\n runtime: ReactRuntime,\n): Promise<void>\nexport default async function elementTree(\n ...args: ElementTreeHandlerArgs\n): Promise<NextResponse<ElementTreeResponse> | void> {\n const [, , runtime] = args\n\n const body = await match(args)\n .with(routeHandlerPattern, ([request]) => request.json())\n .with(apiRoutePattern, ([req]) => req.body)\n .exhaustive()\n const elementTree = body.elementTree\n const replacementContext = body.replacementContext\n\n if (elementTree == null) {\n const status = 400\n const body = { message: 'elementTree must be defined' }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n\n if (replacementContext == null) {\n const status = 400\n const body = { message: 'replacementContext must be defined' }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n\n const generatedElementTree = runtime.copyElementTree(elementTree, replacementContext)\n\n const response = { elementTree: generatedElementTree }\n\n return match(args)\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AgBD,cAAa,kBAAkB;AAEpF,QAAM,WAAW,EAAE,aAAa,qBAAqB;AAErD,aAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,MAAM,2BAAa,KAAK,QAAQ,CAAC,EAC3D,KAAK,iBAAiB,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,KAAK,QAAQ,CAAC,EACrD,WAAW;AAChB;","names":["elementTree","body"]}
|
|
@@ -21,8 +21,13 @@ __export(fonts_exports, {
|
|
|
21
21
|
default: () => fonts
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(fonts_exports);
|
|
24
|
-
|
|
24
|
+
var import_server = require("next/server");
|
|
25
|
+
var import_ts_pattern = require("ts-pattern");
|
|
26
|
+
const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
27
|
+
const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
28
|
+
async function fonts(...args) {
|
|
29
|
+
const [, , { getFonts }] = args;
|
|
25
30
|
const fonts2 = await getFonts?.() ?? [];
|
|
26
|
-
return res.json(fonts2);
|
|
31
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(fonts2)).with(apiRoutePattern, ([, res]) => res.json(fonts2)).exhaustive();
|
|
27
32
|
}
|
|
28
33
|
//# sourceMappingURL=fonts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/fonts.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\n\ntype FontVariant = { weight: string; style: 'italic' | 'normal'; src?: string }\n\nexport type Font = {\n family: string\n label?: string\n variants: FontVariant[]\n}\n\ntype Fonts = Font[]\n\nexport type GetFonts = () => Fonts | Promise<Fonts>\n\nexport type FontsResponse = Fonts\n\nexport default async function fonts(\n _req: NextApiRequest,\n res: NextApiResponse<FontsResponse>,\n { getFonts }: { getFonts?: GetFonts }
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/fonts.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype FontVariant = { weight: string; style: 'italic' | 'normal'; src?: string }\n\nexport type Font = {\n family: string\n label?: string\n variants: FontVariant[]\n}\n\ntype Fonts = Font[]\n\nexport type GetFonts = () => Fonts | Promise<Fonts>\n\nexport type FontsResponse = Fonts\n\ntype FontsHandlerArgs =\n | [request: NextRequest, context: Context, params: { getFonts?: GetFonts }]\n | [req: NextApiRequest, res: NextApiResponse<FontsResponse>, params: { getFonts?: GetFonts }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function fonts(\n request: NextRequest,\n context: Context,\n { getFonts }: { getFonts?: GetFonts },\n): Promise<NextResponse<FontsResponse>>\nexport default async function fonts(\n _req: NextApiRequest,\n res: NextApiResponse<FontsResponse>,\n { getFonts }: { getFonts?: GetFonts },\n): Promise<void>\nexport default async function fonts(\n ...args: FontsHandlerArgs\n): Promise<NextResponse<FontsResponse> | void> {\n const [, , { getFonts }] = args\n\n const fonts = (await getFonts?.()) ?? []\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(fonts))\n .with(apiRoutePattern, ([, res]) => res.json(fonts))\n .exhaustive()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0C;AAC1C,wBAAyB;AAsBzB,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAY5C,eAAO,SACF,MAC0C;AAC7C,QAAM,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,IAAI;AAE3B,QAAMA,SAAS,MAAM,WAAW,KAAM,CAAC;AAEvC,aAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,MAAM,2BAAa,KAAKA,MAAK,CAAC,EACxD,KAAK,iBAAiB,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,KAAKA,MAAK,CAAC,EAClD,WAAW;AAChB;","names":["fonts"]}
|
|
@@ -21,20 +21,32 @@ __export(manifest_exports, {
|
|
|
21
21
|
default: () => handler
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(manifest_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
var import_server = require("next/server");
|
|
25
|
+
var import_ts_pattern = require("ts-pattern");
|
|
26
|
+
const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
27
|
+
const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
28
|
+
async function handler(...args) {
|
|
29
|
+
const [, , { apiKey }] = args;
|
|
30
|
+
const secret = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, ([request]) => request.nextUrl.searchParams.get("secret")).with(apiRoutePattern, ([req]) => req.query.secret).exhaustive();
|
|
31
|
+
if (secret !== apiKey) {
|
|
32
|
+
const status = 401;
|
|
33
|
+
const body2 = { message: "Unauthorized" };
|
|
34
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body2)).exhaustive();
|
|
27
35
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
const supportsPreviewMode = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => false).with(apiRoutePattern, () => true).exhaustive();
|
|
37
|
+
const supportsDraftMode = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
|
|
38
|
+
const body = {
|
|
39
|
+
version: "0.15.0",
|
|
40
|
+
previewMode: supportsPreviewMode,
|
|
41
|
+
draftMode: supportsDraftMode,
|
|
31
42
|
interactionMode: true,
|
|
32
|
-
clientSideNavigation:
|
|
43
|
+
clientSideNavigation: false,
|
|
33
44
|
elementFromPoint: false,
|
|
34
45
|
customBreakpoints: true,
|
|
35
46
|
siteVersions: true,
|
|
36
47
|
unstable_siteVersions: true,
|
|
37
48
|
localizedPageSSR: true
|
|
38
|
-
}
|
|
49
|
+
};
|
|
50
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body)).with(apiRoutePattern, ([, res]) => res.json(body)).exhaustive();
|
|
39
51
|
}
|
|
40
52
|
//# sourceMappingURL=manifest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/manifest.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\n\nexport type Manifest = {\n version: string\n previewMode: boolean\n interactionMode: boolean\n clientSideNavigation: boolean\n elementFromPoint: boolean\n customBreakpoints: boolean\n siteVersions: boolean\n unstable_siteVersions: boolean\n localizedPageSSR: boolean\n}\n\ntype ManifestError = { message: string }\n\nexport type ManifestResponse = Manifest | ManifestError\n\nexport default async function handler(\n req: NextApiRequest,\n res: NextApiResponse<ManifestResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/manifest.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\nexport type Manifest = {\n version: string\n previewMode: boolean\n interactionMode: boolean\n clientSideNavigation: boolean\n elementFromPoint: boolean\n customBreakpoints: boolean\n siteVersions: boolean\n unstable_siteVersions: boolean\n localizedPageSSR: boolean\n}\n\ntype ManifestError = { message: string }\n\nexport type ManifestResponse = Manifest | ManifestError\n\ntype ManifestHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<ManifestResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function handler(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ManifestResponse>>\nexport default async function handler(\n req: NextApiRequest,\n res: NextApiResponse<ManifestResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function handler(\n ...args: ManifestHandlerArgs\n): Promise<NextResponse<ManifestResponse> | void> {\n const [, , { apiKey }] = args\n\n const secret = match(args)\n .with(routeHandlerPattern, ([request]) => request.nextUrl.searchParams.get('secret'))\n .with(apiRoutePattern, ([req]) => req.query.secret)\n .exhaustive()\n\n if (secret !== apiKey) {\n const status = 401\n const body = { message: 'Unauthorized' }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n\n const supportsPreviewMode = match(args)\n .with(routeHandlerPattern, () => false)\n .with(apiRoutePattern, () => true)\n .exhaustive()\n\n const supportsDraftMode = match(args)\n .with(routeHandlerPattern, () => true)\n .with(apiRoutePattern, () => false)\n .exhaustive()\n\n const body = {\n version: PACKAGE_VERSION,\n previewMode: supportsPreviewMode,\n draftMode: supportsDraftMode,\n interactionMode: true,\n clientSideNavigation: false,\n elementFromPoint: false,\n customBreakpoints: true,\n siteVersions: true,\n unstable_siteVersions: true,\n localizedPageSSR: true,\n }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body))\n .with(apiRoutePattern, ([, res]) => res.json(body))\n .exhaustive()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0C;AAC1C,wBAAyB;AAwBzB,MAAM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B,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,KAAK,IAAI,CAAC,EACjD,WAAW;AAChB;","names":["body"]}
|
|
@@ -21,16 +21,27 @@ __export(merge_translated_data_exports, {
|
|
|
21
21
|
default: () => mergeTranslatedData
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(merge_translated_data_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
var import_server = require("next/server");
|
|
25
|
+
var import_ts_pattern = require("ts-pattern");
|
|
26
|
+
const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
27
|
+
const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
28
|
+
async function mergeTranslatedData(...args) {
|
|
29
|
+
const [, , client] = args;
|
|
30
|
+
const body = await (0, import_ts_pattern.match)(args).with(routeHandlerPattern, ([request]) => request.json()).with(apiRoutePattern, ([req]) => req.body).exhaustive();
|
|
31
|
+
const translatedData = body.translatedData;
|
|
32
|
+
const elementTree = body.elementTree;
|
|
27
33
|
if (translatedData == null) {
|
|
28
|
-
|
|
34
|
+
const status = 400;
|
|
35
|
+
const body2 = { message: "translatedData must be defined" };
|
|
36
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body2)).exhaustive();
|
|
29
37
|
}
|
|
30
38
|
if (elementTree == null) {
|
|
31
|
-
|
|
39
|
+
const status = 400;
|
|
40
|
+
const body2 = { message: "elementTree must be defined" };
|
|
41
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body2)).exhaustive();
|
|
32
42
|
}
|
|
33
43
|
const translatedElementTree = client.mergeTranslatedData(elementTree, translatedData);
|
|
34
|
-
|
|
44
|
+
const responseBody = { elementTree: translatedElementTree };
|
|
45
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(responseBody)).with(apiRoutePattern, ([, res]) => res.json(responseBody)).exhaustive();
|
|
35
46
|
}
|
|
36
47
|
//# sourceMappingURL=merge-translated-data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/merge-translated-data.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { Element } from '../../../state/react-page'\nimport { Makeswift } from '../../client'\n\ntype TranslatedDataResult = { elementTree: Element }\n\ntype TranslatedDataError = { message: string }\n\nexport type TranslatedDataResponse = TranslatedDataResult | TranslatedDataError\n\nexport default async function mergeTranslatedData(\n req: NextApiRequest,\n res: NextApiResponse<TranslatedDataResponse>,\n client: Makeswift,\n): Promise<void> {\n const
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/merge-translated-data.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { Element } from '../../../state/react-page'\nimport { Makeswift } from '../../client'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype TranslatedDataResult = { elementTree: Element }\n\ntype TranslatedDataError = { message: string }\n\nexport type TranslatedDataResponse = TranslatedDataResult | TranslatedDataError\n\ntype MergeTranslatedDataHandlerArgs =\n | [request: NextRequest, context: Context, client: Makeswift]\n | [req: NextApiRequest, res: NextApiResponse<TranslatedDataResponse>, client: Makeswift]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function mergeTranslatedData(\n request: NextRequest,\n context: Context,\n client: Makeswift,\n): Promise<NextResponse<TranslatedDataResponse>>\nexport default async function mergeTranslatedData(\n req: NextApiRequest,\n res: NextApiResponse<TranslatedDataResponse>,\n client: Makeswift,\n): Promise<void>\nexport default async function mergeTranslatedData(\n ...args: MergeTranslatedDataHandlerArgs\n): Promise<NextResponse<TranslatedDataResponse> | void> {\n const [, , client] = args\n\n const body = await match(args)\n .with(routeHandlerPattern, ([request]) => request.json())\n .with(apiRoutePattern, ([req]) => req.body)\n .exhaustive()\n\n const translatedData = body.translatedData\n const elementTree = body.elementTree\n\n if (translatedData == null) {\n const status = 400\n const body = { message: 'translatedData must be defined' }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n\n if (elementTree == null) {\n const status = 400\n const body = { message: 'elementTree must be defined' }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n\n const translatedElementTree = client.mergeTranslatedData(elementTree, translatedData)\n\n const responseBody = { elementTree: translatedElementTree }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(responseBody))\n .with(apiRoutePattern, ([, res]) => res.json(responseBody))\n .exhaustive()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA0C;AAC1C,wBAAyB;AAczB,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAY5C,eAAO,uBACF,MACmD;AACtD,QAAM,CAAC,EAAE,EAAE,MAAM,IAAI;AAErB,QAAM,OAAO,UAAM,yBAAM,IAAI,EAC1B,KAAK,qBAAqB,CAAC,CAAC,OAAO,MAAM,QAAQ,KAAK,CAAC,EACvD,KAAK,iBAAiB,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,EACzC,WAAW;AAEd,QAAM,iBAAiB,KAAK;AAC5B,QAAM,cAAc,KAAK;AAEzB,MAAI,kBAAkB,MAAM;AAC1B,UAAM,SAAS;AACf,UAAMA,QAAO,EAAE,SAAS,iCAAiC;AAEzD,eAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,MAAM,2BAAa,KAAKA,OAAM,EAAE,OAAO,CAAC,CAAC,EACnE,KAAK,iBAAiB,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,OAAO,MAAM,EAAE,KAAKA,KAAI,CAAC,EAChE,WAAW;AAAA,EAChB;AAEA,MAAI,eAAe,MAAM;AACvB,UAAM,SAAS;AACf,UAAMA,QAAO,EAAE,SAAS,8BAA8B;AAEtD,eAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,MAAM,2BAAa,KAAKA,OAAM,EAAE,OAAO,CAAC,CAAC,EACnE,KAAK,iBAAiB,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,OAAO,MAAM,EAAE,KAAKA,KAAI,CAAC,EAChE,WAAW;AAAA,EAChB;AAEA,QAAM,wBAAwB,OAAO,oBAAoB,aAAa,cAAc;AAEpF,QAAM,eAAe,EAAE,aAAa,sBAAsB;AAE1D,aAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,MAAM,2BAAa,KAAK,YAAY,CAAC,EAC/D,KAAK,iBAAiB,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,KAAK,YAAY,CAAC,EACzD,WAAW;AAChB;","names":["body"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var proxy_draft_mode_exports = {};
|
|
20
|
+
__export(proxy_draft_mode_exports, {
|
|
21
|
+
default: () => proxyDraftMode
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(proxy_draft_mode_exports);
|
|
24
|
+
var import_server = require("next/server");
|
|
25
|
+
var import_ts_pattern = require("ts-pattern");
|
|
26
|
+
var import_headers = require("next/headers");
|
|
27
|
+
var import_draft_mode = require("../../draft-mode");
|
|
28
|
+
var import_preview_mode = require("../../preview-mode");
|
|
29
|
+
const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
30
|
+
const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
31
|
+
async function proxyDraftMode(...args) {
|
|
32
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, (args2) => proxyDraftModeRouteHandler(...args2)).with(apiRoutePattern, (args2) => proxyDraftModeApiRouteHandler(...args2)).exhaustive();
|
|
33
|
+
}
|
|
34
|
+
async function proxyDraftModeRouteHandler(request, _context, { apiKey }) {
|
|
35
|
+
const secret = request.nextUrl.searchParams.get("x-makeswift-draft-mode") ?? request.headers.get("X-Makeswift-Draft-Mode");
|
|
36
|
+
if (secret !== apiKey)
|
|
37
|
+
return new import_server.NextResponse("Unauthorized", { status: 401 });
|
|
38
|
+
const draftModeData = {
|
|
39
|
+
makeswift: true,
|
|
40
|
+
siteVersion: import_preview_mode.MakeswiftSiteVersion.Working
|
|
41
|
+
};
|
|
42
|
+
(0, import_headers.draftMode)().enable();
|
|
43
|
+
const proxyUrl = request.nextUrl.clone();
|
|
44
|
+
proxyUrl.searchParams.delete("x-makeswift-draft-mode");
|
|
45
|
+
const proxyRequest = new import_server.NextRequest(proxyUrl, { headers: request.headers });
|
|
46
|
+
proxyRequest.headers.delete("x-makeswift-draft-mode");
|
|
47
|
+
const draftModeCookie = (0, import_headers.cookies)().get("__prerender_bypass");
|
|
48
|
+
if (draftModeCookie) {
|
|
49
|
+
proxyRequest.cookies.set(draftModeCookie);
|
|
50
|
+
proxyRequest.cookies.set(import_draft_mode.MAKESWIFT_DRAFT_MODE_DATA_COOKIE, JSON.stringify(draftModeData));
|
|
51
|
+
}
|
|
52
|
+
(0, import_headers.draftMode)().disable();
|
|
53
|
+
const proxyResponse = await fetch(proxyRequest);
|
|
54
|
+
const response = new import_server.NextResponse(proxyResponse.body, {
|
|
55
|
+
headers: proxyResponse.headers,
|
|
56
|
+
status: proxyResponse.status
|
|
57
|
+
});
|
|
58
|
+
if (response.headers.has("content-encoding")) {
|
|
59
|
+
response.headers.delete("content-encoding");
|
|
60
|
+
response.headers.delete("content-length");
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
}
|
|
64
|
+
async function proxyDraftModeApiRouteHandler(_req, res, {}) {
|
|
65
|
+
const message = "Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler to the `app` directory";
|
|
66
|
+
console.error(message);
|
|
67
|
+
return res.status(500).send(message);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=proxy-draft-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-draft-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { cookies, draftMode } from 'next/headers'\nimport { MAKESWIFT_DRAFT_MODE_DATA_COOKIE, MakeswiftDraftData } from '../../draft-mode'\nimport { MakeswiftSiteVersion } from '../../preview-mode'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyDraftModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyDraftModeResponse = ProxyDraftModeError | ProxyResponse\n\ntype ProxyDraftModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<ProxyDraftModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function proxyDraftMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>>\nexport default async function proxyDraftMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyDraftMode(\n ...args: ProxyDraftModeHandlerArgs\n): Promise<NextResponse<ProxyDraftModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyDraftModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyDraftModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyDraftModeRouteHandler(\n request: NextRequest,\n _context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>> {\n const secret =\n request.nextUrl.searchParams.get('x-makeswift-draft-mode') ??\n request.headers.get('X-Makeswift-Draft-Mode')\n\n if (secret !== apiKey) return new NextResponse('Unauthorized', { status: 401 })\n\n const draftModeData: MakeswiftDraftData = {\n makeswift: true,\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n draftMode().enable()\n\n const proxyUrl = request.nextUrl.clone()\n proxyUrl.searchParams.delete('x-makeswift-draft-mode')\n\n const proxyRequest = new NextRequest(proxyUrl, { headers: request.headers })\n proxyRequest.headers.delete('x-makeswift-draft-mode')\n\n const draftModeCookie = cookies().get('__prerender_bypass')\n if (draftModeCookie) {\n proxyRequest.cookies.set(draftModeCookie)\n proxyRequest.cookies.set(MAKESWIFT_DRAFT_MODE_DATA_COOKIE, JSON.stringify(draftModeData))\n }\n\n draftMode().disable()\n\n const proxyResponse = await fetch(proxyRequest)\n\n const response = new NextResponse<ProxyResponse>(proxyResponse.body, {\n headers: proxyResponse.headers,\n status: proxyResponse.status,\n })\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (response.headers.has('content-encoding')) {\n response.headers.delete('content-encoding')\n response.headers.delete('content-length')\n }\n\n return response\n}\n\nasync function proxyDraftModeApiRouteHandler(\n _req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n {}: { apiKey: string },\n): Promise<void> {\n const message =\n 'Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler to the `app` directory'\n console.error(message)\n return res.status(500).send(message)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0C;AAC1C,wBAAyB;AACzB,qBAAmC;AACnC,wBAAqE;AACrE,0BAAqC;AAcrC,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAY5C,eAAO,kBACF,MACmD;AACtD,aAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,CAAAA,UAAQ,2BAA2B,GAAGA,KAAI,CAAC,EACrE,KAAK,iBAAiB,CAAAA,UAAQ,8BAA8B,GAAGA,KAAI,CAAC,EACpE,WAAW;AAChB;AAEA,eAAe,2BACb,SACA,UACA,EAAE,OAAO,GACsC;AAC/C,QAAM,SACJ,QAAQ,QAAQ,aAAa,IAAI,wBAAwB,KACzD,QAAQ,QAAQ,IAAI,wBAAwB;AAE9C,MAAI,WAAW;AAAQ,WAAO,IAAI,2BAAa,gBAAgB,EAAE,QAAQ,IAAI,CAAC;AAE9E,QAAM,gBAAoC;AAAA,IACxC,WAAW;AAAA,IACX,aAAa,yCAAqB;AAAA,EACpC;AAEA,gCAAU,EAAE,OAAO;AAEnB,QAAM,WAAW,QAAQ,QAAQ,MAAM;AACvC,WAAS,aAAa,OAAO,wBAAwB;AAErD,QAAM,eAAe,IAAI,0BAAY,UAAU,EAAE,SAAS,QAAQ,QAAQ,CAAC;AAC3E,eAAa,QAAQ,OAAO,wBAAwB;AAEpD,QAAM,sBAAkB,wBAAQ,EAAE,IAAI,oBAAoB;AAC1D,MAAI,iBAAiB;AACnB,iBAAa,QAAQ,IAAI,eAAe;AACxC,iBAAa,QAAQ,IAAI,oDAAkC,KAAK,UAAU,aAAa,CAAC;AAAA,EAC1F;AAEA,gCAAU,EAAE,QAAQ;AAEpB,QAAM,gBAAgB,MAAM,MAAM,YAAY;AAE9C,QAAM,WAAW,IAAI,2BAA4B,cAAc,MAAM;AAAA,IACnE,SAAS,cAAc;AAAA,IACvB,QAAQ,cAAc;AAAA,EACxB,CAAC;AAOD,MAAI,SAAS,QAAQ,IAAI,kBAAkB,GAAG;AAC5C,aAAS,QAAQ,OAAO,kBAAkB;AAC1C,aAAS,QAAQ,OAAO,gBAAgB;AAAA,EAC1C;AAEA,SAAO;AACT;AAEA,eAAe,8BACb,MACA,KACA,CAAC,GACc;AACf,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,IAAI,OAAO,GAAG,EAAE,KAAK,OAAO;AACrC;","names":["args"]}
|
|
@@ -21,12 +21,37 @@ __export(proxy_preview_mode_exports, {
|
|
|
21
21
|
default: () => proxyPreviewMode
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(proxy_preview_mode_exports);
|
|
24
|
-
var import_cookie = require("cookie");
|
|
25
|
-
var import_http_proxy = require("http-proxy");
|
|
26
|
-
var import_set_cookie_parser = require("set-cookie-parser");
|
|
27
24
|
var import_preview_mode = require("../../preview-mode");
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
var import_server = require("next/server");
|
|
26
|
+
var import_ts_pattern = require("ts-pattern");
|
|
27
|
+
const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
28
|
+
const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
29
|
+
function mapRequestHeadersToHeaders(requestHeaders) {
|
|
30
|
+
const headers = new Headers();
|
|
31
|
+
Object.entries(requestHeaders).forEach(([key, value]) => {
|
|
32
|
+
(0, import_ts_pattern.match)(value).with(import_ts_pattern.P.array(import_ts_pattern.P.string), (value2) => value2.map((val) => headers.append(key, val))).with(import_ts_pattern.P.string, (value2) => headers.set(key, value2));
|
|
33
|
+
});
|
|
34
|
+
return headers;
|
|
35
|
+
}
|
|
36
|
+
function mapRequestToProxyUrl(req) {
|
|
37
|
+
const isForwardedProtoHttps = (0, import_ts_pattern.match)(req.headers["X-Forwarded-Proto"]).with(import_ts_pattern.P.string, (x) => x.split(",")).with(import_ts_pattern.P.array(import_ts_pattern.P.string), (x) => x).otherwise(() => []).includes("https");
|
|
38
|
+
const isForwardedSSL = (0, import_ts_pattern.match)(req.headers["X-Forwarded-SSL"]).with("on", () => true).otherwise(() => false);
|
|
39
|
+
const proto = isForwardedProtoHttps || isForwardedSSL ? "https" : "http";
|
|
40
|
+
return new URL(`${proto}://${req.headers.host}${req.url}`);
|
|
41
|
+
}
|
|
42
|
+
async function proxyPreviewMode(...args) {
|
|
43
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, (args2) => proxyPreviewModeRouteHandler(...args2)).with(apiRoutePattern, (args2) => proxyPreviewModeApiRouteHandler(...args2)).exhaustive();
|
|
44
|
+
}
|
|
45
|
+
async function proxyPreviewModeRouteHandler(_request, _context, {}) {
|
|
46
|
+
const message = "Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory";
|
|
47
|
+
console.error(message);
|
|
48
|
+
return import_server.NextResponse.json(message, { status: 500 });
|
|
49
|
+
}
|
|
50
|
+
async function proxyPreviewModeApiRouteHandler(req, res, { apiKey }) {
|
|
51
|
+
if (req.query.secret !== apiKey)
|
|
52
|
+
return res.status(401).send("Unauthorized");
|
|
53
|
+
if (req.headers.host == null)
|
|
54
|
+
return res.status(400).send("Bad Request");
|
|
30
55
|
const NextRequestMetaSymbol = Reflect.ownKeys(req).find(
|
|
31
56
|
(key) => key.toString() === "Symbol(NextRequestMeta)" || key.toString() === "Symbol(NextInternalRequestMeta)"
|
|
32
57
|
);
|
|
@@ -40,50 +65,36 @@ async function proxyPreviewMode(req, res, { apiKey }) {
|
|
|
40
65
|
} catch {
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
proxyReq.path = url.pathname + url.search;
|
|
50
|
-
});
|
|
51
|
-
if (req.query.secret !== apiKey)
|
|
52
|
-
return res.status(401).send("Unauthorized");
|
|
53
|
-
const host = req.headers.host;
|
|
54
|
-
const originalCookies = req.headers.cookie;
|
|
55
|
-
if (host == null)
|
|
56
|
-
return res.status(400).send("Bad Request");
|
|
57
|
-
const forwardedProtoHeader = req.headers["x-forwarded-proto"];
|
|
58
|
-
let forwardedProto = [];
|
|
59
|
-
if (Array.isArray(forwardedProtoHeader)) {
|
|
60
|
-
forwardedProto = forwardedProtoHeader;
|
|
61
|
-
} else if (typeof forwardedProtoHeader === "string") {
|
|
62
|
-
forwardedProto = forwardedProtoHeader.split(",");
|
|
63
|
-
}
|
|
64
|
-
const isForwardedProtoHttps = forwardedProto.includes("https");
|
|
65
|
-
const forwardedSSL = req.headers["x-forwarded-ssl"];
|
|
66
|
-
const isForwardedSSL = typeof forwardedSSL === "string" && forwardedSSL === "on";
|
|
67
|
-
const proto = isForwardedProtoHttps || isForwardedSSL ? "https" : "http";
|
|
68
|
-
let target = `${proto}://${host}`;
|
|
69
|
-
const secure = process.env["NODE_ENV"] === "production";
|
|
68
|
+
const proxyHeaders = mapRequestHeadersToHeaders(req.headers);
|
|
69
|
+
const proxyUrl = mapRequestToProxyUrl(req);
|
|
70
|
+
proxyUrl.searchParams.delete("x-makeswift-preview-mode");
|
|
71
|
+
proxyHeaders.delete("x-makeswift-preview-mode");
|
|
72
|
+
proxyHeaders.delete("x-invoke-path");
|
|
73
|
+
proxyHeaders.delete("x-invoke-query");
|
|
70
74
|
const previewData = {
|
|
71
75
|
makeswift: true,
|
|
76
|
+
// This will eventually be dynamic
|
|
72
77
|
siteVersion: import_preview_mode.MakeswiftSiteVersion.Working
|
|
73
78
|
};
|
|
74
|
-
const setCookie = res.setPreviewData(previewData).getHeader("
|
|
75
|
-
res.removeHeader("
|
|
79
|
+
const setCookie = res.setPreviewData(previewData).getHeader("set-cookie");
|
|
80
|
+
res.removeHeader("set-cookie");
|
|
76
81
|
if (!Array.isArray(setCookie))
|
|
77
82
|
return res.status(500).send("Internal Server Error");
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
83
|
+
setCookie.forEach((cookie) => proxyHeaders.append("cookie", cookie));
|
|
84
|
+
const response = await fetch(proxyUrl, {
|
|
85
|
+
headers: proxyHeaders
|
|
86
|
+
});
|
|
87
|
+
response.headers.forEach((value, name) => {
|
|
88
|
+
res.setHeader(name, value);
|
|
89
|
+
});
|
|
90
|
+
res.statusCode = response.status;
|
|
91
|
+
res.statusMessage = response.statusText;
|
|
92
|
+
if (res.hasHeader("content-encoding")) {
|
|
93
|
+
res.removeHeader("content-encoding");
|
|
94
|
+
res.removeHeader("content-length");
|
|
95
|
+
}
|
|
96
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
97
|
+
res.write(arrayBuffer);
|
|
98
|
+
res.end();
|
|
88
99
|
}
|
|
89
100
|
//# sourceMappingURL=proxy-preview-mode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-preview-mode.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-preview-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { MakeswiftPreviewData, MakeswiftSiteVersion } from '../../preview-mode'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyPreviewModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyPreviewModeResponse = ProxyPreviewModeError | ProxyResponse\n\ntype ProxyPreviewModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n params: { apiKey: string },\n ]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nfunction mapRequestHeadersToHeaders(requestHeaders: NextApiRequest['headers']): Headers {\n const headers = new Headers()\n\n Object.entries(requestHeaders).forEach(([key, value]) => {\n match(value)\n .with(P.array(P.string), value => value.map(val => headers.append(key, val)))\n .with(P.string, value => headers.set(key, value))\n })\n\n return headers\n}\n\nfunction mapRequestToProxyUrl(req: NextApiRequest): URL {\n const isForwardedProtoHttps = match(req.headers['X-Forwarded-Proto'])\n .with(P.string, x => x.split(','))\n .with(P.array(P.string), x => x)\n .otherwise(() => [])\n .includes('https')\n\n const isForwardedSSL = match(req.headers['X-Forwarded-SSL'])\n .with('on', () => true)\n .otherwise(() => false)\n\n const proto = isForwardedProtoHttps || isForwardedSSL ? 'https' : 'http'\n\n return new URL(`${proto}://${req.headers.host}${req.url}`)\n}\n\nexport default async function proxyPreviewMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>>\nexport default async function proxyPreviewMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyPreviewMode(\n ...args: ProxyPreviewModeHandlerArgs\n): Promise<NextResponse<ProxyPreviewModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyPreviewModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyPreviewModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyPreviewModeRouteHandler(\n _request: NextRequest,\n _context: Context,\n {}: { apiKey: string },\n): Promise<NextResponse<ProxyPreviewModeResponse>> {\n const message =\n 'Cannot request preview endpoint from an API handler registered in `app`. Move your Makeswift API handler to the `pages/api` directory'\n console.error(message)\n return NextResponse.json(message, { status: 500 })\n}\n\nasync function proxyPreviewModeApiRouteHandler(\n req: NextApiRequest,\n res: NextApiResponse<ProxyPreviewModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n if (req.query.secret !== apiKey) return res.status(401).send('Unauthorized')\n if (req.headers.host == null) return res.status(400).send('Bad Request')\n\n // TODO: This is a hack to get the locale from the request.\n // Next.js strips the locale from the req.url, and there's no official way to get the locale\n // from an API route: https://github.com/vercel/next.js/discussions/21798.\n // The current workaround is to get the locale from an internal object: RequestMeta,\n // https://github.com/vercel/next.js/blob/a0d1d728b9003f12c9df6c5e9a33bc4c33cef0ab/packages/next/src/server/request-meta.ts\n // One possible way to properly fix this is by updating how we do preview mode. For example,\n // by using partitioned cookies instead of a proxy.\n const NextRequestMetaSymbol = Reflect.ownKeys(req).find(\n key =>\n key.toString() === 'Symbol(NextRequestMeta)' ||\n key.toString() === 'Symbol(NextInternalRequestMeta)',\n ) as keyof NextApiRequest | undefined\n\n if (NextRequestMetaSymbol) {\n const nextRequestMeta = req[NextRequestMetaSymbol]\n const initUrl = nextRequestMeta?.__NEXT_INIT_URL ?? nextRequestMeta?.initURL\n const isLocaleStripped =\n nextRequestMeta?.__nextStrippedLocale ?? nextRequestMeta?.didStripLocale\n\n try {\n if (isLocaleStripped && initUrl) req.url = new URL(initUrl).pathname\n } catch {}\n }\n\n const proxyHeaders = mapRequestHeadersToHeaders(req.headers)\n const proxyUrl = mapRequestToProxyUrl(req)\n\n proxyUrl.searchParams.delete('x-makeswift-preview-mode')\n proxyHeaders.delete('x-makeswift-preview-mode')\n // The following headers are Next.js-specific and are removed to prevent Next.js from\n // short-circuiting requests, breaking routing.\n proxyHeaders.delete('x-invoke-path')\n proxyHeaders.delete('x-invoke-query')\n\n const previewData: MakeswiftPreviewData = {\n makeswift: true,\n // This will eventually be dynamic\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const setCookie = res.setPreviewData(previewData).getHeader('set-cookie')\n res.removeHeader('set-cookie')\n\n if (!Array.isArray(setCookie)) return res.status(500).send('Internal Server Error')\n\n setCookie.forEach((cookie) => proxyHeaders.append('cookie', cookie))\n\n const response = await fetch(proxyUrl, {\n headers: proxyHeaders,\n });\n\n response.headers.forEach((value, name) => {\n res.setHeader(name, value);\n })\n\n res.statusCode = response.status;\n res.statusMessage = response.statusText\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (res.hasHeader('content-encoding')) {\n res.removeHeader('content-encoding')\n res.removeHeader('content-length')\n }\n\n const arrayBuffer = await response.arrayBuffer()\n\n res.write(arrayBuffer)\n res.end()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAA2D;AAC3D,oBAA0C;AAC1C,wBAAyB;AAkBzB,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;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QAAI,UAAU,MAAM,KAAK;AAAA,EAC3B,CAAC;AAED,MAAI,aAAa,SAAS;AAC1B,MAAI,gBAAgB,SAAS;AAO7B,MAAI,IAAI,UAAU,kBAAkB,GAAG;AACrC,QAAI,aAAa,kBAAkB;AACnC,QAAI,aAAa,gBAAgB;AAAA,EACnC;AAEA,QAAM,cAAc,MAAM,SAAS,YAAY;AAE/C,MAAI,MAAM,WAAW;AACrB,MAAI,IAAI;AACV;","names":["value","args"]}
|
|
@@ -32,28 +32,39 @@ __export(revalidate_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(revalidate_exports);
|
|
34
34
|
var import_isErrorWithMessage = __toESM(require("../../../utils/isErrorWithMessage"));
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
var import_server = require("next/server");
|
|
36
|
+
var import_ts_pattern = require("ts-pattern");
|
|
37
|
+
var import_cache = require("next/cache");
|
|
38
|
+
const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
39
|
+
const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
40
|
+
async function revalidate(...args) {
|
|
41
|
+
const [, , { apiKey }] = args;
|
|
42
|
+
const secret = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, ([request]) => request.nextUrl.searchParams.get("secret")).with(apiRoutePattern, ([req]) => req.query.secret).exhaustive();
|
|
43
|
+
if (secret !== apiKey) {
|
|
44
|
+
const body = { message: "Unauthorized" };
|
|
45
|
+
const status = 401;
|
|
46
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body)).exhaustive();
|
|
38
47
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const message = `Cannot revalidate path "${req.query.path}" because \`revalidate\` function does not exist in API handler response. Please update to Next.js v12.2.0 or higher for support for on-demand revalidation.
|
|
45
|
-
Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-regeneration-stable`;
|
|
46
|
-
console.warn(message);
|
|
47
|
-
return res.json({ revalidated: false });
|
|
48
|
+
const path = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, ([request]) => request.nextUrl.searchParams.get("path")).with(apiRoutePattern, ([req]) => req.query.path).exhaustive();
|
|
49
|
+
if (typeof path !== "string") {
|
|
50
|
+
const status = 400;
|
|
51
|
+
const body = { message: "Bad Request" };
|
|
52
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body)).exhaustive();
|
|
48
53
|
}
|
|
54
|
+
const revalidate2 = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_cache.revalidatePath).with(apiRoutePattern, ([, res]) => res.revalidate).exhaustive();
|
|
49
55
|
try {
|
|
50
|
-
await revalidate2(
|
|
51
|
-
|
|
56
|
+
await revalidate2(path);
|
|
57
|
+
const body = { revalidated: true };
|
|
58
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body)).with(apiRoutePattern, ([, res]) => res.json(body)).exhaustive();
|
|
52
59
|
} catch (error) {
|
|
53
60
|
if ((0, import_isErrorWithMessage.default)(error)) {
|
|
54
|
-
|
|
61
|
+
const status2 = 500;
|
|
62
|
+
const body2 = { message: error.message };
|
|
63
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2, { status: status2 })).with(apiRoutePattern, ([, res]) => res.status(status2).json(body2)).exhaustive();
|
|
55
64
|
}
|
|
56
|
-
|
|
65
|
+
const status = 500;
|
|
66
|
+
const body = { message: "Error Revalidating" };
|
|
67
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body)).exhaustive();
|
|
57
68
|
}
|
|
58
69
|
}
|
|
59
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/revalidate.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport isErrorWithMessage from '../../../utils/isErrorWithMessage'\n\ntype RevalidationResult = { revalidated: boolean }\n\ntype RevalidationError = { message: string }\n\nexport type RevalidationResponse = RevalidationResult | RevalidationError\n\nexport async function revalidate(\n req: NextApiRequest,\n res: NextApiResponse<RevalidationResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void> {\n
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/handlers/revalidate.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport isErrorWithMessage from '../../../utils/isErrorWithMessage'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { revalidatePath } from 'next/cache'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype RevalidationResult = { revalidated: boolean }\n\ntype RevalidationError = { message: string }\n\nexport type RevalidationResponse = RevalidationResult | RevalidationError\n\ntype RevalidateHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<RevalidationResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport async function revalidate(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<RevalidationResponse>>\nexport async function revalidate(\n req: NextApiRequest,\n res: NextApiResponse<RevalidationResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport async function revalidate(\n ...args: RevalidateHandlerArgs\n): Promise<NextResponse<RevalidationResponse> | void> {\n const [, , { apiKey }] = args\n\n const secret = match(args)\n .with(routeHandlerPattern, ([request]) => request.nextUrl.searchParams.get('secret'))\n .with(apiRoutePattern, ([req]) => req.query.secret)\n .exhaustive()\n\n if (secret !== apiKey) {\n const body = { message: 'Unauthorized' }\n const status = 401\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n\n const path = match(args)\n .with(routeHandlerPattern, ([request]) => request.nextUrl.searchParams.get('path'))\n .with(apiRoutePattern, ([req]) => req.query.path)\n .exhaustive()\n\n if (typeof path !== 'string') {\n const status = 400\n const body = { message: 'Bad Request' }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n\n const revalidate = match(args)\n .with(routeHandlerPattern, () => revalidatePath)\n .with(apiRoutePattern, ([, res]) => res.revalidate)\n .exhaustive()\n\n try {\n await revalidate(path)\n\n const body = { revalidated: true }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body))\n .with(apiRoutePattern, ([, res]) => res.json(body))\n .exhaustive()\n } catch (error) {\n if (isErrorWithMessage(error)) {\n const status = 500\n const body = { message: error.message }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n\n const status = 500\n const body = { message: 'Error Revalidating' }\n\n return match(args)\n .with(routeHandlerPattern, () => NextResponse.json(body, { status }))\n .with(apiRoutePattern, ([, res]) => res.status(status).json(body))\n .exhaustive()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gCAA+B;AAC/B,oBAA0C;AAC1C,wBAAyB;AACzB,mBAA+B;AAc/B,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,K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A,YAAW,IAAI;AAErB,UAAM,OAAO,EAAE,aAAa,KAAK;AAEjC,eAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,MAAM,2BAAa,KAAK,IAAI,CAAC,EACvD,KAAK,iBAAiB,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,KAAK,IAAI,CAAC,EACjD,WAAW;AAAA,EAChB,SAAS,OAAO;AACd,YAAI,0BAAAC,SAAmB,KAAK,GAAG;AAC7B,YAAMC,UAAS;AACf,YAAMC,QAAO,EAAE,SAAS,MAAM,QAAQ;AAEtC,iBAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,MAAM,2BAAa,KAAKA,OAAM,EAAE,QAAAD,QAAO,CAAC,CAAC,EACnE,KAAK,iBAAiB,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,OAAOA,OAAM,EAAE,KAAKC,KAAI,CAAC,EAChE,WAAW;AAAA,IAChB;AAEA,UAAM,SAAS;AACf,UAAM,OAAO,EAAE,SAAS,qBAAqB;AAE7C,eAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,MAAM,2BAAa,KAAK,MAAM,EAAE,OAAO,CAAC,CAAC,EACnE,KAAK,iBAAiB,CAAC,CAAC,EAAE,GAAG,MAAM,IAAI,OAAO,MAAM,EAAE,KAAK,IAAI,CAAC,EAChE,WAAW;AAAA,EAChB;AACF;","names":["revalidate","isErrorWithMessage","status","body"]}
|
|
@@ -21,16 +21,27 @@ __export(translatable_data_exports, {
|
|
|
21
21
|
default: () => translatableData
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(translatable_data_exports);
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
var import_server = require("next/server");
|
|
25
|
+
var import_ts_pattern = require("ts-pattern");
|
|
26
|
+
const routeHandlerPattern = [import_ts_pattern.P.instanceOf(Request), import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
27
|
+
const apiRoutePattern = [import_ts_pattern.P.any, import_ts_pattern.P.any, import_ts_pattern.P.any];
|
|
28
|
+
async function translatableData(...args) {
|
|
29
|
+
const [, , client] = args;
|
|
30
|
+
const body = await (0, import_ts_pattern.match)(args).with(routeHandlerPattern, ([request]) => request.json()).with(apiRoutePattern, ([req]) => req.body).exhaustive();
|
|
31
|
+
const elementTree = body.elementTree;
|
|
26
32
|
if (elementTree == null) {
|
|
27
|
-
|
|
33
|
+
const status = 400;
|
|
34
|
+
const body2 = { message: "elementTree must be defined." };
|
|
35
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body2)).exhaustive();
|
|
28
36
|
}
|
|
29
37
|
try {
|
|
30
38
|
let translatableData2 = client.getTranslatableData(elementTree);
|
|
31
|
-
|
|
39
|
+
const body2 = { translatableData: translatableData2 };
|
|
40
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2)).with(apiRoutePattern, ([, res]) => res.json(body2)).exhaustive();
|
|
32
41
|
} catch (error) {
|
|
33
|
-
|
|
42
|
+
const status = 500;
|
|
43
|
+
const body2 = { message: "Failed to get traslatable data." };
|
|
44
|
+
return (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => import_server.NextResponse.json(body2, { status })).with(apiRoutePattern, ([, res]) => res.status(status).json(body2)).exhaustive();
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
47
|
//# sourceMappingURL=translatable-data.js.map
|