kizlo 0.1.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/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/adapters/auth.d.ts +18 -0
- package/dist/adapters/auth.js +15 -0
- package/dist/adapters/captcha.d.ts +28 -0
- package/dist/adapters/captcha.js +86 -0
- package/dist/adapters/geo.d.ts +18 -0
- package/dist/adapters/geo.js +18 -0
- package/dist/adapters/geo.vercel.d.ts +6 -0
- package/dist/adapters/geo.vercel.js +41 -0
- package/dist/adapters/logger.d.ts +31 -0
- package/dist/adapters/logger.js +30 -0
- package/dist/cli/banner.js +26 -0
- package/dist/cli/commands/generate.js +34 -0
- package/dist/cli/commands/init.js +313 -0
- package/dist/cli/commands/test.js +68 -0
- package/dist/cli/commands/watch.js +53 -0
- package/dist/cli/commands/wp.js +66 -0
- package/dist/cli/daemon/config.js +87 -0
- package/dist/cli/daemon/generate.js +40 -0
- package/dist/cli/daemon/lock.js +31 -0
- package/dist/cli/daemon/logger.js +8 -0
- package/dist/cli/daemon/watch.js +37 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +22 -0
- package/dist/cli/presets/base.js +23 -0
- package/dist/cli/presets/index.js +16 -0
- package/dist/cli/presets/nextjs.js +39 -0
- package/dist/cli/utils.js +182 -0
- package/dist/cli/wp/bootstrap.js +114 -0
- package/dist/cli/wp/compose/docker-compose.yml +73 -0
- package/dist/cli/wp/constants.js +52 -0
- package/dist/cli/wp/docker.d.ts +24 -0
- package/dist/cli/wp/docker.js +69 -0
- package/dist/cli/wp/setup.js +39 -0
- package/dist/cli/wp/types.d.ts +72 -0
- package/dist/cli/wp/types.js +8 -0
- package/dist/cli/wp/utils.d.ts +39 -0
- package/dist/cli/wp/utils.js +105 -0
- package/dist/client.d.ts +24 -0
- package/dist/client.js +55 -0
- package/dist/comment/errors.js +47 -0
- package/dist/comment/index.js +138 -0
- package/dist/comment/schema.js +72 -0
- package/dist/comment/utils.js +35 -0
- package/dist/config.d.ts +39 -0
- package/dist/config.js +7 -0
- package/dist/context.d.ts +73 -0
- package/dist/context.js +145 -0
- package/dist/cookie.d.ts +19 -0
- package/dist/cookie.js +25 -0
- package/dist/email/service.d.ts +11 -0
- package/dist/email/service.interface.d.ts +8 -0
- package/dist/email/service.js +20 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +31 -0
- package/dist/integrations/nextjs/kizlo.client.d.ts +10 -0
- package/dist/integrations/nextjs/kizlo.client.js +13 -0
- package/dist/integrations/nextjs/kizlo.server.d.ts +12 -0
- package/dist/integrations/nextjs/kizlo.server.js +13 -0
- package/dist/integrations/nextjs/utils.js +11 -0
- package/dist/kizlo.d.ts +73 -0
- package/dist/kizlo.js +144 -0
- package/dist/menu/errors.js +16 -0
- package/dist/menu/fixture.d.ts +8 -0
- package/dist/menu/fixture.js +62 -0
- package/dist/menu/index.js +70 -0
- package/dist/menu/schema.js +70 -0
- package/dist/menu/utils.js +57 -0
- package/dist/nextjs/server.d.ts +2 -0
- package/dist/nextjs/server.js +3 -0
- package/dist/nextjs.d.ts +2 -0
- package/dist/nextjs.js +3 -0
- package/dist/package.js +5 -0
- package/dist/post/error.js +30 -0
- package/dist/post/fixture.d.ts +8 -0
- package/dist/post/fixture.js +71 -0
- package/dist/post/index.js +123 -0
- package/dist/post/schema.js +120 -0
- package/dist/post/utils.js +42 -0
- package/dist/post-type/service.js +48 -0
- package/dist/router.d.ts +624 -0
- package/dist/router.js +15 -0
- package/dist/seo/index.js +54 -0
- package/dist/seo/schema.d.ts +196 -0
- package/dist/seo/schema.js +96 -0
- package/dist/seo/types.d.ts +80 -0
- package/dist/seo/utils.js +44 -0
- package/dist/service.d.ts +17 -0
- package/dist/service.js +17 -0
- package/dist/shared/constants.js +10 -0
- package/dist/shared/contract.d.ts +21 -0
- package/dist/shared/contract.js +43 -0
- package/dist/shared/crypto.d.ts +28 -0
- package/dist/shared/crypto.js +34 -0
- package/dist/shared/error.d.ts +128 -0
- package/dist/shared/error.js +147 -0
- package/dist/shared/extension.d.ts +25 -0
- package/dist/shared/extension.js +7 -0
- package/dist/shared/identifier.d.ts +11 -0
- package/dist/shared/identifier.js +26 -0
- package/dist/shared/middleware.d.ts +29 -0
- package/dist/shared/procedure.d.ts +114 -0
- package/dist/shared/procedure.js +114 -0
- package/dist/shared/result.d.ts +24 -0
- package/dist/shared/result.js +49 -0
- package/dist/shared/router.d.ts +7 -0
- package/dist/shared/router.js +26 -0
- package/dist/shared/schema.d.ts +55 -0
- package/dist/shared/schema.js +43 -0
- package/dist/shared/serialize.d.ts +12 -0
- package/dist/shared/serialize.js +51 -0
- package/dist/shared/types.d.ts +35 -0
- package/dist/shared/utils.js +17 -0
- package/dist/test/auth.d.ts +7 -0
- package/dist/test/auth.js +15 -0
- package/dist/test/captcha.d.ts +7 -0
- package/dist/test/captcha.js +8 -0
- package/dist/test/client.d.ts +11 -0
- package/dist/test/client.js +14 -0
- package/dist/test/fixtures.d.ts +14 -0
- package/dist/test/fixtures.js +13 -0
- package/dist/test/server.d.ts +10 -0
- package/dist/test/server.js +32 -0
- package/dist/test/users.d.ts +14 -0
- package/dist/test/users.js +17 -0
- package/dist/test.d.ts +12 -0
- package/dist/test.js +13 -0
- package/dist/webhook/index.d.ts +38 -0
- package/dist/webhook/index.js +44 -0
- package/dist/webhook/schema.d.ts +45 -0
- package/dist/webhook/schema.js +72 -0
- package/dist/webhook/utils.js +21 -0
- package/dist/wordpress/comment/service.d.ts +28 -0
- package/dist/wordpress/comment/service.js +55 -0
- package/dist/wordpress/comment/types.d.ts +206 -0
- package/dist/wordpress/constants.d.ts +14 -0
- package/dist/wordpress/constants.js +13 -0
- package/dist/wordpress/error.d.ts +9 -0
- package/dist/wordpress/error.js +12 -0
- package/dist/wordpress/index.d.ts +15 -0
- package/dist/wordpress/menu/items/service.d.ts +28 -0
- package/dist/wordpress/menu/items/service.js +55 -0
- package/dist/wordpress/menu/items/types.d.ts +214 -0
- package/dist/wordpress/menu/service.d.ts +30 -0
- package/dist/wordpress/menu/service.js +58 -0
- package/dist/wordpress/menu/types.d.ts +115 -0
- package/dist/wordpress/post/service.d.ts +28 -0
- package/dist/wordpress/post/service.js +55 -0
- package/dist/wordpress/post/types.d.ts +290 -0
- package/dist/wordpress/service.d.ts +77 -0
- package/dist/wordpress/service.js +180 -0
- package/dist/wordpress/types.d.ts +67 -0
- package/dist/wordpress/user/service.d.ts +28 -0
- package/dist/wordpress/user/service.js +55 -0
- package/dist/wordpress/user/types.d.ts +221 -0
- package/dist/wordpress/utils.d.ts +7 -0
- package/dist/wordpress/utils.js +9 -0
- package/package.json +109 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { WebhookEvent } from "./schema.js";
|
|
2
|
+
import { safeValidateSchema } from "@kizlo/shared";
|
|
3
|
+
|
|
4
|
+
//#region src/webhook/utils.ts
|
|
5
|
+
async function validateWebhookEvent(events, data) {
|
|
6
|
+
const internal = await safeValidateSchema(WebhookEvent, data);
|
|
7
|
+
if (internal.success) return internal.value;
|
|
8
|
+
const external = events?.find((a) => a.types.includes(data.type))?.data;
|
|
9
|
+
if (external) {
|
|
10
|
+
const result = await safeValidateSchema(external, data.data);
|
|
11
|
+
if (!result.success) return null;
|
|
12
|
+
return {
|
|
13
|
+
type: data.type,
|
|
14
|
+
data: result.value
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { validateWebhookEvent };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WP_Error } from "../error.js";
|
|
2
|
+
import { WP_List, WP_Result } from "../types.js";
|
|
3
|
+
import { WordPressService } from "../service.js";
|
|
4
|
+
import { WP_Comment, WP_CommentCreateErrorCode, WP_CommentCreateInput, WP_CommentDeleteErrorCode, WP_CommentDeleteInput, WP_CommentDeleteResponse, WP_CommentListErrorCode, WP_CommentListInput, WP_CommentRetrieveErrorCode, WP_CommentRetrieveInput, WP_CommentUpdateErrorCode, WP_CommentUpdateInput } from "./types.js";
|
|
5
|
+
import "../index.js";
|
|
6
|
+
|
|
7
|
+
//#region src/wordpress/comment/service.d.ts
|
|
8
|
+
declare class CommentService {
|
|
9
|
+
private readonly wordpress;
|
|
10
|
+
constructor(wordpress: WordPressService);
|
|
11
|
+
list(input: WP_CommentListInput): Promise<{
|
|
12
|
+
data: null;
|
|
13
|
+
status: number;
|
|
14
|
+
headers: Headers;
|
|
15
|
+
error: WP_Error<WP_CommentListErrorCode>;
|
|
16
|
+
} | {
|
|
17
|
+
data: WP_List<WP_Comment>;
|
|
18
|
+
status: number;
|
|
19
|
+
headers: Headers;
|
|
20
|
+
error: null;
|
|
21
|
+
}>;
|
|
22
|
+
create(input: WP_CommentCreateInput): Promise<WP_Result<WP_Comment, WP_CommentCreateErrorCode>>;
|
|
23
|
+
get(input: WP_CommentRetrieveInput): Promise<WP_Result<WP_Comment, WP_CommentRetrieveErrorCode>>;
|
|
24
|
+
update(input: WP_CommentUpdateInput): Promise<WP_Result<WP_Comment, WP_CommentUpdateErrorCode>>;
|
|
25
|
+
delete(input: WP_CommentDeleteInput): Promise<WP_Result<WP_CommentDeleteResponse, WP_CommentDeleteErrorCode>>;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { CommentService };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WP_CORE_BASE } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/wordpress/comment/service.ts
|
|
4
|
+
var CommentService = class {
|
|
5
|
+
wordpress;
|
|
6
|
+
constructor(wordpress) {
|
|
7
|
+
this.wordpress = wordpress;
|
|
8
|
+
}
|
|
9
|
+
async list(input) {
|
|
10
|
+
const { ...searchParams } = input;
|
|
11
|
+
const result = await this.wordpress.get("/comments", {
|
|
12
|
+
base: WP_CORE_BASE,
|
|
13
|
+
searchParams
|
|
14
|
+
});
|
|
15
|
+
if (result.error) return result;
|
|
16
|
+
return {
|
|
17
|
+
...result,
|
|
18
|
+
data: this.wordpress.resolveList({
|
|
19
|
+
data: result.data,
|
|
20
|
+
headers: result.headers,
|
|
21
|
+
searchParams
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async create(input) {
|
|
26
|
+
return this.wordpress.post("/comments", {
|
|
27
|
+
base: WP_CORE_BASE,
|
|
28
|
+
body: input
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async get(input) {
|
|
32
|
+
const { id,...searchParams } = input;
|
|
33
|
+
return this.wordpress.get(`/comments/${id}`, {
|
|
34
|
+
base: WP_CORE_BASE,
|
|
35
|
+
searchParams
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async update(input) {
|
|
39
|
+
const { id,...body } = input;
|
|
40
|
+
return this.wordpress.post(`/comments/${id}`, {
|
|
41
|
+
base: WP_CORE_BASE,
|
|
42
|
+
body
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async delete(input) {
|
|
46
|
+
const { id,...searchParams } = input;
|
|
47
|
+
return this.wordpress.delete(`/comments/${id}`, {
|
|
48
|
+
base: WP_CORE_BASE,
|
|
49
|
+
searchParams
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { CommentService };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { WP_Context, WP_Link, WP_ListOrder } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/wordpress/comment/types.d.ts
|
|
4
|
+
/** State of the comment, as returned in responses. */
|
|
5
|
+
type WP_CommentStatus = "approved" | "hold" | "spam" | "trash" | "unapproved";
|
|
6
|
+
/** Status filter values accepted by `GET /wp/v2/comments`. WP's list filter uses present-tense (`approve`, not `approved`) and adds an `all` alias. */
|
|
7
|
+
type WP_CommentStatusFilter = "approve" | "hold" | "spam" | "trash" | "all";
|
|
8
|
+
/** Status values accepted by `POST /wp/v2/comments` and `POST /wp/v2/comments/<id>`. Same present-tense vocabulary as the filter, minus the `all` alias. */
|
|
9
|
+
type WP_CommentStatusInput = "approve" | "hold" | "spam" | "trash";
|
|
10
|
+
/** Type of the comment. */
|
|
11
|
+
type WP_CommentType = "comment" | "pingback" | "trackback";
|
|
12
|
+
/** Sort collection by comment attribute. */
|
|
13
|
+
type WP_CommentOrderBy = "date" | "date_gmt" | "id" | "include" | "post" | "parent" | "type";
|
|
14
|
+
/** The content for the comment. */
|
|
15
|
+
interface WP_CommentContent {
|
|
16
|
+
/** HTML content for the comment, transformed for display. */
|
|
17
|
+
rendered: string;
|
|
18
|
+
/** Content for the comment, as it exists in the database. */
|
|
19
|
+
raw: string;
|
|
20
|
+
}
|
|
21
|
+
/** Avatar URLs for the comment author, keyed by image size in pixels (e.g. "24", "48", "96"). */
|
|
22
|
+
type WP_CommentAvatarUrls = Record<string, string>;
|
|
23
|
+
/** Hypermedia links for the comment resource. */
|
|
24
|
+
interface WP_CommentLinks {
|
|
25
|
+
self?: WP_Link[];
|
|
26
|
+
collection?: WP_Link[];
|
|
27
|
+
up?: WP_Link[];
|
|
28
|
+
"in-reply-to"?: WP_Link[];
|
|
29
|
+
children?: WP_Link[];
|
|
30
|
+
author?: WP_Link[];
|
|
31
|
+
[rel: string]: WP_Link[] | undefined;
|
|
32
|
+
}
|
|
33
|
+
interface WP_Comment {
|
|
34
|
+
/** Unique identifier for the comment. */
|
|
35
|
+
id: number;
|
|
36
|
+
/** The ID of the user object, if author was a user. */
|
|
37
|
+
author: number;
|
|
38
|
+
/** Email address for the comment author. */
|
|
39
|
+
author_email: string;
|
|
40
|
+
/** IP address for the comment author. */
|
|
41
|
+
author_ip: string;
|
|
42
|
+
/** Display name for the comment author. */
|
|
43
|
+
author_name: string;
|
|
44
|
+
/** URL for the comment author. */
|
|
45
|
+
author_url: string;
|
|
46
|
+
/** User agent for the comment author. */
|
|
47
|
+
author_user_agent: string;
|
|
48
|
+
/** The content for the comment. */
|
|
49
|
+
content: WP_CommentContent;
|
|
50
|
+
/** The date the comment was published, in the site's timezone. */
|
|
51
|
+
date: string;
|
|
52
|
+
/** The date the comment was published, as GMT. */
|
|
53
|
+
date_gmt: string;
|
|
54
|
+
/** URL to the comment. */
|
|
55
|
+
link: string;
|
|
56
|
+
/** The ID for the parent of the comment. */
|
|
57
|
+
parent: number;
|
|
58
|
+
/** The ID of the associated post object. */
|
|
59
|
+
post: number;
|
|
60
|
+
/** State of the comment. */
|
|
61
|
+
status: WP_CommentStatus;
|
|
62
|
+
/** Type of the comment. */
|
|
63
|
+
type: WP_CommentType;
|
|
64
|
+
/** Avatar URLs for the comment author. */
|
|
65
|
+
author_avatar_urls: WP_CommentAvatarUrls;
|
|
66
|
+
/** Meta fields. */
|
|
67
|
+
meta: Record<string, unknown>;
|
|
68
|
+
/** Hypermedia links. */
|
|
69
|
+
_links?: WP_CommentLinks;
|
|
70
|
+
}
|
|
71
|
+
interface WP_CommentListInput {
|
|
72
|
+
/** Scope under which the request is made; determines fields present in response. */
|
|
73
|
+
context?: WP_Context;
|
|
74
|
+
/** Current page of the collection. */
|
|
75
|
+
page?: number;
|
|
76
|
+
/** Maximum number of items to be returned in result set. */
|
|
77
|
+
per_page?: number;
|
|
78
|
+
/** Limit results to those matching a string. */
|
|
79
|
+
search?: string;
|
|
80
|
+
/** Limit response to comments published after a given ISO8601 compliant date. */
|
|
81
|
+
after?: string;
|
|
82
|
+
/** Limit result set to comments assigned to specific user IDs. Requires authorization. */
|
|
83
|
+
author?: number | number[];
|
|
84
|
+
/** Ensure result set excludes comments assigned to specific user IDs. Requires authorization. */
|
|
85
|
+
author_exclude?: number | number[];
|
|
86
|
+
/** Limit result set to that from a specific author email. Requires authorization. */
|
|
87
|
+
author_email?: string;
|
|
88
|
+
/** Limit response to comments published before a given ISO8601 compliant date. */
|
|
89
|
+
before?: string;
|
|
90
|
+
/** Ensure result set excludes specific IDs. */
|
|
91
|
+
exclude?: number | number[];
|
|
92
|
+
/** Limit result set to specific IDs. */
|
|
93
|
+
include?: number | number[];
|
|
94
|
+
/** Offset the result set by a specific number of items. */
|
|
95
|
+
offset?: number;
|
|
96
|
+
/** Order sort attribute ascending or descending. */
|
|
97
|
+
order?: WP_ListOrder;
|
|
98
|
+
/** Sort collection by comment attribute. */
|
|
99
|
+
orderby?: WP_CommentOrderBy;
|
|
100
|
+
/** Limit result set to comments of specific parent IDs. */
|
|
101
|
+
parent?: number | number[];
|
|
102
|
+
/** Ensure result set excludes specific parent IDs. */
|
|
103
|
+
parent_exclude?: number | number[];
|
|
104
|
+
/** Limit result set to comments assigned to specific post IDs. */
|
|
105
|
+
post?: number | number[];
|
|
106
|
+
/** Limit result set to comments assigned a specific status. Requires authorization. */
|
|
107
|
+
status?: WP_CommentStatusFilter | WP_CommentStatusFilter[];
|
|
108
|
+
/** Limit result set to comments assigned a specific type. Requires authorization. */
|
|
109
|
+
type?: string;
|
|
110
|
+
/** The password for the post if it is password protected. */
|
|
111
|
+
password?: string;
|
|
112
|
+
}
|
|
113
|
+
type WP_CommentListErrorCode = "rest_cannot_read" | "rest_cannot_read_post" | "rest_forbidden_context" | "rest_forbidden_param" | "rest_comment_not_supported_post_type";
|
|
114
|
+
/** Content payload accepted when creating or updating a comment. */
|
|
115
|
+
type WP_CommentContentInput = string | {
|
|
116
|
+
raw: string;
|
|
117
|
+
};
|
|
118
|
+
interface WP_CommentCreateInput {
|
|
119
|
+
/** The ID of the user object, if author was a user. */
|
|
120
|
+
author?: number;
|
|
121
|
+
/** Email address for the comment author. */
|
|
122
|
+
author_email?: string;
|
|
123
|
+
/** IP address for the comment author. */
|
|
124
|
+
author_ip?: string;
|
|
125
|
+
/** Display name for the comment author. */
|
|
126
|
+
author_name?: string;
|
|
127
|
+
/** URL for the comment author. */
|
|
128
|
+
author_url?: string;
|
|
129
|
+
/** User agent for the comment author. */
|
|
130
|
+
author_user_agent?: string;
|
|
131
|
+
/** The content for the comment. */
|
|
132
|
+
content?: WP_CommentContentInput;
|
|
133
|
+
/** The date the comment was published, in the site's timezone. */
|
|
134
|
+
date?: string;
|
|
135
|
+
/** The date the comment was published, as GMT. */
|
|
136
|
+
date_gmt?: string;
|
|
137
|
+
/** The ID for the parent of the comment. */
|
|
138
|
+
parent?: number;
|
|
139
|
+
/** The ID of the associated post object. */
|
|
140
|
+
post?: number;
|
|
141
|
+
/** State of the comment. */
|
|
142
|
+
status?: WP_CommentStatusInput;
|
|
143
|
+
/** Meta fields. */
|
|
144
|
+
meta?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
type WP_CommentCreateErrorCode = "rest_comment_author_data_required" | "rest_comment_author_invalid" | "rest_comment_content_invalid" | "rest_comment_exists" | "rest_invalid_comment_type" | "rest_cannot_read_post" | "rest_comment_login_required" | "rest_cannot_create_note" | "rest_comment_closed" | "rest_comment_draft_post" | "rest_comment_invalid_author" | "rest_comment_invalid_author_ip" | "rest_comment_invalid_post_id" | "rest_comment_invalid_status" | "rest_comment_not_supported_post_type" | "rest_comment_trash_post" | "rest_comment_failed_create";
|
|
147
|
+
interface WP_CommentRetrieveInput {
|
|
148
|
+
/** Unique identifier for the comment. */
|
|
149
|
+
id: number;
|
|
150
|
+
/** Scope under which the request is made; determines fields present in response. */
|
|
151
|
+
context?: WP_Context;
|
|
152
|
+
/** The password for the parent post of the comment (if the post is password protected). */
|
|
153
|
+
password?: string | undefined;
|
|
154
|
+
}
|
|
155
|
+
type WP_CommentRetrieveErrorCode = "rest_cannot_read" | "rest_cannot_read_post" | "rest_forbidden_context" | "rest_comment_invalid_id" | "rest_post_invalid_id";
|
|
156
|
+
interface WP_CommentUpdateInput {
|
|
157
|
+
/** Unique identifier for the comment. */
|
|
158
|
+
id: number;
|
|
159
|
+
/** The ID of the user object, if author was a user. */
|
|
160
|
+
author?: number;
|
|
161
|
+
/** Email address for the comment author. */
|
|
162
|
+
author_email?: string;
|
|
163
|
+
/** IP address for the comment author. */
|
|
164
|
+
author_ip?: string;
|
|
165
|
+
/** Display name for the comment author. */
|
|
166
|
+
author_name?: string;
|
|
167
|
+
/** URL for the comment author. */
|
|
168
|
+
author_url?: string;
|
|
169
|
+
/** User agent for the comment author. */
|
|
170
|
+
author_user_agent?: string;
|
|
171
|
+
/** The content for the comment. */
|
|
172
|
+
content?: WP_CommentContentInput;
|
|
173
|
+
/** The date the comment was published, in the site's timezone. */
|
|
174
|
+
date?: string;
|
|
175
|
+
/** The date the comment was published, as GMT. */
|
|
176
|
+
date_gmt?: string;
|
|
177
|
+
/** The ID for the parent of the comment. */
|
|
178
|
+
parent?: number;
|
|
179
|
+
/** The ID of the associated post object. */
|
|
180
|
+
post?: number;
|
|
181
|
+
/** State of the comment. */
|
|
182
|
+
status?: WP_CommentStatusInput;
|
|
183
|
+
/** Meta fields. */
|
|
184
|
+
meta?: Record<string, unknown>;
|
|
185
|
+
}
|
|
186
|
+
type WP_CommentUpdateErrorCode = "rest_comment_author_invalid" | "rest_comment_content_invalid" | "rest_cannot_edit" | "rest_comment_invalid_post_id" | "rest_comment_invalid_id" | "rest_comment_invalid_type" | "rest_post_invalid_id" | "rest_comment_failed_edit";
|
|
187
|
+
interface WP_CommentDeleteInput {
|
|
188
|
+
/** Unique identifier for the comment. */
|
|
189
|
+
id: number;
|
|
190
|
+
/** Whether to bypass Trash and force deletion. */
|
|
191
|
+
force?: boolean;
|
|
192
|
+
/** The password for the parent post of the comment (if the post is password protected). */
|
|
193
|
+
password?: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Response from `DELETE /wp/v2/comments/<id>`.
|
|
197
|
+
* - When `force=true`: returns `{ deleted: true, previous: WP_Comment }`.
|
|
198
|
+
* - When `force=false` (trashed): returns the updated `WP_Comment` with `status: "trash"`.
|
|
199
|
+
*/
|
|
200
|
+
type WP_CommentDeleteResponse = WP_Comment | {
|
|
201
|
+
deleted: true;
|
|
202
|
+
previous: WP_Comment;
|
|
203
|
+
};
|
|
204
|
+
type WP_CommentDeleteErrorCode = "rest_cannot_delete" | "rest_comment_invalid_id" | "rest_post_invalid_id" | "rest_already_trashed" | "rest_trash_not_supported";
|
|
205
|
+
//#endregion
|
|
206
|
+
export { WP_Comment, WP_CommentAvatarUrls, WP_CommentContent, WP_CommentContentInput, WP_CommentCreateErrorCode, WP_CommentCreateInput, WP_CommentDeleteErrorCode, WP_CommentDeleteInput, WP_CommentDeleteResponse, WP_CommentLinks, WP_CommentListErrorCode, WP_CommentListInput, WP_CommentOrderBy, WP_CommentRetrieveErrorCode, WP_CommentRetrieveInput, WP_CommentStatus, WP_CommentStatusFilter, WP_CommentStatusInput, WP_CommentType, WP_CommentUpdateErrorCode, WP_CommentUpdateInput };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Duration } from "@kizlo/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/wordpress/constants.d.ts
|
|
4
|
+
declare const WC_CORE_BASE = "/wp-json/wc/v3";
|
|
5
|
+
declare const WP_CORE_BASE = "/wp-json/wp/v2";
|
|
6
|
+
declare const WP_KIZLO_BASE = "/wp-json/kizlo/v1";
|
|
7
|
+
declare const WC_STORE_BASE = "/wp-json/wc/store/v1";
|
|
8
|
+
declare const CART_HASH_HEADER_KEY = "cart-hash";
|
|
9
|
+
declare const WP_AUTH_TYPE = "Basic";
|
|
10
|
+
declare const WP_AUTH_HEADER_KEY = "authorization";
|
|
11
|
+
declare const UNEXPECTED_BODY_SNIPPET_LENGTH = 500;
|
|
12
|
+
declare const SAFE_REQUEST_TIMEOUT: Duration;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { CART_HASH_HEADER_KEY, SAFE_REQUEST_TIMEOUT, UNEXPECTED_BODY_SNIPPET_LENGTH, WC_CORE_BASE, WC_STORE_BASE, WP_AUTH_HEADER_KEY, WP_AUTH_TYPE, WP_CORE_BASE, WP_KIZLO_BASE };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/wordpress/constants.ts
|
|
2
|
+
const WC_CORE_BASE = `/wp-json/wc/v3`;
|
|
3
|
+
const WP_CORE_BASE = "/wp-json/wp/v2";
|
|
4
|
+
const WP_KIZLO_BASE = `/wp-json/kizlo/v1`;
|
|
5
|
+
const WC_STORE_BASE = `/wp-json/wc/store/v1`;
|
|
6
|
+
const CART_HASH_HEADER_KEY = "cart-hash";
|
|
7
|
+
const WP_AUTH_TYPE = "Basic";
|
|
8
|
+
const WP_AUTH_HEADER_KEY = "authorization";
|
|
9
|
+
const UNEXPECTED_BODY_SNIPPET_LENGTH = 500;
|
|
10
|
+
const SAFE_REQUEST_TIMEOUT = "30 seconds";
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { CART_HASH_HEADER_KEY, SAFE_REQUEST_TIMEOUT, UNEXPECTED_BODY_SNIPPET_LENGTH, WC_CORE_BASE, WC_STORE_BASE, WP_AUTH_HEADER_KEY, WP_AUTH_TYPE, WP_CORE_BASE, WP_KIZLO_BASE };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WP_CommonErrorCode, WP_ErrorData } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/wordpress/error.d.ts
|
|
4
|
+
declare class WP_Error<TCode extends string = string> extends Error {
|
|
5
|
+
code: TCode | WP_CommonErrorCode;
|
|
6
|
+
constructor(error: WP_ErrorData<TCode>);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { WP_Error };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/wordpress/error.ts
|
|
2
|
+
var WP_Error = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(error) {
|
|
5
|
+
super(error.message ?? "Internal server error, please try again.");
|
|
6
|
+
this.name = "WordPress Error";
|
|
7
|
+
this.code = error.code;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { WP_Error };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WP_Error } from "./error.js";
|
|
2
|
+
import { WP_CommonErrorCode, WP_Context, WP_CurrencyFormat, WP_ErrorData, WP_Link, WP_List, WP_ListMetadata, WP_ListOrder, WP_RequestInput, WP_Result, WordPressCredentials } from "./types.js";
|
|
3
|
+
import { WP_MenuItem, WP_MenuItemCreateErrorCode, WP_MenuItemCreateInput, WP_MenuItemDeleteErrorCode, WP_MenuItemDeleteInput, WP_MenuItemDeleteResponse, WP_MenuItemLinks, WP_MenuItemListErrorCode, WP_MenuItemListInput, WP_MenuItemOrderBy, WP_MenuItemRetrieveErrorCode, WP_MenuItemRetrieveInput, WP_MenuItemStatus, WP_MenuItemStatusFilter, WP_MenuItemTarget, WP_MenuItemTaxRelation, WP_MenuItemTitle, WP_MenuItemTitleInput, WP_MenuItemType, WP_MenuItemUpdateErrorCode, WP_MenuItemUpdateInput } from "./menu/items/types.js";
|
|
4
|
+
import { MenuItemService } from "./menu/items/service.js";
|
|
5
|
+
import { WP_Menu, WP_MenuCreateErrorCode, WP_MenuCreateInput, WP_MenuDeleteErrorCode, WP_MenuDeleteInput, WP_MenuDeleteResponse, WP_MenuLinks, WP_MenuListErrorCode, WP_MenuListInput, WP_MenuOrderBy, WP_MenuRetrieveErrorCode, WP_MenuRetrieveInput, WP_MenuUpdateErrorCode, WP_MenuUpdateInput } from "./menu/types.js";
|
|
6
|
+
import { MenuService } from "./menu/service.js";
|
|
7
|
+
import { WP_Post, WP_PostCommentStatus, WP_PostContent, WP_PostContentInput, WP_PostCreateErrorCode, WP_PostCreateInput, WP_PostDeleteErrorCode, WP_PostDeleteInput, WP_PostDeleteResponse, WP_PostExcerpt, WP_PostExcerptInput, WP_PostFormat, WP_PostGuid, WP_PostLinks, WP_PostListErrorCode, WP_PostListInput, WP_PostOrderBy, WP_PostRetrieveErrorCode, WP_PostRetrieveInput, WP_PostStatus, WP_PostStatusFilter, WP_PostTaxRelation, WP_PostTitle, WP_PostTitleInput, WP_PostUpdateErrorCode, WP_PostUpdateInput } from "./post/types.js";
|
|
8
|
+
import { PostService } from "./post/service.js";
|
|
9
|
+
import { WP_User, WP_UserAvatarUrls, WP_UserCapabilities, WP_UserCreateErrorCode, WP_UserCreateInput, WP_UserDeleteErrorCode, WP_UserDeleteInput, WP_UserDeleteMeErrorCode, WP_UserDeleteMeInput, WP_UserDeleteMeResponse, WP_UserDeleteResponse, WP_UserLinks, WP_UserListErrorCode, WP_UserListInput, WP_UserOrderBy, WP_UserRetrieveErrorCode, WP_UserRetrieveInput, WP_UserRetrieveMeErrorCode, WP_UserRetrieveMeInput, WP_UserUpdateErrorCode, WP_UserUpdateInput, WP_UserUpdateMeErrorCode, WP_UserUpdateMeInput, WP_UserWho } from "./user/types.js";
|
|
10
|
+
import { UserService } from "./user/service.js";
|
|
11
|
+
import { WordPressService } from "./service.js";
|
|
12
|
+
import { WP_Comment, WP_CommentAvatarUrls, WP_CommentContent, WP_CommentContentInput, WP_CommentCreateErrorCode, WP_CommentCreateInput, WP_CommentDeleteErrorCode, WP_CommentDeleteInput, WP_CommentDeleteResponse, WP_CommentLinks, WP_CommentListErrorCode, WP_CommentListInput, WP_CommentOrderBy, WP_CommentRetrieveErrorCode, WP_CommentRetrieveInput, WP_CommentStatus, WP_CommentStatusFilter, WP_CommentStatusInput, WP_CommentType, WP_CommentUpdateErrorCode, WP_CommentUpdateInput } from "./comment/types.js";
|
|
13
|
+
import { CommentService } from "./comment/service.js";
|
|
14
|
+
import { CART_HASH_HEADER_KEY, SAFE_REQUEST_TIMEOUT, UNEXPECTED_BODY_SNIPPET_LENGTH, WC_CORE_BASE, WC_STORE_BASE, WP_AUTH_HEADER_KEY, WP_AUTH_TYPE, WP_CORE_BASE, WP_KIZLO_BASE } from "./constants.js";
|
|
15
|
+
import { isWordPressResourceError } from "./utils.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WP_Error } from "../../error.js";
|
|
2
|
+
import { WP_List, WP_Result } from "../../types.js";
|
|
3
|
+
import { WP_MenuItem, WP_MenuItemCreateErrorCode, WP_MenuItemCreateInput, WP_MenuItemDeleteErrorCode, WP_MenuItemDeleteInput, WP_MenuItemDeleteResponse, WP_MenuItemListErrorCode, WP_MenuItemListInput, WP_MenuItemRetrieveErrorCode, WP_MenuItemRetrieveInput, WP_MenuItemUpdateErrorCode, WP_MenuItemUpdateInput } from "./types.js";
|
|
4
|
+
import { WordPressService } from "../../service.js";
|
|
5
|
+
import "../../index.js";
|
|
6
|
+
|
|
7
|
+
//#region src/wordpress/menu/items/service.d.ts
|
|
8
|
+
declare class MenuItemService {
|
|
9
|
+
private readonly wordpress;
|
|
10
|
+
constructor(wordpress: WordPressService);
|
|
11
|
+
list(input: WP_MenuItemListInput): Promise<{
|
|
12
|
+
data: null;
|
|
13
|
+
status: number;
|
|
14
|
+
headers: Headers;
|
|
15
|
+
error: WP_Error<WP_MenuItemListErrorCode>;
|
|
16
|
+
} | {
|
|
17
|
+
data: WP_List<WP_MenuItem>;
|
|
18
|
+
status: number;
|
|
19
|
+
headers: Headers;
|
|
20
|
+
error: null;
|
|
21
|
+
}>;
|
|
22
|
+
create(input: WP_MenuItemCreateInput): Promise<WP_Result<WP_MenuItem, WP_MenuItemCreateErrorCode>>;
|
|
23
|
+
get(input: WP_MenuItemRetrieveInput): Promise<WP_Result<WP_MenuItem, WP_MenuItemRetrieveErrorCode>>;
|
|
24
|
+
update(input: WP_MenuItemUpdateInput): Promise<WP_Result<WP_MenuItem, WP_MenuItemUpdateErrorCode>>;
|
|
25
|
+
delete(input: WP_MenuItemDeleteInput): Promise<WP_Result<WP_MenuItemDeleteResponse, WP_MenuItemDeleteErrorCode>>;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { MenuItemService };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WP_CORE_BASE } from "../../constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/wordpress/menu/items/service.ts
|
|
4
|
+
var MenuItemService = class {
|
|
5
|
+
wordpress;
|
|
6
|
+
constructor(wordpress) {
|
|
7
|
+
this.wordpress = wordpress;
|
|
8
|
+
}
|
|
9
|
+
async list(input) {
|
|
10
|
+
const { ...searchParams } = input;
|
|
11
|
+
const result = await this.wordpress.get("/menu-items", {
|
|
12
|
+
base: WP_CORE_BASE,
|
|
13
|
+
searchParams
|
|
14
|
+
});
|
|
15
|
+
if (result.error) return result;
|
|
16
|
+
return {
|
|
17
|
+
...result,
|
|
18
|
+
data: this.wordpress.resolveList({
|
|
19
|
+
data: result.data,
|
|
20
|
+
headers: result.headers,
|
|
21
|
+
searchParams
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async create(input) {
|
|
26
|
+
return this.wordpress.post("/menu-items", {
|
|
27
|
+
base: WP_CORE_BASE,
|
|
28
|
+
body: input
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async get(input) {
|
|
32
|
+
const { id,...searchParams } = input;
|
|
33
|
+
return this.wordpress.get(`/menu-items/${id}`, {
|
|
34
|
+
base: WP_CORE_BASE,
|
|
35
|
+
searchParams
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async update(input) {
|
|
39
|
+
const { id,...body } = input;
|
|
40
|
+
return this.wordpress.post(`/menu-items/${id}`, {
|
|
41
|
+
base: WP_CORE_BASE,
|
|
42
|
+
body
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async delete(input) {
|
|
46
|
+
const { id,...searchParams } = input;
|
|
47
|
+
return this.wordpress.delete(`/menu-items/${id}`, {
|
|
48
|
+
base: WP_CORE_BASE,
|
|
49
|
+
searchParams
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { MenuItemService };
|