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

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pronto-tools-and-more/pronto",
3
- "version": "12.25.0",
3
+ "version": "12.26.0",
4
4
  "description": "",
5
5
  "main": "src/main.js",
6
6
  "type": "module",
@@ -17,16 +17,16 @@
17
17
  "@lvce-editor/ipc": "^13.7.0",
18
18
  "@lvce-editor/json-rpc": "^5.4.0",
19
19
  "@lvce-editor/verror": "^1.6.0",
20
- "@pronto-tools-and-more/file-watcher": "12.25.0",
21
- "@pronto-tools-and-more/files": "12.25.0",
22
- "@pronto-tools-and-more/network-process": "12.25.0",
23
- "@pronto-tools-and-more/sass-compiler": "12.25.0",
24
- "@pronto-tools-and-more/components-renderer": "12.25.0",
25
- "@pronto-tools-and-more/components": "12.25.0",
26
- "@pronto-tools-and-more/schema-process": "12.25.0",
27
- "@pronto-tools-and-more/diff-process": "12.25.0",
28
- "@pronto-tools-and-more/type-checker": "12.25.0",
29
- "@pronto-tools-and-more/custom-js-functions": "12.25.0",
20
+ "@pronto-tools-and-more/file-watcher": "12.26.0",
21
+ "@pronto-tools-and-more/files": "12.26.0",
22
+ "@pronto-tools-and-more/network-process": "12.26.0",
23
+ "@pronto-tools-and-more/sass-compiler": "12.26.0",
24
+ "@pronto-tools-and-more/components-renderer": "12.26.0",
25
+ "@pronto-tools-and-more/components": "12.26.0",
26
+ "@pronto-tools-and-more/schema-process": "12.26.0",
27
+ "@pronto-tools-and-more/diff-process": "12.26.0",
28
+ "@pronto-tools-and-more/type-checker": "12.26.0",
29
+ "@pronto-tools-and-more/custom-js-functions": "12.26.0",
30
30
  "execa": "^9.5.2",
31
31
  "express": "^4.21.2"
32
32
  },
@@ -126,6 +126,17 @@ export const build = async () => {
126
126
  )
127
127
  );
128
128
  }
129
+
130
+ if (
131
+ tag &&
132
+ Config.pushToReleaseOnGitTag &&
133
+ existsSync(join(dist, "src", "default", "storefront", "robots.prod.txt"))
134
+ ) {
135
+ await cp(
136
+ join(dist, "src", "default", "storefront", "robots.prod.txt"),
137
+ join(dist, "src", "default", "storefront", "robots.txt")
138
+ );
139
+ }
129
140
  if (Config.validateSchema) {
130
141
  await ValidateAllSchemas.validateAllSchemas();
131
142
  }
