dotcms 0.0.18 → 0.0.20

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 (131) hide show
  1. package/README.md +9 -9
  2. package/package.json +7 -11
  3. package/{index.d.ts → src/index.d.ts} +0 -0
  4. package/src/index.js +40 -0
  5. package/src/index.js.map +1 -0
  6. package/{lib → src/lib}/api/DotApiAuthorization.d.ts +0 -1
  7. package/src/lib/api/DotApiAuthorization.js +46 -0
  8. package/src/lib/api/DotApiAuthorization.js.map +1 -0
  9. package/{lib → src/lib}/api/DotApiConfiguration.d.ts +0 -0
  10. package/src/lib/api/DotApiConfiguration.js +32 -0
  11. package/src/lib/api/DotApiConfiguration.js.map +1 -0
  12. package/{lib → src/lib}/api/DotApiContent.d.ts +0 -0
  13. package/src/lib/api/DotApiContent.js +59 -0
  14. package/src/lib/api/DotApiContent.js.map +1 -0
  15. package/{lib → src/lib}/api/DotApiContentType.d.ts +1 -1
  16. package/src/lib/api/DotApiContentType.js +35 -0
  17. package/src/lib/api/DotApiContentType.js.map +1 -0
  18. package/{lib → src/lib}/api/DotApiElasticSearch.d.ts +0 -0
  19. package/src/lib/api/DotApiElasticSearch.js +37 -0
  20. package/src/lib/api/DotApiElasticSearch.js.map +1 -0
  21. package/{lib → src/lib}/api/DotApiEvent.d.ts +0 -0
  22. package/src/lib/api/DotApiEvent.js +20 -0
  23. package/src/lib/api/DotApiEvent.js.map +1 -0
  24. package/{lib → src/lib}/api/DotApiForm.d.ts +1 -1
  25. package/src/lib/api/DotApiForm.js +25 -0
  26. package/src/lib/api/DotApiForm.js.map +1 -0
  27. package/{lib → src/lib}/api/DotApiLanguage.d.ts +0 -0
  28. package/src/lib/api/DotApiLanguage.js +33 -0
  29. package/src/lib/api/DotApiLanguage.js.map +1 -0
  30. package/{lib → src/lib}/api/DotApiNavigation.d.ts +1 -1
  31. package/src/lib/api/DotApiNavigation.js +34 -0
  32. package/src/lib/api/DotApiNavigation.js.map +1 -0
  33. package/{lib → src/lib}/api/DotApiPage.d.ts +1 -1
  34. package/src/lib/api/DotApiPage.js +51 -0
  35. package/src/lib/api/DotApiPage.js.map +1 -0
  36. package/{lib → src/lib}/api/DotApiSite.d.ts +0 -0
  37. package/src/lib/api/DotApiSite.js +31 -0
  38. package/src/lib/api/DotApiSite.js.map +1 -0
  39. package/{lib → src/lib}/api/DotApiWidget.d.ts +0 -0
  40. package/src/lib/api/DotApiWidget.js +33 -0
  41. package/src/lib/api/DotApiWidget.js.map +1 -0
  42. package/{lib → src/lib}/models/DotCMSAuthorization.model.d.ts +0 -0
  43. package/src/lib/models/DotCMSAuthorization.model.js +3 -0
  44. package/src/lib/models/DotCMSAuthorization.model.js.map +1 -0
  45. package/{lib → src/lib}/models/DotCMSConfiguration.model.d.ts +1 -1
  46. package/src/lib/models/DotCMSConfiguration.model.js +3 -0
  47. package/src/lib/models/DotCMSConfiguration.model.js.map +1 -0
  48. package/{lib → src/lib}/models/DotCMSContent.model.d.ts +0 -0
  49. package/src/lib/models/DotCMSContent.model.js +3 -0
  50. package/src/lib/models/DotCMSContent.model.js.map +1 -0
  51. package/{lib → src/lib}/models/DotCMSElasticSearch.model.d.ts +0 -0
  52. package/src/lib/models/DotCMSElasticSearch.model.js +3 -0
  53. package/src/lib/models/DotCMSElasticSearch.model.js.map +1 -0
  54. package/{lib → src/lib}/models/DotCMSError.model.d.ts +0 -0
  55. package/src/lib/models/DotCMSError.model.js +3 -0
  56. package/src/lib/models/DotCMSError.model.js.map +1 -0
  57. package/{lib → src/lib}/models/DotCMSEvent.model.d.ts +0 -0
  58. package/src/lib/models/DotCMSEvent.model.js +3 -0
  59. package/src/lib/models/DotCMSEvent.model.js.map +1 -0
  60. package/{lib → src/lib}/models/DotCMSForm.model.d.ts +0 -0
  61. package/src/lib/models/DotCMSForm.model.js +3 -0
  62. package/src/lib/models/DotCMSForm.model.js.map +1 -0
  63. package/{lib → src/lib}/models/DotCMSHttpClient.model.d.ts +0 -0
  64. package/src/lib/models/DotCMSHttpClient.model.js +3 -0
  65. package/src/lib/models/DotCMSHttpClient.model.js.map +1 -0
  66. package/{lib → src/lib}/models/DotCMSLanguage.model.d.ts +0 -0
  67. package/src/lib/models/DotCMSLanguage.model.js +3 -0
  68. package/src/lib/models/DotCMSLanguage.model.js.map +1 -0
  69. package/{lib → src/lib}/models/DotCMSNavigation.model.d.ts +0 -0
  70. package/src/lib/models/DotCMSNavigation.model.js +3 -0
  71. package/src/lib/models/DotCMSNavigation.model.js.map +1 -0
  72. package/{lib → src/lib}/models/DotCMSPage.model.d.ts +0 -0
  73. package/src/lib/models/DotCMSPage.model.js +3 -0
  74. package/src/lib/models/DotCMSPage.model.js.map +1 -0
  75. package/{lib → src/lib}/models/DotCMSPageFormat.model.d.ts +0 -0
  76. package/src/lib/models/DotCMSPageFormat.model.js +3 -0
  77. package/src/lib/models/DotCMSPageFormat.model.js.map +1 -0
  78. package/{lib → src/lib}/models/DotCMSSite.model.d.ts +0 -0
  79. package/src/lib/models/DotCMSSite.model.js +3 -0
  80. package/src/lib/models/DotCMSSite.model.js.map +1 -0
  81. package/{lib → src/lib}/models/index.d.ts +0 -0
  82. package/src/lib/models/index.js +17 -0
  83. package/src/lib/models/index.js.map +1 -0
  84. package/{lib → src/lib}/utils/DotCMSHttpClient.d.ts +0 -0
  85. package/src/lib/utils/DotCMSHttpClient.js +14 -0
  86. package/src/lib/utils/DotCMSHttpClient.js.map +1 -0
  87. package/{lib → src/lib}/utils/getEsQuery.d.ts +0 -0
  88. package/src/lib/utils/getEsQuery.js +39 -0
  89. package/src/lib/utils/getEsQuery.js.map +1 -0
  90. package/{lib → src/lib}/utils/request.d.ts +1 -1
  91. package/src/lib/utils/request.js +47 -0
  92. package/src/lib/utils/request.js.map +1 -0
  93. package/bundles/dotcms.umd.js +0 -966
  94. package/bundles/dotcms.umd.js.map +0 -1
  95. package/bundles/dotcms.umd.min.js +0 -16
  96. package/bundles/dotcms.umd.min.js.map +0 -1
  97. package/dotcms.d.ts +0 -4
  98. package/dotcms.metadata.json +0 -1
  99. package/esm2015/dotcms.js +0 -5
  100. package/esm2015/index.js +0 -36
  101. package/esm2015/lib/api/DotApiAuthorization.js +0 -43
  102. package/esm2015/lib/api/DotApiConfiguration.js +0 -28
  103. package/esm2015/lib/api/DotApiContent.js +0 -55
  104. package/esm2015/lib/api/DotApiContentType.js +0 -31
  105. package/esm2015/lib/api/DotApiElasticSearch.js +0 -33
  106. package/esm2015/lib/api/DotApiEvent.js +0 -16
  107. package/esm2015/lib/api/DotApiForm.js +0 -21
  108. package/esm2015/lib/api/DotApiLanguage.js +0 -29
  109. package/esm2015/lib/api/DotApiNavigation.js +0 -30
  110. package/esm2015/lib/api/DotApiPage.js +0 -47
  111. package/esm2015/lib/api/DotApiSite.js +0 -27
  112. package/esm2015/lib/api/DotApiWidget.js +0 -29
  113. package/esm2015/lib/models/DotCMSAuthorization.model.js +0 -2
  114. package/esm2015/lib/models/DotCMSConfiguration.model.js +0 -2
  115. package/esm2015/lib/models/DotCMSContent.model.js +0 -2
  116. package/esm2015/lib/models/DotCMSElasticSearch.model.js +0 -2
  117. package/esm2015/lib/models/DotCMSError.model.js +0 -2
  118. package/esm2015/lib/models/DotCMSEvent.model.js +0 -2
  119. package/esm2015/lib/models/DotCMSForm.model.js +0 -2
  120. package/esm2015/lib/models/DotCMSHttpClient.model.js +0 -2
  121. package/esm2015/lib/models/DotCMSLanguage.model.js +0 -2
  122. package/esm2015/lib/models/DotCMSNavigation.model.js +0 -2
  123. package/esm2015/lib/models/DotCMSPage.model.js +0 -2
  124. package/esm2015/lib/models/DotCMSPageFormat.model.js +0 -2
  125. package/esm2015/lib/models/DotCMSSite.model.js +0 -2
  126. package/esm2015/lib/models/index.js +0 -14
  127. package/esm2015/lib/utils/DotCMSHttpClient.js +0 -10
  128. package/esm2015/lib/utils/getEsQuery.js +0 -35
  129. package/esm2015/lib/utils/request.js +0 -44
  130. package/fesm2015/dotcms.js +0 -494
  131. package/fesm2015/dotcms.js.map +0 -1
