@contentstack/cli-variants 0.0.1-alpha

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.
Files changed (124) hide show
  1. package/lib/export/attributes.d.ts +15 -0
  2. package/lib/export/attributes.js +62 -0
  3. package/lib/export/audiences.d.ts +15 -0
  4. package/lib/export/audiences.js +63 -0
  5. package/lib/export/events.d.ts +15 -0
  6. package/lib/export/events.js +63 -0
  7. package/lib/export/experiences.d.ts +9 -0
  8. package/lib/export/experiences.js +99 -0
  9. package/lib/export/index.d.ts +9 -0
  10. package/lib/export/index.js +21 -0
  11. package/lib/export/projects.d.ts +9 -0
  12. package/lib/export/projects.js +73 -0
  13. package/lib/export/variant-entries.d.ts +18 -0
  14. package/lib/export/variant-entries.js +109 -0
  15. package/lib/import/attribute.d.ts +17 -0
  16. package/lib/import/attribute.js +64 -0
  17. package/lib/import/audiences.d.ts +19 -0
  18. package/lib/import/audiences.js +71 -0
  19. package/lib/import/events.d.ts +17 -0
  20. package/lib/import/events.js +62 -0
  21. package/lib/import/experiences.d.ts +46 -0
  22. package/lib/import/experiences.js +214 -0
  23. package/lib/import/index.d.ts +14 -0
  24. package/lib/import/index.js +21 -0
  25. package/lib/import/project.d.ts +13 -0
  26. package/lib/import/project.js +74 -0
  27. package/lib/import/variant-entries.d.ts +98 -0
  28. package/lib/import/variant-entries.js +407 -0
  29. package/lib/index.d.ts +5 -0
  30. package/lib/index.js +21 -0
  31. package/lib/messages/index.d.ts +35 -0
  32. package/lib/messages/index.js +55 -0
  33. package/lib/types/adapter-helper.d.ts +8 -0
  34. package/lib/types/adapter-helper.js +2 -0
  35. package/lib/types/content-types.d.ts +19 -0
  36. package/lib/types/content-types.js +2 -0
  37. package/lib/types/export-config.d.ts +264 -0
  38. package/lib/types/export-config.js +2 -0
  39. package/lib/types/import-config.d.ts +92 -0
  40. package/lib/types/import-config.js +2 -0
  41. package/lib/types/index.d.ts +8 -0
  42. package/lib/types/index.js +24 -0
  43. package/lib/types/personalization-api-adapter.d.ts +152 -0
  44. package/lib/types/personalization-api-adapter.js +2 -0
  45. package/lib/types/utils.d.ts +7 -0
  46. package/lib/types/utils.js +2 -0
  47. package/lib/types/variant-api-adapter.d.ts +49 -0
  48. package/lib/types/variant-api-adapter.js +2 -0
  49. package/lib/types/variant-entry.d.ts +47 -0
  50. package/lib/types/variant-entry.js +2 -0
  51. package/lib/utils/adapter-helper.d.ts +30 -0
  52. package/lib/utils/adapter-helper.js +95 -0
  53. package/lib/utils/attributes-helper.d.ts +7 -0
  54. package/lib/utils/attributes-helper.js +37 -0
  55. package/lib/utils/audiences-helper.d.ts +8 -0
  56. package/lib/utils/audiences-helper.js +49 -0
  57. package/lib/utils/error-helper.d.ts +6 -0
  58. package/lib/utils/error-helper.js +27 -0
  59. package/lib/utils/events-helper.d.ts +8 -0
  60. package/lib/utils/events-helper.js +27 -0
  61. package/lib/utils/helper.d.ts +4 -0
  62. package/lib/utils/helper.js +51 -0
  63. package/lib/utils/index.d.ts +9 -0
  64. package/lib/utils/index.js +25 -0
  65. package/lib/utils/logger.d.ts +3 -0
  66. package/lib/utils/logger.js +175 -0
  67. package/lib/utils/personalization-api-adapter.d.ts +73 -0
  68. package/lib/utils/personalization-api-adapter.js +184 -0
  69. package/lib/utils/variant-api-adapter.d.ts +79 -0
  70. package/lib/utils/variant-api-adapter.js +263 -0
  71. package/package.json +38 -0
  72. package/src/export/attributes.ts +55 -0
  73. package/src/export/audiences.ts +57 -0
  74. package/src/export/events.ts +57 -0
  75. package/src/export/experiences.ts +80 -0
  76. package/src/export/index.ts +11 -0
  77. package/src/export/projects.ts +45 -0
  78. package/src/export/variant-entries.ts +88 -0
  79. package/src/import/attribute.ts +60 -0
  80. package/src/import/audiences.ts +69 -0
  81. package/src/import/events.ts +58 -0
  82. package/src/import/experiences.ts +224 -0
  83. package/src/import/index.ts +16 -0
  84. package/src/import/project.ts +71 -0
  85. package/src/import/variant-entries.ts +483 -0
  86. package/src/index.ts +5 -0
  87. package/src/messages/index.ts +63 -0
  88. package/src/types/adapter-helper.ts +10 -0
  89. package/src/types/content-types.ts +41 -0
  90. package/src/types/export-config.ts +292 -0
  91. package/src/types/import-config.ts +95 -0
  92. package/src/types/index.ts +8 -0
  93. package/src/types/personalization-api-adapter.ts +197 -0
  94. package/src/types/utils.ts +8 -0
  95. package/src/types/variant-api-adapter.ts +56 -0
  96. package/src/types/variant-entry.ts +61 -0
  97. package/src/utils/adapter-helper.ts +79 -0
  98. package/src/utils/attributes-helper.ts +31 -0
  99. package/src/utils/audiences-helper.ts +50 -0
  100. package/src/utils/error-helper.ts +26 -0
  101. package/src/utils/events-helper.ts +26 -0
  102. package/src/utils/helper.ts +34 -0
  103. package/src/utils/index.ts +9 -0
  104. package/src/utils/logger.ts +160 -0
  105. package/src/utils/personalization-api-adapter.ts +188 -0
  106. package/src/utils/variant-api-adapter.ts +326 -0
  107. package/test/unit/export/variant-entries.test.ts +80 -0
  108. package/test/unit/import/variant-entries.test.ts +200 -0
  109. package/test/unit/mock/contents/content_types/CT-1.json +7 -0
  110. package/test/unit/mock/contents/entries/CT-1/en-us/variants/E-1/9b0da6xd7et72y-6gv7he23.json +12 -0
  111. package/test/unit/mock/contents/entries/CT-1/en-us/variants/E-1/index.json +3 -0
  112. package/test/unit/mock/contents/entries/CT-1/en-us/variants/E-2/9b0da6xd7et72y-6gv7he23.json +12 -0
  113. package/test/unit/mock/contents/entries/CT-1/en-us/variants/E-2/index.json +3 -0
  114. package/test/unit/mock/contents/mapper/assets/uid-mapping.json +6 -0
  115. package/test/unit/mock/contents/mapper/assets/url-mapping.json +6 -0
  116. package/test/unit/mock/contents/mapper/entries/data-for-variant-entry.json +6 -0
  117. package/test/unit/mock/contents/mapper/entries/empty-data/data-for-variant-entry.json +1 -0
  118. package/test/unit/mock/contents/mapper/entries/uid-mapping.json +6 -0
  119. package/test/unit/mock/contents/mapper/marketplace_apps/uid-mapping.json +3 -0
  120. package/test/unit/mock/contents/mapper/personalization/experiences/variants-uid-mapping.json +5 -0
  121. package/test/unit/mock/contents/mapper/taxonomies/terms/success.json +1 -0
  122. package/test/unit/mock/export-config.json +48 -0
  123. package/test/unit/mock/import-config.json +63 -0
  124. package/tsconfig.json +19 -0
