Skip to content

Commit 1688036

Browse files
@W-19995399 - Add Rules for Custom API in Dev Guidelines (#3413)
1 parent 25ea212 commit 1688036

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

packages/pwa-kit-mcp/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- Added Hooks Recommendation tool [#3388](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3388)
55
- Added Agent Guidelines. [#3366](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3366)
66
- Added Explore SCAPI SHOP API Tool [#3385](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3385)
7-
- Added Custom APIs Discovery. [##3387](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3387)
7+
- Added Custom APIs Discovery. [##3387](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3387), [#3413](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3413)
88

99
## v0.3.0 (Sep 25, 2025)
1010
- Added telemetry for MCP tools. [#3327](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3327)

packages/pwa-kit-mcp/src/tools/custom-api-discovery.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,14 @@ export default {
241241
const processedEntries = []
242242
for (const entry of dxEndpointResponse.data) {
243243
if (entry.cartridgeName) {
244+
const endpointPath = entry.endpointPath.startsWith('/')
245+
? entry.endpointPath.substring(1)
246+
: entry.endpointPath
244247
let customApiBaseUrl = null
245248
let schemaContent = null
246249
try {
247250
// Construct the custom API base URL
248-
customApiBaseUrl = `https://${shortCode}.api.commercecloud.salesforce.com/custom/${entry.apiName}/${entry.apiVersion}/organizations/${organizationId}${entry.endpointPath}`
251+
customApiBaseUrl = `https://${shortCode}.api.commercecloud.salesforce.com/custom/${entry.apiName}/${entry.apiVersion}/organizations/${organizationId}/${endpointPath}`
249252

250253
const webdavResponse = await searchForEndpointFiles(
251254
hostname,
@@ -265,7 +268,7 @@ export default {
265268
apiName: entry.apiName,
266269
apiVersion: entry.apiVersion,
267270
cartridgeName: entry.cartridgeName,
268-
endpointPath: entry.endpointPath,
271+
endpointPath: endpointPath,
269272
httpMethod: entry.httpMethod,
270273
status: entry.status,
271274
securityScheme: entry.securityScheme,

packages/pwa-kit-mcp/src/tools/developer-guideline.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,60 @@ This document offers guidelines in the development of Salesforce Commerce Compos
9999
- Use kebab-case for file names. Only start with an underscore (_) if they are special components.
100100
- Use React Hooks (e.g., useState, useEffect, useContext, useMemo, useCallback) for state management and side effects.
101101
102+
### Custom API Implementation
103+
- Use 'useCustomQuery' or 'useCustomMutation' hooks from 'commerce-sdk-react'
104+
- **DON'T** include any extra '/' before or after path parameters in the 'customApiPathParameters' object
105+
- Parameters for 'useCustomQuery' or 'useCustomMutation':
106+
- \`options\` (Object): Configuration for the API request.
107+
- \`method\` (String): The HTTP method to use (e.g., 'POST', 'GET').
108+
- \`customApiPathParameters\` (Object): Contains parameters to define the API path.
109+
- \`endpointPath\` (String): Specific endpoint path to target in the API.
110+
- \`apiName\` (String): The name of the API
111+
- \`useCustomQuery\` usage :
112+
\`\`\`jsx
113+
const query = useCustomQuery(
114+
{
115+
options: {
116+
method: 'GET',
117+
customApiPathParameters: {
118+
apiName: 'your-api-name',
119+
apiVersion: 'your-api-version',
120+
endpointPath: 'your-endpoint'
121+
},
122+
parameters: {
123+
c_yourParam: params.yourParam,
124+
// other parameters
125+
}
126+
}
127+
}
128+
)
129+
\`\`\`
130+
#### \`mutate\` Method
131+
The \`mutation.mutate(args)\` function is used to execute the mutation. It accepts an argument \`args\`, which is an object that may contain the following properties:
132+
- \`headers\` (Object): Optional headers to send with the request.
133+
- \`parameters\` (Object): Optional query parameters to append to the API URL.
134+
- \`body\` (Object): Optional the payload for POST, PUT, PATCH methods.
135+
- \`useCustomMutation\` usage:
136+
\`\`\`jsx
137+
const mutation = useCustomMutation({
138+
options: {
139+
method: 'POST',
140+
customApiPathParameters: {
141+
apiName: 'your-api-name',
142+
apiVersion: 'your-api-version',
143+
endpointPath: 'your-endpoint'
144+
}
145+
}
146+
});
147+
148+
// In your React component
149+
<button onClick={() => mutation.mutate({
150+
body: { test: '123' },
151+
parameters: { additional: 'value' },
152+
headers: { ['X-Custom-Header']: 'test' }
153+
})}> Send Request </button>
154+
\`\`\`
155+
102156
## Quality Standards
103157
- Maintain consistent code formatting using project standards.
104158
- Write comprehensive test coverage.

0 commit comments

Comments
 (0)