kizlo 0.1.1 → 0.2.1
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/README.md +1 -1
- 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 +203 -20
- package/dist/cli/commands/init.js +240 -47
- package/dist/cli/commands/test.js +56 -19
- package/dist/cli/commands/watch.js +5 -23
- package/dist/cli/daemon/config.js +11 -5
- package/dist/cli/daemon/logger.js +1 -0
- package/dist/cli/daemon/watch.js +35 -2
- package/dist/cli/presets/base.js +8 -1
- package/dist/cli/presets/nextjs.js +1 -1
- package/dist/cli/utils.js +74 -5
- package/dist/cli/wp/compose/docker-compose.yml +12 -0
- package/dist/cli/wp/dev.js +4 -2
- package/dist/cli/wp/docker.d.ts +22 -4
- package/dist/cli/wp/docker.js +27 -5
- 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/types.d.ts +5 -3
- package/dist/cli/wp/utils.d.ts +7 -1
- package/dist/cli/wp/utils.js +17 -1
- 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/context.d.ts +12 -1
- package/dist/context.js +1 -1
- package/dist/index.d.ts +16 -12
- package/dist/index.js +9 -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/package.js +1 -1
- package/dist/router.d.ts +7 -7
- 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 +3 -3
- 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 +1 -1
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 {
|