omni-sync-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,191 @@
1
+ # @omni-sync/sdk
2
+
3
+ SDK for integrating vibe coding stores with Omni-Sync Platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @omni-sync/sdk
9
+ # or
10
+ pnpm add @omni-sync/sdk
11
+ # or
12
+ yarn add @omni-sync/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { OmniSyncClient } from '@omni-sync/sdk';
19
+
20
+ const omni = new OmniSyncClient({
21
+ apiKey: process.env.OMNI_SYNC_API_KEY!,
22
+ });
23
+
24
+ // Get products
25
+ const { data: products } = await omni.getProducts();
26
+
27
+ // Create an order
28
+ const order = await omni.createOrder({
29
+ items: [
30
+ { productId: products[0].id, quantity: 2, price: 99.99 }
31
+ ],
32
+ customer: { email: 'customer@example.com', name: 'John Doe' },
33
+ totalAmount: 199.98,
34
+ });
35
+ ```
36
+
37
+ ## Products
38
+
39
+ ```typescript
40
+ // List products with pagination
41
+ const { data, meta } = await omni.getProducts({
42
+ page: 1,
43
+ limit: 20,
44
+ status: 'active',
45
+ search: 'shirt',
46
+ });
47
+
48
+ // Get single product
49
+ const product = await omni.getProduct('prod_123');
50
+
51
+ // Create product
52
+ const newProduct = await omni.createProduct({
53
+ name: 'Blue T-Shirt',
54
+ sku: 'TSHIRT-BLUE-M',
55
+ basePrice: 29.99,
56
+ status: 'active',
57
+ });
58
+
59
+ // Update product
60
+ const updated = await omni.updateProduct('prod_123', {
61
+ salePrice: 24.99,
62
+ });
63
+
64
+ // Delete product
65
+ await omni.deleteProduct('prod_123');
66
+ ```
67
+
68
+ ## Orders
69
+
70
+ ```typescript
71
+ // Create order (auto-deducts inventory, syncs to all platforms)
72
+ const order = await omni.createOrder({
73
+ items: [
74
+ { productId: 'prod_123', quantity: 1, price: 29.99 },
75
+ { productId: 'prod_456', quantity: 2, price: 49.99 },
76
+ ],
77
+ customer: {
78
+ email: 'john@example.com',
79
+ name: 'John Doe',
80
+ phone: '+1234567890',
81
+ },
82
+ totalAmount: 129.97,
83
+ });
84
+
85
+ // List orders
86
+ const { data: orders } = await omni.getOrders({
87
+ status: 'pending',
88
+ });
89
+
90
+ // Update order status
91
+ await omni.updateOrder('order_123', { status: 'shipped' });
92
+ ```
93
+
94
+ ## Inventory
95
+
96
+ ```typescript
97
+ // Get current inventory
98
+ const inventory = await omni.getInventory('prod_123');
99
+ console.log(`Available: ${inventory.available}`);
100
+
101
+ // Update inventory (syncs to all platforms)
102
+ await omni.updateInventory('prod_123', { quantity: 50 });
103
+ ```
104
+
105
+ ## Webhooks
106
+
107
+ Receive real-time updates when products, orders, or inventory change on any connected platform.
108
+
109
+ ### Setup webhook endpoint
110
+
111
+ ```typescript
112
+ // api/webhooks/omni-sync/route.ts (Next.js App Router)
113
+ import { verifyWebhook, createWebhookHandler } from '@omni-sync/sdk';
114
+
115
+ const handler = createWebhookHandler({
116
+ 'product.updated': async (event) => {
117
+ console.log('Product updated:', event.entityId);
118
+ // Invalidate cache, update UI, etc.
119
+ },
120
+ 'inventory.updated': async (event) => {
121
+ console.log('Stock changed:', event.data);
122
+ },
123
+ 'order.created': async (event) => {
124
+ console.log('New order from:', event.platform);
125
+ },
126
+ });
127
+
128
+ export async function POST(req: Request) {
129
+ const signature = req.headers.get('x-omni-signature');
130
+ const body = await req.json();
131
+
132
+ // Verify signature
133
+ if (!verifyWebhook(body, signature, process.env.OMNI_SYNC_WEBHOOK_SECRET!)) {
134
+ return new Response('Invalid signature', { status: 401 });
135
+ }
136
+
137
+ // Process event
138
+ await handler(body);
139
+
140
+ return new Response('OK');
141
+ }
142
+ ```
143
+
144
+ ### Webhook Events
145
+
146
+ | Event | Description |
147
+ |-------|-------------|
148
+ | `product.created` | New product created |
149
+ | `product.updated` | Product details changed |
150
+ | `product.deleted` | Product removed |
151
+ | `inventory.updated` | Stock levels changed |
152
+ | `order.created` | New order received |
153
+ | `order.updated` | Order status changed |
154
+
155
+ ## Environment Variables
156
+
157
+ ```env
158
+ OMNI_SYNC_API_KEY=omni_your_api_key_here
159
+ OMNI_SYNC_WEBHOOK_SECRET=your_webhook_secret_here
160
+ ```
161
+
162
+ ## Error Handling
163
+
164
+ ```typescript
165
+ import { OmniSyncClient, OmniSyncError } from '@omni-sync/sdk';
166
+
167
+ try {
168
+ const product = await omni.getProduct('invalid_id');
169
+ } catch (error) {
170
+ if (error instanceof OmniSyncError) {
171
+ console.error(`API Error: ${error.message} (${error.statusCode})`);
172
+ }
173
+ }
174
+ ```
175
+
176
+ ## TypeScript Support
177
+
178
+ Full TypeScript support with exported types:
179
+
180
+ ```typescript
181
+ import type {
182
+ Product,
183
+ Order,
184
+ CreateProductDto,
185
+ WebhookEvent
186
+ } from '@omni-sync/sdk';
187
+ ```
188
+
189
+ ## License
190
+
191
+ MIT