@pintahub/shopify-api 1.1.4 → 1.1.5

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,11 +1,13 @@
1
1
  import { StorefrontAPIOptions } from "../interfaces/StorefrontAPI";
2
2
  import { PageAPIInterface } from "./storefront/pages";
3
3
  import { ShopAPIInterface } from "./storefront/shop";
4
+ import { ProductAPIInterface } from "./storefront/products";
4
5
  export declare class StorefrontAPI {
5
6
  private readonly options;
6
7
  private readonly client;
7
8
  readonly page: PageAPIInterface;
8
9
  readonly shop: ShopAPIInterface;
10
+ readonly product: ProductAPIInterface;
9
11
  constructor(options: StorefrontAPIOptions);
10
12
  private _createClient;
11
13
  }
@@ -4,12 +4,14 @@ exports.StorefrontAPI = void 0;
4
4
  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
+ const products_1 = require("./storefront/products");
7
8
  class StorefrontAPI {
8
9
  constructor(options) {
9
10
  this.options = options;
10
11
  this.client = this._createClient();
11
12
  this.page = new pages_1.PageAPI(this.client);
12
13
  this.shop = new shop_1.ShopAPI(this.client);
14
+ this.product = new products_1.ProductAPI(this.client);
13
15
  }
14
16
  _createClient() {
15
17
  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 GetProductInput extends Record<string, any> {
4
+ id: string;
5
+ }
6
+ export interface GetProductOutput extends Record<string, any> {
7
+ }
8
+ export declare class GetProduct extends ActionBuilder<StorefrontApiClient, GetProductInput, GetProductOutput> {
9
+ run(args: GetProductInput): Promise<GetProductOutput>;
10
+ }
@@ -0,0 +1,90 @@
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.GetProduct = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ const getGlobalID_1 = require("../../../utils/getGlobalID");
15
+ class GetProduct extends ActionBuilder_1.ActionBuilder {
16
+ run(args) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const { id } = args;
19
+ const globalId = (0, getGlobalID_1.getGlobalID)(id, 'Product');
20
+ const query = `
21
+ {
22
+ product(id: "${globalId}") {
23
+ priceRange {
24
+ maxVariantPrice {
25
+ amount
26
+ currencyCode
27
+ }
28
+ minVariantPrice {
29
+ amount
30
+ currencyCode
31
+ }
32
+ }
33
+ compareAtPriceRange {
34
+ maxVariantPrice {
35
+ amount
36
+ currencyCode
37
+ }
38
+ minVariantPrice {
39
+ amount
40
+ currencyCode
41
+ }
42
+ }
43
+ description(truncateAt: 300)
44
+ descriptionHtml
45
+ options {
46
+ values
47
+ name
48
+ }
49
+ images(first: 20) {
50
+ nodes {
51
+ id
52
+ url(transform: {maxWidth: 1000, crop: CENTER, preferredContentType: WEBP})
53
+ height
54
+ altText
55
+ width
56
+ }
57
+ }
58
+ vendor
59
+ variants(first: 250) {
60
+ nodes {
61
+ id
62
+ availableForSale
63
+ selectedOptions {
64
+ name
65
+ value
66
+ }
67
+ price {
68
+ amount
69
+ currencyCode
70
+ }
71
+ compareAtPrice {
72
+ amount
73
+ currencyCode
74
+ }
75
+ image {
76
+ id
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
82
+ `;
83
+ const { data } = yield this.client.request(query);
84
+ console.log('data', data);
85
+ const { product } = Object.assign({}, data);
86
+ return Object.assign({}, product);
87
+ });
88
+ }
89
+ }
90
+ exports.GetProduct = GetProduct;
@@ -0,0 +1,12 @@
1
+ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/types";
2
+ import { ActionBuilder } from "../../ActionBuilder";
3
+ export interface SearchProductsInput extends Record<string, any> {
4
+ after?: string;
5
+ }
6
+ export interface SearchProductsOutput extends Record<string, any> {
7
+ items: any[];
8
+ pageInfo: any;
9
+ }
10
+ export declare class SearchProducts extends ActionBuilder<AdminApiClient, SearchProductsInput, SearchProductsOutput> {
11
+ run(args?: SearchProductsInput): Promise<SearchProductsOutput>;
12
+ }
@@ -0,0 +1,47 @@
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.SearchProducts = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ class SearchProducts extends ActionBuilder_1.ActionBuilder {
15
+ run(args) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const { after } = Object.assign({}, args);
18
+ const query = `
19
+ {
20
+ products(
21
+ first: 10
22
+ sortKey: UPDATED_AT
23
+ reverse: true
24
+ ${after ? `after: "${after}"` : ''}
25
+ ) {
26
+ nodes {
27
+ id
28
+ }
29
+ pageInfo {
30
+ hasNextPage
31
+ endCursor
32
+ }
33
+ }
34
+ }
35
+ `;
36
+ const { data } = yield this.client.request(query);
37
+ const { products } = Object.assign({}, data);
38
+ const { nodes, pageInfo } = Object.assign({}, products);
39
+ const items = Array.isArray(nodes) ? nodes : [];
40
+ return {
41
+ items,
42
+ pageInfo
43
+ };
44
+ });
45
+ }
46
+ }
47
+ exports.SearchProducts = SearchProducts;
@@ -0,0 +1,10 @@
1
+ import { APIBase } from "../../APIBase";
2
+ import { GetProductInput, GetProductOutput } from "./GetProduct";
3
+ import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
4
+ export interface ProductAPIInterface {
5
+ get(args: GetProductInput): Promise<GetProductOutput>;
6
+ }
7
+ export declare class ProductAPI extends APIBase<StorefrontApiClient> implements ProductAPIInterface {
8
+ private _runAction;
9
+ get(args: GetProductInput): Promise<GetProductOutput>;
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.ProductAPI = void 0;
13
+ const APIBase_1 = require("../../APIBase");
14
+ const GetProduct_1 = require("./GetProduct");
15
+ class ProductAPI 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
+ get(args) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ return this._runAction(GetProduct_1.GetProduct, args);
25
+ });
26
+ }
27
+ }
28
+ exports.ProductAPI = ProductAPI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",