@miguelmorales13/nestkit 0.26.0 → 0.28.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.
Files changed (278) hide show
  1. package/dist/alerts/alert-on-failure.decorator.d.ts +5 -0
  2. package/dist/alerts/alert-sinks.d.ts +29 -0
  3. package/dist/alerts/alerts.module.d.ts +19 -0
  4. package/dist/alerts/alerts.options.d.ts +1 -0
  5. package/dist/alerts/alerts.service.d.ts +28 -0
  6. package/dist/alerts/alerts.types.d.ts +66 -0
  7. package/dist/alerts/index.cjs +276 -0
  8. package/dist/alerts/index.d.ts +10 -0
  9. package/dist/alerts/index.js +276 -0
  10. package/dist/alerts/logger-with-alerts.d.ts +18 -0
  11. package/dist/alerts/process-guards.d.ts +21 -0
  12. package/dist/alerts/runtime.d.ts +4 -0
  13. package/dist/audit/index.cjs +13 -13
  14. package/dist/audit/index.js +2 -2
  15. package/dist/auth/index.cjs +21 -21
  16. package/dist/auth/index.js +3 -3
  17. package/dist/auth/oauth/index.cjs +101 -101
  18. package/dist/auth/oauth/index.js +3 -3
  19. package/dist/bootstrap/apply-defaults.d.ts +9 -0
  20. package/dist/bootstrap/index.cjs +7 -6
  21. package/dist/bootstrap/index.js +6 -5
  22. package/dist/chunk-3TUMVLPJ.js +14 -0
  23. package/dist/{chunk-PA24P76K.js → chunk-45SW7FBE.js} +1 -1
  24. package/dist/{chunk-RF75KC63.cjs → chunk-47IYXZHW.cjs} +2 -2
  25. package/dist/{chunk-TUNDBBQF.js → chunk-4WWOKZIO.js} +4 -4
  26. package/dist/{chunk-2DUEQKOI.js → chunk-5LVGCTJ3.js} +4 -4
  27. package/dist/chunk-A6YGIZCQ.cjs +14 -0
  28. package/dist/chunk-A7FI6HXV.js +40 -0
  29. package/dist/chunk-CU4FUIVJ.cjs +8 -0
  30. package/dist/{chunk-FH5UNWWW.cjs → chunk-D35TBVRO.cjs} +4 -4
  31. package/dist/{chunk-4MGIQFAJ.js → chunk-D3DDJWUD.js} +5 -0
  32. package/dist/chunk-DVGPEBUL.js +8 -0
  33. package/dist/{chunk-VKOPDDCC.js → chunk-ENZ7LQRE.js} +1 -1
  34. package/dist/{chunk-3AUOOEQO.cjs → chunk-F77X4QUN.cjs} +2 -2
  35. package/dist/chunk-FBNV5X6C.js +61 -0
  36. package/dist/{chunk-APUFKA4K.cjs → chunk-FDZQCLLK.cjs} +6 -6
  37. package/dist/{chunk-DYHSOULW.js → chunk-IGSNB5BX.js} +1 -1
  38. package/dist/chunk-IVWPA6QH.cjs +90 -0
  39. package/dist/{chunk-LSDY6ETG.cjs → chunk-JJKGQNGD.cjs} +5 -5
  40. package/dist/{chunk-ALIKVFOV.cjs → chunk-JRFE7NSO.cjs} +12 -4
  41. package/dist/{chunk-HVHYZXBB.cjs → chunk-KNU5RN3O.cjs} +3 -3
  42. package/dist/{chunk-52IOOHNX.cjs → chunk-KQPJCVN3.cjs} +26 -26
  43. package/dist/chunk-LGFHLAY3.cjs +61 -0
  44. package/dist/{chunk-2REOCMUD.cjs → chunk-LRX7AMSS.cjs} +6 -1
  45. package/dist/{chunk-4PFAKLT3.js → chunk-MUWHGBIB.js} +1 -1
  46. package/dist/{chunk-ZJMLEP5H.js → chunk-NJYLQDB3.js} +1 -1
  47. package/dist/{chunk-IFNYRZP2.js → chunk-OSRH6KYZ.js} +4 -4
  48. package/dist/{chunk-6RAPVLJM.js → chunk-OTE77ONL.js} +1 -1
  49. package/dist/chunk-UDACUMLO.cjs +40 -0
  50. package/dist/{chunk-PFHHLB7B.js → chunk-UGAAJRPO.js} +10 -2
  51. package/dist/{chunk-SPTDXUED.cjs → chunk-URLDTS2Q.cjs} +2 -2
  52. package/dist/{chunk-W2T2VFLC.cjs → chunk-VALDHJOO.cjs} +5 -5
  53. package/dist/chunk-WFCQDOSN.js +90 -0
  54. package/dist/consent/consent.interceptor.d.ts +20 -0
  55. package/dist/consent/consent.module.d.ts +25 -0
  56. package/dist/consent/consent.options.d.ts +30 -0
  57. package/dist/consent/consent.port.d.ts +17 -0
  58. package/dist/consent/consent.service.d.ts +44 -0
  59. package/dist/consent/guard/index.cjs +13 -0
  60. package/dist/consent/guard/index.d.ts +31 -0
  61. package/dist/consent/guard/index.js +13 -0
  62. package/dist/consent/index.cjs +271 -0
  63. package/dist/consent/index.d.ts +13 -0
  64. package/dist/consent/index.js +271 -0
  65. package/dist/consent/memory.store.d.ts +7 -0
  66. package/dist/consent/shared/index.cjs +11 -0
  67. package/dist/consent/shared/index.d.ts +19 -0
  68. package/dist/consent/shared/index.js +11 -0
  69. package/dist/consent/typeorm.store.d.ts +22 -0
  70. package/dist/crud/index.cjs +4 -4
  71. package/dist/crud/index.js +3 -3
  72. package/dist/database/postgres/index.cjs +3 -3
  73. package/dist/database/postgres/index.js +2 -2
  74. package/dist/database/supabase/index.cjs +3 -3
  75. package/dist/database/supabase/index.js +2 -2
  76. package/dist/database/typeorm/index.cjs +2 -2
  77. package/dist/database/typeorm/index.js +1 -1
  78. package/dist/devices/device-check.interceptor.d.ts +20 -0
  79. package/dist/devices/devices.module.d.ts +28 -0
  80. package/dist/devices/devices.options.d.ts +53 -0
  81. package/dist/devices/devices.port.d.ts +62 -0
  82. package/dist/devices/devices.service.d.ts +58 -0
  83. package/dist/devices/index.cjs +327 -0
  84. package/dist/devices/index.d.ts +8 -0
  85. package/dist/devices/index.js +327 -0
  86. package/dist/devices/memory.store.d.ts +12 -0
  87. package/dist/email/index.cjs +2 -2
  88. package/dist/email/index.js +1 -1
  89. package/dist/email/nodemailer/index.cjs +2 -2
  90. package/dist/email/nodemailer/index.js +1 -1
  91. package/dist/email/resend/index.cjs +2 -2
  92. package/dist/email/resend/index.js +1 -1
  93. package/dist/entities/index.cjs +1 -1
  94. package/dist/entities/index.js +1 -1
  95. package/dist/errors/index.cjs +7 -7
  96. package/dist/errors/index.js +7 -7
  97. package/dist/events/buses.d.ts +27 -0
  98. package/dist/events/events.controller.d.ts +15 -0
  99. package/dist/events/events.module.d.ts +29 -0
  100. package/dist/events/events.options.d.ts +50 -0
  101. package/dist/events/events.service.d.ts +49 -0
  102. package/dist/events/events.types.d.ts +77 -0
  103. package/dist/events/index.cjs +557 -0
  104. package/dist/events/index.d.ts +10 -0
  105. package/dist/events/index.js +557 -0
  106. package/dist/events/memory-ticket.store.d.ts +9 -0
  107. package/dist/google-business/google-business-http.d.ts +41 -0
  108. package/dist/google-business/google-business.errors.d.ts +75 -0
  109. package/dist/google-business/google-business.mappers.d.ts +52 -0
  110. package/dist/google-business/google-business.module.d.ts +26 -0
  111. package/dist/google-business/google-business.options.d.ts +40 -0
  112. package/dist/google-business/google-business.ports.d.ts +18 -0
  113. package/dist/google-business/google-business.service.d.ts +120 -0
  114. package/dist/google-business/google-business.types.d.ts +155 -0
  115. package/dist/google-business/index.cjs +1025 -0
  116. package/dist/google-business/index.d.ts +15 -0
  117. package/dist/google-business/index.js +1025 -0
  118. package/dist/google-business/testing/google-simulator.d.ts +61 -0
  119. package/dist/hardening/body-limits.d.ts +24 -0
  120. package/dist/hardening/http.types.d.ts +26 -0
  121. package/dist/hardening/index.cjs +179 -0
  122. package/dist/hardening/index.d.ts +19 -0
  123. package/dist/hardening/index.js +179 -0
  124. package/dist/hardening/memory-rate-limit.store.d.ts +10 -0
  125. package/dist/hardening/origin-secret.d.ts +29 -0
  126. package/dist/hardening/rate-limit.decorator.d.ts +8 -0
  127. package/dist/hardening/rate-limit.guard.d.ts +18 -0
  128. package/dist/hardening/rate-limit.module.d.ts +23 -0
  129. package/dist/hardening/rate-limit.options.d.ts +35 -0
  130. package/dist/hardening/rate-limit.port.d.ts +11 -0
  131. package/dist/hardening/redis-rate-limit.store.d.ts +23 -0
  132. package/dist/hardening/trust-proxy.d.ts +22 -0
  133. package/dist/health/health.controller.d.ts +32 -0
  134. package/dist/health/health.module.d.ts +15 -0
  135. package/dist/health/health.options.d.ts +24 -0
  136. package/dist/health/index.cjs +103 -0
  137. package/dist/health/index.d.ts +5 -0
  138. package/dist/health/index.js +103 -0
  139. package/dist/i18n/index.cjs +3 -3
  140. package/dist/i18n/index.js +2 -2
  141. package/dist/idempotency/idempotency.interceptor.d.ts +1 -0
  142. package/dist/idempotency/idempotency.options.d.ts +15 -0
  143. package/dist/idempotency/index.cjs +214 -7
  144. package/dist/idempotency/index.d.ts +5 -0
  145. package/dist/idempotency/index.js +210 -3
  146. package/dist/idempotency/no-idempotency.decorator.d.ts +8 -0
  147. package/dist/idempotency/postgres.store.d.ts +49 -0
  148. package/dist/idempotency/redis.store.d.ts +59 -0
  149. package/dist/index.cjs +19 -18
  150. package/dist/index.js +32 -31
  151. package/dist/invoicing/index.cjs +2 -2
  152. package/dist/invoicing/index.js +1 -1
  153. package/dist/jobs/defer-job.d.ts +10 -0
  154. package/dist/jobs/index.cjs +318 -0
  155. package/dist/jobs/index.d.ts +8 -0
  156. package/dist/jobs/index.js +318 -0
  157. package/dist/jobs/jobs-admin.controller.d.ts +18 -0
  158. package/dist/jobs/jobs.module.d.ts +33 -0
  159. package/dist/jobs/jobs.options.d.ts +62 -0
  160. package/dist/jobs/jobs.service.d.ts +53 -0
  161. package/dist/jobs/jobs.sql.d.ts +11 -0
  162. package/dist/media/index.cjs +14 -14
  163. package/dist/media/index.js +1 -1
  164. package/dist/meta/index.cjs +3 -3
  165. package/dist/meta/index.js +1 -1
  166. package/dist/notifications/index.cjs +375 -0
  167. package/dist/notifications/index.d.ts +8 -0
  168. package/dist/notifications/index.js +375 -0
  169. package/dist/notifications/memory.stores.d.ts +23 -0
  170. package/dist/notifications/notifications.controller.d.ts +11 -0
  171. package/dist/notifications/notifications.module.d.ts +31 -0
  172. package/dist/notifications/notifications.options.d.ts +33 -0
  173. package/dist/notifications/notifications.port.d.ts +97 -0
  174. package/dist/notifications/notifier.service.d.ts +31 -0
  175. package/dist/payments/index.cjs +7 -7
  176. package/dist/payments/index.js +1 -1
  177. package/dist/pinterest/index.cjs +3 -3
  178. package/dist/pinterest/index.js +1 -1
  179. package/dist/privacy/anonymizer.d.ts +14 -0
  180. package/dist/privacy/index.cjs +768 -0
  181. package/dist/privacy/index.d.ts +13 -0
  182. package/dist/privacy/index.js +768 -0
  183. package/dist/privacy/memory.store.d.ts +15 -0
  184. package/dist/privacy/privacy.module.d.ts +30 -0
  185. package/dist/privacy/privacy.options.d.ts +43 -0
  186. package/dist/privacy/privacy.port.d.ts +25 -0
  187. package/dist/privacy/privacy.service.d.ts +69 -0
  188. package/dist/privacy/privacy.types.d.ts +125 -0
  189. package/dist/privacy/sql.d.ts +7 -0
  190. package/dist/privacy/sql.store.d.ts +21 -0
  191. package/dist/privacy/zip.d.ts +23 -0
  192. package/dist/push/index.cjs +13 -13
  193. package/dist/push/index.js +5 -5
  194. package/dist/resilience/alert-channels.d.ts +39 -0
  195. package/dist/resilience/alert-errors.interceptor.d.ts +10 -0
  196. package/dist/resilience/alert-on-failure.decorator.d.ts +10 -0
  197. package/dist/resilience/alert.service.d.ts +77 -0
  198. package/dist/resilience/index.cjs +863 -0
  199. package/dist/resilience/index.d.ts +18 -0
  200. package/dist/resilience/index.js +863 -0
  201. package/dist/resilience/memory-alert-store.d.ts +26 -0
  202. package/dist/resilience/provider-health.controller.d.ts +14 -0
  203. package/dist/resilience/provider-unavailable.exception.d.ts +11 -0
  204. package/dist/resilience/resilience.module.d.ts +34 -0
  205. package/dist/resilience/resilience.options.d.ts +28 -0
  206. package/dist/resilience/resilience.types.d.ts +167 -0
  207. package/dist/resilience/resilient-fetch.d.ts +38 -0
  208. package/dist/resilience/runtime.d.ts +24 -0
  209. package/dist/resilience/typeorm/alert.entity.d.ts +21 -0
  210. package/dist/resilience/typeorm/index.cjs +102 -0
  211. package/dist/resilience/typeorm/index.d.ts +3 -0
  212. package/dist/resilience/typeorm/index.js +102 -0
  213. package/dist/resilience/typeorm/typeorm-alert-store.d.ts +39 -0
  214. package/dist/resilience/validate-destination.d.ts +63 -0
  215. package/dist/response/index.cjs +3 -3
  216. package/dist/response/index.js +2 -2
  217. package/dist/scheduling/cron-lock.service.d.ts +36 -0
  218. package/dist/scheduling/cron-unico.decorator.d.ts +27 -0
  219. package/dist/scheduling/fallback.store.d.ts +34 -0
  220. package/dist/scheduling/index.cjs +392 -0
  221. package/dist/scheduling/index.d.ts +18 -0
  222. package/dist/scheduling/index.js +392 -0
  223. package/dist/scheduling/lock-store.port.d.ts +19 -0
  224. package/dist/scheduling/memory.store.d.ts +15 -0
  225. package/dist/scheduling/redis.module.d.ts +31 -0
  226. package/dist/scheduling/redis.store.d.ts +24 -0
  227. package/dist/scheduling/scheduling.module.d.ts +24 -0
  228. package/dist/scheduling/scheduling.options.d.ts +27 -0
  229. package/dist/scheduling/sql.store.d.ts +26 -0
  230. package/dist/secrets/index.cjs +274 -0
  231. package/dist/secrets/index.d.ts +8 -0
  232. package/dist/secrets/index.js +274 -0
  233. package/dist/secrets/secrets.errors.d.ts +6 -0
  234. package/dist/secrets/secrets.module.d.ts +21 -0
  235. package/dist/secrets/secrets.options.d.ts +32 -0
  236. package/dist/secrets/secrets.service.d.ts +54 -0
  237. package/dist/secrets/secrets.transformer.d.ts +33 -0
  238. package/dist/security/hash.d.ts +8 -0
  239. package/dist/security/index.cjs +119 -2
  240. package/dist/security/index.d.ts +5 -0
  241. package/dist/security/index.js +119 -2
  242. package/dist/security/mask.d.ts +22 -0
  243. package/dist/security/signed-grant.d.ts +30 -0
  244. package/dist/storage/index.cjs +2 -2
  245. package/dist/storage/index.js +1 -1
  246. package/dist/stripe/index.cjs +7 -7
  247. package/dist/stripe/index.js +1 -1
  248. package/dist/telegram/index.cjs +2 -2
  249. package/dist/telegram/index.js +1 -1
  250. package/dist/tenancy/app-role.d.ts +24 -0
  251. package/dist/tenancy/db-helpers.d.ts +12 -0
  252. package/dist/tenancy/index.cjs +205 -0
  253. package/dist/tenancy/index.d.ts +14 -0
  254. package/dist/tenancy/index.js +205 -0
  255. package/dist/tenancy/pg/index.cjs +34 -0
  256. package/dist/tenancy/pg/index.d.ts +2 -0
  257. package/dist/tenancy/pg/index.js +34 -0
  258. package/dist/tenancy/pg/with-tenant.d.ts +23 -0
  259. package/dist/tenancy/request-context.d.ts +18 -0
  260. package/dist/tenancy/rls-guardrail.d.ts +38 -0
  261. package/dist/tenancy/scope.d.ts +5 -0
  262. package/dist/tenancy/tenancy.errors.d.ts +5 -0
  263. package/dist/tenancy/tenancy.middleware.d.ts +8 -0
  264. package/dist/tenancy/tenancy.module.d.ts +37 -0
  265. package/dist/tenancy/tenancy.options.d.ts +34 -0
  266. package/dist/tenancy/typeorm/index.cjs +41 -0
  267. package/dist/tenancy/typeorm/index.d.ts +2 -0
  268. package/dist/tenancy/typeorm/index.js +41 -0
  269. package/dist/tenancy/typeorm/with-tenant.d.ts +23 -0
  270. package/dist/tiktok/index.cjs +3 -3
  271. package/dist/tiktok/index.js +1 -1
  272. package/dist/tracking/index.cjs +3 -3
  273. package/dist/tracking/index.js +2 -2
  274. package/dist/umami/index.cjs +4 -4
  275. package/dist/umami/index.js +1 -1
  276. package/dist/whatsapp/index.cjs +2 -2
  277. package/dist/whatsapp/index.js +1 -1
  278. package/package.json +107 -2
