kizlo 0.5.0 → 0.6.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { POST_EVENT_TYPES, TERM_EVENT_TYPES } from "../../webhook/schema.js";
|
|
1
|
+
import { POST_EVENT_TYPES, SETTINGS_EVENT_TYPES, TERM_EVENT_TYPES } from "../../webhook/schema.js";
|
|
2
2
|
import { createEventHandler } from "../../webhook/index.js";
|
|
3
3
|
import { createExtension } from "../../shared/extension.js";
|
|
4
4
|
import { ROBOTS_CACHE_TAG } from "./robots.js";
|
|
@@ -10,6 +10,8 @@ const DEFAULT_SITEMAP_TARGET = {
|
|
|
10
10
|
type: "layout"
|
|
11
11
|
};
|
|
12
12
|
const CONTENT_EVENT_TYPES = new Set([...POST_EVENT_TYPES, ...TERM_EVENT_TYPES]);
|
|
13
|
+
const NON_FRONTEND_SETTINGS_EVENT_TYPES = new Set(["settings.crawling.updated", "settings.integration.updated"]);
|
|
14
|
+
const FRONTEND_SETTINGS_EVENT_TYPES = new Set(SETTINGS_EVENT_TYPES.filter((type) => !NON_FRONTEND_SETTINGS_EVENT_TYPES.has(type)));
|
|
13
15
|
function nextRevalidation(options) {
|
|
14
16
|
return createExtension({
|
|
15
17
|
id: "nextjs-revalidation",
|
|
@@ -17,13 +19,15 @@ function nextRevalidation(options) {
|
|
|
17
19
|
if (!event) return;
|
|
18
20
|
const revalidatePath = options?.revalidatePath ?? (await import("next/cache")).revalidatePath;
|
|
19
21
|
const revalidateTag = options?.revalidateTag ?? (await import("next/cache")).revalidateTag;
|
|
22
|
+
const eventUrl = event.data && "url" in event.data ? event.data.url : void 0;
|
|
20
23
|
const paths = [
|
|
21
24
|
...await Promise.resolve(options?.paths?.(event) ?? []),
|
|
22
|
-
...
|
|
25
|
+
...eventUrl ? [eventUrl] : [],
|
|
23
26
|
"/post"
|
|
24
27
|
];
|
|
25
28
|
for (const path of normalizePaths(paths)) revalidatePath(path);
|
|
26
|
-
if (event.type === "settings.
|
|
29
|
+
if (event.type === "settings.crawling.updated" || event.type === "settings.site.updated") revalidateTag(ROBOTS_CACHE_TAG, { expire: 0 });
|
|
30
|
+
if (FRONTEND_SETTINGS_EVENT_TYPES.has(event.type)) revalidatePath("/", "layout");
|
|
27
31
|
if (CONTENT_EVENT_TYPES.has(event.type)) {
|
|
28
32
|
revalidateTag(SITEMAP_CACHE_TAG, { expire: 0 });
|
|
29
33
|
for (const target of resolveSitemapTargets(options?.sitemap)) revalidatePath(normalizePath(target.path), target.type);
|
package/dist/package.js
CHANGED
package/dist/webhook/schema.d.ts
CHANGED
|
@@ -29,9 +29,22 @@ declare const KizloEvent: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
29
29
|
}, z.core.$strip>;
|
|
30
30
|
}, z.core.$strip>, z.ZodObject<{
|
|
31
31
|
type: z.ZodEnum<{
|
|
32
|
-
"settings.
|
|
32
|
+
"settings.site.updated": "settings.site.updated";
|
|
33
|
+
"settings.brand.updated": "settings.brand.updated";
|
|
34
|
+
"settings.identity.updated": "settings.identity.updated";
|
|
35
|
+
"settings.authors.updated": "settings.authors.updated";
|
|
36
|
+
"settings.crawling.updated": "settings.crawling.updated";
|
|
37
|
+
"settings.integration.updated": "settings.integration.updated";
|
|
33
38
|
}>;
|
|
34
39
|
data: z.ZodNull;
|
|
40
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
41
|
+
type: z.ZodEnum<{
|
|
42
|
+
"settings.post_type.updated": "settings.post_type.updated";
|
|
43
|
+
"settings.taxonomy.updated": "settings.taxonomy.updated";
|
|
44
|
+
}>;
|
|
45
|
+
data: z.ZodObject<{
|
|
46
|
+
key: z.ZodString;
|
|
47
|
+
}, z.core.$strip>;
|
|
35
48
|
}, z.core.$strip>]>;
|
|
36
49
|
type KizloEvent = z.infer<typeof KizloEvent>;
|
|
37
50
|
//#endregion
|
package/dist/webhook/schema.js
CHANGED
|
@@ -14,7 +14,18 @@ const POST_EVENT_TYPES = [
|
|
|
14
14
|
"post.deleted"
|
|
15
15
|
];
|
|
16
16
|
const PostEventType = z.enum(POST_EVENT_TYPES);
|
|
17
|
-
const
|
|
17
|
+
const SETTINGS_SIMPLE_EVENT_TYPES = [
|
|
18
|
+
"settings.site.updated",
|
|
19
|
+
"settings.brand.updated",
|
|
20
|
+
"settings.identity.updated",
|
|
21
|
+
"settings.authors.updated",
|
|
22
|
+
"settings.crawling.updated",
|
|
23
|
+
"settings.integration.updated"
|
|
24
|
+
];
|
|
25
|
+
const SettingsSimpleEventType = z.enum(SETTINGS_SIMPLE_EVENT_TYPES);
|
|
26
|
+
const SETTINGS_INDEXED_EVENT_TYPES = ["settings.post_type.updated", "settings.taxonomy.updated"];
|
|
27
|
+
const SettingsIndexedEventType = z.enum(SETTINGS_INDEXED_EVENT_TYPES);
|
|
28
|
+
const SETTINGS_EVENT_TYPES = [...SETTINGS_SIMPLE_EVENT_TYPES, ...SETTINGS_INDEXED_EVENT_TYPES];
|
|
18
29
|
const SettingsEventType = z.enum(SETTINGS_EVENT_TYPES);
|
|
19
30
|
const EVENT_TYPES = [
|
|
20
31
|
...TERM_EVENT_TYPES,
|
|
@@ -42,15 +53,22 @@ const TermEvent = z.object({
|
|
|
42
53
|
type: TermEventType,
|
|
43
54
|
data: TermEventData
|
|
44
55
|
});
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
type:
|
|
48
|
-
data:
|
|
56
|
+
const SettingsSimpleEventData = z.null();
|
|
57
|
+
const SettingsSimpleEvent = z.object({
|
|
58
|
+
type: SettingsSimpleEventType,
|
|
59
|
+
data: SettingsSimpleEventData
|
|
60
|
+
});
|
|
61
|
+
const SettingsIndexedEventData = z.object({ key: z.string() });
|
|
62
|
+
const SettingsIndexedEvent = z.object({
|
|
63
|
+
type: SettingsIndexedEventType,
|
|
64
|
+
data: SettingsIndexedEventData
|
|
49
65
|
});
|
|
66
|
+
const SettingsEvent = z.union([SettingsSimpleEvent, SettingsIndexedEvent]);
|
|
50
67
|
const KizloEvent = z.union([
|
|
51
68
|
PostEvent,
|
|
52
69
|
TermEvent,
|
|
53
|
-
|
|
70
|
+
SettingsSimpleEvent,
|
|
71
|
+
SettingsIndexedEvent
|
|
54
72
|
]);
|
|
55
73
|
const AnyEvent = z.object({
|
|
56
74
|
type: z.string(),
|
|
@@ -58,4 +76,4 @@ const AnyEvent = z.object({
|
|
|
58
76
|
});
|
|
59
77
|
|
|
60
78
|
//#endregion
|
|
61
|
-
export { AnyEvent, KizloEvent, POST_EVENT_TYPES, TERM_EVENT_TYPES };
|
|
79
|
+
export { AnyEvent, KizloEvent, POST_EVENT_TYPES, SETTINGS_EVENT_TYPES, TERM_EVENT_TYPES };
|