@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,33 @@
1
+ import { type SecretsService } from './secrets.service.js';
2
+ export interface EncryptedColumnOptions {
3
+ /** Store `JSON.stringify(value)` and parse it back, for object-valued columns. */
4
+ json?: boolean;
5
+ /** Fixed context for every row (a per-tenant context needs explicit `encrypt` calls instead). */
6
+ context?: string;
7
+ /**
8
+ * Return values that are not encrypted as they are, instead of throwing. Only for the window
9
+ * while old plaintext rows are being migrated; they are re-sealed on the next write.
10
+ */
11
+ allowPlaintext?: boolean;
12
+ /** Service to use; defaults to the one `SecretsModule` registered. */
13
+ service?: SecretsService;
14
+ }
15
+ /**
16
+ * TypeORM `ValueTransformer` (structural: no `typeorm` import) that seals a column on write
17
+ * and opens it on read.
18
+ *
19
+ * ```ts
20
+ * @Column({ type: 'text', nullable: true, transformer: new EncryptedColumnTransformer() })
21
+ * apiToken!: string | null;
22
+ * ```
23
+ *
24
+ * Querying by the column's value will not work (every encryption is different), and a
25
+ * failed decrypt throws rather than yielding an empty credential.
26
+ */
27
+ export declare class EncryptedColumnTransformer {
28
+ private readonly options;
29
+ constructor(options?: EncryptedColumnOptions);
30
+ to(value: unknown): string | null | undefined;
31
+ from(value: unknown): unknown;
32
+ private service;
33
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Hex SHA-256 of a long random token, as stored and compared. Plain SHA-256, no salt or cost: the token
3
+ * is 32 random bytes, not a guessable password; the hash only keeps a table dump from handing out usable
4
+ * tokens, and making it expensive would be paid on every request. Do NOT use it for passwords.
5
+ */
6
+ export declare const hashSha256: (value: string) => string;
7
+ /** Compares two strings in constant time (different lengths return false without leaking where they differ). */
8
+ export declare function constantTimeEqual(a: string, b: string): boolean;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }require('../chunk-2REOCMUD.cjs');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }require('../chunk-LRX7AMSS.cjs');
2
2
 
3
3
  // src/security/signed-state.ts
4
4
  var _crypto = require('crypto');
@@ -30,6 +30,123 @@ function readState(state, options) {
30
30
  return rest;
31
31
  }
32
32
 
