@griddo/cx 11.9.17-rc.1 → 11.10.0

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 +13 -240
  2. package/build/commands/end-render.d.ts +0 -1
  3. package/build/commands/end-render.js +31 -0
  4. package/build/commands/end-render.js.map +7 -0
  5. package/build/commands/prepare-assets-directory.js +9 -0
  6. package/build/commands/prepare-assets-directory.js.map +7 -0
  7. package/build/commands/prepare-domains-render.js +40 -0
  8. package/build/commands/prepare-domains-render.js.map +7 -0
  9. package/build/commands/reset-render.d.ts +0 -1
  10. package/build/commands/reset-render.js +31 -0
  11. package/build/commands/reset-render.js.map +7 -0
  12. package/build/commands/single-domain-upload-search-content.d.ts +1 -0
  13. package/build/commands/start-render.d.ts +0 -1
  14. package/build/commands/start-render.js +66 -0
  15. package/build/commands/start-render.js.map +7 -0
  16. package/build/commands/upload-search-content.d.ts +0 -1
  17. package/build/commands/upload-search-content.js +32 -0
  18. package/build/commands/upload-search-content.js.map +7 -0
  19. package/build/core/GriddoLog.d.ts +16 -0
  20. package/build/{utils/health-checks.d.ts → core/check-env-health.d.ts} +4 -2
  21. package/build/core/db-class.d.ts +11 -0
  22. package/build/core/db.d.ts +4 -0
  23. package/build/core/dist-rollback.d.ts +11 -0
  24. package/build/core/errors.d.ts +26 -0
  25. package/build/core/fs.d.ts +69 -0
  26. package/build/core/life-cycle.d.ts +26 -0
  27. package/build/core/logger.d.ts +18 -0
  28. package/build/core/objects.d.ts +11 -0
  29. package/build/core/print-logos.d.ts +5 -0
  30. package/build/index.d.ts +10 -29
  31. package/build/index.js +404 -73
  32. package/build/react/DynamicScript/index.d.ts +4 -0
  33. package/build/react/GriddoFavicon/index.d.ts +4 -0
  34. package/build/react/GriddoIntegrations/index.d.ts +3 -4
  35. package/build/react/GriddoIntegrations/utils.d.ts +7 -6
  36. package/build/react/GriddoOpenGraph/index.d.ts +10 -0
  37. package/build/react/index.d.ts +3 -2
  38. package/build/react/index.js +1 -3
  39. package/build/{utils → services}/api.d.ts +1 -1
  40. package/build/services/auth.d.ts +2 -5
  41. package/build/services/domains.d.ts +3 -4
  42. package/build/services/manage-sites.d.ts +22 -0
  43. package/build/services/manage-store.d.ts +32 -0
  44. package/build/services/navigation.d.ts +16 -16
  45. package/build/{utils → services}/pages.d.ts +3 -3
  46. package/build/services/reference-fields.d.ts +3 -3
  47. package/build/services/render-artifacts.d.ts +6 -0
  48. package/build/services/render.d.ts +70 -0
  49. package/build/services/robots.d.ts +2 -19
  50. package/build/services/sitemaps.d.ts +5 -0
  51. package/build/services/sites.d.ts +8 -5
  52. package/build/services/store.d.ts +10 -1
  53. package/build/shared/context.d.ts +36 -0
  54. package/build/shared/envs.d.ts +17 -0
  55. package/build/{errors/errors-data.d.ts → shared/errors.d.ts} +5 -3
  56. package/build/shared/npm-modules/brush.d.ts +18 -0
  57. package/build/shared/npm-modules/find-up-simple.d.ts +34 -0
  58. package/build/shared/npm-modules/pkg-dir.d.ts +7 -0
  59. package/build/shared/npm-modules/xml-parser.d.ts +4 -0
  60. package/build/{types → shared/types}/api.d.ts +18 -18
  61. package/build/{types → shared/types}/global.d.ts +15 -16
  62. package/build/{types → shared/types}/navigation.d.ts +5 -5
  63. package/build/{types → shared/types}/pages.d.ts +9 -9
  64. package/build/shared/types/render.d.ts +56 -0
  65. package/build/{types → shared/types}/sites.d.ts +18 -19
  66. package/build/shared/types.d.ts +15 -0
  67. package/build/ssg-adapters/gatsby/actions/clean.d.ts +3 -0
  68. package/build/ssg-adapters/gatsby/actions/close.d.ts +3 -0
  69. package/build/ssg-adapters/gatsby/actions/data.d.ts +2 -0
  70. package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +2 -0
  71. package/build/ssg-adapters/gatsby/actions/init.d.ts +2 -0
  72. package/build/ssg-adapters/gatsby/actions/logs.d.ts +3 -0
  73. package/build/ssg-adapters/gatsby/actions/meta.d.ts +2 -0
  74. package/build/ssg-adapters/gatsby/actions/prepare.d.ts +2 -0
  75. package/build/ssg-adapters/gatsby/actions/relocation.d.ts +2 -0
  76. package/build/ssg-adapters/gatsby/actions/restore.d.ts +3 -0
  77. package/build/ssg-adapters/gatsby/actions/ssg.d.ts +3 -0
  78. package/build/ssg-adapters/gatsby/actions/sync.d.ts +3 -0
  79. package/build/ssg-adapters/gatsby/index.d.ts +9 -0
  80. package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +4 -0
  81. package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +15 -0
  82. package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +7 -0
  83. package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +7 -0
  84. package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +18 -0
  85. package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +26 -0
  86. package/build/ssg-adapters/gatsby/shared/types.d.ts +34 -0
  87. package/cli.mjs +231 -0
  88. package/exporter/build-esbuild.noop +42 -0
  89. package/exporter/build.sh +16 -24
  90. package/exporter/commands/README.md +142 -0
  91. package/exporter/commands/end-render.ts +53 -87
  92. package/exporter/commands/prepare-assets-directory.ts +35 -0
  93. package/exporter/commands/prepare-domains-render.ts +150 -33
  94. package/exporter/commands/reset-render.ts +13 -8
  95. package/exporter/commands/single-domain-upload-search-content.ts +206 -0
  96. package/exporter/commands/start-render.ts +14 -65
  97. package/exporter/commands/upload-search-content.ts +204 -26
  98. package/exporter/core/GriddoLog.ts +45 -0
  99. package/exporter/core/check-env-health.ts +203 -0
  100. package/exporter/core/db-class.ts +54 -0
  101. package/exporter/core/db.ts +33 -0
  102. package/exporter/core/dist-rollback.ts +49 -0
  103. package/exporter/core/errors.ts +93 -0
  104. package/exporter/core/fs.ts +385 -0
  105. package/exporter/{utils → core}/images.ts +1 -6
  106. package/exporter/{utils → core}/instance.ts +9 -13
  107. package/exporter/core/life-cycle.ts +73 -0
  108. package/exporter/core/logger.ts +137 -0
  109. package/exporter/core/objects.ts +37 -0
  110. package/exporter/core/print-logos.ts +21 -0
  111. package/exporter/index.ts +14 -56
  112. package/exporter/react/DynamicScript/index.tsx +33 -0
  113. package/exporter/react/{Favicon → GriddoFavicon}/index.tsx +3 -9
  114. package/exporter/react/GriddoIntegrations/index.tsx +17 -23
  115. package/exporter/react/GriddoIntegrations/utils.ts +24 -12
  116. package/exporter/react/GriddoOpenGraph/index.tsx +39 -0
  117. package/exporter/react/index.tsx +3 -9
  118. package/exporter/services/api.ts +306 -0
  119. package/exporter/services/auth.ts +8 -10
  120. package/exporter/services/domains.ts +23 -8
  121. package/exporter/services/manage-sites.ts +116 -0
  122. package/exporter/services/manage-store.ts +173 -0
  123. package/exporter/services/navigation.ts +12 -18
  124. package/exporter/{utils → services}/pages.ts +27 -92
  125. package/exporter/services/reference-fields.ts +14 -32
  126. package/exporter/services/render-artifacts.ts +44 -0
  127. package/exporter/services/render.ts +229 -0
  128. package/exporter/services/robots.ts +33 -61
  129. package/exporter/services/sitemaps.ts +129 -0
  130. package/exporter/services/sites.ts +40 -28
  131. package/exporter/services/store.ts +354 -321
  132. package/exporter/shared/context.ts +49 -0
  133. package/exporter/{constants → shared}/endpoints.ts +12 -11
  134. package/exporter/shared/envs.ts +58 -0
  135. package/exporter/{errors/errors-data.ts → shared/errors.ts} +24 -14
  136. package/exporter/shared/npm-modules/README.md +36 -0
  137. package/exporter/shared/npm-modules/brush.ts +34 -0
  138. package/exporter/shared/npm-modules/find-up-simple.ts +100 -0
  139. package/exporter/shared/npm-modules/pkg-dir.ts +17 -0
  140. package/exporter/shared/npm-modules/xml-parser.ts +57 -0
  141. package/exporter/{types → shared/types}/api.ts +40 -41
  142. package/exporter/{types → shared/types}/global.ts +17 -21
  143. package/exporter/{types → shared/types}/navigation.ts +3 -3
  144. package/exporter/{types → shared/types}/pages.ts +10 -11
  145. package/exporter/shared/types/render.ts +65 -0
  146. package/exporter/{types → shared/types}/sites.ts +18 -19
  147. package/exporter/shared/types.ts +15 -0
  148. package/exporter/ssg-adapters/gatsby/actions/clean.ts +26 -0
  149. package/exporter/ssg-adapters/gatsby/actions/close.ts +17 -0
  150. package/exporter/ssg-adapters/gatsby/actions/data.ts +22 -0
  151. package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +10 -0
  152. package/exporter/ssg-adapters/gatsby/actions/init.ts +12 -0
  153. package/exporter/ssg-adapters/gatsby/actions/logs.ts +10 -0
  154. package/exporter/ssg-adapters/gatsby/actions/meta.ts +13 -0
  155. package/exporter/ssg-adapters/gatsby/actions/prepare.ts +9 -0
  156. package/exporter/ssg-adapters/gatsby/actions/relocation.ts +15 -0
  157. package/exporter/ssg-adapters/gatsby/actions/restore.ts +21 -0
  158. package/exporter/ssg-adapters/gatsby/actions/ssg.ts +12 -0
  159. package/exporter/ssg-adapters/gatsby/actions/sync.ts +65 -0
  160. package/exporter/ssg-adapters/gatsby/index.ts +117 -0
  161. package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +17 -0
  162. package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +128 -0
  163. package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +75 -0
  164. package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +58 -0
  165. package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +33 -0
  166. package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +298 -0
  167. package/exporter/ssg-adapters/gatsby/shared/types.ts +35 -0
  168. package/gatsby-browser.tsx +41 -58
  169. package/gatsby-config.ts +10 -17
  170. package/gatsby-node.ts +20 -79
  171. package/gatsby-ssr.tsx +2 -1
  172. package/package.json +41 -78
  173. package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
  174. package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
  175. package/src/components/Head.tsx +28 -73
  176. package/src/components/template.tsx +6 -29
  177. package/src/gatsby-node-utils.ts +81 -2
  178. package/src/html.tsx +2 -11
  179. package/src/types.ts +3 -3
  180. package/tsconfig.commands.json +36 -0
  181. package/tsconfig.exporter.json +21 -0
  182. package/tsconfig.json +5 -3
  183. package/build/adapters/gatsby/index.d.ts +0 -4
  184. package/build/adapters/gatsby/utils.d.ts +0 -26
  185. package/build/artifacts/index.d.ts +0 -6
  186. package/build/constants/envs.d.ts +0 -37
  187. package/build/constants/index.d.ts +0 -57
  188. package/build/end-render.js +0 -74
  189. package/build/end-render.js.map +0 -7
  190. package/build/errors/index.d.ts +0 -15
  191. package/build/index.js.map +0 -7
  192. package/build/prepare-domains-render.js +0 -73
  193. package/build/prepare-domains-render.js.map +0 -7
  194. package/build/react/Favicon/index.d.ts +0 -5
  195. package/build/registers/api.d.ts +0 -9
  196. package/build/registers/gatsby.d.ts +0 -9
  197. package/build/registers/index.d.ts +0 -3
  198. package/build/reset-render.js +0 -74
  199. package/build/reset-render.js.map +0 -7
  200. package/build/services/register.d.ts +0 -36
  201. package/build/services/settings.d.ts +0 -4
  202. package/build/start-render.js +0 -100
  203. package/build/start-render.js.map +0 -7
  204. package/build/upload-search-content.js +0 -74
  205. package/build/upload-search-content.js.map +0 -7
  206. package/build/utils/alerts.d.ts +0 -3
  207. package/build/utils/cache.d.ts +0 -35
  208. package/build/utils/core-utils.d.ts +0 -107
  209. package/build/utils/create-build-data.d.ts +0 -8
  210. package/build/utils/domains.d.ts +0 -13
  211. package/build/utils/folders.d.ts +0 -53
  212. package/build/utils/loggin.d.ts +0 -51
  213. package/build/utils/render.d.ts +0 -13
  214. package/build/utils/searches.d.ts +0 -15
  215. package/build/utils/sites.d.ts +0 -31
  216. package/build/utils/store.d.ts +0 -81
  217. package/cx.config.d.ts +0 -5
  218. package/cx.config.js +0 -36
  219. package/exporter/adapters/gatsby/index.ts +0 -182
  220. package/exporter/adapters/gatsby/utils.ts +0 -186
  221. package/exporter/artifacts/README.md +0 -34
  222. package/exporter/artifacts/index.ts +0 -33
  223. package/exporter/commands/move-assets.ts +0 -11
  224. package/exporter/constants/envs.ts +0 -94
  225. package/exporter/constants/index.ts +0 -129
  226. package/exporter/errors/index.ts +0 -40
  227. package/exporter/registers/api.ts +0 -14
  228. package/exporter/registers/gatsby.ts +0 -14
  229. package/exporter/registers/index.ts +0 -4
  230. package/exporter/services/register.ts +0 -113
  231. package/exporter/services/settings.ts +0 -17
  232. package/exporter/utils/alerts.ts +0 -29
  233. package/exporter/utils/api.ts +0 -243
  234. package/exporter/utils/cache.ts +0 -142
  235. package/exporter/utils/core-utils.ts +0 -458
  236. package/exporter/utils/create-build-data.ts +0 -17
  237. package/exporter/utils/domains.ts +0 -39
  238. package/exporter/utils/folders.ts +0 -320
  239. package/exporter/utils/health-checks.ts +0 -64
  240. package/exporter/utils/loggin.ts +0 -184
  241. package/exporter/utils/render.ts +0 -71
  242. package/exporter/utils/searches.ts +0 -156
  243. package/exporter/utils/sites.ts +0 -312
  244. package/exporter/utils/store.ts +0 -314
  245. package/src/README.md +0 -7
  246. package/start-render.js +0 -7
  247. /package/build/commands/{move-assets.d.ts → prepare-assets-directory.d.ts} +0 -0
  248. /package/build/{utils → core}/images.d.ts +0 -0
  249. /package/build/{utils → core}/instance.d.ts +0 -0
  250. /package/build/react/{Favicon → GriddoFavicon}/utils.d.ts +0 -0
  251. /package/build/{constants → shared}/endpoints.d.ts +0 -0
  252. /package/build/{types → shared/types}/templates.d.ts +0 -0
  253. /package/exporter/react/{Favicon → GriddoFavicon}/utils.ts +0 -0
  254. /package/exporter/{types → shared/types}/templates.ts +0 -0
