Skip to content

Commit

Permalink
Merge pull request #1188 from contentstack/refactor/CS-42891
Browse files Browse the repository at this point in the history
fix: Marketplace private apps missing manifest data fix [CS-42891]
  • Loading branch information
antonyagustine authored Nov 30, 2023
2 parents 856aa59 + 28103a7 commit bfdd1ed
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 91 deletions.
65 changes: 22 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/contentstack-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -98,4 +98,4 @@
}
},
"repository": "https://github.com/contentstack/cli"
}
}
83 changes: 54 additions & 29 deletions packages/contentstack-export/src/export/modules/marketplace-apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>[];
private installedApps: Record<string, unknown>[];
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<ModuleClassParams, 'stackAPIClient' | 'moduleName'>) {
this.exportConfig = exportConfig;
this.httpClient = new HttpClient();
this.marketplaceAppConfig = exportConfig.modules.marketplace_apps;
this.listOfApps = [];
this.installedApps = [];
}

async start(): Promise<void> {
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions packages/contentstack-export/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"extends": "../tsconfig.json",
"include": ["./unit/**/*"]
}
"extends": "../tsconfig",
"compilerOptions": {
"noEmit": true,
"resolveJsonModule": true
},
"references": [
{"path": ".."}
]
}
Loading

0 comments on commit bfdd1ed

Please sign in to comment.