@enonic/nextjs-adapter 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.
Files changed (81) hide show
  1. package/ComponentRegistry.d.ts +64 -0
  2. package/ComponentRegistry.js +121 -0
  3. package/UrlProcessor.d.ts +25 -0
  4. package/{src/UrlProcessor.ts → UrlProcessor.js} +35 -53
  5. package/baseMappings.d.ts +1 -0
  6. package/{src/baseMappings.ts → baseMappings.js} +3 -13
  7. package/guillotine/fetchContent.d.ts +49 -0
  8. package/{src/guillotine/fetchContent.ts → guillotine/fetchContent.js} +243 -493
  9. package/guillotine/getMetaData.d.ts +94 -0
  10. package/guillotine/getMetaData.js +128 -0
  11. package/{src/index.ts → index.d.ts} +1 -1
  12. package/index.js +5 -0
  13. package/package.json +2 -2
  14. package/query/Shortcut.d.ts +1 -0
  15. package/server/ClearableFileCache.d.ts +31 -0
  16. package/server/ClearableFileCache.js +472 -0
  17. package/server/cache.d.ts +2 -0
  18. package/server/cache.js +129 -0
  19. package/server/index.d.ts +5 -0
  20. package/server/index.js +132 -0
  21. package/utils.d.ts +114 -0
  22. package/{src/utils.ts → utils.js} +69 -148
  23. package/views/BaseComponent.d.ts +25 -0
  24. package/{src/views/BaseComponent.tsx → views/BaseComponent.jsx} +39 -73
  25. package/views/BaseContent.d.ts +4 -0
  26. package/{src/views/BaseContent.tsx → views/BaseContent.jsx} +17 -24
  27. package/views/BaseLayout.d.ts +17 -0
  28. package/views/BaseLayout.jsx +24 -0
  29. package/views/BaseMacro.d.ts +16 -0
  30. package/{src/views/BaseMacro.tsx → views/BaseMacro.jsx} +29 -45
  31. package/views/BasePage.d.ts +19 -0
  32. package/views/BasePage.jsx +34 -0
  33. package/views/BasePart.d.ts +19 -0
  34. package/views/BasePart.jsx +24 -0
  35. package/views/Empty.d.ts +3 -0
  36. package/{src/views/Empty.tsx → views/Empty.jsx} +0 -2
  37. package/views/Fragment.d.ts +10 -0
  38. package/views/Fragment.jsx +30 -0
  39. package/views/MainView.d.ts +4 -0
  40. package/views/MainView.jsx +14 -0
  41. package/views/Region.d.ts +20 -0
  42. package/views/Region.jsx +52 -0
  43. package/views/RichTextView.d.ts +16 -0
  44. package/{src/views/RichTextView.tsx → views/RichTextView.jsx} +10 -31
  45. package/views/SingleComponent.d.ts +5 -0
  46. package/{src/views/SingleComponent.tsx → views/SingleComponent.jsx} +2 -8
  47. package/views/StaticContent.d.ts +15 -0
  48. package/views/StaticContent.jsx +36 -0
  49. package/views/Text.d.ts +9 -0
  50. package/views/Text.jsx +4 -0
  51. package/views/macros/DefaultMacro.d.ts +4 -0
  52. package/views/macros/DefaultMacro.jsx +3 -0
  53. package/views/macros/DisableMacro.d.ts +3 -0
  54. package/views/macros/DisableMacro.jsx +2 -0
  55. package/.eslint-childrc.js +0 -17
  56. package/.eslintrc.js +0 -15
  57. package/.github/dependabot.yml +0 -20
  58. package/.github/pull-merger.yml +0 -1
  59. package/.github/workflows/release.yml +0 -39
  60. package/LICENSE +0 -201
  61. package/RELEASE.md +0 -75
  62. package/server/.eslintrc.js +0 -11
  63. package/server/ClearableFileCache.ts +0 -410
  64. package/server/cache.ts +0 -50
  65. package/server/index.ts +0 -74
  66. package/server/tsconfig.json +0 -23
  67. package/src/.eslintrc.js +0 -11
  68. package/src/ComponentRegistry.ts +0 -189
  69. package/src/guillotine/getMetaData.ts +0 -246
  70. package/src/tsconfig.json +0 -20
  71. package/src/views/BaseLayout.tsx +0 -45
  72. package/src/views/BasePage.tsx +0 -56
  73. package/src/views/BasePart.tsx +0 -50
  74. package/src/views/Fragment.tsx +0 -45
  75. package/src/views/MainView.tsx +0 -21
  76. package/src/views/Region.tsx +0 -89
  77. package/src/views/StaticContent.tsx +0 -40
  78. package/src/views/Text.tsx +0 -15
  79. package/src/views/macros/DefaultMacro.tsx +0 -9
  80. package/src/views/macros/DisableMacro.tsx +0 -8
  81. /package/{src/query/Shortcut.ts → query/Shortcut.js} +0 -0
