Skip to content

Commit df85a14

Browse files
Smoke Test SDK (@W-18482922@) (#428)
* fix updateApis command * fix generation * fix readme and export slasHelpers correctly * update package.json * remove normalize flag * update raml toolkit version * update test files and lint
1 parent 0c2474a commit df85a14

File tree

8 files changed

+64
-22
lines changed

8 files changed

+64
-22
lines changed

.nycrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"src/updateApis.ts",
77
"src/lib/config.ts",
88
"src/generate-oas.ts",
9+
"src/removeInternalOas.ts",
910
"src/static/helpers/index.ts",
1011
"src/lib/utils.ts"
1112
],

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ async function getGuestUserAuthToken(): Promise<ShopperLoginTypes.TokenResponse>
137137
}
138138

139139
// Alternatively you may use the SLAS helper functions to generate JWT/access token
140-
const guestTokenResponse = await slasHelpers.loginGuestUser(
141-
new ShopperLogin(config),
142-
{ redirectURI: 'http://localhost:3000/callback' }
143-
)
140+
const guestTokenResponse = await slasHelpers.loginGuestUser({
141+
slasClient: new ShopperLogin(config),
142+
parameters: { redirectURI: 'http://localhost:3000/callback' }
143+
})
144144
.then((guestTokenResponse) => {
145145
console.log("Guest Token Response: ", guestTokenResponse);
146146
return guestTokenResponse;

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
"lint:dev": "sort-package-json && eslint . --ext .ts --fix",
3333
"prepack": "npm run build",
3434
"prepare": "snyk protect",
35+
"removeInternalOas": "ts-node src/removeInternalOas.ts",
3536
"renderTemplates": "PACKAGE_VERSION=$(node -p \"require('./package.json').version\") ts-node src/generate-oas.ts",
3637
"snyk:auth": "snyk auth",
3738
"pretest": "npm run lint && npm run depcheck",
3839
"test": "nyc mocha \"src/**/*.test.ts\"",
3940
"test:ci": "npm test -- --reporter=xunit --reporter-options output=./reports/generator.xml",
40-
"updateApis": "npm run backupApis && ts-node src/updateApis.ts && npm run diffApis"
41+
"updateApis": "npm run removeInternalOas && npm run backupApis && ts-node src/updateApis.ts && npm run removeInternalOas && npm run diffApis"
4142
},
4243
"mocha": {
4344
"file": [
@@ -55,7 +56,7 @@
5556
"tslib": "^2.4.1"
5657
},
5758
"devDependencies": {
58-
"@commerce-apps/raml-toolkit": "^0.7.0",
59+
"@commerce-apps/raml-toolkit": "^0.8.0",
5960
"@istanbuljs/nyc-config-typescript": "^1.0.2",
6061
"@types/mocha": "^8.2.3",
6162
"@types/node-fetch": "^2.5.12",

src/generate-oas.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function appendVersionIfV2(name: string, version: string): string {
4646
* Helper function. Also contains explicit workaround for some API names.
4747
*/
4848
export function resolveApiName(name: string, version: string): string {
49-
if (name === "Shopper Baskets OAS") {
50-
return version === "v2" ? "ShopperBasketsV2" : "ShopperBasketsV1";
49+
if (name === "Shopper Baskets OAS" && version === "v2") {
50+
return "ShopperBasketsV2";
5151
}
5252
if (name === "CDN API - Process APIs OAS") {
5353
return "CDNZones";
@@ -81,10 +81,7 @@ export function getAPIDetailsFromExchange(directory: string): ApiSpecDetail {
8181
) as download.ExchangeConfig;
8282

8383
return {
84-
filepath: path.join(
85-
directory,
86-
exchangeConfig.main.replace("-public.yaml", "-internal.yaml")
87-
),
84+
filepath: path.join(directory, exchangeConfig.main),
8885
filename: exchangeConfig.main,
8986
directoryName: kebabToCamelCase(
9087
appendVersionIfV2(

src/lib/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const API_FAMILIES = [
3434
"shopper-experience-oas",
3535
"shopper-login-oas",
3636
"shopper-stores-oas",
37+
"shopper-consents-oas",
3738
];
3839

3940
export const PRODUCTION_API_PATH = `${__dirname}/../../apis`;

src/removeInternalOas.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import path from "path";
9+
import fs from "fs-extra";
10+
import { PRODUCTION_API_PATH } from "./lib/config";
11+
12+
/**
13+
* Recursively removes all files ending in '-internal.yaml' from a directory and its subdirectories
14+
* @param directoryPath - The path to the directory to process
15+
*/
16+
export function removeInternalOas(directoryPath: string): void {
17+
if (!fs.existsSync(directoryPath)) {
18+
console.warn(`Directory does not exist: ${directoryPath}`);
19+
return;
20+
}
21+
22+
const items = fs.readdirSync(directoryPath);
23+
24+
items.forEach((item) => {
25+
const fullPath = path.join(directoryPath, item);
26+
const stat = fs.statSync(fullPath);
27+
28+
if (stat.isDirectory()) {
29+
// Recursively process subdirectories
30+
removeInternalOas(fullPath);
31+
} else if (stat.isFile() && item.endsWith("-internal.yaml")) {
32+
// Remove internal files
33+
fs.removeSync(fullPath);
34+
console.log(`Removed internal file: ${fullPath}`);
35+
}
36+
});
37+
}
38+
39+
// Run the function if this file is executed directly
40+
if (require.main === module) {
41+
console.log(`Removing internal OAS files from: ${PRODUCTION_API_PATH}`);
42+
removeInternalOas(PRODUCTION_API_PATH);
43+
console.log("Internal OAS files removal completed.");
44+
}

templates/index.ts.hbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ import type * as {{apiName}}Types from "./{{directoryName}}";
44
export type { {{apiName}}Types };
55
{{/each}}
66

7-
import * as helpers from "./helpers";
8-
export { helpers };
9-
7+
export { helpers, slasHelpers } from "./helpers";
108
export { ClientConfig, CommonParameters, sdkLogger } from "@commerce-apps/core"

0 commit comments

Comments
 (0)