@geins/cms 0.1.1-canary

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.
@@ -0,0 +1,30 @@
1
+ import { ContentAreaType, ContentContainerType } from '@geins/core';
2
+ import type { GeinsMenuItemTypeType } from '@geins/types';
3
+ export declare function parseMenuItem(item: any): GeinsMenuItemTypeType;
4
+ export declare function parseContentArea(result: any): ContentAreaType;
5
+ export declare function parseContainer(container: any): ContentContainerType;
6
+ export declare function parseMetaData(meta: any): {
7
+ title: any;
8
+ description: any;
9
+ };
10
+ export declare function parseContent(content: any): {
11
+ config: {
12
+ name: any;
13
+ displayName: any;
14
+ active: boolean;
15
+ type: any;
16
+ size: any;
17
+ sortOrder: any;
18
+ };
19
+ data: {};
20
+ };
21
+ export declare function parseContentData(type: string, data: any): any;
22
+ export declare function parseContentDataByType(type: string, data: any): any;
23
+ export declare function parseJsonSafe(data: any): any;
24
+ export declare function parseContentDataJson(data: any): any;
25
+ export declare function parseContentDataText(data: any): any;
26
+ export declare function parseContentDataHtml(data: any): any;
27
+ export declare function parseContentDataProductList(data: any): any;
28
+ export declare function parseContentDataImage(data: any): any;
29
+ export declare function parseContentDataBanner(data: any): any;
30
+ export declare function parseContentDataButtons(data: any): any;
@@ -0,0 +1,8 @@
1
+ import { ContentAreaVariables, ContentAreaType } from '@geins/core';
2
+ import { BaseApiService } from '@geins/core';
3
+ export declare class ContentAreaService extends BaseApiService {
4
+ private generateVars;
5
+ getRaw(variables: ContentAreaVariables): Promise<any>;
6
+ get(variables: ContentAreaVariables): Promise<unknown>;
7
+ protected parseResult(result: any): ContentAreaType;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { ContentPageVariables, ContentAreaType } from '@geins/core';
2
+ import { BaseApiService } from '@geins/core';
3
+ export declare class ContentPageService extends BaseApiService {
4
+ private generateVars;
5
+ getRaw(variables: ContentPageVariables): Promise<any>;
6
+ get(variables: ContentPageVariables): Promise<unknown>;
7
+ protected parseResult(result: any): ContentAreaType;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from './contentAreaService';
2
+ export * from './contentPageService';
3
+ export * from './menuService';
@@ -0,0 +1,9 @@
1
+ import type { MenuVariables } from '@geins/types';
2
+ import { BaseApiService } from '@geins/core';
3
+ export declare class MenuService extends BaseApiService {
4
+ private generateVars;
5
+ getRaw(variables: MenuVariables): Promise<any>;
6
+ get(variables: MenuVariables): Promise<unknown>;
7
+ protected parseResult(result: any): any;
8
+ protected parseMenuItem(item: any): any;
9
+ }
@@ -0,0 +1 @@
1
+ export * from '../parsers/contentParsers';
@@ -0,0 +1,3 @@
1
+ import { geinsSharedConfig } from '@geins/eslint-config/eslint-config.js';
2
+
3
+ export default [...geinsSharedConfig];
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ // /packages/sdk/core/jest.config.js
2
+ import baseConfig from '../../../jest.config.js';
3
+
4
+ export default {
5
+ ...baseConfig,
6
+ displayName: '@geins/core',
7
+ roots: ['<rootDir>'],
8
+ };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@geins/cms",
3
+ "version": "0.1.1-canary",
4
+ "main": "dist/index.cjs",
5
+ "module": "dist/index.esm.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "license": "MIT",
9
+ "scripts": {
10
+ "build": "rollup -c",
11
+ "prepublishOnly": "yarn build",
12
+ "lint": "eslint --fix .",
13
+ "link": "yarn link"
14
+ },
15
+ "dependencies": {
16
+ "@apollo/client": "^3.11.8",
17
+ "graphql": "^16.9.0",
18
+ "@geins/core": "0.1.1-canary"
19
+ },
20
+ "devDependencies": {
21
+ "@rollup/plugin-commonjs": "^28.0.0",
22
+ "@rollup/plugin-node-resolve": "^15.3.0",
23
+ "@rollup/plugin-typescript": "^12.1.0",
24
+ "@geins/eslint-config": "*",
25
+ "typescript": "^5.6.2",
26
+ "eslint": "^9.11.1"
27
+ }
28
+ }
@@ -0,0 +1,26 @@
1
+ import resolve from '@rollup/plugin-node-resolve';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import typescript from '@rollup/plugin-typescript';
4
+ import graphql from '@rollup/plugin-graphql';
5
+
6
+ export default {
7
+ input: 'src/index.ts',
8
+ output: [
9
+ {
10
+ file: 'dist/index.cjs',
11
+ format: 'cjs',
12
+ },
13
+ {
14
+ file: 'dist/index.esm.js',
15
+ format: 'esm',
16
+ },
17
+ ],
18
+ plugins: [
19
+ resolve({
20
+ preferBuiltins: true,
21
+ }),
22
+ commonjs(),
23
+ typescript(),
24
+ graphql(),
25
+ ],
26
+ };
@@ -0,0 +1,36 @@
1
+ import { GeinsCore, BasePackage } from '@geins/core';
2
+ import { MenuService, ContentPageService, ContentAreaService } from './services';
3
+
4
+ class GeinsCMS extends BasePackage {
5
+ private _menu!: MenuService;
6
+ private _page!: ContentPageService;
7
+ private _area!: ContentAreaService;
8
+
9
+ constructor(core: GeinsCore) {
10
+ super(core);
11
+ const { client, geinsSettings } = core;
12
+ this._geinsSettings = geinsSettings;
13
+ this._apiClient = () => client ?? undefined;
14
+ this.initServices();
15
+ }
16
+
17
+ private async initServices(): Promise<void> {
18
+ this._menu = new MenuService(() => this._apiClient(), this._geinsSettings);
19
+ this._page = new ContentPageService(() => this._apiClient(), this._geinsSettings);
20
+ this._area = new ContentAreaService(() => this._apiClient(), this._geinsSettings);
21
+ }
22
+
23
+ get menu(): MenuService {
24
+ return this._menu;
25
+ }
26
+
27
+ get area(): ContentAreaService {
28
+ return this._area;
29
+ }
30
+
31
+ get page(): ContentPageService {
32
+ return this._page;
33
+ }
34
+ }
35
+
36
+ export { GeinsCMS };
@@ -0,0 +1,11 @@
1
+ #import "./menu-item.gql"
2
+
3
+ fragment MenuItemBase on MenuItemType {
4
+ children {
5
+ children {
6
+ ...MenuItem
7
+ }
8
+ ...MenuItem
9
+ }
10
+ ...MenuItem
11
+ }
@@ -0,0 +1,11 @@
1
+ fragment MenuItem on MenuItemType {
2
+ id
3
+ label
4
+ open
5
+ hidden
6
+ targetBlank
7
+ type
8
+ order
9
+ title
10
+ canonicalUrl
11
+ }
@@ -0,0 +1,8 @@
1
+ declare module '*.graphql' {
2
+ const value: string;
3
+ export default value;
4
+ }
5
+ declare module '*.gql' {
6
+ const value: string;
7
+ export default value;
8
+ }
@@ -0,0 +1 @@
1
+ export * from './queries';
@@ -0,0 +1,24 @@
1
+ #import "./fragments/menu-item-base.gql"
2
+ fragment Menu on MenuType {
3
+ id
4
+ title
5
+ menuItems {
6
+ ...MenuItemBase
7
+ }
8
+ }
9
+
10
+ query MenuAtLocation(
11
+ $menuLocationId: String
12
+ $channelId: String
13
+ $languageId: String
14
+ $marketId: String
15
+ ) {
16
+ getMenuAtLocation(
17
+ menuLocationId: $menuLocationId
18
+ channelId: $channelId
19
+ languageId: $languageId
20
+ marketId: $marketId
21
+ ) {
22
+ ...Menu
23
+ }
24
+ }
@@ -0,0 +1,4 @@
1
+ fragment Meta on MetadataType {
2
+ description
3
+ title
4
+ }
@@ -0,0 +1,9 @@
1
+ import menu from './menu.gql';
2
+ import contentArea from './widget-area.graphql';
3
+
4
+ const queries = {
5
+ menu,
6
+ contentArea,
7
+ };
8
+
9
+ export { queries };
@@ -0,0 +1,58 @@
1
+ #import "./meta.graphql"
2
+
3
+ query widgetArea(
4
+ $family: String = null
5
+ $areaName: String = null
6
+ $alias: String = null
7
+ $displaySetting: String = null
8
+ $filters: [PageWidgetCollectionFilterInputType] = null
9
+ $preview: Boolean = null
10
+ $customerType: CustomerType
11
+ $channelId: String
12
+ $languageId: String
13
+ $url: String
14
+ $marketId: String
15
+ ) {
16
+ widgetArea(
17
+ family: $family
18
+ areaName: $areaName
19
+ alias: $alias
20
+ displaySetting: $displaySetting
21
+ filters: $filters
22
+ preview: $preview
23
+ customerType: $customerType
24
+ channelId: $channelId
25
+ languageId: $languageId
26
+ url: $url
27
+ marketId: $marketId
28
+ ) {
29
+ meta {
30
+ ...Meta
31
+ }
32
+ tags
33
+ containers {
34
+ id
35
+ name
36
+ sortOrder
37
+ layout
38
+ responsiveMode
39
+ design
40
+
41
+ widgets {
42
+ id
43
+ name
44
+ sortOrder
45
+ type
46
+ size
47
+ configuration
48
+ images {
49
+ fileName
50
+ largestSize {
51
+ imageWidth
52
+ imageHeight
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './geinsCMS';
@@ -0,0 +1,210 @@
1
+ import { ContentAreaType, ContentContainerType } from '@geins/core';
2
+ import type { GeinsMenuItemTypeType } from '@geins/types';
3
+
4
+ export function parseMenuItem(item: any): GeinsMenuItemTypeType {
5
+ return {
6
+ id: item.id,
7
+ label: item.label,
8
+ title: item.title,
9
+ canonicalUrl: item.canonicalUrl,
10
+ type: item.type,
11
+ order: item.order,
12
+ open: item.open,
13
+ hidden: item.hidden,
14
+ targetBlank: item.targetBlank,
15
+ children: item.children
16
+ ? item.children.map((child: any) => parseMenuItem(child))
17
+ : [],
18
+ };
19
+ }
20
+
21
+ export function parseContentArea(result: any): ContentAreaType {
22
+ if (!result || !result.data) {
23
+ throw new Error('Invalid result structure for content area');
24
+ }
25
+ const area = result.data.widgetArea;
26
+
27
+ if (!area) {
28
+ console.warn('No area found');
29
+ return {
30
+ meta: {},
31
+ tags: [],
32
+ containers: [],
33
+ };
34
+ }
35
+
36
+ const parsedResult = {
37
+ meta: area.meta ? parseMetaData(area.meta) : {},
38
+ tags: area.tags,
39
+ containers: area.containers.map((item: any) => parseContainer(item)),
40
+ };
41
+
42
+ return parsedResult as ContentAreaType;
43
+ }
44
+
45
+ export function parseContainer(container: any): ContentContainerType {
46
+ const parsedContainer = {
47
+ id: container.id,
48
+ name: container.name,
49
+ sortOrder: container.sortOrder,
50
+ layout: container.layout,
51
+ responsiveMode: container.responsiveMode,
52
+ design: container.design,
53
+ content: container.widgets.map((content: any) => parseContent(content)),
54
+ };
55
+ return parsedContainer;
56
+ }
57
+
58
+ export function parseMetaData(meta: any) {
59
+ return {
60
+ title: meta.title,
61
+ description: meta.description,
62
+ };
63
+ }
64
+
65
+ export function parseContent(content: any) {
66
+ const parsedContent = {
67
+ config: {
68
+ name: content.name,
69
+ displayName: content.name,
70
+ active: false,
71
+ type: content.type,
72
+ size: content.size,
73
+ sortOrder: content.sortOrder,
74
+ },
75
+ data: {},
76
+ };
77
+
78
+ if (content.type) {
79
+ const data = parseContentData(content.type, content.configuration);
80
+
81
+ if (data) {
82
+ parsedContent.data = data;
83
+ }
84
+
85
+ if (data.active) {
86
+ parsedContent.config.active = data.active;
87
+ delete data.active;
88
+ }
89
+
90
+ if (data.displayName) {
91
+ parsedContent.config.displayName = data.displayName;
92
+ delete data.displayName;
93
+ }
94
+ }
95
+
96
+ return parsedContent;
97
+ }
98
+
99
+ export function parseContentData(type: string, data: any) {
100
+ if (!data) {
101
+ console.warn('No data found for type', type);
102
+ return {};
103
+ }
104
+
105
+ const parsedData = parseContentDataByType(type, data);
106
+ const parsedContentData = {
107
+ name: data.name,
108
+ active: data.active || false,
109
+ ...parsedData,
110
+ };
111
+
112
+ return parsedContentData;
113
+ }
114
+
115
+ export function parseContentDataByType(type: string, data: any) {
116
+ switch (type) {
117
+ case 'TextPageWidget':
118
+ return parseContentDataText(data);
119
+ case 'HTMLPageWidget':
120
+ return parseContentDataHtml(data);
121
+ case 'Product listPageWidget':
122
+ return parseContentDataProductList(data);
123
+ case 'ButtonsPageWidget':
124
+ return parseContentDataButtons(data);
125
+ case 'ImagePageWidget':
126
+ return parseContentDataImage(data);
127
+ case 'BannerPageWidget':
128
+ return parseContentDataBanner(data);
129
+ case 'JSONPageWidget':
130
+ return parseContentDataJson(data);
131
+ default:
132
+ return parseJsonSafe(data);
133
+ }
134
+ }
135
+
136
+ export function parseJsonSafe(data: any) {
137
+ try {
138
+ return JSON.parse(data);
139
+ } catch (e) {
140
+ return {};
141
+ }
142
+ }
143
+
144
+ export function parseContentDataJson(data: any) {
145
+ let parsedData: any = {};
146
+ let jsonData: any = {};
147
+
148
+ try {
149
+ parsedData = JSON.parse(data);
150
+ } catch (e) {
151
+ console.error('Error parsing data', e);
152
+ }
153
+ try {
154
+ jsonData = JSON.parse(parsedData.json);
155
+ } catch (e) {
156
+ console.error('Error parsing json attribute from content data', e);
157
+ }
158
+ if (parsedData.json) {
159
+ delete parsedData.json;
160
+ }
161
+ return { ...parsedData, ...jsonData };
162
+ }
163
+
164
+ export function parseContentDataText(data: any) {
165
+ try {
166
+ return JSON.parse(data);
167
+ } catch (e) {
168
+ return {};
169
+ }
170
+ }
171
+
172
+ export function parseContentDataHtml(data: any) {
173
+ try {
174
+ return JSON.parse(data);
175
+ } catch (e) {
176
+ return {};
177
+ }
178
+ }
179
+
180
+ export function parseContentDataProductList(data: any) {
181
+ try {
182
+ return JSON.parse(data);
183
+ } catch (e) {
184
+ return {};
185
+ }
186
+ }
187
+
188
+ export function parseContentDataImage(data: any) {
189
+ try {
190
+ return JSON.parse(data);
191
+ } catch (e) {
192
+ return {};
193
+ }
194
+ }
195
+
196
+ export function parseContentDataBanner(data: any) {
197
+ try {
198
+ return JSON.parse(data);
199
+ } catch (e) {
200
+ return {};
201
+ }
202
+ }
203
+
204
+ export function parseContentDataButtons(data: any) {
205
+ try {
206
+ return JSON.parse(data);
207
+ } catch (e) {
208
+ return {};
209
+ }
210
+ }
@@ -0,0 +1,31 @@
1
+ import { ContentAreaVariables, ContentAreaType } from '@geins/core';
2
+ import { BaseApiService, GraphQLQueryOptions } from '@geins/core';
3
+ import { queries } from '../graphql';
4
+ import * as contentParsers from '../parsers/contentParsers';
5
+ export class ContentAreaService extends BaseApiService {
6
+ private async generateVars(variables: ContentAreaVariables) {
7
+ if (!variables.areaName || !variables.family) {
8
+ throw new Error('areaName and family is required');
9
+ }
10
+ return this.createVariables(variables);
11
+ }
12
+ async getRaw(variables: ContentAreaVariables) {
13
+ const options: any = {
14
+ query: queries.contentArea,
15
+ variables: await this.generateVars(variables),
16
+ };
17
+ return await this.runQuery(options);
18
+ }
19
+
20
+ async get(variables: ContentAreaVariables) {
21
+ const options: any = {
22
+ query: queries.contentArea,
23
+ variables: await this.generateVars(variables),
24
+ };
25
+ return await this.runQueryParsed(options);
26
+ }
27
+
28
+ protected parseResult(result: any): ContentAreaType {
29
+ return contentParsers.parseContentArea(result);
30
+ }
31
+ }
@@ -0,0 +1,33 @@
1
+ import { ContentPageVariables, ContentAreaType } from '@geins/core';
2
+ import { BaseApiService } from '@geins/core';
3
+ import { queries } from '../graphql';
4
+ import * as contentParsers from '../parsers/contentParsers';
5
+
6
+ export class ContentPageService extends BaseApiService {
7
+ private async generateVars(variables: ContentPageVariables) {
8
+ if (!variables.alias) {
9
+ throw new Error('Alias is required');
10
+ }
11
+ return this.createVariables(variables);
12
+ }
13
+
14
+ async getRaw(variables: ContentPageVariables) {
15
+ const options = {
16
+ query: queries.contentArea,
17
+ variables: await this.generateVars(variables),
18
+ };
19
+ return await this.runQuery(options);
20
+ }
21
+
22
+ async get(variables: ContentPageVariables) {
23
+ const options = {
24
+ query: queries.contentArea,
25
+ variables: await this.generateVars(variables),
26
+ };
27
+ return await this.runQueryParsed(options);
28
+ }
29
+
30
+ protected parseResult(result: any): ContentAreaType {
31
+ return contentParsers.parseContentArea(result);
32
+ }
33
+ }
@@ -0,0 +1,3 @@
1
+ export * from './contentAreaService';
2
+ export * from './contentPageService';
3
+ export * from './menuService';
@@ -0,0 +1,59 @@
1
+ import type { MenuVariables } from '@geins/types';
2
+ import { BaseApiService, logWrite } from '@geins/core';
3
+ import { queries } from '../graphql';
4
+ export class MenuService extends BaseApiService {
5
+ private async generateVars(variables: MenuVariables) {
6
+ if (!variables.menuLocationId) {
7
+ throw new Error('LocationId is required');
8
+ }
9
+ const vars = this.createVariables(variables);
10
+ return vars;
11
+ }
12
+
13
+ async getRaw(variables: MenuVariables) {
14
+ const options = {
15
+ query: queries.menu,
16
+ variables: await this.generateVars(variables),
17
+ };
18
+ return await this.runQuery(options);
19
+ }
20
+
21
+ async get(variables: MenuVariables) {
22
+ const options = {
23
+ query: queries.menu,
24
+ variables: await this.generateVars(variables),
25
+ };
26
+ return await this.runQueryParsed(options);
27
+ }
28
+
29
+ protected parseResult(result: any): any {
30
+ if (!result || !result.data || !result.data.getMenuAtLocation) {
31
+ throw new Error('Invalid result structure');
32
+ }
33
+ const menu = result.data.getMenuAtLocation;
34
+ const parsedResult = {
35
+ id: menu.id,
36
+ title: menu.title,
37
+ menuItems: menu.menuItems.map((item: any) => this.parseMenuItem(item)),
38
+ };
39
+
40
+ return parsedResult;
41
+ }
42
+
43
+ protected parseMenuItem(item: any): any {
44
+ return {
45
+ id: item.id,
46
+ label: item.label,
47
+ title: item.title,
48
+ canonicalUrl: item.canonicalUrl,
49
+ type: item.type,
50
+ order: item.order,
51
+ open: item.open,
52
+ hidden: item.hidden,
53
+ targetBlank: item.targetBlank,
54
+ children: item.children
55
+ ? item.children.map((child: any) => this.parseMenuItem(child))
56
+ : [],
57
+ };
58
+ }
59
+ }
@@ -0,0 +1 @@
1
+ export * from '../parsers/contentParsers';
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "module": "ESNext",
5
+ "moduleResolution": "node",
6
+ "declaration": true,
7
+ "outDir": "./dist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true
13
+ },
14
+ "include": [
15
+ "src/**/*.ts",
16
+ "src/**/*.gql"
17
+ ]
18
+ }