kizlo 0.27.1 → 0.28.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.
@@ -0,0 +1,16 @@
1
+ //#region src/adapters/cloudflare-connection.ts
2
+ function cloudflareConnInfo(headers) {
3
+ const country = headers?.get("cf-ipcountry") || null;
4
+ return {
5
+ ip: headers?.get("cf-connecting-ip") || null,
6
+ country: country === "XX" || country === "T1" ? null : country,
7
+ city: null,
8
+ state: null,
9
+ postcode: null,
10
+ timezone: null,
11
+ userAgent: headers?.get("user-agent") || null
12
+ };
13
+ }
14
+
15
+ //#endregion
16
+ export { cloudflareConnInfo };
@@ -1,3 +1,5 @@
1
+ import { cloudflareConnInfo } from "./cloudflare-connection.js";
2
+
1
3
  //#region src/adapters/geo.cloudflare.ts
2
4
  /** Read trusted Cloudflare connection headers in Next.js/vinext. Only use behind Cloudflare ingress. */
3
5
  function geoCloudflareNext() {
@@ -6,16 +8,7 @@ function geoCloudflareNext() {
6
8
  if (!headers) try {
7
9
  headers = await (await import("next/headers")).headers();
8
10
  } catch {}
9
- const country = headers?.get("cf-ipcountry") || null;
10
- return {
11
- ip: headers?.get("cf-connecting-ip") || null,
12
- country: country === "XX" || country === "T1" ? null : country,
13
- city: null,
14
- state: null,
15
- postcode: null,
16
- timezone: null,
17
- userAgent: headers?.get("user-agent") || null
18
- };
11
+ return cloudflareConnInfo(headers);
19
12
  } };
20
13
  }
21
14
 
