Skip to content

Commit 5d4207d

Browse files
authored
Merge pull request #1616 from contentstack/development
DX | 14-10-2024 | Release
2 parents 0ddee21 + c749eb4 commit 5d4207d

File tree

39 files changed

+2778
-1358
lines changed

39 files changed

+2778
-1358
lines changed

package-lock.json

Lines changed: 1287 additions & 620 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ EXAMPLES
269269
$ csdx plugins
270270
```
271271

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

274274
## `csdx plugins:add PLUGIN`
275275

@@ -343,7 +343,7 @@ EXAMPLES
343343
$ csdx plugins:inspect myplugin
344344
```
345345

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

348348
## `csdx plugins:install PLUGIN`
349349

@@ -392,7 +392,7 @@ EXAMPLES
392392
$ csdx plugins:install someuser/someplugin
393393
```
394394

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

397397
## `csdx plugins:link PATH`
398398

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

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

427428
## `csdx plugins:remove [PLUGIN]`
428429

@@ -463,7 +464,7 @@ FLAGS
463464
--reinstall Reinstall all plugins after uninstalling.
464465
```
465466

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

468469
## `csdx plugins:uninstall [PLUGIN]`
469470

@@ -491,7 +492,7 @@ EXAMPLES
491492
$ csdx plugins:uninstall myplugin
492493
```
493494

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

496497
## `csdx plugins:unlink [PLUGIN]`
497498

@@ -535,5 +536,5 @@ DESCRIPTION
535536
Update installed plugins.
536537
```
537538

538-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/update.ts)_
539+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.14/src/commands/plugins/update.ts)_
539540
<!-- commandsstop -->

