@griddo/cx 11.7.11 → 11.7.12-rc.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 (302) hide show
  1. package/README.md +27 -226
  2. package/build/adapters/gatsby/actions/clean.js +10 -0
  3. package/build/adapters/gatsby/actions/clean.js.map +1 -0
  4. package/build/adapters/gatsby/actions/close.js +14 -0
  5. package/build/adapters/gatsby/actions/close.js.map +1 -0
  6. package/build/adapters/gatsby/actions/data.js +18 -0
  7. package/build/adapters/gatsby/actions/data.js.map +1 -0
  8. package/build/adapters/gatsby/actions/healthCheck.js +10 -0
  9. package/build/adapters/gatsby/actions/healthCheck.js.map +1 -0
  10. package/build/adapters/gatsby/actions/init.js +22 -0
  11. package/build/adapters/gatsby/actions/init.js.map +1 -0
  12. package/build/adapters/gatsby/actions/logs.js +9 -0
  13. package/build/adapters/gatsby/actions/logs.js.map +1 -0
  14. package/build/adapters/gatsby/actions/meta.js +13 -0
  15. package/build/adapters/gatsby/actions/meta.js.map +1 -0
  16. package/build/adapters/gatsby/actions/prepare.js +9 -0
  17. package/build/adapters/gatsby/actions/prepare.js.map +1 -0
  18. package/build/adapters/gatsby/actions/relocation.js +15 -0
  19. package/build/adapters/gatsby/actions/relocation.js.map +1 -0
  20. package/build/adapters/gatsby/actions/restore.js +26 -0
  21. package/build/adapters/gatsby/actions/restore.js.map +1 -0
  22. package/build/adapters/gatsby/actions/ssg.js +9 -0
  23. package/build/adapters/gatsby/actions/ssg.js.map +1 -0
  24. package/build/adapters/gatsby/actions/sync.js +51 -0
  25. package/build/adapters/gatsby/actions/sync.js.map +1 -0
  26. package/build/adapters/gatsby/index.js +78 -0
  27. package/build/adapters/gatsby/index.js.map +1 -0
  28. package/build/adapters/gatsby/shared/artifacts.js +20 -0
  29. package/build/adapters/gatsby/shared/artifacts.js.map +1 -0
  30. package/build/adapters/gatsby/shared/context.js +31 -0
  31. package/build/adapters/gatsby/shared/context.js.map +1 -0
  32. package/build/adapters/gatsby/shared/diff-assets.js +101 -0
  33. package/build/adapters/gatsby/shared/diff-assets.js.map +1 -0
  34. package/build/adapters/gatsby/shared/extract-assets.js +58 -0
  35. package/build/adapters/gatsby/shared/extract-assets.js.map +1 -0
  36. package/build/adapters/gatsby/shared/gatsby-build.js +55 -0
  37. package/build/adapters/gatsby/shared/gatsby-build.js.map +1 -0
  38. package/build/adapters/gatsby/shared/sync-render.js +210 -0
  39. package/build/adapters/gatsby/shared/sync-render.js.map +1 -0
  40. package/build/adapters/gatsby/shared/types.js +3 -0
  41. package/build/adapters/gatsby/shared/types.js.map +1 -0
  42. package/build/commands/end-render.js +87 -0
  43. package/build/commands/end-render.js.map +1 -0
  44. package/build/commands/prepare-assets-directory.js +30 -0
  45. package/build/commands/prepare-assets-directory.js.map +1 -0
  46. package/build/commands/prepare-domains-render.js +133 -0
  47. package/build/commands/prepare-domains-render.js.map +1 -0
  48. package/build/commands/reset-render.js +21 -0
  49. package/build/commands/reset-render.js.map +1 -0
  50. package/build/commands/start-render.js +44 -0
  51. package/build/commands/start-render.js.map +1 -0
  52. package/build/commands/upload-search-content.js +180 -0
  53. package/build/commands/upload-search-content.js.map +1 -0
  54. package/build/constants/endpoints.js +43 -0
  55. package/build/constants/endpoints.js.map +1 -0
  56. package/build/constants/envs.js +68 -0
  57. package/build/constants/envs.js.map +1 -0
  58. package/build/constants/errors.js +81 -0
  59. package/build/constants/errors.js.map +1 -0
  60. package/build/services/auth.js +40 -0
  61. package/build/services/auth.js.map +1 -0
  62. package/build/services/db-class.js +49 -0
  63. package/build/services/db-class.js.map +1 -0
  64. package/build/services/db.js +34 -0
  65. package/build/services/db.js.map +1 -0
  66. package/build/services/navigation.js +96 -0
  67. package/build/services/navigation.js.map +1 -0
  68. package/build/services/reference-fields.js +131 -0
  69. package/build/services/reference-fields.js.map +1 -0
  70. package/build/services/robots.js +60 -0
  71. package/build/services/robots.js.map +1 -0
  72. package/build/services/sites.js +110 -0
  73. package/build/services/sites.js.map +1 -0
  74. package/build/services/store.js +257 -0
  75. package/build/services/store.js.map +1 -0
  76. package/build/types/api.js +3 -0
  77. package/build/types/api.js.map +1 -0
  78. package/build/types/global.js +3 -0
  79. package/build/types/global.js.map +1 -0
  80. package/build/types/navigation.js +3 -0
  81. package/build/types/navigation.js.map +1 -0
  82. package/build/types/pages.js +3 -0
  83. package/build/types/pages.js.map +1 -0
  84. package/build/types/render.js +10 -0
  85. package/build/types/render.js.map +1 -0
  86. package/build/types/sites.js +3 -0
  87. package/build/types/sites.js.map +1 -0
  88. package/build/types/templates.js +3 -0
  89. package/build/types/templates.js.map +1 -0
  90. package/build/utils/api.js +165 -0
  91. package/build/utils/api.js.map +1 -0
  92. package/build/utils/artifacts.js +38 -0
  93. package/build/utils/artifacts.js.map +1 -0
  94. package/build/utils/brush.js +30 -0
  95. package/build/utils/brush.js.map +1 -0
  96. package/build/utils/cache.js +106 -0
  97. package/build/utils/cache.js.map +1 -0
  98. package/build/utils/check-environment-health.js +69 -0
  99. package/build/utils/check-environment-health.js.map +1 -0
  100. package/build/utils/core-utils.js +270 -0
  101. package/build/utils/core-utils.js.map +1 -0
  102. package/build/utils/domains.js +37 -0
  103. package/build/utils/domains.js.map +1 -0
  104. package/build/utils/errors.js +30 -0
  105. package/build/utils/errors.js.map +1 -0
  106. package/build/utils/folders.js +341 -0
  107. package/build/utils/folders.js.map +1 -0
  108. package/build/utils/images.js +45 -0
  109. package/build/utils/images.js.map +1 -0
  110. package/build/utils/instance.js +66 -0
  111. package/build/utils/instance.js.map +1 -0
  112. package/build/utils/loggin.js +119 -0
  113. package/build/utils/loggin.js.map +1 -0
  114. package/build/utils/npm-deps/find-up-simple.js +75 -0
  115. package/build/utils/npm-deps/find-up-simple.js.map +1 -0
  116. package/build/utils/npm-deps/pkg-dir.js +20 -0
  117. package/build/utils/npm-deps/pkg-dir.js.map +1 -0
  118. package/build/utils/npm-deps/xml-parser.js +49 -0
  119. package/build/utils/npm-deps/xml-parser.js.map +1 -0
  120. package/build/utils/pages.js +359 -0
  121. package/build/utils/pages.js.map +1 -0
  122. package/build/utils/render.js +168 -0
  123. package/build/utils/render.js.map +1 -0
  124. package/build/utils/sitemaps.js +110 -0
  125. package/build/utils/sitemaps.js.map +1 -0
  126. package/build/utils/sites.js +105 -0
  127. package/build/utils/sites.js.map +1 -0
  128. package/build/utils/store.js +193 -0
  129. package/build/utils/store.js.map +1 -0
  130. package/exporter/adapters/gatsby/actions/clean.ts +14 -0
  131. package/exporter/adapters/gatsby/actions/close.ts +20 -0
  132. package/exporter/adapters/gatsby/actions/data.ts +25 -0
  133. package/exporter/adapters/gatsby/actions/healthCheck.ts +10 -0
  134. package/exporter/adapters/gatsby/actions/init.ts +26 -0
  135. package/exporter/adapters/gatsby/actions/logs.ts +10 -0
  136. package/exporter/adapters/gatsby/actions/meta.ts +16 -0
  137. package/exporter/adapters/gatsby/actions/prepare.ts +9 -0
  138. package/exporter/adapters/gatsby/actions/relocation.ts +15 -0
  139. package/exporter/adapters/gatsby/actions/restore.ts +36 -0
  140. package/exporter/adapters/gatsby/actions/ssg.ts +12 -0
  141. package/exporter/adapters/gatsby/actions/sync.ts +71 -0
  142. package/exporter/adapters/gatsby/index.ts +73 -153
  143. package/exporter/adapters/gatsby/shared/artifacts.ts +16 -0
  144. package/exporter/adapters/gatsby/shared/context.ts +50 -0
  145. package/exporter/adapters/gatsby/shared/diff-assets.ts +113 -0
  146. package/exporter/adapters/gatsby/shared/extract-assets.ts +61 -0
  147. package/exporter/adapters/gatsby/shared/gatsby-build.ts +58 -0
  148. package/exporter/adapters/gatsby/shared/sync-render.ts +276 -0
  149. package/exporter/adapters/gatsby/shared/types.ts +35 -0
  150. package/exporter/build-esbuild.noop +42 -0
  151. package/exporter/build.sh +4 -38
  152. package/exporter/commands/end-render.ts +72 -70
  153. package/exporter/commands/prepare-assets-directory.ts +30 -0
  154. package/exporter/commands/prepare-domains-render.ts +143 -31
  155. package/exporter/commands/reset-render.ts +10 -3
  156. package/exporter/commands/start-render.ts +22 -45
  157. package/exporter/commands/upload-search-content.ts +194 -21
  158. package/exporter/constants/endpoints.ts +2 -1
  159. package/exporter/constants/envs.ts +57 -55
  160. package/exporter/{errors/errors-data.ts → constants/errors.ts} +24 -14
  161. package/exporter/services/auth.ts +7 -6
  162. package/exporter/services/db-class.ts +54 -0
  163. package/exporter/services/db.ts +32 -0
  164. package/exporter/services/navigation.ts +4 -10
  165. package/exporter/services/reference-fields.ts +9 -24
  166. package/exporter/services/robots.ts +9 -16
  167. package/exporter/services/sites.ts +36 -24
  168. package/exporter/services/store.ts +107 -96
  169. package/exporter/types/api.ts +27 -28
  170. package/exporter/types/global.ts +8 -11
  171. package/exporter/types/navigation.ts +1 -1
  172. package/exporter/types/pages.ts +2 -3
  173. package/exporter/types/render.ts +59 -0
  174. package/exporter/types/sites.ts +1 -2
  175. package/exporter/utils/api.ts +55 -75
  176. package/exporter/utils/artifacts.ts +38 -0
  177. package/exporter/utils/brush.ts +34 -0
  178. package/exporter/utils/cache.ts +37 -62
  179. package/exporter/utils/check-environment-health.ts +80 -0
  180. package/exporter/utils/core-utils.ts +133 -272
  181. package/exporter/utils/domains.ts +10 -7
  182. package/exporter/{errors/index.ts → utils/errors.ts} +10 -9
  183. package/exporter/utils/folders.ts +163 -98
  184. package/exporter/utils/images.ts +1 -6
  185. package/exporter/utils/instance.ts +9 -13
  186. package/exporter/utils/loggin.ts +44 -91
  187. package/exporter/utils/npm-deps/find-up-simple.ts +100 -0
  188. package/exporter/utils/npm-deps/pkg-dir.ts +17 -0
  189. package/exporter/utils/npm-deps/xml-parser.ts +57 -0
  190. package/exporter/utils/pages.ts +23 -88
  191. package/exporter/utils/render.ts +180 -48
  192. package/exporter/utils/sitemaps.ts +129 -0
  193. package/exporter/utils/sites.ts +19 -197
  194. package/exporter/utils/store.ts +87 -180
  195. package/gatsby-browser.tsx +41 -58
  196. package/gatsby-config.ts +10 -17
  197. package/gatsby-node.ts +17 -78
  198. package/gatsby-ssr.tsx +2 -1
  199. package/package.json +35 -86
  200. package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
  201. package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
  202. package/react/DynamicScript/index.tsx +33 -0
  203. package/{exporter/react → react}/Favicon/index.tsx +1 -7
  204. package/{exporter/react → react}/GriddoIntegrations/index.tsx +16 -22
  205. package/{exporter/react → react}/GriddoIntegrations/utils.ts +21 -9
  206. package/{build/react/index.d.ts → react/index.tsx} +1 -0
  207. package/src/components/Head.tsx +13 -46
  208. package/src/components/template.tsx +8 -30
  209. package/src/gatsby-node-utils.ts +73 -2
  210. package/src/html.tsx +2 -11
  211. package/src/types.ts +5 -5
  212. package/tsconfig.commands.json +36 -0
  213. package/tsconfig.exporter.json +19 -0
  214. package/tsconfig.json +5 -3
  215. package/build/adapters/gatsby/index.d.ts +0 -4
  216. package/build/adapters/gatsby/utils.d.ts +0 -22
  217. package/build/artifacts/index.d.ts +0 -6
  218. package/build/commands/end-render.d.ts +0 -2
  219. package/build/commands/move-assets.d.ts +0 -1
  220. package/build/commands/prepare-domains-render.d.ts +0 -1
  221. package/build/commands/reset-render.d.ts +0 -2
  222. package/build/commands/start-render.d.ts +0 -2
  223. package/build/commands/upload-search-content.d.ts +0 -2
  224. package/build/constants/endpoints.d.ts +0 -19
  225. package/build/constants/envs.d.ts +0 -37
  226. package/build/constants/index.d.ts +0 -57
  227. package/build/end-render.js +0 -74
  228. package/build/end-render.js.map +0 -7
  229. package/build/errors/errors-data.d.ts +0 -22
  230. package/build/errors/index.d.ts +0 -15
  231. package/build/index.d.ts +0 -29
  232. package/build/index.js +0 -73
  233. package/build/index.js.map +0 -7
  234. package/build/prepare-domains-render.js +0 -73
  235. package/build/prepare-domains-render.js.map +0 -7
  236. package/build/react/Favicon/index.d.ts +0 -5
  237. package/build/react/Favicon/utils.d.ts +0 -9
  238. package/build/react/GriddoIntegrations/index.d.ts +0 -20
  239. package/build/react/GriddoIntegrations/utils.d.ts +0 -26
  240. package/build/react/index.js +0 -3
  241. package/build/registers/api.d.ts +0 -9
  242. package/build/registers/gatsby.d.ts +0 -9
  243. package/build/registers/index.d.ts +0 -3
  244. package/build/reset-render.js +0 -74
  245. package/build/reset-render.js.map +0 -7
  246. package/build/services/auth.d.ts +0 -10
  247. package/build/services/domains.d.ts +0 -6
  248. package/build/services/navigation.d.ts +0 -50
  249. package/build/services/reference-fields.d.ts +0 -20
  250. package/build/services/register.d.ts +0 -36
  251. package/build/services/robots.d.ts +0 -19
  252. package/build/services/settings.d.ts +0 -4
  253. package/build/services/sites.d.ts +0 -29
  254. package/build/services/store.d.ts +0 -6
  255. package/build/start-render.js +0 -100
  256. package/build/start-render.js.map +0 -7
  257. package/build/types/api.d.ts +0 -142
  258. package/build/types/global.d.ts +0 -84
  259. package/build/types/navigation.d.ts +0 -28
  260. package/build/types/pages.d.ts +0 -144
  261. package/build/types/sites.d.ts +0 -57
  262. package/build/types/templates.d.ts +0 -8
  263. package/build/upload-search-content.js +0 -74
  264. package/build/upload-search-content.js.map +0 -7
  265. package/build/utils/alerts.d.ts +0 -3
  266. package/build/utils/api.d.ts +0 -23
  267. package/build/utils/cache.d.ts +0 -35
  268. package/build/utils/core-utils.d.ts +0 -107
  269. package/build/utils/create-build-data.d.ts +0 -8
  270. package/build/utils/domains.d.ts +0 -13
  271. package/build/utils/folders.d.ts +0 -53
  272. package/build/utils/health-checks.d.ts +0 -7
  273. package/build/utils/images.d.ts +0 -16
  274. package/build/utils/instance.d.ts +0 -21
  275. package/build/utils/loggin.d.ts +0 -51
  276. package/build/utils/pages.d.ts +0 -34
  277. package/build/utils/render.d.ts +0 -13
  278. package/build/utils/searches.d.ts +0 -15
  279. package/build/utils/sites.d.ts +0 -31
  280. package/build/utils/store.d.ts +0 -81
  281. package/cx.config.d.ts +0 -5
  282. package/cx.config.js +0 -36
  283. package/exporter/adapters/gatsby/utils.ts +0 -161
  284. package/exporter/artifacts/README.md +0 -34
  285. package/exporter/artifacts/index.ts +0 -33
  286. package/exporter/commands/move-assets.ts +0 -11
  287. package/exporter/constants/index.ts +0 -129
  288. package/exporter/index.ts +0 -82
  289. package/exporter/react/index.tsx +0 -11
  290. package/exporter/registers/api.ts +0 -14
  291. package/exporter/registers/gatsby.ts +0 -14
  292. package/exporter/registers/index.ts +0 -4
  293. package/exporter/services/domains.ts +0 -16
  294. package/exporter/services/register.ts +0 -113
  295. package/exporter/services/settings.ts +0 -17
  296. package/exporter/utils/alerts.ts +0 -29
  297. package/exporter/utils/create-build-data.ts +0 -17
  298. package/exporter/utils/health-checks.ts +0 -64
  299. package/exporter/utils/searches.ts +0 -156
  300. package/src/README.md +0 -7
  301. package/start-render.js +0 -7
  302. /package/{exporter/react → react}/Favicon/utils.ts +0 -0
