Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export type SavedData = {
entries: CmsEntry[],
assets: Asset[],
syncToken: string,
updated: boolean
};
type SyncOpts = {
initial: boolean,
nextSyncToken?: string
};
type Client = {
sync: SyncOpts => Promise
};
const client: Client = createClient({
space: Config.CONTENTFUL_SPACE_ID,
accessToken: Config.CONTENTFUL_API_KEY
});
export const getCmsData = async (
loadCmsDataFn: typeof loadCmsData = loadCmsData,
updateCmsDataFn: typeof updateCmsData = updateCmsData
): Promise => {
const localCmsData = await loadCmsDataFn();
const hasLocalCmsData = !!localCmsData;
if (hasLocalCmsData) {
return { ...localCmsData, updated: false };
}
return updateCmsDataFn();
};
type SyncOpts = {
initial: boolean,
nextSyncToken?: string
};
type Client = {
sync: SyncOpts => Promise
};
type UpdateEvents = () => Promise;
type GetEvents = (
loadEvents?: loadEvents,
updateEvents?: updateEvents
) => Promise;
const client: Client = createClient({
space: Config.CONTENTFUL_SPACE_ID,
accessToken: Config.CONTENTFUL_API_KEY
});
export const getEvents: GetEvents = async (
loadEventsFn = loadEvents,
updateEventsFn = updateEvents
) => {
const localEventsData = await loadEventsFn();
const hasLocalEventsData =
!!localEventsData && localEventsData.events.length > 0;
if (hasLocalEventsData) {
return localEventsData.events;
}