@anywayseo/gatsby-plugin 1.1.0 → 2.0.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 (61) hide show
  1. package/gatsby-node.d.ts +4 -4
  2. package/gatsby-node.js +60 -80
  3. package/package.json +9 -2
  4. package/types/index.d.ts +8 -2
  5. package/utils/slug.d.ts +2 -0
  6. package/utils/slug.js +8 -0
  7. package/utils/strapi-source/index.d.ts +5 -0
  8. package/utils/strapi-source/index.js +13 -0
  9. package/utils/strapi-source/schema/components.d.ts +1 -0
  10. package/utils/strapi-source/schema/components.js +152 -0
  11. package/utils/strapi-source/schema/index.d.ts +1 -0
  12. package/utils/strapi-source/schema/index.js +10 -0
  13. package/utils/strapi-source/schema/localization.d.ts +1 -0
  14. package/utils/strapi-source/schema/localization.js +14 -0
  15. package/utils/strapi-source/schema/navigation.d.ts +1 -0
  16. package/utils/strapi-source/schema/navigation.js +25 -0
  17. package/utils/strapi-source/schema/page.d.ts +1 -0
  18. package/utils/strapi-source/schema/page.js +17 -0
  19. package/utils/strapi-source/schema/shared.d.ts +1 -0
  20. package/utils/strapi-source/schema/shared.js +22 -0
  21. package/utils/strapi-source/schema/site.d.ts +1 -0
  22. package/utils/strapi-source/schema/site.js +14 -0
  23. package/utils/{strapi-client.d.ts → strapi-source/strapi-client/index.d.ts} +2 -1
  24. package/utils/strapi-source/strapi-client/index.js +44 -0
  25. package/utils/strapi-source/strapi-content/clean-entity.d.ts +2 -0
  26. package/utils/strapi-source/strapi-content/clean-entity.js +93 -0
  27. package/utils/strapi-source/strapi-content/create-nodes.d.ts +3 -0
  28. package/utils/strapi-source/strapi-content/create-nodes.js +202 -0
  29. package/utils/strapi-source/strapi-content/delete-nodes.d.ts +3 -0
  30. package/utils/strapi-source/strapi-content/delete-nodes.js +76 -0
  31. package/utils/strapi-source/strapi-content/download-media.d.ts +15 -0
  32. package/utils/strapi-source/strapi-content/download-media.js +174 -0
  33. package/utils/strapi-source/strapi-content/fetch-entity.d.ts +4 -0
  34. package/utils/strapi-source/strapi-content/fetch-entity.js +35 -0
  35. package/utils/strapi-source/strapi-content/fetch-schemas.d.ts +3 -0
  36. package/utils/strapi-source/strapi-content/fetch-schemas.js +23 -0
  37. package/utils/strapi-source/strapi-content/get-cached-entities.d.ts +3 -0
  38. package/utils/strapi-source/strapi-content/get-cached-entities.js +27 -0
  39. package/utils/strapi-source/strapi-content/get-endpoints.d.ts +2 -0
  40. package/utils/strapi-source/strapi-content/get-endpoints.js +32 -0
  41. package/utils/strapi-source/strapi-content/get-entities.d.ts +2 -0
  42. package/utils/strapi-source/strapi-content/get-entities.js +17 -0
  43. package/utils/strapi-source/strapi-content/helpers.d.ts +9 -0
  44. package/utils/strapi-source/strapi-content/helpers.js +56 -0
  45. package/utils/strapi-source/strapi-content/index.d.ts +3 -0
  46. package/utils/strapi-source/strapi-content/index.js +113 -0
  47. package/utils/strapi-source/strapi-content/types.d.ts +43 -0
  48. package/utils/strapi-source/strapi-content/types.js +2 -0
  49. package/utils/strapi-source/strapi-content/utils.d.ts +5 -0
  50. package/utils/strapi-source/strapi-content/utils.js +30 -0
  51. package/utils/strapi-source/strapi-localization/index.d.ts +3 -0
  52. package/utils/strapi-source/strapi-localization/index.js +38 -0
  53. package/utils/strapi-source/strapi-localization/types.d.ts +9 -0
  54. package/utils/strapi-source/strapi-localization/types.js +2 -0
  55. package/utils/strapi-source/strapi-navigation/index.d.ts +3 -0
  56. package/utils/strapi-source/strapi-navigation/index.js +48 -0
  57. package/utils/strapi-source/strapi-navigation/types.d.ts +5 -0
  58. package/utils/strapi-source/strapi-navigation/types.js +2 -0
  59. package/utils/schema.d.ts +0 -1
  60. package/utils/schema.js +0 -194
  61. package/utils/strapi-client.js +0 -20
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getCachedEntities = getCachedEntities;
13
+ const TIMESTAMP_KEY = 'timestamp';
14
+ function getCachedEntities(cache, endpoints, onFetch) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const timestamp = yield cache.get(TIMESTAMP_KEY);
17
+ let cachedEntities = null;
18
+ if (Boolean(timestamp)) {
19
+ const deltaEndpoints = endpoints.map((endpoint) => {
20
+ return Object.assign(Object.assign({}, endpoint), { queryParams: Object.assign(Object.assign({}, endpoint.queryParams), { filters: Object.assign(Object.assign({}, endpoint.queryParams.filters), { updatedAt: { $gt: timestamp } }) }) });
21
+ });
22
+ cachedEntities = yield Promise.all(deltaEndpoints.map((endpoint) => onFetch(endpoint)));
23
+ }
24
+ yield cache.set(TIMESTAMP_KEY, Date.now());
25
+ return cachedEntities;
26
+ });
27
+ }
@@ -0,0 +1,2 @@
1
+ import type { Schema, SchemaEndpoint, TypeConfig } from './types';
2
+ export declare function getEndpoints(schemas: Schema[], typeConfigs: TypeConfig[]): SchemaEndpoint[];
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEndpoints = getEndpoints;
4
+ const helpers_1 = require("./helpers");
5
+ function getEndpoints(schemas, typeConfigs) {
6
+ const endpoints = schemas.filter((0, helpers_1.isValidEndpoint)(typeConfigs)).map(({ schema, uid, plugin }) => {
7
+ const { kind, singularName, pluralName } = schema;
8
+ const typeConfig = typeConfigs.find((config) => config.singularName === singularName);
9
+ const { queryParams, queryLimit } = typeConfig;
10
+ const defaultSingleTypeQueryParams = { populate: '*' };
11
+ const defaultCollectionTypeQueryParams = {
12
+ populate: '*',
13
+ pagination: {
14
+ pageSize: queryLimit || 100,
15
+ page: 1,
16
+ },
17
+ };
18
+ const pluginPrefix = plugin && singularName !== 'user' ? `${plugin}/` : '';
19
+ const endpoint = `${pluginPrefix}${kind === 'singleType' ? singularName : pluralName}`;
20
+ const schemaEndpoint = Object.assign({ uid,
21
+ endpoint,
22
+ singularName,
23
+ kind }, (kind === 'singleType'
24
+ ? { queryParams: queryParams || defaultSingleTypeQueryParams }
25
+ : {
26
+ pluralName: pluralName,
27
+ queryParams: queryParams || defaultCollectionTypeQueryParams,
28
+ }));
29
+ return schemaEndpoint;
30
+ });
31
+ return endpoints;
32
+ }
@@ -0,0 +1,2 @@
1
+ import type { SchemaEndpoint, Entity } from './types';
2
+ export declare function getEntities(endpoints: SchemaEndpoint[], onFetch: (endpoint: SchemaEndpoint) => Promise<Entity[]>): Promise<Entity[][]>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getEntities = getEntities;
13
+ function getEntities(endpoints, onFetch) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ return yield Promise.all(endpoints.map((endpoint) => onFetch(endpoint)));
16
+ });
17
+ }
@@ -0,0 +1,9 @@
1
+ import type { Node } from 'gatsby';
2
+ import type { Schema, TypeConfig } from './types';
3
+ export declare function isStrapiOrFileNode(node: Node): boolean;
4
+ export declare function isValidEndpoint(config: TypeConfig[]): (endpoint: Schema) => boolean;
5
+ export declare function convertQueryParameters(queryParameters: Record<string, any>): Record<string, any>;
6
+ export declare function getContentTypeSchema(schemas: Schema[], uid: string): Schema | null;
7
+ export declare function makeNodeName(singularName: string): string;
8
+ export declare function makeComponentNodeName(uid: string): string;
9
+ export declare function makeParentNodeName(schemas: Schema[], uid: string): string;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.isStrapiOrFileNode = isStrapiOrFileNode;
15
+ exports.isValidEndpoint = isValidEndpoint;
16
+ exports.convertQueryParameters = convertQueryParameters;
17
+ exports.getContentTypeSchema = getContentTypeSchema;
18
+ exports.makeNodeName = makeNodeName;
19
+ exports.makeComponentNodeName = makeComponentNodeName;
20
+ exports.makeParentNodeName = makeParentNodeName;
21
+ const utils_1 = require("./utils");
22
+ function isStrapiOrFileNode(node) {
23
+ return node.internal.owner === '@anywayseo/gatsby-plugin' || node.internal.type === 'File';
24
+ }
25
+ function isValidEndpoint(config) {
26
+ return ({ uid, schema }) => {
27
+ const hasConfig = config.some(({ singularName }) => singularName === schema.singularName);
28
+ const isAdminUid = uid.startsWith('admin::');
29
+ return !isAdminUid && hasConfig;
30
+ };
31
+ }
32
+ function convertQueryParameters(queryParameters) {
33
+ const { publicationState } = queryParameters, rest = __rest(queryParameters, ["publicationState"]);
34
+ return publicationState === 'preview' ? Object.assign(Object.assign({}, rest), { status: 'draft' }) : queryParameters;
35
+ }
36
+ function getContentTypeSchema(schemas, uid) {
37
+ var _a;
38
+ const schema = (_a = schemas.find((schema) => schema.uid === uid)) !== null && _a !== void 0 ? _a : null;
39
+ return schema;
40
+ }
41
+ function makeNodeName(singularName) {
42
+ return `Strapi_${(0, utils_1.toSnakeCase)(singularName)}`.toUpperCase();
43
+ }
44
+ function makeComponentNodeName(uid) {
45
+ return `Strapi__Component_${(0, utils_1.toSnakeCase)(uid)}`.toUpperCase();
46
+ }
47
+ function makeParentNodeName(schemas, uid) {
48
+ const schema = getContentTypeSchema(schemas, uid);
49
+ if (!schema) {
50
+ return '';
51
+ }
52
+ const { singularName, kind } = schema.schema;
53
+ const isComponentType = !['collectionType', 'singleType'].includes(kind);
54
+ const nodeName = isComponentType ? makeComponentNodeName(uid) : makeNodeName(singularName);
55
+ return nodeName;
56
+ }
@@ -0,0 +1,3 @@
1
+ import type { SourceNodesArgs } from 'gatsby';
2
+ import type { StrapiClient } from '../strapi-client';
3
+ export declare function sourceStrapiContentNode(args: SourceNodesArgs, strapiClient: StrapiClient): Promise<void>;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.sourceStrapiContentNode = sourceStrapiContentNode;
13
+ const create_nodes_1 = require("./create-nodes");
14
+ const delete_nodes_1 = require("./delete-nodes");
15
+ const download_media_1 = require("./download-media");
16
+ const fetch_entity_1 = require("./fetch-entity");
17
+ const fetch_schemas_1 = require("./fetch-schemas");
18
+ const get_endpoints_1 = require("./get-endpoints");
19
+ const get_entities_1 = require("./get-entities");
20
+ const config = {
21
+ skipFileDownloads: false,
22
+ };
23
+ const singleTypes = [
24
+ {
25
+ singularName: 'site',
26
+ queryParams: { populate: '*' },
27
+ },
28
+ ];
29
+ const collectionTypes = [
30
+ {
31
+ singularName: 'page',
32
+ queryParams: {
33
+ populate: {
34
+ seo: {
35
+ populate: '*',
36
+ },
37
+ content: {
38
+ on: {
39
+ 'content.faq': {
40
+ populate: '*',
41
+ },
42
+ 'content.features': {
43
+ populate: '*',
44
+ },
45
+ 'content.game-demo': {
46
+ populate: '*',
47
+ },
48
+ 'content.game-info': {
49
+ populate: '*',
50
+ },
51
+ 'content.how-to': {
52
+ populate: {
53
+ steps: {
54
+ populate: '*',
55
+ },
56
+ },
57
+ },
58
+ 'content.list': {
59
+ populate: '*',
60
+ },
61
+ 'content.media': {
62
+ populate: '*',
63
+ },
64
+ 'content.pros-cons': {
65
+ populate: '*',
66
+ },
67
+ 'content.rich-text': {
68
+ populate: '*',
69
+ },
70
+ 'content.table': {
71
+ populate: '*',
72
+ },
73
+ 'content.tip': {
74
+ populate: '*',
75
+ },
76
+ },
77
+ },
78
+ author: {
79
+ populate: '*',
80
+ },
81
+ },
82
+ locale: '*',
83
+ },
84
+ },
85
+ ];
86
+ function sourceStrapiContentNode(args, strapiClient) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const { actions, reporter, cache } = args;
89
+ const { createNode } = actions;
90
+ reporter.info('Starting to fetch content data from Strapi');
91
+ const schemas = yield (0, fetch_schemas_1.fetchSchemas)(strapiClient);
92
+ const endpoints = (0, get_endpoints_1.getEndpoints)(schemas, [...singleTypes, ...collectionTypes]);
93
+ // TODO: Add cache values extraction (see. getCachedEntities)
94
+ const entities = yield (0, get_entities_1.getEntities)(endpoints, (endpoint) => (0, fetch_entity_1.fetchEntity)(endpoint, schemas, strapiClient, reporter));
95
+ (0, delete_nodes_1.deleteNodes)(entities, endpoints, args);
96
+ for (const [index, { uid }] of endpoints.entries()) {
97
+ if (entities[index]) {
98
+ if (!config.skipFileDownloads) {
99
+ yield (0, download_media_1.downloadMediaFiles)(entities[index], uid, {
100
+ args,
101
+ schemas,
102
+ strapiClient,
103
+ config: { apiUrl: strapiClient.getApiUrl() },
104
+ });
105
+ }
106
+ for (let entity of entities[index]) {
107
+ const nodes = (0, create_nodes_1.createNodes)(entity, uid, schemas, args);
108
+ yield Promise.all(nodes.map((node) => createNode(node)));
109
+ }
110
+ }
111
+ }
112
+ });
113
+ }
@@ -0,0 +1,43 @@
1
+ export type TypeConfig = {
2
+ singularName: string;
3
+ pluralName?: string;
4
+ queryParams?: Record<string, any>;
5
+ queryLimit?: number;
6
+ };
7
+ export type Schema = {
8
+ uid: string;
9
+ schema: {
10
+ kind: 'collectionType' | 'singleType';
11
+ singularName: string;
12
+ pluralName?: string;
13
+ attributes: AnyAttributes;
14
+ };
15
+ plugin?: string;
16
+ };
17
+ export type SchemaEndpoint = {
18
+ kind: 'collectionType' | 'singleType';
19
+ singularName: string;
20
+ pluralName?: string;
21
+ uid: string;
22
+ endpoint: string;
23
+ queryParams: Record<string, any>;
24
+ };
25
+ interface AnyAttributes {
26
+ [attribute: string]: any;
27
+ }
28
+ export interface Entity extends AnyAttributes {
29
+ id: number;
30
+ documentId?: string;
31
+ createdAt?: string;
32
+ updatedAt?: string;
33
+ publishedAt?: string;
34
+ }
35
+ export interface Meta {
36
+ pagination?: {
37
+ page?: number;
38
+ pageSize?: number;
39
+ pageCount?: number;
40
+ total?: number;
41
+ };
42
+ }
43
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export declare const STRAPI_ID_PROPERTY = "strapi_id";
2
+ export declare function castArray<T>(value: T | T[]): T[];
3
+ export declare function toSnakeCase(str?: string): string;
4
+ export declare function pick<T extends Record<string, any>>(obj: T, keys: string[]): Partial<T>;
5
+ export declare function isPlainObject(obj: unknown): obj is Record<string, any>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STRAPI_ID_PROPERTY = void 0;
4
+ exports.castArray = castArray;
5
+ exports.toSnakeCase = toSnakeCase;
6
+ exports.pick = pick;
7
+ exports.isPlainObject = isPlainObject;
8
+ exports.STRAPI_ID_PROPERTY = 'strapi_id';
9
+ function castArray(value) {
10
+ return Array.isArray(value) ? value : [value];
11
+ }
12
+ function toSnakeCase(str = '') {
13
+ let result = str
14
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
15
+ .replace(/[\s\-]+/g, '_')
16
+ .replace(/\./g, '_');
17
+ return result.toLowerCase();
18
+ }
19
+ function pick(obj, keys) {
20
+ const result = {};
21
+ for (const key of keys) {
22
+ if (key in obj) {
23
+ result[key] = obj[key];
24
+ }
25
+ }
26
+ return result;
27
+ }
28
+ function isPlainObject(obj) {
29
+ return Object.prototype.toString.call(obj) === '[object Object]';
30
+ }
@@ -0,0 +1,3 @@
1
+ import type { SourceNodesArgs } from 'gatsby';
2
+ import type { StrapiClient } from '../strapi-client';
3
+ export declare function sourceStrapiLocalizationNode(args: SourceNodesArgs, strapiClient: StrapiClient): Promise<void>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.sourceStrapiLocalizationNode = sourceStrapiLocalizationNode;
13
+ function sourceStrapiLocalizationNode(args, strapiClient) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const { actions, reporter, createNodeId, createContentDigest } = args;
16
+ reporter.info('Starting to fetch localization data from Strapi');
17
+ try {
18
+ const locales = yield strapiClient.fetch('i18n/locales');
19
+ reporter.info(`Found ${locales.length} locale objects`);
20
+ const nodeMeta = {
21
+ id: createNodeId(`strapi-localization`),
22
+ parent: null,
23
+ children: [],
24
+ internal: {
25
+ type: `StrapiLocalization`,
26
+ mediaType: `application/json`,
27
+ content: JSON.stringify(locales),
28
+ contentDigest: createContentDigest(locales),
29
+ },
30
+ };
31
+ actions.createNode(Object.assign(Object.assign({}, nodeMeta), { locales }));
32
+ reporter.success('Localization node created');
33
+ }
34
+ catch (error) {
35
+ reporter.panicOnBuild('Error fetching list of locales from Strapi:', error);
36
+ }
37
+ });
38
+ }
@@ -0,0 +1,9 @@
1
+ export interface ILocale {
2
+ code: string;
3
+ name: string;
4
+ documentId?: string;
5
+ createdAt?: string;
6
+ updatedAt?: string;
7
+ publishedAt?: string;
8
+ isDefault?: boolean;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import type { SourceNodesArgs } from 'gatsby';
2
+ import type { StrapiClient } from '../strapi-client';
3
+ export declare function sourceStrapiNavigationNode(args: SourceNodesArgs, strapiClient: StrapiClient): Promise<void>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.sourceStrapiNavigationNode = sourceStrapiNavigationNode;
13
+ function sourceStrapiNavigationNode(args, strapiClient) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const { actions, reporter, createNodeId, createContentDigest } = args;
16
+ reporter.info('Starting to fetch navigation data from Strapi');
17
+ try {
18
+ const navigation = yield strapiClient.fetch('navigation');
19
+ reporter.info(`Found ${navigation.length} navigation objects`);
20
+ const strapiNavigation = [];
21
+ for (const { slug, name } of navigation) {
22
+ const navigationItems = yield strapiClient.fetch(`navigation/render/${slug}?type=TREE`);
23
+ if (!navigationItems.length) {
24
+ reporter.warn(`Missing navigation items in ${slug}`);
25
+ continue;
26
+ }
27
+ strapiNavigation.push({ name, slug, items: navigationItems });
28
+ }
29
+ const nodeContent = JSON.stringify(strapiNavigation);
30
+ const nodeMeta = {
31
+ id: createNodeId(`strapi-navigation`),
32
+ parent: null,
33
+ children: [],
34
+ internal: {
35
+ type: `StrapiNavigation`,
36
+ mediaType: `application/json`,
37
+ content: nodeContent,
38
+ contentDigest: createContentDigest(strapiNavigation),
39
+ },
40
+ };
41
+ actions.createNode(Object.assign(Object.assign({}, nodeMeta), { items: strapiNavigation }));
42
+ reporter.success('Navigation node created');
43
+ }
44
+ catch (error) {
45
+ reporter.panicOnBuild('Error fetching navigation from Strapi:', error);
46
+ }
47
+ });
48
+ }
@@ -0,0 +1,5 @@
1
+ export interface INavigationList {
2
+ id: number;
3
+ name: string;
4
+ slug: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/utils/schema.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const typeDefs = "\n # === BASE DEFINITIONS ===\n type Image {\n localFile: File @link(from: \"localFile\")\n alternativeText: String\n }\n\n type Seo {\n metaTitle: String\n metaDescription: String\n }\n\n type Author {\n name: String\n role: String\n bio: String\n avatar: Image\n }\n\n # === STRAPI DEFINITIONS ===\n type StrapiSite implements Node {\n id: ID!\n name: String\n lang: String\n currency: String\n theme: String\n primaryColor: String\n logo: Image\n seo: Seo\n }\n\n type StrapiPage implements Node {\n id: ID!\n title: String\n slug: String\n seo: Seo\n author: Author\n content: [ContentComponent]\n createdAt: Date @dateformat\n updatedAt: Date @dateformat\n }\n\n # === STRAPI NAVIGATION DEFINITIONS ===\n type StrapiNavigation implements Node {\n id: ID!\n items: [NavigationGroup!]\n }\n\n type NavigationGroup {\n name: String!\n slug: String!\n items: [NavigationItem!]\n }\n\n type NavigationItem {\n type: String!\n title: String!\n slug: String!\n path: String!\n menuAttached: Boolean!\n items: [NavigationItem!]\n }\n\n # === COMPONENT DEFINITIONS ===\n union ContentComponent =\n STRAPI__COMPONENT_CONTENT_FAQ\n | STRAPI__COMPONENT_CONTENT_FEATURES\n | STRAPI__COMPONENT_CONTENT_GAME_DEMO\n | STRAPI__COMPONENT_CONTENT_GAME_INFO\n | STRAPI__COMPONENT_CONTENT_HOW_TO\n | STRAPI__COMPONENT_CONTENT_LIST\n | STRAPI__COMPONENT_CONTENT_MEDIA\n | STRAPI__COMPONENT_CONTENT_PROS_CONS\n | STRAPI__COMPONENT_CONTENT_RICH_TEXT\n | STRAPI__COMPONENT_CONTENT_TABLE\n | STRAPI__COMPONENT_CONTENT_TIP\n\n type STRAPI__COMPONENT_CONTENT_FAQ {\n items: [FaqItem!]\n }\n\n type FaqItem {\n question: String\n answer: String\n }\n\n type STRAPI__COMPONENT_CONTENT_FEATURES {\n items: [ListItem!]\n }\n\n type STRAPI__COMPONENT_CONTENT_PROS_CONS {\n pros: [ListItem!]\n cons: [ListItem!]\n }\n\n type ListItem {\n title: String\n description: String\n }\n\n type STRAPI__COMPONENT_CONTENT_GAME_DEMO {\n name: String\n src: String\n href: String\n previewImage: Image\n }\n\n type STRAPI__COMPONENT_CONTENT_GAME_INFO {\n general: GAME_GENERAL\n features: GAME_FEATURES\n }\n\n type GAME_GENERAL {\n NAME: String\n DEVELOPER: String\n RELEASE_DATE: Date @dateformat\n THEME: String\n TYPE: String\n VOLATILITY: String\n RTP: String\n PAY_LINES: String\n ROWS_WITH_PINS: String\n REELS_NUMBER: String\n MIN_BET: String\n MAX_BET: String\n MAX_WIN: String\n COMPATIBILITY: String\n }\n\n type GAME_FEATURES {\n HAS_DEMO: Boolean\n HAS_AUTOPLAY: Boolean\n HAS_FREE_SPINS: Boolean\n HAS_FAST_SPIN: Boolean\n HAS_BONUS_PURCHASE: Boolean\n HAS_COLLECTION_SYMBOLS: Boolean\n HAS_PROGRESSIVE_JACKPOT: Boolean\n BONUS_FEATURES: String\n FUNCTIONS: String\n LANGUAGES: String\n }\n\n type STRAPI__COMPONENT_CONTENT_HOW_TO {\n steps: [HowToStep!]\n }\n\n type HowToStep {\n title: String!\n description: String\n thumbnail: Image\n }\n\n type STRAPI__COMPONENT_CONTENT_TIP {\n tip: String\n author: Author\n }\n\n type STRAPI__COMPONENT_CONTENT_RICH_TEXT {\n content: RichTextContent\n }\n\n type RichTextContent {\n data: RichTextData\n }\n\n type RichTextData {\n content: String\n }\n\n type STRAPI__COMPONENT_CONTENT_LIST {\n bullet: String\n content: JsonValue\n }\n\n type STRAPI__COMPONENT_CONTENT_MEDIA {\n file: Image\n }\n\n type STRAPI__COMPONENT_CONTENT_TABLE {\n columnNumber: Int\n striped: Boolean\n bordered: Boolean\n scrollable: Boolean\n content: JsonValue\n caption: String\n }\n\n type JsonValue {\n strapi_json_value: JSON\n }\n ";