@yassirbenmoussa/aicommerce-sdk
v1.9.15
Published
AI Commerce SDK - AI-powered product recommendations for e-commerce
Maintainers
Readme
AI Commerce SDK
AI-powered product recommendations for e-commerce. This SDK allows you to easily integrate AI Commerce into your website or application.
Installation
npm / yarn / pnpm
npm install @yassirbenmoussa/aicommerce-sdk
# or
yarn add @yassirbenmoussa/aicommerce-sdk
# or
pnpm add @yassirbenmoussa/aicommerce-sdkScript Tag (CDN)
<script src="https://cdn.aicommerce.dev/sdk/ai-commerce.min.js"></script>Quick Start
ES Modules / TypeScript
import { AICommerce } from '@yassirbenmoussa/aicommerce-sdk';
// Initialize the client
const client = new AICommerce({
apiKey: 'your-api-key',
storeId: 'your-store-id',
});
// Send a message and get product recommendations
const response = await client.chat('I need a laptop under $1000');
console.log(response.reply); // AI response text
console.log(response.products); // Recommended productsCommonJS
const { AICommerce } = require('@yassirbenmoussa/aicommerce-sdk');
const client = new AICommerce({
apiKey: 'your-api-key',
storeId: 'your-store-id',
});
client.chat('I need a laptop').then(response => {
console.log(response.products);
});Script Tag
<script src="https://cdn.aicommerce.dev/sdk/ai-commerce.min.js"></script>
<script>
const client = new AICommerceSDK.AICommerce({
apiKey: 'your-api-key',
storeId: 'your-store-id'
});
client.chat('I need a laptop').then(response => {
console.log(response.products);
});
</script>API Reference
new AICommerce(config)
Create a new AI Commerce client.
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| apiKey | string | Yes | Your API key from the dashboard |
| storeId | string | Yes | Your Store ID from the dashboard |
| baseUrl | string | No | API base URL (defaults to auto-detect) |
| timeout | number | No | Request timeout in ms (default: 30000) |
client.chat(message, context?)
Send a message and get product recommendations.
const response = await client.chat('I need running shoes', {
budget: { max: 150, currency: 'USD' },
preferences: ['comfortable', 'lightweight']
});Returns:
{
reply: string; // AI response text
products: Product[]; // Recommended products
sessionToken: string; // For follow-up messages
suggestions?: string[]; // Suggested follow-up questions
confidence?: number; // AI confidence score (0-1)
}client.createSession()
Create a new chat session explicitly.
const session = await client.createSession();
console.log(session.token);client.clearSession()
Clear the current session token.
AICommerce.quickChat(options)
Static method for one-off requests without creating a client instance.
const response = await AICommerce.quickChat({
apiKey: 'your-api-key',
message: 'I need a laptop',
context: { budget: { max: 1000 } }
});TypeScript Support
Full TypeScript support with exported types:
import type {
AICommerceConfig,
ChatRequest,
ChatResponse,
Product,
ChatContext
} from '@yassirbenmoussa/aicommerce-sdk';Error Handling
import { AICommerce, AICommerceError } from '@yassirbenmoussa/aicommerce-sdk';
try {
const response = await client.chat('Hello');
} catch (error) {
if (error instanceof AICommerceError) {
console.log(error.code); // Error code (e.g., 'UNAUTHORIZED')
console.log(error.status); // HTTP status code
console.log(error.message); // Error message
}
}License
MIT