33
+ // src/security/mask.ts
34
+ function maskEmail(email) {
35
+ const clean = email.trim();
36
+ const at = clean.lastIndexOf("@");
37
+ if (at < 1) return "***";
38
+ return `${clean[0]}***${clean.slice(at)}`;
39
+ }
40
+ function maskPhone(phone, visible = 4) {
41
+ const digits = phone.replace(/\D/g, "");
42
+ if (digits.length <= visible) return "***";
43
+ return `***${digits.slice(-visible)}`;
44
+ }
45
+ function maskToken(token, keep = 2) {
46
+ if (token.length <= keep * 2) return "***";
47
+ return `${token.slice(0, keep)}***${token.slice(-keep)}`;
48
+ }
49
+ function shapeOf(value, depth = 4) {
50
+ if (value === null) return "null";
51
+ if (Array.isArray(value)) return depth <= 0 ? "array" : value.slice(0, 3).map((v) => shapeOf(v, depth - 1));
52
+ if (typeof value === "object") {
53
+ if (depth <= 0) return "object";
54
+ return Object.fromEntries(
55
+ Object.entries(value).map(([k, v]) => [k, shapeOf(v, depth - 1)])
56
+ );
57
+ }
58
+ return typeof value;
59
+ }
60
+ var apply = (rule, value) => {
61
+ if (typeof rule === "function") return rule(value);
62
+ if (rule === "drop") return void 0;
63
+ if (rule === "redact" || typeof value !== "string") return "***";
64
+ if (rule === "email") return maskEmail(value);
65
+ if (rule === "phone") return maskPhone(value);
66
+ return maskToken(value);
67
+ };
68
+ function maskFields(value, rules, maxDepth = 8) {
69
+ const byKey = new Map(Object.entries(rules).map(([k, r]) => [k.toLowerCase(), r]));
70
+ const seen = /* @__PURE__ */ new WeakSet();
71
+ const walk = (v, depth) => {
72
+ if (v === null || typeof v !== "object") return v;
73
+ if (depth > maxDepth || seen.has(v)) return "[\u2026]";
74
+ seen.add(v);
75
+ if (Array.isArray(v)) return v.map((x) => walk(x, depth + 1));
76
+ const out = {};
77
+ for (const [k, x] of Object.entries(v)) {
78
+ const rule = byKey.get(k.toLowerCase());
79
+ if (rule === void 0) out[k] = walk(x, depth + 1);
80
+ else {
81
+ try {
82
+ const masked = apply(rule, x);
83
+ if (masked !== void 0) out[k] = masked;
84
+ } catch (e2) {
85
+ out[k] = "***";
86
+ }
87
+ }
88
+ }
89
+ return out;
90
+ };
91
+ return walk(value, 0);
92
+ }
93
+
94
+ // src/security/hash.ts
95
+
96
+ var hashSha256 = (value) => _crypto.createHash.call(void 0, "sha256").update(value).digest("hex");
97
+ function constantTimeEqual(a, b) {
98
+ const ba = Buffer.from(a);
99
+ const bb = Buffer.from(b);
100
+ if (ba.length !== bb.length) {
101
+ _crypto.timingSafeEqual.call(void 0, ba, ba);
102
+ return false;
103
+ }
104
+ return _crypto.timingSafeEqual.call(void 0, ba, bb);
105
+ }
106
+
107
+ // src/security/signed-grant.ts
108
+
109
+ var sign = (b64, secret) => _crypto.createHmac.call(void 0, "sha256", secret).update(b64).digest("base64url");
110
+ function signGrant(claims, secret, ttlMs = 6e4) {
111
+ const body = JSON.stringify({
112
+ a: claims.actor,
113
+ p: claims.permission,
114
+ r: claims.resource,
115
+ t: claims.tenant,
116
+ exp: Date.now() + ttlMs,
117
+ n: _crypto.randomBytes.call(void 0, 8).toString("hex")
118
+ });
119
+ const b64 = Buffer.from(body).toString("base64url");
120
+ return `${b64}.${sign(b64, secret)}`;
121
+ }
122
+ function verifyGrant(token, secret, expected) {
123
+ if (!token) return null;
124
+ const parts = token.split(".");
125
+ if (parts.length !== 2) return null;
126
+ const [b64, sig] = parts;
127
+ if (!constantTimeEqual(sig, sign(b64, secret))) return null;
128
+ let p;
129
+ try {
130
+ p = JSON.parse(Buffer.from(b64, "base64url").toString());
131
+ } catch (e3) {
132
+ return null;
133
+ }
134
+ if (typeof p.exp !== "number" || !Number.isFinite(p.exp) || Date.now() >= p.exp) return null;
135
+ if (typeof p.a !== "string" || typeof p.p !== "string" || typeof p.r !== "string" || typeof p.t !== "string") return null;
136
+ if (p.p !== expected.permission || p.r !== expected.resource || p.t !== expected.tenant) return null;
137
+ if (expected.actor !== void 0 && p.a !== expected.actor) return null;
138
+ return { actor: p.a, permission: p.p, resource: p.r, tenant: p.t };
139
+ }
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
33
150
 
34
151
 
35
- exports.readState = readState; exports.signState = signState;
152
+ exports.constantTimeEqual = constantTimeEqual; exports.hashSha256 = hashSha256; exports.maskEmail = maskEmail; exports.maskFields = maskFields; exports.maskPhone = maskPhone; exports.maskToken = maskToken; exports.readState = readState; exports.shapeOf = shapeOf; exports.signGrant = signGrant; exports.signState = signState; exports.verifyGrant = verifyGrant;
@@ -1,2 +1,7 @@
1
1
  export { signState, readState } from './signed-state.js';
