@pintahub/shopify-api 1.6.9 → 1.7.0

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.
@@ -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;
@@ -3,14 +3,17 @@ 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";
6
7
  export interface CartAPIInterface {
7
8
  create(args: CreateCartInput): Promise<CreateCartOutput>;
8
9
  get(args: GetCartInput): Promise<GetCartOutput>;
9
10
  updateBuyer(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
11
+ addItem(args: AddToCartInput): Promise<AddToCartOutput>;
10
12
  }
11
13
  export declare class CartAPI extends APIBase<StorefrontApiClient> implements CartAPIInterface {
12
14
  private _runAction;
13
15
  updateBuyer(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
14
16
  get(args: GetCartInput): Promise<GetCartOutput>;
15
17
  create(args: CreateCartInput): Promise<CreateCartOutput>;
18
+ addItem(args: AddToCartInput): Promise<AddToCartOutput>;
16
19
  }
@@ -14,6 +14,7 @@ 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");
17
18
  class CartAPI extends APIBase_1.APIBase {
18
19
  _runAction(Action, args) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
@@ -36,5 +37,10 @@ class CartAPI extends APIBase_1.APIBase {
36
37
  return this._runAction(CreateCart_1.CreateCart, args);
37
38
  });
38
39
  }
40
+ addItem(args) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ return this._runAction(AddToCart_1.AddToCart, args);
43
+ });
44
+ }
39
45
  }
40
46
  exports.CartAPI = CartAPI;
@@ -0,0 +1,2 @@
1
+ export interface CartObject extends Record<string, any> {
2
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "1.6.9",
3
+ "version": "1.7.0",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",