@geowiki/cms-proxy 0.15.0-dev.1

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.
package/dist/index.js ADDED
@@ -0,0 +1,621 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __accessCheck = (obj, member, msg) => {
47
+ if (!member.has(obj))
48
+ throw TypeError("Cannot " + msg);
49
+ };
50
+ var __privateGet = (obj, member, getter) => {
51
+ __accessCheck(obj, member, "read from private field");
52
+ return getter ? getter.call(obj) : member.get(obj);
53
+ };
54
+ var __privateAdd = (obj, member, value) => {
55
+ if (member.has(obj))
56
+ throw TypeError("Cannot add the same private member more than once");
57
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
58
+ };
59
+ var __privateSet = (obj, member, value, setter) => {
60
+ __accessCheck(obj, member, "write to private field");
61
+ setter ? setter.call(obj, value) : member.set(obj, value);
62
+ return value;
63
+ };
64
+ var __async = (__this, __arguments, generator) => {
65
+ return new Promise((resolve2, reject) => {
66
+ var fulfilled = (value) => {
67
+ try {
68
+ step(generator.next(value));
69
+ } catch (e) {
70
+ reject(e);
71
+ }
72
+ };
73
+ var rejected = (value) => {
74
+ try {
75
+ step(generator.throw(value));
76
+ } catch (e) {
77
+ reject(e);
78
+ }
79
+ };
80
+ var step = (x) => x.done ? resolve2(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
81
+ step((generator = generator.apply(__this, __arguments)).next());
82
+ });
83
+ };
84
+
85
+ // index.ts
86
+ var cms_proxy_exports = {};
87
+ __export(cms_proxy_exports, {
88
+ ApiError: () => ApiError,
89
+ CancelError: () => CancelError,
90
+ CancelablePromise: () => CancelablePromise,
91
+ DefaultService: () => DefaultService,
92
+ FlowAlignment: () => FlowAlignment,
93
+ OpenAPI: () => OpenAPI,
94
+ QueryApiService: () => QueryApiService,
95
+ SettingsService: () => SettingsService
96
+ });
97
+ module.exports = __toCommonJS(cms_proxy_exports);
98
+
99
+ // core/ApiError.ts
100
+ var ApiError = class extends Error {
101
+ constructor(request2, response, message) {
102
+ super(message);
103
+ this.name = "ApiError";
104
+ this.url = response.url;
105
+ this.status = response.status;
106
+ this.statusText = response.statusText;
107
+ this.body = response.body;
108
+ this.request = request2;
109
+ }
110
+ };
111
+
112
+ // core/CancelablePromise.ts
113
+ var CancelError = class extends Error {
114
+ constructor(message) {
115
+ super(message);
116
+ this.name = "CancelError";
117
+ }
118
+ get isCancelled() {
119
+ return true;
120
+ }
121
+ };
122
+ var _isResolved, _isRejected, _isCancelled, _cancelHandlers, _promise, _resolve, _reject;
123
+ var CancelablePromise = class {
124
+ constructor(executor) {
125
+ __privateAdd(this, _isResolved, void 0);
126
+ __privateAdd(this, _isRejected, void 0);
127
+ __privateAdd(this, _isCancelled, void 0);
128
+ __privateAdd(this, _cancelHandlers, void 0);
129
+ __privateAdd(this, _promise, void 0);
130
+ __privateAdd(this, _resolve, void 0);
131
+ __privateAdd(this, _reject, void 0);
132
+ __privateSet(this, _isResolved, false);
133
+ __privateSet(this, _isRejected, false);
134
+ __privateSet(this, _isCancelled, false);
135
+ __privateSet(this, _cancelHandlers, []);
136
+ __privateSet(this, _promise, new Promise((resolve2, reject) => {
137
+ __privateSet(this, _resolve, resolve2);
138
+ __privateSet(this, _reject, reject);
139
+ const onResolve = (value) => {
140
+ if (__privateGet(this, _isResolved) || __privateGet(this, _isRejected) || __privateGet(this, _isCancelled)) {
141
+ return;
142
+ }
143
+ __privateSet(this, _isResolved, true);
144
+ if (__privateGet(this, _resolve))
145
+ __privateGet(this, _resolve).call(this, value);
146
+ };
147
+ const onReject = (reason) => {
148
+ if (__privateGet(this, _isResolved) || __privateGet(this, _isRejected) || __privateGet(this, _isCancelled)) {
149
+ return;
150
+ }
151
+ __privateSet(this, _isRejected, true);
152
+ if (__privateGet(this, _reject))
153
+ __privateGet(this, _reject).call(this, reason);
154
+ };
155
+ const onCancel = (cancelHandler) => {
156
+ if (__privateGet(this, _isResolved) || __privateGet(this, _isRejected) || __privateGet(this, _isCancelled)) {
157
+ return;
158
+ }
159
+ __privateGet(this, _cancelHandlers).push(cancelHandler);
160
+ };
161
+ Object.defineProperty(onCancel, "isResolved", {
162
+ get: () => __privateGet(this, _isResolved)
163
+ });
164
+ Object.defineProperty(onCancel, "isRejected", {
165
+ get: () => __privateGet(this, _isRejected)
166
+ });
167
+ Object.defineProperty(onCancel, "isCancelled", {
168
+ get: () => __privateGet(this, _isCancelled)
169
+ });
170
+ return executor(onResolve, onReject, onCancel);
171
+ }));
172
+ }
173
+ get [Symbol.toStringTag]() {
174
+ return "Cancellable Promise";
175
+ }
176
+ then(onFulfilled, onRejected) {
177
+ return __privateGet(this, _promise).then(onFulfilled, onRejected);
178
+ }
179
+ catch(onRejected) {
180
+ return __privateGet(this, _promise).catch(onRejected);
181
+ }
182
+ finally(onFinally) {
183
+ return __privateGet(this, _promise).finally(onFinally);
184
+ }
185
+ cancel() {
186
+ if (__privateGet(this, _isResolved) || __privateGet(this, _isRejected) || __privateGet(this, _isCancelled)) {
187
+ return;
188
+ }
189
+ __privateSet(this, _isCancelled, true);
190
+ if (__privateGet(this, _cancelHandlers).length) {
191
+ try {
192
+ for (const cancelHandler of __privateGet(this, _cancelHandlers)) {
193
+ cancelHandler();
194
+ }
195
+ } catch (error) {
196
+ console.warn("Cancellation threw an error", error);
197
+ return;
198
+ }
199
+ }
200
+ __privateGet(this, _cancelHandlers).length = 0;
201
+ if (__privateGet(this, _reject))
202
+ __privateGet(this, _reject).call(this, new CancelError("Request aborted"));
203
+ }
204
+ get isCancelled() {
205
+ return __privateGet(this, _isCancelled);
206
+ }
207
+ };
208
+ _isResolved = new WeakMap();
209
+ _isRejected = new WeakMap();
210
+ _isCancelled = new WeakMap();
211
+ _cancelHandlers = new WeakMap();
212
+ _promise = new WeakMap();
213
+ _resolve = new WeakMap();
214
+ _reject = new WeakMap();
215
+
216
+ // core/OpenAPI.ts
217
+ var OpenAPI = {
218
+ BASE: "http://cms.geowiki.iiasa.ac.at/geoquest",
219
+ VERSION: "1.0.0",
220
+ WITH_CREDENTIALS: false,
221
+ CREDENTIALS: "include",
222
+ TOKEN: void 0,
223
+ USERNAME: void 0,
224
+ PASSWORD: void 0,
225
+ HEADERS: void 0,
226
+ ENCODE_PATH: void 0
227
+ };
228
+
229
+ // models/FlowAlignment.ts
230
+ var FlowAlignment = /* @__PURE__ */ ((FlowAlignment2) => {
231
+ FlowAlignment2[FlowAlignment2["_0"] = 0] = "_0";
232
+ FlowAlignment2[FlowAlignment2["_1"] = 1] = "_1";
233
+ FlowAlignment2[FlowAlignment2["_2"] = 2] = "_2";
234
+ FlowAlignment2[FlowAlignment2["_3"] = 3] = "_3";
235
+ return FlowAlignment2;
236
+ })(FlowAlignment || {});
237
+
238
+ // core/request.ts
239
+ var import_axios = __toESM(require("axios"));
240
+ var import_form_data = __toESM(require("form-data"));
241
+ var isDefined = (value) => {
242
+ return value !== void 0 && value !== null;
243
+ };
244
+ var isString = (value) => {
245
+ return typeof value === "string";
246
+ };
247
+ var isStringWithValue = (value) => {
248
+ return isString(value) && value !== "";
249
+ };
250
+ var isBlob = (value) => {
251
+ return typeof value === "object" && typeof value.type === "string" && typeof value.stream === "function" && typeof value.arrayBuffer === "function" && typeof value.constructor === "function" && typeof value.constructor.name === "string" && /^(Blob|File)$/.test(value.constructor.name) && /^(Blob|File)$/.test(value[Symbol.toStringTag]);
252
+ };
253
+ var isFormData = (value) => {
254
+ return value instanceof import_form_data.default;
255
+ };
256
+ var isSuccess = (status) => {
257
+ return status >= 200 && status < 300;
258
+ };
259
+ var base64 = (str) => {
260
+ try {
261
+ return btoa(str);
262
+ } catch (err) {
263
+ return Buffer.from(str).toString("base64");
264
+ }
265
+ };
266
+ var getQueryString = (params) => {
267
+ const qs = [];
268
+ const append = (key, value) => {
269
+ qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
270
+ };
271
+ const process = (key, value) => {
272
+ if (isDefined(value)) {
273
+ if (Array.isArray(value)) {
274
+ value.forEach((v) => {
275
+ process(key, v);
276
+ });
277
+ } else if (typeof value === "object") {
278
+ Object.entries(value).forEach(([k, v]) => {
279
+ process(`${key}[${k}]`, v);
280
+ });
281
+ } else {
282
+ append(key, value);
283
+ }
284
+ }
285
+ };
286
+ Object.entries(params).forEach(([key, value]) => {
287
+ process(key, value);
288
+ });
289
+ if (qs.length > 0) {
290
+ return `?${qs.join("&")}`;
291
+ }
292
+ return "";
293
+ };
294
+ var getUrl = (config, options) => {
295
+ const encoder = config.ENCODE_PATH || encodeURI;
296
+ const path = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => {
297
+ var _a;
298
+ if ((_a = options.path) == null ? void 0 : _a.hasOwnProperty(group)) {
299
+ return encoder(String(options.path[group]));
300
+ }
301
+ return substring;
302
+ });
303
+ const url = `${config.BASE}${path}`;
304
+ if (options.query) {
305
+ return `${url}${getQueryString(options.query)}`;
306
+ }
307
+ return url;
308
+ };
309
+ var getFormData = (options) => {
310
+ if (options.formData) {
311
+ const formData = new import_form_data.default();
312
+ const process = (key, value) => {
313
+ if (isString(value) || isBlob(value)) {
314
+ formData.append(key, value);
315
+ } else {
316
+ formData.append(key, JSON.stringify(value));
317
+ }
318
+ };
319
+ Object.entries(options.formData).filter(([_, value]) => isDefined(value)).forEach(([key, value]) => {
320
+ if (Array.isArray(value)) {
321
+ value.forEach((v) => process(key, v));
322
+ } else {
323
+ process(key, value);
324
+ }
325
+ });
326
+ return formData;
327
+ }
328
+ return void 0;
329
+ };
330
+ var resolve = (options, resolver) => __async(void 0, null, function* () {
331
+ if (typeof resolver === "function") {
332
+ return resolver(options);
333
+ }
334
+ return resolver;
335
+ });
336
+ var getHeaders = (config, options, formData) => __async(void 0, null, function* () {
337
+ const [token, username, password, additionalHeaders] = yield Promise.all([
338
+ resolve(options, config.TOKEN),
339
+ resolve(options, config.USERNAME),
340
+ resolve(options, config.PASSWORD),
341
+ resolve(options, config.HEADERS)
342
+ ]);
343
+ const formHeaders = typeof (formData == null ? void 0 : formData.getHeaders) === "function" && (formData == null ? void 0 : formData.getHeaders()) || {};
344
+ const headers = Object.entries(__spreadValues(__spreadValues(__spreadValues({
345
+ Accept: "application/json"
346
+ }, additionalHeaders), options.headers), formHeaders)).filter(([_, value]) => isDefined(value)).reduce(
347
+ (headers2, [key, value]) => __spreadProps(__spreadValues({}, headers2), {
348
+ [key]: String(value)
349
+ }),
350
+ {}
351
+ );
352
+ if (isStringWithValue(token)) {
353
+ headers["Authorization"] = `Bearer ${token}`;
354
+ }
355
+ if (isStringWithValue(username) && isStringWithValue(password)) {
356
+ const credentials = base64(`${username}:${password}`);
357
+ headers["Authorization"] = `Basic ${credentials}`;
358
+ }
359
+ if (options.body) {
360
+ if (options.mediaType) {
361
+ headers["Content-Type"] = options.mediaType;
362
+ } else if (isBlob(options.body)) {
363
+ headers["Content-Type"] = options.body.type || "application/octet-stream";
364
+ } else if (isString(options.body)) {
365
+ headers["Content-Type"] = "text/plain";
366
+ } else if (!isFormData(options.body)) {
367
+ headers["Content-Type"] = "application/json";
368
+ }
369
+ }
370
+ return headers;
371
+ });
372
+ var getRequestBody = (options) => {
373
+ if (options.body) {
374
+ return options.body;
375
+ }
376
+ return void 0;
377
+ };
378
+ var sendRequest = (config, options, url, body, formData, headers, onCancel, axiosClient) => __async(void 0, null, function* () {
379
+ const source = import_axios.default.CancelToken.source();
380
+ const requestConfig = {
381
+ url,
382
+ headers,
383
+ data: body != null ? body : formData,
384
+ method: options.method,
385
+ withCredentials: config.WITH_CREDENTIALS,
386
+ cancelToken: source.token
387
+ };
388
+ onCancel(() => source.cancel("The user aborted a request."));
389
+ try {
390
+ return yield axiosClient.request(requestConfig);
391
+ } catch (error) {
392
+ const axiosError = error;
393
+ if (axiosError.response) {
394
+ return axiosError.response;
395
+ }
396
+ throw error;
397
+ }
398
+ });
399
+ var getResponseHeader = (response, responseHeader) => {
400
+ if (responseHeader) {
401
+ const content = response.headers[responseHeader];
402
+ if (isString(content)) {
403
+ return content;
404
+ }
405
+ }
406
+ return void 0;
407
+ };
408
+ var getResponseBody = (response) => {
409
+ if (response.status !== 204) {
410
+ return response.data;
411
+ }
412
+ return void 0;
413
+ };
414
+ var catchErrorCodes = (options, result) => {
415
+ var _a, _b;
416
+ const errors = __spreadValues({
417
+ 400: "Bad Request",
418
+ 401: "Unauthorized",
419
+ 403: "Forbidden",
420
+ 404: "Not Found",
421
+ 500: "Internal Server Error",
422
+ 502: "Bad Gateway",
423
+ 503: "Service Unavailable"
424
+ }, options.errors);
425
+ const error = errors[result.status];
426
+ if (error) {
427
+ throw new ApiError(options, result, error);
428
+ }
429
+ if (!result.ok) {
430
+ const errorStatus = (_a = result.status) != null ? _a : "unknown";
431
+ const errorStatusText = (_b = result.statusText) != null ? _b : "unknown";
432
+ const errorBody = (() => {
433
+ try {
434
+ return JSON.stringify(result.body, null, 2);
435
+ } catch (e) {
436
+ return void 0;
437
+ }
438
+ })();
439
+ throw new ApiError(
440
+ options,
441
+ result,
442
+ `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
443
+ );
444
+ }
445
+ };
446
+ var request = (config, options, axiosClient = import_axios.default) => {
447
+ return new CancelablePromise((resolve2, reject, onCancel) => __async(void 0, null, function* () {
448
+ try {
449
+ const url = getUrl(config, options);
450
+ const formData = getFormData(options);
451
+ const body = getRequestBody(options);
452
+ const headers = yield getHeaders(config, options, formData);
453
+ if (!onCancel.isCancelled) {
454
+ const response = yield sendRequest(
455
+ config,
456
+ options,
457
+ url,
458
+ body,
459
+ formData,
460
+ headers,
461
+ onCancel,
462
+ axiosClient
463
+ );
464
+ const responseBody = getResponseBody(response);
465
+ const responseHeader = getResponseHeader(
466
+ response,
467
+ options.responseHeader
468
+ );
469
+ const result = {
470
+ url,
471
+ ok: isSuccess(response.status),
472
+ status: response.status,
473
+ statusText: response.statusText,
474
+ body: responseHeader != null ? responseHeader : responseBody
475
+ };
476
+ catchErrorCodes(options, result);
477
+ resolve2(result.body);
478
+ }
479
+ } catch (error) {
480
+ reject(error);
481
+ }
482
+ }));
483
+ };
484
+
485
+ // services/DefaultService.ts
486
+ var DefaultService = class {
487
+ /**
488
+ * @param contentItemId
489
+ * @returns any
490
+ * @throws ApiError
491
+ */
492
+ static getApiContent(contentItemId) {
493
+ return request(OpenAPI, {
494
+ method: "GET",
495
+ url: "/api/content/{contentItemId}",
496
+ path: {
497
+ contentItemId
498
+ }
499
+ });
500
+ }
501
+ /**
502
+ * @param contentItemId
503
+ * @returns any
504
+ * @throws ApiError
505
+ */
506
+ static deleteApiContent(contentItemId) {
507
+ return request(OpenAPI, {
508
+ method: "DELETE",
509
+ url: "/api/content/{contentItemId}",
510
+ path: {
511
+ contentItemId
512
+ }
513
+ });
514
+ }
515
+ /**
516
+ * @param draft
517
+ * @param requestBody
518
+ * @returns any
519
+ * @throws ApiError
520
+ */
521
+ static postApiContent(draft = false, requestBody) {
522
+ return request(OpenAPI, {
523
+ method: "POST",
524
+ url: "/api/content",
525
+ query: {
526
+ draft
527
+ },
528
+ body: requestBody,
529
+ mediaType: "application/json"
530
+ });
531
+ }
532
+ };
533
+
534
+ // services/QueryApiService.ts
535
+ var QueryApiService = class {
536
+ /**
537
+ * @param name
538
+ * @param parameters
539
+ * @returns QueriesItemsDto
540
+ * @throws ApiError
541
+ */
542
+ static apiQueryPost(name, parameters) {
543
+ return request(OpenAPI, {
544
+ method: "POST",
545
+ url: "/api/queries/{name}",
546
+ path: {
547
+ name
548
+ },
549
+ query: {
550
+ parameters
551
+ }
552
+ });
553
+ }
554
+ /**
555
+ * @param name
556
+ * @param parameters
557
+ * @returns QueriesItemsDto
558
+ * @throws ApiError
559
+ */
560
+ static apiQueryGet(name, parameters) {
561
+ return request(OpenAPI, {
562
+ method: "GET",
563
+ url: "/api/queries/{name}",
564
+ path: {
565
+ name
566
+ },
567
+ query: {
568
+ parameters
569
+ }
570
+ });
571
+ }
572
+ };
573
+
574
+ // services/SettingsService.ts
575
+ var SettingsService = class {
576
+ /**
577
+ * @param settingsType
578
+ * @returns binary
579
+ * @throws ApiError
580
+ */
581
+ static settingsGetSiteSettings(settingsType) {
582
+ return request(OpenAPI, {
583
+ method: "GET",
584
+ url: "/api/settings/{settingsType}",
585
+ path: {
586
+ settingsType
587
+ }
588
+ });
589
+ }
590
+ /**
591
+ * @returns binary
592
+ * @throws ApiError
593
+ */
594
+ static settingsGetDefaultSiteSettings() {
595
+ return request(OpenAPI, {
596
+ method: "GET",
597
+ url: "/api/settings/default"
598
+ });
599
+ }
600
+ /**
601
+ * @returns binary
602
+ * @throws ApiError
603
+ */
604
+ static settingsGetMenu() {
605
+ return request(OpenAPI, {
606
+ method: "GET",
607
+ url: "/api/settings/menu"
608
+ });
609
+ }
610
+ };
611
+ // Annotate the CommonJS export names for ESM import in node:
612
+ 0 && (module.exports = {
613
+ ApiError,
614
+ CancelError,
615
+ CancelablePromise,
616
+ DefaultService,
617
+ FlowAlignment,
618
+ OpenAPI,
619
+ QueryApiService,
620
+ SettingsService
621
+ });