omni-sync-sdk 0.19.2 → 0.19.4

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.d.mts CHANGED
@@ -1338,6 +1338,16 @@ interface AddToCartDto {
1338
1338
  quantity: number;
1339
1339
  notes?: string;
1340
1340
  metadata?: Record<string, unknown>;
1341
+ /**
1342
+ * Optional product info for local cart (guest mode).
1343
+ * If provided, SDK uses this directly without fetching from API.
1344
+ * Recommended: pass this when you already have the product loaded.
1345
+ */
1346
+ productInfo?: {
1347
+ name: string;
1348
+ price: string;
1349
+ image?: string;
1350
+ };
1341
1351
  }
1342
1352
  interface UpdateCartItemDto {
1343
1353
  quantity: number;
package/dist/index.d.ts CHANGED
@@ -1338,6 +1338,16 @@ interface AddToCartDto {
1338
1338
  quantity: number;
1339
1339
  notes?: string;
1340
1340
  metadata?: Record<string, unknown>;
1341
+ /**
1342
+ * Optional product info for local cart (guest mode).
1343
+ * If provided, SDK uses this directly without fetching from API.
1344
+ * Recommended: pass this when you already have the product loaded.
1345
+ */
1346
+ productInfo?: {
1347
+ name: string;
1348
+ price: string;
1349
+ image?: string;
1350
+ };
1341
1351
  }
1342
1352
  interface UpdateCartItemDto {
1343
1353
  quantity: number;
package/dist/index.js CHANGED
@@ -1759,21 +1759,27 @@ var OmniSyncClient = class {
1759
1759
  let productName = "Unknown Product";
1760
1760
  let productPrice = "0";
1761
1761
  let productImage;
1762
- try {
1763
- const product = await this.getProduct(item.productId);
1764
- productName = product.name;
1765
- productPrice = product.salePrice || product.basePrice;
1766
- productImage = product.images?.[0]?.url;
1767
- if (item.variantId && product.variants) {
1768
- const variant = product.variants.find((v) => v.id === item.variantId);
1769
- if (variant) {
1770
- productPrice = variant.salePrice || variant.price || productPrice;
1771
- if (variant.image) {
1772
- productImage = typeof variant.image === "string" ? variant.image : variant.image.url;
1762
+ if (item.productInfo) {
1763
+ productName = item.productInfo.name;
1764
+ productPrice = item.productInfo.price;
1765
+ productImage = item.productInfo.image;
1766
+ } else {
1767
+ try {
1768
+ const product = await this.getProduct(item.productId);
1769
+ productName = product.name;
1770
+ productPrice = product.salePrice || product.basePrice;
1771
+ productImage = product.images?.[0]?.url;
1772
+ if (item.variantId && product.variants) {
1773
+ const variant = product.variants.find((v) => v.id === item.variantId);
1774
+ if (variant) {
1775
+ productPrice = variant.salePrice || variant.price || productPrice;
1776
+ if (variant.image) {
1777
+ productImage = typeof variant.image === "string" ? variant.image : variant.image.url;
1778
+ }
1773
1779
  }
1774
1780
  }
1781
+ } catch {
1775
1782
  }
1776
- } catch {
1777
1783
  }
1778
1784
  this.addToLocalCart({
1779
1785
  productId: item.productId,
@@ -4387,7 +4393,15 @@ function getCartItemImage(item) {
4387
4393
  if (imgObj.url) return imgObj.url;
4388
4394
  }
4389
4395
  }
4390
- return item.product.images?.[0]?.url;
4396
+ const firstImage = item.product.images?.[0];
4397
+ if (typeof firstImage === "string") {
4398
+ return firstImage;
4399
+ }
4400
+ if (typeof firstImage === "object" && firstImage !== null) {
4401
+ const imgObj = firstImage;
4402
+ if (imgObj.url) return imgObj.url;
4403
+ }
4404
+ return void 0;
4391
4405
  }
4392
4406
  function getVariantOptions(variant) {
4393
4407
  if (!variant?.attributes) return [];
package/dist/index.mjs CHANGED
@@ -1722,21 +1722,27 @@ var OmniSyncClient = class {
1722
1722
  let productName = "Unknown Product";
1723
1723
  let productPrice = "0";
1724
1724
  let productImage;
1725
- try {
1726
- const product = await this.getProduct(item.productId);
1727
- productName = product.name;
1728
- productPrice = product.salePrice || product.basePrice;
1729
- productImage = product.images?.[0]?.url;
1730
- if (item.variantId && product.variants) {
1731
- const variant = product.variants.find((v) => v.id === item.variantId);
1732
- if (variant) {
1733
- productPrice = variant.salePrice || variant.price || productPrice;
1734
- if (variant.image) {
1735
- productImage = typeof variant.image === "string" ? variant.image : variant.image.url;
1725
+ if (item.productInfo) {
1726
+ productName = item.productInfo.name;
1727
+ productPrice = item.productInfo.price;
1728
+ productImage = item.productInfo.image;
1729
+ } else {
1730
+ try {
1731
+ const product = await this.getProduct(item.productId);
1732
+ productName = product.name;
1733
+ productPrice = product.salePrice || product.basePrice;
1734
+ productImage = product.images?.[0]?.url;
1735
+ if (item.variantId && product.variants) {
1736
+ const variant = product.variants.find((v) => v.id === item.variantId);
1737
+ if (variant) {
1738
+ productPrice = variant.salePrice || variant.price || productPrice;
1739
+ if (variant.image) {
1740
+ productImage = typeof variant.image === "string" ? variant.image : variant.image.url;
1741
+ }
1736
1742
  }
1737
1743
  }
1744
+ } catch {
1738
1745
  }
1739
- } catch {
1740
1746
  }
1741
1747
  this.addToLocalCart({
1742
1748
  productId: item.productId,
@@ -4350,7 +4356,15 @@ function getCartItemImage(item) {
4350
4356
  if (imgObj.url) return imgObj.url;
4351
4357
  }
4352
4358
  }
4353
- return item.product.images?.[0]?.url;
4359
+ const firstImage = item.product.images?.[0];
4360
+ if (typeof firstImage === "string") {
4361
+ return firstImage;
4362
+ }
4363
+ if (typeof firstImage === "object" && firstImage !== null) {
4364
+ const imgObj = firstImage;
4365
+ if (imgObj.url) return imgObj.url;
4366
+ }
4367
+ return void 0;
4354
4368
  }
4355
4369
  function getVariantOptions(variant) {
4356
4370
  if (!variant?.attributes) return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-sync-sdk",
3
- "version": "0.19.2",
3
+ "version": "0.19.4",
4
4
  "description": "Official SDK for building e-commerce storefronts with OmniSync Platform. Perfect for vibe-coded sites, AI-built stores (Cursor, Lovable, v0), and custom storefronts.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -16,6 +16,14 @@
16
16
  "dist",
17
17
  "README.md"
18
18
  ],
19
+ "scripts": {
20
+ "build": "tsup src/index.ts --format cjs,esm --dts",
21
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
22
+ "lint": "eslint \"src/**/*.ts\"",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "prepublishOnly": "pnpm build"
26
+ },
19
27
  "keywords": [
20
28
  "omni-sync",
21
29
  "e-commerce",
@@ -64,12 +72,5 @@
64
72
  "typescript": {
65
73
  "optional": true
66
74
  }
67
- },
68
- "scripts": {
69
- "build": "tsup src/index.ts --format cjs,esm --dts",
70
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
71
- "lint": "eslint \"src/**/*.ts\"",
72
- "test": "vitest run",
73
- "test:watch": "vitest"
74
75
  }
75
- }
76
+ }
package/LICENSE DELETED
File without changes