@@ -1,966 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('cross-fetch')) :
3
- typeof define === 'function' && define.amd ? define('dotcms', ['exports', 'cross-fetch'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.dotcms = {}, global.fetch));
5
- }(this, (function (exports, fetch) { 'use strict';
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
10
-
11
- /*! *****************************************************************************
12
- Copyright (c) Microsoft Corporation.
13
-
14
- Permission to use, copy, modify, and/or distribute this software for any
15
- purpose with or without fee is hereby granted.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
- PERFORMANCE OF THIS SOFTWARE.
24
- ***************************************************************************** */
25
- /* global Reflect, Promise */
26
- var extendStatics = function (d, b) {
27
- extendStatics = Object.setPrototypeOf ||
28
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29
- function (d, b) { for (var p in b)
30
- if (Object.prototype.hasOwnProperty.call(b, p))
31
- d[p] = b[p]; };
32
- return extendStatics(d, b);
33
- };
34
- function __extends(d, b) {
35
- if (typeof b !== "function" && b !== null)
36
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
37
- extendStatics(d, b);
38
- function __() { this.constructor = d; }
39
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
40
- }
41
- var __assign = function () {
42
- __assign = Object.assign || function __assign(t) {
43
- for (var s, i = 1, n = arguments.length; i < n; i++) {
44
- s = arguments[i];
45
- for (var p in s)
46
- if (Object.prototype.hasOwnProperty.call(s, p))
47
- t[p] = s[p];
48
- }
49
- return t;
50
- };
51
- return __assign.apply(this, arguments);
52
- };
53
- function __rest(s, e) {
54
- var t = {};
55
- for (var p in s)
56
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
57
- t[p] = s[p];
58
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
59
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
60
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
61
- t[p[i]] = s[p[i]];
62
- }
63
- return t;
64
- }
65
- function __decorate(decorators, target, key, desc) {
66
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
67
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
68
- r = Reflect.decorate(decorators, target, key, desc);
69
- else
70
- for (var i = decorators.length - 1; i >= 0; i--)
71
- if (d = decorators[i])
72
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
73
- return c > 3 && r && Object.defineProperty(target, key, r), r;
74
- }
75
- function __param(paramIndex, decorator) {
76
- return function (target, key) { decorator(target, key, paramIndex); };
77
- }
78
- function __metadata(metadataKey, metadataValue) {
79
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
80
- return Reflect.metadata(metadataKey, metadataValue);
81
- }
82
- function __awaiter(thisArg, _arguments, P, generator) {
83
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
84
- return new (P || (P = Promise))(function (resolve, reject) {
85
- function fulfilled(value) { try {
86
- step(generator.next(value));
87
- }
88
- catch (e) {
89
- reject(e);
90
- } }
91
- function rejected(value) { try {
92
- step(generator["throw"](value));
93
- }
94
- catch (e) {
95
- reject(e);
96
- } }
97
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
98
- step((generator = generator.apply(thisArg, _arguments || [])).next());
99
- });
100
- }
101
- function __generator(thisArg, body) {
102
- var _ = { label: 0, sent: function () { if (t[0] & 1)
103
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
104
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
105
- function verb(n) { return function (v) { return step([n, v]); }; }
106
- function step(op) {
107
- if (f)
108
- throw new TypeError("Generator is already executing.");
109
- while (_)
110
- try {
111
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
112
- return t;
113
- if (y = 0, t)
114
- op = [op[0] & 2, t.value];
115
- switch (op[0]) {
116
- case 0:
117
- case 1:
118
- t = op;
119
- break;
120
- case 4:
121
- _.label++;
122
- return { value: op[1], done: false };
123
- case 5:
124
- _.label++;
125
- y = op[1];
126
- op = [0];
127
- continue;
128
- case 7:
129
- op = _.ops.pop();
130
- _.trys.pop();
131
- continue;
132
- default:
133
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
134
- _ = 0;
135
- continue;
136
- }
137
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
138
- _.label = op[1];
139
- break;
140
- }
141
- if (op[0] === 6 && _.label < t[1]) {
142
- _.label = t[1];
143
- t = op;
144
- break;
145
- }
146
- if (t && _.label < t[2]) {
147
- _.label = t[2];
148
- _.ops.push(op);
149
- break;
150
- }
151
- if (t[2])
152
- _.ops.pop();
153
- _.trys.pop();
154
- continue;
155
- }
156
- op = body.call(thisArg, _);
157
- }
158
- catch (e) {
159
- op = [6, e];
160
- y = 0;
161
- }
162
- finally {
163
- f = t = 0;
164
- }
165
- if (op[0] & 5)
166
- throw op[1];
167
- return { value: op[0] ? op[1] : void 0, done: true };
168
- }
169
- }
170
- var __createBinding = Object.create ? (function (o, m, k, k2) {
171
- if (k2 === undefined)
172
- k2 = k;
173
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
174
- }) : (function (o, m, k, k2) {
175
- if (k2 === undefined)
176
- k2 = k;
177
- o[k2] = m[k];
178
- });
179
- function __exportStar(m, o) {
180
- for (var p in m)
181
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
182
- __createBinding(o, m, p);
183
- }
184
- function __values(o) {
185
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
186
- if (m)
187
- return m.call(o);
188
- if (o && typeof o.length === "number")
189
- return {
190
- next: function () {
191
- if (o && i >= o.length)
192
- o = void 0;
193
- return { value: o && o[i++], done: !o };
194
- }
195
- };
196
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
197
- }
198
- function __read(o, n) {
199
- var m = typeof Symbol === "function" && o[Symbol.iterator];
200
- if (!m)
201
- return o;
202
- var i = m.call(o), r, ar = [], e;
203
- try {
204
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
205
- ar.push(r.value);
206
- }
207
- catch (error) {
208
- e = { error: error };
209
- }
210
- finally {
211
- try {
212
- if (r && !r.done && (m = i["return"]))
213
- m.call(i);
214
- }
215
- finally {
216
- if (e)
217
- throw e.error;
218
- }
219
- }
220
- return ar;
221
- }
222
- /** @deprecated */
223
- function __spread() {
224
- for (var ar = [], i = 0; i < arguments.length; i++)
225
- ar = ar.concat(__read(arguments[i]));
226
- return ar;
227
- }
228
- /** @deprecated */
229
- function __spreadArrays() {
230
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
231
- s += arguments[i].length;
232
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
233
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
234
- r[k] = a[j];
235
- return r;
236
- }
237
- function __spreadArray(to, from) {
238
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
239
- to[j] = from[i];
240
- return to;
241
- }
242
- function __await(v) {
243
- return this instanceof __await ? (this.v = v, this) : new __await(v);
244
- }
245
- function __asyncGenerator(thisArg, _arguments, generator) {
246
- if (!Symbol.asyncIterator)
247
- throw new TypeError("Symbol.asyncIterator is not defined.");
248
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
249
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
250
- function verb(n) { if (g[n])
251
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
252
- function resume(n, v) { try {
253
- step(g[n](v));
254
- }
255
- catch (e) {
256
- settle(q[0][3], e);
257
- } }
258
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
259
- function fulfill(value) { resume("next", value); }
260
- function reject(value) { resume("throw", value); }
261
- function settle(f, v) { if (f(v), q.shift(), q.length)
262
- resume(q[0][0], q[0][1]); }
263
- }
264
- function __asyncDelegator(o) {
265
- var i, p;
266
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
267
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
268
- }
269
- function __asyncValues(o) {
270
- if (!Symbol.asyncIterator)
271
- throw new TypeError("Symbol.asyncIterator is not defined.");
272
- var m = o[Symbol.asyncIterator], i;
273
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
274
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
275
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
276
- }
277
- function __makeTemplateObject(cooked, raw) {
278
- if (Object.defineProperty) {
279
- Object.defineProperty(cooked, "raw", { value: raw });
280
- }
281
- else {
282
- cooked.raw = raw;
283
- }
284
- return cooked;
285
- }
286
- ;
287
- var __setModuleDefault = Object.create ? (function (o, v) {
288
- Object.defineProperty(o, "default", { enumerable: true, value: v });
289
- }) : function (o, v) {
290
- o["default"] = v;
291
- };
292
- function __importStar(mod) {
293
- if (mod && mod.__esModule)
294
- return mod;
295
- var result = {};
296
- if (mod != null)
297
- for (var k in mod)
298
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
299
- __createBinding(result, mod, k);
300
- __setModuleDefault(result, mod);
301
- return result;
302
- }
303
- function __importDefault(mod) {
304
- return (mod && mod.__esModule) ? mod : { default: mod };
305
- }
306
- function __classPrivateFieldGet(receiver, privateMap) {
307
- if (!privateMap.has(receiver)) {
308
- throw new TypeError("attempted to get private field on non-instance");
309
- }
310
- return privateMap.get(receiver);
311
- }
312
- function __classPrivateFieldSet(receiver, privateMap, value) {
313
- if (!privateMap.has(receiver)) {
314
- throw new TypeError("attempted to set private field on non-instance");
315
- }
316
- privateMap.set(receiver, value);
317
- return value;
318
- }
319
-
320
- function getErrorMessage(data) {
321
- if (data.errors) {
322
- return data.errors[0].message;
323
- }
324
- if (data.error) {
325
- return data.error;
326
- }
327
- }
328
- /**
329
- * DotCMS Authentication handler to intereact with {@link https://dotcms.com/docs/latest/rest-api-authentication | Authentication API}
330
- *
331
- */
332
- var DotApiAuthorization = /** @class */ (function () {
333
- function DotApiAuthorization() {
334
- }
335
- /**
336
- * Given user, password and expiration date to get a DotCMS Autorization Token
337
- */
338
- DotApiAuthorization.prototype.getToken = function (params) {
339
- var _this = this;
340
- var user = params.user, password = params.password, expirationDays = params.expirationDays, host = params.host;
341
- return fetch__default['default']((host || '') + "/api/v1/authentication/api-token", {
342
- method: 'POST',
343
- headers: {
344
- 'Content-Type': 'application/json'
345
- },
346
- body: JSON.stringify({
347
- user: user,
348
- password: password,
349
- expirationDays: expirationDays || 10
350
- })
351
- }).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
352
- var data;
353
- return __generator(this, function (_a) {
354
- switch (_a.label) {
355
- case 0: return [4 /*yield*/, res.json()];
356
- case 1:
357
- data = _a.sent();
358
- if (res.status === 200) {
359
- return [2 /*return*/, data.entity.token];
360
- }
361
- throw {
362
- message: getErrorMessage(data),
363
- statusCode: res.status
364
- };
365
- }
366
- });
367
- }); });
368
- };
369
- return DotApiAuthorization;
370
- }());
371
-
372
- /**
373
- * Get the information of DotCMS configuration
374
- *
375
- */
376
- var DotApiConfiguration = /** @class */ (function () {
377
- function DotApiConfiguration(httpClient) {
378
- this.dotCMSHttpClient = httpClient;
379
- }
380
- // TODO: CATCH THIS ERROR
381
- DotApiConfiguration.prototype.get = function () {
382
- var _this = this;
383
- return this.dotCMSHttpClient
384
- .request({
385
- url: '/api/v1/configuration'
386
- })
387
- .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
388
- var data, _a;
389
- return __generator(this, function (_b) {
390
- switch (_b.label) {
391
- case 0:
392
- if (!(response.status === 200)) return [3 /*break*/, 2];
393
- return [4 /*yield*/, response.json()];
394
- case 1:
395
- data = _b.sent();
396
- return [2 /*return*/, data.entity];
397
- case 2:
398
- _a = {};
399
- return [4 /*yield*/, response.text()];
400
- case 3: throw _a.message = _b.sent(),
401
- _a.statusCode = response.status,
402
- _a;
403
- }
404
- });
405
- }); });
406
- };
407
- return DotApiConfiguration;
408
- }());
409
-
410
- // tslint:disable-next-line:cyclomatic-complexity
411
- function getEsQuery(params) {
412
- var contentType = params.contentType, _a = params.queryParams, languageId = _a.languageId, sortResultsBy = _a.sortResultsBy, sortOrder1 = _a.sortOrder1, offset = _a.offset, pagination = _a.pagination, itemsPerPage = _a.itemsPerPage, numberOfResults = _a.numberOfResults, detailedSearchQuery = _a.detailedSearchQuery;
413
- var paginationQuery = ",\n \"from\": OFFSETVALUE,\n \"size\": SIZEPERPAGE";
414
- var query = "{\n \"query\": {\n \"bool\": {\n \"must\": {\n \"query_string\" : {\n \"query\" : \"+contentType:CONTENTTYPE +languageId:LANGUAGEIDVALUE " + (detailedSearchQuery || '') + "\"\n }\n }\n }\n },\n \"sort\" : [\n { \"SORTBYVALUE\" : {\"order\" : \"SORTTYPEVALUE\"}}\n ]\n " + (pagination || numberOfResults ? paginationQuery : '') + "\n }";
415
- var esParams = {
416
- CONTENTTYPE: contentType,
417
- LANGUAGEIDVALUE: languageId || '1',
418
- SORTBYVALUE: sortResultsBy || 'title_dotraw',
419
- SORTTYPEVALUE: sortOrder1 || 'asc',
420
- OFFSETVALUE: offset || '0',
421
- SIZEPERPAGE: pagination ? itemsPerPage || 20 : numberOfResults || 40
422
- };
423
- Object.keys(esParams).forEach(function (key) {
424
- query = query.replace(key, esParams[key]);
425
- });
426
- return query;
427
- }
428
-
429
- /**
430
- * Request content from DotCMS using the {@link https://dotcms.com/docs/latest/elasticsearch-rest-api | Elastic Search API}
431
- *
432
- */
433
- var DotApiElasticSearch = /** @class */ (function () {
434
- function DotApiElasticSearch(httpClient) {
435
- this.dotCMSHttpClient = httpClient;
436
- }
437
- /**
438
- * Provide the content type and the elastic search query and get the results contentlets and elastic search information
439
- *
440
- */
441
- DotApiElasticSearch.prototype.search = function (params) {
442
- var _this = this;
443
- return this.dotCMSHttpClient
444
- .request({
445
- url: '/api/es/search',
446
- method: 'POST',
447
- body: getEsQuery(params)
448
- })
449
- .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
450
- var _a;
451
- return __generator(this, function (_b) {
452
- switch (_b.label) {
453
- case 0:
454
- if (response.status === 200) {
455
- return [2 /*return*/, response.json()];
456
- }
457
- _a = {};
458
- return [4 /*yield*/, response.text()];
459
- case 1: throw _a.message = _b.sent(),
460
- _a.statusCode = response.status,
461
- _a;
462
- }
463
- });
464
- }); });
465
- };
466
- return DotApiElasticSearch;
467
- }());
468
-
469
- /**
470
- * Emit custom events for the DotCMS Edit Mode
471
- *
472
- */
473
- var DotApiEvent = /** @class */ (function () {
474
- function DotApiEvent() {
475
- }
476
- DotApiEvent.prototype.emit = function (params) {
477
- var name = params.name, data = params.data;
478
- var customEvent = window.top.document.createEvent('CustomEvent');
479
- customEvent.initCustomEvent('ng-event', false, false, {
480
- name: name,
481
- data: data
482
- });
483
- window.top.document.dispatchEvent(customEvent);
484
- };
485
- return DotApiEvent;
486
- }());
487
-
488
- /**
489
- * Get DotCMS {@link https://dotcms.com/docs/latest/adding-and-editing-languages | Language code}
490
- *
491
- */
492
- var DotApiLanguage = /** @class */ (function () {
493
- function DotApiLanguage(appConfig) {
494
- this.dotAppConfig = appConfig;
495
- }
496
- DotApiLanguage.prototype.getId = function (langCode) {
497
- return __awaiter(this, void 0, void 0, function () {
498
- var languages, language;
499
- return __generator(this, function (_a) {
500
- switch (_a.label) {
501
- case 0: return [4 /*yield*/, this.getLanguages()];
502
- case 1:
503
- languages = _a.sent();
504
- language = languages.find(function (lang) { return lang.languageCode === langCode; });
505
- return [2 /*return*/, language ? "" + language.id : null];
506
- }
507
- });
508
- });
509
- };
510
- DotApiLanguage.prototype.getLanguages = function () {
511
- return __awaiter(this, void 0, void 0, function () {
512
- var _a;
513
- return __generator(this, function (_b) {
514
- switch (_b.label) {
515
- case 0:
516
- if (this._languagesConf) {
517
- return [2 /*return*/, this._languagesConf];
518
- }
519
- _a = this;
520
- return [4 /*yield*/, this.dotAppConfig
521
- .get()
522
- .then(function (data) { return data.languages; })];
523
- case 1:
524
- _a._languagesConf = _b.sent();
525
- return [2 /*return*/, this._languagesConf];
526
- }
527
- });
528
- });
529
- };
530
- return DotApiLanguage;
531
- }());
532
-
533
- /**
534
- * Retrieve information about the dotCMS file and folder tree with the {@link https://dotcms.com/docs/latest/navigation-rest-api | Navigation REST API }
535
- *
536
- */
537
- var DotApiNavigation = /** @class */ (function () {
538
- function DotApiNavigation(httpClient) {
539
- this.dotCMSHttpClient = httpClient;
540
- }
541
- DotApiNavigation.prototype.get = function (deep, location) {
542
- var _this = this;
543
- if (deep === void 0) { deep = '2'; }
544
- if (location === void 0) { location = '/'; }
545
- return this.dotCMSHttpClient
546
- .request({
547
- url: "/api/v1/nav/" + location,
548
- params: {
549
- deep: deep
550
- }
551
- })
552
- .then(function (res) { return __awaiter(_this, void 0, void 0, function () {
553
- var data, _a;
554
- return __generator(this, function (_b) {
555
- switch (_b.label) {
556
- case 0:
557
- if (!(res.status === 200)) return [3 /*break*/, 2];
558
- return [4 /*yield*/, res.json()];
559
- case 1:
560
- data = _b.sent();
561
- return [2 /*return*/, data.entity];
562
- case 2:
563
- _a = {};
564
- return [4 /*yield*/, res.text()];
565
- case 3: throw _a.message = _b.sent(),
566
- _a.statusCode = res.status,
567
- _a;
568
- }
569
- });
570
- }); });
571
- };
572
- return DotApiNavigation;
573
- }());
574
-
575
- /**
576
- * Allow easy interaction with {@link https://dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas | DotCMS Page API}
577
- *
578
- */
579
- var DotApiPage = /** @class */ (function () {
580
- function DotApiPage(httpClient, appLanguage) {
581
- this.dotCMSHttpClient = httpClient;
582
- this.dotAppLanguage = appLanguage;
583
- }
584
- /**
585
- * Given the page url and the language return a {@link DotCMSPageAsset}
586
- *
587
- */
588
- DotApiPage.prototype.get = function (params, format /* JSON */) {
589
- if (format === void 0) { format = "json"; }
590
- return __awaiter(this, void 0, void 0, function () {
591
- var _b, _c, _d, _e, _f;
592
- var _this = this;
593
- return __generator(this, function (_g) {
594
- switch (_g.label) {
595
- case 0:
596
- if (!params.language) return [3 /*break*/, 4];
597
- _c = (_b = Object).assign;
598
- _d = [Object.assign({}, params)];
599
- _e = {};
600
- if (!isNaN(params.language)) return [3 /*break*/, 2];
601
- return [4 /*yield*/, this.dotAppLanguage.getId(params.language)];
602
- case 1:
603
- _f = _g.sent();
604
- return [3 /*break*/, 3];
605
- case 2:
606
- _f = params.language;
607
- _g.label = 3;
608
- case 3:
609
- params = _c.apply(_b, _d.concat([(_e.language = _f, _e)]));
610
- _g.label = 4;
611
- case 4:
612
- params = Object.assign(Object.assign({}, params), { url: "/api/v1/page/" + format + params.url });
613
- return [2 /*return*/, this.dotCMSHttpClient.request(params).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
614
- var data, response, error;
615
- return __generator(this, function (_b) {
616
- switch (_b.label) {
617
- case 0:
618
- if (!(res.status === 200)) return [3 /*break*/, 2];
619
- return [4 /*yield*/, res.json()];
620
- case 1:
621
- data = _b.sent();
622
- return [2 /*return*/, data.entity];
623
- case 2: return [4 /*yield*/, res.text()];
624
- case 3:
625
- response = _b.sent();
626
- try {
627
- error = {
628
- statusCode: res.status,
629
- message: JSON.parse(response).message
630
- };
631
- }
632
- catch (_a) {
633
- error = {
634
- statusCode: res.status,
635
- message: response
636
- };
637
- }
638
- throw error;
639
- }
640
- });
641
- }); })];
642
- }
643
- });
644
- });
645
- };
646
- return DotApiPage;
647
- }());
648
-
649
- /**
650
- * Get information from {@link https://dotcms.com/docs/latest/multi-site-management | DotCMS Sites}
651
- */
652
- var DotApiSite = /** @class */ (function () {
653
- function DotApiSite(httpClient) {
654
- this.dotCMSHttpClient = httpClient;
655
- }
656
- DotApiSite.prototype.getCurrentSite = function () {
657
- var _this = this;
658
- return this.dotCMSHttpClient
659
- .request({
660
- url: "/api/v1/site/currentSite"
661
- })
662
- .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
663
- var data, _a, map, site, _b;
664
- return __generator(this, function (_c) {
665
- switch (_c.label) {
666
- case 0:
667
- if (!(response.status === 200)) return [3 /*break*/, 2];
668
- return [4 /*yield*/, response.json()];
669
- case 1:
670
- data = _c.sent();
671
- _a = data.entity, map = _a.map, site = __rest(_a, ["map"]);
672
- return [2 /*return*/, site];
673
- case 2:
674
- _b = {};
675
- return [4 /*yield*/, response.text()];
676
- case 3: throw _b.message = _c.sent(),
677
- _b.statusCode = response.status,
678
- _b;
679
- }
680
- });
681
- }); });
682
- };
683
- return DotApiSite;
684
- }());
685
-
686
- /**
687
- * DotCMS {@link https://dotcms.com/docs/latest/widgets | widgets handler}
688
- */
689
- var DotApiWidget = /** @class */ (function () {
690
- function DotApiWidget(httpClient) {
691
- this.dotCMSHttpClient = httpClient;
692
- }
693
- /**
694
- * Get the widght HTML strong with it identifier
695
- *
696
- */
697
- DotApiWidget.prototype.getHtml = function (widgetId) {
698
- var _this = this;
699
- return this.dotCMSHttpClient
700
- .request({
701
- url: "/api/widget/id/" + widgetId
702
- })
703
- .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
704
- var _a;
705
- return __generator(this, function (_b) {
706
- switch (_b.label) {
707
- case 0:
708
- if (response.status === 200) {
709
- return [2 /*return*/, response.text()];
710
- }
711
- _a = {};
712
- return [4 /*yield*/, response.text()];
713
- case 1: throw _a.message = _b.sent(),
714
- _a.statusCode = response.status,
715
- _a;
716
- }
717
- });
718
- }); });
719
- };
720
- return DotApiWidget;
721
- }());
722
-
723
- function getUrl(_a, _b) {
724
- var params = _a.params, url = _a.url;
725
- var host = _b.host, hostId = _b.hostId;
726
- return __awaiter(this, void 0, void 0, function () {
727
- var newUrl, paramsKeys;
728
- return __generator(this, function (_a) {
729
- if (!host) {
730
- throw new Error('Please pass the DotCMS instance in the initDotCMS initialization');
731
- }
732
- newUrl = new URL("" + host + url);
733
- paramsKeys = params ? Object.keys(params) : [];
734
- if (paramsKeys.length) {
735
- paramsKeys.map(function (key) {
736
- newUrl.searchParams.append(key, params[key]);
737
- });
738
- }
739
- if (hostId) {
740
- newUrl.searchParams.append('host_id', hostId);
741
- }
742
- return [2 /*return*/, "" + newUrl.toString()];
743
- });
744
- });
745
- }
746
- function shouldAppendBody(params) {
747
- return params.method === 'POST' && !!params.body;
748
- }
749
- function getOpts(params, config) {
750
- var opts = {
751
- method: params.method || 'GET',
752
- headers: {
753
- Authorization: "Bearer " + config.token,
754
- 'Content-type': 'application/json'
755
- }
756
- };
757
- if (shouldAppendBody(params)) {
758
- opts = Object.assign(Object.assign({}, opts), { body: params.body });
759
- }
760
- return opts;
761
- }
762
- function request(options, config) {
763
- return __awaiter(this, void 0, void 0, function () {
764
- var url, opts;
765
- return __generator(this, function (_a) {
766
- switch (_a.label) {
767
- case 0: return [4 /*yield*/, getUrl(options, config)];
768
- case 1:
769
- url = _a.sent();
770
- opts = getOpts(options, config);
771
- return [2 /*return*/, fetch__default['default'](url, opts)];
772
- }
773
- });
774
- });
775
- }
776
-
777
- var DotCMSHttpClient = /** @class */ (function () {
778
- function DotCMSHttpClient(config) {
779
- this._config = config;
780
- }
781
- DotCMSHttpClient.prototype.request = function (params) {
782
- return request(params, this._config);
783
- };
784
- return DotCMSHttpClient;
785
- }());
786
-
787
- function populateQueryUrl(params) {
788
- var e_1, _a, e_2, _b;
789
- var url = '';
790
- var attrs = {
791
- depth: "/depth/" + params.options.depth,
792
- limit: "/limit/" + params.options.limit,
793
- offset: "/offset/" + params.options.offset,
794
- orderBy: "/orderby/" + params.options.orderBy
795
- };
796
- if (params.queryParams) {
797
- try {
798
- for (var _c = __values(Object.keys(params.queryParams)), _d = _c.next(); !_d.done; _d = _c.next()) {
799
- var key = _d.value;
800
- url += "+" + key + ":" + params.queryParams[key] + "%20";
801
- }
802
- }
803
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
804
- finally {
805
- try {
806
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
807
- }
808
- finally { if (e_1) throw e_1.error; }
809
- }
810
- }
811
- try {
812
- for (var _e = __values(Object.keys(params.options)), _f = _e.next(); !_f.done; _f = _e.next()) {
813
- var key = _f.value;
814
- url += attrs[key];
815
- }
816
- }
817
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
818
- finally {
819
- try {
820
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
821
- }
822
- finally { if (e_2) throw e_2.error; }
823
- }
824
- return url;
825
- }
826
- /**
827
- * Query/Save/Publish the information of DotCMS Content
828
- *
829
- */
830
- var DotApiContent = /** @class */ (function () {
831
- function DotApiContent(httpClient) {
832
- this.dotCMSHttpClient = httpClient;
833
- }
834
- DotApiContent.prototype.query = function (params) {
835
- var url = "/api/content/query/+contentType:" + params.contentType + "%20" + populateQueryUrl(params);
836
- return this.doRequest(url, null, 'GET');
837
- };
838
- DotApiContent.prototype.save = function (params) {
839
- return this.doRequest('/api/content/save/1', params);
840
- };
841
- DotApiContent.prototype.publish = function (params) {
842
- return this.doRequest('/api/content/publish/1', params);
843
- };
844
- DotApiContent.prototype.doRequest = function (url, params, httpMethod) {
845
- if (httpMethod === void 0) { httpMethod = 'POST'; }
846
- return __awaiter(this, void 0, void 0, function () {
847
- var response, _a;
848
- return __generator(this, function (_b) {
849
- switch (_b.label) {
850
- case 0: return [4 /*yield*/, this.dotCMSHttpClient.request({
851
- url: url,
852
- method: httpMethod,
853
- body: params ? JSON.stringify(params) : ''
854
- })];
855
- case 1:
856
- response = _b.sent();
857
- if (!(response.status !== 200)) return [3 /*break*/, 3];
858
- _a = {};
859
- return [4 /*yield*/, response.text()];
860
- case 2: throw _a.message = _b.sent(),
861
- _a.statusCode = response.status,
862
- _a;
863
- case 3: return [2 /*return*/, response];
864
- }
865
- });
866
- });
867
- };
868
- return DotApiContent;
869
- }());
870
-
871
- /**
872
- * Get the information of DotCMS contentTypes
873
- *
874
- */
875
- var DotApiContentType = /** @class */ (function () {
876
- function DotApiContentType(httpClient) {
877
- this.dotCMSHttpClient = httpClient;
878
- }
879
- DotApiContentType.prototype.get = function (contentTypeId) {
880
- return __awaiter(this, void 0, void 0, function () {
881
- var response, _a, data;
882
- return __generator(this, function (_b) {
883
- switch (_b.label) {
884
- case 0: return [4 /*yield*/, this.dotCMSHttpClient.request({
885
- url: "/api/v1/contenttype/id/" + contentTypeId
886
- })];
887
- case 1:
888
- response = _b.sent();
889
- if (!(response.status !== 200)) return [3 /*break*/, 3];
890
- _a = {};
891
- return [4 /*yield*/, response.text()];
892
- case 2: throw _a.message = _b.sent(),
893
- _a.statusCode = response.status,
894
- _a;
895
- case 3: return [4 /*yield*/, response.json()];
896
- case 4:
897
- data = _b.sent();
898
- return [2 /*return*/, data.entity];
899
- }
900
- });
901
- });
902
- };
903
- DotApiContentType.prototype.getLayout = function (contentTypeId) {
904
- return this.get(contentTypeId).then(function (contentType) {
905
- return contentType.layout;
906
- });
907
- };
908
- return DotApiContentType;
909
- }());
910
-
911
- /**
912
- * Creates and provide methods to render a DotCMS Form
913
- *
914
- */
915
- var DotApiForm = /** @class */ (function () {
916
- function DotApiForm(dotApiContentType, formConfig) {
917
- this.dotApiContentType = dotApiContentType;
918
- this.formConfig = formConfig;
919
- }
920
- /**
921
- * Render form on provided html element
922
- * @memberof DotApiForm
923
- */
924
- DotApiForm.prototype.get = function () {
925
- return __awaiter(this, void 0, void 0, function () {
926
- return __generator(this, function (_a) {
927
- return [2 /*return*/, this.dotApiContentType.get(this.formConfig.identifier)];
928
- });
929
- });
930
- };
931
- return DotApiForm;
932
- }());
933
-
934
- var initDotCMS = function (config) {
935
- var httpClient = new DotCMSHttpClient(config);
936
- var apiConfig = new DotApiConfiguration(httpClient);
937
- var apiLanguage = new DotApiLanguage(apiConfig);
938
- var content = new DotApiContent(httpClient);
939
- var dotApiContentType = new DotApiContentType(httpClient);
940
- return {
941
- auth: new DotApiAuthorization(),
942
- config: apiConfig,
943
- content: content,
944
- contentType: new DotApiContentType(httpClient),
945
- esSearch: new DotApiElasticSearch(httpClient),
946
- event: new DotApiEvent(),
947
- form: function (formConfig) { return new DotApiForm(dotApiContentType, formConfig); },
948
- language: apiLanguage,
949
- nav: new DotApiNavigation(httpClient),
950
- page: new DotApiPage(httpClient, apiLanguage),
951
- site: new DotApiSite(httpClient),
952
- widget: new DotApiWidget(httpClient),
953
- httpClient: httpClient
954
- };
955
- };
956
-
957
- /**
958
- * Generated bundle index. Do not edit.
959
- */
960
-
961
- exports.initDotCMS = initDotCMS;
962
-
963
- Object.defineProperty(exports, '__esModule', { value: true });
964
-
965
- })));
966
- //# sourceMappingURL=dotcms.umd.js.map