2
2
  export type { SignedStateOptions } from './signed-state.js';
3
+ export { maskEmail, maskPhone, maskToken, shapeOf, maskFields } from './mask.js';
4
+ export type { MaskRule, MaskRules } from './mask.js';
5
+ export { hashSha256, constantTimeEqual } from './hash.js';
6
+ export { signGrant, verifyGrant } from './signed-grant.js';
7
+ export type { GrantClaims, VerifyGrantExpectation } from './signed-grant.js';
@@ -1,4 +1,4 @@
1
- import "../chunk-4MGIQFAJ.js";
1
+ import "../chunk-D3DDJWUD.js";
2
2
 
3
3
  // src/security/signed-state.ts
4
4
  import { createHmac, randomBytes, timingSafeEqual } from "crypto";
@@ -29,7 +29,124 @@ function readState(state, options) {
29
29
  const { ts: _ts, nonce: _nonce, ...rest } = parsed;
30
30
  return rest;
31
31
  }
32
+
33
+ // src/security/mask.ts
34
+ function maskEmail(email) {
35
+ const clean = email.trim();
36
+ const at = clean.lastIndexOf("@");
37
+ if (at < 1) return "***";
38
+ return `${clean[0]}***${clean.slice(at)}`;
39
+ }
40
+ function maskPhone(phone, visible = 4) {
41
+ const digits = phone.replace(/\D/g, "");
42
+ if (digits.length <= visible) return "***";
43
+ return `***${digits.slice(-visible)}`;
44
+ }
45
+ function maskToken(token, keep = 2) {
46
+ if (token.length <= keep * 2) return "***";
47
+ return `${token.slice(0, keep)}***${token.slice(-keep)}`;
48
+ }
49
+ function shapeOf(value, depth = 4) {
50
+ if (value === null) return "null";
51
+ if (Array.isArray(value)) return depth <= 0 ? "array" : value.slice(0, 3).map((v) => shapeOf(v, depth - 1));
52
+ if (typeof value === "object") {
53
+ if (depth <= 0) return "object";
54
+ return Object.fromEntries(
55
+ Object.entries(value).map(([k, v]) => [k, shapeOf(v, depth - 1)])
56
+ );
57
+ }
58
+ return typeof value;
59
+ }
60
+ var apply = (rule, value) => {
61
+ if (typeof rule === "function") return rule(value);
62
+ if (rule === "drop") return void 0;
63
+ if (rule === "redact" || typeof value !== "string") return "***";
64
+ if (rule === "email") return maskEmail(value);
65
+ if (rule === "phone") return maskPhone(value);
66
+ return maskToken(value);
67
+ };
68
+ function maskFields(value, rules, maxDepth = 8) {
69
+ const byKey = new Map(Object.entries(rules).map(([k, r]) => [k.toLowerCase(), r]));
70
+ const seen = /* @__PURE__ */ new WeakSet();
71
+ const walk = (v, depth) => {
72
+ if (v === null || typeof v !== "object") return v;
73
+ if (depth > maxDepth || seen.has(v)) return "[\u2026]";
74
+ seen.add(v);
75
+ if (Array.isArray(v)) return v.map((x) => walk(x, depth + 1));
76
+ const out = {};
77
+ for (const [k, x] of Object.entries(v)) {
78
+ const rule = byKey.get(k.toLowerCase());
79
+ if (rule === void 0) out[k] = walk(x, depth + 1);
80
+ else {
81
+ try {
82
+ const masked = apply(rule, x);
83
+ if (masked !== void 0) out[k] = masked;
84
+ } catch {
85
+ out[k] = "***";
86
+ }
87
+ }
88
+ }
89
+ return out;
90
+ };
91
+ return walk(value, 0);
92
+ }
93
+
94
+ // src/security/hash.ts
95
+ import { createHash, timingSafeEqual as timingSafeEqual2 } from "crypto";
96
+ var hashSha256 = (value) => createHash("sha256").update(value).digest("hex");
97
+ function constantTimeEqual(a, b) {
98
+ const ba = Buffer.from(a);
99
+ const bb = Buffer.from(b);
100
+ if (ba.length !== bb.length) {
101
+ timingSafeEqual2(ba, ba);
102
+ return false;
103
+ }
104
+ return timingSafeEqual2(ba, bb);
105
+ }
106
+
107
+ // src/security/signed-grant.ts
108
+ import { createHmac as createHmac2, randomBytes as randomBytes2 } from "crypto";
109
+ var sign = (b64, secret) => createHmac2("sha256", secret).update(b64).digest("base64url");
110
+ function signGrant(claims, secret, ttlMs = 6e4) {
111
+ const body = JSON.stringify({
112
+ a: claims.actor,
113
+ p: claims.permission,
114
+ r: claims.resource,
115
+ t: claims.tenant,
116
+ exp: Date.now() + ttlMs,
117
+ n: randomBytes2(8).toString("hex")
118
+ });
119
+ const b64 = Buffer.from(body).toString("base64url");
120
+ return `${b64}.${sign(b64, secret)}`;
121
+ }
122
+ function verifyGrant(token, secret, expected) {
123
+ if (!token) return null;
124
+ const parts = token.split(".");
125
+ if (parts.length !== 2) return null;
126
+ const [b64, sig] = parts;
127
+ if (!constantTimeEqual(sig, sign(b64, secret))) return null;
128
+ let p;
129
+ try {
130
+ p = JSON.parse(Buffer.from(b64, "base64url").toString());
131
+ } catch {
132
+ return null;
133
+ }
134
+ if (typeof p.exp !== "number" || !Number.isFinite(p.exp) || Date.now() >= p.exp) return null;
135
+ if (typeof p.a !== "string" || typeof p.p !== "string" || typeof p.r !== "string" || typeof p.t !== "string") return null;
136
+ if (p.p !== expected.permission || p.r !== expected.resource || p.t !== expected.tenant) return null;
137
+ if (expected.actor !== void 0 && p.a !== expected.actor) return null;
138
+ return { actor: p.a, permission: p.p, resource: p.r, tenant: p.t };
139
+ }
32
140
  export {
141
+ constantTimeEqual,
142
+ hashSha256,
143
+ maskEmail,
144
+ maskFields,
145
+ maskPhone,
146
+ maskToken,
33
147
  readState,
34
- signState
148
+ shapeOf,
149
+ signGrant,
150
+ signState,
151
+ verifyGrant
35
152
  };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Keeps personal data out of logs and alerts. Logs are stored, searched and read by more people than
