kizlo 0.1.0 → 0.2.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.
Files changed (87) hide show
  1. package/dist/adapters/auth.d.ts +11 -2
  2. package/dist/adapters/auth.js +5 -1
  3. package/dist/adapters/captcha.d.ts +3 -1
  4. package/dist/adapters/captcha.js +5 -1
  5. package/dist/adapters/cookies.d.ts +7 -0
  6. package/dist/adapters/cookies.js +8 -0
  7. package/dist/adapters/geo.d.ts +13 -2
  8. package/dist/adapters/geo.js +5 -1
  9. package/dist/adapters/logger.d.ts +8 -1
  10. package/dist/adapters/logger.js +5 -1
  11. package/dist/cli/banner.js +12 -1
  12. package/dist/cli/commands/dev.js +262 -0
  13. package/dist/cli/commands/init.js +235 -43
  14. package/dist/cli/commands/test.js +133 -34
  15. package/dist/cli/commands/watch.js +2 -2
  16. package/dist/cli/daemon/config.js +73 -7
  17. package/dist/cli/daemon/generate.js +1 -1
  18. package/dist/cli/daemon/lock.js +1 -1
  19. package/dist/cli/index.js +1 -1
  20. package/dist/cli/presets/base.js +8 -1
  21. package/dist/cli/presets/nextjs.js +1 -1
  22. package/dist/cli/utils.js +90 -6
  23. package/dist/cli/wp/bootstrap.js +13 -10
  24. package/dist/cli/wp/byo.js +113 -0
  25. package/dist/cli/wp/compose/docker-compose.yml +13 -2
  26. package/dist/cli/wp/compose/opcache.ini +16 -0
  27. package/dist/cli/wp/compose/override.js +104 -0
  28. package/dist/cli/wp/compose/override.test.ts +115 -0
  29. package/dist/cli/wp/compose/override.ts +134 -0
  30. package/dist/cli/wp/compose/remap-entrypoint.sh +17 -0
  31. package/dist/cli/wp/constants.js +7 -8
  32. package/dist/cli/wp/dev.js +146 -0
  33. package/dist/cli/wp/docker.d.ts +55 -15
  34. package/dist/cli/wp/docker.js +102 -41
  35. package/dist/cli/wp/ports.js +72 -0
  36. package/dist/cli/wp/session.js +150 -0
  37. package/dist/cli/wp/settings.js +73 -0
  38. package/dist/cli/wp/setup.js +1 -1
  39. package/dist/cli/wp/stack.js +58 -0
  40. package/dist/cli/wp/types.d.ts +26 -5
  41. package/dist/cli/wp/types.js +5 -1
  42. package/dist/cli/wp/utils.d.ts +29 -2
  43. package/dist/cli/wp/utils.js +61 -3
  44. package/dist/cli/wp/watchdog.d.ts +1 -0
  45. package/dist/cli/wp/watchdog.js +45 -0
  46. package/dist/client.d.ts +1 -1
  47. package/dist/client.js +2 -2
  48. package/dist/config.d.ts +49 -3
  49. package/dist/context.d.ts +12 -1
  50. package/dist/context.js +1 -1
  51. package/dist/index.d.ts +16 -11
  52. package/dist/index.js +10 -6
  53. package/dist/integrations/nextjs/kizlo.server.d.ts +1 -1
  54. package/dist/integrations/nextjs/kizlo.server.js +2 -2
  55. package/dist/integrations/nextjs/utils.js +2 -2
  56. package/dist/kizlo.d.ts +27 -6
  57. package/dist/kizlo.js +24 -11
  58. package/dist/menu/fixture.d.ts +1 -1
  59. package/dist/package.js +1 -1
  60. package/dist/post/fixture.d.ts +1 -1
  61. package/dist/service.d.ts +2 -0
  62. package/dist/service.js +3 -0
  63. package/dist/settings/service.d.ts +22 -0
  64. package/dist/settings/service.interface.d.ts +134 -0
  65. package/dist/settings/service.js +43 -0
  66. package/dist/shared/error.d.ts +16 -5
  67. package/dist/shared/error.js +4 -0
  68. package/dist/shared/extension.d.ts +2 -0
  69. package/dist/shared/middleware.d.ts +13 -10
  70. package/dist/shared/middleware.js +7 -0
  71. package/dist/shared/procedure.d.ts +34 -28
  72. package/dist/shared/procedure.js +3 -6
  73. package/dist/shared/types.d.ts +19 -13
  74. package/dist/test/client.d.ts +5 -0
  75. package/dist/test/client.js +5 -0
  76. package/dist/test/server.d.ts +6 -0
  77. package/dist/test/server.js +6 -0
  78. package/dist/test.d.ts +4 -4
  79. package/dist/test.js +4 -4
  80. package/dist/webhook/index.d.ts +14 -13
  81. package/dist/webhook/index.js +5 -5
  82. package/dist/webhook/schema.d.ts +3 -3
  83. package/dist/webhook/schema.js +37 -37
  84. package/dist/webhook/utils.js +4 -4
  85. package/dist/wordpress/service.js +6 -0
  86. package/package.json +2 -2
  87. package/dist/cli/commands/wp.js +0 -66
