/** * Custom APIs DX API client for B2C Commerce. * * Provides a fully typed client for Custom APIs DX API operations using * openapi-fetch with OAuth authentication middleware. Used for retrieving * the status of deployed Custom API endpoints. * * @module clients/custom-apis */ import { type Client } from 'openapi-fetch'; import type { AuthStrategy } from '../auth/types.js'; import type { paths, components } from './custom-apis.generated.js'; import { type MiddlewareRegistry } from './middleware-registry.js'; /** * Re-export generated types for external use. */ export type { paths, components }; /** * The typed Custom APIs client for Custom SCAPI endpoint management. * * ## Common Endpoints * * | Method | Path | Description | * |--------|------|-------------| * | GET | `/organizations/{organizationId}/endpoints` | List all custom API endpoints | * | GET | `/organizations/{organizationId}/endpoints/{apiName}` | Get specific API info | * * @example * ```typescript * import { createCustomApisClient, toOrganizationId } from '@salesforce/b2c-tooling-sdk/clients'; * import { OAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * * const auth = new OAuthStrategy({ * clientId: 'your-client-id', * clientSecret: 'your-client-secret', * }); * * const client = createCustomApisClient( * { shortCode: 'kv7kzm78', tenantId: 'zzxy_prd' }, * auth * ); * * // List all custom API endpoints * const { data, error } = await client.GET('/organizations/{organizationId}/endpoints', { * params: { path: { organizationId: toOrganizationId('zzxy_prd') } } * }); * ``` * * @see {@link createCustomApisClient} for instantiation * @see {@link https://developer.salesforce.com/docs/commerce/commerce-api/references/custom-apis?meta=Summary | Custom APIs Reference} */ export type CustomApisClient = Client; /** * Helper type to extract response data from an operation. */ export type CustomApisResponse = T extends { content: { 'application/json': infer R; }; } ? R : never; /** * Standard Custom APIs error response structure. */ export type CustomApisError = components['schemas']['ErrorResponse']; /** Default OAuth scopes required for Custom APIs (read-only) */ export declare const CUSTOM_APIS_DEFAULT_SCOPES: string[]; /** * Configuration for creating a Custom APIs client. */ export interface CustomApisClientConfig { /** * The short code for the SCAPI instance. * This is typically a 4-8 character alphanumeric code. * @example "kv7kzm78" */ shortCode: string; /** * The tenant ID (with or without f_ecom_ prefix). * Used to build the organizationId path parameter and tenant-specific OAuth scope. * @example "zzxy_prd" or "f_ecom_zzxy_prd" */ tenantId: string; /** * Optional scope override. If not provided, defaults to domain scope * (sfcc.custom-apis) plus tenant-specific scope (SALESFORCE_COMMERCE_API:{tenant}). */ scopes?: string[]; /** * Middleware registry to use for this client. * If not specified, uses the global middleware registry. */ middlewareRegistry?: MiddlewareRegistry; } /** * Creates a typed Custom APIs DX API client. * * Returns the openapi-fetch client directly, with authentication * handled via middleware. This gives full access to all openapi-fetch * features with type-safe paths, parameters, and responses. * * The client automatically handles OAuth scope requirements: * - Domain scope: `sfcc.custom-apis` (or custom via config.scopes) * - Tenant scope: `SALESFORCE_COMMERCE_API:{tenantId}` * * @param config - Custom APIs client configuration including shortCode and tenantId * @param auth - Authentication strategy (typically OAuth) * @returns Typed openapi-fetch client * * @example * // Create Custom APIs client - scopes are handled automatically * const oauthStrategy = new OAuthStrategy({ * clientId: 'your-client-id', * clientSecret: 'your-client-secret', * }); * * const client = createCustomApisClient( * { shortCode: 'kv7kzm78', tenantId: 'zzxy_prd' }, * oauthStrategy * ); * * // Get all Custom API endpoints * const { data, error } = await client.GET('/organizations/{organizationId}/endpoints', { * params: { * path: { organizationId: toOrganizationId('zzxy_prd') } * } * }); */ export declare function createCustomApisClient(config: CustomApisClientConfig, auth: AuthStrategy): CustomApisClient; /** Prefix required for SCAPI organizationId */ export declare const ORGANIZATION_ID_PREFIX = "f_ecom_"; /** Prefix for tenant-specific SCAPI OAuth scopes */ export declare const SCAPI_TENANT_SCOPE_PREFIX = "SALESFORCE_COMMERCE_API:"; /** * Ensures a tenant ID has the required f_ecom_ prefix for use as an SCAPI organizationId. * If the value already has the prefix, it's returned as-is. * * @param tenantId - The tenant ID (e.g., "zzxy_prd" or "f_ecom_zzxy_prd") * @returns The organization ID with the f_ecom_ prefix (e.g., "f_ecom_zzxy_prd") * * @example * toOrganizationId('zzxy_prd') // Returns 'f_ecom_zzxy_prd' * toOrganizationId('f_ecom_zzxy_prd') // Returns 'f_ecom_zzxy_prd' (unchanged) */ export declare function toOrganizationId(tenantId: string): string; /** * Normalizes any parseable tenant/organization ID form to the canonical underscore format. * * Supported input forms (all resolve to `abcd_123`): * - `abcd_123` — canonical tenant ID (returned as-is) * - `abcd-123` — hyphenated tenant ID * - `f_ecom_abcd_123` — organization ID * - `f_ecom_abcd-123` — org ID with hyphenated tenant * - `abcd-123.dx.commercecloud.salesforce.com` — sandbox hostname * * @param value - The tenant ID, organization ID, or hostname * @returns The normalized tenant ID in canonical underscore format (e.g., "abcd_123") * * @example * normalizeTenantId('f_ecom_zzxy_prd') // Returns 'zzxy_prd' * normalizeTenantId('zzxy-prd') // Returns 'zzxy_prd' * normalizeTenantId('zzxy-prd.dx.commercecloud.salesforce.com') // Returns 'zzxy_prd' */ export declare function normalizeTenantId(value: string): string; /** * Builds the tenant-specific OAuth scope required for SCAPI APIs. * * @param tenantId - The tenant ID (with or without f_ecom_ prefix) * @returns The tenant-specific scope (e.g., "SALESFORCE_COMMERCE_API:zzxy_prd") * * @example * buildTenantScope('zzxy_prd') // Returns 'SALESFORCE_COMMERCE_API:zzxy_prd' * buildTenantScope('f_ecom_zzxy_prd') // Returns 'SALESFORCE_COMMERCE_API:zzxy_prd' */ export declare function buildTenantScope(tenantId: string): string;