/** * Managed Runtime (MRT) API client for B2C Commerce. * * Provides a fully typed client for Managed Runtime API operations using * openapi-fetch with API key authentication middleware. Used for * managing deployments, bundles, projects, and environments. * * @module clients/mrt */ import { type Client } from 'openapi-fetch'; import type { AuthStrategy } from '../auth/types.js'; import type { paths, components } from './mrt.generated.js'; import { type MiddlewareRegistry } from './middleware-registry.js'; /** * Re-export generated types for external use. */ export type { paths, components }; /** * The typed MRT client for Managed Runtime operations. * * ## Common Endpoints * * | Method | Path | Description | * |--------|------|-------------| * | GET | `/api/projects/` | List all projects | * | GET | `/api/projects/{projectSlug}/` | Get project details | * | POST | `/api/projects/{projectSlug}/builds/` | Push a bundle | * | GET | `/api/projects/{projectSlug}/target/{targetId}/` | Get target/environment | * | POST | `/api/projects/{projectSlug}/target/{targetId}/deploy/` | Deploy to target | * * @example * ```typescript * import { createMrtClient } from '@salesforce/b2c-tooling-sdk/clients'; * import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * * const auth = new ApiKeyStrategy(apiKey, 'Authorization'); * const client = createMrtClient({}, auth); * * // List all projects * const { data, error } = await client.GET('/api/projects/', {}); * ``` * * @see {@link createMrtClient} for instantiation * @see {@link https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/references/mrt-admin?meta=Summary | MRT Admin API Reference} */ export type MrtClient = Client; /** * Helper type to extract response data from an operation. */ export type MrtResponse = T extends { content: { 'application/json': infer R; }; } ? R : never; /** * Standard MRT error response structure. */ export interface MrtError { status: number; message: string; detail?: string; } /** * Response from pushing a bundle to MRT. * * Note: The OpenAPI spec doesn't properly define this response type, * so we define it based on the actual API response. */ export interface BuildPushResponse { /** The bundle ID assigned by MRT */ bundle_id: number; /** Success message from the API */ message: string; /** URL to view the bundle in the MRT dashboard */ url: string; /** Preview URL for the bundle (if available) */ bundle_preview_url: string | null; /** Any warnings from the push operation */ warnings: string[]; } /** * Configuration for creating an MRT client. */ export interface MrtClientConfig { /** * The origin URL for the MRT API. * @default "https://cloud.mobify.com" * @example "https://cloud.mobify.com" */ origin?: string; /** * Middleware registry to use for this client. * If not specified, uses the global middleware registry. */ middlewareRegistry?: MiddlewareRegistry; } /** * Default MRT API origin. */ export declare const DEFAULT_MRT_ORIGIN = "https://cloud.mobify.com"; /** * Creates a typed Managed Runtime 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. * * @param config - MRT client configuration * @param auth - Authentication strategy (typically ApiKeyStrategy) * @returns Typed openapi-fetch client * * @example * // Create MRT client with API key auth * const apiKeyStrategy = new ApiKeyStrategy(apiKey, 'Authorization'); * * const client = createMrtClient({}, apiKeyStrategy); * * // Push a bundle to a project * const { data, error } = await client.POST('/api/projects/{projectSlug}/builds/', { * params: { * path: { projectSlug: 'my-project' } * }, * body: { * message: 'My bundle', * encoding: 'base64', * data: bundleData, * ssr_parameters: {}, * ssr_only: ['ssr.js'], * ssr_shared: ['shared.js'] * } * }); * * @example * // List all projects * const { data, error } = await client.GET('/api/projects/', {}); * * @example * // Get a specific target/environment * const { data, error } = await client.GET('/api/projects/{projectSlug}/target/{targetId}/', { * params: { path: { projectSlug: 'my-project', targetId: 'staging' } } * }); */ export declare function createMrtClient(config: MrtClientConfig, auth: AuthStrategy): MrtClient;