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