Skip to content

@W-21207882: Adding support for SCAPI CORS preferences#231

Draft
amit-kumar8-sf wants to merge 1 commit intomainfrom
feature-W-21207882-add-scapi-cors-support
Draft

@W-21207882: Adding support for SCAPI CORS preferences#231
amit-kumar8-sf wants to merge 1 commit intomainfrom
feature-W-21207882-add-scapi-cors-support

Conversation

@amit-kumar8-sf
Copy link
Collaborator

Summary

Implements scapi cors commands (get, set, delete) for managing Cross-Origin Resource Sharing (CORS) preferences via the SCAPI CORS Preferences API.

SDK (@salesforce/b2c-tooling-sdk)

  • Added scapi-cors-v1.yaml OpenAPI spec and generated types (scapi-cors.generated.ts)
  • Added typed createScapiCorsClient factory with SCAPI_CORS_READ_SCOPES / SCAPI_CORS_RW_SCOPES scope constants
  • Registered scapi-cors in middleware-registry.ts

CLI (@salesforce/b2c-cli)

  • b2c scapi cors get — fetches CORS preferences for a site with table output
  • b2c scapi cors set — creates/replaces CORS preferences; validates --client-id against ^[-a-zA-Z0-9]+$ and each origin against <scheme>://<domain>.<tld> (no port, no path); --client-id serves as both OAuth credential and CORS body target per API spec
  • b2c scapi cors delete — deletes all CORS preferences for a site
  • --site-id flag with 1–32 character length validation; consistent INFO/ERROR log format for all parse-time and runtime errors
  • Added cors subtopic under scapi in package.json oclif config and i18n keys

Tests

  • packages/b2c-tooling-sdk/test/clients/scapi-cors.test.ts — 8 SDK client tests (GET/PUT/DELETE responses, auth header, error handling, scope constants)
  • packages/b2c-cli/test/commands/scapi/cors/get.test.ts — 5 tests (missing config, empty/non-empty response, API error)
  • packages/b2c-cli/test/commands/scapi/cors/set.test.ts — 10 tests (client-id pattern validation, origins port/path/no-scheme rejection, multi-invalid error, empty origins, request body shape, API error)
  • packages/b2c-cli/test/commands/scapi/cors/delete.test.ts — 4 tests (success, siteId query param, missing site-id, API error)

Documentation

  • docs/cli/scapi-cors.md — full CLI reference with flag tables, origin format rules, and output examples
  • docs/.vitepress/config.mts — sidebar entry added
  • skills/b2c-cli/skills/b2c-scapi-cors/SKILL.md — agent skill with usage examples

Testing

  • All new tests pass (pnpm --filter @salesforce/b2c-cli run test:agent, pnpm --filter @salesforce/b2c-tooling-sdk run test:agent)
  • Manually tested get, set, and delete against a live SCAPI CORS endpoint
  • Verified error messages for missing flags, invalid client-id pattern, invalid origins (port, path, bare hostname), and site-id length violations

Dependencies

  • No net-new third-party dependencies were added

  • Tests pass (pnpm test)
  • Code is formatted (pnpm run format)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant