-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.d.ts
238 lines (212 loc) · 5.62 KB
/
controls.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
interface BaseAttachment {
uuid?: string;
description: string;
viewer?: string;
preview?: boolean;
}
interface FileAttachment extends BaseAttachment {
type: "file";
filename: string;
}
interface UrlAttachment extends BaseAttachment {
type: "url";
url: string;
}
interface YoutubeAttachment extends BaseAttachment {
type: "youtube";
videoId: string;
uploadedDate: Date;
}
interface CloudAttachment<Meta extends object = object> extends BaseAttachment {
type: "cloud";
providerId: string;
vendorId: string;
cloudType: string;
display?: object;
meta?: Meta;
indexText?: string;
indexFiles?: string[];
}
type Attachment =
| FileAttachment
| UrlAttachment
| YoutubeAttachment
| CloudAttachment;
interface AddAttachment {
command: "addAttachment";
attachment: Attachment;
xmlPath?: string;
}
interface EditAttachment {
command: "editAttachment";
attachment: Attachment;
}
interface DeleteAttachment {
command: "deleteAttachment";
uuid: string;
xmlPath?: string;
}
type ItemCommand = AddAttachment | EditAttachment | DeleteAttachment;
interface ControlParameters<T extends object> {
vendorId: string;
controlType: string;
providerId: string;
title: string;
ctrlId: string;
element: HTMLElement;
reload: () => void;
config: T;
}
interface ItemState {
xml: XMLDocument;
attachments: Attachment[];
files: FileEntries;
}
interface AddAttachmentResponse {
type: "added";
attachment: Attachment;
}
interface EditAttachmentResponse {
type: "edited";
attachment: Attachment;
}
interface DeleteAttachmentResponse {
type: "deleted";
uuid: string;
}
interface FileEntries {
[x: string]: FileEntry;
}
interface FileEntry {
size: number;
files?: FileEntries;
}
type EditXMLFunc = (edit: (doc: XMLDocument) => XMLDocument) => void;
type ItemCommandResponse =
| AddAttachmentResponse
| EditAttachmentResponse
| DeleteAttachmentResponse;
type ControlValidator = (
editXml: EditXMLFunc,
setRequired: (required: boolean) => void
) => boolean;
interface ControlApi<T extends object = object> extends ControlParameters<T> {
/**
* The current API version.
*/
apiVersion: { major: number; minor: number; patch: number };
/**
* The XML metadata when your control was initialized.
*/
xml: XMLDocument;
/**
* The list of attachments (in REST API format), when your control was initialized.
*/
attachments: Attachment[];
/**
* The tree of file entries contained in this item, when your control was initialized.
*/
files: FileEntries;
/**
* The staging id of the item being edited.
*/
stagingId: string;
/**
* The user id of the user editing the item.
*/
userId: string;
/**
* A function which takes a callback which edits XML metadata document.
*/
editXml: EditXMLFunc;
/**
* A function which can be used to make changes to the attachment list
* and optionally associated metadata path.
* @param edits An array of `ItemCommand`s which can either create, edit or delete an attachment.
* @returns A Promise with an array of corresponding response object giving the result of each command.
*/
edits(edits: ItemCommand[]): Promise<ItemCommandResponse[]>;
/**
* Subscribe to updates to the ItemState (xml, attachments and files).
* @param callback The callback to receive the state update
*/
subscribeUpdates(callback: (doc: ItemState) => void): void;
/**
* Cancel an updates subscription.
* @param callback The callback to remove
*/
unsubscribeUpdates(callback: (doc: ItemState) => void): void;
/**
* Upload/overwrite a file in the staging area for this item.
* @param filepath The filepath to upload to
* @param f The file to upload
*/
uploadFile(filepath: string, f: File): Promise<void>;
/**
* Delete a file from the staging area for this item.
* @param filepath The filepath to delete
*/
deleteFile(filepath: string): Promise<void>;
/**
* Register for the cloud provider to receieve a
* notification to it's `itemNotification` service.
*/
registerNotification(): void;
/**
* Register to participate in wizard control validation.
* @param validator The `ControlValidator` to register
*/
registerValidator(validator: ControlValidator): void;
/**
* De-register a previously registered validator.
* This should be called if your control has been unmounted.
* @param validator
*/
deregisterValidator(validator: ControlValidator): void;
/**
* Get a URL which can be used to proxy requests from your control
* back to your cloud provider service. The returned URL can have extra
* parameters added to the end of it and they will be used as extra substitution
* variables by the service URL mapper.
* @param serviceId The cloud provider service you would like to call.
* @returns A URL to either GET or POST to.
*/
providerUrl(serviceId: string): string;
}
type CloudConfigConfigType =
| "XPath"
| "Textfield"
| "Dropdown"
| "Check"
| "Radio";
interface CloudControlConfig {
id: String;
name: string;
description?: string;
configType: CloudConfigConfigType;
options?: {
name: string;
value: string;
}[];
min?: number;
max?: number;
}
interface CloudControlDefinition {
name: string;
iconUrl?: string;
configuration: CloudControlConfig[];
}
export interface CloudControls {
[controlId: string]: CloudControlDefinition;
}
export interface CloudControlRegister {
register: <T extends object = object>(
vendorId: string,
controlId: string,
mount: (api: ControlApi<T>) => void,
unmount: (removed: Element) => void
) => void;
}
declare global {
const CloudControl: CloudControlRegister;
}