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