@@ -10,15 +10,146 @@ npm install @salesforce/b2c-tooling
1010
1111## Quick Start
1212
13+ ### From dw.json (Recommended)
14+
15+ The easiest way to create an instance is from a ` dw.json ` file:
16+
17+ ``` typescript
18+ import { B2CInstance } from ' @salesforce/b2c-tooling' ;
19+
20+ // Load configuration from dw.json, override secrets from environment
21+ const instance = B2CInstance .fromDwJson ({
22+ clientId: process .env .SFCC_CLIENT_ID ,
23+ clientSecret: process .env .SFCC_CLIENT_SECRET ,
24+ });
25+
26+ // Use typed WebDAV client
27+ await instance .webdav .mkcol (' Cartridges/v1' );
28+ await instance .webdav .put (' Cartridges/v1/app.zip' , zipBuffer );
29+
30+ // Use typed OCAPI client (openapi-fetch)
31+ const { data, error } = await instance .ocapi .GET (' /sites' , {
32+ params: { query: { select: ' (**)' } },
33+ });
34+ ```
35+
36+ ### Direct Construction
37+
38+ You can also construct an instance directly with configuration:
39+
40+ ``` typescript
41+ import { B2CInstance } from ' @salesforce/b2c-tooling' ;
42+
43+ const instance = new B2CInstance (
44+ { hostname: ' your-sandbox.demandware.net' , codeVersion: ' v1' },
45+ {
46+ oauth: {
47+ clientId: ' your-client-id' ,
48+ clientSecret: ' your-client-secret'
49+ }
50+ }
51+ );
52+ ```
53+
54+ ## Authentication
55+
56+ B2CInstance supports multiple authentication methods:
57+
58+ ### OAuth (Client Credentials)
59+
60+ Used for OCAPI and can be used for WebDAV:
61+
62+ ``` typescript
63+ const instance = new B2CInstance (
64+ { hostname: ' sandbox.demandware.net' },
65+ {
66+ oauth: {
67+ clientId: ' your-client-id' ,
68+ clientSecret: ' your-client-secret' ,
69+ scopes: [' SALESFORCE_COMMERCE_API:...:dwsid' ],
70+ }
71+ }
72+ );
73+ ```
74+
75+ ### Basic Auth
76+
77+ Used for WebDAV operations (Business Manager credentials):
78+
79+ ``` typescript
80+ const instance = new B2CInstance (
81+ { hostname: ' sandbox.demandware.net' },
82+ {
83+ basic: {
84+ username: ' admin' ,
85+ password: ' your-access-key'
86+ },
87+ oauth: {
88+ clientId: ' your-client-id' ,
89+ clientSecret: ' your-client-secret' ,
90+ }
91+ }
92+ );
93+ ```
94+
95+ When both are configured, WebDAV uses Basic auth and OCAPI uses OAuth.
96+
97+ ## Typed Clients
98+
99+ ### WebDAV Client
100+
101+ ``` typescript
102+ // Create directories
103+ await instance .webdav .mkcol (' Cartridges/v1' );
104+
105+ // Upload files
106+ await instance .webdav .put (' Cartridges/v1/app.zip' , buffer , ' application/zip' );
107+
108+ // Download files
109+ const content = await instance .webdav .get (' Cartridges/v1/app.zip' );
110+
111+ // List directory
112+ const entries = await instance .webdav .propfind (' Cartridges' );
113+
114+ // Check existence
115+ const exists = await instance .webdav .exists (' Cartridges/v1' );
116+
117+ // Delete
118+ await instance .webdav .delete (' Cartridges/v1/old-file.zip' );
119+ ```
120+
121+ ### OCAPI Client
122+
123+ The OCAPI client uses [ openapi-fetch] ( https://openapi-ts.dev/openapi-fetch/ ) with full TypeScript support:
124+
13125``` typescript
14- import { B2CInstance } from ' @salesforce/b2c-tooling/instance' ;
15- import { OAuthStrategy } from ' @salesforce/b2c-tooling/auth' ;
16-
17- const instance = new B2CInstance ({
18- hostname: ' your-instance.salesforce.com' ,
19- auth: new OAuthStrategy ({
20- clientId: ' your-client-id' ,
21- clientSecret: ' your-client-secret' ,
22- }),
126+ // List sites
127+ const { data, error } = await instance .ocapi .GET (' /sites' , {
128+ params: { query: { select: ' (**)' } },
129+ });
130+
131+ // Get a specific site
132+ const { data, error } = await instance .ocapi .GET (' /sites/{site_id}' , {
133+ params: { path: { site_id: ' RefArch' } },
23134});
135+
136+ // Activate a code version
137+ const { data, error } = await instance .ocapi .PATCH (' /code_versions/{code_version_id}' , {
138+ params: { path: { code_version_id: ' v1' } },
139+ body: { active: true },
140+ });
141+ ```
142+
143+ ## Logging
144+
145+ Configure logging for debugging HTTP requests:
146+
147+ ``` typescript
148+ import { configureLogger } from ' @salesforce/b2c-tooling/logging' ;
149+
150+ // Enable debug logging (shows HTTP request summaries)
151+ configureLogger ({ level: ' debug' });
152+
153+ // Enable trace logging (shows full request/response with headers and bodies)
154+ configureLogger ({ level: ' trace' });
24155```
0 commit comments