@salesforce/storefront-next-dev 0.3.1 → 0.4.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/bin/run.js +19 -9
- package/dist/cartridge-services/index.js +9 -1
- package/dist/cartridge-services/index.js.map +1 -1
- package/dist/commands/config/inspect.js +191 -0
- package/dist/commands/create-bundle.js +1 -1
- package/dist/commands/create-storefront.js +3 -3
- package/dist/commands/dev.js +1 -3
- package/dist/commands/extensions/install.js +1 -1
- package/dist/commands/extensions/list.js +1 -1
- package/dist/commands/extensions/remove.js +1 -1
- package/dist/commands/generate-cartridge.js +1 -1
- package/dist/commands/locales/aggregate-extensions.js +181 -0
- package/dist/commands/prepare-local.js +1 -1
- package/dist/commands/preview.js +1 -3
- package/dist/commands/scapi/add.js +298 -0
- package/dist/commands/scapi/list.js +35 -0
- package/dist/commands/scapi/remove.js +56 -0
- package/dist/commands/validate-cartridge.js +1 -1
- package/dist/configs/react-router.config.js +2 -1
- package/dist/configs/react-router.config.js.map +1 -1
- package/dist/data-store/local-provider.d.ts +42 -0
- package/dist/data-store/local-provider.d.ts.map +1 -0
- package/dist/data-store/local-provider.js +66 -0
- package/dist/data-store/local-provider.js.map +1 -0
- package/dist/flags.js +5 -3
- package/dist/generate-cartridge.js +9 -1
- package/dist/generate-custom-clients.js +73 -0
- package/dist/hooks/init.js +29 -4
- package/dist/index.d.ts +46 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +260 -42
- package/dist/index.js.map +1 -1
- package/dist/logger.js +1 -1
- package/dist/mrt/ssr.mjs +51 -51
- package/dist/mrt/ssr.mjs.map +1 -1
- package/dist/mrt/streamingHandler.mjs +57 -57
- package/dist/mrt/streamingHandler.mjs.map +1 -1
- package/dist/schema-utils.js +64 -0
- package/dist/utils.js +3 -11
- package/package.json +19 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { extname, join } from "node:path";
|
|
3
|
+
import YAML from "yaml";
|
|
4
|
+
|
|
5
|
+
//#region src/scapi/schema-utils.ts
|
|
6
|
+
/**
|
|
7
|
+
* Convert an API name like "shopper-products" to a camelCase client key like "shopperProducts".
|
|
8
|
+
*/
|
|
9
|
+
function deriveClientKey(apiName) {
|
|
10
|
+
return apiName.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Derive the SCAPI base path from an OpenAPI schema file.
|
|
14
|
+
*
|
|
15
|
+
* Parses the `servers[].url` field. SCAPI schemas typically have server URLs like:
|
|
16
|
+
* https://{shortCode}.api.commercecloud.salesforce.com/product/shopper-products/v1
|
|
17
|
+
*
|
|
18
|
+
* Returns the path portion (e.g., "/product/shopper-products/v1").
|
|
19
|
+
*
|
|
20
|
+
* @param schemaPath - Path to the OAS YAML/JSON file
|
|
21
|
+
* @returns The derived base path, or undefined if it cannot be determined
|
|
22
|
+
*/
|
|
23
|
+
function deriveBasePath(schemaPath) {
|
|
24
|
+
const content = readFileSync(schemaPath, "utf-8");
|
|
25
|
+
const ext = extname(schemaPath).toLowerCase();
|
|
26
|
+
let schema;
|
|
27
|
+
if (ext === ".yaml" || ext === ".yml") schema = YAML.parse(content);
|
|
28
|
+
else schema = JSON.parse(content);
|
|
29
|
+
const servers = schema.servers;
|
|
30
|
+
if (!servers || servers.length === 0) return void 0;
|
|
31
|
+
const serverUrl = servers[0].url;
|
|
32
|
+
if (!serverUrl) return void 0;
|
|
33
|
+
try {
|
|
34
|
+
const normalizedUrl = serverUrl.replace(/\{[^}]+\}/g, "placeholder");
|
|
35
|
+
const pathname = new URL(normalizedUrl).pathname;
|
|
36
|
+
return pathname && pathname !== "/" ? pathname : void 0;
|
|
37
|
+
} catch {
|
|
38
|
+
if (serverUrl.startsWith("/") && serverUrl !== "/") return serverUrl;
|
|
39
|
+
return serverUrl.match(/(?:https?:\/\/[^/]+)?(\/.+)/)?.[1] ?? void 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Read all .meta.json sidecars from a schemas directory.
|
|
44
|
+
*/
|
|
45
|
+
function readAllSchemaMetadata(schemasDir) {
|
|
46
|
+
if (!existsSync(schemasDir)) return [];
|
|
47
|
+
return readdirSync(schemasDir).filter((f) => f.endsWith(".meta.json")).map((f) => {
|
|
48
|
+
const content = JSON.parse(readFileSync(join(schemasDir, f), "utf-8"));
|
|
49
|
+
const schemaName = f.replace(".meta.json", "");
|
|
50
|
+
return {
|
|
51
|
+
...content,
|
|
52
|
+
schemaName
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Write a .meta.json sidecar for a schema file.
|
|
58
|
+
*/
|
|
59
|
+
function writeSchemaMetadata(schemasDir, schemaName, meta) {
|
|
60
|
+
writeFileSync(join(schemasDir, `${schemaName}.meta.json`), `${JSON.stringify(meta, null, 2)}\n`, "utf-8");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { writeSchemaMetadata as i, deriveClientKey as n, readAllSchemaMetadata as r, deriveBasePath as t };
|
package/dist/utils.js
CHANGED
|
@@ -3,7 +3,6 @@ import { execSync } from "child_process";
|
|
|
3
3
|
import os from "os";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import fs from "fs-extra";
|
|
6
|
-
import dotenv from "dotenv";
|
|
7
6
|
|
|
8
7
|
//#region src/utils.ts
|
|
9
8
|
const getDefaultBuildDir = (targetDir) => path.join(targetDir, "build");
|
|
@@ -20,18 +19,11 @@ const getProjectPkg = (projectDir) => {
|
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
21
|
/**
|
|
23
|
-
* Load .env file from project directory
|
|
24
|
-
*/
|
|
25
|
-
const loadEnvFile = (projectDir) => {
|
|
26
|
-
const envPath = path.join(projectDir, ".env");
|
|
27
|
-
if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
|
|
28
|
-
else logger.warn("No .env file found");
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
22
|
* Get MRT configuration with priority logic: .env -> package.json -> defaults
|
|
23
|
+
*
|
|
24
|
+
* Note: .env loading is handled once at startup in the oclif init hook (src/hooks/init.ts) before any command runs.
|
|
32
25
|
*/
|
|
33
26
|
const getMrtConfig = (projectDir) => {
|
|
34
|
-
loadEnvFile(projectDir);
|
|
35
27
|
const pkg = getProjectPkg(projectDir);
|
|
36
28
|
const defaultMrtProject = process.env.MRT_PROJECT ?? pkg.name;
|
|
37
29
|
if (!defaultMrtProject || defaultMrtProject.trim() === "") throw new Error("Project name couldn't be determined. Do one of these options:\n 1. Set MRT_PROJECT in your .env file, or\n 2. Ensure package.json has a valid \"name\" field.");
|
|
@@ -123,4 +115,4 @@ const generateEnvFile = (projectDir, configOverrides) => {
|
|
|
123
115
|
};
|
|
124
116
|
|
|
125
117
|
//#endregion
|
|
126
|
-
export { getProjectDependencyTree as a,
|
|
118
|
+
export { getProjectDependencyTree as a, getMrtConfig as i, getDefaultBuildDir as n, getProjectPkg as o, getDefaultMessage as r, getPwaKitDependencies as s, generateEnvFile as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/storefront-next-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-alpha.0",
|
|
4
4
|
"description": "Dev and build tools for SFCC Storefront Next",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
+
"./data-store/local-provider": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/data-store/local-provider.d.ts",
|
|
19
|
+
"default": "./dist/data-store/local-provider.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
16
22
|
"./logger": {
|
|
17
23
|
"import": {
|
|
18
24
|
"types": "./dist/logger/index.d.ts",
|
|
@@ -81,6 +87,15 @@
|
|
|
81
87
|
"topics": {
|
|
82
88
|
"extensions": {
|
|
83
89
|
"description": "Manage storefront extensions"
|
|
90
|
+
},
|
|
91
|
+
"scapi": {
|
|
92
|
+
"description": "Manage custom SCAPI clients"
|
|
93
|
+
},
|
|
94
|
+
"config": {
|
|
95
|
+
"description": "Inspect and manage storefront configuration"
|
|
96
|
+
},
|
|
97
|
+
"locales": {
|
|
98
|
+
"description": "Manage locale and translation files"
|
|
84
99
|
}
|
|
85
100
|
}
|
|
86
101
|
},
|
|
@@ -169,8 +184,7 @@
|
|
|
169
184
|
"chalk": "^5.3.0",
|
|
170
185
|
"compressible": "2.0.18",
|
|
171
186
|
"compression": "^1.7.4",
|
|
172
|
-
"
|
|
173
|
-
"express": "5.2.1",
|
|
187
|
+
"express": "5.1.0",
|
|
174
188
|
"fs-extra": "^11.2.0",
|
|
175
189
|
"glob": "^11.0.0",
|
|
176
190
|
"handlebars": "4.7.8",
|
|
@@ -181,11 +195,13 @@
|
|
|
181
195
|
"morgan": "^1.10.0",
|
|
182
196
|
"negotiator": "1.0.0",
|
|
183
197
|
"npm-run-path": "6.0.0",
|
|
198
|
+
"openapi-typescript": "7.10.1",
|
|
184
199
|
"prompts": "2.4.2",
|
|
185
200
|
"ts-morph": "^24.0.0",
|
|
186
201
|
"tsdown": "^0.15.4",
|
|
187
202
|
"tsx": "^4.20.5",
|
|
188
203
|
"undici": "^6.21.3",
|
|
204
|
+
"yaml": "^2.8.2",
|
|
189
205
|
"zod": "4.1.13"
|
|
190
206
|
},
|
|
191
207
|
"engines": {
|