@pintahub/shopify-api 1.7.5 → 1.7.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,10 @@
1
+ import { AdminApiClient } from "@shopify/admin-api-client/dist/ts/graphql/types";
2
+ import { ActionBuilder } from "../../ActionBuilder";
3
+ export interface GetListFAQsInput extends Record<string, any> {
4
+ }
5
+ export interface GetListFAQsOutput extends Record<string, any> {
6
+ items: any[];
7
+ }
8
+ export declare class GetListFAQs extends ActionBuilder<AdminApiClient, GetListFAQsInput, GetListFAQsOutput> {
9
+ run(args?: GetListFAQsInput): Promise<GetListFAQsOutput>;
10
+ }
@@ -0,0 +1,45 @@
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.GetListFAQs = void 0;
13
+ const ActionBuilder_1 = require("../../ActionBuilder");
14
+ const _parseFAQs_1 = require("./faqs/_parseFAQs");
15
+ class GetListFAQs extends ActionBuilder_1.ActionBuilder {
16
+ run(args) {
17
+ var _a;
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const query = `
20
+ {
21
+ metaobjects(type: "faq", first: 100) {
22
+ nodes {
23
+ id
24
+ type
25
+ handle
26
+ updatedAt
27
+ fields {
28
+ key
29
+ value
30
+ type
31
+ }
32
+ }
33
+ }
34
+ }
35
+ `;
36
+ const { data } = yield this.client.request(query);
37
+ const pages = (_a = data === null || data === void 0 ? void 0 : data.metaobjects) === null || _a === void 0 ? void 0 : _a.nodes;
38
+ const vPages = yield (0, _parseFAQs_1._parseFAQs)(pages);
39
+ return {
40
+ items: vPages
41
+ };
42
+ });
43
+ }
44
+ }
45
+ exports.GetListFAQs = GetListFAQs;
@@ -0,0 +1 @@
1
+ export declare const _parseContentObjToHTML: (content: string, type: string) => Promise<string>;
@@ -0,0 +1,23 @@
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._parseContentObjToHTML = void 0;
13
+ const richText_1 = require("../../../../utils/richText");
14
+ const _parseContentObjToHTML = (content, type) => __awaiter(void 0, void 0, void 0, function* () {
15
+ if (type === 'single_line_text_field') {
16
+ return `<p>${content}</p>`;
17
+ }
18
+ if (type !== 'rich_text_field')
19
+ return content;
20
+ const html = (0, richText_1.convertSchemaToHtml)(content);
21
+ return `<div>${html}</div>`;
22
+ });
23
+ exports._parseContentObjToHTML = _parseContentObjToHTML;
@@ -0,0 +1 @@
1
+ export declare const _parseFAQs: (pages?: never[]) => Promise<any>;
@@ -0,0 +1,51 @@
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._parseFAQs = void 0;
24
+ const _parseContentObjToHTML_1 = require("./_parseContentObjToHTML");
25
+ const pMap = require('p-map');
26
+ const _parsePage = (page) => __awaiter(void 0, void 0, void 0, function* () {
27
+ const { fields } = page, rest = __rest(page, ["fields"]);
28
+ if (!fields || !fields.length)
29
+ return false;
30
+ const obj = fields.reduce((acc, field) => {
31
+ const { key } = field;
32
+ acc[key] = field;
33
+ return acc;
34
+ }, {});
35
+ const { title, content } = Object.assign({}, obj);
36
+ const { value: vTitle } = Object.assign({}, title);
37
+ if (!vTitle)
38
+ return false;
39
+ const { value: vContent, type } = Object.assign({}, content);
40
+ const body = yield (0, _parseContentObjToHTML_1._parseContentObjToHTML)(vContent, type);
41
+ return Object.assign(Object.assign({}, rest), { title: vTitle, body });
42
+ });
43
+ const _parseFAQs = (pages = []) => __awaiter(void 0, void 0, void 0, function* () {
44
+ if (!pages || !pages.length)
45
+ return [];
46
+ const vPages = yield pMap(pages, (page) => __awaiter(void 0, void 0, void 0, function* () {
47
+ return _parsePage(page);
48
+ }), { concurrency: 10 });
49
+ return vPages.filter(Boolean);
50
+ });
51
+ exports._parseFAQs = _parseFAQs;
@@ -3,14 +3,17 @@ import { APIBase } from "../../APIBase";
3
3
  import { SearchMetaObjectsInput, SearchMetaObjectsOutput } from "./SearchMetaObjects";
4
4
  import { GetMetaObjectInput, GetMetaObjectOutput } from "./GetMetaObject";
5
5
  import { GetListBannersInput, GetListBannersOutput } from "./GetListBanners";
6
+ import { GetListFAQsInput, GetListFAQsOutput } from "./GetListFAQs";
6
7
  export interface AdminMetaObjectAPIInterface {
7
8
  get(args: GetMetaObjectInput): Promise<GetMetaObjectOutput>;
8
9
  search(args: SearchMetaObjectsInput): Promise<SearchMetaObjectsOutput>;
9
10
  listBanners(args: GetListBannersInput): Promise<GetListBannersOutput>;
11
+ listFAQs(args: GetListFAQsInput): Promise<GetListFAQsOutput>;
10
12
  }
11
13
  export declare class AdminMetaObjectAPI extends APIBase<AdminApiClient> implements AdminMetaObjectAPIInterface {
12
14
  private _runAction;
13
15
  get(args: GetMetaObjectInput): Promise<GetMetaObjectOutput>;
14
16
  search(args: SearchMetaObjectsInput): Promise<SearchMetaObjectsOutput>;
15
17
  listBanners(args: GetListBannersInput): Promise<GetListBannersOutput>;
18
+ listFAQs(args: GetListFAQsInput): Promise<GetListFAQsOutput>;
16
19
  }
