@geowiki/cms-proxy 0.0.0

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