Skip to content

Commit 69decfb

Browse files
committed
better docs config/layout
1 parent 22bcee2 commit 69decfb

File tree

11 files changed

+352
-26
lines changed

11 files changed

+352
-26
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ pnpm install
2222
pnpm start # start the cli in dev mode; see CLI readme for more details
2323
pnpm test
2424
```
25+
26+
Docs development
27+
28+
```bash
29+
pnpm run docs:dev
30+
```

docs/.vitepress/config.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default defineConfig({
1212
},
1313

1414
themeConfig: {
15+
logo: '/logo.svg',
1516
outline: {
1617
level: [2, 3],
1718
},
@@ -21,6 +22,11 @@ export default defineConfig({
2122
{ text: 'API Reference', link: '/api/' },
2223
],
2324

25+
footer: {
26+
message: 'Released under the MIT License.',
27+
copyright: `Copyright © ${new Date().getFullYear()} Salesforce, Inc. All rights reserved.`,
28+
},
29+
2430
sidebar: {
2531
'/guide/': [
2632
{

docs/public/logo.svg

Lines changed: 31 additions & 0 deletions
Loading

packages/b2c-tooling/src/auth/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
/**
2+
* Authentication strategies for B2C Commerce APIs.
3+
*
4+
* This module provides different authentication mechanisms for connecting to
5+
* B2C Commerce instances and platform services.
6+
*
7+
* ## Available Strategies
8+
*
9+
* - {@link BasicAuthStrategy} - Username/password authentication for WebDAV operations
10+
* - {@link OAuthStrategy} - OAuth 2.0 client credentials for OCAPI and platform APIs
11+
* - {@link ApiKeyStrategy} - API key authentication for MRT services
12+
*
13+
* ## Usage
14+
*
15+
* All strategies implement the {@link AuthStrategy} interface, allowing you to
16+
* switch authentication methods without changing your code:
17+
*
18+
* ```typescript
19+
* import { BasicAuthStrategy, OAuthStrategy } from '@salesforce/b2c-tooling';
20+
*
21+
* // For WebDAV operations (code upload)
22+
* const basicAuth = new BasicAuthStrategy('username', 'access-key');
23+
*
24+
* // For OCAPI operations (sites, jobs)
25+
* const oauthAuth = new OAuthStrategy({
26+
* clientId: 'your-client-id',
27+
* clientSecret: 'your-client-secret',
28+
* });
29+
* ```
30+
*
31+
* @module auth
32+
*/
133
export {AuthStrategy, AccessTokenResponse, DecodedJWT} from './types.js';
234
export {BasicAuthStrategy} from './basic.js';
335
export {OAuthStrategy, OAuthConfig, decodeJWT} from './oauth.js';

packages/b2c-tooling/src/i18n/index.ts

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,63 @@
1-
import i18next, {TOptions, Resource} from 'i18next';
2-
3-
// Re-export TOptions for consumers
4-
export type {TOptions} from 'i18next';
5-
import {locales} from './locales/index.js';
6-
71
/**
8-
* i18n module for B2C CLI tools.
2+
* Internationalization (i18n) support for B2C CLI tools.
3+
*
4+
* This module provides translation utilities using i18next, with support for
5+
* multiple languages and environment-based language detection.
6+
*
7+
* ## Key Features
98
*
10-
* Key features:
119
* - Default strings are stored inline at point of use (no separate en.ts needed)
1210
* - TypeScript locale files for type safety and bundling
1311
* - Namespace separation: 'b2c' for tooling, 'cli' for CLI-specific messages
1412
*
15-
* Language detection precedence:
16-
* 1. Explicit setLanguage() call (from --lang flag)
17-
* 2. LANGUAGE environment variable (GNU gettext standard, supports colon-separated list)
18-
* 3. LANG system environment variable (Unix standard)
13+
* ## Language Detection
14+
*
15+
* Language is detected in this order:
16+
* 1. Explicit {@link setLanguage} call (from --lang flag)
17+
* 2. `LANGUAGE` environment variable (GNU gettext standard)
18+
* 3. `LANG` system environment variable (Unix standard)
1919
* 4. Default: 'en'
2020
*
21-
* Supported locale formats:
22-
* - "de" - simple language code
23-
* - "de_DE" - language with country
24-
* - "de-DE" - language with country (hyphen)
25-
* - "de_DE.UTF-8" - with encoding
26-
* - "de_DE@euro" - with modifier
27-
* - "de:en:fr" - colon-separated preference list (LANGUAGE only)
21+
* ## Supported Locale Formats
22+
*
23+
* - `de` - simple language code
24+
* - `de_DE` - language with country
25+
* - `de-DE` - language with country (hyphen)
26+
* - `de_DE.UTF-8` - with encoding
27+
* - `de:en:fr` - colon-separated preference list (LANGUAGE only)
28+
*
29+
* ## Usage
2830
*
29-
* Usage:
30-
* import { t } from '@salesforce/b2c-tooling'
31-
* throw new Error(t('error.serverRequired', 'Server is required.'))
31+
* ```typescript
32+
* import { t } from '@salesforce/b2c-tooling';
3233
*
33-
* With interpolation:
34-
* t('error.fileNotFound', 'File {{path}} not found.', { path: '/foo/bar' })
34+
* // Simple translation with inline default
35+
* const message = t('error.serverRequired', 'Server is required.');
36+
*
37+
* // With interpolation
38+
* const fileError = t('error.fileNotFound', 'File {{path}} not found.', {
39+
* path: '/foo/bar'
40+
* });
41+
* ```
42+
*
43+
* ## Adding Translations
44+
*
45+
* ```typescript
46+
* import { registerTranslations } from '@salesforce/b2c-tooling';
47+
*
48+
* // Register translations for a new namespace
49+
* registerTranslations('my-package', 'de', {
50+
* greeting: 'Hallo Welt'
51+
* });
52+
* ```
53+
*
54+
* @module i18n
3555
*/
56+
import i18next, {TOptions, Resource} from 'i18next';
57+
58+
// Re-export TOptions for consumers
59+
export type {TOptions} from 'i18next';
60+
import {locales} from './locales/index.js';
3661

3762
/** The namespace used by b2c-tooling messages */
3863
export const B2C_NAMESPACE = 'b2c';

packages/b2c-tooling/src/instance/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
/**
2+
* B2C Instance management.
3+
*
4+
* This module provides the {@link B2CInstance} class which represents a connection
5+
* to a specific B2C Commerce instance. It combines instance configuration with
6+
* an authentication strategy to make API requests.
7+
*
8+
* ## Usage
9+
*
10+
* ```typescript
11+
* import { B2CInstance } from '@salesforce/b2c-tooling';
12+
* import { OAuthStrategy } from '@salesforce/b2c-tooling/auth';
13+
*
14+
* const auth = new OAuthStrategy({
15+
* clientId: 'your-client-id',
16+
* clientSecret: 'your-client-secret',
17+
* });
18+
*
19+
* const instance = new B2CInstance(
20+
* { hostname: 'your-sandbox.demandware.net', codeVersion: 'v1' },
21+
* auth
22+
* );
23+
*
24+
* // Make OCAPI requests
25+
* const response = await instance.ocapiDataRequest('sites');
26+
* ```
27+
*
28+
* @module instance
29+
*/
130
import {AuthStrategy} from '../auth/types.js';
231

332
export interface InstanceConfig {

packages/b2c-tooling/src/logger.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
11
/**
2-
* Logger interface for b2c-tooling
3-
* Consumers can provide their own logger implementation
2+
* Logging utilities for B2C CLI tools.
3+
*
4+
* This module provides a pluggable logging interface that allows consumers
5+
* to integrate their own logging implementation.
6+
*
7+
* ## Built-in Loggers
8+
*
9+
* - {@link noopLogger} - Silent logger (default) - does nothing
10+
* - {@link consoleLogger} - Logs to console
11+
*
12+
* ## Usage
13+
*
14+
* ```typescript
15+
* import { setLogger, getLogger, consoleLogger } from '@salesforce/b2c-tooling';
16+
*
17+
* // Enable console logging
18+
* setLogger(consoleLogger);
19+
*
20+
* // Or use a custom logger
21+
* setLogger({
22+
* debug: (msg, ...args) => myLogger.debug(msg, ...args),
23+
* info: (msg, ...args) => myLogger.info(msg, ...args),
24+
* warn: (msg, ...args) => myLogger.warn(msg, ...args),
25+
* error: (msg, ...args) => myLogger.error(msg, ...args),
26+
* });
27+
*
28+
* // Get the current logger
29+
* const logger = getLogger();
30+
* logger.info('Operation completed');
31+
* ```
32+
*
33+
* ## Default Behavior
34+
*
35+
* By default, the {@link noopLogger} is used, which silently discards all
36+
* log messages. This ensures the library doesn't produce unexpected output
37+
* unless logging is explicitly enabled.
38+
*
39+
* @module logger
40+
*/
41+
42+
/**
43+
* Logger interface for b2c-tooling.
44+
* Consumers can provide their own logger implementation.
445
*/
546
export interface Logger {
647
debug(message: string, ...args: unknown[]): void;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1+
/**
2+
* Code deployment operations for B2C Commerce.
3+
*
4+
* This module provides functions for uploading cartridges and managing
5+
* code versions on B2C Commerce instances via WebDAV.
6+
*
7+
* ## Functions
8+
*
9+
* - {@link uploadCartridges} - Upload cartridge code to an instance
10+
* - {@link activateCodeVersion} - Activate a code version on an instance
11+
*
12+
* ## Usage
13+
*
14+
* ```typescript
15+
* import { uploadCartridges, activateCodeVersion } from '@salesforce/b2c-tooling/operations/code';
16+
* import { B2CInstance, BasicAuthStrategy } from '@salesforce/b2c-tooling';
17+
*
18+
* const auth = new BasicAuthStrategy('username', 'access-key');
19+
* const instance = new B2CInstance(
20+
* { hostname: 'your-sandbox.demandware.net', codeVersion: 'v1' },
21+
* auth
22+
* );
23+
*
24+
* // Upload cartridges from local directory
25+
* await uploadCartridges(instance, './cartridges');
26+
*
27+
* // Activate the code version
28+
* await activateCodeVersion(instance, 'v1');
29+
* ```
30+
*
31+
* ## Authentication
32+
*
33+
* Code deployment uses WebDAV, which supports both Basic Auth and OAuth.
34+
* Basic Auth is recommended for better performance.
35+
*
36+
* @module operations/code
37+
*/
138
export {uploadCartridges, activateCodeVersion} from './upload.js';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1+
/**
2+
* Job execution operations for B2C Commerce.
3+
*
4+
* This module provides functions for running and monitoring jobs
5+
* on B2C Commerce instances via OCAPI.
6+
*
7+
* ## Functions
8+
*
9+
* - {@link runJob} - Start a job execution
10+
* - {@link getJobStatus} - Check the status of a running job
11+
*
12+
* ## Usage
13+
*
14+
* ```typescript
15+
* import { runJob, getJobStatus } from '@salesforce/b2c-tooling/operations/jobs';
16+
* import { B2CInstance, OAuthStrategy } from '@salesforce/b2c-tooling';
17+
*
18+
* const auth = new OAuthStrategy({
19+
* clientId: 'your-client-id',
20+
* clientSecret: 'your-client-secret',
21+
* });
22+
* const instance = new B2CInstance(
23+
* { hostname: 'your-sandbox.demandware.net' },
24+
* auth
25+
* );
26+
*
27+
* // Start a job
28+
* const result = await runJob(instance, 'my-job-id');
29+
*
30+
* // Poll for completion
31+
* let status = await getJobStatus(instance, result.jobId, result.executionId);
32+
* while (status.status === 'running') {
33+
* await new Promise(resolve => setTimeout(resolve, 5000));
34+
* status = await getJobStatus(instance, result.jobId, result.executionId);
35+
* }
36+
* ```
37+
*
38+
* ## Authentication
39+
*
40+
* Job operations require OAuth authentication with appropriate OCAPI permissions.
41+
*
42+
* @module operations/jobs
43+
*/
144
export {runJob, getJobStatus, JobExecutionResult} from './run.js';

packages/b2c-tooling/src/operations/sites/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
/**
2+
* Site management operations for B2C Commerce.
3+
*
4+
* This module provides functions for listing and retrieving site information
5+
* from B2C Commerce instances via OCAPI.
6+
*
7+
* ## Functions
8+
*
9+
* - {@link listSites} - List all sites on an instance
10+
* - {@link getSite} - Get details for a specific site
11+
*
12+
* ## Usage
13+
*
14+
* ```typescript
15+
* import { listSites, getSite } from '@salesforce/b2c-tooling/operations/sites';
16+
* import { B2CInstance, OAuthStrategy } from '@salesforce/b2c-tooling';
17+
*
18+
* const auth = new OAuthStrategy({
19+
* clientId: 'your-client-id',
20+
* clientSecret: 'your-client-secret',
21+
* });
22+
* const instance = new B2CInstance(
23+
* { hostname: 'your-sandbox.demandware.net' },
24+
* auth
25+
* );
26+
*
27+
* // List all sites
28+
* const sites = await listSites(instance);
29+
* for (const site of sites) {
30+
* console.log(`${site.id}: ${site.displayName} (${site.status})`);
31+
* }
32+
*
33+
* // Get a specific site
34+
* const site = await getSite(instance, 'RefArch');
35+
* ```
36+
*
37+
* ## Authentication
38+
*
39+
* Site operations require OAuth authentication with appropriate OCAPI permissions.
40+
*
41+
* @module operations/sites
42+
*/
143
import {B2CInstance} from '../../instance/index.js';
244

345
export interface Site {

0 commit comments

Comments
 (0)