@griddo/cx 10.5.4 → 10.6.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.
@@ -41,8 +41,8 @@ declare function exporterCleanDisposableDirectories(domain: string): Promise<voi
41
41
  */
42
42
  declare function verbose(str: string): void;
43
43
  /**
44
- * Returns true for `true`, true, positive numbers
45
- * Returns false for `false`, false, 0, negative integers and anything else
44
+ * Returns true for "true", "on", true and positive numbers.
45
+ * Returns false for "false", "off", false, 0, negative integers and anything else.
46
46
  */
47
47
  declare function isTruthy(value: any): boolean;
48
48
  /**
@@ -11,4 +11,5 @@ declare function postSearchInfo(props: PostSearchInfoProps): Promise<PostSearchI
11
11
  * send it to the search table in the ddbb using the API.
12
12
  */
13
13
  declare function uploadRenderedSearchContentToAPI(distDomainPath: string, domain: string): Promise<void>;
14
- export { postSearchInfo, uploadRenderedSearchContentToAPI };
14
+ declare function startAIEmbeddings(): Promise<void>;
15
+ export { postSearchInfo, startAIEmbeddings, uploadRenderedSearchContentToAPI };
package/cx.config.d.ts CHANGED
@@ -11,6 +11,8 @@ declare const CXDir: {
11
11
  SSG: "__ssg";
12
12
  COMPONENTS: "__components";
13
13
  ROOT: "__root";
14
+ EXPORT_DIST: "__exports_dist";
15
+ CX_DIST: "__cx_dist";
14
16
  };
15
17
 
16
18
  export type Artifact = "store" | "apiCache" | "dist" | "assets";
package/cx.config.js CHANGED
@@ -28,6 +28,8 @@ const config = {
28
28
  SSG: "__ssg",
29
29
  COMPONENTS: "__components",
30
30
  ROOT: "__root",
31
+ EXPORTS_DIST: "__exports_dist",
32
+ CX_DIST: "__cx_dist",
31
33
  },
32
34
  paths: (domain) => ({
33
35
  __caches: path.join(CX_CACHE_DIR, domain || ""),
@@ -36,6 +38,8 @@ const config = {
36
38
  __exports: path.join(EXPORTS_DIR, domain || ""),
37
39
  __root: REPO_ROOT_DIR,
38
40
  __ssg: SSG_DIR,
41
+ __exports_dist: domain ? path.join(EXPORTS_DIR, domain, "dist") : "",
42
+ __cx_dist: path.join(CX_ROOT_DIR, "dist"),
39
43
  }),
40
44
  };
41
45
 