@@ -0,0 +1,49 @@
1
+ import type { PlaceholderPath, RenderArtifacts } from "./types/global";
2
+ import type { RenderMode } from "./types/render";
3
+
4
+ interface RenderContextProps<T> {
5
+ domain: string;
6
+ renderMode: RenderMode;
7
+ pathsHydratedWithDomain: Record<PlaceholderPath, string>;
8
+ ssg: T;
9
+ renderMetadata: {
10
+ griddoVersion: string;
11
+ buildReportFileName: string;
12
+ };
13
+ renderArtifacts: RenderArtifacts;
14
+ }
15
+
16
+ /**
17
+ * Encapsulates the state, configuration, and artifacts for a single SSG
18
+ * render process.
19
+ *
20
+ * This class is instantiated at the beginning of a render and passed through
21
+ * each lifecycle step, providing a centralized and consistent context for all
22
+ * operations. It is agnostic to the specific SSG being used.
23
+ */
24
+ export class RenderContext<T = unknown> {
25
+ readonly domain: string;
26
+ readonly renderMode: RenderMode;
27
+ readonly pathsHydratedWithDomain: Record<PlaceholderPath, string>;
28
+ pagesToCreate: number[] = [];
29
+ pagesToDelete: number[] = [];
30
+ ssg: T;
31
+ renderMetadata: { griddoVersion: string; buildReportFileName: string };
32
+ renderArtifacts: RenderArtifacts;
33
+
34
+ constructor({
35
+ domain,
36
+ renderMode,
37
+ ssg,
38
+ pathsHydratedWithDomain,
39
+ renderMetadata,
40
+ renderArtifacts,
41
+ }: RenderContextProps<T>) {
42
+ this.domain = domain;
43
+ this.renderMode = renderMode;
44
+ this.pathsHydratedWithDomain = pathsHydratedWithDomain;
45
+ this.renderMetadata = renderMetadata;
46
+ this.renderArtifacts = renderArtifacts;
47
+ this.ssg = ssg;
48
+ }
49
+ }
@@ -1,6 +1,5 @@
1
- import { GRIDDO_API_URL, GRIDDO_PUBLIC_API_URL } from "./envs";
2
-
3
- const WITH_URI = `${GRIDDO_API_URL}/site/`;
1
+ const GRIDDO_API_URL = process.env.GRIDDO_API_URL;
2
+ const GRIDDO_PUBLIC_API_URL = process.env.GRIDDO_PUBLIC_API_URL;
4
3
 
