-
Notifications
You must be signed in to change notification settings - Fork 0
/
cms-api.ts
54 lines (47 loc) · 1.51 KB
/
cms-api.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
/*By Sherik*/
import { Job, Sponsor, Stage, Speaker } from '@lib/types';
import * as agilityApi from './cms-providers/agility';
import * as datoCmsApi from './cms-providers/dato';
import * as contentfulApi from './cms-providers/contentful';
import * as prismicApi from './cms-providers/prismic';
import * as storyblokApi from './cms-providers/storyblok';
let cmsApi: {
getAllSpeakers: () => Promise<Speaker[]>;
getAllStages: () => Promise<Stage[]>;
getAllSponsors: () => Promise<Sponsor[]>;
getAllJobs: () => Promise<Job[]>;
};
if (process.env.DATOCMS_READ_ONLY_API_TOKEN) {
cmsApi = datoCmsApi;
} else if (process.env.CONTENTFUL_ACCESS_TOKEN && process.env.CONTENTFUL_SPACE_ID) {
cmsApi = contentfulApi;
} else if (process.env.STORYBLOK_PREVIEW_TOKEN) {
cmsApi = storyblokApi;
} else if (process.env.PRISMIC_REPO_ID) {
cmsApi = prismicApi;
} else if (
process.env.AGILITY_GUID &&
process.env.AGILITY_API_FETCH_KEY &&
process.env.AGILITY_API_PREVIEW_KEY
) {
cmsApi = agilityApi;
} else {
cmsApi = {
getAllSpeakers: async () => [],
getAllStages: async () => [],
getAllSponsors: async () => [],
getAllJobs: async () => []
};
}
export async function getAllSpeakers(): Promise<Speaker[]> {
return cmsApi.getAllSpeakers();
}
export async function getAllStages(): Promise<Stage[]> {
return cmsApi.getAllStages();
}
export async function getAllSponsors(): Promise<Sponsor[]> {
return cmsApi.getAllSponsors();
}
export async function getAllJobs(): Promise<Job[]> {
return cmsApi.getAllJobs();
}