@@ -0,0 +1,94 @@
1
+ import { RENDER_MODE, XP_COMPONENT_TYPE, XP_REQUEST_TYPE } from '../utils';
2
+ export declare const richTextQuery: (fieldName: string) => string;
3
+ export declare const pageFragmentQuery: () => string;
4
+ export declare function getMetaQuery(pageFragment?: string): string;
5
+ export interface PageComponent {
6
+ [key: string]: any;
7
+ type: XP_COMPONENT_TYPE;
8
+ path: string;
9
+ page?: PageData;
10
+ part?: PartData;
11
+ layout?: LayoutData;
12
+ fragment?: FragmentData;
13
+ text?: TextData;
14
+ image?: any;
15
+ regions?: RegionTree;
16
+ data?: any;
17
+ error?: any;
18
+ }
19
+ export interface TextData {
20
+ value: RichTextData;
21
+ }
22
+ export interface RichTextData {
23
+ processedHtml: string;
24
+ links: LinkData[];
25
+ macros: MacroData[];
26
+ images: ImageData[];
27
+ }
28
+ export interface LinkData {
29
+ ref: string;
30
+ media: {
31
+ content: {
32
+ id: string;
33
+ };
34
+ } | null;
35
+ }
36
+ export interface MacroData {
37
+ ref: string;
38
+ name: string;
39
+ descriptor: string;
40
+ config: {
41
+ [name: string]: MacroConfig;
42
+ };
43
+ }
44
+ export interface ImageData {
45
+ ref: string;
46
+ image: {
47
+ id: string;
48
+ } | null;
49
+ }
50
+ export interface MacroConfig {
51
+ [key: string]: any;
52
+ }
53
+ export interface RegionTree {
54
+ [key: string]: PageRegion;
55
+ }
56
+ export interface PageRegion {
57
+ name: string;
58
+ components: PageComponent[];
59
+ }
60
+ export interface PartData {
61
+ descriptor: string;
62
+ config: any;
63
+ [customKeysFromQuery: string]: any;
64
+ }
65
+ export interface LayoutData {
66
+ descriptor: string;
67
+ config?: any;
68
+ [customKeysFromQuery: string]: any;
69
+ }
70
+ export interface PageData {
71
+ descriptor: string;
72
+ config?: any;
73
+ template?: string | null;
74
+ regions?: RegionTree;
75
+ }
76
+ export interface FragmentData {
77
+ id: string;
78
+ fragment: {
79
+ components: PageComponent[];
80
+ };
81
+ }
82
+ export interface MetaData {
83
+ type: string;
84
+ path: string;
85
+ requestType: XP_REQUEST_TYPE;
86
+ renderMode: RENDER_MODE;
87
+ requestedComponent?: PageComponent;
88
+ canRender: boolean;
89
+ catchAll: boolean;
90
+ apiUrl: string;
91
+ baseUrl: string;
92
+ locale: string;
93
+ defaultLocale: string;
94
+ }
@@ -0,0 +1,128 @@
1
+ import { sanitizeGraphqlName } from '../utils';
2
+ import { ComponentRegistry } from '../ComponentRegistry';
3
+ const macroConfigQuery = () => {
4
+ return configQuery(ComponentRegistry.getMacros(), false, false);
5
+ };
6
+ const partConfigQuery = () => {
7
+ return configQuery(ComponentRegistry.getParts());
8
+ };
9
+ const layoutConfigQuery = () => {
10
+ return configQuery(ComponentRegistry.getLayouts());
11
+ };
12
+ const pageConfigQuery = () => {
13
+ return configQuery(ComponentRegistry.getPages());
14
+ };
15
+ const configQuery = (list, includeAppName = true, canUseConfigAsJson = true) => {
16
+ const hasQueryList = (list === null || list === void 0 ? void 0 : list.filter(([key, def]) => def.configQuery)) || [];
17
+ if (hasQueryList.length === 0) {
18
+ return canUseConfigAsJson ? 'configAsJson' : '';
19
+ }
20
+ const configsByApp = {};
21
+ hasQueryList
22
+ .forEach((entry) => {
23
+ const nameParts = entry[0].split(':');
24
+ if (nameParts.length === 2) {
25
+ const sanitizedAppName = sanitizeGraphqlName(nameParts[0]);
26
+ let existingConfigs = configsByApp[sanitizedAppName];
27
+ if (!existingConfigs) {
28
+ existingConfigs = [];
29
+ configsByApp[sanitizedAppName] = existingConfigs;
30
+ }
31
+ existingConfigs.push(`${sanitizeGraphqlName(nameParts[1])}${entry[1].configQuery}`);
32
+ }
33
+ });
34
+ // Still query for configAsJson if at least one item has no configQuery defined
35
+ const configAsJsonQuery = canUseConfigAsJson && hasQueryList.length < list.length ? 'configAsJson' : '';
36
+ if (!includeAppName) {
37
+ return `${configAsJsonQuery}
38
+ config {
39
+ ${Object.values(configsByApp).reduce((arr, curr) => arr.concat(curr), []).join('\n')}
40
+ }`;
41
+ }
42
+ else {
43
+ return `${configAsJsonQuery}
44
+ config {
45
+ ${Object.entries(configsByApp).map(entry => entry[0] + '{\n' + entry[1].join('\n') + '\n}')}
46
+ }`;
47
+ }
48
+ };
49
+ /*
50
+ IMPORTANT: make sure to transform your queries into functions too when using this function inside them !!!
51
+ */
52
+ export const richTextQuery = (fieldName) => {
53
+ return `${fieldName}(processHtml:{type:absolute, imageWidths:[400, 800, 1200], imageSizes:"(max-width: 400px) 400px, (max-width: 800px) 800px, 1200px"}) {
54
+ processedHtml
55
+ macros {
56
+ ref
57
+ name
58
+ descriptor
59
+ ${macroConfigQuery()}
60
+ }
61
+ links {
62
+ ref
63
+ media {
64
+ content {
65
+ _id
66
+ }
67
+ }
68
+ }
69
+ images {
70
+ ref
71
+ image {
72
+ _id
73
+ }
74
+ }
75
+ }`;
76
+ };
77
+ const componentsQuery = () => `
78
+ type
79
+ path
80
+ page {
81
+ descriptor
82
+ ${pageConfigQuery()}
83
+ template {
84
+ _path
85
+ }
86
+ }
87
+ layout {
88
+ descriptor
89
+ ${layoutConfigQuery()}
90
+ }
91
+ text {
92
+ ${richTextQuery('value')}
93
+ }
94
+ part {
95
+ descriptor
96
+ ${partConfigQuery()}
97
+ }
98
+ image {
99
+ caption
100
+ image {
101
+ imageUrl (type:absolute, scale: "width-768")
102
+ }
103
+ }
104
+ `;
105
+ // THIS QUERY DOES NOT SUPPORT NESTED FRAGMENTS
106
+ export const pageFragmentQuery = () => `
107
+ components(resolveFragment: false, resolveTemplate: true) {
108
+ fragment {
109
+ id
110
+ fragment {
111
+ components {
112
+ ${componentsQuery()}
113
+ }
114
+ }
115
+ }
116
+ ${componentsQuery()}
117
+ }`;
118
+ export function getMetaQuery(pageFragment) {
119
+ return `query($path:ID!){
120
+ guillotine {
121
+ get(key:$path) {
122
+ _path
123
+ type
124
+ ${pageFragment || ''}
125
+ }
126
+ }
127
+ }`;
128
+ }
@@ -2,4 +2,4 @@ export * from './utils';
2
2
  export * from './guillotine/fetchContent';
