@pintahub/shopify-api 1.0.4 → 1.0.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,4 +1,5 @@
1
1
  import { AdminProductAPIInterface } from "./admin/products";
2
+ import { AdminCollectionAPIInterface } from "./admin/collections";
2
3
  export interface APIOptions extends Record<string, any> {
3
4
  shop: string;
4
5
  accessToken: string;
@@ -7,6 +8,7 @@ export declare class AdminAPI {
7
8
  private readonly options;
8
9
  private readonly client;
9
10
  readonly product: AdminProductAPIInterface;
11
+ readonly collection: AdminCollectionAPIInterface;
10
12
  constructor(options: APIOptions);
11
13
  private _createClient;
12
14
  }
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AdminAPI = void 0;
4
4
  const admin_api_client_1 = require("@shopify/admin-api-client");
5
5
  const products_1 = require("./admin/products");
6
+ const collections_1 = require("./admin/collections");
6
7
  class AdminAPI {
7
8
  constructor(options) {
8
9
  this.options = options;
9
10
  this.client = this._createClient();
10
11
  this.product = new products_1.AdminProductAPI(this.client);
12
+ this.collection = new collections_1.AdminCollectionAPI(this.client);
11
13
  }
12
14
  _createClient() {
13
15
  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 GetCollectionInput extends Record<string, any> {
4
+ id: string;
5
+ }
6
+ export interface GetCollectionOutput extends Record<string, any> {
7
+ }
8
+ export declare class GetCollection extends ActionBuilder<AdminApiClient, GetCollectionInput, GetCollectionOutput> {
9
+ run(args: GetCollectionInput): Promise<GetCollectionOutput>;
10
+ }
@@ -0,0 +1,49 @@
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.GetCollection = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ const getGlobalID_1 = require("../../../utils/getGlobalID");
15
+ class GetCollection extends ActionBuilder_1.ActionBuilder {
16
+ run(args) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const query = `
19
+ query ($id: ID!) {
20
+ collection(id: $id) {
21
+ handle
22
+ title
23
+ updatedAt
24
+ id
25
+ descriptionHtml
26
+ productsCount
27
+ image {
28
+ id
29
+ url
30
+ altText
31
+ height
32
+ width
33
+ }
34
+ }
35
+ }
36
+ `;
37
+ const { id } = args;
38
+ const globalId = (0, getGlobalID_1.getGlobalID)(id, 'Collection');
39
+ const { data } = yield this.client.request(query, {
40
+ variables: {
41
+ id: globalId
42
+ }
43
+ });
44
+ const { collection } = Object.assign({}, data);
45
+ return Object.assign({}, collection);
46
+ });
47
+ }
48
+ }
49
+ exports.GetCollection = GetCollection;
@@ -0,0 +1,11 @@
1
+ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/types";
2
+ import { ActionBuilder } from "../../ActionBuilder";
3
+ export interface SearchCollectionsInput extends Record<string, any> {
4
+ }
5
+ export interface SearchCollectionsOutput extends Record<string, any> {
6
+ items: any[];
7
+ pageInfo: any;
8
+ }
9
+ export declare class SearchCollections extends ActionBuilder<AdminApiClient, SearchCollectionsInput, SearchCollectionsOutput> {
10
+ run(args?: SearchCollectionsInput): Promise<SearchCollectionsOutput>;
11
+ }
@@ -0,0 +1,41 @@
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.SearchCollections = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ class SearchCollections extends ActionBuilder_1.ActionBuilder {
15
+ run(args) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const query = `
18
+ {
19
+ collections(first: 100, reverse: false, sortKey: UPDATED_AT) {
20
+ nodes {
21
+ id
22
+ }
23
+ pageInfo {
24
+ endCursor
25
+ hasNextPage
26
+ }
27
+ }
28
+ }
29
+ `;
30
+ const { data } = yield this.client.request(query);
31
+ const { collections } = Object.assign({}, data);
32
+ const { nodes, pageInfo } = Object.assign({}, collections);
33
+ const items = Array.isArray(nodes) ? nodes : [];
34
+ return {
35
+ items,
36
+ pageInfo
37
+ };
38
+ });
39
+ }
40
+ }
41
+ exports.SearchCollections = SearchCollections;
@@ -0,0 +1,13 @@
1
+ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/types";
2
+ import { APIBase } from "../../APIBase";
3
+ import { SearchCollectionsInput, SearchCollectionsOutput } from "./SearchCollections";
4
+ import { GetCollectionInput, GetCollectionOutput } from "./GetCollection";
5
+ export interface AdminCollectionAPIInterface {
6
+ get(args?: GetCollectionInput): Promise<GetCollectionOutput>;
7
+ search(args?: SearchCollectionsInput): Promise<SearchCollectionsOutput>;
8
+ }
9
+ export declare class AdminCollectionAPI extends APIBase<AdminApiClient> implements AdminCollectionAPIInterface {
10
+ private _runAction;
11
+ get(args: GetCollectionInput): Promise<GetCollectionOutput>;
12
+ search(args?: SearchCollectionsInput): Promise<SearchCollectionsOutput>;
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.AdminCollectionAPI = void 0;
13
+ const APIBase_1 = require("../../APIBase");
14
+ const SearchCollections_1 = require("./SearchCollections");
15
+ const GetCollection_1 = require("./GetCollection");
16
+ class AdminCollectionAPI 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
+ get(args) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return this._runAction(GetCollection_1.GetCollection, args);
26
+ });
27
+ }
28
+ search(args) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return this._runAction(SearchCollections_1.SearchCollections, args);
31
+ });
32
+ }
33
+ }
34
+ exports.AdminCollectionAPI = AdminCollectionAPI;
@@ -3,11 +3,11 @@ import { APIBase } from "../../APIBase";
3
3
  import { GetProductInput, GetProductOutput } from "./GetProduct";
4
4
  import { SearchProductsInput, SearchProductsOutput } from "./SearchProducts";
5
5
  export interface AdminProductAPIInterface {
6
- getProduct(args: GetProductInput): Promise<GetProductOutput>;
7
- searchProducts(args?: SearchProductsInput): Promise<SearchProductsOutput>;
6
+ get(args: GetProductInput): Promise<GetProductOutput>;
7
+ search(args?: SearchProductsInput): Promise<SearchProductsOutput>;
8
8
  }
9
9
  export declare class AdminProductAPI extends APIBase<AdminApiClient> implements AdminProductAPIInterface {
10
10
  private _runAction;
11
- getProduct(args: GetProductInput): Promise<GetProductOutput>;
12
- searchProducts(args?: SearchProductsInput): Promise<SearchProductsOutput>;
11
+ get(args: GetProductInput): Promise<GetProductOutput>;
12
+ search(args?: SearchProductsInput): Promise<SearchProductsOutput>;
13
13
  }
@@ -20,12 +20,12 @@ class AdminProductAPI extends APIBase_1.APIBase {
20
20
  return action.run(args);
21
21
  });
22
22
  }
23
- getProduct(args) {
23
+ get(args) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  return this._runAction(GetProduct_1.GetProduct, args);
26
26
  });
27
27
  }
28
- searchProducts(args) {
28
+ search(args) {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
30
  return this._runAction(SearchProducts_1.SearchProducts, args);
31
31
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",