@@ -0,0 +1,41 @@
1
+ import * as GraphQlQueryPathSegments from "../GraphQlQueryPathSegments/GraphQlQueryPathSegments.js";
2
+
3
+ export const getPostIds = async ({ appId, apiUrl, slug }) => {
4
+ const realBottom = {
5
+ ...GraphQlQueryPathSegments.bottom,
6
+ appInfo: {
7
+ ...GraphQlQueryPathSegments.bottom.appInfo,
8
+ appId,
9
+ },
10
+ pathSegments: [slug],
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: GraphQlQueryPathSegments.queryName,
20
+ query: GraphQlQueryPathSegments.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.lookupPathSegments
32
+ .flatMap((item) => item.matches)
33
+ .map((match) => {
34
+ const { __typename, ...rest } = match;
35
+ return rest;
36
+ })
37
+ .map((match) => {
38
+ return match.id;
39
+ });
40
+ return realData;
41
+ };
@@ -1,99 +1,30 @@
1
- import * as GraphQlQueryPathSegments from "../GraphQlQueryPathSegments/GraphQlQueryPathSegments.js";
2
- import * as GraphQlQueryContent from "../GraphQlQueryContent/GraphQlQueryContent.js";
3
-
4
- const getPostIds = async ({ appId, apiUrl, slug }) => {
5
- const realBottom = {
6
- ...GraphQlQueryPathSegments.bottom,
7
- appInfo: {
8
- ...GraphQlQueryPathSegments.bottom.appInfo,
9
- appId,
10
- },
11
- pathSegments: [slug],
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: GraphQlQueryPathSegments.queryName,
21
- query: GraphQlQueryPathSegments.top,
22
- variables: realBottom,
23
- }),
24
- });
25
- const result = await response.json();
26
- // @ts-ignore
27
- if (result && result.error) {
28
- // @ts-ignore
29
- throw new Error(`api error: ${result.error}`);
30
- }
31
- // @ts-ignore
32
- const realData = result.data.catalog.lookupPathSegments
33
- .flatMap((item) => item.matches)
34
- .map((match) => {
35
- const { __typename, ...rest } = match;
36
- return rest;
37
- })
38
- .map((match) => {
39
- return match.id;
40
- });
41
- return realData;
42
- };
43
-
44
- const getContent = async ({ appId, apiUrl, postId }) => {
45
- const realBottom = {
46
- ...GraphQlQueryContent.bottom,
47
- appInfo: {
48
- ...GraphQlQueryContent.bottom.appInfo,
49
- appId,
50
- },
51
- filter: {
52
- id: {
53
- value: postId,
54
- },
55
- },
56
- };
57
- const response = await fetch(apiUrl, {
58
- method: "POST",
59
- headers: {
60
- Accept: "application/json",
61
- "Content-Type": "application/json",
62
- },
63
- body: JSON.stringify({
64
- operationName: GraphQlQueryContent.queryName,
65
- query: GraphQlQueryContent.top,
66
- variables: realBottom,
67
- }),
68
- });
69
- const result = await response.json();
70
- // @ts-ignore
71
- if (result && result.error) {
72
- // @ts-ignore
73
- throw new Error(`api error: ${result.error}`);
74
- }
75
- // @ts-ignore
76
- const realData = result.data.catalog.contentsConnection.edges
77
- .map((edge) => edge.content)
78
- .map((match) => {
79
- const { __typename, ...rest } = match;
80
- return rest;
81
- });
82
- return realData;
83
- };
1
+ import * as GetPostIds from "../GetPostIds/GetPostIds.js";
2
+ import * as HandleApiPostByName from "../HandleApiPostByName/HandleApiPostByName.js";
3
+ import * as HandleApiArticleByCategoryId from "../HandleApiArticleByCategoryId/HandleApiArticleByCategoryId.js";
84
4
 
85
5
  export const handleApiArticle =
86
6
  ({ appId, apiUrl }) =>
87
7
  async (req, res, next) => {
88
8
  const articleSlug = req.url.slice("/articles/".length);
89
- const postIds = await getPostIds({ appId, apiUrl, slug: articleSlug });
90
- if (postIds.length === 0) {
91
- res.setHeader("content-type", "application/json");
92
- res.end(JSON.stringify("Not found", null, 2));
93
- return;
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
+ });
94
18
  }
95
- const postId = postIds[0];
96
- const content = await getContent({ appId, apiUrl, postId });
97
- res.setHeader("content-type", "application/json");
98
- res.end(JSON.stringify(content, null, 2));
19
+ const postIds = await GetPostIds.getPostIds({
20
+ appId,
21
+ apiUrl,
22
+ slug: articleSlug,
23
+ });
24
+ return HandleApiPostByName.handleApiPostByName({
25
+ apiUrl,
26
+ appId,
27
+ postIds,
28
+ res,
29
+ });
99
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
+ };
@@ -32,6 +32,12 @@ const getCollections = async ({ appId, apiUrl, name }) => {
32
32
  throw new Error(`api error: ${result.error}`);
33
33
  }
34
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
35
41
  const realData = result.data.catalog.collectionsConnection.edges
36
42
  .map((edge) => {
37
43
  return edge.node;
@@ -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.25.0'
1
+ export const version = '12.26.0'