contentful-management
Version:
Client for Contentful's Content Management API
154 lines (153 loc) • 5.4 kB
TypeScript
import type { Except } from 'type-fest';
import type { CursorPaginationParams, DataTypeDefinition, ExoCursorPaginatedCollectionProp, ExoMetadataProps, ExoQueryFilters, Link, ResourceLink } from '../common-types';
export type ComponentTypeQueryOptions = CursorPaginationParams & ExoQueryFilters & {
order?: string;
};
export type ComponentTypeViewport = {
id: string;
query: string;
displayName: string;
previewSize: string;
};
export type ComponentTypeContentProperty = DataTypeDefinition & {
id: string;
name: string;
required: boolean;
defaultValue?: unknown;
};
export type StringDesignPropertyRegexpValidation = {
regexp: {
pattern: string;
};
};
export type DesignTokenAllowedResource = {
type: 'DesignToken';
value: string;
name?: string;
};
export type DTCGDesignPropertyType = 'DTCG.Color' | 'DTCG.Dimension' | 'DTCG.FontFamily' | 'DTCG.FontWeight' | 'DTCG.Duration' | 'DTCG.CubicBezier' | 'DTCG.Number' | 'DTCG.StrokeStyle' | 'DTCG.Border' | 'DTCG.Transition' | 'DTCG.Shadow' | 'DTCG.Gradient' | 'DTCG.Typography';
type DesignPropertyCommonFields = {
id: string;
name: string;
description?: string;
};
export type StringDesignProperty = DesignPropertyCommonFields & {
type: 'String';
fallbackValue?: {
type: 'ManualDesignValue';
value: string;
};
validations?: StringDesignPropertyRegexpValidation[];
};
export type BooleanDesignProperty = DesignPropertyCommonFields & {
type: 'Boolean';
fallbackValue?: {
type: 'ManualDesignValue';
value: boolean;
};
};
export type TokenBackedDesignProperty = DesignPropertyCommonFields & {
type: DTCGDesignPropertyType;
fallbackValue?: DesignTokenValue;
allowedResources?: DesignTokenAllowedResource[];
};
export type ComponentTypeDesignProperty = StringDesignProperty | BooleanDesignProperty | TokenBackedDesignProperty;
export type ContentPropertyPointerValue = `$contentProperties/${string}`;
export type DesignPropertyPointerValue = `$designProperties/${string}`;
export type ManualDesignValue = {
type: 'ManualDesignValue';
value: string | number | boolean;
};
export type DesignTokenValue = {
type: 'DesignToken';
/** Must be non-empty (min length 1) */
value: string;
};
export type DesignPropertyValue = ManualDesignValue | DesignTokenValue;
export type DimensionedDesignPropertyValue = Record<string, DesignPropertyValue>;
export type ComponentTreeDesignPropertyValue = DesignPropertyValue | DesignPropertyPointerValue | DimensionedDesignPropertyValue;
export type ComponentNode = {
id: string;
name?: string;
nodeType: 'Component';
componentType: ResourceLink<'Contentful:ComponentType'>;
contentProperties: Record<string, ContentPropertyPointerValue | unknown> | string;
designProperties: Record<string, ComponentTreeDesignPropertyValue>;
slots: Record<string, TreeNode[]>;
};
export type FragmentNode = {
id: string;
name?: string;
nodeType: 'Fragment';
fragment: ResourceLink<'Contentful:Fragment'>;
};
export type SlotNode = {
id: string;
nodeType: 'Slot';
slotId: string;
};
export type TreeNode = ComponentNode | FragmentNode | SlotNode;
export type DataAssemblyLink = ResourceLink<'Contentful:DataAssembly'>;
export declare const COMPONENT_TYPE_ALLOWED_RESOURCE_SOURCE: "crn:contentful:::experience:spaces/$self/environments/$self";
export type ComponentTypeSlotDefinition = {
id: string;
name: string;
required: boolean;
validations: Array<{
size?: {
min?: number;
max?: number;
};
}>;
allowedResources?: Array<{
type: 'Contentful:ComponentType';
source: typeof COMPONENT_TYPE_ALLOWED_RESOURCE_SOURCE;
allowedTypes: string[];
}>;
};
export type ComponentTypeSys = {
id: string;
type: 'ComponentType';
version: number;
space: Link<'Space'>;
environment: Link<'Environment'>;
fieldStatus?: Record<string, Record<string, 'draft' | 'published' | 'changed'>>;
publishedAt?: string;
publishedVersion?: number;
publishedCounter?: number;
firstPublishedAt?: string;
publishedBy?: Link<'User'> | Link<'AppDefinition'>;
variant?: string;
variantType?: string;
variantDimension?: string;
createdAt: string;
createdBy: Link<'User'>;
updatedAt: string;
updatedBy: Link<'User'>;
};
export type ComponentTypeProps = {
sys: ComponentTypeSys;
name: string;
description: string;
viewports: ComponentTypeViewport[];
contentProperties: ComponentTypeContentProperty[];
designProperties: ComponentTypeDesignProperty[];
componentTree?: TreeNode[];
slots?: ComponentTypeSlotDefinition[];
metadata?: ExoMetadataProps;
dataAssemblies?: DataAssemblyLink[];
source?: ResourceLink<'Contentful:DesignSystemSource'>;
};
export type CreateComponentTypeProps = Except<ComponentTypeProps, 'sys' | 'source'> & {
source?: ResourceLink<'Contentful:DesignSystemSource'> | null;
};
export type UpsertComponentTypeProps = Except<ComponentTypeProps, 'sys' | 'source'> & {
sys: {
id: string;
type: 'ComponentType';
version?: number;
};
source?: ResourceLink<'Contentful:DesignSystemSource'> | null;
};
export type ComponentTypeCollection = ExoCursorPaginatedCollectionProp<ComponentTypeProps>;
export {};