|
| 1 | +# Salesforce Commerce Cloud B2C Tooling SDK |
| 2 | + |
| 3 | +> [!NOTE] |
| 4 | +> This project is currently in **Developer Preview**. Not all features are implemented, and the API may change in future releases. |
| 5 | +
|
| 6 | +A TypeScript SDK for programmatic access to Salesforce Commerce Cloud B2C APIs including OCAPI, WebDAV, SLAS, ODS, and MRT. |
| 7 | + |
| 8 | +[](https://npmjs.org/package/@salesforce/b2c-tooling-sdk) |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +```bash |
| 13 | +npm install @salesforce/b2c-tooling-sdk |
| 14 | +``` |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +### From Environment Configuration (Recommended) |
| 19 | + |
| 20 | +The easiest way to create an instance is from environment configuration files: |
| 21 | + |
| 22 | +```typescript |
| 23 | +import { B2CInstance } from '@salesforce/b2c-tooling-sdk'; |
| 24 | + |
| 25 | +// Load configuration from environment files (dw.json, etc.), override secrets from environment |
| 26 | +const instance = B2CInstance.fromEnvironment({ |
| 27 | + clientId: process.env.SFCC_CLIENT_ID, |
| 28 | + clientSecret: process.env.SFCC_CLIENT_SECRET, |
| 29 | +}); |
| 30 | + |
| 31 | +// Use typed WebDAV client |
| 32 | +await instance.webdav.mkcol('Cartridges/v1'); |
| 33 | +await instance.webdav.put('Cartridges/v1/app.zip', zipBuffer); |
| 34 | + |
| 35 | +// Use typed OCAPI client (openapi-fetch) |
| 36 | +const { data, error } = await instance.ocapi.GET('/sites', { |
| 37 | + params: { query: { select: '(**)' } }, |
| 38 | +}); |
| 39 | +``` |
| 40 | + |
| 41 | +### Direct Construction |
| 42 | + |
| 43 | +You can also construct an instance directly with configuration: |
| 44 | + |
| 45 | +```typescript |
| 46 | +import { B2CInstance } from '@salesforce/b2c-tooling-sdk'; |
| 47 | + |
| 48 | +const instance = new B2CInstance( |
| 49 | + { hostname: 'your-sandbox.demandware.net', codeVersion: 'v1' }, |
| 50 | + { |
| 51 | + oauth: { |
| 52 | + clientId: 'your-client-id', |
| 53 | + clientSecret: 'your-client-secret' |
| 54 | + } |
| 55 | + } |
| 56 | +); |
| 57 | +``` |
| 58 | + |
| 59 | +## Features |
| 60 | + |
| 61 | +### WebDAV Operations |
| 62 | + |
| 63 | +```typescript |
| 64 | +// Create directories |
| 65 | +await instance.webdav.mkcol('Cartridges/v1'); |
| 66 | + |
| 67 | +// Upload files |
| 68 | +await instance.webdav.put('Cartridges/v1/app.zip', buffer, 'application/zip'); |
| 69 | + |
| 70 | +// Download files |
| 71 | +const content = await instance.webdav.get('Cartridges/v1/app.zip'); |
| 72 | + |
| 73 | +// List directory |
| 74 | +const entries = await instance.webdav.propfind('Cartridges'); |
| 75 | + |
| 76 | +// Check existence |
| 77 | +const exists = await instance.webdav.exists('Cartridges/v1'); |
| 78 | + |
| 79 | +// Delete |
| 80 | +await instance.webdav.delete('Cartridges/v1/old-file.zip'); |
| 81 | +``` |
| 82 | + |
| 83 | +### OCAPI Client |
| 84 | + |
| 85 | +The OCAPI client uses [openapi-fetch](https://openapi-ts.dev/openapi-fetch/) with full TypeScript support: |
| 86 | + |
| 87 | +```typescript |
| 88 | +// List sites |
| 89 | +const { data, error } = await instance.ocapi.GET('/sites', { |
| 90 | + params: { query: { select: '(**)' } }, |
| 91 | +}); |
| 92 | + |
| 93 | +// Activate a code version |
| 94 | +const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version_id}', { |
| 95 | + params: { path: { code_version_id: 'v1' } }, |
| 96 | + body: { active: true }, |
| 97 | +}); |
| 98 | +``` |
| 99 | + |
| 100 | +### Code Deployment |
| 101 | + |
| 102 | +```typescript |
| 103 | +import { findAndDeployCartridges, activateCodeVersion } from '@salesforce/b2c-tooling-sdk/operations/code'; |
| 104 | + |
| 105 | +// Deploy cartridges |
| 106 | +await findAndDeployCartridges(instance, './cartridges', { reload: true }); |
| 107 | + |
| 108 | +// Activate code version |
| 109 | +await activateCodeVersion(instance, 'v1'); |
| 110 | +``` |
| 111 | + |
| 112 | +### Job Execution |
| 113 | + |
| 114 | +```typescript |
| 115 | +import { executeJob, waitForJob, siteArchiveImport } from '@salesforce/b2c-tooling-sdk/operations/jobs'; |
| 116 | + |
| 117 | +// Run a job and wait for completion |
| 118 | +const execution = await executeJob(instance, 'my-job-id'); |
| 119 | +const result = await waitForJob(instance, 'my-job-id', execution.id); |
| 120 | + |
| 121 | +// Import a site archive |
| 122 | +await siteArchiveImport(instance, './site-data.zip'); |
| 123 | +``` |
| 124 | + |
| 125 | +## Module Exports |
| 126 | + |
| 127 | +The SDK provides subpath exports for tree-shaking and organization: |
| 128 | + |
| 129 | +| Export | Description | |
| 130 | +|--------|-------------| |
| 131 | +| `@salesforce/b2c-tooling-sdk` | Main entry point with all exports | |
| 132 | +| `@salesforce/b2c-tooling-sdk/auth` | Authentication strategies (OAuth, Basic, API Key) | |
| 133 | +| `@salesforce/b2c-tooling-sdk/instance` | B2CInstance class | |
| 134 | +| `@salesforce/b2c-tooling-sdk/clients` | Low-level API clients (WebDAV, OCAPI, SLAS, ODS, MRT) | |
| 135 | +| `@salesforce/b2c-tooling-sdk/operations/code` | Code deployment operations | |
| 136 | +| `@salesforce/b2c-tooling-sdk/operations/jobs` | Job execution and site import/export | |
| 137 | +| `@salesforce/b2c-tooling-sdk/operations/sites` | Site management | |
| 138 | +| `@salesforce/b2c-tooling-sdk/logging` | Structured logging utilities | |
| 139 | + |
| 140 | +## Logging |
| 141 | + |
| 142 | +Configure logging for debugging HTTP requests: |
| 143 | + |
| 144 | +```typescript |
| 145 | +import { configureLogger } from '@salesforce/b2c-tooling-sdk/logging'; |
| 146 | + |
| 147 | +// Enable debug logging (shows HTTP request summaries) |
| 148 | +configureLogger({ level: 'debug' }); |
| 149 | + |
| 150 | +// Enable trace logging (shows full request/response with headers and bodies) |
| 151 | +configureLogger({ level: 'trace' }); |
| 152 | +``` |
| 153 | + |
| 154 | +## Documentation |
| 155 | + |
| 156 | +Full documentation is available at: https://salesforcecommercecloud.github.io/b2c-developer-tooling/ |
| 157 | + |
| 158 | +## Requirements |
| 159 | + |
| 160 | +- Node.js >= 22.16.0 |
| 161 | + |
| 162 | +## License |
| 163 | + |
| 164 | +This project is licensed under the Apache License 2.0. See [LICENSE.txt](../../LICENSE.txt) for full details. |
| 165 | + |
| 166 | +## Disclaimer |
| 167 | + |
| 168 | +This project is currently in **Developer Preview** and is provided "as-is" without warranty of any kind. It is not yet generally available (GA) and should not be used in production environments. Features, APIs, and functionality may change without notice in future releases. |
0 commit comments