@pintahub/shopify-api 1.7.1 → 1.7.2
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/classes/storefront/cart/GetCart.d.ts +2 -1
- package/dist/classes/storefront/cart/GetCart.js +3 -2
- package/dist/classes/storefront/cart/UpdateItemCart.d.ts +12 -0
- package/dist/classes/storefront/cart/UpdateItemCart.js +39 -0
- package/dist/classes/storefront/cart/index.d.ts +3 -0
- package/dist/classes/storefront/cart/index.js +6 -0
- package/dist/utils/handleErrors.js +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ActionBuilder } from "../../ActionBuilder";
|
|
2
2
|
import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
|
|
3
3
|
export interface GetCartInput extends Record<string, any> {
|
|
4
|
-
|
|
4
|
+
cartId: string;
|
|
5
|
+
id?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface GetCartOutput extends Record<string, any> {
|
|
7
8
|
}
|
|
@@ -17,8 +17,9 @@ const handleErrors_1 = require("../../../utils/handleErrors");
|
|
|
17
17
|
class GetCart extends ActionBuilder_1.ActionBuilder {
|
|
18
18
|
run(args) {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const { id } = Object.assign({}, args);
|
|
21
|
-
const
|
|
20
|
+
const { id, cartId } = Object.assign({}, args);
|
|
21
|
+
const vId = cartId || id || '';
|
|
22
|
+
const globalId = (0, getGlobalID_1.getGlobalID)(vId, 'Cart');
|
|
22
23
|
const query = `
|
|
23
24
|
{
|
|
24
25
|
cart(id: "${globalId}") {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ActionBuilder } from "../../ActionBuilder";
|
|
2
|
+
import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
|
|
3
|
+
import { CartObject } from "../../../interfaces/Cart";
|
|
4
|
+
export interface UpdateItemCartInput extends Record<string, any> {
|
|
5
|
+
cartId: string;
|
|
6
|
+
lines: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface UpdateItemCartOutput extends CartObject {
|
|
9
|
+
}
|
|
10
|
+
export declare class UpdateItemCart extends ActionBuilder<StorefrontApiClient, UpdateItemCartInput, UpdateItemCartOutput> {
|
|
11
|
+
run(args: UpdateItemCartInput): Promise<UpdateItemCartOutput>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UpdateItemCart = void 0;
|
|
13
|
+
const ActionBuilder_1 = require("../../ActionBuilder");
|
|
14
|
+
const cart_1 = require("../../../fragments/cart");
|
|
15
|
+
const handleErrors_1 = require("../../../utils/handleErrors");
|
|
16
|
+
class UpdateItemCart extends ActionBuilder_1.ActionBuilder {
|
|
17
|
+
run(args) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const query = `
|
|
20
|
+
mutation cartLinesUpdate($lines: [CartLineUpdateInput!]!, $cartId: ID!) {
|
|
21
|
+
cartLinesUpdate(lines: $lines, cartId: $cartId) {
|
|
22
|
+
cart {
|
|
23
|
+
...cart
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
${cart_1.cartFragment}
|
|
28
|
+
`;
|
|
29
|
+
const { data, errors } = yield this.client.request(query, {
|
|
30
|
+
variables: args
|
|
31
|
+
});
|
|
32
|
+
yield (0, handleErrors_1.handleErrors)(errors);
|
|
33
|
+
const { cartLinesUpdate } = Object.assign({}, data);
|
|
34
|
+
const { cart } = Object.assign({}, cartLinesUpdate);
|
|
35
|
+
return Object.assign({}, cart);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.UpdateItemCart = UpdateItemCart;
|
|
@@ -5,12 +5,14 @@ import { GetCartInput, GetCartOutput } from "./GetCart";
|
|
|
5
5
|
import { CreateCartInput, CreateCartOutput } from "./CreateCart";
|
|
6
6
|
import { AddToCartInput, AddToCartOutput } from "./AddToCart";
|
|
7
7
|
import { RemoveItemCartInput, RemoveItemCartOutput } from "./RemoveItem";
|
|
8
|
+
import { UpdateItemCartInput, UpdateItemCartOutput } from "./UpdateItemCart";
|
|
8
9
|
export interface CartAPIInterface {
|
|
9
10
|
create(args: CreateCartInput): Promise<CreateCartOutput>;
|
|
10
11
|
get(args: GetCartInput): Promise<GetCartOutput>;
|
|
11
12
|
updateBuyer(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
|
|
12
13
|
addItem(args: AddToCartInput): Promise<AddToCartOutput>;
|
|
13
14
|
removeItem(args: RemoveItemCartInput): Promise<RemoveItemCartOutput>;
|
|
15
|
+
updateItem(args: UpdateItemCartInput): Promise<UpdateItemCartOutput>;
|
|
14
16
|
}
|
|
15
17
|
export declare class CartAPI extends APIBase<StorefrontApiClient> implements CartAPIInterface {
|
|
16
18
|
private _runAction;
|
|
@@ -19,4 +21,5 @@ export declare class CartAPI extends APIBase<StorefrontApiClient> implements Car
|
|
|
19
21
|
create(args: CreateCartInput): Promise<CreateCartOutput>;
|
|
20
22
|
addItem(args: AddToCartInput): Promise<AddToCartOutput>;
|
|
21
23
|
removeItem(args: RemoveItemCartInput): Promise<RemoveItemCartOutput>;
|
|
24
|
+
updateItem(args: UpdateItemCartInput): Promise<UpdateItemCartOutput>;
|
|
22
25
|
}
|
|
@@ -16,6 +16,7 @@ const GetCart_1 = require("./GetCart");
|
|
|
16
16
|
const CreateCart_1 = require("./CreateCart");
|
|
17
17
|
const AddToCart_1 = require("./AddToCart");
|
|
18
18
|
const RemoveItem_1 = require("./RemoveItem");
|
|
19
|
+
const UpdateItemCart_1 = require("./UpdateItemCart");
|
|
19
20
|
class CartAPI extends APIBase_1.APIBase {
|
|
20
21
|
_runAction(Action, args) {
|
|
21
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -48,5 +49,10 @@ class CartAPI extends APIBase_1.APIBase {
|
|
|
48
49
|
return this._runAction(RemoveItem_1.RemoveItemCart, args);
|
|
49
50
|
});
|
|
50
51
|
}
|
|
52
|
+
updateItem(args) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
return this._runAction(UpdateItemCart_1.UpdateItemCart, args);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
51
57
|
}
|
|
52
58
|
exports.CartAPI = CartAPI;
|