3
3
  export * from './guillotine/getMetaData';
4
4
  export * from './ComponentRegistry';
5
- export * from './UrlProcessor';
5
+ export * from './UrlProcessor';
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './utils';
2
+ export * from './guillotine/fetchContent';
3
+ export * from './guillotine/getMetaData';
4
+ export * from './ComponentRegistry';
5
+ export * from './UrlProcessor';
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@enonic/nextjs-adapter",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "scripts": {
10
- "copy": "npx --yes cpy-cli package.json README.md dist",
10
+ "copy": "npx --yes cpy-cli package.json README.md setversion.js dist",
11
11
  "build": "tsc --build src/tsconfig.json && tsc --build server/tsconfig.json",
12
12
  "lint": "eslint --quiet server && eslint --quiet src",
13
13
  "lint:fix": "eslint --fix server && eslint --fix src",
@@ -0,0 +1 @@
1
+ export declare const getShortcutQuery = "\n query($path:ID!){\n guillotine {\n get(key:$path) {\n ... on base_Shortcut {\n data {\n target {\n pageUrl(type: absolute)\n }\n }\n }\n }\n }\n }";
@@ -0,0 +1,31 @@
1
+ import { CacheHandler, CacheHandlerContext, CacheHandlerValue } from 'next/dist/server/lib/incremental-cache';
2
+ import { CacheFs } from 'next/dist/shared/lib/utils';
3
+ type FileSystemCacheContext = Omit<CacheHandlerContext, 'fs' | 'serverDistDir'> & {
4
+ fs: CacheFs;
5
+ serverDistDir: string;
6
+ };
7
+ export default class FileSystemCache implements CacheHandler {
8
+ private fs;
9
+ private flushToDisk?;
10
+ private serverDistDir;
11
+ private appDir;
12
+ private tagsManifestPath?;
13
+ private revalidatedTags;
14
+ constructor(ctx: FileSystemCacheContext);
15
+ clear(): void;
16
+ delete(path: string): boolean | undefined;
17
+ private loadTagsManifest;
18
+ setTags(key: string, tags: string[]): Promise<void>;
19
+ revalidateTag(tag: string): Promise<void>;
20
+ get(key: string, fetchCache?: boolean): Promise<CacheHandlerValue | null>;
21
+ set(key: string, data: CacheHandlerValue['value']): Promise<void>;
22
+ getFsPath({ pathname, appDir, fetchCache, }: {
23
+ pathname: string;
24
+ appDir?: boolean;
25
+ fetchCache?: boolean;
26
+ }): Promise<{
27
+ filePath: string;
28
+ isAppPath: boolean;
29
+ }>;
30
+ }
31
+ export {};