@griddo/cx 11.9.9-rc.0 → 11.9.9-rc.2

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.
Files changed (254) hide show
  1. package/README.md +240 -13
  2. package/build/adapters/gatsby/index.d.ts +4 -0
  3. package/build/adapters/gatsby/utils.d.ts +22 -0
  4. package/build/artifacts/index.d.ts +6 -0
  5. package/build/commands/end-render.d.ts +1 -0
  6. package/build/commands/reset-render.d.ts +1 -0
  7. package/build/commands/start-render.d.ts +1 -0
  8. package/build/commands/upload-search-content.d.ts +1 -0
  9. package/build/constants/envs.d.ts +37 -0
  10. package/build/constants/index.d.ts +57 -0
  11. package/build/end-render.js +74 -0
  12. package/build/end-render.js.map +7 -0
  13. package/build/{shared/errors.d.ts → errors/errors-data.d.ts} +3 -5
  14. package/build/errors/index.d.ts +15 -0
  15. package/build/index.d.ts +29 -10
  16. package/build/index.js +73 -406
  17. package/build/index.js.map +7 -0
  18. package/build/prepare-domains-render.js +73 -0
  19. package/build/prepare-domains-render.js.map +7 -0
  20. package/build/react/Favicon/index.d.ts +5 -0
  21. package/build/react/GriddoIntegrations/index.d.ts +4 -3
  22. package/build/react/GriddoIntegrations/utils.d.ts +6 -7
  23. package/build/react/index.d.ts +2 -3
  24. package/build/react/index.js +3 -1
  25. package/build/registers/api.d.ts +9 -0
  26. package/build/registers/gatsby.d.ts +9 -0
  27. package/build/registers/index.d.ts +3 -0
  28. package/build/reset-render.js +74 -0
  29. package/build/reset-render.js.map +7 -0
  30. package/build/services/auth.d.ts +5 -2
  31. package/build/services/domains.d.ts +4 -3
  32. package/build/services/navigation.d.ts +16 -16
  33. package/build/services/reference-fields.d.ts +3 -3
  34. package/build/services/register.d.ts +36 -0
  35. package/build/services/robots.d.ts +19 -2
  36. package/build/services/settings.d.ts +4 -0
  37. package/build/services/sites.d.ts +5 -8
  38. package/build/services/store.d.ts +1 -10
  39. package/build/start-render.js +100 -0
  40. package/build/start-render.js.map +7 -0
  41. package/build/{shared/types → types}/api.d.ts +18 -18
  42. package/build/{shared/types → types}/global.d.ts +16 -15
  43. package/build/{shared/types → types}/navigation.d.ts +5 -5
  44. package/build/{shared/types → types}/pages.d.ts +9 -9
  45. package/build/{shared/types → types}/sites.d.ts +19 -18
  46. package/build/upload-search-content.js +74 -0
  47. package/build/upload-search-content.js.map +7 -0
  48. package/build/utils/alerts.d.ts +3 -0
  49. package/build/{services → utils}/api.d.ts +1 -1
  50. package/build/utils/cache.d.ts +35 -0
  51. package/build/utils/core-utils.d.ts +107 -0
  52. package/build/utils/create-build-data.d.ts +8 -0
  53. package/build/utils/domains.d.ts +13 -0
  54. package/build/utils/folders.d.ts +53 -0
  55. package/build/{core/check-env-health.d.ts → utils/health-checks.d.ts} +2 -4
  56. package/build/utils/loggin.d.ts +51 -0
  57. package/build/{services → utils}/pages.d.ts +3 -3
  58. package/build/utils/render.d.ts +13 -0
  59. package/build/utils/searches.d.ts +15 -0
  60. package/build/utils/sites.d.ts +31 -0
  61. package/build/utils/store.d.ts +81 -0
  62. package/cx.config.d.ts +5 -0
  63. package/cx.config.js +36 -0
  64. package/exporter/adapters/gatsby/index.ts +162 -0
  65. package/exporter/adapters/gatsby/utils.ts +161 -0
  66. package/exporter/artifacts/README.md +34 -0
  67. package/exporter/artifacts/index.ts +33 -0
  68. package/exporter/build.sh +24 -16
  69. package/exporter/commands/end-render.ts +86 -65
  70. package/exporter/commands/move-assets.ts +11 -0
  71. package/exporter/commands/prepare-domains-render.ts +35 -147
  72. package/exporter/commands/reset-render.ts +8 -13
  73. package/exporter/commands/start-render.ts +64 -26
  74. package/exporter/commands/upload-search-content.ts +26 -201
  75. package/exporter/{shared → constants}/endpoints.ts +11 -12
  76. package/exporter/constants/envs.ts +94 -0
  77. package/exporter/constants/index.ts +129 -0
  78. package/exporter/{shared/errors.ts → errors/errors-data.ts} +14 -24
  79. package/exporter/errors/index.ts +40 -0
  80. package/exporter/index.ts +56 -14
  81. package/exporter/react/{GriddoFavicon → Favicon}/index.tsx +9 -3
  82. package/exporter/react/GriddoIntegrations/index.tsx +23 -17
  83. package/exporter/react/GriddoIntegrations/utils.ts +12 -24
  84. package/exporter/react/index.tsx +9 -3
  85. package/exporter/registers/api.ts +14 -0
  86. package/exporter/registers/gatsby.ts +14 -0
  87. package/exporter/registers/index.ts +4 -0
  88. package/exporter/services/auth.ts +10 -8
  89. package/exporter/services/domains.ts +8 -23
  90. package/exporter/services/navigation.ts +18 -12
  91. package/exporter/services/reference-fields.ts +32 -14
  92. package/exporter/services/register.ts +113 -0
  93. package/exporter/services/robots.ts +61 -33
  94. package/exporter/services/settings.ts +17 -0
  95. package/exporter/services/sites.ts +28 -40
  96. package/exporter/services/store.ts +321 -354
  97. package/exporter/{shared/types → types}/api.ts +41 -40
  98. package/exporter/{shared/types → types}/global.ts +21 -17
  99. package/exporter/{shared/types → types}/navigation.ts +3 -3
  100. package/exporter/{shared/types → types}/pages.ts +11 -10
  101. package/exporter/{shared/types → types}/sites.ts +19 -18
  102. package/exporter/utils/alerts.ts +29 -0
  103. package/exporter/utils/api.ts +243 -0
  104. package/exporter/utils/cache.ts +142 -0
  105. package/exporter/utils/core-utils.ts +458 -0
  106. package/exporter/utils/create-build-data.ts +17 -0
  107. package/exporter/utils/domains.ts +39 -0
  108. package/exporter/utils/folders.ts +320 -0
  109. package/exporter/utils/health-checks.ts +64 -0
  110. package/exporter/{core → utils}/images.ts +6 -1
  111. package/exporter/{core → utils}/instance.ts +13 -9
  112. package/exporter/utils/loggin.ts +184 -0
  113. package/exporter/{services → utils}/pages.ts +92 -27
  114. package/exporter/utils/render.ts +71 -0
  115. package/exporter/utils/searches.ts +156 -0
  116. package/exporter/utils/sites.ts +312 -0
  117. package/exporter/utils/store.ts +314 -0
  118. package/gatsby-browser.tsx +58 -41
  119. package/gatsby-config.ts +17 -10
  120. package/gatsby-node.ts +79 -20
  121. package/gatsby-ssr.tsx +1 -2
  122. package/package.json +80 -41
  123. package/src/README.md +7 -0
  124. package/src/components/Head.tsx +73 -28
  125. package/src/components/template.tsx +29 -6
  126. package/src/gatsby-node-utils.ts +2 -76
  127. package/src/html.tsx +11 -2
  128. package/src/types.ts +3 -3
  129. package/start-render.js +7 -0
  130. package/tsconfig.json +3 -5
  131. package/build/commands/end-render.js +0 -31
  132. package/build/commands/end-render.js.map +0 -7
  133. package/build/commands/prepare-assets-directory.js +0 -9
  134. package/build/commands/prepare-assets-directory.js.map +0 -7
  135. package/build/commands/prepare-domains-render.js +0 -38
  136. package/build/commands/prepare-domains-render.js.map +0 -7
  137. package/build/commands/reset-render.js +0 -31
  138. package/build/commands/reset-render.js.map +0 -7
  139. package/build/commands/single-domain-upload-search-content.d.ts +0 -1
  140. package/build/commands/start-render.js +0 -66
  141. package/build/commands/start-render.js.map +0 -7
  142. package/build/commands/upload-search-content.js +0 -31
  143. package/build/commands/upload-search-content.js.map +0 -7
  144. package/build/core/GriddoLog.d.ts +0 -16
  145. package/build/core/db-class.d.ts +0 -11
  146. package/build/core/db.d.ts +0 -4
  147. package/build/core/dist-rollback.d.ts +0 -11
  148. package/build/core/errors.d.ts +0 -26
  149. package/build/core/fs.d.ts +0 -69
  150. package/build/core/life-cycle.d.ts +0 -26
  151. package/build/core/logger.d.ts +0 -18
  152. package/build/core/objects.d.ts +0 -11
  153. package/build/core/print-logos.d.ts +0 -5
  154. package/build/react/DynamicScript/index.d.ts +0 -4
  155. package/build/react/GriddoFavicon/index.d.ts +0 -4
  156. package/build/react/GriddoOpenGraph/index.d.ts +0 -10
  157. package/build/services/manage-sites.d.ts +0 -22
  158. package/build/services/manage-store.d.ts +0 -32
  159. package/build/services/render-artifacts.d.ts +0 -6
  160. package/build/services/render.d.ts +0 -70
  161. package/build/services/sitemaps.d.ts +0 -5
  162. package/build/shared/context.d.ts +0 -36
  163. package/build/shared/envs.d.ts +0 -19
  164. package/build/shared/npm-modules/brush.d.ts +0 -18
  165. package/build/shared/npm-modules/find-up-simple.d.ts +0 -34
  166. package/build/shared/npm-modules/pkg-dir.d.ts +0 -7
  167. package/build/shared/npm-modules/xml-parser.d.ts +0 -4
  168. package/build/shared/types/render.d.ts +0 -54
  169. package/build/shared/types.d.ts +0 -15
  170. package/build/ssg-adapters/gatsby/actions/clean.d.ts +0 -3
  171. package/build/ssg-adapters/gatsby/actions/close.d.ts +0 -3
  172. package/build/ssg-adapters/gatsby/actions/data.d.ts +0 -2
  173. package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +0 -2
  174. package/build/ssg-adapters/gatsby/actions/init.d.ts +0 -2
  175. package/build/ssg-adapters/gatsby/actions/logs.d.ts +0 -3
  176. package/build/ssg-adapters/gatsby/actions/meta.d.ts +0 -2
  177. package/build/ssg-adapters/gatsby/actions/prepare.d.ts +0 -2
  178. package/build/ssg-adapters/gatsby/actions/relocation.d.ts +0 -2
  179. package/build/ssg-adapters/gatsby/actions/restore.d.ts +0 -3
  180. package/build/ssg-adapters/gatsby/actions/ssg.d.ts +0 -3
  181. package/build/ssg-adapters/gatsby/actions/sync.d.ts +0 -3
  182. package/build/ssg-adapters/gatsby/index.d.ts +0 -9
  183. package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +0 -4
  184. package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +0 -15
  185. package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +0 -7
  186. package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +0 -7
  187. package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +0 -18
  188. package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +0 -26
  189. package/build/ssg-adapters/gatsby/shared/types.d.ts +0 -34
  190. package/cli.mjs +0 -231
  191. package/exporter/build-esbuild.noop +0 -42
  192. package/exporter/commands/README.md +0 -151
  193. package/exporter/commands/prepare-assets-directory.ts +0 -34
  194. package/exporter/commands/single-domain-upload-search-content.ts +0 -206
  195. package/exporter/core/GriddoLog.ts +0 -45
  196. package/exporter/core/check-env-health.ts +0 -204
  197. package/exporter/core/db-class.ts +0 -54
  198. package/exporter/core/db.ts +0 -33
  199. package/exporter/core/dist-rollback.ts +0 -49
  200. package/exporter/core/errors.ts +0 -92
  201. package/exporter/core/fs.ts +0 -385
  202. package/exporter/core/life-cycle.ts +0 -73
  203. package/exporter/core/logger.ts +0 -141
  204. package/exporter/core/objects.ts +0 -37
  205. package/exporter/core/print-logos.ts +0 -21
  206. package/exporter/react/DynamicScript/index.tsx +0 -33
  207. package/exporter/react/GriddoOpenGraph/index.tsx +0 -39
  208. package/exporter/services/api.ts +0 -306
  209. package/exporter/services/manage-sites.ts +0 -116
  210. package/exporter/services/manage-store.ts +0 -173
  211. package/exporter/services/render-artifacts.ts +0 -44
  212. package/exporter/services/render.ts +0 -229
  213. package/exporter/services/sitemaps.ts +0 -129
  214. package/exporter/shared/context.ts +0 -49
  215. package/exporter/shared/envs.ts +0 -62
  216. package/exporter/shared/npm-modules/README.md +0 -36
  217. package/exporter/shared/npm-modules/brush.ts +0 -34
  218. package/exporter/shared/npm-modules/find-up-simple.ts +0 -100
  219. package/exporter/shared/npm-modules/pkg-dir.ts +0 -17
  220. package/exporter/shared/npm-modules/xml-parser.ts +0 -57
  221. package/exporter/shared/types/render.ts +0 -63
  222. package/exporter/shared/types.ts +0 -15
  223. package/exporter/ssg-adapters/gatsby/actions/clean.ts +0 -26
  224. package/exporter/ssg-adapters/gatsby/actions/close.ts +0 -17
  225. package/exporter/ssg-adapters/gatsby/actions/data.ts +0 -22
  226. package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +0 -10
  227. package/exporter/ssg-adapters/gatsby/actions/init.ts +0 -12
  228. package/exporter/ssg-adapters/gatsby/actions/logs.ts +0 -10
  229. package/exporter/ssg-adapters/gatsby/actions/meta.ts +0 -13
  230. package/exporter/ssg-adapters/gatsby/actions/prepare.ts +0 -9
  231. package/exporter/ssg-adapters/gatsby/actions/relocation.ts +0 -15
  232. package/exporter/ssg-adapters/gatsby/actions/restore.ts +0 -21
  233. package/exporter/ssg-adapters/gatsby/actions/ssg.ts +0 -12
  234. package/exporter/ssg-adapters/gatsby/actions/sync.ts +0 -65
  235. package/exporter/ssg-adapters/gatsby/index.ts +0 -114
  236. package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +0 -17
  237. package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +0 -128
  238. package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +0 -75
  239. package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +0 -58
  240. package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +0 -33
  241. package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +0 -298
  242. package/exporter/ssg-adapters/gatsby/shared/types.ts +0 -35
  243. package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
  244. package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
  245. package/tsconfig.commands.json +0 -36
  246. package/tsconfig.exporter.json +0 -21
  247. /package/build/commands/{prepare-assets-directory.d.ts → move-assets.d.ts} +0 -0
  248. /package/build/{shared → constants}/endpoints.d.ts +0 -0
  249. /package/build/react/{GriddoFavicon → Favicon}/utils.d.ts +0 -0
  250. /package/build/{shared/types → types}/templates.d.ts +0 -0
  251. /package/build/{core → utils}/images.d.ts +0 -0
  252. /package/build/{core → utils}/instance.d.ts +0 -0
  253. /package/exporter/react/{GriddoFavicon → Favicon}/utils.ts +0 -0
  254. /package/exporter/{shared/types → types}/templates.ts +0 -0
