@dotcms/client 0.0.1-alpha.3 → 0.0.1-alpha.30

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 (83) hide show
  1. package/README.md +0 -1
  2. package/package.json +7 -3
  3. package/src/index.d.ts +6 -2
  4. package/src/index.js +6 -2
  5. package/src/index.js.map +1 -1
  6. package/src/lib/client/content/builders/collection/collection.d.ts +148 -0
  7. package/src/lib/client/content/builders/collection/collection.js +264 -0
  8. package/src/lib/client/content/builders/collection/collection.js.map +1 -0
  9. package/src/lib/client/content/content-api.d.ts +78 -0
  10. package/src/lib/client/content/content-api.js +87 -0
  11. package/src/lib/client/content/content-api.js.map +1 -0
  12. package/src/lib/client/content/shared/const.d.ts +3 -0
  13. package/src/lib/client/content/shared/const.js +5 -0
  14. package/src/lib/client/content/shared/const.js.map +1 -0
  15. package/src/lib/client/content/shared/types.d.ts +62 -0
  16. package/src/lib/client/content/shared/types.js +2 -0
  17. package/src/lib/client/content/shared/types.js.map +1 -0
  18. package/src/lib/client/content/shared/utils.d.ts +12 -0
  19. package/src/lib/client/content/shared/utils.js +20 -0
  20. package/src/lib/client/content/shared/utils.js.map +1 -0
  21. package/src/lib/client/models/index.d.ts +1 -0
  22. package/src/lib/client/models/index.js +9 -0
  23. package/src/lib/client/models/index.js.map +1 -0
  24. package/src/lib/client/models/types.d.ts +5 -0
  25. package/src/lib/client/models/types.js +2 -0
  26. package/src/lib/client/models/types.js.map +1 -0
  27. package/src/lib/{sdk-js-client.d.ts → client/sdk-js-client.d.ts} +33 -23
  28. package/src/lib/{sdk-js-client.js → client/sdk-js-client.js} +87 -38
  29. package/src/lib/client/sdk-js-client.js.map +1 -0
  30. package/src/lib/editor/listeners/listeners.d.ts +46 -0
  31. package/src/lib/editor/listeners/listeners.js +180 -0
  32. package/src/lib/editor/listeners/listeners.js.map +1 -0
  33. package/src/lib/{postMessageToEditor.d.ts → editor/models/client.model.d.ts} +33 -1
  34. package/src/lib/editor/models/client.model.js +73 -0
  35. package/src/lib/editor/models/client.model.js.map +1 -0
  36. package/src/lib/editor/models/editor.model.d.ts +49 -0
  37. package/src/lib/editor/models/editor.model.js +2 -0
  38. package/src/lib/editor/models/editor.model.js.map +1 -0
  39. package/src/lib/editor/models/listeners.model.d.ts +47 -0
  40. package/src/lib/editor/models/listeners.model.js +26 -0
  41. package/src/lib/editor/models/listeners.model.js.map +1 -0
  42. package/src/lib/editor/sdk-editor-vtl.d.ts +6 -0
  43. package/src/lib/editor/sdk-editor-vtl.js +20 -0
  44. package/src/lib/editor/sdk-editor-vtl.js.map +1 -0
  45. package/src/lib/editor/sdk-editor.d.ts +29 -0
  46. package/src/lib/editor/sdk-editor.js +65 -0
  47. package/src/lib/editor/sdk-editor.js.map +1 -0
  48. package/src/lib/editor/utils/editor.utils.d.ts +83 -0
  49. package/src/lib/editor/utils/editor.utils.js +134 -0
  50. package/src/lib/editor/utils/editor.utils.js.map +1 -0
  51. package/src/lib/query-builder/lucene-syntax/Equals.d.ts +83 -0
  52. package/src/lib/query-builder/lucene-syntax/Equals.js +101 -0
  53. package/src/lib/query-builder/lucene-syntax/Equals.js.map +1 -0
  54. package/src/lib/query-builder/lucene-syntax/Field.d.ts +23 -0
  55. package/src/lib/query-builder/lucene-syntax/Field.js +31 -0
  56. package/src/lib/query-builder/lucene-syntax/Field.js.map +1 -0
  57. package/src/lib/query-builder/lucene-syntax/NotOperand.d.ts +22 -0
  58. package/src/lib/query-builder/lucene-syntax/NotOperand.js +30 -0
  59. package/src/lib/query-builder/lucene-syntax/NotOperand.js.map +1 -0
  60. package/src/lib/query-builder/lucene-syntax/Operand.d.ts +44 -0
  61. package/src/lib/query-builder/lucene-syntax/Operand.js +55 -0
  62. package/src/lib/query-builder/lucene-syntax/Operand.js.map +1 -0
  63. package/src/lib/query-builder/lucene-syntax/index.d.ts +4 -0
  64. package/src/lib/query-builder/lucene-syntax/index.js +5 -0
  65. package/src/lib/query-builder/lucene-syntax/index.js.map +1 -0
  66. package/src/lib/query-builder/sdk-query-builder.d.ts +42 -0
  67. package/src/lib/query-builder/sdk-query-builder.js +54 -0
  68. package/src/lib/query-builder/sdk-query-builder.js.map +1 -0
  69. package/src/lib/query-builder/utils/index.d.ts +91 -0
  70. package/src/lib/query-builder/utils/index.js +115 -0
  71. package/src/lib/query-builder/utils/index.js.map +1 -0
  72. package/src/lib/utils/graphql/transforms.d.ts +11 -0
  73. package/src/lib/utils/graphql/transforms.js +52 -0
  74. package/src/lib/utils/graphql/transforms.js.map +1 -0
  75. package/src/lib/utils/index.d.ts +2 -0
  76. package/src/lib/utils/index.js +3 -0
  77. package/src/lib/utils/index.js.map +1 -0
  78. package/src/lib/utils/page/common-utils.d.ts +14 -0
  79. package/src/lib/utils/page/common-utils.js +12 -0
  80. package/src/lib/utils/page/common-utils.js.map +1 -0
  81. package/src/lib/postMessageToEditor.js +0 -41
  82. package/src/lib/postMessageToEditor.js.map +0 -1
  83. package/src/lib/sdk-js-client.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../../../../../../libs/sdk/client/src/lib/client/content/shared/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAE5C,gEAAgE;AAChE,MAAM,CAAC,MAAM,wBAAwB,GAAa,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AAEnG,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { Equals } from '../../../query-builder/lucene-syntax';
