|
| 1 | +// Type definitions for contentful |
| 2 | +// Definitions by: Miika Hänninen <https://github.com/googol> |
| 3 | + |
| 4 | +export interface CreateClientParams { |
| 5 | + space: string; |
| 6 | + accessToken: string; |
| 7 | + insecure?: boolean; |
| 8 | + host?: string; |
| 9 | + agent?: any; |
| 10 | + headers?: any; |
| 11 | + concurrency?: number; |
| 12 | + delay?: number; |
| 13 | + maxRetries?: number; |
| 14 | + retryOnTooManyRequests?: boolean; |
| 15 | + resolveLinks?: boolean; |
| 16 | +} |
| 17 | + |
| 18 | +export interface ContentfulClientApi { |
| 19 | + getAsset(id: string, query?: any): Promise<Asset>; |
| 20 | + getAssets(query?: any): Promise<AssetCollection>; |
| 21 | + getContentType(id: string): Promise<ContentType>; |
| 22 | + getContentTypes(query?: any): Promise<ContentTypeCollection>; |
| 23 | + getEntries(query?: any): Promise<EntryCollection<any>>; |
| 24 | + getEntry(id: string, query?: any): Promise<Entry<any>>; |
| 25 | + getSpace(): Promise<Space>; |
| 26 | + sync(query: any): Promise<SyncCollection>; |
| 27 | +} |
| 28 | + |
| 29 | +export interface Asset { |
| 30 | + sys: Sys; |
| 31 | + fields: { |
| 32 | + title: string; |
| 33 | + description: string; |
| 34 | + file: { |
| 35 | + url: string; |
| 36 | + details: any; |
| 37 | + fileNmae: string; |
| 38 | + contentType: string; |
| 39 | + }; |
| 40 | + }; |
| 41 | + toPlainObject(): Asset; |
| 42 | +} |
| 43 | + |
| 44 | +export interface ContentfulCollection<T> { |
| 45 | + total: number; |
| 46 | + skip: number; |
| 47 | + limit: number; |
| 48 | + items: Array<T>; |
| 49 | + toPlainObject(): this; |
| 50 | +} |
| 51 | + |
| 52 | +export type AssetCollection = ContentfulCollection<Asset> |
| 53 | + |
| 54 | +export interface Entry<T> { |
| 55 | + sys: Sys; |
| 56 | + fields: T; |
| 57 | + toPlainObject(): Entry<T>; |
| 58 | +} |
| 59 | + |
| 60 | +export interface EntryCollection<T> extends ContentfulCollection<Entry<T>> { |
| 61 | + errors?: Array<any>; |
| 62 | + includes?: any; |
| 63 | + stringifySafe(replacer: any, space: any): string; |
| 64 | +} |
| 65 | + |
| 66 | +export interface ContentType { |
| 67 | + sys: Sys; |
| 68 | + name: string; |
| 69 | + description: string; |
| 70 | + displayField: string; |
| 71 | + Array: string; |
| 72 | + toPlainObject(): ContentType; |
| 73 | +} |
| 74 | + |
| 75 | +export type ContentTypeCollection = ContentfulCollection<ContentType>; |
| 76 | + |
| 77 | +export interface Space { |
| 78 | + sys: Sys; |
| 79 | + name: string; |
| 80 | + locales: Array<string>; |
| 81 | + toPlainObject(): Space; |
| 82 | +} |
| 83 | + |
| 84 | +export interface SyncCollection { |
| 85 | + entries: Array<Entry<any>>; |
| 86 | + assets: Array<Asset>; |
| 87 | + deletedEntries: Array<Entry<any>>; |
| 88 | + deletedAssets: Array<Asset>; |
| 89 | + nextSyncToken: string; |
| 90 | + toPlainObject(): SyncCollection; |
| 91 | + stringifySafe(replacer: any, space: any): string; |
| 92 | +} |
| 93 | + |
| 94 | +export interface Sys { |
| 95 | + type: string; |
| 96 | + id: string; |
| 97 | + createdAt: string; |
| 98 | + updatedAt: string; |
| 99 | + locale: string; |
| 100 | + contentType: { |
| 101 | + sys: ContentTypeLink; |
| 102 | + }; |
| 103 | +} |
| 104 | + |
| 105 | +export interface ContentTypeLink { |
| 106 | + type: 'Link'; |
| 107 | + linkType: 'ContentType'; |
| 108 | + id: string; |
| 109 | +} |
| 110 | + |
| 111 | +export function createClient(params: CreateClientParams): ContentfulClientApi; |
0 commit comments