3
+ * the database; an e-mail or a whole customer payload should not end up there.
4
+ */
5
+ /** `ana.perez@gmail.com` -> `a***@gmail.com`: enough to know who is meant in an investigation. */
6
+ export declare function maskEmail(email: string): string;
7
+ /** `+52 55 1234 5678` -> `***5678`. Shows only the last `visible` digits. */
8
+ export declare function maskPhone(phone: string, visible?: number): string;
9
+ /** Keeps the first and last `keep` chars of a long token. */
10
+ export declare function maskToken(token: string, keep?: number): string;
11
+ /**
12
+ * The SHAPE of a JSON value without its data: keys and the type of each leaf, never values. Lets a
13
+ * log say "the provider's response does not look as expected" without dumping the customer inside.
14
+ */
15
+ export declare function shapeOf(value: unknown, depth?: number): unknown;
16
+ export type MaskRule = 'email' | 'phone' | 'token' | 'redact' | 'drop' | ((value: unknown) => unknown);
17
+ export type MaskRules = Record<string, MaskRule>;
18
+ /**
19
+ * Deep copy of `value` where every key named in `rules` (case-insensitive) is masked by its rule.
20
+ * Never mutates the input, survives cycles, never throws.
21
+ */
22
+ export declare function maskFields<T>(value: T, rules: MaskRules, maxDepth?: number): T;
@@ -0,0 +1,30 @@
1
+ /** What a grant authorizes: who approved, what, on which resource, in which tenant. */
2
+ export interface GrantClaims {
3
+ /** Who gave the authorization (e.g. the supervisor). */
4
+ actor: string;
5
+ /** The permission granted (e.g. "refund"). */
6
+ permission: string;
7
+ /** The specific resource it applies to (e.g. an order id). */
8
+ resource: string;
9
+ /** Tenant the grant is valid in. */
10
+ tenant: string;
11
+ }
12
+ export interface VerifyGrantExpectation {
13
+ permission: string;
14
+ resource: string;
15
+ tenant: string;
16
+ /** If set, the grant must come from this actor. */
17
+ actor?: string;
18
+ }
19
+ /**
20
+ * Signs a short-lived, stateless authorization: "`actor` allows `permission` on `resource` in `tenant`".
21
+ * Meant for one-off approvals (a supervisor PIN for a refund) handed to a different request than the
22
+ * one that obtained it. Generalizes {@link signState}: same HMAC scheme, fixed claims, short TTL.
23
+ * The expiry is embedded, so verification needs no server-side storage (it is NOT single-use).
24
+ */
25
+ export declare function signGrant(claims: GrantClaims, secret: string, ttlMs?: number): string;
26
+ /**
27
+ * Returns the claims if the grant is authentic, not expired and matches what the caller expects
28
+ * (permission, resource, tenant, optionally actor); otherwise `null`. Never throws.
29
+ */
30
+ export declare function verifyGrant(token: string | undefined, secret: string, expected: VerifyGrantExpectation): GrantClaims | null;
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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 _chunk2REOCMUDcjs = require('../chunk-2REOCMUD.cjs');
3
+ var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
4
4
 
