diff --git a/package.json b/package.json index da93d6b5..ff1a229e 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "@babel/preset-env": "7.18.6", "@babel/preset-react": "7.18.6", "@babel/preset-typescript": "^7.18.6", - "@commerce-apps/raml-toolkit": "0.6.0", + "@commerce-apps/raml-toolkit": "file:../raml-toolkit", "@rollup/plugin-babel": "5.3.1", "@rollup/plugin-commonjs": "13.0.2", "@rollup/plugin-node-resolve": "8.4.0", diff --git a/scripts/config.ts b/scripts/config.ts deleted file mode 100644 index 1a0d35f8..00000000 --- a/scripts/config.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2019, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: BSD-3-Clause - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ -export const PRIMITIVE_DATA_TYPE_MAP = { - 'http://www.w3.org/2001/XMLSchema#string': 'string', - 'http://www.w3.org/2001/XMLSchema#integer': 'number', - 'http://www.w3.org/2001/XMLSchema#double': 'number', - 'http://www.w3.org/2001/XMLSchema#float': 'number', - 'http://www.w3.org/2001/XMLSchema#boolean': 'boolean', -}; -export const API_LIST: string[] = [ - 'shopper-baskets-oas', - 'shopper-context-oas', - 'shopper-customers-oas', - 'shopper-experience-oas', - 'shopper-gift-certificates-oas', - 'shopper-login-oas', - 'shopper-orders-oas', - 'shopper-products-oas', - 'shopper-promotions-oas', - 'shopper-search-oas', - 'shopper-seo-oas', - 'shopper-stores-oas', -]; diff --git a/scripts/updateApis.ts b/scripts/updateApis.ts index 580c96df..8c8edcca 100644 --- a/scripts/updateApis.ts +++ b/scripts/updateApis.ts @@ -9,7 +9,6 @@ import path from 'path'; import fs from 'fs-extra'; import dotenv from 'dotenv'; import {downloadLatestApis} from './utils'; -import {API_LIST} from './config'; dotenv.config(); @@ -26,7 +25,9 @@ const PRODUCTION_API_PATH = path.join(__dirname, '../apis'); fs.moveSync(PRODUCTION_API_PATH, OLD_APIS_PATH, {overwrite: true}); fs.ensureDirSync(PRODUCTION_API_PATH); -API_LIST.forEach(name => { - // eslint-disable-next-line no-console - downloadLatestApis(name, PRODUCTION_API_PATH).catch(console.error); -}); +// eslint-disable-next-line no-console + +downloadLatestApis( + 'category:Visibility = "External" category:"SDK Type" = "Commerce" category:"SDK Type" = "Isomorphic"', + PRODUCTION_API_PATH +).catch(console.error); diff --git a/scripts/utils.test.ts b/scripts/utils.test.ts index f82d1293..6d64a80e 100644 --- a/scripts/utils.test.ts +++ b/scripts/utils.test.ts @@ -9,22 +9,16 @@ import {downloadLatestApis} from './utils'; describe('test downloadLatestApis script', () => { it('throws error when no results', async () => { - await expect(downloadLatestApis('noResults', '/tmp')).rejects.toThrow( - "No results in Exchange for 'noResults'" + await expect(downloadLatestApis('"noResults"', '/tmp')).rejects.toThrow( + 'No results in Exchange for \'"noResults"\'' ); }); - it('throws error when no exact match', async () => { - await expect(downloadLatestApis('noMatch', '/tmp')).rejects.toThrow( - "No exact match in Exchange for 'noMatch'" - ); - }); - - it('downloads when exact match', async () => { + it('downloads the apis with default search query', async () => { jest.spyOn(download, 'downloadRestApis').mockResolvedValue(''); await expect( - downloadLatestApis('shopper-customers', '/tmp') + downloadLatestApis('category:Visibility = "External"', '/tmp') ).resolves.toBeUndefined(); }); @@ -33,7 +27,7 @@ describe('test downloadLatestApis script', () => { .spyOn(download, 'downloadRestApis') .mockRejectedValue(new Error('It failed.')); await expect( - downloadLatestApis('shopper-customers', '/tmp') - ).rejects.toThrow('Failed to download shopper-customers: It failed.'); + downloadLatestApis('category:Visibility = "External"', '/tmp') + ).rejects.toThrow('Failed to download API specs: It failed.'); }); }); diff --git a/scripts/utils.ts b/scripts/utils.ts index 1c2e1b92..d07d075e 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -29,31 +29,24 @@ import {download} from '@commerce-apps/raml-toolkit'; * We should have some followup to figure out how to cover it. * Ive spent hours trying to mock download * - * @param name - Api name to search for + * @param searchQuery - Query to search exchange * @param rootPath - Root path to download to * * @returns a promise that we will complete */ export async function downloadLatestApis( - name: string, - rootPath: string, - isOAS = true + searchQuery: string, + rootPath: string ): Promise { - const matchedApis = await download.search(`"${name}"`); + const matchedApis = await download.search(searchQuery, undefined, true); if (!(matchedApis?.length > 0)) { - throw new Error(`No results in Exchange for '${name}'`); - } - const api = matchedApis.find( - (matchedApi: {assetId: string}) => matchedApi?.assetId === name - ); - if (!api) { - throw new Error(`No exact match in Exchange for '${name}'`); + throw new Error(`No results in Exchange for '${searchQuery}'`); } try { - await download.downloadRestApis([api], rootPath, isOAS); + await download.downloadRestApis(matchedApis, rootPath, true); } catch (err: unknown) { if (err instanceof Error) { - err.message = `Failed to download ${name}: ${err.message}`; + err.message = `Failed to download API specs: ${err.message}`; } throw err; }