dotcms 0.0.17 → 0.0.19

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 (166) hide show
  1. package/README.md +72 -10
  2. package/dotcms.d.ts.map +1 -0
  3. package/esm2020/dotcms.mjs +5 -0
  4. package/esm2020/index.mjs +36 -0
  5. package/esm2020/lib/api/DotApiAuthorization.mjs +42 -0
  6. package/esm2020/lib/api/DotApiConfiguration.mjs +27 -0
  7. package/esm2020/lib/api/DotApiContent.mjs +52 -0
  8. package/esm2020/lib/api/DotApiContentType.mjs +28 -0
  9. package/esm2020/lib/api/DotApiElasticSearch.mjs +32 -0
  10. package/esm2020/lib/api/DotApiEvent.mjs +16 -0
  11. package/esm2020/lib/api/DotApiForm.mjs +18 -0
  12. package/esm2020/lib/api/DotApiLanguage.mjs +24 -0
  13. package/esm2020/lib/api/DotApiNavigation.mjs +29 -0
  14. package/esm2020/lib/api/DotApiPage.mjs +50 -0
  15. package/esm2020/lib/api/DotApiSite.mjs +26 -0
  16. package/esm2020/lib/api/DotApiWidget.mjs +28 -0
  17. package/esm2020/lib/models/DotCMSAuthorization.model.mjs +2 -0
  18. package/esm2020/lib/models/DotCMSConfiguration.model.mjs +2 -0
  19. package/esm2020/lib/models/DotCMSContent.model.mjs +2 -0
  20. package/esm2020/lib/models/DotCMSElasticSearch.model.mjs +2 -0
  21. package/esm2020/lib/models/DotCMSError.model.mjs +2 -0
  22. package/esm2020/lib/models/DotCMSEvent.model.mjs +2 -0
  23. package/esm2020/lib/models/DotCMSForm.model.mjs +2 -0
  24. package/esm2020/lib/models/DotCMSHttpClient.model.mjs +2 -0
  25. package/esm2020/lib/models/DotCMSLanguage.model.mjs +2 -0
  26. package/esm2020/lib/models/DotCMSNavigation.model.mjs +2 -0
  27. package/esm2020/lib/models/DotCMSPage.model.mjs +2 -0
  28. package/esm2020/lib/models/DotCMSPageFormat.model.mjs +2 -0
  29. package/esm2020/lib/models/DotCMSSite.model.mjs +2 -0
  30. package/esm2020/lib/models/index.mjs +14 -0
  31. package/esm2020/lib/utils/DotCMSHttpClient.mjs +10 -0
  32. package/esm2020/lib/utils/getEsQuery.mjs +35 -0
  33. package/esm2020/lib/utils/request.mjs +42 -0
  34. package/{public_api.d.ts → index.d.ts} +1 -0
  35. package/index.d.ts.map +1 -0
  36. package/lib/api/DotApiAuthorization.d.ts +1 -0
  37. package/lib/api/DotApiAuthorization.d.ts.map +1 -0
  38. package/lib/api/DotApiConfiguration.d.ts +1 -0
  39. package/lib/api/DotApiConfiguration.d.ts.map +1 -0
  40. package/lib/api/DotApiContent.d.ts +1 -0
  41. package/lib/api/DotApiContent.d.ts.map +1 -0
  42. package/lib/api/DotApiContentType.d.ts +2 -1
  43. package/lib/api/DotApiContentType.d.ts.map +1 -0
  44. package/lib/api/DotApiElasticSearch.d.ts +1 -0
  45. package/lib/api/DotApiElasticSearch.d.ts.map +1 -0
  46. package/lib/api/DotApiEvent.d.ts +1 -0
  47. package/lib/api/DotApiEvent.d.ts.map +1 -0
  48. package/lib/api/DotApiForm.d.ts +2 -1
  49. package/lib/api/DotApiForm.d.ts.map +1 -0
  50. package/lib/api/DotApiLanguage.d.ts +4 -3
  51. package/lib/api/DotApiLanguage.d.ts.map +1 -0
  52. package/lib/api/DotApiNavigation.d.ts +2 -1
  53. package/lib/api/DotApiNavigation.d.ts.map +1 -0
  54. package/lib/api/DotApiPage.d.ts +1 -0
  55. package/lib/api/DotApiPage.d.ts.map +1 -0
  56. package/lib/api/DotApiSite.d.ts +1 -0
  57. package/lib/api/DotApiSite.d.ts.map +1 -0
  58. package/lib/api/DotApiWidget.d.ts +1 -0
  59. package/lib/api/DotApiWidget.d.ts.map +1 -0
  60. package/lib/models/DotCMSAuthorization.model.d.ts +1 -0
  61. package/lib/models/DotCMSAuthorization.model.d.ts.map +1 -0
  62. package/lib/models/DotCMSConfiguration.model.d.ts +1 -0
  63. package/lib/models/DotCMSConfiguration.model.d.ts.map +1 -0
  64. package/lib/models/DotCMSContent.model.d.ts +1 -0
  65. package/lib/models/DotCMSContent.model.d.ts.map +1 -0
  66. package/lib/models/DotCMSElasticSearch.model.d.ts +1 -0
  67. package/lib/models/DotCMSElasticSearch.model.d.ts.map +1 -0
  68. package/lib/models/DotCMSError.model.d.ts +1 -0
  69. package/lib/models/DotCMSError.model.d.ts.map +1 -0
  70. package/lib/models/DotCMSEvent.model.d.ts +1 -0
  71. package/lib/models/DotCMSEvent.model.d.ts.map +1 -0
  72. package/lib/models/DotCMSForm.model.d.ts +1 -0
  73. package/lib/models/DotCMSForm.model.d.ts.map +1 -0
  74. package/lib/models/DotCMSHttpClient.model.d.ts +4 -1
  75. package/lib/models/DotCMSHttpClient.model.d.ts.map +1 -0
  76. package/lib/models/DotCMSLanguage.model.d.ts +1 -0
  77. package/lib/models/DotCMSLanguage.model.d.ts.map +1 -0
  78. package/lib/models/DotCMSNavigation.model.d.ts +1 -0
  79. package/lib/models/DotCMSNavigation.model.d.ts.map +1 -0
  80. package/lib/models/DotCMSPage.model.d.ts +1 -0
  81. package/lib/models/DotCMSPage.model.d.ts.map +1 -0
  82. package/lib/models/DotCMSPageFormat.model.d.ts +1 -0
  83. package/lib/models/DotCMSPageFormat.model.d.ts.map +1 -0
  84. package/lib/models/DotCMSSite.model.d.ts +1 -0
  85. package/lib/models/DotCMSSite.model.d.ts.map +1 -0
  86. package/lib/models/index.d.ts +1 -0
  87. package/lib/models/index.d.ts.map +1 -0
  88. package/lib/utils/DotCMSHttpClient.d.ts +1 -0
  89. package/lib/utils/DotCMSHttpClient.d.ts.map +1 -0
  90. package/lib/utils/getEsQuery.d.ts +1 -0
  91. package/lib/utils/getEsQuery.d.ts.map +1 -0
  92. package/lib/utils/request.d.ts +2 -1
  93. package/lib/utils/request.d.ts.map +1 -0
  94. package/package.json +22 -14
  95. package/bundles/dotcms.umd.js +0 -1152
  96. package/bundles/dotcms.umd.js.map +0 -1
  97. package/bundles/dotcms.umd.min.js +0 -2
  98. package/bundles/dotcms.umd.min.js.map +0 -1
  99. package/dotcms.d.ts +0 -4
  100. package/dotcms.metadata.json +0 -1
  101. package/esm2015/dotcms.js +0 -10
  102. package/esm2015/lib/api/DotApiAuthorization.js +0 -55
  103. package/esm2015/lib/api/DotApiConfiguration.js +0 -43
  104. package/esm2015/lib/api/DotApiContent.js +0 -96
  105. package/esm2015/lib/api/DotApiContentType.js +0 -53
  106. package/esm2015/lib/api/DotApiElasticSearch.js +0 -47
  107. package/esm2015/lib/api/DotApiEvent.js +0 -26
  108. package/esm2015/lib/api/DotApiForm.js +0 -37
  109. package/esm2015/lib/api/DotApiLanguage.js +0 -52
  110. package/esm2015/lib/api/DotApiNavigation.js +0 -45
  111. package/esm2015/lib/api/DotApiPage.js +0 -68
  112. package/esm2015/lib/api/DotApiSite.js +0 -43
  113. package/esm2015/lib/api/DotApiWidget.js +0 -43
  114. package/esm2015/lib/models/DotCMSAuthorization.model.js +0 -18
  115. package/esm2015/lib/models/DotCMSConfiguration.model.js +0 -34
  116. package/esm2015/lib/models/DotCMSContent.model.js +0 -22
  117. package/esm2015/lib/models/DotCMSElasticSearch.model.js +0 -80
  118. package/esm2015/lib/models/DotCMSError.model.js +0 -14
  119. package/esm2015/lib/models/DotCMSEvent.model.js +0 -14
  120. package/esm2015/lib/models/DotCMSForm.model.js +0 -28
  121. package/esm2015/lib/models/DotCMSHttpClient.model.js +0 -18
  122. package/esm2015/lib/models/DotCMSLanguage.model.js +0 -20
  123. package/esm2015/lib/models/DotCMSNavigation.model.js +0 -32
  124. package/esm2015/lib/models/DotCMSPage.model.js +0 -468
  125. package/esm2015/lib/models/DotCMSPageFormat.model.js +0 -12
  126. package/esm2015/lib/models/DotCMSSite.model.js +0 -312
  127. package/esm2015/lib/models/index.js +0 -6
  128. package/esm2015/lib/utils/DotCMSHttpClient.js +0 -26
  129. package/esm2015/lib/utils/getEsQuery.js +0 -47
  130. package/esm2015/lib/utils/request.js +0 -79
  131. package/esm2015/public_api.js +0 -77
  132. package/esm5/dotcms.js +0 -10
  133. package/esm5/lib/api/DotApiAuthorization.js +0 -82
  134. package/esm5/lib/api/DotApiConfiguration.js +0 -63
  135. package/esm5/lib/api/DotApiContent.js +0 -152
  136. package/esm5/lib/api/DotApiContentType.js +0 -75
  137. package/esm5/lib/api/DotApiElasticSearch.js +0 -72
  138. package/esm5/lib/api/DotApiEvent.js +0 -42
  139. package/esm5/lib/api/DotApiForm.js +0 -54
  140. package/esm5/lib/api/DotApiLanguage.js +0 -80
  141. package/esm5/lib/api/DotApiNavigation.js +0 -68
  142. package/esm5/lib/api/DotApiPage.js +0 -108
  143. package/esm5/lib/api/DotApiSite.js +0 -60
  144. package/esm5/lib/api/DotApiWidget.js +0 -66
  145. package/esm5/lib/models/DotCMSAuthorization.model.js +0 -18
  146. package/esm5/lib/models/DotCMSConfiguration.model.js +0 -34
  147. package/esm5/lib/models/DotCMSContent.model.js +0 -22
  148. package/esm5/lib/models/DotCMSElasticSearch.model.js +0 -80
  149. package/esm5/lib/models/DotCMSError.model.js +0 -14
  150. package/esm5/lib/models/DotCMSEvent.model.js +0 -14
  151. package/esm5/lib/models/DotCMSForm.model.js +0 -28
  152. package/esm5/lib/models/DotCMSHttpClient.model.js +0 -18
  153. package/esm5/lib/models/DotCMSLanguage.model.js +0 -20
  154. package/esm5/lib/models/DotCMSNavigation.model.js +0 -32
  155. package/esm5/lib/models/DotCMSPage.model.js +0 -468
  156. package/esm5/lib/models/DotCMSPageFormat.model.js +0 -12
  157. package/esm5/lib/models/DotCMSSite.model.js +0 -312
  158. package/esm5/lib/models/index.js +0 -6
  159. package/esm5/lib/utils/DotCMSHttpClient.js +0 -29
  160. package/esm5/lib/utils/getEsQuery.js +0 -31
  161. package/esm5/lib/utils/request.js +0 -86
  162. package/esm5/public_api.js +0 -77
  163. package/fesm2015/dotcms.js +0 -723
  164. package/fesm2015/dotcms.js.map +0 -1
  165. package/fesm5/dotcms.js +0 -972
  166. package/fesm5/dotcms.js.map +0 -1