5
5
  // src/storage/storage.port.ts
6
6
  var STORAGE = /* @__PURE__ */ Symbol("STORAGE");
@@ -511,7 +511,7 @@ var StorageModule = class {
511
511
  };
512
512
  }
513
513
  };
514
- StorageModule = exports.StorageModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
514
+ StorageModule = exports.StorageModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
515
515
  _common.Global.call(void 0, ),
516
516
  _common.Module.call(void 0, {})
517
517
  ], StorageModule);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __decorateClass
3
- } from "../chunk-4MGIQFAJ.js";
3
+ } from "../chunk-D3DDJWUD.js";
4
4
 
5
5
  // src/storage/storage.port.ts
6
6
  var STORAGE = /* @__PURE__ */ Symbol("STORAGE");
@@ -6,7 +6,7 @@ require('../chunk-PNK5WMPP.cjs');
6
6
 
7
7
 
8
8
 
9
- var _chunk2REOCMUDcjs = require('../chunk-2REOCMUD.cjs');
9
+ var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
10
10
 
11
11
  // src/stripe/stripe.module.ts
12
12
  var _common = require('@nestjs/common');
@@ -14,7 +14,7 @@ var _stripe = require('stripe'); var _stripe2 = _interopRequireDefault(_stripe);
14
14
  var STRIPE_CLIENT = /* @__PURE__ */ Symbol("STRIPE_CLIENT");
15
15
  var StripeModule = class {
16
16
  };
17
- StripeModule = exports.StripeModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
17
+ StripeModule = exports.StripeModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
18
18
  _common.Module.call(void 0, {
19
19
  providers: [
20
20
  {
@@ -61,14 +61,14 @@ function createStripeWebhookController(options) {
61
61
  return { received: true };
62
62
  }
63
63
  };
64
- _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
64
+ _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
65
65
  _common.Post.call(void 0, ),
66
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Req.call(void 0, )),
67
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Headers.call(void 0, "stripe-signature"))
66
+ _chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Req.call(void 0, )),
67
+ _chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Headers.call(void 0, "stripe-signature"))
68
68
  ], StripeWebhookControllerHost.prototype, "handleWebhook", 1);