@@ -0,0 +1,7 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region src/integrations/cloudflare/vinext.d.ts
4
+ /** Capture Cloudflare context inside each Vinext stage, including cache misses and regeneration. */
5
+ declare function cloudflareVinext(): Plugin;
6
+ //#endregion
7
+ export { cloudflareVinext };
@@ -0,0 +1,44 @@
1
+ //#region src/integrations/cloudflare/vinext.ts
2
+ const stages = new Map([["vinext/server/request-stage", ["loadVinextRequestStage", "handleRequestStage"]], ["vinext/server/response-stage", ["loadVinextResponseStage", "handleResponseStage"]]]);
3
+ /** Capture Cloudflare context inside each Vinext stage, including cache misses and regeneration. */
4
+ function cloudflareVinext() {
5
+ const modules = /* @__PURE__ */ new Map();
6
+ return {
7
+ name: "kizlo:cloudflare-vinext",
8
+ enforce: "pre",
9
+ async resolveId(source, importer) {
10
+ const stage = stages.get(source);
11
+ if (!stage) return null;
12
+ const resolved = await this.resolve(source, importer, { skipSelf: true });
13
+ if (!resolved) return this.error(`Cannot resolve ${source}. Use a Vinext release exposing the public stage loaders.`);
14
+ const id = `\0kizlo:cloudflare:${resolved.id}`;
15
+ modules.set(id, {
16
+ original: resolved.id,
17
+ loader: stage[0],
18
+ handler: stage[1]
19
+ });
20
+ return id;
21
+ },
22
+ load(id) {
23
+ const stage = modules.get(id);
24
+ if (!stage) return null;
25
+ return `
26
+ import { withCloudflareRequest } from "kizlo/cloudflare";
27
+ import { ${stage.loader} as loadStage } from ${JSON.stringify(stage.original)};
28
+ export * from ${JSON.stringify(stage.original)};
29
+ export async function ${stage.loader}(...args) {
30
+ const stage = await loadStage(...args);
31
+ return {
32
+ ...stage,
33
+ ${stage.handler}(request, ...args) {
34
+ return withCloudflareRequest(request, () => stage.${stage.handler}(request, ...args));
35
+ }
36
+ };
37
+ }
38
+ `;
39
+ }
40
+ };
41
+ }
42
+
43
+ //#endregion
44
+ export { cloudflareVinext };
@@ -0,0 +1,3 @@
1
+ import { cloudflare } from "./integrations/cloudflare/integration.js";
2
+ import { geoCloudflare, withCloudflareRequest } from "./integrations/cloudflare/request-context.js";
3
+ export { cloudflare, geoCloudflare, withCloudflareRequest };
@@ -0,0 +1,4 @@
1
+ import { geoCloudflare, withCloudflareRequest } from "./integrations/cloudflare/request-context.js";
2
+ import { cloudflare } from "./integrations/cloudflare/integration.js";
3
+
4
+ export { cloudflare, geoCloudflare, withCloudflareRequest };
@@ -0,0 +1,8 @@
1
+ import { Integration } from "../../shared/integration.js";
2
+ import "../../index.js";
3
+
4
+ //#region src/integrations/cloudflare/integration.d.ts
5
+ /** Supply Cloudflare connection info independently of the frontend framework or WordPress host. */
6
+ declare function cloudflare(): Integration<"cloudflare", Record<never, never>>;
7
+ //#endregion
8
+ export { cloudflare };
@@ -0,0 +1,16 @@
1
+ import { FRAMEWORK_INTEGRATION_ORDER } from "../../shared/constants.js";
2
+ import { createIntegration } from "../../shared/integration.js";
3
+ import { geoCloudflare } from "./request-context.js";
4
+
5
+ //#region src/integrations/cloudflare/integration.ts
6
+ /** Supply Cloudflare connection info independently of the frontend framework or WordPress host. */
7
+ function cloudflare() {
8
+ return createIntegration({
9
+ id: "cloudflare",
10
+ order: FRAMEWORK_INTEGRATION_ORDER,
11
+ adapters: { geo: geoCloudflare() }
12
+ });
13
+ }
14
+
15
+ //#endregion
16
+ export { cloudflare };
@@ -0,0 +1,9 @@
1
+ import { GeoAdapter } from "../../adapters/geo.js";
2
+
3
+ //#region src/integrations/cloudflare/request-context.d.ts
4
+ /** Read an explicit Cloudflare request or the active Worker entry context, without framework headers. */
5
+ declare function geoCloudflare(): GeoAdapter;
6
+ /** Wrap the complete Worker fetch handler, including SSR and streamed response production. */
7
+ declare function withCloudflareRequest(request: Request, handle: () => Response | Promise<Response>): Promise<Response>;
8
+ //#endregion
9
+ export { geoCloudflare, withCloudflareRequest };
@@ -0,0 +1,58 @@
1
+ import { cloudflareConnInfo } from "../../adapters/cloudflare-connection.js";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+
4
+ //#region src/integrations/cloudflare/request-context.ts
5
+ const requests = new AsyncLocalStorage();
6
+ /** Read an explicit Cloudflare request or the active Worker entry context, without framework headers. */
7
+ function geoCloudflare() {
8
+ return { getConnInfo: (request) => request ? cloudflareConnInfo(request.headers) : { ...requests.getStore()?.connection ?? cloudflareConnInfo() } };
9
+ }
10
+ /** Wrap the complete Worker fetch handler, including SSR and streamed response production. */
11
+ function withCloudflareRequest(request, handle) {
12
+ const store = { connection: cloudflareConnInfo(request.headers) };
13
+ return requests.run(store, async () => {
14
+ try {
15
+ const response = await handle();
16
+ if (!response.body || response.status === 101) {
17
+ store.connection = null;
18
+ return response;
19
+ }
20
+ const reader = response.body.getReader();
21
+ const body = new ReadableStream({
22
+ pull(controller) {
23
+ return requests.run(store, async () => {
24
+ try {
25
+ const { value, done } = await reader.read();
26
+ if (done) {
27
+ store.connection = null;
28
+ reader.releaseLock();
29
+ controller.close();
30
+ } else controller.enqueue(value);
31
+ } catch (error) {
32
+ store.connection = null;
33
+ reader.releaseLock();
34
+ controller.error(error);
35
+ }
36
+ });
37
+ },
38
+ cancel(reason) {
39
+ return requests.run(store, async () => {
40
+ try {
41
+ await reader.cancel(reason);
42
+ } finally {
43
+ store.connection = null;
44
+ reader.releaseLock();
45
+ }
46
+ });
47
+ }
48
+ }, { highWaterMark: 0 });
49
+ return new Response(body, response);
50
+ } catch (error) {
51
+ store.connection = null;
52
+ throw error;
53
+ }
54
+ });
55
+ }
56
+
57
+ //#endregion
58
+ export { geoCloudflare, withCloudflareRequest };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.27.1";
2
+ var version = "0.28.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -1,6 +1,6 @@
1
1
  import { WP_CustomFields } from "../wordpress/types.js";
2
2
  import "../wordpress/index.js";
3
- import * as _kizlo_shared3 from "@kizlo/shared";
3
+ import * as _kizlo_shared7 from "@kizlo/shared";
4
4
  import z from "zod/v4";
