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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 0 additions & 27 deletions scripts/config.ts

This file was deleted.

11 changes: 6 additions & 5 deletions scripts/updateApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

Suggested change

downloadLatestApis(
'category:Visibility = "External" category:"SDK Type" = "Commerce" category:"SDK Type" = "Isomorphic"',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we have SDK type as both Commerce and Isomorphic? If we just query for Isomorphic will it return all the same APIs?

wondering if we should remove Commerce SDK type so its not confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just Isomorphic is enough. I remember Kay mentioning to use both. This is kind of ensuring we don't download non-commerce specs that are tagged as Isomorphic (as this is a generic term)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb question, but how does this query guarantee that we only pull in the oas specs and not the raml specs?

PRODUCTION_API_PATH
).catch(console.error);
18 changes: 6 additions & 12 deletions scripts/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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.');
});
});
21 changes: 7 additions & 14 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const matchedApis = await download.search(`"${name}"`);
const matchedApis = await download.search(searchQuery, undefined, true);
Copy link
Contributor

@joeluong-sfcc joeluong-sfcc Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a small comment on why we're passing undefined to this search function? Might not be clear to someone who's unfamiliar with these changes

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;
}
Expand Down
Loading