@@ -0,0 +1,274 @@
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
+
3
+
4
+ var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
5
+
6
+ // src/secrets/secrets.options.ts
7
+ var SECRETS_OPTIONS = /* @__PURE__ */ Symbol("SECRETS_OPTIONS");
8
+
9
+ // src/secrets/secrets.errors.ts
10
+ var SecretsError = class extends Error {
11
+ constructor(code, message) {
12
+ super(message);
13
+ this.code = code;
14
+ this.name = "SecretsError";
15
+ }
16
+ };
17
+
18
+ // src/secrets/secrets.service.ts
19
+
20
+
21
+
22
+
23
+
24
+
25
+ var _crypto = require('crypto');
26
+ var _common = require('@nestjs/common');
27
+ var ALGORITHM = "aes-256-gcm";
28
+ var KEY_BYTES = 32;
29
+ var IV_BYTES = 12;
30
+ var PREFIX = "nk1";
31
+ var KID_PATTERN = /^[A-Za-z0-9_-]{1,32}$/;
32
+ function parseKey(raw) {
33
+ if (Buffer.isBuffer(raw)) {
34
+ if (raw.length !== KEY_BYTES) throw new SecretsError("BAD_KEY", "The key must be 32 bytes.");
35
+ return raw;
36
+ }
37
+ const text = raw.trim();
38
+ const bytes = /^[0-9a-fA-F]{64}$/.test(text) ? Buffer.from(text, "hex") : Buffer.from(text.replace(/-/g, "+").replace(/_/g, "/"), "base64");
39
+ if (bytes.length !== KEY_BYTES) {
40
+ throw new SecretsError(
41
+ "BAD_KEY",
42
+ `The key must be 32 bytes (64 hex chars or base64); got ${bytes.length}. Generate one with: openssl rand -base64 32`
43
+ );
44
+ }
45
+ return bytes;
46
+ }
47
+ function secretsOptionsFromEnv(env = process.env, names = {}) {
48
+ const keyVar = _nullishCoalesce(names.key, () => ( "APP_ENCRYPTION_KEY"));
49
+ const keysVar = _nullishCoalesce(names.keys, () => ( "APP_ENCRYPTION_KEYS"));
50
+ const activeVar = _nullishCoalesce(names.active, () => ( "APP_ENCRYPTION_KEY_ID"));
51
+ const keys = {};
52
+ for (const pair of (_nullishCoalesce(env[keysVar], () => ( ""))).split(",")) {
53
+ const at = pair.indexOf(":");
54
+ if (at < 1) continue;
55
+ keys[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();
56
+ }
57
+ const single = _optionalChain([env, 'access', _ => _[keyVar], 'optionalAccess', _2 => _2.trim, 'call', _3 => _3()]);
58
+ if (single && Object.keys(keys).length === 0) keys["default"] = single;
59
+ const ids = Object.keys(keys);
60
+ if (ids.length === 0) return {};
61
+ return { keys, activeKid: _optionalChain([env, 'access', _4 => _4[activeVar], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]) || ids[ids.length - 1] };
62
+ }
63
+ var SecretsService = class {
64
+ constructor(options = {}) {
65
+ this.keys = /* @__PURE__ */ new Map();
66
+ for (const [kid, raw] of Object.entries(_nullishCoalesce(options.keys, () => ( {})))) {
67
+ if (!KID_PATTERN.test(kid)) {
68
+ throw new SecretsError(
69
+ "BAD_KEY",
70
+ `Invalid key id "${kid}" (letters, digits, _ or -, up to 32).`
71
+ );
72
+ }
73
+ this.keys.set(kid, parseKey(raw));
74
+ }
75
+ const ids = [...this.keys.keys()];
76
+ if (ids.length === 0) this.active = null;
77
+ else if (options.activeKid) {
78
+ if (!this.keys.has(options.activeKid)) {
79
+ throw new SecretsError(
80
+ "UNKNOWN_KID",
81
+ `activeKid "${options.activeKid}" is not among the keys.`
82
+ );
83
+ }
84
+ this.active = options.activeKid;
85
+ } else if (ids.length === 1) this.active = ids[0];
86
+ else throw new SecretsError("BAD_KEY", "Several keys configured: set activeKid.");
87
+ if (options.legacyKid && !this.keys.has(options.legacyKid)) {
88
+ throw new SecretsError(
89
+ "UNKNOWN_KID",
90
+ `legacyKid "${options.legacyKid}" is not among the keys.`
91
+ );
92
+ }
93
+ this.derive = _nullishCoalesce(options.derive, () => ( false));
94
+ this.legacyKid = options.legacyKid;
95
+ }
96
+ onModuleInit() {
97
+ setDefaultSecrets(this);
98
+ }
99
+ /** `false` when no key is configured: callers can hide the feature instead of failing late. */
100
+ get enabled() {
101
+ return this.active !== null;
102
+ }
103
+ get activeKid() {
104
+ return this.active;
105
+ }
106
+ encrypt(plain, options = {}) {
107
+ if (this.active === null) {
108
+ throw new SecretsError("NO_KEY", "No encryption key configured; secrets cannot be stored.");
109
+ }
110
+ const key = this.keyFor(this.active, options.context);
111
+ const iv = _crypto.randomBytes.call(void 0, IV_BYTES);
112
+ const cipher = _crypto.createCipheriv.call(void 0, ALGORITHM, key, iv);
113
+ if (options.context) cipher.setAAD(Buffer.from(options.context, "utf8"));
114
+ const body = Buffer.concat([cipher.update(plain, "utf8"), cipher.final()]);
115
+ return [PREFIX, this.active, b64(iv), b64(cipher.getAuthTag()), b64(body)].join(".");
116
+ }
117
+ decrypt(payload, options = {}) {
118
+ const parts = payload.split(".");
119
+ if (parts[0] === PREFIX && parts.length === 5) {
120
+ const [, kid, iv, tag, body] = parts;
121
+ return this.open(this.keyFor(kid, options.context), iv, tag, body, "base64url", options.context);
122
+ }
123
+ if (this.legacyKid && parts.length === 3) {
124
+ return this.open(this.legacyKey(), parts[0], parts[1], parts[2], "base64");
125
+ }
126
+ if (this.legacyKid && parts.length === 4 && parts[0] === "v1") {
127
+ return this.open(this.legacyKey(), parts[1], parts[2], parts[3], "base64url");
128
+ }
129
+ throw new SecretsError("BAD_FORMAT", "Unrecognised encrypted secret format.");
130
+ }
131
+ /** Is this value one of ours (current format)? Cheap, needs no key. */
132
+ isEncrypted(value) {
133
+ return typeof value === "string" && value.startsWith(`${PREFIX}.`) && value.split(".").length === 5;
134
+ }
135
+ /** True when sealed with a key that is no longer the active one, or in a legacy shape. */
136
+ needsRotation(payload) {
137
+ if (!this.isEncrypted(payload)) return true;
138
+ return payload.split(".")[1] !== this.active;
139
+ }
140
+ /** Re-seals under the active key. Returns the input untouched if it already is. */
141
+ rotate(payload, options = {}) {
142
+ return this.needsRotation(payload) ? this.encrypt(this.decrypt(payload, options), options) : payload;
143
+ }
144
+ /** Last characters, so an owner can recognise which credential is stored without reading it. */
145
+ hint(secret, visible = 4) {
146
+ return secret.length <= visible ? "\u2022\u2022\u2022\u2022" : secret.slice(-visible);
147
+ }
148
+ /** Constant-time comparison (webhook signatures, tokens). */
149
+ static safeEqual(a, b) {
150
+ const ba = Buffer.from(a, "utf8");
151
+ const bb = Buffer.from(b, "utf8");
152
+ return ba.length === bb.length && _crypto.timingSafeEqual.call(void 0, ba, bb);
153
+ }
154
+ keyFor(kid, context) {
155
+ const master = this.keys.get(kid);
156
+ if (!master) {
157
+ throw new SecretsError(
158
+ "UNKNOWN_KID",
159
+ `No key with id "${kid}"; keep old keys listed until their rows are rotated.`
160
+ );
161
+ }
162
+ if (!this.derive) return master;
163
+ if (!context) {
164
+ throw new SecretsError("CONTEXT_REQUIRED", "derive is on: pass a context (e.g. the tenant id).");
165
+ }
166
+ return Buffer.from(
167
+ _crypto.hkdfSync.call(void 0, "sha256", master, Buffer.from(kid), `nestkit-secrets:${context}`, KEY_BYTES)
168
+ );
169
+ }
170
+ /** Legacy payloads predate derivation and context: the master key itself, no AAD. */
171
+ legacyKey() {
172
+ return this.keys.get(this.legacyKid);
173
+ }
174
+ open(key, iv, tag, body, alphabet, context) {
175
+ try {
176
+ const decipher = _crypto.createDecipheriv.call(void 0, ALGORITHM, key, Buffer.from(iv, alphabet));
177
+ if (context) decipher.setAAD(Buffer.from(context, "utf8"));
178
+ decipher.setAuthTag(Buffer.from(tag, alphabet));
179
+ return Buffer.concat([
180
+ decipher.update(Buffer.from(body, alphabet)),
181
+ decipher.final()
182
+ ]).toString("utf8");
183
+ } catch (e) {
184
+ throw new SecretsError(
185
+ "TAMPERED",
186
+ "The secret was altered, or the key or context is not the one that sealed it."
187
+ );
188
+ }
189
+ }
190
+ };
191
+ SecretsService = exports.SecretsService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
192
+ _common.Injectable.call(void 0, ),
193
+ _chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, SECRETS_OPTIONS))
194
+ ], SecretsService);
195
+ var b64 = (b) => b.toString("base64url");
196
+ var defaultSecrets = null;
197
+ function setDefaultSecrets(service) {
198
+ defaultSecrets = service;
199
+ }
200
+ function getDefaultSecrets() {
201
+ if (!defaultSecrets) {
202
+ throw new SecretsError(
203
+ "NO_KEY",
204
+ "SecretsModule is not registered; the column transformer has no service."
205
+ );
206
+ }
207
+ return defaultSecrets;
208
+ }
209
+
210
+ // src/secrets/secrets.transformer.ts
211
+ var EncryptedColumnTransformer = class {
212
+ constructor(options = {}) {
213
+ this.options = options;
214
+ }
215
+ to(value) {
216
+ if (value === null || value === void 0) return value;
217
+ const secrets = this.service();
218
+ const plain = this.options.json ? JSON.stringify(value) : String(value);
219
+ return secrets.encrypt(plain, { context: this.options.context });
220
+ }
221
+ from(value) {
222
+ if (value === null || value === void 0) return value;
223
+ if (typeof value !== "string") {
224
+ throw new SecretsError("BAD_FORMAT", "An encrypted column must hold text.");
225
+ }
226
+ const secrets = this.service();
227
+ if (!secrets.isEncrypted(value) && this.options.allowPlaintext) {
228
+ return this.options.json ? JSON.parse(value) : value;
229
+ }
230
+ const plain = secrets.decrypt(value, { context: this.options.context });
231
+ return this.options.json ? JSON.parse(plain) : plain;
232
+ }
233
+ service() {
234
+ return _nullishCoalesce(this.options.service, () => ( getDefaultSecrets()));
235
+ }
236
+ };
237
+
238
+ // src/secrets/secrets.module.ts
239
+
240
+ var SecretsModule = class {
241
+ static forRoot(options = {}) {
242
+ return {
243
+ module: SecretsModule,
244
+ providers: [{ provide: SECRETS_OPTIONS, useValue: options }, SecretsService],
245
+ exports: [SecretsService, SECRETS_OPTIONS]
246
+ };
247
+ }
248
+ static forRootAsync(config) {
249
+ return {
250
+ module: SecretsModule,
251
+ imports: _nullishCoalesce(config.imports, () => ( [])),
252
+ providers: [
253
+ { provide: SECRETS_OPTIONS, useFactory: config.useFactory, inject: _nullishCoalesce(config.inject, () => ( [])) },
254
+ SecretsService
255
+ ],
256
+ exports: [SecretsService, SECRETS_OPTIONS]
257
+ };
258
+ }
259
+ };
260
+ SecretsModule = exports.SecretsModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
261
+ _common.Global.call(void 0, ),
262
+ _common.Module.call(void 0, {})
263
+ ], SecretsModule);
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+ exports.EncryptedColumnTransformer = EncryptedColumnTransformer; exports.SECRETS_OPTIONS = SECRETS_OPTIONS; exports.SecretsError = SecretsError; exports.SecretsModule = SecretsModule; exports.SecretsService = SecretsService; exports.getDefaultSecrets = getDefaultSecrets; exports.parseKey = parseKey; exports.secretsOptionsFromEnv = secretsOptionsFromEnv; exports.setDefaultSecrets = setDefaultSecrets;
@@ -0,0 +1,8 @@
1
+ export { SECRETS_OPTIONS } from './secrets.options.js';
2
+ export type { SecretsOptions, SecretsContextOptions } from './secrets.options.js';
3
+ export { SecretsError } from './secrets.errors.js';
4
+ export type { SecretsErrorCode } from './secrets.errors.js';
5
+ export { SecretsService, parseKey, secretsOptionsFromEnv, getDefaultSecrets, setDefaultSecrets, } from './secrets.service.js';
6
+ export { EncryptedColumnTransformer } from './secrets.transformer.js';
7
+ export type { EncryptedColumnOptions } from './secrets.transformer.js';
8
+ export { SecretsModule } from './secrets.module.js';
@@ -0,0 +1,274 @@
1
+ import {
2
+ __decorateClass,
3
+ __decorateParam
4
+ } from "../chunk-D3DDJWUD.js";
5
+
6
+ // src/secrets/secrets.options.ts
7
+ var SECRETS_OPTIONS = /* @__PURE__ */ Symbol("SECRETS_OPTIONS");
8
+
9
+ // src/secrets/secrets.errors.ts
10
+ var SecretsError = class extends Error {
11
+ constructor(code, message) {
12
+ super(message);
13
+ this.code = code;
14
+ this.name = "SecretsError";
15
+ }
16
+ };
17
+
18
+ // src/secrets/secrets.service.ts
19
+ import {
20
+ createCipheriv,
21
+ createDecipheriv,
22
+ hkdfSync,
23
+ randomBytes,
24
+ timingSafeEqual
25
+ } from "crypto";
26
+ import { Inject, Injectable } from "@nestjs/common";
27
+ var ALGORITHM = "aes-256-gcm";
28
+ var KEY_BYTES = 32;
29
+ var IV_BYTES = 12;
30
+ var PREFIX = "nk1";
31
+ var KID_PATTERN = /^[A-Za-z0-9_-]{1,32}$/;
32
+ function parseKey(raw) {
33
+ if (Buffer.isBuffer(raw)) {
34
+ if (raw.length !== KEY_BYTES) throw new SecretsError("BAD_KEY", "The key must be 32 bytes.");
35
+ return raw;
36
+ }
37
+ const text = raw.trim();
38
+ const bytes = /^[0-9a-fA-F]{64}$/.test(text) ? Buffer.from(text, "hex") : Buffer.from(text.replace(/-/g, "+").replace(/_/g, "/"), "base64");
39
+ if (bytes.length !== KEY_BYTES) {
40
+ throw new SecretsError(
41
+ "BAD_KEY",
42
+ `The key must be 32 bytes (64 hex chars or base64); got ${bytes.length}. Generate one with: openssl rand -base64 32`
43
+ );
44
+ }
45
+ return bytes;
46
+ }
47
+ function secretsOptionsFromEnv(env = process.env, names = {}) {
48
+ const keyVar = names.key ?? "APP_ENCRYPTION_KEY";
49
+ const keysVar = names.keys ?? "APP_ENCRYPTION_KEYS";
50
+ const activeVar = names.active ?? "APP_ENCRYPTION_KEY_ID";
51
+ const keys = {};
52
+ for (const pair of (env[keysVar] ?? "").split(",")) {
53
+ const at = pair.indexOf(":");
54
+ if (at < 1) continue;
55
+ keys[pair.slice(0, at).trim()] = pair.slice(at + 1).trim();
56
+ }
57
+ const single = env[keyVar]?.trim();
58
+ if (single && Object.keys(keys).length === 0) keys["default"] = single;
59
+ const ids = Object.keys(keys);
60
+ if (ids.length === 0) return {};
61
+ return { keys, activeKid: env[activeVar]?.trim() || ids[ids.length - 1] };
62
+ }
63
+ var SecretsService = class {
64
+ constructor(options = {}) {
65
+ this.keys = /* @__PURE__ */ new Map();
66
+ for (const [kid, raw] of Object.entries(options.keys ?? {})) {
67
+ if (!KID_PATTERN.test(kid)) {
68
+ throw new SecretsError(
69
+ "BAD_KEY",
70
+ `Invalid key id "${kid}" (letters, digits, _ or -, up to 32).`
71
+ );
72
+ }
73
+ this.keys.set(kid, parseKey(raw));
74
+ }
75
+ const ids = [...this.keys.keys()];
76
+ if (ids.length === 0) this.active = null;
77
+ else if (options.activeKid) {
78
+ if (!this.keys.has(options.activeKid)) {
79
+ throw new SecretsError(
80
+ "UNKNOWN_KID",
81
+ `activeKid "${options.activeKid}" is not among the keys.`
82
+ );
83
+ }
84
+ this.active = options.activeKid;
85
+ } else if (ids.length === 1) this.active = ids[0];
86
+ else throw new SecretsError("BAD_KEY", "Several keys configured: set activeKid.");
87
+ if (options.legacyKid && !this.keys.has(options.legacyKid)) {
88
+ throw new SecretsError(
89
+ "UNKNOWN_KID",
90
+ `legacyKid "${options.legacyKid}" is not among the keys.`
91
+ );
92
+ }
93
+ this.derive = options.derive ?? false;
94
+ this.legacyKid = options.legacyKid;
95
+ }
96
+ onModuleInit() {
97
+ setDefaultSecrets(this);
98
+ }
99
+ /** `false` when no key is configured: callers can hide the feature instead of failing late. */
100
+ get enabled() {
101
+ return this.active !== null;
102
+ }
103
+ get activeKid() {
104
+ return this.active;
105
+ }
106
+ encrypt(plain, options = {}) {
107
+ if (this.active === null) {
108
+ throw new SecretsError("NO_KEY", "No encryption key configured; secrets cannot be stored.");
109
+ }
110
+ const key = this.keyFor(this.active, options.context);
111
+ const iv = randomBytes(IV_BYTES);
112
+ const cipher = createCipheriv(ALGORITHM, key, iv);
113
+ if (options.context) cipher.setAAD(Buffer.from(options.context, "utf8"));
114
+ const body = Buffer.concat([cipher.update(plain, "utf8"), cipher.final()]);
115
+ return [PREFIX, this.active, b64(iv), b64(cipher.getAuthTag()), b64(body)].join(".");
116
+ }
117
+ decrypt(payload, options = {}) {
118
+ const parts = payload.split(".");
119
+ if (parts[0] === PREFIX && parts.length === 5) {
120
+ const [, kid, iv, tag, body] = parts;
121
+ return this.open(this.keyFor(kid, options.context), iv, tag, body, "base64url", options.context);
122
+ }
123
+ if (this.legacyKid && parts.length === 3) {
124
+ return this.open(this.legacyKey(), parts[0], parts[1], parts[2], "base64");
125
+ }
126
+ if (this.legacyKid && parts.length === 4 && parts[0] === "v1") {
127
+ return this.open(this.legacyKey(), parts[1], parts[2], parts[3], "base64url");
128
+ }
129
+ throw new SecretsError("BAD_FORMAT", "Unrecognised encrypted secret format.");
130
+ }
131
+ /** Is this value one of ours (current format)? Cheap, needs no key. */
132
+ isEncrypted(value) {
133
+ return typeof value === "string" && value.startsWith(`${PREFIX}.`) && value.split(".").length === 5;
134
+ }
135
+ /** True when sealed with a key that is no longer the active one, or in a legacy shape. */
136
+ needsRotation(payload) {
137
+ if (!this.isEncrypted(payload)) return true;
138
+ return payload.split(".")[1] !== this.active;
139
+ }
140
+ /** Re-seals under the active key. Returns the input untouched if it already is. */
141
+ rotate(payload, options = {}) {
142
+ return this.needsRotation(payload) ? this.encrypt(this.decrypt(payload, options), options) : payload;
143
+ }
144
+ /** Last characters, so an owner can recognise which credential is stored without reading it. */
145
+ hint(secret, visible = 4) {
146
+ return secret.length <= visible ? "\u2022\u2022\u2022\u2022" : secret.slice(-visible);
147
+ }
148
+ /** Constant-time comparison (webhook signatures, tokens). */
149
+ static safeEqual(a, b) {
150
+ const ba = Buffer.from(a, "utf8");
151
+ const bb = Buffer.from(b, "utf8");
152
+ return ba.length === bb.length && timingSafeEqual(ba, bb);
153
+ }
154
+ keyFor(kid, context) {
155
+ const master = this.keys.get(kid);
156
+ if (!master) {
157
+ throw new SecretsError(
158
+ "UNKNOWN_KID",
159
+ `No key with id "${kid}"; keep old keys listed until their rows are rotated.`
160
+ );
161
+ }
162
+ if (!this.derive) return master;
163
+ if (!context) {
164
+ throw new SecretsError("CONTEXT_REQUIRED", "derive is on: pass a context (e.g. the tenant id).");
165
+ }
166
+ return Buffer.from(
167
+ hkdfSync("sha256", master, Buffer.from(kid), `nestkit-secrets:${context}`, KEY_BYTES)
168
+ );
169
+ }
170
+ /** Legacy payloads predate derivation and context: the master key itself, no AAD. */
171
+ legacyKey() {
172
+ return this.keys.get(this.legacyKid);
173
+ }
174
+ open(key, iv, tag, body, alphabet, context) {
175
+ try {
176
+ const decipher = createDecipheriv(ALGORITHM, key, Buffer.from(iv, alphabet));
177
+ if (context) decipher.setAAD(Buffer.from(context, "utf8"));
178
+ decipher.setAuthTag(Buffer.from(tag, alphabet));
179
+ return Buffer.concat([
180
+ decipher.update(Buffer.from(body, alphabet)),
181
+ decipher.final()
182
+ ]).toString("utf8");
183
+ } catch {
184
+ throw new SecretsError(
185
+ "TAMPERED",
186
+ "The secret was altered, or the key or context is not the one that sealed it."
187
+ );
188
+ }
189
+ }
190
+ };
191
+ SecretsService = __decorateClass([
192
+ Injectable(),
193
+ __decorateParam(0, Inject(SECRETS_OPTIONS))
194
+ ], SecretsService);
195
+ var b64 = (b) => b.toString("base64url");
196
+ var defaultSecrets = null;
197
+ function setDefaultSecrets(service) {
198
+ defaultSecrets = service;
199
+ }
200
+ function getDefaultSecrets() {
201
+ if (!defaultSecrets) {
202
+ throw new SecretsError(
203
+ "NO_KEY",
204
+ "SecretsModule is not registered; the column transformer has no service."
205
+ );
206
+ }
207
+ return defaultSecrets;
208
+ }
209
+
210
+ // src/secrets/secrets.transformer.ts
211
+ var EncryptedColumnTransformer = class {
212
+ constructor(options = {}) {
213
+ this.options = options;
214
+ }
215
+ to(value) {
216
+ if (value === null || value === void 0) return value;
217
+ const secrets = this.service();
218
+ const plain = this.options.json ? JSON.stringify(value) : String(value);
219
+ return secrets.encrypt(plain, { context: this.options.context });
220
+ }
221
+ from(value) {
222
+ if (value === null || value === void 0) return value;
223
+ if (typeof value !== "string") {
224
+ throw new SecretsError("BAD_FORMAT", "An encrypted column must hold text.");
225
+ }
226
+ const secrets = this.service();
227
+ if (!secrets.isEncrypted(value) && this.options.allowPlaintext) {
228
+ return this.options.json ? JSON.parse(value) : value;
229
+ }
230
+ const plain = secrets.decrypt(value, { context: this.options.context });
231
+ return this.options.json ? JSON.parse(plain) : plain;
232
+ }
233
+ service() {
234
+ return this.options.service ?? getDefaultSecrets();
235
+ }
236
+ };
237
+
238
+ // src/secrets/secrets.module.ts
239
+ import { Global, Module } from "@nestjs/common";
240
+ var SecretsModule = class {
241
+ static forRoot(options = {}) {
242
+ return {
243
+ module: SecretsModule,
244
+ providers: [{ provide: SECRETS_OPTIONS, useValue: options }, SecretsService],
245
+ exports: [SecretsService, SECRETS_OPTIONS]
246
+ };
247
+ }
248
+ static forRootAsync(config) {
249
+ return {
250
+ module: SecretsModule,
251
+ imports: config.imports ?? [],
252
+ providers: [
253
+ { provide: SECRETS_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },
254
+ SecretsService
255
+ ],
256
+ exports: [SecretsService, SECRETS_OPTIONS]
257
+ };
258
+ }
259
+ };
260
+ SecretsModule = __decorateClass([
261
+ Global(),
262
+ Module({})
263
+ ], SecretsModule);
264
+ export {
265
+ EncryptedColumnTransformer,
266
+ SECRETS_OPTIONS,
267
+ SecretsError,
268
+ SecretsModule,
269
+ SecretsService,
270
+ getDefaultSecrets,
271
+ parseKey,
272
+ secretsOptionsFromEnv,
273
+ setDefaultSecrets
274
+ };
@@ -0,0 +1,6 @@
1
+ export type SecretsErrorCode = 'NO_KEY' | 'BAD_KEY' | 'BAD_FORMAT' | 'UNKNOWN_KID' | 'CONTEXT_REQUIRED' | 'TAMPERED';
2
+ /** Stable `code` so callers decide by code, not by message text. Never carries the secret. */
3
+ export declare class SecretsError extends Error {
4
+ readonly code: SecretsErrorCode;
5
+ constructor(code: SecretsErrorCode, message: string);
6
+ }
@@ -0,0 +1,21 @@
1
+ import { type DynamicModule } from '@nestjs/common';
2
+ import { type SecretsOptions } from './secrets.options.js';
3
+ /**
4
+ * Encryption at rest for per-tenant third-party secrets.
5
+ *
6
+ * ```ts
7
+ * SecretsModule.forRoot({ keys: { k1: process.env.APP_ENCRYPTION_KEY! } })
8
+ * SecretsModule.forRoot(secretsOptionsFromEnv()) // APP_ENCRYPTION_KEYS / _KEY_ID
9
+ * SecretsModule.forRoot({ keys: { k1, k2 }, activeKid: 'k2', derive: true }) // rotation + per-tenant keys
10
+ * ```
11
+ *
12
+ * Registering it also makes `EncryptedColumnTransformer` work without wiring.
13
+ */
14
+ export declare class SecretsModule {
15
+ static forRoot(options?: SecretsOptions): DynamicModule;
16
+ static forRootAsync(config: {
17
+ imports?: any[];
18
+ inject?: any[];
19
+ useFactory: (...args: any[]) => SecretsOptions | Promise<SecretsOptions>;
20
+ }): DynamicModule;
21
+ }
@@ -0,0 +1,32 @@
1
+ /** DI token carrying the resolved {@link SecretsOptions}. */
2
+ export declare const SECRETS_OPTIONS: unique symbol;
3
+ export interface SecretsOptions {
4
+ /**
5
+ * Master keys by id (`kid`). Each is 32 bytes as 64 hex chars, base64/base64url, or a Buffer.
6
+ * Keep old ids here while rows encrypted with them still exist: that is rotation.
7
+ * Empty/omitted means the feature is off (`enabled === false`; `encrypt` throws `NO_KEY`).
8
+ * Generate one with `openssl rand -base64 32`.
9
+ */
10
+ keys?: Record<string, string | Buffer>;
11
+ /** Key id used to encrypt. Required when there is more than one key; defaults to the only one. */
12
+ activeKid?: string;
13
+ /**
14
+ * Derive a distinct key per `context` (HKDF-SHA256 from the master key) so each tenant
15
+ * has its own key and a leaked row cannot be opened under another tenant. Every
16
+ * `encrypt`/`decrypt` must then pass a `context`.
17
+ */
18
+ derive?: boolean;
19
+ /**
20
+ * Key id that opens payloads in the two legacy shapes this module replaces:
21
+ * `iv.tag.cipher` (three base64 parts) and `v1.iv.tag.cipher` (four base64url parts).
22
+ * They carry no `kid` and no context. New writes always use the versioned format.
23
+ */
24
+ legacyKid?: string;
25
+ }
26
+ export interface SecretsContextOptions {
27
+ /**
28
+ * Who the secret belongs to (tenant id, row id…). Authenticated as AAD: a payload copied
29
+ * to another tenant's row fails to decrypt. With `derive` it also selects the key.
30
+ */
31
+ context?: string;
32
+ }
@@ -0,0 +1,54 @@
1
+ import { type OnModuleInit } from '@nestjs/common';
2
+ import { type SecretsContextOptions, type SecretsOptions } from './secrets.options.js';
3
+ /** Parses a 32-byte key given as 64 hex chars, base64/base64url, or a Buffer. */
4
+ export declare function parseKey(raw: string | Buffer): Buffer;
5
+ /**
6
+ * Builds options from the environment. `APP_ENCRYPTION_KEYS="2026a:<key>,2026b:<key>"` plus
7
+ * `APP_ENCRYPTION_KEY_ID` (active; default the last one listed), or a single
8
+ * `APP_ENCRYPTION_KEY` (kid `default`). Variable names are overridable. Returns `{}`
9
+ * (feature off) when none is set.
10
+ */
11
+ export declare function secretsOptionsFromEnv(env?: Record<string, string | undefined>, names?: {
12
+ key?: string;
13
+ keys?: string;
14
+ active?: string;
15
+ }): SecretsOptions;
16
+ /**
17
+ * AES-256-GCM for third-party secrets stored per tenant (payment tokens, PAC keys).
18
+ *
19
+ * Output: `nk1.<kid>.<iv>.<tag>.<cipher>` (base64url). The `kid` says which key sealed a
20
+ * value, so rotation is: add the new key, make it active, keep the old ones listed, and
21
+ * re-encrypt lazily with {@link rotate}. GCM authenticates, so a flipped byte — or the wrong
22
+ * key, context or tenant — makes `decrypt` throw `TAMPERED` instead of returning garbage.
23
+ *
24
+ * Protects against a database dump; not against someone holding the dump AND the key.
25
+ */
26
+ export declare class SecretsService implements OnModuleInit {
27
+ private readonly keys;
28
+ private readonly active;
29
+ private readonly derive;
30
+ private readonly legacyKid?;
31
+ constructor(options?: SecretsOptions);
32
+ onModuleInit(): void;
33
+ /** `false` when no key is configured: callers can hide the feature instead of failing late. */
34
+ get enabled(): boolean;
35
+ get activeKid(): string | null;
36
+ encrypt(plain: string, options?: SecretsContextOptions): string;
37
+ decrypt(payload: string, options?: SecretsContextOptions): string;
38
+ /** Is this value one of ours (current format)? Cheap, needs no key. */
39
+ isEncrypted(value: unknown): value is string;
40
+ /** True when sealed with a key that is no longer the active one, or in a legacy shape. */
41
+ needsRotation(payload: string): boolean;
42
+ /** Re-seals under the active key. Returns the input untouched if it already is. */
43
+ rotate(payload: string, options?: SecretsContextOptions): string;
44
+ /** Last characters, so an owner can recognise which credential is stored without reading it. */
45
+ hint(secret: string, visible?: number): string;
46
+ /** Constant-time comparison (webhook signatures, tokens). */
47
+ static safeEqual(a: string, b: string): boolean;
48
+ private keyFor;
49
+ /** Legacy payloads predate derivation and context: the master key itself, no AAD. */
50
+ private legacyKey;
51
+ private open;
52
+ }
53
+ export declare function setDefaultSecrets(service: SecretsService | null): void;
54
+ export declare function getDefaultSecrets(): SecretsService;