5
4
  const AI_EMBEDDINGS = `${GRIDDO_API_URL}/ai/embeddings`;
6
5
  const ALERT = `${GRIDDO_PUBLIC_API_URL}/alert`;
@@ -13,14 +12,16 @@ const ROBOTS = `${GRIDDO_API_URL}/domains/robots`;
13
12
  const SEARCH = `${GRIDDO_API_URL}/search`;
14
13
  const SETTINGS = `${GRIDDO_API_URL}/settings`;
15
14
 
16
- const BUILD_END = [WITH_URI, "/build/end"];
17
- const BUILD_START = [WITH_URI, "/build/start"];
18
- const GET_PAGES = [WITH_URI, "/pages?pagination=false"];
19
- const GET_REFERENCE_FIELD_DATA = [WITH_URI, "/distributor"];
20
- const GET_SITEMAP = [WITH_URI, "/sitemap"];
21
- const INFO = [WITH_URI, "/all"];
22
- const LANGUAGES = [WITH_URI, "/languages"];
23
- const SOCIALS = [WITH_URI, "/socials"];
15
+ // Site
16
+ const SITE_URI = `${GRIDDO_API_URL}/site/`;
17
+ const BUILD_END = [SITE_URI, "/build/end"];
18
+ const BUILD_START = [SITE_URI, "/build/start"];
19
+ const GET_PAGES = [SITE_URI, "/pages?pagination=false"];
20
+ const GET_REFERENCE_FIELD_DATA = [SITE_URI, "/distributor"];
21
+ const GET_SITEMAP = [SITE_URI, "/sitemap"];
22
+ const INFO = [SITE_URI, "/all"];
23
+ const LANGUAGES = [SITE_URI, "/languages"];
24
+ const SOCIALS = [SITE_URI, "/socials"];
24
25
 