69
- StripeWebhookControllerHost = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
69
+ StripeWebhookControllerHost = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
70
70
  _common.Controller.call(void 0, _nullishCoalesce(options.path, () => ( "stripe/webhook"))),
71
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, STRIPE_CLIENT))
71
+ _chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, STRIPE_CLIENT))
72
72
  ], StripeWebhookControllerHost);
73
73
  return StripeWebhookControllerHost;
74
74
  }
@@ -6,7 +6,7 @@ import "../chunk-VVMRZEIW.js";
6
6
  import {
7
7
  __decorateClass,
8
8
  __decorateParam
9
- } from "../chunk-4MGIQFAJ.js";
9
+ } from "../chunk-D3DDJWUD.js";
10
10
 
11
11
  // src/stripe/stripe.module.ts
12
12
  import { Module } from "@nestjs/common";
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk2REOCMUDcjs = require('../chunk-2REOCMUD.cjs');
3
+ var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
4
4
 
5
5
  // src/telegram/telegram.module.ts
6
6
  var _common = require('@nestjs/common');
@@ -8,7 +8,7 @@ var _telegraf = require('telegraf');
8
8
  var TELEGRAM_BOT = /* @__PURE__ */ Symbol("TELEGRAM_BOT");
9
9
  var TelegramModule = class {
10
10
  };
11
- TelegramModule = exports.TelegramModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
11
+ TelegramModule = exports.TelegramModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
12
12
  _common.Module.call(void 0, {
13
13
  providers: [
14
14
  {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __decorateClass
3
- } from "../chunk-4MGIQFAJ.js";
3
+ } from "../chunk-D3DDJWUD.js";
4
4
 
5
5
  // src/telegram/telegram.module.ts
6
6
  import { Module } from "@nestjs/common";
@@ -0,0 +1,24 @@
1
+ /** Structural `pg.Client` / `pg.Pool`. */
2
+ export interface AdminLike {
3
+ query(sql: string, params?: any[]): Promise<{
4
+ rowCount?: number | null;
5
+ rows?: any[];
6
+ }>;
7
+ }
8
+ export interface EnsureAppRoleOptions {
9
+ role: string;
10
+ password: string;
11
+ /** Database name to grant CONNECT on. */
12
+ db: string;
13
+ /** Only for a service role (workers, cross-tenant jobs). Default false: the app role must obey RLS. */
14
+ bypassRls?: boolean;
15
+ /** Schema to grant on. Default `public`. */
16
+ schema?: string;
17
+ }
18
+ /**
19
+ * Creates (if missing) the runtime role of the API: NOSUPERUSER and NOBYPASSRLS by default, so the
20
+ * RLS policies apply. Idempotent: if the role exists it only re-grants. Run it with the owner role;
21
+ * migrations keep running as the owner, the app connects as this one. Creating a role needs
22
+ * CREATEROLE: an owner without it must have the role pre-created and this only grants.
23
+ */
24
+ export declare function ensureAppRole(admin: AdminLike, options: EnsureAppRoleOptions): Promise<void>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * SQLSTATE of a Postgres error, direct (`pg`) or wrapped by TypeORM (`QueryFailedError.driverError`).
3
+ * `23505` unique violation, `40001` serialization failure, `40P01` deadlock.
4
+ */
5
+ export declare function pgSqlState(error: unknown): string | undefined;
6
+ /**
7
+ * Rows of an `UPDATE/DELETE ... RETURNING` run through TypeORM's `query()`. It does not normalize:
8
+ * SELECT and INSERT return `[row, ...]` but UPDATE and DELETE return the tuple `[rows, count]`, so
9
+ * `result.length` is always 2 and `result[0]` is an array. Also accepts a `pg` result (`{ rows }`)
10
+ * and a plain array. The shape is checked at runtime, not assumed.
11
+ */
12
+ export declare function updatedRows<T = Record<string, unknown>>(result: unknown): T[];