Skip to content

Commit

Permalink
Merge pull request #1616 from contentstack/development
Browse files Browse the repository at this point in the history
DX | 14-10-2024 | Release
  • Loading branch information
cs-raj authored Oct 9, 2024
2 parents c662990 + ca8673e commit b4164e5
Show file tree
Hide file tree
Showing 39 changed files with 2,778 additions and 1,358 deletions.
1,907 changes: 1,287 additions & 620 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ EXAMPLES
$ csdx plugins
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/index.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/index.ts)_

## `csdx plugins:add PLUGIN`

Expand Down Expand Up @@ -343,7 +343,7 @@ EXAMPLES
$ csdx plugins:inspect myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/inspect.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/inspect.ts)_

## `csdx plugins:install PLUGIN`

Expand Down Expand Up @@ -392,7 +392,7 @@ EXAMPLES
$ csdx plugins:install someuser/someplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/install.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/install.ts)_

## `csdx plugins:link PATH`

Expand All @@ -412,6 +412,7 @@ FLAGS
DESCRIPTION
Links a plugin into the CLI for development.
Installation of a linked plugin will override a user-installed or core plugin.
e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
Expand All @@ -422,7 +423,7 @@ EXAMPLES
$ csdx plugins:link myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/link.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/link.ts)_

## `csdx plugins:remove [PLUGIN]`

Expand Down Expand Up @@ -463,7 +464,7 @@ FLAGS
--reinstall Reinstall all plugins after uninstalling.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/reset.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/reset.ts)_

## `csdx plugins:uninstall [PLUGIN]`

Expand Down Expand Up @@ -491,7 +492,7 @@ EXAMPLES
$ csdx plugins:uninstall myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/uninstall.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/uninstall.ts)_

## `csdx plugins:unlink [PLUGIN]`

