@pintahub/shopify-api 2.0.3 → 2.0.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.
- package/dist/classes/admin/products-v2/GetProductMedia.d.ts +12 -0
- package/dist/classes/admin/products-v2/GetProductMedia.js +87 -0
- package/dist/classes/admin/products-v2/index.d.ts +3 -0
- package/dist/classes/admin/products-v2/index.js +6 -0
- package/dist/classes/rest/orders/GetOrderTransaction.js +1 -0
- package/package.json +1 -1
|
@@ -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);
|