From a3580173e4949fc89065ce70e0ebb47d2c28d562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Guimar=C3=A3es=20Ribeiro?= Date: Fri, 10 Jun 2022 10:14:15 -0300 Subject: [PATCH] Regression: Fix apps wrong typing (#25824) --- apps/meteor/app/apps/client/orchestrator.ts | 47 ++++++++++++--------- packages/rest-typings/src/apps/index.ts | 23 ++++++---- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/apps/meteor/app/apps/client/orchestrator.ts b/apps/meteor/app/apps/client/orchestrator.ts index dc37aef84e74..ea224409fbc4 100644 --- a/apps/meteor/app/apps/client/orchestrator.ts +++ b/apps/meteor/app/apps/client/orchestrator.ts @@ -132,30 +132,33 @@ class AppClientOrchestrator { public async getApps(): Promise { 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 { 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 { @@ -257,12 +260,14 @@ class AppClientOrchestrator { throw new Error('Failed to build external url'); } - public async getCategories(): Promise[]> { + public async getCategories(): Promise> { 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[]; } - throw new Error('Categories not found'); + throw new Error('Failed to get categories'); } public getUIHost(): RealAppsEngineUIHost { @@ -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; diff --git a/packages/rest-typings/src/apps/index.ts b/packages/rest-typings/src/apps/index.ts index d7f6fd10c9b2..1a8c801bf790 100644 --- a/packages/rest-typings/src/apps/index.ts +++ b/packages/rest-typings/src/apps/index.ts @@ -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;