@stackbit/cms-contentstack 0.1.1-staging.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/contentstack-api-client.d.ts +63 -0
- package/dist/contentstack-api-client.d.ts.map +1 -0
- package/dist/contentstack-api-client.js +295 -0
- package/dist/contentstack-api-client.js.map +1 -0
- package/dist/contentstack-content-poller.d.ts +46 -0
- package/dist/contentstack-content-poller.d.ts.map +1 -0
- package/dist/contentstack-content-poller.js +111 -0
- package/dist/contentstack-content-poller.js.map +1 -0
- package/dist/contentstack-content-source.d.ts +138 -0
- package/dist/contentstack-content-source.d.ts.map +1 -0
- package/dist/contentstack-content-source.js +544 -0
- package/dist/contentstack-content-source.js.map +1 -0
- package/dist/contentstack-conversion-utils.d.ts +41 -0
- package/dist/contentstack-conversion-utils.d.ts.map +1 -0
- package/dist/contentstack-conversion-utils.js +504 -0
- package/dist/contentstack-conversion-utils.js.map +1 -0
- package/dist/contentstack-entries-converter.d.ts +39 -0
- package/dist/contentstack-entries-converter.d.ts.map +1 -0
- package/dist/contentstack-entries-converter.js +333 -0
- package/dist/contentstack-entries-converter.js.map +1 -0
- package/dist/contentstack-operation-converter.d.ts +42 -0
- package/dist/contentstack-operation-converter.d.ts.map +1 -0
- package/dist/contentstack-operation-converter.js +535 -0
- package/dist/contentstack-operation-converter.js.map +1 -0
- package/dist/contentstack-schema-converter.d.ts +26 -0
- package/dist/contentstack-schema-converter.d.ts.map +1 -0
- package/dist/contentstack-schema-converter.js +379 -0
- package/dist/contentstack-schema-converter.js.map +1 -0
- package/dist/contentstack-types.d.ts +429 -0
- package/dist/contentstack-types.d.ts.map +1 -0
- package/dist/contentstack-types.js +3 -0
- package/dist/contentstack-types.js.map +1 -0
- package/dist/contentstack-utils.d.ts +31 -0
- package/dist/contentstack-utils.d.ts.map +1 -0
- package/dist/contentstack-utils.js +144 -0
- package/dist/contentstack-utils.js.map +1 -0
- package/dist/entries-converter.d.ts +10 -0
- package/dist/entries-converter.d.ts.map +1 -0
- package/dist/entries-converter.js +245 -0
- package/dist/entries-converter.js.map +1 -0
- package/dist/file-download.d.ts +2 -0
- package/dist/file-download.d.ts.map +1 -0
- package/dist/file-download.js +33 -0
- package/dist/file-download.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/schema-converter.d.ts +3 -0
- package/dist/schema-converter.d.ts.map +1 -0
- package/dist/schema-converter.js +169 -0
- package/dist/schema-converter.js.map +1 -0
- package/dist/transformation-utils.d.ts +41 -0
- package/dist/transformation-utils.d.ts.map +1 -0
- package/dist/transformation-utils.js +730 -0
- package/dist/transformation-utils.js.map +1 -0
- package/dist/types.d.ts +120 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -0
- package/src/contentstack-api-client.ts +330 -0
- package/src/contentstack-content-poller.ts +157 -0
- package/src/contentstack-content-source.ts +687 -0
- package/src/contentstack-entries-converter.ts +438 -0
- package/src/contentstack-operation-converter.ts +703 -0
- package/src/contentstack-schema-converter.ts +486 -0
- package/src/contentstack-types.ts +527 -0
- package/src/contentstack-utils.ts +174 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import type { Stack as ContentStackStack } from '@contentstack/management/types/stack';
|
|
2
|
+
import type { User as ContentStackUser } from '@contentstack/management/types/user';
|
|
3
|
+
import type { ContentType as ContentStackContentType } from '@contentstack/management/types/stack/contentType';
|
|
4
|
+
import type { GlobalField as ContentStackGlobalField } from '@contentstack/management/types/stack/globalField';
|
|
5
|
+
import type { Environment as ContentStackEnvironment } from '@contentstack/management/types/stack/environment';
|
|
6
|
+
import type { Entry as ContentStackEntry } from '@contentstack/management/types/stack/contentType/entry';
|
|
7
|
+
import type { Asset as ContentStackAsset } from '@contentstack/management/types/stack/asset';
|
|
8
|
+
import type { Webhook as ContentStackWebhook, WebhookDestination as ContentStackWebhookDestination } from '@contentstack/management/types/stack/webhook';
|
|
9
|
+
|
|
10
|
+
// Stack
|
|
11
|
+
// =====
|
|
12
|
+
|
|
13
|
+
export type Stack = ContentStackStack & {
|
|
14
|
+
uid: string;
|
|
15
|
+
name: string;
|
|
16
|
+
api_key: string;
|
|
17
|
+
org_uid: string;
|
|
18
|
+
master_locale: string;
|
|
19
|
+
created_at: string;
|
|
20
|
+
updated_at: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// User
|
|
24
|
+
// ====
|
|
25
|
+
|
|
26
|
+
export type User = ContentStackUser & {
|
|
27
|
+
uid: string;
|
|
28
|
+
created_at?: string;
|
|
29
|
+
updated_at?: string;
|
|
30
|
+
email?: string;
|
|
31
|
+
username?: string;
|
|
32
|
+
first_name?: string;
|
|
33
|
+
last_name?: string;
|
|
34
|
+
active?: boolean;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Models
|
|
38
|
+
// ======
|
|
39
|
+
|
|
40
|
+
export type GlobalField = ContentStackGlobalField & {
|
|
41
|
+
uid: string;
|
|
42
|
+
title: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
created_at?: string;
|
|
45
|
+
updated_at?: string;
|
|
46
|
+
urlPath?: string;
|
|
47
|
+
_version?: number;
|
|
48
|
+
_branch?: string;
|
|
49
|
+
inbuilt_class?: boolean;
|
|
50
|
+
last_activity?: unknown;
|
|
51
|
+
maintain_revisions?: boolean;
|
|
52
|
+
schema: ContentStackField[];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type ContentType = ContentStackContentType & {
|
|
56
|
+
uid: string;
|
|
57
|
+
title: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
created_at?: string;
|
|
60
|
+
updated_at?: string;
|
|
61
|
+
_version?: number;
|
|
62
|
+
_branch?: string;
|
|
63
|
+
inbuilt_class?: boolean;
|
|
64
|
+
last_activity?: unknown;
|
|
65
|
+
maintain_revisions?: boolean;
|
|
66
|
+
DEFAULT_ACL?: unknown;
|
|
67
|
+
SYS_ACL?: unknown;
|
|
68
|
+
options?: {
|
|
69
|
+
is_page: boolean;
|
|
70
|
+
singleton: boolean;
|
|
71
|
+
sub_title: any[];
|
|
72
|
+
title: string;
|
|
73
|
+
url_pattern?: string;
|
|
74
|
+
url_prefix?: string;
|
|
75
|
+
};
|
|
76
|
+
abilities?: {
|
|
77
|
+
get_one_object: boolean;
|
|
78
|
+
get_all_objects: boolean;
|
|
79
|
+
create_object: boolean;
|
|
80
|
+
update_object: boolean;
|
|
81
|
+
delete_object: boolean;
|
|
82
|
+
delete_all_objects: boolean;
|
|
83
|
+
};
|
|
84
|
+
schema: ContentStackField[];
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type ContentStackField =
|
|
88
|
+
| ContenteStackFieldText
|
|
89
|
+
| ContentStackFieldBoolean
|
|
90
|
+
| ContentStackFieldJson
|
|
91
|
+
| ContentStackFieldFile
|
|
92
|
+
| ContentStackFieldDate
|
|
93
|
+
| ContentStackFieldNumber
|
|
94
|
+
| ContentStackFieldLink
|
|
95
|
+
| ContentStackFieldGroup
|
|
96
|
+
| ContentStackFieldGlobalField
|
|
97
|
+
| ContentStackFieldReference
|
|
98
|
+
| ContentStackFieldBlocks;
|
|
99
|
+
|
|
100
|
+
export type ContentStackFieldCommon = {
|
|
101
|
+
uid: string;
|
|
102
|
+
display_name: string;
|
|
103
|
+
mandatory: boolean;
|
|
104
|
+
multiple: boolean;
|
|
105
|
+
non_localizable: boolean;
|
|
106
|
+
unique: boolean;
|
|
107
|
+
field_metadata: {
|
|
108
|
+
description?: string;
|
|
109
|
+
placeholder?: string;
|
|
110
|
+
instruction?: string;
|
|
111
|
+
default_value?: any;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export type ContenteStackFieldText = ContentStackFieldCommon &
|
|
116
|
+
ContentStackFieldEnumCommon<string> & {
|
|
117
|
+
data_type: 'text';
|
|
118
|
+
format?: string;
|
|
119
|
+
// reference_to for allowed models when rich-text is used
|
|
120
|
+
reference_to: string[];
|
|
121
|
+
field_metadata?: {
|
|
122
|
+
_default?: boolean;
|
|
123
|
+
// multiline text
|
|
124
|
+
multiline?: boolean;
|
|
125
|
+
// markdown text
|
|
126
|
+
markdown?: boolean;
|
|
127
|
+
// rich-text
|
|
128
|
+
allow_rich_text?: boolean;
|
|
129
|
+
rich_text_type?: 'basic' | 'advanced' | 'custom';
|
|
130
|
+
// allowed rich-text options, e.g., h1, h2, bold, italic, etc.
|
|
131
|
+
options?: string[];
|
|
132
|
+
ref_multiple_content_types?: boolean;
|
|
133
|
+
// allows embedding entries into rich-text
|
|
134
|
+
embed_entry?: boolean;
|
|
135
|
+
// default key for enum options when advanced enum is used
|
|
136
|
+
default_key?: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type ContentStackFieldEnumCommon<ValueType> = {
|
|
141
|
+
// display type for enums. The 'dropdown' and 'radio' used on single enum
|
|
142
|
+
// values, while 'dropdown' and 'checkbox' for list of enums.
|
|
143
|
+
display_type?: 'dropdown' | 'checkbox' | 'radio';
|
|
144
|
+
// enum options when enum is used
|
|
145
|
+
enum?: ContentStackEnumOptions<ValueType>;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export type ContentStackEnumOptions<ValueType> = ContentStackEnumOptionsSimple<ValueType> | ContentStackEnumOptionsAdvanced<ValueType>;
|
|
149
|
+
|
|
150
|
+
export type ContentStackEnumOptionsSimple<ValueType> = {
|
|
151
|
+
advanced: false;
|
|
152
|
+
choices: {
|
|
153
|
+
value: ValueType;
|
|
154
|
+
}[];
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export type ContentStackEnumOptionsAdvanced<ValueType> = {
|
|
158
|
+
advanced: true;
|
|
159
|
+
choices: {
|
|
160
|
+
key: string;
|
|
161
|
+
value: ValueType;
|
|
162
|
+
}[];
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export type ContentStackFieldBoolean = ContentStackFieldCommon & {
|
|
166
|
+
data_type: 'boolean';
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export type ContentStackFieldJson = ContentStackFieldCommon & {
|
|
170
|
+
data_type: 'json';
|
|
171
|
+
format?: string;
|
|
172
|
+
// reference_to for allowed models when rich-text is used
|
|
173
|
+
reference_to?: string[];
|
|
174
|
+
field_metadata: {
|
|
175
|
+
allow_json_rte?: boolean;
|
|
176
|
+
embed_entry?: boolean;
|
|
177
|
+
multiline?: boolean;
|
|
178
|
+
rich_text_type?: 'basic' | 'advanced' | 'custom';
|
|
179
|
+
// allowed rich-text options, e.g., h1, h2, bold, italic, etc.
|
|
180
|
+
options?: string[];
|
|
181
|
+
ref_multiple_content_types?: boolean;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export type ContentStackFieldFile = ContentStackFieldCommon & {
|
|
186
|
+
data_type: 'file';
|
|
187
|
+
field_metadata: {
|
|
188
|
+
rich_text_type?: 'standard';
|
|
189
|
+
image?: boolean;
|
|
190
|
+
};
|
|
191
|
+
// file size limit
|
|
192
|
+
min?: number;
|
|
193
|
+
max?: number;
|
|
194
|
+
// image dimension limit
|
|
195
|
+
dimension?: {
|
|
196
|
+
width: ImageDimensions;
|
|
197
|
+
height: ImageDimensions;
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export type ImageDimensions = {
|
|
202
|
+
min?: number | null;
|
|
203
|
+
max?: number | null;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export type ContentStackFieldDate = ContentStackFieldCommon & {
|
|
207
|
+
data_type: 'isodate';
|
|
208
|
+
startDate?: string | null;
|
|
209
|
+
endDate?: string | null;
|
|
210
|
+
field_metadata: {
|
|
211
|
+
hide_time?: boolean;
|
|
212
|
+
date_range?: boolean;
|
|
213
|
+
default_value?: {
|
|
214
|
+
custom: boolean;
|
|
215
|
+
date?: string;
|
|
216
|
+
time?: string;
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export type ContentStackFieldNumber = ContentStackFieldCommon &
|
|
222
|
+
ContentStackFieldEnumCommon<number> & {
|
|
223
|
+
data_type: 'number';
|
|
224
|
+
min?: number | null;
|
|
225
|
+
max?: number | null;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export type ContentStackFieldLink = ContentStackFieldCommon & {
|
|
229
|
+
data_type: 'link';
|
|
230
|
+
field_metadata: {
|
|
231
|
+
default_value?: {
|
|
232
|
+
title?: string;
|
|
233
|
+
url?: string;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export type ContentStackFieldGroup = ContentStackFieldCommon & {
|
|
239
|
+
data_type: 'group';
|
|
240
|
+
schema: ContentStackField[];
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export type ContentStackFieldGlobalField = ContentStackFieldCommon & {
|
|
244
|
+
data_type: 'global_field';
|
|
245
|
+
reference_to: string;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export type ContentStackFieldReference = ContentStackFieldCommon & {
|
|
249
|
+
data_type: 'reference';
|
|
250
|
+
reference_to?: string[];
|
|
251
|
+
field_metadata: {
|
|
252
|
+
ref_multiple: boolean;
|
|
253
|
+
ref_multiple_content_types: boolean;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export type ContentStackFieldBlocks = Omit<ContentStackFieldCommon, 'multiple'> & {
|
|
258
|
+
data_type: 'blocks';
|
|
259
|
+
multiple: true;
|
|
260
|
+
blocks: (ContentStackFieldBlockItemSimple | ContentStackFieldBlockItemGlobalField)[];
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export type ContentStackFieldBlockItemGlobalField = {
|
|
264
|
+
uid: string;
|
|
265
|
+
title: string;
|
|
266
|
+
reference_to: string;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
export type ContentStackFieldBlockItemSimple = {
|
|
270
|
+
uid: string;
|
|
271
|
+
title: string;
|
|
272
|
+
schema: ContentStackField[];
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// Entries
|
|
276
|
+
// =======
|
|
277
|
+
|
|
278
|
+
export type Entry = ContentStackEntry & {
|
|
279
|
+
uid: string;
|
|
280
|
+
content_type_uid: string;
|
|
281
|
+
title: string;
|
|
282
|
+
url?: string;
|
|
283
|
+
created_at: string;
|
|
284
|
+
updated_at: string;
|
|
285
|
+
created_by: string;
|
|
286
|
+
updated_by: string;
|
|
287
|
+
locale?: string;
|
|
288
|
+
tags?: string[];
|
|
289
|
+
publish_details?: PublishDetails[];
|
|
290
|
+
ACL?: unknown;
|
|
291
|
+
_branch?: string;
|
|
292
|
+
_version?: number;
|
|
293
|
+
_in_progress?: boolean;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export type PublishDetails = {
|
|
297
|
+
environment: string;
|
|
298
|
+
time: string;
|
|
299
|
+
user: string;
|
|
300
|
+
version: number;
|
|
301
|
+
/**
|
|
302
|
+
* The locale of the published document.
|
|
303
|
+
* Note, the locale may be different from entry's own locale.
|
|
304
|
+
*/
|
|
305
|
+
locale: string;
|
|
306
|
+
/**
|
|
307
|
+
* The 'entry_locale' specified the original entry locale under which the
|
|
308
|
+
* entry was published, it may be different from the 'locale'.
|
|
309
|
+
*
|
|
310
|
+
* For example, if an entry with locale "A" has been published to locale "B",
|
|
311
|
+
* for which it isn't localized. Then the 'locale' will be locale "B", while
|
|
312
|
+
* the entry's own locale will remain "A" (because it is not localized),
|
|
313
|
+
* even when entries are fetched with locale=B filter.
|
|
314
|
+
* But, once the entry will be localized to locale "B", the 'entry_locale'
|
|
315
|
+
* will be set to locale "A", and the 'locale' will be set to locale "B"
|
|
316
|
+
* matching the entry's own locale.
|
|
317
|
+
*/
|
|
318
|
+
entry_locale?: string;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// Assets
|
|
322
|
+
// ======
|
|
323
|
+
|
|
324
|
+
export type Asset = ContentStackAsset & {
|
|
325
|
+
uid: string;
|
|
326
|
+
title?: string;
|
|
327
|
+
description?: string;
|
|
328
|
+
created_at: string;
|
|
329
|
+
updated_at: string;
|
|
330
|
+
created_by: string;
|
|
331
|
+
updated_by: string;
|
|
332
|
+
content_type?: string;
|
|
333
|
+
file_size?: string;
|
|
334
|
+
tags?: string[];
|
|
335
|
+
filename?: string;
|
|
336
|
+
url?: string;
|
|
337
|
+
ACL?: unknown;
|
|
338
|
+
is_dir?: boolean;
|
|
339
|
+
parent_uid?: unknown;
|
|
340
|
+
_version?: number;
|
|
341
|
+
_branch?: string;
|
|
342
|
+
publish_details?: PublishDetails[];
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// Locales
|
|
346
|
+
// =======
|
|
347
|
+
|
|
348
|
+
export type ContentStackLocale = {
|
|
349
|
+
uid: string;
|
|
350
|
+
code: string;
|
|
351
|
+
name: string;
|
|
352
|
+
fallback_locale?: string | null;
|
|
353
|
+
created_by?: string;
|
|
354
|
+
updated_by?: string;
|
|
355
|
+
created_at?: string;
|
|
356
|
+
updated_at?: string;
|
|
357
|
+
ACL?: unknown;
|
|
358
|
+
_version?: number;
|
|
359
|
+
_branch?: string;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// Environments
|
|
363
|
+
// ============
|
|
364
|
+
|
|
365
|
+
export type Environment = ContentStackEnvironment & {
|
|
366
|
+
uid: string;
|
|
367
|
+
name: string;
|
|
368
|
+
urls?: any[];
|
|
369
|
+
ACL?: unknown;
|
|
370
|
+
created_at?: string;
|
|
371
|
+
updated_at?: string;
|
|
372
|
+
created_by?: string;
|
|
373
|
+
updated_by?: string;
|
|
374
|
+
_version?: number;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
// Webhooks
|
|
378
|
+
// ========
|
|
379
|
+
|
|
380
|
+
export type Webhook = ContentStackWebhook & {
|
|
381
|
+
uid: string;
|
|
382
|
+
name: string;
|
|
383
|
+
destinations: WebhookDestination[];
|
|
384
|
+
channels?: string[];
|
|
385
|
+
branches: string[];
|
|
386
|
+
retry_policy: string;
|
|
387
|
+
disabled: boolean;
|
|
388
|
+
concise_payload: boolean;
|
|
389
|
+
notifiers: unknown[];
|
|
390
|
+
applikation_id?: string;
|
|
391
|
+
app_user_object_uid: string;
|
|
392
|
+
org_uid?: string;
|
|
393
|
+
created_at?: string;
|
|
394
|
+
updated_at?: string;
|
|
395
|
+
updated_by?: string;
|
|
396
|
+
created_by?: string;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
export type WebhookDestination = ContentStackWebhookDestination & {
|
|
400
|
+
target_url: string;
|
|
401
|
+
http_basic_auth?: string;
|
|
402
|
+
http_basic_password?: string;
|
|
403
|
+
custom_header?: {
|
|
404
|
+
header_name?: string;
|
|
405
|
+
value?: string;
|
|
406
|
+
}[];
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
export type WebhookPayload = WebhookPayloadEntry | WebhookPayloadAsset | WebhookPayloadContentType | WebhookPayloadGlobalField;
|
|
410
|
+
|
|
411
|
+
export type WebhookPayloadBasicEvent = 'create' | 'update' | 'delete';
|
|
412
|
+
|
|
413
|
+
export type WebhookPayloadCommonProps = {
|
|
414
|
+
api_key?: string;
|
|
415
|
+
triggered_at?: string;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
export type WebhookPayloadEntry = WebhookPayloadCommonProps & {
|
|
419
|
+
module: 'entry';
|
|
420
|
+
data: {
|
|
421
|
+
content_type: {
|
|
422
|
+
uid: string;
|
|
423
|
+
};
|
|
424
|
+
branch: WebhookPayloadBranch;
|
|
425
|
+
};
|
|
426
|
+
} & (
|
|
427
|
+
| {
|
|
428
|
+
event: WebhookPayloadBasicEvent;
|
|
429
|
+
data: {
|
|
430
|
+
entry: Omit<Entry, 'content_type_uid' | 'publish_details' | '_branch'>;
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
| {
|
|
434
|
+
event: 'publish';
|
|
435
|
+
data: {
|
|
436
|
+
action: 'publish';
|
|
437
|
+
status: string;
|
|
438
|
+
locale: string;
|
|
439
|
+
environment: Environment;
|
|
440
|
+
entry: Omit<Entry, 'content_type_uid' | 'publish_details' | '_branch'> & {
|
|
441
|
+
publish_details?: Omit<PublishDetails, 'version'>;
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
| {
|
|
446
|
+
event: 'unpublish';
|
|
447
|
+
data: {
|
|
448
|
+
action: 'unpublish';
|
|
449
|
+
status: string;
|
|
450
|
+
locale: string;
|
|
451
|
+
environment: Environment;
|
|
452
|
+
entry: Omit<Entry, 'content_type_uid' | '_branch' | 'publish_details'>;
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
export type WebhookPayloadAsset = WebhookPayloadCommonProps & {
|
|
458
|
+
module: 'asset';
|
|
459
|
+
data: {
|
|
460
|
+
branch: WebhookPayloadBranch;
|
|
461
|
+
};
|
|
462
|
+
} & (
|
|
463
|
+
| {
|
|
464
|
+
event: WebhookPayloadBasicEvent;
|
|
465
|
+
data: {
|
|
466
|
+
asset: Omit<Asset, '_branch' | 'publish_details'>;
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
| {
|
|
470
|
+
event: 'publish';
|
|
471
|
+
data: {
|
|
472
|
+
// only when event is publish or unpublish
|
|
473
|
+
action: 'publish';
|
|
474
|
+
status: string;
|
|
475
|
+
locale: string;
|
|
476
|
+
environment: Environment;
|
|
477
|
+
asset: Omit<Asset, '_branch' | 'publish_details'> & {
|
|
478
|
+
publish_details?: Omit<PublishDetails, 'version'>;
|
|
479
|
+
};
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
| {
|
|
483
|
+
event: 'unpublish';
|
|
484
|
+
data: {
|
|
485
|
+
action: 'unpublish';
|
|
486
|
+
status: string;
|
|
487
|
+
locale: string;
|
|
488
|
+
environment: Environment;
|
|
489
|
+
asset: Omit<Asset, '_branch' | 'publish_details'>;
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
export type WebhookPayloadContentType = WebhookPayloadCommonProps & {
|
|
495
|
+
module: 'content_type';
|
|
496
|
+
event: WebhookPayloadBasicEvent;
|
|
497
|
+
data: {
|
|
498
|
+
uid: string;
|
|
499
|
+
title: string;
|
|
500
|
+
description: string;
|
|
501
|
+
created_at: string;
|
|
502
|
+
updated_at: string;
|
|
503
|
+
schema: unknown;
|
|
504
|
+
options: unknown;
|
|
505
|
+
branch: WebhookPayloadBranch;
|
|
506
|
+
};
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
export type WebhookPayloadGlobalField = WebhookPayloadCommonProps & {
|
|
510
|
+
module: 'global_field';
|
|
511
|
+
event: WebhookPayloadBasicEvent;
|
|
512
|
+
data: {
|
|
513
|
+
uid: string;
|
|
514
|
+
title: string;
|
|
515
|
+
description: string;
|
|
516
|
+
created_at: string;
|
|
517
|
+
updated_at: string;
|
|
518
|
+
schema: unknown;
|
|
519
|
+
branch: WebhookPayloadBranch;
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
export type WebhookPayloadBranch = {
|
|
524
|
+
uid: string;
|
|
525
|
+
source: string;
|
|
526
|
+
alias: [];
|
|
527
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createWriteStream } from 'fs';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import type { Logger } from '@stackbit/types';
|
|
4
|
+
import type { Asset, Entry, Environment, User } from './contentstack-types';
|
|
5
|
+
import type { ContentStackClient } from './contentstack-api-client';
|
|
6
|
+
|
|
7
|
+
export function getContentstackDashboardUrl({ apiKey, branch }: { apiKey: string; branch?: string }) {
|
|
8
|
+
branch = branch ? `?branch=${branch}` : '';
|
|
9
|
+
return getUrl(apiKey, `/dashboard${branch}`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getEntryUrl({ apiKey, entry }: { apiKey: string; entry: Entry }) {
|
|
13
|
+
const branch = entry._branch ? `?branch=${entry._branch}` : '';
|
|
14
|
+
return getUrl(apiKey, `/content-type/${entry.content_type_uid}/${entry.locale}/entry/${entry.uid}/edit${branch}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getAssetUrl({ apiKey, asset }: { apiKey: string; asset: Asset }) {
|
|
18
|
+
const branch = asset._branch ? `?branch=${asset._branch}` : '';
|
|
19
|
+
return getUrl(apiKey, `/assets/${asset.uid}${branch}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getUrl(apiKey: string, path: string) {
|
|
23
|
+
const baseUrl = 'https://app.contentstack.com/#!/stack/';
|
|
24
|
+
return `${baseUrl}${apiKey}${path}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function userMissingInMap(usersById: Record<string, User>, entity: Entry | Asset) {
|
|
28
|
+
return !usersById[entity.created_by] || !usersById[entity.updated_by];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function resolvePublishEnvironment({
|
|
32
|
+
environments,
|
|
33
|
+
publishEnvironmentName,
|
|
34
|
+
logger
|
|
35
|
+
}: {
|
|
36
|
+
environments: Environment[];
|
|
37
|
+
publishEnvironmentName?: string;
|
|
38
|
+
logger: Logger;
|
|
39
|
+
}): Environment {
|
|
40
|
+
if (publishEnvironmentName) {
|
|
41
|
+
const resolvedEnv = environments.find((env) => env.name === publishEnvironmentName);
|
|
42
|
+
if (resolvedEnv) {
|
|
43
|
+
return resolvedEnv;
|
|
44
|
+
}
|
|
45
|
+
logger.warn(
|
|
46
|
+
`The 'publishEnvironmentName' '${publishEnvironmentName}' provided to ContentStackSource constructor ` +
|
|
47
|
+
`does not match any environment name: [${environments.map((env) => env.name).join(', ')}]`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (environments.length === 1) {
|
|
51
|
+
const resolvedEnv = environments[0]!;
|
|
52
|
+
logger.info(`The Contentstack stack has a single '${resolvedEnv.name}' environment, using it for publishing content`);
|
|
53
|
+
return resolvedEnv;
|
|
54
|
+
}
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Stack has multiple environments: [${environments.map((env) => env.name).join(', ')}], ` +
|
|
57
|
+
`please specify one of them using the 'publishEnvironmentName' property in the ContentStackSource constructor options`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function createWebhookIfNeeded({
|
|
62
|
+
webhookUrl,
|
|
63
|
+
publishEnvironmentName,
|
|
64
|
+
branch,
|
|
65
|
+
isLocalDev,
|
|
66
|
+
contentStackClient,
|
|
67
|
+
logger
|
|
68
|
+
}: {
|
|
69
|
+
webhookUrl?: string;
|
|
70
|
+
publishEnvironmentName: string;
|
|
71
|
+
branch?: string;
|
|
72
|
+
isLocalDev: boolean;
|
|
73
|
+
contentStackClient: ContentStackClient;
|
|
74
|
+
logger: Logger;
|
|
75
|
+
}) {
|
|
76
|
+
if (!webhookUrl) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
logger.debug(`webhook URL: ${webhookUrl}`);
|
|
80
|
+
const webhooks = await contentStackClient.getWebhooks();
|
|
81
|
+
if (isLocalDev) {
|
|
82
|
+
const localDevWebhookName = 'Stackbit local-dev webhook';
|
|
83
|
+
const localDevWebhook = webhooks.find((webhook) => webhook.name === localDevWebhookName);
|
|
84
|
+
if (localDevWebhook) {
|
|
85
|
+
const hasTargetUrlToWebhookUrl = localDevWebhook.destinations.find((destination) => destination.target_url === webhookUrl);
|
|
86
|
+
const hasBranch = !branch || localDevWebhook.branches.includes(branch);
|
|
87
|
+
if (!localDevWebhook.disabled && hasBranch && hasTargetUrlToWebhookUrl) {
|
|
88
|
+
logger.debug(
|
|
89
|
+
`found enabled webhook '${localDevWebhookName}' for [${localDevWebhook.branches.join(', ')}] branch(es) and target_url '${webhookUrl}'`
|
|
90
|
+
);
|
|
91
|
+
return localDevWebhook;
|
|
92
|
+
}
|
|
93
|
+
logger.debug(
|
|
94
|
+
`found ${localDevWebhook.disabled ? 'disabled' : 'enabled'} webhook '${localDevWebhookName}' ` +
|
|
95
|
+
`for [${localDevWebhook.branches.join(', ')}] branch(es) ` +
|
|
96
|
+
`and target_url '${localDevWebhook.destinations[0]?.target_url}', resetting webhook`
|
|
97
|
+
);
|
|
98
|
+
const webhook = await contentStackClient.updateWebhook({
|
|
99
|
+
webhookId: localDevWebhook.uid,
|
|
100
|
+
webhookUrl,
|
|
101
|
+
branch
|
|
102
|
+
});
|
|
103
|
+
logger.debug(`webhook ${webhook.name} updated`);
|
|
104
|
+
} else {
|
|
105
|
+
logger.debug(`no webhook named '${localDevWebhookName}' was found, creating a webhook for branch '${branch}' and target_url '${webhookUrl}'`);
|
|
106
|
+
const webhook = await contentStackClient.createWebhook({
|
|
107
|
+
webhookName: localDevWebhookName,
|
|
108
|
+
webhookUrl,
|
|
109
|
+
publishEnvironmentName,
|
|
110
|
+
branch
|
|
111
|
+
});
|
|
112
|
+
logger.debug(`webhook ${webhook.name} created`);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
const matchedWebhook = webhooks.find((webhook) => {
|
|
116
|
+
return webhook.destinations.find((destination) => destination.target_url === webhookUrl);
|
|
117
|
+
});
|
|
118
|
+
if (matchedWebhook) {
|
|
119
|
+
const hasBranch = !branch || matchedWebhook.branches.includes(branch);
|
|
120
|
+
if (!matchedWebhook.disabled && hasBranch) {
|
|
121
|
+
logger.debug(
|
|
122
|
+
`found enabled webhook '${matchedWebhook.name}' for [${matchedWebhook.branches.join(', ')}] branch(es) and target_url '${webhookUrl}'`
|
|
123
|
+
);
|
|
124
|
+
return matchedWebhook;
|
|
125
|
+
}
|
|
126
|
+
logger.debug(
|
|
127
|
+
`found ${matchedWebhook.disabled ? 'disabled' : 'enabled'} webhook '${matchedWebhook.name}' ` +
|
|
128
|
+
`for [${matchedWebhook.branches.join(', ')}] branch(es) ` +
|
|
129
|
+
`and target_url '${matchedWebhook.destinations[0]?.target_url}', resetting webhook`
|
|
130
|
+
);
|
|
131
|
+
const webhook = await contentStackClient.updateWebhook({
|
|
132
|
+
webhookId: matchedWebhook.uid,
|
|
133
|
+
webhookUrl,
|
|
134
|
+
branch
|
|
135
|
+
});
|
|
136
|
+
logger.debug(`webhook ${webhook.name} updated`);
|
|
137
|
+
} else {
|
|
138
|
+
logger.debug(`no webhook matching the provided webhookUrl was found, creating a webhook for branch '${branch}' and target_url '${webhookUrl}'`);
|
|
139
|
+
const webhook = await contentStackClient.createWebhook({
|
|
140
|
+
webhookName: 'Stackbit webhook',
|
|
141
|
+
webhookUrl,
|
|
142
|
+
publishEnvironmentName,
|
|
143
|
+
branch
|
|
144
|
+
});
|
|
145
|
+
logger.debug(`webhook ${webhook.name} created`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function downloadFile(fileUrl: string, outputLocationPath: string) {
|
|
151
|
+
const writer = createWriteStream(outputLocationPath);
|
|
152
|
+
const response = await axios({
|
|
153
|
+
method: 'get',
|
|
154
|
+
url: fileUrl,
|
|
155
|
+
responseType: 'stream'
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
response.data.pipe(writer);
|
|
159
|
+
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
let error: Error | null = null;
|
|
162
|
+
writer.on('error', (err) => {
|
|
163
|
+
error = err;
|
|
164
|
+
writer.close();
|
|
165
|
+
reject(err);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
writer.on('close', () => {
|
|
169
|
+
if (!error) {
|
|
170
|
+
resolve(true);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
package/src/index.ts
ADDED