@pronto-tools-and-more/api 12.35.1
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.
- package/package.json +22 -0
- package/src/main.js +3 -0
- package/src/parts/Callback/Callback.js +1 -0
- package/src/parts/Command/Command.js +9 -0
- package/src/parts/CommandMap/CommandMap.js +5 -0
- package/src/parts/CommandState/CommandState.js +17 -0
- package/src/parts/ErrorCodes/ErrorCodes.js +2 -0
- package/src/parts/GetPostIds/GetPostIds.js +41 -0
- package/src/parts/GraphQlQueryAppSettings/GraphQlQueryAppSettings.js +42 -0
- package/src/parts/GraphQlQueryAuthors/GraphQlQueryAuthors.js +66 -0
- package/src/parts/GraphQlQueryCategories/GraphQlQueryCategories.js +66 -0
- package/src/parts/GraphQlQueryCollection/GraphQlQueryCollection.js +227 -0
- package/src/parts/GraphQlQueryCollections/GraphQlQueryCollections.js +227 -0
- package/src/parts/GraphQlQueryContent/GraphQlQueryContent.js +198 -0
- package/src/parts/GraphQlQueryDossier/GraphQlQueryDossier.js +221 -0
- package/src/parts/GraphQlQueryDossiers/GraphQlQueryDossiers.js +201 -0
- package/src/parts/GraphQlQueryIssues/GraphQlQueryIssues.js +202 -0
- package/src/parts/GraphQlQueryMenus/GraphQlQueryMenus.js +77 -0
- package/src/parts/GraphQlQueryPathSegment/GraphQlQueryPathSegment.js +57 -0
- package/src/parts/GraphQlQueryPathSegments/GraphQlQueryPathSegments.js +59 -0
- package/src/parts/GraphQlQueryTaxonomies/GraphQlQueryTaxonomies.js +66 -0
- package/src/parts/HandleApi/HandleApi.js +52 -0
- package/src/parts/HandleApiAppSettings/HandleApiAppSettings.js +41 -0
- package/src/parts/HandleApiArticle/HandleApiArticle.js +26 -0
- package/src/parts/HandleApiArticleByCategoryId/HandleApiArticleByCategoryId.js +97 -0
- package/src/parts/HandleApiAuthors/HandleApiAuthors.js +38 -0
- package/src/parts/HandleApiCategories/HandleApiCategories.js +38 -0
- package/src/parts/HandleApiCollection/HandleApiCollection.js +62 -0
- package/src/parts/HandleApiCollections/HandleApiCollections.js +52 -0
- package/src/parts/HandleApiDossier/HandleApiDossier.js +109 -0
- package/src/parts/HandleApiDossiers/HandleApiDossiers.js +39 -0
- package/src/parts/HandleApiIndex/HandleApiIndex.js +30 -0
- package/src/parts/HandleApiIssues/HandleApiIssues.js +39 -0
- package/src/parts/HandleApiMenus/HandleApiMenus.js +40 -0
- package/src/parts/HandleApiPostByName/HandleApiPostByName.js +63 -0
- package/src/parts/HandleIpc/HandleIpc.js +10 -0
- package/src/parts/HandleMessage/HandleMessage.js +27 -0
- package/src/parts/IpcChild/IpcChild.js +15 -0
- package/src/parts/IpcChildModule/IpcChildModule.js +25 -0
- package/src/parts/IpcChildType/IpcChildType.js +20 -0
- package/src/parts/JsonRpc/JsonRpc.js +1 -0
- package/src/parts/Listen/Listen.js +8 -0
- package/src/parts/Main/Main.js +8 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
import * as GraphQlQueryAppSettings from "../GraphQlQueryAppSettings/GraphQlQueryAppSettings.js";
|
2
|
+
|
3
|
+
export const handleApiAppSettings = async ({ appId, apiUrl, req }) => {
|
4
|
+
const realBottom = {
|
5
|
+
...GraphQlQueryAppSettings.bottom,
|
6
|
+
filter: {},
|
7
|
+
appInfo: {
|
8
|
+
...GraphQlQueryAppSettings.bottom.appInfo,
|
9
|
+
appId,
|
10
|
+
},
|
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: GraphQlQueryAppSettings.queryName,
|
20
|
+
query: GraphQlQueryAppSettings.top,
|
21
|
+
variables: realBottom,
|
22
|
+
}),
|
23
|
+
});
|
24
|
+
const result = await response.json();
|
25
|
+
|
26
|
+
// @ts-ignore
|
27
|
+
const realData = result.data.catalog.appSettingsConnection.edges
|
28
|
+
.map((edge) => edge.node)
|
29
|
+
.map((node) => {
|
30
|
+
const { __typename, ...rest } = node;
|
31
|
+
return rest;
|
32
|
+
});
|
33
|
+
|
34
|
+
return {
|
35
|
+
headers: {
|
36
|
+
"content-type": "application/json",
|
37
|
+
},
|
38
|
+
status: 200,
|
39
|
+
body: JSON.stringify(realData, null, 2),
|
40
|
+
};
|
41
|
+
};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import * as GetPostIds from "../GetPostIds/GetPostIds.js";
|
2
|
+
import * as HandleApiPostByName from "../HandleApiPostByName/HandleApiPostByName.js";
|
3
|
+
import * as HandleApiArticleByCategoryId from "../HandleApiArticleByCategoryId/HandleApiArticleByCategoryId.js";
|
4
|
+
|
5
|
+
export const handleApiArticle = async ({ appId, apiUrl, req }) => {
|
6
|
+
const articleSlug = req.url.slice("/articles/".length);
|
7
|
+
const url = new URL(req.url, "https://example.com");
|
8
|
+
const categoryId = url.searchParams.get("categoryId");
|
9
|
+
if (categoryId) {
|
10
|
+
return HandleApiArticleByCategoryId.handleApiArticleByCategoryId({
|
11
|
+
apiUrl,
|
12
|
+
appId,
|
13
|
+
categoryId,
|
14
|
+
});
|
15
|
+
}
|
16
|
+
const postIds = await GetPostIds.getPostIds({
|
17
|
+
appId,
|
18
|
+
apiUrl,
|
19
|
+
slug: articleSlug,
|
20
|
+
});
|
21
|
+
return HandleApiPostByName.handleApiPostByName({
|
22
|
+
apiUrl,
|
23
|
+
appId,
|
24
|
+
postIds,
|
25
|
+
});
|
26
|
+
};
|
@@ -0,0 +1,97 @@
|
|
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
|
+
}) => {
|
89
|
+
const content = await getContent({ appId, apiUrl, categoryId });
|
90
|
+
return {
|
91
|
+
status: 200,
|
92
|
+
headers: {
|
93
|
+
"content-type": "application/json",
|
94
|
+
},
|
95
|
+
body: JSON.stringify(content, null, 2),
|
96
|
+
};
|
97
|
+
};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as GraphQlQueryAuthors from "../GraphQlQueryAuthors/GraphQlQueryAuthors.js";
|
2
|
+
|
3
|
+
export const handleAuthors = async ({ appId, apiUrl, req }) => {
|
4
|
+
const realBottom = {
|
5
|
+
...GraphQlQueryAuthors.bottom,
|
6
|
+
appInfo: {
|
7
|
+
...GraphQlQueryAuthors.bottom.appInfo,
|
8
|
+
appId,
|
9
|
+
},
|
10
|
+
};
|
11
|
+
const response = await fetch(apiUrl, {
|
12
|
+
method: "POST",
|
13
|
+
headers: {
|
14
|
+
Accept: "application/json",
|
15
|
+
"Content-Type": "application/json",
|
16
|
+
},
|
17
|
+
body: JSON.stringify({
|
18
|
+
operationName: "CatalogContentsQuery",
|
19
|
+
query: GraphQlQueryAuthors.top,
|
20
|
+
variables: realBottom,
|
21
|
+
}),
|
22
|
+
});
|
23
|
+
const result = await response.json();
|
24
|
+
// @ts-ignore
|
25
|
+
const realData = result.data.catalog.taxonomiesConnection.edges
|
26
|
+
.map((edge) => edge.node)
|
27
|
+
.map((node) => {
|
28
|
+
const { __typename, ...rest } = node;
|
29
|
+
return rest;
|
30
|
+
});
|
31
|
+
return {
|
32
|
+
status: 200,
|
33
|
+
headers: {
|
34
|
+
"content-type": "application/json",
|
35
|
+
},
|
36
|
+
body: JSON.stringify(realData, null, 2),
|
37
|
+
};
|
38
|
+
};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as GraphQlQueryCategories from "../GraphQlQueryCategories/GraphQlQueryCategories.js";
|
2
|
+
|
3
|
+
export const handleCategories = async ({ appId, apiUrl, req }) => {
|
4
|
+
const realBottom = {
|
5
|
+
...GraphQlQueryCategories.bottom,
|
6
|
+
appInfo: {
|
7
|
+
...GraphQlQueryCategories.bottom.appInfo,
|
8
|
+
appId,
|
9
|
+
},
|
10
|
+
};
|
11
|
+
const response = await fetch(apiUrl, {
|
12
|
+
method: "POST",
|
13
|
+
headers: {
|
14
|
+
Accept: "application/json",
|
15
|
+
"Content-Type": "application/json",
|
16
|
+
},
|
17
|
+
body: JSON.stringify({
|
18
|
+
operationName: "CatalogContentsQuery",
|
19
|
+
query: GraphQlQueryCategories.top,
|
20
|
+
variables: realBottom,
|
21
|
+
}),
|
22
|
+
});
|
23
|
+
const result = await response.json();
|
24
|
+
// @ts-ignore
|
25
|
+
const realData = result.data.catalog.taxonomiesConnection.edges
|
26
|
+
.map((edge) => edge.node)
|
27
|
+
.map((node) => {
|
28
|
+
const { __typename, ...rest } = node;
|
29
|
+
return rest;
|
30
|
+
});
|
31
|
+
return {
|
32
|
+
status: 200,
|
33
|
+
headers: {
|
34
|
+
"content-type": "application/json",
|
35
|
+
},
|
36
|
+
body: JSON.stringify(realData, null, 2),
|
37
|
+
};
|
38
|
+
};
|
@@ -0,0 +1,62 @@
|
|
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 = async ({ appId, apiUrl, req }) => {
|
53
|
+
const name = req.url.slice("/collections/".length);
|
54
|
+
const content = await getCollections({ appId, apiUrl, name });
|
55
|
+
return {
|
56
|
+
status: 200,
|
57
|
+
headers: {
|
58
|
+
"content-type": "application/json",
|
59
|
+
},
|
60
|
+
body: JSON.stringify(content, null, 2),
|
61
|
+
};
|
62
|
+
};
|
@@ -0,0 +1,52 @@
|
|
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 = async ({ appId, apiUrl, req }) => {
|
43
|
+
const content = await getCollections({ appId, apiUrl });
|
44
|
+
console.log({ content });
|
45
|
+
return {
|
46
|
+
status: 200,
|
47
|
+
headers: {
|
48
|
+
"content-type": "application/json",
|
49
|
+
},
|
50
|
+
body: JSON.stringify(content, null, 2),
|
51
|
+
};
|
52
|
+
};
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import * as GraphQlQueryPathSegment from "../GraphQlQueryPathSegment/GraphQlQueryPathSegment.js";
|
2
|
+
import * as GraphQlQueryDossier from "../GraphQlQueryDossier/GraphQlQueryDossier.js";
|
3
|
+
|
4
|
+
const getBundleId = async ({ appId, reqUrl }) => {
|
5
|
+
const url = `https://catalog.purplemanager.com/graphql`;
|
6
|
+
const part = reqUrl.slice("/dossiers".length + 1);
|
7
|
+
const realBottom = {
|
8
|
+
...GraphQlQueryPathSegment.bottom1,
|
9
|
+
appInfo: {
|
10
|
+
...GraphQlQueryPathSegment.bottom1.appInfo,
|
11
|
+
appId,
|
12
|
+
},
|
13
|
+
pathSegments: [part],
|
14
|
+
};
|
15
|
+
const response = await fetch(url, {
|
16
|
+
method: "POST",
|
17
|
+
headers: {
|
18
|
+
Accept: "application/json",
|
19
|
+
"Content-Type": "application/json",
|
20
|
+
},
|
21
|
+
body: JSON.stringify({
|
22
|
+
operationName: "LookupPathSegmentsQuery",
|
23
|
+
query: GraphQlQueryPathSegment.top1,
|
24
|
+
variables: realBottom,
|
25
|
+
}),
|
26
|
+
});
|
27
|
+
const result = await response.json();
|
28
|
+
// @ts-ignore
|
29
|
+
const items = result.data.catalog.lookupPathSegments.flatMap(
|
30
|
+
(item) => item.matches
|
31
|
+
);
|
32
|
+
if (items.length === 0) {
|
33
|
+
return "";
|
34
|
+
}
|
35
|
+
const id = items[0].id;
|
36
|
+
return id;
|
37
|
+
};
|
38
|
+
|
39
|
+
export const handleDossier = async ({ appId, apiUrl, req }) => {
|
40
|
+
const bundleId = await getBundleId({
|
41
|
+
appId,
|
42
|
+
reqUrl: req.url,
|
43
|
+
});
|
44
|
+
if (!bundleId) {
|
45
|
+
return {
|
46
|
+
status: 404,
|
47
|
+
headers: {},
|
48
|
+
body: "Not found",
|
49
|
+
};
|
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
|
+
},
|
63
|
+
},
|
64
|
+
{
|
65
|
+
contentType: {
|
66
|
+
value: "POST",
|
67
|
+
},
|
68
|
+
},
|
69
|
+
{
|
70
|
+
AND: [
|
71
|
+
{
|
72
|
+
bundleId: {
|
73
|
+
value: bundleId,
|
74
|
+
},
|
75
|
+
},
|
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
|
+
}),
|
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
|
+
});
|
101
|
+
|
102
|
+
return {
|
103
|
+
status: 200,
|
104
|
+
headers: {
|
105
|
+
"content-type": "application/json",
|
106
|
+
},
|
107
|
+
body: JSON.stringify(realData, null, 2),
|
108
|
+
};
|
109
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import * as GraphQlQueryDossiers from "../GraphQlQueryDossiers/GraphQlQueryDossiers.js";
|
2
|
+
|
3
|
+
export const handleDossiers = async ({ appId, apiUrl, req }) => {
|
4
|
+
const realBottom = {
|
5
|
+
...GraphQlQueryDossiers.bottom,
|
6
|
+
appInfo: {
|
7
|
+
...GraphQlQueryDossiers.bottom.appInfo,
|
8
|
+
appId,
|
9
|
+
},
|
10
|
+
};
|
11
|
+
const response = await fetch(apiUrl, {
|
12
|
+
method: "POST",
|
13
|
+
headers: {
|
14
|
+
Accept: "application/json",
|
15
|
+
"Content-Type": "application/json",
|
16
|
+
},
|
17
|
+
body: JSON.stringify({
|
18
|
+
operationName: "CatalogContentsQuery",
|
19
|
+
query: GraphQlQueryDossiers.top,
|
20
|
+
variables: realBottom,
|
21
|
+
}),
|
22
|
+
});
|
23
|
+
const result = await response.json();
|
24
|
+
// @ts-ignore
|
25
|
+
const realData = result.data.catalog.contentsConnection.edges
|
26
|
+
.map((edge) => edge.content)
|
27
|
+
.map((node) => {
|
28
|
+
const { __typename, ...rest } = node;
|
29
|
+
return rest;
|
30
|
+
});
|
31
|
+
|
32
|
+
return {
|
33
|
+
status: 200,
|
34
|
+
headers: {
|
35
|
+
"content-type": "application/json",
|
36
|
+
},
|
37
|
+
body: JSON.stringify(realData, null, 2),
|
38
|
+
};
|
39
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
export const handleIndex = async (req, res, next) => {
|
2
|
+
const html = `<!doctype html>
|
3
|
+
<html lang="en">
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8" />
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7
|
+
<title>Api</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<ul>
|
11
|
+
<li><a href="/api/issues">Issues</a></li>
|
12
|
+
<li><a href="/api/dossiers">Dossiers</a></li>
|
13
|
+
<li><a href="/api/categories">Categories</a></li>
|
14
|
+
<li><a href="/api/articles">Articles</a></li>
|
15
|
+
<li><a href="/api/authors">Authors</a></li>
|
16
|
+
<li><a href="/api/collections">Collections</a></li>
|
17
|
+
<li><a href="/api/menus">Menus</a></li>
|
18
|
+
<li><a href="/api/appSettings">App Settings</a></li>
|
19
|
+
</ul>
|
20
|
+
</body>
|
21
|
+
</html>
|
22
|
+
`;
|
23
|
+
return {
|
24
|
+
body: html,
|
25
|
+
status: 200,
|
26
|
+
headers: {
|
27
|
+
"content-type": "text.html",
|
28
|
+
},
|
29
|
+
};
|
30
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import * as GraphQlQueryIssues from "../GraphQlQueryIssues/GraphQlQueryIssues.js";
|
2
|
+
|
3
|
+
export const handleIssues = async ({ appId, apiUrl, req }) => {
|
4
|
+
const realBottom = {
|
5
|
+
...GraphQlQueryIssues.bottom,
|
6
|
+
appInfo: {
|
7
|
+
...GraphQlQueryIssues.bottom.appInfo,
|
8
|
+
appId,
|
9
|
+
},
|
10
|
+
};
|
11
|
+
const response = await fetch(apiUrl, {
|
12
|
+
method: "POST",
|
13
|
+
headers: {
|
14
|
+
Accept: "application/json",
|
15
|
+
"Content-Type": "application/json",
|
16
|
+
},
|
17
|
+
body: JSON.stringify({
|
18
|
+
operationName: "CatalogContentsQuery",
|
19
|
+
query: GraphQlQueryIssues.top,
|
20
|
+
variables: realBottom,
|
21
|
+
}),
|
22
|
+
});
|
23
|
+
const result = await response.json();
|
24
|
+
// @ts-ignore
|
25
|
+
const realData = result.data.catalog.contentsConnection.edges
|
26
|
+
.map((edge) => edge.content)
|
27
|
+
.map((node) => {
|
28
|
+
const { __typename, ...rest } = node;
|
29
|
+
return rest;
|
30
|
+
});
|
31
|
+
|
32
|
+
return {
|
33
|
+
status: 200,
|
34
|
+
headers: {
|
35
|
+
"content-type": "application/json",
|
36
|
+
},
|
37
|
+
body: JSON.stringify(realData, null, 2),
|
38
|
+
};
|
39
|
+
};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import * as GraphQlQueryMenus from "../GraphQlQueryMenus/GraphQlQueryMenus.js";
|
2
|
+
|
3
|
+
export const handleMenus = async ({ appId, apiUrl, req }) => {
|
4
|
+
const realBottom = {
|
5
|
+
...GraphQlQueryMenus.bottom,
|
6
|
+
filter: {},
|
7
|
+
appInfo: {
|
8
|
+
...GraphQlQueryMenus.bottom.appInfo,
|
9
|
+
appId,
|
10
|
+
},
|
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: GraphQlQueryMenus.queryName,
|
20
|
+
query: GraphQlQueryMenus.top,
|
21
|
+
variables: realBottom,
|
22
|
+
}),
|
23
|
+
});
|
24
|
+
const result = await response.json();
|
25
|
+
// @ts-ignore
|
26
|
+
const realData = result.data.catalog.menusConnection.edges
|
27
|
+
.map((edge) => edge.content)
|
28
|
+
.map((node) => {
|
29
|
+
const { __typename, ...rest } = node;
|
30
|
+
return rest;
|
31
|
+
});
|
32
|
+
|
33
|
+
return {
|
34
|
+
headers: {
|
35
|
+
"content-type": "application/json",
|
36
|
+
},
|
37
|
+
status: 200,
|
38
|
+
body: JSON.stringify(realData, null, 2),
|
39
|
+
};
|
40
|
+
};
|
@@ -0,0 +1,63 @@
|
|
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, appId, apiUrl }) => {
|
45
|
+
if (postIds.length === 0) {
|
46
|
+
return {
|
47
|
+
status: 404,
|
48
|
+
headers: {
|
49
|
+
"content-type": "application/json",
|
50
|
+
},
|
51
|
+
body: JSON.stringify("Not found", null, 2),
|
52
|
+
};
|
53
|
+
}
|
54
|
+
const postId = postIds[0];
|
55
|
+
const content = await getContent({ appId, apiUrl, postId });
|
56
|
+
return {
|
57
|
+
status: 200,
|
58
|
+
headers: {
|
59
|
+
"content-type": "application/json",
|
60
|
+
},
|
61
|
+
body: JSON.stringify(content, null, 2),
|
62
|
+
};
|
63
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import * as HandleMessage from "../HandleMessage/HandleMessage.js";
|
2
|
+
|
3
|
+
export const handleIpc = (ipc) => {
|
4
|
+
if ("addEventListener" in ipc) {
|
5
|
+
ipc.addEventListener("message", HandleMessage.handleMessage);
|
6
|
+
} else if ("on" in ipc) {
|
7
|
+
// deprecated
|
8
|
+
ipc.on("message", HandleMessage.handleMessage);
|
9
|
+
}
|
10
|
+
};
|