UNPKG

13.1 kBTypeScriptView Raw
1/// <reference types="node" />
2import './polyfills/custom-event-polyfill';
3import { IncomingMessage, ServerResponse } from 'http';
4import { nextTick } from './functions/next-tick.function';
5import { BehaviorSubject } from './classes/observable.class';
6import { throttle } from './functions/throttle.function';
7import { Animator } from './classes/animator.class';
8import { BuilderElement } from './types/element';
9import Cookies from './classes/cookies.class';
10import { BuilderContent } from './types/content';
11export declare type Url = any;
12export declare const isReactNative: boolean;
13export declare const validEnvList: string[];
14export declare const isBrowser: boolean;
15export declare const isIframe: boolean;
16export interface ParamsMap {
17 [key: string]: any;
18}
19interface EventData {
20 contentId?: string;
21 ownerId: string;
22 variationId?: string;
23 userAttributes?: any;
24 targetSelector?: string;
25 targetBuilderElement?: string;
26 unique?: boolean;
27 metadata?: any | string;
28 meta?: any | string;
29 sessionId?: string;
30 visitorId?: string;
31 amount?: number;
32}
33export interface UserAttributes {
34 urlPath?: string;
35 queryString?: string | ParamsMap;
36 device?: 'mobile' | 'tablet' | 'desktop';
37 location?: any;
38 userAgent?: string;
39 referrer?: string;
40 entryMedium?: string;
41 language?: string;
42 browser?: string;
43 cookie?: string;
44 newVisitor?: boolean;
45 operatingSystem?: string;
46}
47export interface GetContentOptions {
48 userAttributes?: UserAttributes;
49 url?: string;
50 includeUrl?: boolean;
51 cacheSeconds?: number;
52 staleCacheSeconds?: number;
53 limit?: number;
54 query?: any;
55 cachebust?: boolean;
56 prerender?: boolean;
57 extractCss?: boolean;
58 offset?: number;
59 initialContent?: any;
60 model?: string;
61 cache?: boolean;
62 preview?: boolean;
63 entry?: string;
64 alias?: string;
65 key?: string;
66 format?: 'amp' | 'email' | 'html';
67 noWrap?: true;
68 rev?: string;
69 static?: boolean;
70}
71export declare type Class = {
72 name?: string;
73 new (...args: any[]): any;
74};
75interface Map<K, V> {
76 clear(): void;
77 delete(key: K): boolean;
78 entries(): IterableIterator<[K, V]>;
79 forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
80 get(key: K): V;
81 has(key: K): boolean;
82 keys(): IterableIterator<K>;
83 set(key: K, value?: V): Map<K, V>;
84 size: number;
85 values(): IterableIterator<V>;
86 [Symbol.iterator](): IterableIterator<[K, V]>;
87}
88export interface Input {
89 name: string;
90 friendlyName?: string;
91 description?: string;
92 defaultValue?: any;
93 type: string;
94 required?: boolean;
95 autoFocus?: boolean;
96 subFields?: Input[];
97 helperText?: string;
98 allowedFileTypes?: string[];
99 imageHeight?: number;
100 imageWidth?: number;
101 mediaHeight?: number;
102 mediaWidth?: number;
103 hideFromUI?: boolean;
104 modelId?: string;
105 enum?: string[] | {
106 label: string;
107 value: any;
108 helperText?: string;
109 }[];
110 /** Regex field validation for all string types (text, longText, html, url, etc) */
111 regex?: {
112 /** pattern to test, like "^\/[a-z]$" */
113 pattern: string;
114 /** flags for the RegExp constructor, e.g. "gi" */
115 options?: string;
116 /**
117 * Friendly message to display to end-users if the regex fails, e.g.
118 * "You must use a relative url starting with '/...' "
119 */
120 message: string;
121 };
122 advanced?: boolean;
123 onChange?: Function | string;
124 code?: boolean;
125 richText?: boolean;
126 showIf?: ((options: Map<string, any>) => boolean) | string;
127}
128export interface Component {
129 /**
130 * Name your component something unique, e.g. 'MyButton'. You can override built-in components
131 * by registering a component with the same name, e.g. 'Text', to replace the built-in text component
132 */
133 name: string;
134 description?: string;
135 /**
136 * Link to a documentation page for this component
137 */
138 docsLink?: string;
139 image?: string;
140 /**
141 * Input schema for your component for users to fill in the options
142 */
143 inputs?: Input[];
144 class?: any;
145 type?: 'angular' | 'webcomponent' | 'react' | 'vue';
146 defaultStyles?: {
147 [key: string]: string;
148 };
149 /**
150 * Turn on if your component can accept children. Be sure to use in combination with
151 * withChildren(YourComponent) like here
152 * github.com/BuilderIO/builder/blob/master/examples/react-design-system/src/components/HeroWithChildren/HeroWithChildren.builder.js#L5
153 */
154 canHaveChildren?: boolean;
155 fragment?: boolean;
156 /**
157 * Do not wrap a component in a dom element. Be sure to use {...props.attributes} with this option
158 * like here github.com/BuilderIO/builder/blob/master/packages/react/src/blocks/forms/Input.tsx#L34
159 */
160 noWrap?: boolean;
161 /**
162 * Default children
163 */
164 defaultChildren?: BuilderElement[];
165 defaults?: Partial<BuilderElement>;
166 hooks?: {
167 [key: string]: string | Function;
168 };
169 hideFromInsertMenu?: boolean;
170 tag?: string;
171 static?: boolean;
172 /**
173 * Specify restrictions direct children must match
174 */
175 childRequirements?: {
176 /** Message to show when this doesn't match, e.g. "Children of 'Columns' must be a 'Column'" */
177 message: string;
178 /** Simple way to say children must be a specific component name */
179 component?: string;
180 /**
181 * More advanced - specify a MongoDB-style query (using sift.js github.com/crcn/sift.js)
182 * of what the children objects should match, e.g.
183 *
184 * @example
185 * query: {
186 * // Child of this element must be a 'Button' or 'Text' component
187 * 'component.name': { $in: ['Button', 'Text'] }
188 * }
189 */
190 query?: any;
191 };
192 /**
193 * Specify restrictions any parent must match
194 */
195 requiresParent?: {
196 /** Message to show when this doesn't match, e.g. "'Add to cart' buttons must be within a 'Product box'" */
197 message: string;
198 /** Simple way to say a parent must be a specific component name, e.g. 'Product box' */
199 component?: string;
200 /**
201 * More advanced - specify a MongoDB-style query (using sift.js github.com/crcn/sift.js)
202 * of what at least one parent in the parents hierarchy should match, e.g.
203 *
204 * @example
205 * query: {
206 * // Thils element must be somewhere inside either a 'Product box' or 'Collection' component
207 * 'component.name': { $in: ['Product Box', 'Collection'] }
208 * }
209 */
210 query?: any;
211 };
212 /** not yet implemented */
213 friendlyName?: string;
214}
215declare type DeepPartial<T> = {
216 [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]>;
217};
218export interface InsertMenuItem {
219 name: string;
220 icon?: string;
221 item: DeepPartial<BuilderElement>;
222}
223export interface InsertMenuConfig {
224 name: string;
225 priority?: number;
226 persist?: boolean;
227 advanced?: boolean;
228 items: InsertMenuItem[];
229}
230export declare function BuilderComponent(info?: Partial<Component>): (component: Class) => Class;
231declare type Settings = any;
232export interface Action {
233 name: string;
234 inputs?: Input[];
235 returnType?: Input;
236 action: Function | string;
237}
238export declare class Builder {
239 protected request?: IncomingMessage | undefined;
240 protected response?: ServerResponse | undefined;
241 static VERSION: string;
242 static components: Component[];
243 static singletonInstance: Builder;
244 static useNewApi: boolean;
245 static isStatic: boolean;
246 static animator: Animator;
247 static nextTick: typeof nextTick;
248 static throttle: typeof throttle;
249 authToken: string;
250 static editors: any[];
251 static plugins: any[];
252 static actions: Action[];
253 static registry: {
254 [key: string]: any[];
255 };
256 /**
257 * @todo `key` property on any info where if a key matches a current
258 * key it gets removed
259 */
260 static register(type: 'insertMenu', info: InsertMenuConfig): void;
261 static register(type: string, info: any): void;
262 static registryChange: BehaviorSubject<{
263 [key: string]: any[];
264 }, any>;
265 static registerEditor(info: any): void;
266 static registerPlugin(info: any): void;
267 static registerAction(action: Action): void;
268 static runAction(action: Action | string): void;
269 static fields(name: string, fields: Input[]): void;
270 private static _editingPage;
271 static isIframe: boolean;
272 static isBrowser: boolean;
273 static isReactNative: boolean;
274 static isServer: boolean;
275 static previewingModel: string | false | null;
276 static settings: Settings;
277 static settingsChange: BehaviorSubject<any, any>;
278 static set(settings: Settings): void;
279 static import(packageName: string): any;
280 static isEditing: boolean;
281 static isPreviewing: boolean;
282 static get editingPage(): boolean;
283 static set editingPage(editingPage: boolean);
284 private static prepareComponentSpecToSend;
285 static registerComponent(component: any, options: Component): void;
286 private static addComponent;
287 static component(info?: Partial<Component>): (component: Class) => Class;
288 static isReact: boolean;
289 static get Component(): typeof Builder.component;
290 private eventsQueue;
291 private throttledClearEventsQueue;
292 private processEventsQueue;
293 env: string;
294 sessionId: string;
295 targetContent: boolean;
296 private cookies;
297 private cachebust;
298 private overrideParams;
299 private noCache;
300 private preview;
301 get browserTrackingDisabled(): boolean;
302 get canTrack(): boolean;
303 set canTrack(canTrack: boolean);
304 private canTrack$;
305 private apiKey$;
306 userAttributesChanged: BehaviorSubject<any, any>;
307 get editingMode(): boolean;
308 set editingMode(value: boolean);
309 editingMode$: BehaviorSubject<boolean, any>;
310 get editingModel(): string | null;
311 set editingModel(value: string | null);
312 private findParentElement;
313 private findBuilderParent;
314 editingModel$: BehaviorSubject<string | null, any>;
315 setUserAgent(userAgent: string): void;
316 userAgent: string;
317 track(eventName: string, properties?: Partial<EventData>): void;
318 getSessionId(): string;
319 visitorId: string;
320 getVisitorId(): string;
321 trackImpression(contentId: string, variationId?: string): void;
322 trackConversion(amount?: number, customProperties?: any): void;
323 autoTrack: boolean;
324 useNewContentApi: boolean;
325 private get isDevelopmentEnv();
326 trackInteraction(contentId: string, variationId?: string, alreadyTrackedOne?: boolean, event?: MouseEvent): void;
327 static overrideUserAttributes: Partial<UserAttributes>;
328 component(info?: Partial<Component>): (component: Class) => Class;
329 get apiKey(): string | null;
330 set apiKey(key: string | null);
331 constructor(apiKey?: string | null, request?: IncomingMessage | undefined, response?: ServerResponse | undefined, forceNewInstance?: boolean);
332 private modifySearch;
333 setTestsFromUrl(): void;
334 resetOverrides(): void;
335 getOverridesFromQueryString(): void;
336 private messageFrameLoaded;
337 private blockContentLoading;
338 private bindMessageListeners;
339 observersByKey: {
340 [key: string]: BehaviorSubject<BuilderContent[]> | undefined;
341 };
342 get defaultCanTrack(): boolean;
343 init(apiKey: string, canTrack?: boolean, req?: IncomingMessage, res?: ServerResponse): this;
344 getLocation(): Url;
345 getUserAttributes(userAgent?: string): UserAttributes;
346 protected overrides: {
347 [key: string]: string;
348 };
349 private getContentQueue;
350 private priorContentQueue;
351 setUserAttributes(options: object): void;
352 get(modelName: string, options?: GetContentOptions & {
353 req?: IncomingMessage;
354 res?: ServerResponse;
355 apiKey?: string;
356 }): BehaviorSubject<any, any>;
357 queueGetContent(modelName: string, options?: GetContentOptions): BehaviorSubject<BuilderContent[], any>;
358 requestUrl(url: string): Promise<any>;
359 get host(): string;
360 private flushGetContentQueue;
361 private testCookiePrefix;
362 private processResultsForTests;
363 private getTestCookie;
364 private cookieQueue;
365 private setTestCookie;
366 getCookie(name: string): any;
367 setCookie(name: string, value: any, expires?: Date): false | void | Cookies;
368 getContent(modelName: string, options?: GetContentOptions): BehaviorSubject<BuilderContent[], any>;
369}
370export {};