@pintahub/shopify-api 1.4.0 → 1.4.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/StorefrontAPI.d.ts +2 -0
- package/dist/classes/StorefrontAPI.js +2 -0
- package/dist/classes/storefront/cart/GetPage.d.ts +10 -0
- package/dist/classes/storefront/cart/GetPage.js +43 -0
- package/dist/classes/storefront/cart/UpdateBuyerIdentity.d.ts +15 -0
- package/dist/classes/storefront/cart/UpdateBuyerIdentity.js +48 -0
- package/dist/classes/storefront/cart/index.d.ts +10 -0
- package/dist/classes/storefront/cart/index.js +28 -0
- package/dist/classes/storefront/products/GetProduct.js +3 -1
- package/package.json +1 -1
|
@@ -2,12 +2,14 @@ import { StorefrontAPIOptions } from "../interfaces/StorefrontAPI";
|
|
|
2
2
|
import { PageAPIInterface } from "./storefront/pages";
|
|
3
3
|
import { ShopAPIInterface } from "./storefront/shop";
|
|
4
4
|
import { ProductAPIInterface } from "./storefront/products";
|
|
5
|
+
import { CartAPIInterface } from "./storefront/cart";
|
|
5
6
|
export declare class StorefrontAPI {
|
|
6
7
|
private readonly options;
|
|
7
8
|
private readonly client;
|
|
8
9
|
readonly page: PageAPIInterface;
|
|
9
10
|
readonly shop: ShopAPIInterface;
|
|
10
11
|
readonly product: ProductAPIInterface;
|
|
12
|
+
readonly cart: CartAPIInterface;
|
|
11
13
|
constructor(options: StorefrontAPIOptions);
|
|
12
14
|
private _createClient;
|
|
13
15
|
}
|
|
@@ -5,6 +5,7 @@ const storefront_api_client_1 = require("@shopify/storefront-api-client");
|
|
|
5
5
|
const pages_1 = require("./storefront/pages");
|
|
6
6
|
const shop_1 = require("./storefront/shop");
|
|
7
7
|
const products_1 = require("./storefront/products");
|
|
8
|
+
const cart_1 = require("./storefront/cart");
|
|
8
9
|
class StorefrontAPI {
|
|
9
10
|
constructor(options) {
|
|
10
11
|
this.options = options;
|
|
@@ -12,6 +13,7 @@ class StorefrontAPI {
|
|
|
12
13
|
this.page = new pages_1.PageAPI(this.client);
|
|
13
14
|
this.shop = new shop_1.ShopAPI(this.client);
|
|
14
15
|
this.product = new products_1.ProductAPI(this.client);
|
|
16
|
+
this.cart = new cart_1.CartAPI(this.client);
|
|
15
17
|
}
|
|
16
18
|
_createClient() {
|
|
17
19
|
const { shop, accessToken } = this.options;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionBuilder } from "../../ActionBuilder";
|
|
2
|
+
import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
|
|
3
|
+
export interface GetPageInput extends Record<string, any> {
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
export interface GetPageOutput extends Record<string, any> {
|
|
7
|
+
}
|
|
8
|
+
export declare class GetPage extends ActionBuilder<StorefrontApiClient, GetPageInput, GetPageOutput> {
|
|
9
|
+
run(args: GetPageInput): Promise<GetPageOutput>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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.GetPage = void 0;
|
|
13
|
+
const ActionBuilder_1 = require("../../ActionBuilder");
|
|
14
|
+
const getGlobalID_1 = require("../../../utils/getGlobalID");
|
|
15
|
+
class GetPage extends ActionBuilder_1.ActionBuilder {
|
|
16
|
+
run(args) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const query = `
|
|
19
|
+
query ($id: ID){
|
|
20
|
+
page(id: $id) {
|
|
21
|
+
body
|
|
22
|
+
handle
|
|
23
|
+
id
|
|
24
|
+
title
|
|
25
|
+
onlineStoreUrl
|
|
26
|
+
bodySummary
|
|
27
|
+
updatedAt
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
const { id } = args;
|
|
32
|
+
const globalId = (0, getGlobalID_1.getGlobalID)(id);
|
|
33
|
+
const { data } = yield this.client.request(query, {
|
|
34
|
+
variables: {
|
|
35
|
+
id: globalId
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const { page } = Object.assign({}, data);
|
|
39
|
+
return Object.assign({}, page);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.GetPage = GetPage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ActionBuilder } from "../../ActionBuilder";
|
|
2
|
+
import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
|
|
3
|
+
interface BuyerIdentity extends Record<string, any> {
|
|
4
|
+
countryCode?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UpdateBuyerIdentityInput extends Record<string, any> {
|
|
7
|
+
id: string;
|
|
8
|
+
buyerIdentity: BuyerIdentity;
|
|
9
|
+
}
|
|
10
|
+
export interface UpdateBuyerIdentityOutput extends Record<string, any> {
|
|
11
|
+
}
|
|
12
|
+
export declare class UpdateBuyerIdentity extends ActionBuilder<StorefrontApiClient, UpdateBuyerIdentityInput, UpdateBuyerIdentityOutput> {
|
|
13
|
+
run(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
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.UpdateBuyerIdentity = void 0;
|
|
13
|
+
const ActionBuilder_1 = require("../../ActionBuilder");
|
|
14
|
+
const getGlobalID_1 = require("../../../utils/getGlobalID");
|
|
15
|
+
class UpdateBuyerIdentity extends ActionBuilder_1.ActionBuilder {
|
|
16
|
+
run(args) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const query = `
|
|
19
|
+
mutation cartBuyerIdentityUpdate($buyerIdentity: CartBuyerIdentityInput!, $cartId: ID!) {
|
|
20
|
+
cartBuyerIdentityUpdate(buyerIdentity: $buyerIdentity, cartId: $cartId) {
|
|
21
|
+
cart {
|
|
22
|
+
id
|
|
23
|
+
buyerIdentity {
|
|
24
|
+
countryCode
|
|
25
|
+
email
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
userErrors {
|
|
29
|
+
field
|
|
30
|
+
message
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
const { id, buyerIdentity } = args;
|
|
36
|
+
const globalId = (0, getGlobalID_1.getGlobalID)(id, 'Cart');
|
|
37
|
+
const { data } = yield this.client.request(query, {
|
|
38
|
+
variables: {
|
|
39
|
+
cartId: globalId,
|
|
40
|
+
buyerIdentity
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const { cartBuyerIdentityUpdate } = Object.assign({}, data);
|
|
44
|
+
return Object.assign({}, cartBuyerIdentityUpdate);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.UpdateBuyerIdentity = UpdateBuyerIdentity;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { APIBase } from "../../APIBase";
|
|
2
|
+
import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
|
|
3
|
+
import { UpdateBuyerIdentityInput, UpdateBuyerIdentityOutput } from "./UpdateBuyerIdentity";
|
|
4
|
+
export interface CartAPIInterface {
|
|
5
|
+
updateBuyer(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
|
|
6
|
+
}
|
|
7
|
+
export declare class CartAPI extends APIBase<StorefrontApiClient> implements CartAPIInterface {
|
|
8
|
+
private _runAction;
|
|
9
|
+
updateBuyer(args: UpdateBuyerIdentityInput): Promise<UpdateBuyerIdentityOutput>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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.CartAPI = void 0;
|
|
13
|
+
const APIBase_1 = require("../../APIBase");
|
|
14
|
+
const UpdateBuyerIdentity_1 = require("./UpdateBuyerIdentity");
|
|
15
|
+
class CartAPI extends APIBase_1.APIBase {
|
|
16
|
+
_runAction(Action, args) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const action = new Action(this.client);
|
|
19
|
+
return action.run(args);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
updateBuyer(args) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return this._runAction(UpdateBuyerIdentity_1.UpdateBuyerIdentity, args);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CartAPI = CartAPI;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.GetProduct = void 0;
|
|
13
13
|
const ActionBuilder_1 = require("../../ActionBuilder");
|
|
14
14
|
const getGlobalID_1 = require("../../../utils/getGlobalID");
|
|
15
|
+
const handleErrors_1 = require("../../../utils/handleErrors");
|
|
15
16
|
class GetProduct extends ActionBuilder_1.ActionBuilder {
|
|
16
17
|
run(args) {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -83,7 +84,8 @@ class GetProduct extends ActionBuilder_1.ActionBuilder {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
`;
|
|
86
|
-
const { data } = yield this.client.request(query);
|
|
87
|
+
const { data, errors } = yield this.client.request(query);
|
|
88
|
+
yield (0, handleErrors_1.handleErrors)(errors);
|
|
87
89
|
const { product } = Object.assign({}, data);
|
|
88
90
|
return Object.assign({}, product);
|
|
89
91
|
});
|