@@ -1,31 +1,32 @@
1
- import { WebhookEvent } from "./schema.js";
1
+ import { KizloEvent } from "./schema.js";
2
2
  import { DefinedErrorMapLike } from "../shared/error.js";
3
3
  import { ServerContext } from "../context.js";
4
4
  import { Procedure } from "../shared/procedure.js";
5
5
  import "../index.js";
6
- import { Pathname, Schema, SchemaOutput } from "@kizlo/shared";
6
+ import { Schema, SchemaOutput } from "@kizlo/shared";
7
7
 
8
8
  //#region src/webhook/index.d.ts
9
- type AnyWebhookEventSchema<TData = unknown> = Schema<unknown, TData>;
10
- type AnyWebhookEvents = {
9
+ type AnyEventSchema<TData = unknown> = Schema<unknown, TData>;
10
+ type AnyEvents = {
11
+ /** Event type strings this entry matches, e.g. `["review.created"]`. The handler's `event.type` is narrowed to this union. */
11
12
  types: string[];
12
- data: AnyWebhookEventSchema;
13
+ /** Standard Schema that validates and types each matched event's `data` payload. */
14
+ data: AnyEventSchema;
13
15
  }[];
14
- type InferWebhookEventUnion<T extends AnyWebhookEvents> = { [K in keyof T]: {
16
+ type InferEventUnion<T extends AnyEvents> = { [K in keyof T]: {
15
17
  type: T[K]["types"][number];
16
18
  data: SchemaOutput<T[K]["data"]>;
17
19
  } }[number];
18
- type WebhookHandlerFn<T extends AnyWebhookEvents> = (event: InferWebhookEventUnion<T> | WebhookEvent | null, context: ServerContext) => Promise<void> | void;
20
+ type EventHandlerFn<T extends AnyEvents> = (event: InferEventUnion<T> | KizloEvent | null, context: ServerContext) => Promise<void> | void;
19
21
  interface WebhookOptions {
20
- path?: Pathname;
21
22
  events?: EventHandler[];
22
23
  }
23
24
  interface EventHandler {
24
- events?: AnyWebhookEvents;
25
- handler: WebhookHandlerFn<AnyWebhookEvents>;
25
+ events?: AnyEvents;
26
+ handler: EventHandlerFn<AnyEvents>;
26
27
  }
27
- declare function createEventHandler<const T extends AnyWebhookEvents = never>(handler: WebhookHandlerFn<T>): EventHandler;
28
- declare function createEventHandler<const T extends AnyWebhookEvents = never>(events: T, handler: WebhookHandlerFn<T>): EventHandler;
28
+ declare function createEventHandler<const T extends AnyEvents = never>(handler: EventHandlerFn<T>): EventHandler;
29
+ declare function createEventHandler<const T extends AnyEvents = never>(events: T, handler: EventHandlerFn<T>): EventHandler;
29
30
  declare function createWebhookRouter(options?: WebhookOptions): {
30
31
  webhooks: Procedure<"api", {
31
32
  body: {
@@ -35,4 +36,4 @@ declare function createWebhookRouter(options?: WebhookOptions): {
35
36
  }, unknown, DefinedErrorMapLike>;
36
37
  };
37
38
  //#endregion
38
- export { AnyWebhookEventSchema, AnyWebhookEvents, EventHandler, InferWebhookEventUnion, WebhookHandlerFn, WebhookOptions, createEventHandler, createWebhookRouter };
39
+ export { AnyEventSchema, AnyEvents, EventHandler, EventHandlerFn, InferEventUnion, WebhookOptions, createEventHandler, createWebhookRouter };
@@ -1,7 +1,7 @@
1
1
  import { KizloError } from "../shared/error.js";
2
2
  import { createProcedure } from "../shared/procedure.js";
3
- import { AnyWebhookEvent } from "./schema.js";
4
- import { validateWebhookEvent } from "./utils.js";
3
+ import { AnyEvent } from "./schema.js";
4
+ import { validateEvent } from "./utils.js";
5
5
  import { tryCatchSync, verifyWebhook } from "@kizlo/shared";
6
6
  import z from "zod";
7
7
 
@@ -19,8 +19,8 @@ function createWebhookRouter(options) {
19
19
  return { webhooks: createProcedure({
20
20
  scope: "api",
21
21
  method: "POST",
22
- body: AnyWebhookEvent,
23
- path: options?.path ?? "/webhooks",
22
+ body: AnyEvent,
23
+ path: "/webhooks",
24
24
  output: z.void()
25
25
  }, async ({ context, input }) => {
26
26
  const payload = await context.request?.text() ?? "";
@@ -32,7 +32,7 @@ function createWebhookRouter(options) {
32
32
  }));
33
33
  if (err) throw new KizloError("FORBIDDEN", { message: "Signature verification failed." });
34
34
  const results = await Promise.allSettled((options?.events ?? []).map(async ({ events, handler }) => {
35
- const event = await validateWebhookEvent(events, input.body);
35
+ const event = await validateEvent(events, input.body);
36
36
  if (!event) return;
37
37
  await handler(event, context);
38
38
  }));
@@ -2,7 +2,7 @@ import z from "zod/v4";
2
2
 
3
3
  //#region src/webhook/schema.d.ts
4
4
 
5
- declare const WebhookEvent: z.ZodUnion<readonly [z.ZodObject<{
5
+ declare const KizloEvent: z.ZodUnion<readonly [z.ZodObject<{
6
6
  type: z.ZodEnum<{
7
7
  "post.created": "post.created";
8
8
  "post.updated": "post.updated";
@@ -40,6 +40,6 @@ declare const WebhookEvent: z.ZodUnion<readonly [z.ZodObject<{
40
40
  }>;
41
41
  data: z.ZodNull;
42
42
  }, z.core.$strip>]>;
43
- type WebhookEvent = z.infer<typeof WebhookEvent>;
43
+ type KizloEvent = z.infer<typeof KizloEvent>;
44
44
  //#endregion
45
- export { WebhookEvent };
45
+ export { KizloEvent };
@@ -1,72 +1,72 @@
1
1
  import z from "zod/v4";
2
2
 
3
3
  //#region src/webhook/schema.ts
4
- const TERM_WEBHOOK_EVENT_TYPES = [
4
+ const TERM_EVENT_TYPES = [
5
5
  "term.created",
6
6
  "term.updated",
7
7
  "term.deleted"
8
8
  ];
9
- const TermWebhookEventType = z.enum(TERM_WEBHOOK_EVENT_TYPES);
10
- const POST_WEBHOOK_EVENT_TYPES = [
9
+ const TermEventType = z.enum(TERM_EVENT_TYPES);
10
+ const POST_EVENT_TYPES = [
11
11
  "post.created",
12
12
  "post.updated",
13
13
  "post.trashed",
14
14
  "post.deleted"
15
15
  ];
16
- const PostWebhookEventType = z.enum(POST_WEBHOOK_EVENT_TYPES);
17
- const PAYMENT_WEBHOOK_EVENT_TYPES = ["payment.status_requested"];
18
- const PaymentWebhookEventType = z.enum(PAYMENT_WEBHOOK_EVENT_TYPES);
19
- const SETTINGS_WEBHOOK_EVENT_TYPES = ["settings.saved"];
20
- const SettingsWebhookEventType = z.enum(SETTINGS_WEBHOOK_EVENT_TYPES);
21
- const WEBHOOK_EVENT_TYPES = [
22
- ...TERM_WEBHOOK_EVENT_TYPES,
23
- ...POST_WEBHOOK_EVENT_TYPES,
24
- ...PAYMENT_WEBHOOK_EVENT_TYPES,
25
- ...SETTINGS_WEBHOOK_EVENT_TYPES
16
+ const PostEventType = z.enum(POST_EVENT_TYPES);
17
+ const PAYMENT_EVENT_TYPES = ["payment.status_requested"];
18
+ const PaymentEventType = z.enum(PAYMENT_EVENT_TYPES);
19
+ const SETTINGS_EVENT_TYPES = ["settings.saved"];
20
+ const SettingsEventType = z.enum(SETTINGS_EVENT_TYPES);
21
+ const EVENT_TYPES = [
22
+ ...TERM_EVENT_TYPES,
23
+ ...POST_EVENT_TYPES,
24
+ ...PAYMENT_EVENT_TYPES,
25
+ ...SETTINGS_EVENT_TYPES
26
26
  ];
27
- const WebhookEventType = z.enum(WEBHOOK_EVENT_TYPES);
28
- const PostWebhookEventData = z.object({
27
+ const EventType = z.enum(EVENT_TYPES);
28
+ const PostEventData = z.object({
29
29
  post_id: z.number(),
30
30
  post_type: z.string()
31
31
  });
32
- const PostWebhookEvent = z.object({
33
- type: PostWebhookEventType,
34
- data: PostWebhookEventData
32
+ const PostEvent = z.object({
33
+ type: PostEventType,
34
+ data: PostEventData
35
35
  });
36
- const TermWebhookEventData = z.object({
36
+ const TermEventData = z.object({
37
37
  term_id: z.number(),
38
38
  taxonomy: z.string(),
39
39
  post_types: z.array(z.string()),
40
40
  count: z.number().nonnegative()
41
41
  });
42
- const TermWebhookEvent = z.object({
43
- type: TermWebhookEventType,
44
- data: TermWebhookEventData
42
+ const TermEvent = z.object({
43
+ type: TermEventType,
44
+ data: TermEventData
45
45
  });
46
- const PaymentWebhookEventData = z.object({
46
+ const PaymentEventData = z.object({
47
47
  transaction_id: z.nullable(z.string()),
48
48
  payment_method_id: z.string(),
49
49
  payment_session_id: z.string()
50
50
  });
51
- const PaymentWebhookEvent = z.object({
52
- type: PaymentWebhookEventType,
53
- data: PaymentWebhookEventData
51
+ const PaymentEvent = z.object({
52
+ type: PaymentEventType,
53
+ data: PaymentEventData
54
54
  });
55
- const SettingsWebhookEventData = z.null();
56
- const SettingsWebhookEvent = z.object({
57
- type: SettingsWebhookEventType,
58
- data: SettingsWebhookEventData
55
+ const SettingsEventData = z.null();
56
+ const SettingsEvent = z.object({
57
+ type: SettingsEventType,
58
+ data: SettingsEventData
59
59
  });
60
- const WebhookEvent = z.union([
61
- PostWebhookEvent,
62
- TermWebhookEvent,
63
- PaymentWebhookEvent,
64
- SettingsWebhookEvent
60
+ const KizloEvent = z.union([
61
+ PostEvent,
62
+ TermEvent,
63
+ PaymentEvent,
64
+ SettingsEvent
65
65
  ]);
66
- const AnyWebhookEvent = z.object({
66
+ const AnyEvent = z.object({
67
67
  type: z.string(),
68
68
  data: z.unknown()
69
69
  });
70
70
 
71
71
  //#endregion
72
- export { AnyWebhookEvent, WebhookEvent };
72
+ export { AnyEvent, KizloEvent };
@@ -1,9 +1,9 @@
1
- import { WebhookEvent } from "./schema.js";
1
+ import { KizloEvent } from "./schema.js";
2
2
  import { safeValidateSchema } from "@kizlo/shared";
3
3
 
4
4
  //#region src/webhook/utils.ts
5
- async function validateWebhookEvent(events, data) {
6
- const internal = await safeValidateSchema(WebhookEvent, data);
5
+ async function validateEvent(events, data) {
6
+ const internal = await safeValidateSchema(KizloEvent, data);
7
7
  if (internal.success) return internal.value;
8
8
  const external = events?.find((a) => a.types.includes(data.type))?.data;
9
9
  if (external) {
@@ -18,4 +18,4 @@ async function validateWebhookEvent(events, data) {
18
18
  }
19
19
 
20
20
  //#endregion
21
- export { validateWebhookEvent };
21
+ export { validateEvent };
@@ -104,6 +104,12 @@ var WordPressService = class {
104
104
  message: readErr.message
105
105
  })
106
106
  };
107
+ if (response.ok && text.trim() === "") return {
108
+ data: null,
109
+ status: response.status,
110
+ headers: response.headers,
111
+ error: null
112
+ };
107
113
  const [parseErr, data] = tryCatchSync(() => JSON.parse(text));
108
114
  if (!response.ok) {
109
115
  if (isWordPressResourceError(data)) return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kizlo",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "A headless WordPress toolkit for TypeScript.",
6
6
  "keywords": [
@@ -76,7 +76,7 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "@clack/prompts": "^1.5.1",
79
- "@kizlo/shared": "0.1.0",
79
+ "@kizlo/shared": "0.1.1",
80
80
  "@orpc/client": "^1.14.3",
81
81
  "@orpc/contract": "^1.14.3",
82
82
  "@orpc/openapi": "^1.14.3",
@@ -1,66 +0,0 @@
1
- import { isSeeded } from "../wp/utils.js";
2
- import { composeDown, composeStop, composeUp } from "../wp/docker.js";
3
- import { withSpinner } from "../utils.js";
4
- import { log } from "../daemon/logger.js";
5
- import { resolveTestConfig } from "../daemon/config.js";
6
- import { runSeeds } from "../wp/setup.js";
7
- import { defineCommand } from "citty";
8
-
9
- //#region src/cli/commands/wp.ts
10
- /** Boot the stack and seed it once (idempotent — skips seeding if already seeded). */
11
- async function bringUp(cwd) {
12
- const cfg = await resolveTestConfig(cwd);
13
- process.env.WP_PORT = String(cfg.port);
14
- await withSpinner("Starting WordPress test stack", composeUp, "WordPress test stack ready");
15
- if (await isSeeded()) {
16
- log.info("Stack already seeded — skipping seed.");
17
- return;
18
- }
19
- await withSpinner("Seeding WordPress", () => runSeeds({
20
- port: cfg.port,
21
- fixtures: cfg.fixtures
22
- }), "WordPress seeded");
23
- log.success(`Stack ready on http://localhost:${cfg.port} — credentials at ${cfg.credentialsPath}`);
24
- }
25
- const up = defineCommand({
26
- meta: {
27
- name: "up",
28
- description: "Start the WordPress test stack and seed it if needed"
29
- },
30
- async run() {
31
- await bringUp(process.cwd());
32
- }
33
- });
34
- const reset = defineCommand({
35
- meta: {
36
- name: "reset",
37
- description: "Wipe the database and reseed a fresh WordPress test stack"
38
- },
39
- async run() {
40
- await withSpinner("Wiping WordPress database", () => composeDown({ volumes: true }), "Database wiped");
41
- await bringUp(process.cwd());
42
- }
43
- });
44
- const stop = defineCommand({
45
- meta: {
46
- name: "stop",
47
- description: "Stop the WordPress test stack, keeping the database volume"
48
- },
49
- async run() {
50
- await withSpinner("Stopping WordPress test stack", composeStop, "Stack stopped (volumes kept)");
51
- }
52
- });
53
- const wp = defineCommand({
54
- meta: {
55
- name: "wp",
56
- description: "Manage the WordPress test stack (advanced: up | reset | stop)"
57
- },
58
- subCommands: {
59
- up,
60
- reset,
61
- stop
62
- }
63
- });
64
-
65
- //#endregion
66
- export { wp };