Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions apps/meteor/app/apps/client/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,33 @@ class AppClientOrchestrator {

public async getApps(): Promise<App[]> {
const result = await APIClient.get('/apps');

if ('apps' in result) {
return result.apps;
// TODO: chapter day: multiple results are returned, but we only need one
return result.apps as App[];
}
throw new Error('Apps not found');
throw new Error('Invalid response from API');
}

public async getAppsFromMarketplace(): Promise<App[]> {
const result = await APIClient.get('/apps', { marketplace: 'true' });

if ('apps' in result) {
const { apps: appsOverviews } = result;
return appsOverviews.map((app) => {
const { latest, price, pricingPlans, purchaseType, isEnterpriseOnly, modifiedAt } = app;
return {
...latest,
price,
pricingPlans,
purchaseType,
isEnterpriseOnly,
modifiedAt,
};
});
if (!Array.isArray(result)) {
// TODO: chapter day: multiple results are returned, but we only need one
throw new Error('Invalid response from API');
}
throw new Error('Apps not found');

return (result as App[]).map((app: App) => {
const { latest, price, pricingPlans, purchaseType, isEnterpriseOnly, modifiedAt } = app;
return {
...latest,
price,
pricingPlans,
purchaseType,
isEnterpriseOnly,
modifiedAt,
};
});
}

public async getAppsOnBundle(bundleId: string): Promise<App[]> {
Expand Down Expand Up @@ -257,12 +260,14 @@ class AppClientOrchestrator {
throw new Error('Failed to build external url');
}

public async getCategories(): Promise<Serialized<ICategory>[]> {
public async getCategories(): Promise<Serialized<ICategory[]>> {
const result = await APIClient.get('/apps', { categories: 'true' });
if ('categories' in result) {
return result.categories;

if (Array.isArray(result)) {
// TODO: chapter day: multiple results are returned, but we only need one
return result as Serialized<ICategory>[];
}
throw new Error('Categories not found');
throw new Error('Failed to get categories');
}

public getUIHost(): RealAppsEngineUIHost {
Expand All @@ -274,7 +279,7 @@ export const Apps = new AppClientOrchestrator();

Meteor.startup(() => {
CachedCollectionManager.onLogin(() => {
Meteor.call('/apps/is-enabled', (error: Error, isEnabled: boolean) => {
Meteor.call('apps/is-enabled', (error: Error, isEnabled: boolean) => {
if (error) {
Apps.handleError(error);
return;
Expand Down
23 changes: 14 additions & 9 deletions packages/rest-typings/src/apps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,27 @@ export type AppsEndpoints = {
})
| ((params: {
purchaseType?: 'buy' | 'subscription';
marketplace?: 'true' | 'false';
marketplace?: 'false';
version?: string;
appId?: string;
details?: 'true' | 'false';
}) => {
apps: App[];
})
| ((params: {
purchaseType?: 'buy' | 'subscription';
marketplace: 'true';
version?: string;
appId?: string;
details?: 'true' | 'false';
}) => App[])
| ((params: { categories: 'true' | 'false' }) => {
categories: {
createdDate: string;
description: string;
id: string;
modifiedDate: Date;
title: string;
}[];
});
createdDate: Date;
description: string;
id: string;
modifiedDate: Date;
title: string;
}[]);

POST: (params: { appId: string; marketplace: boolean; version: string; permissionsGranted: IPermission[] }) => {
app: App;
Expand Down