This repository was archived by the owner on Jun 9, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathClient.ts
More file actions
63 lines (55 loc) · 2.24 KB
/
Copy pathClient.ts
File metadata and controls
63 lines (55 loc) · 2.24 KB
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
import type { DeferredJobsApiClient } from '../../api';
import { routing } from '../../routing';
import type { Newsroom, NewsroomTheme, NewsroomThemePreset } from '../../types';
type NewsroomId = Newsroom['uuid'] | Newsroom['id'];
type NewsroomThemeId = NewsroomTheme['id'];
export type Client = ReturnType<typeof createClient>;
export function createClient(api: DeferredJobsApiClient) {
async function apply(
newsroomId: NewsroomId,
themeId: NewsroomThemeId,
settings: NewsroomThemePreset['settings'],
): Promise<NewsroomThemePreset> {
const url = routing.newsroomThemesUrl.replace(':newsroom_id', String(newsroomId));
const { theme } = await api.post<{ theme: NewsroomThemePreset }>(`${url}/${themeId}`, {
payload: settings,
});
return theme;
}
async function get(
newsroomId: NewsroomId,
themeId: NewsroomThemeId,
): Promise<NewsroomThemePreset> {
const url = routing.newsroomThemesUrl.replace(':newsroom_id', String(newsroomId));
const { theme } = await api.get<{ theme: NewsroomThemePreset }>(`${url}/${themeId}`);
return theme;
}
async function getActive(newsroomId: NewsroomId): Promise<NewsroomThemePreset> {
const url = routing.newsroomThemesUrl.replace(':newsroom_id', String(newsroomId));
const { theme } = await api.get<{ theme: NewsroomThemePreset }>(`${url}/active`);
return theme;
}
async function list(newsroomId: NewsroomId): Promise<NewsroomThemePreset[]> {
const url = routing.newsroomThemesUrl.replace(':newsroom_id', String(newsroomId));
const { themes } = await api.get<{ themes: NewsroomThemePreset[] }>(url);
return themes;
}
async function update(
newsroomId: NewsroomId,
themeId: NewsroomThemeId,
settings: NewsroomThemePreset['settings'],
): Promise<NewsroomThemePreset> {
const url = routing.newsroomThemesUrl.replace(':newsroom_id', String(newsroomId));
const { theme } = await api.patch<{ theme: NewsroomThemePreset }>(`${url}/${themeId}`, {
payload: settings,
});
return theme;
}
return {
apply,
get,
getActive,
list,
update,
};
}