@pintahub/shopify-api 1.9.8 → 2.0.0

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.
@@ -0,0 +1,18 @@
1
+ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/graphql/types";
2
+ import { ActionBuilder } from "../../ActionBuilder";
3
+ export interface SearchProductsInput extends Record<string, any> {
4
+ first?: number;
5
+ last?: number;
6
+ sortKey?: string;
7
+ before?: string;
8
+ after?: string;
9
+ query?: string;
10
+ reverse?: boolean;
11
+ }
12
+ export interface SearchProductsOutput extends Record<string, any> {
13
+ items: any[];
14
+ pageInfo: any;
15
+ }
16
+ export declare class SearchProducts extends ActionBuilder<AdminApiClient, SearchProductsInput, SearchProductsOutput> {
17
+ run(args?: SearchProductsInput): Promise<SearchProductsOutput>;
18
+ }
@@ -0,0 +1,66 @@
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
+ const handleErrors_1 = require("../../../utils/handleErrors");
15
+ class SearchProducts extends ActionBuilder_1.ActionBuilder {
16
+ run(args) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const vArgs = Object.assign({
19
+ first: 10,
20
+ sortKey: 'UPDATED_AT',
21
+ reverse: true
22
+ }, args);
23
+ const query = `
24
+ query searchProducts($first: Int, $last: Int, $query: String,
25
+ $before: String, $after: String,
26
+ $reverse: Boolean, $sortKey: ProductSortKeys,
27
+ ) {
28
+ products(
29
+ first: $first
30
+ sortKey: $sortKey
31
+ reverse: $reverse
32
+ query: $query
33
+ before: $before
34
+ after: $after
35
+ last: $last
36
+ ) {
37
+ nodes {
38
+ id
39
+ handle
40
+ title
41
+ status
42
+ productType
43
+ vendor
44
+ }
45
+ pageInfo {
46
+ hasNextPage
47
+ endCursor
48
+ }
49
+ }
50
+ }
51
+ `;
52
+ const { data, errors } = yield this.client.request(query, {
53
+ variables: vArgs
54
+ });
55
+ yield (0, handleErrors_1.handleErrors)(errors);
56
+ const { products } = Object.assign({}, data);
57
+ const { nodes, pageInfo } = Object.assign({}, products);
58
+ const items = Array.isArray(nodes) ? nodes : [];
59
+ return {
60
+ items,
61
+ pageInfo
62
+ };
63
+ });
64
+ }
65
+ }
66
+ exports.SearchProducts = SearchProducts;
@@ -3,13 +3,16 @@ import { APIBase } from "../../APIBase";
3
3
  import { UpdateVariantsInput, UpdateVariantsOutput } from "./UpdateVariants";
4
4
  import { UpdateProductInput, UpdateProductOutput } from "./UpdateProduct";
5
5
  import { GetProductInput, GetProductOutput } from "./GetProduct";
6
+ import { SearchProductsInput, SearchProductsOutput } from "./SearchProducts";
6
7
  export interface AdminProductsAPIInterface {
8
+ search(args: SearchProductsInput): Promise<SearchProductsOutput>;
7
9
  get(args: GetProductInput): Promise<GetProductOutput>;
8
10
  update(args: UpdateProductInput): Promise<UpdateProductOutput>;
9
11
  updateVariants(args: UpdateVariantsInput): Promise<UpdateVariantsOutput>;
10
12
  }
11
13
  export declare class AdminProductsAPI extends APIBase<AdminApiClient> implements AdminProductsAPIInterface {
12
14
  private _runAction;
15
+ search(args: SearchProductsInput): Promise<SearchProductsOutput>;
13
16
  get(args: GetProductInput): Promise<GetProductOutput>;
14
17
  update(args: UpdateProductInput): Promise<UpdateProductOutput>;
15
18
  updateVariants(args: UpdateVariantsInput): Promise<UpdateVariantsOutput>;
@@ -14,6 +14,7 @@ const APIBase_1 = require("../../APIBase");
14
14
  const UpdateVariants_1 = require("./UpdateVariants");
15
15
  const UpdateProduct_1 = require("./UpdateProduct");
16
16
  const GetProduct_1 = require("./GetProduct");
17
+ const SearchProducts_1 = require("./SearchProducts");
17
18
  class AdminProductsAPI extends APIBase_1.APIBase {
18
19
  _runAction(Action, args) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
@@ -21,6 +22,11 @@ class AdminProductsAPI extends APIBase_1.APIBase {
21
22
  return action.run(args);
22
23
  });
23
24
  }
