@miguelmorales13/nestkit 0.16.0 → 0.19.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 +212 -61
- package/dist/audit/index.cjs +12 -12
- package/dist/audit/index.js +2 -2
- package/dist/auth/index.cjs +12 -11
- package/dist/auth/index.js +5 -4
- package/dist/auth/oauth/http.d.ts +10 -3
- package/dist/auth/oauth/index.cjs +189 -30
- package/dist/auth/oauth/index.d.ts +6 -4
- package/dist/auth/oauth/index.js +169 -10
- package/dist/auth/oauth/magic-link.dto.d.ts +6 -0
- package/dist/auth/oauth/memory-magic-link.store.d.ts +19 -0
- package/dist/auth/oauth/oauth-auth.service.d.ts +46 -5
- package/dist/auth/oauth/oauth.controller.d.ts +5 -1
- package/dist/auth/oauth/oauth.options.d.ts +34 -1
- package/dist/auth/oauth/oauth.ports.d.ts +38 -0
- package/dist/bootstrap/index.cjs +8 -6
- package/dist/bootstrap/index.js +7 -5
- package/dist/{chunk-UWDHAZVE.cjs → chunk-3AUOOEQO.cjs} +2 -2
- package/dist/{chunk-JV4EAOF2.js → chunk-4PFAKLT3.js} +1 -1
- package/dist/{chunk-47FXU74G.cjs → chunk-52IOOHNX.cjs} +2 -2
- package/dist/chunk-6RAPVLJM.js +212 -0
- package/dist/{chunk-KRC47OX6.js → chunk-A2DGK4ZL.js} +26 -3
- package/dist/chunk-APUFKA4K.cjs +212 -0
- package/dist/chunk-AXMW5JF7.cjs +83 -0
- package/dist/{chunk-DABTRWA6.js → chunk-DYHSOULW.js} +1 -1
- package/dist/{chunk-KP2ZHJSR.js → chunk-ETRUVZTJ.js} +8 -0
- package/dist/{chunk-C5DV4RAX.cjs → chunk-FH5UNWWW.cjs} +6 -6
- package/dist/{chunk-4GT66KQS.cjs → chunk-FNUZGYUF.cjs} +4 -4
- package/dist/{chunk-FDNGAYTZ.cjs → chunk-HDFPSA2V.cjs} +6 -6
- package/dist/{chunk-U7QK24HL.cjs → chunk-HVHYZXBB.cjs} +2 -2
- package/dist/{chunk-LK3OINS7.js → chunk-IFNYRZP2.js} +1 -1
- package/dist/{chunk-YFYHLYHN.js → chunk-M3GQDRWR.js} +7 -1
- package/dist/{chunk-67B7IYAV.cjs → chunk-MSTXS3MU.cjs} +28 -5
- package/dist/chunk-PNK5WMPP.cjs +30 -0
- package/dist/chunk-Q5Y33L7B.cjs +19 -0
- package/dist/{chunk-EBPEMVZU.cjs → chunk-SDWHKPXI.cjs} +8 -0
- package/dist/{chunk-MLOQDUBN.js → chunk-TUNDBBQF.js} +4 -4
- package/dist/{chunk-UIVBPNH4.js → chunk-UNEVXCFW.js} +4 -4
- package/dist/chunk-VVMRZEIW.js +30 -0
- package/dist/{chunk-XX5ROVSC.cjs → chunk-W2T2VFLC.cjs} +3 -3
- package/dist/chunk-X4PQJZ4G.js +83 -0
- package/dist/{chunk-ORWJ7LES.js → chunk-ZFIDAX7K.js} +1 -1
- package/dist/{chunk-XHW4CTBS.js → chunk-ZJMLEP5H.js} +1 -1
- package/dist/crud/index.cjs +4 -4
- package/dist/crud/index.js +3 -3
- package/dist/email/adapters/brevo.email.d.ts +22 -0
- package/dist/email/adapters/memory.email.d.ts +14 -0
- package/dist/email/adapters/message.d.ts +13 -0
- package/dist/email/adapters/resend.email.d.ts +28 -0
- package/dist/email/adapters/smtp.email.d.ts +22 -0
- package/dist/email/address.d.ts +15 -0
- package/dist/email/email.module.d.ts +37 -0
- package/dist/email/email.options.d.ts +39 -0
- package/dist/email/email.port.d.ts +62 -0
- package/dist/email/index.cjs +314 -0
- package/dist/email/index.d.ts +12 -0
- package/dist/email/index.js +314 -0
- package/dist/errors/app.exception.d.ts +9 -1
- package/dist/errors/common.exceptions.d.ts +6 -5
- package/dist/errors/global-exception.filter.d.ts +9 -0
- package/dist/errors/index.cjs +8 -5
- package/dist/errors/index.js +9 -6
- package/dist/i18n/i18n.interceptor.d.ts +16 -0
- package/dist/i18n/i18n.module.d.ts +49 -3
- package/dist/i18n/index.cjs +26 -2
- package/dist/i18n/index.d.ts +8 -0
- package/dist/i18n/index.js +25 -1
- package/dist/i18n/locale.d.ts +53 -0
- package/dist/i18n/message.d.ts +36 -0
- package/dist/i18n/nestjs-i18n.translator.d.ts +9 -0
- package/dist/i18n/runtime.d.ts +55 -0
- package/dist/i18n/translator.port.d.ts +29 -0
- package/dist/idempotency/index.cjs +6 -5
- package/dist/idempotency/index.js +3 -2
- package/dist/index.cjs +38 -16
- package/dist/index.js +47 -25
- package/dist/invoicing/index.cjs +14 -13
- package/dist/invoicing/index.js +3 -2
- package/dist/payments/index.cjs +15 -14
- package/dist/payments/index.js +3 -2
- package/dist/response/index.cjs +3 -3
- package/dist/response/index.js +2 -2
- package/dist/stripe/index.cjs +4 -3
- package/dist/stripe/index.js +3 -2
- package/dist/tracking/index.cjs +3 -3
- package/dist/tracking/index.js +2 -2
- package/dist/tracking/request-context.d.ts +10 -0
- package/package.json +6 -1
- package/dist/chunk-IYUUYCP5.js +0 -36
- package/dist/chunk-M3EL5O6T.cjs +0 -36
- package/dist/chunk-R7BVS6CI.cjs +0 -13
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkQ5Y33L7Bcjs = require('./chunk-Q5Y33L7B.cjs');
|
|
4
4
|
|
|
5
5
|
// src/errors/common.exceptions.ts
|
|
6
6
|
var _common = require('@nestjs/common');
|
|
7
|
-
var NotFoundAppException = class extends
|
|
7
|
+
var NotFoundAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
|
|
8
8
|
constructor(message = "Resource not found", details, code = "NOT_FOUND") {
|
|
9
9
|
super(code, message, _common.HttpStatus.NOT_FOUND, details);
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
var ConflictAppException = class extends
|
|
12
|
+
var ConflictAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
|
|
13
13
|
constructor(message = "Conflict", details, code = "CONFLICT") {
|
|
14
14
|
super(code, message, _common.HttpStatus.CONFLICT, details);
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
var ValidationAppException = class extends
|
|
17
|
+
var ValidationAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
|
|
18
18
|
constructor(message = "Validation failed", details, code = "VALIDATION_ERROR") {
|
|
19
19
|
super(code, message, _common.HttpStatus.BAD_REQUEST, details);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
var UnauthorizedAppException = class extends
|
|
22
|
+
var UnauthorizedAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
|
|
23
23
|
constructor(message = "Unauthorized", details, code = "UNAUTHORIZED") {
|
|
24
24
|
super(code, message, _common.HttpStatus.UNAUTHORIZED, details);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
var ForbiddenAppException = class extends
|
|
27
|
+
var ForbiddenAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
|
|
28
28
|
constructor(message = "Forbidden", details, code = "FORBIDDEN") {
|
|
29
29
|
super(code, message, _common.HttpStatus.FORBIDDEN, details);
|
|
30
30
|
}
|
|
@@ -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 _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.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
|
+
_chunkSDWHKPXIcjs.RequestContext.run({ requestId }, () => next());
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
RequestIdMiddleware = exports.RequestIdMiddleware = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isI18nMessage
|
|
3
|
+
} from "./chunk-VVMRZEIW.js";
|
|
4
|
+
|
|
1
5
|
// src/errors/app.exception.ts
|
|
2
6
|
import { HttpException } from "@nestjs/common";
|
|
3
7
|
var AppException = class extends HttpException {
|
|
4
8
|
constructor(code, message, status, details) {
|
|
5
|
-
|
|
9
|
+
const text = isI18nMessage(message) ? message.toJSON() : message;
|
|
10
|
+
super({ code, message: text, details }, status);
|
|
6
11
|
this.code = code;
|
|
7
12
|
this.details = details;
|
|
13
|
+
if (isI18nMessage(message)) this.i18n = message;
|
|
8
14
|
}
|
|
9
15
|
};
|
|
10
16
|
|
|
@@ -1,9 +1,14 @@
|
|
|
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 _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
|
|
4
3
|
|
|
5
4
|
|
|
6
|
-
var
|
|
5
|
+
var _chunkAXMW5JF7cjs = require('./chunk-AXMW5JF7.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkQ5Y33L7Bcjs = require('./chunk-Q5Y33L7B.cjs');
|
|
7
12
|
|
|
8
13
|
|
|
9
14
|
var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
|
|
@@ -20,15 +25,19 @@ var GlobalExceptionFilter = class {
|
|
|
20
25
|
this.logger = new (0, _common.Logger)(GlobalExceptionFilter.name);
|
|
21
26
|
}
|
|
22
27
|
catch(exception, host) {
|
|
23
|
-
const
|
|
28
|
+
const http = host.switchToHttp();
|
|
29
|
+
const response = http.getResponse();
|
|
24
30
|
const resolved = this.resolve(exception);
|
|
25
31
|
if (resolved.status >= _common.HttpStatus.INTERNAL_SERVER_ERROR) {
|
|
26
32
|
const stack = exception instanceof Error ? exception.stack : void 0;
|
|
27
33
|
this.logger.error(`Unhandled exception: ${resolved.message}`, stack);
|
|
28
34
|
}
|
|
35
|
+
if (exception instanceof _chunkQ5Y33L7Bcjs.AppException) {
|
|
36
|
+
this.localize(resolved, exception, http.getRequest());
|
|
37
|
+
}
|
|
29
38
|
const body = {
|
|
30
39
|
success: false,
|
|
31
|
-
requestId: _nullishCoalesce(
|
|
40
|
+
requestId: _nullishCoalesce(_chunkSDWHKPXIcjs.RequestContext.getRequestId(), () => ( "unknown")),
|
|
32
41
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
33
42
|
error: {
|
|
34
43
|
code: resolved.code,
|
|
@@ -38,8 +47,22 @@ var GlobalExceptionFilter = class {
|
|
|
38
47
|
};
|
|
39
48
|
response.status(resolved.status).send(body);
|
|
40
49
|
}
|
|
50
|
+
localize(resolved, exception, request) {
|
|
51
|
+
const runtime = _chunkAXMW5JF7cjs.getI18nRuntime.call(void 0, );
|
|
52
|
+
if (!runtime) return;
|
|
53
|
+
const lang = _nullishCoalesce(runtime.resolveLocale(request), () => ( runtime.fallbackLanguage));
|
|
54
|
+
if (exception.i18n) {
|
|
55
|
+
resolved.message = _chunkAXMW5JF7cjs.translate.call(void 0, exception.i18n, { lang, defaultValue: resolved.message });
|
|
56
|
+
} else if (runtime.errorCodes !== false) {
|
|
57
|
+
resolved.message = _chunkAXMW5JF7cjs.translate.call(void 0, `${runtime.errorCodes}.${exception.code}`, {
|
|
58
|
+
lang,
|
|
59
|
+
defaultValue: resolved.message
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
resolved.details = _chunkAXMW5JF7cjs.translateDeep.call(void 0, resolved.details, lang);
|
|
63
|
+
}
|
|
41
64
|
resolve(exception) {
|
|
42
|
-
if (exception instanceof
|
|
65
|
+
if (exception instanceof _chunkQ5Y33L7Bcjs.AppException) {
|
|
43
66
|
return {
|
|
44
67
|
status: exception.getStatus(),
|
|
45
68
|
code: exception.code,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/i18n/message.ts
|
|
2
|
+
var I18N_MESSAGE = /* @__PURE__ */ Symbol.for("nestkit.i18n.message");
|
|
3
|
+
var _a;
|
|
4
|
+
_a = I18N_MESSAGE;
|
|
5
|
+
var I18nMessage = class {
|
|
6
|
+
constructor(key, args, fallback) {
|
|
7
|
+
this.key = key;
|
|
8
|
+
this.args = args;
|
|
9
|
+
this.fallback = fallback;
|
|
10
|
+
this[_a] = true;
|
|
11
|
+
}
|
|
12
|
+
toJSON() {
|
|
13
|
+
return _nullishCoalesce(this.fallback, () => ( this.key));
|
|
14
|
+
}
|
|
15
|
+
toString() {
|
|
16
|
+
return this.toJSON();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
function t(key, args, fallback) {
|
|
20
|
+
return new I18nMessage(key, args, fallback);
|
|
21
|
+
}
|
|
22
|
+
function isI18nMessage(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && value[I18N_MESSAGE] === true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
exports.I18nMessage = I18nMessage; exports.t = t; exports.isI18nMessage = isI18nMessage;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkPNK5WMPPcjs = require('./chunk-PNK5WMPP.cjs');
|
|
4
|
+
|
|
5
|
+
// src/errors/app.exception.ts
|
|
6
|
+
var _common = require('@nestjs/common');
|
|
7
|
+
var AppException = class extends _common.HttpException {
|
|
8
|
+
constructor(code, message, status, details) {
|
|
9
|
+
const text = _chunkPNK5WMPPcjs.isI18nMessage.call(void 0, message) ? message.toJSON() : message;
|
|
10
|
+
super({ code, message: text, details }, status);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.details = details;
|
|
13
|
+
if (_chunkPNK5WMPPcjs.isI18nMessage.call(void 0, message)) this.i18n = message;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.AppException = AppException;
|
|
@@ -28,6 +28,14 @@ var RequestContext = class {
|
|
|
28
28
|
static getActor() {
|
|
29
29
|
return _optionalChain([this, 'access', _5 => _5.storage, 'access', _6 => _6.getStore, 'call', _7 => _7(), 'optionalAccess', _8 => _8.actor]);
|
|
30
30
|
}
|
|
31
|
+
/** Same contract as {@link setActor}: mutates the current store, no-op outside a request. */
|
|
32
|
+
static setLang(lang) {
|
|
33
|
+
const store = this.storage.getStore();
|
|
34
|
+
if (store) store.lang = lang;
|
|
35
|
+
}
|
|
36
|
+
static getLang() {
|
|
37
|
+
return _optionalChain([this, 'access', _9 => _9.storage, 'access', _10 => _10.getStore, 'call', _11 => _11(), 'optionalAccess', _12 => _12.lang]);
|
|
38
|
+
}
|
|
31
39
|
};
|
|
32
40
|
|
|
33
41
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RequestContext
|
|
3
|
-
} from "./chunk-KP2ZHJSR.js";
|
|
4
1
|
import {
|
|
5
2
|
UnauthorizedAppException
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZFIDAX7K.js";
|
|
4
|
+
import {
|
|
5
|
+
RequestContext
|
|
6
|
+
} from "./chunk-ETRUVZTJ.js";
|
|
7
7
|
import {
|
|
8
8
|
__decorateClass
|
|
9
9
|
} from "./chunk-4MGIQFAJ.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GlobalExceptionFilter
|
|
3
|
-
} from "./chunk-KRC47OX6.js";
|
|
4
1
|
import {
|
|
5
2
|
ResponseInterceptor
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DYHSOULW.js";
|
|
4
|
+
import {
|
|
5
|
+
GlobalExceptionFilter
|
|
6
|
+
} from "./chunk-A2DGK4ZL.js";
|
|
7
7
|
|
|
8
8
|
// src/bootstrap/apply-defaults.ts
|
|
9
9
|
import {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/i18n/message.ts
|
|
2
|
+
var I18N_MESSAGE = /* @__PURE__ */ Symbol.for("nestkit.i18n.message");
|
|
3
|
+
var _a;
|
|
4
|
+
_a = I18N_MESSAGE;
|
|
5
|
+
var I18nMessage = class {
|
|
6
|
+
constructor(key, args, fallback) {
|
|
7
|
+
this.key = key;
|
|
8
|
+
this.args = args;
|
|
9
|
+
this.fallback = fallback;
|
|
10
|
+
this[_a] = true;
|
|
11
|
+
}
|
|
12
|
+
toJSON() {
|
|
13
|
+
return this.fallback ?? this.key;
|
|
14
|
+
}
|
|
15
|
+
toString() {
|
|
16
|
+
return this.toJSON();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
function t(key, args, fallback) {
|
|
20
|
+
return new I18nMessage(key, args, fallback);
|
|
21
|
+
}
|
|
22
|
+
function isI18nMessage(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && value[I18N_MESSAGE] === true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
I18nMessage,
|
|
28
|
+
t,
|
|
29
|
+
isI18nMessage
|
|
30
|
+
};
|
|
@@ -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(); } } 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 _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -15,12 +15,12 @@ var AUDIT_OPTIONS = /* @__PURE__ */ Symbol("AUDIT_OPTIONS");
|
|
|
15
15
|
// src/audit/audit.service.ts
|
|
16
16
|
var _common = require('@nestjs/common');
|
|
17
17
|
function withRequestContext(event) {
|
|
18
|
-
const actor =
|
|
18
|
+
const actor = _chunkSDWHKPXIcjs.RequestContext.getActor();
|
|
19
19
|
return {
|
|
20
20
|
...event,
|
|
21
21
|
actorId: _nullishCoalesce(event.actorId, () => ( _optionalChain([actor, 'optionalAccess', _ => _.id]))),
|
|
22
22
|
tenantId: _nullishCoalesce(event.tenantId, () => ( _optionalChain([actor, 'optionalAccess', _2 => _2.tenantId]))),
|
|
23
|
-
requestId: _nullishCoalesce(event.requestId, () => (
|
|
23
|
+
requestId: _nullishCoalesce(event.requestId, () => ( _chunkSDWHKPXIcjs.RequestContext.getRequestId())),
|
|
24
24
|
at: _nullishCoalesce(event.at, () => ( /* @__PURE__ */ new Date()))
|
|
25
25
|
};
|
|
26
26
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPaginated,
|
|
3
|
+
paginated
|
|
4
|
+
} from "./chunk-TCAMLNUZ.js";
|
|
5
|
+
import {
|
|
6
|
+
RequestContext
|
|
7
|
+
} from "./chunk-ETRUVZTJ.js";
|
|
8
|
+
import {
|
|
9
|
+
I18nMessage,
|
|
10
|
+
isI18nMessage
|
|
11
|
+
} from "./chunk-VVMRZEIW.js";
|
|
12
|
+
|
|
13
|
+
// src/i18n/runtime.ts
|
|
14
|
+
var runtime;
|
|
15
|
+
function setI18nRuntime(next) {
|
|
16
|
+
runtime = next;
|
|
17
|
+
}
|
|
18
|
+
function getI18nRuntime() {
|
|
19
|
+
return runtime;
|
|
20
|
+
}
|
|
21
|
+
function currentLanguage() {
|
|
22
|
+
return RequestContext.getLang() ?? runtime?.fallbackLanguage;
|
|
23
|
+
}
|
|
24
|
+
function translate(input, options = {}) {
|
|
25
|
+
const message = typeof input === "string" ? new I18nMessage(input, options.args) : input;
|
|
26
|
+
const fallback = message.fallback ?? options.defaultValue ?? message.key;
|
|
27
|
+
if (!runtime) return fallback;
|
|
28
|
+
const lang = options.lang ?? currentLanguage();
|
|
29
|
+
try {
|
|
30
|
+
return runtime.translator.translate(message.key, { lang, args: message.args }) ?? fallback;
|
|
31
|
+
} catch {
|
|
32
|
+
return fallback;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function translateDeep(value, lang) {
|
|
36
|
+
if (!runtime) return value;
|
|
37
|
+
return walk(value, lang, /* @__PURE__ */ new WeakSet());
|
|
38
|
+
}
|
|
39
|
+
function walk(value, lang, seen) {
|
|
40
|
+
if (isI18nMessage(value)) return translate(value, { lang });
|
|
41
|
+
if (typeof value !== "object" || value === null) return value;
|
|
42
|
+
if (seen.has(value)) return value;
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
seen.add(value);
|
|
45
|
+
let copy2;
|
|
46
|
+
value.forEach((item, index) => {
|
|
47
|
+
const next = walk(item, lang, seen);
|
|
48
|
+
if (next !== item) {
|
|
49
|
+
copy2 ??= [...value];
|
|
50
|
+
copy2[index] = next;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return copy2 ?? value;
|
|
54
|
+
}
|
|
55
|
+
if (isPaginated(value)) {
|
|
56
|
+
seen.add(value);
|
|
57
|
+
const items = walk(value.items, lang, seen);
|
|
58
|
+
return items === value.items ? value : paginated(items, value.meta);
|
|
59
|
+
}
|
|
60
|
+
if (!isPlainObject(value)) return value;
|
|
61
|
+
seen.add(value);
|
|
62
|
+
let copy;
|
|
63
|
+
for (const [key, item] of Object.entries(value)) {
|
|
64
|
+
const next = walk(item, lang, seen);
|
|
65
|
+
if (next !== item) {
|
|
66
|
+
copy ??= { ...value };
|
|
67
|
+
copy[key] = next;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return copy ?? value;
|
|
71
|
+
}
|
|
72
|
+
function isPlainObject(value) {
|
|
73
|
+
const proto = Object.getPrototypeOf(value);
|
|
74
|
+
return proto === Object.prototype || proto === null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
setI18nRuntime,
|
|
79
|
+
getI18nRuntime,
|
|
80
|
+
currentLanguage,
|
|
81
|
+
translate,
|
|
82
|
+
translateDeep
|
|
83
|
+
};
|
package/dist/crud/index.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
5
|
+
var _chunk52IOOHNXcjs = require('../chunk-52IOOHNX.cjs');
|
|
6
|
+
require('../chunk-W2T2VFLC.cjs');
|
|
7
7
|
require('../chunk-Y72D5L6I.cjs');
|
|
8
|
-
require('../chunk-
|
|
8
|
+
require('../chunk-SDWHKPXI.cjs');
|
|
9
9
|
require('../chunk-2REOCMUD.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.BaseCrudService =
|
|
14
|
+
exports.BaseCrudService = _chunk52IOOHNXcjs.BaseCrudService; exports.ListQuery = _chunk52IOOHNXcjs.ListQuery; exports.createCrudController = _chunk52IOOHNXcjs.createCrudController;
|
package/dist/crud/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
BaseCrudService,
|
|
3
3
|
ListQuery,
|
|
4
4
|
createCrudController
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-IFNYRZP2.js";
|
|
6
|
+
import "../chunk-ZJMLEP5H.js";
|
|
7
7
|
import "../chunk-TCAMLNUZ.js";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-ETRUVZTJ.js";
|
|
9
9
|
import "../chunk-4MGIQFAJ.js";
|
|
10
10
|
export {
|
|
11
11
|
BaseCrudService,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BrevoEmailOptions } from '../email.options.js';
|
|
2
|
+
import { type EmailMessage, type EmailPort, type SentEmail } from '../email.port.js';
|
|
3
|
+
/**
|
|
4
|
+
* Brevo (formerly Sendinblue) over its v3 REST API — one `POST /smtp/email`
|
|
5
|
+
* with the key in an `api-key` header. No SDK: the call is a dozen lines of
|
|
6
|
+
* `fetch`, and every field it sends is visible here, which is the same
|
|
7
|
+
* reasoning as `payments` and `auth/oauth`.
|
|
8
|
+
*
|
|
9
|
+
* Attachments travel base64-encoded inside the JSON; Brevo caps the whole
|
|
10
|
+
* request at 10 MB, so anything bigger belongs in `storage` with a link.
|
|
11
|
+
*/
|
|
12
|
+
export declare class BrevoEmail implements EmailPort {
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly defaults;
|
|
15
|
+
private readonly baseUrl;
|
|
16
|
+
private readonly fetchImpl;
|
|
17
|
+
constructor(options: BrevoEmailOptions, defaults?: {
|
|
18
|
+
from?: string;
|
|
19
|
+
replyTo?: string;
|
|
20
|
+
});
|
|
21
|
+
send(input: EmailMessage): Promise<SentEmail>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EmailMessage, EmailPort, SentEmail } from '../email.port.js';
|
|
2
|
+
/**
|
|
3
|
+
* Keeps every message in memory instead of sending it. For tests, and for a
|
|
4
|
+
* development environment that must not email anyone. `sent` is the outbox.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryEmail implements EmailPort {
|
|
7
|
+
private readonly defaults;
|
|
8
|
+
readonly sent: EmailMessage[];
|
|
9
|
+
constructor(defaults?: {
|
|
10
|
+
from?: string;
|
|
11
|
+
replyTo?: string;
|
|
12
|
+
});
|
|
13
|
+
send(message: EmailMessage): Promise<SentEmail>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EmailAddress, EmailMessage } from '../email.port.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fills the defaults in and refuses what no provider would accept, so each
|
|
4
|
+
* adapter can assume a complete message and the error reads the same
|
|
5
|
+
* whichever one is configured.
|
|
6
|
+
*/
|
|
7
|
+
export declare function completeMessage(message: EmailMessage, defaults: {
|
|
8
|
+
from?: string;
|
|
9
|
+
replyTo?: string;
|
|
10
|
+
}): EmailMessage & {
|
|
11
|
+
from: EmailAddress;
|
|
12
|
+
};
|
|
13
|
+
export declare function attachmentBuffer(content: Buffer | string): Buffer;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Resend } from 'resend';
|
|
2
|
+
import type { ResendEmailOptions } from '../email.options.js';
|
|
3
|
+
import { type EmailMessage, type EmailPort, type SentEmail } from '../email.port.js';
|
|
4
|
+
/** The one method of the SDK this adapter uses — what a test hands in instead of the real thing. */
|
|
5
|
+
export type ResendLike = {
|
|
6
|
+
emails: {
|
|
7
|
+
send: Resend['emails']['send'];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Resend through its SDK, loaded lazily on the first send so an app on Brevo
|
|
12
|
+
* or SMTP never loads it — the same rule as `storage`'s S3 adapter.
|
|
13
|
+
*
|
|
14
|
+
* The SDK does not throw: it answers `{ data, error }`. The adapter turns the
|
|
15
|
+
* error half into {@link EmailProviderException} so a failed send is an
|
|
16
|
+
* exception here like everywhere else, and never a silently ignored result.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ResendEmail implements EmailPort {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private readonly defaults;
|
|
21
|
+
private clientPromise?;
|
|
22
|
+
constructor(options: ResendEmailOptions, defaults?: {
|
|
23
|
+
from?: string;
|
|
24
|
+
replyTo?: string;
|
|
25
|
+
}, client?: ResendLike);
|
|
26
|
+
private client;
|
|
27
|
+
send(input: EmailMessage): Promise<SentEmail>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Transporter } from 'nodemailer';
|
|
2
|
+
import type { SmtpEmailOptions } from '../email.options.js';
|
|
3
|
+
import { type EmailMessage, type EmailPort, type SentEmail } from '../email.port.js';
|
|
4
|
+
/** The one method this adapter needs from a transport. */
|
|
5
|
+
export type TransporterLike = Pick<Transporter, 'sendMail'>;
|
|
6
|
+
/**
|
|
7
|
+
* Any SMTP server through Nodemailer, loaded lazily on the first send.
|
|
8
|
+
*
|
|
9
|
+
* Tags have no place in SMTP; they go out as `X-Tag-<name>` headers, which
|
|
10
|
+
* most providers' relays surface in their dashboards and nobody else minds.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SmtpEmail implements EmailPort {
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly defaults;
|
|
15
|
+
private transportPromise?;
|
|
16
|
+
constructor(options: SmtpEmailOptions, defaults?: {
|
|
17
|
+
from?: string;
|
|
18
|
+
replyTo?: string;
|
|
19
|
+
}, transport?: TransporterLike);
|
|
20
|
+
private transport;
|
|
21
|
+
send(input: EmailMessage): Promise<SentEmail>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EmailAddress } from './email.port.js';
|
|
2
|
+
export interface ParsedAddress {
|
|
3
|
+
email: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Normalises the two spellings the port accepts into one shape. Providers
|
|
8
|
+
* disagree — Resend and Nodemailer take `"Name <email>"`, Brevo wants
|
|
9
|
+
* `{ name, email }` — so every adapter goes through here and the caller
|
|
10
|
+
* never has to know which one is behind the port.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseAddress(address: EmailAddress): ParsedAddress;
|
|
13
|
+
/** `Name <email>` when there is a name, the bare address otherwise. */
|
|
14
|
+
export declare function formatAddress(address: EmailAddress): string;
|
|
15
|
+
export declare function toList(value: EmailAddress | EmailAddress[] | undefined): EmailAddress[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { type EmailOptions } from './email.options.js';
|
|
3
|
+
import { type EmailPort } from './email.port.js';
|
|
4
|
+
/**
|
|
5
|
+
* Merges explicit options with the environment; anything not passed in code
|
|
6
|
+
* falls back to the env, so `EmailModule.forRoot()` with no arguments works
|
|
7
|
+
* when the environment is configured.
|
|
8
|
+
*
|
|
9
|
+
* Recognised vars: `EMAIL_PROVIDER`, `EMAIL_FROM`, `EMAIL_REPLY_TO`; resend
|
|
10
|
+
* `RESEND_API_KEY`; smtp `SMTP_HOST`, `SMTP_PORT`, `SMTP_SECURE`, `SMTP_USER`,
|
|
11
|
+
* `SMTP_PASSWORD`; brevo `BREVO_API_KEY`, `BREVO_BASE_URL`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveEmailOptions(options?: EmailOptions): EmailOptions;
|
|
14
|
+
/** Constructs the adapter the options select, failing loudly on missing config. */
|
|
15
|
+
export declare function createEmailAdapter(options?: EmailOptions): EmailPort;
|
|
16
|
+
/**
|
|
17
|
+
* Provider-agnostic transactional email. Register once in the root module
|
|
18
|
+
* and inject the port anywhere with `@Inject(EMAIL) email: EmailPort`.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* EmailModule.forRoot({ provider: 'brevo' }) // reads BREVO_API_KEY, EMAIL_FROM
|
|
22
|
+
* EmailModule.forRoot({ provider: 'resend', from: 'Mi App <hola@miapp.mx>' })
|
|
23
|
+
* EmailModule.forRoot({ provider: 'smtp', smtp: { host, port: 587, user, password } })
|
|
24
|
+
* EmailModule.forRootAsync({ inject: [Config], useFactory: (c) => ({ provider: c.emailProvider }) })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Switching providers is this one line — no call site changes, because
|
|
28
|
+
* everything depends on `EmailPort`, never on a concrete client.
|
|
29
|
+
*/
|
|
30
|
+
export declare class EmailModule {
|
|
31
|
+
static forRoot(options?: EmailOptions): DynamicModule;
|
|
32
|
+
static forRootAsync(config: {
|
|
33
|
+
imports?: any[];
|
|
34
|
+
inject?: any[];
|
|
35
|
+
useFactory: (...args: any[]) => EmailOptions | Promise<EmailOptions>;
|
|
36
|
+
}): DynamicModule;
|
|
37
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** DI token carrying the resolved {@link EmailOptions}. */
|
|
2
|
+
export declare const EMAIL_OPTIONS: unique symbol;
|
|
3
|
+
/** Which adapter backs the {@link EmailPort}. */
|
|
4
|
+
export type EmailProvider = 'resend' | 'smtp' | 'brevo' | 'memory';
|
|
5
|
+
export interface ResendEmailOptions {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Any SMTP server, through Nodemailer. Brevo's own relay works here too
|
|
10
|
+
* (`smtp-relay.brevo.com:587`, login + SMTP key) for an app that would rather
|
|
11
|
+
* not depend on the HTTP API — but the `brevo` adapter is the lighter choice.
|
|
12
|
+
*/
|
|
13
|
+
export interface SmtpEmailOptions {
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
/** TLS from the first byte (port 465). Off for STARTTLS on 587. */
|
|
17
|
+
secure?: boolean;
|
|
18
|
+
/** Both omitted for a relay that needs no authentication (a local MailHog, say). */
|
|
19
|
+
user?: string;
|
|
20
|
+
password?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface BrevoEmailOptions {
|
|
23
|
+
apiKey: string;
|
|
24
|
+
/** Defaults to `https://api.brevo.com/v3`. */
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
/** For tests. Defaults to the global `fetch`. */
|
|
27
|
+
fetchImpl?: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
export interface EmailOptions {
|
|
30
|
+
/** Read from `EMAIL_PROVIDER` when omitted. There is no default: a misconfigured app must not send nowhere in silence. */
|
|
31
|
+
provider?: EmailProvider;
|
|
32
|
+
/** Default sender, `"Name <email>"` or bare. `EMAIL_FROM` when omitted. A message may override it. */
|
|
33
|
+
from?: string;
|
|
34
|
+
/** Default reply-to. `EMAIL_REPLY_TO` when omitted. */
|
|
35
|
+
replyTo?: string;
|
|
36
|
+
resend?: ResendEmailOptions;
|
|
37
|
+
smtp?: SmtpEmailOptions;
|
|
38
|
+
brevo?: BrevoEmailOptions;
|
|
39
|
+
}
|