@@ -1,723 +0,0 @@
1
- import fetch from 'node-fetch';
2
- import { __awaiter, __rest } from 'tslib';
3
-
4
- /**
5
- * @fileoverview added by tsickle
6
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
7
- */
8
- /**
9
- * @param {?} data
10
- * @return {?}
11
- */
12
- function getErrorMessage(data) {
13
- if (data["errors"]) {
14
- return data["errors"][0].message;
15
- }
16
- if (data["error"]) {
17
- return data["error"];
18
- }
19
- }
20
- /**
21
- * DotCMS Authentication handler to intereact with {\@link https://dotcms.com/docs/latest/rest-api-authentication | Authentication API}
22
- *
23
- */
24
- class DotApiAuthorization {
25
- /**
26
- * Given user, password and expiration date to get a DotCMS Autorization Token
27
- * @param {?} params
28
- * @return {?}
29
- */
30
- getToken(params) {
31
- const { user, password, expirationDays, host } = params;
32
- return fetch(`${host || ''}/api/v1/authentication/api-token`, {
33
- method: 'POST',
34
- headers: {
35
- 'Content-Type': 'application/json'
36
- },
37
- body: JSON.stringify({
38
- user: user,
39
- password: password,
40
- expirationDays: expirationDays || 10
41
- })
42
- }).then((res) => __awaiter(this, void 0, void 0, function* () {
43
- /** @type {?} */
44
- const data = yield res.json();
45
- if (res.status === 200) {
46
- return data.entity.token;
47
- }
48
- throw /** @type {?} */ ({
49
- message: getErrorMessage(data),
50
- statusCode: res.status
51
- });
52
- }));
53
- }
54
- }
55
-
56
- /**
57
- * @fileoverview added by tsickle
58
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
59
- */
60
- /**
61
- * Get the information of DotCMS configuration
62
- *
63
- */
64
- class DotApiConfiguration {
65
- /**
66
- * @param {?} httpClient
67
- */
68
- constructor(httpClient) {
69
- this.dotCMSHttpClient = httpClient;
70
- }
71
- /**
72
- * @return {?}
73
- */
74
- get() {
75
- return this.dotCMSHttpClient
76
- .request({
77
- url: '/api/v1/configuration'
78
- })
79
- .then((response) => __awaiter(this, void 0, void 0, function* () {
80
- if (response.status === 200) {
81
- /** @type {?} */
82
- const data = yield response.json();
83
- return data.entity;
84
- }
85
- throw /** @type {?} */ ({
86
- message: yield response.text(),
87
- statusCode: response.status
88
- });
89
- }));
90
- }
91
- }
92
-
93
- /**
94
- * @fileoverview added by tsickle
95
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
96
- */
97
- /**
98
- * @param {?} params
99
- * @return {?}
100
- */
101
- function getEsQuery(params) {
102
- const { contentType, queryParams: { languageId, sortResultsBy, sortOrder1, offset, pagination, itemsPerPage, numberOfResults, detailedSearchQuery } } = params;
103
- /** @type {?} */
104
- const paginationQuery = `,
105
- "from": OFFSETVALUE,
106
- "size": SIZEPERPAGE`;
107
- /** @type {?} */
108
- let query = `{
109
- "query": {
110
- "bool": {
111
- "must": {
112
- "query_string" : {
113
- "query" : "+contentType:CONTENTTYPE +languageId:LANGUAGEIDVALUE ${detailedSearchQuery ||
114
- ''}"
115
- }
116
- }
117
- }
118
- },
119
- "sort" : [
120
- { "SORTBYVALUE" : {"order" : "SORTTYPEVALUE"}}
121
- ]
122
- ${pagination || numberOfResults ? paginationQuery : ''}
123
- }`;
124
- /** @type {?} */
125
- const esParams = {
126
- CONTENTTYPE: contentType,
127
- LANGUAGEIDVALUE: languageId || '1',
128
- SORTBYVALUE: sortResultsBy || 'title_dotraw',
129
- SORTTYPEVALUE: sortOrder1 || 'asc',
130
- OFFSETVALUE: offset || '0',
131
- SIZEPERPAGE: pagination ? itemsPerPage || 20 : numberOfResults || 40
132
- };
133
- Object.keys(esParams).forEach((key) => {
134
- query = query.replace(key, esParams[key]);
135
- });
136
- return query;
137
- }
138
-
139
- /**
140
- * @fileoverview added by tsickle
141
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
142
- */
143
- /**
144
- * Request content from DotCMS using the {\@link https://dotcms.com/docs/latest/elasticsearch-rest-api | Elastic Search API}
145
- *
146
- */
147
- class DotApiElasticSearch {
148
- /**
149
- * @param {?} httpClient
150
- */
151
- constructor(httpClient) {
152
- this.dotCMSHttpClient = httpClient;
153
- }
154
- /**
155
- * Provide the content type and the elastic search query and get the results contentlets and elastic search information
156
- *
157
- * @param {?} params
158
- * @return {?}
159
- */
160
- search(params) {
161
- return this.dotCMSHttpClient
162
- .request({
163
- url: '/api/es/search',
164
- method: 'POST',
165
- body: getEsQuery(params)
166
- })
167
- .then((response) => __awaiter(this, void 0, void 0, function* () {
168
- if (response.status === 200) {
169
- return response.json();
170
- }
171
- throw /** @type {?} */ ({
172
- message: yield response.text(),
173
- statusCode: response.status
174
- });
175
- }));
176
- }
177
- }
178
-
179
- /**
180
- * @fileoverview added by tsickle
181
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
182
- */
183
- /**
184
- * Emit custom events for the DotCMS Edit Mode
185
- *
186
- */
187
- class DotApiEvent {
188
- /**
189
- * @param {?} params
190
- * @return {?}
191
- */
192
- emit(params) {
193
- const { name, data } = params;
194
- /** @type {?} */
195
- const customEvent = window.top.document.createEvent('CustomEvent');
196
- customEvent.initCustomEvent('ng-event', false, false, {
197
- name: name,
198
- data: data
199
- });
200
- window.top.document.dispatchEvent(customEvent);
201
- }
202
- }
203
-
204
- /**
205
- * @fileoverview added by tsickle
206
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
207
- */
208
- /**
209
- * Get DotCMS {\@link https://dotcms.com/docs/latest/adding-and-editing-languages | Language code}
210
- *
211
- */
212
- class DotApiLanguage {
213
- /**
214
- * @param {?} appConfig
215
- */
216
- constructor(appConfig) {
217
- this.dotAppConfig = appConfig;
218
- }
219
- /**
220
- * @param {?} langCode
221
- * @return {?}
222
- */
223
- getId(langCode) {
224
- return __awaiter(this, void 0, void 0, function* () {
225
- /** @type {?} */
226
- const languages = yield this.getLanguages();
227
- /** @type {?} */
228
- const language = languages.find((lang) => lang.languageCode === langCode);
229
- return language ? `${language.id}` : null;
230
- });
231
- }
232
- /**
233
- * @return {?}
234
- */
235
- getLanguages() {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- if (this._languagesConf) {
238
- return this._languagesConf;
239
- }
240
- this._languagesConf = yield this.dotAppConfig
241
- .get()
242
- .then((data) => data.languages);
243
- return this._languagesConf;
244
- });
245
- }
246
- }
247
-
248
- /**
249
- * @fileoverview added by tsickle
250
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
251
- */
252
- /**
253
- * Retrieve information about the dotCMS file and folder tree with the {\@link https://dotcms.com/docs/latest/navigation-rest-api | Navigation REST API }
254
- *
255
- */
256
- class DotApiNavigation {
257
- /**
258
- * @param {?} httpClient
259
- */
260
- constructor(httpClient) {
261
- this.dotCMSHttpClient = httpClient;
262
- }
263
- /**
264
- * @param {?=} deep
265
- * @param {?=} location
266
- * @return {?}
267
- */
268
- get(deep = '2', location = '/') {
269
- return this.dotCMSHttpClient
270
- .request({
271
- url: `/api/v1/nav/${location}?depth=${deep}`
272
- })
273
- .then((res) => __awaiter(this, void 0, void 0, function* () {
274
- if (res.status === 200) {
275
- /** @type {?} */
276
- const data = yield res.json();
277
- return /** @type {?} */ (data.entity);
278
- }
279
- throw /** @type {?} */ ({
280
- message: yield res.text(),
281
- statusCode: res.status
282
- });
283
- }));
284
- }
285
- }
286
-
287
- /**
288
- * @fileoverview added by tsickle
289
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
290
- */
291
- /**
292
- * Allow easy interaction with {\@link https://dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas | DotCMS Page API}
293
- *
294
- */
295
- class DotApiPage {
296
- /**
297
- * @param {?} httpClient
298
- * @param {?} appLanguage
299
- */
300
- constructor(httpClient, appLanguage) {
301
- this.dotCMSHttpClient = httpClient;
302
- this.dotAppLanguage = appLanguage;
303
- }
304
- /**
305
- * Given the page url and the language return a {\@link DotCMSPageAsset}
306
- *
307
- * @param {?} params
308
- * @param {?=} format
309
- * @return {?}
310
- */
311
- get(params, format = "json" /* JSON */) {
312
- return __awaiter(this, void 0, void 0, function* () {
313
- if (params.language) {
314
- params = Object.assign({}, params, { language: isNaN(/** @type {?} */ (params.language))
315
- ? yield this.dotAppLanguage.getId(params.language)
316
- : params.language });
317
- }
318
- params = Object.assign({}, params, { url: `/api/v1/page/${format}${params.url}` });
319
- return this.dotCMSHttpClient.request(params).then((res) => __awaiter(this, void 0, void 0, function* () {
320
- if (res.status === 200) {
321
- /** @type {?} */
322
- const data = yield res.json();
323
- return /** @type {?} */ (data.entity);
324
- }
325
- /** @type {?} */
326
- const response = yield res.text();
327
- /** @type {?} */
328
- let error;
329
- try {
330
- error = {
331
- statusCode: res.status,
332
- message: JSON.parse(response).message
333
- };
334
- }
335
- catch (_a) {
336
- error = {
337
- statusCode: res.status,
338
- message: response
339
- };
340
- }
341
- throw error;
342
- }));
343
- });
344
- }
345
- }
346
-
347
- /**
348
- * @fileoverview added by tsickle
349
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
350
- */
351
- /**
352
- * Get information from {\@link https://dotcms.com/docs/latest/multi-site-management | DotCMS Sites}
353
- */
354
- class DotApiSite {
355
- /**
356
- * @param {?} httpClient
357
- */
358
- constructor(httpClient) {
359
- this.dotCMSHttpClient = httpClient;
360
- }
361
- /**
362
- * @return {?}
363
- */
364
- getCurrentSite() {
365
- return this.dotCMSHttpClient
366
- .request({
367
- url: `/api/v1/site/currentSite`
368
- })
369
- .then((response) => __awaiter(this, void 0, void 0, function* () {
370
- if (response.status === 200) {
371
- /** @type {?} */
372
- const data = yield response.json();
373
- const _a = data.entity, site = __rest(_a, ["map"]);
374
- return /** @type {?} */ (site);
375
- }
376
- throw /** @type {?} */ ({
377
- message: yield response.text(),
378
- statusCode: response.status
379
- });
380
- }));
381
- }
382
- }
383
-
384
- /**
385
- * @fileoverview added by tsickle
386
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
387
- */
388
- /**
389
- * DotCMS {\@link https://dotcms.com/docs/latest/widgets | widgets handler}
390
- */
391
- class DotApiWidget {
392
- /**
393
- * @param {?} httpClient
394
- */
395
- constructor(httpClient) {
396
- this.dotCMSHttpClient = httpClient;
397
- }
398
- /**
399
- * Get the widght HTML strong with it identifier
400
- *
401
- * @param {?} widgetId
402
- * @return {?}
403
- */
404
- getHtml(widgetId) {
405
- return this.dotCMSHttpClient
406
- .request({
407
- url: `/api/widget/id/${widgetId}`
408
- })
409
- .then((response) => __awaiter(this, void 0, void 0, function* () {
410
- if (response.status === 200) {
411
- return response.text();
412
- }
413
- throw /** @type {?} */ ({
414
- message: yield response.text(),
415
- statusCode: response.status
416
- });
417
- }));
418
- }
419
- }
420
-
421
- /**
422
- * @fileoverview added by tsickle
423
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
424
- */
425
- /**
426
- * @param {?} language
427
- * @param {?} hostId
428
- * @return {?}
429
- */
430
- function getQueryParams(language, hostId) {
431
- /** @type {?} */
432
- let result = language || hostId ? '?' : '';
433
- if (language) {
434
- result += `language_id=${language}`;
435
- if (hostId) {
436
- result += '&';
437
- }
438
- }
439
- if (hostId) {
440
- result += `host_id=${hostId}`;
441
- }
442
- return result;
443
- }
444
- /**
445
- * @param {?} params
446
- * @param {?} config
447
- * @return {?}
448
- */
449
- function getUrl(params, config) {
450
- return __awaiter(this, void 0, void 0, function* () {
451
- /** @type {?} */
452
- const host = config.host || '';
453
- return `${host}${params.url}${getQueryParams(params.language, config.hostId)}`;
454
- });
455
- }
456
- /**
457
- * @param {?} params
458
- * @return {?}
459
- */
460
- function shouldAppendBody(params) {
461
- return params.method === 'POST' && !!params.body;
462
- }
463
- /**
464
- * @param {?} params
465
- * @param {?} config
466
- * @return {?}
467
- */
468
- function getOpts(params, config) {
469
- /** @type {?} */
470
- let opts = {
471
- method: params.method || 'GET',
472
- headers: {
473
- Authorization: `Bearer ${config.token}`,
474
- 'Content-type': 'application/json'
475
- }
476
- };
477
- if (shouldAppendBody(params)) {
478
- opts = Object.assign({}, opts, { body: params.body });
479
- }
480
- return opts;
481
- }
482
- /**
483
- * @param {?} params
484
- * @param {?} config
485
- * @return {?}
486
- */
487
- function request(params, config) {
488
- return __awaiter(this, void 0, void 0, function* () {
489
- /** @type {?} */
490
- const url = yield getUrl(params, config);
491
- /** @type {?} */
492
- const opts = getOpts(params, config);
493
- return fetch(url, opts);
494
- });
495
- }
496
-
497
- /**
498
- * @fileoverview added by tsickle
499
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
500
- */
501
- class DotCMSHttpClient {
502
- /**
503
- * @param {?} config
504
- */
505
- constructor(config) {
506
- this._config = config;
507
- }
508
- /**
509
- * @param {?} params
510
- * @return {?}
511
- */
512
- request(params) {
513
- return request(params, this._config);
514
- }
515
- }
516
-
517
- /**
518
- * @fileoverview added by tsickle
519
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
520
- */
521
- /**
522
- * @param {?} params
523
- * @return {?}
524
- */
525
- function populateQueryUrl(params) {
526
- /** @type {?} */
527
- let url = '';
528
- /** @type {?} */
529
- const attrs = {
530
- depth: `/depth/${params.options.depth}`,
531
- limit: `/limit/${params.options.limit}`,
532
- offset: `/offset/${params.options.offset}`,
533
- orderBy: `/orderby/${params.options.orderBy}`
534
- };
535
- if (params.queryParams) {
536
- for (const key of Object.keys(params.queryParams)) {
537
- url += `+${key}:${params.queryParams[key]}%20`;
538
- }
539
- }
540
- for (const key of Object.keys(params.options)) {
541
- url += attrs[key];
542
- }
543
- return url;
544
- }
545
- /**
546
- * Query/Save/Publish the information of DotCMS Content
547
- *
548
- */
549
- class DotApiContent {
550
- /**
551
- * @param {?} httpClient
552
- */
553
- constructor(httpClient) {
554
- this.dotCMSHttpClient = httpClient;
555
- }
556
- /**
557
- * @param {?} params
558
- * @return {?}
559
- */
560
- query(params) {
561
- /** @type {?} */
562
- const url = `/api/content/query/+contentType:${params.contentType}%20${populateQueryUrl(params)}`;
563
- return this.doRequest(url, null, 'GET');
564
- }
565
- /**
566
- * @template Content
567
- * @param {?} params
568
- * @return {?}
569
- */
570
- save(params) {
571
- return this.doRequest('/api/content/save/1', params);
572
- }
573
- /**
574
- * @template Content
575
- * @param {?} params
576
- * @return {?}
577
- */
578
- publish(params) {
579
- return this.doRequest('/api/content/publish/1', params);
580
- }
581
- /**
582
- * @template Content
583
- * @param {?} url
584
- * @param {?=} params
585
- * @param {?=} httpMethod
586
- * @return {?}
587
- */
588
- doRequest(url, params, httpMethod = 'POST') {
589
- return __awaiter(this, void 0, void 0, function* () {
590
- /** @type {?} */
591
- const response = yield this.dotCMSHttpClient.request({
592
- url,
593
- method: httpMethod,
594
- body: params ? JSON.stringify(params) : ''
595
- });
596
- if (response.status !== 200) {
597
- throw /** @type {?} */ ({
598
- message: yield response.text(),
599
- statusCode: response.status
600
- });
601
- }
602
- return response;
603
- });
604
- }
605
- }
606
-
607
- /**
608
- * @fileoverview added by tsickle
609
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
610
- */
611
- /**
612
- * Get the information of DotCMS contentTypes
613
- *
614
- */
615
- class DotApiContentType {
616
- /**
617
- * @param {?} httpClient
618
- */
619
- constructor(httpClient) {
620
- this.dotCMSHttpClient = httpClient;
621
- }
622
- /**
623
- * @param {?} contentTypeId
624
- * @return {?}
625
- */
626
- get(contentTypeId) {
627
- return __awaiter(this, void 0, void 0, function* () {
628
- /** @type {?} */
629
- const response = yield this.dotCMSHttpClient.request({
630
- url: `/api/v1/contenttype/id/${contentTypeId}`
631
- });
632
- if (response.status !== 200) {
633
- throw /** @type {?} */ ({
634
- message: yield response.text(),
635
- statusCode: response.status
636
- });
637
- }
638
- /** @type {?} */
639
- const data = yield response.json();
640
- return data.entity;
641
- });
642
- }
643
- /**
644
- * @param {?} contentTypeId
645
- * @return {?}
646
- */
647
- getLayout(contentTypeId) {
648
- return this.get(contentTypeId).then((contentType) => {
649
- return contentType.layout;
650
- });
651
- }
652
- }
653
-
654
- /**
655
- * @fileoverview added by tsickle
656
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
657
- */
658
- /**
659
- * Creates and provide methods to render a DotCMS Form
660
- *
661
- */
662
- class DotApiForm {
663
- /**
664
- * @param {?} dotApiContentType
665
- * @param {?} formConfig
666
- */
667
- constructor(dotApiContentType, formConfig) {
668
- this.dotApiContentType = dotApiContentType;
669
- this.formConfig = formConfig;
670
- }
671
- /**
672
- * Render form on provided html element
673
- * \@memberof DotApiForm
674
- * @return {?}
675
- */
676
- get() {
677
- return __awaiter(this, void 0, void 0, function* () {
678
- return this.dotApiContentType.get(this.formConfig.identifier);
679
- });
680
- }
681
- }
682
-
683
- /**
684
- * @fileoverview added by tsickle
685
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
686
- */
687
- /** @type {?} */
688
- const initDotCMS = (config) => {
689
- /** @type {?} */
690
- const httpClient = new DotCMSHttpClient(config);
691
- /** @type {?} */
692
- const apiConfig = new DotApiConfiguration(httpClient);
693
- /** @type {?} */
694
- const apiLanguage = new DotApiLanguage(apiConfig);
695
- /** @type {?} */
696
- const content = new DotApiContent(httpClient);
697
- /** @type {?} */
698
- const dotApiContentType = new DotApiContentType(httpClient);
699
- return {
700
- auth: new DotApiAuthorization(),
701
- config: apiConfig,
702
- content: content,
703
- contentType: new DotApiContentType(httpClient),
704
- esSearch: new DotApiElasticSearch(httpClient),
705
- event: new DotApiEvent(),
706
- form: (formConfig) => new DotApiForm(dotApiContentType, formConfig),
707
- language: apiLanguage,
708
- nav: new DotApiNavigation(httpClient),
709
- page: new DotApiPage(httpClient, apiLanguage),
710
- site: new DotApiSite(httpClient),
711
- widget: new DotApiWidget(httpClient),
712
- httpClient
713
- };
714
- };
715
-
716
- /**
717
- * @fileoverview added by tsickle
718
- * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
719
- */
720
-
721
- export { initDotCMS };
722
-
723
- //# sourceMappingURL=dotcms.js.map