5
5
 
6
6
  //#region src/page/schema.d.ts
@@ -104,7 +104,7 @@ declare const Page: z.ZodObject<{
104
104
  custom: z.ZodType<Record<string, unknown>, Record<string, unknown>, z.core.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>;
105
105
  createdAt: z.ZodNumber;
106
106
  updatedAt: z.ZodNumber;
107
- meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared3.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared3.JSONValue, unknown>>>;
107
+ meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared7.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared7.JSONValue, unknown>>>;
108
108
  }, z.core.$strip>;
109
109
  type Page = Omit<z.output<typeof Page>, "custom"> & {
110
110
  custom: PageCustomFields;
@@ -207,7 +207,7 @@ declare const PageList: z.ZodObject<{
207
207
  custom: z.ZodType<Record<string, unknown>, Record<string, unknown>, z.core.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>;
208
208
  createdAt: z.ZodNumber;
209
209
  updatedAt: z.ZodNumber;
210
- meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared3.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared3.JSONValue, unknown>>>;
210
+ meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared7.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared7.JSONValue, unknown>>>;
211
211
  }, z.core.$strip>>;
212
212
  meta: z.ZodObject<{
213
213
  page: z.ZodNumber;
@@ -1,6 +1,6 @@
1
1
  import { WP_CustomFields } from "../wordpress/types.js";
2
2
  import "../wordpress/index.js";
3
- import * as _kizlo_shared7 from "@kizlo/shared";
3
+ import * as _kizlo_shared3 from "@kizlo/shared";
4
4
  import z from "zod/v4";
5
5
 
6
6
  //#region src/post/schema.d.ts
@@ -26,14 +26,14 @@ declare const Post: z.ZodObject<{
26
26
  private: "private";
27
27
  }>;
28
28
  format: z.ZodEnum<{
29
- status: "status";
29
+ image: "image";
30
+ link: "link";
30
31
  standard: "standard";
31
32
  aside: "aside";
32
33
  chat: "chat";
33
34
  gallery: "gallery";
34
- link: "link";
35
- image: "image";
36
35
  quote: "quote";
36
+ status: "status";
37
37
  video: "video";
38
38
  audio: "audio";
39
39
  }>;
@@ -125,7 +125,7 @@ declare const Post: z.ZodObject<{
125
125
  custom: z.ZodType<Record<string, unknown>, Record<string, unknown>, z.core.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>;
126
126
  createdAt: z.ZodNumber;
127
127
  updatedAt: z.ZodNumber;
128
- meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared7.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared7.JSONValue, unknown>>>;
128
+ meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared3.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared3.JSONValue, unknown>>>;
129
129
  }, z.core.$strip>;
130
130
  type Post = Omit<z.output<typeof Post>, "custom"> & {
131
131
  custom: PostCustomFields;
@@ -150,14 +150,14 @@ declare const PostList: z.ZodObject<{
150
150
  private: "private";
151
151
  }>;
152
152
  format: z.ZodEnum<{
153
- status: "status";
153
+ image: "image";
154
+ link: "link";
154
155
  standard: "standard";
155
156
  aside: "aside";
156
157
  chat: "chat";
157
158
  gallery: "gallery";
158
- link: "link";
159
- image: "image";
160
159
  quote: "quote";
160
+ status: "status";
161
161
  video: "video";
162
162
  audio: "audio";
163
163
  }>;
@@ -249,7 +249,7 @@ declare const PostList: z.ZodObject<{
249
249
  custom: z.ZodType<Record<string, unknown>, Record<string, unknown>, z.core.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>;
250
250
  createdAt: z.ZodNumber;
251
251
  updatedAt: z.ZodNumber;
252
- meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared7.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared7.JSONValue, unknown>>>;
252
+ meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared3.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared3.JSONValue, unknown>>>;
253
253
  }, z.core.$strip>>;
254
254
  meta: z.ZodObject<{
255
255
  page: z.ZodNumber;
@@ -44,7 +44,7 @@ declare const CORE_PROCEDURES: {
44
44
  include?: string | number | (string | number)[] | undefined;
45
45
  offset?: string | number | undefined;
46
46
  order?: "asc" | "desc" | undefined;
47
- orderby?: "date" | "id" | "slug" | "parent" | "title" | "author" | "include" | "modified" | "relevance" | "include_slugs" | undefined;
47
+ orderby?: "title" | "author" | "date" | "id" | "slug" | "parent" | "include" | "include_slugs" | "modified" | "relevance" | undefined;
48
48
  searchColumns?: ("post_title" | "post_content" | "post_excerpt")[] | undefined;
49
49
  slug?: string | string[] | undefined;
50
50
  taxRelation?: "AND" | "OR" | undefined;
@@ -99,7 +99,7 @@ declare const CORE_PROCEDURES: {
99
99
  include?: string | number | (string | number)[] | undefined;
100
100
  offset?: string | number | undefined;
101
101
  order?: "asc" | "desc" | undefined;
102
- orderby?: "date" | "id" | "slug" | "parent" | "title" | "author" | "include" | "modified" | "relevance" | "include_slugs" | "menu_order" | undefined;
102
+ orderby?: "title" | "author" | "date" | "id" | "slug" | "parent" | "include" | "include_slugs" | "modified" | "relevance" | "menu_order" | undefined;
103
103
  searchColumns?: ("post_title" | "post_content" | "post_excerpt")[] | undefined;
104
104
  slug?: string | string[] | undefined;
105
105
  parent?: string | number | (string | number)[] | undefined;
@@ -136,7 +136,7 @@ declare const CORE_PROCEDURES: {
136
136
  exclude?: string | number | (string | number)[] | undefined;
137
137
  include?: string | number | (string | number)[] | undefined;
138
138
  order?: "asc" | "desc" | undefined;
139
- orderBy?: "count" | "id" | "slug" | "name" | "description" | "include" | "include_slugs" | "term_group" | undefined;
139
+ orderBy?: "description" | "id" | "name" | "slug" | "include" | "include_slugs" | "term_group" | "count" | undefined;
140
140
  hideEmpty?: string | boolean | undefined;
141
141
  parent?: string | number | undefined;
142
142
  post?: string | number | undefined;
@@ -172,7 +172,7 @@ declare const CORE_PROCEDURES: {
172
172
  exclude?: string | number | (string | number)[] | undefined;
173
173
  include?: string | number | (string | number)[] | undefined;
174
174
  order?: "asc" | "desc" | undefined;
175
- orderBy?: "count" | "id" | "slug" | "name" | "description" | "include" | "include_slugs" | "term_group" | undefined;
175
+ orderBy?: "description" | "id" | "name" | "slug" | "include" | "include_slugs" | "term_group" | "count" | undefined;
176
176
  hideEmpty?: string | boolean | undefined;
177
177
  post?: string | number | undefined;
178
178
  slug?: string | string[] | undefined;
@@ -241,7 +241,7 @@ declare const CORE_PROCEDURES: {
241
241
  sitemaps: {
242
242
  list: Procedure<"internal", {}, {
243
243
  key: string;
244
- type: "post_type" | "taxonomy" | "author";
244
+ type: "author" | "post_type" | "taxonomy";
245
245
  pages: number;
246
246
  lastmod: string;
247
247
  }[], DefinedErrorMapLike>;
@@ -249,7 +249,7 @@ declare const CORE_PROCEDURES: {
249
249
  origin: string;
250
250
  sitemaps: {
251
251
  key: string;
252
- type: "post_type" | "taxonomy" | "author";
252
+ type: "author" | "post_type" | "taxonomy";
253
253
  pages: number;
254
254
  lastmod: string;
255
255
  }[];
@@ -292,7 +292,7 @@ declare const CORE_PROCEDURES: {
292
292
  include?: string | number | (string | number)[] | undefined;
293
293
  offset?: string | number | undefined;
294
294
  order?: "asc" | "desc" | undefined;
295
- orderby?: "date" | "id" | "slug" | "parent" | "title" | "author" | "include" | "relevance" | "include_slugs" | "menu_order" | undefined;
295
+ orderby?: "title" | "author" | "date" | "id" | "slug" | "parent" | "include" | "include_slugs" | "relevance" | "menu_order" | undefined;
296
296
  searchColumns?: ("post_title" | "post_content" | "post_excerpt")[] | undefined;
297
297
  slug?: string | string[] | undefined;
298
298
  taxRelation?: "AND" | "OR" | undefined;
@@ -371,7 +371,7 @@ declare const CORE_PROCEDURES: {
371
371
  include?: string | number | (string | number)[] | undefined;
372
372
  offset?: string | number | undefined;
373
373
  order?: "asc" | "desc" | undefined;
374
- orderby?: "date" | "id" | "slug" | "parent" | "title" | "author" | "include" | "relevance" | "include_slugs" | "menu_order" | undefined;
374
+ orderby?: "title" | "author" | "date" | "id" | "slug" | "parent" | "include" | "include_slugs" | "relevance" | "menu_order" | undefined;
375
375
  searchColumns?: ("post_title" | "post_content" | "post_excerpt")[] | undefined;
376
376
  slug?: string | string[] | undefined;
377
377
  taxRelation?: "AND" | "OR" | undefined;
@@ -108,17 +108,17 @@ declare const Seo: z.ZodObject<{
108
108
  type Seo = z.infer<typeof Seo>;
109
109
  declare const CONTENT_TYPES: readonly ["post_type", "taxonomy", "author"];
110
110
  declare const ContentType: z.ZodEnum<{
111
+ author: "author";
111
112
  post_type: "post_type";
112
113
  taxonomy: "taxonomy";
113
- author: "author";
114
114
  }>;
115
115
  type ContentType = z.infer<typeof ContentType>;
116
116
  declare const Sitemap: z.ZodObject<{
117
117
  key: z.ZodString;
118
118
  type: z.ZodEnum<{
119
+ author: "author";
119
120
  post_type: "post_type";
120
121
  taxonomy: "taxonomy";
121
- author: "author";
122
122
  }>;
123
123
  pages: z.ZodNumber;
124
124
  lastmod: z.ZodString;
@@ -127,9 +127,9 @@ type Sitemap = z.infer<typeof Sitemap>;
127
127
  declare const SitemapList: z.ZodArray<z.ZodObject<{
128
128
  key: z.ZodString;
129
129
  type: z.ZodEnum<{
130
+ author: "author";
130
131
  post_type: "post_type";
131
132
  taxonomy: "taxonomy";
132
- author: "author";
133
133
  }>;
134
134
  pages: z.ZodNumber;
135
135
  lastmod: z.ZodString;
@@ -140,9 +140,9 @@ declare const SitemapIndex: z.ZodObject<{
140
140
  sitemaps: z.ZodArray<z.ZodObject<{
141
141
  key: z.ZodString;
142
142
  type: z.ZodEnum<{
143
+ author: "author";
143
144
  post_type: "post_type";
144
145
  taxonomy: "taxonomy";
145
- author: "author";
146
146
  }>;
147
147
  pages: z.ZodNumber;
148
148
  lastmod: z.ZodString;
@@ -174,9 +174,9 @@ declare const SitemapUrlList: z.ZodArray<z.ZodObject<{
174
174
  type SitemapUrlList = z.infer<typeof SitemapUrlList>;
175
175
  declare const ListSitemapUrlInputBase: z.ZodObject<{
176
176
  type: z.ZodEnum<{
177
+ author: "author";
177
178
  post_type: "post_type";
178
179
  taxonomy: "taxonomy";
179
- author: "author";
180
180
  }>;
181
181
  page: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodCoercedNumber<string | number>>>;
182
182
  }, z.core.$strip>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kizlo",
3
- "version": "0.27.1",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "description": "A headless WordPress framework for TypeScript.",
6
6
  "keywords": [
@@ -58,6 +58,18 @@
58
58
  "default": "./dist/test.js"
59
59
  }
60
60
  },
61
+ "./cloudflare": {
62
+ "import": {
63
+ "types": "./dist/cloudflare.d.ts",
64
+ "default": "./dist/cloudflare.js"
65
+ }
66
+ },
67
+ "./cloudflare/vinext": {
68
+ "import": {
69
+ "types": "./dist/cloudflare/vinext.d.ts",
70
+ "default": "./dist/cloudflare/vinext.js"
71
+ }
72
+ },
61
73
  "./node": {
62
74
  "import": {
63
75
  "types": "./dist/node.d.ts",
@@ -139,7 +151,8 @@
139
151
  "next": "^14.0.0 || ^15.0.0 || ^16.0.0",
140
152
  "react": "^18.0.0 || ^19.0.0",
141
153
  "react-dom": "^18.0.0 || ^19.0.0",
142
- "typescript": "^5.0.0"
154
+ "typescript": "^5.0.0",
155
+ "vite": "^8.0.0"
143
156
  },
144
157
  "peerDependenciesMeta": {
145
158
  "@tanstack/react-router": {
@@ -162,6 +175,9 @@
162
175
  },
163
176
  "typescript": {
164
177
  "optional": true
178
+ },
179
+ "vite": {
180
+ "optional": true
165
181
  }
166
182
  }
167
183
  }