Skip to content

Commit

Permalink
Merge branch 'development' into fix/CS-42005
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-from-contentstack authored Nov 3, 2023
2 parents b5bb1a3 + ddca58e commit 5d6b89a
Show file tree
Hide file tree
Showing 13 changed files with 1,264 additions and 430 deletions.
409 changes: 260 additions & 149 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions packages/contentstack-config/src/utils/region-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { configHandler } from '@contentstack/cli-utilities';

function validURL(str) {
const pattern = new RegExp(
'^(https:\\/\\/)?' + // protocol
'((([a-z0-9A-Z]*)[\\. |-]([a-z0-9A-Z]*))[\\.|-]([a-z0-9]{2,})+(\\.[a-z]{2,}\\.([a-z]{2,})|\\.([a-z]{2,}))|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'^(https?:\\/\\/)?' + // protocol (http or https)
'([a-zA-Z0-9.-]+|' + // domain name
'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))' + // IP address
'(:\\d+)?' + // port
'(/[-a-zA-Z0-9_.~+-]*)*' + // path
'(\\?[;&a-zA-Z0-9_.~+=-]*)?' + // query string
'(\\#[-a-zA-Z0-9_]*)?$', // fragment
'i',
);
return Boolean(pattern.test(str));

return pattern.test(str);
}

// Available region list
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-export-to-csv",
"description": "Export entities to csv",
"version": "1.4.4",
"version": "1.5.0",
"author": "Abhinav Gupta @abhinav-from-contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ExportToCsvCommand extends Command {
action: flags.string({
required: false,
multiple: false,
options: ['entries', 'users'],
description: `Option to export data (entries, users)`,
options: ['entries', 'users', 'teams'],
description: `Option to export data (entries, users, teams)`,
}),
alias: flags.string({
char: 'a',
Expand Down Expand Up @@ -59,6 +59,9 @@ class ExportToCsvCommand extends Command {
multiple: false,
required: false,
}),
"team-uid": flags.string({
description: 'Uid of the team whose user data and stack roles are required'
})
};

async run() {
Expand All @@ -75,11 +78,18 @@ class ExportToCsvCommand extends Command {
'content-type': contentTypesFlag,
alias: managementTokenAlias,
branch: branchUid,
"team-uid": teamUid
},
} = await this.parse(ExportToCsvCommand);

if (!managementTokenAlias) {
managementAPIClient = await managementSDKClient({ host: this.cmaHost });
if (!isAuthenticated()) {
this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
exit: 2,
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
});
}
}

if (actionFlag) {
Expand Down Expand Up @@ -113,14 +123,6 @@ class ExportToCsvCommand extends Command {
this.error('Provided management token alias not found in your config.!');
} else {
let organization;

if (!isAuthenticated()) {
this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
exit: 2,
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
});
}

if (org) {
organization = { uid: org };
} else {
Expand Down Expand Up @@ -227,12 +229,6 @@ class ExportToCsvCommand extends Command {
case config.exportUsers:
case 'users': {
try {
if (!isAuthenticated()) {
this.error(config.CLI_EXPORT_CSV_LOGIN_FAILED, {
exit: 2,
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
});
}
let organization;

if (org) {
Expand All @@ -258,6 +254,24 @@ class ExportToCsvCommand extends Command {
}
break;
}
case config.exportTeams:
case 'teams': {
try{
let organization;
if (org) {
organization = { uid: org, name: orgName || org };
} else {
organization = await util.chooseOrganization(managementAPIClient, action); // prompt for organization
}

await util.exportTeams(managementAPIClient,organization,teamUid);
} catch (error) {
if (error.message || error.errorMessage) {
cliux.error(util.formatError(error));
}
}
}
break;
}
} catch (error) {
if (error.message || error.errorMessage) {
Expand Down Expand Up @@ -310,6 +324,21 @@ ExportToCsvCommand.examples = [
'',
'Exporting organization users to csv with organization name provided',
'csdx cm:export-to-csv --action <users> --org <org-uid> --org-name <org-name>',
'',
'Exporting Organizations Teams to CSV',
'csdx cm:export-to-csv --action <teams>',
'',
'Exporting Organizations Teams to CSV with org-uid',
'csdx cm:export-to-csv --action <teams> --org <org-uid>',
'',
'Exporting Organizations Teams to CSV with team uid',
'csdx cm:export-to-csv --action <teams> --team-uid <team-uid>',
'',
'Exporting Organizations Teams to CSV with org-uid and team uid',
'csdx cm:export-to-csv --action <teams> --org <org-uid> --team-uid <team-uid>',
'',
'Exporting Organizations Teams to CSV with org-uid and team uid',
'csdx cm:export-to-csv --action <teams> --org <org-uid> --team-uid <team-uid> --org-name <org-name>',
];

module.exports = ExportToCsvCommand;
7 changes: 4 additions & 3 deletions packages/contentstack-export-to-csv/src/util/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
cancelString: 'Cancel and Exit',
exportEntries: 'Export entries to a .CSV file',
exportUsers: "Export organization users' data to a .CSV file",
exportUsers: "Export organization user's data to a .CSV file",
exportTeams: "Export organization team's data to a .csv file",
adminError: "Unable to export data. Make sure you're an admin or owner of this organization",
organizationNameRegex: /\'/,
CLI_EXPORT_CSV_LOGIN_FAILED: "You need to login to execute this command. See: auth:login --help",
CLI_EXPORT_CSV_ENTRIES_ERROR: "You need to either login or provide a management token to execute this command"

CLI_EXPORT_CSV_ENTRIES_ERROR: "You need to either login or provide a management token to execute this command",
CLI_EXPORT_CSV_API_FAILED: 'Something went wrong. Please try again!'
};
Loading

0 comments on commit 5d6b89a

Please sign in to comment.