@stackbit/cms-contentful
Version:
Stackbit Contentful CMS Interface
36 lines (30 loc) • 1.54 kB
text/typescript
import { createPlainApiClient, fetchAllContentTypes, fetchAllEditorInterfaces, fetchAllLocales } from './contentful-api-client';
import { convertSchema } from './contentful-schema-converter';
export * from './contentful-content-source';
export * from './sync-poller';
export { default as ContentfulEncoderDelegate } from './contentful-encoder-delegate';
export { localizeFieldData } from './localize-field-data';
export { localizeModels } from './localize-models';
export interface FetchAndConvertSchemaOptions {
accessToken: string;
spaceId: string;
environment?: string;
}
export async function fetchAndConvertSchema(options: FetchAndConvertSchemaOptions) {
const client = createPlainApiClient({
accessToken: options.accessToken ?? process.env.CONTENTFUL_ACCESS_TOKEN,
spaceId: options.spaceId ?? process.env.CONTENTFUL_SPACE_ID,
environment: options.environment ?? process.env.CONTENTFUL_ENVIRONMENT ?? 'master'
});
const contentTypes = await fetchAllContentTypes(client);
const editorInterfaces = await fetchAllEditorInterfaces(client);
const locales = await fetchAllLocales(client);
const defaultLocaleCode = locales.find((locale) => locale.default)?.code;
return convertSchema({
contentTypes,
editorInterfaces,
defaultLocaleCode: defaultLocaleCode ?? 'en-US',
cloudinaryImagesAsList: false, // before CSI, always create single image field for cloudinary
bynderImagesAsList: false // not supported in non CSI at all
});
}