@@ -105,10 +105,10 @@ class DistributorService {
105
105
  const { site, lang } = data;
106
106
 
107
107
  // Infor that the distributor has not dat.sources
108
- if (!data.sources) {
108
+ if (!data.sources && data.mode === "auto") {
109
109
  logBox(
110
- `Warning: Page with id: ${page.id} in the site ${site} has a ReferenceField with \`undefined\` \`data.sources\``,
111
- "Undefined data.sources in ReferenceField"
110
+ `Warning: Page with id: ${page.id} has a ReferenceField with \`undefined\` \`data.sources\``,
111
+ "undefined data.sources in ReferenceField"
112
112
  );
113
113
  }
114
114
 
@@ -94,7 +94,9 @@ type CXDir =
94
94
  | "__cx"
95
95
  | "__ssg"
96
96
  | "__components"
97
- | "__root";
97
+ | "__root"
98
+ | "__exports_dist"
99
+ | "__cx_dist";
98
100
 
99
101
  interface CXConfig {
100
102
  proDomain: string;
@@ -106,10 +108,17 @@ interface CXConfig {
106
108
  SSG: "__ssg";
107
109
  COMPONENTS: "__components";
108
110
  ROOT: "__root";
111
+ EXPORTS_DIST: "__exports_dist";
112
+ CX_DIST: "__cx_dist";
109
113
  };
110
114
  paths: (domain?: string) => Record<CXDir, string>;
111
115
  }
112
116
 
117
+ interface AIEmbeddingsResponse {
118
+ code: number;
119
+ message: string;
120
+ }
121
+
113
122
  export {
114
123
  BuildProcessData,
115
124
  CXConfig,
@@ -123,4 +132,5 @@ export {
123
132
  Robot,
124
133
  Robots,
125
134
  Settings,
135
+ type AIEmbeddingsResponse,
126
136
  };
@@ -1,35 +1,40 @@
1
1
  import fs from "node:fs";
2
- import path from "node:path";
3
2
 
4
- import pkgDir from "pkg-dir";
3
+ import dotenv from "dotenv";
5
4
 
5
+ import { getConfig, isTruthy } from "./utils/core-utils";
6
6
  import { getInstanceDomains } from "./utils/domains";
7
- import { uploadRenderedSearchContentToAPI } from "./utils/searches";
7
+ import {
8
+ startAIEmbeddings,
9
+ uploadRenderedSearchContentToAPI,
10
+ } from "./utils/searches";
8
11
 
9
- const doSearch = JSON.parse(process.env.GRIDDO_SEARCH_FEATURE || "false");
12
+ dotenv.config();
10
13
 
11
- // Where we are going to find export folders
12
- const execBasePath = pkgDir.sync(path.resolve(__dirname, "../.."))!;
13
-
14
- // Where we are going to find archived exports
15
- const exportArchiveBasePath = path.resolve(execBasePath, "exports/sites");
14
+ const GRIDDO_SEARCH_FEATURE = isTruthy(process.env.GRIDDO_SEARCH_FEATURE);
15
+ const GRIDDO_AI_EMBEDDINGS = isTruthy(process.env.GRIDDO_AI_EMBEDDINGS);
16
16
 
17
17
  async function main() {
18
- // Feature not enabled
19
- if (!doSearch) {
18
+ if (!GRIDDO_SEARCH_FEATURE) {
20
19
  return;
21
20
  }
22
21
 
23
22
  const domains = await getInstanceDomains();
23
+ const config = getConfig();
24
24
 
25
25
  for (const domain of domains) {
26
- const distDomainPath = path.resolve(exportArchiveBasePath, domain, "dist");
26
+ const { __exports_dist } = config.paths();
27
27
 
28
- // If the export/sites/domain has not exported sites, do not upload search content.
29
- if (fs.existsSync(distDomainPath)) {
30
- await uploadRenderedSearchContentToAPI(distDomainPath, domain);
28
+ // If __exports_dist has not exported sites (directories), it does not
29
+ // upload search content.
30
+ if (fs.existsSync(__exports_dist)) {
31
+ await uploadRenderedSearchContentToAPI(__exports_dist, domain);
31
32
  }
32
33
  }
34
+
35
+ if (GRIDDO_AI_EMBEDDINGS) {
36
+ await startAIEmbeddings();
37
+ }
33
38
  }
34
39
 
35
40
  main().catch((err) => {
@@ -99,19 +99,23 @@ function verbose(str: string) {
99
99
  }
100
100
 
101
101
  /**
102
- * Returns true for `true`, true, positive numbers
103
- * Returns false for `false`, false, 0, negative integers and anything else
102
+ * Returns true for "true", "on", true and positive numbers.
103
+ * Returns false for "false", "off", false, 0, negative integers and anything else.
104
104
  */
105
105
  function isTruthy(value: any): boolean {
106
106
  // Return if Boolean
107
- if (typeof value === `boolean`) return value;
107
+ if (typeof value === "boolean") return value;
108
108
 
109
109
  // Return false if null or undefined
110
110
  if (value === undefined || value === null) return false;
111
111
 
112
112
  // If the String is true or false
113
- if (value.toLowerCase() === `true`) return true;
114
- if (value.toLowerCase() === `false`) return false;
113
+ if (value.toLowerCase() === "true") return true;
114
+ if (value.toLowerCase() === "false") return false;
115
+
116
+ // "on" | "off", We love them in Griddo ^^.
117
+ if (value.toLowerCase() === "on") return true;
118
+ if (value.toLowerCase() === "off") return false;
115
119
 
116
120
  // Now check if it's a number
117
121
  const number = parseInt(value, 10);
@@ -1,5 +1,8 @@
1
1
  import type { PostSearchInfoResponse } from "../types/api";
2
- import type { PostSearchInfoProps } from "../types/global";
2
+ import type {
3
+ AIEmbeddingsResponse,
4
+ PostSearchInfoProps,
5
+ } from "../types/global";
3
6
 
4
7
  import fs from "node:fs";
5
8
  import path from "node:path";
@@ -55,7 +58,7 @@ async function postSearchInfo(props: PostSearchInfoProps) {
55
58
  function prepareHTMLContentForSearch(content: string) {
56
59
  const noTagsContent = removeHTMLTags(
57
60
  ["meta", "link", "style", "script", "noscript", "nav", "header", "footer"],
58
- content
61
+ content,
59
62
  );
60
63
  const plainTextContent = stripHTMLTags(noTagsContent);
61
64
 
@@ -109,7 +112,7 @@ function stripSpaces(str: string) {
109
112
  */
110
113
  async function uploadRenderedSearchContentToAPI(
111
114
  distDomainPath: string,
112
- domain: string
115
+ domain: string,
113
116
  ) {
114
117
  const config = getConfig();
115
118
  const { __caches } = config.paths(domain);
@@ -121,7 +124,7 @@ async function uploadRenderedSearchContentToAPI(
121
124
  // renderizardos bajo el mismo. Por lo que `store` no existe.
122
125
  if (!fs.existsSync(storeFolder)) {
123
126
  console.log(
124
- `Skipping uploading content to the search endpoint for the domain ${domain}, it has not exported sites.`
127
+ `Skipping uploading content to the search endpoint for the domain ${domain}, it has not exported sites.`,
125
128
  );
126
129
  return;
127
130
  }
@@ -156,4 +159,15 @@ async function uploadRenderedSearchContentToAPI(
156
159
  }
157
160
  }
158
161
 
159
- export { postSearchInfo, uploadRenderedSearchContentToAPI };
162
+ async function startAIEmbeddings() {
163
+ try {
164
+ await post<AIEmbeddingsResponse>({ endpoint: `${API_URL}/ai/embeddings` });
165
+ } catch (error) {
166
+ console.warn(
167
+ "There was an error with the ai embeddings",
168
+ (error as Error).message,
169
+ );
170
+ }
171
+ }
172
+
173
+ export { postSearchInfo, startAIEmbeddings, uploadRenderedSearchContentToAPI };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/cx",
3
3
  "description": "Griddo SSG based on Gatsby",
4
- "version": "10.5.4",
4
+ "version": "10.6.1",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -48,7 +48,7 @@
48
48
  "@babel/preset-env": "^7.14.5",
49
49
  "@babel/preset-react": "^7.14.5",
50
50
  "@babel/preset-typescript": "^7.16.5",
51
- "@griddo/core": "10.5.4",
51
+ "@griddo/core": "10.6.1",
52
52
  "@svgr/webpack": "^5.5.0",
53
53
  "babel-loader": "^8.0.6",
54
54
  "babel-plugin-transform-runtime": "^6.23.0",
@@ -119,5 +119,5 @@
119
119
  "publishConfig": {
120
120
  "access": "public"
121
121
  },
122
- "gitHead": "aee8c57f859479efdec9e7e1d1acfdcd4caa34b8"
122
+ "gitHead": "7c09ff5f84d88f828072c1e328345173f2cdf992"
123
123
  }