@pintahub/shopify-api 1.7.0 → 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.
@@ -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
- id: string;
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 globalId = (0, getGlobalID_1.getGlobalID)(id, 'Cart');
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 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;
@@ -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;
@@ -4,11 +4,15 @@ import { UpdateBuyerIdentityInput, UpdateBuyerIdentityOutput } from "./UpdateBuy
4
4
  import { GetCartInput, GetCartOutput } from "./GetCart";
5
5
  import { CreateCartInput, CreateCartOutput } from "./CreateCart";
6
6
  import { AddToCartInput, AddToCartOutput } from "./AddToCart";
7
+ import { RemoveItemCartInput, RemoveItemCartOutput } from "./RemoveItem";
8
+ import { UpdateItemCartInput, UpdateItemCartOutput } from "./UpdateItemCart";
7
9
  export interface CartAPIInterface {
8
10
  create(args: CreateCartInput): Promise<CreateCartOutput>;
9
11
  get(args: GetCartInput): Promise<GetCartOutput>;
10
12
  updateBuyer(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
11
13
  addItem(args: AddToCartInput): Promise<AddToCartOutput>;
14
+ removeItem(args: RemoveItemCartInput): Promise<RemoveItemCartOutput>;
15
+ updateItem(args: UpdateItemCartInput): Promise<UpdateItemCartOutput>;
12
16
  }
13
17
  export declare class CartAPI extends APIBase<StorefrontApiClient> implements CartAPIInterface {
14
18
  private _runAction;
@@ -16,4 +20,6 @@ export declare class CartAPI extends APIBase<StorefrontApiClient> implements Car
16
20
  get(args: GetCartInput): Promise<GetCartOutput>;
17
21
  create(args: CreateCartInput): Promise<CreateCartOutput>;
18
22
  addItem(args: AddToCartInput): Promise<AddToCartOutput>;
23
+ removeItem(args: RemoveItemCartInput): Promise<RemoveItemCartOutput>;
24
+ updateItem(args: UpdateItemCartInput): Promise<UpdateItemCartOutput>;
19
25
  }
@@ -15,6 +15,8 @@ const UpdateBuyerIdentity_1 = require("./UpdateBuyerIdentity");
15
15
  const GetCart_1 = require("./GetCart");
16
16
  const CreateCart_1 = require("./CreateCart");
17
17
  const AddToCart_1 = require("./AddToCart");
18
+ const RemoveItem_1 = require("./RemoveItem");
19
+ const UpdateItemCart_1 = require("./UpdateItemCart");
18
20
  class CartAPI extends APIBase_1.APIBase {
19
21
  _runAction(Action, args) {
20
22
  return __awaiter(this, void 0, void 0, function* () {
@@ -42,5 +44,15 @@ class CartAPI extends APIBase_1.APIBase {
42
44
  return this._runAction(AddToCart_1.AddToCart, args);
43
45
  });
44
46
  }
47
+ removeItem(args) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return this._runAction(RemoveItem_1.RemoveItemCart, args);
50
+ });
51
+ }
52
+ updateItem(args) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ return this._runAction(UpdateItemCart_1.UpdateItemCart, args);
55
+ });
56
+ }
45
57
  }
46
58
  exports.CartAPI = CartAPI;
@@ -24,6 +24,7 @@ const handleErrors = (errors) => __awaiter(void 0, void 0, void 0, function* ()
24
24
  }
25
25
  }
26
26
  }
27
+ console.log('errors', errors);
27
28
  if (message) {
28
29
  throw new Error(message);
29
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",