@griddo/cx 1.75.210 → 1.75.212

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.
package/build/index.js CHANGED
@@ -25,7 +25,7 @@ GFS4: `),console.error(e)});G[Q]||(ea=global[Q]||[],ra(G,ea),G.close=function(e)
25
25
  \u2502 Access credentials failure \u2502
26
26
  \u2502 Check that the login details are correct in your .env file \u2502
27
27
  \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F
28
- `)),process.exit(1)}}},hr=new On;var Yu=Y(Rn()),Xu=Y(mt()),Ku=Y(Gt());var fp=Y(mt()),Uu=Y(Gt()),hp=Y(eu()),Gu=Y($u());var Hu="1.75.210";Uu.default.config();var dp=!!process.env.GRIDDO_BUILD_LOGS&&!!JSON.parse(process.env.GRIDDO_BUILD_LOGS);function zu(...e){dp&&console.info(...e)}function Wu(e){return new Promise(t=>setTimeout(t,e))}function ai(e,t=3){return(e/1e3).toFixed(t)}function Ju(e){return"site"in e&&e.site?e?.site:void 0}function ci(...e){let t=performance.now();return e.forEach(r=>r()),ai(performance.now()-t)}function Vu(){let e=`
28
+ `)),process.exit(1)}}},hr=new On;var Yu=Y(Rn()),Xu=Y(mt()),Ku=Y(Gt());var fp=Y(mt()),Uu=Y(Gt()),hp=Y(eu()),Gu=Y($u());var Hu="1.75.212";Uu.default.config();var dp=!!process.env.GRIDDO_BUILD_LOGS&&!!JSON.parse(process.env.GRIDDO_BUILD_LOGS);function zu(...e){dp&&console.info(...e)}function Wu(e){return new Promise(t=>setTimeout(t,e))}function ai(e,t=3){return(e/1e3).toFixed(t)}function Ju(e){return"site"in e&&e.site?e?.site:void 0}function ci(...e){let t=performance.now();return e.forEach(r=>r()),ai(performance.now()-t)}function Vu(){let e=`
29
29
  \xB7\xB7
30
30
  \xB7\xB7
31
31
  \xB7\xB7
@@ -41,7 +41,7 @@ GFS4: `),console.error(e)});G[Q]||(ea=global[Q]||[],ra(G,ea),G.close=function(e)
41
41
  \xB7\xB7
42
42
  \xB7\xB7
43
43
  \xB7\xB7
44
- `;console.log(Gu.default.cristal(e))}Ku.default.config();var{env:{RETRY_WAIT_SECONDS:pp="4",RETRY_ATTEMPTS:Qu="1"}}=process;async function Zu(e){let{endpoint:t,body:r,cached:n,attempt:i,method:s,headers:o}=e,a={endpoint:t,body:r,cached:n};if(n){let c=hs(a);if(c)return c}try{let{data:c}=await(0,Yu.default)({url:t,method:s,headers:{...o,...hr.headers},data:r});return fs(a,c),c}catch(c){let d=c;if(mp(d,{callInfo:{endpoint:t,body:r,attempt:i},breakProcess:d.response.status!==404}),d.response.status===404)return null;if(i&&i<parseInt(Qu))return console.warn(`Waiting for retry: ${s}`,t),await Wu(parseInt(pp)*1e3),Zu({endpoint:t,body:r,cached:n,method:s,attempt:i+1});throw new Error(`Error in ${s}`)}}async function el(e){let t=new Date,{endpoint:r}=e,n=await Zu({...e,method:"get"}),i=e.cached?"(cached)":"(fetch)",s=Ju(n),o=s?`site: ${s} `:"",a=ai(new Date().getTime()-t.getTime());return zu(`GET ${i} ${o} ${r} - ${a}s`),n}function mp(e,t){let{response:r,message:n,stack:i}=e,{breakProcess:s,callInfo:o}=t,{status:a,statusText:c,data:d}=r||{},h=[];for(let _ of Object.keys(o)){let R=_;h.push(`${_}: ${typeof o[R]=="object"?JSON.stringify(o[R]):o[R]}`)}let p=h.join(`
44
+ `;console.log(Gu.default.cristal(e))}Ku.default.config();var{env:{RETRY_WAIT_SECONDS:pp="4",RETRY_ATTEMPTS:Qu="1"}}=process;async function Zu(e){let{endpoint:t,body:r,cached:n,attempt:i=1,method:s,headers:o}=e,a={endpoint:t,body:r,cached:n};if(n){let c=hs(a);if(c)return c}try{let{data:c}=await(0,Yu.default)({url:t,method:s,headers:{...o,...hr.headers},data:r});return fs(a,c),c}catch(c){let d=c;if(mp(d,{callInfo:{endpoint:t,body:r,attempt:i},breakProcess:d.response.status!==404}),d.response.status===404)return null;if(i<=parseInt(Qu))return console.warn(`Waiting for retry: ${s}`,t),await Wu(parseInt(pp)*1e3),Zu({endpoint:t,body:r,cached:n,method:s,attempt:i+1});throw new Error(`Error in ${s}`)}}async function el(e){let t=new Date,{endpoint:r}=e,n=await Zu({...e,method:"get"}),i=e.cached?"(cached)":"(fetch)",s=Ju(n),o=s?`site: ${s} `:"",a=ai(new Date().getTime()-t.getTime());return zu(`GET ${i} ${o} ${r} - ${a}s`),n}function mp(e,t){let{response:r,message:n,stack:i}=e,{breakProcess:s,callInfo:o}=t,{status:a,statusText:c,data:d}=r||{},h=[];for(let _ of Object.keys(o)){let R=_;h.push(`${_}: ${typeof o[R]=="object"?JSON.stringify(o[R]):o[R]}`)}let p=h.join(`
45
45
  `),m=r?`Code: ${a} - ${c}
46
46
  Response: ${JSON.stringify(d)}`:"",y=`${n}
47
47
  ${i}`;console.warn(Xu.default.bold.red(`
@@ -57,7 +57,7 @@ ${m}
57
57
  ${y}
58
58
 
59
59
  =============
60
- `)),s&&(typeof o?.attempt!="number"||o.attempt>=parseInt(Qu))&&process.exit(1)}var yp=process.env.API_URL,gp={GET_ALL:`${yp}/domains`},Dr=class{static async getAll(){let{GET_ALL:t}=gp;return await el({endpoint:t})}};async function tl(){await hr.login();let e=await Dr.getAll();return vp(e)}function vp(e){let t=e.filter(({slug:r})=>!!r).map(({slug:r})=>r.replace("/",""));return[...new Set(t)]}sl.default.config();var ui=["dist","assets","apiCache"],rl=["public","store",".cache"],bp=li.default.sync(),wp=It.default.resolve(bp,"exports/sites"),ol=li.default.sync(__dirname),_p=e=>t=>xp(t,e),xp=(e,t={})=>(0,il.execSync)(e,{cwd:ol,stdio:"inherit",env:{...process.env,...t,GRIDDO_EXPORTER:"true"}}),Ep=e=>!process.env.GRIDDO_ASSET_PREFIX||!e||!e.startsWith("pro-")?"":`${process.env.GRIDDO_ASSET_PREFIX}/${e}`,nl=(...e)=>console.log(...e),Ge=(...e)=>console.log(...e),Sp=(...e)=>console.log(...e),Ue=(...e)=>console.log(...e),kp=async e=>{let t=Rp(e),r=ci(t.init,t.restoreArtifacts);Ge(`
60
+ `)),s&&(typeof o?.attempt!="number"||o.attempt>parseInt(Qu))&&process.exit(1)}var yp=process.env.API_URL,gp={GET_ALL:`${yp}/domains`},Dr=class{static async getAll(){let{GET_ALL:t}=gp;return await el({endpoint:t})}};async function tl(){await hr.login();let e=await Dr.getAll();return vp(e)}function vp(e){let t=e.filter(({slug:r})=>!!r).map(({slug:r})=>r.replace("/",""));return[...new Set(t)]}sl.default.config();var ui=["dist","assets","apiCache"],rl=["public","store",".cache"],bp=li.default.sync(),wp=It.default.resolve(bp,"exports/sites"),ol=li.default.sync(__dirname),_p=e=>t=>xp(t,e),xp=(e,t={})=>(0,il.execSync)(e,{cwd:ol,stdio:"inherit",env:{...process.env,...t,GRIDDO_EXPORTER:"true"}}),Ep=e=>!process.env.GRIDDO_ASSET_PREFIX||!e||!e.startsWith("pro-")?"":`${process.env.GRIDDO_ASSET_PREFIX}/${e}`,nl=(...e)=>console.log(...e),Ge=(...e)=>console.log(...e),Sp=(...e)=>console.log(...e),Ue=(...e)=>console.log(...e),kp=async e=>{let t=Rp(e),r=ci(t.init,t.restoreArtifacts);Ge(`
61
61
  \u231B\uFE0F Domain ${e} restaured: ${r}s`),t.runExporter();let n=ci(t.archiveArtifacts);Ge(`
62
62
  \u231B\uFE0F Domain ${e} archived: ${n}s`)},Cp=async()=>{Vu(),us();let e=await tl();for(let t of e)Ge(`\uFE0F\u{1F6A2} Exporting domain ${Z.default.underline(t)}`),await kp(t)},Rp=e=>{let t=Ep(e),r=_p({DOMAIN:e,GRIDDO_ASSET_PREFIX:t,HAS_ASSET_DOMAIN:t&&t!=="",RENDERID:new Date().valueOf()}),n=()=>{Ge(`\u{1F680} Initializing ${Z.default.underline(e)} exporter`),s(),o()},i=(S="")=>{let C=It.default.resolve(wp,e),P=It.default.resolve(C,S),J=`${P}-BACKUP`,de=It.default.resolve(ol,S);return{domainExportArchiveBasePath:C,currentExportArchivePath:P,currentExportBackupPath:J,currentExportWorkingPath:de}},s=()=>{for(let S of[...ui,...rl]){let{currentExportWorkingPath:C}=i(S);Se.default.existsSync(C)&&(Ue(`\u{1F9F9} Cleanup dirty ${Z.default.gray(C)}`),r(`rm -rf ${C}`))}},o=()=>{let{domainExportArchiveBasePath:S}=i();Se.default.existsSync(S)||(Ge(`\u2728 Creating ${S}`),r(`mkdir -p ${S}`))},a=S=>{let{currentExportArchivePath:C,currentExportWorkingPath:P}=i(S);Ge(`\u{1F69A} Moving files from ${Z.default.gray(P)} to ${Z.default.gray(C)}`),r(`mv ${P} ${C}`)},c=()=>{for(let S of ui){let{currentExportWorkingPath:C,currentExportArchivePath:P}=i(S);if(!Se.default.existsSync(C)){nl("\u{1F4C1} Source directory has not been created:",C);continue}try{h(S),a(S),m(S)}catch(J){nl(`\u{1F69A} Error moving files to ${P}`,J.message),p(S);continue}}},d=()=>{for(let S of ui){let{currentExportArchivePath:C,currentExportWorkingPath:P}=i(S);Se.default.existsSync(C)&&(Ue(`\uFE0F\u267B\uFE0F Restoring ${Z.default.gray(C)}`),r(`cp -R ${C} ${P}`))}_()},h=S=>{let{currentExportArchivePath:C,currentExportBackupPath:P}=i(S);Se.default.existsSync(C)&&(Ge(`\u{1F4BF} Creating backup of ${Z.default.gray(C)}`),r(`mv ${C} ${P}`))},p=S=>{let{currentExportArchivePath:C,currentExportBackupPath:P}=i(S);Se.default.existsSync(P)&&(Ue(`\uFE0F\u267B\uFE0F Restoring backup ${Z.default.gray(C)}`),r(`mv ${P} ${C}`))},m=S=>{let{currentExportArchivePath:C,currentExportBackupPath:P}=i(S);Ue(`\uFE0F\u{1F5D1}\uFE0F Removing backup ${Z.default.gray(C)}`),r(`rm -rf ${P}`)},y=()=>{console.log(`
63
63
  ${Z.default.black(Z.default.bgGreen(" Gatsby (start) "))}
package/gatsby-node.ts CHANGED
@@ -22,24 +22,16 @@ const GRIDDO_STORE_MODE = (process.env.GRIDDO_STORE_MODE ||
22
22
  const PUBLIC_FOLDER = path.resolve(__dirname, "./public");
23
23
  const STORE_DIR_PATH = path.resolve(__dirname, "./store/");
24
24
  const REPORT_FILE = path.resolve(PUBLIC_FOLDER, "__build-report__.json");
25
- const GRIDDO_SANITIZE_PAGES = false;
26
- const envVars: Record<string, any> = {};
27
25
 
28
26
  // -----------------------------------------------------------------------------
29
27
  // onPreInit
30
28
  // -----------------------------------------------------------------------------
31
29
  export const onPreInit = async () => {
32
- console.log("Envs");
33
- Object.keys(process.env)
34
- .filter((key) => key.startsWith("GRIDDO_") || key.startsWith("GATSBY"))
35
- .forEach((key) => (envVars[key] = process.env[key]));
36
- console.log(envVars);
37
-
38
30
  splash();
39
31
  initCache();
40
32
  prepareStaticFolder();
41
33
  StoreService.init(STORE_DIR_PATH, {
42
- sanitize: GRIDDO_SANITIZE_PAGES,
34
+ sanitize: true,
43
35
  mode: GRIDDO_STORE_MODE,
44
36
  });
45
37
  await StoreService.createBuildSource();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/cx",
3
3
  "description": "Griddo SSG based on Gatsby",
4
- "version": "1.75.210",
4
+ "version": "1.75.212",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -33,7 +33,7 @@
33
33
  "@babel/preset-env": "^7.14.5",
34
34
  "@babel/preset-react": "^7.14.5",
35
35
  "@babel/preset-typescript": "^7.16.5",
36
- "@griddo/core": "^1.75.210",
36
+ "@griddo/core": "^1.75.212",
37
37
  "@svgr/webpack": "^5.5.0",
38
38
  "babel-loader": "^8.0.6",
39
39
  "babel-plugin-styled-components": "^1.10.7",
@@ -63,7 +63,7 @@
63
63
  "react-helmet": "^6.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@griddo/eslint-config-back": "^1.75.210",
66
+ "@griddo/eslint-config-back": "^1.75.212",
67
67
  "@types/babel__core": "^7.20.0",
68
68
  "@types/babel__preset-env": "^7.9.2",
69
69
  "@types/csvtojson": "^2.0.0",
@@ -111,5 +111,5 @@
111
111
  "publishConfig": {
112
112
  "access": "public"
113
113
  },
114
- "gitHead": "2b9df0e7e16083025b24814e8952c45078a732a8"
114
+ "gitHead": "ea263310a45b718e25b02b662d57d6dd3c341f02"
115
115
  }
@@ -14,7 +14,8 @@ import { logBox } from "../utils/shared";
14
14
  */
15
15
  class DistributorService {
16
16
  /**
17
- * Get the body data from a ReferenceField in auto or manual mode.
17
+ * Get the body data from a ReferenceField.
18
+ * `auto`, `manual` or `navigation` mode.
18
19
  *
19
20
  * @param data The ReferenceField props.
20
21
  * @returns The props for one of the ReferenceField mode.
@@ -78,7 +79,7 @@ class DistributorService {
78
79
  * @param props.page The Page object
79
80
  * @param props.component.data The ReferenceField, always in the data prop.
80
81
  * @param props.cached Boolean that indicates cache use.
81
- * @returns The Content Type data.
82
+ * @returns The ContentType data.
82
83
  */
83
84
  static async fetchContentTypeData(props: FetchDataProps) {
84
85
  const {
@@ -68,20 +68,20 @@ const BUILD_PROCESS_DATA: BuildProcessData = {};
68
68
  const UNWANTED_PAGE_PROPS = ["editorID", "parentEditorID"];
69
69
 
70
70
  /**
71
- * Store service to fetch, process and save temporarily object pages and site
72
- * data to be consumed by external services (Griddo itself, Gatsby, etc.)
71
+ * Store service to fetch, process and save object pages and sites data to be
72
+ * consumed by other services (Griddo itself, Gatsby, etc.)
73
73
  *
74
74
  * Modes:
75
- * - File mode will save the final page objects in individual json files in the file system.
76
- * - Memory mode will save the final page objects in an array of objects in memory.
75
+ * - { File mode } save the objects as json files in the file system (json DB)
76
+ * - { Memory mode } save the objects in an array.
77
77
  *
78
78
  * @example
79
79
  * import { StoreService } from "./store"
80
80
  *
81
81
  * // Init the store service.
82
- * StoreService.init("foo/pages", { mode: "file" })
82
+ * StoreService.init("foo/pages", { mode: "file", ... })
83
83
  * // Save the data into files.
84
- * await StoreService.saveBuildData()
84
+ * await StoreService.createBuildSource()
85
85
  * // Consume the pages as an interator.
86
86
  * const pages = StoreService.getPages()
87
87
  */
@@ -94,8 +94,6 @@ class StoreService {
94
94
  static buildProcessData: BuildProcessData;
95
95
  static createdPages: Array<number>;
96
96
 
97
- // Public methods
98
-
99
97
  /**
100
98
  * Initialize the Store with a path to save files (file mode) and an option object to configure the Store.
101
99
  *
@@ -164,6 +162,7 @@ class StoreService {
164
162
  );
165
163
 
166
164
  // Unpublish (API) and delete sites
165
+ // TODO: Manage this to save end data to the __report-build__ file ???
167
166
  await unpublishSites(sitesToUnpublish);
168
167
 
169
168
  // Delete (clean) sites to publish
@@ -172,7 +171,6 @@ class StoreService {
172
171
  // Set robots information to use later in the `onPostBuild` phase.
173
172
  await RobotsService.loadRobots();
174
173
 
175
- // const siteToPublishPromises = sitesToPublish.map(async (site) => {
176
174
  for (const site of sitesToPublish) {
177
175
  const { id: siteId, slug: siteSlug, theme, favicon } = site;
178
176
 
@@ -373,14 +371,6 @@ class StoreService {
373
371
 
374
372
  await Promise.all(pagesToRender);
375
373
  }
376
-
377
- // Create the pLimit array of promises
378
- // const limit = pLimit(1);
379
- // const sitesToPublishAwaited = siteToPublishPromises.map((site) =>
380
- // limit(() => site)
381
- // );
382
-
383
- // await Promise.all(sitesToPublishAwaited);
384
374
  } catch (e) {
385
375
  const error = e as { message: string };
386
376
 
@@ -396,11 +386,9 @@ class StoreService {
396
386
  * If the Store is in memory mode `getPages` will return an array of pages.
397
387
  */
398
388
  public static getPages() {
399
- if (this.mode === "file") {
400
- return this.getPagesFromFiles();
401
- } else {
402
- return this.getPagesFromMemory();
403
- }
389
+ return this.mode === "file"
390
+ ? this.getPagesFromFiles()
391
+ : this.getPagesFromMemory();
404
392
  }
405
393
 
406
394
  /**
@@ -415,11 +403,9 @@ class StoreService {
415
403
  pages.forEach((page) => removeProperties(page, UNWANTED_PAGE_PROPS));
416
404
  }
417
405
 
418
- if (this.mode === "file") {
419
- await this.savePagesToFiles(pages);
420
- } else {
421
- this.savePagesToMemory(pages);
422
- }
406
+ return this.mode === "file"
407
+ ? await this.savePagesToFiles(pages)
408
+ : this.savePagesToMemory(pages);
423
409
  }
424
410
 
425
411
  /**
package/src/utils/api.ts CHANGED
@@ -39,7 +39,7 @@ const {
39
39
  async function requestAPI<T extends APIResponses>(
40
40
  props: APIRequest & { method: Method }
41
41
  ): Promise<T> {
42
- const { endpoint, body, cached, attempt, method, headers } = props;
42
+ const { endpoint, body, cached, attempt = 1, method, headers } = props;
43
43
  const cacheOptions = { endpoint, body, cached };
44
44
 
45
45
  // Cache
@@ -76,7 +76,7 @@ async function requestAPI<T extends APIResponses>(
76
76
  return null;
77
77
  }
78
78
 
79
- if (attempt && attempt < parseInt(RETRY_ATTEMPTS)) {
79
+ if (attempt <= parseInt(RETRY_ATTEMPTS)) {
80
80
  console.warn(`Waiting for retry: ${method}`, endpoint);
81
81
 
82
82
  await delay(parseInt(RETRY_WAIT_SECONDS) * 1000);
@@ -220,7 +220,7 @@ ${errorDetailsStr}
220
220
  if (
221
221
  breakProcess &&
222
222
  (typeof callInfo?.attempt !== "number" ||
223
- callInfo.attempt >= parseInt(RETRY_ATTEMPTS))
223
+ callInfo.attempt > parseInt(RETRY_ATTEMPTS))
224
224
  ) {
225
225
  process.exit(1);
226
226
  }