@@ -1,7 +1,7 @@
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 = {
@@ -29,32 +29,31 @@ export interface ReferenceFieldBody {
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. */
@@ -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. */
@@ -1,6 +1,6 @@
1
+ import type { Core, Fields } from "@griddo/core";
1
2
  import type { EndSiteRenderBody } from "./api";
2
3
  import type { Site } from "./sites";
3
- import type { Core, Fields } from "@griddo/core";
4
4
 
5
5
  interface Settings {
6
6
  apiVersion?: string;
@@ -70,9 +70,7 @@ interface RenderInfo {
70
70
  sitesToPublish: Array<Site>;
71
71
  }
72
72
 
73
- type LifeCycleSteps = Array<
74
- (...args: Array<unknown>) => unknown | Promise<unknown>
75
- >;
73
+ type LifeCycleAction = (...args: Array<unknown>) => void | Promise<void>;
76
74
 
77
75
  type LifeCyclesNames =
78
76
  | "Init"
@@ -82,12 +80,11 @@ type LifeCyclesNames =
82
80
  | "SSG"
83
81
  | "Relocation"
84
82
  | "Meta"
85
- | "Archive"
83
+ | "Sync"
86
84
  | "Clean"
87
85
  | "Close"
88
86
  | "HealthCheck"
89
- | "Close"
90
- | "__DEBUG__";
87
+ | "Close";
91
88
 
92
89
  type PlaceholderPath =
93
90
  | "__exports"
@@ -97,13 +94,12 @@ type PlaceholderPath =
97
94
  | "__components"
98
95
  | "__root"
99
96
  | "__exports_dist"
100
- | "__cx_dist";
97
+ | "__sites";
101
98
 
102
99
  interface CXConfig {
103
- proDomain: string;
100
+ proDomainPrefix: string;
104
101
  griddoVersion: string;
105
102
  buildReportFileName: string;
106
- paths: (domain?: string) => Record<PlaceholderPath, string>;
107
103
  }
108
104
 
109
105
  interface AIEmbeddingsResponse {
@@ -116,6 +112,7 @@ interface Artifacts {
116
112
  cacheables: Array<string>;
117
113
  initials: Array<string>;
118
114
  archivables: Array<string>;
115
+ restaurable: Array<string>;
119
116
  }
120
117
 
121
118
  export type {
@@ -134,5 +131,5 @@ export type {
134
131
  Robot,
135
132
  Robots,
136
133
  Settings,
137
- LifeCycleSteps,
134
+ LifeCycleAction,
138
135
  };
@@ -21,5 +21,5 @@ export type Footer = {
21
21
  setAsDefault: boolean;
22
22
  theme: null | string;
23
23
  title: string;
24
- type: "header";
24
+ type: "footer";
25
25
  };
@@ -1,7 +1,7 @@
1
+ import type { Core, Fields } from "@griddo/core";
1
2
  import type { SocialsResponse } from "./api";
2
3
  import type { Settings } from "./global";
3
4
  import type { Site } from "./sites";
4
- import type { Core, Fields } from "@griddo/core";
5
5
 
6
6
  // TODO: In @griddo/core the type Core.Page has header/footer as React-Types,
7
7
  // but API return `number | null`.
@@ -156,8 +156,7 @@ export interface Dimensions {
156
156
  dimensionsSelect?: Array<string>;
157
157
  }
158
158
 
159
- export interface GatsbyPageTemplateProps
160
- extends Omit<GriddoPageObject, "context"> {
159
+ export interface GatsbyPageTemplateProps extends Omit<GriddoPageObject, "context"> {
161
160
  pageContext: GriddoPageObject["context"] & {
162
161
  page: Core.Page;
163
162
  };
@@ -0,0 +1,59 @@
1
+ import type { RenderInfo } from "./global";
2
+
3
+ const RENDER_MODE = {
4
+ FROM_SCRATCH: "FROM_SCRATCH",
5
+ INCREMENTAL: "INCREMENTAL",
6
+ IDLE: "IDLE",
7
+ } as const;
8
+
9
+ type RenderMode = (typeof RENDER_MODE)[keyof typeof RENDER_MODE];
10
+
11
+ export interface RenderModeTuple {
12
+ renderMode: RenderMode;
13
+ reason?: string;
14
+ }
15
+
16
+ type DomainLike = string;
17
+
18
+ type RenderDB = {
19
+ proDomainPrefix: string;
20
+ griddoVersion: string;
21
+ buildReportFileName: string;
22
+ sortedDomains: Array<DomainLike>;
23
+ paths: {
24
+ root: string;
25
+ cx: string;
26
+ ssg: string;
27
+ cxCache: string;
28
+ components: string;
29
+ exportsDir: string;
30
+ };
31
+ domains: {
32
+ [key: DomainLike]: {
33
+ renderMode?: RenderMode;
34
+ shouldBeRendered?: boolean;
35
+ isRendering?: boolean;
36
+ renderInfo?: RenderInfo;
37
+ renderModeReason?: string;
38
+ };
39
+ };
40
+ };
41
+
42
+ interface Report {
43
+ authControl:
44
+ | {
45
+ Authorization: string;
46
+ "Cache-Control": string;
47
+ lang?: string | undefined;
48
+ }
49
+ | undefined;
50
+ sites: Array<{
51
+ siteId: number;
52
+ publishHashes: Array<string>;
53
+ siteHash: string | null;
54
+ unpublishHashes: Array<string>;
55
+ publishPagesIds: Array<number>;
56
+ }>;
57
+ }
58
+
59
+ export { RENDER_MODE, type RenderDB, type RenderMode, type Report };
@@ -1,6 +1,6 @@
1
+ import type { Core } from "@griddo/core";
1
2
  import type { SocialsResponse } from "./api";
2
3
  import type { Footer, Header } from "./navigation";
3
- import type { Core } from "@griddo/core";
4
4
 
5
5
  /**
6
6
  * Describes a Griddo site object from API.
@@ -43,7 +43,6 @@ export interface Site
43
43
  */
44
44
  pages: Array<number>;
45
45
  onlinePages: Array<number>;
46
- changedPages: Array<number>;
47
46
  published: string;
48
47
  rendering: boolean;
49
48
  renderingHours: number;
@@ -6,25 +6,16 @@ import type {
6
6
  PutAPI,
7
7
  ShowApiErrorOptions,
8
8
  } from "../types/api";
9
- import type { AxiosError, Method } from "axios";
10
-
11
- import axios from "axios";
12
- import dotenv from "dotenv";
13
- import kleur from "kleur";
14
9
 
10
+ import { AuthService } from "../services/auth";
11
+ import { brush } from "./brush";
15
12
  import { saveCache, searchCacheData } from "./cache";
16
13
  import { delay, getSafeSiteId, msToSec } from "./core-utils";
17
- import { buildLog } from "./loggin";
18
- import { envs } from "../constants";
19
- import { apiRegister } from "../registers";
20
- import { AuthService } from "../services/auth";
21
-
22
- dotenv.config();
14
+ import { appendLogToFile } from "./loggin";
23
15
 
24
16
  // Envs
25
- const {
26
- env: { RETRY_WAIT_SECONDS = "4", RETRY_ATTEMPTS = "4" },
27
- } = process;
17
+ const { env } = process;
18
+ const { RETRY_WAIT_SECONDS = "4", RETRY_ATTEMPTS = "4" } = env;
28
19
 
29
20
  /**
30
21
  * Make a GET/PUT/POST request to the Griddo API.
@@ -41,7 +32,7 @@ const {
41
32
  */
42
33
  async function requestAPI<T extends APIResponses>(
43
34
  props: APIRequest,
44
- method: Method,
35
+ method: string,
45
36
  appendToLog = "",
46
37
  ): Promise<T> {
47
38
  const {
@@ -51,21 +42,24 @@ async function requestAPI<T extends APIResponses>(
51
42
  attempt = 1,
52
43
  headers,
53
44
  useApiCacheDir = true,
45
+ logToFile = true,
54
46
  } = props;
55
47
  const cacheOptions = { endpoint, body, headers, cacheKey };
56
48
 
57
49
  // Cache
58
50
  if (cacheKey && useApiCacheDir) {
59
51
  const start = new Date();
60
- const cacheData = searchCacheData<T>(cacheOptions);
52
+ const cacheData = await searchCacheData<T>(cacheOptions);
61
53
 
62
54
  if (cacheData) {
63
55
  const siteId = getSafeSiteId(cacheData);
64
56
  const siteIdMsg = siteId ? `site: ${siteId}` : "";
65
- const duration = msToSec(new Date().getTime() - start.getTime());
66
- buildLog(
67
- `${method} (cache) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`,
68
- );
57
+ const duration = msToSec(Date.now() - start.getTime());
58
+ if (logToFile) {
59
+ await appendLogToFile(
60
+ `${method} (cache) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`,
61
+ );
62
+ }
69
63
  return cacheData;
70
64
  }
71
65
  }
@@ -73,47 +67,50 @@ async function requestAPI<T extends APIResponses>(
73
67
  // Network
74
68
  try {
75
69
  const start = new Date();
76
- const {
77
- data,
78
- headers: responseHeaders,
79
- }: { data: T; headers: { "content-length": string } } = await axios({
80
- url: endpoint,
81
- method,
82
- headers: Object.assign({}, headers, AuthService.headers),
83
- data: body,
84
- });
70
+
71
+ // Prepare fetch options
72
+ const fetchOptions: RequestInit = {
73
+ method: method.toUpperCase(),
74
+ headers: Object.assign({}, headers, AuthService.headers) as Record<string, string>,
75
+ };
76
+
77
+ // Add body for non-GET requests
78
+ if (method.toLowerCase() !== "get" && body) {
79
+ fetchOptions.body = JSON.stringify(body);
80
+ if (!fetchOptions.headers) fetchOptions.headers = {};
81
+ (fetchOptions.headers as Record<string, string>)["Content-Type"] = "application/json";
82
+ }
83
+
84
+ const response = await fetch(endpoint, fetchOptions);
85
+
86
+ // Handle non-2xx responses
87
+ if (!response.ok) {
88
+ if (response.status === 404) {
89
+ // @ts-expect-error page maybe will be 404
90
+ return null;
91
+ }
92
+
93
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
94
+ }
95
+
96
+ const data: T = await response.json();
85
97
 
86
98
  const siteId = getSafeSiteId(data);
87
99
  const siteIdMsg = siteId ? `site: ${siteId}` : "";
88
- const duration = msToSec(new Date().getTime() - start.getTime());
89
- buildLog(
90
- `${method} (fetch) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`,
91
- );
92
-
93
- if (useApiCacheDir) {
94
- saveCache(cacheOptions, data);
100
+ const duration = msToSec(Date.now() - start.getTime());
101
+ if (logToFile) {
102
+ await appendLogToFile(
103
+ `${method} (fetch) ${siteIdMsg} ${endpoint} - ${duration}s ${appendToLog}`,
104
+ );
95
105
  }
96
106
 
97
- // Only save registers if alerts are enabled
98
- if (envs.GRIDDO_ALERT_FEATURE) {
99
- const responseSize = Number.parseInt(responseHeaders["content-length"]);
100
- if (responseSize > envs.GRIDDO_API_MAX_RESPONSE_SIZE) {
101
- apiRegister.insert("API_RESPONSE_TOO_BIG", {
102
- endpoint,
103
- responseSize,
104
- duration,
105
- });
106
- }
107
+ if (useApiCacheDir) {
108
+ await saveCache(cacheOptions, data);
107
109
  }
108
110
 
109
111
  return data;
110
112
  } catch (e) {
111
- const error = e as AxiosError;
112
-
113
- if (error.response?.status === 404) {
114
- // @ts-expect-error page maybe will be 404
115
- return null;
116
- }
113
+ const error = e as Error;
117
114
 
118
115
  if (attempt > parseInt(RETRY_ATTEMPTS)) {
119
116
  console.log(`
@@ -122,7 +119,7 @@ Max attempts ${RETRY_ATTEMPTS} reached
122
119
  - ${method.toUpperCase()} ${endpoint}
123
120
  - BODY: ${JSON.stringify(body)}
124
121
  - HEADERS: ${JSON.stringify(headers)}
125
- - RESPONSE: ${error.response?.status} ${JSON.stringify(error.response?.data)}
122
+ - ERROR: ${error.message}
126
123
  --------------------------------------
127
124
  `);
128
125
 
@@ -130,12 +127,6 @@ Max attempts ${RETRY_ATTEMPTS} reached
130
127
  process.exit(1);
131
128
  }
132
129
 
133
- if (!error.response) {
134
- console.log("Unknown error occurred");
135
- console.log(JSON.stringify(error, null, 2));
136
- process.exit(1);
137
- }
138
-
139
130
  showApiError(error, {
140
131
  callInfo: { endpoint, body },
141
132
  });
@@ -188,9 +179,7 @@ async function postApi<T extends APIResponses>(props: PostAPI) {
188
179
  const { endpoint, body, headers } = props;
189
180
  const referenceFieldBodyParams =
190
181
  endpoint.endsWith("/distributor") &&
191
- `# ReferenceField body: ${JSON.stringify(body)} lang: ${JSON.stringify(
192
- headers?.lang,
193
- )}`;
182
+ `# ReferenceField body: ${JSON.stringify(body)} lang: ${JSON.stringify(headers?.lang)}`;
194
183
 
195
184
  return requestAPI<T>(props, "post", referenceFieldBodyParams || "");
196
185
  }
@@ -198,40 +187,31 @@ async function postApi<T extends APIResponses>(props: PostAPI) {
198
187
  /**
199
188
  * Shows an API error through the terminal.
200
189
  */
201
- function showApiError(error: AxiosError, options: ShowApiErrorOptions) {
202
- const { response, message, stack } = error;
190
+ function showApiError(error: Error, options: ShowApiErrorOptions) {
191
+ const { message, stack } = error;
203
192
  const { callInfo } = options;
204
- const { status, statusText, data } = response || {};
205
193
  const callInfoArray = [];
206
194
 
207
195
  for (const item of Object.keys(callInfo) as Array<keyof typeof callInfo>) {
208
196
  callInfoArray.push(
209
197
  `${item}: ${
210
- typeof callInfo[item] === "object"
211
- ? JSON.stringify(callInfo[item])
212
- : callInfo[item]
198
+ typeof callInfo[item] === "object" ? JSON.stringify(callInfo[item]) : callInfo[item]
213
199
  }`,
214
200
  );
215
201
  }
216
202
 
217
203
  // Compose the errors output
218
204
  const callInfoStr = callInfoArray.join("\n");
219
- const apiResponseStr = response
220
- ? `Code: ${status} - ${statusText}\nResponse: ${JSON.stringify(data)}`
221
- : "";
222
205
  const errorDetailsStr = `${message}\n${stack}`;
223
206
 
224
207
  // Print the error
225
208
  console.warn(
226
- kleur.red(`
209
+ brush.red(`
227
210
  =============
228
211
 
229
212
  { Call info }
230
213
  ${callInfoStr}
231
214
 
232
- { API Response }
233
- ${apiResponseStr}
234
-
235
215
  { Error details }
236
216
  ${errorDetailsStr}
237
217
 
@@ -0,0 +1,38 @@
1
+ import type { Artifacts } from "../types/global";
2
+
3
+ import path from "node:path";
4
+
5
+ import { getRenderPathsFromDB } from "./render";
6
+
7
+ /**
8
+ * Returns the artifacts of CX.
9
+ */
10
+ async function getCxArtifacts(domain: string): Promise<Artifacts> {
11
+ const { __exports, __cache, __root, __ssg } = await getRenderPathsFromDB({ domain });
12
+
13
+ return {
14
+ initials: [
15
+ __exports, // `<root>/exports/<domain>`
16
+ __cache, // `<root>/.cx-cache/<domain>`
17
+ path.join(__exports, "logs"),
18
+ path.join(__root, "store"),
19
+ path.join(__root, "apiCache"),
20
+ ],
21
+ disposables: [
22
+ path.join(__root, "store"),
23
+ path.join(__root, "apiCache"),
24
+ path.join(__root, "dist"),
25
+ path.join(__root, "dist-restored"),
26
+ path.join(__root, "assets"),
27
+ path.join(__root, "render-detail-log.txt"),
28
+ path.join(__ssg, "domains.json"),
29
+ path.join(__ssg, "domains.txt"),
30
+ path.join(__ssg, "render-metadata.json"),
31
+ ],
32
+ cacheables: [],
33
+ archivables: ["dist", "assets"],
34
+ restaurable: ["dist"],
35
+ };
36
+ }
37
+
38
+ export { getCxArtifacts };
@@ -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 };