sfcc/valid-custom-api-export
Requires a public static CommonJS export for each Custom API endpoint mapped to the current file in the rest-apis api.json.
What it checks
- Resolves the
api.jsonin the same directory as the linted file - For every endpoint entry whose
implementationresolves to the linted file, requires:- a static export named after the
endpoint(for exampleexports.getLoyaltyInfo = ...) - that export marked as public:
exports.getLoyaltyInfo.public = true
- a static export named after the
- Recognizes
exports.method = ...andmodule.exports.method = ...as valid static exports - Accepts the public flag either directly on the export (
exports.method.public = true) or on the same local handler assigned to that export (handler.public = true;exports.method = handler) - Applies only to JavaScript-like inputs:
.js,.mjs,.cjs,.ds, and<input> - Has no effect on files that are not referenced as an
implementationby anyapi.json
Why this rule exists
Custom API endpoints are only registered when the implementation script exports a function matching the operationId and marks it public. Salesforce Commerce Cloud only reports this at code-version activation time. This rule surfaces the same requirement directly through ESLint, in editors and lint-only CI steps.
Default behavior
- Severity:
error - Auto-fix: none
Example
api.json
json
{
"endpoints": [
{ "endpoint": "getLoyaltyInfo", "schema": "schema.yaml", "implementation": "script" }
]
}Invalid: script.js
js
exports.getLoyaltyInfo = function () {}Valid: script.js
js
function accountLookup() {}
accountLookup.public = true
exports.getLoyaltyInfo = accountLookup