diff --git a/.nycrc.json b/.nycrc.json index 096322bf..81215f0e 100644 --- a/.nycrc.json +++ b/.nycrc.json @@ -6,6 +6,7 @@ "src/updateApis.ts", "src/lib/config.ts", "src/generate-oas.ts", + "src/removeInternalOas.ts", "src/static/helpers/index.ts", "src/lib/utils.ts" ], diff --git a/README.md b/README.md index 89288ad3..532dcb09 100644 --- a/README.md +++ b/README.md @@ -137,10 +137,10 @@ async function getGuestUserAuthToken(): Promise } // Alternatively you may use the SLAS helper functions to generate JWT/access token -const guestTokenResponse = await slasHelpers.loginGuestUser( - new ShopperLogin(config), - { redirectURI: 'http://localhost:3000/callback' } - ) +const guestTokenResponse = await slasHelpers.loginGuestUser({ + slasClient: new ShopperLogin(config), + parameters: { redirectURI: 'http://localhost:3000/callback' } + }) .then((guestTokenResponse) => { console.log("Guest Token Response: ", guestTokenResponse); return guestTokenResponse; diff --git a/package-lock.json b/package-lock.json index 3cc40b68..d2a2cb52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "tslib": "^2.4.1" }, "devDependencies": { - "@commerce-apps/raml-toolkit": "^0.7.0", + "@commerce-apps/raml-toolkit": "^0.8.0", "@istanbuljs/nyc-config-typescript": "^1.0.2", "@types/mocha": "^8.2.3", "@types/node-fetch": "^2.5.12", @@ -343,9 +343,9 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" }, "node_modules/@commerce-apps/raml-toolkit": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@commerce-apps/raml-toolkit/-/raml-toolkit-0.7.0.tgz", - "integrity": "sha512-mz/Vf0wXV9dh4MLPJK3FZfAaxpyhuOHI3cF39zByX1dgCAUi8wGhzc29xqWfKTg5G/8LE2bnLOG4xDbcikOyEA==", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@commerce-apps/raml-toolkit/-/raml-toolkit-0.8.0.tgz", + "integrity": "sha512-n4ivteJjnOlPR70djOwlUSX2AuhJZtAGW2aZ3XwN5aMYWJueN5SHAr/OatXrW9I1QZWqVnSPrQpkGzfr2a5UPw==", "dev": true, "license": "BSD 3-Clause", "dependencies": { @@ -13110,9 +13110,9 @@ } }, "@commerce-apps/raml-toolkit": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@commerce-apps/raml-toolkit/-/raml-toolkit-0.7.0.tgz", - "integrity": "sha512-mz/Vf0wXV9dh4MLPJK3FZfAaxpyhuOHI3cF39zByX1dgCAUi8wGhzc29xqWfKTg5G/8LE2bnLOG4xDbcikOyEA==", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@commerce-apps/raml-toolkit/-/raml-toolkit-0.8.0.tgz", + "integrity": "sha512-n4ivteJjnOlPR70djOwlUSX2AuhJZtAGW2aZ3XwN5aMYWJueN5SHAr/OatXrW9I1QZWqVnSPrQpkGzfr2a5UPw==", "dev": true, "requires": { "@oclif/command": "1.8.4", diff --git a/package.json b/package.json index 5363e17f..c75ffcce 100644 --- a/package.json +++ b/package.json @@ -32,12 +32,13 @@ "lint:dev": "sort-package-json && eslint . --ext .ts --fix", "prepack": "npm run build", "prepare": "snyk protect", + "removeInternalOas": "ts-node src/removeInternalOas.ts", "renderTemplates": "PACKAGE_VERSION=$(node -p \"require('./package.json').version\") ts-node src/generate-oas.ts", "snyk:auth": "snyk auth", "pretest": "npm run lint && npm run depcheck", "test": "nyc mocha \"src/**/*.test.ts\"", "test:ci": "npm test -- --reporter=xunit --reporter-options output=./reports/generator.xml", - "updateApis": "npm run backupApis && ts-node src/updateApis.ts && npm run diffApis" + "updateApis": "npm run removeInternalOas && npm run backupApis && ts-node src/updateApis.ts && npm run removeInternalOas && npm run diffApis" }, "mocha": { "file": [ @@ -55,7 +56,7 @@ "tslib": "^2.4.1" }, "devDependencies": { - "@commerce-apps/raml-toolkit": "^0.7.0", + "@commerce-apps/raml-toolkit": "^0.8.0", "@istanbuljs/nyc-config-typescript": "^1.0.2", "@types/mocha": "^8.2.3", "@types/node-fetch": "^2.5.12", diff --git a/src/generate-oas.ts b/src/generate-oas.ts index e92d1a6f..a8549b8a 100644 --- a/src/generate-oas.ts +++ b/src/generate-oas.ts @@ -46,8 +46,8 @@ function appendVersionIfV2(name: string, version: string): string { * Helper function. Also contains explicit workaround for some API names. */ export function resolveApiName(name: string, version: string): string { - if (name === "Shopper Baskets OAS") { - return version === "v2" ? "ShopperBasketsV2" : "ShopperBasketsV1"; + if (name === "Shopper Baskets OAS" && version === "v2") { + return "ShopperBasketsV2"; } if (name === "CDN API - Process APIs OAS") { return "CDNZones"; @@ -81,10 +81,7 @@ export function getAPIDetailsFromExchange(directory: string): ApiSpecDetail { ) as download.ExchangeConfig; return { - filepath: path.join( - directory, - exchangeConfig.main.replace("-public.yaml", "-internal.yaml") - ), + filepath: path.join(directory, exchangeConfig.main), filename: exchangeConfig.main, directoryName: kebabToCamelCase( appendVersionIfV2( diff --git a/src/lib/config.ts b/src/lib/config.ts index 115a99d5..bab709e2 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -34,6 +34,7 @@ export const API_FAMILIES = [ "shopper-experience-oas", "shopper-login-oas", "shopper-stores-oas", + "shopper-consents-oas", ]; export const PRODUCTION_API_PATH = `${__dirname}/../../apis`; diff --git a/src/removeInternalOas.ts b/src/removeInternalOas.ts new file mode 100644 index 00000000..b4d5f8c8 --- /dev/null +++ b/src/removeInternalOas.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025, 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 + */ + +import path from "path"; +import fs from "fs-extra"; +import { PRODUCTION_API_PATH } from "./lib/config"; + +/** + * Recursively removes all files ending in '-internal.yaml' from a directory and its subdirectories + * @param directoryPath - The path to the directory to process + */ +export function removeInternalOas(directoryPath: string): void { + if (!fs.existsSync(directoryPath)) { + console.warn(`Directory does not exist: ${directoryPath}`); + return; + } + + const items = fs.readdirSync(directoryPath); + + items.forEach((item) => { + const fullPath = path.join(directoryPath, item); + const stat = fs.statSync(fullPath); + + if (stat.isDirectory()) { + // Recursively process subdirectories + removeInternalOas(fullPath); + } else if (stat.isFile() && item.endsWith("-internal.yaml")) { + // Remove internal files + fs.removeSync(fullPath); + console.log(`Removed internal file: ${fullPath}`); + } + }); +} + +// Run the function if this file is executed directly +if (require.main === module) { + console.log(`Removing internal OAS files from: ${PRODUCTION_API_PATH}`); + removeInternalOas(PRODUCTION_API_PATH); + console.log("Internal OAS files removal completed."); +} diff --git a/templates/index.ts.hbs b/templates/index.ts.hbs index 9dbee884..0086c48a 100644 --- a/templates/index.ts.hbs +++ b/templates/index.ts.hbs @@ -4,7 +4,5 @@ import type * as {{apiName}}Types from "./{{directoryName}}"; export type { {{apiName}}Types }; {{/each}} -import * as helpers from "./helpers"; -export { helpers }; - +export { helpers, slasHelpers } from "./helpers"; export { ClientConfig, CommonParameters, sdkLogger } from "@commerce-apps/core"