-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluginOptions.ts
45 lines (40 loc) · 1.04 KB
/
pluginOptions.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
import { isObject } from '@suin/is-object'
import { Errors } from './errors'
import { GetPostsParameters } from './esaApi'
export type PluginOptions = {
/**
* チーム名
*/
readonly team: string
/**
* esa APIアクセストークン
*/
readonly token: string
/**
* 投稿一覧取得APIのクエリ文字列にセットする情報
*/
readonly posts?: GetPostsParameters
}
/**
* @internal
*/
const isPluginOptions = (value: unknown): value is PluginOptions =>
isObject<PluginOptions>(value) &&
typeof value.team === 'string' &&
typeof value.token === 'string'
/**
* @internal
*/
export const isValidPluginOptions = (
options: unknown,
errors: Errors,
): options is PluginOptions => {
if (!isPluginOptions(options)) {
errors.add('`team` and `token` property must be specified.')
return false
}
const { team, token } = options
if (team.length === 0) errors.add('`team` property must be specified.')
if (token.length === 0) errors.add('`token` property must be specified.')
return errors.noErrors()
}