Skip to content

Commit

Permalink
Merge pull request #1691 from contentstack/staging
Browse files Browse the repository at this point in the history
DX | 05-12-2024 | Release
  • Loading branch information
cs-raj authored Dec 5, 2024
2 parents 1f4bf6f + 391717d commit 83410d1
Show file tree
Hide file tree
Showing 16 changed files with 906 additions and 829 deletions.
963 changes: 448 additions & 515 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 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.15/src/commands/plugins/index.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.17/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.15/src/commands/plugins/inspect.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.17/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.15/src/commands/plugins/install.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.17/src/commands/plugins/install.ts)_

## `csdx plugins:link PATH`

Expand Down Expand Up @@ -423,7 +423,7 @@ EXAMPLES
$ csdx plugins:link myplugin
```

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

## `csdx plugins:remove [PLUGIN]`

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

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

## `csdx plugins:uninstall [PLUGIN]`

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

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

## `csdx plugins:unlink [PLUGIN]`

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

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/update.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.17/src/commands/plugins/update.ts)_
<!-- commandsstop -->
2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@colors/colors": "^1.6.0",
"@contentstack/cli-cm-export": "~1.14.1",
"@contentstack/cli-cm-import": "~1.19.2",
"@contentstack/cli-cm-import": "~1.19.3",
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"async": "^3.2.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-variants": "~1.1.2",
"@contentstack/cli-variants": "~1.1.3",
"@contentstack/cli-utilities": "~1.8.0",
"@oclif/core": "^3.27.0",
"async": "^3.2.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.19.2 darwin-arm64 node-v22.8.0
@contentstack/cli-cm-import/1.19.3 darwin-arm64 node-v22.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.19.2",
"version": "1.19.3",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-audit": "~1.7.3",
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"@contentstack/management": "~1.18.3",
"@contentstack/cli-variants": "~1.1.2",
"@contentstack/cli-variants": "~1.1.3",
"@oclif/core": "^3.27.0",
"big-json": "^3.2.0",
"bluebird": "^3.7.2",
Expand Down
18 changes: 12 additions & 6 deletions packages/contentstack-import/src/import/modules/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,21 @@ export default class ImportAssets extends BaseClass {
const serializeData = (apiOptions: ApiOptions) => {
const { apiData: asset } = apiOptions;
const publishDetails = filter(asset.publish_details, ({ environment }) => {
return this.environments.hasOwnProperty(environment);
return this.environments?.hasOwnProperty(environment);
});
const environments = uniq(map(publishDetails, ({ environment }) => this.environments[environment].name));
const locales = uniq(map(publishDetails, 'locale'));
if (publishDetails.length) {
const environments = uniq(map(publishDetails, ({ environment }) => this.environments[environment].name));
const locales = uniq(map(publishDetails, 'locale'));
if (environments.length === 0 || locales.length === 0) {
apiOptions.entity = undefined
return apiOptions;
}
asset.locales = locales;
asset.environments = environments;
apiOptions.apiData.publishDetails = { locales, environments };
}

asset.locales = locales;
asset.environments = environments;
apiOptions.uid = this.assetsUidMap[asset.uid] as string;
apiOptions.apiData.publishDetails = { locales, environments };

if (!apiOptions.uid) apiOptions.entity = undefined;

Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-cm-import": "~1.19.2",
"@contentstack/cli-cm-import": "~1.19.3",
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"@contentstack/management": "~1.18.3",
Expand All @@ -23,7 +23,7 @@
"@types/node": "^14.18.63",
"@types/tar": "^6.1.13",
"@types/tmp": "^0.2.6",
"axios": "^1.7.7",
"axios": "^1.7.8",
"eslint": "^8.57.1",
"eslint-config-oclif": "^4.0.0",
"eslint-config-oclif-typescript": "^3.1.12",
Expand Down
8 changes: 4 additions & 4 deletions packages/contentstack-utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"author": "contentstack",
"license": "MIT",
"dependencies": {
"@contentstack/management": "~1.18.0",
"@contentstack/marketplace-sdk": "^1.2.1",
"@contentstack/management": "~1.18.3",
"@contentstack/marketplace-sdk": "^1.2.4",
"@oclif/core": "^3.27.0",
"axios": "^1.7.4",
"axios": "^1.7.8",
"chalk": "^4.1.2",
"cli-cursor": "^3.1.0",
"cli-table": "^0.3.11",
Expand Down Expand Up @@ -65,7 +65,7 @@
"@types/chai": "^4.3.20",
"@types/inquirer": "^9.0.7",
"@types/mkdirp": "^1.0.2",
"@types/mocha": "^8.2.3",
"@types/mocha": "^10.0.10",
"@types/node": "^14.18.63",
"@types/sinon": "^10.0.20",
"@types/traverse": "^0.6.37",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-variants/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-variants",
"version": "1.1.2",
"version": "1.1.3",
"description": "Variants plugin",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
try {
this.apiClient.headers({ api_version: undefined });
const res = await this.apiClient.put<VariantEntryStruct>(endpoint, { entry: input });
const data = this.handleVariantAPIRes(res);
const data = await this.handleVariantAPIRes(res);

if (res.status >= 200 && res.status < 300) {
onSuccess(data);
Expand Down Expand Up @@ -238,7 +238,7 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
try {
this.apiClient.headers({ api_version: 3.2 });
const res = await this.apiClient.post<any>(endpoint, input);
const data = this.handleVariantAPIRes(res);
const data = await this.handleVariantAPIRes(res);

if (res.status >= 200 && res.status < 300) {
onSuccess(data);
Expand Down
16 changes: 8 additions & 8 deletions packages/contentstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli/1.31.0 darwin-arm64 node-v22.8.0
@contentstack/cli/1.32.0 darwin-arm64 node-v22.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -3812,7 +3812,7 @@ EXAMPLES
$ csdx plugins
```

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

