@justanarthur/payload-www 0.3.3 → 0.3.5

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.
@@ -54,30 +54,45 @@ var slugField = (options = {}) => {
54
54
 
55
55
  // src/render/_locale.ts
56
56
  function prefixFor(locale, defaultLocale, mode) {
57
+ let result;
57
58
  if (mode === "never")
58
- return "";
59
- if (mode === "as-needed" && locale === defaultLocale)
60
- return "";
61
- return `/${locale}`;
59
+ result = "";
60
+ else if (mode === "as-needed" && locale === defaultLocale)
61
+ result = "";
62
+ else
63
+ result = `/${locale}`;
64
+ console.log("[WWW] render/_locale:prefixFor locale=", locale, "default=", defaultLocale, "mode=", mode, "->", JSON.stringify(result));
65
+ return result;
62
66
  }
63
67
  function resolveLocale(req) {
64
- if (!req || typeof req !== "object")
68
+ if (!req || typeof req !== "object") {
69
+ console.log('[WWW] render/_locale:resolveLocale -> "" (no req)');
65
70
  return "";
71
+ }
66
72
  const r = req;
67
- if (typeof r.locale === "string" && r.locale.length > 0)
73
+ if (typeof r.locale === "string" && r.locale.length > 0) {
74
+ console.log("[WWW] render/_locale:resolveLocale ->", r.locale, "(from req.locale)");
68
75
  return r.locale;
76
+ }
69
77
  const fallback = r.payload?.config?.localization?.defaultLocale;
70
- if (typeof fallback === "string" && fallback.length > 0)
78
+ if (typeof fallback === "string" && fallback.length > 0) {
79
+ console.log("[WWW] render/_locale:resolveLocale ->", fallback, "(from config.localization.defaultLocale)");
71
80
  return fallback;
81
+ }
82
+ console.log('[WWW] render/_locale:resolveLocale -> "" (no locale anywhere)');
72
83
  return "";
73
84
  }
74
85
  function allLocales(req) {
75
- if (!req || typeof req !== "object")
86
+ if (!req || typeof req !== "object") {
87
+ console.log("[WWW] render/_locale:allLocales -> [] (no req)");
76
88
  return [];
89
+ }
77
90
  const r = req;
78
91
  const list = r.payload?.config?.localization?.locales;
79
- if (!Array.isArray(list) || list.length === 0)
92
+ if (!Array.isArray(list) || list.length === 0) {
93
+ console.log("[WWW] render/_locale:allLocales -> [] (no locales declared)");
80
94
  return [];
95
+ }
81
96
  const out = [];
82
97
  for (const entry of list) {
83
98
  if (typeof entry === "string" && entry.length > 0) {
@@ -88,6 +103,7 @@ function allLocales(req) {
88
103
  out.push(code);
89
104
  }
90
105
  }
106
+ console.log("[WWW] render/_locale:allLocales ->", JSON.stringify(out));
91
107
  return out;
92
108
  }
93
109
 
@@ -97,21 +113,28 @@ function nextCacheImport() {
97
113
  return cachePromise ??= import("next/cache");
98
114
  }
99
115
  function shouldSkipRevalidate(context) {
100
- return Boolean(context?.disableRevalidate);
116
+ const skip = Boolean(context?.disableRevalidate);
117
+ if (skip)
118
+ console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
119
+ return skip;
101
120
  }
102
121
  async function safeRevalidatePath(payload, path) {
122
+ console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
103
123
  try {
104
124
  const { revalidatePath } = await nextCacheImport();
105
125
  revalidatePath(path);
106
126
  } catch (error) {
127
+ console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
107
128
  payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
108
129
  }
109
130
  }
110
131
  async function safeRevalidateTag(payload, tag, profile = "max") {
132
+ console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
111
133
  try {
112
134
  const { revalidateTag } = await nextCacheImport();
113
135
  revalidateTag(tag, profile);
114
136
  } catch (error) {
137
+ console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
115
138
  payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
116
139
  }
117
140
  }
@@ -127,6 +150,7 @@ function createRevalidateCollectionHook(options) {
127
150
  pathMode = "url"
128
151
  } = options;
129
152
  const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
153
+ console.log("[WWW] render/hooks:createRevalidateCollectionHook collectionSlug=", collectionSlug, "urlPathPrefix=", urlPathPrefix, "sitemapTag=", resolvedSitemapTag, "pathMode=", pathMode);
130
154
  const resolveDefaults = (req) => {
131
155
  const mode = modeOption ?? "always";
132
156
  const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
@@ -155,6 +179,7 @@ function createRevalidateCollectionHook(options) {
155
179
  }
156
180
  };
157
181
  const fireCollectionTags = async (payload, docId, req) => {
182
+ console.log("[WWW] render/hooks:fireCollectionTags collectionSlug=", collectionSlug, "docId=", docId);
158
183
  if (typeof docId === "string" || typeof docId === "number") {
159
184
  await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
160
185
  }
@@ -168,6 +193,7 @@ function createRevalidateCollectionHook(options) {
168
193
  const { payload } = req;
169
194
  const typed = doc;
170
195
  const prev = previousDoc;
196
+ console.log("[WWW] render/hooks:afterChange collectionSlug=", collectionSlug, "id=", typed.id, "slug=", typed.slug, "prevSlug=", prev?.slug);
171
197
  const isPublished = typed._status === "published";
172
198
  const wasPublished = prev?._status === "published";
173
199
  const prevSlugIsString = typeof prev?.slug === "string";
@@ -191,6 +217,7 @@ function createRevalidateCollectionHook(options) {
191
217
  return doc ?? null;
192
218
  const { payload } = req;
193
219
  const typed = doc;
220
+ console.log("[WWW] render/hooks:afterDelete collectionSlug=", collectionSlug, "id=", typed?.id, "slug=", typed?.slug);
194
221
  if (pathMode !== "tag-only") {
195
222
  await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
196
223
  }
@@ -199,11 +226,14 @@ function createRevalidateCollectionHook(options) {
199
226
  };
200
227
  return { afterChange, afterDelete };
201
228
  }
202
- var createRevalidatePageHooks = (opts = {}) => createRevalidateCollectionHook({
203
- collectionSlug: "pages",
204
- urlPathPrefix: "",
205
- ...opts
206
- });
229
+ var createRevalidatePageHooks = (opts = {}) => {
230
+ console.log("[WWW] render/hooks:createRevalidatePageHooks (deprecated alias) opts=", JSON.stringify(opts));
231
+ return createRevalidateCollectionHook({
232
+ collectionSlug: "pages",
233
+ urlPathPrefix: "",
234
+ ...opts
235
+ });
236
+ };
207
237
 
208
238
  // src/config/constants.ts
209
239
  var PAGES_RENDER_PATH = "@justanarthur/payload-www/render-pages#PagesPage";
@@ -511,10 +541,12 @@ var link = (options = {}) => {
511
541
 
512
542
  // src/render/hooks/revalidateGlobal.ts
513
543
  function createRevalidateGlobalHook(slug) {
544
+ console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
514
545
  return async ({ doc, req: { payload, context, locale } }) => {
515
546
  if (shouldSkipRevalidate(context))
516
547
  return doc;
517
548
  const tags = [`global_${slug}`, `global_${slug}_${locale}`];
549
+ console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
518
550
  payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
519
551
  for (const tag of tags) {
520
552
  await safeRevalidateTag(payload, tag);
package/dist/data-test.js CHANGED
@@ -60,30 +60,45 @@ var slugField = (options = {}) => {
60
60
 
61
61
  // src/render/_locale.ts
62
62
  function prefixFor(locale, defaultLocale, mode) {
63
+ let result;
63
64
  if (mode === "never")
64
- return "";
65
- if (mode === "as-needed" && locale === defaultLocale)
66
- return "";
67
- return `/${locale}`;
65
+ result = "";
66
+ else if (mode === "as-needed" && locale === defaultLocale)
67
+ result = "";
68
+ else
69
+ result = `/${locale}`;
70
+ console.log("[WWW] render/_locale:prefixFor locale=", locale, "default=", defaultLocale, "mode=", mode, "->", JSON.stringify(result));
71
+ return result;
68
72
  }
69
73
  function resolveLocale(req) {
70
- if (!req || typeof req !== "object")
74
+ if (!req || typeof req !== "object") {
75
+ console.log('[WWW] render/_locale:resolveLocale -> "" (no req)');
71
76
  return "";
77
+ }
72
78
  const r = req;
73
- if (typeof r.locale === "string" && r.locale.length > 0)
79
+ if (typeof r.locale === "string" && r.locale.length > 0) {
80
+ console.log("[WWW] render/_locale:resolveLocale ->", r.locale, "(from req.locale)");
74
81
  return r.locale;
82
+ }
75
83
  const fallback = r.payload?.config?.localization?.defaultLocale;
76
- if (typeof fallback === "string" && fallback.length > 0)
84
+ if (typeof fallback === "string" && fallback.length > 0) {
85
+ console.log("[WWW] render/_locale:resolveLocale ->", fallback, "(from config.localization.defaultLocale)");
77
86
  return fallback;
87
+ }
88
+ console.log('[WWW] render/_locale:resolveLocale -> "" (no locale anywhere)');
78
89
  return "";
79
90
  }
80
91
  function allLocales(req) {
81
- if (!req || typeof req !== "object")
92
+ if (!req || typeof req !== "object") {
93
+ console.log("[WWW] render/_locale:allLocales -> [] (no req)");
82
94
  return [];
95
+ }
83
96
  const r = req;
84
97
  const list = r.payload?.config?.localization?.locales;
85
- if (!Array.isArray(list) || list.length === 0)
98
+ if (!Array.isArray(list) || list.length === 0) {
99
+ console.log("[WWW] render/_locale:allLocales -> [] (no locales declared)");
86
100
  return [];
101
+ }
87
102
  const out = [];
88
103
  for (const entry of list) {
89
104
  if (typeof entry === "string" && entry.length > 0) {
@@ -94,6 +109,7 @@ function allLocales(req) {
94
109
  out.push(code);
95
110
  }
96
111
  }
112
+ console.log("[WWW] render/_locale:allLocales ->", JSON.stringify(out));
97
113
  return out;
98
114
  }
99
115
 
@@ -103,21 +119,28 @@ function nextCacheImport() {
103
119
  return cachePromise ??= import("next/cache");
104
120
  }
105
121
  function shouldSkipRevalidate(context) {
106
- return Boolean(context?.disableRevalidate);
122
+ const skip = Boolean(context?.disableRevalidate);
123
+ if (skip)
124
+ console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
125
+ return skip;
107
126
  }
108
127
  async function safeRevalidatePath(payload, path) {
128
+ console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
109
129
  try {
110
130
  const { revalidatePath } = await nextCacheImport();
111
131
  revalidatePath(path);
112
132
  } catch (error) {
133
+ console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
113
134
  payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
114
135
  }
115
136
  }
116
137
  async function safeRevalidateTag(payload, tag, profile = "max") {
138
+ console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
117
139
  try {
118
140
  const { revalidateTag } = await nextCacheImport();
119
141
  revalidateTag(tag, profile);
120
142
  } catch (error) {
143
+ console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
121
144
  payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
122
145
  }
123
146
  }
@@ -133,6 +156,7 @@ function createRevalidateCollectionHook(options) {
133
156
  pathMode = "url"
134
157
  } = options;
135
158
  const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
159
+ console.log("[WWW] render/hooks:createRevalidateCollectionHook collectionSlug=", collectionSlug, "urlPathPrefix=", urlPathPrefix, "sitemapTag=", resolvedSitemapTag, "pathMode=", pathMode);
136
160
  const resolveDefaults = (req) => {
137
161
  const mode = modeOption ?? "always";
138
162
  const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
@@ -161,6 +185,7 @@ function createRevalidateCollectionHook(options) {
161
185
  }
162
186
  };
163
187
  const fireCollectionTags = async (payload, docId, req) => {
188
+ console.log("[WWW] render/hooks:fireCollectionTags collectionSlug=", collectionSlug, "docId=", docId);
164
189
  if (typeof docId === "string" || typeof docId === "number") {
165
190
  await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
166
191
  }
@@ -174,6 +199,7 @@ function createRevalidateCollectionHook(options) {
174
199
  const { payload } = req;
175
200
  const typed = doc;
176
201
  const prev = previousDoc;
202
+ console.log("[WWW] render/hooks:afterChange collectionSlug=", collectionSlug, "id=", typed.id, "slug=", typed.slug, "prevSlug=", prev?.slug);
177
203
  const isPublished = typed._status === "published";
178
204
  const wasPublished = prev?._status === "published";
179
205
  const prevSlugIsString = typeof prev?.slug === "string";
@@ -197,6 +223,7 @@ function createRevalidateCollectionHook(options) {
197
223
  return doc ?? null;
198
224
  const { payload } = req;
199
225
  const typed = doc;
226
+ console.log("[WWW] render/hooks:afterDelete collectionSlug=", collectionSlug, "id=", typed?.id, "slug=", typed?.slug);
200
227
  if (pathMode !== "tag-only") {
201
228
  await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
202
229
  }
@@ -205,11 +232,14 @@ function createRevalidateCollectionHook(options) {
205
232
  };
206
233
  return { afterChange, afterDelete };
207
234
  }
208
- var createRevalidatePageHooks = (opts = {}) => createRevalidateCollectionHook({
209
- collectionSlug: "pages",
210
- urlPathPrefix: "",
211
- ...opts
212
- });
235
+ var createRevalidatePageHooks = (opts = {}) => {
236
+ console.log("[WWW] render/hooks:createRevalidatePageHooks (deprecated alias) opts=", JSON.stringify(opts));
237
+ return createRevalidateCollectionHook({
238
+ collectionSlug: "pages",
239
+ urlPathPrefix: "",
240
+ ...opts
241
+ });
242
+ };
213
243
 
214
244
  // src/config/constants.ts
215
245
  var PAGES_RENDER_PATH = "@justanarthur/payload-www/render-pages#PagesPage";
@@ -517,10 +547,12 @@ var link = (options = {}) => {
517
547
 
518
548
  // src/render/hooks/revalidateGlobal.ts
519
549
  function createRevalidateGlobalHook(slug) {
550
+ console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
520
551
  return async ({ doc, req: { payload, context, locale } }) => {
521
552
  if (shouldSkipRevalidate(context))
522
553
  return doc;
523
554
  const tags = [`global_${slug}`, `global_${slug}_${locale}`];
555
+ console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
524
556
  payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
525
557
  for (const tag of tags) {
526
558
  await safeRevalidateTag(payload, tag);
@@ -615,11 +647,14 @@ function createPreviewHandler(options) {
615
647
  const url = new URL(req.url);
616
648
  const path = url.searchParams.get("path") ?? "/";
617
649
  const previewSecret = url.searchParams.get("previewSecret");
650
+ console.log("[WWW] render/preview:createPreviewHandler:GET path=", path, "hasSecret=", Boolean(previewSecret), "enableDraftMode=", enableDraftMode);
618
651
  if (!previewSecret || previewSecret !== secret) {
652
+ console.warn("[WWW] render/preview:createPreviewHandler:GET invalid preview secret (401)");
619
653
  return new Response("Invalid preview secret", { status: 401 });
620
654
  }
621
655
  if (enableDraftMode) {
622
656
  (await draftMode()).enable();
657
+ console.log("[WWW] render/preview:createPreviewHandler:GET draftMode enabled");
623
658
  }
624
659
  redirect(path);
625
660
  return new Response(null, { status: 204 });
@@ -639,6 +674,7 @@ async function buildHreflangAlternates({
639
674
  localePrefix = "always"
640
675
  }) {
641
676
  const allLocaleSlugs = await queryAllLocaleSlugs(storedSlug, locale);
677
+ console.log("[WWW] render/metadata:buildHreflangAlternates storedSlug=", storedSlug, "locale=", locale, "allLocaleSlugs=", JSON.stringify(allLocaleSlugs));
642
678
  const languages = {};
643
679
  const urlFor = (l, slug) => {
644
680
  const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
@@ -656,6 +692,7 @@ async function buildHreflangAlternates({
656
692
  if (allLocaleSlugs?.[defaultLocale]) {
657
693
  languages["x-default"] = urlFor(defaultLocale, allLocaleSlugs[defaultLocale]);
658
694
  }
695
+ console.log("[WWW] render/metadata:buildHreflangAlternates ->", JSON.stringify(languages));
659
696
  return languages;
660
697
  }
661
698
 
@@ -677,6 +714,7 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
677
714
  draft = false,
678
715
  config
679
716
  }) {
717
+ console.log("[WWW] render/metadata:queryDocBySlug collection=", collectionSlug, "slug=", slug, "slugField=", slugField2, "locale=", locale, "draft=", draft);
680
718
  const payload = await getPayload({ config });
681
719
  const result = await payload.find({
682
720
  collection: collectionSlug,
@@ -687,7 +725,9 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
687
725
  where: { [slugField2]: { equals: slug } },
688
726
  locale
689
727
  });
690
- return result.docs?.[0] ?? null;
728
+ const doc = result.docs?.[0] ?? null;
729
+ console.log("[WWW] render/metadata:queryDocBySlug ->", doc ? "hit" : "miss");
730
+ return doc;
691
731
  });
692
732
  var queryAllDocs = cache(async function queryAllDocs2({
693
733
  collectionSlug,
@@ -695,6 +735,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
695
735
  locale,
696
736
  config
697
737
  }) {
738
+ console.log("[WWW] render/metadata:queryAllDocs collection=", collectionSlug, "locale=", locale);
698
739
  const payload = await getPayload({ config });
699
740
  const result = await payload.find({
700
741
  collection: collectionSlug,
@@ -705,7 +746,9 @@ var queryAllDocs = cache(async function queryAllDocs2({
705
746
  select: { [slugField2]: true },
706
747
  locale
707
748
  });
708
- return result.docs ?? [];
749
+ const docs = result.docs ?? [];
750
+ console.log("[WWW] render/metadata:queryAllDocs -> count=", docs.length);
751
+ return docs;
709
752
  });
710
753
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
711
754
  collectionSlug,
@@ -714,6 +757,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
714
757
  locale,
715
758
  config
716
759
  }) {
760
+ console.log("[WWW] render/metadata:queryAllLocaleSlugs collection=", collectionSlug, "slug=", slug, "locale=", locale);
717
761
  const payload = await getPayload({ config });
718
762
  const result = await payload.find({
719
763
  collection: collectionSlug,
@@ -726,8 +770,10 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
726
770
  select: { [slugField2]: true }
727
771
  });
728
772
  const doc = result.docs?.[0];
729
- if (!doc)
773
+ if (!doc) {
774
+ console.log("[WWW] render/metadata:queryAllLocaleSlugs -> undefined (no doc)");
730
775
  return;
776
+ }
731
777
  let fieldValue = doc[slugField2];
732
778
  if (doc.id != null) {
733
779
  const allLocales2 = await payload.findByID({
@@ -742,6 +788,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
742
788
  fieldValue = allLocales2[slugField2];
743
789
  }
744
790
  if (fieldValue && typeof fieldValue === "object") {
791
+ console.log("[WWW] render/metadata:queryAllLocaleSlugs -> localized map=", JSON.stringify(fieldValue));
745
792
  return fieldValue;
746
793
  }
747
794
  const resolved = await config;
@@ -749,6 +796,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
749
796
  const out = {};
750
797
  for (const l of rawLocales)
751
798
  out[l] = String(fieldValue ?? slug);
799
+ console.log("[WWW] render/metadata:queryAllLocaleSlugs -> flat-fanout locales=", rawLocales.length, "slug=", JSON.stringify(fieldValue ?? slug));
752
800
  return out;
753
801
  });
754
802
  var queryGlobal = cache(async function queryGlobal2({
@@ -758,6 +806,7 @@ var queryGlobal = cache(async function queryGlobal2({
758
806
  draft = false,
759
807
  config
760
808
  }) {
809
+ console.log("[WWW] render/metadata:queryGlobal global=", globalSlug, "locale=", locale, "depth=", depth, "draft=", draft);
761
810
  const payload = await getPayload({ config });
762
811
  try {
763
812
  const global = await payload.findGlobal({
@@ -766,27 +815,35 @@ var queryGlobal = cache(async function queryGlobal2({
766
815
  draft,
767
816
  locale
768
817
  });
818
+ console.log("[WWW] render/metadata:queryGlobal -> hit");
769
819
  return global;
770
- } catch {
820
+ } catch (error) {
821
+ console.warn("[WWW] render/metadata:queryGlobal failed for slug=", globalSlug, "err=", String(error));
771
822
  return null;
772
823
  }
773
824
  });
774
825
  function getRenderModuleExports(exportName, collection, importMap) {
775
826
  const path = collection?.custom?.path;
776
- if (!path)
827
+ if (!path) {
828
+ console.log("[WWW] render/metadata:getRenderModuleExports no custom.path exportName=", exportName);
777
829
  return;
830
+ }
778
831
  const mod = getFromImportMap(path, importMap);
779
- return mod?.[exportName];
832
+ const value = mod?.[exportName];
833
+ console.log("[WWW] render/metadata:getRenderModuleExports exportName=", exportName, "path=", path, "hit=", Boolean(value));
834
+ return value;
780
835
  }
781
836
 
782
837
  // src/render/sitemap/createSitemapFile.ts
783
838
  function createSitemapFile(options) {
784
839
  const { collections } = options;
785
840
  return async function sitemap() {
841
+ console.log("[WWW] render/sitemap:createSitemapFile:sitemap collections=", JSON.stringify(options.collections), "localePrefix=", options.localePrefix ?? "always");
786
842
  const cfg = await options.config;
787
843
  const allLocales2 = Array.isArray(cfg.localization?.locales) ? cfg.localization.locales.map((l) => typeof l === "string" ? l : l.code) : [cfg.localization?.defaultLocale ?? "en"];
788
844
  const defaultLocale = cfg.localization?.defaultLocale ?? allLocales2[0];
789
845
  const activeLocales = Array.isArray(options.locales) && options.locales.length > 0 ? options.locales.filter((l) => allLocales2.includes(l)) : allLocales2;
846
+ console.log("[WWW] render/sitemap:createSitemapFile:sitemap allLocales=", JSON.stringify(allLocales2), "default=", defaultLocale, "active=", JSON.stringify(activeLocales));
790
847
  const entries = [];
791
848
  const seen = new Set;
792
849
  for (const collectionSlug of collections) {
@@ -842,6 +899,7 @@ function createSitemapFile(options) {
842
899
  }
843
900
  }
844
901
  }
902
+ console.log("[WWW] render/sitemap:createSitemapFile:sitemap -> entries=", entries.length);
845
903
  return entries;
846
904
  };
847
905
  }
package/dist/globals.js CHANGED
@@ -126,31 +126,40 @@ function nextCacheImport() {
126
126
  return cachePromise ??= import("next/cache");
127
127
  }
128
128
  function shouldSkipRevalidate(context) {
129
- return Boolean(context?.disableRevalidate);
129
+ const skip = Boolean(context?.disableRevalidate);
130
+ if (skip)
131
+ console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
132
+ return skip;
130
133
  }
131
134
  async function safeRevalidatePath(payload, path) {
135
+ console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
132
136
  try {
133
137
  const { revalidatePath } = await nextCacheImport();
134
138
  revalidatePath(path);
135
139
  } catch (error) {
140
+ console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
136
141
  payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
137
142
  }
138
143
  }
139
144
  async function safeRevalidateTag(payload, tag, profile = "max") {
145
+ console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
140
146
  try {
141
147
  const { revalidateTag } = await nextCacheImport();
142
148
  revalidateTag(tag, profile);
143
149
  } catch (error) {
150
+ console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
144
151
  payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
145
152
  }
146
153
  }
147
154
 
148
155
  // src/render/hooks/revalidateGlobal.ts
149
156
  function createRevalidateGlobalHook(slug) {
157
+ console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
150
158
  return async ({ doc, req: { payload, context, locale } }) => {
151
159
  if (shouldSkipRevalidate(context))
152
160
  return doc;
153
161
  const tags = [`global_${slug}`, `global_${slug}_${locale}`];
162
+ console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
154
163
  payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
155
164
  for (const tag of tags) {
156
165
  await safeRevalidateTag(payload, tag);
package/dist/hooks.js CHANGED
@@ -17,30 +17,45 @@ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
17
 
18
18
  // src/render/_locale.ts
19
19
  function prefixFor(locale, defaultLocale, mode) {
20
+ let result;
20
21
  if (mode === "never")
21
- return "";
22
- if (mode === "as-needed" && locale === defaultLocale)
23
- return "";
24
- return `/${locale}`;
22
+ result = "";
23
+ else if (mode === "as-needed" && locale === defaultLocale)
24
+ result = "";
25
+ else
26
+ result = `/${locale}`;
27
+ console.log("[WWW] render/_locale:prefixFor locale=", locale, "default=", defaultLocale, "mode=", mode, "->", JSON.stringify(result));
28
+ return result;
25
29
  }
26
30
  function resolveLocale(req) {
27
- if (!req || typeof req !== "object")
31
+ if (!req || typeof req !== "object") {
32
+ console.log('[WWW] render/_locale:resolveLocale -> "" (no req)');
28
33
  return "";
34
+ }
29
35
  const r = req;
30
- if (typeof r.locale === "string" && r.locale.length > 0)
36
+ if (typeof r.locale === "string" && r.locale.length > 0) {
37
+ console.log("[WWW] render/_locale:resolveLocale ->", r.locale, "(from req.locale)");
31
38
  return r.locale;
39
+ }
32
40
  const fallback = r.payload?.config?.localization?.defaultLocale;
33
- if (typeof fallback === "string" && fallback.length > 0)
41
+ if (typeof fallback === "string" && fallback.length > 0) {
42
+ console.log("[WWW] render/_locale:resolveLocale ->", fallback, "(from config.localization.defaultLocale)");
34
43
  return fallback;
44
+ }
45
+ console.log('[WWW] render/_locale:resolveLocale -> "" (no locale anywhere)');
35
46
  return "";
36
47
  }
37
48
  function allLocales(req) {
38
- if (!req || typeof req !== "object")
49
+ if (!req || typeof req !== "object") {
50
+ console.log("[WWW] render/_locale:allLocales -> [] (no req)");
39
51
  return [];
52
+ }
40
53
  const r = req;
41
54
  const list = r.payload?.config?.localization?.locales;
42
- if (!Array.isArray(list) || list.length === 0)
55
+ if (!Array.isArray(list) || list.length === 0) {
56
+ console.log("[WWW] render/_locale:allLocales -> [] (no locales declared)");
43
57
  return [];
58
+ }
44
59
  const out = [];
45
60
  for (const entry of list) {
46
61
  if (typeof entry === "string" && entry.length > 0) {
@@ -51,6 +66,7 @@ function allLocales(req) {
51
66
  out.push(code);
52
67
  }
53
68
  }
69
+ console.log("[WWW] render/_locale:allLocales ->", JSON.stringify(out));
54
70
  return out;
55
71
  }
56
72
 
@@ -60,21 +76,28 @@ function nextCacheImport() {
60
76
  return cachePromise ??= import("next/cache");
61
77
  }
62
78
  function shouldSkipRevalidate(context) {
63
- return Boolean(context?.disableRevalidate);
79
+ const skip = Boolean(context?.disableRevalidate);
80
+ if (skip)
81
+ console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
82
+ return skip;
64
83
  }
65
84
  async function safeRevalidatePath(payload, path) {
85
+ console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
66
86
  try {
67
87
  const { revalidatePath } = await nextCacheImport();
68
88
  revalidatePath(path);
69
89
  } catch (error) {
90
+ console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
70
91
  payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
71
92
  }
72
93
  }
73
94
  async function safeRevalidateTag(payload, tag, profile = "max") {
95
+ console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
74
96
  try {
75
97
  const { revalidateTag } = await nextCacheImport();
76
98
  revalidateTag(tag, profile);
77
99
  } catch (error) {
100
+ console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
78
101
  payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
79
102
  }
80
103
  }
@@ -90,6 +113,7 @@ function createRevalidateCollectionHook(options) {
90
113
  pathMode = "url"
91
114
  } = options;
92
115
  const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
116
+ console.log("[WWW] render/hooks:createRevalidateCollectionHook collectionSlug=", collectionSlug, "urlPathPrefix=", urlPathPrefix, "sitemapTag=", resolvedSitemapTag, "pathMode=", pathMode);
93
117
  const resolveDefaults = (req) => {
94
118
  const mode = modeOption ?? "always";
95
119
  const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
@@ -118,6 +142,7 @@ function createRevalidateCollectionHook(options) {
118
142
  }
119
143
  };
120
144
  const fireCollectionTags = async (payload, docId, req) => {
145
+ console.log("[WWW] render/hooks:fireCollectionTags collectionSlug=", collectionSlug, "docId=", docId);
121
146
  if (typeof docId === "string" || typeof docId === "number") {
122
147
  await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
123
148
  }
@@ -131,6 +156,7 @@ function createRevalidateCollectionHook(options) {
131
156
  const { payload } = req;
132
157
  const typed = doc;
133
158
  const prev = previousDoc;
159
+ console.log("[WWW] render/hooks:afterChange collectionSlug=", collectionSlug, "id=", typed.id, "slug=", typed.slug, "prevSlug=", prev?.slug);
134
160
  const isPublished = typed._status === "published";
135
161
  const wasPublished = prev?._status === "published";
136
162
  const prevSlugIsString = typeof prev?.slug === "string";
@@ -154,6 +180,7 @@ function createRevalidateCollectionHook(options) {
154
180
  return doc ?? null;
155
181
  const { payload } = req;
156
182
  const typed = doc;
183
+ console.log("[WWW] render/hooks:afterDelete collectionSlug=", collectionSlug, "id=", typed?.id, "slug=", typed?.slug);
157
184
  if (pathMode !== "tag-only") {
158
185
  await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
159
186
  }
@@ -162,18 +189,23 @@ function createRevalidateCollectionHook(options) {
162
189
  };
163
190
  return { afterChange, afterDelete };
164
191
  }
165
- var createRevalidatePageHooks = (opts = {}) => createRevalidateCollectionHook({
166
- collectionSlug: "pages",
167
- urlPathPrefix: "",
168
- ...opts
169
- });
192
+ var createRevalidatePageHooks = (opts = {}) => {
193
+ console.log("[WWW] render/hooks:createRevalidatePageHooks (deprecated alias) opts=", JSON.stringify(opts));
194
+ return createRevalidateCollectionHook({
195
+ collectionSlug: "pages",
196
+ urlPathPrefix: "",
197
+ ...opts
198
+ });
199
+ };
170
200
 
171
201
  // src/render/hooks/revalidateGlobal.ts
172
202
  function createRevalidateGlobalHook(slug) {
203
+ console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
173
204
  return async ({ doc, req: { payload, context, locale } }) => {
174
205
  if (shouldSkipRevalidate(context))
175
206
  return doc;
176
207
  const tags = [`global_${slug}`, `global_${slug}_${locale}`];
208
+ console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
177
209
  payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
178
210
  for (const tag of tags) {
179
211
  await safeRevalidateTag(payload, tag);
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ import { jsx } from "react/jsx-runtime";
24
24
  var LivePreviewListener = ({ serverURL }) => {
25
25
  const router = useRouter();
26
26
  const url = serverURL ?? process.env.NEXT_PUBLIC_SERVER_URL ?? (typeof window !== "undefined" ? window.location.origin : "");
27
+ console.log("[WWW] render/components:LivePreviewListener serverURL=", url);
27
28
  return /* @__PURE__ */ jsx(PayloadLivePreview, {
28
29
  refresh: router.refresh,
29
30
  serverURL: url