@pronto-tools-and-more/pronto 12.24.0 → 12.26.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,34 +1,35 @@
1
1
  import * as GraphQlQueryIssues from "../GraphQlQueryIssues/GraphQlQueryIssues.js";
2
2
 
3
- export const handleIssues = (appId) => async (req, res, next) => {
4
- const url = `https://catalog.purplemanager.com/graphql`;
5
- const realBottom = {
6
- ...GraphQlQueryIssues.bottom,
7
- appInfo: {
8
- ...GraphQlQueryIssues.bottom.appInfo,
9
- appId,
10
- },
11
- };
12
- const response = await fetch(url, {
13
- method: "POST",
14
- headers: {
15
- Accept: "application/json",
16
- "Content-Type": "application/json",
17
- },
18
- body: JSON.stringify({
19
- operationName: "CatalogContentsQuery",
20
- query: GraphQlQueryIssues.top,
21
- variables: realBottom,
22
- }),
23
- });
24
- const result = await response.json();
25
- // @ts-ignore
26
- const realData = result.data.catalog.contentsConnection.edges
27
- .map((edge) => edge.content)
28
- .map((node) => {
29
- const { __typename, ...rest } = node;
30
- return rest;
3
+ export const handleIssues =
4
+ ({ appId, apiUrl }) =>
5
+ async (req, res, next) => {
6
+ const realBottom = {
7
+ ...GraphQlQueryIssues.bottom,
8
+ appInfo: {
9
+ ...GraphQlQueryIssues.bottom.appInfo,
10
+ appId,
11
+ },
12
+ };
13
+ const response = await fetch(apiUrl, {
14
+ method: "POST",
15
+ headers: {
16
+ Accept: "application/json",
17
+ "Content-Type": "application/json",
18
+ },
19
+ body: JSON.stringify({
20
+ operationName: "CatalogContentsQuery",
21
+ query: GraphQlQueryIssues.top,
22
+ variables: realBottom,
23
+ }),
31
24
  });
32
- res.setHeader("content-type", "application/json");
33
- res.send(JSON.stringify(realData, null, 2));
34
- };
25
+ const result = await response.json();
26
+ // @ts-ignore
27
+ const realData = result.data.catalog.contentsConnection.edges
28
+ .map((edge) => edge.content)
29
+ .map((node) => {
30
+ const { __typename, ...rest } = node;
31
+ return rest;
32
+ });
33
+ res.setHeader("content-type", "application/json");
34
+ res.send(JSON.stringify(realData, null, 2));
35
+ };
@@ -0,0 +1,54 @@
1
+ import * as GraphQlQueryContent from "../GraphQlQueryContent/GraphQlQueryContent.js";
2
+
3
+ const getContent = async ({ appId, apiUrl, postId }) => {
4
+ const realBottom = {
5
+ ...GraphQlQueryContent.bottom,
6
+ appInfo: {
7
+ ...GraphQlQueryContent.bottom.appInfo,
8
+ appId,
9
+ },
10
+ filter: {
11
+ id: {
12
+ value: postId,
13
+ },
14
+ },
15
+ };
16
+ const response = await fetch(apiUrl, {
17
+ method: "POST",
18
+ headers: {
19
+ Accept: "application/json",
20
+ "Content-Type": "application/json",
21
+ },
22
+ body: JSON.stringify({
23
+ operationName: GraphQlQueryContent.queryName,
24
+ query: GraphQlQueryContent.top,
25
+ variables: realBottom,
26
+ }),
27
+ });
28
+ const result = await response.json();
29
+ // @ts-ignore
30
+ if (result && result.error) {
31
+ // @ts-ignore
32
+ throw new Error(`api error: ${result.error}`);
33
+ }
34
+ // @ts-ignore
35
+ const realData = result.data.catalog.contentsConnection.edges
36
+ .map((edge) => edge.content)
37
+ .map((match) => {
38
+ const { __typename, ...rest } = match;
39
+ return rest;
40
+ });
41
+ return realData;
42
+ };
43
+
44
+ export const handleApiPostByName = async ({ postIds, res, appId, apiUrl }) => {
45
+ if (postIds.length === 0) {
46
+ res.setHeader("content-type", "application/json");
47
+ res.end(JSON.stringify("Not found", null, 2));
48
+ return;
49
+ }
50
+ const postId = postIds[0];
51
+ const content = await getContent({ appId, apiUrl, postId });
52
+ res.setHeader("content-type", "application/json");
53
+ res.end(JSON.stringify(content, null, 2));
54
+ };
@@ -1 +1 @@
1
- export const version = '12.24.0'
1
+ export const version = '12.26.0'