Skip to content

Commit

Permalink
Regression: Fix apps wrong typing (#25824)
Browse files Browse the repository at this point in the history
  • Loading branch information
rique223 committed Jun 10, 2022
1 parent e38b5bc commit a358017
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
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

0 comments on commit a358017

Please sign in to comment.