This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
articles.ts
90 lines (76 loc) · 2.77 KB
/
articles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {
ArticleStatus,
GetArticleResponse,
GetRevisionResponse,
ListArticlesResponse,
ListRelatedArticlesResponse,
ListRevisionsResponse,
OrderParameter,
SearchArticlesResponse,
VisibilityParameter,
} from './types/helpscout-docs'
import { get } from './request'
type ArticleStatusParameter = 'all' | ArticleStatus
type ArticleSortParameter = 'number' | 'status' | 'name' | 'popularity' | 'createdAt' | 'updatedAt'
export interface ListArticlesOptions {
page?: number
status?: ArticleStatusParameter
sort?: ArticleSortParameter
order?: OrderParameter
pageSize?: number
}
export async function listArticlesInCollection(apiToken: string, collectionId: string, options?: ListArticlesOptions) {
const path = `collections/${collectionId}/articles`
const response = await get<ListArticlesResponse>(apiToken, path, options)
return response.body
}
export async function listArticlesInCategory(apiToken: string, categoryId: string, options?: ListArticlesOptions) {
const path = `categories/${categoryId}/articles`
const response = await get<ListArticlesResponse>(apiToken, path, options)
return response.body
}
export interface SearchArticlesOptions {
page?: number
query: string
collectionId?: string
siteId?: string
status?: ArticleStatusParameter
visibility?: VisibilityParameter
}
export async function searchArticles(apiToken: string, options: SearchArticlesOptions) {
const path = 'search/articles'
const response = await get<SearchArticlesResponse>(apiToken, path, options)
return response.body
}
export interface ListRelatedArticlesOptions {
page?: number
status?: ArticleStatusParameter
sort?: ArticleSortParameter
order?: OrderParameter
}
export async function listRelatedArticles(apiToken: string, articleId: string, options?: ListRelatedArticlesOptions) {
const path = `articles/${articleId}/related`
const response = await get<ListRelatedArticlesResponse>(apiToken, path, options)
return response.body
}
export interface ListRevisionsOptions {
page?: number
}
export async function listRevisions(apiToken: string, articleId: string, options?: ListRevisionsOptions) {
const path = `articles/${articleId}/revisions`
const response = await get<ListRevisionsResponse>(apiToken, path, options)
return response.body
}
export interface GetArticleOptions {
draft?: boolean
}
export async function getArticle(apiToken: string, articleIdOrNumber: string | number, options?: GetArticleOptions) {
const path = `articles/${articleIdOrNumber}`
const response = await get<GetArticleResponse>(apiToken, path, options)
return response.body
}
export async function getRevision(apiToken: string, revisionId: string) {
const path = `revisions/${revisionId}`
const response = await get<GetRevisionResponse>(apiToken, path)
return response.body
}