@miguelmorales13/nestkit 0.25.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 (281) hide show
  1. package/README.md +5 -0
  2. package/dist/alerts/alert-on-failure.decorator.d.ts +5 -0
  3. package/dist/alerts/alert-sinks.d.ts +29 -0
  4. package/dist/alerts/alerts.module.d.ts +19 -0
  5. package/dist/alerts/alerts.options.d.ts +1 -0
  6. package/dist/alerts/alerts.service.d.ts +28 -0
  7. package/dist/alerts/alerts.types.d.ts +66 -0
  8. package/dist/alerts/index.cjs +276 -0
  9. package/dist/alerts/index.d.ts +10 -0
  10. package/dist/alerts/index.js +276 -0
  11. package/dist/alerts/logger-with-alerts.d.ts +18 -0
  12. package/dist/alerts/process-guards.d.ts +21 -0
  13. package/dist/alerts/runtime.d.ts +4 -0
  14. package/dist/audit/index.cjs +13 -13
  15. package/dist/audit/index.js +2 -2
  16. package/dist/auth/index.cjs +21 -21
  17. package/dist/auth/index.js +3 -3
  18. package/dist/auth/oauth/index.cjs +123 -115
  19. package/dist/auth/oauth/index.js +25 -17
  20. package/dist/auth/oauth/oauth-provider.d.ts +9 -0
  21. package/dist/auth/oauth/providers/apple.d.ts +3 -1
  22. package/dist/bootstrap/apply-defaults.d.ts +9 -0
  23. package/dist/bootstrap/index.cjs +6 -5
  24. package/dist/bootstrap/index.js +5 -4
  25. package/dist/chunk-3TUMVLPJ.js +14 -0
  26. package/dist/{chunk-PA24P76K.js → chunk-45SW7FBE.js} +1 -1
  27. package/dist/{chunk-RF75KC63.cjs → chunk-47IYXZHW.cjs} +2 -2
  28. package/dist/{chunk-TUNDBBQF.js → chunk-4WWOKZIO.js} +4 -4
  29. package/dist/{chunk-A2DGK4ZL.js → chunk-5LVGCTJ3.js} +1 -1
  30. package/dist/chunk-A6YGIZCQ.cjs +14 -0
  31. package/dist/chunk-A7FI6HXV.js +40 -0
  32. package/dist/chunk-CU4FUIVJ.cjs +8 -0
  33. package/dist/{chunk-FH5UNWWW.cjs → chunk-D35TBVRO.cjs} +4 -4
  34. package/dist/{chunk-4MGIQFAJ.js → chunk-D3DDJWUD.js} +5 -0
  35. package/dist/chunk-DVGPEBUL.js +8 -0
  36. package/dist/{chunk-VKOPDDCC.js → chunk-ENZ7LQRE.js} +1 -1
  37. package/dist/{chunk-3AUOOEQO.cjs → chunk-F77X4QUN.cjs} +2 -2
  38. package/dist/chunk-FBNV5X6C.js +61 -0
  39. package/dist/{chunk-APUFKA4K.cjs → chunk-FDZQCLLK.cjs} +6 -6
  40. package/dist/{chunk-DYHSOULW.js → chunk-IGSNB5BX.js} +1 -1
  41. package/dist/chunk-IVWPA6QH.cjs +90 -0
  42. package/dist/{chunk-MSTXS3MU.cjs → chunk-JJKGQNGD.cjs} +2 -2
  43. package/dist/{chunk-FNUZGYUF.cjs → chunk-JRFE7NSO.cjs} +12 -4
  44. package/dist/{chunk-HVHYZXBB.cjs → chunk-KNU5RN3O.cjs} +3 -3
  45. package/dist/{chunk-52IOOHNX.cjs → chunk-KQPJCVN3.cjs} +26 -26
  46. package/dist/chunk-LGFHLAY3.cjs +61 -0
  47. package/dist/{chunk-2REOCMUD.cjs → chunk-LRX7AMSS.cjs} +6 -1
  48. package/dist/{chunk-4PFAKLT3.js → chunk-MUWHGBIB.js} +1 -1
  49. package/dist/{chunk-ZJMLEP5H.js → chunk-NJYLQDB3.js} +1 -1
  50. package/dist/{chunk-IFNYRZP2.js → chunk-OSRH6KYZ.js} +4 -4
  51. package/dist/{chunk-6RAPVLJM.js → chunk-OTE77ONL.js} +1 -1
  52. package/dist/chunk-UDACUMLO.cjs +40 -0
  53. package/dist/{chunk-UNEVXCFW.js → chunk-UGAAJRPO.js} +10 -2
  54. package/dist/{chunk-SPTDXUED.cjs → chunk-URLDTS2Q.cjs} +2 -2
  55. package/dist/{chunk-W2T2VFLC.cjs → chunk-VALDHJOO.cjs} +5 -5
  56. package/dist/chunk-WFCQDOSN.js +90 -0
  57. package/dist/consent/consent.interceptor.d.ts +20 -0
  58. package/dist/consent/consent.module.d.ts +25 -0
  59. package/dist/consent/consent.options.d.ts +30 -0
  60. package/dist/consent/consent.port.d.ts +17 -0
  61. package/dist/consent/consent.service.d.ts +44 -0
  62. package/dist/consent/guard/index.cjs +13 -0
  63. package/dist/consent/guard/index.d.ts +31 -0
  64. package/dist/consent/guard/index.js +13 -0
  65. package/dist/consent/index.cjs +271 -0
  66. package/dist/consent/index.d.ts +13 -0
  67. package/dist/consent/index.js +271 -0
  68. package/dist/consent/memory.store.d.ts +7 -0
  69. package/dist/consent/shared/index.cjs +11 -0
  70. package/dist/consent/shared/index.d.ts +19 -0
  71. package/dist/consent/shared/index.js +11 -0
  72. package/dist/consent/typeorm.store.d.ts +22 -0
  73. package/dist/crud/index.cjs +4 -4
  74. package/dist/crud/index.js +3 -3
  75. package/dist/database/postgres/index.cjs +3 -3
  76. package/dist/database/postgres/index.js +2 -2
  77. package/dist/database/supabase/index.cjs +3 -3
  78. package/dist/database/supabase/index.js +2 -2
  79. package/dist/database/typeorm/index.cjs +2 -2
  80. package/dist/database/typeorm/index.js +1 -1
  81. package/dist/devices/device-check.interceptor.d.ts +20 -0
  82. package/dist/devices/devices.module.d.ts +28 -0
  83. package/dist/devices/devices.options.d.ts +53 -0
  84. package/dist/devices/devices.port.d.ts +62 -0
  85. package/dist/devices/devices.service.d.ts +58 -0
  86. package/dist/devices/index.cjs +327 -0
  87. package/dist/devices/index.d.ts +8 -0
  88. package/dist/devices/index.js +327 -0
  89. package/dist/devices/memory.store.d.ts +12 -0
  90. package/dist/email/index.cjs +2 -2
  91. package/dist/email/index.js +1 -1
  92. package/dist/email/nodemailer/index.cjs +2 -2
  93. package/dist/email/nodemailer/index.js +1 -1
  94. package/dist/email/resend/index.cjs +2 -2
  95. package/dist/email/resend/index.js +1 -1
  96. package/dist/entities/index.cjs +1 -1
  97. package/dist/entities/index.js +1 -1
  98. package/dist/errors/index.cjs +7 -7
  99. package/dist/errors/index.js +7 -7
  100. package/dist/events/buses.d.ts +27 -0
  101. package/dist/events/events.controller.d.ts +15 -0
  102. package/dist/events/events.module.d.ts +29 -0
  103. package/dist/events/events.options.d.ts +50 -0
  104. package/dist/events/events.service.d.ts +49 -0
  105. package/dist/events/events.types.d.ts +77 -0
  106. package/dist/events/index.cjs +557 -0
  107. package/dist/events/index.d.ts +10 -0
  108. package/dist/events/index.js +557 -0
  109. package/dist/events/memory-ticket.store.d.ts +9 -0
  110. package/dist/google-business/google-business-http.d.ts +41 -0
  111. package/dist/google-business/google-business.errors.d.ts +75 -0
  112. package/dist/google-business/google-business.mappers.d.ts +52 -0
  113. package/dist/google-business/google-business.module.d.ts +26 -0
  114. package/dist/google-business/google-business.options.d.ts +40 -0
  115. package/dist/google-business/google-business.ports.d.ts +18 -0
  116. package/dist/google-business/google-business.service.d.ts +120 -0
  117. package/dist/google-business/google-business.types.d.ts +155 -0
  118. package/dist/google-business/index.cjs +1025 -0
  119. package/dist/google-business/index.d.ts +15 -0
  120. package/dist/google-business/index.js +1025 -0
  121. package/dist/google-business/testing/google-simulator.d.ts +61 -0
  122. package/dist/hardening/body-limits.d.ts +24 -0
  123. package/dist/hardening/http.types.d.ts +26 -0
  124. package/dist/hardening/index.cjs +179 -0
  125. package/dist/hardening/index.d.ts +19 -0
  126. package/dist/hardening/index.js +179 -0
  127. package/dist/hardening/memory-rate-limit.store.d.ts +10 -0
  128. package/dist/hardening/origin-secret.d.ts +29 -0
  129. package/dist/hardening/rate-limit.decorator.d.ts +8 -0
  130. package/dist/hardening/rate-limit.guard.d.ts +18 -0
  131. package/dist/hardening/rate-limit.module.d.ts +23 -0
  132. package/dist/hardening/rate-limit.options.d.ts +35 -0
  133. package/dist/hardening/rate-limit.port.d.ts +11 -0
  134. package/dist/hardening/redis-rate-limit.store.d.ts +23 -0
  135. package/dist/hardening/trust-proxy.d.ts +22 -0
  136. package/dist/health/health.controller.d.ts +32 -0
  137. package/dist/health/health.module.d.ts +15 -0
  138. package/dist/health/health.options.d.ts +24 -0
  139. package/dist/health/index.cjs +103 -0
  140. package/dist/health/index.d.ts +5 -0
  141. package/dist/health/index.js +103 -0
  142. package/dist/i18n/index.cjs +3 -3
  143. package/dist/i18n/index.js +2 -2
  144. package/dist/idempotency/idempotency.interceptor.d.ts +1 -0
  145. package/dist/idempotency/idempotency.options.d.ts +15 -0
  146. package/dist/idempotency/index.cjs +214 -7
  147. package/dist/idempotency/index.d.ts +5 -0
  148. package/dist/idempotency/index.js +210 -3
  149. package/dist/idempotency/no-idempotency.decorator.d.ts +8 -0
  150. package/dist/idempotency/postgres.store.d.ts +49 -0
  151. package/dist/idempotency/redis.store.d.ts +59 -0
  152. package/dist/index.cjs +21 -20
  153. package/dist/index.js +31 -30
  154. package/dist/invoicing/index.cjs +2 -2
  155. package/dist/invoicing/index.js +1 -1
  156. package/dist/jobs/defer-job.d.ts +10 -0
  157. package/dist/jobs/index.cjs +318 -0
  158. package/dist/jobs/index.d.ts +8 -0
  159. package/dist/jobs/index.js +318 -0
  160. package/dist/jobs/jobs-admin.controller.d.ts +18 -0
  161. package/dist/jobs/jobs.module.d.ts +33 -0
  162. package/dist/jobs/jobs.options.d.ts +62 -0
  163. package/dist/jobs/jobs.service.d.ts +53 -0
  164. package/dist/jobs/jobs.sql.d.ts +11 -0
  165. package/dist/media/index.cjs +14 -14
  166. package/dist/media/index.js +1 -1
  167. package/dist/meta/index.cjs +3 -3
  168. package/dist/meta/index.js +1 -1
  169. package/dist/notifications/index.cjs +375 -0
  170. package/dist/notifications/index.d.ts +8 -0
  171. package/dist/notifications/index.js +375 -0
  172. package/dist/notifications/memory.stores.d.ts +23 -0
  173. package/dist/notifications/notifications.controller.d.ts +11 -0
  174. package/dist/notifications/notifications.module.d.ts +31 -0
  175. package/dist/notifications/notifications.options.d.ts +33 -0
  176. package/dist/notifications/notifications.port.d.ts +97 -0
  177. package/dist/notifications/notifier.service.d.ts +31 -0
  178. package/dist/payments/index.cjs +7 -7
  179. package/dist/payments/index.js +1 -1
  180. package/dist/pinterest/index.cjs +3 -3
  181. package/dist/pinterest/index.js +1 -1
  182. package/dist/privacy/anonymizer.d.ts +14 -0
  183. package/dist/privacy/index.cjs +768 -0
  184. package/dist/privacy/index.d.ts +13 -0
  185. package/dist/privacy/index.js +768 -0
  186. package/dist/privacy/memory.store.d.ts +15 -0
  187. package/dist/privacy/privacy.module.d.ts +30 -0
  188. package/dist/privacy/privacy.options.d.ts +43 -0
  189. package/dist/privacy/privacy.port.d.ts +25 -0
  190. package/dist/privacy/privacy.service.d.ts +69 -0
  191. package/dist/privacy/privacy.types.d.ts +125 -0
  192. package/dist/privacy/sql.d.ts +7 -0
  193. package/dist/privacy/sql.store.d.ts +21 -0
  194. package/dist/privacy/zip.d.ts +23 -0
  195. package/dist/push/index.cjs +13 -13
  196. package/dist/push/index.js +5 -5
  197. package/dist/resilience/alert-channels.d.ts +39 -0
  198. package/dist/resilience/alert-errors.interceptor.d.ts +10 -0
  199. package/dist/resilience/alert-on-failure.decorator.d.ts +10 -0
  200. package/dist/resilience/alert.service.d.ts +77 -0
  201. package/dist/resilience/index.cjs +863 -0
  202. package/dist/resilience/index.d.ts +18 -0
  203. package/dist/resilience/index.js +863 -0
  204. package/dist/resilience/memory-alert-store.d.ts +26 -0
  205. package/dist/resilience/provider-health.controller.d.ts +14 -0
  206. package/dist/resilience/provider-unavailable.exception.d.ts +11 -0
  207. package/dist/resilience/resilience.module.d.ts +34 -0
  208. package/dist/resilience/resilience.options.d.ts +28 -0
  209. package/dist/resilience/resilience.types.d.ts +167 -0
  210. package/dist/resilience/resilient-fetch.d.ts +38 -0
  211. package/dist/resilience/runtime.d.ts +24 -0
  212. package/dist/resilience/typeorm/alert.entity.d.ts +21 -0
  213. package/dist/resilience/typeorm/index.cjs +102 -0
  214. package/dist/resilience/typeorm/index.d.ts +3 -0
  215. package/dist/resilience/typeorm/index.js +102 -0
  216. package/dist/resilience/typeorm/typeorm-alert-store.d.ts +39 -0
  217. package/dist/resilience/validate-destination.d.ts +63 -0
  218. package/dist/response/index.cjs +3 -3
  219. package/dist/response/index.js +2 -2
  220. package/dist/scheduling/cron-lock.service.d.ts +36 -0
  221. package/dist/scheduling/cron-unico.decorator.d.ts +27 -0
  222. package/dist/scheduling/fallback.store.d.ts +34 -0
  223. package/dist/scheduling/index.cjs +392 -0
  224. package/dist/scheduling/index.d.ts +18 -0
  225. package/dist/scheduling/index.js +392 -0
  226. package/dist/scheduling/lock-store.port.d.ts +19 -0
  227. package/dist/scheduling/memory.store.d.ts +15 -0
  228. package/dist/scheduling/redis.module.d.ts +31 -0
  229. package/dist/scheduling/redis.store.d.ts +24 -0
  230. package/dist/scheduling/scheduling.module.d.ts +24 -0
  231. package/dist/scheduling/scheduling.options.d.ts +27 -0
  232. package/dist/scheduling/sql.store.d.ts +26 -0
  233. package/dist/secrets/index.cjs +274 -0
  234. package/dist/secrets/index.d.ts +8 -0
  235. package/dist/secrets/index.js +274 -0
  236. package/dist/secrets/secrets.errors.d.ts +6 -0
  237. package/dist/secrets/secrets.module.d.ts +21 -0
  238. package/dist/secrets/secrets.options.d.ts +32 -0
  239. package/dist/secrets/secrets.service.d.ts +54 -0
  240. package/dist/secrets/secrets.transformer.d.ts +33 -0
  241. package/dist/security/hash.d.ts +8 -0
  242. package/dist/security/index.cjs +119 -2
  243. package/dist/security/index.d.ts +5 -0
  244. package/dist/security/index.js +119 -2
  245. package/dist/security/mask.d.ts +22 -0
  246. package/dist/security/signed-grant.d.ts +30 -0
  247. package/dist/storage/index.cjs +2 -2
  248. package/dist/storage/index.js +1 -1
  249. package/dist/stripe/index.cjs +7 -7
  250. package/dist/stripe/index.js +1 -1
  251. package/dist/telegram/index.cjs +2 -2
  252. package/dist/telegram/index.js +1 -1
  253. package/dist/tenancy/app-role.d.ts +24 -0
  254. package/dist/tenancy/db-helpers.d.ts +12 -0
  255. package/dist/tenancy/index.cjs +205 -0
  256. package/dist/tenancy/index.d.ts +14 -0
  257. package/dist/tenancy/index.js +205 -0
  258. package/dist/tenancy/pg/index.cjs +34 -0
  259. package/dist/tenancy/pg/index.d.ts +2 -0
  260. package/dist/tenancy/pg/index.js +34 -0
  261. package/dist/tenancy/pg/with-tenant.d.ts +23 -0
  262. package/dist/tenancy/request-context.d.ts +18 -0
  263. package/dist/tenancy/rls-guardrail.d.ts +38 -0
  264. package/dist/tenancy/scope.d.ts +5 -0
  265. package/dist/tenancy/tenancy.errors.d.ts +5 -0
  266. package/dist/tenancy/tenancy.middleware.d.ts +8 -0
  267. package/dist/tenancy/tenancy.module.d.ts +37 -0
  268. package/dist/tenancy/tenancy.options.d.ts +34 -0
  269. package/dist/tenancy/typeorm/index.cjs +41 -0
  270. package/dist/tenancy/typeorm/index.d.ts +2 -0
  271. package/dist/tenancy/typeorm/index.js +41 -0
  272. package/dist/tenancy/typeorm/with-tenant.d.ts +23 -0
  273. package/dist/tiktok/index.cjs +3 -3
  274. package/dist/tiktok/index.js +1 -1
  275. package/dist/tracking/index.cjs +3 -3
  276. package/dist/tracking/index.js +2 -2
  277. package/dist/umami/index.cjs +4 -4
  278. package/dist/umami/index.js +1 -1
  279. package/dist/whatsapp/index.cjs +2 -2
  280. package/dist/whatsapp/index.js +1 -1
  281. package/package.json +107 -2
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  CurrentUser,
3
3
  JwtAuthGuard
