Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/contentstack/cli int…
Browse files Browse the repository at this point in the history
…o feat/CS-41076
  • Loading branch information
antonyagustine committed Sep 27, 2023
2 parents 9b5938e + cd93a81 commit 6754809
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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');
});
}
};
12 changes: 9 additions & 3 deletions packages/contentstack-export/src/utils/marketplace-app-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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'));
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash/isEmpty';
import values from 'lodash/values';
import { join, resolve } from 'node:path';
import { join } from 'node:path';

import { log, formatError, fsUtil, fileHelper } from '../../utils';
import BaseClass, { ApiOptions } from './base-class';
Expand Down Expand Up @@ -118,7 +118,7 @@ export default class ImportCustomRoles extends BaseClass {
async importCustomRoles() {
if (this.customRoles === undefined || isEmpty(this.customRoles)) {
log(this.importConfig, 'No custom-roles found', 'info');
return resolve();
return;
}

const apiContent = values(this.customRoles);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash/isEmpty';
import values from 'lodash/values';
import { join, resolve } from 'node:path';
import { join } from 'node:path';

import { log, formatError, fsUtil, fileHelper } from '../../utils';
import BaseClass, { ApiOptions } from './base-class';
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class ImportEnvironments extends BaseClass {
async importEnvironments() {
if (this.environments === undefined || isEmpty(this.environments)) {
log(this.importConfig, 'No Environment Found', 'info');
return resolve();
return;
}

const apiContent = values(this.environments);
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-import/src/import/modules/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash/isEmpty';
import values from 'lodash/values';
import { join, resolve } from 'node:path';
import { join } from 'node:path';

import { log, formatError, fsUtil, fileHelper } from '../../utils';
import BaseClass, { ApiOptions } from './base-class';
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class ImportExtensions extends BaseClass {
async importExtensions(): Promise<any> {
if (this.extensions === undefined || isEmpty(this.extensions)) {
log(this.importConfig, 'No Extensions Found', 'info');
return resolve();
return;
}

const apiContent = values(this.extensions);
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-import/src/import/modules/labels.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import isEmpty from 'lodash/isEmpty';
import values from 'lodash/values';
import omit from 'lodash/omit';
import { join, resolve } from 'node:path';
import { join } from 'node:path';

import { log, formatError, fsUtil, fileHelper } from '../../utils';
import BaseClass, { ApiOptions } from './base-class';
Expand Down Expand Up @@ -72,7 +72,7 @@ export default class Importlabels extends BaseClass {
async importlabels() {
if (this.labels === undefined || isEmpty(this.labels)) {
log(this.importConfig, 'No Label Found', 'info');
return resolve();
return;
}

const apiContent = values(this.labels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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'));
}
}
4 changes: 2 additions & 2 deletions packages/contentstack-import/src/import/modules/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash/isEmpty';
import values from 'lodash/values';
import { join, resolve } from 'node:path';
import { join } from 'node:path';

import { log, formatError, fsUtil, fileHelper } from '../../utils';
import BaseClass, { ApiOptions } from './base-class';
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class ImportWebhooks extends BaseClass {
async importWebhooks() {
if (this.webhooks === undefined || isEmpty(this.webhooks)) {
log(this.importConfig, 'No Webhook Found', 'info');
return resolve();
return;
}

const apiContent = values(this.webhooks);
Expand Down
15 changes: 11 additions & 4 deletions packages/contentstack-import/src/utils/marketplace-app-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
Expand Down

0 comments on commit 6754809

Please sign in to comment.