diff --git a/packages/contentstack-export/src/export/modules-js/marketplace-apps.js b/packages/contentstack-export/src/export/modules-js/marketplace-apps.js index a9b94e09d7..d4b6c0cb42 100644 --- a/packages/contentstack-export/src/export/modules-js/marketplace-apps.js +++ b/packages/contentstack-export/src/export/modules-js/marketplace-apps.js @@ -44,7 +44,9 @@ module.exports = class ExportMarketplaceApps { } this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config)); - + this.appSdkAxiosInstance = await managementSDKClient({ + host: this.developerHubBaseUrl.split('://').pop() + }); await this.getOrgUid(); const httpClient = new HttpClient(); @@ -65,7 +67,7 @@ module.exports = class ExportMarketplaceApps { ); mkdirp.sync(this.marketplaceAppPath); - this.nodeCrypto= await createNodeCryptoInstance(config); + this.nodeCrypto = await createNodeCryptoInstance(config); return this.exportInstalledExtensions(); } @@ -106,8 +108,12 @@ module.exports = class ExportMarketplaceApps { } getAllStackSpecificApps(listOfApps = [], skip = 0) { - return this.httpClient - .get(`${this.developerHubBaseUrl}/installations?target_uids=${this.config.source_stack}&skip=${skip}`) + return this.appSdkAxiosInstance.axiosInstance + .get(`/installations?target_uids=${this.config.source_stack}&skip=${skip}`, { + headers: { + organization_uid: this.config.org_uid + }, + }) .then(async ({ data }) => { const { data: apps, count } = data; @@ -161,9 +167,9 @@ module.exports = class ExportMarketplaceApps { } else if (error) { log(this.config, `Error on exporting ${appName} app and it's config.`, 'error'); } - }) - .catch(err => { - log(this.config, `Failed to export ${appName} app config ${formatError(err)}`, 'error'); - }) + }) + .catch((err) => { + log(this.config, `Failed to export ${appName} app config ${formatError(err)}`, 'error'); + }); } }; diff --git a/packages/contentstack-export/src/utils/marketplace-app-helper.ts b/packages/contentstack-export/src/utils/marketplace-app-helper.ts index 387208ab06..35752d4820 100644 --- a/packages/contentstack-export/src/utils/marketplace-app-helper.ts +++ b/packages/contentstack-export/src/utils/marketplace-app-helper.ts @@ -3,7 +3,6 @@ import { cliux, configHandler, NodeCrypto, HttpClient, managementSDKClient } fro import { formatError, log } from '../utils'; import { ExportConfig } from '../types'; import { askDeveloperHub } from './interactive'; - export const getDeveloperHubUrl = async (exportConfig: ExportConfig) => { const { cma, name } = configHandler.get('region') || {}; let developerHubBaseUrl = exportConfig?.developerHubUrls[cma]; @@ -56,8 +55,15 @@ export const getStackSpecificApps = async (params: { skip: number; }) => { const { developerHubBaseUrl, httpClient, config, skip } = params; - return httpClient - .get(`${developerHubBaseUrl}/installations?target_uids=${config.source_stack}&skip=${skip}`) + const appSdkAxiosInstance = await managementSDKClient({ + host: developerHubBaseUrl.split('://').pop() + }); + return appSdkAxiosInstance.axiosInstance + .get(`${developerHubBaseUrl}/installations?target_uids=${config.source_stack}&skip=${skip}`, { + headers: { + organization_uid: config.org_uid, + }, + }) .then((data: any) => data.data) .catch((error: any) => log(config, `Failed to export marketplace-apps ${formatError(error)}`, 'error')); }; diff --git a/packages/contentstack-import/src/import/modules-js/marketplace-apps.js b/packages/contentstack-import/src/import/modules-js/marketplace-apps.js index 0537576c01..f0af583cc8 100644 --- a/packages/contentstack-import/src/import/modules-js/marketplace-apps.js +++ b/packages/contentstack-import/src/import/modules-js/marketplace-apps.js @@ -61,7 +61,9 @@ module.exports = class ImportMarketplaceApps { this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config)); this.client = await managementSDKClient({ endpoint: this.developerHubBaseUrl }); - + this.appSdkAxiosInstance = await managementSDKClient({ + host: this.developerHubBaseUrl.split('://').pop() + }); await this.getOrgUid(); const httpClient = new HttpClient(); @@ -519,9 +521,12 @@ module.exports = class ImportMarketplaceApps { if (_.isEmpty(app) || _.isEmpty(payload) || !uid) { return Promise.resolve(); } - - return this.httpClient - .put(`${this.developerHubBaseUrl}/installations/${uid}`, payload) + return this.appSdkAxiosInstance.axiosInstance + .put(`${this.developerHubBaseUrl}/installations/${uid}`, payload, { + headers: { + organization_uid: this.config.org_uid + }, + }) .then(({ data }) => { if (data.message) { log(this.config, formatError(data.message), 'success'); diff --git a/packages/contentstack-import/src/import/modules/marketplace-apps.ts b/packages/contentstack-import/src/import/modules/marketplace-apps.ts index e72f6a614a..63869e6cc7 100644 --- a/packages/contentstack-import/src/import/modules/marketplace-apps.ts +++ b/packages/contentstack-import/src/import/modules/marketplace-apps.ts @@ -55,7 +55,7 @@ export default class ImportMarketplaceApps extends BaseClass { public developerHubBaseUrl: string; public sdkClient: ContentstackClient; public nodeCrypto: NodeCrypto; - + public appSdkAxiosInstance: any constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); @@ -100,6 +100,9 @@ export default class ImportMarketplaceApps extends BaseClass { await fsUtil.makeDirectory(this.mapperDirPath); this.developerHubBaseUrl = this.importConfig.developerHubBaseUrl || (await getDeveloperHubUrl(this.importConfig)); this.sdkClient = await managementSDKClient({ endpoint: this.developerHubBaseUrl }); + this.appSdkAxiosInstance = await managementSDKClient({ + host: this.developerHubBaseUrl.split('://').pop() + }); this.importConfig.org_uid = await getOrgUid(this.importConfig); await this.setHttpClient(); await this.startInstallation(); @@ -403,15 +406,19 @@ export default class ImportMarketplaceApps extends BaseClass { // TODO migrate this HTTP API call into SDK // NOTE Use updateAppConfig(this.sdkClient, this.importConfig, app, payload) utility when migrating to SDK call; - return this.httpClient - .put(`${this.developerHubBaseUrl}/installations/${uid}`, payload) - .then(({ data }) => { - if (data.message) { + return this.appSdkAxiosInstance.axiosInstance + .put(`${this.developerHubBaseUrl}/installations/${uid}`, payload, { + headers: { + organization_uid: this.importConfig.org_uid, + }, + }) + .then(({data}:any) => { + if (data?.message) { log(this.importConfig, formatError(data.message), 'success'); } else { log(this.importConfig, `${app.manifest.name} app config updated successfully.!`, 'success'); } }) - .catch((error) => log(this.importConfig, formatError(error), 'error')); + .catch((error:any) => log(this.importConfig, formatError(error), 'error')); } } diff --git a/packages/contentstack-import/src/utils/marketplace-app-helper.ts b/packages/contentstack-import/src/utils/marketplace-app-helper.ts index 5e14ddd69b..3f643472ca 100644 --- a/packages/contentstack-import/src/utils/marketplace-app-helper.ts +++ b/packages/contentstack-import/src/utils/marketplace-app-helper.ts @@ -16,10 +16,17 @@ export const getAllStackSpecificApps = async ( httpClient: HttpClient, config: ImportConfig, ) => { - return await httpClient - .get(`${developerHubBaseUrl}/installations?target_uids=${config.target_stack}`) - .then(({ data }) => data.data) - .catch((error) => log(config, `Failed to export marketplace-apps ${formatError(error)}`, 'error')); + const appSdkAxiosInstance = await managementSDKClient({ + host: developerHubBaseUrl.split('://').pop() + }); + return await appSdkAxiosInstance.axiosInstance + .get(`${developerHubBaseUrl}/installations?target_uids=${config.target_stack}`, { + headers: { + organization_uid: config.org_uid, + }, + }) + .then(( {data}:any) => data.data) + .catch((error:any) => log(config, `Failed to export marketplace-apps ${formatError(error)}`, 'error')); }; export const getDeveloperHubUrl = async (config: ImportConfig): Promise => {