@wpnuxt/core 1.0.0-edge.9 → 2.0.0-alpha.2

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 (69) hide show
  1. package/dist/client-options.d.mts +1 -0
  2. package/dist/client-options.d.ts +1 -0
  3. package/dist/client-options.mjs +1 -0
  4. package/dist/module.d.mts +72 -82
  5. package/dist/module.d.ts +72 -82
  6. package/dist/module.json +4 -5
  7. package/dist/module.mjs +601 -271
  8. package/dist/runtime/app/graphqlMiddleware.clientOptions.d.ts +0 -0
  9. package/dist/runtime/app/graphqlMiddleware.clientOptions.js +12 -0
  10. package/dist/runtime/components/WPNuxtLogo.d.vue.ts +0 -0
  11. package/dist/runtime/components/WPNuxtLogo.vue +7 -7
  12. package/dist/runtime/components/WPNuxtLogo.vue.d.ts +0 -0
  13. package/dist/runtime/composables/useWPContent.d.ts +0 -5
  14. package/dist/runtime/composables/useWPContent.js +30 -16
  15. package/dist/runtime/plugins/graphqlConfig.d.ts +0 -0
  16. package/dist/runtime/plugins/graphqlConfig.js +17 -0
  17. package/dist/runtime/plugins/graphqlErrors.d.ts +0 -0
  18. package/dist/runtime/plugins/graphqlErrors.js +9 -0
  19. package/dist/runtime/queries/GeneralSettings.gql +0 -2
  20. package/dist/runtime/queries/Menu.gql +0 -2
  21. package/dist/runtime/queries/Node.gql +0 -3
  22. package/dist/runtime/queries/Pages.gql +0 -2
  23. package/dist/runtime/queries/Posts.gql +15 -2
  24. package/dist/runtime/queries/Viewer.gql +4 -4
  25. package/dist/runtime/queries/fragments/GeneralSettings.fragment.gql +0 -1
  26. package/dist/runtime/queries/fragments/NodeWithFeaturedImage.fragment.gql +0 -2
  27. package/dist/runtime/queries/fragments/NodeWithFeaturedImageToMediaItemConnectionEdge.fragment.gql +0 -2
  28. package/dist/runtime/queries/fragments/Page.fragment.gql +0 -4
  29. package/dist/runtime/queries/fragments/Post.fragment.gql +8 -5
  30. package/dist/runtime/server/graphqlMiddleware.serverOptions.d.ts +0 -0
  31. package/dist/runtime/server/graphqlMiddleware.serverOptions.js +18 -0
  32. package/dist/runtime/server/tsconfig.json +3 -0
  33. package/dist/runtime/types/stub.d.ts +22 -0
  34. package/dist/runtime/util/images.d.ts +0 -2
  35. package/dist/runtime/util/images.js +11 -3
  36. package/dist/server-options.d.mts +2 -0
  37. package/dist/server-options.d.ts +2 -0
  38. package/dist/server-options.mjs +1 -0
  39. package/dist/types.d.mts +2 -2
  40. package/package.json +50 -79
  41. package/README.md +0 -80
  42. package/dist/module.cjs +0 -5
  43. package/dist/runtime/app/graphqlMiddleware.serverOptions.d.ts +0 -2
  44. package/dist/runtime/app/graphqlMiddleware.serverOptions.js +0 -11
  45. package/dist/runtime/components/StagingBanner.vue +0 -107
  46. package/dist/runtime/components/WordPressLogo.vue +0 -15
  47. package/dist/runtime/composables/index.d.ts +0 -3
  48. package/dist/runtime/composables/index.js +0 -3
  49. package/dist/runtime/composables/isStaging.d.ts +0 -1
  50. package/dist/runtime/composables/isStaging.js +0 -6
  51. package/dist/runtime/composables/useFeaturedImage.d.ts +0 -2
  52. package/dist/runtime/composables/useFeaturedImage.js +0 -7
  53. package/dist/runtime/composables/usePrevNextPost.d.ts +0 -4
  54. package/dist/runtime/composables/usePrevNextPost.js +0 -25
  55. package/dist/runtime/composables/useWPUri.d.ts +0 -8
  56. package/dist/runtime/composables/useWPUri.js +0 -23
  57. package/dist/runtime/plugins/vue-sanitize-directive.d.ts +0 -2
  58. package/dist/runtime/plugins/vue-sanitize-directive.js +0 -5
  59. package/dist/runtime/server/api/purgeCache.get.d.ts +0 -5
  60. package/dist/runtime/server/api/purgeCache.get.js +0 -9
  61. package/dist/runtime/server/api/wpContent.post.d.ts +0 -9
  62. package/dist/runtime/server/api/wpContent.post.js +0 -50
  63. package/dist/runtime/server/index.d.ts +0 -1
  64. package/dist/runtime/server/index.js +0 -8
  65. package/dist/runtime/server/storage.d.ts +0 -3
  66. package/dist/runtime/server/storage.js +0 -11
  67. package/dist/runtime/util/logger.d.ts +0 -3
  68. package/dist/runtime/util/logger.js +0 -25
  69. package/dist/types.d.ts +0 -7
