@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,100 +1,30 @@
1
- import * as GraphQlQueryPathSegments from "../GraphQlQueryPathSegments/GraphQlQueryPathSegments.js";
2
- import * as GraphQlQueryContent from "../GraphQlQueryContent/GraphQlQueryContent.js";
1
+ import * as GetPostIds from "../GetPostIds/GetPostIds.js";
2
+ import * as HandleApiPostByName from "../HandleApiPostByName/HandleApiPostByName.js";
3
+ import * as HandleApiArticleByCategoryId from "../HandleApiArticleByCategoryId/HandleApiArticleByCategoryId.js";
3
4
 
4
- const getPostIds = async (appId, slug) => {
5
- const url = `https://catalog.purplemanager.com/graphql`;
6
- const realBottom = {
7
- ...GraphQlQueryPathSegments.bottom,
8
- appInfo: {
9
- ...GraphQlQueryPathSegments.bottom.appInfo,
5
+ export const handleApiArticle =
6
+ ({ appId, apiUrl }) =>
7
+ async (req, res, next) => {
8
+ const articleSlug = req.url.slice("/articles/".length);
9
+ const url = new URL(req.url, "https://example.com");
10
+ const categoryId = url.searchParams.get("categoryId");
11
+ if (categoryId) {
12
+ return HandleApiArticleByCategoryId.handleApiArticleByCategoryId({
13
+ apiUrl,
14
+ appId,
15
+ categoryId,
16
+ res,
17
+ });
18
+ }
19
+ const postIds = await GetPostIds.getPostIds({
10
20
  appId,
11
- },
12
- pathSegments: [slug],
13
- };
14
- const response = await fetch(url, {
15
- method: "POST",
16
- headers: {
17
- Accept: "application/json",
18
- "Content-Type": "application/json",
19
- },
20
- body: JSON.stringify({
21
- operationName: GraphQlQueryPathSegments.queryName,
22
- query: GraphQlQueryPathSegments.top,
23
- variables: realBottom,
24
- }),
25
- });
26
- const result = await response.json();
27
- // @ts-ignore
28
- if (result && result.error) {
29
- // @ts-ignore
30
- throw new Error(`api error: ${result.error}`);
31
- }
32
- // @ts-ignore
33
- const realData = result.data.catalog.lookupPathSegments
34
- .flatMap((item) => item.matches)
35
- .map((match) => {
36
- const { __typename, ...rest } = match;
37
- return rest;
38
- })
39
- .map((match) => {
40
- return match.id;
21
+ apiUrl,
22
+ slug: articleSlug,
41
23
  });
42
- return realData;
43
- };
44
-
45
- const getContent = async (appId, postId) => {
46
- const url = `https://catalog.purplemanager.com/graphql`;
47
- const realBottom = {
48
- ...GraphQlQueryContent.bottom,
49
- appInfo: {
50
- ...GraphQlQueryContent.bottom.appInfo,
24
+ return HandleApiPostByName.handleApiPostByName({
25
+ apiUrl,
51
26
  appId,
52
- },
53
- filter: {
54
- id: {
55
- value: postId,
56
- },
57
- },
58
- };
59
- const response = await fetch(url, {
60
- method: "POST",
61
- headers: {
62
- Accept: "application/json",
63
- "Content-Type": "application/json",
64
- },
65
- body: JSON.stringify({
66
- operationName: GraphQlQueryContent.queryName,
67
- query: GraphQlQueryContent.top,
68
- variables: realBottom,
69
- }),
70
- });
71
- const result = await response.json();
72
- // @ts-ignore
73
- if (result && result.error) {
74
- // @ts-ignore
75
- throw new Error(`api error: ${result.error}`);
76
- }
77
- // @ts-ignore
78
- const realData = result.data.catalog.contentsConnection.edges
79
- .map((edge) => edge.content)
80
- .map((match) => {
81
- const { __typename, ...rest } = match;
82
- return rest;
27
+ postIds,
28
+ res,
83
29
  });
84
- return realData;
85
- };
86
-
87
- export const handleApiArticle = (appId) => async (req, res, next) => {
88
- const articleSlug = req.url.slice("/articles/".length);
89
- console.log({ articleSlug });
90
- const postIds = await getPostIds(appId, articleSlug);
91
- if (postIds.length === 0) {
92
- res.setHeader("content-type", "application/json");
93
- res.end(JSON.stringify("Not found", null, 2));
94
- return;
95
- }
96
- const postId = postIds[0];
97
- const content = await getContent(appId, postId);
98
- res.setHeader("content-type", "application/json");
99
- res.end(JSON.stringify(content, null, 2));
100
- };
30
+ };
@@ -0,0 +1,93 @@
1
+ import * as GraphQlQueryContent from "../GraphQlQueryContent/GraphQlQueryContent.js";
2
+
3
+ const getContent = async ({ appId, apiUrl, categoryId }) => {
4
+ const realBottom = {
5
+ ...GraphQlQueryContent.bottom,
6
+ appInfo: {
7
+ ...GraphQlQueryContent.bottom.appInfo,
8
+ appId,
9
+ },
10
+ filter: {
11
+ AND: [
12
+ {
13
+ contentType: {
14
+ value: "POST",
15
+ },
16
+ },
17
+ {
18
+ postType: {
19
+ value: "post",
20
+ },
21
+ },
22
+ {
23
+ taxonomies: {
24
+ content: {
25
+ value: {
26
+ AND: [
27
+ {
28
+ type: {
29
+ value: "category",
30
+ },
31
+ },
32
+ {
33
+ OR: [
34
+ {
35
+ id: {
36
+ value: categoryId,
37
+ },
38
+ },
39
+ ],
40
+ },
41
+ ],
42
+ },
43
+ },
44
+ },
45
+ },
46
+ {
47
+ id: {
48
+ value: "^()$",
49
+ operation: "REGEX",
50
+ negated: true,
51
+ },
52
+ },
53
+ ],
54
+ },
55
+ };
56
+ const response = await fetch(apiUrl, {
57
+ method: "POST",
58
+ headers: {
59
+ Accept: "application/json",
60
+ "Content-Type": "application/json",
61
+ },
62
+ body: JSON.stringify({
63
+ operationName: GraphQlQueryContent.queryName,
64
+ query: GraphQlQueryContent.top,
65
+ variables: realBottom,
66
+ }),
67
+ });
68
+ const result = await response.json();
69
+ // @ts-ignore
70
+ if (result && result.error) {
71
+ // @ts-ignore
72
+ throw new Error(`api error: ${result.error}`);
73
+ }
74
+ // @ts-ignore
75
+ const realData = result.data.catalog.contentsConnection.edges
76
+ .map((edge) => edge.content)
77
+ .map((match) => {
78
+ const { __typename, ...rest } = match;
79
+ return rest;
80
+ });
81
+ return realData;
82
+ };
83
+
84
+ export const handleApiArticleByCategoryId = async ({
85
+ appId,
86
+ apiUrl,
87
+ categoryId,
88
+ res,
89
+ }) => {
90
+ const content = await getContent({ appId, apiUrl, categoryId });
91
+ res.setHeader("content-type", "application/json");
92
+ res.end(JSON.stringify(content, null, 2));
93
+ };
@@ -1,34 +1,35 @@
1
1
  import * as GraphQlQueryAuthors from "../GraphQlQueryAuthors/GraphQlQueryAuthors.js";
2
2
 
3
- export const handleAuthors = (appId) => async (req, res, next) => {
4
- const url = `https://catalog.purplemanager.com/graphql`;
5
- const realBottom = {
6
- ...GraphQlQueryAuthors.bottom,
7
- appInfo: {
8
- ...GraphQlQueryAuthors.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: GraphQlQueryAuthors.top,
21
- variables: realBottom,
22
- }),
23
- });
24
- const result = await response.json();
25
- // @ts-ignore
26
- const realData = result.data.catalog.taxonomiesConnection.edges
27
- .map((edge) => edge.node)
28
- .map((node) => {
29
- const { __typename, ...rest } = node;
30
- return rest;
3
+ export const handleAuthors =
4
+ ({ appId, apiUrl }) =>
5
+ async (req, res, next) => {
6
+ const realBottom = {
7
+ ...GraphQlQueryAuthors.bottom,
8
+ appInfo: {
9
+ ...GraphQlQueryAuthors.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: GraphQlQueryAuthors.top,
22
+ variables: realBottom,
23
+ }),
31
24
  });
32
- res.setHeader("content-type", "application/json");
33
- res.end(JSON.stringify(realData, null, 2));
34
- };
25
+ const result = await response.json();
26
+ // @ts-ignore
27
+ const realData = result.data.catalog.taxonomiesConnection.edges
28
+ .map((edge) => edge.node)
29
+ .map((node) => {
30
+ const { __typename, ...rest } = node;
31
+ return rest;
32
+ });
33
+ res.setHeader("content-type", "application/json");
34
+ res.end(JSON.stringify(realData, null, 2));
35
+ };
@@ -1,34 +1,35 @@
1
1
  import * as GraphQlQueryCategories from "../GraphQlQueryCategories/GraphQlQueryCategories.js";
2
2
 
3
- export const handleCategories = (appId) => async (req, res, next) => {
4
- const url = `https://catalog.purplemanager.com/graphql`;
5
- const realBottom = {
6
- ...GraphQlQueryCategories.bottom,
7
- appInfo: {
8
- ...GraphQlQueryCategories.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: GraphQlQueryCategories.top,
21
- variables: realBottom,
22
- }),
23
- });
24
- const result = await response.json();
25
- // @ts-ignore
26
- const realData = result.data.catalog.taxonomiesConnection.edges
27
- .map((edge) => edge.node)
28
- .map((node) => {
29
- const { __typename, ...rest } = node;
30
- return rest;
3
+ export const handleCategories =
4
+ ({ appId, apiUrl }) =>
5
+ async (req, res, next) => {
6
+ const realBottom = {
7
+ ...GraphQlQueryCategories.bottom,
8
+ appInfo: {
9
+ ...GraphQlQueryCategories.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: GraphQlQueryCategories.top,
22
+ variables: realBottom,
23
+ }),
31
24
  });
32
- res.setHeader("content-type", "application/json");
33
- res.end(JSON.stringify(realData, null, 2));
34
- };
25
+ const result = await response.json();
26
+ // @ts-ignore
27
+ const realData = result.data.catalog.taxonomiesConnection.edges
28
+ .map((edge) => edge.node)
29
+ .map((node) => {
30
+ const { __typename, ...rest } = node;
31
+ return rest;
32
+ });
33
+ res.setHeader("content-type", "application/json");
34
+ res.end(JSON.stringify(realData, null, 2));
35
+ };
@@ -0,0 +1,59 @@
1
+ import * as GraphQlQueryCollection from "../GraphQlQueryCollection/GraphQlQueryCollection.js";
2
+
3
+ const getCollections = async ({ appId, apiUrl, name }) => {
4
+ const realBottom = {
5
+ ...GraphQlQueryCollection.bottom,
6
+ appInfo: {
7
+ ...GraphQlQueryCollection.bottom.appInfo,
8
+ appId,
9
+ },
10
+ filter: {
11
+ name: {
12
+ value: name,
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: GraphQlQueryCollection.queryName,
24
+ query: GraphQlQueryCollection.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
+ if (result && result.errors) {
36
+ // @ts-ignore
37
+ throw new Error(`api error: ${result.errors[0].message}`);
38
+ }
39
+ console.log({ result });
40
+ // @ts-ignore
41
+ const realData = result.data.catalog.collectionsConnection.edges
42
+ .map((edge) => {
43
+ return edge.node;
44
+ })
45
+ .map((match) => {
46
+ const { __typename, ...rest } = match;
47
+ return rest;
48
+ });
49
+ return realData;
50
+ };
51
+
52
+ export const handleApiCollection =
53
+ ({ appId, apiUrl }) =>
54
+ async (req, res, next) => {
55
+ const name = req.url.slice("/collections/".length);
56
+ const content = await getCollections({ appId, apiUrl, name });
57
+ res.setHeader("content-type", "application/json");
58
+ res.end(JSON.stringify(content, null, 2));
59
+ };
@@ -0,0 +1,49 @@
1
+ import * as GraphQlQueryCollections from "../GraphQlQueryCollections/GraphQlQueryCollections.js";
2
+
3
+ const getCollections = async ({ appId, apiUrl }) => {
4
+ const realBottom = {
5
+ ...GraphQlQueryCollections.bottom,
6
+ appInfo: {
7
+ ...GraphQlQueryCollections.bottom.appInfo,
8
+ appId,
9
+ },
10
+ filter: {},
11
+ };
12
+ const response = await fetch(apiUrl, {
13
+ method: "POST",
14
+ headers: {
15
+ Accept: "application/json",
16
+ "Content-Type": "application/json",
17
+ },
18
+ body: JSON.stringify({
19
+ operationName: GraphQlQueryCollections.queryName,
20
+ query: GraphQlQueryCollections.top,
21
+ variables: realBottom,
22
+ }),
23
+ });
24
+ const result = await response.json();
25
+ // @ts-ignore
26
+ if (result && result.error) {
27
+ // @ts-ignore
28
+ throw new Error(`api error: ${result.error}`);
29
+ }
30
+ // @ts-ignore
31
+ const realData = result.data.catalog.collectionsConnection.edges
32
+ .map((edge) => {
33
+ return edge.node;
34
+ })
35
+ .map((match) => {
36
+ const { __typename, ...rest } = match;
37
+ return rest;
38
+ });
39
+ return realData;
40
+ };
41
+
42
+ export const handleApiCollections =
43
+ ({ appId, apiUrl }) =>
44
+ async (req, res, next) => {
45
+ const content = await getCollections({ appId, apiUrl });
46
+ console.log({ content });
47
+ res.setHeader("content-type", "application/json");
48
+ res.end(JSON.stringify(content, null, 2));
49
+ };
@@ -36,68 +36,69 @@ const getBundleId = async ({ appId, reqUrl }) => {
36
36
  return id;
37
37
  };
38
38
 
39
- export const handleDossier = (appId) => async (req, res, next) => {
40
- const bundleId = await getBundleId({
41
- appId,
42
- reqUrl: req.url,
43
- });
44
- if (!bundleId) {
45
- res.statusCode = 404;
46
- res.end("Not found");
47
- return;
48
- }
49
- const url = `https://catalog.purplemanager.com/graphql`;
50
- const realBottom = {
51
- ...GraphQlQueryDossier.bottom1,
52
- appInfo: {
53
- ...GraphQlQueryDossier.bottom1.appInfo,
39
+ export const handleDossier =
40
+ ({ appId, apiUrl }) =>
41
+ async (req, res, next) => {
42
+ const bundleId = await getBundleId({
54
43
  appId,
55
- },
56
- filter: {
57
- AND: [
58
- {
59
- postType: {
60
- value: "post",
44
+ reqUrl: req.url,
45
+ });
46
+ if (!bundleId) {
47
+ res.statusCode = 404;
48
+ res.end("Not found");
49
+ return;
50
+ }
51
+ const realBottom = {
52
+ ...GraphQlQueryDossier.bottom1,
53
+ appInfo: {
54
+ ...GraphQlQueryDossier.bottom1.appInfo,
55
+ appId,
56
+ },
57
+ filter: {
58
+ AND: [
59
+ {
60
+ postType: {
61
+ value: "post",
62
+ },
61
63
  },
62
- },
63
- {
64
- contentType: {
65
- value: "POST",
64
+ {
65
+ contentType: {
66
+ value: "POST",
67
+ },
66
68
  },
67
- },
68
- {
69
- AND: [
70
- {
71
- bundleId: {
72
- value: bundleId,
69
+ {
70
+ AND: [
71
+ {
72
+ bundleId: {
73
+ value: bundleId,
74
+ },
73
75
  },
74
- },
75
- ],
76
- },
77
- ],
78
- },
79
- };
80
- const response = await fetch(url, {
81
- method: "POST",
82
- headers: {
83
- Accept: "application/json",
84
- "Content-Type": "application/json",
85
- },
86
- body: JSON.stringify({
87
- operationName: "CatalogContentsQuery",
88
- query: GraphQlQueryDossier.top1,
89
- variables: realBottom,
90
- }),
91
- });
92
- const result = await response.json();
93
- // @ts-ignore
94
- const realData = result.data.catalog.contentsConnection.edges
95
- .map((edge) => edge.content)
96
- .map((node) => {
97
- const { __typename, ...rest } = node;
98
- return rest;
76
+ ],
77
+ },
78
+ ],
79
+ },
80
+ };
81
+ const response = await fetch(apiUrl, {
82
+ method: "POST",
83
+ headers: {
84
+ Accept: "application/json",
85
+ "Content-Type": "application/json",
86
+ },
87
+ body: JSON.stringify({
88
+ operationName: "CatalogContentsQuery",
89
+ query: GraphQlQueryDossier.top1,
90
+ variables: realBottom,
91
+ }),
99
92
  });
93
+ const result = await response.json();
94
+ // @ts-ignore
95
+ const realData = result.data.catalog.contentsConnection.edges
96
+ .map((edge) => edge.content)
97
+ .map((node) => {
98
+ const { __typename, ...rest } = node;
99
+ return rest;
100
+ });
100
101
 
101
- res.setHeader("content-type", "application/json");
102
- res.send(JSON.stringify(realData, null, 2));
103
- };
102
+ res.setHeader("content-type", "application/json");
103
+ res.send(JSON.stringify(realData, null, 2));
104
+ };
@@ -1,35 +1,36 @@
1
1
  import * as GraphQlQueryDossiers from "../GraphQlQueryDossiers/GraphQlQueryDossiers.js";
2
2
 
3
- export const handleDossiers = (appId) => async (req, res, next) => {
4
- const url = `https://catalog.purplemanager.com/graphql`;
5
- const realBottom = {
6
- ...GraphQlQueryDossiers.bottom,
7
- appInfo: {
8
- ...GraphQlQueryDossiers.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: GraphQlQueryDossiers.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 handleDossiers =
4
+ ({ appId, apiUrl }) =>
5
+ async (req, res, next) => {
6
+ const realBottom = {
7
+ ...GraphQlQueryDossiers.bottom,
8
+ appInfo: {
9
+ ...GraphQlQueryDossiers.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: GraphQlQueryDossiers.top,
22
+ variables: realBottom,
23
+ }),
31
24
  });
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
+ });
32
33
 
33
- res.setHeader("content-type", "application/json");
34
- res.send(JSON.stringify(realData, null, 2));
35
- };
34
+ res.setHeader("content-type", "application/json");
35
+ res.send(JSON.stringify(realData, null, 2));
36
+ };
@@ -13,6 +13,7 @@ export const handleIndex = async (req, res, next) => {
13
13
  <li><a href="/api/categories">Categories</a></li>
14
14
  <li><a href="/api/articles">Articles</a></li>
15
15
  <li><a href="/api/authors">Authors</a></li>
16
+ <li><a href="/api/collections">Collections</a></li>
16
17
  </ul>
17
18
  </body>
18
19
  </html>