2
+ import { QueryBuilder } from '../../../query-builder/sdk-query-builder';
3
+ export type SortBy = {
4
+ field: string;
5
+ order: 'asc' | 'desc';
6
+ };
7
+ export type BuildQuery = (qb: QueryBuilder) => Equals;
8
+ export interface ContentTypeMainFields {
9
+ hostName: string;
10
+ modDate: string;
11
+ publishDate: string;
12
+ title: string;
13
+ baseType: string;
14
+ inode: string;
15
+ archived: boolean;
16
+ ownerName: string;
17
+ host: string;
18
+ working: boolean;
19
+ locked: boolean;
20
+ stInode: string;
21
+ contentType: string;
22
+ live: boolean;
23
+ owner: string;
24
+ identifier: string;
25
+ publishUserName: string;
26
+ publishUser: string;
27
+ languageId: number;
28
+ creationDate: string;
29
+ url: string;
30
+ titleImage: string;
31
+ modUserName: string;
32
+ hasLiveVersion: boolean;
33
+ folder: string;
34
+ hasTitleImage: boolean;
35
+ sortOrder: number;
36
+ modUser: string;
37
+ __icon__: string;
38
+ contentTypeIcon: string;
39
+ variant: string;
40
+ }
41
+ export type Contentlet<T> = T & ContentTypeMainFields;
42
+ export type OnFullfilled<T> = ((value: GetCollectionResponse<T>) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void) | undefined | null;
43
+ export type OnRejected = ((error: GetCollectionError) => GetCollectionError | PromiseLike<GetCollectionError> | void) | undefined | null;
44
+ export interface GetCollectionResponse<T> {
45
+ contentlets: Contentlet<T>[];
46
+ page: number;
47
+ size: number;
48
+ total: number;
49
+ sortedBy?: SortBy[];
50
+ }
51
+ export interface GetCollectionRawResponse<T> {
52
+ entity: {
53
+ jsonObjectView: {
54
+ contentlets: Contentlet<T>[];
55
+ };
56
+ resultsSize: number;
57
+ };
58
+ }
59
+ export interface GetCollectionError {
60
+ status: number;
61
+ [key: string]: unknown;
62
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../../../libs/sdk/client/src/lib/client/content/shared/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Sanitizes the query for the given content type.
3
+ * It replaces the fields that are not contentType fields with the correct format.
4
+ * Example: +field: -> +contentTypeVar.field:
5
+ *
6
+ *
7
+ * @export
8
+ * @param {string} query
9
+ * @param {string} contentType
10
+ * @return {*} {string}
11
+ */
12
+ export declare function sanitizeQueryForContentType(query: string, contentType: string): string;
@@ -0,0 +1,20 @@
1
+ import { CONTENT_TYPE_MAIN_FIELDS } from './const';
2
+ /**
3
+ * Sanitizes the query for the given content type.
4
+ * It replaces the fields that are not contentType fields with the correct format.
5
+ * Example: +field: -> +contentTypeVar.field:
6
+ *
7
+ *
8
+ * @export
9
+ * @param {string} query
10
+ * @param {string} contentType
11
+ * @return {*} {string}
12
+ */
13
+ export function sanitizeQueryForContentType(query, contentType) {
14
+ return query.replace(/\+([^+:]*?):/g, (original, field) => {
15
+ return !CONTENT_TYPE_MAIN_FIELDS.includes(field) // Fields that are not contentType fields
16
+ ? `+${contentType}.${field}:` // Should have this format: +contentTypeVar.field:
17
+ : original; // Return the field if it is a contentType field
18
+ });
19
+ }
20
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../../../../libs/sdk/client/src/lib/client/content/shared/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,2BAA2B,CAAC,KAAa,EAAE,WAAmB;IAC1E,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtD,OAAO,CAAC,wBAAwB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,yCAAyC;YACtF,CAAC,CAAC,IAAI,WAAW,IAAI,KAAK,GAAG,CAAC,kDAAkD;YAChF,CAAC,CAAC,QAAQ,CAAC,CAAC,gDAAgD;IACpE,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const ErrorMessages: Record<number, string>;
@@ -0,0 +1,9 @@
1
+ export const ErrorMessages = {
2
+ 401: 'Unauthorized. Check the token and try again.',
3
+ 403: 'Forbidden. Check the permissions and try again.',
4
+ 404: 'Not Found. Check the URL and try again.',
5
+ 500: 'Internal Server Error. Try again later.',
6
+ 502: 'Bad Gateway. Try again later.',
7
+ 503: 'Service Unavailable. Try again later.'
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/client/models/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAA2B;IACjD,GAAG,EAAE,8CAA8C;IACnD,GAAG,EAAE,iDAAiD;IACtD,GAAG,EAAE,yCAAyC;IAC9C,GAAG,EAAE,yCAAyC;IAC9C,GAAG,EAAE,+BAA+B;IACpC,GAAG,EAAE,uCAAuC;CAC/C,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type DotcmsClientListener = {
2
+ action: string;
3
+ event: string;
4
+ callback: (...args: any[]) => void;
5
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/client/models/types.ts"],"names":[],"mappings":""}
@@ -1,3 +1,5 @@
1
+ import { Content } from './content/content-api';
2
+ export type ClientOptions = Omit<RequestInit, 'body' | 'method'>;
1
3
  export interface ClientConfig {
2
4
  /**
3
5
  * The URL of the dotCMS instance.
@@ -31,10 +33,10 @@ export interface ClientConfig {
31
33
  *
32
34
  * @description These options will be used in the fetch request. Any option can be specified except for 'body' and 'method' which are omitted.
33
35
  * @example `{ headers: { 'Content-Type': 'application/json' } }`
34
- * @type {Omit<RequestInit, 'body' | 'method'>}
36
+ * @type {ClientOptions}
35
37
  * @optional
36
38
  */
37
- requestOptions?: Omit<RequestInit, 'body' | 'method'>;
39
+ requestOptions?: ClientOptions;
38
40
  }
39
41
  type PageApiOptions = {
40
42
  /**
@@ -49,6 +51,12 @@ type PageApiOptions = {
49
51
  * @type {number}
50
52
  */
51
53
  siteId?: string;
54
+ /**
55
+ * The mode of the page you want to retrieve. If not provided will use the default mode of the site.
56
+ *
57
+ * @type {number}
58
+ */
59
+ mode?: string;
52
60
  /**
53
61
  * The language id of the page you want to retrieve. If not provided will use the default language of the site.
54
62
  *
@@ -125,8 +133,10 @@ type NavApiOptions = {
125
133
  *
126
134
  */
127
135
  export declare class DotCmsClient {
128
- private config;
129
- private requestOptions;
136
+ #private;
137
+ static instance: DotCmsClient;
138
+ dotcmsUrl?: string;
139
+ content: Content;
130
140
  constructor(config?: ClientConfig);
131
141
  page: {
132
142
  /**
@@ -144,6 +154,23 @@ export declare class DotCmsClient {
144
154
  */
145
155
  get: (options: PageApiOptions) => Promise<unknown>;
146
156
  };
157
+ editor: {
158
+ /**
159
+ * `editor.on` is an asynchronous method of the `DotCmsClient` class that allows you to react to actions issued by the UVE.
160
+ *
161
+ * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
162
+ * @param action - The name of the name emitted by UVE
163
+ * @param callbackFn - The function to execute when the UVE emits the action
164
+ */
165
+ on: (action: string, callbackFn: (payload: unknown) => void) => void;
166
+ /**
167
+ * `editor.off` is an synchronous method of the `DotCmsClient` class that allows you to stop listening and reacting to an action issued by UVE.
168
+ *
169
+ * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
170
+ * @param action
171
+ */
172
+ off: (action: string) => void;
173
+ };
147
174
  nav: {
148
175
  /**
149
176
  * `nav.get` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
@@ -158,26 +185,9 @@ export declare class DotCmsClient {
158
185
  */
159
186
  get: (options?: NavApiOptions) => Promise<unknown>;
160
187
  };
188
+ static init(config: ClientConfig): DotCmsClient;
189
+ static get dotcmsUrl(): string;
161
190
  private validatePageOptions;
162
191
  private validateNavOptions;
163
192
  }
164
- /**
165
- * `dotcmsClient` is an object that provides a method to initialize the DotCMS SDK client.
166
- * It has a single method `init` which takes a configuration object and returns an instance of the `DotCmsClient` class.
167
- *
168
- * @namespace dotcmsClient
169
- *
170
- * @method init(config: ClientConfig): DotCmsClient - Initializes the SDK client.
171
- */
172
- export declare const dotcmsClient: {
173
- /**
174
- * `init` is a method of the `dotcmsClient` object that initializes the SDK client.
175
- * It takes a configuration object as a parameter and returns an instance of the `DotCmsClient` class.
176
- *
177
- * @method init
178
- * @param {ClientConfig} config - The configuration object for the DotCMS client.
179
- * @returns {DotCmsClient} - An instance of the {@link DotCmsClient} class.
180
- */
181
- init: (config: ClientConfig) => DotCmsClient;
182
- };
183
193
  export {};
@@ -1,10 +1,14 @@
1
- function isValidUrl(url) {
1
+ var _DotCmsClient_config, _DotCmsClient_requestOptions, _DotCmsClient_listeners;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import { Content } from './content/content-api';
4
+ import { ErrorMessages } from './models';
5
+ import { isInsideEditor } from '../editor/sdk-editor';
6
+ function getHostURL(url) {
2
7
  try {
3
- new URL(url);
4
- return true;
8
+ return new URL(url);
5
9
  }
6
10
  catch (error) {
7
- return false;
11
+ return undefined;
8
12
  }
9
13
  }
10
14
  /**
@@ -24,6 +28,9 @@ function isValidUrl(url) {
24
28
  */
25
29
  export class DotCmsClient {
26
30
  constructor(config = { dotcmsUrl: '', authToken: '', requestOptions: {}, siteId: '' }) {
31
+ _DotCmsClient_config.set(this, void 0);
32
+ _DotCmsClient_requestOptions.set(this, void 0);
33
+ _DotCmsClient_listeners.set(this, []);
27
34
  this.page = {
28
35
  /**
29
36
  * `page.get` is an asynchronous method of the `DotCmsClient` class that retrieves all the elements of any Page in your dotCMS system in JSON format.
@@ -47,19 +54,67 @@ export class DotCmsClient {
47
54
  if (key === 'personaId') {
48
55
  queryParamsObj['com.dotmarketing.persona.id'] = String(value);
49
56
  }
57
+ else if (key === 'mode' && value) {
58
+ queryParamsObj['mode'] = String(value);
59
+ }
50
60
  else {
51
61
  queryParamsObj[key] = String(value);
52
62
  }
53
63
  }
54
- const queryHostId = options.siteId ?? this.config.siteId ?? '';
64
+ const queryHostId = options.siteId ?? __classPrivateFieldGet(this, _DotCmsClient_config, "f").siteId ?? '';
55
65
  if (queryHostId) {
56
66
  queryParamsObj['host_id'] = queryHostId;
57
67
  }
58
68
  const queryParams = new URLSearchParams(queryParamsObj).toString();
59
69
  const formattedPath = options.path.startsWith('/') ? options.path : `/${options.path}`;
60
- const url = `${this.config.dotcmsUrl}/api/v1/page/json${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
61
- const response = await fetch(url, this.requestOptions);
62
- return response.json();
70
+ const url = `${__classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl}/api/v1/page/json${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
71
+ const response = await fetch(url, __classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"));
72
+ if (!response.ok) {
73
+ const error = {
74
+ status: response.status,
75
+ message: ErrorMessages[response.status] || response.statusText
76
+ };
77
+ console.error(error);
78
+ throw error;
79
+ }
80
+ return response.json().then((data) => data.entity);
81
+ }
82
+ };
83
+ this.editor = {
84
+ /**
85
+ * `editor.on` is an asynchronous method of the `DotCmsClient` class that allows you to react to actions issued by the UVE.
86
+ *
87
+ * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
88
+ * @param action - The name of the name emitted by UVE
89
+ * @param callbackFn - The function to execute when the UVE emits the action
90
+ */
91
+ on: (action, callbackFn) => {
92
+ if (!isInsideEditor()) {
93
+ return;
94
+ }
95
+ if (action === 'changes') {
96
+ const messageCallback = (event) => {
97
+ if (event.data.name === 'SET_PAGE_DATA') {
98
+ callbackFn(event.data.payload);
99
+ }
100
+ };
101
+ window.addEventListener('message', messageCallback);
102
+ __classPrivateFieldGet(this, _DotCmsClient_listeners, "f").push({ event: 'message', callback: messageCallback, action });
103
+ }
104
+ },
105
+ /**
106
+ * `editor.off` is an synchronous method of the `DotCmsClient` class that allows you to stop listening and reacting to an action issued by UVE.
107
+ *
108
+ * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
109
+ * @param action
110
+ */
111
+ off: (action) => {
112
+ const listenerIndex = __classPrivateFieldGet(this, _DotCmsClient_listeners, "f").findIndex((listener) => listener.action === action);
113
+ if (listenerIndex !== -1) {
114
+ const listener = __classPrivateFieldGet(this, _DotCmsClient_listeners, "f")[listenerIndex];
115
+ window.removeEventListener(listener.event, listener.callback);
116
+ __classPrivateFieldGet(this, _DotCmsClient_listeners, "f").splice(listenerIndex, 1);
117
+ }
63
118
  }
64
119
  };
65
120
  this.nav = {
@@ -87,28 +142,42 @@ export class DotCmsClient {
87
142
  const queryParams = new URLSearchParams(queryParamsObj).toString();
88
143
  // Format the URL correctly depending on the 'path' value
89
144
  const formattedPath = path === '/' ? '/' : `/${path}`;
90
- const url = `${this.config.dotcmsUrl}/api/v1/nav${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
91
- const response = await fetch(url, this.requestOptions);
145
+ const url = `${__classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl}/api/v1/nav${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
146
+ const response = await fetch(url, __classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"));
92
147
  return response.json();
93
148
  }
94
149
  };
95
150
  if (!config.dotcmsUrl) {
96
151
  throw new Error("Invalid configuration - 'dotcmsUrl' is required");
97
152
  }
98
- if (!isValidUrl(config.dotcmsUrl)) {
153
+ this.dotcmsUrl = getHostURL(config.dotcmsUrl)?.origin;
154
+ if (!this.dotcmsUrl) {
99
155
  throw new Error("Invalid configuration - 'dotcmsUrl' must be a valid URL");
100
156
  }
101
157
  if (!config.authToken) {
102
158
  throw new Error("Invalid configuration - 'authToken' is required");
103
159
  }
104
- this.config = config;
105
- this.requestOptions = {
106
- ...this.config.requestOptions,
160
+ __classPrivateFieldSet(this, _DotCmsClient_config, {
161
+ ...config,
162
+ dotcmsUrl: this.dotcmsUrl
163
+ }, "f");
164
+ __classPrivateFieldSet(this, _DotCmsClient_requestOptions, {
165
+ ...__classPrivateFieldGet(this, _DotCmsClient_config, "f").requestOptions,
107
166
  headers: {
108
- Authorization: `Bearer ${this.config.authToken}`,
109
- ...this.config.requestOptions?.headers
167
+ Authorization: `Bearer ${__classPrivateFieldGet(this, _DotCmsClient_config, "f").authToken}`,
168
+ ...__classPrivateFieldGet(this, _DotCmsClient_config, "f").requestOptions?.headers
110
169
  }
111
- };
170
+ }, "f");
171
+ this.content = new Content(__classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"), __classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl);
172
+ }
173
+ static init(config) {
174
+ if (this.instance) {
175
+ console.warn('DotCmsClient has already been initialized. Please use the instance to interact with the DotCMS API.');
176
+ }
177
+ return this.instance ?? (this.instance = new DotCmsClient(config));
178
+ }
179
+ static get dotcmsUrl() {
180
+ return (this.instance && __classPrivateFieldGet(this.instance, _DotCmsClient_config, "f").dotcmsUrl) || '';
112
181
  }
113
182
  validatePageOptions(options) {
114
183
  if (!options.path) {
@@ -121,25 +190,5 @@ export class DotCmsClient {
121
190
  }
122
191
  }
123
192
  }
124
- /**
125
- * `dotcmsClient` is an object that provides a method to initialize the DotCMS SDK client.
126
- * It has a single method `init` which takes a configuration object and returns an instance of the `DotCmsClient` class.
127
- *
128
- * @namespace dotcmsClient
129
- *
130
- * @method init(config: ClientConfig): DotCmsClient - Initializes the SDK client.
131
- */
132
- export const dotcmsClient = {
133
- /**
134
- * `init` is a method of the `dotcmsClient` object that initializes the SDK client.
135
- * It takes a configuration object as a parameter and returns an instance of the `DotCmsClient` class.
136
- *
137
- * @method init
138
- * @param {ClientConfig} config - The configuration object for the DotCMS client.
139
- * @returns {DotCmsClient} - An instance of the {@link DotCmsClient} class.
140
- */
141
- init: (config) => {
142
- return new DotCmsClient(config);
143
- }
144
- };
193
+ _DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
145
194
  //# sourceMappingURL=sdk-js-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-js-client.js","sourceRoot":"","sources":["../../../../../../../libs/sdk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,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACzE,CAAC;IACL,CAAC;IAEO,kBAAkB,CAAC,OAAsB;QAC7C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,46 @@
1
+ import { DotCMSPageEditorSubscription } from '../models/listeners.model';
2
+ declare global {
3
+ interface Window {
4
+ lastScrollYPosition: number;
5
+ }
6
+ }
7
+ /**
8
+ * Represents an array of DotCMSPageEditorSubscription objects.
9
+ * Used to store the subscriptions for the editor and unsubscribe later.
10
+ */
11
+ export declare const subscriptions: DotCMSPageEditorSubscription[];
12
+ /**
13
+ * Listens for editor messages and performs corresding actions based on the received message.
14
+ *
15
+ * @private
16
+ * @memberof DotCMSPageEditor
17
+ */
18
+ export declare function listenEditorMessages(): void;
19
+ /**
20
+ * Listens for pointer move events and extracts information about the hovered contentlet.
21
+ *
22
+ * @private
23
+ * @memberof DotCMSPageEditor
24
+ */
25
+ export declare function listenHoveredContentlet(): void;
26
+ /**
27
+ * Attaches a scroll event listener to the window
28
+ * and sends a message to the editor when the window is scrolled.
29
+ *
30
+ * @private
31
+ * @memberof DotCMSPageEditor
32
+ */
33
+ export declare function scrollHandler(): void;
34
+ /**
35
+ * Restores the scroll position of the window when an iframe is loaded.
36
+ * Only used in VTL Pages.
37
+ * @export
38
+ */
39
+ export declare function preserveScrollOnIframe(): void;
40
+ /**
41
+ * Sends a message to the editor to get the page data.
42
+ * @param {string} pathname - The pathname of the page.
43
+ * @private
44
+ * @memberof DotCMSPageEditor
45
+ */
46
+ export declare function fetchPageDataFromInsideUVE(pathname: string): void;
@@ -0,0 +1,180 @@
1
+ import { CUSTOMER_ACTIONS, postMessageToEditor } from '../models/client.model';
2
+ import { NOTIFY_CUSTOMER } from '../models/listeners.model';
3
+ import { findVTLData, findDotElement, getClosestContainerData, getPageElementBound, scrollIsInBottom } from '../utils/editor.utils';
4
+ /**
5
+ * Represents an array of DotCMSPageEditorSubscription objects.
6
+ * Used to store the subscriptions for the editor and unsubscribe later.
7
+ */
8
+ export const subscriptions = [];
9
+ /**
10
+ * Sets the bounds of the containers in the editor.
11
+ * Retrieves the containers from the DOM and sends their position data to the editor.
12
+ * @private
13
+ * @memberof DotCMSPageEditor
14
+ */
15
+ function setBounds() {
16
+ const containers = Array.from(document.querySelectorAll('[data-dot-object="container"]'));
17
+ const positionData = getPageElementBound(containers);
18
+ postMessageToEditor({
19
+ action: CUSTOMER_ACTIONS.SET_BOUNDS,
20
+ payload: positionData
21
+ });
22
+ }
23
+ /**
24
+ * Listens for editor messages and performs corresding actions based on the received message.
25
+ *
26
+ * @private
27
+ * @memberof DotCMSPageEditor
28
+ */
29
+ export function listenEditorMessages() {
30
+ const messageCallback = (event) => {
31
+ switch (event.data) {
32
+ case NOTIFY_CUSTOMER.EMA_REQUEST_BOUNDS: {
33
+ setBounds();
34
+ break;
35
+ }
36
+ }
37
+ if (event.data.name === NOTIFY_CUSTOMER.EMA_SCROLL_INSIDE_IFRAME) {
38
+ const direction = event.data.direction;
39
+ if ((window.scrollY === 0 && direction === 'up') ||
40
+ (scrollIsInBottom() && direction === 'down')) {
41
+ /**
42
+ * If the iframe scroll is in the top of bottom, we dont send anything.
43
+ * This to avoid the lost of scrollend event
44
+ **/
45
+ return;
46
+ }
47
+ const scrollY = direction === 'up' ? -120 : 120;
48
+ window.scrollBy({ left: 0, top: scrollY, behavior: 'smooth' });
49
+ }
50
+ };
51
+ window.addEventListener('message', messageCallback);
52
+ subscriptions.push({
53
+ type: 'listener',
54
+ event: 'message',
55
+ callback: messageCallback
56
+ });
57
+ }
58
+ /**
59
+ * Listens for pointer move events and extracts information about the hovered contentlet.
60
+ *
61
+ * @private
62
+ * @memberof DotCMSPageEditor
63
+ */
64
+ export function listenHoveredContentlet() {
65
+ const pointerMoveCallback = (event) => {
66
+ const foundElement = findDotElement(event.target);
67
+ if (!foundElement)
68
+ return;
69
+ const { x, y, width, height } = foundElement.getBoundingClientRect();
70
+ const isContainer = foundElement.dataset?.['dotObject'] === 'container';
71
+ const contentletForEmptyContainer = {
72
+ identifier: 'TEMP_EMPTY_CONTENTLET',
73
+ title: 'TEMP_EMPTY_CONTENTLET',
74
+ contentType: 'TEMP_EMPTY_CONTENTLET_TYPE',
75
+ inode: 'TEMPY_EMPTY_CONTENTLET_INODE',
76
+ widgetTitle: 'TEMP_EMPTY_CONTENTLET',
77
+ baseType: 'TEMP_EMPTY_CONTENTLET',
78
+ onNumberOfPages: 1
79
+ };
80
+ const contentlet = {
81
+ identifier: foundElement.dataset?.['dotIdentifier'],
82
+ title: foundElement.dataset?.['dotTitle'],
83
+ inode: foundElement.dataset?.['dotInode'],
84
+ contentType: foundElement.dataset?.['dotType'],
85
+ baseType: foundElement.dataset?.['dotBasetype'],
86
+ widgetTitle: foundElement.dataset?.['dotWidgetTitle'],
87
+ onNumberOfPages: foundElement.dataset?.['dotOnNumberOfPages']
88
+ };
89
+ const vtlFiles = findVTLData(foundElement);
90
+ const contentletPayload = {
91
+ container:
92
+ // Here extract dot-container from contentlet if is Headless
93
+ // or search in parent container if is VTL
94
+ foundElement.dataset?.['dotContainer']
95
+ ? JSON.parse(foundElement.dataset?.['dotContainer'])
96
+ : getClosestContainerData(foundElement),
97
+ contentlet: isContainer ? contentletForEmptyContainer : contentlet,
98
+ vtlFiles
99
+ };
100
+ postMessageToEditor({
101
+ action: CUSTOMER_ACTIONS.SET_CONTENTLET,
102
+ payload: {
103
+ x,
104
+ y,
105
+ width,
106
+ height,
107
+ payload: contentletPayload
108
+ }
109
+ });
110
+ };
111
+ document.addEventListener('pointermove', pointerMoveCallback);
112
+ subscriptions.push({
113
+ type: 'listener',
114
+ event: 'pointermove',
115
+ callback: pointerMoveCallback
116
+ });
117
+ }
118
+ /**
119
+ * Attaches a scroll event listener to the window
120
+ * and sends a message to the editor when the window is scrolled.
121
+ *
122
+ * @private
123
+ * @memberof DotCMSPageEditor
124
+ */
125
+ export function scrollHandler() {
126
+ const scrollCallback = () => {
127
+ postMessageToEditor({
128
+ action: CUSTOMER_ACTIONS.IFRAME_SCROLL
129
+ });
130
+ window.lastScrollYPosition = window.scrollY;
131
+ };
132
+ const scrollEndCallback = () => {
133
+ postMessageToEditor({
134
+ action: CUSTOMER_ACTIONS.IFRAME_SCROLL_END
135
+ });
136
+ };
137
+ window.addEventListener('scroll', scrollCallback);
138
+ window.addEventListener('scrollend', scrollEndCallback);
139
+ subscriptions.push({
140
+ type: 'listener',
141
+ event: 'scroll',
142
+ callback: scrollEndCallback
143
+ });
144
+ subscriptions.push({
145
+ type: 'listener',
146
+ event: 'scroll',
147
+ callback: scrollCallback
148
+ });
149
+ }
150
+ /**
151
+ * Restores the scroll position of the window when an iframe is loaded.
152
+ * Only used in VTL Pages.
153
+ * @export
154
+ */
155
+ export function preserveScrollOnIframe() {
156
+ const preserveScrollCallback = () => {
157
+ window.scrollTo(0, window.lastScrollYPosition);
158
+ };
159
+ window.addEventListener('load', preserveScrollCallback);
160
+ subscriptions.push({
161
+ type: 'listener',
162
+ event: 'scroll',
163
+ callback: preserveScrollCallback
164
+ });
165
+ }
166
+ /**
167
+ * Sends a message to the editor to get the page data.
168
+ * @param {string} pathname - The pathname of the page.
169
+ * @private
170
+ * @memberof DotCMSPageEditor
171
+ */
172
+ export function fetchPageDataFromInsideUVE(pathname) {
173
+ postMessageToEditor({
174
+ action: CUSTOMER_ACTIONS.GET_PAGE_DATA,
175
+ payload: {
176
+ pathname
177
+ }
178
+ });
179
+ }
180
+ //# sourceMappingURL=listeners.js.map