@@ -1,107 +0,0 @@
1
- <script setup lang="ts">
2
- import { useWPUri } from '../composables/useWPUri'
3
- import { useWPContent } from '../composables'
4
- import WPNuxtLogo from './WPNuxtLogo.vue'
5
- import WordPressLogo from './WordPressLogo.vue'
6
- import { useRuntimeConfig, useHead, useRoute } from '#imports'
7
-
8
- const config = useRuntimeConfig()
9
- const frontendUrl = config.public.wpNuxt.frontendUrl
10
- const wordpressUrl = config.public.wpNuxt.wordpressUrl
11
- const wpUri = useWPUri()
12
- useHead({
13
- title: 'Staging',
14
- link: [
15
- {
16
- type: 'stylesheet',
17
- href: wordpressUrl + '/wp-admin/load-styles.php?c=0&dir=ltr&load%5Bchunk_0%5D=dashicons,admin-bar,site-health,common,forms,admin-menu,dashboard,list-tables,edit,revisions,media,themes,about,nav-menus,wp-poi&load%5Bchunk_1%5D=nter,widgets,site-icon,l10n,buttons,wp-auth-check&ver=6.4.3'
18
- }
19
- ]
20
- })
21
-
22
- const route = useRoute()
23
- let uri = route.path === '/' ? 'home' : route.path
24
- if (uri.startsWith('/')) {
25
- uri = uri.substring(1)
26
- }
27
- if (uri.endsWith('/')) {
28
- uri = uri.substring(0, uri.length - 1)
29
- }
30
- const { data: post } = await useWPContent('NodeByUri', ['nodeByUri'], false, { uri: uri })
31
-
32
- if (import.meta.client) {
33
- document.body.style.marginBottom = '40px'
34
- }
35
- </script>
36
-
37
- <template>
38
- <div id="wpNuxtStagingBar">
39
- <div class="bar-container">
40
- <div class="bar-left">
41
- <WPNuxtLogo wp-color="white" />
42
- <div class="bar-button-wrapper">
43
- <NuxtLink
44
- :to="wpUri.admin"
45
- class="bar-button"
46
- >
47
- <WordPressLogo /> Admin
48
- </NuxtLink>
49
- </div>
50
- <div
51
- v-if="post"
52
- class="bar-button-wrapper"
53
- >
54
- <NuxtLink
55
- :to="wpUri.postEdit('' + post.databaseId)"
56
- class="bar-button primary"
57
- >
58
- <svg
59
- class="icon"
60
- xmlns="http://www.w3.org/2000/svg"
61
- viewBox="0 0 24 24"
62
- width="24"
63
- height="24"
64
- >
65
- <path
66
- fill="none"
67
- stroke-linecap="round"
68
- stroke-linejoin="round"
69
- stroke-width="1.5"
70
- d="m16.862 4.487l1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L6.832 19.82a4.5 4.5 0 0 1-1.897 1.13l-2.685.8l.8-2.685a4.5 4.5 0 0 1 1.13-1.897zm0 0L19.5 7.125"
71
- />
72
- </svg>
73
- Edit <span class="hidden sm:inline-flex">{{ post.contentTypeName }}</span>
74
- </NuxtLink>
75
- </div>
76
- </div>
77
- <div class="bar-right">
78
- <div class="bar-button-wrapper">
79
- <NuxtLink
80
- v-if="frontendUrl"
81
- :to="frontendUrl"
82
- class="bar-button"
83
- target="_blank"
84
- >
85
- Live site
86
- <svg
87
- class="icon"
88
- xmlns="http://www.w3.org/2000/svg"
89
- viewBox="0 0 24 24"
90
- width="24"
91
- height="24"
92
- >
93
- <path
94
- fill="black"
95
- d="M18 10.82a1 1 0 0 0-1 1V19a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8a1 1 0 0 1 1-1h7.18a1 1 0 0 0 0-2H5a3 3 0 0 0-3 3v11a3 3 0 0 0 3 3h11a3 3 0 0 0 3-3v-7.18a1 1 0 0 0-1-1m3.92-8.2a1 1 0 0 0-.54-.54A1 1 0 0 0 21 2h-6a1 1 0 0 0 0 2h3.59L8.29 14.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0L20 5.41V9a1 1 0 0 0 2 0V3a1 1 0 0 0-.08-.38"
96
- />
97
- </svg>
98
- </NuxtLink>
99
- </div>
100
- </div>
101
- </div>
102
- </div>
103
- </template>
104
-
105
- <style scoped>
106
- #wpNuxtStagingBar{background-color:#171717;height:40px;width:100%;--tw-shadow:0 -1px 10px -3px rgb(0,0,0,0.3);--tw-shadow-colored:0 -1px 10px -3px var(--tw-shadow-color);bottom:0;box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow);left:0;position:fixed;right:0;z-index:9999}#wpNuxtStagingBar .bar-container{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));margin-left:auto;margin-right:auto;max-width:80rem;padding:7px}#wpNuxtStagingBar .bar-left{text-align:left}#wpNuxtStagingBar .bar-left,#wpNuxtStagingBar .bar-right{display:flex;flex-grow:1;overflow:hidden;vertical-align:top}#wpNuxtStagingBar .bar-right{flex:none;justify-content:flex-end;text-align:right}.wpnuxt-logo{margin-right:1.5rem}.wordpress-logo{height:1rem;width:1rem}.bar-button{--tw-ring-color:#ccc;--tw-ring-inset:inset;--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000);--tw-text-opacity:1;align-items:center;background-color:#eee;border-radius:.375rem;color:#000;-moz-column-gap:.25rem;column-gap:.25rem;display:inline-flex;flex-shrink:0;font-size:.75rem;font-weight:500;line-height:1rem;margin-right:.5rem;padding:.25rem .5rem;stroke:#000;text-decoration:none}.bar-button:hover{--tw-ring-color:#999;background-color:#aaa;text-decoration:none}.bar-button.primary{--tw-ring-color:#999;background-color:rgb(186 175 78/var(--tw-text-opacity))}.bar-button.primary:hover{color:#fff;stroke:#fff;--tw-ring-color:#666;background-color:rgb(156 142 27/var(--tw-text-opacity));text-decoration:none}.bar-button-wrapper{display:inline-block;margin-top:.25rem;vertical-align:top}.icon{background-color:transparent;display:inline-block;height:1em;width:1em}
107
- </style>
@@ -1,15 +0,0 @@
1
- <template>
2
- <svg
3
- class="wordpress-logo"
4
- viewBox="0 0 122.52 122.523"
5
- xmlns="http://www.w3.org/2000/svg"
6
- >
7
- <g fill="black">
8
- <path d="m8.708 61.26c0 20.802 12.089 38.779 29.619 47.298l-25.069-68.686c-2.916 6.536-4.55 13.769-4.55 21.388z" />
9
- <path d="m96.74 58.608c0-6.495-2.333-10.993-4.334-14.494-2.664-4.329-5.161-7.995-5.161-12.324 0-4.831 3.664-9.328 8.825-9.328.233 0 .454.029.681.042-9.35-8.566-21.807-13.796-35.489-13.796-18.36 0-34.513 9.42-43.91 23.688 1.233.037 2.395.063 3.382.063 5.497 0 14.006-.667 14.006-.667 2.833-.167 3.167 3.994.337 4.329 0 0-2.847.335-6.015.501l19.138 56.925 11.501-34.493-8.188-22.434c-2.83-.166-5.511-.501-5.511-.501-2.832-.166-2.5-4.496.332-4.329 0 0 8.679.667 13.843.667 5.496 0 14.006-.667 14.006-.667 2.835-.167 3.168 3.994.337 4.329 0 0-2.853.335-6.015.501l18.992 56.494 5.242-17.517c2.272-7.269 4.001-12.49 4.001-16.989z" />
10
- <path d="m62.184 65.857-15.768 45.819c4.708 1.384 9.687 2.141 14.846 2.141 6.12 0 11.989-1.058 17.452-2.979-.141-.225-.269-.464-.374-.724z" />
11
- <path d="m107.376 36.046c.226 1.674.354 3.471.354 5.404 0 5.333-.996 11.328-3.996 18.824l-16.053 46.413c15.624-9.111 26.133-26.038 26.133-45.426.001-9.137-2.333-17.729-6.438-25.215z" />
12
- <path d="m61.262 0c-33.779 0-61.262 27.481-61.262 61.26 0 33.783 27.483 61.263 61.262 61.263 33.778 0 61.265-27.48 61.265-61.263-.001-33.779-27.487-61.26-61.265-61.26zm0 119.715c-32.23 0-58.453-26.223-58.453-58.455 0-32.23 26.222-58.451 58.453-58.451 32.229 0 58.45 26.221 58.45 58.451 0 32.232-26.221 58.455-58.45 58.455z" />
13
- </g>
14
- </svg>
15
- </template>
@@ -1,3 +0,0 @@
1
- export { isStaging } from './isStaging.js';
2
- export { useWPContent } from './useWPContent.js';
3
- export { useWPUri } from './useWPUri.js';
@@ -1,3 +0,0 @@
1
- export { isStaging } from "./isStaging.js";
2
- export { useWPContent } from "./useWPContent.js";
3
- export { useWPUri } from "./useWPUri.js";
@@ -1 +0,0 @@
1
- export declare const isStaging: () => Promise<any>;
@@ -1,6 +0,0 @@
1
- import { useRuntimeConfig } from "#imports";
2
- const _isStaging = async () => {
3
- const config = useRuntimeConfig();
4
- return config.public.wpNuxt.staging;
5
- };
6
- export const isStaging = _isStaging;
@@ -1,2 +0,0 @@
1
- import type { Post, Page } from '#graphql-operations';
2
- export declare const useFeaturedImage: (contentNode: Post | Page) => string | undefined;
@@ -1,7 +0,0 @@
1
- import { getRelativeImagePath } from "../util/images.js";
2
- const _useFeaturedImage = (contentNode) => {
3
- const sourceUrl = contentNode?.featuredImage?.node?.sourceUrl;
4
- if (sourceUrl) return getRelativeImagePath(sourceUrl);
5
- else return void 0;
6
- };
7
- export const useFeaturedImage = _useFeaturedImage;
@@ -1,4 +0,0 @@
1
- export declare const usePrevNextPost: (currentPostSlug: string) => Promise<{
2
- prev: any;
3
- next: any;
4
- }>;
@@ -1,25 +0,0 @@
1
- import { useWPContent } from "./useWPContent.js";
2
- const _usePrevNextPost = async (currentPostSlug) => {
3
- const allPosts = await getAllPosts();
4
- if (!allPosts) return { prev: null, next: null };
5
- const currentIndex = allPosts.slugs.findIndex((slug) => slug === currentPostSlug);
6
- const nextPost = currentIndex > 0 ? allPosts.slugs[currentIndex - 1] : null;
7
- const prevPost = allPosts.slugs.length > currentIndex + 1 ? allPosts.slugs[currentIndex + 1] : null;
8
- return {
9
- prev: prevPost ? prevPost : null,
10
- next: nextPost ? nextPost : null
11
- };
12
- };
13
- const getAllPosts = async () => {
14
- const { data: allPosts } = await useWPContent("Posts", ["posts", "nodes"], false);
15
- if (allPosts) {
16
- return {
17
- slugs: allPosts?.map((post) => {
18
- if (post) return post.slug;
19
- else return null;
20
- })
21
- };
22
- }
23
- return;
24
- };
25
- export const usePrevNextPost = _usePrevNextPost;
@@ -1,8 +0,0 @@
1
- export declare const useWPUri: () => {
2
- base: any;
3
- admin: string;
4
- pagesAdmin: string;
5
- postAdmin: string;
6
- postEdit: (path: string) => string;
7
- settingsEdit: string;
8
- };
@@ -1,23 +0,0 @@
1
- import { useRuntimeConfig } from "#imports";
2
- const _useWPUri = () => {
3
- const config = useRuntimeConfig();
4
- const base = config.public.wpNuxt.wordpressUrl;
5
- const admin = base + "/wp-admin";
6
- const pagesAdmin = base + "/wp-admin/edit.php?post_type=page";
7
- const postAdmin = base + "/wp-admin/edit.php?post_type=post";
8
- const settingsEdit = base + "/wp-admin/options-general.php";
9
- const postEdit = (path) => {
10
- if (path)
11
- return base + "/wp-admin/post.php?post=" + path + "&action=edit";
12
- else return postAdmin;
13
- };
14
- return {
15
- base,
16
- admin,
17
- pagesAdmin,
18
- postAdmin,
19
- postEdit,
20
- settingsEdit
21
- };
22
- };
23
- export const useWPUri = _useWPUri;
@@ -1,2 +0,0 @@
1
- declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
- export default _default;
@@ -1,5 +0,0 @@
1
- import { defineNuxtPlugin } from "nuxt/app";
2
- import VueSanitize from "vue-sanitize-directive";
3
- export default defineNuxtPlugin((nuxtApp) => {
4
- nuxtApp.vueApp.use(VueSanitize);
5
- });
@@ -1,5 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- data: string;
3
- errors: never[];
4
- }>>;
5
- export default _default;
@@ -1,9 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- import { purgeCache } from "../storage.js";
3
- export default defineEventHandler(async () => {
4
- purgeCache();
5
- return {
6
- data: "Cache purged!",
7
- errors: []
8
- };
9
- });
@@ -1,9 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- data: any;
3
- errors: any;
4
- }>>;
5
- export default _default;
6
- /**
7
- * Get the parameters for the GraphQL middleware query.
8
- */
9
- export declare function buildRequestParams(variables?: Record<string, any> | undefined | null): Record<string, any>;
@@ -1,50 +0,0 @@
1
- import { defineEventHandler, readBody } from "h3";
2
- import { cacheStorage } from "../storage.js";
3
- import { isStaging } from "../../composables/isStaging.js";
4
- import { useRuntimeConfig } from "#imports";
5
- export default defineEventHandler(async (event) => {
6
- const config = useRuntimeConfig();
7
- const body = await readBody(event);
8
- const staging = await isStaging();
9
- if (!body || !body.queryName) {
10
- throw new Error(
11
- "The request must contain a queryName"
12
- );
13
- }
14
- const cacheKey = `wpContent-${body.queryName}-${body.params ? JSON.stringify(body.params).replaceAll('"', "").replaceAll(":", "-") : ""}`;
15
- if (config.public.wpNuxt.enableCache && !staging) {
16
- const cachedContent = await cacheStorage.getItem(cacheKey);
17
- if (cachedContent) {
18
- return {
19
- data: cachedContent,
20
- errors: []
21
- };
22
- }
23
- }
24
- return $fetch("/api/graphql_middleware/query/" + body.queryName, {
25
- params: buildRequestParams(body.params),
26
- headers: {
27
- Authorization: `Bearer ${event.context.accessToken}`
28
- }
29
- }).then((v) => {
30
- cacheStorage.setItem(cacheKey, v.data).catch(() => {
31
- });
32
- return {
33
- data: v.data,
34
- errors: v.errors || []
35
- };
36
- });
37
- });
38
- export function buildRequestParams(variables) {
39
- if (!variables) {
40
- return {};
41
- }
42
- for (const key in variables) {
43
- if (typeof variables[key] !== "string") {
44
- return {
45
- __variables: JSON.stringify(variables)
46
- };
47
- }
48
- }
49
- return variables;
50
- }
@@ -1 +0,0 @@
1
- export declare function usePosts(): Promise<unknown>;
@@ -1,8 +0,0 @@
1
- export function usePosts() {
2
- return $fetch("/api/wpContent", {
3
- method: "POST",
4
- body: {
5
- queryName: "Posts"
6
- }
7
- });
8
- }
@@ -1,3 +0,0 @@
1
- import { type Storage } from 'unstorage';
2
- export declare const cacheStorage: Storage;
3
- export declare const purgeCache: () => Promise<void>;
@@ -1,11 +0,0 @@
1
- import { prefixStorage } from "unstorage";
2
- import { useLogger } from "../util/logger.js";
3
- import { useStorage } from "#imports";
4
- export const cacheStorage = prefixStorage(useStorage(), "cache:wpnuxt-content");
5
- export const purgeCache = async () => {
6
- const keys = await cacheStorage.getKeys("cache:wpnuxt-content");
7
- keys.forEach(async (key) => {
8
- await cacheStorage.removeItem(key);
9
- });
10
- useLogger().info("ServerSide cache purged!");
11
- };
@@ -1,3 +0,0 @@
1
- import { type LogLevel } from 'consola';
2
- export declare const useLogger: () => any;
3
- export declare const initLogger: (logLevel: LogLevel | undefined) => any;
@@ -1,25 +0,0 @@
1
- import { createConsola } from "consola";
2
- import { ref } from "vue";
3
- import { useRuntimeConfig } from "#imports";
4
- const loggerRef = ref();
5
- export const useLogger = () => {
6
- const logger = loggerRef.value;
7
- if (logger) {
8
- return logger;
9
- } else {
10
- const config = useRuntimeConfig();
11
- return initLogger(config.public.wpNuxt.logLevel ? config.public.wpNuxt.logLevel : 3);
12
- }
13
- };
14
- export const initLogger = (logLevel) => {
15
- loggerRef.value = createConsola({
16
- level: logLevel ? logLevel : 3,
17
- formatOptions: {
18
- colors: true,
19
- compact: true,
20
- date: true,
21
- fancy: true
22
- }
23
- }).withTag("wpnuxt");
24
- return loggerRef.value;
25
- };
package/dist/types.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { NuxtModule } from '@nuxt/schema'
2
-
3
- import type { default as Module } from './module'
4
-
5
- export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
-
7
- export { default } from './module'