sfnext-scapi
БесплатноБез исполняемых скриптовНе проверенUse and extend SCAPI clients in a Storefront Next project: createApiClients, the `@/scapi` type barrel, typing `c_*` custom attributes by overriding a…
от SalesforceCommerceCloud★ 58 звёзд на GitHubОб этом скилле
Storefront Next SCAPI Clients and Custom APIs
The runtime (@salesforce/storefront-next-runtime/scapi) already ships typed clients for the standard shopper APIs (products, search, baskets, customers, orders, and so on). You do not "add" those. sfnext scapi add does one of two things on top:
- Override a built-in client (client key matches, for example
shopperProducts) with a richer schema, typically your tenant's schema expanded withc_*custom attributes, soproduct.c_myAttris typed. - Add a custom API you deployed to B2C Commerce (a new property such as
clients.loyalty).
Which one you get is decided automatically from the client key. Deep dive: docs/README-SCAPI.md in your project.
The CLI surface
Run as b2c sfnext scapi ..., or inside your project as pnpm sfnext scapi ... (the sfnext bin ships with the project). Add -d <dir> / --project-directory to target another directory.
| Command | What it does |
|---|---|
scapi available |
Probes your tenant: for each of the built-in shopper APIs counts c_* attributes, lists tenant custom APIs, and prints the matching scapi add command. Needs OAuth. No filter flags. |
scapi add <apiFamily> <apiName> <apiVersion> |
Pull mode: fetch the schema from the SCAPI Schemas API. Needs OAuth. |
scapi add --schema <file> --name <clientKey> |
Local mode: use a YAML/JSON OpenAPI file. --name is required here. |
scapi list |
Shows registered Overrides and Custom APIs (schema, base path, locale). |
scapi remove <clientKey> |
Removes the registration and its generated files (one positional argument: the client key, for example loyalty). |
add flags: --name <key> (defaults to camelCase of the API name in pull mode), --base-path <path> (derived from the schema servers[].url if omitted), --supports-locale / --no-supports-locale (overrides inherit the built-in default), --expand-custom-properties (default on, pull mode only; include c_*, use --no-expand-custom-properties to skip). Re-running add regenerates; there is no --force and no --json. There is no install step after add.
Pull mode prerequisites: SCAPI short code (SFCC_SHORTCODE or --short-code), tenant id (SFCC_TENANT_ID or --tenant-id), and an Account Manager API client allowed the sfcc.scapi-schemas scope (SFCC_CLIENT_ID and SFCC_CLIENT_SECRET, or --client-id/--client-secret, or dw.json). The legacy names SFCC_OAUTH_CLIENT_ID / SFCC_OAUTH_CLIENT_SECRET are also accepted because the CLI resolves both. If the @salesforce/storefront-next-dev package is in the project, b2c uses that local version.
# Which built-in APIs have c_ attributes on my tenant? Which custom APIs exist?
b2c sfnext scapi available
# Type c_* attributes on products (override; pulls schema with custom properties)
b2c sfnext scapi add product shopper-products v1
# Register a custom API from the tenant, or from a local file
b2c sfnext scapi add custom loyalty v1
b2c sfnext scapi add --schema ./loyalty-api.yaml --name loyalty --base-path /custom/loyalty/v1
b2c sfnext scapi list
b2c sfnext scapi remove loyalty
For a schema-only look without touching the project use b2c scapi schemas get/list (see b2c-cli:b2c-scapi-schemas; both need --tenant-id).
What gets generated
src/scapi/
index.ts barrel (generated), the only SCAPI import surface for app code
custom-clients.ts registry of overrides and custom clients (generated)
schemas/ <name>-<ver>.yaml and .meta.json
generated/ <name>-<ver>.ts, .operations.ts, (.namespace.ts for overrides)
Never hand-edit these; rerun sfnext scapi add. Registry entries carry key, basePath, ops, locale, orgPrefix. Custom clients use orgPrefix: true (base /custom/<name>/v1/organizations/{orgId}); the shipped sfnextNotify entry is a working example.
Import rule
Import types and clients from the barrel, not from the runtime package:
import { ApiError, type ShopperProducts } from '@/scapi'; // picks up overrides
// import { ShopperProducts } from '@salesforce/storefront-next-runtime/scapi'; // bypasses overrides, lint warns
Only src/scapi/** and src/lib/api-clients.server.ts may import the runtime path directly.
Use clients in loaders and actions
import { createApiClients } from '@/lib/api-clients.server';
export async function loader({ context }: LoaderFunctionArgs) {
const clients = createApiClients(context);
const { data: product } = await clients.shopperProducts.getProduct({
params: { path: { id: 'my-product-id' } },
});
const { data: rewards } = await clients.loyalty.getLoyaltyRewards(); // custom client
return { product, rewardTier: product?.c_loyaltyTier, rewards };
}
- Calls return
{ data }and throwApiErroron failure (wrap inNormalizedApiErrorfrom@/lib/api/normalized-api-errorwhen you need a message/statu
Установить sfnext-scapi в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл sfnext-scapi?
Use and extend SCAPI clients in a Storefront Next project: createApiClients, the `@/scapi` type barrel, typing `c_*` custom attributes by overriding a built-in client, and adding your own custom API end to end with `b2c sfnext scapi` (add, available, list, remove). Use for "clients.shopperProducts", "c_ attribute is not typed", "sfnext scapi add", "add custom API to the storefront", src/scapi/ generated files, custom-clients.ts, calling a loyalty/notify-style custom endpoint from a loader or action, useScapiFetcher, personalized=none for custom clients, or 404 from a custom endpoint. Do not use for writing the cartridge/schema.yaml itself (use `b2c:b2c-custom-api-development`), endpoint registration status (use `b2c-cli:b2c-scapi-custom`), loader/caching strategy (use `storefront-next:sfnext-data-fetching`), or login/session code (use `storefront-next:sfnext-authentication`).
Как установить скилл sfnext-scapi?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sfnext-scapi запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic