@anker-in/shopify-sdk 0.1.1-beta.16 → 0.1.1-beta.18

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
@@ -10280,6 +10280,7 @@ interface NormalizedCart {
10280
10280
  code: string;
10281
10281
  }>;
10282
10282
  discountAllocations?: Array<{
10283
+ title: string;
10283
10284
  code: string;
10284
10285
  amount: number;
10285
10286
  }>;
@@ -10400,6 +10401,8 @@ interface CreateCartOptions {
10400
10401
  variant: HasMetafieldsIdentifier[];
10401
10402
  product: HasMetafieldsIdentifier[];
10402
10403
  };
10404
+ /** Whether to update the cookie * 默认不更新cookie/ 仅在需要更新cookie时设置为true */
10405
+ updateCookie?: boolean;
10403
10406
  }
10404
10407
  /**
10405
10408
  * Create a new cart
@@ -10437,25 +10440,12 @@ declare function createCart(client: ShopifyClient, options?: CreateCartOptions):
10437
10440
  */
10438
10441
 
10439
10442
  interface AddCartLinesOptions {
10440
- /** Cart ID (optional, will create new cart if not provided) */
10441
- cartId?: string;
10443
+ /** Cart ID (required) */
10444
+ cartId: string;
10442
10445
  /** Lines to add */
10443
10446
  lines: CartLineInput[];
10444
10447
  /** Cookie adapter for managing cart ID */
10445
10448
  cookieAdapter?: CartCookieAdapter;
10446
- /** Current locale */
10447
- /** Buyer identity for cart creation */
10448
- buyerIdentity?: {
10449
- email?: string;
10450
- countryCode?: string;
10451
- };
10452
- /** Discount codes (only used when creating new cart) */
10453
- discountCodes?: string[];
10454
- /** Custom attributes (only used when creating new cart) */
10455
- customAttributes?: Array<{
10456
- key: string;
10457
- value: string;
10458
- }>;
10459
10449
  /** Metafield identifiers */
10460
10450
  metafieldIdentifiers?: {
10461
10451
  variant: HasMetafieldsIdentifier[];
@@ -10463,7 +10453,7 @@ interface AddCartLinesOptions {
10463
10453
  };
10464
10454
  }
10465
10455
  /**
10466
- * Add lines to cart (creates new cart if needed)
10456
+ * Add lines to an existing cart
10467
10457
  *
10468
10458
  * @param client - Shopify GraphQL client
10469
10459
  * @param options - Add cart lines options
@@ -10472,7 +10462,7 @@ interface AddCartLinesOptions {
10472
10462
  * @example
10473
10463
  * ```ts
10474
10464
  * const cart = await addCartLines(client, {
10475
- * locale: 'us',
10465
+ * cartId: 'gid://shopify/Cart/xxx',
10476
10466
  * lines: [{
10477
10467
  * merchandiseId: 'gid://shopify/ProductVariant/123',
10478
10468
  * quantity: 1
package/dist/index.d.ts CHANGED
@@ -10280,6 +10280,7 @@ interface NormalizedCart {
10280
10280
  code: string;
10281
10281
  }>;
10282
10282
  discountAllocations?: Array<{
10283
+ title: string;
10283
10284
  code: string;
10284
10285
  amount: number;
10285
10286
  }>;
@@ -10400,6 +10401,8 @@ interface CreateCartOptions {
10400
10401
  variant: HasMetafieldsIdentifier[];
10401
10402
  product: HasMetafieldsIdentifier[];
10402
10403
  };
10404
+ /** Whether to update the cookie * 默认不更新cookie/ 仅在需要更新cookie时设置为true */
10405
+ updateCookie?: boolean;
10403
10406
  }
10404
10407
  /**
10405
10408
  * Create a new cart
@@ -10437,25 +10440,12 @@ declare function createCart(client: ShopifyClient, options?: CreateCartOptions):
10437
10440
  */
10438
10441
 
10439
10442
  interface AddCartLinesOptions {
10440
- /** Cart ID (optional, will create new cart if not provided) */
10441
- cartId?: string;
10443
+ /** Cart ID (required) */
10444
+ cartId: string;
10442
10445
  /** Lines to add */
10443
10446
  lines: CartLineInput[];
10444
10447
  /** Cookie adapter for managing cart ID */
10445
10448
  cookieAdapter?: CartCookieAdapter;
10446
- /** Current locale */
10447
- /** Buyer identity for cart creation */
10448
- buyerIdentity?: {
10449
- email?: string;
10450
- countryCode?: string;
10451
- };
10452
- /** Discount codes (only used when creating new cart) */
10453
- discountCodes?: string[];
10454
- /** Custom attributes (only used when creating new cart) */
10455
- customAttributes?: Array<{
10456
- key: string;
10457
- value: string;
10458
- }>;
10459
10449
  /** Metafield identifiers */
10460
10450
  metafieldIdentifiers?: {
10461
10451
  variant: HasMetafieldsIdentifier[];
@@ -10463,7 +10453,7 @@ interface AddCartLinesOptions {
10463
10453
  };
10464
10454
  }
10465
10455
  /**
10466
- * Add lines to cart (creates new cart if needed)
10456
+ * Add lines to an existing cart
10467
10457
  *
10468
10458
  * @param client - Shopify GraphQL client
10469
10459
  * @param options - Add cart lines options
@@ -10472,7 +10462,7 @@ interface AddCartLinesOptions {
10472
10462
  * @example
10473
10463
  * ```ts
10474
10464
  * const cart = await addCartLines(client, {
10475
- * locale: 'us',
10465
+ * cartId: 'gid://shopify/Cart/xxx',
10476
10466
  * lines: [{
10477
10467
  * merchandiseId: 'gid://shopify/ProductVariant/123',
10478
10468
  * quantity: 1
package/dist/index.js CHANGED
@@ -1449,7 +1449,8 @@ function normalizeCart(cart) {
1449
1449
  orderDiscounts,
1450
1450
  discountCodes: cart.discountCodes || [],
1451
1451
  discountAllocations: cart?.discountAllocations?.map((item) => ({
1452
- code: item?.code || item?.title || "",
1452
+ title: item?.title || "",
1453
+ code: item?.code || "",
1453
1454
  amount: Number(item?.discountedAmount?.amount || 0)
1454
1455
  })) || [],
1455
1456
  // Map delivery amount from cart cost
@@ -1511,7 +1512,8 @@ async function createCart(client, options = {}) {
1511
1512
  buyerIdentity,
1512
1513
  discountCodes,
1513
1514
  customAttributes,
1514
- metafieldIdentifiers
1515
+ metafieldIdentifiers,
1516
+ updateCookie = false
1515
1517
  } = options;
1516
1518
  const locale = client.getLocale();
1517
1519
  try {
@@ -1533,7 +1535,7 @@ async function createCart(client, options = {}) {
1533
1535
  return void 0;
1534
1536
  }
1535
1537
  const normalizedCart = normalizeCart(cart);
1536
- if (cookieAdapter && normalizedCart.id) {
1538
+ if (cookieAdapter && normalizedCart.id && updateCookie) {
1537
1539
  cookieAdapter.setCartId(locale, normalizedCart.id);
1538
1540
  }
1539
1541
  return normalizedCart;
@@ -1545,46 +1547,22 @@ async function createCart(client, options = {}) {
1545
1547
 
1546
1548
  // src/api/cart/add-cart-lines.ts
1547
1549
  async function addCartLines(client, options) {
1548
- const {
1549
- cartId: providedCartId,
1550
- lines,
1551
- cookieAdapter,
1552
- buyerIdentity,
1553
- discountCodes,
1554
- customAttributes,
1555
- metafieldIdentifiers
1556
- } = options;
1550
+ const { cartId, lines, cookieAdapter, metafieldIdentifiers } = options;
1557
1551
  const locale = client.getLocale();
1558
- const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1559
1552
  const normalizedMetafieldIdentifiers = constructMetafieldIdentifiersQueryParams(
1560
1553
  metafieldIdentifiers,
1561
1554
  client.getConfig().getMetafieldNamespacePrefix()
1562
1555
  );
1563
1556
  try {
1564
- let cart;
1565
- if (cartId) {
1566
- const data = await client.query(addCartItemsMutation, {
1567
- cartId,
1568
- lines,
1569
- ...normalizedMetafieldIdentifiers
1570
- });
1571
- if (data?.cartLinesAdd?.userErrors?.length) {
1572
- console.error("[addCartLines] User errors:", data.cartLinesAdd.userErrors);
1573
- }
1574
- cart = data?.cartLinesAdd?.cart;
1575
- } else {
1576
- const data = await client.query(createCartMutation, {
1577
- lines,
1578
- buyerIdentity,
1579
- discountCodes,
1580
- attributes: customAttributes,
1581
- ...normalizedMetafieldIdentifiers
1582
- });
1583
- if (data?.cartCreate?.userErrors?.length) {
1584
- console.error("[addCartLines] User errors:", data.cartCreate.userErrors);
1585
- }
1586
- cart = data?.cartCreate?.cart;
1557
+ const data = await client.query(addCartItemsMutation, {
1558
+ cartId,
1559
+ lines,
1560
+ ...normalizedMetafieldIdentifiers
1561
+ });
1562
+ if (data?.cartLinesAdd?.userErrors?.length) {
1563
+ console.error("[addCartLines] User errors:", data.cartLinesAdd.userErrors);
1587
1564
  }
1565
+ const cart = data?.cartLinesAdd?.cart;
1588
1566
  if (!cart) {
1589
1567
  return void 0;
1590
1568
  }