@pintahub/shopify-api 2.0.3 → 2.0.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.
@@ -9,11 +9,11 @@ import { AdminProductsAPIInterface } from "./admin/products-v2";
9
9
  import { AdminCustomersAPIInterface } from "./admin/customers";
10
10
  export declare class AdminAPI {
11
11
  private readonly options;
12
- private readonly client;
13
- readonly product: AdminProductAPIInterface;
14
- readonly metaobject: AdminMetaObjectAPIInterface;
15
- readonly order: AdminOrderAPIInterface;
16
- readonly files: AdminFileAPIInterface;
12
+ private readonly client?;
13
+ readonly product?: AdminProductAPIInterface;
14
+ readonly metaobject?: AdminMetaObjectAPIInterface;
15
+ readonly order?: AdminOrderAPIInterface;
16
+ readonly files?: AdminFileAPIInterface;
17
17
  readonly menus: AdminMenuAPIInterface;
18
18
  readonly products: AdminProductsAPIInterface;
19
19
  readonly customers: AdminCustomersAPIInterface;
@@ -12,12 +12,18 @@ const products_v2_1 = require("./admin/products-v2");
12
12
  const customers_1 = require("./admin/customers");
13
13
  class AdminAPI {
14
14
  constructor(options) {
15
- this.options = options;
16
- this.client = this._createClient();
17
- this.product = new products_1.AdminProductAPI(this.client);
18
- this.metaobject = new metaobjects_1.AdminMetaObjectAPI(this.client);
19
- this.order = new orders_1.AdminOrderAPI(this.client);
20
- this.files = new files_1.AdminFileAPI(this.client); //Start migration with plurality
15
+ const defaultOptions = {
16
+ legacy: true
17
+ };
18
+ this.options = Object.assign({}, defaultOptions, options);
19
+ const { legacy } = this.options;
20
+ if (legacy) {
21
+ this.client = this._createClient();
22
+ this.product = new products_1.AdminProductAPI(this.client);
23
+ this.metaobject = new metaobjects_1.AdminMetaObjectAPI(this.client);
24
+ this.order = new orders_1.AdminOrderAPI(this.client);
25
+ this.files = new files_1.AdminFileAPI(this.client); //Start migration with plurality
26
+ }
21
27
  this.menus = new menus_1.AdminMenuAPI(this._createClient('2024-07'));
22
28
  this.products = new products_v2_1.AdminProductsAPI(this._createClient('2024-10'));
23
29
  this.customers = new customers_1.AdminCustomersAPI(this._createClient('2024-10'));
@@ -0,0 +1,12 @@
1
+ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/graphql/types";
2
+ import { ActionBuilder } from "../../ActionBuilder";
3
+ export interface GetProductMediaInput extends Record<string, any> {
4
+ id: string;
5
+ }
6
+ export interface GetProductMediaOutput extends Record<string, any> {
7
+ media: Array<Record<string, any>>;
8
+ }
9
+ export declare class GetProductMedia extends ActionBuilder<AdminApiClient, GetProductMediaInput, GetProductMediaOutput> {
10
+ private _formatMedia;
11
+ run(args: GetProductMediaInput): Promise<GetProductMediaOutput>;
12
+ }
@@ -0,0 +1,87 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.GetProductMedia = void 0;
24
+ const ActionBuilder_1 = require("../../ActionBuilder");
25
+ const getGlobalID_1 = require("../../../utils/getGlobalID");
26
+ const handleErrors_1 = require("../../../utils/handleErrors");
27
+ class GetProductMedia extends ActionBuilder_1.ActionBuilder {
28
+ _formatMedia(media) {
29
+ return media.map(item => {
30
+ const _a = Object.assign({}, item), { preview } = _a, rest = __rest(_a, ["preview"]);
31
+ const { image } = Object.assign({}, preview);
32
+ const { url, width, height, altText } = Object.assign({}, image);
33
+ return Object.assign(Object.assign({}, rest), { url,
34
+ width,
35
+ height,
36
+ altText });
37
+ });
38
+ }
39
+ run(args) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const query = `
42
+ query getMedia($id: ID!) {
43
+ product(id: $id) {
44
+ id
45
+ media(first: 250) {
46
+ nodes {
47
+ id
48
+ alt
49
+ mediaContentType
50
+ status
51
+ ... on MediaImage {
52
+ id
53
+ mimeType
54
+ preview {
55
+ image {
56
+ altText
57
+ height
58
+ id
59
+ url
60
+ width
61
+ }
62
+ }
63
+ updatedAt
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ `;
70
+ const { id } = args;
71
+ const { data, errors, extensions } = yield this.client.request(query, {
72
+ variables: {
73
+ id: (0, getGlobalID_1.getGlobalID)(id, 'Product')
74
+ }
75
+ });
76
+ yield (0, handleErrors_1.handleErrors)(errors);
77
+ const { product } = Object.assign({}, data);
78
+ const { media } = Object.assign({}, product);
79
+ const { nodes } = Object.assign({}, media);
80
+ const arr = Array.isArray(nodes) ? nodes : [];
81
+ return {
82
+ media: this._formatMedia(arr)
83
+ };
84
+ });
85
+ }
86
+ }
87
+ exports.GetProductMedia = GetProductMedia;
@@ -4,11 +4,13 @@ import { UpdateVariantsInput, UpdateVariantsOutput } from "./UpdateVariants";
4
4
  import { UpdateProductInput, UpdateProductOutput } from "./UpdateProduct";
