Skip to content

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.json in the same directory as the linted file
  • For every endpoint entry whose implementation resolves to the linted file, requires:
    • a static export named after the endpoint (for example exports.getLoyaltyInfo = ...)
    • that export marked as public: exports.getLoyaltyInfo.public = true
  • Recognizes exports.method = ... and module.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 implementation by any api.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

Released under the MIT License.