-
Notifications
You must be signed in to change notification settings - Fork 0
/
cms-api.ts
71 lines (64 loc) · 2.19 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Copyright 2020 Vercel Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Job, Sponsor, Stage, Speaker } from '@lib/types';
import * as strapiApi from './cms-providers/strapi';
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 if (process.env.STRAPI_API_URL) {
cmsApi = strapiApi;
} 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();
}