@freshpointcz/fresh-core 0.0.11 → 0.0.13

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,1551 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __commonJS = (cb, mod) => function __require2() {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
35
+
36
+ // ../../node_modules/dotenv/package.json
37
+ var require_package = __commonJS({
38
+ "../../node_modules/dotenv/package.json"(exports, module) {
39
+ module.exports = {
40
+ name: "dotenv",
41
+ version: "16.6.1",
42
+ description: "Loads environment variables from .env file",
43
+ main: "lib/main.js",
44
+ types: "lib/main.d.ts",
45
+ exports: {
46
+ ".": {
47
+ types: "./lib/main.d.ts",
48
+ require: "./lib/main.js",
49
+ default: "./lib/main.js"
50
+ },
51
+ "./config": "./config.js",
52
+ "./config.js": "./config.js",
53
+ "./lib/env-options": "./lib/env-options.js",
54
+ "./lib/env-options.js": "./lib/env-options.js",
55
+ "./lib/cli-options": "./lib/cli-options.js",
56
+ "./lib/cli-options.js": "./lib/cli-options.js",
57
+ "./package.json": "./package.json"
58
+ },
59
+ scripts: {
60
+ "dts-check": "tsc --project tests/types/tsconfig.json",
61
+ lint: "standard",
62
+ pretest: "npm run lint && npm run dts-check",
63
+ test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
64
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
65
+ prerelease: "npm test",
66
+ release: "standard-version"
67
+ },
68
+ repository: {
69
+ type: "git",
70
+ url: "git://github.com/motdotla/dotenv.git"
71
+ },
72
+ homepage: "https://github.com/motdotla/dotenv#readme",
73
+ funding: "https://dotenvx.com",
74
+ keywords: [
75
+ "dotenv",
76
+ "env",
77
+ ".env",
78
+ "environment",
79
+ "variables",
80
+ "config",
81
+ "settings"
82
+ ],
83
+ readmeFilename: "README.md",
84
+ license: "BSD-2-Clause",
85
+ devDependencies: {
86
+ "@types/node": "^18.11.3",
87
+ decache: "^4.6.2",
88
+ sinon: "^14.0.1",
89
+ standard: "^17.0.0",
90
+ "standard-version": "^9.5.0",
91
+ tap: "^19.2.0",
92
+ typescript: "^4.8.4"
93
+ },
94
+ engines: {
95
+ node: ">=12"
96
+ },
97
+ browser: {
98
+ fs: false
99
+ }
100
+ };
101
+ }
102
+ });
103
+
104
+ // ../../node_modules/dotenv/lib/main.js
105
+ var require_main = __commonJS({
106
+ "../../node_modules/dotenv/lib/main.js"(exports, module) {
107
+ "use strict";
108
+ var fs = __require("fs");
109
+ var path2 = __require("path");
110
+ var os = __require("os");
111
+ var crypto = __require("crypto");
112
+ var packageJson = require_package();
113
+ var version = packageJson.version;
114
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
115
+ function parse(src) {
116
+ const obj = {};
117
+ let lines = src.toString();
118
+ lines = lines.replace(/\r\n?/mg, "\n");
119
+ let match;
120
+ while ((match = LINE.exec(lines)) != null) {
121
+ const key = match[1];
122
+ let value = match[2] || "";
123
+ value = value.trim();
124
+ const maybeQuote = value[0];
125
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
126
+ if (maybeQuote === '"') {
127
+ value = value.replace(/\\n/g, "\n");
128
+ value = value.replace(/\\r/g, "\r");
129
+ }
130
+ obj[key] = value;
131
+ }
132
+ return obj;
133
+ }
134
+ __name(parse, "parse");
135
+ function _parseVault(options) {
136
+ options = options || {};
137
+ const vaultPath = _vaultPath(options);
138
+ options.path = vaultPath;
139
+ const result = DotenvModule.configDotenv(options);
140
+ if (!result.parsed) {
141
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
142
+ err.code = "MISSING_DATA";
143
+ throw err;
144
+ }
145
+ const keys = _dotenvKey(options).split(",");
146
+ const length = keys.length;
147
+ let decrypted;
148
+ for (let i = 0; i < length; i++) {
149
+ try {
150
+ const key = keys[i].trim();
151
+ const attrs = _instructions(result, key);
152
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
153
+ break;
154
+ } catch (error) {
155
+ if (i + 1 >= length) {
156
+ throw error;
157
+ }
158
+ }
159
+ }
160
+ return DotenvModule.parse(decrypted);
161
+ }
162
+ __name(_parseVault, "_parseVault");
163
+ function _warn(message) {
164
+ console.log(`[dotenv@${version}][WARN] ${message}`);
165
+ }
166
+ __name(_warn, "_warn");
167
+ function _debug(message) {
168
+ console.log(`[dotenv@${version}][DEBUG] ${message}`);
169
+ }
170
+ __name(_debug, "_debug");
171
+ function _log(message) {
172
+ console.log(`[dotenv@${version}] ${message}`);
173
+ }
174
+ __name(_log, "_log");
175
+ function _dotenvKey(options) {
176
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
177
+ return options.DOTENV_KEY;
178
+ }
179
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
180
+ return process.env.DOTENV_KEY;
181
+ }
182
+ return "";
183
+ }
184
+ __name(_dotenvKey, "_dotenvKey");
185
+ function _instructions(result, dotenvKey) {
186
+ let uri;
187
+ try {
188
+ uri = new URL(dotenvKey);
189
+ } catch (error) {
190
+ if (error.code === "ERR_INVALID_URL") {
191
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
192
+ err.code = "INVALID_DOTENV_KEY";
193
+ throw err;
194
+ }
195
+ throw error;
196
+ }
197
+ const key = uri.password;
198
+ if (!key) {
199
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
200
+ err.code = "INVALID_DOTENV_KEY";
201
+ throw err;
202
+ }
203
+ const environment = uri.searchParams.get("environment");
204
+ if (!environment) {
205
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
206
+ err.code = "INVALID_DOTENV_KEY";
207
+ throw err;
208
+ }
209
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
210
+ const ciphertext = result.parsed[environmentKey];
211
+ if (!ciphertext) {
212
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
213
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
214
+ throw err;
215
+ }
216
+ return {
217
+ ciphertext,
218
+ key
219
+ };
220
+ }
221
+ __name(_instructions, "_instructions");
222
+ function _vaultPath(options) {
223
+ let possibleVaultPath = null;
224
+ if (options && options.path && options.path.length > 0) {
225
+ if (Array.isArray(options.path)) {
226
+ for (const filepath of options.path) {
227
+ if (fs.existsSync(filepath)) {
228
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
229
+ }
230
+ }
231
+ } else {
232
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
233
+ }
234
+ } else {
235
+ possibleVaultPath = path2.resolve(process.cwd(), ".env.vault");
236
+ }
237
+ if (fs.existsSync(possibleVaultPath)) {
238
+ return possibleVaultPath;
239
+ }
240
+ return null;
241
+ }
242
+ __name(_vaultPath, "_vaultPath");
243
+ function _resolveHome(envPath) {
244
+ return envPath[0] === "~" ? path2.join(os.homedir(), envPath.slice(1)) : envPath;
245
+ }
246
+ __name(_resolveHome, "_resolveHome");
247
+ function _configVault(options) {
248
+ const debug = Boolean(options && options.debug);
249
+ const quiet = options && "quiet" in options ? options.quiet : true;
250
+ if (debug || !quiet) {
251
+ _log("Loading env from encrypted .env.vault");
252
+ }
253
+ const parsed = DotenvModule._parseVault(options);
254
+ let processEnv = process.env;
255
+ if (options && options.processEnv != null) {
256
+ processEnv = options.processEnv;
257
+ }
258
+ DotenvModule.populate(processEnv, parsed, options);
259
+ return {
260
+ parsed
261
+ };
262
+ }
263
+ __name(_configVault, "_configVault");
264
+ function configDotenv(options) {
265
+ const dotenvPath = path2.resolve(process.cwd(), ".env");
266
+ let encoding = "utf8";
267
+ const debug = Boolean(options && options.debug);
268
+ const quiet = options && "quiet" in options ? options.quiet : true;
269
+ if (options && options.encoding) {
270
+ encoding = options.encoding;
271
+ } else {
272
+ if (debug) {
273
+ _debug("No encoding is specified. UTF-8 is used by default");
274
+ }
275
+ }
276
+ let optionPaths = [
277
+ dotenvPath
278
+ ];
279
+ if (options && options.path) {
280
+ if (!Array.isArray(options.path)) {
281
+ optionPaths = [
282
+ _resolveHome(options.path)
283
+ ];
284
+ } else {
285
+ optionPaths = [];
286
+ for (const filepath of options.path) {
287
+ optionPaths.push(_resolveHome(filepath));
288
+ }
289
+ }
290
+ }
291
+ let lastError;
292
+ const parsedAll = {};
293
+ for (const path3 of optionPaths) {
294
+ try {
295
+ const parsed = DotenvModule.parse(fs.readFileSync(path3, {
296
+ encoding
297
+ }));
298
+ DotenvModule.populate(parsedAll, parsed, options);
299
+ } catch (e) {
300
+ if (debug) {
301
+ _debug(`Failed to load ${path3} ${e.message}`);
302
+ }
303
+ lastError = e;
304
+ }
305
+ }
306
+ let processEnv = process.env;
307
+ if (options && options.processEnv != null) {
308
+ processEnv = options.processEnv;
309
+ }
310
+ DotenvModule.populate(processEnv, parsedAll, options);
311
+ if (debug || !quiet) {
312
+ const keysCount = Object.keys(parsedAll).length;
313
+ const shortPaths = [];
314
+ for (const filePath of optionPaths) {
315
+ try {
316
+ const relative = path2.relative(process.cwd(), filePath);
317
+ shortPaths.push(relative);
318
+ } catch (e) {
319
+ if (debug) {
320
+ _debug(`Failed to load ${filePath} ${e.message}`);
321
+ }
322
+ lastError = e;
323
+ }
324
+ }
325
+ _log(`injecting env (${keysCount}) from ${shortPaths.join(",")}`);
326
+ }
327
+ if (lastError) {
328
+ return {
329
+ parsed: parsedAll,
330
+ error: lastError
331
+ };
332
+ } else {
333
+ return {
334
+ parsed: parsedAll
335
+ };
336
+ }
337
+ }
338
+ __name(configDotenv, "configDotenv");
339
+ function config2(options) {
340
+ if (_dotenvKey(options).length === 0) {
341
+ return DotenvModule.configDotenv(options);
342
+ }
343
+ const vaultPath = _vaultPath(options);
344
+ if (!vaultPath) {
345
+ _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
346
+ return DotenvModule.configDotenv(options);
347
+ }
348
+ return DotenvModule._configVault(options);
349
+ }
350
+ __name(config2, "config");
351
+ function decrypt(encrypted, keyStr) {
352
+ const key = Buffer.from(keyStr.slice(-64), "hex");
353
+ let ciphertext = Buffer.from(encrypted, "base64");
354
+ const nonce = ciphertext.subarray(0, 12);
355
+ const authTag = ciphertext.subarray(-16);
356
+ ciphertext = ciphertext.subarray(12, -16);
357
+ try {
358
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
359
+ aesgcm.setAuthTag(authTag);
360
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
361
+ } catch (error) {
362
+ const isRange = error instanceof RangeError;
363
+ const invalidKeyLength = error.message === "Invalid key length";
364
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
365
+ if (isRange || invalidKeyLength) {
366
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
367
+ err.code = "INVALID_DOTENV_KEY";
368
+ throw err;
369
+ } else if (decryptionFailed) {
370
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
371
+ err.code = "DECRYPTION_FAILED";
372
+ throw err;
373
+ } else {
374
+ throw error;
375
+ }
376
+ }
377
+ }
378
+ __name(decrypt, "decrypt");
379
+ function populate(processEnv, parsed, options = {}) {
380
+ const debug = Boolean(options && options.debug);
381
+ const override = Boolean(options && options.override);
382
+ if (typeof parsed !== "object") {
383
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
384
+ err.code = "OBJECT_REQUIRED";
385
+ throw err;
386
+ }
387
+ for (const key of Object.keys(parsed)) {
388
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
389
+ if (override === true) {
390
+ processEnv[key] = parsed[key];
391
+ }
392
+ if (debug) {
393
+ if (override === true) {
394
+ _debug(`"${key}" is already defined and WAS overwritten`);
395
+ } else {
396
+ _debug(`"${key}" is already defined and was NOT overwritten`);
397
+ }
398
+ }
399
+ } else {
400
+ processEnv[key] = parsed[key];
401
+ }
402
+ }
403
+ }
404
+ __name(populate, "populate");
405
+ var DotenvModule = {
406
+ configDotenv,
407
+ _configVault,
408
+ _parseVault,
409
+ config: config2,
410
+ decrypt,
411
+ parse,
412
+ populate
413
+ };
414
+ module.exports.configDotenv = DotenvModule.configDotenv;
415
+ module.exports._configVault = DotenvModule._configVault;
416
+ module.exports._parseVault = DotenvModule._parseVault;
417
+ module.exports.config = DotenvModule.config;
418
+ module.exports.decrypt = DotenvModule.decrypt;
419
+ module.exports.parse = DotenvModule.parse;
420
+ module.exports.populate = DotenvModule.populate;
421
+ module.exports = DotenvModule;
422
+ }
423
+ });
424
+
425
+ // src/common/date-utils.ts
426
+ import dayjs from "dayjs";
427
+ import utc from "dayjs/plugin/utc";
428
+ import timezone from "dayjs/plugin/timezone";
429
+ import isBetween from "dayjs/plugin/isBetween";
430
+ import customParseFormat from "dayjs/plugin/customParseFormat";
431
+ dayjs.extend(utc);
432
+ dayjs.extend(timezone);
433
+ dayjs.extend(isBetween);
434
+ dayjs.extend(customParseFormat);
435
+ var _DateUtils = class _DateUtils {
436
+ //#endregion
437
+ //#region SQL timestamps
438
+ static fromISOtoSQLtimestamp(ts) {
439
+ return dayjs(ts).utc().format("YYYY-MM-DD HH:mm:ss");
440
+ }
441
+ static toSQLtimestamp(ts) {
442
+ return ts.format("YYYY-MM-DD HH:mm:ss");
443
+ }
444
+ static fromSQLtimestamp(mysqlDate) {
445
+ return dayjs(mysqlDate, "YYYY-MM-DD HH:mm:ss").utc(true);
446
+ }
447
+ static getSqlTimestampFromNowCzech() {
448
+ return _DateUtils.toSQLtimestamp(_DateUtils.getNowCzech());
449
+ }
450
+ //#endregion
451
+ // ---------- UTC
452
+ static fromISO(isoDate) {
453
+ return dayjs(isoDate).utc(false);
454
+ }
455
+ // ----------
456
+ static getDate(ts) {
457
+ return dayjs(ts);
458
+ }
459
+ static getNow() {
460
+ return dayjs();
461
+ }
462
+ static getNowCzech() {
463
+ return dayjs().tz("Europe/Prague").utc(true);
464
+ }
465
+ static clone(ts) {
466
+ return dayjs(ts);
467
+ }
468
+ static getLastSunday(weeksOffset = 0) {
469
+ let now = _DateUtils.getNowCzech();
470
+ now = now.date(now.date() - (now.day() + 1) % 7 - 7 * weeksOffset);
471
+ now = now.hour(0);
472
+ now = now.minute(0);
473
+ now = now.second(0);
474
+ now = now.millisecond(0);
475
+ return now;
476
+ }
477
+ static dayInWeek(ts) {
478
+ const input = ts != null ? ts : dayjs();
479
+ const day = input.day();
480
+ if (day === 0) {
481
+ return 7;
482
+ }
483
+ return day;
484
+ }
485
+ static isWorkdayDay(ts) {
486
+ const weekDay = ts.get("day");
487
+ if (weekDay === 0) {
488
+ return false;
489
+ }
490
+ if (weekDay === 6) {
491
+ return false;
492
+ }
493
+ ts = ts.set("hour", 0).set("minutes", 0).set("seconds", 0).set("milliseconds", 0);
494
+ return !_DateUtils.HOLIDAYS.includes(ts.valueOf());
495
+ }
496
+ static getDiffInMinutesWithNow(inputTime) {
497
+ const now = dayjs();
498
+ const diffInMinutes = now.diff(inputTime, "minute");
499
+ return diffInMinutes;
500
+ }
501
+ static isInLastDays(numOfDays, timestampInput) {
502
+ const timestamp = typeof timestampInput === "string" ? dayjs(timestampInput) : timestampInput;
503
+ const now = dayjs();
504
+ const dateLimit = now.subtract(numOfDays, "day");
505
+ return timestamp.isAfter(dateLimit);
506
+ }
507
+ };
508
+ __name(_DateUtils, "DateUtils");
509
+ //#region Holidays
510
+ /** Holidays 2025-2030 as YYYY-MM-DD strings */
511
+ __publicField(_DateUtils, "HOLIDAYS_STR", [
512
+ /* 2025 */
513
+ "2025-01-01",
514
+ "2025-04-18",
515
+ "2025-04-21",
516
+ "2025-05-01",
517
+ "2025-05-08",
518
+ "2025-07-05",
519
+ "2025-07-06",
520
+ "2025-09-28",
521
+ "2025-10-28",
522
+ "2025-11-17",
523
+ "2025-12-24",
524
+ "2025-12-25",
525
+ "2025-12-26",
526
+ /* 2026 */
527
+ "2026-01-01",
528
+ "2026-04-03",
529
+ "2026-04-06",
530
+ "2026-05-01",
531
+ "2026-05-08",
532
+ "2026-07-05",
533
+ "2026-07-06",
534
+ "2026-09-28",
535
+ "2026-10-28",
536
+ "2026-11-17",
537
+ "2026-12-24",
538
+ "2026-12-25",
539
+ "2026-12-26",
540
+ /* 2027 */
541
+ "2027-01-01",
542
+ "2027-03-26",
543
+ "2027-03-29",
544
+ "2027-05-01",
545
+ "2027-05-08",
546
+ "2027-07-05",
547
+ "2027-07-06",
548
+ "2027-09-28",
549
+ "2027-10-28",
550
+ "2027-11-17",
551
+ "2027-12-24",
552
+ "2027-12-25",
553
+ "2027-12-26",
554
+ /* 2028 */
555
+ "2028-01-01",
556
+ "2028-04-14",
557
+ "2028-04-17",
558
+ "2028-05-01",
559
+ "2028-05-08",
560
+ "2028-07-05",
561
+ "2028-07-06",
562
+ "2028-09-28",
563
+ "2028-10-28",
564
+ "2028-11-17",
565
+ "2028-12-24",
566
+ "2028-12-25",
567
+ "2028-12-26",
568
+ /* 2029 */
569
+ "2029-01-01",
570
+ "2029-03-30",
571
+ "2029-04-02",
572
+ "2029-05-01",
573
+ "2029-05-08",
574
+ "2029-07-05",
575
+ "2029-07-06",
576
+ "2029-09-28",
577
+ "2029-10-28",
578
+ "2029-11-17",
579
+ "2029-12-24",
580
+ "2029-12-25",
581
+ "2029-12-26",
582
+ /* 2030 */
583
+ "2030-01-01",
584
+ "2030-04-19",
585
+ "2030-04-22",
586
+ "2030-05-01",
587
+ "2030-05-08",
588
+ "2030-07-05",
589
+ "2030-07-06",
590
+ "2030-09-28",
591
+ "2030-10-28",
592
+ "2030-11-17",
593
+ "2030-12-24",
594
+ "2030-12-25",
595
+ "2030-12-26"
596
+ ]);
597
+ /** Holidays 2025-2030 as UTC timestamps */
598
+ __publicField(_DateUtils, "HOLIDAYS", _DateUtils.HOLIDAYS_STR.map((h) => {
599
+ const date = new Date(h);
600
+ date.setUTCHours(0, 0, 0, 0);
601
+ return date.getTime();
602
+ }));
603
+ var DateUtils = _DateUtils;
604
+
605
+ // src/common/promise-magic/deferred.ts
606
+ function createDeferred() {
607
+ let resolve;
608
+ let reject;
609
+ const promise = new Promise((res, rej) => {
610
+ resolve = res;
611
+ reject = rej;
612
+ });
613
+ return {
614
+ promise,
615
+ resolve,
616
+ reject
617
+ };
618
+ }
619
+ __name(createDeferred, "createDeferred");
620
+
621
+ // src/common/promise-magic/single-promise-waiter.ts
622
+ var _SinglePromiseWaiter = class _SinglePromiseWaiter {
623
+ constructor() {
624
+ __publicField(this, "_promise", null);
625
+ }
626
+ static getInstance() {
627
+ if (!_SinglePromiseWaiter._instance) {
628
+ _SinglePromiseWaiter._instance = new _SinglePromiseWaiter();
629
+ }
630
+ return _SinglePromiseWaiter._instance;
631
+ }
632
+ get promise() {
633
+ return this._promise;
634
+ }
635
+ set promise(promise) {
636
+ if (promise !== null) {
637
+ this._promise = promise;
638
+ this._promise.finally(() => {
639
+ this._promise = null;
640
+ });
641
+ }
642
+ }
643
+ get hasPromise() {
644
+ return this._promise !== null;
645
+ }
646
+ };
647
+ __name(_SinglePromiseWaiter, "SinglePromiseWaiter");
648
+ __publicField(_SinglePromiseWaiter, "_instance");
649
+ var SinglePromiseWaiter = _SinglePromiseWaiter;
650
+
651
+ // src/common/winston.ts
652
+ import winston from "winston";
653
+ var SERVICE = process.env.SERVICE_NAME || "depot-ordering-service";
654
+ var ENV = process.env.NODE_ENV || "localhost";
655
+ var levelToSeverity = {
656
+ silly: "debug",
657
+ verbose: "debug",
658
+ debug: "debug",
659
+ http: "info",
660
+ info: "info",
661
+ warn: "warn",
662
+ error: "error"
663
+ };
664
+ var baseFormat = winston.format.combine(winston.format.timestamp({
665
+ format: /* @__PURE__ */ __name(() => (/* @__PURE__ */ new Date()).toISOString(), "format")
666
+ }), winston.format.errors({
667
+ stack: true
668
+ }), winston.format.printf((info) => {
669
+ const payload = {
670
+ ts: info.timestamp,
671
+ level: info.level,
672
+ severity: levelToSeverity[info.level] || info.level,
673
+ message: info.message,
674
+ service: SERVICE,
675
+ env: ENV,
676
+ process_name: process.title || process.argv[1] || "node",
677
+ pid: process.pid,
678
+ device: process.env.DEVICE_ID || void 0,
679
+ traceId: info.traceId,
680
+ spanId: info.spanId,
681
+ extra: info.extra || info.meta || void 0,
682
+ stack: info.stack
683
+ };
684
+ return JSON.stringify(payload);
685
+ }));
686
+ var transports = [
687
+ new winston.transports.Console({
688
+ level: process.env.LOG_LEVEL || "info"
689
+ })
690
+ ];
691
+ var logger = winston.createLogger({
692
+ level: process.env.LOG_LEVEL || "info",
693
+ format: baseFormat,
694
+ transports,
695
+ exitOnError: false
696
+ });
697
+ logger.stream = {
698
+ write: /* @__PURE__ */ __name((message) => logger.info(message.trim()), "write")
699
+ };
700
+
701
+ // src/common/utils/is-cron-valid.ts
702
+ function isValidCron(expr) {
703
+ const parts = expr.trim().split(/\s+/);
704
+ if (parts.length < 5 || parts.length > 6) {
705
+ return false;
706
+ }
707
+ const cronPart = /^(\*|\d+|\d+\-\d+|\d+\/\d+|\*\/\d+)(,\d+)*$/;
708
+ return parts.every((part) => cronPart.test(part));
709
+ }
710
+ __name(isValidCron, "isValidCron");
711
+
712
+ // src/common/patterns/singleton.ts
713
+ var _Singleton = class _Singleton {
714
+ constructor() {
715
+ const ctor = this.constructor;
716
+ const existing = _Singleton.instances.get(ctor);
717
+ if (existing) {
718
+ return existing;
719
+ }
720
+ _Singleton.instances.set(ctor, this);
721
+ }
722
+ static getInstance(...args) {
723
+ let instance = _Singleton.instances.get(this);
724
+ if (!instance) {
725
+ instance = new this(...args);
726
+ _Singleton.instances.set(this, instance);
727
+ }
728
+ return instance;
729
+ }
730
+ };
731
+ __name(_Singleton, "Singleton");
732
+ __publicField(_Singleton, "instances", /* @__PURE__ */ new Map());
733
+ var Singleton = _Singleton;
734
+
735
+ // src/common/dto/status-dto.ts
736
+ var _StatusDto = class _StatusDto {
737
+ constructor(status, details, timestamp) {
738
+ /**
739
+ * Call result status
740
+ */
741
+ __publicField(this, "status");
742
+ /**
743
+ * UTC Timestamp
744
+ * @example "2021-12-01T13:23:39.305Z"
745
+ */
746
+ __publicField(this, "timestamp");
747
+ /**
748
+ * Details (optional)
749
+ */
750
+ __publicField(this, "details");
751
+ this.status = status;
752
+ this.details = details;
753
+ this.timestamp = timestamp != null ? timestamp : DateUtils.getNowCzech().toISOString();
754
+ }
755
+ };
756
+ __name(_StatusDto, "StatusDto");
757
+ var StatusDto = _StatusDto;
758
+
759
+ // src/common/constants/amount-unit.ts
760
+ var AMOUNT_UNIT = {
761
+ 1: {
762
+ symbol: "g",
763
+ translations: {
764
+ en: "gram",
765
+ cs: "gram"
766
+ }
767
+ },
768
+ 2: {
769
+ symbol: "kg",
770
+ translations: {
771
+ en: "kilogram",
772
+ cs: "kilogram"
773
+ }
774
+ },
775
+ 3: {
776
+ symbol: "ml",
777
+ translations: {
778
+ en: "milliliter",
779
+ cs: "mililitr"
780
+ }
781
+ },
782
+ 4: {
783
+ symbol: "l",
784
+ translations: {
785
+ en: "liter",
786
+ cs: "litr"
787
+ }
788
+ }
789
+ };
790
+
791
+ // src/common/schema/entities/category.entity.ts
792
+ import { Entity } from "typeorm";
793
+
794
+ // src/database/entities/fresh-entity.ts
795
+ import { BaseEntity, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index, Column } from "typeorm";
796
+
797
+ // ../../node_modules/uuid/dist/esm/stringify.js
798
+ var byteToHex = [];
799
+ for (let i = 0; i < 256; ++i) {
800
+ byteToHex.push((i + 256).toString(16).slice(1));
801
+ }
802
+ function unsafeStringify(arr, offset = 0) {
803
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
804
+ }
805
+ __name(unsafeStringify, "unsafeStringify");
806
+
807
+ // ../../node_modules/uuid/dist/esm/rng.js
808
+ import { randomFillSync } from "crypto";
809
+ var rnds8Pool = new Uint8Array(256);
810
+ var poolPtr = rnds8Pool.length;
811
+ function rng() {
812
+ if (poolPtr > rnds8Pool.length - 16) {
813
+ randomFillSync(rnds8Pool);
814
+ poolPtr = 0;
815
+ }
816
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
817
+ }
818
+ __name(rng, "rng");
819
+
820
+ // ../../node_modules/uuid/dist/esm/native.js
821
+ import { randomUUID } from "crypto";
822
+ var native_default = {
823
+ randomUUID
824
+ };
825
+
826
+ // ../../node_modules/uuid/dist/esm/v4.js
827
+ function v4(options, buf, offset) {
828
+ var _a, _b, _c;
829
+ if (native_default.randomUUID && !buf && !options) {
830
+ return native_default.randomUUID();
831
+ }
832
+ options = options || {};
833
+ const rnds = (_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng();
834
+ if (rnds.length < 16) {
835
+ throw new Error("Random bytes length must be >= 16");
836
+ }
837
+ rnds[6] = rnds[6] & 15 | 64;
838
+ rnds[8] = rnds[8] & 63 | 128;
839
+ if (buf) {
840
+ offset = offset || 0;
841
+ if (offset < 0 || offset + 16 > buf.length) {
842
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
843
+ }
844
+ for (let i = 0; i < 16; ++i) {
845
+ buf[offset + i] = rnds[i];
846
+ }
847
+ return buf;
848
+ }
849
+ return unsafeStringify(rnds);
850
+ }
851
+ __name(v4, "v4");
852
+ var v4_default = v4;
853
+
854
+ // src/database/entities/fresh-entity.ts
855
+ function _ts_decorate(decorators, target, key, desc) {
856
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
857
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
858
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
859
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
860
+ }
861
+ __name(_ts_decorate, "_ts_decorate");
862
+ function _ts_metadata(k, v) {
863
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
864
+ }
865
+ __name(_ts_metadata, "_ts_metadata");
866
+ var _FreshEntity = class _FreshEntity extends BaseEntity {
867
+ /** After manual construction `id` is irrelevant. Refer to `uuid` only, because that will be inserted into DB */
868
+ constructor() {
869
+ super();
870
+ __publicField(this, "id");
871
+ __publicField(this, "uuid");
872
+ __publicField(this, "created_at");
873
+ __publicField(this, "updated_at");
874
+ // for soft delete methods by typeorm
875
+ __publicField(this, "deleted_at");
876
+ this.id = 0;
877
+ this.uuid = v4_default();
878
+ const newDate = /* @__PURE__ */ new Date();
879
+ this.created_at = newDate;
880
+ this.updated_at = newDate;
881
+ this.deleted_at = null;
882
+ }
883
+ };
884
+ __name(_FreshEntity, "FreshEntity");
885
+ var FreshEntity = _FreshEntity;
886
+ _ts_decorate([
887
+ PrimaryGeneratedColumn("increment"),
888
+ _ts_metadata("design:type", Number)
889
+ ], FreshEntity.prototype, "id", void 0);
890
+ _ts_decorate([
891
+ Index({
892
+ unique: true
893
+ }),
894
+ Column({
895
+ type: "uuid",
896
+ default: /* @__PURE__ */ __name(() => "timescale.uuid_generate_v4()", "default")
897
+ }),
898
+ _ts_metadata("design:type", String)
899
+ ], FreshEntity.prototype, "uuid", void 0);
900
+ _ts_decorate([
901
+ CreateDateColumn({
902
+ type: "timestamptz"
903
+ }),
904
+ _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
905
+ ], FreshEntity.prototype, "created_at", void 0);
906
+ _ts_decorate([
907
+ UpdateDateColumn({
908
+ type: "timestamptz"
909
+ }),
910
+ _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
911
+ ], FreshEntity.prototype, "updated_at", void 0);
912
+ _ts_decorate([
913
+ DeleteDateColumn({
914
+ type: "timestamptz",
915
+ nullable: true
916
+ }),
917
+ _ts_metadata("design:type", Object)
918
+ ], FreshEntity.prototype, "deleted_at", void 0);
919
+
920
+ // src/database/entities/fresh-hyper-entity.ts
921
+ import { BaseEntity as BaseEntity2, PrimaryColumn } from "typeorm";
922
+
923
+ // src/database/decorators/timestamp-column.ts
924
+ import { Column as Column2 } from "typeorm";
925
+ function TimestampColumn(options = {}) {
926
+ const defaultOptions = {
927
+ type: "timestamptz",
928
+ nullable: false,
929
+ default: /* @__PURE__ */ __name(() => "CURRENT_TIMESTAMP", "default"),
930
+ ...options
931
+ };
932
+ return Column2(defaultOptions);
933
+ }
934
+ __name(TimestampColumn, "TimestampColumn");
935
+
936
+ // src/database/entities/fresh-hyper-entity.ts
937
+ function _ts_decorate2(decorators, target, key, desc) {
938
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
939
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
940
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
941
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
942
+ }
943
+ __name(_ts_decorate2, "_ts_decorate");
944
+ function _ts_metadata2(k, v) {
945
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
946
+ }
947
+ __name(_ts_metadata2, "_ts_metadata");
948
+ var _FreshHyperEntity = class _FreshHyperEntity extends BaseEntity2 {
949
+ /** After manual construction `id` is irrelevant */
950
+ constructor(timestamp) {
951
+ super();
952
+ // input timestamp as PK
953
+ __publicField(this, "timestamp");
954
+ // just info column about time of insert
955
+ __publicField(this, "created_at");
956
+ this.timestamp = timestamp != null ? timestamp : /* @__PURE__ */ new Date();
957
+ this.created_at = /* @__PURE__ */ new Date();
958
+ }
959
+ };
960
+ __name(_FreshHyperEntity, "FreshHyperEntity");
961
+ var FreshHyperEntity = _FreshHyperEntity;
962
+ _ts_decorate2([
963
+ PrimaryColumn({
964
+ type: "timestamptz"
965
+ }),
966
+ _ts_metadata2("design:type", typeof Date === "undefined" ? Object : Date)
967
+ ], FreshHyperEntity.prototype, "timestamp", void 0);
968
+ _ts_decorate2([
969
+ TimestampColumn(),
970
+ _ts_metadata2("design:type", typeof Date === "undefined" ? Object : Date)
971
+ ], FreshHyperEntity.prototype, "created_at", void 0);
972
+
973
+ // src/database/entities/fresh-translation-entity.ts
974
+ import { PrimaryGeneratedColumn as PrimaryGeneratedColumn2, Column as Column3, BaseEntity as BaseEntity3, Check } from "typeorm";
975
+
976
+ // src/enums/action-command-code.ts
977
+ var ActionCommandCode = /* @__PURE__ */ (function(ActionCommandCode2) {
978
+ ActionCommandCode2[ActionCommandCode2["RESTART_PC"] = 1] = "RESTART_PC";
979
+ ActionCommandCode2[ActionCommandCode2["RESTART_APPLICATION"] = 2] = "RESTART_APPLICATION";
980
+ ActionCommandCode2[ActionCommandCode2["RESTART_ROUTER"] = 3] = "RESTART_ROUTER";
981
+ ActionCommandCode2[ActionCommandCode2["RESTART_REMOTE_CONTROL"] = 4] = "RESTART_REMOTE_CONTROL";
982
+ ActionCommandCode2[ActionCommandCode2["SYNCHRONIZE"] = 5] = "SYNCHRONIZE";
983
+ ActionCommandCode2[ActionCommandCode2["DIAGNOSE_LOCKS"] = 6] = "DIAGNOSE_LOCKS";
984
+ ActionCommandCode2[ActionCommandCode2["SYNCHRONIZE_CONFIG"] = 7] = "SYNCHRONIZE_CONFIG";
985
+ return ActionCommandCode2;
986
+ })({});
987
+
988
+ // src/enums/depot-pool-status.ts
989
+ var DepotPoolStatus = /* @__PURE__ */ (function(DepotPoolStatus2) {
990
+ DepotPoolStatus2[DepotPoolStatus2["NEW"] = 0] = "NEW";
991
+ DepotPoolStatus2[DepotPoolStatus2["PICKED"] = 1] = "PICKED";
992
+ DepotPoolStatus2[DepotPoolStatus2["WRITTEN_OFF"] = 2] = "WRITTEN_OFF";
993
+ DepotPoolStatus2[DepotPoolStatus2["ACTIVE"] = 3] = "ACTIVE";
994
+ DepotPoolStatus2[DepotPoolStatus2["TERMINATED"] = 4] = "TERMINATED";
995
+ return DepotPoolStatus2;
996
+ })({});
997
+
998
+ // src/enums/http-status.ts
999
+ var HttpStatus = /* @__PURE__ */ (function(HttpStatus2) {
1000
+ HttpStatus2[HttpStatus2["CONTINUE"] = 100] = "CONTINUE";
1001
+ HttpStatus2[HttpStatus2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
1002
+ HttpStatus2[HttpStatus2["PROCESSING"] = 102] = "PROCESSING";
1003
+ HttpStatus2[HttpStatus2["EARLY_HINTS"] = 103] = "EARLY_HINTS";
1004
+ HttpStatus2[HttpStatus2["OK"] = 200] = "OK";
1005
+ HttpStatus2[HttpStatus2["CREATED"] = 201] = "CREATED";
1006
+ HttpStatus2[HttpStatus2["ACCEPTED"] = 202] = "ACCEPTED";
1007
+ HttpStatus2[HttpStatus2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
1008
+ HttpStatus2[HttpStatus2["NO_CONTENT"] = 204] = "NO_CONTENT";
1009
+ HttpStatus2[HttpStatus2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
1010
+ HttpStatus2[HttpStatus2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
1011
+ HttpStatus2[HttpStatus2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
1012
+ HttpStatus2[HttpStatus2["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
1013
+ HttpStatus2[HttpStatus2["IM_USED"] = 226] = "IM_USED";
1014
+ HttpStatus2[HttpStatus2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
1015
+ HttpStatus2[HttpStatus2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
1016
+ HttpStatus2[HttpStatus2["FOUND"] = 302] = "FOUND";
1017
+ HttpStatus2[HttpStatus2["SEE_OTHER"] = 303] = "SEE_OTHER";
1018
+ HttpStatus2[HttpStatus2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
1019
+ HttpStatus2[HttpStatus2["USE_PROXY"] = 305] = "USE_PROXY";
1020
+ HttpStatus2[HttpStatus2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
1021
+ HttpStatus2[HttpStatus2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
1022
+ HttpStatus2[HttpStatus2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
1023
+ HttpStatus2[HttpStatus2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
1024
+ HttpStatus2[HttpStatus2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
1025
+ HttpStatus2[HttpStatus2["FORBIDDEN"] = 403] = "FORBIDDEN";
1026
+ HttpStatus2[HttpStatus2["NOT_FOUND"] = 404] = "NOT_FOUND";
1027
+ HttpStatus2[HttpStatus2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
1028
+ HttpStatus2[HttpStatus2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
1029
+ HttpStatus2[HttpStatus2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
1030
+ HttpStatus2[HttpStatus2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
1031
+ HttpStatus2[HttpStatus2["CONFLICT"] = 409] = "CONFLICT";
1032
+ HttpStatus2[HttpStatus2["GONE"] = 410] = "GONE";
1033
+ HttpStatus2[HttpStatus2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
1034
+ HttpStatus2[HttpStatus2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
1035
+ HttpStatus2[HttpStatus2["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
1036
+ HttpStatus2[HttpStatus2["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
1037
+ HttpStatus2[HttpStatus2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
1038
+ HttpStatus2[HttpStatus2["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
1039
+ HttpStatus2[HttpStatus2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
1040
+ HttpStatus2[HttpStatus2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
1041
+ HttpStatus2[HttpStatus2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
1042
+ HttpStatus2[HttpStatus2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
1043
+ HttpStatus2[HttpStatus2["LOCKED"] = 423] = "LOCKED";
1044
+ HttpStatus2[HttpStatus2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
1045
+ HttpStatus2[HttpStatus2["TOO_EARLY"] = 425] = "TOO_EARLY";
1046
+ HttpStatus2[HttpStatus2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
1047
+ HttpStatus2[HttpStatus2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
1048
+ HttpStatus2[HttpStatus2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
1049
+ HttpStatus2[HttpStatus2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
1050
+ HttpStatus2[HttpStatus2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
1051
+ HttpStatus2[HttpStatus2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
1052
+ HttpStatus2[HttpStatus2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
1053
+ HttpStatus2[HttpStatus2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
1054
+ HttpStatus2[HttpStatus2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
1055
+ HttpStatus2[HttpStatus2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
1056
+ HttpStatus2[HttpStatus2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
1057
+ HttpStatus2[HttpStatus2["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
1058
+ HttpStatus2[HttpStatus2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
1059
+ HttpStatus2[HttpStatus2["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
1060
+ HttpStatus2[HttpStatus2["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
1061
+ HttpStatus2[HttpStatus2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
1062
+ return HttpStatus2;
1063
+ })({});
1064
+
1065
+ // src/enums/language-code.ts
1066
+ var LanguageCode = /* @__PURE__ */ (function(LanguageCode2) {
1067
+ LanguageCode2["CS"] = "cs";
1068
+ LanguageCode2["EN"] = "en";
1069
+ LanguageCode2["DE"] = "de";
1070
+ LanguageCode2["PL"] = "pl";
1071
+ LanguageCode2["SK"] = "sk";
1072
+ return LanguageCode2;
1073
+ })({});
1074
+
1075
+ // src/enums/payment-method.ts
1076
+ var PaymentMethod = /* @__PURE__ */ (function(PaymentMethod2) {
1077
+ PaymentMethod2[PaymentMethod2["CODE"] = 0] = "CODE";
1078
+ PaymentMethod2[PaymentMethod2["CARD"] = 1] = "CARD";
1079
+ PaymentMethod2[PaymentMethod2["NONE"] = 2] = "NONE";
1080
+ return PaymentMethod2;
1081
+ })({});
1082
+
1083
+ // src/enums/transaction-type.ts
1084
+ var TransactionType = /* @__PURE__ */ (function(TransactionType2) {
1085
+ TransactionType2[TransactionType2["WRITEOFF"] = 0] = "WRITEOFF";
1086
+ TransactionType2[TransactionType2["SALE"] = 1] = "SALE";
1087
+ TransactionType2[TransactionType2["LOST"] = 2] = "LOST";
1088
+ TransactionType2[TransactionType2["ADD"] = 3] = "ADD";
1089
+ TransactionType2[TransactionType2["DELIVERY"] = 4] = "DELIVERY";
1090
+ TransactionType2[TransactionType2["DEPOT_WRITEOFF"] = 5] = "DEPOT_WRITEOFF";
1091
+ TransactionType2[TransactionType2["DEPOT_ADD"] = 6] = "DEPOT_ADD";
1092
+ TransactionType2[TransactionType2["RETURN"] = 7] = "RETURN";
1093
+ TransactionType2[TransactionType2["INVENTORY_SURPLUS"] = 8] = "INVENTORY_SURPLUS";
1094
+ TransactionType2[TransactionType2["INVENTORY_MISSING"] = 9] = "INVENTORY_MISSING";
1095
+ return TransactionType2;
1096
+ })({});
1097
+
1098
+ // src/database/entities/fresh-translation-entity.ts
1099
+ function _ts_decorate3(decorators, target, key, desc) {
1100
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1101
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1102
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1103
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1104
+ }
1105
+ __name(_ts_decorate3, "_ts_decorate");
1106
+ function _ts_metadata3(k, v) {
1107
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1108
+ }
1109
+ __name(_ts_metadata3, "_ts_metadata");
1110
+ var languageValues = Object.values(LanguageCode).map((v) => `'${v}'`).join(",");
1111
+ var _FreshTranslationBase = class _FreshTranslationBase extends BaseEntity3 {
1112
+ constructor() {
1113
+ super();
1114
+ __publicField(this, "id");
1115
+ __publicField(this, "languageCode");
1116
+ this.id = 0;
1117
+ this.languageCode = LanguageCode.CS;
1118
+ }
1119
+ };
1120
+ __name(_FreshTranslationBase, "FreshTranslationBase");
1121
+ var FreshTranslationBase = _FreshTranslationBase;
1122
+ _ts_decorate3([
1123
+ PrimaryGeneratedColumn2(),
1124
+ _ts_metadata3("design:type", Number)
1125
+ ], FreshTranslationBase.prototype, "id", void 0);
1126
+ _ts_decorate3([
1127
+ Column3({
1128
+ type: "varchar",
1129
+ length: 3,
1130
+ nullable: false
1131
+ }),
1132
+ Check(`"languageCode" IN (${languageValues})`),
1133
+ _ts_metadata3("design:type", typeof LanguageCode === "undefined" ? Object : LanguageCode)
1134
+ ], FreshTranslationBase.prototype, "languageCode", void 0);
1135
+
1136
+ // src/database/dao/fresh-dao.ts
1137
+ var _FreshDao = class _FreshDao {
1138
+ };
1139
+ __name(_FreshDao, "FreshDao");
1140
+ var FreshDao = _FreshDao;
1141
+
1142
+ // src/common/schema/entities/category.entity.ts
1143
+ function _ts_decorate4(decorators, target, key, desc) {
1144
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1145
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1146
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1147
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1148
+ }
1149
+ __name(_ts_decorate4, "_ts_decorate");
1150
+ var _Category = class _Category extends FreshEntity {
1151
+ };
1152
+ __name(_Category, "Category");
1153
+ var Category = _Category;
1154
+ Category = _ts_decorate4([
1155
+ Entity()
1156
+ ], Category);
1157
+
1158
+ // src/common/schema/entities/device.entity.ts
1159
+ import { Entity as Entity2 } from "typeorm";
1160
+ function _ts_decorate5(decorators, target, key, desc) {
1161
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1162
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1163
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1164
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1165
+ }
1166
+ __name(_ts_decorate5, "_ts_decorate");
1167
+ var _Device = class _Device extends FreshEntity {
1168
+ };
1169
+ __name(_Device, "Device");
1170
+ var Device = _Device;
1171
+ Device = _ts_decorate5([
1172
+ Entity2()
1173
+ ], Device);
1174
+
1175
+ // src/common/schema/entities/manufacturer.entity.ts
1176
+ import { Entity as Entity3 } from "typeorm";
1177
+ function _ts_decorate6(decorators, target, key, desc) {
1178
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1179
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1180
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1181
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1182
+ }
1183
+ __name(_ts_decorate6, "_ts_decorate");
1184
+ var _Manufacturer = class _Manufacturer extends FreshEntity {
1185
+ };
1186
+ __name(_Manufacturer, "Manufacturer");
1187
+ var Manufacturer = _Manufacturer;
1188
+ Manufacturer = _ts_decorate6([
1189
+ Entity3()
1190
+ ], Manufacturer);
1191
+
1192
+ // src/common/schema/entities/product.entity.ts
1193
+ import { Entity as Entity4 } from "typeorm";
1194
+ function _ts_decorate7(decorators, target, key, desc) {
1195
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1196
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1197
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1198
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1199
+ }
1200
+ __name(_ts_decorate7, "_ts_decorate");
1201
+ var _Product = class _Product extends FreshEntity {
1202
+ };
1203
+ __name(_Product, "Product");
1204
+ var Product = _Product;
1205
+ Product = _ts_decorate7([
1206
+ Entity4()
1207
+ ], Product);
1208
+
1209
+ // src/common/schema/entities/subcategory.entity.ts
1210
+ import { Entity as Entity5 } from "typeorm";
1211
+ function _ts_decorate8(decorators, target, key, desc) {
1212
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1213
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1214
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1215
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1216
+ }
1217
+ __name(_ts_decorate8, "_ts_decorate");
1218
+ var _Subcategory = class _Subcategory extends FreshEntity {
1219
+ };
1220
+ __name(_Subcategory, "Subcategory");
1221
+ var Subcategory = _Subcategory;
1222
+ Subcategory = _ts_decorate8([
1223
+ Entity5()
1224
+ ], Subcategory);
1225
+
1226
+ // src/core/data-helper.ts
1227
+ var _DataHelper = class _DataHelper {
1228
+ constructor(startDataRetrieve = true, deviceIds) {
1229
+ __publicField(this, "_data");
1230
+ __publicField(this, "_dataPromise", null);
1231
+ __publicField(this, "deviceIds");
1232
+ this.deviceIds = deviceIds;
1233
+ if (startDataRetrieve) {
1234
+ this._dataPromise = this.startDataRetrieval();
1235
+ }
1236
+ }
1237
+ get data() {
1238
+ return this._data;
1239
+ }
1240
+ set data(value) {
1241
+ this._data = value;
1242
+ }
1243
+ get dataPromise() {
1244
+ return this._dataPromise;
1245
+ }
1246
+ set dataPromise(value) {
1247
+ this._dataPromise = value;
1248
+ }
1249
+ async getData() {
1250
+ if (this._dataPromise) {
1251
+ return await this._dataPromise;
1252
+ }
1253
+ if (this._data === void 0) {
1254
+ this._dataPromise = this.startDataRetrieval();
1255
+ return this._dataPromise;
1256
+ }
1257
+ return this._data;
1258
+ }
1259
+ };
1260
+ __name(_DataHelper, "DataHelper");
1261
+ var DataHelper = _DataHelper;
1262
+
1263
+ // src/core/class/fresh-job.ts
1264
+ import { scheduleJob } from "node-schedule";
1265
+ var _FreshJob = class _FreshJob extends Singleton {
1266
+ /**
1267
+ * @param cronExpression must be cron of just numbers ex.: `0 5 * * 4`
1268
+ * By default timezone is added " Europe/Prague"
1269
+ */
1270
+ constructor(jobName, cronExpression, jobEnabled) {
1271
+ super();
1272
+ __publicField(this, "_jobName");
1273
+ __publicField(this, "_cronExpression");
1274
+ __publicField(this, "_job", null);
1275
+ this._jobName = jobName;
1276
+ if (!isValidCron(cronExpression)) {
1277
+ throw new Error(`Job ${this.jobName} cannot be constructed with invalid cron: "${cronExpression}"`);
1278
+ }
1279
+ this._cronExpression = cronExpression;
1280
+ if (jobEnabled) {
1281
+ this._job = scheduleJob({
1282
+ rule: this._cronExpression,
1283
+ tz: "Europe/Prague"
1284
+ }, async () => {
1285
+ await this.invoke();
1286
+ });
1287
+ if (!this._job) {
1288
+ throw new Error(`Job ${this._jobName} could not be scheduled`);
1289
+ }
1290
+ }
1291
+ this.onInit();
1292
+ }
1293
+ /** Just logging */
1294
+ onInit(rescheduled) {
1295
+ console.log(`Job ${this.jobName} ${rescheduled ? "rescheduled" : "initialized"} with cron rule: "${this.cronExpression}"`);
1296
+ }
1297
+ get jobName() {
1298
+ return this._jobName;
1299
+ }
1300
+ set jobName(value) {
1301
+ this._jobName = value;
1302
+ }
1303
+ get cronExpression() {
1304
+ return this._cronExpression;
1305
+ }
1306
+ set cronExpression(value) {
1307
+ this._cronExpression = value;
1308
+ }
1309
+ get job() {
1310
+ return this._job;
1311
+ }
1312
+ set job(value) {
1313
+ this._job = value;
1314
+ }
1315
+ };
1316
+ __name(_FreshJob, "FreshJob");
1317
+ var FreshJob = _FreshJob;
1318
+
1319
+ // src/core/errors/api-error.ts
1320
+ var _ApiError = class _ApiError extends Error {
1321
+ constructor(statusCode, status, detail) {
1322
+ super();
1323
+ __publicField(this, "_statusCode");
1324
+ __publicField(this, "_statusDto");
1325
+ this._statusCode = statusCode;
1326
+ this._statusDto = new StatusDto(status, detail);
1327
+ }
1328
+ get statusCode() {
1329
+ return this._statusCode;
1330
+ }
1331
+ get statusDto() {
1332
+ return this._statusDto;
1333
+ }
1334
+ };
1335
+ __name(_ApiError, "ApiError");
1336
+ var ApiError = _ApiError;
1337
+
1338
+ // src/config/eslint-config.ts
1339
+ import tseslint from "typescript-eslint";
1340
+ import eslintPluginPrettier from "eslint-plugin-prettier";
1341
+ import eslintConfigPrettier from "eslint-config-prettier";
1342
+ var FRESH_ESLINT_CONFIG = [
1343
+ {
1344
+ // Prettier integration
1345
+ ...eslintConfigPrettier,
1346
+ // Affected files
1347
+ files: [
1348
+ "**/*.ts",
1349
+ "**/*.tsx"
1350
+ ],
1351
+ ignores: [
1352
+ "dist/**",
1353
+ "node_modules/**",
1354
+ "build/**",
1355
+ "**/*.js",
1356
+ "**/*.mjs",
1357
+ "**/*-migration.ts",
1358
+ "**/*-migration.js"
1359
+ ],
1360
+ languageOptions: {
1361
+ parser: tseslint.parser,
1362
+ ecmaVersion: "latest",
1363
+ sourceType: "module"
1364
+ },
1365
+ // Extra plugins declared
1366
+ plugins: {
1367
+ "@typescript-eslint": tseslint.plugin,
1368
+ prettier: eslintPluginPrettier
1369
+ },
1370
+ rules: {
1371
+ // Eslint rules
1372
+ // no lets or vars
1373
+ "prefer-const": "error",
1374
+ // blocks ("red" === color) these ifs
1375
+ yoda: [
1376
+ "error",
1377
+ "never"
1378
+ ],
1379
+ "no-multiple-empty-lines": [
1380
+ "error",
1381
+ {
1382
+ max: 1
1383
+ }
1384
+ ],
1385
+ // semi-colons
1386
+ semi: [
1387
+ "error",
1388
+ "always"
1389
+ ],
1390
+ // forces block for all control statements (forbid one-line returns)
1391
+ curly: [
1392
+ "error",
1393
+ "all"
1394
+ ],
1395
+ // makes spaces between brackets
1396
+ "object-curly-spacing": [
1397
+ "error",
1398
+ "always"
1399
+ ],
1400
+ // checks same if/else conditions
1401
+ "no-dupe-else-if": "error",
1402
+ // keeps imports from one package in same declaration
1403
+ "no-duplicate-imports": "error",
1404
+ // blocks simple '=' in condition blocks
1405
+ "no-cond-assign": [
1406
+ "error",
1407
+ "always"
1408
+ ],
1409
+ // forbids promise inside promise
1410
+ "no-async-promise-executor": "error",
1411
+ // watches possible falltrough in switch cases
1412
+ "no-fallthrough": "error",
1413
+ // use === instead of ==
1414
+ eqeqeq: [
1415
+ "error",
1416
+ "always"
1417
+ ],
1418
+ // Prettier formatting rules
1419
+ "prettier/prettier": [
1420
+ "error",
1421
+ {
1422
+ // max 100 chars per line
1423
+ printWidth: 100,
1424
+ // keep 4 spaces and no tabs
1425
+ tabWidth: 4,
1426
+ useTabs: false,
1427
+ // enforce semicolons
1428
+ semi: true,
1429
+ // prefers ""
1430
+ singleQuote: false,
1431
+ // last comma in array or object
1432
+ trailingComma: "es5",
1433
+ // enable spacing next to brackets
1434
+ bracketSpacing: true,
1435
+ // enables CRLF eol which is enforced by git
1436
+ endOfLine: "auto"
1437
+ }
1438
+ ],
1439
+ // Namin conventions
1440
+ "@typescript-eslint/naming-convention": [
1441
+ "error",
1442
+ {
1443
+ selector: [
1444
+ "variable",
1445
+ "function"
1446
+ ],
1447
+ format: [
1448
+ "camelCase"
1449
+ ],
1450
+ leadingUnderscore: "allow"
1451
+ },
1452
+ {
1453
+ selector: "class",
1454
+ format: [
1455
+ "PascalCase"
1456
+ ]
1457
+ },
1458
+ {
1459
+ selector: "variable",
1460
+ modifiers: [
1461
+ "const",
1462
+ "exported"
1463
+ ],
1464
+ format: [
1465
+ "UPPER_CASE",
1466
+ "PascalCase"
1467
+ ]
1468
+ },
1469
+ {
1470
+ selector: "property",
1471
+ modifiers: [
1472
+ "readonly"
1473
+ ],
1474
+ format: [
1475
+ "UPPER_CASE"
1476
+ ]
1477
+ }
1478
+ ]
1479
+ }
1480
+ }
1481
+ ];
1482
+ var eslint_config_default = FRESH_ESLINT_CONFIG;
1483
+
1484
+ // src/config/datasource.ts
1485
+ var import_dotenv = __toESM(require_main());
1486
+ import path from "path";
1487
+ import { SnakeNamingStrategy } from "typeorm-naming-strategies";
1488
+ (0, import_dotenv.config)();
1489
+ var basePath = process.cwd();
1490
+ var isTs = process.env.LOCAL === "true";
1491
+ var PG_DATA_SOURCE_OPTIONS = {
1492
+ applicationName: "<service-name>",
1493
+ name: "<service-name>-connection",
1494
+ type: "postgres",
1495
+ host: process.env.POSTGRE_SQL_HOST || "<host>",
1496
+ port: Number(process.env.POSTGRE_SQL_PORT || "3300"),
1497
+ username: process.env.POSTGRE_SQL_USER || "<user>",
1498
+ password: process.env.POSTGRE_SQL_PASSWORD || "<password>",
1499
+ database: process.env.POSTGRE_SQL_DATABASE || "<database>",
1500
+ schema: process.env.POSTGRE_SQL_SCHEMA || "<scheme>",
1501
+ entities: [
1502
+ path.join(basePath, isTs ? "src/entity/*.{ts,js}" : "build/entity/*.js")
1503
+ ],
1504
+ migrations: [
1505
+ path.join(basePath, isTs ? "src/migration/*.{ts,js}" : "build/migration/*.js")
1506
+ ],
1507
+ migrationsRun: process.env.RUN_MIGRATIONS === "true",
1508
+ migrationsTableName: "migrations",
1509
+ migrationsTransactionMode: "each",
1510
+ synchronize: false,
1511
+ logging: false,
1512
+ extra: {
1513
+ connectionLimit: 20
1514
+ },
1515
+ useUTC: true,
1516
+ cache: true,
1517
+ namingStrategy: new SnakeNamingStrategy()
1518
+ };
1519
+ var datasource_default = PG_DATA_SOURCE_OPTIONS;
1520
+ export {
1521
+ AMOUNT_UNIT,
1522
+ ActionCommandCode,
1523
+ ApiError,
1524
+ Category,
1525
+ DataHelper,
1526
+ DateUtils,
1527
+ DepotPoolStatus,
1528
+ Device,
1529
+ FreshDao,
1530
+ FreshEntity,
1531
+ FreshHyperEntity,
1532
+ FreshJob,
1533
+ FreshTranslationBase,
1534
+ HttpStatus,
1535
+ LanguageCode,
1536
+ Manufacturer,
1537
+ PaymentMethod,
1538
+ datasource_default as PgDataSourceOptions,
1539
+ Product,
1540
+ SinglePromiseWaiter,
1541
+ Singleton,
1542
+ StatusDto,
1543
+ Subcategory,
1544
+ TimestampColumn,
1545
+ TransactionType,
1546
+ createDeferred,
1547
+ eslint_config_default as freshEslintConfig,
1548
+ isValidCron,
1549
+ logger
1550
+ };
1551
+ //# sourceMappingURL=index.mjs.map