-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtypes.ts
More file actions
372 lines (342 loc) · 7.84 KB
/
types.ts
File metadata and controls
372 lines (342 loc) · 7.84 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/* eslint-disable @cspell/spellchecker */
import { HttpClientParams } from "@contentstack/core";
import { PersistanceStoreOptions, StorageType } from "../persistance";
import { AxiosRequestConfig, AxiosResponse } from "axios";
// Internal Types
export type params = {
[key: string]: any;
};
export type queryParams = {
[key: string]: string | boolean | number | string[];
};
/**
* Interface for creating Contentstack plugins
*
* @example
* ```typescript
* import { ContentstackPlugin } from '@contentstack/delivery-sdk';
*
* class MyPlugin implements ContentstackPlugin {
* onRequest(config: any): any {
* // Modify request configuration
* console.log('Processing request:', config.url);
* return { ...config, headers: { ...config.headers, 'X-Custom-Header': 'value' } };
* }
*
* onResponse(request: any, response: any, data: any): any {
* // Process response data
* console.log('Processing response:', response.status);
* return { ...response, data: { ...data, processed: true } };
* }
* }
*
* const stack = contentstack.stack({
* apiKey: 'your-api-key',
* deliveryToken: 'your-delivery-token',
* environment: 'your-environment',
* plugins: [new MyPlugin()]
* });
* ```
*/
export interface ContentstackPlugin {
/**
* Called before each request is sent
* @param config - Axios request configuration object (with possible custom properties)
* @returns Modified request configuration (can be sync or async)
*/
onRequest(config: any): any;
/**
* Called after each response is received
* @param request - The original request configuration
* @param response - Axios response object (with possible custom properties)
* @param data - Response data
* @returns Modified response object (can be sync or async)
*/
onResponse(request: any, response: any, data: any): any;
}
// External Types
export enum Region {
US = "us",
EU = "eu",
AU = "au",
AZURE_NA = "azure-na",
AZURE_EU = "azure-eu",
GCP_NA = "gcp-na",
GCP_EU = "gcp-eu",
}
export interface StackConfig extends HttpClientParams {
host?: string;
apiKey: string;
deliveryToken: string;
environment: string;
branch?: string;
early_access?: string[];
region?: Region;
locale?: string;
plugins?: ContentstackPlugin[];
logHandler?: (level: string, data: any) => void;
cacheOptions?: CacheOptions;
live_preview?: LivePreview;
port?: number;
debug?: boolean;
}
export interface CacheOptions extends PersistanceStoreOptions {
policy: Policy;
storeType?: StorageType;
}
export enum Policy {
IGNORE_CACHE = "IGNORE_CACHE",
CACHE_THEN_NETWORK = "CACHE_THEN_NETWORK",
CACHE_ELSE_NETWORK = "CACHE_ELSE_NETWORK",
NETWORK_ELSE_CACHE = "NETWORK_ELSE_CACHE",
}
export interface SyncStack {
paginationToken?: string;
syncToken?: string;
}
export enum PublishType {
ENTRY_PUBLISHED = "entry_published",
ENTRY_UNPUBLISHED = "entry_unpublished",
ENTRY_DELETED = "entry_deleted",
ASSET_PUBLISHED = "asset_published",
ASSET_UNPUBLISHED = "asset_unpublished",
ASSET_DELETED = "asset_deleted",
CONTENT_TYPE_DELETED = "content_type_deleted",
}
export interface SyncType {
environment?: string;
contentTypeUid?: string;
type?: PublishType[] | PublishType | string;
locale?: string;
startDate?: string;
}
export type TransformData = { [key: string]: string | string[] };
export enum Format {
GIF = "gif",
PNG = "png",
JPG = "jpg",
PJPG = "pjpg",
WEBP = "webp",
WEBPLL = "webpll",
WEBPLY = "webply",
}
export enum CropBy {
DEFAULT = "default",
ASPECTRATIO = "aspectRatio",
REGION = "region",
OFFSET = "offset",
}
export enum FitBy {
BOUNDS = "bounds",
CROP = "crop",
}
export enum Orientation {
DEFAULT = 1,
FLIP_HORIZONTAL = 2,
FLIP_HORIZONTAL_VERTICAL = 3,
FLIP_VERTICAL = 4,
FLIP_HORIZONTAL_LEFT = 5,
RIGHT = 6,
FLIP_HORIZONTAL_RIGHT = 7,
LEFT = 8,
}
export enum OverlayAlign {
TOP = "top",
BOTTOM = "bottom",
LEFT = "left",
RIGHT = "right",
MIDDLE = "middle",
CENTER = "center",
}
export enum OverlayRepeat {
X = "x",
Y = "y",
BOTH = "both",
}
export enum ResizeFilter {
NEAREST = "nearest",
BILINEAR = "bilinear",
BICUBIC = "bicubic",
LANCZOS2 = "lanczos2",
LANCZOS3 = "lanczos3",
}
export enum CanvasBy {
DEFAULT = "default",
ASPECTRATIO = "aspectRatio",
REGION = "region",
OFFSET = "offset",
}
export enum QueryOperation {
EQUALS = "",
NOT_EQUALS = "$ne",
INCLUDES = "$in",
EXCLUDES = "$nin",
IS_LESS_THAN = "$lt",
IS_LESS_THAN_OR_EQUAL = "$lte",
IS_GREATER_THAN = "$gt",
IS_GREATER_THAN_OR_EQUAL = "$gte",
EXISTS = "$exists",
MATCHES = "$regex",
}
export enum TaxonomyQueryOperation {
ABOVE = "$above",
BELOW = "$below",
EQ_ABOVE = "$eq_above",
EQ_BELOW = "$eq_below",
}
export type BaseQueryParameters = {
[key: string]:
| string
| string[]
| { [key in QueryOperation]?: string | string[] }
| { [key: string]: BaseQueryParameters | any };
};
export enum QueryOperator {
AND = "$and",
OR = "$or",
}
export type PaginationObj = {
skip?: number;
limit?: number;
};
interface ACL {
roles?: Record<string, never>;
others?: {
read?: boolean;
create?: boolean;
update?: boolean;
delete?: boolean;
sub_acl?: {
read?: boolean;
create?: boolean;
update?: boolean;
delete?: boolean;
publish?: boolean;
};
};
}
export interface PublishDetails {
environment: string;
locale: string;
time: string;
user: string;
}
export interface BaseEntry {
_version: number;
locale: string;
uid: string;
ACL: Record<string, never> | ACL;
_in_progress: boolean;
created_at: string;
created_by: string;
tags: string[];
title: string;
updated_at: string;
updated_by: string;
publish_details: PublishDetails;
}
export interface ReferenceResponse {
uid: string;
_content_type_uid: string;
}
export interface BaseAsset {
uid: string;
created_at: string;
updated_at: string;
created_by: string;
updated_by: string;
content_type: string;
file_size: string;
tags: [];
filename: string;
url: string;
ACL: ACL;
is_dir: boolean;
parent_uid: null | string;
_version: number;
title: string;
publish_details?: PublishDetails;
}
export interface BaseContentType {
title: string;
uid: string;
options: {
is_page: false;
singleton: false;
title: string;
sub_title: [];
};
DEFAULT_ACL: ACL;
SYS_ACL: ACL;
created_at: string;
updated_at: string;
inbuilt_class: false;
description: string;
abilities: {
get_one_object: true;
get_all_objects: true;
create_object: true;
update_object: true;
delete_object: true;
delete_all_objects: true;
};
last_activity: any;
maintain_revisions: boolean;
_version: number;
schema: any;
}
export interface FindResponse<T> {
entries?: T[];
content_types?: T[];
assets?: T[];
global_fields?: T[];
count?: number;
taxonomies?: T[];
terms?: T[];
}
export interface LivePreviewQuery {
live_preview: string;
include_applied_variants?: boolean;
contentTypeUid?: string;
content_type_uid?: string;
entry_uid?: string;
entryUid?: any;
preview_timestamp?: string;
release_id?: string;
}
export type LivePreview = {
live_preview?: string;
include_applied_variants?: boolean;
contentTypeUid?: string;
entryUid?: any;
host?: string;
enable: boolean;
management_token?: string;
preview_token?: string;
};
export interface BaseTaxonomy {
uid: string;
name: string;
description?: string;
terms_count?: number;
created_at: string;
updated_at: string;
created_by: string;
updated_by: string;
type: string;
ACL: ACL;
publish_details?: PublishDetails;
}
export interface BaseTerm {
taxonomy_uid: string;
uid: string;
name: string;
created_by: string;
created_at: string;
updated_by: string;
updated_at: string;
children_count?: number;
depth?: number;
ACL: ACL;
publish_details?: PublishDetails;
}