@driveflux/cms 3.0.2 → 3.0.3

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/dist/config.js CHANGED
@@ -4,22 +4,21 @@ export const ConfigValidation = z.object({
4
4
  graphCms: z.object({
5
5
  devAuthToken: z.string(),
6
6
  prodAuthToken: z.string(),
7
- projectApi: z.string(),
8
- }),
7
+ projectApi: z.string()
8
+ })
9
9
  });
10
- export const getConfig = () => ConfigValidation.parse({
11
- graphCms: {
12
- devAuthToken: process.env.GRAPHCMS_AUTH_TOKEN,
13
- prodAuthToken: process.env.GRAPHCMS_AUTH_TOKEN,
14
- projectApi: process.env.GRAPHCMS_PROJECT_API,
15
- },
16
- });
17
- export let config = initSingleton('fluxCmsConfug', () => getConfig());
18
- export const setConfig = (key, value) => {
10
+ export const getConfig = ()=>ConfigValidation.parse({
11
+ graphCms: {
12
+ devAuthToken: process.env.GRAPHCMS_AUTH_TOKEN,
13
+ prodAuthToken: process.env.GRAPHCMS_AUTH_TOKEN,
14
+ projectApi: process.env.GRAPHCMS_PROJECT_API
15
+ }
16
+ });
17
+ export let config = initSingleton('fluxCmsConfug', ()=>getConfig());
18
+ export const setConfig = (key, value)=>{
19
19
  config[key] = value;
20
20
  };
21
- export const resetConfig = () => {
22
- config = initSingleton('fluxCmsConfug', () => getConfig(), true);
21
+ export const resetConfig = ()=>{
22
+ config = initSingleton('fluxCmsConfug', ()=>getConfig(), true);
23
23
  return config;
24
24
  };
25
- //# sourceMappingURL=config.js.map
@@ -1,130 +1,130 @@
1
1
  import { cloneDeep } from '@driveflux/utils';
2
2
  import pThrottle from 'p-throttle';
3
- const headerProps = ({ header, forceHeaderAlign }) => ({
4
- header,
5
- forceHeaderAlign,
6
- });
7
- const buttonProps = ({ buttonLink, buttonText }) => ({
8
- buttonLink,
9
- buttonText,
10
- });
3
+ const headerProps = ({ header, forceHeaderAlign })=>({
4
+ header,
5
+ forceHeaderAlign
6
+ });
7
+ const buttonProps = ({ buttonLink, buttonText })=>({
8
+ buttonLink,
9
+ buttonText
10
+ });
11
11
  const DEFAULT_SECTION_HANDLERS = {
12
- Reviews: (section) => {
12
+ Reviews: (section)=>{
13
13
  return {
14
14
  __typename: section.__typename,
15
15
  ...headerProps(section),
16
16
  ...buttonProps(section),
17
- reviews: section.names.map((name, i) => {
17
+ reviews: section.names.map((name, i)=>{
18
18
  const data = {
19
19
  name,
20
20
  image: section.images?.[i],
21
21
  vehicle: section.vehicles?.[i],
22
- review: section.reviews?.[i],
22
+ review: section.reviews?.[i]
23
23
  };
24
- for (const key of Object.keys(data)) {
24
+ for (const key of Object.keys(data)){
25
25
  if (data[key] === undefined) {
26
26
  delete data[key];
27
27
  }
28
28
  }
29
29
  return data;
30
- }),
30
+ })
31
31
  };
32
32
  },
33
- VehicleShowcase: (section) => {
33
+ VehicleShowcase: (section)=>{
34
34
  return {
35
35
  __typename: section.__typename,
36
36
  ...headerProps(section),
37
37
  ...buttonProps(section),
38
- vehicles: section.topTitles.map((topTitle, i) => {
38
+ vehicles: section.topTitles.map((topTitle, i)=>{
39
39
  const data = {
40
40
  topTitle,
41
41
  secondaryTitle: section.secondaryTitles?.[i],
42
42
  photo: section.photos?.[i],
43
- content: section.contents?.[i],
43
+ content: section.contents?.[i]
44
44
  };
45
- for (const key of Object.keys(data)) {
45
+ for (const key of Object.keys(data)){
46
46
  if (data[key] === undefined) {
47
47
  delete data[key];
48
48
  }
49
49
  }
50
50
  return data;
51
- }),
51
+ })
52
52
  };
53
53
  },
54
- MultiplePhotoCaption: (section) => {
54
+ MultiplePhotoCaption: (section)=>{
55
55
  return {
56
56
  __typename: section.__typename,
57
57
  ...headerProps(section),
58
58
  ...buttonProps(section),
59
59
  useIconSize: section.useIconSize,
60
- photoCaptions: section.photos.map((photo, i) => {
60
+ photoCaptions: section.photos.map((photo, i)=>{
61
61
  const data = {
62
62
  photo,
63
63
  description: section.descriptions?.[i],
64
- title: section.titles?.[i],
64
+ title: section.titles?.[i]
65
65
  };
66
- for (const key of Object.keys(data)) {
66
+ for (const key of Object.keys(data)){
67
67
  if (data[key] === undefined) {
68
68
  delete data[key];
69
69
  }
70
70
  }
71
71
  return data;
72
- }),
72
+ })
73
73
  };
74
74
  },
75
- PhotoCarousel: (section) => {
75
+ PhotoCarousel: (section)=>{
76
76
  return {
77
77
  __typename: section.__typename,
78
78
  ...headerProps(section),
79
79
  ...buttonProps(section),
80
- photos: section.photos.map((photo, i) => {
80
+ photos: section.photos.map((photo, i)=>{
81
81
  const data = {
82
82
  photo,
83
83
  title: section.titles?.[i],
84
- href: section.hrefs?.[i],
84
+ href: section.hrefs?.[i]
85
85
  };
86
- for (const key of Object.keys(data)) {
86
+ for (const key of Object.keys(data)){
87
87
  if (data[key] === undefined) {
88
88
  delete data[key];
89
89
  }
90
90
  }
91
91
  return data;
92
- }),
92
+ })
93
93
  };
94
94
  },
95
- BigTextColumns: (section) => {
95
+ BigTextColumns: (section)=>{
96
96
  return {
97
97
  __typename: section.__typename,
98
98
  ...headerProps(section),
99
99
  ...buttonProps(section),
100
100
  content: section.content,
101
- columns: section.bigTitles.map((bigTitle, i) => {
101
+ columns: section.bigTitles.map((bigTitle, i)=>{
102
102
  const data = {
103
103
  bigTitle,
104
104
  smallTitle: section.smallTitles?.[i],
105
- description: section.descriptions?.[i],
105
+ description: section.descriptions?.[i]
106
106
  };
107
- for (const key of Object.keys(data)) {
107
+ for (const key of Object.keys(data)){
108
108
  if (data[key] === undefined) {
109
109
  delete data[key];
110
110
  }
111
111
  }
112
112
  return data;
113
- }),
113
+ })
114
114
  };
115
- },
115
+ }
116
116
  };
117
117
  const throttle = pThrottle({
118
118
  limit: 5,
119
- interval: 1000,
119
+ interval: 1000
120
120
  });
121
- export const throttledFetch = throttle(async (req, init) => fetch(req, init));
121
+ export const throttledFetch = throttle(async (req, init)=>fetch(req, init));
122
122
  export class GraphCMS {
123
123
  preview;
124
124
  #config;
125
125
  #locale;
126
126
  #sectionHandlers;
127
- constructor(config, preview = false, locale) {
127
+ constructor(config, preview = false, locale){
128
128
  this.preview = preview;
129
129
  this.#config = config;
130
130
  this.#locale = locale;
@@ -135,7 +135,7 @@ export class GraphCMS {
135
135
  //@ts-expect-error - this is a browser import, we will fix it later!
136
136
  const headers = {
137
137
  'Content-Type': 'application/json',
138
- Authorization: `Bearer ${this.preview ? this.#config.devAuthToken : this.#config.prodAuthToken}`,
138
+ Authorization: `Bearer ${this.preview ? this.#config.devAuthToken : this.#config.prodAuthToken}`
139
139
  };
140
140
  if (this.#locale) {
141
141
  headers['gcms-locales'] = `${this.#locale},en`;
@@ -147,11 +147,11 @@ export class GraphCMS {
147
147
  query,
148
148
  variables: {
149
149
  ...variables,
150
- stage: this.stage(),
151
- },
152
- }),
150
+ stage: this.stage()
151
+ }
152
+ })
153
153
  });
154
- const json = (await res.json());
154
+ const json = await res.json();
155
155
  if (json.errors) {
156
156
  console.error('GraphCMS Error:', JSON.stringify(json.errors, undefined, 2));
157
157
  const error = new Error('Failed to fetch API');
@@ -218,7 +218,7 @@ export class GraphCMS {
218
218
  }
219
219
  }
220
220
  `, {
221
- id,
221
+ id
222
222
  });
223
223
  return data.post;
224
224
  }
@@ -274,7 +274,7 @@ export class GraphCMS {
274
274
  }
275
275
  }
276
276
  `, {
277
- slug,
277
+ slug
278
278
  });
279
279
  const post = data1.post;
280
280
  if (!post) {
@@ -310,22 +310,21 @@ export class GraphCMS {
310
310
  }
311
311
  }
312
312
  `, {
313
- postId: post.id,
313
+ postId: post.id
314
314
  });
315
315
  return {
316
316
  ...data1,
317
317
  next: data2.next?.[0],
318
318
  previous: data2.previous?.[0],
319
- latest: data2.latest,
319
+ latest: data2.latest
320
320
  };
321
321
  }
322
322
  /**
323
- * Get a list of posts
324
- *
325
- * @param first take first X elements
326
- * @param after after ID
327
- */
328
- async getPostsForBlog(first, after) {
323
+ * Get a list of posts
324
+ *
325
+ * @param first take first X elements
326
+ * @param after after ID
327
+ */ async getPostsForBlog(first, after) {
329
328
  const data = await this.fetchAPI(`
330
329
  query Posts($first: Int!, $after: String, $stage: Stage!) {
331
330
  posts(first: $first, after: $after, stage: $stage, where: {OR:[{featured: null}, {featured_not: true}]}, orderBy: date_DESC) {
@@ -347,8 +346,7 @@ export class GraphCMS {
347
346
  category
348
347
  }
349
348
 
350
- ${!after
351
- ? `featured: posts(first: 3, stage: $stage, where: { featured: true }, orderBy: date_DESC) {
349
+ ${!after ? `featured: posts(first: 3, stage: $stage, where: { featured: true }, orderBy: date_DESC) {
352
350
  title
353
351
  slug
354
352
  excerpt
@@ -364,52 +362,48 @@ export class GraphCMS {
364
362
  })
365
363
  }
366
364
  category
367
- }`
368
- : ''}
365
+ }` : ''}
369
366
  }
370
367
  `, {
371
368
  first,
372
- after,
369
+ after
373
370
  });
374
371
  return data;
375
372
  }
376
373
  /**
377
- * Get a list of post slugs. This is used for getStaticPaths()
378
- *
379
- * @param first take first X elements
380
- */
381
- async getPostsSlugs(first) {
374
+ * Get a list of post slugs. This is used for getStaticPaths()
375
+ *
376
+ * @param first take first X elements
377
+ */ async getPostsSlugs(first) {
382
378
  const data = await this.fetchAPI(`
383
379
  query PostsWithSlugs($first: Int!) {
384
380
  posts(first: $first) {
385
381
  slug
386
382
  }
387
383
  }`, {
388
- first,
384
+ first
389
385
  });
390
- return data.posts.map((p) => p.slug);
386
+ return data.posts.map((p)=>p.slug);
391
387
  }
392
388
  /**
393
- * Get a list of page slugs. This is used for getStaticPaths()
394
- *
395
- * @param first take first X elements
396
- */
397
- async getPagesSlugs(first) {
389
+ * Get a list of page slugs. This is used for getStaticPaths()
390
+ *
391
+ * @param first take first X elements
392
+ */ async getPagesSlugs(first) {
398
393
  const data = await this.fetchAPI(`
399
394
  query PagesSlugs($first: Int!) {
400
395
  pages(first: $first) {
401
396
  slug
402
397
  }
403
398
  }`, {
404
- first,
399
+ first
405
400
  });
406
- return data.pages.map((p) => p.slug);
401
+ return data.pages.map((p)=>p.slug);
407
402
  }
408
403
  /**
409
- * Get a list of entries for the sitemap
410
- *
411
- */
412
- async getSitemap() {
404
+ * Get a list of entries for the sitemap
405
+ *
406
+ */ async getSitemap() {
413
407
  const data = await this.fetchAPI(`
414
408
  query Sitemap() {
415
409
  pages() {
@@ -422,24 +416,23 @@ export class GraphCMS {
422
416
  }
423
417
  }`);
424
418
  return [
425
- ...(data.pages?.map((p) => ({
426
- type: 'page',
427
- slug: p.slug,
428
- lastModifiedAt: p.updatedAt,
429
- })) || []),
430
- ...(data.posts?.map((p) => ({
431
- type: 'post',
432
- slug: p.slug,
433
- lastModifiedAt: p.updatedAt,
434
- })) || []),
419
+ ...data.pages?.map((p)=>({
420
+ type: 'page',
421
+ slug: p.slug,
422
+ lastModifiedAt: p.updatedAt
423
+ })) || [],
424
+ ...data.posts?.map((p)=>({
425
+ type: 'post',
426
+ slug: p.slug,
427
+ lastModifiedAt: p.updatedAt
428
+ })) || []
435
429
  ];
436
430
  }
437
431
  /**
438
- * Get a page
439
- *
440
- * @param slug slug of the page
441
- */
442
- async getPage(slug) {
432
+ * Get a page
433
+ *
434
+ * @param slug slug of the page
435
+ */ async getPage(slug) {
443
436
  const data = await this.fetchAPI(`
444
437
  query PageBySlug($slug: String!, $stage: Stage!) {
445
438
  page(where: { slug: $slug }, stage: $stage) {
@@ -648,7 +641,7 @@ export class GraphCMS {
648
641
  }
649
642
  }
650
643
  }`, {
651
- slug,
644
+ slug
652
645
  });
653
646
  if (!data.page) {
654
647
  return null;
@@ -656,31 +649,26 @@ export class GraphCMS {
656
649
  const { sections, ...pageData } = data.page;
657
650
  return {
658
651
  ...pageData,
659
- sections: this.fixSectionArrays(sections),
652
+ sections: this.fixSectionArrays(sections)
660
653
  };
661
654
  }
662
655
  fixSectionArrays(sections) {
663
656
  const newSections = [];
664
- for (const section of sections) {
657
+ for (const section of sections){
665
658
  const fixedSection = cloneDeep(section);
666
- for (const key of Object.keys(fixedSection)) {
659
+ for (const key of Object.keys(fixedSection)){
667
660
  if (key.startsWith('_dedupe')) {
668
661
  const parts = key.split('_');
669
662
  // Remove the first two
670
663
  parts.shift();
671
664
  parts.shift();
672
- fixedSection[parts.join('')] =
673
- fixedSection[key];
665
+ fixedSection[parts.join('')] = fixedSection[key];
674
666
  // @ts-expect-error // TODO
675
667
  delete fixedSection[key];
676
668
  }
677
669
  }
678
- newSections.push(this.#sectionHandlers[section.__typename]
679
- ? // @ts-expect-error // TODO
680
- this.#sectionHandlers[section.__typename](fixedSection)
681
- : fixedSection);
670
+ newSections.push(this.#sectionHandlers[section.__typename] ? this.#sectionHandlers[section.__typename](fixedSection) : fixedSection);
682
671
  }
683
672
  return newSections;
684
673
  }
685
674
  }
686
- //# sourceMappingURL=graphcms.js.map
@@ -1,6 +1,5 @@
1
1
  import { config } from '../config.js';
2
2
  import { GraphCMS } from './drivers/graphcms.js';
3
- export const getHygraph = (preview, locale) => {
3
+ export const getHygraph = (preview, locale)=>{
4
4
  return new GraphCMS(config.graphCms, preview, locale);
5
5
  };
6
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ export { };
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './hygraph/index.js';
2
2
  export * from './hygraph/types.js';
3
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/cms",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -12,17 +12,17 @@
12
12
  "dist"
13
13
  ],
14
14
  "dependencies": {
15
- "@driveflux/singleton": "3.0.2",
15
+ "@driveflux/singleton": "3.0.3",
16
16
  "@driveflux/utils": "6.0.2",
17
17
  "@graphcms/rich-text-types": "^0.5.1",
18
18
  "p-throttle": "^8.1.0",
19
19
  "zod": "^4.4.3"
20
20
  },
21
21
  "devDependencies": {
22
- "@driveflux/fab": "4.0.2",
22
+ "@driveflux/fab": "4.0.3",
23
23
  "@driveflux/tsconfig": "3.0.2",
24
24
  "@swc/cli": "^0.8.1",
25
- "@swc/core": "^1.15.33",
25
+ "@swc/core": "^1.15.40",
26
26
  "@types/lodash": "^4.17.24",
27
27
  "@types/node": "^25.9.1",
28
28
  "del-cli": "^7.0.0",