@pintahub/shopify-api 2.3.7 → 2.3.8
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,11 @@
|
|
|
1
|
+
import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/graphql/types";
|
|
2
|
+
import { ActionBuilder } from "../../ActionBuilder";
|
|
3
|
+
export interface GetVariantsInput extends Record<string, any> {
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
export interface GetVariantsOutput extends Record<string, any> {
|
|
7
|
+
variants: Array<Record<string, any>>;
|
|
8
|
+
}
|
|
9
|
+
export declare class GetVariants extends ActionBuilder<AdminApiClient, GetVariantsInput, GetVariantsOutput> {
|
|
10
|
+
run(args: GetVariantsInput): Promise<GetVariantsOutput>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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.GetVariants = void 0;
|
|
13
|
+
const ActionBuilder_1 = require("../../ActionBuilder");
|
|
14
|
+
const getGlobalID_1 = require("../../../utils/getGlobalID");
|
|
15
|
+
const handleErrors_1 = require("../../../utils/handleErrors");
|
|
16
|
+
class GetVariants 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
|
+
variants(first: 250) {
|
|
26
|
+
nodes {
|
|
27
|
+
id
|
|
28
|
+
availableForSale
|
|
29
|
+
selectedOptions {
|
|
30
|
+
name
|
|
31
|
+
value
|
|
32
|
+
}
|
|
33
|
+
image {
|
|
34
|
+
id
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
const { data, errors } = yield this.client.request(query);
|
|
42
|
+
yield (0, handleErrors_1.handleErrors)(errors);
|
|
43
|
+
const { product } = Object.assign({}, data);
|
|
44
|
+
const { variants, id: productId } = Object.assign({}, product);
|
|
45
|
+
if (!productId) {
|
|
46
|
+
throw new Error('Product not found!');
|
|
47
|
+
}
|
|
48
|
+
const { nodes } = Object.assign({}, variants);
|
|
49
|
+
const arr = Array.isArray(nodes) ? nodes : [];
|
|
50
|
+
return {
|
|
51
|
+
variants: arr
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.GetVariants = GetVariants;
|
|
@@ -13,6 +13,7 @@ import { ReorderMediaInput, ReorderMediaOutput } from "./ReorderMedia";
|
|
|
13
13
|
import { CreateProductInput, CreateProductOutput } from "./CreateProduct";
|
|
14
14
|
import { PublishProductInput, PublishProductOutput } from "./PublishProduct";
|
|
15
15
|
import { NextCreateProductInput, NextCreateProductOutput } from "./NextCreateProduct";
|
|
16
|
+
import { GetVariantsInput, GetVariantsOutput } from "./GetVariants";
|
|
16
17
|
export interface AdminProductsAPIInterface {
|
|
17
18
|
search(args: SearchProductsInput): Promise<SearchProductsOutput>;
|
|
18
19
|
get(args: GetProductInput): Promise<GetProductOutput>;
|
|
@@ -21,6 +22,7 @@ export interface AdminProductsAPIInterface {
|
|
|
21
22
|
getOptions(args: GetProductOptionsInput): Promise<GetProductOptionsOutput>;
|
|
22
23
|
update(args: UpdateProductInput): Promise<UpdateProductOutput>;
|
|
23
24
|
delete(args: DeleteProductInput): Promise<DeleteProductOutput>;
|
|
25
|
+
getVariants(args: GetVariantsInput): Promise<GetVariantsOutput>;
|
|
24
26
|
updateVariants(args: UpdateVariantsInput): Promise<UpdateVariantsOutput>;
|
|
25
27
|
getMedia(args: GetProductMediaInput): Promise<GetProductMediaOutput>;
|
|
26
28
|
deleteMedia(args: DeleteProductMediaInput): Promise<DeleteProductMediaOutput>;
|
|
@@ -37,6 +39,7 @@ export declare class AdminProductsAPI extends APIBase<AdminApiClient> implements
|
|
|
37
39
|
getOptions(args: GetProductOptionsInput): Promise<GetProductOptionsOutput>;
|
|
38
40
|
update(args: UpdateProductInput): Promise<UpdateProductOutput>;
|
|
39
41
|
delete(args: DeleteProductInput): Promise<DeleteProductOutput>;
|
|
42
|
+
getVariants(args: GetVariantsInput): Promise<GetVariantsOutput>;
|
|
40
43
|
updateVariants(args: UpdateVariantsInput): Promise<UpdateVariantsOutput>;
|
|
41
44
|
getMedia(args: GetProductMediaInput): Promise<GetProductMediaOutput>;
|
|
42
45
|
deleteMedia(args: DeleteProductMediaInput): Promise<DeleteProductMediaOutput>;
|
|
@@ -24,6 +24,7 @@ const ReorderMedia_1 = require("./ReorderMedia");
|
|
|
24
24
|
const CreateProduct_1 = require("./CreateProduct");
|
|
25
25
|
const PublishProduct_1 = require("./PublishProduct");
|
|
26
26
|
const NextCreateProduct_1 = require("./NextCreateProduct");
|
|
27
|
+
const GetVariants_1 = require("./GetVariants");
|
|
27
28
|
class AdminProductsAPI extends APIBase_1.APIBase {
|
|
28
29
|
_runAction(Action, args) {
|
|
29
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -66,6 +67,11 @@ class AdminProductsAPI extends APIBase_1.APIBase {
|
|
|
66
67
|
return this._runAction(DeleteProduct_1.DeleteProduct, args);
|
|
67
68
|
});
|
|
68
69
|
}
|
|
70
|
+
getVariants(args) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return this._runAction(GetVariants_1.GetVariants, args);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
69
75
|
updateVariants(args) {
|
|
70
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
77
|
return this._runAction(UpdateVariants_1.UpdateVariants, args);
|