4
- } from "../../chunk-TUNDBBQF.js";
4
+ } from "../../chunk-4WWOKZIO.js";
5
+ import "../../chunk-ETRUVZTJ.js";
5
6
  import {
6
7
  NotFoundAppException,
7
8
  UnauthorizedAppException,
8
9
  ValidationAppException
9
10
  } from "../../chunk-ZFIDAX7K.js";
10
- import "../../chunk-ETRUVZTJ.js";
11
11
  import "../../chunk-M3GQDRWR.js";
12
12
  import "../../chunk-VVMRZEIW.js";
13
13
  import {
14
14
  __decorateClass,
15
15
  __decorateParam
16
- } from "../../chunk-4MGIQFAJ.js";
16
+ } from "../../chunk-D3DDJWUD.js";
17
17
 
18
18
  // src/auth/oauth/oauth-provider.ts
19
19
  async function readJson(response, what) {
@@ -32,6 +32,7 @@ async function readJson(response, what) {
32
32
  function googleProvider(credentials = {}) {
33
33
  return {
34
34
  name: "google",
35
+ fetchImpl: credentials.fetchImpl,
35
36
  clientId: credentials.clientId ?? process.env.GOOGLE_CLIENT_ID,
36
37
  clientSecret: credentials.clientSecret ?? process.env.GOOGLE_CLIENT_SECRET,
37
38
  callbackUrl: credentials.callbackUrl ?? process.env.GOOGLE_CALLBACK_URL,
@@ -47,7 +48,7 @@ function googleProvider(credentials = {}) {
47
48
  },
48
49
  async fetchProfile(accessToken) {
49
50
  const data = await readJson(
50
- await fetch("https://www.googleapis.com/oauth2/v3/userinfo", {
51
+ await (credentials.fetchImpl ?? fetch)("https://www.googleapis.com/oauth2/v3/userinfo", {
51
52
  headers: { Authorization: `Bearer ${accessToken}` }
52
53
  }),
53
54
  "Google userinfo"
@@ -69,6 +70,7 @@ function facebookProvider(credentials = {}) {
69
70
  const version = process.env.FACEBOOK_GRAPH_VERSION ?? "v21.0";
70
71
  return {
71
72
  name: "facebook",
73
+ fetchImpl: credentials.fetchImpl,
72
74
  clientId: credentials.clientId ?? process.env.FACEBOOK_APP_ID,
73
75
  clientSecret: credentials.clientSecret ?? process.env.FACEBOOK_APP_SECRET,
74
76
  callbackUrl: credentials.callbackUrl ?? process.env.FACEBOOK_CALLBACK_URL,
@@ -79,7 +81,7 @@ function facebookProvider(credentials = {}) {
79
81
  const url = new URL(`https://graph.facebook.com/${version}/me`);
80
82
  url.searchParams.set("fields", "id,name,email,picture.type(large)");
81
83
  const data = await readJson(
82
- await fetch(url, { headers: { Authorization: `Bearer ${accessToken}` } }),
84
+ await (credentials.fetchImpl ?? fetch)(url, { headers: { Authorization: `Bearer ${accessToken}` } }),
83
85
  "Facebook me"
84
86
  );
85
87
  const picture = data.picture;
@@ -113,7 +115,7 @@ async function exchangeCode(provider, code) {
113
115
  code
114
116
  });
115
117
  const data = await readJson(
116
- await fetch(provider.tokenUrl, {
118
+ await (provider.fetchImpl ?? fetch)(provider.tokenUrl, {
117
119
  method: "POST",
118
120
  headers: {
119
121
  "Content-Type": "application/x-www-form-urlencoded",
@@ -145,6 +147,7 @@ function appleProvider(credentials = {}) {
145
147
  const configured = Boolean(clientId && teamId && keyId && privateKey);
146
148
  return {
147
149
  name: "apple",
150
+ fetchImpl: credentials.fetchImpl,
148
151
  clientId,
149
152
  // Only offered as configured when every piece exists: `provider()` tests
150
153
  // `clientSecret` for truthiness, and a function that would throw later
@@ -158,7 +161,7 @@ function appleProvider(credentials = {}) {
158
161
  callbackMethod: "POST",
159
162
  async fetchProfile(_accessToken, tokens, callback) {
160
163
  if (!tokens.id_token) throw new Error("Apple token exchange returned no id_token.");
161
- const claims = await verifyAppleIdToken(tokens.id_token, clientId, keysUrl);
164
+ const claims = await verifyAppleIdToken(tokens.id_token, clientId, keysUrl, credentials.fetchImpl);
162
165
  const verified = claims.email_verified === true || claims.email_verified === "true";
163
166
  return {
164
167
  providerAccountId: claims.sub,
@@ -180,17 +183,17 @@ function mintClientSecret(clientId, teamId, keyId, privateKey) {
180
183
  }
181
184
  var cachedKeys;
182
185
  var KEYS_TTL_MS = 60 * 60 * 1e3;
183
- async function appleKeys(keysUrl, kid) {
186
+ async function appleKeys(keysUrl, kid, fetchImpl) {
184
187
  const fresh = cachedKeys && Date.now() - cachedKeys.fetchedAt < KEYS_TTL_MS;
185
188
  if (fresh && cachedKeys.keys.some((k) => k.kid === kid)) return cachedKeys.keys;
186
- const data = await readJson(await fetch(keysUrl), "Apple keys");
189
+ const data = await readJson(await (fetchImpl ?? fetch)(keysUrl), "Apple keys");
187
190
  cachedKeys = { fetchedAt: Date.now(), keys: data.keys ?? [] };
188
191
  return cachedKeys.keys;
189
192
  }
190
- async function verifyAppleIdToken(idToken, clientId, keysUrl = KEYS_URL) {
193
+ async function verifyAppleIdToken(idToken, clientId, keysUrl = KEYS_URL, fetchImpl) {
191
194
  const decoded = jwt.decode(idToken, { complete: true });
192
195
  const kid = decoded?.header.kid;
193
- const key = (await appleKeys(keysUrl, kid)).find((k) => k.kid === kid);
196
+ const key = (await appleKeys(keysUrl, kid, fetchImpl)).find((k) => k.kid === kid);
194
197
  if (!key) throw new Error("Apple id_token is signed with a key Apple does not publish.");
195
198
  const pem = createPublicKey({ key, format: "jwk" }).export({ type: "spki", format: "pem" });
196
199
  return jwt.verify(idToken, pem, { algorithms: ["RS256"], audience: clientId, issuer: ISSUER });
@@ -211,6 +214,7 @@ function nameFromCallback(callback) {
211
214
  function tiktokProvider(credentials = {}) {
212
215
  return {
213
216
  name: "tiktok",
217
+ fetchImpl: credentials.fetchImpl,
214
218
  clientId: credentials.clientId ?? process.env.TIKTOK_CLIENT_KEY,
215
219
  clientSecret: credentials.clientSecret ?? process.env.TIKTOK_CLIENT_SECRET,
216
220
  callbackUrl: credentials.callbackUrl ?? process.env.TIKTOK_CALLBACK_URL,
@@ -222,7 +226,7 @@ function tiktokProvider(credentials = {}) {
222
226
  const url = new URL("https://open.tiktokapis.com/v2/user/info/");
223
227
  url.searchParams.set("fields", "open_id,display_name,avatar_url");
224
228
  const data = await readJson(
225
- await fetch(url, { headers: { Authorization: `Bearer ${accessToken}` } }),
229
+ await (credentials.fetchImpl ?? fetch)(url, { headers: { Authorization: `Bearer ${accessToken}` } }),
226
230
  "TikTok user info"
227
231
  );
228
232
  const error = data.error;
@@ -243,6 +247,7 @@ function tiktokProvider(credentials = {}) {
243
247
  function githubProvider(credentials = {}) {
244
248
  return {
245
249
  name: "github",
250
+ fetchImpl: credentials.fetchImpl,
246
251
  clientId: credentials.clientId ?? process.env.GITHUB_CLIENT_ID,
247
252
  clientSecret: credentials.clientSecret ?? process.env.GITHUB_CLIENT_SECRET,
248
253
  callbackUrl: credentials.callbackUrl ?? process.env.GITHUB_CALLBACK_URL,
@@ -255,9 +260,9 @@ function githubProvider(credentials = {}) {
255
260
  Accept: "application/vnd.github+json",
256
261
  "User-Agent": "nestkit"
257
262
  };
258
- const user = await readJson(await fetch("https://api.github.com/user", { headers }), "GitHub user");
263
+ const user = await readJson(await (credentials.fetchImpl ?? fetch)("https://api.github.com/user", { headers }), "GitHub user");
259
264
  const emails = await readJson(
260
- await fetch("https://api.github.com/user/emails", { headers }),
265
+ await (credentials.fetchImpl ?? fetch)("https://api.github.com/user/emails", { headers }),
261
266
  "GitHub emails"
262
267
  );
263
268
  const primary = Array.isArray(emails) ? emails.find((e) => e.primary && e.verified) ?? emails.find((e) => e.verified) : void 0;
@@ -276,6 +281,7 @@ function microsoftProvider(credentials = {}) {
276
281
  const tenant = credentials.tenant ?? process.env.MICROSOFT_TENANT ?? "common";
277
282
  return {
278
283
  name: "microsoft",
284
+ fetchImpl: credentials.fetchImpl,
279
285
  clientId: credentials.clientId ?? process.env.MICROSOFT_CLIENT_ID,
280
286
  clientSecret: credentials.clientSecret ?? process.env.MICROSOFT_CLIENT_SECRET,
281
287
  callbackUrl: credentials.callbackUrl ?? process.env.MICROSOFT_CALLBACK_URL,
@@ -284,7 +290,7 @@ function microsoftProvider(credentials = {}) {
284
290
  scope: credentials.scope ?? "openid profile email User.Read",
285
291
  async fetchProfile(accessToken) {
286
292
  const me = await readJson(
287
- await fetch("https://graph.microsoft.com/v1.0/me", { headers: { Authorization: `Bearer ${accessToken}` } }),
293
+ await (credentials.fetchImpl ?? fetch)("https://graph.microsoft.com/v1.0/me", { headers: { Authorization: `Bearer ${accessToken}` } }),
288
294
  "Microsoft Graph me"
289
295
  );
290
296
  const email = me.mail ?? me.userPrincipalName;
@@ -301,6 +307,7 @@ function microsoftProvider(credentials = {}) {
301
307
  function discordProvider(credentials = {}) {
302
308
  return {
303
309
  name: "discord",
310
+ fetchImpl: credentials.fetchImpl,
304
311
  clientId: credentials.clientId ?? process.env.DISCORD_CLIENT_ID,
305
312
  clientSecret: credentials.clientSecret ?? process.env.DISCORD_CLIENT_SECRET,
306
313
  callbackUrl: credentials.callbackUrl ?? process.env.DISCORD_CALLBACK_URL,
@@ -309,7 +316,7 @@ function discordProvider(credentials = {}) {
309
316
  scope: credentials.scope ?? "identify email",
310
317
  async fetchProfile(accessToken) {
311
318
  const user = await readJson(
312
- await fetch("https://discord.com/api/users/@me", { headers: { Authorization: `Bearer ${accessToken}` } }),
319
+ await (credentials.fetchImpl ?? fetch)("https://discord.com/api/users/@me", { headers: { Authorization: `Bearer ${accessToken}` } }),
313
320
  "Discord user"
314
321
  );
315
322
  const id = String(user.id);
@@ -328,6 +335,7 @@ function discordProvider(credentials = {}) {
328
335
  function linkedinProvider(credentials = {}) {
329
336
  return {
330
337
  name: "linkedin",
338
+ fetchImpl: credentials.fetchImpl,
331
339
  clientId: credentials.clientId ?? process.env.LINKEDIN_CLIENT_ID,
332
340
  clientSecret: credentials.clientSecret ?? process.env.LINKEDIN_CLIENT_SECRET,
333
341
  callbackUrl: credentials.callbackUrl ?? process.env.LINKEDIN_CALLBACK_URL,
@@ -336,7 +344,7 @@ function linkedinProvider(credentials = {}) {
336
344
  scope: credentials.scope ?? "openid profile email",
337
345
  async fetchProfile(accessToken) {
338
346
  const claims = await readJson(
339
- await fetch("https://api.linkedin.com/v2/userinfo", { headers: { Authorization: `Bearer ${accessToken}` } }),
347
+ await (credentials.fetchImpl ?? fetch)("https://api.linkedin.com/v2/userinfo", { headers: { Authorization: `Bearer ${accessToken}` } }),
340
348
  "LinkedIn userinfo"
341
349
  );
342
350
  return {
@@ -63,6 +63,8 @@ export interface OAuthProviderConfig {
63
63
  authorizeUrl: string;
64
64
  /** Where the `code` is exchanged for an access token. */
65
65
  tokenUrl: string;
66
+ /** Optional network hook for the token exchange (`exchangeCode`). Default: global `fetch`. */
67
+ fetchImpl?: typeof fetch;
66
68
  scope: string;
67
69
  /** Extra query parameters for the consent screen (`prompt`, `access_type`…). */
68
70
  authorizeParams?: Record<string, string>;
@@ -92,6 +94,13 @@ export interface ProviderCredentials {
92
94
  callbackUrl?: string;
93
95
  /** Overrides the default scope. */
94
96
  scope?: string;
97
+ /**
98
+ * Optional network hook for this provider's own calls (profile reads, and
99
+ * the `code` exchange via `OAuthProviderConfig.fetchImpl`). Lets the app
100
+ * route them through a resilient client (timeout, retries, alerts).
101
+ * Default: the global `fetch`.
102
+ */
103
+ fetchImpl?: typeof fetch;
95
104
  }
96
105
  /**
97
106
  * Reads a provider's JSON, or throws with the body when it fails.
@@ -1,5 +1,7 @@
1
1
  import { type OAuthProviderConfig } from '../oauth-provider.js';
2
2
  export interface AppleCredentials {
3
+ /** Optional network hook (token exchange and Apple's public keys). Default: global `fetch`. */
4
+ fetchImpl?: typeof fetch;
3
5
  /** The Services ID (`com.example.web`), not the App ID. `APPLE_CLIENT_ID`. */
4
6
  clientId?: string;
5
7
  /** `APPLE_TEAM_ID`. */
@@ -54,5 +56,5 @@ export declare function appleProvider(credentials?: AppleCredentials): OAuthProv
54
56
  */
55
57
  export declare function mintClientSecret(clientId: string, teamId: string, keyId: string, privateKey: string): string;
56
58
  /** Signature, issuer, audience and expiry — the four things a forged or replayed token fails. */
57
- export declare function verifyAppleIdToken(idToken: string, clientId: string, keysUrl?: string): Promise<AppleIdClaims>;
59
+ export declare function verifyAppleIdToken(idToken: string, clientId: string, keysUrl?: string, fetchImpl?: typeof fetch): Promise<AppleIdClaims>;
58
60
  export {};
@@ -1,5 +1,8 @@
1
1
  import { type INestApplication, type ValidationPipeOptions } from '@nestjs/common';
2
2
  import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
3
+ import { type BodyLimitsOptions } from '../hardening/body-limits.js';
4
+ import { type OriginSecretOptions } from '../hardening/origin-secret.js';
5
+ import { type TrustProxyValue } from '../hardening/trust-proxy.js';
3
6
  export interface SwaggerBootstrapOptions {
4
7
  title: string;
5
8
  path?: string;
@@ -9,6 +12,12 @@ export interface ApplyNestKitDefaultsOptions {
9
12
  /** Pass `false` to skip mounting Swagger entirely. */
10
13
  swagger?: SwaggerBootstrapOptions | false;
11
14
  validation?: ValidationPipeOptions;
15
+ /** Express `trust proxy` (e.g. `1` behind one proxy). Omitted: untouched. */
16
+ trustProxy?: TrustProxyValue;
17
+ /** Rejects with 403 whatever does not carry the CDN's shared secret header. Omitted: off. */
18
+ originSecret?: OriginSecretOptions;
19
+ /** JSON body limit (default and per route). Omitted: Nest/Express defaults. */
20
+ bodyLimits?: BodyLimitsOptions;
12
21
  }
13
22
  /**
14
23
  * Applies nestkit's opinionated defaults to a Nest application, in order:
@@ -1,14 +1,15 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkFNUZGYUFcjs = require('../chunk-FNUZGYUF.cjs');
4
- require('../chunk-3AUOOEQO.cjs');
5
- require('../chunk-MSTXS3MU.cjs');
3
+ var _chunkJRFE7NSOcjs = require('../chunk-JRFE7NSO.cjs');
4
+ require('../chunk-F77X4QUN.cjs');
5
+ require('../chunk-JJKGQNGD.cjs');
6
+ require('../chunk-IVWPA6QH.cjs');
6
7
  require('../chunk-AXMW5JF7.cjs');
7
8
  require('../chunk-Y72D5L6I.cjs');
8
9
  require('../chunk-SDWHKPXI.cjs');
9
10
  require('../chunk-Q5Y33L7B.cjs');
10
11
  require('../chunk-PNK5WMPP.cjs');
11
- require('../chunk-2REOCMUD.cjs');
12
+ require('../chunk-LRX7AMSS.cjs');
12
13
 
13
14
 
14
- exports.applyNestKitDefaults = _chunkFNUZGYUFcjs.applyNestKitDefaults;
15
+ exports.applyNestKitDefaults = _chunkJRFE7NSOcjs.applyNestKitDefaults;
@@ -1,14 +1,15 @@
1
1
  import {
2
2
  applyNestKitDefaults
3
- } from "../chunk-UNEVXCFW.js";
4
- import "../chunk-DYHSOULW.js";
5
- import "../chunk-A2DGK4ZL.js";
3
+ } from "../chunk-UGAAJRPO.js";
4
+ import "../chunk-IGSNB5BX.js";
5
+ import "../chunk-5LVGCTJ3.js";
6
+ import "../chunk-WFCQDOSN.js";
6
7
  import "../chunk-X4PQJZ4G.js";
7
8
  import "../chunk-TCAMLNUZ.js";
8
9
  import "../chunk-ETRUVZTJ.js";
9
10
  import "../chunk-M3GQDRWR.js";
10
11
  import "../chunk-VVMRZEIW.js";
11
- import "../chunk-4MGIQFAJ.js";
12
+ import "../chunk-D3DDJWUD.js";
12
13
  export {
13
14
  applyNestKitDefaults
14
15
  };
@@ -0,0 +1,14 @@
1
+ // src/consent/shared/index.ts
2
+ function compareVersions(a, b) {
3
+ return a === b ? 0 : a < b ? -1 : 1;
4
+ }
5
+ function versionAceptadaVigente(version, minima) {
6
+ return !!version && version >= minima;
7
+ }
8
+ var isAcceptedVersionValid = versionAceptadaVigente;
9
+
10
+ export {
11
+ compareVersions,
12
+ versionAceptadaVigente,
13
+ isAcceptedVersionValid
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/database/supabase/supabase.module.ts
6
6
  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/database/postgres/postgres.module.ts
6
6
  var _common = require('@nestjs/common');
@@ -8,7 +8,7 @@ var _pg = require('pg');
8
8
  var PG_POOL = /* @__PURE__ */ Symbol("PG_POOL");
9
9
  var PgModule = class {
10
10
  };
11
- PgModule = exports.PgModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
11
+ PgModule = exports.PgModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
12
12
  _common.Module.call(void 0, {
13
13
  providers: [
14
14
  {
@@ -1,12 +1,12 @@
1
- import {
2
- UnauthorizedAppException
3
- } from "./chunk-ZFIDAX7K.js";
4
1
  import {
5
2
  RequestContext
6
3
  } from "./chunk-ETRUVZTJ.js";
4
+ import {
5
+ UnauthorizedAppException
6
+ } from "./chunk-ZFIDAX7K.js";
7
7
  import {
8
8
  __decorateClass
9
- } from "./chunk-4MGIQFAJ.js";
9
+ } from "./chunk-D3DDJWUD.js";
10
10
 
11
11
  // src/auth/token.service.ts
12
12
  import jwt from "jsonwebtoken";
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-M3GQDRWR.js";
12
12
  import {
13
13
  __decorateClass
14
- } from "./chunk-4MGIQFAJ.js";
14
+ } from "./chunk-D3DDJWUD.js";
15
15
 
16
16
  // src/errors/global-exception.filter.ts
17
17
  import {
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/consent/shared/index.ts
2
+ function compareVersions(a, b) {
3
+ return a === b ? 0 : a < b ? -1 : 1;
4
+ }
5
+ function versionAceptadaVigente(version, minima) {
6
+ return !!version && version >= minima;
7
+ }
8
+ var isAcceptedVersionValid = versionAceptadaVigente;
9
+
10
+
11
+
12
+
13
+
14
+ exports.compareVersions = compareVersions; exports.versionAceptadaVigente = versionAceptadaVigente; exports.isAcceptedVersionValid = isAcceptedVersionValid;
@@ -0,0 +1,40 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-D3DDJWUD.js";
4
+
5
+ // src/consent/guard/index.ts
6
+ var guard_exports = {};
7
+ __export(guard_exports, {
8
+ bundleContains: () => bundleContains,
9
+ checkParity: () => checkParity,
10
+ extractVersion: () => extractVersion,
11
+ verifyRelease: () => verifyRelease
12
+ });
13
+ function extractVersion(source, pattern) {
14
+ return pattern.exec(source)?.[1] ?? null;
15
+ }
16
+ function checkParity(mobile, server) {
17
+ if (!mobile || !server) return { ok: false, message: "No se pudo leer la versi\xF3n m\xEDnima (m\xF3vil o servidor)." };
18
+ return mobile === server ? { ok: true, message: `Paridad correcta: ${server}.` } : { ok: false, message: `La m\xEDnima del m\xF3vil (${mobile}) no coincide con la del servidor (${server}).` };
19
+ }
20
+ function bundleContains(bundleText, minimum) {
21
+ return bundleText.includes(minimum) ? { ok: true, message: `El bundle web trae ${minimum}.` } : { ok: false, message: `El bundle web publicado NO trae ${minimum}: publ\xEDcalo antes de desplegar la API.` };
22
+ }
23
+ function verifyRelease(input) {
24
+ const results = [checkParity(input.mobile, input.server)];
25
+ if (input.webBundle !== void 0 && input.server)
26
+ results.push(bundleContains(input.webBundle, input.server));
27
+ if (input.mobilePublished !== void 0)
28
+ results.push(
29
+ input.mobilePublished === input.server ? { ok: true, message: "M\xF3vil publicado confirmado." } : { ok: false, message: `M\xF3vil publicado (${input.mobilePublished}) distinto de la m\xEDnima (${input.server}).` }
30
+ );
31
+ return { ok: results.every((r) => r.ok), results };
32
+ }
33
+
34
+ export {
35
+ extractVersion,
36
+ checkParity,
37
+ bundleContains,
38
+ verifyRelease,
39
+ guard_exports
40
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/push/push.port.ts
2
+ var PUSH = /* @__PURE__ */ Symbol("PUSH");
3
+ var PUSH_DEVICE_STORE = /* @__PURE__ */ Symbol("PUSH_DEVICE_STORE");
4
+
5
+
6
+
7
+
8
+ exports.PUSH = PUSH; exports.PUSH_DEVICE_STORE = PUSH_DEVICE_STORE;
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkHDFPSA2Vcjs = require('./chunk-HDFPSA2V.cjs');
3
+ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
4
4
 
5
5
 
6
- var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
6
+ var _chunkHDFPSA2Vcjs = require('./chunk-HDFPSA2V.cjs');
7
7
 
8
8
 
9
- var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
9
+ var _chunkLRX7AMSScjs = require('./chunk-LRX7AMSS.cjs');
10
10
 
11
11
  // src/auth/token.service.ts
12
12
  var _jsonwebtoken = require('jsonwebtoken'); var _jsonwebtoken2 = _interopRequireDefault(_jsonwebtoken);
@@ -63,7 +63,7 @@ var JwtAuthGuard = class {
63
63
  return true;
64
64
  }
65
65
  };
66
- JwtAuthGuard = exports.JwtAuthGuard = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
66
+ JwtAuthGuard = exports.JwtAuthGuard = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
67
67
  _common.Injectable.call(void 0, )
68
68
  ], JwtAuthGuard);
69
69
 
@@ -1,5 +1,9 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
3
7
  var __decorateClass = (decorators, target, key, kind) => {
4
8
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
9
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -11,6 +15,7 @@ var __decorateClass = (decorators, target, key, kind) => {
11
15
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
12
16
 
13
17
  export {
18
+ __export,
14
19
  __decorateClass,
15
20
  __decorateParam
16
21
  };
@@ -0,0 +1,8 @@
1
+ // src/push/push.port.ts
2
+ var PUSH = /* @__PURE__ */ Symbol("PUSH");
3
+ var PUSH_DEVICE_STORE = /* @__PURE__ */ Symbol("PUSH_DEVICE_STORE");
4
+
5
+ export {
6
+ PUSH,
7
+ PUSH_DEVICE_STORE
8
+ };
@@ -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/database/postgres/postgres.module.ts
6
6
  import { Module } from "@nestjs/common";
@@ -6,7 +6,7 @@ var _chunkY72D5L6Icjs = require('./chunk-Y72D5L6I.cjs');
6
6
  var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
7
7
 
8
8
 
9
- var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
9
+ var _chunkLRX7AMSScjs = require('./chunk-LRX7AMSS.cjs');
10
10
 
11
11
  // src/response/response.interceptor.ts
12
12
  var _common = require('@nestjs/common');
@@ -25,7 +25,7 @@ var ResponseInterceptor = class {
25
25
  );
26
26
  }
27
27
  };
28
- ResponseInterceptor = exports.ResponseInterceptor = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
28
+ ResponseInterceptor = exports.ResponseInterceptor = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
29
29
  _common.Injectable.call(void 0, )
30
30
  ], ResponseInterceptor);
31
31
 
@@ -0,0 +1,61 @@
1
+ // src/tenancy/tenancy.options.ts
2
+ var TENANCY_OPTIONS = /* @__PURE__ */ Symbol("TENANCY_OPTIONS");
3
+ var DEFAULT_GUCS = { tenant: "app.tenant_id", actor: "app.actor_id" };
4
+
5
+ // src/tenancy/request-context.ts
6
+ import { AsyncLocalStorage } from "async_hooks";
7
+ var storage = new AsyncLocalStorage();
8
+ var TenancyContext = {
9
+ run(fn, initial = {}) {
10
+ return storage.run({ ...initial }, fn);
11
+ },
12
+ setTenant(tenantId) {
13
+ const s = storage.getStore();
14
+ if (s) s.tenantId = tenantId;
15
+ },
16
+ setActor(actorId) {
17
+ const s = storage.getStore();
18
+ if (s) s.actorId = actorId;
19
+ },
20
+ tenantId() {
21
+ return storage.getStore()?.tenantId;
22
+ },
23
+ actorId() {
24
+ return storage.getStore()?.actorId;
25
+ }
26
+ };
27
+
28
+ // src/tenancy/tenancy.errors.ts
29
+ var TenantRequiredError = class extends Error {
30
+ constructor(message = "No tenant in scope: refusing to run a tenant query without one.") {
31
+ super(message);
32
+ this.code = "TENANT_REQUIRED";
33
+ this.name = "TenantRequiredError";
34
+ }
35
+ };
36
+
37
+ // src/tenancy/scope.ts
38
+ var GUC_NAME = /^[a-zA-Z_][\w]*(\.[\w-]+)+$/;
39
+ async function applyScope(query, scope, options = {}) {
40
+ const gucs = options.gucs ?? DEFAULT_GUCS;
41
+ const tenantId = scope.tenantId ?? TenancyContext.tenantId();
42
+ const actorId = scope.actorId ?? TenancyContext.actorId();
43
+ if (!tenantId && options.failClosed !== false) throw new TenantRequiredError();
44
+ const pairs = [];
45
+ if (tenantId) pairs.push([gucs.tenant, tenantId]);
46
+ if (gucs.actor && actorId) pairs.push([gucs.actor, actorId]);
47
+ for (const [name] of pairs) {
48
+ if (!GUC_NAME.test(name)) throw new Error(`Invalid GUC name: ${name}`);
49
+ }
50
+ for (const [name, value] of pairs) {
51
+ await query("SELECT set_config($1, $2, true)", [name, value]);
52
+ }
53
+ }
54
+
55
+ export {
56
+ TENANCY_OPTIONS,
57
+ DEFAULT_GUCS,
58
+ TenancyContext,
59
+ TenantRequiredError,
60
+ applyScope
61
+ };
@@ -9,7 +9,7 @@ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
9
9
 
10
10
 
11
11
 
12
- var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
12
+ var _chunkLRX7AMSScjs = require('./chunk-LRX7AMSS.cjs');
13
13
 
14
14
  // src/i18n/i18n.module.ts
15
15
 
@@ -36,7 +36,7 @@ var I18nInterceptor = class {
36
36
  return next.handle().pipe(_operators.map.call(void 0, (data) => _chunkAXMW5JF7cjs.translateDeep.call(void 0, data, lang)));
37
37
  }
38
38
  };
39
- I18nInterceptor = exports.I18nInterceptor = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
39
+ I18nInterceptor = exports.I18nInterceptor = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
40
40
  _common.Injectable.call(void 0, )
41
41
  ], I18nInterceptor);
42
42
 
@@ -181,11 +181,11 @@ var I18nModule = class {
181
181
  return this.i18n;
182
182
  }
183
183
  };
184
- I18nModule = exports.I18nModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
184
+ I18nModule = exports.I18nModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
185
185
  _common.Module.call(void 0, {}),
186
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, NESTKIT_I18N_OPTIONS)),
187
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Optional.call(void 0, )),
188
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, _nestjsi18n.I18nService))
186
+ _chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, NESTKIT_I18N_OPTIONS)),
187
+ _chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Optional.call(void 0, )),
188
+ _chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, _nestjsi18n.I18nService))
189
189
  ], I18nModule);
190
190
  var RuntimeResolver = class {
191
191
  resolve(context) {
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-ETRUVZTJ.js";
7
7
  import {
8
8
  __decorateClass
9
- } from "./chunk-4MGIQFAJ.js";
9
+ } from "./chunk-D3DDJWUD.js";
10
10
 
11
11
  // src/response/response.interceptor.ts
12
12
  import { Injectable } from "@nestjs/common";