@pintahub/shopify-api 1.7.3 → 1.7.4

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.
@@ -3,6 +3,7 @@ import { PageAPIInterface } from "./storefront/pages";
3
3
  import { ShopAPIInterface } from "./storefront/shop";
4
4
  import { ProductAPIInterface } from "./storefront/products";
5
5
  import { CartAPIInterface } from "./storefront/cart";
6
+ import { PostsAPIInterface } from "./storefront/posts";
6
7
  export declare class StorefrontAPI {
7
8
  private readonly options;
8
9
  private readonly client;
@@ -10,6 +11,7 @@ export declare class StorefrontAPI {
10
11
  readonly shop: ShopAPIInterface;
11
12
  readonly product: ProductAPIInterface;
12
13
  readonly cart: CartAPIInterface;
14
+ readonly posts: PostsAPIInterface;
13
15
  constructor(options: StorefrontAPIOptions);
14
16
  private _createClient;
15
17
  }
@@ -6,6 +6,7 @@ const pages_1 = require("./storefront/pages");
6
6
  const shop_1 = require("./storefront/shop");
7
7
  const products_1 = require("./storefront/products");
8
8
  const cart_1 = require("./storefront/cart");
9
+ const posts_1 = require("./storefront/posts");
9
10
  class StorefrontAPI {
10
11
  constructor(options) {
11
12
  this.options = options;
@@ -14,6 +15,7 @@ class StorefrontAPI {
14
15
  this.shop = new shop_1.ShopAPI(this.client);
15
16
  this.product = new products_1.ProductAPI(this.client);
16
17
  this.cart = new cart_1.CartAPI(this.client);
18
+ this.posts = new posts_1.PostsAPI(this.client);
17
19
  }
18
20
  _createClient() {
19
21
  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 GetPostInput extends Record<string, any> {
4
+ id: string;
5
+ }
6
+ export interface GetPostOutput extends Record<string, any> {
7
+ }
8
+ export declare class GetPost extends ActionBuilder<StorefrontApiClient, GetPostInput, GetPostOutput> {
9
+ run(args: GetPostInput): Promise<GetPostOutput>;
10
+ }
@@ -0,0 +1,53 @@
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.GetPost = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ const handleErrors_1 = require("../../../utils/handleErrors");
15
+ const getGlobalID_1 = require("../../../utils/getGlobalID");
16
+ class GetPost extends ActionBuilder_1.ActionBuilder {
17
+ run(args) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const { id } = args;
20
+ const globalId = (0, getGlobalID_1.getGlobalID)(id, 'Article');
21
+ const query = `
22
+ {
23
+ article(id: "${globalId}") {
24
+ authorV2 {
25
+ name
26
+ }
27
+ contentHtml
28
+ excerpt
29
+ handle
30
+ image {
31
+ url
32
+ width
33
+ height
34
+ altText
35
+ }
36
+ publishedAt
37
+ seo {
38
+ description
39
+ title
40
+ }
41
+ tags
42
+ title
43
+ }
44
+ }
45
+ `;
46
+ const { data, errors } = yield this.client.request(query);
47
+ yield (0, handleErrors_1.handleErrors)(errors);
48
+ const { article } = Object.assign({}, data);
49
+ return Object.assign({}, article);
50
+ });
51
+ }
52
+ }
53
+ exports.GetPost = GetPost;
@@ -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,94 @@
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
+ const handleErrors_1 = require("../../../utils/handleErrors");
16
+ class GetProduct extends ActionBuilder_1.ActionBuilder {
17
+ run(args) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const { id } = args;
20
+ const globalId = (0, getGlobalID_1.getGlobalID)(id, 'Product');
21
+ const query = `
22
+ {
23
+ product(id: "${globalId}") {
24
+ id
25
+ title
26
+ handle
27
+ priceRange {
28
+ maxVariantPrice {
29
+ amount
30
+ currencyCode
31
+ }
32
+ minVariantPrice {
33
+ amount
34
+ currencyCode
35
+ }
36
+ }
37
+ compareAtPriceRange {
38
+ maxVariantPrice {
39
+ amount
40
+ currencyCode
41
+ }
42
+ minVariantPrice {
43
+ amount
44
+ currencyCode
45
+ }
46
+ }
47
+ description(truncateAt: 300)
48
+ descriptionHtml
49
+ options {
50
+ values
51
+ name
52
+ }
53
+ images(first: 20) {
54
+ nodes {
55
+ id
56
+ url(transform: {maxWidth: 1200})
57
+ height
58
+ altText
59
+ width
60
+ }
61
+ }
62
+ vendor
63
+ variants(first: 250) {
64
+ nodes {
65
+ id
66
+ availableForSale
67
+ selectedOptions {
68
+ name
69
+ value
70
+ }
71
+ price {
72
+ amount
73
+ currencyCode
74
+ }
75
+ compareAtPrice {
76
+ amount
77
+ currencyCode
78
+ }
79
+ image {
80
+ id
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ `;
87
+ const { data, errors } = yield this.client.request(query);
88
+ yield (0, handleErrors_1.handleErrors)(errors);
89
+ const { product } = Object.assign({}, data);
90
+ return Object.assign({}, product);
91
+ });
92
+ }
93
+ }
94
+ exports.GetProduct = GetProduct;
@@ -0,0 +1,9 @@
1
+ import { ActionBuilder } from "../../ActionBuilder";
2
+ import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
3
+ export interface SearchPostsInput extends Record<string, any> {
4
+ }
5
+ export interface SearchPostsOutput extends Record<string, any> {
6
+ }
7
+ export declare class SearchPosts extends ActionBuilder<StorefrontApiClient, SearchPostsInput, SearchPostsOutput> {
8
+ run(args: SearchPostsInput): Promise<SearchPostsOutput>;
9
+ }
@@ -0,0 +1,58 @@
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.SearchPosts = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ const handleErrors_1 = require("../../../utils/handleErrors");
15
+ class SearchPosts extends ActionBuilder_1.ActionBuilder {
16
+ run(args) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const query = `
19
+ {
20
+ articles(first: 20, sortKey: PUBLISHED_AT, reverse: true) {
21
+ nodes {
22
+ authorV2 {
23
+ name
24
+ }
25
+ id
26
+ excerpt
27
+ handle
28
+ publishedAt
29
+ title
30
+ tags
31
+ image {
32
+ url(transform: {maxWidth: 500})
33
+ altText
34
+ width
35
+ height
36
+ }
37
+ }
38
+ pageInfo {
39
+ hasNextPage
40
+ hasPreviousPage
41
+ startCursor
42
+ endCursor
43
+ }
44
+ }
45
+ }
46
+ `;
47
+ const { data, errors } = yield this.client.request(query);
48
+ yield (0, handleErrors_1.handleErrors)(errors);
49
+ const { articles } = Object.assign({}, data);
50
+ const { nodes, pageInfo } = Object.assign({}, articles);
51
+ return {
52
+ items: Array.isArray(nodes) ? nodes : [],
53
+ pageInfo,
54
+ };
55
+ });
56
+ }
57
+ }
58
+ exports.SearchPosts = SearchPosts;
@@ -0,0 +1,13 @@
1
+ import { APIBase } from "../../APIBase";
2
+ import { SearchPostsInput, SearchPostsOutput } from "./SearchPosts";
3
+ import { StorefrontApiClient } from "@shopify/storefront-api-client/dist/ts/types";
4
+ import { GetPostInput, GetPostOutput } from "./GetPost";
5
+ export interface PostsAPIInterface {
6
+ search(args: SearchPostsInput): Promise<SearchPostsOutput>;
7
+ get(args: GetPostInput): Promise<GetPostOutput>;
8
+ }
9
+ export declare class PostsAPI extends APIBase<StorefrontApiClient> implements PostsAPIInterface {
10
+ private _runAction;
11
+ search(args: SearchPostsInput): Promise<SearchPostsOutput>;
12
+ get(args: GetPostInput): Promise<GetPostOutput>;
13
+ }
@@ -0,0 +1,34 @@
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.PostsAPI = void 0;
13
+ const APIBase_1 = require("../../APIBase");
14
+ const SearchPosts_1 = require("./SearchPosts");
15
+ const GetPost_1 = require("./GetPost");
16
+ class PostsAPI extends APIBase_1.APIBase {
17
+ _runAction(Action, args) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const action = new Action(this.client);
20
+ return action.run(args);
21
+ });
22
+ }
23
+ search(args) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return this._runAction(SearchPosts_1.SearchPosts, args);
26
+ });
27
+ }
28
+ get(args) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return this._runAction(GetPost_1.GetPost, args);
31
+ });
32
+ }
33
+ }
34
+ exports.PostsAPI = PostsAPI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",