25
26
  export {
26
27
  AI_EMBEDDINGS,
@@ -0,0 +1,58 @@
1
+ const { env } = process;
2
+
3
+ /**
4
+ * Returns true/false from string
5
+ */
6
+ function envIsTruthy(value?: string): boolean {
7
+ if (!value) return false;
8
+
9
+ switch (value.trim().toLowerCase()) {
10
+ case "1":
11
+ case "true":
12
+ case "yes":
13
+ case "y":
14
+ case "on":
15
+ return true;
16
+ default:
17
+ return false;
18
+ }
19
+ }
20
+
21
+ // Credentials
22
+ const GRIDDO_API_URL = env.GRIDDO_API_URL || env.API_URL;
23
+ const GRIDDO_PUBLIC_API_URL = env.GRIDDO_PUBLIC_API_URL || env.PUBLIC_API_URL;
24
+ const GRIDDO_BOT_USER = env.botEmail || env.GRIDDO_BOT_USER;
25
+ const GRIDDO_BOT_PASSWORD = env.botPassword || env.GRIDDO_BOT_PASSWORD;
26
+
27
+ // Rendering
28
+ const GRIDDO_API_CONCURRENCY_COUNT = Number.parseInt(env.GRIDDO_API_CONCURRENCY_COUNT || "10");
29
+ const GRIDDO_SKIP_BUILD_CHECKS = envIsTruthy(env.GRIDDO_SKIP_BUILD_CHECKS);
30
+ const GRIDDO_BUILD_LOGS = envIsTruthy(env.GRIDDO_BUILD_LOGS);
31
+ const GRIDDO_BUILD_LOGS_BUFFER_SIZE = Number.parseInt(env.GRIDDO_BUILD_LOGS_BUFFER_SIZE || "500");
32
+ const GRIDDO_SSG_VERBOSE_LOGS = envIsTruthy(env.GRIDDO_SSG_VERBOSE_LOGS);
33
+ const GRIDDO_SEARCH_FEATURE = envIsTruthy(env.GRIDDO_SEARCH_FEATURE);
34
+ const GRIDDO_ASSET_PREFIX = env.GRIDDO_ASSET_PREFIX || env.ASSET_PREFIX;
35
+ const GRIDDO_REACT_APP_INSTANCE = env.GRIDDO_REACT_APP_INSTANCE || env.REACT_APP_INSTANCE;
36
+ const GRIDDO_AI_EMBEDDINGS = envIsTruthy(env.GRIDDO_AI_EMBEDDINGS);
37
+ const GRIDDO_VERBOSE_LOGS = envIsTruthy(env.GRIDDO_VERBOSE_LOGS);
38
+ const GRIDDO_USE_DIST_BACKUP = envIsTruthy(env.GRIDDO_USE_DIST_BACKUP);
39
+ const GRIDDO_SSG_BUNDLE_ANALYZER = envIsTruthy(env.GRIDDO_SSG_BUNDLE_ANALYZER);
40
+
41
+ export {
42
+ GRIDDO_AI_EMBEDDINGS,
43
+ GRIDDO_API_CONCURRENCY_COUNT,
44
+ GRIDDO_API_URL,
45
+ GRIDDO_ASSET_PREFIX,
46
+ GRIDDO_BOT_PASSWORD,
47
+ GRIDDO_BOT_USER,
48
+ GRIDDO_BUILD_LOGS,
49
+ GRIDDO_BUILD_LOGS_BUFFER_SIZE,
50
+ GRIDDO_PUBLIC_API_URL,
51
+ GRIDDO_REACT_APP_INSTANCE,
52
+ GRIDDO_SEARCH_FEATURE,
53
+ GRIDDO_SKIP_BUILD_CHECKS,
54
+ GRIDDO_SSG_BUNDLE_ANALYZER,
55
+ GRIDDO_SSG_VERBOSE_LOGS,
56
+ GRIDDO_USE_DIST_BACKUP,
57
+ GRIDDO_VERBOSE_LOGS,
58
+ };
@@ -7,11 +7,13 @@
7
7
  * obligatorily.
8
8
  */
9
9
 
10
- import type { ErrorData } from ".";
11
10
  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"
15
17
  | "ErrorInSSGBuildProcess"
16
18
  | "LifecycleExecutionError"
17
19
  | "LoginError"
@@ -20,6 +22,7 @@ type ErrorsType =
20
22
  | "ReadFromStoreError"
21
23
  | "ReferenceFieldSourcesNotFoundError"
22
24
  | "RenderUUIDError"
25
+ | "UploadSearchError"
23
26
  | "WriteToStoreError";
24
27
 
25
28
  const ArtifactError: ErrorData = {
@@ -30,19 +33,13 @@ const ArtifactError: ErrorData = {
30
33
  hint: "Have there been any recent deployments? These can delete directories from the current render.",
31
34
  };
32
35
 
33
- const ErrorInSSGBuildProcess = (
34
- command: SpawnSyncReturns<string>,
35
- ): ErrorData => ({
36
+ const ErrorInSSGBuildProcess = (command: SpawnSyncReturns<string>): ErrorData => ({
36
37
  error: "ErrorInSSGBuildProcess",
37
38
  message: `Error in SSG build process: ${JSON.stringify(command)}`,
38
- expected:
39
- "This can happen if there was a problem with the SSG build process.",
39
+ expected: "This can happen if there was a problem with the SSG build process.",
40
40
  });
41
41
 
42
- const LifecycleExecutionError = (
43
- attempts: number,
44
- name: string,
45
- ): ErrorData => ({
42
+ const LifecycleExecutionError = (attempts: number, name: string): ErrorData => ({
46
43
  error: "LifecycleExecutionError",
47
44
  message: `Exceeded maximum retry attempts (${attempts}) for ${name} LifeCycle`,
48
45
  });
@@ -50,14 +47,12 @@ const LifecycleExecutionError = (
50
47
  const LoginError: ErrorData = {
51
48
  error: "LoginError",
52
49
  message: "There was a problem logging in to the API",
53
- expected:
54
- "This happens if the API is currently not working or the credentials are incorrect.",
50
+ expected: "This happens if the API is currently not working or the credentials are incorrect.",
55
51
  };
56
52
 
57
53
  const NoDomainsFoundError: ErrorData = {
58
54
  error: "NoDomainsFoundError",
59
- message:
60
- "No domains were found in this instance. The process cannot continue.",
55
+ message: "No domains were found in this instance. The process cannot continue.",
61
56
  expected:
62
57
  "This may happen if the API is not functioning, or the site is not properly configured, or the domains are not registered.",
63
58
  hint: "You can contact the instance administrator.",
@@ -98,8 +93,22 @@ const WriteToStoreError: ErrorData = {
98
93
  hint: "There may be an issue such as lack of space or permissions preventing the file from being written.",
99
94
  };
100
95
 
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
+
101
109
  export {
102
110
  ArtifactError,
111
+ CheckHealthError,
103
112
  ErrorInSSGBuildProcess,
104
113
  LifecycleExecutionError,
105
114
  LoginError,
@@ -108,6 +117,7 @@ export {
108
117
  ReadFromStoreError,
109
118
  ReferenceFieldSourcesNotFoundError,
110
119
  RenderUUIDError,
120
+ UploadSearchError,
111
121
  WriteToStoreError,
112
122
  type ErrorsType,
113
123
  };
@@ -0,0 +1,36 @@
1
+ # Dependencias Externas Incluidas
2
+
3
+ Esta carpeta contiene dependencias externas que han sido incluidas directamente en el repositorio para evitar tener que fetchearlas desde npm en cada instalación del software.
4
+
5
+ ## Razón
6
+
7
+ Este software se instala frecuentemente y estas dependencias pequeñas se incluyen directamente para:
8
+ - Reducir el tiempo de instalación
9
+ - Evitar dependencias de red durante el setup
10
+ - Mantener versiones específicas y estables
11
+
12
+ ## Archivos incluidos
13
+
14
+ - **`find-up-simple.ts`** - Versión simplificada de `find-up` para buscar archivos hacia arriba en el árbol de directorios
15
+ - **`pkg-dir.ts`** - Encuentra el directorio raíz del paquete (que contiene `package.json`)
16
+ - **`xml-parser.ts`** - Parser simple de XML para sitemaps (Desarrollado por Griddo)
17
+ - **`brush.ts`** - Version ultra-reducida de utilidad para añadir colores a texto parecido a chalk o kleur. (Desarrollado por Griddo)
18
+
19
+ ## Nota importante
20
+
21
+ **Este no es código desarrollado por nosotros.** Son adaptaciones o versiones simplificadas de librerías existentes en npm.
22
+
23
+ ## Enlaces para futuras actualizaciones
24
+
25
+ Si en el futuro se decide usar estas dependencias como paquetes npm oficiales:
26
+
27
+ - `find-up-simple`: Basado en [find-up](https://www.npmjs.com/package/find-up)
28
+ - `pkg-dir`: Basado en [pkg-dir](https://www.npmjs.com/package/pkg-dir)
29
+ - `xml-parser`: Parser XML simple (posiblemente reemplazable por [fast-xml-parser](https://www.npmjs.com/package/fast-xml-parser))
30
+
31
+ ## Mantenimiento
32
+
33
+ Estos archivos no requieren actualizaciones frecuentes ya que implementan funcionalidades básicas y estables. Solo actualizar en caso de:
34
+ - Cambios en las APIs de Node.js que los afecten
35
+ - Bugs de seguridad críticos
36
+ - Mejoras de rendimiento significativas
@@ -0,0 +1,34 @@
1
+ //
2
+ // Brush adds color to a string|number, it does not print it!
3
+ // Its simple, no log, no chains, just color in a string|number
4
+ // usage:
5
+ // console.log(brush.green("sucess!"))
6
+ //
7
+
8
+ const RESET = "\x1b[0m";
9
+ const CODES = {
10
+ black: "\x1b[30m",
11
+ red: "\x1b[31m",
12
+ green: "\x1b[32m",
13
+ yellow: "\x1b[33m",
14
+ blue: "\x1b[34m",
15
+ magenta: "\x1b[35m",
16
+ cyan: "\x1b[36m",
17
+ white: "\x1b[37m",
18
+ gray: "\x1b[90m",
19
+ bold: "\x1b[1m",
20
+ dim: "\x1b[2m",
21
+ } as const;
22
+
23
+ type ColorFunction = (text: string | number) => string;
24
+ type ColorName = keyof typeof CODES;
25
+ type Brush = Record<ColorName, ColorFunction>;
26
+
27
+ const brush = {} as Brush;
28
+
29
+ for (const color in CODES) {
30
+ const key = color as ColorName;
31
+ brush[key] = (text: string | number) => `${CODES[key]}${text}${RESET}`;
32
+ }
33
+
34
+ export { brush };
@@ -0,0 +1,100 @@
1
+ import fs from "node:fs";
2
+ import fsPromises from "node:fs/promises";
3
+ import path from "node:path";
4
+ import process from "node:process";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ /**
8
+ * Opciones para controlar el comportamiento de la búsqueda.
9
+ */
10
+ export type Options = {
11
+ /**
12
+ El directorio desde donde empezar a buscar.
13
+ @default process.cwd()
14
+ */
15
+ readonly cwd?: URL | string;
16
+
17
+ /**
18
+ El tipo de ruta a buscar.
19
+ @default 'file'
20
+ */
21
+ readonly type?: "file" | "directory";
22
+
23
+ /**
24
+ Un directorio en el que la búsqueda se detiene si no se encuentran coincidencias.
25
+ @default El directorio raíz del sistema
26
+ */
27
+ readonly stopAt?: URL | string;
28
+ };
29
+
30
+ // Función auxiliar para convertir una URL en una ruta de archivo de tipo string.
31
+ const toPath = (urlOrPath: URL | string | undefined): string | undefined =>
32
+ urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
33
+
34
+ /**
35
+ * Encuentra un archivo o directorio de forma asíncrona subiendo por los directorios padre.
36
+ * @param name - El nombre del archivo o directorio a buscar.
37
+ * @param options - Opciones de búsqueda.
38
+ * @returns La ruta encontrada o `undefined` si no se pudo encontrar.
39
+ */
40
+ export async function findUp(name: string, options: Options = {}): Promise<string | undefined> {
41
+ const { cwd = process.cwd(), type = "file", stopAt: stopAtOption } = options;
42
+
43
+ let directory = path.resolve(toPath(cwd) ?? "");
44
+ const { root } = path.parse(directory);
45
+ const stopAt = stopAtOption ? path.resolve(directory, toPath(stopAtOption)!) : root;
46
+ const isAbsoluteName = path.isAbsolute(name);
47
+
48
+ while (true) {
49
+ const filePath = isAbsoluteName ? name : path.join(directory, name);
50
+ try {
51
+ // eslint-disable-next-line no-await-in-loop
52
+ const stats = await fsPromises.stat(filePath);
53
+ if ((type === "file" && stats.isFile()) || (type === "directory" && stats.isDirectory())) {
54
+ return filePath;
55
+ }
56
+ } catch {
57
+ // Ignora errores (ej. el archivo no existe) y continúa la búsqueda.
58
+ }
59
+
60
+ if (directory === stopAt || directory === root) {
61
+ break;
62
+ }
63
+
64
+ directory = path.dirname(directory);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Encuentra un archivo o directorio de forma síncrona subiendo por los directorios padre.
70
+ * @param name - El nombre del archivo o directorio a buscar.
71
+ * @param options - Opciones de búsqueda.
72
+ * @returns La ruta encontrada o `undefined` si no se pudo encontrar.
73
+ */
74
+ export function findUpSync(name: string, options: Options = {}): string | undefined {
75
+ const { cwd = process.cwd(), type = "file", stopAt: stopAtOption } = options;
76
+
77
+ let directory = path.resolve(toPath(cwd) ?? "");
78
+ const { root } = path.parse(directory);
79
+ const stopAt = stopAtOption ? path.resolve(directory, toPath(stopAtOption)!) : root;
80
+ const isAbsoluteName = path.isAbsolute(name);
81
+
82
+ while (true) {
83
+ const filePath = isAbsoluteName ? name : path.join(directory, name);
84
+ try {
85
+ const stats = fs.statSync(filePath, { throwIfNoEntry: false });
86
+ if ((type === "file" && stats?.isFile()) || (type === "directory" && stats?.isDirectory())) {
87
+ return filePath;
88
+ }
89
+ } catch {
90
+ // En teoría, statSync con `throwIfNoEntry: false` no debería lanzar un error,
91
+ // pero se mantiene por seguridad.
92
+ }
93
+
94
+ if (directory === stopAt || directory === root) {
95
+ break;
96
+ }
97
+
98
+ directory = path.dirname(directory);
99
+ }
100
+ }
@@ -0,0 +1,17 @@
1
+ import path from "node:path";
2
+
3
+ import { findUp, findUpSync } from "./find-up-simple";
4
+
5
+ async function pkgDir(options?: { readonly cwd?: string }) {
6
+ const { cwd } = options || {};
7
+ const filePath = await findUp("package.json", { cwd });
8
+ return filePath && path.dirname(filePath);
9
+ }
10
+
11
+ function pkgDirSync(options?: { readonly cwd?: string }) {
12
+ const { cwd } = options || {};
13
+ const filePath = findUpSync("package.json", { cwd });
14
+ return filePath && path.dirname(filePath);
15
+ }
16
+
17
+ export { pkgDir, pkgDirSync };
@@ -0,0 +1,57 @@
1
+ import type { SitemapItem } from "../types/api";
2
+
3
+ function escapeXml(unsafe: string) {
4
+ return unsafe.replace(/[<>&'"”]/g, (c) => {
5
+ switch (c) {
6
+ case "<":
7
+ return "&lt;";
8
+ case ">":
9
+ return "&gt;";
10
+ case "&":
11
+ return "&amp;";
12
+ case "'":
13
+ return "&apos;";
14
+ case '"':
15
+ return "&quot;";
16
+ case "”":
17
+ return "&quot;";
18
+ default:
19
+ return c;
20
+ }
21
+ });
22
+ }
23
+
24
+ function generateUrlsetXml(pages: SitemapItem[]) {
25
+ const urls = pages
26
+ .map(
27
+ (page) =>
28
+ ` <url>
29
+ <loc>${escapeXml(page.loc)}</loc>
30
+ <lastmod>${page.lastmod}</lastmod>
31
+ <priority>${page.priority}</priority>
32
+ </url>`,
33
+ )
34
+ .join("\n");
35
+
36
+ return `<?xml version="1.0" encoding="UTF-8"?>
37
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
38
+ ${urls}
39
+ </urlset>`;
40
+ }
41
+
42
+ function generateSitemapIndexXml(sitemaps: string[]) {
43
+ const sitemapEntries = sitemaps
44
+ .map(
45
+ (loc) => ` <sitemap>
46
+ <loc>${escapeXml(loc)}</loc>
47
+ </sitemap>`,
48
+ )
49
+ .join("\n");
50
+
51
+ return `<?xml version="1.0" encoding="UTF-8"?>
52
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
53
+ ${sitemapEntries}
54
+ </sitemapindex>`;
55
+ }
56
+
57
+ export { generateSitemapIndexXml, generateUrlsetXml };
@@ -1,60 +1,59 @@
1
+ import type { Core, Fields } from "@griddo/core";
1
2
  import type { Domains, Robots, Settings } from "./global";
2
3
  import type { APIPageObject } from "./pages";
3
4
  import type { Site } from "./sites";
4
- import type { Core, Fields } from "@griddo/core";
5
5
 
6
6
  /** EndSiteRender Body */
7
7
  export type EndSiteRenderBody = {
8
8
  /** Site hashes to publish. */
9
- publishHashes: Array<string>;
9
+ publishHashes: string[];
10
10
  /** Current site hash. */
11
11
  siteHash: string | null;
12
12
  /** Site hashes to unpublish. */
13
- unpublishHashes: Array<string>;
13
+ unpublishHashes: string[];
14
14
  /** Page ids that publish */
15
- publishPagesIds: Array<number>;
15
+ publishPagesIds: number[];
16
16
  };
17
17
 
18
18
  /** ReferenceField Body */
19
19
  export interface ReferenceFieldBody {
20
20
  mode?: "auto" | "manual" | "navigation";
21
21
  order?: string;
22
- sources?: Array<Fields.Source<unknown>>;
22
+ sources?: Fields.Source<unknown>[];
23
23
  quantity?: number;
24
- filter?: Array<unknown>;
24
+ filter?: unknown[];
25
25
  fullRelations?: boolean;
26
26
  allLanguages?: boolean;
27
- fixed?: Array<number>;
27
+ fixed?: number[];
28
28
  referenceId?: number;
29
29
  }
30
30
 
31
31
  /** Describes the props of the body object for the get page */
32
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
- interface PageBody {
34
- /** The title of the page. */
35
- title?: string;
36
- /** The description of the page. */
37
- description?: string;
38
- /** The URL of the page's image. */
39
- image?: string;
40
- /** The ID of the page. */
41
- pageId?: number;
42
- /** The ID of the page's language. */
43
- languageId?: number;
44
- /** The ID of the page's site. */
45
- siteId?: number;
46
- /** The URL of the page. */
47
- url?: string;
48
- /** The template of the page. */
49
- template?: string | null | number;
50
- /** The content of the page. */
51
- content?: string;
52
- /** Additional properties. */
53
- [key: string]: unknown;
54
- }
32
+ // interface PageBody {
33
+ // /** The title of the page. */
34
+ // title?: string;
35
+ // /** The description of the page. */
36
+ // description?: string;
37
+ // /** The URL of the page's image. */
38
+ // image?: string;
39
+ // /** The ID of the page. */
40
+ // pageId?: number;
41
+ // /** The ID of the page's language. */
42
+ // languageId?: number;
43
+ // /** The ID of the page's site. */
44
+ // siteId?: number;
45
+ // /** The URL of the page. */
46
+ // url?: string;
47
+ // /** The template of the page. */
48
+ // template?: string | null | number;
49
+ // /** The content of the page. */
50
+ // content?: string;
51
+ // /** Additional properties. */
52
+ // [key: string]: unknown;
53
+ // }
55
54
 
56
55
  /** Describes an item in a sitemap. */
57
- interface SitemapItem {
56
+ export interface SitemapItem {
58
57
  /** The URL of the page. */
59
58
  loc: string;
60
59
  /** The date the page was last modified. */
@@ -74,7 +73,7 @@ interface URL {
74
73
  }
75
74
 
76
75
  /** Describes the items returned by a sitemap response. */
77
- export type SitemapItems = Record<string, Array<SitemapItem>>;
76
+ export type SitemapItems = Record<string, SitemapItem[]>;
78
77
 
79
78
  /** Describes the response object returned by a Griddo ReferenceField. */
80
79
  export type ReferenceFieldResponse = Fields.QueriedData<unknown>;
@@ -105,7 +104,7 @@ export interface LanguagesResponse {
105
104
  /** Total of languages */
106
105
  totalItems: number;
107
106
  /** Array of languages objects */
108
- items: Array<Core.SiteLanguage>;
107
+ items: Core.SiteLanguage[];
109
108
  }
110
109
 
111
110
  /** Describes common props for api responses. */
@@ -120,12 +119,12 @@ export interface APIRequest {
120
119
  attempt?: number;
121
120
  /**
122
121
  * Headers for the post api fetch
123
- * @shame any
124
- * @todo type this correctly from axios types
125
122
  */
126
- headers?: any; // Record<string, unknown>;
123
+ headers?: Record<string, unknown>;
127
124
  /* Save results in apiCache folder */
128
125
  useApiCacheDir?: boolean;
126
+ /* Save log in the cx log file */
127
+ logToFile?: boolean;
129
128
  }
130
129
 
131
130
  /** Type with the POST request properties. */
@@ -142,11 +141,11 @@ export type PutAPI = APIRequest;
142
141
  /** Response type for the start render API call */
143
142
  export interface StartPageRenderResponse {
144
143
  /** Site hashes to publish */
145
- publishIds: Array<number>;
144
+ publishIds: number[];
146
145
  /** Current site hash */
147
146
  siteHash: string | null;
148
147
  /** Site hashes to unpublish */
149
- unpublishHashes: Array<string>;
148
+ unpublishHashes: string[];
150
149
  }
151
150
 
152
151
  /** Response type for the end render API call */
@@ -160,7 +159,7 @@ export interface EndPageInfoResponse {
160
159
  export type PostEmbeddingsResponse = string;
161
160
 
162
161
  /** Describes a response type for GET all sites */
163
- export type AllSitesReponse = Array<Site>;
162
+ export type AllSitesReponse = Site[];
164
163
 
165
164
  /** Describes a response type for GET one page */
166
165
  export type PageResponse = APIPageObject;
@@ -189,8 +188,8 @@ export interface ShowApiErrorOptions {
189
188
 
190
189
  export interface BuildMetaData {
191
190
  buildProcessData: Record<string, EndSiteRenderBody>;
192
- createdPages: Array<number>;
193
- sitesToPublish: Array<Site>;
191
+ createdPages: number[];
192
+ sitesToPublish: Site[];
194
193
  }
195
194
 
196
195
  export interface Auth {