@@ -0,0 +1,292 @@
1
+ /**
2
+ * NOTE: Accessing ExportConfig from the export package is not possible
3
+ * because it will create a circular dependency and cause the prepack/build command to fail.
4
+ * Therefore, we are duplicating the following types from the export.
5
+ */
6
+ import { AnyProperty } from './utils';
7
+
8
+ export type Modules =
9
+ | 'stack'
10
+ | 'assets'
11
+ | 'locales'
12
+ | 'environments'
13
+ | 'extensions'
14
+ | 'webhooks'
15
+ | 'global-fields'
16
+ | 'entries'
17
+ | 'content-types'
18
+ | 'custom-roles'
19
+ | 'workflows'
20
+ | 'labels'
21
+ | 'marketplace-apps'
22
+ | 'taxonomies'
23
+ | 'personalization';
24
+
25
+ export type branch = {
26
+ uid: string;
27
+ source: string;
28
+ };
29
+
30
+ export type masterLocale = {
31
+ code: string;
32
+ };
33
+
34
+ export interface DefaultConfig {
35
+ contentVersion: number;
36
+ versioning: boolean;
37
+ host: string;
38
+ cdn?: string;
39
+ developerHubUrls: any;
40
+ modules: {
41
+ types: Modules[];
42
+ locales: {
43
+ dirName: string;
44
+ fileName: string;
45
+ requiredKeys: string[];
46
+ dependencies?: Modules[];
47
+ };
48
+ customRoles: {
49
+ dirName: string;
50
+ fileName: string;
51
+ customRolesLocalesFileName: string;
52
+ dependencies?: Modules[];
53
+ };
54
+ 'custom-roles': {
55
+ dirName: string;
56
+ fileName: string;
57
+ customRolesLocalesFileName: string;
58
+ dependencies?: Modules[];
59
+ };
60
+ environments: {
61
+ dirName: string;
62
+ fileName: string;
63
+ dependencies?: Modules[];
64
+ };
65
+ labels: {
66
+ dirName: string;
67
+ fileName: string;
68
+ invalidKeys: string[];
69
+ dependencies?: Modules[];
70
+ };
71
+ webhooks: {
72
+ dirName: string;
73
+ fileName: string;
74
+ dependencies?: Modules[];
75
+ };
76
+ releases: {
77
+ dirName: string;
78
+ fileName: string;
79
+ releasesList: string;
80
+ invalidKeys: string[];
81
+ dependencies?: Modules[];
82
+ };
83
+ workflows: {
84
+ dirName: string;
85
+ fileName: string;
86
+ invalidKeys: string[];
87
+ dependencies?: Modules[];
88
+ };
89
+ globalfields: {
90
+ dirName: string;
91
+ fileName: string;
92
+ validKeys: string[];
93
+ dependencies?: Modules[];
94
+ };
95
+ 'global-fields': {
96
+ dirName: string;
97
+ fileName: string;
98
+ validKeys: string[];
99
+ dependencies?: Modules[];
100
+ };
101
+ assets: {
102
+ dirName: string;
103
+ fileName: string;
104
+ // This is the total no. of asset objects fetched in each 'get assets' call
105
+ batchLimit: number;
106
+ host: string;
107
+ invalidKeys: string[];
108
+ // no of asset version files (of a single asset) that'll be downloaded parallel
109
+ chunkFileSize: number; // measured on Megabits (5mb)
110
+ downloadLimit: number;
111
+ fetchConcurrency: number;
112
+ assetsMetaKeys: string[]; // Default keys ['uid', 'url', 'filename']
113
+ securedAssets: boolean;
114
+ displayExecutionTime: boolean;
115
+ enableDownloadStatus: boolean;
116
+ includeVersionedAssets: boolean;
117
+ dependencies?: Modules[];
118
+ };
119
+ content_types: {
120
+ dirName: string;
121
+ fileName: string;
122
+ validKeys: string[];
123
+ // total no of content types fetched in each 'get content types' call
124
+ limit: number;
125
+ dependencies?: Modules[];
126
+ };
127
+ 'content-types': {
128
+ dirName: string;
129
+ fileName: string;
130
+ validKeys: string[];
131
+ // total no of content types fetched in each 'get content types' call
132
+ limit: number;
133
+ dependencies?: Modules[];
134
+ };
135
+ entries: {
136
+ dirName: string;
137
+ fileName: string;
138
+ invalidKeys: string[];
139
+ batchLimit: number;
140
+ downloadLimit: number;
141
+ // total no of entries fetched in each content type in a single call
142
+ limit: number;
143
+ dependencies?: Modules[];
144
+ exportVersions: boolean;
145
+ };
146
+ variantEntry: {
147
+ dirName: string;
148
+ fileName: string;
149
+ chunkFileSize: number;
150
+ query: {
151
+ skip: number;
152
+ limit: number;
153
+ include_variant: boolean;
154
+ include_count: boolean;
155
+ include_publish_details: boolean;
156
+ } & AnyProperty;
157
+ } & AnyProperty;
158
+ personalization: {
159
+ dirName: string;
160
+ baseURL: Record<string, string>;
161
+ } & AnyProperty;
162
+ extensions: {
163
+ dirName: string;
164
+ fileName: string;
165
+ dependencies?: Modules[];
166
+ };
167
+ stack: {
168
+ dirName: string;
169
+ fileName: string;
170
+ dependencies?: Modules[];
171
+ };
172
+ dependency: {
173
+ entries: string[];
174
+ };
175
+ marketplace_apps: {
176
+ dirName: string;
177
+ fileName: string;
178
+ dependencies?: Modules[];
179
+ };
180
+ 'marketplace-apps': {
181
+ dirName: string;
182
+ fileName: string;
183
+ dependencies?: Modules[];
184
+ };
185
+ masterLocale: {
186
+ dirName: string;
187
+ fileName: string;
188
+ requiredKeys: string[];
189
+ };
190
+ taxonomies: {
191
+ dirName: string;
192
+ fileName: string;
193
+ invalidKeys: string[];
194
+ dependencies?: Modules[];
195
+ };
196
+ events: {
197
+ dirName: string;
198
+ fileName: string;
199
+ invalidKeys: string[];
200
+ dependencies?: Modules[];
201
+ };
202
+ audiences: {
203
+ dirName: string;
204
+ fileName: string;
205
+ invalidKeys: string[];
206
+ dependencies?: Modules[];
207
+ };
208
+ attributes: {
209
+ dirName: string;
210
+ fileName: string;
211
+ invalidKeys: string[];
212
+ dependencies?: Modules[];
213
+ };
214
+ };
215
+ languagesCode: string[];
216
+ apis: {
217
+ userSession: string;
218
+ globalfields: string;
219
+ locales: string;
220
+ labels: string;
221
+ environments: string;
222
+ assets: string;
223
+ content_types: string;
224
+ entries: string;
225
+ users: string;
226
+ extension: string;
227
+ webhooks: string;
228
+ stacks: string;
229
+ };
230
+ preserveStackVersion: boolean;
231
+ fetchConcurrency: number;
232
+ writeConcurrency: number;
233
+ developerHubBaseUrl: string;
234
+ marketplaceAppEncryptionKey: string;
235
+ onlyTSModules: string[];
236
+ }
237
+
238
+ export interface ExportConfig extends DefaultConfig {
239
+ exportDir: string;
240
+ data: string;
241
+ management_token?: string;
242
+ apiKey: string;
243
+ forceStopMarketplaceAppsPrompt: boolean;
244
+ auth_token?: string;
245
+ branchName?: string;
246
+ securedAssets?: boolean;
247
+ contentTypes?: string[];
248
+ branches?: branch[];
249
+ branchEnabled?: boolean;
250
+ branchDir?: string;
251
+ singleModuleExport?: boolean;
252
+ moduleName?: Modules;
253
+ master_locale: masterLocale;
254
+ headers?: {
255
+ api_key?: string;
256
+ access_token?: string;
257
+ authtoken?: string;
258
+ 'X-User-Agent': string;
259
+ organization_uid?: string;
260
+ 'X-Project-Uid'?: string;
261
+ };
262
+ project_id?: string; // To fetch events, audiences & attributes
263
+ access_token?: string;
264
+ org_uid?: string;
265
+ source_stack?: string;
266
+ sourceStackName?: string;
267
+ personalizationEnabled: boolean;
268
+ personalizationHost?: string;
269
+ region: any;
270
+ }
271
+
272
+ export interface PersonalizationConfig {
273
+ dirName: string;
274
+ baseURL: Record<string, string>;
275
+ }
276
+ export interface EventsConfig {
277
+ dirName: string;
278
+ fileName: string;
279
+ invalidKeys: string[];
280
+ }
281
+
282
+ export interface AudiencesConfig {
283
+ dirName: string;
284
+ fileName: string;
285
+ invalidKeys: string[];
286
+ }
287
+
288
+ export interface AttributesConfig {
289
+ dirName: string;
290
+ fileName: string;
291
+ invalidKeys: string[];
292
+ }
@@ -0,0 +1,95 @@
1
+ import { AnyProperty } from './utils';
2
+
3
+ export interface ImportDefaultConfig extends AnyProperty {
4
+ modules: {
5
+ 'content-types': {
6
+ dirName: string;
7
+ fileName: string;
8
+ validKeys: string[];
9
+ limit: number;
10
+ };
11
+ entries: {
12
+ dirName: string;
13
+ fileName: string;
14
+ };
15
+ personalization: {
16
+ baseURL: Record<string, string>;
17
+ dirName: string;
18
+ importData: boolean;
19
+ importOrder: string[];
20
+ project_id?: string;
21
+ projects: {
22
+ dirName: string;
23
+ fileName: string;
24
+ };
25
+ attributes: {
26
+ dirName: string;
27
+ fileName: string;
28
+ };
29
+ audiences: {
30
+ dirName: string;
31
+ fileName: string;
32
+ };
33
+ events: {
34
+ dirName: string;
35
+ fileName: string;
36
+ };
37
+ experiences: {
38
+ dirName: string;
39
+ fileName: string;
40
+ thresholdTimer: number;
41
+ checkIntervalDuration: number;
42
+ };
43
+ };
44
+ variantEntry: {
45
+ dirName: string;
46
+ fileName: string;
47
+ apiConcurrency: number;
48
+ query: {
49
+ locale: string;
50
+ } & AnyProperty;
51
+ } & AnyProperty;
52
+ } & AnyProperty;
53
+ }
54
+
55
+ export interface ImportConfig extends ImportDefaultConfig, AnyProperty {
56
+ contentDir: string;
57
+ data: string;
58
+ management_token?: string;
59
+ apiKey: string;
60
+ auth_token?: string;
61
+ branchName?: string;
62
+ branches?: branch[];
63
+ branchEnabled?: boolean;
64
+ branchDir?: string;
65
+ master_locale: masterLocale;
66
+ headers?: {
67
+ api_key: string;
68
+ access_token?: string;
69
+ authtoken?: string;
70
+ 'X-User-Agent': string;
71
+ 'X-Project-Uid'?: string;
72
+ };
73
+ access_token?: string;
74
+ isAuthenticated?: boolean;
75
+ target_stack?: string;
76
+ singleModuleImport?: boolean;
77
+ masterLocale: masterLocale;
78
+ backupDir: string;
79
+ authtoken?: string;
80
+ destinationStackName?: string;
81
+ org_uid?: string;
82
+ contentVersion: number;
83
+ replaceExisting?: boolean;
84
+ skipExisting?: boolean;
85
+ stackName?: string;
86
+ }
87
+
88
+ type branch = {
89
+ uid: string;
90
+ source: string;
91
+ };
92
+
93
+ type masterLocale = {
94
+ code: string;
95
+ };
@@ -0,0 +1,8 @@
1
+ export * from './utils'
2
+ export * from './export-config'
3
+ export * from './import-config'
4
+ export * from './variant-entry'
5
+ export * from './content-types'
6
+ export * from './adapter-helper'
7
+ export * from './variant-api-adapter';
8
+ export * from './personalization-api-adapter'
@@ -0,0 +1,197 @@
1
+ import { HttpClient } from '@contentstack/cli-utilities';
2
+
3
+ import { AnyProperty } from './utils';
4
+ import { AdapterHelperInterface } from './adapter-helper';
5
+
6
+ export type ProjectStruct = {
7
+ _id: string;
8
+ uid: string;
9
+ name: string;
10
+ description: string;
11
+ audienceCount: number;
12
+ organizationUid: string;
13
+ activeExperienceCount: number;
14
+ } & AnyProperty;
15
+
16
+ export type GetProjectsParams = {
17
+ connectedStackApiKey: string;
18
+ includeAudienceCount?: boolean;
19
+ includeActiveExperienceCount?: boolean;
20
+ callback?: (value: ProjectStruct[]) => void;
21
+ } & AnyProperty;
22
+
23
+ export interface CreateProjectInput {
24
+ name: string;
25
+ description: string;
26
+ connectedStackApiKey?: string;
27
+ }
28
+
29
+ export type GetVariantGroupInput = {
30
+ experienceUid: string;
31
+ };
32
+
33
+ export type VariantGroup = {
34
+ uid: string;
35
+ name: string;
36
+ content_types: string[];
37
+ description: string;
38
+ } & AnyProperty;
39
+
40
+ export type VariantGroupStruct = {
41
+ variant_groups: Array<VariantGroup>;
42
+ } & AnyProperty;
43
+
44
+ export type EventStruct = {
45
+ _id: string;
46
+ uid: string;
47
+ key: string;
48
+ name: string;
49
+ description: string;
50
+ project: string;
51
+ } & AnyProperty;
52
+
53
+ export type AudienceStruct = {
54
+ _id: string;
55
+ uid: string;
56
+ definition: {
57
+ _type: string;
58
+ combinationType: string;
59
+ rules: Record<string, any>[];
60
+ };
61
+ name: string;
62
+ description: string;
63
+ project: string;
64
+ } & AnyProperty;
65
+
66
+ export type AttributeStruct = {
67
+ _id: string;
68
+ uid: string;
69
+ key: string;
70
+ name: string;
71
+ project: string;
72
+ description: string;
73
+ } & AnyProperty;
74
+
75
+ export interface CreateAttributeInput {
76
+ name: string;
77
+ key: string;
78
+ description: string;
79
+ }
80
+
81
+ export interface CreateEventInput {
82
+ key: string;
83
+ description: string;
84
+ }
85
+
86
+ export interface CreateAudienceInput {
87
+ name: string;
88
+ definition: object;
89
+ description: string;
90
+ }
91
+
92
+ type ExpVariations = {
93
+ name: string;
94
+ __type: string;
95
+ audiences?: string[];
96
+ audienceCombinationType?: string;
97
+ shortUid?: string;
98
+ trafficDistribution?: string;
99
+ } & AnyProperty;
100
+
101
+ type ExpTargeting = {
102
+ audience?: {
103
+ audiences?: string[];
104
+ audienceCombinationType?: string;
105
+ } & AnyProperty;
106
+ };
107
+
108
+ export type ExpMetric = {
109
+ event: string;
110
+ name: string;
111
+ __type: string;
112
+ } & AnyProperty;
113
+
114
+ export type ExperienceStruct = {
115
+ _id: string;
116
+ uid: string;
117
+ name: string;
118
+ __type: string;
119
+ description: string;
120
+ targeting?: ExpTargeting;
121
+ variations: ExpVariations[];
122
+ variationSplit?: string;
123
+ metrics?: ExpMetric[];
124
+ status: string;
125
+ metadata?: object;
126
+ _cms?: {
127
+ variantGroup: object;
128
+ variants: Record<string, string>;
129
+ };
130
+ content_types?: string[];
131
+ } & AnyProperty;
132
+
133
+ export interface CreateExperienceInput {
134
+ name: string;
135
+ __type: string;
136
+ description: string;
137
+ targeting?: ExpTargeting;
138
+ variations: ExpVariations[];
139
+ variationSplit?: string;
140
+ metrics?: ExpMetric[];
141
+ status: string;
142
+ metadata?: object;
143
+ }
144
+
145
+ export interface UpdateExperienceInput {
146
+ contentTypes: string[];
147
+ }
148
+
149
+ export interface CMSExperienceStruct {
150
+ uid: string;
151
+ contentTypes: string[];
152
+ content_types?: string[];
153
+ }
154
+
155
+ export type VariantAPIRes =
156
+ | ProjectStruct[]
157
+ | ProjectStruct
158
+ | AttributeStruct[]
159
+ | AttributeStruct
160
+ | ExperienceStruct[]
161
+ | EventStruct[]
162
+ | AudienceStruct[]
163
+ | ExperienceStruct
164
+ | EventStruct
165
+ | AudienceStruct
166
+ | CMSExperienceStruct
167
+ | VariantGroupStruct
168
+ | Error;
169
+
170
+ export interface APIResponse {
171
+ status: number;
172
+ data: any;
173
+ }
174
+
175
+ export interface Personalization<T> extends AdapterHelperInterface<T, HttpClient> {
176
+ projects(options: GetProjectsParams): Promise<ProjectStruct[] | void>;
177
+
178
+ createProject(project: CreateProjectInput): Promise<ProjectStruct | void>;
179
+
180
+ getEvents(): Promise<EventStruct[] | void>;
181
+
182
+ getAudiences(): Promise<AudienceStruct[] | void>;
183
+
184
+ getAttributes(): Promise<AttributeStruct[] | void>;
185
+
186
+ createAttribute(attribute: CreateAttributeInput): Promise<AttributeStruct | void>;
187
+
188
+ createAudience(attribute: CreateAudienceInput): Promise<AudienceStruct | void>;
189
+
190
+ createExperience(experience: CreateExperienceInput): Promise<ExperienceStruct | void>;
191
+
192
+ getCTsFromExperience(experienceUid: string): Promise<CMSExperienceStruct | void>;
193
+
194
+ updateCTsInExperience(experience: UpdateExperienceInput, experienceUid: string): Promise<CMSExperienceStruct | void>;
195
+
196
+ handleVariantAPIRes(res: any): VariantAPIRes;
197
+ }
@@ -0,0 +1,8 @@
1
+ export interface AnyProperty {
2
+ [propName: string]: any;
3
+ }
4
+
5
+ export interface LogType {
6
+ (message: any): void;
7
+ (config: any, message: any, type: 'info' | 'error' | 'success'): void;
8
+ }
@@ -0,0 +1,56 @@
1
+ import { HttpClientOptions, HttpRequestConfig, HttpResponse } from '@contentstack/cli-utilities';
2
+
3
+ import { APIResponse } from '../types';
4
+ import { AnyProperty } from './utils';
5
+ import { ExportConfig } from './export-config';
6
+ import { AdapterHelperInterface } from './adapter-helper';
7
+ import { CreateVariantEntryDto, CreateVariantEntryOptions, VariantEntryStruct } from './variant-entry';
8
+
9
+ export type APIConfig = HttpRequestConfig & {
10
+ httpClient?: boolean;
11
+ sharedConfig?: ExportConfig | Record<string, any> | undefined;
12
+ personalizationURL?: string;
13
+ config: ExportConfig | Record<string, any> | undefined;
14
+ baseURL?: string;
15
+ cmaConfig?: HttpRequestConfig;
16
+ };
17
+
18
+ export interface AdapterConstructor<T, C> {
19
+ new (config: C, options?: HttpClientOptions): T;
20
+ }
21
+
22
+ export type AdapterType<T, C> = {
23
+ Adapter: AdapterConstructor<T, C>;
24
+ };
25
+
26
+ export type VariantsOption = {
27
+ skip?: number;
28
+ limit?: number;
29
+ locale?: string;
30
+ entry_uid: string;
31
+ getAllData?: boolean;
32
+ returnResult?: boolean;
33
+ content_type_uid: string;
34
+ include_variant?: boolean;
35
+ include_count?: boolean;
36
+ include_publish_details?: boolean;
37
+ callback?: (value: Record<string, any>[]) => void;
38
+ } & AnyProperty;
39
+
40
+ export type VariantOptions = VariantsOption & {
41
+ variant_uid: string;
42
+ };
43
+
44
+ export interface VariantInterface<T, ApiClient> extends AdapterHelperInterface<T, ApiClient> {
45
+ variantEntry(options: VariantOptions): Promise<{ entry: Record<string, any> }>;
46
+
47
+ variantEntries(options: VariantsOption): Promise<{ entries?: Record<string, any>[] | unknown[] } | void>;
48
+
49
+ createVariantEntry(
50
+ input: CreateVariantEntryDto,
51
+ options: CreateVariantEntryOptions,
52
+ apiParams: Record<string, any>,
53
+ ): Promise<VariantEntryStruct | string | void>;
54
+
55
+ handleVariantAPIRes(res: APIResponse): VariantEntryStruct | { entries: VariantEntryStruct[]; count: number } | string;
56
+ }
@@ -0,0 +1,61 @@
1
+ import { AnyProperty } from './utils';
2
+
3
+ export type VariantEntryStruct = {
4
+ uid: string;
5
+ title: string;
6
+ variant_id: string;
7
+ locale: string;
8
+ _version: number;
9
+ _variant: {
10
+ uid: string;
11
+ _change_set: string[];
12
+ _base_entry_version: number;
13
+ };
14
+ publish_details: Record<string, any>[];
15
+ } & AnyProperty;
16
+
17
+ type PublishDetails = {
18
+ environment: string;
19
+ locale: string;
20
+ time: string;
21
+ user: string;
22
+ version: number;
23
+ } & AnyProperty;
24
+
25
+ export type EntryDataForVariantEntries = {
26
+ content_type: string;
27
+ locale: string;
28
+ entry_uid: string;
29
+ };
30
+
31
+ export type CreateVariantEntryDto = {
32
+ _variant: {
33
+ _change_set: string[];
34
+ };
35
+ } & AnyProperty;
36
+
37
+ export type CreateVariantEntryOptions = {
38
+ locale?: string;
39
+ entry_uid: string;
40
+ variant_id: string;
41
+ content_type_uid: string;
42
+ };
43
+
44
+ export type PublishVariantEntryOptions = {
45
+ entry_uid: string;
46
+ content_type_uid: string;
47
+ };
48
+
49
+ export type PublishVariantEntryDto = {
50
+ entry: {
51
+ environments: string[];
52
+ locales: string[];
53
+ publish_with_base_entry: boolean;
54
+ variants: {
55
+ uid: string;
56
+ version?: number;
57
+ }[];
58
+ }
59
+ locale: string;
60
+ version?: number;
61
+ } & AnyProperty;