
Security News
/Research
Fake Corepack Site Distributes Infostealer and Proxyware to Developers
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.
@chargebee/code-samples
Advanced tools
A self-contained, reusable React component for generating and displaying API code samples from OpenAPI specifications
A self-contained, reusable React component for displaying API code samples with syntax highlighting, language switching, and copy functionality.
createCodeGenerator)pnpm add @chargebee/code-samples
import { CodeSamples } from '@chargebee/code-samples';
import '@chargebee/code-samples/styles';
function MyPage() {
return (
<CodeSamples
codeString={`curl https://your-site.chargebee.com/api/v2/customers \\
-u test_api_key: \\
-X POST \\
-d "first_name=John&last_name=Doe"`}
language="curl"
theme="github-light"
features={{
copyButton: true,
showLineNumbers: true,
}}
/>
);
}
import { CodeSamples } from '@chargebee/code-samples';
import '@chargebee/code-samples/styles';
function MyPage() {
// Pre-generate samples using generateCodeSamples (see Pure Function API below)
const samples = {
'curl': 'curl https://...',
'node-v3': 'const chargebee = new Chargebee({...})',
'python-v3': 'import chargebee\nchargebee.configure(...)',
};
return (
<CodeSamples
samples={samples}
initialLanguage="node-v3"
theme="github-light"
features={{
carousel: true,
copyButton: true,
showLanguageSwitcher: true,
}}
/>
);
}
| Prop | Type | Required | Description |
|---|---|---|---|
codeString | string | ❌ | Raw code string to display (simplest usage) |
language | string | ❌ | Language identifier (required if codeString is provided) |
samples | Record<string, string> | Array<{languageSnippets: Record<string, string>}> | ❌ | Pre-generated code samples object or array |
responseData | any | ❌ | Sample response JSON to display |
initialLanguage | string | ❌ | Initial language selection (default: first language) |
theme | string | ThemeConfig | ❌ | Shiki theme name or custom config (default: "github-dark") |
highlighter | HighlighterConfig | ❌ | Shiki highlighter configuration |
features | FeaturesConfig | ❌ | Feature toggles (see below) |
className | string | ❌ | Additional CSS classes |
style | React.CSSProperties | ❌ | Inline styles |
replacements | Record<string, string> | ❌ | String replacements (e.g., {"{site}": "acme"}) |
onLanguageChange | (lang: string) => void | ❌ | Language change callback |
onCopy | (code: string) => void | ❌ | Copy callback |
onSampleChange | (index: number) => void | ❌ | Sample change callback (for carousel) |
| Feature | Type | Default | Description |
|---|---|---|---|
carousel | boolean | false | Enable carousel for multiple samples |
copyButton | boolean | true | Show copy-to-clipboard button |
animations | boolean | true | Enable fade transitions |
showHeader | boolean | true | Show/hide entire header |
showLanguageSwitcher | boolean | true | Show/hide language dropdown |
showApiExplorer | boolean | false | Show "Try in API Explorer" button |
showLineNumbers | boolean | true | Show line numbers in code blocks |
title | string | "Sample Request" | Header title |
languageFilter | string[] | undefined | Show only specific languages |
onApiExplorerClick | () => void | undefined | Callback for API Explorer button |
For advanced usage, you can import sub-components and hooks to build custom implementations:
import {
CodeBlock, // Syntax-highlighted code display
CodeSampleHeader, // Header with title and copy button
Carousel, // Multi-sample navigation
LanguageSwitcher // Language dropdown
} from '@chargebee/code-samples';
// Use CodeBlock for simple code display
<CodeBlock
code="const x = 1;"
language="typescript"
theme="github-light"
/>
import {
useSampleLoader, // Load and normalize samples
useLanguageSelection // Manage language state
} from '@chargebee/code-samples';
function MyCustomComponent() {
const { samples, loading } = useSampleLoader({ /* ... */ });
const { language, setLanguage } = useLanguageSelection();
// ...
}
import {
AVAILABLE_LANGUAGES, // List of supported languages
DEFAULT_LANGUAGE, // Default language ("curl")
DEFAULT_THEME // Default theme ("github-dark")
} from '@chargebee/code-samples';
# Install dependencies
pnpm install
# Start dev server (port 5001)
pnpm dev
# Build for production
pnpm build
Important: The CodeSamples component is a display component - it renders pre-generated code strings. It does NOT generate code from OpenAPI specs.
To generate code from OpenAPI specs, use the generateCodeSample or generateCodeSamples functions (see Pure Function API below), then pass the result to the component:
import { CodeSamples } from '@chargebee/code-samples';
import { generateCodeSamples } from '@chargebee/code-samples';
// In your loader/server component (SSG/SSR)
export async function loader() {
const samples = await generateCodeSamples({
languages: ['curl', 'node-v3', 'python-v3'],
resource: 'customer',
operation: 'create_a_customer',
apiVersion: 'v2',
pcVersion: 'v2',
site: 'acme-test',
apiKey: 'test_api_key',
request: {
params: { first_name: 'John', last_name: 'Doe' },
body: { email: 'john@example.com' }
}
});
return { samples };
}
// In your React component
function MyPage({ samples }) {
return <CodeSamples samples={samples} />;
}
For browser environments that need to generate code dynamically, use the browser export:
import { createCodeGenerator } from '@chargebee/code-samples/browser';
// Create a generator instance
const generator = createCodeGenerator({
specsBaseUrl: 'https://unpkg.com/@chargebee/code-samples@latest/dist/specs',
apiVersion: 'v2',
pcVersion: 'v2',
site: 'acme-test',
apiKey: 'test_api_key',
cache: 'memory' // Only 'memory' is supported in browser
});
// Generate code for a specific operation
const result = await generator.generate({
language: 'curl',
operationId: 'create_a_customer',
requestSample: {
params: { first_name: 'John', last_name: 'Doe' },
body: { email: 'john@example.com' }
}
});
console.log(result.code); // Generated code string
Note: The browser export uses memory-only caching and fetches OpenAPI specs from a CDN. It's optimized for client-side usage.
For Node.js, LLMs, Deno, Bun, or server-side generation (SSG/SSR), use the pure function API:
import { generateCodeSample, generateCodeSamples } from '@chargebee/code-samples';
// Generate code for a specific language
const result = await generateCodeSample({
language: 'node-v3',
resource: 'customer',
operation: 'create_a_customer',
apiVersion: 'v2',
pcVersion: 'v2',
site: 'acme-test',
apiKey: 'test_api_key',
request: {
params: { first_name: 'John', last_name: 'Doe' },
body: { email: 'john@example.com' }
}
});
console.log(result.code); // Generated Node.js code string
console.log(result.language); // 'node-v3'
// Generate code for multiple languages
const allSamples = await generateCodeSamples({
languages: ['curl', 'node-v3', 'python-v3', 'java'],
resource: 'customer',
operation: 'create_a_customer',
apiVersion: 'v2',
pcVersion: 'v2',
site: 'acme-test',
apiKey: 'test_api_key',
request: {
params: { first_name: 'John' },
body: { email: 'john@example.com' }
}
});
console.log(allSamples['node-v3']); // Node.js code
console.log(allSamples['python-v3']); // Python code
// Or use pre-generated samples (no generation needed)
const result = await generateCodeSample({
language: 'python-v3',
samples: {
'python-v3': 'import chargebee\nchargebee.configure(...)'
}
});
Use Cases:
The code generators use pre-generated operation descriptors (bundled with the package). No external OpenAPI utils dependency is required:
import { getGenerator, getSupportedLanguages, getOperation } from '@chargebee/code-samples';
// Get list of supported languages
const languages = getSupportedLanguages(); // ['curl', 'node-v3', 'python-v3', ...]
// Get generator for a specific language
const generator = getGenerator('node-v3');
// Get operation descriptor
const operation = getOperation('v2-pcv2', 'create_a_customer');
import type {
CodeSamplesPropsInterface,
GenerateCodeSampleOptions,
GenerateCodeSampleResult,
Language,
ApiVersion,
OperationDescriptor
} from '@chargebee/code-samples';
import {
GoToApiExplorer, // Link to API Explorer
TryInApiExplorer // Button to try in API Explorer
} from '@chargebee/code-samples';
MIT
FAQs
A self-contained, reusable React component for generating and displaying API code samples from OpenAPI specifications
The npm package @chargebee/code-samples receives a total of 0 weekly downloads. As such, @chargebee/code-samples popularity was classified as not popular.
We found that @chargebee/code-samples demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.

Research
/Security News
A large-scale campaign abused GitHub Actions in compromised repositories to exploit CVE-2026-41940 in cPanel and WHM and steal server credentials.

Security News
Five frontier LLMs generated the same nonexistent package names, leaving 53 available for potential slopsquatting across PyPI and npm.