import Contentful from 'contentful-management'
type Contentful = {
accessToken: string
environment: string
spaceId: string
}
const makeClient = (resource: Contentful) => {
return Contentful.createClient(
{ accessToken: resource.accessToken },
{
type: 'plain',
defaults: { spaceId: resource.spaceId, environmentId: resource.environment }
}
)
}
export async function main(
resource: Contentful,
propsValue: {
locale: string
contentTypeId: string
query: object
limit?: number
skip?: number
include?: number
select?: string[]
}
) {
const client = makeClient(resource)
const select = propsValue.select?.join(',')
const response = await client.entry.getMany({
query: {
...propsValue.query,
limit: propsValue.limit || 10,
skip: propsValue.skip || 0,
content_type: propsValue.contentTypeId,
include: propsValue.include || 1,
select: select || undefined
}
})
return response
}
Submitted by hugo697 26 days ago