5
5
  import { GetProductInput, GetProductOutput } from "./GetProduct";
6
6
  import { SearchProductsInput, SearchProductsOutput } from "./SearchProducts";
7
+ import { GetProductMediaInput, GetProductMediaOutput } from "./GetProductMedia";
7
8
  export interface AdminProductsAPIInterface {
8
9
  search(args: SearchProductsInput): Promise<SearchProductsOutput>;
9
10
  get(args: GetProductInput): Promise<GetProductOutput>;
10
11
  update(args: UpdateProductInput): Promise<UpdateProductOutput>;
11
12
  updateVariants(args: UpdateVariantsInput): Promise<UpdateVariantsOutput>;
13
+ getMedia(args: GetProductMediaInput): Promise<GetProductMediaOutput>;
12
14
  }
13
15
  export declare class AdminProductsAPI extends APIBase<AdminApiClient> implements AdminProductsAPIInterface {
14
16
  private _runAction;
@@ -16,4 +18,5 @@ export declare class AdminProductsAPI extends APIBase<AdminApiClient> implements
16
18
  get(args: GetProductInput): Promise<GetProductOutput>;
17
19
  update(args: UpdateProductInput): Promise<UpdateProductOutput>;
18
20
  updateVariants(args: UpdateVariantsInput): Promise<UpdateVariantsOutput>;
21
+ getMedia(args: GetProductMediaInput): Promise<GetProductMediaOutput>;
19
22
  }
@@ -15,6 +15,7 @@ const UpdateVariants_1 = require("./UpdateVariants");
15
15
  const UpdateProduct_1 = require("./UpdateProduct");
16
16
  const GetProduct_1 = require("./GetProduct");
17
17
  const SearchProducts_1 = require("./SearchProducts");
18
+ const GetProductMedia_1 = require("./GetProductMedia");
18
19
  class AdminProductsAPI extends APIBase_1.APIBase {
19
20
  _runAction(Action, args) {
20
21
  return __awaiter(this, void 0, void 0, function* () {
@@ -42,5 +43,10 @@ class AdminProductsAPI extends APIBase_1.APIBase {
42
43
  return this._runAction(UpdateVariants_1.UpdateVariants, args);
43
44
  });
44
45
  }
46
+ getMedia(args) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return this._runAction(GetProductMedia_1.GetProductMedia, args);
49
+ });
50
+ }
45
51
  }
46
52
  exports.AdminProductsAPI = AdminProductsAPI;
@@ -14,6 +14,7 @@ const ActionBuilder_1 = require("../../ActionBuilder");
14
14
  const parseOnlyId_1 = require("../../../utils/parseOnlyId");
15
15
  class GetOrderTransaction extends ActionBuilder_1.ActionBuilder {
16
16
  _parseFee(receipt, gateway) {
17
+ console.log('receipt', receipt);
17
18
  if (gateway === 'shopify_payments') {
18
19
  const { metadata } = Object.assign({}, receipt);
19
20
  const { transaction_fee_total_amount } = Object.assign({}, metadata);
@@ -1,4 +1,5 @@
1
1
  export interface APIOptions extends Record<string, any> {
2
2
  shop: string;
3
3
  accessToken: string;
4
+ legacy?: boolean;
4
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",