@miguelmorales13/nestkit 0.10.0 → 0.16.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/README.md +518 -12
- package/dist/audit/audit.module.d.ts +23 -0
- package/dist/audit/audit.options.d.ts +16 -0
- package/dist/audit/audit.port.d.ts +37 -0
- package/dist/audit/audit.service.d.ts +29 -0
- package/dist/audit/index.cjs +72 -0
- package/dist/audit/index.d.ts +7 -0
- package/dist/audit/index.js +72 -0
- package/dist/audit/sinks.d.ts +18 -0
- package/dist/auth/index.cjs +4 -3
- package/dist/auth/index.js +2 -1
- package/dist/auth/oauth/index.cjs +81 -13
- package/dist/auth/oauth/index.js +75 -7
- package/dist/auth/oauth/oauth-auth.service.d.ts +29 -1
- package/dist/auth/oauth/oauth.options.d.ts +11 -0
- package/dist/bootstrap/index.cjs +6 -5
- package/dist/bootstrap/index.js +5 -4
- package/dist/chunk-47FXU74G.cjs +205 -0
- package/dist/{chunk-54ZXIB5T.cjs → chunk-4GT66KQS.cjs} +4 -4
- package/dist/{chunk-J7TURDAL.cjs → chunk-67B7IYAV.cjs} +2 -2
- package/dist/{chunk-NVCI3CQI.cjs → chunk-C5DV4RAX.cjs} +6 -1
- package/dist/{chunk-KDAA6GFF.js → chunk-DABTRWA6.js} +12 -7
- package/dist/{chunk-ZA56XBCK.cjs → chunk-EBPEMVZU.cjs} +15 -0
- package/dist/{chunk-EYURGACO.js → chunk-JV4EAOF2.js} +1 -1
- package/dist/chunk-KP2ZHJSR.js +35 -0
- package/dist/{chunk-7I2Y7V52.js → chunk-KRC47OX6.js} +1 -1
- package/dist/chunk-LK3OINS7.js +205 -0
- package/dist/{chunk-A3B2EY4V.js → chunk-MLOQDUBN.js} +6 -1
- package/dist/chunk-TCAMLNUZ.js +27 -0
- package/dist/{chunk-V2M75FN3.cjs → chunk-U7QK24HL.cjs} +2 -2
- package/dist/{chunk-AOCF5QCZ.js → chunk-UIVBPNH4.js} +4 -4
- package/dist/{chunk-TJHRABML.cjs → chunk-UWDHAZVE.cjs} +12 -7
- package/dist/chunk-XHW4CTBS.js +57 -0
- package/dist/chunk-XX5ROVSC.cjs +57 -0
- package/dist/chunk-Y72D5L6I.cjs +27 -0
- package/dist/crud/crud.controller.d.ts +3 -1
- package/dist/crud/crud.service.d.ts +63 -4
- package/dist/crud/index.cjs +7 -2
- package/dist/crud/index.d.ts +2 -1
- package/dist/crud/index.js +6 -1
- package/dist/crud/list-query.dto.d.ts +23 -0
- package/dist/crud/repository.port.d.ts +33 -1
- package/dist/errors/index.cjs +4 -4
- package/dist/errors/index.js +4 -4
- package/dist/idempotency/idempotency.interceptor.d.ts +35 -0
- package/dist/idempotency/idempotency.module.d.ts +27 -0
- package/dist/idempotency/idempotency.options.d.ts +29 -0
- package/dist/idempotency/idempotency.port.d.ts +43 -0
- package/dist/idempotency/index.cjs +206 -0
- package/dist/idempotency/index.d.ts +7 -0
- package/dist/idempotency/index.js +206 -0
- package/dist/idempotency/memory.store.d.ts +24 -0
- package/dist/index.cjs +24 -13
- package/dist/index.js +29 -18
- package/dist/invoicing/adapters/facturama.invoicing.d.ts +50 -0
- package/dist/invoicing/adapters/facturapi.invoicing.d.ts +35 -0
- package/dist/invoicing/amounts.d.ts +52 -0
- package/dist/invoicing/index.cjs +577 -0
- package/dist/invoicing/index.d.ts +11 -0
- package/dist/invoicing/index.js +577 -0
- package/dist/invoicing/invoicing.module.d.ts +42 -0
- package/dist/invoicing/invoicing.options.d.ts +51 -0
- package/dist/invoicing/invoicing.port.d.ts +156 -0
- package/dist/invoicing/lines.d.ts +21 -0
- package/dist/invoicing/provider-http.d.ts +21 -0
- package/dist/media/index.cjs +57 -7
- package/dist/media/index.d.ts +2 -2
- package/dist/media/index.js +56 -6
- package/dist/media/media.options.d.ts +20 -0
- package/dist/media/media.service.d.ts +18 -1
- package/dist/payments/adapters/clip.terminal.d.ts +101 -0
- package/dist/payments/adapters/mercadopago.terminal.d.ts +74 -0
- package/dist/payments/index.cjs +795 -0
- package/dist/payments/index.d.ts +12 -0
- package/dist/payments/index.js +795 -0
- package/dist/payments/money.d.ts +20 -0
- package/dist/payments/payments-webhook.controller.d.ts +30 -0
- package/dist/payments/payments.module.d.ts +45 -0
- package/dist/payments/payments.options.d.ts +84 -0
- package/dist/payments/payments.port.d.ts +174 -0
- package/dist/payments/provider-http.d.ts +26 -0
- package/dist/response/api-response.d.ts +7 -0
- package/dist/response/index.cjs +12 -4
- package/dist/response/index.d.ts +2 -0
- package/dist/response/index.js +12 -4
- package/dist/response/paginated.d.ts +25 -0
- package/dist/response/response.interceptor.d.ts +4 -0
- package/dist/tracking/index.cjs +3 -3
- package/dist/tracking/index.d.ts +1 -1
- package/dist/tracking/index.js +2 -2
- package/dist/tracking/request-context.d.ts +22 -0
- package/package.json +25 -3
- package/dist/chunk-3CLYZC3T.cjs +0 -104
- package/dist/chunk-EBO6UKHL.js +0 -20
- package/dist/chunk-JOVBJDJ2.js +0 -104
- /package/dist/{chunk-MR2IFCZE.cjs → chunk-H2EHN366.cjs} +0 -0
- /package/dist/{chunk-NAK4WDKS.js → chunk-ODPSIFOB.js} +0 -0
package/dist/bootstrap/index.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
3
|
+
var _chunk4GT66KQScjs = require('../chunk-4GT66KQS.cjs');
|
|
4
|
+
require('../chunk-67B7IYAV.cjs');
|
|
5
|
+
require('../chunk-UWDHAZVE.cjs');
|
|
6
|
+
require('../chunk-Y72D5L6I.cjs');
|
|
7
|
+
require('../chunk-EBPEMVZU.cjs');
|
|
7
8
|
require('../chunk-R7BVS6CI.cjs');
|
|
8
9
|
require('../chunk-2REOCMUD.cjs');
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
exports.applyNestKitDefaults =
|
|
12
|
+
exports.applyNestKitDefaults = _chunk4GT66KQScjs.applyNestKitDefaults;
|
package/dist/bootstrap/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyNestKitDefaults
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-UIVBPNH4.js";
|
|
4
|
+
import "../chunk-KRC47OX6.js";
|
|
5
|
+
import "../chunk-DABTRWA6.js";
|
|
6
|
+
import "../chunk-TCAMLNUZ.js";
|
|
7
|
+
import "../chunk-KP2ZHJSR.js";
|
|
7
8
|
import "../chunk-YFYHLYHN.js";
|
|
8
9
|
import "../chunk-4MGIQFAJ.js";
|
|
9
10
|
export {
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkXX5ROVSCcjs = require('./chunk-XX5ROVSC.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkY72D5L6Icjs = require('./chunk-Y72D5L6I.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
|
|
12
|
+
|
|
13
|
+
// src/crud/list-query.dto.ts
|
|
14
|
+
var _classtransformer = require('class-transformer');
|
|
15
|
+
var _classvalidator = require('class-validator');
|
|
16
|
+
var ListQuery = class {
|
|
17
|
+
};
|
|
18
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
19
|
+
_classvalidator.IsOptional.call(void 0, ),
|
|
20
|
+
_classtransformer.Type.call(void 0, () => Number),
|
|
21
|
+
_classvalidator.IsInt.call(void 0, ),
|
|
22
|
+
_classvalidator.Min.call(void 0, 1)
|
|
23
|
+
], ListQuery.prototype, "page", 2);
|
|
24
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
25
|
+
_classvalidator.IsOptional.call(void 0, ),
|
|
26
|
+
_classtransformer.Type.call(void 0, () => Number),
|
|
27
|
+
_classvalidator.IsInt.call(void 0, ),
|
|
28
|
+
_classvalidator.Min.call(void 0, 1),
|
|
29
|
+
_classvalidator.Max.call(void 0, 200)
|
|
30
|
+
], ListQuery.prototype, "limit", 2);
|
|
31
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
32
|
+
_classvalidator.IsOptional.call(void 0, ),
|
|
33
|
+
_classvalidator.IsString.call(void 0, )
|
|
34
|
+
], ListQuery.prototype, "sortBy", 2);
|
|
35
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
36
|
+
_classvalidator.IsOptional.call(void 0, ),
|
|
37
|
+
_classvalidator.IsIn.call(void 0, ["asc", "desc"])
|
|
38
|
+
], ListQuery.prototype, "sortOrder", 2);
|
|
39
|
+
|
|
40
|
+
// src/crud/crud.service.ts
|
|
41
|
+
var BaseCrudService = class {
|
|
42
|
+
constructor(repository, options = {}) {
|
|
43
|
+
this.repository = repository;
|
|
44
|
+
this.options = options;
|
|
45
|
+
}
|
|
46
|
+
findById(id, tenantId) {
|
|
47
|
+
return this.repository.findById(id, tenantId);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* One page of rows.
|
|
51
|
+
*
|
|
52
|
+
* Everything a caller can influence is bounded here rather than in the
|
|
53
|
+
* controller, so calling the service directly is as safe as going through
|
|
54
|
+
* HTTP: the limit is capped, and filter and sort fields are checked against
|
|
55
|
+
* the allowlists before they reach the adapter.
|
|
56
|
+
*/
|
|
57
|
+
async findAll(query = {}, tenantId) {
|
|
58
|
+
const maxLimit = _nullishCoalesce(this.options.maxLimit, () => ( 100));
|
|
59
|
+
const limit = Math.min(Math.max(_nullishCoalesce(_nullishCoalesce(query.limit, () => ( this.options.defaultLimit)), () => ( 20)), 1), maxLimit);
|
|
60
|
+
const page = Math.max(_nullishCoalesce(query.page, () => ( 1)), 1);
|
|
61
|
+
const sortBy = query.sortBy && (_nullishCoalesce(this.options.sortable, () => ( []))).includes(query.sortBy) ? query.sortBy : void 0;
|
|
62
|
+
const { items, total } = await this.repository.findAll(
|
|
63
|
+
{
|
|
64
|
+
filter: this.allowedFilter(query),
|
|
65
|
+
limit,
|
|
66
|
+
offset: (page - 1) * limit,
|
|
67
|
+
sortBy,
|
|
68
|
+
sortOrder: sortBy ? _nullishCoalesce(query.sortOrder, () => ( "desc")) : void 0
|
|
69
|
+
},
|
|
70
|
+
tenantId
|
|
71
|
+
);
|
|
72
|
+
return _chunkY72D5L6Icjs.paginated.call(void 0, items, _chunkY72D5L6Icjs.buildPageMeta.call(void 0, total, page, limit));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Keeps only the query fields this service declares filterable. Anything
|
|
76
|
+
* else is dropped silently — a rejection would tell a caller which columns
|
|
77
|
+
* exist, which is the question they were asking.
|
|
78
|
+
*/
|
|
79
|
+
allowedFilter(query) {
|
|
80
|
+
const filterable = _nullishCoalesce(this.options.filterable, () => ( []));
|
|
81
|
+
if (filterable.length === 0) return void 0;
|
|
82
|
+
const filter = {};
|
|
83
|
+
for (const field of filterable) {
|
|
84
|
+
if (query[field] !== void 0) filter[field] = query[field];
|
|
85
|
+
}
|
|
86
|
+
return Object.keys(filter).length > 0 ? filter : void 0;
|
|
87
|
+
}
|
|
88
|
+
async create(data, tenantId) {
|
|
89
|
+
const created = await this.repository.create(data, tenantId);
|
|
90
|
+
await this.audit("created", created.id, { after: created, tenantId });
|
|
91
|
+
return created;
|
|
92
|
+
}
|
|
93
|
+
async update(id, data, tenantId) {
|
|
94
|
+
const before = await this.readBefore(id, tenantId);
|
|
95
|
+
const updated = await this.repository.update(id, data, tenantId);
|
|
96
|
+
await this.audit("updated", id, { before, after: updated, tenantId });
|
|
97
|
+
return updated;
|
|
98
|
+
}
|
|
99
|
+
async delete(id, tenantId) {
|
|
100
|
+
const before = await this.readBefore(id, tenantId);
|
|
101
|
+
if (this.options.deleteStrategy === "soft") {
|
|
102
|
+
await this.repository.update(id, { deletedAt: /* @__PURE__ */ new Date() }, tenantId);
|
|
103
|
+
} else {
|
|
104
|
+
await this.repository.delete(id, tenantId);
|
|
105
|
+
}
|
|
106
|
+
await this.audit(this.options.deleteStrategy === "soft" ? "soft-deleted" : "deleted", id, {
|
|
107
|
+
before,
|
|
108
|
+
tenantId
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Only when the trail is configured to want it — otherwise it is a query for nothing. */
|
|
112
|
+
async readBefore(id, tenantId) {
|
|
113
|
+
if (!_optionalChain([this, 'access', _ => _.options, 'access', _2 => _2.audit, 'optionalAccess', _3 => _3.includeBefore])) return void 0;
|
|
114
|
+
return await _asyncNullishCoalesce(await this.repository.findById(id, tenantId), async () => ( void 0));
|
|
115
|
+
}
|
|
116
|
+
async audit(action, resourceId, details) {
|
|
117
|
+
const audit = this.options.audit;
|
|
118
|
+
if (!audit) return;
|
|
119
|
+
await audit.recorder.record(
|
|
120
|
+
_chunkXX5ROVSCcjs.withRequestContext.call(void 0, {
|
|
121
|
+
action,
|
|
122
|
+
resource: audit.resource,
|
|
123
|
+
resourceId,
|
|
124
|
+
before: details.before,
|
|
125
|
+
after: details.after,
|
|
126
|
+
tenantId: details.tenantId
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/crud/crud.controller.ts
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
var _common = require('@nestjs/common');
|
|
145
|
+
function createCrudController(serviceToken, options = {}) {
|
|
146
|
+
const tenantIdOf = (req) => _optionalChain([options, 'access', _4 => _4.tenantIdExtractor, 'optionalCall', _5 => _5(req)]);
|
|
147
|
+
let CrudControllerHost = class {
|
|
148
|
+
constructor(service) {
|
|
149
|
+
this.service = service;
|
|
150
|
+
}
|
|
151
|
+
findAll(query, req) {
|
|
152
|
+
const raw = _nullishCoalesce(req.query, () => ( {}));
|
|
153
|
+
return this.service.findAll({ ...raw, ...query }, tenantIdOf(req));
|
|
154
|
+
}
|
|
155
|
+
findById(id, req) {
|
|
156
|
+
return this.service.findById(id, tenantIdOf(req));
|
|
157
|
+
}
|
|
158
|
+
create(data, req) {
|
|
159
|
+
return this.service.create(data, tenantIdOf(req));
|
|
160
|
+
}
|
|
161
|
+
update(id, data, req) {
|
|
162
|
+
return this.service.update(id, data, tenantIdOf(req));
|
|
163
|
+
}
|
|
164
|
+
remove(id, req) {
|
|
165
|
+
return this.service.delete(id, tenantIdOf(req));
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
169
|
+
_common.Get.call(void 0, ),
|
|
170
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Query.call(void 0, )),
|
|
171
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
|
|
172
|
+
], CrudControllerHost.prototype, "findAll", 1);
|
|
173
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
174
|
+
_common.Get.call(void 0, ":id"),
|
|
175
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
|
|
176
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
|
|
177
|
+
], CrudControllerHost.prototype, "findById", 1);
|
|
178
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
179
|
+
_common.Post.call(void 0, ),
|
|
180
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Body.call(void 0, )),
|
|
181
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
|
|
182
|
+
], CrudControllerHost.prototype, "create", 1);
|
|
183
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
184
|
+
_common.Patch.call(void 0, ":id"),
|
|
185
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
|
|
186
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Body.call(void 0, )),
|
|
187
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 2, _common.Req.call(void 0, ))
|
|
188
|
+
], CrudControllerHost.prototype, "update", 1);
|
|
189
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
190
|
+
_common.Delete.call(void 0, ":id"),
|
|
191
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
|
|
192
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
|
|
193
|
+
], CrudControllerHost.prototype, "remove", 1);
|
|
194
|
+
CrudControllerHost = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
195
|
+
_common.Controller.call(void 0, _nullishCoalesce(options.path, () => ( ""))),
|
|
196
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, serviceToken))
|
|
197
|
+
], CrudControllerHost);
|
|
198
|
+
return CrudControllerHost;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
exports.ListQuery = ListQuery; exports.BaseCrudService = BaseCrudService; exports.createCrudController = createCrudController;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk67B7IYAVcjs = require('./chunk-67B7IYAV.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkUWDHAZVEcjs = require('./chunk-UWDHAZVE.cjs');
|
|
7
7
|
|
|
8
8
|
// src/bootstrap/apply-defaults.ts
|
|
9
9
|
|
|
@@ -17,8 +17,8 @@ function applyNestKitDefaults(app, options = {}) {
|
|
|
17
17
|
app.useGlobalPipes(
|
|
18
18
|
new (0, _common.ValidationPipe)({ whitelist: true, transform: true, ...options.validation })
|
|
19
19
|
);
|
|
20
|
-
app.useGlobalFilters(new (0,
|
|
21
|
-
app.useGlobalInterceptors(new (0,
|
|
20
|
+
app.useGlobalFilters(new (0, _chunk67B7IYAVcjs.GlobalExceptionFilter)());
|
|
21
|
+
app.useGlobalInterceptors(new (0, _chunkUWDHAZVEcjs.ResponseInterceptor)());
|
|
22
22
|
if (options.swagger !== false) {
|
|
23
23
|
const swaggerOptions = _nullishCoalesce(options.swagger, () => ( { title: "API" }));
|
|
24
24
|
const config = new (0, _swagger.DocumentBuilder)().setTitle(swaggerOptions.title).build();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkR7BVS6CIcjs = require('./chunk-R7BVS6CI.cjs');
|
|
@@ -28,7 +28,7 @@ var GlobalExceptionFilter = class {
|
|
|
28
28
|
}
|
|
29
29
|
const body = {
|
|
30
30
|
success: false,
|
|
31
|
-
requestId: _nullishCoalesce(
|
|
31
|
+
requestId: _nullishCoalesce(_chunkEBPEMVZUcjs.RequestContext.getRequestId(), () => ( "unknown")),
|
|
32
32
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
33
33
|
error: {
|
|
34
34
|
code: resolved.code,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
+
var _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
var _chunkFDNGAYTZcjs = require('./chunk-FDNGAYTZ.cjs');
|
|
4
7
|
|
|
5
8
|
|
|
@@ -54,7 +57,9 @@ var JwtAuthGuard = class {
|
|
|
54
57
|
if (!token) {
|
|
55
58
|
throw new (0, _chunkFDNGAYTZcjs.UnauthorizedAppException)("Missing Authorization bearer token");
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
const user = this.tokens.verifyAccessToken(token);
|
|
61
|
+
req.user = user;
|
|
62
|
+
_chunkEBPEMVZUcjs.RequestContext.setActor({ id: user.sub, tenantId: user.tenantId, roles: user.roles });
|
|
58
63
|
return true;
|
|
59
64
|
}
|
|
60
65
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPaginated
|
|
3
|
+
} from "./chunk-TCAMLNUZ.js";
|
|
1
4
|
import {
|
|
2
5
|
RequestContext
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-KP2ZHJSR.js";
|
|
4
7
|
import {
|
|
5
8
|
__decorateClass
|
|
6
9
|
} from "./chunk-4MGIQFAJ.js";
|
|
@@ -11,12 +14,14 @@ import { map } from "rxjs/operators";
|
|
|
11
14
|
var ResponseInterceptor = class {
|
|
12
15
|
intercept(_context, next) {
|
|
13
16
|
return next.handle().pipe(
|
|
14
|
-
map((data) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
map((data) => {
|
|
18
|
+
const envelope = {
|
|
19
|
+
success: true,
|
|
20
|
+
requestId: RequestContext.getRequestId() ?? "unknown",
|
|
21
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
22
|
+
};
|
|
23
|
+
return isPaginated(data) ? { ...envelope, data: data.items, meta: data.meta } : { ...envelope, data };
|
|
24
|
+
})
|
|
20
25
|
);
|
|
21
26
|
}
|
|
22
27
|
};
|
|
@@ -13,6 +13,21 @@ var RequestContext = class {
|
|
|
13
13
|
static getRequestId() {
|
|
14
14
|
return _optionalChain([this, 'access', _ => _.storage, 'access', _2 => _2.getStore, 'call', _3 => _3(), 'optionalAccess', _4 => _4.requestId]);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Records who this request belongs to. Mutates the current store rather than
|
|
18
|
+
* opening a new scope: a guard runs inside the middleware's scope, and
|
|
19
|
+
* calling `run` again there would hide everything set before it.
|
|
20
|
+
*
|
|
21
|
+
* Silently does nothing outside a request — a queue worker has no store, and
|
|
22
|
+
* a guard should not explode because of where it was called from.
|
|
23
|
+
*/
|
|
24
|
+
static setActor(actor) {
|
|
25
|
+
const store = this.storage.getStore();
|
|
26
|
+
if (store) store.actor = actor;
|
|
27
|
+
}
|
|
28
|
+
static getActor() {
|
|
29
|
+
return _optionalChain([this, 'access', _5 => _5.storage, 'access', _6 => _6.getStore, 'call', _7 => _7(), 'optionalAccess', _8 => _8.actor]);
|
|
30
|
+
}
|
|
16
31
|
};
|
|
17
32
|
|
|
18
33
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/tracking/request-context.ts
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
var RequestContext = class {
|
|
4
|
+
static {
|
|
5
|
+
this.storage = new AsyncLocalStorage();
|
|
6
|
+
}
|
|
7
|
+
static run(store, fn) {
|
|
8
|
+
return this.storage.run(store, fn);
|
|
9
|
+
}
|
|
10
|
+
static getStore() {
|
|
11
|
+
return this.storage.getStore();
|
|
12
|
+
}
|
|
13
|
+
static getRequestId() {
|
|
14
|
+
return this.storage.getStore()?.requestId;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Records who this request belongs to. Mutates the current store rather than
|
|
18
|
+
* opening a new scope: a guard runs inside the middleware's scope, and
|
|
19
|
+
* calling `run` again there would hide everything set before it.
|
|
20
|
+
*
|
|
21
|
+
* Silently does nothing outside a request — a queue worker has no store, and
|
|
22
|
+
* a guard should not explode because of where it was called from.
|
|
23
|
+
*/
|
|
24
|
+
static setActor(actor) {
|
|
25
|
+
const store = this.storage.getStore();
|
|
26
|
+
if (store) store.actor = actor;
|
|
27
|
+
}
|
|
28
|
+
static getActor() {
|
|
29
|
+
return this.storage.getStore()?.actor;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
RequestContext
|
|
35
|
+
};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withRequestContext
|
|
3
|
+
} from "./chunk-XHW4CTBS.js";
|
|
4
|
+
import {
|
|
5
|
+
buildPageMeta,
|
|
6
|
+
paginated
|
|
7
|
+
} from "./chunk-TCAMLNUZ.js";
|
|
8
|
+
import {
|
|
9
|
+
__decorateClass,
|
|
10
|
+
__decorateParam
|
|
11
|
+
} from "./chunk-4MGIQFAJ.js";
|
|
12
|
+
|
|
13
|
+
// src/crud/list-query.dto.ts
|
|
14
|
+
import { Type } from "class-transformer";
|
|
15
|
+
import { IsIn, IsInt, IsOptional, IsString, Max, Min } from "class-validator";
|
|
16
|
+
var ListQuery = class {
|
|
17
|
+
};
|
|
18
|
+
__decorateClass([
|
|
19
|
+
IsOptional(),
|
|
20
|
+
Type(() => Number),
|
|
21
|
+
IsInt(),
|
|
22
|
+
Min(1)
|
|
23
|
+
], ListQuery.prototype, "page", 2);
|
|
24
|
+
__decorateClass([
|
|
25
|
+
IsOptional(),
|
|
26
|
+
Type(() => Number),
|
|
27
|
+
IsInt(),
|
|
28
|
+
Min(1),
|
|
29
|
+
Max(200)
|
|
30
|
+
], ListQuery.prototype, "limit", 2);
|
|
31
|
+
__decorateClass([
|
|
32
|
+
IsOptional(),
|
|
33
|
+
IsString()
|
|
34
|
+
], ListQuery.prototype, "sortBy", 2);
|
|
35
|
+
__decorateClass([
|
|
36
|
+
IsOptional(),
|
|
37
|
+
IsIn(["asc", "desc"])
|
|
38
|
+
], ListQuery.prototype, "sortOrder", 2);
|
|
39
|
+
|
|
40
|
+
// src/crud/crud.service.ts
|
|
41
|
+
var BaseCrudService = class {
|
|
42
|
+
constructor(repository, options = {}) {
|
|
43
|
+
this.repository = repository;
|
|
44
|
+
this.options = options;
|
|
45
|
+
}
|
|
46
|
+
findById(id, tenantId) {
|
|
47
|
+
return this.repository.findById(id, tenantId);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* One page of rows.
|
|
51
|
+
*
|
|
52
|
+
* Everything a caller can influence is bounded here rather than in the
|
|
53
|
+
* controller, so calling the service directly is as safe as going through
|
|
54
|
+
* HTTP: the limit is capped, and filter and sort fields are checked against
|
|
55
|
+
* the allowlists before they reach the adapter.
|
|
56
|
+
*/
|
|
57
|
+
async findAll(query = {}, tenantId) {
|
|
58
|
+
const maxLimit = this.options.maxLimit ?? 100;
|
|
59
|
+
const limit = Math.min(Math.max(query.limit ?? this.options.defaultLimit ?? 20, 1), maxLimit);
|
|
60
|
+
const page = Math.max(query.page ?? 1, 1);
|
|
61
|
+
const sortBy = query.sortBy && (this.options.sortable ?? []).includes(query.sortBy) ? query.sortBy : void 0;
|
|
62
|
+
const { items, total } = await this.repository.findAll(
|
|
63
|
+
{
|
|
64
|
+
filter: this.allowedFilter(query),
|
|
65
|
+
limit,
|
|
66
|
+
offset: (page - 1) * limit,
|
|
67
|
+
sortBy,
|
|
68
|
+
sortOrder: sortBy ? query.sortOrder ?? "desc" : void 0
|
|
69
|
+
},
|
|
70
|
+
tenantId
|
|
71
|
+
);
|
|
72
|
+
return paginated(items, buildPageMeta(total, page, limit));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Keeps only the query fields this service declares filterable. Anything
|
|
76
|
+
* else is dropped silently — a rejection would tell a caller which columns
|
|
77
|
+
* exist, which is the question they were asking.
|
|
78
|
+
*/
|
|
79
|
+
allowedFilter(query) {
|
|
80
|
+
const filterable = this.options.filterable ?? [];
|
|
81
|
+
if (filterable.length === 0) return void 0;
|
|
82
|
+
const filter = {};
|
|
83
|
+
for (const field of filterable) {
|
|
84
|
+
if (query[field] !== void 0) filter[field] = query[field];
|
|
85
|
+
}
|
|
86
|
+
return Object.keys(filter).length > 0 ? filter : void 0;
|
|
87
|
+
}
|
|
88
|
+
async create(data, tenantId) {
|
|
89
|
+
const created = await this.repository.create(data, tenantId);
|
|
90
|
+
await this.audit("created", created.id, { after: created, tenantId });
|
|
91
|
+
return created;
|
|
92
|
+
}
|
|
93
|
+
async update(id, data, tenantId) {
|
|
94
|
+
const before = await this.readBefore(id, tenantId);
|
|
95
|
+
const updated = await this.repository.update(id, data, tenantId);
|
|
96
|
+
await this.audit("updated", id, { before, after: updated, tenantId });
|
|
97
|
+
return updated;
|
|
98
|
+
}
|
|
99
|
+
async delete(id, tenantId) {
|
|
100
|
+
const before = await this.readBefore(id, tenantId);
|
|
101
|
+
if (this.options.deleteStrategy === "soft") {
|
|
102
|
+
await this.repository.update(id, { deletedAt: /* @__PURE__ */ new Date() }, tenantId);
|
|
103
|
+
} else {
|
|
104
|
+
await this.repository.delete(id, tenantId);
|
|
105
|
+
}
|
|
106
|
+
await this.audit(this.options.deleteStrategy === "soft" ? "soft-deleted" : "deleted", id, {
|
|
107
|
+
before,
|
|
108
|
+
tenantId
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Only when the trail is configured to want it — otherwise it is a query for nothing. */
|
|
112
|
+
async readBefore(id, tenantId) {
|
|
113
|
+
if (!this.options.audit?.includeBefore) return void 0;
|
|
114
|
+
return await this.repository.findById(id, tenantId) ?? void 0;
|
|
115
|
+
}
|
|
116
|
+
async audit(action, resourceId, details) {
|
|
117
|
+
const audit = this.options.audit;
|
|
118
|
+
if (!audit) return;
|
|
119
|
+
await audit.recorder.record(
|
|
120
|
+
withRequestContext({
|
|
121
|
+
action,
|
|
122
|
+
resource: audit.resource,
|
|
123
|
+
resourceId,
|
|
124
|
+
before: details.before,
|
|
125
|
+
after: details.after,
|
|
126
|
+
tenantId: details.tenantId
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/crud/crud.controller.ts
|
|
133
|
+
import {
|
|
134
|
+
Body,
|
|
135
|
+
Controller,
|
|
136
|
+
Delete,
|
|
137
|
+
Get,
|
|
138
|
+
Inject,
|
|
139
|
+
Param,
|
|
140
|
+
Patch,
|
|
141
|
+
Post,
|
|
142
|
+
Query,
|
|
143
|
+
Req
|
|
144
|
+
} from "@nestjs/common";
|
|
145
|
+
function createCrudController(serviceToken, options = {}) {
|
|
146
|
+
const tenantIdOf = (req) => options.tenantIdExtractor?.(req);
|
|
147
|
+
let CrudControllerHost = class {
|
|
148
|
+
constructor(service) {
|
|
149
|
+
this.service = service;
|
|
150
|
+
}
|
|
151
|
+
findAll(query, req) {
|
|
152
|
+
const raw = req.query ?? {};
|
|
153
|
+
return this.service.findAll({ ...raw, ...query }, tenantIdOf(req));
|
|
154
|
+
}
|
|
155
|
+
findById(id, req) {
|
|
156
|
+
return this.service.findById(id, tenantIdOf(req));
|
|
157
|
+
}
|
|
158
|
+
create(data, req) {
|
|
159
|
+
return this.service.create(data, tenantIdOf(req));
|
|
160
|
+
}
|
|
161
|
+
update(id, data, req) {
|
|
162
|
+
return this.service.update(id, data, tenantIdOf(req));
|
|
163
|
+
}
|
|
164
|
+
remove(id, req) {
|
|
165
|
+
return this.service.delete(id, tenantIdOf(req));
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
__decorateClass([
|
|
169
|
+
Get(),
|
|
170
|
+
__decorateParam(0, Query()),
|
|
171
|
+
__decorateParam(1, Req())
|
|
172
|
+
], CrudControllerHost.prototype, "findAll", 1);
|
|
173
|
+
__decorateClass([
|
|
174
|
+
Get(":id"),
|
|
175
|
+
__decorateParam(0, Param("id")),
|
|
176
|
+
__decorateParam(1, Req())
|
|
177
|
+
], CrudControllerHost.prototype, "findById", 1);
|
|
178
|
+
__decorateClass([
|
|
179
|
+
Post(),
|
|
180
|
+
__decorateParam(0, Body()),
|
|
181
|
+
__decorateParam(1, Req())
|
|
182
|
+
], CrudControllerHost.prototype, "create", 1);
|
|
183
|
+
__decorateClass([
|
|
184
|
+
Patch(":id"),
|
|
185
|
+
__decorateParam(0, Param("id")),
|
|
186
|
+
__decorateParam(1, Body()),
|
|
187
|
+
__decorateParam(2, Req())
|
|
188
|
+
], CrudControllerHost.prototype, "update", 1);
|
|
189
|
+
__decorateClass([
|
|
190
|
+
Delete(":id"),
|
|
191
|
+
__decorateParam(0, Param("id")),
|
|
192
|
+
__decorateParam(1, Req())
|
|
193
|
+
], CrudControllerHost.prototype, "remove", 1);
|
|
194
|
+
CrudControllerHost = __decorateClass([
|
|
195
|
+
Controller(options.path ?? ""),
|
|
196
|
+
__decorateParam(0, Inject(serviceToken))
|
|
197
|
+
], CrudControllerHost);
|
|
198
|
+
return CrudControllerHost;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export {
|
|
202
|
+
ListQuery,
|
|
203
|
+
BaseCrudService,
|
|
204
|
+
createCrudController
|
|
205
|
+
};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RequestContext
|
|
3
|
+
} from "./chunk-KP2ZHJSR.js";
|
|
1
4
|
import {
|
|
2
5
|
UnauthorizedAppException
|
|
3
6
|
} from "./chunk-ORWJ7LES.js";
|
|
@@ -54,7 +57,9 @@ var JwtAuthGuard = class {
|
|
|
54
57
|
if (!token) {
|
|
55
58
|
throw new UnauthorizedAppException("Missing Authorization bearer token");
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
const user = this.tokens.verifyAccessToken(token);
|
|
61
|
+
req.user = user;
|
|
62
|
+
RequestContext.setActor({ id: user.sub, tenantId: user.tenantId, roles: user.roles });
|
|
58
63
|
return true;
|
|
59
64
|
}
|
|
60
65
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/response/paginated.ts
|
|
2
|
+
var PAGINATED = /* @__PURE__ */ Symbol.for("nestkit.paginated");
|
|
3
|
+
function buildPageMeta(total, page, limit) {
|
|
4
|
+
const pages = limit > 0 ? Math.ceil(total / limit) : 0;
|
|
5
|
+
return {
|
|
6
|
+
page,
|
|
7
|
+
limit,
|
|
8
|
+
total,
|
|
9
|
+
pages,
|
|
10
|
+
hasNext: page < pages,
|
|
11
|
+
hasPrevious: page > 1 && total > 0
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function paginated(items, meta) {
|
|
15
|
+
const page = { items, meta };
|
|
16
|
+
Object.defineProperty(page, PAGINATED, { value: true, enumerable: false });
|
|
17
|
+
return page;
|
|
18
|
+
}
|
|
19
|
+
function isPaginated(value) {
|
|
20
|
+
return typeof value === "object" && value !== null && value[PAGINATED] === true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
buildPageMeta,
|
|
25
|
+
paginated,
|
|
26
|
+
isPaginated
|
|
27
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
|
|
@@ -15,7 +15,7 @@ var RequestIdMiddleware = class {
|
|
|
15
15
|
const requestId = _nullishCoalesce((Array.isArray(incoming) ? incoming[0] : incoming), () => ( _crypto.randomUUID.call(void 0, )));
|
|
16
16
|
req.requestId = requestId;
|
|
17
17
|
res.setHeader(REQUEST_ID_HEADER, requestId);
|
|
18
|
-
|
|
18
|
+
_chunkEBPEMVZUcjs.RequestContext.run({ requestId }, () => next());
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
RequestIdMiddleware = exports.RequestIdMiddleware = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|