@pintahub/shopify-api 1.6.9 → 1.7.1
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/AddToCart.d.ts +18 -0
- package/dist/classes/storefront/cart/AddToCart.js +39 -0
- package/dist/classes/storefront/cart/RemoveItem.d.ts +12 -0
- package/dist/classes/storefront/cart/RemoveItem.js +39 -0
- package/dist/classes/storefront/cart/index.d.ts +6 -0
- package/dist/classes/storefront/cart/index.js +12 -0
- package/dist/interfaces/Cart.d.ts +2 -0
- package/dist/interfaces/Cart.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ActionBuilder } from "../../ActionBuilder";
|
|
2
|
+
import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
|
|
3
|
+
import { CartObject } from "../../../interfaces/Cart";
|
|
4
|
+
interface LineInput extends Record<string, any> {
|
|
5
|
+
merchandiseId: string;
|
|
6
|
+
quantity: number;
|
|
7
|
+
attributes: Record<string, any>[];
|
|
8
|
+
}
|
|
9
|
+
export interface AddToCartInput extends Record<string, any> {
|
|
10
|
+
cartId: string;
|
|
11
|
+
lines: LineInput[];
|
|
12
|
+
}
|
|
13
|
+
export interface AddToCartOutput extends CartObject {
|
|
14
|
+
}
|
|
15
|
+
export declare class AddToCart extends ActionBuilder<StorefrontApiClient, AddToCartInput, AddToCartOutput> {
|
|
16
|
+
run(args: AddToCartInput): Promise<AddToCartOutput>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -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.AddToCart = void 0;
|
|
13
|
+
const ActionBuilder_1 = require("../../ActionBuilder");
|
|
14
|
+
const cart_1 = require("../../../fragments/cart");
|
|
15
|
+
const handleErrors_1 = require("../../../utils/handleErrors");
|
|
16
|
+
class AddToCart extends ActionBuilder_1.ActionBuilder {
|
|
17
|
+
run(args) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const query = `
|
|
20
|
+
mutation cartLinesAdd($lines: [CartLineInput!]!, $cartId: ID!) {
|
|
21
|
+
cartLinesAdd(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 { cartLinesAdd } = Object.assign({}, data);
|
|
34
|
+
const { cart } = Object.assign({}, cartLinesAdd);
|
|
35
|
+
return Object.assign({}, cart);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.AddToCart = AddToCart;
|
|
@@ -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 RemoveItemCartInput extends Record<string, any> {
|
|
5
|
+
cartId: string;
|
|
6
|
+
lineIds: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface RemoveItemCartOutput extends CartObject {
|
|
9
|
+
}
|
|
10
|
+
export declare class RemoveItemCart extends ActionBuilder<StorefrontApiClient, RemoveItemCartInput, RemoveItemCartOutput> {
|
|
11
|
+
run(args: RemoveItemCartInput): Promise<RemoveItemCartOutput>;
|
|
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.RemoveItemCart = void 0;
|
|
13
|
+
const ActionBuilder_1 = require("../../ActionBuilder");
|
|
14
|
+
const cart_1 = require("../../../fragments/cart");
|
|
15
|
+
const handleErrors_1 = require("../../../utils/handleErrors");
|
|
16
|
+
class RemoveItemCart extends ActionBuilder_1.ActionBuilder {
|
|
17
|
+
run(args) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const query = `
|
|
20
|
+
mutation cartLinesRemove($lineIds: [ID!]!, $cartId: ID!) {
|
|
21
|
+
cartLinesRemove(lineIds: $lineIds, 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 { cartLinesRemove } = Object.assign({}, data);
|
|
34
|
+
const { cart } = Object.assign({}, cartLinesRemove);
|
|
35
|
+
return Object.assign({}, cart);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.RemoveItemCart = RemoveItemCart;
|
|
@@ -3,14 +3,20 @@ import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/type
|
|
|
3
3
|
import { UpdateBuyerIdentityInput, UpdateBuyerIdentityOutput } from "./UpdateBuyerIdentity";
|
|
4
4
|
import { GetCartInput, GetCartOutput } from "./GetCart";
|
|
5
5
|
import { CreateCartInput, CreateCartOutput } from "./CreateCart";
|
|
6
|
+
import { AddToCartInput, AddToCartOutput } from "./AddToCart";
|
|
7
|
+
import { RemoveItemCartInput, RemoveItemCartOutput } from "./RemoveItem";
|
|
6
8
|
export interface CartAPIInterface {
|
|
7
9
|
create(args: CreateCartInput): Promise<CreateCartOutput>;
|
|
8
10
|
get(args: GetCartInput): Promise<GetCartOutput>;
|
|
9
11
|
updateBuyer(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
|
|
12
|
+
addItem(args: AddToCartInput): Promise<AddToCartOutput>;
|
|
13
|
+
removeItem(args: RemoveItemCartInput): Promise<RemoveItemCartOutput>;
|
|
10
14
|
}
|
|
11
15
|
export declare class CartAPI extends APIBase<StorefrontApiClient> implements CartAPIInterface {
|
|
12
16
|
private _runAction;
|
|
13
17
|
updateBuyer(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
|
|
14
18
|
get(args: GetCartInput): Promise<GetCartOutput>;
|
|
15
19
|
create(args: CreateCartInput): Promise<CreateCartOutput>;
|
|
20
|
+
addItem(args: AddToCartInput): Promise<AddToCartOutput>;
|
|
21
|
+
removeItem(args: RemoveItemCartInput): Promise<RemoveItemCartOutput>;
|
|
16
22
|
}
|
|
@@ -14,6 +14,8 @@ const APIBase_1 = require("../../APIBase");
|
|
|
14
14
|
const UpdateBuyerIdentity_1 = require("./UpdateBuyerIdentity");
|
|
15
15
|
const GetCart_1 = require("./GetCart");
|
|
16
16
|
const CreateCart_1 = require("./CreateCart");
|
|
17
|
+
const AddToCart_1 = require("./AddToCart");
|
|
18
|
+
const RemoveItem_1 = require("./RemoveItem");
|
|
17
19
|
class CartAPI extends APIBase_1.APIBase {
|
|
18
20
|
_runAction(Action, args) {
|
|
19
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -36,5 +38,15 @@ class CartAPI extends APIBase_1.APIBase {
|
|
|
36
38
|
return this._runAction(CreateCart_1.CreateCart, args);
|
|
37
39
|
});
|
|
38
40
|
}
|
|
41
|
+
addItem(args) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return this._runAction(AddToCart_1.AddToCart, args);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
removeItem(args) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return this._runAction(RemoveItem_1.RemoveItemCart, args);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
39
51
|
}
|
|
40
52
|
exports.CartAPI = CartAPI;
|