@freshpointcz/fresh-core 0.0.16 → 0.0.18
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.d.mts +98 -5
- package/dist/index.d.ts +98 -5
- package/dist/index.js +160 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -108,7 +108,7 @@ var require_main = __commonJS({
|
|
|
108
108
|
var fs = __require("fs");
|
|
109
109
|
var path2 = __require("path");
|
|
110
110
|
var os = __require("os");
|
|
111
|
-
var
|
|
111
|
+
var crypto = __require("crypto");
|
|
112
112
|
var packageJson = require_package();
|
|
113
113
|
var version = packageJson.version;
|
|
114
114
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
@@ -355,7 +355,7 @@ var require_main = __commonJS({
|
|
|
355
355
|
const authTag = ciphertext.subarray(-16);
|
|
356
356
|
ciphertext = ciphertext.subarray(12, -16);
|
|
357
357
|
try {
|
|
358
|
-
const aesgcm =
|
|
358
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
359
359
|
aesgcm.setAuthTag(authTag);
|
|
360
360
|
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
361
361
|
} catch (error) {
|
|
@@ -648,56 +648,6 @@ __name(_SinglePromiseWaiter, "SinglePromiseWaiter");
|
|
|
648
648
|
__publicField(_SinglePromiseWaiter, "_instance");
|
|
649
649
|
var SinglePromiseWaiter = _SinglePromiseWaiter;
|
|
650
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
651
|
// src/common/utils/is-cron-valid.ts
|
|
702
652
|
function isValidCron(expr) {
|
|
703
653
|
const parts = expr.trim().split(/\s+/);
|
|
@@ -822,46 +772,53 @@ import { Entity } from "typeorm";
|
|
|
822
772
|
// src/database/entities/fresh-entity.ts
|
|
823
773
|
import { BaseEntity, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index, Column } from "typeorm";
|
|
824
774
|
|
|
825
|
-
// ../../node_modules/uuid/dist/esm
|
|
826
|
-
|
|
775
|
+
// ../../node_modules/uuid/dist/esm/stringify.js
|
|
776
|
+
var byteToHex = [];
|
|
777
|
+
for (let i = 0; i < 256; ++i) {
|
|
778
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
779
|
+
}
|
|
780
|
+
function unsafeStringify(arr, offset = 0) {
|
|
781
|
+
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();
|
|
782
|
+
}
|
|
783
|
+
__name(unsafeStringify, "unsafeStringify");
|
|
784
|
+
|
|
785
|
+
// ../../node_modules/uuid/dist/esm/rng.js
|
|
786
|
+
import { randomFillSync } from "crypto";
|
|
827
787
|
var rnds8Pool = new Uint8Array(256);
|
|
828
788
|
var poolPtr = rnds8Pool.length;
|
|
829
789
|
function rng() {
|
|
830
790
|
if (poolPtr > rnds8Pool.length - 16) {
|
|
831
|
-
|
|
791
|
+
randomFillSync(rnds8Pool);
|
|
832
792
|
poolPtr = 0;
|
|
833
793
|
}
|
|
834
794
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
835
795
|
}
|
|
836
796
|
__name(rng, "rng");
|
|
837
797
|
|
|
838
|
-
// ../../node_modules/uuid/dist/esm
|
|
839
|
-
|
|
840
|
-
for (let i = 0; i < 256; ++i) {
|
|
841
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
|
842
|
-
}
|
|
843
|
-
function unsafeStringify(arr, offset = 0) {
|
|
844
|
-
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]];
|
|
845
|
-
}
|
|
846
|
-
__name(unsafeStringify, "unsafeStringify");
|
|
847
|
-
|
|
848
|
-
// ../../node_modules/uuid/dist/esm-node/native.js
|
|
849
|
-
import crypto2 from "crypto";
|
|
798
|
+
// ../../node_modules/uuid/dist/esm/native.js
|
|
799
|
+
import { randomUUID } from "crypto";
|
|
850
800
|
var native_default = {
|
|
851
|
-
randomUUID
|
|
801
|
+
randomUUID
|
|
852
802
|
};
|
|
853
803
|
|
|
854
|
-
// ../../node_modules/uuid/dist/esm
|
|
804
|
+
// ../../node_modules/uuid/dist/esm/v4.js
|
|
855
805
|
function v4(options, buf, offset) {
|
|
806
|
+
var _a, _b, _c;
|
|
856
807
|
if (native_default.randomUUID && !buf && !options) {
|
|
857
808
|
return native_default.randomUUID();
|
|
858
809
|
}
|
|
859
810
|
options = options || {};
|
|
860
|
-
const rnds = options.random
|
|
811
|
+
const rnds = (_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng();
|
|
812
|
+
if (rnds.length < 16) {
|
|
813
|
+
throw new Error("Random bytes length must be >= 16");
|
|
814
|
+
}
|
|
861
815
|
rnds[6] = rnds[6] & 15 | 64;
|
|
862
816
|
rnds[8] = rnds[8] & 63 | 128;
|
|
863
817
|
if (buf) {
|
|
864
818
|
offset = offset || 0;
|
|
819
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
820
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
821
|
+
}
|
|
865
822
|
for (let i = 0; i < 16; ++i) {
|
|
866
823
|
buf[offset + i] = rnds[i];
|
|
867
824
|
}
|
|
@@ -1164,6 +1121,83 @@ var _FreshDao = class _FreshDao {
|
|
|
1164
1121
|
__name(_FreshDao, "FreshDao");
|
|
1165
1122
|
var FreshDao = _FreshDao;
|
|
1166
1123
|
|
|
1124
|
+
// src/database/subscribers/base-entity-change.subscriber.ts
|
|
1125
|
+
var _BaseEntityChangeSubscriber = class _BaseEntityChangeSubscriber {
|
|
1126
|
+
// ─── TypeORM lifecycle hooks ────────────────────────────────────────
|
|
1127
|
+
afterInsert(event) {
|
|
1128
|
+
var _a;
|
|
1129
|
+
const id = (_a = event.entity) == null ? void 0 : _a.id;
|
|
1130
|
+
if (!id) {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
if (event.queryRunner.isTransactionActive) {
|
|
1134
|
+
this.addPending(event, id, "created");
|
|
1135
|
+
} else {
|
|
1136
|
+
console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
|
|
1137
|
+
this.sendNotification(id, "created", event.queryRunner.manager);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
afterUpdate(event) {
|
|
1141
|
+
var _a, _b, _c;
|
|
1142
|
+
const id = (_c = (_a = event.entity) == null ? void 0 : _a.id) != null ? _c : (_b = event.databaseEntity) == null ? void 0 : _b.id;
|
|
1143
|
+
if (!id) {
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
if (event.queryRunner.isTransactionActive) {
|
|
1147
|
+
this.addPending(event, id, "updated");
|
|
1148
|
+
} else {
|
|
1149
|
+
console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
|
|
1150
|
+
this.sendNotification(id, "updated", event.queryRunner.manager);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
afterSoftRemove(event) {
|
|
1154
|
+
var _a, _b, _c;
|
|
1155
|
+
const id = (_c = (_a = event.entity) == null ? void 0 : _a.id) != null ? _c : (_b = event.databaseEntity) == null ? void 0 : _b.id;
|
|
1156
|
+
if (!id) {
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
if (event.queryRunner.isTransactionActive) {
|
|
1160
|
+
this.addPending(event, id, "deleted");
|
|
1161
|
+
} else {
|
|
1162
|
+
console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
|
|
1163
|
+
this.sendNotification(id, "deleted", event.queryRunner.manager);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
async afterTransactionCommit(event) {
|
|
1167
|
+
var _a;
|
|
1168
|
+
const pending = (_a = event.queryRunner.data) == null ? void 0 : _a[this.PENDING_KEY];
|
|
1169
|
+
if (!pending || pending.size === 0) {
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
event.queryRunner.data[this.PENDING_KEY] = /* @__PURE__ */ new Map();
|
|
1173
|
+
for (const [id, changeEvent] of pending) {
|
|
1174
|
+
await this.sendNotification(id, changeEvent, event.connection.manager);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
// ─── Private helpers ───────────────────────────────────────────────
|
|
1178
|
+
addPending(event, id, changeEvent) {
|
|
1179
|
+
if (!event.queryRunner.data) {
|
|
1180
|
+
event.queryRunner.data = {};
|
|
1181
|
+
}
|
|
1182
|
+
if (!event.queryRunner.data[this.PENDING_KEY]) {
|
|
1183
|
+
event.queryRunner.data[this.PENDING_KEY] = /* @__PURE__ */ new Map();
|
|
1184
|
+
}
|
|
1185
|
+
const existing = event.queryRunner.data[this.PENDING_KEY].get(id);
|
|
1186
|
+
if (!existing || changeEvent === "created" || changeEvent === "deleted") {
|
|
1187
|
+
event.queryRunner.data[this.PENDING_KEY].set(id, changeEvent);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
async sendNotification(id, changeEvent, manager) {
|
|
1191
|
+
try {
|
|
1192
|
+
await this.handleNotification(id, changeEvent, manager);
|
|
1193
|
+
} catch (error) {
|
|
1194
|
+
console.error(`${this.SUBSCRIBER_NAME} - Failed to send notification: ${error instanceof Error ? error.message : error}`);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
__name(_BaseEntityChangeSubscriber, "BaseEntityChangeSubscriber");
|
|
1199
|
+
var BaseEntityChangeSubscriber = _BaseEntityChangeSubscriber;
|
|
1200
|
+
|
|
1167
1201
|
// src/common/schema/entities/category.entity.ts
|
|
1168
1202
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
1169
1203
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1297,6 +1331,40 @@ function isNumberInRange(v, min, max, options) {
|
|
|
1297
1331
|
return true;
|
|
1298
1332
|
}
|
|
1299
1333
|
__name(isNumberInRange, "isNumberInRange");
|
|
1334
|
+
var TO_BINARY_FLAG = /* @__PURE__ */ __name((v) => v === 1 || v === true ? 1 : 0, "TO_BINARY_FLAG");
|
|
1335
|
+
|
|
1336
|
+
// src/common/utils/async.utils.ts
|
|
1337
|
+
async function runWithConcurrency(items, concurrency, worker) {
|
|
1338
|
+
const queue = [
|
|
1339
|
+
...items
|
|
1340
|
+
];
|
|
1341
|
+
const runNext = /* @__PURE__ */ __name(async () => {
|
|
1342
|
+
const item = queue.shift();
|
|
1343
|
+
if (!item) {
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1346
|
+
await worker(item);
|
|
1347
|
+
await runNext();
|
|
1348
|
+
}, "runNext");
|
|
1349
|
+
await Promise.all(Array.from({
|
|
1350
|
+
length: Math.min(concurrency, items.length)
|
|
1351
|
+
}, runNext));
|
|
1352
|
+
}
|
|
1353
|
+
__name(runWithConcurrency, "runWithConcurrency");
|
|
1354
|
+
|
|
1355
|
+
// src/common/utils/patch.utils.ts
|
|
1356
|
+
function buildPatch(data, keys, transforms) {
|
|
1357
|
+
const patch = {};
|
|
1358
|
+
for (const k of keys) {
|
|
1359
|
+
const value = data[k];
|
|
1360
|
+
if (value === void 0) {
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1363
|
+
patch[k] = (transforms == null ? void 0 : transforms[k]) ? transforms[k](value) : value;
|
|
1364
|
+
}
|
|
1365
|
+
return patch;
|
|
1366
|
+
}
|
|
1367
|
+
__name(buildPatch, "buildPatch");
|
|
1300
1368
|
|
|
1301
1369
|
// src/core/data-helper.ts
|
|
1302
1370
|
var _DataHelper = class _DataHelper {
|
|
@@ -1471,6 +1539,18 @@ var _ApiError = class _ApiError extends Error {
|
|
|
1471
1539
|
__name(_ApiError, "ApiError");
|
|
1472
1540
|
var ApiError = _ApiError;
|
|
1473
1541
|
|
|
1542
|
+
// src/core/errors/business-warning.ts
|
|
1543
|
+
var _BusinessWarning = class _BusinessWarning extends Error {
|
|
1544
|
+
constructor(code, message) {
|
|
1545
|
+
super(message);
|
|
1546
|
+
__publicField(this, "code");
|
|
1547
|
+
this.code = code;
|
|
1548
|
+
this.name = "BusinessWarning";
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
__name(_BusinessWarning, "BusinessWarning");
|
|
1552
|
+
var BusinessWarning = _BusinessWarning;
|
|
1553
|
+
|
|
1474
1554
|
// src/types/maybe-type.ts
|
|
1475
1555
|
function isMaybe(v, inner) {
|
|
1476
1556
|
return v === null || inner(v);
|
|
@@ -1663,6 +1743,8 @@ export {
|
|
|
1663
1743
|
AMOUNT_UNIT,
|
|
1664
1744
|
ActionCommandCode,
|
|
1665
1745
|
ApiError,
|
|
1746
|
+
BaseEntityChangeSubscriber,
|
|
1747
|
+
BusinessWarning,
|
|
1666
1748
|
Category,
|
|
1667
1749
|
DataHelper,
|
|
1668
1750
|
DateUtils,
|
|
@@ -1683,8 +1765,10 @@ export {
|
|
|
1683
1765
|
Singleton,
|
|
1684
1766
|
StatusDto,
|
|
1685
1767
|
Subcategory,
|
|
1768
|
+
TO_BINARY_FLAG,
|
|
1686
1769
|
TimestampColumn,
|
|
1687
1770
|
TransactionType,
|
|
1771
|
+
buildPatch,
|
|
1688
1772
|
createDeferred,
|
|
1689
1773
|
eslint_config_default as freshEslintConfig,
|
|
1690
1774
|
hasOwn,
|
|
@@ -1696,6 +1780,6 @@ export {
|
|
|
1696
1780
|
isObject,
|
|
1697
1781
|
isString,
|
|
1698
1782
|
isValidCron,
|
|
1699
|
-
|
|
1783
|
+
runWithConcurrency
|
|
1700
1784
|
};
|
|
1701
1785
|
//# sourceMappingURL=index.mjs.map
|