@@ -7,13 +7,11 @@
7
7
  * obligatorily.
8
8
  */
9
9
 
10
+ import type { ErrorData } from ".";
10
11
  import type { SpawnSyncReturns } from "node:child_process";
11
- import type { ErrorData } from "../core/errors";
12
12
 
13
13
  type ErrorsType =
14
14
  | "ArtifactError"
15
- | "BundlesInconsistencyError"
16
- | "CheckHealthError"
17
15
  | "ErrorInSSGBuildProcess"
18
16
  | "LifecycleExecutionError"
19
17
  | "LoginError"
@@ -22,7 +20,6 @@ type ErrorsType =
22
20
  | "ReadFromStoreError"
23
21
  | "ReferenceFieldSourcesNotFoundError"
24
22
  | "RenderUUIDError"
25
- | "UploadSearchError"
26
23
  | "WriteToStoreError";
27
24
 
28
25
  const ArtifactError: ErrorData = {
@@ -33,13 +30,19 @@ const ArtifactError: ErrorData = {
33
30
  hint: "Have there been any recent deployments? These can delete directories from the current render.",
34
31
  };
35
32
 
36
- const ErrorInSSGBuildProcess = (command: SpawnSyncReturns<string>): ErrorData => ({
33
+ const ErrorInSSGBuildProcess = (
34
+ command: SpawnSyncReturns<string>,
35
+ ): ErrorData => ({
37
36
  error: "ErrorInSSGBuildProcess",
38
37
  message: `Error in SSG build process: ${JSON.stringify(command)}`,
39
- expected: "This can happen if there was a problem with the SSG build process.",
38
+ expected:
39
+ "This can happen if there was a problem with the SSG build process.",
40
40
  });
41
41
 
42
- const LifecycleExecutionError = (attempts: number, name: string): ErrorData => ({
42
+ const LifecycleExecutionError = (
43
+ attempts: number,
44
+ name: string,
45
+ ): ErrorData => ({
43
46
  error: "LifecycleExecutionError",
44
47
  message: `Exceeded maximum retry attempts (${attempts}) for ${name} LifeCycle`,
45
48
  });
@@ -47,12 +50,14 @@ const LifecycleExecutionError = (attempts: number, name: string): ErrorData => (
47
50
  const LoginError: ErrorData = {
48
51
  error: "LoginError",
49
52
  message: "There was a problem logging in to the API",
50
- expected: "This happens if the API is currently not working or the credentials are incorrect.",
53
+ expected:
54
+ "This happens if the API is currently not working or the credentials are incorrect.",
51
55
  };
52
56
 
53
57
  const NoDomainsFoundError: ErrorData = {
54
58
  error: "NoDomainsFoundError",
55
- message: "No domains were found in this instance. The process cannot continue.",
59
+ message:
60
+ "No domains were found in this instance. The process cannot continue.",
56
61
  expected:
57
62
  "This may happen if the API is not functioning, or the site is not properly configured, or the domains are not registered.",
58
63
  hint: "You can contact the instance administrator.",
@@ -93,22 +98,8 @@ const WriteToStoreError: ErrorData = {
93
98
  hint: "There may be an issue such as lack of space or permissions preventing the file from being written.",
94
99
  };
95
100
 
96
- const UploadSearchError: ErrorData = {
97
- error: "UploadSearchError",
98
- message: "There was an error uploading content to API for search",
99
- hint: "This happens if the API is currently not working or the credentials are incorrect.",
100
- };
101
-
102
- const CheckHealthError: ErrorData = {
103
- error: "CheckHealthError",
104
- message: "There was a problem with environment vars configuration.",
105
- expected: "Some of the required environment variables are not set correctly or are missing",
106
- hint: "Are the environment variables correctly set?",
107
- };
108
-
109
101
  export {
110
102
  ArtifactError,
111
- CheckHealthError,
112
103
  ErrorInSSGBuildProcess,
113
104
  LifecycleExecutionError,
114
105
  LoginError,
@@ -117,7 +108,6 @@ export {
117
108
  ReadFromStoreError,
118
109
  ReferenceFieldSourcesNotFoundError,
119
110
  RenderUUIDError,
120
- UploadSearchError,
121
111
  WriteToStoreError,
122
112
  type ErrorsType,
123
113
  };
@@ -0,0 +1,40 @@
1
+ import type { ErrorsType } from "./errors-data";
2
+
3
+ import kleur from "kleur";
4
+
5
+ export type ErrorData = {
6
+ error: ErrorsType;
7
+ message: string;
8
+ expected?: string;
9
+ hint?: string;
10
+ };
11
+
12
+ export class RenderError extends Error {
13
+ constructor() {
14
+ super();
15
+ this.name = "InternalCXError";
16
+ this.stack = "";
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Throws an error with the provided error message, expected value, and hint.
22
+ */
23
+ function throwError(options: ErrorData, stack?: unknown) {
24
+ const { error, message, expected, hint } = options;
25
+
26
+ const errorColor = kleur.red("[ " + error + " ]");
27
+ const extraText = [expected, hint].filter(Boolean).join("\n");
28
+
29
+ console.log(`
30
+ ${errorColor}
31
+ ${message}
32
+ ${extraText}
33
+
34
+ ${kleur.red("stack")}
35
+ ${JSON.stringify(stack, null, 2)}`);
36
+
37
+ throw new RenderError();
38
+ }
39
+
40
+ export { throwError };
package/exporter/index.ts CHANGED
@@ -1,4 +1,22 @@
1
- import type { SocialsResponse } from "./shared/types/api";
1
+ /**
2
+ *
3
+ * Griddo CX library main export file.
4
+ *
5
+ * This file exports functions to use in both: adapters and SSG's frameworks.
6
+ * Turning CX basically in a javascript library.
7
+ *
8
+ * # React
9
+ * There is another export in the `/react` directory to use exclusivelly in
10
+ * the browser context where nodejs (path, fs, etc..) is not available.
11
+ *
12
+ * # Separate scripts.
13
+ * There are some separate .ts files as end-render.ts or reset-render.ts
14
+ * that are intended to be used by infra via npm script like `npm run
15
+ * end-render`
16
+ *
17
+ */
18
+
19
+ import type { SocialsResponse } from "./types/api";
2
20
  import type {
3
21
  AdditionalInfo,
4
22
  Dimensions,
@@ -6,29 +24,53 @@ import type {
6
24
  GriddoMultiPage,
7
25
  GriddoPageObject,
8
26
  GriddoSinglePage,
9
- } from "./shared/types/pages";
10
- import type { Site } from "./shared/types/sites";
27
+ } from "./types/pages";
28
+ import type { Site } from "./types/sites";
11
29
 
12
- import { throwError } from "./core/errors";
13
- import { walkStore } from "./core/fs";
30
+ import { endpoints, envs } from "./constants";
31
+ import { apiRegister } from "./registers/index";
32
+ import { FileRegister, MemoryRegister, Register } from "./services/register";
33
+ import { insertAlert } from "./utils/alerts";
34
+ import { getConfig, walk } from "./utils/core-utils";
14
35
  import {
15
36
  componentLibraryPathAlias,
16
37
  isComponentLibrary,
17
38
  resolveComponentsPath,
18
- } from "./core/instance";
19
- import { addLogToBuffer } from "./core/logger";
20
- import { getRenderPathsHydratedWithDomainFromDB } from "./services/render";
21
- import { ReadFromStoreError } from "./shared/errors";
39
+ } from "./utils/instance";
40
+ import {
41
+ buildLog,
42
+ debugLog,
43
+ infoLog,
44
+ pageSizeLog,
45
+ verboseLog,
46
+ } from "./utils/loggin";
47
+ import {
48
+ getBuildPagesFromCachedStore,
49
+ getBuildPagesFromStore,
50
+ getBuildPagesPath,
51
+ } from "./utils/store";
22
52
 
23
53
  export {
24
- addLogToBuffer,
54
+ apiRegister,
55
+ buildLog,
25
56
  componentLibraryPathAlias,
26
- getRenderPathsHydratedWithDomainFromDB,
57
+ debugLog,
58
+ endpoints,
59
+ envs,
60
+ FileRegister,
61
+ getBuildPagesFromCachedStore,
62
+ getBuildPagesFromStore,
63
+ getBuildPagesPath,
64
+ getConfig,
65
+ infoLog,
66
+ insertAlert,
27
67
  isComponentLibrary,
28
- ReadFromStoreError,
68
+ MemoryRegister,
69
+ pageSizeLog,
70
+ Register,
29
71
  resolveComponentsPath,
30
- throwError,
31
- walkStore,
72
+ verboseLog,
73
+ walk,
32
74
  type AdditionalInfo,
33
75
  type Dimensions,
34
76
  type GriddoListPage,
@@ -1,6 +1,8 @@
1
+ import * as React from "react";
2
+
1
3
  import { formatImage } from "./utils";
2
4
 
3
- function GriddoFavicon({ url }: { url: string | undefined }) {
5
+ function Favicon({ url }: { url: string | undefined }) {
4
6
  if (!url) {
5
7
  return null;
6
8
  }
@@ -24,9 +26,13 @@ function GriddoFavicon({ url }: { url: string | undefined }) {
24
26
  sizes="180x180"
25
27
  href={formatImage(url, { width: 180, height: 180, format: "png" })}
26
28
  />
27
- <link rel="icon" type="image/svg+xml" href={formatImage(url, { format: "svg" })} />
29
+ <link
30
+ rel="icon"
31
+ type="image/svg+xml"
32
+ href={formatImage(url, { format: "svg" })}
33
+ />
28
34
  </>
29
35
  );
30
36
  }
31
37
 
32
- export { GriddoFavicon };
38
+ export { Favicon };
@@ -1,19 +1,18 @@
1
+ import type { Dimensions } from "../../types/pages";
1
2
  import type { Core } from "@griddo/core";
2
- import type { Dimensions } from "../../shared/types/pages";
3
-
4
- import * as React from "react";
5
3
 
6
4
  import { generateAutomaticDimensions } from "@griddo-instance";
5
+ import parse from "html-react-parser";
6
+ import * as React from "react";
7
7
 
8
8
  import {
9
9
  composeAnalytics,
10
- extractScriptContent,
11
10
  filterBodyIntegrationFromPosition,
12
11
  filterHeadIntegrations,
13
12
  } from "./utils";
14
13
 
15
14
  export interface GriddoIntegrationsProps {
16
- integrations?: Core.PageIntegration[];
15
+ integrations?: Array<Core.PageIntegration>;
17
16
  location: "head" | "start-body" | "end-body";
18
17
  id?: string;
19
18
  analyticScript?: string;
@@ -57,7 +56,12 @@ function GriddoIntegrations(props: GriddoIntegrationsProps) {
57
56
  // @shame!
58
57
  // El fix sería llamar a `composeAnalytics()` solo si `pageInfo` existe.
59
58
  const { analyticsScript, analyticsDimensions } = pageInfo
60
- ? composeAnalytics(siteScript, dimensions, pageInfo, generateAutomaticDimensions)
59
+ ? composeAnalytics(
60
+ siteScript,
61
+ dimensions,
62
+ pageInfo,
63
+ generateAutomaticDimensions,
64
+ )
61
65
  : { analyticsDimensions: null, analyticsScript: null };
62
66
 
63
67
  // GTAG WITH UA
@@ -66,13 +70,9 @@ function GriddoIntegrations(props: GriddoIntegrationsProps) {
66
70
  `https://www.googletagmanager.com/gtag/js?id=${analyticsScript}`) ||
67
71
  null;
68
72
 
69
- const siteScriptContent = extractScriptContent(siteScript);
70
-
71
73
  return (
72
74
  <>
73
75
  {integrationsOrdered?.map((integration, key) => {
74
- const integrationScriptContent = extractScriptContent(integration.content);
75
-
76
76
  /* Data Layer */
77
77
  if (integration.type === "datalayer") {
78
78
  return (
@@ -88,19 +88,25 @@ function GriddoIntegrations(props: GriddoIntegrationsProps) {
88
88
  if (integration.type === "analytics") {
89
89
  // If UA- is provided
90
90
  if (analyticsWithUA) {
91
- return <script key={key} src={analyticsWithUA} data-griddo-id={id} />;
91
+ return (
92
+ <script key={key} src={analyticsWithUA} data-griddo-id={id} />
93
+ );
92
94
  }
93
95
 
94
- return siteScriptContent ? (
95
- <script key={key} dangerouslySetInnerHTML={{ __html: siteScriptContent }} />
96
- ) : null;
96
+ return (
97
+ <React.Fragment key={key}>
98
+ {siteScript && parse(siteScript, { trim: true })}
99
+ </React.Fragment>
100
+ );
97
101
  }
98
102
 
99
103
  /* Integration integration.type === "addon" */
100
104
  if (integration.type === "addon") {
101
- return integrationScriptContent ? (
102
- <script key={key} dangerouslySetInnerHTML={{ __html: integrationScriptContent }} />
103
- ) : null;
105
+ return (
106
+ <React.Fragment key={key}>
107
+ {parse(integration.content, { trim: true })}
108
+ </React.Fragment>
109
+ );
104
110
  }
105
111
 
106
112
  return null;
@@ -1,5 +1,5 @@
1
+ import type { Dimensions } from "../../types/pages";
1
2
  import type { Core } from "@griddo/core";
2
- import type { Dimensions } from "../../shared/types/pages";
3
3
 
4
4
  /**
5
5
  * Return true if the argument is an object (not null)
@@ -9,7 +9,7 @@ function isObject(value: unknown) {
9
9
  }
10
10
 
11
11
  function filterBodyIntegrationFromPosition(
12
- integrations: Core.PageIntegration[],
12
+ integrations: Array<Core.PageIntegration>,
13
13
  position: "start" | "end",
14
14
  ) {
15
15
  return (
@@ -26,7 +26,7 @@ function filterBodyIntegrationFromPosition(
26
26
  );
27
27
  }
28
28
 
29
- function filterHeadIntegrations(integrations: Core.PageIntegration[]) {
29
+ function filterHeadIntegrations(integrations: Array<Core.PageIntegration>) {
30
30
  // A la hora de filtrar las integraciones, los addons si que tienen
31
31
  // contenido en head pero en el caso de analytics y datalayer el contenido
32
32
  // llega a null, pero deben ir en el <head>
@@ -48,7 +48,7 @@ function filterHeadIntegrations(integrations: Core.PageIntegration[]) {
48
48
  }
49
49
 
50
50
  const filterPositionIntegrations = (
51
- integrations: Core.PageIntegration[],
51
+ integrations: Array<Core.PageIntegration>,
52
52
  position: "head" | "start" | "end",
53
53
  ) => {
54
54
  switch (position) {
@@ -70,13 +70,16 @@ function composeAnalytics(
70
70
  };
71
71
  };
72
72
  },
73
- generateAutomaticDimensions = (_page: Record<string, unknown>) => null,
73
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
+ generateAutomaticDimensions = (page: Record<string, unknown>) => null,
74
75
  ) {
75
76
  const analyticsScript = siteScriptRaw ? siteScriptRaw.trim() : "";
76
77
 
77
78
  // Las dimensiones o DataLayer
78
79
  const dynamicValuePrefix = "__SCRIPT:";
79
- const dimensionValues = isObject(dimensions?.values) ? dimensions?.values : {};
80
+ const dimensionValues = isObject(dimensions?.values)
81
+ ? dimensions?.values
82
+ : {};
80
83
  const automaticDimensionValues = generateAutomaticDimensions
81
84
  ? generateAutomaticDimensions(page || {})
82
85
  : {};
@@ -101,7 +104,9 @@ function composeAnalytics(
101
104
  );
102
105
  }
103
106
 
104
- const analyticsDimensions = allDimensions.length ? `{${allDimensions.join(",")}}` : null;
107
+ const analyticsDimensions = allDimensions.length
108
+ ? `{${allDimensions.join(",")}}`
109
+ : null;
105
110
 
106
111
  return {
107
112
  analyticsScript,
@@ -109,25 +114,8 @@ function composeAnalytics(
109
114
  };
110
115
  }
111
116
 
112
- function extractScriptContent(rawInput?: unknown) {
113
- if (typeof rawInput !== "string" || !rawInput) {
114
- return null;
115
- }
116
-
117
- const trimmedInput = rawInput.trim();
118
-
119
- if (!trimmedInput.startsWith("<script>") || !trimmedInput.endsWith("</script>")) {
120
- return null;
121
- }
122
-
123
- const content = trimmedInput.replace(/<script>|<\/script>/g, "").trim();
124
-
125
- return content || null;
126
- }
127
-
128
117
  export {
129
118
  composeAnalytics,
130
- extractScriptContent,
131
119
  filterBodyIntegrationFromPosition,
132
120
  filterHeadIntegrations,
133
121
  filterPositionIntegrations,
@@ -1,5 +1,11 @@
1
- import { GriddoFavicon } from "./GriddoFavicon";
1
+ //
2
+ // Griddo CX library react export file.
3
+ // This file exports functions to use in the SSG's frameworks.
4
+ //
5
+ // import { ... } from "@griddo/cx/react";
6
+ //
7
+
8
+ import { Favicon } from "./Favicon";
2
9
  import { GriddoIntegrations } from "./GriddoIntegrations";
3
- import { GriddoOpenGraph } from "./GriddoOpenGraph";
4
10
 
5
- export { GriddoFavicon, GriddoIntegrations, GriddoOpenGraph };
11
+ export { Favicon, GriddoIntegrations };
@@ -0,0 +1,14 @@
1
+ import { MemoryRegister, Register } from "../services/register";
2
+
3
+ const entries = {
4
+ API_RESPONSE_TOO_BIG: {
5
+ title: "API response size is too large",
6
+ description:
7
+ "API response size is too large and may affect rendering performance",
8
+ entries: [],
9
+ },
10
+ };
11
+
12
+ const register = new Register(new MemoryRegister(entries));
13
+
14
+ export default register;
@@ -0,0 +1,14 @@
1
+ import { MemoryRegister, Register } from "../services/register";
2
+
3
+ const entries = {
4
+ GATSBY_PAGE_SIZE_TOO_BIG: {
5
+ title: "Gatsby JSON page size is too large",
6
+ description:
7
+ "The JSON of some Gatsby pages (page-data folder) are too large and may affect rendering performance",
8
+ entries: [],
9
+ },
10
+ };
11
+
12
+ const register = new Register(new MemoryRegister(entries));
13
+
14
+ export default register;
@@ -0,0 +1,4 @@
1
+ import apiRegister from "./api";
2
+ import gatsbyRegister from "./gatsby";
3
+
4
+ export { apiRegister, gatsbyRegister };
@@ -1,21 +1,23 @@
1
- import type { AuthHeaders } from "../shared/types/api";
1
+ import type { AuthHeaders } from "../types/api";
2
2
 
3
- import { throwError } from "../core/errors";
4
- import { LOGIN } from "../shared/endpoints";
5
- import { GRIDDO_BOT_PASSWORD, GRIDDO_BOT_USER } from "../shared/envs";
6
- import { LoginError } from "../shared/errors";
3
+ import { endpoints, envs } from "../constants";
4
+ import { throwError } from "../errors";
5
+ import { LoginError } from "../errors/errors-data";
7
6
 
7
+ /**
8
+ * Service for authentication in the Griddo Private API
9
+ */
8
10
  class AuthService {
9
11
  headers: AuthHeaders | undefined;
10
12
 
11
13
  async login() {
12
14
  try {
13
- const response = await fetch(LOGIN, {
15
+ const response = await fetch(endpoints.LOGIN, {
14
16
  method: "POST",
15
17
  headers: { "Content-Type": "application/json", Connection: "close" },
16
18
  body: JSON.stringify({
17
- username: GRIDDO_BOT_USER,
18
- password: GRIDDO_BOT_PASSWORD,
19
+ username: envs.GRIDDO_BOT_USER,
20
+ password: envs.GRIDDO_BOT_PASSWORD,
19
21
  }),
20
22
  });
21
23
 
@@ -1,31 +1,16 @@
1
- import type { Domains } from "../shared/types/global";
1
+ import type { Domains } from "../types/global";
2
2
 
3
- import { throwError } from "../core/errors";
4
- import { GriddoLog } from "../core/GriddoLog";
5
- import { DOMAINS } from "../shared/endpoints";
6
- import { NoDomainsFoundError } from "../shared/errors";
7
- import { get } from "./api";
3
+ import { endpoints } from "../constants";
4
+ import { get } from "../utils/api";
8
5
 
9
6
  /**
10
- * Return an array of domains name (string) of the current instance.
7
+ * Get an array of available domain.
11
8
  */
12
- async function getInstanceDomains() {
13
- const domains = await get<Domains>({
14
- endpoint: DOMAINS,
9
+ async function getAllDomains() {
10
+ return get<Domains>({
11
+ endpoint: endpoints.DOMAINS,
15
12
  useApiCacheDir: false,
16
13
  });
17
-
18
- if (!domains.length) {
19
- throwError(NoDomainsFoundError);
20
- }
21
-
22
- GriddoLog.verbose(`getting domains names (${domains.length})`);
23
-
24
- const filteredDomains = domains
25
- .filter(({ slug }) => !!slug)
26
- .map(({ slug }) => slug.replace("/", ""));
27
-
28
- return [...new Set(filteredDomains)];
29
14
  }
30
15
 
31
- export { getInstanceDomains };
16
+ export { getAllDomains };
@@ -1,12 +1,12 @@
1
- import type { Footer, Header } from "../shared/types/navigation";
2
- import type { APIPageObject } from "../shared/types/pages";
1
+ import type { Footer, Header } from "../types/navigation";
2
+ import type { APIPageObject } from "../types/pages";
3
3
 
4
4
  class NavigationService {
5
5
  private _defaultHeaders: Record<string, Header>;
6
6
  private _defaultFooters: Record<string, Footer>;
7
7
  private _navigations: {
8
- headers: Header[];
9
- footers: Footer[];
8
+ headers: Array<Header>;
9
+ footers: Array<Footer>;
10
10
  };
11
11
 
12
12
  constructor() {
@@ -53,11 +53,11 @@ class NavigationService {
53
53
  }
54
54
 
55
55
  getRightLanguage(
56
- list: {
56
+ list: Array<{
57
57
  language: number;
58
- navigationLanguages: { navigationId: number }[];
58
+ navigationLanguages: Array<{ navigationId: number }>;
59
59
  id: number;
60
- }[],
60
+ }>,
61
61
  id: number,
62
62
  language: number,
63
63
  ) {
@@ -68,7 +68,9 @@ class NavigationService {
68
68
  const rightLanguageItem = list.find(
69
69
  (item) =>
70
70
  item.language === language &&
71
- item.navigationLanguages?.find((version) => version.navigationId === id),
71
+ item.navigationLanguages?.find(
72
+ (version) => version.navigationId === id,
73
+ ),
72
74
  );
73
75
 
74
76
  const result = rightLanguageItem || list.find((item) => item.id === id);
@@ -85,15 +87,19 @@ class NavigationService {
85
87
  }
86
88
 
87
89
  getPageNavigations(page: APIPageObject) {
88
- const { header: pageHeader, footer: pageFooter, language, template, templateConfig } = page;
89
- const { templateType } = template;
90
- const { defaultHeader, defaultFooter, templates } = templateConfig;
90
+ const {
91
+ header: pageHeader,
92
+ footer: pageFooter,
93
+ language,
94
+ template: { templateType },
95
+ templateConfig: { defaultHeader, defaultFooter, templates },
96
+ } = page;
91
97
 
92
98
  // The navigations would be:
93
99
  // - The one with the page or ...
94
100
  // - The one defined for that template or ...
95
101
  // - The one you have defined for that data package
96
- const getValidNavigation = (values: (number | unknown)[]) => {
102
+ const getValidNavigation = (values: Array<number | unknown>) => {
97
103
  const fineNavigation = values.find((item) => typeof item === "number");
98
104
 
99
105
  return typeof fineNavigation === "number" ? fineNavigation : null;