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.
- package/dist/adapters/auth.d.ts +11 -2
- package/dist/adapters/auth.js +5 -1
- package/dist/adapters/captcha.d.ts +3 -1
- package/dist/adapters/captcha.js +5 -1
- package/dist/adapters/cookies.d.ts +7 -0
- package/dist/adapters/cookies.js +8 -0
- package/dist/adapters/geo.d.ts +13 -2
- package/dist/adapters/geo.js +5 -1
- package/dist/adapters/logger.d.ts +8 -1
- package/dist/adapters/logger.js +5 -1
- package/dist/cli/banner.js +12 -1
- package/dist/cli/commands/dev.js +262 -0
- package/dist/cli/commands/init.js +235 -43
- package/dist/cli/commands/test.js +133 -34
- package/dist/cli/commands/watch.js +2 -2
- package/dist/cli/daemon/config.js +73 -7
- package/dist/cli/daemon/generate.js +1 -1
- package/dist/cli/daemon/lock.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/presets/base.js +8 -1
- package/dist/cli/presets/nextjs.js +1 -1
- package/dist/cli/utils.js +90 -6
- package/dist/cli/wp/bootstrap.js +13 -10
- package/dist/cli/wp/byo.js +113 -0
- package/dist/cli/wp/compose/docker-compose.yml +13 -2
- package/dist/cli/wp/compose/opcache.ini +16 -0
- package/dist/cli/wp/compose/override.js +104 -0
- package/dist/cli/wp/compose/override.test.ts +115 -0
- package/dist/cli/wp/compose/override.ts +134 -0
- package/dist/cli/wp/compose/remap-entrypoint.sh +17 -0
- package/dist/cli/wp/constants.js +7 -8
- package/dist/cli/wp/dev.js +146 -0
- package/dist/cli/wp/docker.d.ts +55 -15
- package/dist/cli/wp/docker.js +102 -41
- package/dist/cli/wp/ports.js +72 -0
- package/dist/cli/wp/session.js +150 -0
- package/dist/cli/wp/settings.js +73 -0
- package/dist/cli/wp/setup.js +1 -1
- package/dist/cli/wp/stack.js +58 -0
- package/dist/cli/wp/types.d.ts +26 -5
- package/dist/cli/wp/types.js +5 -1
- package/dist/cli/wp/utils.d.ts +29 -2
- package/dist/cli/wp/utils.js +61 -3
- package/dist/cli/wp/watchdog.d.ts +1 -0
- package/dist/cli/wp/watchdog.js +45 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +2 -2
- package/dist/config.d.ts +49 -3
- package/dist/context.d.ts +12 -1
- package/dist/context.js +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.js +10 -6
- package/dist/integrations/nextjs/kizlo.server.d.ts +1 -1
- package/dist/integrations/nextjs/kizlo.server.js +2 -2
- package/dist/integrations/nextjs/utils.js +2 -2
- package/dist/kizlo.d.ts +27 -6
- package/dist/kizlo.js +24 -11
- package/dist/menu/fixture.d.ts +1 -1
- package/dist/package.js +1 -1
- package/dist/post/fixture.d.ts +1 -1
- package/dist/service.d.ts +2 -0
- package/dist/service.js +3 -0
- package/dist/settings/service.d.ts +22 -0
- package/dist/settings/service.interface.d.ts +134 -0
- package/dist/settings/service.js +43 -0
- package/dist/shared/error.d.ts +16 -5
- package/dist/shared/error.js +4 -0
- package/dist/shared/extension.d.ts +2 -0
- package/dist/shared/middleware.d.ts +13 -10
- package/dist/shared/middleware.js +7 -0
- package/dist/shared/procedure.d.ts +34 -28
- package/dist/shared/procedure.js +3 -6
- package/dist/shared/types.d.ts +19 -13
- package/dist/test/client.d.ts +5 -0
- package/dist/test/client.js +5 -0
- package/dist/test/server.d.ts +6 -0
- package/dist/test/server.js +6 -0
- package/dist/test.d.ts +4 -4
- package/dist/test.js +4 -4
- package/dist/webhook/index.d.ts +14 -13
- package/dist/webhook/index.js +5 -5
- package/dist/webhook/schema.d.ts +3 -3
- package/dist/webhook/schema.js +37 -37
- package/dist/webhook/utils.js +4 -4
- package/dist/wordpress/service.js +6 -0
- package/package.json +2 -2
- package/dist/cli/commands/wp.js +0 -66
package/dist/webhook/index.d.ts
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
6
|
+
import { Schema, SchemaOutput } from "@kizlo/shared";
|
|
7
7
|
|
|
8
8
|
//#region src/webhook/index.d.ts
|
|
9
|
-
type
|
|
10
|
-
type
|
|
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
|
|
13
|
+
/** Standard Schema that validates and types each matched event's `data` payload. */
|
|
14
|
+
data: AnyEventSchema;
|
|
13
15
|
}[];
|
|
14
|
-
type
|
|
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
|
|
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?:
|
|
25
|
-
handler:
|
|
25
|
+
events?: AnyEvents;
|
|
26
|
+
handler: EventHandlerFn<AnyEvents>;
|
|
26
27
|
}
|
|
27
|
-
declare function createEventHandler<const T extends
|
|
28
|
-
declare function createEventHandler<const T extends
|
|
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 {
|
|
39
|
+
export { AnyEventSchema, AnyEvents, EventHandler, EventHandlerFn, InferEventUnion, WebhookOptions, createEventHandler, createWebhookRouter };
|
package/dist/webhook/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { KizloError } from "../shared/error.js";
|
|
2
2
|
import { createProcedure } from "../shared/procedure.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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:
|
|
23
|
-
path:
|
|
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
|
|
35
|
+
const event = await validateEvent(events, input.body);
|
|
36
36
|
if (!event) return;
|
|
37
37
|
await handler(event, context);
|
|
38
38
|
}));
|
package/dist/webhook/schema.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import z from "zod/v4";
|
|
|
2
2
|
|
|
3
3
|
//#region src/webhook/schema.d.ts
|
|
4
4
|
|
|
5
|
-
declare const
|
|
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
|
|
43
|
+
type KizloEvent = z.infer<typeof KizloEvent>;
|
|
44
44
|
//#endregion
|
|
45
|
-
export {
|
|
45
|
+
export { KizloEvent };
|
package/dist/webhook/schema.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
import z from "zod/v4";
|
|
2
2
|
|
|
3
3
|
//#region src/webhook/schema.ts
|
|
4
|
-
const
|
|
4
|
+
const TERM_EVENT_TYPES = [
|
|
5
5
|
"term.created",
|
|
6
6
|
"term.updated",
|
|
7
7
|
"term.deleted"
|
|
8
8
|
];
|
|
9
|
-
const
|
|
10
|
-
const
|
|
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
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
...
|
|
23
|
-
...
|
|
24
|
-
...
|
|
25
|
-
...
|
|
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
|
|
28
|
-
const
|
|
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
|
|
33
|
-
type:
|
|
34
|
-
data:
|
|
32
|
+
const PostEvent = z.object({
|
|
33
|
+
type: PostEventType,
|
|
34
|
+
data: PostEventData
|
|
35
35
|
});
|
|
36
|
-
const
|
|
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
|
|
43
|
-
type:
|
|
44
|
-
data:
|
|
42
|
+
const TermEvent = z.object({
|
|
43
|
+
type: TermEventType,
|
|
44
|
+
data: TermEventData
|
|
45
45
|
});
|
|
46
|
-
const
|
|
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
|
|
52
|
-
type:
|
|
53
|
-
data:
|
|
51
|
+
const PaymentEvent = z.object({
|
|
52
|
+
type: PaymentEventType,
|
|
53
|
+
data: PaymentEventData
|
|
54
54
|
});
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
type:
|
|
58
|
-
data:
|
|
55
|
+
const SettingsEventData = z.null();
|
|
56
|
+
const SettingsEvent = z.object({
|
|
57
|
+
type: SettingsEventType,
|
|
58
|
+
data: SettingsEventData
|
|
59
59
|
});
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const KizloEvent = z.union([
|
|
61
|
+
PostEvent,
|
|
62
|
+
TermEvent,
|
|
63
|
+
PaymentEvent,
|
|
64
|
+
SettingsEvent
|
|
65
65
|
]);
|
|
66
|
-
const
|
|
66
|
+
const AnyEvent = z.object({
|
|
67
67
|
type: z.string(),
|
|
68
68
|
data: z.unknown()
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
//#endregion
|
|
72
|
-
export {
|
|
72
|
+
export { AnyEvent, KizloEvent };
|
package/dist/webhook/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
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
|
|
6
|
-
const internal = await safeValidateSchema(
|
|
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 {
|
|
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.
|
|
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.
|
|
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",
|
package/dist/cli/commands/wp.js
DELETED
|
@@ -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 };
|