omni-sync-sdk 0.1.1 → 0.2.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/dist/index.js CHANGED
@@ -63,9 +63,8 @@ var OmniSyncClient = class {
63
63
  headers: {
64
64
  Authorization: `Bearer ${this.apiKey}`,
65
65
  "Content-Type": "application/json",
66
- "X-SDK-Version": "0.1.0",
66
+ "X-SDK-Version": "0.1.1",
67
67
  "ngrok-skip-browser-warning": "true"
68
- // Skip ngrok warning page for dev tunnels
69
68
  },
70
69
  body: body ? JSON.stringify(body) : void 0,
71
70
  signal: controller.signal
@@ -135,6 +134,147 @@ var OmniSyncClient = class {
135
134
  async deleteProduct(productId) {
136
135
  await this.request("DELETE", `/api/v1/products/${productId}`);
137
136
  }
137
+ /**
138
+ * Convert a SIMPLE product to VARIABLE product
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const product = await omni.convertToVariable('prod_123');
143
+ * console.log('Product type:', product.type); // 'VARIABLE'
144
+ * ```
145
+ */
146
+ async convertToVariable(productId) {
147
+ return this.request("PATCH", `/api/v1/products/${productId}/convert-to-variable`);
148
+ }
149
+ /**
150
+ * Convert a VARIABLE product to SIMPLE product
151
+ * Note: This will delete all variants
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const product = await omni.convertToSimple('prod_123');
156
+ * console.log('Product type:', product.type); // 'SIMPLE'
157
+ * ```
158
+ */
159
+ async convertToSimple(productId) {
160
+ return this.request("PATCH", `/api/v1/products/${productId}/convert-to-simple`);
161
+ }
162
+ /**
163
+ * Publish a product to specific platforms
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * const result = await omni.publishProduct('prod_123', ['SHOPIFY', 'WOOCOMMERCE']);
168
+ * console.log('Publish results:', result.results);
169
+ * ```
170
+ */
171
+ async publishProduct(productId, platforms) {
172
+ return this.request("POST", `/api/v1/products/${productId}/publish`, {
173
+ platforms
174
+ });
175
+ }
176
+ // -------------------- Variants --------------------
177
+ /**
178
+ * Create a new variant for a product
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const variant = await omni.createVariant('prod_123', {
183
+ * sku: 'PROD-SM-RED',
184
+ * name: 'Small / Red',
185
+ * attributes: { size: 'S', color: 'Red' },
186
+ * price: 29.99,
187
+ * inventory: 100,
188
+ * });
189
+ * ```
190
+ */
191
+ async createVariant(productId, data) {
192
+ return this.request("POST", `/api/v1/products/${productId}/variants`, data);
193
+ }
194
+ /**
195
+ * Bulk save variants (create, update, delete in one operation)
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const result = await omni.bulkSaveVariants('prod_123', {
200
+ * variants: [
201
+ * { sku: 'SM-RED', attributes: { size: 'S', color: 'Red' }, stock: 10, isEnabled: true },
202
+ * { id: 'var_456', sku: 'MD-BLUE', attributes: { size: 'M', color: 'Blue' }, stock: 5, isEnabled: true },
203
+ * { id: 'var_789', sku: 'LG-GREEN', attributes: {}, stock: 0, isEnabled: false, isDeleted: true },
204
+ * ],
205
+ * });
206
+ * console.log(`Created: ${result.created}, Updated: ${result.updated}, Deleted: ${result.deleted}`);
207
+ * ```
208
+ */
209
+ async bulkSaveVariants(productId, data) {
210
+ return this.request(
211
+ "POST",
212
+ `/api/v1/products/${productId}/variants/bulk`,
213
+ data
214
+ );
215
+ }
216
+ /**
217
+ * Update a variant
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * const variant = await omni.updateVariant('prod_123', 'var_456', {
222
+ * price: 34.99,
223
+ * salePrice: 29.99,
224
+ * });
225
+ * ```
226
+ */
227
+ async updateVariant(productId, variantId, data) {
228
+ return this.request(
229
+ "PATCH",
230
+ `/api/v1/products/${productId}/variants/${variantId}`,
231
+ data
232
+ );
233
+ }
234
+ /**
235
+ * Delete a variant
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * await omni.deleteVariant('prod_123', 'var_456');
240
+ * ```
241
+ */
242
+ async deleteVariant(productId, variantId) {
243
+ await this.request("DELETE", `/api/v1/products/${productId}/variants/${variantId}`);
244
+ }
245
+ /**
246
+ * Get inventory for a specific variant
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const inventory = await omni.getVariantInventory('prod_123', 'var_456');
251
+ * console.log('Available:', inventory.available);
252
+ * ```
253
+ */
254
+ async getVariantInventory(productId, variantId) {
255
+ return this.request(
256
+ "GET",
257
+ `/api/v1/products/${productId}/variants/${variantId}/inventory`
258
+ );
259
+ }
260
+ /**
261
+ * Update inventory for a specific variant
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * const inventory = await omni.updateVariantInventory('prod_123', 'var_456', {
266
+ * newTotal: 50,
267
+ * reason: 'Restocked from supplier',
268
+ * });
269
+ * ```
270
+ */
271
+ async updateVariantInventory(productId, variantId, data) {
272
+ return this.request(
273
+ "PATCH",
274
+ `/api/v1/products/${productId}/variants/${variantId}/inventory`,
275
+ data
276
+ );
277
+ }
138
278
  // -------------------- Orders --------------------
139
279
  /**
140
280
  * Get a list of orders with pagination
@@ -167,6 +307,209 @@ var OmniSyncClient = class {
167
307
  async updateOrder(orderId, data) {
168
308
  return this.request("PATCH", `/api/v1/orders/${orderId}`, data);
169
309
  }
310
+ /**
311
+ * Update order status
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * const order = await omni.updateOrderStatus('order_123', 'shipped');
316
+ * ```
317
+ */
318
+ async updateOrderStatus(orderId, status) {
319
+ return this.request("PATCH", `/api/v1/orders/${orderId}/status`, { status });
320
+ }
321
+ /**
322
+ * Update order payment method
323
+ * Note: Only WooCommerce supports syncing payment method changes back to platform
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * const order = await omni.updatePaymentMethod('order_123', 'credit_card');
328
+ * ```
329
+ */
330
+ async updatePaymentMethod(orderId, paymentMethod) {
331
+ return this.request("PATCH", `/api/v1/orders/${orderId}/payment-method`, {
332
+ paymentMethod
333
+ });
334
+ }
335
+ /**
336
+ * Update order notes
337
+ *
338
+ * @example
339
+ * ```typescript
340
+ * const order = await omni.updateOrderNotes('order_123', 'Customer requested gift wrapping');
341
+ * ```
342
+ */
343
+ async updateOrderNotes(orderId, notes) {
344
+ return this.request("PATCH", `/api/v1/orders/${orderId}/notes`, { notes });
345
+ }
346
+ /**
347
+ * Get refunds for an order
348
+ * Returns refunds from the source platform (Shopify/WooCommerce only)
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * const refunds = await omni.getOrderRefunds('order_123');
353
+ * console.log('Total refunds:', refunds.length);
354
+ * ```
355
+ */
356
+ async getOrderRefunds(orderId) {
357
+ return this.request("GET", `/api/v1/orders/${orderId}/refunds`);
358
+ }
359
+ /**
360
+ * Create a refund for an order
361
+ * Creates refund on the source platform (Shopify/WooCommerce only)
362
+ *
363
+ * @example
364
+ * ```typescript
365
+ * // Full refund
366
+ * const refund = await omni.createRefund('order_123', {
367
+ * type: 'full',
368
+ * restockInventory: true,
369
+ * notifyCustomer: true,
370
+ * reason: 'Customer request',
371
+ * });
372
+ *
373
+ * // Partial refund
374
+ * const partialRefund = await omni.createRefund('order_123', {
375
+ * type: 'partial',
376
+ * items: [
377
+ * { lineItemId: 'item_456', quantity: 1 },
378
+ * ],
379
+ * restockInventory: true,
380
+ * });
381
+ * ```
382
+ */
383
+ async createRefund(orderId, data) {
384
+ return this.request("POST", `/api/v1/orders/${orderId}/refunds`, data);
385
+ }
386
+ /**
387
+ * Update order shipping address
388
+ * Syncs to source platform (Shopify/WooCommerce only)
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * const order = await omni.updateOrderShipping('order_123', {
393
+ * firstName: 'John',
394
+ * lastName: 'Doe',
395
+ * line1: '456 New Address',
396
+ * city: 'Los Angeles',
397
+ * state: 'CA',
398
+ * country: 'US',
399
+ * postalCode: '90001',
400
+ * });
401
+ * ```
402
+ */
403
+ async updateOrderShipping(orderId, data) {
404
+ return this.request("PATCH", `/api/v1/orders/${orderId}/shipping`, data);
405
+ }
406
+ /**
407
+ * Cancel an order
408
+ * Works for Shopify and WooCommerce orders that haven't been fulfilled
409
+ *
410
+ * @example
411
+ * ```typescript
412
+ * const order = await omni.cancelOrder('order_123');
413
+ * console.log('Order status:', order.status); // 'cancelled'
414
+ * ```
415
+ */
416
+ async cancelOrder(orderId) {
417
+ return this.request("POST", `/api/v1/orders/${orderId}/cancel`);
418
+ }
419
+ /**
420
+ * Fulfill an order (mark as shipped)
421
+ * Works for Shopify and WooCommerce orders
422
+ *
423
+ * @example
424
+ * ```typescript
425
+ * const order = await omni.fulfillOrder('order_123', {
426
+ * trackingNumber: '1Z999AA10123456784',
427
+ * trackingCompany: 'UPS',
428
+ * notifyCustomer: true,
429
+ * });
430
+ * ```
431
+ */
432
+ async fulfillOrder(orderId, data) {
433
+ return this.request("POST", `/api/v1/orders/${orderId}/fulfill`, data || {});
434
+ }
435
+ /**
436
+ * Sync draft orders from connected platforms
437
+ *
438
+ * @example
439
+ * ```typescript
440
+ * const result = await omni.syncDraftOrders();
441
+ * console.log('Draft orders synced');
442
+ * ```
443
+ */
444
+ async syncDraftOrders() {
445
+ return this.request("POST", "/api/v1/orders/sync-drafts");
446
+ }
447
+ /**
448
+ * Complete a draft order (convert to regular order)
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * const order = await omni.completeDraftOrder('draft_123', {
453
+ * paymentPending: false,
454
+ * });
455
+ * ```
456
+ */
457
+ async completeDraftOrder(orderId, data) {
458
+ return this.request("POST", `/api/v1/orders/${orderId}/complete-draft`, data || {});
459
+ }
460
+ /**
461
+ * Send invoice for a draft order
462
+ *
463
+ * @example
464
+ * ```typescript
465
+ * await omni.sendDraftInvoice('draft_123', {
466
+ * to: 'customer@example.com',
467
+ * subject: 'Your Invoice',
468
+ * customMessage: 'Thank you for your order!',
469
+ * });
470
+ * ```
471
+ */
472
+ async sendDraftInvoice(orderId, data) {
473
+ return this.request(
474
+ "POST",
475
+ `/api/v1/orders/${orderId}/send-invoice`,
476
+ data || {}
477
+ );
478
+ }
479
+ /**
480
+ * Delete a draft order
481
+ *
482
+ * @example
483
+ * ```typescript
484
+ * await omni.deleteDraftOrder('draft_123');
485
+ * ```
486
+ */
487
+ async deleteDraftOrder(orderId) {
488
+ await this.request("DELETE", `/api/v1/orders/${orderId}/draft`);
489
+ }
490
+ /**
491
+ * Update a draft order
492
+ *
493
+ * @example
494
+ * ```typescript
495
+ * const order = await omni.updateDraftOrder('draft_123', {
496
+ * note: 'Updated customer note',
497
+ * email: 'newemail@example.com',
498
+ * shippingAddress: {
499
+ * firstName: 'John',
500
+ * lastName: 'Doe',
501
+ * address1: '123 Main St',
502
+ * city: 'New York',
503
+ * province: 'NY',
504
+ * country: 'US',
505
+ * zip: '10001',
506
+ * },
507
+ * });
508
+ * ```
509
+ */
510
+ async updateDraftOrder(orderId, data) {
511
+ return this.request("PATCH", `/api/v1/orders/${orderId}/draft`, data);
512
+ }
170
513
  // -------------------- Inventory --------------------
171
514
  /**
172
515
  * Update inventory for a product
@@ -179,7 +522,74 @@ var OmniSyncClient = class {
179
522
  * Get current inventory for a product
180
523
  */
181
524
  async getInventory(productId) {
182
- return this.request("GET", `/api/v1/products/${productId}/inventory`);
525
+ return this.request("GET", `/api/v1/inventory/${productId}`);
526
+ }
527
+ /**
528
+ * Edit inventory manually with reason for audit trail
529
+ *
530
+ * @example
531
+ * ```typescript
532
+ * const inventory = await omni.editInventory({
533
+ * productId: 'prod_123',
534
+ * newTotal: 100,
535
+ * reason: 'Restocked from warehouse',
536
+ * });
537
+ * ```
538
+ */
539
+ async editInventory(data) {
540
+ return this.request("POST", "/api/v1/inventory/edit", data);
541
+ }
542
+ /**
543
+ * Get inventory sync status for all products in the store
544
+ *
545
+ * @example
546
+ * ```typescript
547
+ * const status = await omni.getInventorySyncStatus();
548
+ * console.log(`${status.pending} products pending sync`);
549
+ * console.log(`Last sync: ${status.lastSyncAt}`);
550
+ * ```
551
+ */
552
+ async getInventorySyncStatus() {
553
+ return this.request("GET", "/api/v1/inventory/sync-status");
554
+ }
555
+ /**
556
+ * Get inventory for multiple products at once
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * const inventories = await omni.getBulkInventory(['prod_123', 'prod_456', 'prod_789']);
561
+ * inventories.forEach(inv => {
562
+ * console.log(`${inv.productId}: ${inv.available} available`);
563
+ * });
564
+ * ```
565
+ */
566
+ async getBulkInventory(productIds) {
567
+ return this.request("POST", "/api/v1/inventory/bulk", { productIds });
568
+ }
569
+ /**
570
+ * Reconcile inventory between OmniSync and connected platforms
571
+ * Detects and optionally fixes discrepancies
572
+ *
573
+ * @example
574
+ * ```typescript
575
+ * // Reconcile single product (dry run)
576
+ * const result = await omni.reconcileInventory({ productId: 'prod_123' });
577
+ *
578
+ * // Reconcile all products with auto-fix
579
+ * const summary = await omni.reconcileInventory({ autoFix: true });
580
+ * console.log(`Reconciled ${summary.reconciled} products`);
581
+ * ```
582
+ */
583
+ async reconcileInventory(options) {
584
+ const queryParams = {};
585
+ if (options?.productId) queryParams.productId = options.productId;
586
+ if (options?.autoFix) queryParams.autoFix = "true";
587
+ return this.request(
588
+ "POST",
589
+ "/api/v1/inventory/reconcile",
590
+ void 0,
591
+ queryParams
592
+ );
183
593
  }
184
594
  // -------------------- Sync --------------------
185
595
  /**