@driveflux/cms 2.0.1 → 2.0.2

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,21 +4,22 @@ 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,21 +310,22 @@ 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
- */ async getPostsForBlog(first, after) {
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) {
328
329
  const data = await this.fetchAPI(`
329
330
  query Posts($first: Int!, $after: String, $stage: Stage!) {
330
331
  posts(first: $first, after: $after, stage: $stage, where: {OR:[{featured: null}, {featured_not: true}]}, orderBy: date_DESC) {
@@ -346,7 +347,8 @@ export class GraphCMS {
346
347
  category
347
348
  }
348
349
 
349
- ${!after ? `featured: posts(first: 3, stage: $stage, where: { featured: true }, orderBy: date_DESC) {
350
+ ${!after
351
+ ? `featured: posts(first: 3, stage: $stage, where: { featured: true }, orderBy: date_DESC) {
350
352
  title
351
353
  slug
352
354
  excerpt
@@ -362,48 +364,52 @@ export class GraphCMS {
362
364
  })
363
365
  }
364
366
  category
365
- }` : ''}
367
+ }`
368
+ : ''}
366
369
  }
367
370
  `, {
368
371
  first,
369
- after
372
+ after,
370
373
  });
371
374
  return data;
372
375
  }
373
376
  /**
374
- * Get a list of post slugs. This is used for getStaticPaths()
375
- *
376
- * @param first take first X elements
377
- */ async getPostsSlugs(first) {
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) {
378
382
  const data = await this.fetchAPI(`
379
383
  query PostsWithSlugs($first: Int!) {
380
384
  posts(first: $first) {
381
385
  slug
382
386
  }
383
387
  }`, {
384
- first
388
+ first,
385
389
  });
386
- return data.posts.map((p)=>p.slug);
390
+ return data.posts.map((p) => p.slug);
387
391
  }
388
392
  /**
389
- * Get a list of page slugs. This is used for getStaticPaths()
390
- *
391
- * @param first take first X elements
392
- */ async getPagesSlugs(first) {
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) {
393
398
  const data = await this.fetchAPI(`
394
399
  query PagesSlugs($first: Int!) {
395
400
  pages(first: $first) {
396
401
  slug
397
402
  }
398
403
  }`, {
399
- first
404
+ first,
400
405
  });
401
- return data.pages.map((p)=>p.slug);
406
+ return data.pages.map((p) => p.slug);
402
407
  }
403
408
  /**
404
- * Get a list of entries for the sitemap
405
- *
406
- */ async getSitemap() {
409
+ * Get a list of entries for the sitemap
410
+ *
411
+ */
412
+ async getSitemap() {
407
413
  const data = await this.fetchAPI(`
408
414
  query Sitemap() {
409
415
  pages() {
@@ -416,23 +422,24 @@ export class GraphCMS {
416
422
  }
417
423
  }`);
418
424
  return [
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
- })) || []
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
+ })) || []),
429
435
  ];
430
436
  }
431
437
  /**
432
- * Get a page
433
- *
434
- * @param slug slug of the page
435
- */ async getPage(slug) {
438
+ * Get a page
439
+ *
440
+ * @param slug slug of the page
441
+ */
442
+ async getPage(slug) {
436
443
  const data = await this.fetchAPI(`
437
444
  query PageBySlug($slug: String!, $stage: Stage!) {
438
445
  page(where: { slug: $slug }, stage: $stage) {
@@ -641,7 +648,7 @@ export class GraphCMS {
641
648
  }
642
649
  }
643
650
  }`, {
644
- slug
651
+ slug,
645
652
  });
646
653
  if (!data.page) {
647
654
  return null;
@@ -649,26 +656,31 @@ export class GraphCMS {
649
656
  const { sections, ...pageData } = data.page;
650
657
  return {
651
658
  ...pageData,
652
- sections: this.fixSectionArrays(sections)
659
+ sections: this.fixSectionArrays(sections),
653
660
  };
654
661
  }
655
662
  fixSectionArrays(sections) {
656
663
  const newSections = [];
657
- for (const section of sections){
664
+ for (const section of sections) {
658
665
  const fixedSection = cloneDeep(section);
659
- for (const key of Object.keys(fixedSection)){
666
+ for (const key of Object.keys(fixedSection)) {
660
667
  if (key.startsWith('_dedupe')) {
661
668
  const parts = key.split('_');
662
669
  // Remove the first two
663
670
  parts.shift();
664
671
  parts.shift();
665
- fixedSection[parts.join('')] = fixedSection[key];
672
+ fixedSection[parts.join('')] =
673
+ fixedSection[key];
666
674
  // @ts-expect-error // TODO
667
675
  delete fixedSection[key];
668
676
  }
669
677
  }
670
- newSections.push(this.#sectionHandlers[section.__typename] ? this.#sectionHandlers[section.__typename](fixedSection) : fixedSection);
678
+ newSections.push(this.#sectionHandlers[section.__typename]
679
+ ? // @ts-expect-error // TODO
680
+ this.#sectionHandlers[section.__typename](fixedSection)
681
+ : fixedSection);
671
682
  }
672
683
  return newSections;
673
684
  }
674
685
  }
686
+ //# sourceMappingURL=graphcms.js.map
@@ -1,5 +1,6 @@
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 +1,2 @@
1
- export { };
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './hygraph/types.js';
2
2
  export * from './hygraph/index.js';
3
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/cms",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -12,15 +12,15 @@
12
12
  "dist"
13
13
  ],
14
14
  "dependencies": {
15
- "@driveflux/singleton": "2.0.1",
16
- "@driveflux/utils": "5.0.1",
15
+ "@driveflux/singleton": "2.0.2",
16
+ "@driveflux/utils": "5.0.2",
17
17
  "@graphcms/rich-text-types": "^0.5.1",
18
18
  "p-throttle": "^7.0.0",
19
19
  "zod": "^3.24.4"
20
20
  },
21
21
  "devDependencies": {
22
- "@driveflux/fab": "3.0.1",
23
- "@driveflux/tsconfig": "2.0.1",
22
+ "@driveflux/fab": "3.0.2",
23
+ "@driveflux/tsconfig": "2.0.2",
24
24
  "@swc/cli": "0.7.5",
25
25
  "@swc/core": "1.11.24",
26
26
  "@types/lodash": "^4.17.16",