packages/contentstack-auth/src/commands/auth/login.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
6666
}
6767
} catch (error) {
6868
let errorMessage = formatError(error) || 'Something went wrong while logging. Please try again.';
69+
if (typeof errorMessage === 'object' && Object.keys(errorMessage)?.length === 0) {
70+
console.log(error);
71+
}
6972
this.logger.error('login failed', errorMessage);
7073
cliux.error('CLI_AUTH_LOGIN_FAILED');
7174
cliux.error(errorMessage);

packages/contentstack-auth/test/integration/auth.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('contentstack-auth plugin test', () => {
2525

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

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

56+
//NOTE
5357
describe('Check auth:login command with correct credentials.', () => {
54-
test
58+
test.loadConfig({ root: process.cwd() })
5559
// @ts-ignore
5660
.stub(CliUx, 'inquire', async (inquire) => {
5761
switch (inquire.name) {
@@ -69,17 +73,17 @@ describe('contentstack-auth plugin test', () => {
6973
});
7074

7175
describe('Check auth:logout command', () => {
72-
test
76+
test.loadConfig({ root: process.cwd() })
7377
.stub(CliUx, 'inquire', async () => 'Yes')
7478
.stdout({ print: PRINT_LOGS || false })
75-
.command(['auth:logout'])
79+
.command(['auth:logout','--yes'])
7680
.it('Logout should succeed.!', (ctx) => {
7781
expect(ctx.stdout).to.a('string').includes('Successfully logged out');
7882
});
7983
});
8084

8185
describe('Check auth:login command with --username, --password flags', () => {
82-
test
86+
test.loadConfig({ root: process.cwd() })
8387
.stdout({ print: PRINT_LOGS || false })
8488
.command(['auth:login', `-u=${username}`, `-p=${password}`])
8589
.it('Login should succeed!', (ctx) => {
@@ -95,7 +99,7 @@ describe('contentstack-auth plugin test', () => {
9599
after(() => {
96100
mail = '';
97101
});
98-
test
102+
test.loadConfig({ root: process.cwd() })
99103
.stdout({ print: PRINT_LOGS || false })
100104
.command(['whoami'])
101105
.it('shows user email who logged in', (ctx) => {

packages/contentstack-branches/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
3737
$ csdx COMMAND
3838
running command...
3939
$ csdx (--version)
40-
@contentstack/cli-cm-branches/1.1.4 darwin-arm64 node-v22.2.0
40+
@contentstack/cli-cm-branches/1.2.0 darwin-arm64 node-v22.2.0
4141
$ csdx --help [COMMAND]
4242
USAGE
4343
$ csdx COMMAND

packages/contentstack-branches/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"name": "@contentstack/cli-cm-branches",
33
"description": "Contentstack CLI plugin to do branches operations",
4-
"version": "1.1.4",
4+
"version": "1.2.0",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
8+
"@contentstack/cli-command": "~1.3.2",
9+
"@contentstack/cli-utilities": "~1.8.0",
810
"@contentstack/cli-command": "~1.3.2",
911
"@contentstack/cli-utilities": "~1.8.0",
1012
"@oclif/core": "^3.26.5",
@@ -26,7 +28,7 @@
2628
},
2729
"devDependencies": {
2830
"@contentstack/cli-auth": "~1.3.22",
29-
"@contentstack/cli-config": "~1.7.3",
31+
"@contentstack/cli-config": "~1.8.0",
3032
"@contentstack/cli-dev-dependencies": "~1.2.4",
3133
"@oclif/plugin-help": "^5.1.19",
3234
"@oclif/test": "^2.5.6",

packages/contentstack-branches/src/utils/entry-create-script.ts

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ export function entryCreateScript(contentType) {
108108
findAssetIdsFromJsonRte(entry, schema);
109109
parent.pop();
110110
}
111+
if (
112+
schema[i].data_type === 'json' &&
113+
schema[i].field_metadata.extension &&
114+
schema[i].field_metadata.is_asset
115+
) {
116+
fetchAssetFromFileFields(parent,schema[i],entry);
117+
}
111118
if (
112119
schema[i].data_type === 'text' &&
113120
schema[i].field_metadata &&
@@ -121,43 +128,47 @@ export function entryCreateScript(contentType) {
121128
parent.pop();
122129
}
123130
if (schema[i].data_type === 'file') {
124-
parent.push(schema[i].uid);
125-
let updatedEntry = entry;
126-
for (let i = 0; i < parent.length; i++) {
127-
updatedEntry = updatedEntry[parent[i]];
128-
}
129-
const imgDetails = updatedEntry;
130-
if (schema[i].multiple) {
131-
if (imgDetails && imgDetails.length) {
132-
imgDetails.forEach((img) => {
133-
const obj = {
134-
uid: img.uid,
135-
parent_uid: img.parent_uid,
136-
description: img.description,
137-
title: img.title,
138-
filename: img.filename,
139-
url: img.url,
140-
};
141-
cAssetDetails.push(obj);
142-
});
143-
}
144-
} else {
145-
if (imgDetails) {
146-
const obj = {
147-
uid: imgDetails.uid,
148-
parent_uid: imgDetails.parent_uid,
149-
description: imgDetails.description,
150-
title: imgDetails.title,
151-
filename: imgDetails.filename,
152-
url: imgDetails.url,
153-
};
154-
cAssetDetails.push(obj);
155-
}
156-
}
157-
parent.pop();
131+
fetchAssetFromFileFields(parent,schema[i],entry);
158132
}
159133
}
160134
};
135+
136+
function fetchAssetFromFileFields (parent, schema, entry) {
137+
parent.push(schema.uid);
138+
let updatedEntry = entry;
139+
for (let i = 0; i < parent.length; i++) {
140+
updatedEntry = updatedEntry[parent[i]];
141+
}
142+
const imgDetails = updatedEntry;
143+
if (schema.multiple) {
144+
if (imgDetails && imgDetails.length) {
145+
imgDetails.forEach((img) => {
146+
const obj = {
147+
uid: img.uid,
148+
parent_uid: img.parent_uid,
149+
description: img.description,
150+
title: img.title,
151+
filename: img.filename,
152+
url: img.url,
153+
};
154+
assetDetails.push(obj);
155+
});
156+
}
157+
} else {
158+
if (imgDetails) {
159+
const obj = {
160+
uid: imgDetails.uid,
161+
parent_uid: imgDetails.parent_uid,
162+
description: imgDetails.description,
163+
title: imgDetails.title,
164+
filename: imgDetails.filename,
165+
url: imgDetails.url,
166+
};
167+
assetDetails.push(obj);
168+
}
169+
}
170+
parent.pop();
171+
}
161172
162173
function findAssetIdsFromHtmlRte(entryObj, ctSchema) {
163174
const regex = /<img asset_uid=\\"([^"]+)\\"/g;

packages/contentstack-branches/src/utils/entry-create-update-script.ts

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ export function entryCreateUpdateScript(contentType) {
130130
findAssetIdsFromJsonRte(entry, schema);
131131
parent.pop();
132132
}
133+
134+
if (
135+
schema[i].data_type === 'json' &&
136+
schema[i].field_metadata.extension &&
137+
schema[i].field_metadata.is_asset
138+
) {
139+
fetchAssetFromFileFields(parent,schema[i],entry);
140+
}
141+
133142
if (
134143
schema[i].data_type === 'text' &&
135144
schema[i].field_metadata &&
@@ -143,44 +152,47 @@ export function entryCreateUpdateScript(contentType) {
143152
parent.pop();
144153
}
145154
if (schema[i].data_type === 'file') {
146-
parent.push(schema[i].uid);
147-
let updatedEntry = entry;
148-
for (let i = 0; i < parent.length; i++) {
149-
updatedEntry = updatedEntry[parent[i]];
150-
}
151-
const imgDetails = updatedEntry;
152-
if (schema[i].multiple) {
153-
if (imgDetails && imgDetails.length) {
154-
imgDetails.forEach((img) => {
155-
const obj = {
156-
uid: img.uid,
157-
parent_uid: img.parent_uid,
158-
description: img.description,
159-
title: img.title,
160-
filename: img.filename,
161-
url: img.url,
162-
};
163-
assetDetails.push(obj);
164-
});
165-
}
166-
} else {
167-
if (imgDetails) {
168-
const obj = {
169-
uid: imgDetails.uid,
170-
parent_uid: imgDetails.parent_uid,
171-
description: imgDetails.description,
172-
title: imgDetails.title,
173-
filename: imgDetails.filename,
174-
url: imgDetails.url,
175-
};
176-
assetDetails.push(obj);
177-
}
178-
}
179-
parent.pop();
155+
fetchAssetFromFileFields(parent,schema[i],entry);
180156
}
181157
}
182158
};
183159
160+
function fetchAssetFromFileFields (parent, schema, entry) {
161+
parent.push(schema.uid);
162+
let updatedEntry = entry;
163+
for (let i = 0; i < parent.length; i++) {
164+
updatedEntry = updatedEntry[parent[i]];
165+
}
166+
const imgDetails = updatedEntry;
167+
if (schema.multiple) {
168+
if (imgDetails && imgDetails.length) {
169+
imgDetails.forEach((img) => {
170+
const obj = {
171+
uid: img.uid,
172+
parent_uid: img.parent_uid,
173+
description: img.description,
174+
title: img.title,
175+
filename: img.filename,
176+
url: img.url,
177+
};
178+
assetDetails.push(obj);
179+
});
180+
}
181+
} else {
182+
if (imgDetails) {
183+
const obj = {
184+
uid: imgDetails.uid,
185+
parent_uid: imgDetails.parent_uid,
186+
description: imgDetails.description,
187+
title: imgDetails.title,
188+
filename: imgDetails.filename,
189+
url: imgDetails.url,
190+
};
191+
assetDetails.push(obj);
192+
}
193+
}
194+
parent.pop();
195+
}
184196
function findAssetIdsFromHtmlRte(entryObj, ctSchema) {
185197
const regex = /<img asset_uid=\\"([^"]+)\\"/g;
186198
let match;

0 commit comments

Comments
 (0)