UNPKG

3.75 kBTypeScriptView Raw
1import { FieldType } from './field-type';
2import { DefinedParameters, ParameterDefinition } from './widget-parameters';
3import { DefaultElements, BasicMetaSysProps, SysLink, MakeRequest } from '../common-types';
4import { SetRequired, RequireExactlyOne } from 'type-fest';
5declare type ExtensionSysProps = BasicMetaSysProps & {
6 space: SysLink;
7 environment: SysLink;
8 srcdocSha256?: string;
9};
10export declare type ExtensionProps = {
11 sys: ExtensionSysProps;
12 extension: {
13 /**
14 * Extension name
15 */
16 name: string;
17 /**
18 * Field types where an extension can be used
19 */
20 fieldTypes: FieldType[];
21 /**
22 * URL where the root HTML document of the extension can be found
23 */
24 src?: string;
25 /**
26 * String representation of the extension (e.g. inline HTML code)
27 */
28 srcdoc?: string;
29 /**
30 * Parameter definitions
31 */
32 parameters?: {
33 instance?: ParameterDefinition[];
34 installation?: ParameterDefinition[];
35 };
36 /**
37 * Controls the location of the extension. If true it will be rendered on the sidebar instead of replacing the field's editing control
38 */
39 sidebar?: boolean;
40 };
41 /**
42 * Values for installation parameters
43 */
44 parameters?: DefinedParameters;
45};
46export declare type CreateExtensionProps = {
47 extension: RequireExactlyOne<SetRequired<ExtensionProps['extension'], 'name' | 'fieldTypes' | 'sidebar'>, 'src' | 'srcdoc'>;
48};
49export interface Extension extends ExtensionProps, DefaultElements<ExtensionProps> {
50 /**
51 * Sends an update to the server with any changes made to the object's properties
52 * @return Object returned from the server with updated changes.
53 * @example ```javascript
54 * const contentful = require('contentful-management')
55 *
56 * const client = contentful.createClient({
57 * accessToken: '<content_management_api_key>'
58 * })
59 *
60 * client.getSpace('<space_id>')
61 * .then((space) => space.getEnvironment('<environment_id>'))
62 * .then((environment) => environment.getUiExtension('<ui_extension_id>'))
63 * .then((extension) => {
64 * extension.extension.name = 'New UI Extension name'
65 * return extension.update()
66 * })
67 * .then((extension) => console.log(`UI Extension ${extension.sys.id} updated.`))
68 * .catch(console.error)
69 * ```
70 */
71 update(): Promise<Extension>;
72 /**
73 * Deletes this object on the server.
74 * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
75 * @example ```javascript
76 * const contentful = require('contentful-management')
77 *
78 * const client = contentful.createClient({
79 * accessToken: '<content_management_api_key>'
80 * })
81 *
82 * client.getSpace('<space_id>')
83 * .then((space) => space.getEnvironment('<environment_id>'))
84 * .then((environment) => environment.getUiExtension('<ui_extension_id>'))
85 * .then((extension) => extension.delete())
86 * .then(() => console.log(`UI Extension deleted.`))
87 * .catch(console.error)
88 * ```
89 */
90 delete(): Promise<void>;
91}
92/**
93 * @private
94 * @param makeRequest - function to make requests via an adapter
95 * @param data - Raw UI Extension data
96 * @return Wrapped UI Extension data
97 */
98export declare function wrapExtension(makeRequest: MakeRequest, data: ExtensionProps): Extension;
99/**
100 * @private
101 */
102export declare const wrapExtensionCollection: (makeRequest: MakeRequest, data: import("../common-types").CollectionProp<ExtensionProps>) => import("../common-types").Collection<Extension, ExtensionProps>;
103export {};