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
1 change: 1 addition & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ async function getGuestUserAuthToken(): Promise<ShopperLoginTypes.TokenResponse>
}

// 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;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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",
Expand Down
9 changes: 3 additions & 6 deletions src/generate-oas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on this, I assume we've decided to name shopper baskets V1 as ShopperBaskets and not ShopperBasketsV1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes that's correct

}
if (name === "CDN API - Process APIs OAS") {
return "CDNZones";
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
44 changes: 44 additions & 0 deletions src/removeInternalOas.ts
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, do we need to run this more than once? Or is this just a helper function for cleaning up the -internal files current state of the repo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll have to run it everytime we pull down the APIs as the internal OAS file will always be a part of anypoint exchange asset (at least for now)

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.");
}
4 changes: 1 addition & 3 deletions templates/index.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading