@anker-in/shopify-sdk 0.1.1-beta.16 → 0.1.1-beta.17
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 +6 -17
- package/dist/index.d.ts +6 -17
- package/dist/index.js +12 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -10400,6 +10400,8 @@ interface CreateCartOptions {
|
|
|
10400
10400
|
variant: HasMetafieldsIdentifier[];
|
|
10401
10401
|
product: HasMetafieldsIdentifier[];
|
|
10402
10402
|
};
|
|
10403
|
+
/** Whether to update the cookie * 默认不更新cookie/ 仅在需要更新cookie时设置为true */
|
|
10404
|
+
updateCookie?: boolean;
|
|
10403
10405
|
}
|
|
10404
10406
|
/**
|
|
10405
10407
|
* Create a new cart
|
|
@@ -10437,25 +10439,12 @@ declare function createCart(client: ShopifyClient, options?: CreateCartOptions):
|
|
|
10437
10439
|
*/
|
|
10438
10440
|
|
|
10439
10441
|
interface AddCartLinesOptions {
|
|
10440
|
-
/** Cart ID (
|
|
10441
|
-
cartId
|
|
10442
|
+
/** Cart ID (required) */
|
|
10443
|
+
cartId: string;
|
|
10442
10444
|
/** Lines to add */
|
|
10443
10445
|
lines: CartLineInput[];
|
|
10444
10446
|
/** Cookie adapter for managing cart ID */
|
|
10445
10447
|
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
10448
|
/** Metafield identifiers */
|
|
10460
10449
|
metafieldIdentifiers?: {
|
|
10461
10450
|
variant: HasMetafieldsIdentifier[];
|
|
@@ -10463,7 +10452,7 @@ interface AddCartLinesOptions {
|
|
|
10463
10452
|
};
|
|
10464
10453
|
}
|
|
10465
10454
|
/**
|
|
10466
|
-
* Add lines to
|
|
10455
|
+
* Add lines to an existing cart
|
|
10467
10456
|
*
|
|
10468
10457
|
* @param client - Shopify GraphQL client
|
|
10469
10458
|
* @param options - Add cart lines options
|
|
@@ -10472,7 +10461,7 @@ interface AddCartLinesOptions {
|
|
|
10472
10461
|
* @example
|
|
10473
10462
|
* ```ts
|
|
10474
10463
|
* const cart = await addCartLines(client, {
|
|
10475
|
-
*
|
|
10464
|
+
* cartId: 'gid://shopify/Cart/xxx',
|
|
10476
10465
|
* lines: [{
|
|
10477
10466
|
* merchandiseId: 'gid://shopify/ProductVariant/123',
|
|
10478
10467
|
* quantity: 1
|
package/dist/index.d.ts
CHANGED
|
@@ -10400,6 +10400,8 @@ interface CreateCartOptions {
|
|
|
10400
10400
|
variant: HasMetafieldsIdentifier[];
|
|
10401
10401
|
product: HasMetafieldsIdentifier[];
|
|
10402
10402
|
};
|
|
10403
|
+
/** Whether to update the cookie * 默认不更新cookie/ 仅在需要更新cookie时设置为true */
|
|
10404
|
+
updateCookie?: boolean;
|
|
10403
10405
|
}
|
|
10404
10406
|
/**
|
|
10405
10407
|
* Create a new cart
|
|
@@ -10437,25 +10439,12 @@ declare function createCart(client: ShopifyClient, options?: CreateCartOptions):
|
|
|
10437
10439
|
*/
|
|
10438
10440
|
|
|
10439
10441
|
interface AddCartLinesOptions {
|
|
10440
|
-
/** Cart ID (
|
|
10441
|
-
cartId
|
|
10442
|
+
/** Cart ID (required) */
|
|
10443
|
+
cartId: string;
|
|
10442
10444
|
/** Lines to add */
|
|
10443
10445
|
lines: CartLineInput[];
|
|
10444
10446
|
/** Cookie adapter for managing cart ID */
|
|
10445
10447
|
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
10448
|
/** Metafield identifiers */
|
|
10460
10449
|
metafieldIdentifiers?: {
|
|
10461
10450
|
variant: HasMetafieldsIdentifier[];
|
|
@@ -10463,7 +10452,7 @@ interface AddCartLinesOptions {
|
|
|
10463
10452
|
};
|
|
10464
10453
|
}
|
|
10465
10454
|
/**
|
|
10466
|
-
* Add lines to
|
|
10455
|
+
* Add lines to an existing cart
|
|
10467
10456
|
*
|
|
10468
10457
|
* @param client - Shopify GraphQL client
|
|
10469
10458
|
* @param options - Add cart lines options
|
|
@@ -10472,7 +10461,7 @@ interface AddCartLinesOptions {
|
|
|
10472
10461
|
* @example
|
|
10473
10462
|
* ```ts
|
|
10474
10463
|
* const cart = await addCartLines(client, {
|
|
10475
|
-
*
|
|
10464
|
+
* cartId: 'gid://shopify/Cart/xxx',
|
|
10476
10465
|
* lines: [{
|
|
10477
10466
|
* merchandiseId: 'gid://shopify/ProductVariant/123',
|
|
10478
10467
|
* quantity: 1
|
package/dist/index.js
CHANGED
|
@@ -1511,7 +1511,8 @@ async function createCart(client, options = {}) {
|
|
|
1511
1511
|
buyerIdentity,
|
|
1512
1512
|
discountCodes,
|
|
1513
1513
|
customAttributes,
|
|
1514
|
-
metafieldIdentifiers
|
|
1514
|
+
metafieldIdentifiers,
|
|
1515
|
+
updateCookie = false
|
|
1515
1516
|
} = options;
|
|
1516
1517
|
const locale = client.getLocale();
|
|
1517
1518
|
try {
|
|
@@ -1533,7 +1534,7 @@ async function createCart(client, options = {}) {
|
|
|
1533
1534
|
return void 0;
|
|
1534
1535
|
}
|
|
1535
1536
|
const normalizedCart = normalizeCart(cart);
|
|
1536
|
-
if (cookieAdapter && normalizedCart.id) {
|
|
1537
|
+
if (cookieAdapter && normalizedCart.id && updateCookie) {
|
|
1537
1538
|
cookieAdapter.setCartId(locale, normalizedCart.id);
|
|
1538
1539
|
}
|
|
1539
1540
|
return normalizedCart;
|
|
@@ -1545,46 +1546,22 @@ async function createCart(client, options = {}) {
|
|
|
1545
1546
|
|
|
1546
1547
|
// src/api/cart/add-cart-lines.ts
|
|
1547
1548
|
async function addCartLines(client, options) {
|
|
1548
|
-
const {
|
|
1549
|
-
cartId: providedCartId,
|
|
1550
|
-
lines,
|
|
1551
|
-
cookieAdapter,
|
|
1552
|
-
buyerIdentity,
|
|
1553
|
-
discountCodes,
|
|
1554
|
-
customAttributes,
|
|
1555
|
-
metafieldIdentifiers
|
|
1556
|
-
} = options;
|
|
1549
|
+
const { cartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1557
1550
|
const locale = client.getLocale();
|
|
1558
|
-
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1559
1551
|
const normalizedMetafieldIdentifiers = constructMetafieldIdentifiersQueryParams(
|
|
1560
1552
|
metafieldIdentifiers,
|
|
1561
1553
|
client.getConfig().getMetafieldNamespacePrefix()
|
|
1562
1554
|
);
|
|
1563
1555
|
try {
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
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;
|
|
1556
|
+
const data = await client.query(addCartItemsMutation, {
|
|
1557
|
+
cartId,
|
|
1558
|
+
lines,
|
|
1559
|
+
...normalizedMetafieldIdentifiers
|
|
1560
|
+
});
|
|
1561
|
+
if (data?.cartLinesAdd?.userErrors?.length) {
|
|
1562
|
+
console.error("[addCartLines] User errors:", data.cartLinesAdd.userErrors);
|
|
1587
1563
|
}
|
|
1564
|
+
const cart = data?.cartLinesAdd?.cart;
|
|
1588
1565
|
if (!cart) {
|
|
1589
1566
|
return void 0;
|
|
1590
1567
|
}
|