25
+ search(args) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return this._runAction(SearchProducts_1.SearchProducts, args);
28
+ });
29
+ }
24
30
  get(args) {
25
31
  return __awaiter(this, void 0, void 0, function* () {
26
32
  return this._runAction(GetProduct_1.GetProduct, args);
@@ -0,0 +1,12 @@
1
+ import { ActionBuilder } from "../../ActionBuilder";
2
+ import { AxiosInstance } from "axios";
3
+ export interface GetOrderTransactionInput extends Record<string, any> {
4
+ id: string;
5
+ }
6
+ export interface GetOrderTransactionOutput extends Record<string, any> {
7
+ }
8
+ export declare class GetOrderTransaction extends ActionBuilder<AxiosInstance, GetOrderTransactionInput, GetOrderTransactionOutput> {
9
+ private _parseFee;
10
+ private _parseTransaction;
11
+ run(args: GetOrderTransactionInput): Promise<GetOrderTransactionOutput>;
12
+ }
@@ -0,0 +1,65 @@
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.GetOrderTransaction = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ const parseOnlyId_1 = require("../../../utils/parseOnlyId");
15
+ class GetOrderTransaction extends ActionBuilder_1.ActionBuilder {
16
+ _parseFee(receipt, gateway) {
17
+ if (gateway === 'shopify_payments') {
18
+ const { metadata } = Object.assign({}, receipt);
19
+ const { transaction_fee_total_amount } = Object.assign({}, metadata);
20
+ if (!transaction_fee_total_amount)
21
+ return null;
22
+ const n = parseFloat(transaction_fee_total_amount);
23
+ if (isNaN(n))
24
+ return null;
25
+ return n;
26
+ }
27
+ const { fee_amount } = Object.assign({}, receipt);
28
+ if (fee_amount) {
29
+ const n = parseFloat(fee_amount);
30
+ if (!isNaN(n))
31
+ return n;
32
+ }
33
+ return null;
34
+ }
35
+ _parseTransaction(transactions = []) {
36
+ const arr = Array.isArray(transactions) ? transactions : [];
37
+ const saleTransaction = arr.find(transaction => {
38
+ const { kind, status } = Object.assign({}, transaction);
39
+ return kind === 'sale' && status === 'success';
40
+ });
41
+ if (!saleTransaction) {
42
+ return {};
43
+ }
44
+ const { receipt, gateway } = Object.assign({}, saleTransaction);
45
+ console.log('receipt', receipt);
46
+ const fee_amount = this._parseFee(receipt, gateway);
47
+ return {
48
+ gateway,
49
+ fee_amount
50
+ };
51
+ }
52
+ run(args) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const { id } = args;
55
+ const cleanId = (0, parseOnlyId_1.parseOnlyId)(id);
56
+ const { data } = yield this.client({
57
+ url: `orders/${cleanId}/transactions.json`,
58
+ method: 'GET'
59
+ });
60
+ const { transactions } = Object.assign({}, data);
61
+ return this._parseTransaction(transactions);
62
+ });
63
+ }
64
+ }
65
+ exports.GetOrderTransaction = GetOrderTransaction;
@@ -2,12 +2,15 @@ import { APIBase } from "../../APIBase";
2
2
  import { GetOrderInput, GetOrderOutput } from "./GetOrder";
3
3
  import { AxiosInstance } from "axios";
4
4
  import { UpdateTrackingInput, UpdateTrackingOutput } from "./UpdateTracking";
5
+ import { GetOrderTransactionInput, GetOrderTransactionOutput } from "./GetOrderTransaction";
5
6
  export interface RestOrderAPIInterface {
6
7
  get(args: GetOrderInput): Promise<GetOrderOutput>;
7
8
  updateTracking(args: UpdateTrackingInput): Promise<UpdateTrackingOutput>;
9
+ getTransaction(args: GetOrderTransactionInput): Promise<GetOrderTransactionOutput>;
8
10
  }
9
11
  export declare class RestOrderAPI extends APIBase<AxiosInstance> implements RestOrderAPIInterface {
10
12
  private _runAction;
11
13
  get(args?: GetOrderInput): Promise<GetOrderOutput>;
12
14
  updateTracking(args?: UpdateTrackingInput): Promise<UpdateTrackingOutput>;
15
+ getTransaction(args?: GetOrderTransactionInput): Promise<GetOrderTransactionOutput>;
13
16
  }
@@ -13,6 +13,7 @@ exports.RestOrderAPI = void 0;
13
13
  const APIBase_1 = require("../../APIBase");
14
14
  const GetOrder_1 = require("./GetOrder");
15
15
  const UpdateTracking_1 = require("./UpdateTracking");
16
+ const GetOrderTransaction_1 = require("./GetOrderTransaction");
16
17
  class RestOrderAPI extends APIBase_1.APIBase {
17
18
  _runAction(Action, args) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -30,5 +31,10 @@ class RestOrderAPI extends APIBase_1.APIBase {
30
31
  return this._runAction(UpdateTracking_1.UpdateTracking, args);
31
32
  });
32
33
  }
34
+ getTransaction(args) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ return this._runAction(GetOrderTransaction_1.GetOrderTransaction, args);
37
+ });
38
+ }
33
39
  }
34
40
  exports.RestOrderAPI = RestOrderAPI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "1.9.8",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",