## `csdx plugins:add PLUGIN`

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

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

## `csdx plugins:install PLUGIN`

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

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

## `csdx plugins:link PATH`

Expand Down Expand Up @@ -3966,7 +3966,7 @@ EXAMPLES
$ csdx plugins:link myplugin
```

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

## `csdx plugins:remove [PLUGIN]`

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

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

## `csdx plugins:uninstall [PLUGIN]`

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

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

## `csdx plugins:unlink [PLUGIN]`

Expand Down Expand Up @@ -4079,7 +4079,7 @@ DESCRIPTION
Update installed plugins.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/update.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.17/src/commands/plugins/update.ts)_

## `csdx tokens`

Expand Down
11 changes: 7 additions & 4 deletions packages/contentstack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli",
"description": "Command-line tool (CLI) to interact with Contentstack",
"version": "1.31.0",
"version": "1.32.0",
"author": "Contentstack",
"bin": {
"csdx": "./bin/run.js"
Expand Down Expand Up @@ -30,7 +30,7 @@
"@contentstack/cli-cm-export": "~1.14.1",
"@contentstack/cli-cm-clone": "~1.13.0",
"@contentstack/cli-cm-export-to-csv": "~1.7.3",
"@contentstack/cli-cm-import": "~1.19.2",
"@contentstack/cli-cm-import": "~1.19.3",
"@contentstack/cli-cm-migrate-rte": "~1.4.20",
"@contentstack/cli-cm-seed": "~1.10.0",
"@contentstack/cli-command": "~1.3.2",
Expand All @@ -39,7 +39,7 @@
"@contentstack/cli-migration": "~1.6.4",
"@contentstack/cli-utilities": "~1.8.0",
"@contentstack/management": "~1.18.3",
"@contentstack/cli-variants": "~1.1.2",
"@contentstack/cli-variants": "~1.1.3",
"@oclif/core": "^3.27.0",
"@oclif/plugin-help": "^5",
"@oclif/plugin-not-found": "^2.4.3",
Expand All @@ -50,6 +50,7 @@
"inquirer": "8.2.6",
"node-machine-id": "^1.1.12",
"open": "^8.4.2",
"semver": "^7.6.3",
"short-uuid": "^4.2.2",
"uuid": "^9.0.1",
"winston": "^3.17.0"
Expand All @@ -61,6 +62,7 @@
"@types/mkdirp": "^1.0.2",
"@types/mocha": "^8.2.3",
"@types/node": "^14.18.63",
"@types/semver": "^7.5.8",
"@types/sinon": "^10.0.20",
"chai": "^4.5.0",
"eslint": "^8.57.1",
Expand Down Expand Up @@ -153,7 +155,8 @@
"hooks": {
"prerun": [
"./lib/hooks/prerun/command-deprecation-check",
"./lib/hooks/prerun/default-rate-limit-check"
"./lib/hooks/prerun/default-rate-limit-check",
"./lib/hooks/prerun/latest-version-warning"
],
"init": [
"./lib/hooks/init/context-init",
Expand Down
58 changes: 58 additions & 0 deletions packages/contentstack/src/hooks/prerun/latest-version-warning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { cliux, configHandler, HttpClient, LoggerService } from '@contentstack/cli-utilities';
import * as semver from 'semver';
import { IVersionUpgradeCache, IVersionUpgradeWarningFrequency } from '../../interfaces';

const versionUpgradeWarningFrequency: IVersionUpgradeWarningFrequency = {
versionSyncDuration: 3 * 24 * 60 * 60 * 1000,
};
export default async function (_opts): Promise<void> {
const now = Date.now();
const today = new Date().toISOString().split('T')[0];
const logger: LoggerService = new LoggerService(process.env.CS_CLI_LOG_PATH || process.cwd(), 'cli-log');
let cache: IVersionUpgradeCache = { lastChecked: 0, lastWarnedDate: '', latestVersion: '' };

if (!configHandler.get('versionUpgradeWarningFrequency')) {
configHandler.set('versionUpgradeWarningFrequency', versionUpgradeWarningFrequency);
}
const versionUpgradeWarningFrequencyConfig: IVersionUpgradeWarningFrequency = configHandler.get(
'versionUpgradeWarningFrequency',
);

// Load cache if it exists
if (configHandler.get('versionUpgradeWarningCache')) {
cache = configHandler.get('versionUpgradeWarningCache');
}

// Perform update check if needed
const httpClient = new HttpClient();

if (now - cache.lastChecked > versionUpgradeWarningFrequencyConfig.versionSyncDuration) {
try {
const latestVersion = (await httpClient.get(`https://registry.npmjs.org/@contentstack/cli/latest`))?.data
?.version;
if (!latestVersion) {
logger.error('Failed to retrieve the latest version from the registry.');
return;
}
cache.latestVersion = latestVersion;
cache.lastChecked = now;

// Save updated cache
configHandler.set('versionUpgradeWarningCache', cache);
} catch (error) {
logger.error('Failed to check the latest version', error);
return;
}
}

// Show warning if an update is available and last warning was yesterday
if (semver.gt(cache.latestVersion, this.config.version) && cache.lastWarnedDate !== today) {
cliux.print(
`You are using version ${this.config.version}, but the latest version is ${cache.latestVersion}. Please update your CLI for the best experience.`,
{ color: 'yellow' },
);
// Update the last warned timestamp
cache.lastWarnedDate = today;
configHandler.set('versionUpgradeWarningCache', cache);
}
}
9 changes: 9 additions & 0 deletions packages/contentstack/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ export interface Context {
export interface CLIConfig extends Config {
context: Context;
}

export interface IVersionUpgradeCache {
lastChecked: number;
lastWarnedDate: string;
latestVersion: string;
}
export interface IVersionUpgradeWarningFrequency {
versionSyncDuration: number;
}
Loading

0 comments on commit 83410d1

Please sign in to comment.