gatsby-attainlabs-cms 1.0.15 → 1.0.17

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/README.md CHANGED
@@ -57,6 +57,7 @@ module.exports = {
57
57
  options: {
58
58
  brand: "Cash Money", // LendDirect | Cash Money | Heights Finance adding-puck-for-visual-code-editing
59
59
  // personalAccessToken: "optional-fallback", // not recommended, but supported
60
+ environment: "production", // production | dev
60
61
  },
61
62
  },
62
63
  ],
@@ -0,0 +1,16 @@
1
+ module.exports = ({ brand }) => ({
2
+ plugins: [
3
+ `gatsby-plugin-image`,
4
+ {
5
+ resolve: `gatsby-plugin-sharp`,
6
+ options: {
7
+ defaults: {
8
+ quality: 100,
9
+ placeholder: "none",
10
+ formats: [`webp`, "avif"],
11
+ },
12
+ },
13
+ },
14
+ `gatsby-transformer-sharp`,
15
+ ],
16
+ });
package/gatsby-node.js CHANGED
@@ -59,11 +59,23 @@ const createPage = async (blocks, pageUrl, id) => {
59
59
  require("dotenv").config();
60
60
  // Load PAT from env instead of hardcoding (fallback to old const for now but warn)
61
61
  exports.onPreInit = async (_, pluginOptions) => {
62
- const { brand, azureBranch, personalAccessToken: patOption } = pluginOptions;
62
+ const {
63
+ brand,
64
+ azureBranch,
65
+ personalAccessToken: patOption,
66
+ environment,
67
+ } = pluginOptions;
63
68
 
64
69
  // Try env first, then plugin option fallback
65
70
  const pat = process.env.PERSONAL_ACCESS_TOKEN || patOption;
66
71
 
72
+ if (environment === "dev") {
73
+ console.log(
74
+ "ℹ️ [gatsby-attainlabs-cms] Running in 'dev' environment mode. Skipping component sync."
75
+ );
76
+ return;
77
+ }
78
+
67
79
  if (!pat) {
68
80
  console.warn(
69
81
  "⚠️ [gatsby-attainlabs-cms] No PERSONAL_ACCESS_TOKEN found. " +
@@ -106,12 +118,11 @@ exports.onPreInit = async (_, pluginOptions) => {
106
118
  // List of folders to download from
107
119
  const targets = [
108
120
  {
109
- repoPath: `/apps/cms/src/cms/components/editor/visual-block-editor/components/brands/${brands[brand]}`,
110
- localBasePath: path.resolve("./src/cms/components/"),
121
+ repoPath: `/apps/cms/src/cms/editors/visual-block-editor/brands/${brands[brand]}/`,
122
+ localBasePath: path.resolve("./src/cms/"),
111
123
  },
112
124
  {
113
- repoPath:
114
- "/apps/cms/src/cms/components/editor/visual-block-editor/components/global/blocks",
125
+ repoPath: "/apps/cms/src/cms/editors/visual-block-editor/core/",
115
126
  localBasePath: path.resolve("./src/cms/components/"),
116
127
  },
117
128
  {
@@ -165,13 +176,12 @@ exports.onPreInit = async (_, pluginOptions) => {
165
176
  const result = JSON.parse(data);
166
177
  const posix = path.posix;
167
178
 
168
- // Keep only index.tsx files
179
+ // Exclude files named config.tsx
169
180
  const items = (result.value || []).filter(
170
181
  (i) =>
171
182
  !i.isFolder &&
172
183
  i.gitObjectType === "blob" &&
173
- (posix.basename(i.path) === "index.tsx" ||
174
- posix.extname(i.path) === ".ts")
184
+ posix.basename(i.path) !== "config.tsx"
175
185
  );
176
186
 
177
187
  console.log(`Found ${items.length} files in ${repoPath}`);
@@ -259,11 +269,96 @@ exports.onPreInit = async (_, pluginOptions) => {
259
269
  doRequest(fileUrl);
260
270
  }
261
271
  };
272
+ exports.sourceNodes = async (
273
+ { actions, createNodeId, createContentDigest },
274
+ pluginOptions
275
+ ) => {
276
+ const { createNode } = actions;
277
+ const { trustpilotApiKey, brand } = pluginOptions;
278
+ const apiKey = process.env.TRUSTPILOT_API_KEY || trustpilotApiKey;
279
+ console.log(
280
+ `ℹ️ [gatsby-attainlabs-cms] Fetching Trustpilot data for brand: ${brand}`
281
+ );
282
+ // // Map brand names to Trustpilot business unit IDs
283
+ const businessIds = {
284
+ LendDirect: "599affea0000ff0005a95acd",
285
+ "Cash Money": "599afd420000ff0005a95a9d",
286
+ "Heights Finance": "5e72238d600d1a0001be01eb",
287
+ };
288
+ const businessUnitId = businessIds[brand];
289
+ if (!apiKey) {
290
+ console.warn(
291
+ "⚠️ [gatsby-attainlabs-cms] No TRUSTPILOT_API_KEY found. " +
292
+ "Set it in your project's .env file (recommended) or pass via plugin options.\n" +
293
+ "Example .env:\n" +
294
+ "TRUSTPILOT_API_KEY=xxxxxxx\n"
295
+ );
296
+ return; // stop execution early
297
+ }
298
+ if (!brand || !businessUnitId) {
299
+ console.warn(
300
+ "⚠️ [gatsby-attainlabs-cms] Invalid or missing 'brand' option for Trustpilot integration. " +
301
+ `Current value: '${brand}'. Supported brands: ${Object.keys(businessIds).join(", ")}. ` +
302
+ "Trustpilot data will not be fetched."
303
+ );
304
+ return; // stop execution early
305
+ }
306
+
307
+ const fetchTrustpilotData = async (endpoint) => {
308
+ try {
309
+ const response = await fetch(
310
+ `https://api.trustpilot.com/v1/business-units/${businessUnitId}/${endpoint}`,
311
+ {
312
+ headers: { ApiKey: apiKey },
313
+ }
314
+ );
315
+
316
+ if (!response.ok) {
317
+ throw new Error(`HTTP error! status: ${response.status}`);
318
+ }
262
319
 
320
+ return await response.json();
321
+ } catch (error) {
322
+ console.error(
323
+ `Failed to fetch data from Trustpilot (${endpoint}):`,
324
+ error.message
325
+ );
326
+ return null;
327
+ }
328
+ };
329
+
330
+ const businessData = await fetchTrustpilotData("");
331
+ const recentReviewsData = await fetchTrustpilotData(
332
+ "reviews?stars=5&includeReportedReviews=true"
333
+ );
334
+
335
+ if (businessData || recentReviewsData) {
336
+ const combinedData = {
337
+ businessData: businessData || {},
338
+ recentReviews: recentReviewsData || {},
339
+ };
340
+
341
+ return createNode({
342
+ ...combinedData,
343
+ id: createNodeId("trustPilotReviews"),
344
+ parent: null,
345
+ internal: {
346
+ type: "TrustPilotReviews",
347
+ contentDigest: createContentDigest(combinedData),
348
+ },
349
+ });
350
+ }
351
+ };
263
352
  exports.createPages = async ({ actions, store }, pluginOptions) => {
264
- const { brand } = pluginOptions;
353
+ const { brand, environment } = pluginOptions;
265
354
  const { createSlice } = actions;
266
355
  const siteRoot = store.getState().program.directory;
356
+ if (environment === "dev") {
357
+ console.log(
358
+ "ℹ️ [gatsby-attainlabs-cms] Running in 'dev' environment mode. Skipping component sync."
359
+ );
360
+ return;
361
+ }
267
362
  // 🚨 Validate brand option
268
363
  if (!brand || !brands[brand]) {
269
364
  throw new Error(
@@ -292,34 +387,38 @@ exports.createPages = async ({ actions, store }, pluginOptions) => {
292
387
  },
293
388
  },
294
389
  id,
390
+ published,
295
391
  } = page;
296
392
 
297
- //Generate page's blocks slices
298
- await Promise.all(
299
- content.map(async (b) => {
300
- const name = b.props.component.name;
301
- const blockId = `block--${pageUrl}--${name}--${id}`;
302
- console.log(`Creating slice: ${blockId}`);
303
- // here we could await something per slice if needed later
304
- createSlice({
305
- id: blockId,
306
- component: path.resolve(
307
- siteRoot,
308
- "src/cms/components/sliceWrapper.tsx"
309
- ),
310
- context: {
311
- componentPath: `./src/cms/components/${b.props.component.path}/index.tsx`,
312
- ...b.props,
313
- },
314
- });
315
- })
316
- );
317
-
318
- const pageSource = await createPage(content, pageUrl, id);
319
- const outPath = path.join(siteRoot, "src/pages", `${pageUrl}.tsx`);
320
- // Generate the page itself
321
- await fse.outputFile(outPath, pageSource);
322
- console.log(`✅ Wrote page to ${outPath}`);
393
+ if (published) {
394
+ //Generate page's blocks slices
395
+ await Promise.all(
396
+ content.map(async (b) => {
397
+ const name = b.props.component.name;
398
+ const blockId = `block--${pageUrl}--${name}--${id}`;
399
+ console.log(`Creating slice: ${blockId}`);
400
+ // here we could await something per slice if needed later
401
+ createSlice({
402
+ id: blockId,
403
+ component: path.resolve(
404
+ siteRoot,
405
+ "src/cms/components/sliceWrapper.tsx"
406
+ ),
407
+ context: {
408
+ componentPath: `./src/cms/components/${b.props.component.path}/index.tsx`,
409
+ ...b.props,
410
+ },
411
+ });
412
+ })
413
+ );
414
+
415
+ const pageSource = await createPage(content, pageUrl, id);
416
+ const outPath = path.join(siteRoot, "src/pages", `${pageUrl}.tsx`);
417
+ // Generate the page itself
418
+ await fse.outputFile(outPath, pageSource);
419
+ console.log(`✅ Wrote page to ${outPath}`);
420
+ }
323
421
  }
324
422
  }
325
423
  };
424
+
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "gatsby-attainlabs-cms",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
- "types": "dist/index.d.ts",
6
+ "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
9
  "build": "tsc"
@@ -16,6 +16,11 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "dotenv": "^17.2.1",
19
+ "gatsby-background-image": "^1.6.0",
20
+ "gatsby-plugin-image": "^3.15.0",
21
+ "gatsby-plugin-sharp": "^5.15.0",
22
+ "gatsby-source-filesystem": "^5.15.0",
23
+ "gatsby-transformer-sharp": "^5.15.0",
19
24
  "prettier": "^3.6.2",
20
25
  "react-slick": "^0.31.0"
21
26
  },