kizlo 0.7.0 → 0.8.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/category/error.js +14 -0
- package/dist/category/index.js +77 -0
- package/dist/category/schema.js +40 -0
- package/dist/category/utils.js +20 -0
- package/dist/cli/banner.js +1 -1
- package/dist/cli/commands/_setup.js +342 -0
- package/dist/cli/commands/create.js +146 -0
- package/dist/cli/commands/dev.js +1 -1
- package/dist/cli/commands/init.js +53 -300
- package/dist/cli/index.js +2 -1
- package/dist/cli/presets/generated/templates.js +59 -0
- package/dist/cli/presets/nextjs.js +3 -95
- package/dist/cli/presets/patch.js +133 -0
- package/dist/cli/presets/template.js +36 -0
- package/dist/comment/index.js +4 -4
- package/dist/context.d.ts +25 -8
- package/dist/context.js +15 -5
- package/dist/email/service.d.ts +4 -3
- package/dist/email/service.js +4 -4
- package/dist/index.d.ts +15 -11
- package/dist/index.js +10 -4
- package/dist/integrations/nextjs/metadata.js +6 -3
- package/dist/integrations/nextjs/sitemap.d.ts +8 -7
- package/dist/integrations/nextjs/sitemap.js +3 -3
- package/dist/menu/index.js +19 -14
- package/dist/menu/schema.d.ts +14 -0
- package/dist/menu/schema.js +35 -40
- package/dist/menu/utils.js +23 -14
- package/dist/nextjs/server.d.ts +2 -1
- package/dist/nextjs/server.js +2 -1
- package/dist/package.js +1 -1
- package/dist/page/error.js +20 -0
- package/dist/page/index.js +128 -0
- package/dist/page/schema.js +75 -0
- package/dist/page/utils.js +43 -0
- package/dist/post/error.js +4 -14
- package/dist/post/index.js +17 -9
- package/dist/post/schema.js +37 -66
- package/dist/post/utils.js +27 -24
- package/dist/router.d.ts +1006 -185
- package/dist/router.js +6 -0
- package/dist/seo/index.js +7 -44
- package/dist/seo/schema.d.ts +10 -6
- package/dist/seo/schema.js +7 -5
- package/dist/seo/sitemap.d.ts +9 -1
- package/dist/seo/sitemap.js +17 -1
- package/dist/seo/types.d.ts +17 -20
- package/dist/seo/utils.js +9 -7
- package/dist/settings/index.js +27 -24
- package/dist/settings/service.d.ts +14 -13
- package/dist/settings/service.interface.d.ts +2 -2
- package/dist/settings/service.js +9 -9
- package/dist/shared/middleware.d.ts +4 -4
- package/dist/shared/procedure.d.ts +6 -7
- package/dist/tag/error.js +14 -0
- package/dist/tag/index.js +76 -0
- package/dist/tag/schema.js +38 -0
- package/dist/tag/utils.js +19 -0
- package/dist/taxonomy/service.js +48 -0
- package/dist/test/fixtures.d.ts +1 -1
- package/dist/test/fixtures.js +1 -1
- package/dist/webhook/index.d.ts +2 -2
- package/dist/wordpress/category/service.d.ts +28 -0
- package/dist/wordpress/category/service.js +55 -0
- package/dist/wordpress/category/types.d.ts +120 -0
- package/dist/wordpress/category/types.js +15 -0
- package/dist/wordpress/comment/service.d.ts +1 -1
- package/dist/wordpress/index.d.ts +9 -4
- package/dist/wordpress/menu/items/types.d.ts +7 -4
- package/dist/wordpress/menu/items/types.js +22 -0
- package/dist/wordpress/page/service.d.ts +28 -0
- package/dist/wordpress/page/service.js +55 -0
- package/dist/wordpress/page/types.d.ts +270 -0
- package/dist/wordpress/page/types.js +27 -0
- package/dist/wordpress/post/types.d.ts +9 -5
- package/dist/wordpress/post/types.js +41 -0
- package/dist/wordpress/service.d.ts +7 -1
- package/dist/wordpress/service.js +6 -0
- package/dist/wordpress/tag/service.d.ts +28 -0
- package/dist/wordpress/tag/service.js +55 -0
- package/dist/wordpress/tag/types.d.ts +113 -0
- package/dist/wordpress/tag/types.js +15 -0
- package/package.json +5 -3
- package/dist/service.d.ts +0 -19
- package/dist/service.js +0 -20
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createProcedure } from "../shared/procedure.js";
|
|
2
|
+
import { parseIdentifier } from "../shared/identifier.js";
|
|
3
|
+
import { deserializeListMetadata } from "../shared/serialize.js";
|
|
4
|
+
import { getTaxonomyService } from "../taxonomy/service.js";
|
|
5
|
+
import { GET_TAG_ERROR_MAP, LIST_TAG_ERROR_MAP } from "./error.js";
|
|
6
|
+
import { ListTagInput, RetrieveTagInput, Tag, TagList } from "./schema.js";
|
|
7
|
+
import { deserializeTag } from "./utils.js";
|
|
8
|
+
|
|
9
|
+
//#region src/tag/index.ts
|
|
10
|
+
const TAG_ROUTER_MAP = {
|
|
11
|
+
get: createProcedure({
|
|
12
|
+
scope: "api",
|
|
13
|
+
method: "GET",
|
|
14
|
+
path: "/tags/{identifier}",
|
|
15
|
+
params: RetrieveTagInput.pick({ identifier: true }),
|
|
16
|
+
output: Tag,
|
|
17
|
+
errors: GET_TAG_ERROR_MAP
|
|
18
|
+
}, async ({ input, context, errors }) => {
|
|
19
|
+
const taxonomy = getTaxonomyService("post_tag", context.wordpress);
|
|
20
|
+
const identifier = parseIdentifier(input.params.identifier);
|
|
21
|
+
if (!identifier) throw errors.TAG_NOT_FOUND();
|
|
22
|
+
const response = await taxonomy.get(identifier);
|
|
23
|
+
if (response.error) switch (response.error.code) {
|
|
24
|
+
case "invalid_taxonomy":
|
|
25
|
+
case "term_not_found":
|
|
26
|
+
case "rest_term_invalid": throw errors.TAG_NOT_FOUND();
|
|
27
|
+
default:
|
|
28
|
+
context.logger.error("Get tag unhandled error", response.error, {
|
|
29
|
+
identifier,
|
|
30
|
+
code: response.error.code
|
|
31
|
+
});
|
|
32
|
+
throw errors.INTERNAL_SERVER_ERROR();
|
|
33
|
+
}
|
|
34
|
+
return deserializeTag(response.data);
|
|
35
|
+
}),
|
|
36
|
+
list: createProcedure({
|
|
37
|
+
scope: "api",
|
|
38
|
+
method: "GET",
|
|
39
|
+
path: "/tags",
|
|
40
|
+
query: ListTagInput.optional(),
|
|
41
|
+
output: TagList,
|
|
42
|
+
errors: LIST_TAG_ERROR_MAP
|
|
43
|
+
}, async ({ input, context, errors }) => {
|
|
44
|
+
const response = await getTaxonomyService("post_tag", context.wordpress).list({
|
|
45
|
+
context: "edit",
|
|
46
|
+
page: input.query?.page,
|
|
47
|
+
per_page: input.query?.perPage,
|
|
48
|
+
search: input.query?.search,
|
|
49
|
+
exclude: input.query?.exclude,
|
|
50
|
+
include: input.query?.include,
|
|
51
|
+
order: input.query?.order,
|
|
52
|
+
orderby: input.query?.orderBy,
|
|
53
|
+
hide_empty: input.query?.hideEmpty,
|
|
54
|
+
post: input.query?.post,
|
|
55
|
+
slug: input.query?.slug
|
|
56
|
+
});
|
|
57
|
+
if (response.error) switch (response.error.code) {
|
|
58
|
+
case "rest_post_invalid_page_number": throw errors.TAG_INVALID_PAGE();
|
|
59
|
+
default:
|
|
60
|
+
context.logger.error("List tags unhandled error", response.error, { code: response.error.code });
|
|
61
|
+
throw errors.INTERNAL_SERVER_ERROR();
|
|
62
|
+
}
|
|
63
|
+
const list = context.wordpress.resolveList({
|
|
64
|
+
data: response.data,
|
|
65
|
+
headers: response.headers,
|
|
66
|
+
searchParams: input.query
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
meta: deserializeListMetadata(list.meta),
|
|
70
|
+
items: list.items.map((item) => deserializeTag(item))
|
|
71
|
+
};
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { TAG_ROUTER_MAP };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IdentifierInput, ListMetadata, ListOrder } from "../shared/schema.js";
|
|
2
|
+
import { WP_TAG_ORDER_BYS } from "../wordpress/tag/types.js";
|
|
3
|
+
import { Seo } from "../seo/schema.js";
|
|
4
|
+
import { BooleanLike, Metadata, NumberLike, arrayable, lenient } from "@kizlo/shared";
|
|
5
|
+
import z from "zod/v4";
|
|
6
|
+
|
|
7
|
+
//#region src/tag/schema.ts
|
|
8
|
+
const Tag = z.object({
|
|
9
|
+
id: z.number(),
|
|
10
|
+
name: z.string(),
|
|
11
|
+
slug: z.string(),
|
|
12
|
+
url: z.string().nullable(),
|
|
13
|
+
description: z.string().nullable(),
|
|
14
|
+
postCount: z.number(),
|
|
15
|
+
seo: Seo.nullable(),
|
|
16
|
+
meta: Metadata
|
|
17
|
+
});
|
|
18
|
+
const RetrieveTagInput = z.object({ identifier: IdentifierInput });
|
|
19
|
+
const TagList = z.object({
|
|
20
|
+
items: z.array(Tag),
|
|
21
|
+
meta: ListMetadata
|
|
22
|
+
});
|
|
23
|
+
const TagOrderBy = z.enum(WP_TAG_ORDER_BYS);
|
|
24
|
+
const ListTagInput = z.object({
|
|
25
|
+
page: NumberLike.pipe(z.number().int().min(1)).catch(1).optional(),
|
|
26
|
+
perPage: lenient(NumberLike.pipe(z.number().int().min(1).max(100))),
|
|
27
|
+
search: lenient(z.string()),
|
|
28
|
+
exclude: lenient(arrayable(NumberLike)),
|
|
29
|
+
include: lenient(arrayable(NumberLike)),
|
|
30
|
+
order: lenient(ListOrder),
|
|
31
|
+
orderBy: lenient(TagOrderBy),
|
|
32
|
+
hideEmpty: lenient(BooleanLike),
|
|
33
|
+
post: lenient(NumberLike),
|
|
34
|
+
slug: lenient(arrayable(z.string()))
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ListTagInput, RetrieveTagInput, Tag, TagList };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { deserializeSeo } from "../seo/utils.js";
|
|
2
|
+
import { stringifiedMetaRecord } from "@kizlo/shared";
|
|
3
|
+
|
|
4
|
+
//#region src/tag/utils.ts
|
|
5
|
+
function deserializeTag(data) {
|
|
6
|
+
return {
|
|
7
|
+
id: data.id,
|
|
8
|
+
name: data.name,
|
|
9
|
+
slug: data.slug,
|
|
10
|
+
url: data.kizlo.url ?? null,
|
|
11
|
+
description: data.description.length > 0 ? data.description : null,
|
|
12
|
+
postCount: data.count,
|
|
13
|
+
seo: data.kizlo.seo ? deserializeSeo(data.kizlo.seo) : null,
|
|
14
|
+
meta: stringifiedMetaRecord(data.meta ?? {})
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { deserializeTag };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WP_KIZLO_BASE } from "../wordpress/constants.js";
|
|
2
|
+
import { trimLeadingTrailingSlashes } from "@kizlo/shared";
|
|
3
|
+
|
|
4
|
+
//#region src/taxonomy/service.ts
|
|
5
|
+
var TaxonomyService = class {
|
|
6
|
+
key;
|
|
7
|
+
wordpress;
|
|
8
|
+
constructor(key, wordpress) {
|
|
9
|
+
this.key = key;
|
|
10
|
+
this.wordpress = wordpress;
|
|
11
|
+
}
|
|
12
|
+
async get(identifier) {
|
|
13
|
+
return await this.wordpress.get(this.resolvePath(identifier), { base: WP_KIZLO_BASE });
|
|
14
|
+
}
|
|
15
|
+
async list(input) {
|
|
16
|
+
return await this.wordpress.get(this.resolvePath(), {
|
|
17
|
+
base: WP_KIZLO_BASE,
|
|
18
|
+
searchParams: { ...input }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async create(input) {
|
|
22
|
+
return await this.wordpress.post(this.resolvePath(), {
|
|
23
|
+
base: WP_KIZLO_BASE,
|
|
24
|
+
body: input
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async update(input) {
|
|
28
|
+
return await this.wordpress.put(this.resolvePath(input.identifier), {
|
|
29
|
+
base: WP_KIZLO_BASE,
|
|
30
|
+
body: input
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async delete(input) {
|
|
34
|
+
return await this.wordpress.delete(this.resolvePath(input.identifier), {
|
|
35
|
+
base: WP_KIZLO_BASE,
|
|
36
|
+
searchParams: { force: input.force }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
resolvePath(identifier) {
|
|
40
|
+
return `/taxonomies/${trimLeadingTrailingSlashes(this.key)}${identifier ? `/${identifier.value}` : ``}`;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
function getTaxonomyService(key, wordpress) {
|
|
44
|
+
return new TaxonomyService(key, wordpress);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { getTaxonomyService };
|
package/dist/test/fixtures.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { postFixture } from "../post/fixture.js";
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The kizlo core content fixtures (posts/comments + menu). Mount these in
|
|
9
|
-
* `kizlo.config.ts` so the
|
|
9
|
+
* `kizlo.config.ts` so the framework's own suites have content to read; consumers
|
|
10
10
|
* who only need a clean WP stack can leave them out.
|
|
11
11
|
*/
|
|
12
12
|
declare const coreFixtures: Fixture[];
|
package/dist/test/fixtures.js
CHANGED
|
@@ -4,7 +4,7 @@ import { postFixture } from "../post/fixture.js";
|
|
|
4
4
|
//#region src/test/fixtures.ts
|
|
5
5
|
/**
|
|
6
6
|
* The kizlo core content fixtures (posts/comments + menu). Mount these in
|
|
7
|
-
* `kizlo.config.ts` so the
|
|
7
|
+
* `kizlo.config.ts` so the framework's own suites have content to read; consumers
|
|
8
8
|
* who only need a clean WP stack can leave them out.
|
|
9
9
|
*/
|
|
10
10
|
const coreFixtures = [postFixture(), menuFixture()];
|
package/dist/webhook/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProcedureContext } from "../context.js";
|
|
2
2
|
import { KizloEvent } from "./schema.js";
|
|
3
3
|
import { DefinedErrorMapLike } from "../shared/error.js";
|
|
4
4
|
import { Procedure } from "../shared/procedure.js";
|
|
@@ -17,7 +17,7 @@ type InferEventUnion<T extends AnyEvents> = { [K in keyof T]: {
|
|
|
17
17
|
type: T[K]["types"][number];
|
|
18
18
|
data: SchemaOutput<T[K]["data"]>;
|
|
19
19
|
} }[number];
|
|
20
|
-
type EventHandlerFn<T extends AnyEvents> = (event: InferEventUnion<T> | KizloEvent | null, context:
|
|
20
|
+
type EventHandlerFn<T extends AnyEvents> = (event: InferEventUnion<T> | KizloEvent | null, context: ProcedureContext) => Promise<void> | void;
|
|
21
21
|
interface WebhookOptions {
|
|
22
22
|
events?: EventHandler[];
|
|
23
23
|
}
|
|
@@ -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_Category, WP_CategoryCreateErrorCode, WP_CategoryCreateInput, WP_CategoryDeleteErrorCode, WP_CategoryDeleteInput, WP_CategoryDeleteResponse, WP_CategoryListErrorCode, WP_CategoryListInput, WP_CategoryRetrieveErrorCode, WP_CategoryRetrieveInput, WP_CategoryUpdateErrorCode, WP_CategoryUpdateInput } from "./types.js";
|
|
5
|
+
import "../index.js";
|
|
6
|
+
|
|
7
|
+
//#region src/wordpress/category/service.d.ts
|
|
8
|
+
declare class CategoryService {
|
|
9
|
+
private readonly wordpress;
|
|
10
|
+
constructor(wordpress: WordPressService);
|
|
11
|
+
list(input: WP_CategoryListInput): Promise<{
|
|
12
|
+
data: null;
|
|
13
|
+
status: number;
|
|
14
|
+
headers: Headers;
|
|
15
|
+
error: WP_Error<WP_CategoryListErrorCode>;
|
|
16
|
+
} | {
|
|
17
|
+
data: WP_List<WP_Category>;
|
|
18
|
+
status: number;
|
|
19
|
+
headers: Headers;
|
|
20
|
+
error: null;
|
|
21
|
+
}>;
|
|
22
|
+
create(input: WP_CategoryCreateInput): Promise<WP_Result<WP_Category, WP_CategoryCreateErrorCode>>;
|
|
23
|
+
get(input: WP_CategoryRetrieveInput): Promise<WP_Result<WP_Category, WP_CategoryRetrieveErrorCode>>;
|
|
24
|
+
update(input: WP_CategoryUpdateInput): Promise<WP_Result<WP_Category, WP_CategoryUpdateErrorCode>>;
|
|
25
|
+
delete(input: WP_CategoryDeleteInput): Promise<WP_Result<WP_CategoryDeleteResponse, WP_CategoryDeleteErrorCode>>;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { CategoryService };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WP_CORE_BASE } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/wordpress/category/service.ts
|
|
4
|
+
var CategoryService = 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("/categories", {
|
|
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("/categories", {
|
|
27
|
+
base: WP_CORE_BASE,
|
|
28
|
+
body: input
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async get(input) {
|
|
32
|
+
const { id,...searchParams } = input;
|
|
33
|
+
return this.wordpress.get(`/categories/${id}`, {
|
|
34
|
+
base: WP_CORE_BASE,
|
|
35
|
+
searchParams
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async update(input) {
|
|
39
|
+
const { id,...body } = input;
|
|
40
|
+
return this.wordpress.post(`/categories/${id}`, {
|
|
41
|
+
base: WP_CORE_BASE,
|
|
42
|
+
body
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async delete(input) {
|
|
46
|
+
const { id,...searchParams } = input;
|
|
47
|
+
return this.wordpress.delete(`/categories/${id}`, {
|
|
48
|
+
base: WP_CORE_BASE,
|
|
49
|
+
searchParams
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { CategoryService };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { WP_Context, WP_Link, WP_ListOrder } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/wordpress/category/types.d.ts
|
|
4
|
+
/** Type attribution for the term. */
|
|
5
|
+
type WP_CategoryTaxonomy = "category";
|
|
6
|
+
/** Sort collection by term attribute. */
|
|
7
|
+
declare const WP_CATEGORY_ORDER_BYS: readonly ["id", "include", "name", "slug", "include_slugs", "term_group", "description", "count"];
|
|
8
|
+
type WP_CategoryOrderBy = (typeof WP_CATEGORY_ORDER_BYS)[number];
|
|
9
|
+
/** Hypermedia links for the category resource. */
|
|
10
|
+
interface WP_CategoryLinks {
|
|
11
|
+
self?: WP_Link[];
|
|
12
|
+
collection?: WP_Link[];
|
|
13
|
+
about?: WP_Link[];
|
|
14
|
+
up?: WP_Link[];
|
|
15
|
+
"wp:post_type"?: WP_Link[];
|
|
16
|
+
curies?: WP_Link[];
|
|
17
|
+
[rel: string]: WP_Link[] | undefined;
|
|
18
|
+
}
|
|
19
|
+
interface WP_Category {
|
|
20
|
+
/** Unique identifier for the term. */
|
|
21
|
+
id: number;
|
|
22
|
+
/** Number of published posts for the term. */
|
|
23
|
+
count: number;
|
|
24
|
+
/** HTML description of the term. */
|
|
25
|
+
description: string;
|
|
26
|
+
/** URL of the term. */
|
|
27
|
+
link: string;
|
|
28
|
+
/** HTML title for the term. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** An alphanumeric identifier for the term unique to its type. */
|
|
31
|
+
slug: string;
|
|
32
|
+
/** Type attribution for the term. */
|
|
33
|
+
taxonomy: WP_CategoryTaxonomy;
|
|
34
|
+
/** The parent term ID. */
|
|
35
|
+
parent: number;
|
|
36
|
+
/** Meta fields. */
|
|
37
|
+
meta: Record<string, unknown>;
|
|
38
|
+
/** Hypermedia links. */
|
|
39
|
+
_links?: WP_CategoryLinks;
|
|
40
|
+
}
|
|
41
|
+
interface WP_CategoryListInput {
|
|
42
|
+
/** Scope under which the request is made; determines fields present in response. */
|
|
43
|
+
context?: WP_Context;
|
|
44
|
+
/** Current page of the collection. */
|
|
45
|
+
page?: number;
|
|
46
|
+
/** Maximum number of items to be returned in result set. */
|
|
47
|
+
per_page?: number;
|
|
48
|
+
/** Limit results to those matching a string. */
|
|
49
|
+
search?: string;
|
|
50
|
+
/** Ensure result set excludes specific IDs. */
|
|
51
|
+
exclude?: number | number[];
|
|
52
|
+
/** Limit result set to specific IDs. */
|
|
53
|
+
include?: number | number[];
|
|
54
|
+
/** Order sort attribute ascending or descending. */
|
|
55
|
+
order?: WP_ListOrder;
|
|
56
|
+
/** Sort collection by term attribute. */
|
|
57
|
+
orderby?: WP_CategoryOrderBy;
|
|
58
|
+
/** Whether to hide terms not assigned to any posts. */
|
|
59
|
+
hide_empty?: boolean;
|
|
60
|
+
/** Limit result set to terms assigned to a specific parent. */
|
|
61
|
+
parent?: number;
|
|
62
|
+
/** Limit result set to terms assigned to a specific post. */
|
|
63
|
+
post?: number;
|
|
64
|
+
/** Limit result set to terms with one or more specific slugs. */
|
|
65
|
+
slug?: string | string[];
|
|
66
|
+
}
|
|
67
|
+
type WP_CategoryListErrorCode = "rest_post_invalid_page_number" | "rest_forbidden_context";
|
|
68
|
+
interface WP_CategoryCreateInput {
|
|
69
|
+
/** HTML description of the term. */
|
|
70
|
+
description?: string;
|
|
71
|
+
/** HTML title for the term. */
|
|
72
|
+
name?: string;
|
|
73
|
+
/** An alphanumeric identifier for the term unique to its type. */
|
|
74
|
+
slug?: string;
|
|
75
|
+
/** The parent term ID. */
|
|
76
|
+
parent?: number;
|
|
77
|
+
/** Meta fields. */
|
|
78
|
+
meta?: Record<string, unknown>;
|
|
79
|
+
}
|
|
80
|
+
type WP_CategoryCreateErrorCode = "rest_taxonomy_not_hierarchical" | "rest_term_invalid" | "rest_cannot_create";
|
|
81
|
+
interface WP_CategoryRetrieveInput {
|
|
82
|
+
/** Unique identifier for the term. */
|
|
83
|
+
id: number;
|
|
84
|
+
/** Scope under which the request is made; determines fields present in response. */
|
|
85
|
+
context?: WP_Context;
|
|
86
|
+
}
|
|
87
|
+
type WP_CategoryRetrieveErrorCode = "rest_forbidden_context" | "rest_term_invalid";
|
|
88
|
+
interface WP_CategoryUpdateInput {
|
|
89
|
+
/** Unique identifier for the term. */
|
|
90
|
+
id: number;
|
|
91
|
+
/** HTML description of the term. */
|
|
92
|
+
description?: string;
|
|
93
|
+
/** HTML title for the term. */
|
|
94
|
+
name?: string;
|
|
95
|
+
/** An alphanumeric identifier for the term unique to its type. */
|
|
96
|
+
slug?: string;
|
|
97
|
+
/** The parent term ID. */
|
|
98
|
+
parent?: number;
|
|
99
|
+
/** Meta fields. */
|
|
100
|
+
meta?: Record<string, unknown>;
|
|
101
|
+
}
|
|
102
|
+
type WP_CategoryUpdateErrorCode = "rest_taxonomy_not_hierarchical" | "rest_term_invalid" | "rest_cannot_update";
|
|
103
|
+
interface WP_CategoryDeleteInput {
|
|
104
|
+
/** Unique identifier for the term. */
|
|
105
|
+
id: number;
|
|
106
|
+
/** Required to be true, as terms do not support trashing. */
|
|
107
|
+
force?: boolean;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Response from `DELETE /wp/v2/categories/<id>`.
|
|
111
|
+
* Terms do not support trashing, so `force=true` is required and the response
|
|
112
|
+
* is always `{ deleted: true, previous: WP_Category }`.
|
|
113
|
+
*/
|
|
114
|
+
type WP_CategoryDeleteResponse = {
|
|
115
|
+
deleted: true;
|
|
116
|
+
previous: WP_Category;
|
|
117
|
+
};
|
|
118
|
+
type WP_CategoryDeleteErrorCode = "rest_cannot_delete" | "rest_term_invalid" | "rest_trash_not_supported";
|
|
119
|
+
//#endregion
|
|
120
|
+
export { WP_CATEGORY_ORDER_BYS, WP_Category, WP_CategoryCreateErrorCode, WP_CategoryCreateInput, WP_CategoryDeleteErrorCode, WP_CategoryDeleteInput, WP_CategoryDeleteResponse, WP_CategoryLinks, WP_CategoryListErrorCode, WP_CategoryListInput, WP_CategoryOrderBy, WP_CategoryRetrieveErrorCode, WP_CategoryRetrieveInput, WP_CategoryTaxonomy, WP_CategoryUpdateErrorCode, WP_CategoryUpdateInput };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/wordpress/category/types.ts
|
|
2
|
+
/** Sort collection by term attribute. */
|
|
3
|
+
const WP_CATEGORY_ORDER_BYS = [
|
|
4
|
+
"id",
|
|
5
|
+
"include",
|
|
6
|
+
"name",
|
|
7
|
+
"slug",
|
|
8
|
+
"include_slugs",
|
|
9
|
+
"term_group",
|
|
10
|
+
"description",
|
|
11
|
+
"count"
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { WP_CATEGORY_ORDER_BYS };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WP_Error } from "../error.js";
|
|
2
2
|
import { WP_List, WP_Result } from "../types.js";
|
|
3
|
-
import { WordPressService } from "../service.js";
|
|
4
3
|
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";
|
|
4
|
+
import { WordPressService } from "../service.js";
|
|
5
5
|
import "../index.js";
|
|
6
6
|
|
|
7
7
|
//#region src/wordpress/comment/service.d.ts
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { WP_Error } from "./error.js";
|
|
2
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 {
|
|
3
|
+
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";
|
|
4
|
+
import { CommentService } from "./comment/service.js";
|
|
5
|
+
import { WP_MENU_ITEM_ORDER_BYES, WP_MENU_ITEM_TARGETS, WP_MENU_ITEM_TAX_RELATIONS, 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
6
|
import { MenuItemService } from "./menu/items/service.js";
|
|
5
7
|
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
8
|
import { MenuService } from "./menu/service.js";
|
|
7
|
-
import {
|
|
9
|
+
import { WP_PAGE_ORDER_BYES, WP_PAGE_STATUSES, WP_Page, WP_PageCommentStatus, WP_PageContent, WP_PageContentInput, WP_PageCreateErrorCode, WP_PageCreateInput, WP_PageDeleteErrorCode, WP_PageDeleteInput, WP_PageDeleteResponse, WP_PageExcerpt, WP_PageExcerptInput, WP_PageGuid, WP_PageLinks, WP_PageListErrorCode, WP_PageListInput, WP_PageOrderBy, WP_PageRetrieveErrorCode, WP_PageRetrieveInput, WP_PageStatus, WP_PageStatusFilter, WP_PageTitle, WP_PageTitleInput, WP_PageUpdateErrorCode, WP_PageUpdateInput } from "./page/types.js";
|
|
10
|
+
import { PageService } from "./page/service.js";
|
|
11
|
+
import { WP_POST_FORMATS, WP_POST_ORDER_BYES, WP_POST_STATUSES, WP_POST_TAX_RELATIONS, 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
12
|
import { PostService } from "./post/service.js";
|
|
13
|
+
import { WP_TAG_ORDER_BYS, WP_Tag, WP_TagCreateErrorCode, WP_TagCreateInput, WP_TagDeleteErrorCode, WP_TagDeleteInput, WP_TagDeleteResponse, WP_TagLinks, WP_TagListErrorCode, WP_TagListInput, WP_TagOrderBy, WP_TagRetrieveErrorCode, WP_TagRetrieveInput, WP_TagTaxonomy, WP_TagUpdateErrorCode, WP_TagUpdateInput } from "./tag/types.js";
|
|
9
14
|
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
15
|
import { UserService } from "./user/service.js";
|
|
11
16
|
import { WordPressService } from "./service.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
17
|
+
import { WP_CATEGORY_ORDER_BYS, WP_Category, WP_CategoryCreateErrorCode, WP_CategoryCreateInput, WP_CategoryDeleteErrorCode, WP_CategoryDeleteInput, WP_CategoryDeleteResponse, WP_CategoryLinks, WP_CategoryListErrorCode, WP_CategoryListInput, WP_CategoryOrderBy, WP_CategoryRetrieveErrorCode, WP_CategoryRetrieveInput, WP_CategoryTaxonomy, WP_CategoryUpdateErrorCode, WP_CategoryUpdateInput } from "./category/types.js";
|
|
18
|
+
import { CategoryService } from "./category/service.js";
|
|
14
19
|
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
20
|
import { isWordPressResourceError } from "./utils.js";
|
|
@@ -8,11 +8,14 @@ type WP_MenuItemStatus = "publish" | "future" | "draft" | "pending" | "private"
|
|
|
8
8
|
/** Status filter values accepted by `GET /wp/v2/menu-items`. Inherits the posts controller's filter enum, widening `WP_MenuItemStatus` with internal statuses and the `any` alias. */
|
|
9
9
|
type WP_MenuItemStatusFilter = WP_MenuItemStatus | "auto-draft" | "inherit" | "any";
|
|
10
10
|
/** The target attribute of the link element for this menu item. */
|
|
11
|
-
|
|
11
|
+
declare const WP_MENU_ITEM_TARGETS: readonly ["_blank", ""];
|
|
12
|
+
type WP_MenuItemTarget = (typeof WP_MENU_ITEM_TARGETS)[number];
|
|
12
13
|
/** Sort collection by object attribute. */
|
|
13
|
-
|
|
14
|
+
declare const WP_MENU_ITEM_ORDER_BYES: readonly ["author", "date", "id", "include", "modified", "parent", "relevance", "slug", "include_slugs", "title", "menu_order"];
|
|
15
|
+
type WP_MenuItemOrderBy = (typeof WP_MENU_ITEM_ORDER_BYES)[number];
|
|
14
16
|
/** Limit result set based on relationship between multiple taxonomies. */
|
|
15
|
-
|
|
17
|
+
declare const WP_MENU_ITEM_TAX_RELATIONS: readonly ["AND", "OR"];
|
|
18
|
+
type WP_MenuItemTaxRelation = (typeof WP_MENU_ITEM_TAX_RELATIONS)[number];
|
|
16
19
|
/** The title for the menu item. */
|
|
17
20
|
interface WP_MenuItemTitle {
|
|
18
21
|
/** HTML title for the object, transformed for display. */
|
|
@@ -211,4 +214,4 @@ type WP_MenuItemDeleteResponse = {
|
|
|
211
214
|
};
|
|
212
215
|
type WP_MenuItemDeleteErrorCode = "rest_cannot_delete" | "rest_user_cannot_delete_post" | "rest_post_invalid_id" | "rest_already_trashed" | "rest_trash_not_supported";
|
|
213
216
|
//#endregion
|
|
214
|
-
export { 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 };
|
|
217
|
+
export { WP_MENU_ITEM_ORDER_BYES, WP_MENU_ITEM_TARGETS, WP_MENU_ITEM_TAX_RELATIONS, 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 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/wordpress/menu/items/types.ts
|
|
2
|
+
/** The target attribute of the link element for this menu item. */
|
|
3
|
+
const WP_MENU_ITEM_TARGETS = ["_blank", ""];
|
|
4
|
+
/** Sort collection by object attribute. */
|
|
5
|
+
const WP_MENU_ITEM_ORDER_BYES = [
|
|
6
|
+
"author",
|
|
7
|
+
"date",
|
|
8
|
+
"id",
|
|
9
|
+
"include",
|
|
10
|
+
"modified",
|
|
11
|
+
"parent",
|
|
12
|
+
"relevance",
|
|
13
|
+
"slug",
|
|
14
|
+
"include_slugs",
|
|
15
|
+
"title",
|
|
16
|
+
"menu_order"
|
|
17
|
+
];
|
|
18
|
+
/** Limit result set based on relationship between multiple taxonomies. */
|
|
19
|
+
const WP_MENU_ITEM_TAX_RELATIONS = ["AND", "OR"];
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { WP_MENU_ITEM_ORDER_BYES, WP_MENU_ITEM_TARGETS, WP_MENU_ITEM_TAX_RELATIONS };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WP_Error } from "../error.js";
|
|
2
|
+
import { WP_List, WP_Result } from "../types.js";
|
|
3
|
+
import { WP_Page, WP_PageCreateErrorCode, WP_PageCreateInput, WP_PageDeleteErrorCode, WP_PageDeleteInput, WP_PageDeleteResponse, WP_PageListErrorCode, WP_PageListInput, WP_PageRetrieveErrorCode, WP_PageRetrieveInput, WP_PageUpdateErrorCode, WP_PageUpdateInput } from "./types.js";
|
|
4
|
+
import { WordPressService } from "../service.js";
|
|
5
|
+
import "../index.js";
|
|
6
|
+
|
|
7
|
+
//#region src/wordpress/page/service.d.ts
|
|
8
|
+
declare class PageService {
|
|
9
|
+
private readonly wordpress;
|
|
10
|
+
constructor(wordpress: WordPressService);
|
|
11
|
+
list(input: WP_PageListInput): Promise<{
|
|
12
|
+
data: null;
|
|
13
|
+
status: number;
|
|
14
|
+
headers: Headers;
|
|
15
|
+
error: WP_Error<WP_PageListErrorCode>;
|
|
16
|
+
} | {
|
|
17
|
+
data: WP_List<WP_Page>;
|
|
18
|
+
status: number;
|
|
19
|
+
headers: Headers;
|
|
20
|
+
error: null;
|
|
21
|
+
}>;
|
|
22
|
+
create(input: WP_PageCreateInput): Promise<WP_Result<WP_Page, WP_PageCreateErrorCode>>;
|
|
23
|
+
get(input: WP_PageRetrieveInput): Promise<WP_Result<WP_Page, WP_PageRetrieveErrorCode>>;
|
|
24
|
+
update(input: WP_PageUpdateInput): Promise<WP_Result<WP_Page, WP_PageUpdateErrorCode>>;
|
|
25
|
+
delete(input: WP_PageDeleteInput): Promise<WP_Result<WP_PageDeleteResponse, WP_PageDeleteErrorCode>>;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { PageService };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WP_CORE_BASE } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/wordpress/page/service.ts
|
|
4
|
+
var PageService = 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("/pages", {
|
|
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("/pages", {
|
|
27
|
+
base: WP_CORE_BASE,
|
|
28
|
+
body: input
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async get(input) {
|
|
32
|
+
const { id,...searchParams } = input;
|
|
33
|
+
return this.wordpress.get(`/pages/${id}`, {
|
|
34
|
+
base: WP_CORE_BASE,
|
|
35
|
+
searchParams
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async update(input) {
|
|
39
|
+
const { id,...body } = input;
|
|
40
|
+
return this.wordpress.post(`/pages/${id}`, {
|
|
41
|
+
base: WP_CORE_BASE,
|
|
42
|
+
body
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async delete(input) {
|
|
46
|
+
const { id,...searchParams } = input;
|
|
47
|
+
return this.wordpress.delete(`/pages/${id}`, {
|
|
48
|
+
base: WP_CORE_BASE,
|
|
49
|
+
searchParams
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { PageService };
|