@pintahub/shopify-api 2.5.7 → 2.6.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,10 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(git add:*)",
5
+ "Bash(git reset:*)",
6
+ "Bash(git commit:*)",
7
+ "Bash(git push:*)"
8
+ ]
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import { ShopAppOptions } from "../interfaces/ShopAppOptions";
2
+ export declare class ShopAppAPI {
3
+ private readonly options;
4
+ private readonly client;
5
+ constructor(options: ShopAppOptions);
6
+ private _createClient;
7
+ getReviews(): Promise<{
8
+ items: any[];
9
+ }>;
10
+ }
@@ -0,0 +1,62 @@
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.ShopAppAPI = void 0;
13
+ const axios_1 = require("axios");
14
+ const StoreReviews_1 = require("./shop/graphql/StoreReviews");
15
+ class ShopAppAPI {
16
+ constructor(options) {
17
+ this.options = options;
18
+ this.client = this._createClient();
19
+ }
20
+ _createClient() {
21
+ const { cookies } = this.options;
22
+ const url = `https://shop.app`;
23
+ return axios_1.default.create({
24
+ baseURL: url,
25
+ headers: {
26
+ cookie: cookies,
27
+ 'x-user-agent': 'ShopWeb desktop',
28
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36',
29
+ },
30
+ responseType: 'json',
31
+ });
32
+ }
33
+ getReviews() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ var _a, _b;
36
+ const variables = {
37
+ "first": 10,
38
+ "shopId": this.options.shop_id,
39
+ "sortBy": "DATE_DESC"
40
+ };
41
+ const { data } = yield this.client({
42
+ url: '/web/api/graphql',
43
+ method: 'POST',
44
+ headers: {
45
+ 'x-graphql-operation-name': 'StoreReviews',
46
+ },
47
+ data: {
48
+ operationName: 'StoreReviews',
49
+ query: StoreReviews_1.StoreReviewsQuery,
50
+ variables
51
+ }
52
+ });
53
+ const reviewsData = Object.assign({}, (_b = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.shop) === null || _b === void 0 ? void 0 : _b.productReviews);
54
+ const items = reviewsData === null || reviewsData === void 0 ? void 0 : reviewsData.nodes;
55
+ const vItems = Array.isArray(items) ? items : [];
56
+ return {
57
+ items: vItems,
58
+ };
59
+ });
60
+ }
61
+ }
62
+ exports.ShopAppAPI = ShopAppAPI;
@@ -0,0 +1,13 @@
1
+ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/graphql/types";
2
+ import { ActionBuilder } from "../../ActionBuilder";
3
+ import { OptionCreateInput } from "../../../input/OptionCreateInput";
4
+ export interface CreateProductOptionInput extends Record<string, any> {
5
+ productId: string;
6
+ options: OptionCreateInput[];
7
+ variantStrategy?: 'LEAVE_AS_IS' | 'CREATE';
8
+ }
9
+ export interface CreateProductOptionOutput extends Record<string, any> {
10
+ }
11
+ export declare class CreateProductOption extends ActionBuilder<AdminApiClient, CreateProductOptionInput, CreateProductOptionOutput> {
12
+ run(args: CreateProductOptionInput): Promise<CreateProductOptionOutput>;
13
+ }
@@ -0,0 +1,63 @@
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.CreateProductOption = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ const getGlobalID_1 = require("../../../utils/getGlobalID");
15
+ const handleErrors_1 = require("../../../utils/handleErrors");
16
+ class CreateProductOption extends ActionBuilder_1.ActionBuilder {
17
+ run(args) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const query = `
20
+ mutation productOptionsCreate($productId: ID!, $options: [OptionCreateInput!]!, $variantStrategy: ProductOptionCreateVariantStrategy) {
21
+ productOptionsCreate(productId: $productId, options: $options, variantStrategy: $variantStrategy) {
22
+ userErrors {
23
+ field
24
+ message
25
+ code
26
+ }
27
+ product {
28
+ id
29
+ options {
30
+ id
31
+ name
32
+ values
33
+ position
34
+ }
35
+ variants(first: 250) {
36
+ nodes {
37
+ id
38
+ title
39
+ selectedOptions {
40
+ name
41
+ value
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ `;
49
+ const { productId } = Object.assign({}, args);
50
+ const globalId = (0, getGlobalID_1.getGlobalID)(productId);
51
+ const newArgs = Object.assign(Object.assign({}, args), { productId: globalId });
52
+ const result = yield this.client.request(query, {
53
+ variables: newArgs
54
+ });
55
+ const { data, errors } = Object.assign({}, result);
56
+ yield (0, handleErrors_1.handleErrors)(errors);
57
+ const { productOptionsCreate } = Object.assign({}, data);
58
+ const { product: updatedProduct } = Object.assign({}, productOptionsCreate);
59
+ return Object.assign({}, updatedProduct);
60
+ });
61
+ }
62
+ }
63
+ exports.CreateProductOption = CreateProductOption;
@@ -25,6 +25,9 @@ class GetVariants extends ActionBuilder_1.ActionBuilder {
25
25
  variants(first: 250) {
26
26
  nodes {
27
27
  id
28
+ title
29
+ price
30
+ compareAtPrice
28
31
  availableForSale
29
32
  selectedOptions {
30
33
  name
@@ -15,6 +15,7 @@ import { PublishProductInput, PublishProductOutput } from "./PublishProduct";
15
15
  import { NextCreateProductInput, NextCreateProductOutput } from "./NextCreateProduct";
16
16
  import { GetVariantsInput, GetVariantsOutput } from "./GetVariants";
17
17
  import { AppendMediaInput, AppendMediaOutput } from "./AppendMedia";
18
+ import { CreateProductOptionInput, CreateProductOptionOutput } from "./CreateProductOption";
18
19
  export interface AdminProductsAPIInterface {
19
20
  search(args: SearchProductsInput): Promise<SearchProductsOutput>;
20
21
  get(args: GetProductInput): Promise<GetProductOutput>;
@@ -28,6 +29,7 @@ export interface AdminProductsAPIInterface {
28
29
  getMedia(args: GetProductMediaInput): Promise<GetProductMediaOutput>;
29
30
  deleteMedia(args: DeleteProductMediaInput): Promise<DeleteProductMediaOutput>;
30
31
  updateOption(args: UpdateProductOptionInput): Promise<UpdateProductOptionOutput>;
32
+ createOption(args: CreateProductOptionInput): Promise<CreateProductOptionOutput>;
31
33
  reorderMedia(args: ReorderMediaInput): Promise<ReorderMediaOutput>;
32
34
  publish(args: PublishProductInput): Promise<PublishProductOutput>;
33
35
  appendMedia(args: AppendMediaInput): Promise<AppendMediaOutput>;
@@ -46,6 +48,7 @@ export declare class AdminProductsAPI extends APIBase<AdminApiClient> implements
46
48
  getMedia(args: GetProductMediaInput): Promise<GetProductMediaOutput>;
47
49
  deleteMedia(args: DeleteProductMediaInput): Promise<DeleteProductMediaOutput>;
48
50
  updateOption(args: UpdateProductOptionInput): Promise<UpdateProductOptionOutput>;
51
+ createOption(args: CreateProductOptionInput): Promise<CreateProductOptionOutput>;
49
52
  reorderMedia(args: ReorderMediaInput): Promise<ReorderMediaOutput>;
50
53
  publish(args: PublishProductInput): Promise<PublishProductOutput>;
51
54
  appendMedia(args: AppendMediaInput): Promise<AppendMediaOutput>;
@@ -26,6 +26,7 @@ const PublishProduct_1 = require("./PublishProduct");
26
26
  const NextCreateProduct_1 = require("./NextCreateProduct");
27
27
  const GetVariants_1 = require("./GetVariants");
28
28
  const AppendMedia_1 = require("./AppendMedia");
29
+ const CreateProductOption_1 = require("./CreateProductOption");
29
30
  class AdminProductsAPI extends APIBase_1.APIBase {
30
31
  _runAction(Action, args) {
31
32
  return __awaiter(this, void 0, void 0, function* () {
@@ -93,6 +94,11 @@ class AdminProductsAPI extends APIBase_1.APIBase {
93
94
  return this._runAction(UpdateProductOption_1.UpdateProductOption, args);
94
95
  });
95
96
  }
97
+ createOption(args) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return this._runAction(CreateProductOption_1.CreateProductOption, args);
100
+ });
101
+ }
96
102
  reorderMedia(args) {
97
103
  return __awaiter(this, void 0, void 0, function* () {
98
104
  return this._runAction(ReorderMedia_1.ReorderMedia, args);
@@ -0,0 +1 @@
1
+ export declare const StoreReviewsQuery = "\nquery StoreReviews($shopId: ID!, $first: Int!, $after: String, $filter: ShopProductReviewsFilterInput, $sortBy: ProductReviewsSortBy) {\n shop(id: $shopId) {\n id\n name\n websiteUrl\n productReviews(filter: $filter, first: $first, after: $after, sortBy: $sortBy) {\n nodes {\n ...StoreProductReview\n __typename\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n __typename\n }\n __typename\n }\n __typename\n }\n}\n\nfragment StoreProductReview on ProductReview {\n id\n syndicated\n reviewer {\n id\n displayName\n __typename\n }\n title\n body\n rating\n product {\n id\n image {\n ...ReducedImage\n __typename\n }\n title\n variantTitle\n slug\n __typename\n }\n submittedAt\n helpfulnessCount\n markedAsHelpfulByMe\n reportedByMe\n publishedVersion {\n id\n merchantReply\n merchantReplySubmittedAt\n createdAt\n __typename\n }\n discoveryProduct {\n id\n url\n title\n images {\n ...ReducedImage\n __typename\n }\n __typename\n }\n __typename\n}\n\nfragment ReducedImage on Image {\n __typename\n url\n altText\n height\n width\n sensitive\n thumbhash\n}\n";
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StoreReviewsQuery = void 0;
4
+ exports.StoreReviewsQuery = `
5
+ query StoreReviews($shopId: ID!, $first: Int!, $after: String, $filter: ShopProductReviewsFilterInput, $sortBy: ProductReviewsSortBy) {
6
+ shop(id: $shopId) {
7
+ id
8
+ name
9
+ websiteUrl
10
+ productReviews(filter: $filter, first: $first, after: $after, sortBy: $sortBy) {
11
+ nodes {
12
+ ...StoreProductReview
13
+ __typename
14
+ }
15
+ totalCount
16
+ pageInfo {
17
+ hasNextPage
18
+ endCursor
19
+ __typename
20
+ }
21
+ __typename
22
+ }
23
+ __typename
24
+ }
25
+ }
26
+
27
+ fragment StoreProductReview on ProductReview {
28
+ id
29
+ syndicated
30
+ reviewer {
31
+ id
32
+ displayName
33
+ __typename
34
+ }
35
+ title
36
+ body
37
+ rating
38
+ product {
39
+ id
40
+ image {
41
+ ...ReducedImage
42
+ __typename
43
+ }
44
+ title
45
+ variantTitle
46
+ slug
47
+ __typename
48
+ }
49
+ submittedAt
50
+ helpfulnessCount
51
+ markedAsHelpfulByMe
52
+ reportedByMe
53
+ publishedVersion {
54
+ id
55
+ merchantReply
56
+ merchantReplySubmittedAt
57
+ createdAt
58
+ __typename
59
+ }
60
+ discoveryProduct {
61
+ id
62
+ url
63
+ title
64
+ images {
65
+ ...ReducedImage
66
+ __typename
67
+ }
68
+ __typename
69
+ }
70
+ __typename
71
+ }
72
+
73
+ fragment ReducedImage on Image {
74
+ __typename
75
+ url
76
+ altText
77
+ height
78
+ width
79
+ sensitive
80
+ thumbhash
81
+ }
82
+ `;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './classes/StorefrontAPI';
2
2
  export * from './classes/AdminAPI';
3
3
  export * from './classes/RestAPI';
4
+ export * from './classes/ShopAppAPI';
package/dist/index.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./classes/StorefrontAPI"), exports);
18
18
  __exportStar(require("./classes/AdminAPI"), exports);
19
19
  __exportStar(require("./classes/RestAPI"), exports);
20
+ __exportStar(require("./classes/ShopAppAPI"), exports);
@@ -0,0 +1,13 @@
1
+ export interface OptionValueCreateInput extends Record<string, any> {
2
+ name: string;
3
+ linkedMetafieldValue?: string;
4
+ }
5
+ export interface OptionCreateInput extends Record<string, any> {
6
+ name: string;
7
+ position?: number;
8
+ values: Array<OptionValueCreateInput>;
9
+ linkedMetafield?: {
10
+ namespace: string;
11
+ key: string;
12
+ };
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export interface ShopAppOptions extends Record<string, any> {
2
+ shop_id: string;
3
+ cookies: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "2.5.7",
3
+ "version": "2.6.0",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
- "scripts": {},
7
+ "scripts": {
8
+ "dev": "nodemon"
9
+ },
8
10
  "keywords": [],
9
11
  "author": "",
10
12
  "license": "ISC",
@@ -12,12 +14,13 @@
12
14
  "@types/bluebird": "^3.5.42",
13
15
  "@types/node": "^20",
14
16
  "bluebird": "^3.7.2",
15
- "dotenv": "^16.3.1"
17
+ "dotenv": "^16.3.1",
18
+ "typescript": "^5"
16
19
  },
17
20
  "dependencies": {
18
21
  "@shopify/admin-api-client": "^1.0.0",
19
22
  "@shopify/storefront-api-client": "^1.0.0",
20
- "axios": "^1.13.2",
23
+ "axios": "^1.13.5",
21
24
  "p-map": "^4"
22
25
  }
23
26
  }