@@ -14,6 +14,7 @@ const APIBase_1 = require("../../APIBase");
14
14
  const SearchMetaObjects_1 = require("./SearchMetaObjects");
15
15
  const GetMetaObject_1 = require("./GetMetaObject");
16
16
  const GetListBanners_1 = require("./GetListBanners");
17
+ const GetListFAQs_1 = require("./GetListFAQs");
17
18
  class AdminMetaObjectAPI extends APIBase_1.APIBase {
18
19
  _runAction(Action, args) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
@@ -36,5 +37,10 @@ class AdminMetaObjectAPI extends APIBase_1.APIBase {
36
37
  return this._runAction(GetListBanners_1.GetListBanners, args);
37
38
  });
38
39
  }
40
+ listFAQs(args) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ return this._runAction(GetListFAQs_1.GetListFAQs, args);
43
+ });
44
+ }
39
45
  }
40
46
  exports.AdminMetaObjectAPI = AdminMetaObjectAPI;
@@ -0,0 +1 @@
1
+ export declare const convertSchemaToHtml: (schema: any, scoped?: boolean) => string;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertSchemaToHtml = void 0;
4
+ const convertSchemaToHtml = (schema, scoped = false) => {
5
+ if (typeof schema === 'string') {
6
+ schema = JSON.parse(schema);
7
+ }
8
+ let html = ``;
9
+ if (schema.type === 'root' && schema.children.length > 0) {
10
+ if (scoped) {
11
+ html += `
12
+ <div class="${scoped === true ? `rte` : scoped}">
13
+ ${(0, exports.convertSchemaToHtml)(schema.children)}
14
+ </div>
15
+ `;
16
+ }
17
+ else {
18
+ html += (0, exports.convertSchemaToHtml)(schema.children);
19
+ }
20
+ }
21
+ else {
22
+ for (const el of schema) {
23
+ switch (el.type) {
24
+ case 'paragraph':
25
+ html += buildParagraph(el);
26
+ break;
27
+ case 'heading':
28
+ html += buildHeading(el);
29
+ break;
30
+ case 'list':
31
+ html += buildList(el);
32
+ break;
33
+ case 'list-item':
34
+ html += buildListItem(el);
35
+ break;
36
+ case 'link':
37
+ html += buildLink(el);
38
+ break;
39
+ case 'text':
40
+ html += buildText(el);
41
+ break;
42
+ default:
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ return html;
48
+ };
49
+ exports.convertSchemaToHtml = convertSchemaToHtml;
50
+ function buildParagraph(el) {
51
+ if (el === null || el === void 0 ? void 0 : el.children) {
52
+ return `<p>${(0, exports.convertSchemaToHtml)(el === null || el === void 0 ? void 0 : el.children)}</p>`;
53
+ }
54
+ }
55
+ function buildHeading(el) {
56
+ if (el === null || el === void 0 ? void 0 : el.children) {
57
+ return `<h${el === null || el === void 0 ? void 0 : el.level}>${(0, exports.convertSchemaToHtml)(el === null || el === void 0 ? void 0 : el.children)}</h${el === null || el === void 0 ? void 0 : el.level}>`;
58
+ }
59
+ }
60
+ function buildList(el) {
61
+ if (el === null || el === void 0 ? void 0 : el.children) {
62
+ if ((el === null || el === void 0 ? void 0 : el.listType) === 'ordered') {
63
+ return `<ol>${(0, exports.convertSchemaToHtml)(el === null || el === void 0 ? void 0 : el.children)}</ol>`;
64
+ }
65
+ else {
66
+ return `<ul>${(0, exports.convertSchemaToHtml)(el === null || el === void 0 ? void 0 : el.children)}</ul>`;
67
+ }
68
+ }
69
+ }
70
+ function buildListItem(el) {
71
+ if (el === null || el === void 0 ? void 0 : el.children) {
72
+ return `<li>${(0, exports.convertSchemaToHtml)(el === null || el === void 0 ? void 0 : el.children)}</li>`;
73
+ }
74
+ }
75
+ function buildLink(el) {
76
+ return `<a href="${el === null || el === void 0 ? void 0 : el.url}" title="${el === null || el === void 0 ? void 0 : el.title}" target="${el === null || el === void 0 ? void 0 : el.target}">${(0, exports.convertSchemaToHtml)(el === null || el === void 0 ? void 0 : el.children)}</a>`;
77
+ }
78
+ function buildText(el) {
79
+ const { value } = el;
80
+ const withBreaks = (value || '').replace(/\n/g, '<br/>');
81
+ if (el === null || el === void 0 ? void 0 : el.bold) {
82
+ return `<strong>${withBreaks}</strong>`;
83
+ }
84
+ if (el === null || el === void 0 ? void 0 : el.italic) {
85
+ return `<em>${withBreaks}</em>`;
86
+ }
87
+ return withBreaks;
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "1.7.5",
3
+ "version": "1.7.8",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -9,12 +9,14 @@
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "devDependencies": {
12
+ "@types/bluebird": "^3.5.42",
12
13
  "@types/node": "^20.10.4",
13
14
  "dotenv": "^16.3.1"
14
15
  },
15
16
  "dependencies": {
16
17
  "@shopify/admin-api-client": "^1.0.0",
17
18
  "@shopify/storefront-api-client": "^1.0.0",
18
- "axios": "^1.7.2"
19
+ "axios": "^1.7.2",
20
+ "p-map": "^4"
19
21
  }
20
22
  }