@pintahub/shopify-api 1.1.4 → 1.1.6

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 { AdminApiClient } from "@shopify/admin-api-client/dist/ts/types";
2
+ import { ActionBuilder } from "../../ActionBuilder";
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<AdminApiClient, GetProductInput, GetProductOutput> {
9
+ run(args: GetProductInput): Promise<GetProductOutput>;
10
+ }
@@ -0,0 +1,104 @@
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
+ id
24
+ handle
25
+ publishedAt
26
+ updatedAt
27
+ status
28
+ featuredImage {
29
+ altText
30
+ url(transform: {preferredContentType: PNG, maxWidth: 1024})
31
+ width
32
+ height
33
+ }
34
+ productType
35
+ title
36
+ descriptionHtml
37
+ priceRangeV2 {
38
+ maxVariantPrice {
39
+ amount
40
+ currencyCode
41
+ }
42
+ minVariantPrice {
43
+ amount
44
+ currencyCode
45
+ }
46
+ }
47
+ tags
48
+ productCategory {
49
+ productTaxonomyNode {
50
+ fullName
51
+ name
52
+ }
53
+ }
54
+ collections(first: 100) {
55
+ nodes {
56
+ id
57
+ }
58
+ }
59
+ options {
60
+ values
61
+ name
62
+ }
63
+ metafields(first: 100) {
64
+ nodes {
65
+ key
66
+ value
67
+ type
68
+ }
69
+ }
70
+ images(first: 20) {
71
+ nodes {
72
+ id
73
+ url(transform: {maxWidth: 1000, crop: CENTER, preferredContentType: WEBP})
74
+ height
75
+ altText
76
+ width
77
+ }
78
+ }
79
+ variants(first: 250) {
80
+ nodes {
81
+ id
82
+ availableForSale
83
+ selectedOptions {
84
+ name
85
+ value
86
+ }
87
+ price
88
+ compareAtPrice
89
+ image {
90
+ id
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ `;
97
+ const { data } = yield this.client.request(query);
98
+ console.log('data', data);
99
+ const { product } = Object.assign({}, data);
100
+ return Object.assign({}, product);
101
+ });
102
+ }
103
+ }
104
+ exports.GetProduct = GetProduct;
@@ -0,0 +1,11 @@
1
+ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/types";
2
+ import { ActionBuilder } from "../../ActionBuilder";
3
+ export interface GetPublicationsInput extends Record<string, any> {
4
+ id: string;
5
+ }
6
+ export interface GetPublicationsOutput extends Record<string, any> {
7
+ publications: Array<any>;
8
+ }
9
+ export declare class GetPublications extends ActionBuilder<AdminApiClient, GetPublicationsInput, GetPublicationsOutput> {
10
+ run(args: GetPublicationsInput): Promise<GetPublicationsOutput>;
11
+ }
@@ -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.GetPublications = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ const getGlobalID_1 = require("../../../utils/getGlobalID");
15
+ class GetPublications 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
+ id
24
+ resourcePublications(first: 50) {
25
+ nodes {
26
+ isPublished
27
+ publication {
28
+ id
29
+ name
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ `;
36
+ const { data, extensions } = yield this.client.request(query);
37
+ const { product } = Object.assign({}, data);
38
+ const { resourcePublications, id: idResult } = Object.assign({}, product);
39
+ const { nodes } = Object.assign({}, resourcePublications);
40
+ const publications = Array.isArray(nodes) ? nodes : [];
41
+ return {
42
+ id: idResult,
43
+ publications,
44
+ };
45
+ });
46
+ }
47
+ }
48
+ exports.GetPublications = GetPublications;
@@ -2,12 +2,15 @@ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/types";
2
2
  import { APIBase } from "../../APIBase";
3
3
  import { GetProductInput, GetProductOutput } from "./GetProduct";
4
4
  import { SearchProductsInput, SearchProductsOutput } from "./SearchProducts";
5
+ import { GetPublicationsInput, GetPublicationsOutput } from "./GetPublications";
5
6
  export interface AdminProductAPIInterface {
6
7
  get(args: GetProductInput): Promise<GetProductOutput>;
8
+ getPublications(args: GetPublicationsInput): Promise<GetPublicationsOutput>;
7
9
  search(args?: SearchProductsInput): Promise<SearchProductsOutput>;
8
10
  }
9
11
  export declare class AdminProductAPI extends APIBase<AdminApiClient> implements AdminProductAPIInterface {
10
12
  private _runAction;
11
13
  get(args: GetProductInput): Promise<GetProductOutput>;
14
+ getPublications(args: GetPublicationsInput): Promise<GetPublicationsOutput>;
12
15
  search(args?: SearchProductsInput): Promise<SearchProductsOutput>;
13
16
  }
@@ -13,6 +13,7 @@ exports.AdminProductAPI = void 0;
13
13
  const APIBase_1 = require("../../APIBase");
14
14
  const GetProduct_1 = require("./GetProduct");
15
15
  const SearchProducts_1 = require("./SearchProducts");
16
+ const GetPublications_1 = require("./GetPublications");
16
17
  class AdminProductAPI extends APIBase_1.APIBase {
17
18
  _runAction(Action, args) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -25,6 +26,11 @@ class AdminProductAPI extends APIBase_1.APIBase {
25
26
  return this._runAction(GetProduct_1.GetProduct, args);
26
27
  });
27
28
  }
29
+ getPublications(args) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return this._runAction(GetPublications_1.GetPublications, args);
32
+ });
33
+ }
28
34
  search(args) {
29
35
  return __awaiter(this, void 0, void 0, function* () {
30
36
  return this._runAction(SearchProducts_1.SearchProducts, args);
@@ -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.6",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",