Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Notify Marketplace on App Install #27925

Merged
merged 5 commits into from Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/meteor/app/apps/server/communication/rest.js
Expand Up @@ -12,6 +12,7 @@ import { Apps } from '../orchestrator';
import { formatAppInstanceForRest } from '../../lib/misc/formatAppInstanceForRest';
import { actionButtonsHandler } from './endpoints/actionButtonsHandler';
import { fetch } from '../../../../server/lib/http/fetch';
import { notifyAppInstall } from '../marketplace/appInstall';

const rocketChatVersion = Info.version;
const appsEngineVersionForMarketplace = Info.marketplaceApiVersion.replace(/-.*/g, '');
Expand Down Expand Up @@ -273,6 +274,8 @@ export class AppsRestApi {

info.status = aff.getApp().getStatus();

notifyAppInstall(orchestrator.getMarketplaceUrl(), 'install', info);

return API.v1.success({
app: info,
implemented: aff.getImplementedInferfaces(),
Expand Down Expand Up @@ -558,6 +561,8 @@ export class AppsRestApi {

info.status = aff.getApp().getStatus();

notifyAppInstall(orchestrator.getMarketplaceUrl(), 'update', info);

return API.v1.success({
app: info,
implemented: aff.getImplementedInferfaces(),
Expand All @@ -578,6 +583,8 @@ export class AppsRestApi {
const info = prl.getInfo();
info.status = prl.getStatus();

notifyAppInstall(orchestrator.getMarketplaceUrl(), 'uninstall', info);

return API.v1.success({ app: info });
},
},
Expand Down
46 changes: 46 additions & 0 deletions apps/meteor/app/apps/server/marketplace/appInstall.ts
@@ -0,0 +1,46 @@
import type { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';

import { getWorkspaceAccessToken } from '../../../cloud/server';
import { settings } from '../../../settings/server';
import { Info } from '../../../utils/server';

export type installAction = 'install' | 'update' | 'uninstall';

export async function notifyAppInstall(marketplaceBaseUrl: string, action: installAction, appInfo: IAppInfo): Promise<void> {
const headers: { Authorization?: string } = {};

try {
const token = await getWorkspaceAccessToken();
headers.Authorization = `Bearer ${token}`;

// eslint-disable-next-line no-empty
} catch {}

let siteUrl = '';
try {
siteUrl = settings.get<string>('Site_Url');

// eslint-disable-next-line no-empty
} catch {}

const data = {
action,
appName: appInfo.name,
appSlug: appInfo.nameSlug,
appVersion: appInfo.version,
rocketChatVersion: Info.version,
engineVersion: Info.marketplaceApiVersion,
siteUrl,
};

const pendingSentUrl = `${marketplaceBaseUrl}/v1/apps/${appInfo.id}/install`;

try {
HTTP.post(pendingSentUrl, {
headers,
data,
});

// eslint-disable-next-line no-empty
} catch {}
}