diff --git a/package-lock.json b/package-lock.json index b6d5c7324c..4790d01393 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2158,21 +2158,21 @@ } }, "node_modules/@oclif/test": { - "version": "2.3.30", - "resolved": "https://registry.npmjs.org/@oclif/test/-/test-2.3.30.tgz", - "integrity": "sha512-zuOv23wiF+H7cRGMjcKx/91qhdcNMcZnr+1TCpbyDeQBIvRs/nGWyuwfrmoF2fXs+HtNZsNFvwbjg7Ue5JfAug==", + "version": "2.5.6", + "resolved": "https://registry.npmjs.org/@oclif/test/-/test-2.5.6.tgz", + "integrity": "sha512-AcusFApdU6/akXaofhBDrY4IM9uYzlOD9bYCCM0NwUXOv1m6320hSp2DT/wkj9H1gsvKbJXZHqgtXsNGZTWLFg==", "dependencies": { - "@oclif/core": "^2.9.3", - "fancy-test": "^2.0.29" + "@oclif/core": "^2.15.0", + "fancy-test": "^2.0.42" }, "engines": { "node": ">=12.0.0" } }, "node_modules/@oclif/test/node_modules/fancy-test": { - "version": "2.0.30", - "resolved": "https://registry.npmjs.org/fancy-test/-/fancy-test-2.0.30.tgz", - "integrity": "sha512-bDQnAXYYODKwjb/6VEwAovEN0uJ1iRMTahEqOpQCRxIX7rIqoFHCy0LEqWYAU3kVw4ERgK4HQSn6GISEA1ipxg==", + "version": "2.0.42", + "resolved": "https://registry.npmjs.org/fancy-test/-/fancy-test-2.0.42.tgz", + "integrity": "sha512-TX8YTALYAmExny+f+G24MFxWry3Pk09+9uykwRjfwjibRxJ9ZjJzrnHYVBZK46XQdyli7d+rQc5U/KK7V6uLsw==", "dependencies": { "@types/chai": "*", "@types/lodash": "*", @@ -2180,7 +2180,7 @@ "@types/sinon": "*", "lodash": "^4.17.13", "mock-stdin": "^1.0.0", - "nock": "^13.3.2", + "nock": "^13.3.3", "stdout-stderr": "^0.1.9" }, "engines": { @@ -24331,7 +24331,7 @@ "@contentstack/cli-config": "~1.4.15", "@contentstack/cli-dev-dependencies": "~1.2.4", "@oclif/plugin-help": "^5.1.19", - "@oclif/test": "^1.2.6", + "@oclif/test": "^2.5.6", "@types/big-json": "^3.2.0", "@types/mkdirp": "^1.0.2", "@types/progress-stream": "^2.0.2", @@ -24765,18 +24765,6 @@ "node": ">=10" } }, - "packages/contentstack-export/node_modules/@oclif/test": { - "version": "1.2.9", - "resolved": "https://registry.npmjs.org/@oclif/test/-/test-1.2.9.tgz", - "integrity": "sha512-op+ak0NTyeBKqjLVH1jfPCRGWK5befIoQpCL/xwekjucUEmMfCbUpV1Sa60f9rU8X58HEqrclwWbAH+DtQR6FQ==", - "dev": true, - "dependencies": { - "fancy-test": "^1.4.10" - }, - "engines": { - "node": ">=8.0.0" - } - }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", "version": "1.12.1", @@ -25586,6 +25574,7 @@ "xdg-basedir": "^4.0.0" }, "devDependencies": { + "@contentstack/cli-dev-dependencies": "^1.2.4", "@oclif/test": "^2.2.10", "@types/chai": "^4.2.18", "@types/inquirer": "^9.0.3", @@ -28152,7 +28141,7 @@ "@contentstack/cli-utilities": "~1.5.9", "@oclif/core": "^2.9.3", "@oclif/plugin-help": "^5.1.19", - "@oclif/test": "^1.2.6", + "@oclif/test": "^2.5.6", "@types/big-json": "^3.2.0", "@types/mkdirp": "^1.0.2", "@types/progress-stream": "^2.0.2", @@ -28183,17 +28172,6 @@ "tslib": "^2.4.1", "typescript": "^4.9.3", "winston": "^3.7.2" - }, - "dependencies": { - "@oclif/test": { - "version": "1.2.9", - "resolved": "https://registry.npmjs.org/@oclif/test/-/test-1.2.9.tgz", - "integrity": "sha512-op+ak0NTyeBKqjLVH1jfPCRGWK5befIoQpCL/xwekjucUEmMfCbUpV1Sa60f9rU8X58HEqrclwWbAH+DtQR6FQ==", - "dev": true, - "requires": { - "fancy-test": "^1.4.10" - } - } } }, "@contentstack/cli-cm-export-to-csv": { @@ -29392,6 +29370,7 @@ "@contentstack/cli-utilities": { "version": "file:packages/contentstack-utilities", "requires": { + "@contentstack/cli-dev-dependencies": "^1.2.4", "@contentstack/management": "~1.13.0", "@contentstack/marketplace-sdk": "^1.0.0", "@oclif/core": "^2.9.3", @@ -31288,18 +31267,18 @@ } }, "@oclif/test": { - "version": "2.3.30", - "resolved": "https://registry.npmjs.org/@oclif/test/-/test-2.3.30.tgz", - "integrity": "sha512-zuOv23wiF+H7cRGMjcKx/91qhdcNMcZnr+1TCpbyDeQBIvRs/nGWyuwfrmoF2fXs+HtNZsNFvwbjg7Ue5JfAug==", + "version": "2.5.6", + "resolved": "https://registry.npmjs.org/@oclif/test/-/test-2.5.6.tgz", + "integrity": "sha512-AcusFApdU6/akXaofhBDrY4IM9uYzlOD9bYCCM0NwUXOv1m6320hSp2DT/wkj9H1gsvKbJXZHqgtXsNGZTWLFg==", "requires": { - "@oclif/core": "^2.9.3", - "fancy-test": "^2.0.29" + "@oclif/core": "^2.15.0", + "fancy-test": "^2.0.42" }, "dependencies": { "fancy-test": { - "version": "2.0.30", - "resolved": "https://registry.npmjs.org/fancy-test/-/fancy-test-2.0.30.tgz", - "integrity": "sha512-bDQnAXYYODKwjb/6VEwAovEN0uJ1iRMTahEqOpQCRxIX7rIqoFHCy0LEqWYAU3kVw4ERgK4HQSn6GISEA1ipxg==", + "version": "2.0.42", + "resolved": "https://registry.npmjs.org/fancy-test/-/fancy-test-2.0.42.tgz", + "integrity": "sha512-TX8YTALYAmExny+f+G24MFxWry3Pk09+9uykwRjfwjibRxJ9ZjJzrnHYVBZK46XQdyli7d+rQc5U/KK7V6uLsw==", "requires": { "@types/chai": "*", "@types/lodash": "*", @@ -31307,7 +31286,7 @@ "@types/sinon": "*", "lodash": "^4.17.13", "mock-stdin": "^1.0.0", - "nock": "^13.3.2", + "nock": "^13.3.3", "stdout-stderr": "^0.1.9" } } diff --git a/packages/contentstack-export/package.json b/packages/contentstack-export/package.json index 00bb3f7616..fab18d1cec 100644 --- a/packages/contentstack-export/package.json +++ b/packages/contentstack-export/package.json @@ -28,7 +28,7 @@ "@contentstack/cli-config": "~1.4.15", "@contentstack/cli-dev-dependencies": "~1.2.4", "@oclif/plugin-help": "^5.1.19", - "@oclif/test": "^1.2.6", + "@oclif/test": "^2.5.6", "@types/big-json": "^3.2.0", "@types/mkdirp": "^1.0.2", "@types/progress-stream": "^2.0.2", @@ -98,4 +98,4 @@ } }, "repository": "https://github.com/contentstack/cli" -} \ No newline at end of file +} diff --git a/packages/contentstack-export/src/export/modules/marketplace-apps.ts b/packages/contentstack-export/src/export/modules/marketplace-apps.ts index 7ae7da9be2..8cc2f65f3d 100644 --- a/packages/contentstack-export/src/export/modules/marketplace-apps.ts +++ b/packages/contentstack-export/src/export/modules/marketplace-apps.ts @@ -5,43 +5,42 @@ import entries from 'lodash/entries'; import isEmpty from 'lodash/isEmpty'; import { resolve as pResolve } from 'node:path'; import { - managementSDKClient, - isAuthenticated, + App, cliux, NodeCrypto, - HttpClientDecorator, - OauthDecorator, HttpClient, - ContentstackClient, + OauthDecorator, + isAuthenticated, + HttpClientDecorator, + marketplaceSDKClient, + ContentstackMarketplaceClient, } from '@contentstack/cli-utilities'; import { log, - getDeveloperHubUrl, + fsUtil, getOrgUid, - createNodeCryptoInstance, formatError, + getDeveloperHubUrl, getStackSpecificApps, - fsUtil, + createNodeCryptoInstance, } from '../../utils'; -import BaseClass from './base-class'; -import { ModuleClassParams, MarketplaceAppsConfig } from '../../types'; - -export default class ExportMarketplaceApps extends BaseClass { - private httpClient: OauthDecorator | HttpClientDecorator | HttpClient; - private marketplaceAppConfig: MarketplaceAppsConfig; - private listOfApps: Record[]; - private installedApps: Record[]; +import { ModuleClassParams, MarketplaceAppsConfig, ExportConfig } from '../../types'; + +export default class ExportMarketplaceApps { + protected httpClient: OauthDecorator | HttpClientDecorator | HttpClient; + protected marketplaceAppConfig: MarketplaceAppsConfig; + protected installedApps: App[] = []; public developerHubBaseUrl: string; public marketplaceAppPath: string; public nodeCrypto: NodeCrypto; + public appSdk: ContentstackMarketplaceClient; + public exportConfig: ExportConfig; - constructor({ exportConfig, stackAPIClient }: ModuleClassParams) { - super({ exportConfig, stackAPIClient }); + constructor({ exportConfig }: Omit) { + this.exportConfig = exportConfig; this.httpClient = new HttpClient(); this.marketplaceAppConfig = exportConfig.modules.marketplace_apps; - this.listOfApps = []; - this.installedApps = []; } async start(): Promise { @@ -64,9 +63,12 @@ export default class ExportMarketplaceApps extends BaseClass { this.developerHubBaseUrl = this.exportConfig.developerHubBaseUrl || (await getDeveloperHubUrl(this.exportConfig)); this.exportConfig.org_uid = await getOrgUid(this.exportConfig); + // NOTE init marketplace app sdk + const host = this.developerHubBaseUrl.split('://').pop(); + this.appSdk = await marketplaceSDKClient({ host }); + await this.setHttpClient(); await this.getAllStackSpecificApps(); - this.installedApps = this.listOfApps; await this.exportInstalledExtensions(); } @@ -101,7 +103,7 @@ export default class ExportMarketplaceApps extends BaseClass { return app; }); - this.listOfApps = [...this.listOfApps, ...stackApps]; + this.installedApps = this.installedApps.concat(stackApps); if (count - (skip + 50) > 0) { return await this.getAllStackSpecificApps(skip + 50); @@ -112,6 +114,12 @@ export default class ExportMarketplaceApps extends BaseClass { if (isEmpty(this.installedApps)) { log(this.exportConfig, 'No marketplace apps found', 'info'); } else { + for (const [index, app] of entries(this.installedApps)) { + if (app.manifest.visibility === 'private') { + await this.getPrivateAppsManifest(+index, app); + } + } + for (const [index, app] of entries(this.installedApps)) { await this.getAppConfigurations(+index, app); } @@ -122,17 +130,34 @@ export default class ExportMarketplaceApps extends BaseClass { } } + /** + * The function `getPrivateAppsManifest` fetches the manifest of a private app and assigns it to the + * `manifest` property of the corresponding installed app. + * @param {number} index - The `index` parameter is a number that represents the position of the app + * in an array or list. It is used to identify the specific app in the `installedApps` array. + * @param {App} appInstallation - The `appInstallation` parameter is an object that represents the + * installation details of an app. It contains information such as the UID (unique identifier) of the + * app's manifest. + */ + async getPrivateAppsManifest(index: number, appInstallation: App) { + const manifest = await this.appSdk + .marketplace(this.exportConfig.org_uid) + .app(appInstallation.manifest.uid) + .fetch({ include_oauth: true }) + .catch((error) => { + log(this.exportConfig, error, 'error'); + }); + + this.installedApps[index].manifest = manifest; + } + async getAppConfigurations(index: number, appInstallation: any) { - const sdkClient: ContentstackClient = await managementSDKClient({ - host: this.developerHubBaseUrl.split('://').pop(), - }); const appName = appInstallation?.manifest?.name; log(this.exportConfig, `Exporting ${appName} app and it's config.`, 'info'); - await sdkClient - .organization(this.exportConfig.org_uid) - .app(appInstallation?.manifest?.uid) - .installation(appInstallation?.uid) + await this.appSdk + .marketplace(this.exportConfig.org_uid) + .installation(appInstallation.uid) .installationData() .then(async (result: any) => { const { data, error } = result; diff --git a/packages/contentstack-export/test/tsconfig.json b/packages/contentstack-export/test/tsconfig.json index 5de9d8e61a..a0f0f6893f 100644 --- a/packages/contentstack-export/test/tsconfig.json +++ b/packages/contentstack-export/test/tsconfig.json @@ -1,4 +1,10 @@ { - "extends": "../tsconfig.json", - "include": ["./unit/**/*"] -} \ No newline at end of file + "extends": "../tsconfig", + "compilerOptions": { + "noEmit": true, + "resolveJsonModule": true + }, + "references": [ + {"path": ".."} + ] +} diff --git a/packages/contentstack-export/test/unit/export/modules/marketplace-apps.test.ts b/packages/contentstack-export/test/unit/export/modules/marketplace-apps.test.ts new file mode 100644 index 0000000000..42eec52769 --- /dev/null +++ b/packages/contentstack-export/test/unit/export/modules/marketplace-apps.test.ts @@ -0,0 +1,237 @@ +import { expect } from '@oclif/test'; +import { App, FsUtility, marketplaceSDKClient } from '@contentstack/cli-utilities'; +import { fancy } from '@contentstack/cli-dev-dependencies'; + +import defaultConfig from '../../../../src/config'; +import * as logUtil from '../../../../src/utils/logger'; +import * as utilities from '@contentstack/cli-utilities'; +import ExportConfig from '../../../../lib/types/export-config'; +import * as appUtility from '../../../../src/utils/marketplace-app-helper'; +import ExportMarketplaceApps from '../../../../src/export/modules/marketplace-apps'; + +describe('ExportMarketplaceApps class', () => { + const exportConfig: ExportConfig = Object.assign(defaultConfig, { + data: './', + exportDir: './', + apiKey: 'TST-API-KEY', + master_locale: { code: 'en-us' }, + forceStopMarketplaceAppsPrompt: false, + developerHubBaseUrl: 'https://test-apps.io', // NOTE dummy url + }) as ExportConfig; + const host = 'test-app.io'; + + describe('start method', () => { + fancy + .stub(utilities, 'isAuthenticated', () => true) + .stub(utilities, 'log', () => {}) + .stub(FsUtility.prototype, 'makeDirectory', () => {}) + .stub(appUtility, 'getOrgUid', () => 'ORG-UID') + .stub(ExportMarketplaceApps.prototype, 'setHttpClient', () => {}) + .stub(ExportMarketplaceApps.prototype, 'getAllStackSpecificApps', () => {}) + .stub(ExportMarketplaceApps.prototype, 'exportInstalledExtensions', () => {}) + .spy(appUtility, 'getOrgUid') + .spy(ExportMarketplaceApps.prototype, 'setHttpClient') + .spy(ExportMarketplaceApps.prototype, 'getAllStackSpecificApps') + .spy(ExportMarketplaceApps.prototype, 'exportInstalledExtensions') + .it('should trigger start method', async ({ spy }) => { + const marketplaceApps = new ExportMarketplaceApps({ exportConfig }); + await marketplaceApps.start(); + + expect(spy.getOrgUid.callCount).to.be.equals(1); + expect(spy.setHttpClient.callCount).to.be.equals(1); + expect(spy.getAllStackSpecificApps.callCount).to.be.equals(1); + expect(spy.exportInstalledExtensions.callCount).to.be.equals(1); + }); + }); + + describe('getAllStackSpecificApps method', () => { + fancy + .stub(appUtility, 'getStackSpecificApps', () => ({ data: [], count: 0 })) + .spy(appUtility, 'getStackSpecificApps') + .it('should get call getStackSpecificApps to get stack specific apps', async ({ spy }) => { + const marketplaceApps = new ExportMarketplaceApps({ exportConfig }); + await marketplaceApps.getAllStackSpecificApps(); + + expect(spy.getStackSpecificApps.callCount).to.be.equals(1); + expect( + spy.getStackSpecificApps.calledWithExactly({ + developerHubBaseUrl: marketplaceApps.developerHubBaseUrl, + config: marketplaceApps.exportConfig, + skip: 0, + }), + ).to.be.true; + }); + + fancy + .stub(appUtility, 'getStackSpecificApps', () => ({ + data: [{ uid: 'UID', name: 'TEST-APP', configuration: { id: 'test' } }], + count: 51, + })) + .stub(appUtility, 'createNodeCryptoInstance', () => ({ encrypt: (val: any) => val })) + .spy(appUtility, 'getStackSpecificApps') + .spy(appUtility, 'createNodeCryptoInstance') + .it('should paginate and get all the apps', async ({ spy }) => { + const marketplaceApps = new ExportMarketplaceApps({ exportConfig }); + marketplaceApps.developerHubBaseUrl = defaultConfig.developerHubBaseUrl; + await marketplaceApps.getAllStackSpecificApps(); + + expect(spy.getStackSpecificApps.callCount).to.be.equals(2); + expect(spy.createNodeCryptoInstance.callCount).to.be.equals(1); + expect( + spy.getStackSpecificApps.calledWith({ + developerHubBaseUrl: marketplaceApps.developerHubBaseUrl, + config: marketplaceApps.exportConfig, + skip: 50, + }), + ).to.be.true; + }); + }); + + describe('exportInstalledExtensions method', () => { + fancy + .stub(logUtil, 'log', () => {}) + .stub(FsUtility.prototype, 'writeFile', () => {}) + .spy(logUtil, 'log') + .it("should log info 'No marketplace apps found'", async ({ spy }) => { + const marketplaceApps = new ExportMarketplaceApps({ exportConfig }); + await marketplaceApps.exportInstalledExtensions(); + + expect(spy.log.callCount).to.be.equals(1); + expect(spy.log.calledWith(marketplaceApps.exportConfig, 'No marketplace apps found', 'info')).to.be.true; + }); + + fancy + .stub(logUtil, 'log', () => {}) + .stub(FsUtility.prototype, 'writeFile', () => {}) + .stub(ExportMarketplaceApps.prototype, 'getPrivateAppsManifest', () => {}) + .stub(ExportMarketplaceApps.prototype, 'getAppConfigurations', () => {}) + .spy(logUtil, 'log') + .spy(FsUtility.prototype, 'writeFile') + .spy(ExportMarketplaceApps.prototype, 'getPrivateAppsManifest') + .spy(ExportMarketplaceApps.prototype, 'getAppConfigurations') + .it('should export all the apps configuration and manifest if private apps', async ({ spy, stdout }) => { + class MPApps extends ExportMarketplaceApps { + protected installedApps = [ + { uid: 'UID', name: 'TEST-APP', configuration: { id: 'test' }, manifest: { visibility: 'private' } }, + ] as unknown as App[]; + protected marketplaceAppConfig = { + dirName: 'test', + fileName: 'mp-apps.json', + }; + } + const marketplaceApps = new MPApps({ exportConfig }); + marketplaceApps.marketplaceAppPath = './'; + await marketplaceApps.exportInstalledExtensions(); + + expect(spy.getPrivateAppsManifest.callCount).to.be.equals(1); + expect(spy.getAppConfigurations.callCount).to.be.equals(1); + expect( + spy.log.calledWith( + marketplaceApps.exportConfig, + 'All the marketplace apps have been exported successfully', + 'info', + ), + ).to.be.true; + }); + }); + + describe('getPrivateAppsManifest method', () => { + fancy + .nock(`https://${host}`, (api) => + api + .get(`/manifests/UID?include_oauth=true`) + .reply(200, { data: { uid: 'UID', visibility: 'private', config: 'test' } }), + ) + .it("should log info 'No marketplace apps found'", async () => { + class MPApps extends ExportMarketplaceApps { + public installedApps = [ + { + uid: 'UID', + name: 'TEST-APP', + configuration: { id: 'test' }, + manifest: { uid: 'UID', visibility: 'private' }, + }, + ] as unknown as App[]; + } + const marketplaceApps = new MPApps({ exportConfig }); + marketplaceApps.exportConfig.org_uid = 'ORG-UID'; + marketplaceApps.appSdk = await marketplaceSDKClient({ host }); + await marketplaceApps.getPrivateAppsManifest(0, { manifest: { uid: 'UID' } } as unknown as App); + + expect(marketplaceApps.installedApps[0].manifest.config).to.be.include('test'); + }); + }); + + describe('getAppConfigurations method', () => { + fancy + .stub(logUtil, 'log', () => {}) + .stub(appUtility, 'createNodeCryptoInstance', () => ({ encrypt: (val: any) => val })) + .nock(`https://${host}`, (api) => + api + .get(`/installations/UID/installationData`) + .reply(200, { data: { uid: 'UID', visibility: 'private', server_configuration: 'test-config' } }), + ) + .it('should get all apps installationData', async () => { + class MPApps extends ExportMarketplaceApps { + public installedApps = [ + { + uid: 'UID', + name: 'TEST-APP', + configuration: { id: 'test' }, + manifest: { uid: 'UID', visibility: 'private' }, + }, + ] as unknown as App[]; + } + const marketplaceApps = new MPApps({ exportConfig }); + marketplaceApps.exportConfig.org_uid = 'ORG-UID'; + marketplaceApps.appSdk = await marketplaceSDKClient({ host }); + await marketplaceApps.getAppConfigurations(0, { uid: 'UID', manifest: { name: 'TEST-APP' } } as unknown as App); + + expect(marketplaceApps.installedApps[0].server_configuration).to.be.include('test-config'); + }); + + fancy + .stub(logUtil, 'log', () => {}) + .spy(logUtil, 'log') + .nock(`https://${host}`, (api) => + api.get(`/installations/UID/installationData`).reply(200, { error: 'API is broken' }), + ) + .it('should log error message if no config received from API/SDK', async ({ spy }) => { + class MPApps extends ExportMarketplaceApps { + public installedApps = [ + { + uid: 'UID', + name: 'TEST-APP', + configuration: { id: 'test' }, + manifest: { uid: 'UID', visibility: 'private' }, + }, + ] as unknown as App[]; + } + const marketplaceApps = new MPApps({ exportConfig }); + marketplaceApps.exportConfig.org_uid = 'ORG-UID'; + marketplaceApps.appSdk = await marketplaceSDKClient({ host }); + await marketplaceApps.getAppConfigurations(0, { uid: 'UID', manifest: { name: 'TEST-APP' } } as unknown as App); + + expect(spy.log.calledWith(marketplaceApps.exportConfig, 'API is broken', 'error')).to.be.true; + }); + + fancy + .stub(logUtil, 'log', () => {}) + .spy(logUtil, 'log') + .nock(`https://${host}`, (api) => + api.get(`/installations/UID/installationData`).reply(500, { error: 'API is broken' }), + ) + .it('should catch API/SDK error and log', async ({ spy }) => { + const marketplaceApps = new ExportMarketplaceApps({ exportConfig }); + marketplaceApps.exportConfig.org_uid = 'ORG-UID'; + marketplaceApps.appSdk = await marketplaceSDKClient({ host }); + await marketplaceApps.getAppConfigurations(0, { + uid: 'UID', + manifest: { name: 'TEST-APP' }, + } as unknown as App); + + const [, errorObj]: any = spy.log.args[spy.log.args.length - 1]; + expect(errorObj.error).to.be.include('API is broken'); + }); + }); +}); diff --git a/packages/contentstack-utilities/package.json b/packages/contentstack-utilities/package.json index 368c5126ac..3fef594c9b 100644 --- a/packages/contentstack-utilities/package.json +++ b/packages/contentstack-utilities/package.json @@ -58,6 +58,7 @@ "xdg-basedir": "^4.0.0" }, "devDependencies": { + "@contentstack/cli-dev-dependencies": "^1.2.4", "@oclif/test": "^2.2.10", "@types/chai": "^4.2.18", "@types/inquirer": "^9.0.3", diff --git a/packages/contentstack-utilities/src/contentstack-marketplace-sdk.ts b/packages/contentstack-utilities/src/contentstack-marketplace-sdk.ts index 11ad0767bb..f3e8f712f8 100644 --- a/packages/contentstack-utilities/src/contentstack-marketplace-sdk.ts +++ b/packages/contentstack-utilities/src/contentstack-marketplace-sdk.ts @@ -1,4 +1,5 @@ import { Agent } from 'node:https'; +import { App } from '@contentstack/marketplace-sdk/types/marketplace/app'; import { client, ContentstackConfig, ContentstackClient, ContentstackToken } from '@contentstack/marketplace-sdk'; import authHandler from './auth-handler'; @@ -8,6 +9,8 @@ type ConfigType = Pick { if (error?.response?.status) { - switch (error.response.status) { - case 401: - case 429: - case 408: - return true; - default: - return false; + if ([408].includes(error.response.status)) { + return true; + } else { + return false; } } }, @@ -133,6 +133,6 @@ class MarketplaceSDKInitiator { export const marketplaceSDKInitiator = new MarketplaceSDKInitiator(); const marketplaceSDKClient: typeof marketplaceSDKInitiator.createAppSDKClient = marketplaceSDKInitiator.createAppSDKClient.bind(marketplaceSDKInitiator); -export { MarketplaceSDKInitiator, ContentstackConfig, ContentstackClient }; +export { App, MarketplaceSDKInitiator, ContentstackMarketplaceConfig, ContentstackMarketplaceClient }; export default marketplaceSDKClient; diff --git a/packages/contentstack-utilities/src/index.ts b/packages/contentstack-utilities/src/index.ts index b0efed3d61..fe5094f6bc 100644 --- a/packages/contentstack-utilities/src/index.ts +++ b/packages/contentstack-utilities/src/index.ts @@ -1,5 +1,11 @@ import Logger from './logger'; -import marketplaceSDKClient, { MarketplaceSDKInitiator, marketplaceSDKInitiator } from './contentstack-marketplace-sdk'; +import marketplaceSDKClient, { + App, + MarketplaceSDKInitiator, + marketplaceSDKInitiator, + ContentstackMarketplaceClient, + ContentstackMarketplaceConfig, +} from './contentstack-marketplace-sdk'; export { LoggerService } from './logger'; export { default as cliux } from './cli-ux'; @@ -24,7 +30,14 @@ export * from './date-time'; export * from './add-locale'; // Marketplace SDK export -export { marketplaceSDKClient, MarketplaceSDKInitiator, marketplaceSDKInitiator }; +export { + App, + marketplaceSDKClient, + MarketplaceSDKInitiator, + marketplaceSDKInitiator, + ContentstackMarketplaceClient, + ContentstackMarketplaceConfig, +}; // NOTE Exporting all @oclif/core modules: So that all the module can be acessed through cli-utility export { diff --git a/packages/contentstack/src/hooks/init/utils-init.ts b/packages/contentstack/src/hooks/init/utils-init.ts index 94ff1e5bcb..a532d07909 100644 --- a/packages/contentstack/src/hooks/init/utils-init.ts +++ b/packages/contentstack/src/hooks/init/utils-init.ts @@ -1,12 +1,12 @@ -import { messageHandler, cliux, managementSDKInitiator } from '@contentstack/cli-utilities'; +import { messageHandler, cliux, managementSDKInitiator, marketplaceSDKInitiator } from '@contentstack/cli-utilities'; /** * Initialize the utilities */ export default function (_opts): void { const { context } = this.config; - // logger.init(context); messageHandler.init(context); cliux.init(context); managementSDKInitiator.init(context); + marketplaceSDKInitiator.init(context); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b9571a3e95..f7b74a6531 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -607,7 +607,7 @@ importers: '@contentstack/cli-utilities': ~1.5.9 '@oclif/core': ^2.9.3 '@oclif/plugin-help': ^5.1.19 - '@oclif/test': ^1.2.6 + '@oclif/test': ^2.5.6 '@types/big-json': ^3.2.0 '@types/mkdirp': ^1.0.2 '@types/progress-stream': ^2.0.2 @@ -661,7 +661,7 @@ importers: '@contentstack/cli-config': link:../contentstack-config '@contentstack/cli-dev-dependencies': link:../contentstack-dev-dependencies '@oclif/plugin-help': 5.2.14_typescript@4.9.5 - '@oclif/test': 1.2.9 + '@oclif/test': 2.5.6_typescript@4.9.5 '@types/big-json': 3.2.0 '@types/mkdirp': 1.0.2 '@types/progress-stream': 2.0.2 @@ -1037,6 +1037,7 @@ importers: packages/contentstack-utilities: specifiers: + '@contentstack/cli-dev-dependencies': ^1.2.4 '@contentstack/management': ~1.13.0 '@contentstack/marketplace-sdk': ^1.0.0 '@oclif/core': ^2.9.3 @@ -1110,6 +1111,7 @@ importers: winston: 3.10.0 xdg-basedir: 4.0.0 devDependencies: + '@contentstack/cli-dev-dependencies': link:../contentstack-dev-dependencies '@oclif/test': 2.3.31_4qcp7qp4jxxdgb4qbxgwox4hwq '@types/chai': 4.3.5 '@types/inquirer': 9.0.3 @@ -3200,6 +3202,20 @@ packages: - typescript dev: true + /@oclif/test/2.5.6_typescript@4.9.5: + resolution: {integrity: sha512-AcusFApdU6/akXaofhBDrY4IM9uYzlOD9bYCCM0NwUXOv1m6320hSp2DT/wkj9H1gsvKbJXZHqgtXsNGZTWLFg==} + engines: {node: '>=12.0.0'} + dependencies: + '@oclif/core': 2.15.0_typescript@4.9.5 + fancy-test: 2.0.42 + transitivePeerDependencies: + - '@swc/core' + - '@swc/wasm' + - '@types/node' + - supports-color + - typescript + dev: true + /@octokit/auth-token/2.5.0: resolution: {integrity: sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==} dependencies: @@ -6822,6 +6838,22 @@ packages: transitivePeerDependencies: - supports-color + /fancy-test/2.0.42: + resolution: {integrity: sha512-TX8YTALYAmExny+f+G24MFxWry3Pk09+9uykwRjfwjibRxJ9ZjJzrnHYVBZK46XQdyli7d+rQc5U/KK7V6uLsw==} + engines: {node: '>=12.0.0'} + dependencies: + '@types/chai': 4.3.6 + '@types/lodash': 4.14.195 + '@types/node': 20.6.5 + '@types/sinon': 10.0.15 + lodash: 4.17.21 + mock-stdin: 1.0.0 + nock: 13.4.0 + stdout-stderr: 0.1.13 + transitivePeerDependencies: + - supports-color + dev: true + /fast-csv/4.3.6: resolution: {integrity: sha512-2RNSpuwwsJGP0frGsOmTb9oUF+VkFSM4SyLTDgwf2ciHWTarN0lQTC+F2f/t5J9QjW+c65VFIAAu85GsvMIusw==} engines: {node: '>=10.0.0'} @@ -10003,6 +10035,17 @@ packages: transitivePeerDependencies: - supports-color + /nock/13.4.0: + resolution: {integrity: sha512-W8NVHjO/LCTNA64yxAPHV/K47LpGYcVzgKd3Q0n6owhwvD0Dgoterc25R4rnZbckJEb6Loxz1f5QMuJpJnbSyQ==} + engines: {node: '>= 10.13'} + dependencies: + debug: 4.3.4 + json-stringify-safe: 5.0.1 + propagate: 2.0.1 + transitivePeerDependencies: + - supports-color + dev: true + /node-fetch/2.6.12: resolution: {integrity: sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==} engines: {node: 4.x || >=6.0.0}