Expand Down Expand Up @@ -535,5 +536,5 @@ DESCRIPTION
Update installed plugins.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/update.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/update.ts)_
<!-- commandsstop -->
3 changes: 3 additions & 0 deletions packages/contentstack-auth/src/commands/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
}
} catch (error) {
let errorMessage = formatError(error) || 'Something went wrong while logging. Please try again.';
if (typeof errorMessage === 'object' && Object.keys(errorMessage)?.length === 0) {
console.log(error);
}
this.logger.error('login failed', errorMessage);
cliux.error('CLI_AUTH_LOGIN_FAILED');
cliux.error(errorMessage);
Expand Down
20 changes: 12 additions & 8 deletions packages/contentstack-auth/test/integration/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('contentstack-auth plugin test', () => {

describe('Check auth:login command with wrong credentials', () => {
test
.loadConfig({ root: process.cwd() })
// @ts-ignore
.stub(CliUx, 'inquire', async (inquire) => {
switch (inquire.name) {
Expand All @@ -34,24 +35,27 @@ describe('contentstack-auth plugin test', () => {
return 'WrongPassword@12345%$#@!'; // NOTE forcing wrong password
}
})
.stub(process,'exit',()=>{})
.stdout({ print: PRINT_LOGS || false })
.command(['auth:login'])
.it('Login should fail due to wrong credentials.!', (ctx) => {
expect(ctx.stdout).to.a('string').includes('Login Error\nLooks like your email or password is invalid');
expect(ctx.stdout).to.be.includes('Login Error\nLooks like your email or password is invalid. Please try again or reset your password.');
});
});

describe('Check auth:login command with --username, --password flags and wrong credentials', () => {
test
test.loadConfig({ root: process.cwd() })
.stdout({ print: PRINT_LOGS || false })
.stub(process,'exit',()=>{})
.command(['auth:login', `--username=${username}`, '--password=WrongPassword@12345%$#@!'])
.it('Login should fail due to wrong credentials.!', (ctx) => {
expect(ctx.stdout).to.a('string').includes('Login Error\nLooks like your email or password is invalid');
expect(ctx.stdout).to.a('string').includes('Login Error\nLooks like your email or password is invalid. Please try again or reset your password.');
});
});

//NOTE
describe('Check auth:login command with correct credentials.', () => {
test
test.loadConfig({ root: process.cwd() })
// @ts-ignore
.stub(CliUx, 'inquire', async (inquire) => {
switch (inquire.name) {
Expand All @@ -69,17 +73,17 @@ describe('contentstack-auth plugin test', () => {
});

describe('Check auth:logout command', () => {
test
test.loadConfig({ root: process.cwd() })
.stub(CliUx, 'inquire', async () => 'Yes')
.stdout({ print: PRINT_LOGS || false })
.command(['auth:logout'])
.command(['auth:logout','--yes'])
.it('Logout should succeed.!', (ctx) => {
expect(ctx.stdout).to.a('string').includes('Successfully logged out');
});
});

describe('Check auth:login command with --username, --password flags', () => {
test
test.loadConfig({ root: process.cwd() })
.stdout({ print: PRINT_LOGS || false })
.command(['auth:login', `-u=${username}`, `-p=${password}`])
.it('Login should succeed!', (ctx) => {
Expand All @@ -95,7 +99,7 @@ describe('contentstack-auth plugin test', () => {
after(() => {
mail = '';
});
test
test.loadConfig({ root: process.cwd() })
.stdout({ print: PRINT_LOGS || false })
.command(['whoami'])
.it('shows user email who logged in', (ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.1.4 darwin-arm64 node-v22.2.0
@contentstack/cli-cm-branches/1.2.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 4 additions & 2 deletions packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.1.4",
"version": "1.2.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"@oclif/core": "^3.26.5",
Expand All @@ -26,7 +28,7 @@
},
"devDependencies": {
"@contentstack/cli-auth": "~1.3.22",
"@contentstack/cli-config": "~1.7.3",
"@contentstack/cli-config": "~1.8.0",
"@contentstack/cli-dev-dependencies": "~1.2.4",
"@oclif/plugin-help": "^5.1.19",
"@oclif/test": "^2.5.6",
Expand Down
79 changes: 45 additions & 34 deletions packages/contentstack-branches/src/utils/entry-create-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export function entryCreateScript(contentType) {
findAssetIdsFromJsonRte(entry, schema);
parent.pop();
}
if (
schema[i].data_type === 'json' &&
schema[i].field_metadata.extension &&
schema[i].field_metadata.is_asset
) {
fetchAssetFromFileFields(parent,schema[i],entry);
}
if (
schema[i].data_type === 'text' &&
schema[i].field_metadata &&
Expand All @@ -121,43 +128,47 @@ export function entryCreateScript(contentType) {
parent.pop();
}
if (schema[i].data_type === 'file') {
parent.push(schema[i].uid);
let updatedEntry = entry;
for (let i = 0; i < parent.length; i++) {
updatedEntry = updatedEntry[parent[i]];
}
const imgDetails = updatedEntry;
if (schema[i].multiple) {
if (imgDetails && imgDetails.length) {
imgDetails.forEach((img) => {
const obj = {
uid: img.uid,
parent_uid: img.parent_uid,
description: img.description,
title: img.title,
filename: img.filename,
url: img.url,
};
cAssetDetails.push(obj);
});
}
} else {
if (imgDetails) {
const obj = {
uid: imgDetails.uid,
parent_uid: imgDetails.parent_uid,
description: imgDetails.description,
title: imgDetails.title,
filename: imgDetails.filename,
url: imgDetails.url,
};
cAssetDetails.push(obj);
}
}
parent.pop();
fetchAssetFromFileFields(parent,schema[i],entry);
}
}
};
function fetchAssetFromFileFields (parent, schema, entry) {
parent.push(schema.uid);
let updatedEntry = entry;
for (let i = 0; i < parent.length; i++) {
updatedEntry = updatedEntry[parent[i]];
}
const imgDetails = updatedEntry;
if (schema.multiple) {
if (imgDetails && imgDetails.length) {
imgDetails.forEach((img) => {
const obj = {
uid: img.uid,
parent_uid: img.parent_uid,
description: img.description,
title: img.title,
filename: img.filename,
url: img.url,
};
assetDetails.push(obj);
});
}
} else {
if (imgDetails) {
const obj = {
uid: imgDetails.uid,
parent_uid: imgDetails.parent_uid,
description: imgDetails.description,
title: imgDetails.title,
filename: imgDetails.filename,
url: imgDetails.url,
};
assetDetails.push(obj);
}
}
parent.pop();
}
function findAssetIdsFromHtmlRte(entryObj, ctSchema) {
const regex = /<img asset_uid=\\"([^"]+)\\"/g;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ export function entryCreateUpdateScript(contentType) {
findAssetIdsFromJsonRte(entry, schema);
parent.pop();
}
if (
schema[i].data_type === 'json' &&
schema[i].field_metadata.extension &&
schema[i].field_metadata.is_asset
) {
fetchAssetFromFileFields(parent,schema[i],entry);
}
if (
schema[i].data_type === 'text' &&
schema[i].field_metadata &&
Expand All @@ -143,44 +152,47 @@ export function entryCreateUpdateScript(contentType) {
parent.pop();
}
if (schema[i].data_type === 'file') {
parent.push(schema[i].uid);
let updatedEntry = entry;
for (let i = 0; i < parent.length; i++) {
updatedEntry = updatedEntry[parent[i]];
}
const imgDetails = updatedEntry;
if (schema[i].multiple) {
if (imgDetails && imgDetails.length) {
imgDetails.forEach((img) => {
const obj = {
uid: img.uid,
parent_uid: img.parent_uid,
description: img.description,
title: img.title,
filename: img.filename,
url: img.url,
};
assetDetails.push(obj);
});
}
} else {
if (imgDetails) {
const obj = {
uid: imgDetails.uid,
parent_uid: imgDetails.parent_uid,
description: imgDetails.description,
title: imgDetails.title,
filename: imgDetails.filename,
url: imgDetails.url,
};
assetDetails.push(obj);
}
}
parent.pop();
fetchAssetFromFileFields(parent,schema[i],entry);
}
}
};
function fetchAssetFromFileFields (parent, schema, entry) {
parent.push(schema.uid);
let updatedEntry = entry;
for (let i = 0; i < parent.length; i++) {
updatedEntry = updatedEntry[parent[i]];
}
const imgDetails = updatedEntry;
if (schema.multiple) {
if (imgDetails && imgDetails.length) {
imgDetails.forEach((img) => {
const obj = {
uid: img.uid,
parent_uid: img.parent_uid,
description: img.description,
title: img.title,
filename: img.filename,
url: img.url,
};
assetDetails.push(obj);
});
}
} else {
if (imgDetails) {
const obj = {
uid: imgDetails.uid,
parent_uid: imgDetails.parent_uid,
description: imgDetails.description,
title: imgDetails.title,
filename: imgDetails.filename,
url: imgDetails.url,
};
assetDetails.push(obj);
}
}
parent.pop();
}
function findAssetIdsFromHtmlRte(entryObj, ctSchema) {
const regex = /<img asset_uid=\\"([^"]+)\\"/g;
let match;
Expand Down
Loading

0 comments on commit b4164e5

Please sign in to comment.