@vigilkids/cms-client 0.1.2 → 0.1.3
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/index.d.mts +18 -8
- package/dist/index.d.ts +18 -8
- package/dist/index.mjs +36 -12
- package/dist/types.d.mts +30 -20
- package/dist/types.d.ts +30 -20
- package/dist/webhook.mjs +1 -0
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArticleListParams, Paginated, ArticleListItem, ArticleDetail, Author, CategoryNode, Comment, CreateCommentPayload, SitemapEntry, RedirectRule, Series } from './types.mjs';
|
|
2
|
-
export { HreflangEntry, LocalizedString, OgMeta, PaginationMeta, RevalidatePayload, SeoMeta, TwitterMeta, WebhookEventType } from './types.mjs';
|
|
1
|
+
import { ArticleListParams, Paginated, ArticleListItem, ArticleDetail, PaginationParams, Author, CategoryNode, Comment, CreateCommentPayload, SitemapEntry, RedirectRule, Series } from './types.mjs';
|
|
2
|
+
export { HreflangEntry, ListResponse, LocalizedString, OgMeta, PaginationMeta, RevalidatePayload, SeoMeta, TwitterMeta, WebhookEventType } from './types.mjs';
|
|
3
3
|
|
|
4
4
|
/** CMS 客户端配置 */
|
|
5
5
|
interface CmsClientConfig {
|
|
@@ -33,16 +33,26 @@ declare class CmsClient {
|
|
|
33
33
|
limit?: number;
|
|
34
34
|
locale?: string;
|
|
35
35
|
}): Promise<ArticleListItem[]>;
|
|
36
|
+
/** 获取作者分页列表 */
|
|
37
|
+
getAuthorsPage(options?: {
|
|
38
|
+
locale?: string;
|
|
39
|
+
} & PaginationParams): Promise<Paginated<Author>>;
|
|
36
40
|
/** 获取所有作者 */
|
|
37
|
-
getAuthors(
|
|
41
|
+
getAuthors(options?: {
|
|
42
|
+
locale?: string;
|
|
43
|
+
} & PaginationParams): Promise<Author[]>;
|
|
38
44
|
/** 获取作者详情 */
|
|
39
|
-
getAuthor(slug: string): Promise<Author>;
|
|
45
|
+
getAuthor(slug: string, locale?: string): Promise<Author>;
|
|
46
|
+
/** 获取作者的文章分页列表 */
|
|
47
|
+
getAuthorArticlesPage(slug: string, options?: {
|
|
48
|
+
is_pinned?: boolean;
|
|
49
|
+
locale?: string;
|
|
50
|
+
} & PaginationParams): Promise<Paginated<ArticleListItem>>;
|
|
40
51
|
/** 获取作者的文章列表 */
|
|
41
52
|
getAuthorArticles(slug: string, options?: {
|
|
42
|
-
|
|
43
|
-
page_size?: number;
|
|
53
|
+
is_pinned?: boolean;
|
|
44
54
|
locale?: string;
|
|
45
|
-
}): Promise<ArticleListItem[]>;
|
|
55
|
+
} & PaginationParams): Promise<ArticleListItem[]>;
|
|
46
56
|
/** 获取分类树 */
|
|
47
57
|
getCategories(): Promise<CategoryNode[]>;
|
|
48
58
|
/** 获取文章评论树 */
|
|
@@ -74,5 +84,5 @@ declare class CmsApiError extends Error {
|
|
|
74
84
|
get isUnauthorized(): boolean;
|
|
75
85
|
}
|
|
76
86
|
|
|
77
|
-
export { ArticleDetail, ArticleListItem, ArticleListParams, Author, CategoryNode, CmsApiError, CmsClient, Comment, CreateCommentPayload, Paginated, RedirectRule, Series, SitemapEntry, createCmsClient };
|
|
87
|
+
export { ArticleDetail, ArticleListItem, ArticleListParams, Author, CategoryNode, CmsApiError, CmsClient, Comment, CreateCommentPayload, Paginated, PaginationParams, RedirectRule, Series, SitemapEntry, createCmsClient };
|
|
78
88
|
export type { CmsClientConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArticleListParams, Paginated, ArticleListItem, ArticleDetail, Author, CategoryNode, Comment, CreateCommentPayload, SitemapEntry, RedirectRule, Series } from './types.js';
|
|
2
|
-
export { HreflangEntry, LocalizedString, OgMeta, PaginationMeta, RevalidatePayload, SeoMeta, TwitterMeta, WebhookEventType } from './types.js';
|
|
1
|
+
import { ArticleListParams, Paginated, ArticleListItem, ArticleDetail, PaginationParams, Author, CategoryNode, Comment, CreateCommentPayload, SitemapEntry, RedirectRule, Series } from './types.js';
|
|
2
|
+
export { HreflangEntry, ListResponse, LocalizedString, OgMeta, PaginationMeta, RevalidatePayload, SeoMeta, TwitterMeta, WebhookEventType } from './types.js';
|
|
3
3
|
|
|
4
4
|
/** CMS 客户端配置 */
|
|
5
5
|
interface CmsClientConfig {
|
|
@@ -33,16 +33,26 @@ declare class CmsClient {
|
|
|
33
33
|
limit?: number;
|
|
34
34
|
locale?: string;
|
|
35
35
|
}): Promise<ArticleListItem[]>;
|
|
36
|
+
/** 获取作者分页列表 */
|
|
37
|
+
getAuthorsPage(options?: {
|
|
38
|
+
locale?: string;
|
|
39
|
+
} & PaginationParams): Promise<Paginated<Author>>;
|
|
36
40
|
/** 获取所有作者 */
|
|
37
|
-
getAuthors(
|
|
41
|
+
getAuthors(options?: {
|
|
42
|
+
locale?: string;
|
|
43
|
+
} & PaginationParams): Promise<Author[]>;
|
|
38
44
|
/** 获取作者详情 */
|
|
39
|
-
getAuthor(slug: string): Promise<Author>;
|
|
45
|
+
getAuthor(slug: string, locale?: string): Promise<Author>;
|
|
46
|
+
/** 获取作者的文章分页列表 */
|
|
47
|
+
getAuthorArticlesPage(slug: string, options?: {
|
|
48
|
+
is_pinned?: boolean;
|
|
49
|
+
locale?: string;
|
|
50
|
+
} & PaginationParams): Promise<Paginated<ArticleListItem>>;
|
|
40
51
|
/** 获取作者的文章列表 */
|
|
41
52
|
getAuthorArticles(slug: string, options?: {
|
|
42
|
-
|
|
43
|
-
page_size?: number;
|
|
53
|
+
is_pinned?: boolean;
|
|
44
54
|
locale?: string;
|
|
45
|
-
}): Promise<ArticleListItem[]>;
|
|
55
|
+
} & PaginationParams): Promise<ArticleListItem[]>;
|
|
46
56
|
/** 获取分类树 */
|
|
47
57
|
getCategories(): Promise<CategoryNode[]>;
|
|
48
58
|
/** 获取文章评论树 */
|
|
@@ -74,5 +84,5 @@ declare class CmsApiError extends Error {
|
|
|
74
84
|
get isUnauthorized(): boolean;
|
|
75
85
|
}
|
|
76
86
|
|
|
77
|
-
export { ArticleDetail, ArticleListItem, ArticleListParams, Author, CategoryNode, CmsApiError, CmsClient, Comment, CreateCommentPayload, Paginated, RedirectRule, Series, SitemapEntry, createCmsClient };
|
|
87
|
+
export { ArticleDetail, ArticleListItem, ArticleListParams, Author, CategoryNode, CmsApiError, CmsClient, Comment, CreateCommentPayload, Paginated, PaginationParams, RedirectRule, Series, SitemapEntry, createCmsClient };
|
|
78
88
|
export type { CmsClientConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -22,6 +22,16 @@ class CmsApiError extends Error {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
function parseApiErrorEnvelope(body) {
|
|
26
|
+
if (typeof body !== "object" || body === null || !("error" in body)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const error = body.error;
|
|
30
|
+
if (typeof error === "object" && error !== null && typeof error.code === "string" && typeof error.message === "string" && typeof error.type === "string") {
|
|
31
|
+
return error;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
25
35
|
class CmsClient {
|
|
26
36
|
config;
|
|
27
37
|
fetchFn;
|
|
@@ -44,33 +54,45 @@ class CmsClient {
|
|
|
44
54
|
}
|
|
45
55
|
/** 获取相关文章 */
|
|
46
56
|
async getRelatedArticles(slug, options) {
|
|
47
|
-
|
|
57
|
+
const result = await this.request(
|
|
48
58
|
"GET",
|
|
49
59
|
`/articles/${encodeURIComponent(slug)}/related`,
|
|
50
60
|
options
|
|
51
61
|
);
|
|
62
|
+
return result.data;
|
|
52
63
|
}
|
|
53
64
|
// ─── 作者 ───────────────────────────────────────────
|
|
65
|
+
/** 获取作者分页列表 */
|
|
66
|
+
async getAuthorsPage(options) {
|
|
67
|
+
return this.request("GET", "/authors", options);
|
|
68
|
+
}
|
|
54
69
|
/** 获取所有作者 */
|
|
55
|
-
async getAuthors() {
|
|
56
|
-
|
|
70
|
+
async getAuthors(options) {
|
|
71
|
+
const result = await this.getAuthorsPage(options);
|
|
72
|
+
return result.data;
|
|
57
73
|
}
|
|
58
74
|
/** 获取作者详情 */
|
|
59
|
-
async getAuthor(slug) {
|
|
60
|
-
return this.request("GET", `/authors/${encodeURIComponent(slug)}
|
|
75
|
+
async getAuthor(slug, locale) {
|
|
76
|
+
return this.request("GET", `/authors/${encodeURIComponent(slug)}`, { locale });
|
|
61
77
|
}
|
|
62
|
-
/**
|
|
63
|
-
async
|
|
78
|
+
/** 获取作者的文章分页列表 */
|
|
79
|
+
async getAuthorArticlesPage(slug, options) {
|
|
64
80
|
return this.request(
|
|
65
81
|
"GET",
|
|
66
82
|
`/authors/${encodeURIComponent(slug)}/articles`,
|
|
67
83
|
options
|
|
68
84
|
);
|
|
69
85
|
}
|
|
86
|
+
/** 获取作者的文章列表 */
|
|
87
|
+
async getAuthorArticles(slug, options) {
|
|
88
|
+
const result = await this.getAuthorArticlesPage(slug, options);
|
|
89
|
+
return result.data;
|
|
90
|
+
}
|
|
70
91
|
// ─── 分类 ───────────────────────────────────────────
|
|
71
92
|
/** 获取分类树 */
|
|
72
93
|
async getCategories() {
|
|
73
|
-
|
|
94
|
+
const result = await this.request("GET", "/categories");
|
|
95
|
+
return result.data;
|
|
74
96
|
}
|
|
75
97
|
// ─── 评论 ───────────────────────────────────────────
|
|
76
98
|
/** 获取文章评论树 */
|
|
@@ -89,11 +111,13 @@ class CmsClient {
|
|
|
89
111
|
// ─── Sitemap / 重定向 / 系列 ──────────────────────
|
|
90
112
|
/** 获取 Sitemap 条目 */
|
|
91
113
|
async getSitemap(locale) {
|
|
92
|
-
|
|
114
|
+
const result = await this.request("GET", "/sitemap", { locale });
|
|
115
|
+
return result.data;
|
|
93
116
|
}
|
|
94
117
|
/** 获取重定向规则 */
|
|
95
118
|
async getRedirects() {
|
|
96
|
-
|
|
119
|
+
const result = await this.request("GET", "/redirects");
|
|
120
|
+
return result.data;
|
|
97
121
|
}
|
|
98
122
|
/** 获取文章系列 */
|
|
99
123
|
async getSeries(slug, locale) {
|
|
@@ -125,8 +149,8 @@ class CmsClient {
|
|
|
125
149
|
let errorMessage = `CMS API \u8BF7\u6C42\u5931\u8D25: ${response.status}`;
|
|
126
150
|
try {
|
|
127
151
|
errorBody = await response.json();
|
|
128
|
-
|
|
129
|
-
|
|
152
|
+
const parsed = parseApiErrorEnvelope(errorBody);
|
|
153
|
+
if (parsed) {
|
|
130
154
|
errorCode = parsed.code;
|
|
131
155
|
errorMessage = parsed.message;
|
|
132
156
|
}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
/** 作者信息 (Go: delivery.DeliveryAuthorResponse) */
|
|
2
2
|
interface Author {
|
|
3
|
+
id: number;
|
|
4
|
+
locale: string;
|
|
3
5
|
display_name: string;
|
|
4
6
|
slug: string;
|
|
5
7
|
avatar_url?: string;
|
|
6
8
|
bio?: string;
|
|
9
|
+
available_locales?: string[];
|
|
10
|
+
localized_slugs?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** 多语言字符串 (Go: domain.LocalizedString = map[string]string) */
|
|
14
|
+
type LocalizedString = Record<string, string>;
|
|
15
|
+
/** 分页元信息 (Go: response.PaginationMeta) */
|
|
16
|
+
interface PaginationMeta {
|
|
17
|
+
page: number;
|
|
18
|
+
page_size: number;
|
|
19
|
+
total: number;
|
|
20
|
+
total_pages: number;
|
|
21
|
+
}
|
|
22
|
+
/** 分页响应 (Go: response.Paginated[T]) */
|
|
23
|
+
interface Paginated<T> {
|
|
24
|
+
data: T[];
|
|
25
|
+
pagination: PaginationMeta;
|
|
26
|
+
}
|
|
27
|
+
/** 列表响应 (Go: response.NewList[T]) */
|
|
28
|
+
type ListResponse<T> = Paginated<T>;
|
|
29
|
+
/** 分页查询参数 */
|
|
30
|
+
interface PaginationParams {
|
|
31
|
+
page?: number;
|
|
32
|
+
page_size?: number;
|
|
7
33
|
}
|
|
8
34
|
|
|
9
35
|
/** 文章详情 (Go: delivery.DeliveryArticleResponse) */
|
|
@@ -28,9 +54,10 @@ interface ArticleDetail {
|
|
|
28
54
|
seo_meta?: SeoMeta;
|
|
29
55
|
og_meta?: OgMeta;
|
|
30
56
|
twitter_meta?: TwitterMeta;
|
|
31
|
-
json_ld:
|
|
57
|
+
json_ld: unknown;
|
|
32
58
|
locale: string;
|
|
33
59
|
available_locales: string[];
|
|
60
|
+
localized_slugs?: Record<string, string>;
|
|
34
61
|
}
|
|
35
62
|
/** 文章列表项 (Go: delivery.DeliveryArticleListItem) */
|
|
36
63
|
interface ArticleListItem {
|
|
@@ -48,14 +75,12 @@ interface ArticleListItem {
|
|
|
48
75
|
authors: Author[];
|
|
49
76
|
}
|
|
50
77
|
/** 文章列表查询参数 */
|
|
51
|
-
interface ArticleListParams {
|
|
78
|
+
interface ArticleListParams extends PaginationParams {
|
|
52
79
|
locale?: string;
|
|
53
80
|
category_id?: number;
|
|
54
81
|
category_slug?: string;
|
|
55
82
|
tag?: string;
|
|
56
83
|
is_pinned?: boolean;
|
|
57
|
-
page?: number;
|
|
58
|
-
page_size?: number;
|
|
59
84
|
}
|
|
60
85
|
/** SEO 元信息 */
|
|
61
86
|
interface SeoMeta {
|
|
@@ -81,21 +106,6 @@ interface TwitterMeta {
|
|
|
81
106
|
image: string | null;
|
|
82
107
|
}
|
|
83
108
|
|
|
84
|
-
/** 多语言字符串 (Go: domain.LocalizedString = map[string]string) */
|
|
85
|
-
type LocalizedString = Record<string, string>;
|
|
86
|
-
/** 分页元信息 (Go: response.PaginationMeta) */
|
|
87
|
-
interface PaginationMeta {
|
|
88
|
-
page: number;
|
|
89
|
-
page_size: number;
|
|
90
|
-
total: number;
|
|
91
|
-
total_pages: number;
|
|
92
|
-
}
|
|
93
|
-
/** 分页响应 (Go: response.Paginated[T]) */
|
|
94
|
-
interface Paginated<T> {
|
|
95
|
-
data: T[];
|
|
96
|
-
pagination: PaginationMeta;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
109
|
/** 分类树节点 (Go: delivery.CategoryNodeResponse) */
|
|
100
110
|
interface CategoryNode {
|
|
101
111
|
id: number;
|
|
@@ -167,4 +177,4 @@ interface RevalidatePayload {
|
|
|
167
177
|
category_slug?: string;
|
|
168
178
|
}
|
|
169
179
|
|
|
170
|
-
export type { ArticleDetail, ArticleListItem, ArticleListParams, Author, CategoryNode, Comment, CreateCommentPayload, HreflangEntry, LocalizedString, OgMeta, Paginated, PaginationMeta, RedirectRule, RevalidatePayload, SeoMeta, Series, SitemapEntry, TwitterMeta, WebhookEventType };
|
|
180
|
+
export type { ArticleDetail, ArticleListItem, ArticleListParams, Author, CategoryNode, Comment, CreateCommentPayload, HreflangEntry, ListResponse, LocalizedString, OgMeta, Paginated, PaginationMeta, PaginationParams, RedirectRule, RevalidatePayload, SeoMeta, Series, SitemapEntry, TwitterMeta, WebhookEventType };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
/** 作者信息 (Go: delivery.DeliveryAuthorResponse) */
|
|
2
2
|
interface Author {
|
|
3
|
+
id: number;
|
|
4
|
+
locale: string;
|
|
3
5
|
display_name: string;
|
|
4
6
|
slug: string;
|
|
5
7
|
avatar_url?: string;
|
|
6
8
|
bio?: string;
|
|
9
|
+
available_locales?: string[];
|
|
10
|
+
localized_slugs?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** 多语言字符串 (Go: domain.LocalizedString = map[string]string) */
|
|
14
|
+
type LocalizedString = Record<string, string>;
|
|
15
|
+
/** 分页元信息 (Go: response.PaginationMeta) */
|
|
16
|
+
interface PaginationMeta {
|
|
17
|
+
page: number;
|
|
18
|
+
page_size: number;
|
|
19
|
+
total: number;
|
|
20
|
+
total_pages: number;
|
|
21
|
+
}
|
|
22
|
+
/** 分页响应 (Go: response.Paginated[T]) */
|
|
23
|
+
interface Paginated<T> {
|
|
24
|
+
data: T[];
|
|
25
|
+
pagination: PaginationMeta;
|
|
26
|
+
}
|
|
27
|
+
/** 列表响应 (Go: response.NewList[T]) */
|
|
28
|
+
type ListResponse<T> = Paginated<T>;
|
|
29
|
+
/** 分页查询参数 */
|
|
30
|
+
interface PaginationParams {
|
|
31
|
+
page?: number;
|
|
32
|
+
page_size?: number;
|
|
7
33
|
}
|
|
8
34
|
|
|
9
35
|
/** 文章详情 (Go: delivery.DeliveryArticleResponse) */
|
|
@@ -28,9 +54,10 @@ interface ArticleDetail {
|
|
|
28
54
|
seo_meta?: SeoMeta;
|
|
29
55
|
og_meta?: OgMeta;
|
|
30
56
|
twitter_meta?: TwitterMeta;
|
|
31
|
-
json_ld:
|
|
57
|
+
json_ld: unknown;
|
|
32
58
|
locale: string;
|
|
33
59
|
available_locales: string[];
|
|
60
|
+
localized_slugs?: Record<string, string>;
|
|
34
61
|
}
|
|
35
62
|
/** 文章列表项 (Go: delivery.DeliveryArticleListItem) */
|
|
36
63
|
interface ArticleListItem {
|
|
@@ -48,14 +75,12 @@ interface ArticleListItem {
|
|
|
48
75
|
authors: Author[];
|
|
49
76
|
}
|
|
50
77
|
/** 文章列表查询参数 */
|
|
51
|
-
interface ArticleListParams {
|
|
78
|
+
interface ArticleListParams extends PaginationParams {
|
|
52
79
|
locale?: string;
|
|
53
80
|
category_id?: number;
|
|
54
81
|
category_slug?: string;
|
|
55
82
|
tag?: string;
|
|
56
83
|
is_pinned?: boolean;
|
|
57
|
-
page?: number;
|
|
58
|
-
page_size?: number;
|
|
59
84
|
}
|
|
60
85
|
/** SEO 元信息 */
|
|
61
86
|
interface SeoMeta {
|
|
@@ -81,21 +106,6 @@ interface TwitterMeta {
|
|
|
81
106
|
image: string | null;
|
|
82
107
|
}
|
|
83
108
|
|
|
84
|
-
/** 多语言字符串 (Go: domain.LocalizedString = map[string]string) */
|
|
85
|
-
type LocalizedString = Record<string, string>;
|
|
86
|
-
/** 分页元信息 (Go: response.PaginationMeta) */
|
|
87
|
-
interface PaginationMeta {
|
|
88
|
-
page: number;
|
|
89
|
-
page_size: number;
|
|
90
|
-
total: number;
|
|
91
|
-
total_pages: number;
|
|
92
|
-
}
|
|
93
|
-
/** 分页响应 (Go: response.Paginated[T]) */
|
|
94
|
-
interface Paginated<T> {
|
|
95
|
-
data: T[];
|
|
96
|
-
pagination: PaginationMeta;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
109
|
/** 分类树节点 (Go: delivery.CategoryNodeResponse) */
|
|
100
110
|
interface CategoryNode {
|
|
101
111
|
id: number;
|
|
@@ -167,4 +177,4 @@ interface RevalidatePayload {
|
|
|
167
177
|
category_slug?: string;
|
|
168
178
|
}
|
|
169
179
|
|
|
170
|
-
export type { ArticleDetail, ArticleListItem, ArticleListParams, Author, CategoryNode, Comment, CreateCommentPayload, HreflangEntry, LocalizedString, OgMeta, Paginated, PaginationMeta, RedirectRule, RevalidatePayload, SeoMeta, Series, SitemapEntry, TwitterMeta, WebhookEventType };
|
|
180
|
+
export type { ArticleDetail, ArticleListItem, ArticleListParams, Author, CategoryNode, Comment, CreateCommentPayload, HreflangEntry, ListResponse, LocalizedString, OgMeta, Paginated, PaginationMeta, PaginationParams, RedirectRule, RevalidatePayload, SeoMeta, Series, SitemapEntry, TwitterMeta, WebhookEventType };
|
package/dist/webhook.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vigilkids/cms-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Framework-agnostic TypeScript client for OnEx CMS Public API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
|
-
"url": "https://github.com/1yhy/onex.git",
|
|
37
|
+
"url": "git+https://github.com/1yhy/onex.git",
|
|
38
38
|
"directory": "packages/cms-client"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|