@contentstack/cli-cm-export-to-csv 1.10.2 → 1.11.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.
@@ -0,0 +1,591 @@
1
+ /**
2
+ * Type definitions for export-to-csv package.
3
+ *
4
+ * Uses types from @contentstack/cli-utilities where available.
5
+ * Defines package-specific types for API responses, CSV structures, and CLI flags.
6
+ */
7
+ export type { Organization, ContentType, Environment, Locale, PrintOptions, InquirePayload, ContentstackClient as ManagementClient, } from '@contentstack/cli-utilities';
8
+ import { ContentstackClient } from '@contentstack/cli-utilities';
9
+ /**
10
+ * Stack API Client - returned by managementClient.stack()
11
+ */
12
+ export type StackClient = ReturnType<ContentstackClient['stack']>;
13
+ /**
14
+ * Available export actions.
15
+ */
16
+ export type ExportAction = 'entries' | 'users' | 'teams' | 'taxonomies';
17
+ /**
18
+ * Parsed CLI flags for the export-to-csv command.
19
+ */
20
+ export interface ExportToCsvFlags {
21
+ [key: string]: unknown;
22
+ action?: ExportAction;
23
+ alias?: string;
24
+ org?: string;
25
+ 'stack-name'?: string;
26
+ 'stack-api-key'?: string;
27
+ 'org-name'?: string;
28
+ locale?: string;
29
+ 'content-type'?: string;
30
+ branch?: string;
31
+ 'team-uid'?: string;
32
+ 'taxonomy-uid'?: string;
33
+ 'include-fallback'?: boolean;
34
+ 'fallback-locale'?: string;
35
+ delimiter?: string;
36
+ }
37
+ /**
38
+ * Token configuration from config handler.
39
+ */
40
+ export interface TokenConfig {
41
+ apiKey: string;
42
+ token: string;
43
+ }
44
+ /**
45
+ * Tokens map from config handler.
46
+ */
47
+ export interface TokensMap {
48
+ [alias: string]: TokenConfig;
49
+ }
50
+ /**
51
+ * Stack details used throughout the command.
52
+ */
53
+ export interface StackDetails {
54
+ name: string;
55
+ apiKey: string;
56
+ token?: string;
57
+ branch_uid?: string;
58
+ }
59
+ /**
60
+ * Branch data structure.
61
+ */
62
+ export interface Branch {
63
+ uid: string;
64
+ source?: string;
65
+ alias?: string[];
66
+ }
67
+ /**
68
+ * Stack initialization options for SDK.
69
+ */
70
+ export interface StackInitOptions {
71
+ api_key: string;
72
+ branch_uid?: string;
73
+ management_token?: string;
74
+ }
75
+ /**
76
+ * Branch existence check result.
77
+ */
78
+ export interface BranchExistsResult {
79
+ errorCode?: string;
80
+ errorMessage?: string;
81
+ }
82
+ /**
83
+ * Stack item structure from API.
84
+ */
85
+ export interface StackItem {
86
+ name: string;
87
+ api_key: string;
88
+ }
89
+ /**
90
+ * Organization item structure from API.
91
+ */
92
+ export interface OrganizationItem {
93
+ uid: string;
94
+ name: string;
95
+ items?: OrganizationItem[];
96
+ }
97
+ /**
98
+ * Organization with roles structure from getUser API.
99
+ */
100
+ export interface OrgWithRoles {
101
+ uid: string;
102
+ name: string;
103
+ is_owner?: boolean;
104
+ org_roles?: Array<{
105
+ admin?: boolean;
106
+ }>;
107
+ }
108
+ /**
109
+ * Organization role map structure.
110
+ */
111
+ export interface OrgRoleMap {
112
+ member?: string;
113
+ admin?: string;
114
+ [key: string]: string | undefined;
115
+ }
116
+ /**
117
+ * Organization user from getInvitations API.
118
+ */
119
+ export interface OrgUser {
120
+ uid?: string;
121
+ email: string;
122
+ user_uid: string;
123
+ org_uid?: string;
124
+ invited_by: string;
125
+ status: string;
126
+ created_at: string;
127
+ updated_at: string;
128
+ is_owner?: boolean;
129
+ org_roles?: string[];
130
+ }
131
+ /**
132
+ * Organization role data.
133
+ */
134
+ export interface OrgRole {
135
+ uid: string;
136
+ name: string;
137
+ description?: string;
138
+ admin?: boolean;
139
+ }
140
+ /**
141
+ * Paginated response for organization users.
142
+ */
143
+ export interface OrgUsersResponse {
144
+ items: OrgUser[];
145
+ }
146
+ /**
147
+ * Paginated response for organization roles.
148
+ */
149
+ export interface OrgRolesResponse {
150
+ items: OrgRole[];
151
+ }
152
+ /**
153
+ * User response from getUser API.
154
+ */
155
+ export interface UserResponse {
156
+ organizations: Array<{
157
+ uid: string;
158
+ name: string;
159
+ is_owner?: boolean;
160
+ org_roles?: Array<{
161
+ admin?: boolean;
162
+ }>;
163
+ getInvitations?: () => Promise<OrgUsersResponse>;
164
+ roles?: () => Promise<OrgRolesResponse>;
165
+ }>;
166
+ }
167
+ /**
168
+ * Content type count response.
169
+ */
170
+ export interface ContentTypeCountResponse {
171
+ content_types: number;
172
+ }
173
+ /**
174
+ * Content type item from API.
175
+ */
176
+ export interface ContentTypeItem {
177
+ uid: string;
178
+ title?: string;
179
+ }
180
+ /**
181
+ * Language/locale item structure from API.
182
+ */
183
+ export interface LanguageItem {
184
+ name: string;
185
+ code: string;
186
+ }
187
+ /**
188
+ * Environment item structure from API.
189
+ */
190
+ export interface EnvironmentItem {
191
+ uid: string;
192
+ name: string;
193
+ }
194
+ /**
195
+ * Entry publish details.
196
+ */
197
+ export interface PublishDetails {
198
+ environment: string;
199
+ locale: string;
200
+ time?: string;
201
+ }
202
+ /**
203
+ * Workflow details for an entry.
204
+ */
205
+ export interface WorkflowDetails {
206
+ name?: string;
207
+ uid?: string;
208
+ }
209
+ /**
210
+ * Raw entry from API (before transformation).
211
+ */
212
+ export interface RawEntry {
213
+ uid: string;
214
+ title: string;
215
+ locale: string;
216
+ content_type_uid?: string;
217
+ publish_details?: PublishDetails[];
218
+ _workflow?: WorkflowDetails;
219
+ setWorkflowStage?: unknown;
220
+ stackHeaders?: unknown;
221
+ update?: unknown;
222
+ delete?: unknown;
223
+ fetch?: unknown;
224
+ publish?: unknown;
225
+ unpublish?: unknown;
226
+ import?: unknown;
227
+ publishRequest?: unknown;
228
+ [key: string]: unknown;
229
+ }
230
+ /**
231
+ * Entries query response from SDK.
232
+ */
233
+ export interface EntriesResponse {
234
+ items: RawEntry[];
235
+ count?: number;
236
+ }
237
+ /**
238
+ * Entry count response from SDK.
239
+ */
240
+ export interface EntriesCountResponse {
241
+ entries: number;
242
+ }
243
+ /**
244
+ * Language/locale data with code and name.
245
+ */
246
+ export interface LanguageChoice {
247
+ code: string;
248
+ name?: string;
249
+ }
250
+ /**
251
+ * Stack role map with stack details.
252
+ */
253
+ export interface StackRoleMap {
254
+ [key: string]: string | {
255
+ name: string;
256
+ uid: string;
257
+ };
258
+ }
259
+ /**
260
+ * Team user data.
261
+ */
262
+ export interface TeamUser {
263
+ [key: string]: unknown;
264
+ userId: string;
265
+ email: string;
266
+ firstName?: string;
267
+ lastName?: string;
268
+ active?: boolean;
269
+ orgInvitationStatus?: string;
270
+ 'team-name'?: string;
271
+ 'team-uid'?: string;
272
+ }
273
+ /**
274
+ * Stack role mapping for teams.
275
+ */
276
+ export interface StackRoleMapping {
277
+ stackApiKey: string;
278
+ roles: string[];
279
+ }
280
+ /**
281
+ * Raw team data from API (before transformation).
282
+ */
283
+ export interface RawTeam {
284
+ uid: string;
285
+ name: string;
286
+ description?: string;
287
+ organizationRole: string;
288
+ users?: TeamUser[];
289
+ stackRoleMapping?: StackRoleMapping[];
290
+ _id?: string;
291
+ createdAt?: string;
292
+ createdBy?: string;
293
+ updatedAt?: string;
294
+ updatedBy?: string;
295
+ __v?: number;
296
+ createdByUserName?: string;
297
+ updatedByUserName?: string;
298
+ organizationUid?: string;
299
+ urlPath?: string;
300
+ update?: unknown;
301
+ delete?: unknown;
302
+ fetch?: unknown;
303
+ stackRoleMappings?: unknown;
304
+ teamUsers?: unknown;
305
+ }
306
+ /**
307
+ * Cleaned team data for CSV export.
308
+ */
309
+ export interface CleanedTeam {
310
+ uid: string;
311
+ name: string;
312
+ description: string;
313
+ organizationRole: string;
314
+ users?: TeamUser[];
315
+ stackRoleMapping?: StackRoleMapping[];
316
+ Total_Members: number;
317
+ }
318
+ /**
319
+ * Teams fetch response.
320
+ */
321
+ export interface TeamsResponse {
322
+ items: RawTeam[];
323
+ count?: number;
324
+ }
325
+ /**
326
+ * Stack role data from SDK.
327
+ */
328
+ export interface StackRole {
329
+ uid: string;
330
+ name: string;
331
+ stack?: {
332
+ api_key: string;
333
+ name: string;
334
+ uid: string;
335
+ };
336
+ }
337
+ /**
338
+ * Stack roles response.
339
+ */
340
+ export interface StackRolesResponse {
341
+ items: StackRole[];
342
+ }
343
+ /**
344
+ * Taxonomy data structure.
345
+ */
346
+ export interface Taxonomy {
347
+ uid: string;
348
+ name: string;
349
+ description?: string;
350
+ }
351
+ /**
352
+ * Taxonomy term data structure.
353
+ */
354
+ export interface Term {
355
+ uid: string;
356
+ name: string;
357
+ parent_uid: string | null;
358
+ depth: number;
359
+ }
360
+ /**
361
+ * Taxonomies query response.
362
+ */
363
+ export interface TaxonomiesResponse {
364
+ items: Taxonomy[];
365
+ count: number;
366
+ }
367
+ /**
368
+ * Terms query response.
369
+ */
370
+ export interface TermsResponse {
371
+ items: Term[];
372
+ count: number;
373
+ }
374
+ /**
375
+ * Taxonomy SDK handler payload.
376
+ */
377
+ export interface TaxonomyPayload {
378
+ stackAPIClient: StackClient;
379
+ type?: 'taxonomies' | 'taxonomy' | 'terms' | 'export-taxonomies';
380
+ taxonomyUID?: string;
381
+ format?: string;
382
+ locale?: string;
383
+ branch?: string;
384
+ include_fallback?: boolean;
385
+ fallback_locale?: string;
386
+ limit: number;
387
+ }
388
+ /**
389
+ * Locale options for taxonomy export.
390
+ */
391
+ export interface TaxonomyLocaleOptions {
392
+ locale?: string;
393
+ branch?: string;
394
+ include_fallback?: boolean;
395
+ fallback_locale?: string;
396
+ }
397
+ /**
398
+ * Flattened entry row for CSV export.
399
+ */
400
+ export interface FlattenedEntryRow {
401
+ uid: string;
402
+ title: string;
403
+ locale: string;
404
+ content_type_uid: string;
405
+ publish_details: string[];
406
+ _workflow: string;
407
+ ACL: string;
408
+ [key: string]: unknown;
409
+ }
410
+ /**
411
+ * Organization user row for CSV export.
412
+ */
413
+ export interface OrgUserCsvRow {
414
+ [key: string]: unknown;
415
+ Email: string;
416
+ 'User UID': string;
417
+ 'Organization Role': string;
418
+ Status: string;
419
+ 'Invited By': string;
420
+ 'Created Time': string;
421
+ 'Updated Time': string;
422
+ }
423
+ /**
424
+ * Team CSV row for export.
425
+ */
426
+ export interface TeamCsvRow {
427
+ [key: string]: unknown;
428
+ uid: string;
429
+ name: string;
430
+ description: string;
431
+ organizationRole: string;
432
+ Total_Members: number;
433
+ }
434
+ /**
435
+ * Team user CSV row for export.
436
+ */
437
+ export interface TeamUserCsvRow {
438
+ [key: string]: unknown;
439
+ userId: string;
440
+ email: string;
441
+ firstName?: string;
442
+ lastName?: string;
443
+ 'team-name': string;
444
+ 'team-uid': string;
445
+ }
446
+ /**
447
+ * Stack role mapping CSV row for export.
448
+ */
449
+ export interface StackRoleMappingCsvRow {
450
+ [key: string]: unknown;
451
+ 'Team Name': string;
452
+ 'Team Uid': string;
453
+ 'Stack Name': string;
454
+ 'Stack Uid': string;
455
+ 'Role Name': string;
456
+ 'Role Uid': string;
457
+ }
458
+ /**
459
+ * Taxonomy CSV row for export.
460
+ */
461
+ export interface TaxonomyCsvRow {
462
+ [key: string]: unknown;
463
+ 'Taxonomy UID': string;
464
+ Name: string;
465
+ Description: string;
466
+ }
467
+ /**
468
+ * Term CSV row for export.
469
+ */
470
+ export interface TermCsvRow {
471
+ [key: string]: unknown;
472
+ 'Taxonomy UID': string;
473
+ UID: string;
474
+ Name: string;
475
+ 'Parent UID': string | null;
476
+ Depth: number;
477
+ }
478
+ /**
479
+ * Pagination parameters for API calls.
480
+ */
481
+ export interface PaginationParams {
482
+ skip: number;
483
+ page: number;
484
+ limit: number;
485
+ }
486
+ /**
487
+ * Query parameters for taxonomy/term API calls.
488
+ */
489
+ export interface TaxonomyQueryParams {
490
+ include_count: boolean;
491
+ limit: number;
492
+ skip?: number;
493
+ locale?: string;
494
+ branch?: string;
495
+ include_fallback?: boolean;
496
+ fallback_locale?: string;
497
+ depth?: number;
498
+ }
499
+ /**
500
+ * API error structure.
501
+ */
502
+ export interface ApiError {
503
+ errorMessage?: string;
504
+ error_message?: string;
505
+ message?: string;
506
+ errors?: Record<string, string>;
507
+ }
508
+ /**
509
+ * Map of organization names to UIDs.
510
+ */
511
+ export type OrgMap = Record<string, string>;
512
+ /**
513
+ * Map of stack names to API keys.
514
+ */
515
+ export type StackMap = Record<string, string>;
516
+ /**
517
+ * Map of content type titles to UIDs.
518
+ */
519
+ export type ContentTypeMap = Record<string, string>;
520
+ /**
521
+ * Map of language names to codes.
522
+ */
523
+ export type LanguageMap = Record<string, string>;
524
+ /**
525
+ * Map of environment UIDs to names.
526
+ */
527
+ export type EnvironmentMap = Record<string, string>;
528
+ /**
529
+ * Map of user UIDs to emails.
530
+ */
531
+ export type UserMap = Record<string, string>;
532
+ /**
533
+ * Map of role UIDs to names.
534
+ */
535
+ export type RoleMap = Record<string, string>;
536
+ /**
537
+ * Organization choice result from prompt.
538
+ */
539
+ export interface OrganizationChoice {
540
+ name: string;
541
+ uid: string;
542
+ }
543
+ /**
544
+ * Stack choice result from prompt.
545
+ */
546
+ export interface StackChoice {
547
+ name: string;
548
+ apiKey: string;
549
+ }
550
+ /**
551
+ * Branch choice result from prompt.
552
+ */
553
+ export interface BranchChoice {
554
+ branch: string;
555
+ }
556
+ /**
557
+ * Fallback options result from prompt.
558
+ */
559
+ export interface FallbackOptions {
560
+ includeFallback: boolean;
561
+ fallbackLocale: string | null;
562
+ }
563
+ /**
564
+ * API error with optional errorMessage and message properties.
565
+ */
566
+ export interface ErrorWithMessage {
567
+ errorMessage?: string;
568
+ message?: string;
569
+ }
570
+ /**
571
+ * Taxonomy-specific error with errors object.
572
+ */
573
+ export interface TaxonomyError {
574
+ errorMessage?: string;
575
+ message?: string;
576
+ errors?: {
577
+ taxonomy?: string;
578
+ term?: string;
579
+ };
580
+ }
581
+ /**
582
+ * CSV row data type - can be any record with string keys or string array.
583
+ */
584
+ export type CsvRow = Record<string, unknown> | string[];
585
+ /**
586
+ * Result from createImportableCSV function.
587
+ */
588
+ export interface ImportableCsvResult {
589
+ taxonomiesData: string[][];
590
+ headers: string[];
591
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Type definitions for export-to-csv package.
4
+ *
5
+ * Uses types from @contentstack/cli-utilities where available.
6
+ * Defines package-specific types for API responses, CSV structures, and CLI flags.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,81 @@
1
+ /**
2
+ * API client utilities.
3
+ * Migrated from: packages/contentstack-export-to-csv/src/util/index.js
4
+ */
5
+ import type { ManagementClient, StackClient, OrgMap, StackMap, ContentTypeMap, LanguageMap, EnvironmentMap, OrgUsersResponse, OrgRolesResponse, OrganizationChoice, CleanedTeam, TeamsResponse, StackRolesResponse, TaxonomyPayload, TaxonomiesResponse, TermsResponse, Taxonomy, Term, EntriesResponse, ImportableCsvResult } from '../types';
6
+ /**
7
+ * Get all organizations the user has access to.
8
+ */
9
+ export declare function getOrganizations(managementAPIClient: ManagementClient): Promise<OrgMap>;
10
+ /**
11
+ * Get organizations where user is admin.
12
+ */
13
+ export declare function getOrganizationsWhereUserIsAdmin(managementAPIClient: ManagementClient): Promise<OrgMap>;
14
+ /**
15
+ * Get organization users.
16
+ */
17
+ export declare function getOrgUsers(managementAPIClient: ManagementClient, orgUid: string): Promise<OrgUsersResponse>;
18
+ /**
19
+ * Get organization roles.
20
+ */
21
+ export declare function getOrgRoles(managementAPIClient: ManagementClient, orgUid: string): Promise<OrgRolesResponse>;
22
+ /**
23
+ * Get all stacks in an organization.
24
+ */
25
+ export declare function getStacks(managementAPIClient: ManagementClient, orgUid: string): Promise<StackMap>;
26
+ /**
27
+ * Get content type count.
28
+ */
29
+ export declare function getContentTypeCount(stackAPIClient: StackClient): Promise<number>;
30
+ /**
31
+ * Get content types with pagination.
32
+ */
33
+ export declare function getContentTypes(stackAPIClient: StackClient, skip: number): Promise<ContentTypeMap>;
34
+ /**
35
+ * Get all languages/locales for a stack.
36
+ */
37
+ export declare function getLanguages(stackAPIClient: StackClient): Promise<LanguageMap>;
38
+ /**
39
+ * Get entry count for a content type.
40
+ */
41
+ export declare function getEntriesCount(stackAPIClient: StackClient, contentType: string, language: string): Promise<number>;
42
+ /**
43
+ * Get entries with pagination.
44
+ */
45
+ export declare function getEntries(stackAPIClient: StackClient, contentType: string, language: string, skip: number, limit: number): Promise<EntriesResponse>;
46
+ /**
47
+ * Get all environments for a stack.
48
+ */
49
+ export declare function getEnvironments(stackAPIClient: StackClient): Promise<EnvironmentMap>;
50
+ /**
51
+ * Get all teams in an organization.
52
+ */
53
+ export declare function getAllTeams(managementAPIClient: ManagementClient, org: OrganizationChoice, queryParam?: Record<string, unknown>): Promise<TeamsResponse>;
54
+ /**
55
+ * Export all organization teams with pagination.
56
+ */
57
+ export declare function exportOrgTeams(managementAPIClient: ManagementClient, org: OrganizationChoice): Promise<CleanedTeam[]>;
58
+ /**
59
+ * Get role data for a stack.
60
+ */
61
+ export declare function getRoleData(managementAPIClient: ManagementClient, stackApiKey: string): Promise<StackRolesResponse>;
62
+ /**
63
+ * Taxonomy & term SDK handler.
64
+ */
65
+ export declare function taxonomySDKHandler(payload: TaxonomyPayload, skip?: number): Promise<TaxonomiesResponse | TermsResponse | Taxonomy | string>;
66
+ /**
67
+ * Get all taxonomies in a stack.
68
+ */
69
+ export declare function getAllTaxonomies(payload: TaxonomyPayload, skip?: number, taxonomies?: Taxonomy[]): Promise<Taxonomy[]>;
70
+ /**
71
+ * Get all terms for a taxonomy.
72
+ */
73
+ export declare function getAllTermsOfTaxonomy(payload: TaxonomyPayload, skip?: number, terms?: Term[]): Promise<Term[]>;
74
+ /**
75
+ * Get a single taxonomy by UID.
76
+ */
77
+ export declare function getTaxonomy(payload: TaxonomyPayload): Promise<Taxonomy>;
78
+ /**
79
+ * Generate importable CSV data for taxonomies.
80
+ */
81
+ export declare function createImportableCSV(payload: TaxonomyPayload, taxonomies: Taxonomy[]): Promise<ImportableCsvResult>;