@miguelmorales13/nestkit 0.26.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/dist/alerts/alert-on-failure.decorator.d.ts +5 -0
- package/dist/alerts/alert-sinks.d.ts +29 -0
- package/dist/alerts/alerts.module.d.ts +19 -0
- package/dist/alerts/alerts.options.d.ts +1 -0
- package/dist/alerts/alerts.service.d.ts +28 -0
- package/dist/alerts/alerts.types.d.ts +66 -0
- package/dist/alerts/index.cjs +276 -0
- package/dist/alerts/index.d.ts +10 -0
- package/dist/alerts/index.js +276 -0
- package/dist/alerts/logger-with-alerts.d.ts +18 -0
- package/dist/alerts/process-guards.d.ts +21 -0
- package/dist/alerts/runtime.d.ts +4 -0
- package/dist/audit/index.cjs +13 -13
- package/dist/audit/index.js +2 -2
- package/dist/auth/index.cjs +21 -21
- package/dist/auth/index.js +3 -3
- package/dist/auth/oauth/index.cjs +101 -101
- package/dist/auth/oauth/index.js +3 -3
- package/dist/bootstrap/apply-defaults.d.ts +9 -0
- package/dist/bootstrap/index.cjs +7 -6
- package/dist/bootstrap/index.js +6 -5
- package/dist/chunk-33KFVAUZ.cjs +151 -0
- package/dist/chunk-3TUMVLPJ.js +14 -0
- package/dist/{chunk-PA24P76K.js → chunk-45SW7FBE.js} +1 -1
- package/dist/{chunk-RF75KC63.cjs → chunk-47IYXZHW.cjs} +2 -2
- package/dist/{chunk-TUNDBBQF.js → chunk-4WWOKZIO.js} +4 -4
- package/dist/{chunk-2DUEQKOI.js → chunk-5LVGCTJ3.js} +4 -4
- package/dist/chunk-A6YGIZCQ.cjs +14 -0
- package/dist/chunk-A7FI6HXV.js +40 -0
- package/dist/chunk-CU4FUIVJ.cjs +8 -0
- package/dist/{chunk-FH5UNWWW.cjs → chunk-D35TBVRO.cjs} +4 -4
- package/dist/{chunk-4MGIQFAJ.js → chunk-D3DDJWUD.js} +5 -0
- package/dist/chunk-DVGPEBUL.js +8 -0
- package/dist/{chunk-VKOPDDCC.js → chunk-ENZ7LQRE.js} +1 -1
- package/dist/{chunk-3AUOOEQO.cjs → chunk-F77X4QUN.cjs} +2 -2
- package/dist/chunk-FBNV5X6C.js +61 -0
- package/dist/{chunk-APUFKA4K.cjs → chunk-FDZQCLLK.cjs} +6 -6
- package/dist/{chunk-DYHSOULW.js → chunk-IGSNB5BX.js} +1 -1
- package/dist/chunk-IVWPA6QH.cjs +90 -0
- package/dist/{chunk-LSDY6ETG.cjs → chunk-JJKGQNGD.cjs} +5 -5
- package/dist/{chunk-ALIKVFOV.cjs → chunk-JRFE7NSO.cjs} +12 -4
- package/dist/{chunk-HVHYZXBB.cjs → chunk-KNU5RN3O.cjs} +3 -3
- package/dist/{chunk-52IOOHNX.cjs → chunk-KQPJCVN3.cjs} +26 -26
- package/dist/chunk-LGFHLAY3.cjs +61 -0
- package/dist/{chunk-2REOCMUD.cjs → chunk-LRX7AMSS.cjs} +6 -1
- package/dist/chunk-LU3HO7B3.js +151 -0
- package/dist/{chunk-4PFAKLT3.js → chunk-MUWHGBIB.js} +1 -1
- package/dist/{chunk-ZJMLEP5H.js → chunk-NJYLQDB3.js} +1 -1
- package/dist/{chunk-IFNYRZP2.js → chunk-OSRH6KYZ.js} +4 -4
- package/dist/{chunk-6RAPVLJM.js → chunk-OTE77ONL.js} +1 -1
- package/dist/chunk-UDACUMLO.cjs +40 -0
- package/dist/{chunk-PFHHLB7B.js → chunk-UGAAJRPO.js} +10 -2
- package/dist/{chunk-SPTDXUED.cjs → chunk-URLDTS2Q.cjs} +2 -2
- package/dist/{chunk-W2T2VFLC.cjs → chunk-VALDHJOO.cjs} +5 -5
- package/dist/chunk-WFCQDOSN.js +90 -0
- package/dist/consent/consent.interceptor.d.ts +20 -0
- package/dist/consent/consent.module.d.ts +25 -0
- package/dist/consent/consent.options.d.ts +30 -0
- package/dist/consent/consent.port.d.ts +17 -0
- package/dist/consent/consent.service.d.ts +44 -0
- package/dist/consent/guard/index.cjs +13 -0
- package/dist/consent/guard/index.d.ts +31 -0
- package/dist/consent/guard/index.js +13 -0
- package/dist/consent/index.cjs +271 -0
- package/dist/consent/index.d.ts +13 -0
- package/dist/consent/index.js +271 -0
- package/dist/consent/memory.store.d.ts +7 -0
- package/dist/consent/shared/index.cjs +11 -0
- package/dist/consent/shared/index.d.ts +19 -0
- package/dist/consent/shared/index.js +11 -0
- package/dist/consent/typeorm.store.d.ts +22 -0
- package/dist/crud/index.cjs +4 -4
- package/dist/crud/index.js +3 -3
- package/dist/database/postgres/index.cjs +3 -3
- package/dist/database/postgres/index.js +2 -2
- package/dist/database/supabase/index.cjs +3 -3
- package/dist/database/supabase/index.js +2 -2
- package/dist/database/typeorm/index.cjs +2 -2
- package/dist/database/typeorm/index.js +1 -1
- package/dist/devices/device-check.interceptor.d.ts +20 -0
- package/dist/devices/devices.module.d.ts +28 -0
- package/dist/devices/devices.options.d.ts +53 -0
- package/dist/devices/devices.port.d.ts +62 -0
- package/dist/devices/devices.service.d.ts +58 -0
- package/dist/devices/index.cjs +327 -0
- package/dist/devices/index.d.ts +8 -0
- package/dist/devices/index.js +327 -0
- package/dist/devices/memory.store.d.ts +12 -0
- package/dist/email/index.cjs +2 -2
- package/dist/email/index.js +1 -1
- package/dist/email/nodemailer/index.cjs +2 -2
- package/dist/email/nodemailer/index.js +1 -1
- package/dist/email/resend/index.cjs +2 -2
- package/dist/email/resend/index.js +1 -1
- package/dist/entities/index.cjs +1 -1
- package/dist/entities/index.js +1 -1
- package/dist/errors/index.cjs +7 -7
- package/dist/errors/index.js +7 -7
- package/dist/events/buses.d.ts +27 -0
- package/dist/events/events.controller.d.ts +15 -0
- package/dist/events/events.module.d.ts +29 -0
- package/dist/events/events.options.d.ts +50 -0
- package/dist/events/events.service.d.ts +49 -0
- package/dist/events/events.types.d.ts +77 -0
- package/dist/events/index.cjs +557 -0
- package/dist/events/index.d.ts +10 -0
- package/dist/events/index.js +557 -0
- package/dist/events/memory-ticket.store.d.ts +9 -0
- package/dist/google-business/google-business-http.d.ts +41 -0
- package/dist/google-business/google-business.errors.d.ts +75 -0
- package/dist/google-business/google-business.mappers.d.ts +52 -0
- package/dist/google-business/google-business.module.d.ts +26 -0
- package/dist/google-business/google-business.options.d.ts +40 -0
- package/dist/google-business/google-business.ports.d.ts +18 -0
- package/dist/google-business/google-business.service.d.ts +120 -0
- package/dist/google-business/google-business.types.d.ts +155 -0
- package/dist/google-business/index.cjs +1025 -0
- package/dist/google-business/index.d.ts +15 -0
- package/dist/google-business/index.js +1025 -0
- package/dist/google-business/testing/google-simulator.d.ts +61 -0
- package/dist/hardening/body-limits.d.ts +24 -0
- package/dist/hardening/http.types.d.ts +26 -0
- package/dist/hardening/index.cjs +179 -0
- package/dist/hardening/index.d.ts +19 -0
- package/dist/hardening/index.js +179 -0
- package/dist/hardening/memory-rate-limit.store.d.ts +10 -0
- package/dist/hardening/origin-secret.d.ts +29 -0
- package/dist/hardening/rate-limit.decorator.d.ts +8 -0
- package/dist/hardening/rate-limit.guard.d.ts +18 -0
- package/dist/hardening/rate-limit.module.d.ts +23 -0
- package/dist/hardening/rate-limit.options.d.ts +35 -0
- package/dist/hardening/rate-limit.port.d.ts +11 -0
- package/dist/hardening/redis-rate-limit.store.d.ts +23 -0
- package/dist/hardening/trust-proxy.d.ts +22 -0
- package/dist/health/health.controller.d.ts +32 -0
- package/dist/health/health.module.d.ts +15 -0
- package/dist/health/health.options.d.ts +24 -0
- package/dist/health/index.cjs +103 -0
- package/dist/health/index.d.ts +5 -0
- package/dist/health/index.js +103 -0
- package/dist/i18n/index.cjs +3 -3
- package/dist/i18n/index.js +2 -2
- package/dist/idempotency/idempotency.interceptor.d.ts +1 -0
- package/dist/idempotency/idempotency.options.d.ts +15 -0
- package/dist/idempotency/index.cjs +214 -7
- package/dist/idempotency/index.d.ts +5 -0
- package/dist/idempotency/index.js +210 -3
- package/dist/idempotency/no-idempotency.decorator.d.ts +8 -0
- package/dist/idempotency/postgres.store.d.ts +49 -0
- package/dist/idempotency/redis.store.d.ts +59 -0
- package/dist/index.cjs +21 -20
- package/dist/index.js +33 -32
- package/dist/invoicing/index.cjs +2 -2
- package/dist/invoicing/index.js +1 -1
- package/dist/jobs/defer-job.d.ts +10 -0
- package/dist/jobs/index.cjs +318 -0
- package/dist/jobs/index.d.ts +8 -0
- package/dist/jobs/index.js +318 -0
- package/dist/jobs/jobs-admin.controller.d.ts +18 -0
- package/dist/jobs/jobs.module.d.ts +33 -0
- package/dist/jobs/jobs.options.d.ts +62 -0
- package/dist/jobs/jobs.service.d.ts +53 -0
- package/dist/jobs/jobs.sql.d.ts +11 -0
- package/dist/media/index.cjs +14 -14
- package/dist/media/index.js +1 -1
- package/dist/meta/index.cjs +3 -3
- package/dist/meta/index.js +1 -1
- package/dist/notifications/index.cjs +375 -0
- package/dist/notifications/index.d.ts +8 -0
- package/dist/notifications/index.js +375 -0
- package/dist/notifications/memory.stores.d.ts +23 -0
- package/dist/notifications/notifications.controller.d.ts +11 -0
- package/dist/notifications/notifications.module.d.ts +31 -0
- package/dist/notifications/notifications.options.d.ts +33 -0
- package/dist/notifications/notifications.port.d.ts +97 -0
- package/dist/notifications/notifier.service.d.ts +31 -0
- package/dist/payments/connect/credentials-cipher.d.ts +14 -0
- package/dist/payments/connect/mercadopago-refund.d.ts +118 -0
- package/dist/payments/connect/mercadopago-signature.d.ts +6 -0
- package/dist/payments/connect/online-checkout.d.ts +69 -0
- package/dist/payments/connect/rejection.d.ts +7 -0
- package/dist/payments/connect/status.d.ts +20 -0
- package/dist/payments/connect/terminal-connections.d.ts +291 -0
- package/dist/payments/index.cjs +908 -10
- package/dist/payments/index.d.ts +10 -0
- package/dist/payments/index.js +900 -2
- package/dist/pinterest/index.cjs +3 -3
- package/dist/pinterest/index.js +1 -1
- package/dist/privacy/anonymizer.d.ts +14 -0
- package/dist/privacy/index.cjs +768 -0
- package/dist/privacy/index.d.ts +13 -0
- package/dist/privacy/index.js +768 -0
- package/dist/privacy/memory.store.d.ts +15 -0
- package/dist/privacy/privacy.module.d.ts +30 -0
- package/dist/privacy/privacy.options.d.ts +43 -0
- package/dist/privacy/privacy.port.d.ts +25 -0
- package/dist/privacy/privacy.service.d.ts +69 -0
- package/dist/privacy/privacy.types.d.ts +125 -0
- package/dist/privacy/sql.d.ts +7 -0
- package/dist/privacy/sql.store.d.ts +21 -0
- package/dist/privacy/zip.d.ts +23 -0
- package/dist/push/index.cjs +13 -13
- package/dist/push/index.js +5 -5
- package/dist/resilience/alert-channels.d.ts +39 -0
- package/dist/resilience/alert-errors.interceptor.d.ts +10 -0
- package/dist/resilience/alert-on-failure.decorator.d.ts +10 -0
- package/dist/resilience/alert.service.d.ts +77 -0
- package/dist/resilience/index.cjs +863 -0
- package/dist/resilience/index.d.ts +18 -0
- package/dist/resilience/index.js +863 -0
- package/dist/resilience/memory-alert-store.d.ts +26 -0
- package/dist/resilience/provider-health.controller.d.ts +14 -0
- package/dist/resilience/provider-unavailable.exception.d.ts +11 -0
- package/dist/resilience/resilience.module.d.ts +34 -0
- package/dist/resilience/resilience.options.d.ts +28 -0
- package/dist/resilience/resilience.types.d.ts +167 -0
- package/dist/resilience/resilient-fetch.d.ts +38 -0
- package/dist/resilience/runtime.d.ts +24 -0
- package/dist/resilience/typeorm/alert.entity.d.ts +21 -0
- package/dist/resilience/typeorm/index.cjs +102 -0
- package/dist/resilience/typeorm/index.d.ts +3 -0
- package/dist/resilience/typeorm/index.js +102 -0
- package/dist/resilience/typeorm/typeorm-alert-store.d.ts +39 -0
- package/dist/resilience/validate-destination.d.ts +63 -0
- package/dist/response/index.cjs +3 -3
- package/dist/response/index.js +2 -2
- package/dist/scheduling/cron-lock.service.d.ts +36 -0
- package/dist/scheduling/cron-unico.decorator.d.ts +27 -0
- package/dist/scheduling/fallback.store.d.ts +34 -0
- package/dist/scheduling/index.cjs +392 -0
- package/dist/scheduling/index.d.ts +18 -0
- package/dist/scheduling/index.js +392 -0
- package/dist/scheduling/lock-store.port.d.ts +19 -0
- package/dist/scheduling/memory.store.d.ts +15 -0
- package/dist/scheduling/redis.module.d.ts +31 -0
- package/dist/scheduling/redis.store.d.ts +24 -0
- package/dist/scheduling/scheduling.module.d.ts +24 -0
- package/dist/scheduling/scheduling.options.d.ts +27 -0
- package/dist/scheduling/sql.store.d.ts +26 -0
- package/dist/secrets/index.cjs +274 -0
- package/dist/secrets/index.d.ts +8 -0
- package/dist/secrets/index.js +274 -0
- package/dist/secrets/secrets.errors.d.ts +6 -0
- package/dist/secrets/secrets.module.d.ts +21 -0
- package/dist/secrets/secrets.options.d.ts +32 -0
- package/dist/secrets/secrets.service.d.ts +54 -0
- package/dist/secrets/secrets.transformer.d.ts +33 -0
- package/dist/security/hash.d.ts +8 -0
- package/dist/security/index.cjs +27 -35
- package/dist/security/index.d.ts +5 -0
- package/dist/security/index.js +24 -32
- package/dist/security/mask.d.ts +22 -0
- package/dist/security/signed-grant.d.ts +30 -0
- package/dist/storage/index.cjs +2 -2
- package/dist/storage/index.js +1 -1
- package/dist/stripe/index.cjs +7 -7
- package/dist/stripe/index.js +1 -1
- package/dist/telegram/index.cjs +2 -2
- package/dist/telegram/index.js +1 -1
- package/dist/tenancy/app-role.d.ts +24 -0
- package/dist/tenancy/db-helpers.d.ts +12 -0
- package/dist/tenancy/index.cjs +205 -0
- package/dist/tenancy/index.d.ts +14 -0
- package/dist/tenancy/index.js +205 -0
- package/dist/tenancy/pg/index.cjs +34 -0
- package/dist/tenancy/pg/index.d.ts +2 -0
- package/dist/tenancy/pg/index.js +34 -0
- package/dist/tenancy/pg/with-tenant.d.ts +23 -0
- package/dist/tenancy/request-context.d.ts +18 -0
- package/dist/tenancy/rls-guardrail.d.ts +38 -0
- package/dist/tenancy/scope.d.ts +5 -0
- package/dist/tenancy/tenancy.errors.d.ts +5 -0
- package/dist/tenancy/tenancy.middleware.d.ts +8 -0
- package/dist/tenancy/tenancy.module.d.ts +37 -0
- package/dist/tenancy/tenancy.options.d.ts +34 -0
- package/dist/tenancy/typeorm/index.cjs +41 -0
- package/dist/tenancy/typeorm/index.d.ts +2 -0
- package/dist/tenancy/typeorm/index.js +41 -0
- package/dist/tenancy/typeorm/with-tenant.d.ts +23 -0
- package/dist/tiktok/index.cjs +3 -3
- package/dist/tiktok/index.js +1 -1
- package/dist/tracking/index.cjs +3 -3
- package/dist/tracking/index.js +2 -2
- package/dist/umami/index.cjs +4 -4
- package/dist/umami/index.js +1 -1
- package/dist/whatsapp/index.cjs +2 -2
- package/dist/whatsapp/index.js +1 -1
- package/package.json +108 -3
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_GUCS,
|
|
3
|
+
TENANCY_OPTIONS,
|
|
4
|
+
TenancyContext,
|
|
5
|
+
TenantRequiredError,
|
|
6
|
+
applyScope
|
|
7
|
+
} from "../chunk-FBNV5X6C.js";
|
|
8
|
+
import {
|
|
9
|
+
__decorateClass,
|
|
10
|
+
__decorateParam
|
|
11
|
+
} from "../chunk-D3DDJWUD.js";
|
|
12
|
+
|
|
13
|
+
// src/tenancy/tenancy.module.ts
|
|
14
|
+
import {
|
|
15
|
+
Global,
|
|
16
|
+
Inject as Inject3,
|
|
17
|
+
Module
|
|
18
|
+
} from "@nestjs/common";
|
|
19
|
+
|
|
20
|
+
// src/tenancy/rls-guardrail.ts
|
|
21
|
+
import { Inject, Injectable, Logger } from "@nestjs/common";
|
|
22
|
+
var RLS_GUARDRAIL_OPTIONS = /* @__PURE__ */ Symbol("RLS_GUARDRAIL_OPTIONS");
|
|
23
|
+
var RLS_GUARDRAIL_DB = /* @__PURE__ */ Symbol("RLS_GUARDRAIL_DB");
|
|
24
|
+
async function checkAppRole(db) {
|
|
25
|
+
const { rows } = await db.query(
|
|
26
|
+
`select current_user as usuario,
|
|
27
|
+
coalesce((select rolbypassrls from pg_roles where rolname = current_user), false) as bypassrls,
|
|
28
|
+
coalesce((select rolsuper from pg_roles where rolname = current_user), false) as superusuario`
|
|
29
|
+
);
|
|
30
|
+
const r = rows[0] ?? {};
|
|
31
|
+
return {
|
|
32
|
+
user: String(r.usuario ?? ""),
|
|
33
|
+
bypassRls: r.bypassrls === true,
|
|
34
|
+
superuser: r.superusuario === true
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
var RlsGuardrail = class {
|
|
38
|
+
constructor(db, options = {}) {
|
|
39
|
+
this.db = db;
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.log = new Logger(RlsGuardrail.name);
|
|
42
|
+
}
|
|
43
|
+
async onApplicationBootstrap() {
|
|
44
|
+
let role;
|
|
45
|
+
try {
|
|
46
|
+
role = await checkAppRole(this.db);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
this.log.warn(`Could not verify the database role: ${String(error)}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!role.bypassRls && !role.superuser) {
|
|
52
|
+
this.log.log(`RLS active: the app connects as "${role.user}" (does not skip RLS).`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const message = `The app connects as "${role.user}", a role that IGNORES Row-Level Security (${role.superuser ? "superuser" : "BYPASSRLS"}). Tenant isolation is OFF: every tenant can read every other tenant's data.${this.options.hint ? ` ${this.options.hint}` : ""}`;
|
|
56
|
+
const env = this.options.env ?? process.env.NODE_ENV;
|
|
57
|
+
const enforce = !(this.options.productionOnly ?? true) || env === "production";
|
|
58
|
+
if (enforce && (this.options.onBypass ?? "abort") === "abort") {
|
|
59
|
+
throw new Error(`BOOT ABORTED - ${message}`);
|
|
60
|
+
}
|
|
61
|
+
this.log.error(message);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
RlsGuardrail = __decorateClass([
|
|
65
|
+
Injectable(),
|
|
66
|
+
__decorateParam(0, Inject(RLS_GUARDRAIL_DB)),
|
|
67
|
+
__decorateParam(1, Inject(RLS_GUARDRAIL_OPTIONS))
|
|
68
|
+
], RlsGuardrail);
|
|
69
|
+
|
|
70
|
+
// src/tenancy/tenancy.middleware.ts
|
|
71
|
+
import { Inject as Inject2, Injectable as Injectable2 } from "@nestjs/common";
|
|
72
|
+
var TenancyMiddleware = class {
|
|
73
|
+
constructor(options) {
|
|
74
|
+
this.options = options;
|
|
75
|
+
}
|
|
76
|
+
use(req, _res, next) {
|
|
77
|
+
let tenantId;
|
|
78
|
+
let actorId;
|
|
79
|
+
try {
|
|
80
|
+
tenantId = this.options.resolveTenant?.(req);
|
|
81
|
+
actorId = this.options.resolveActor?.(req);
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
TenancyContext.run(() => next(), { tenantId, actorId });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
TenancyMiddleware = __decorateClass([
|
|
88
|
+
Injectable2(),
|
|
89
|
+
__decorateParam(0, Inject2(TENANCY_OPTIONS))
|
|
90
|
+
], TenancyMiddleware);
|
|
91
|
+
|
|
92
|
+
// src/tenancy/tenancy.module.ts
|
|
93
|
+
function providers(options) {
|
|
94
|
+
return [options, TenancyMiddleware];
|
|
95
|
+
}
|
|
96
|
+
var TenancyModule = class {
|
|
97
|
+
constructor(options) {
|
|
98
|
+
this.options = options;
|
|
99
|
+
}
|
|
100
|
+
configure(consumer) {
|
|
101
|
+
if (this.options.middleware !== false) consumer.apply(TenancyMiddleware).forRoutes("*");
|
|
102
|
+
}
|
|
103
|
+
static forRoot(options) {
|
|
104
|
+
const { guardrail, ...core } = options;
|
|
105
|
+
const list = providers({ provide: TENANCY_OPTIONS, useValue: core });
|
|
106
|
+
if (guardrail) {
|
|
107
|
+
const { db, ...rest } = guardrail;
|
|
108
|
+
list.push(
|
|
109
|
+
{ provide: RLS_GUARDRAIL_DB, useValue: db },
|
|
110
|
+
{ provide: RLS_GUARDRAIL_OPTIONS, useValue: rest },
|
|
111
|
+
RlsGuardrail
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return { module: TenancyModule, providers: list, exports: [TENANCY_OPTIONS] };
|
|
115
|
+
}
|
|
116
|
+
static forRootAsync(config) {
|
|
117
|
+
const raw = { provide: "TENANCY_RAW", useFactory: config.useFactory, inject: config.inject ?? [] };
|
|
118
|
+
const list = [
|
|
119
|
+
raw,
|
|
120
|
+
{ provide: TENANCY_OPTIONS, useFactory: (o) => {
|
|
121
|
+
const { guardrail: _g, ...core } = o;
|
|
122
|
+
return core;
|
|
123
|
+
}, inject: ["TENANCY_RAW"] },
|
|
124
|
+
TenancyMiddleware,
|
|
125
|
+
{ provide: RLS_GUARDRAIL_DB, useFactory: (o) => o.guardrail?.db, inject: ["TENANCY_RAW"] },
|
|
126
|
+
{
|
|
127
|
+
provide: RLS_GUARDRAIL_OPTIONS,
|
|
128
|
+
useFactory: (o) => {
|
|
129
|
+
const { db: _d, ...rest } = o.guardrail ?? { db: void 0 };
|
|
130
|
+
return rest;
|
|
131
|
+
},
|
|
132
|
+
inject: ["TENANCY_RAW"]
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
provide: RlsGuardrail,
|
|
136
|
+
useFactory: (o, db, opts) => o.guardrail ? new RlsGuardrail(db, opts) : { onApplicationBootstrap: async () => {
|
|
137
|
+
} },
|
|
138
|
+
inject: ["TENANCY_RAW", RLS_GUARDRAIL_DB, RLS_GUARDRAIL_OPTIONS]
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
return { module: TenancyModule, imports: config.imports ?? [], providers: list, exports: [TENANCY_OPTIONS] };
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
TenancyModule = __decorateClass([
|
|
145
|
+
Global(),
|
|
146
|
+
Module({}),
|
|
147
|
+
__decorateParam(0, Inject3(TENANCY_OPTIONS))
|
|
148
|
+
], TenancyModule);
|
|
149
|
+
|
|
150
|
+
// src/tenancy/app-role.ts
|
|
151
|
+
var IDENT = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
152
|
+
async function ensureAppRole(admin, options) {
|
|
153
|
+
const { role, password, db, bypassRls = false, schema = "public" } = options;
|
|
154
|
+
if (!IDENT.test(role) || !IDENT.test(db) || !IDENT.test(schema)) {
|
|
155
|
+
throw new Error("Invalid role, database or schema name.");
|
|
156
|
+
}
|
|
157
|
+
const pass = `'${password.replace(/'/g, "''")}'`;
|
|
158
|
+
const exists = await admin.query("SELECT 1 FROM pg_roles WHERE rolname = $1", [role]);
|
|
159
|
+
if (!exists.rowCount) {
|
|
160
|
+
await admin.query(
|
|
161
|
+
`CREATE ROLE ${role} LOGIN PASSWORD ${pass} NOSUPERUSER ${bypassRls ? "BYPASSRLS" : "NOBYPASSRLS"} NOCREATEDB NOCREATEROLE`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
await admin.query(`GRANT CONNECT ON DATABASE ${db} TO ${role}`);
|
|
165
|
+
await admin.query(`GRANT USAGE ON SCHEMA ${schema} TO ${role}`);
|
|
166
|
+
await admin.query(`GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA ${schema} TO ${role}`);
|
|
167
|
+
await admin.query(`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA ${schema} TO ${role}`);
|
|
168
|
+
await admin.query(
|
|
169
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA ${schema} GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO ${role}`
|
|
170
|
+
);
|
|
171
|
+
await admin.query(
|
|
172
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA ${schema} GRANT USAGE, SELECT ON SEQUENCES TO ${role}`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/tenancy/db-helpers.ts
|
|
177
|
+
function pgSqlState(error) {
|
|
178
|
+
const e = error;
|
|
179
|
+
const code = e?.code ?? e?.driverError?.code;
|
|
180
|
+
return typeof code === "string" ? code : void 0;
|
|
181
|
+
}
|
|
182
|
+
function updatedRows(result) {
|
|
183
|
+
if (result && !Array.isArray(result) && Array.isArray(result.rows)) {
|
|
184
|
+
return result.rows;
|
|
185
|
+
}
|
|
186
|
+
if (!Array.isArray(result)) return [];
|
|
187
|
+
const isTuple = result.length === 2 && Array.isArray(result[0]) && typeof result[1] === "number";
|
|
188
|
+
return isTuple ? result[0] : result;
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
DEFAULT_GUCS,
|
|
192
|
+
RLS_GUARDRAIL_DB,
|
|
193
|
+
RLS_GUARDRAIL_OPTIONS,
|
|
194
|
+
RlsGuardrail,
|
|
195
|
+
TENANCY_OPTIONS,
|
|
196
|
+
TenancyContext,
|
|
197
|
+
TenancyMiddleware,
|
|
198
|
+
TenancyModule,
|
|
199
|
+
TenantRequiredError,
|
|
200
|
+
applyScope,
|
|
201
|
+
checkAppRole,
|
|
202
|
+
ensureAppRole,
|
|
203
|
+
pgSqlState,
|
|
204
|
+
updatedRows
|
|
205
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkLGFHLAY3cjs = require('../../chunk-LGFHLAY3.cjs');
|
|
4
|
+
require('../../chunk-LRX7AMSS.cjs');
|
|
5
|
+
|
|
6
|
+
// src/tenancy/pg/with-tenant.ts
|
|
7
|
+
async function run(pool, begin, scope, fn, options) {
|
|
8
|
+
const client = await pool.connect();
|
|
9
|
+
try {
|
|
10
|
+
await client.query(begin);
|
|
11
|
+
await _chunkLGFHLAY3cjs.applyScope.call(void 0, (sql, params) => client.query(sql, params), scope, options);
|
|
12
|
+
const result = await fn(client);
|
|
13
|
+
await client.query("COMMIT");
|
|
14
|
+
return result;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
try {
|
|
17
|
+
await client.query("ROLLBACK");
|
|
18
|
+
} catch (e) {
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
} finally {
|
|
22
|
+
client.release();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function withTenant(pool, scope, fn, options) {
|
|
26
|
+
return run(pool, "BEGIN", scope, fn, options);
|
|
27
|
+
}
|
|
28
|
+
function withTenantSnapshot(pool, scope, fn, options) {
|
|
29
|
+
return run(pool, "BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY", scope, fn, options);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
exports.withTenant = withTenant; exports.withTenantSnapshot = withTenantSnapshot;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyScope
|
|
3
|
+
} from "../../chunk-FBNV5X6C.js";
|
|
4
|
+
import "../../chunk-D3DDJWUD.js";
|
|
5
|
+
|
|
6
|
+
// src/tenancy/pg/with-tenant.ts
|
|
7
|
+
async function run(pool, begin, scope, fn, options) {
|
|
8
|
+
const client = await pool.connect();
|
|
9
|
+
try {
|
|
10
|
+
await client.query(begin);
|
|
11
|
+
await applyScope((sql, params) => client.query(sql, params), scope, options);
|
|
12
|
+
const result = await fn(client);
|
|
13
|
+
await client.query("COMMIT");
|
|
14
|
+
return result;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
try {
|
|
17
|
+
await client.query("ROLLBACK");
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
} finally {
|
|
22
|
+
client.release();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function withTenant(pool, scope, fn, options) {
|
|
26
|
+
return run(pool, "BEGIN", scope, fn, options);
|
|
27
|
+
}
|
|
28
|
+
function withTenantSnapshot(pool, scope, fn, options) {
|
|
29
|
+
return run(pool, "BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY", scope, fn, options);
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
withTenant,
|
|
33
|
+
withTenantSnapshot
|
|
34
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ScopeOptions, TenantScope } from '../tenancy.options.js';
|
|
2
|
+
/** Structural `pg` client: nothing is imported from `pg`. */
|
|
3
|
+
export interface PgClientLike {
|
|
4
|
+
query(sql: string, params?: any[]): Promise<unknown>;
|
|
5
|
+
release(error?: Error | boolean): void;
|
|
6
|
+
}
|
|
7
|
+
/** Structural `pg.Pool`. */
|
|
8
|
+
export interface PgPoolLike {
|
|
9
|
+
connect(): Promise<PgClientLike>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `pg` flavour. BEGIN, `set_config(guc, value, true)` for tenant and actor, `fn`, COMMIT / ROLLBACK,
|
|
13
|
+
* and the client is always released. Generalizes `database/postgres#withTenantScope` (which only
|
|
14
|
+
* sets `request.jwt.claim.sub`); that one stays for existing users, this one takes the GUC names.
|
|
15
|
+
* Tenant/actor not given fall back to `TenancyContext`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withTenant<T>(pool: PgPoolLike, scope: TenantScope, fn: (client: PgClientLike) => Promise<T>, options?: ScopeOptions): Promise<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Read-only, ONE snapshot (`REPEATABLE READ`): every query in `fn` sees the database as it was when
|
|
20
|
+
* the first one ran, even with concurrent writes. For reports that split one figure across several
|
|
21
|
+
* queries and must add up.
|
|
22
|
+
*/
|
|
23
|
+
export declare function withTenantSnapshot<T>(pool: PgPoolLike, scope: TenantScope, fn: (client: PgClientLike) => Promise<T>, options?: ScopeOptions): Promise<T>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface Store {
|
|
2
|
+
tenantId?: string;
|
|
3
|
+
actorId?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Per-request tenant/actor, so repositories do not need them in every signature.
|
|
7
|
+
* Same technique as `RequestContext` (tracking) uses for the request id. The middleware opens the
|
|
8
|
+
* store; a resolver or a guard fills it once it knows who is calling. Outside a request (worker,
|
|
9
|
+
* boot) everything reads `undefined`, which with `failClosed` means "pass the tenant explicitly".
|
|
10
|
+
*/
|
|
11
|
+
export declare const TenancyContext: {
|
|
12
|
+
run<T>(fn: () => T, initial?: Store): T;
|
|
13
|
+
setTenant(tenantId: string | undefined): void;
|
|
14
|
+
setActor(actorId: string | undefined): void;
|
|
15
|
+
tenantId(): string | undefined;
|
|
16
|
+
actorId(): string | undefined;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type OnApplicationBootstrap } from '@nestjs/common';
|
|
2
|
+
export declare const RLS_GUARDRAIL_OPTIONS: unique symbol;
|
|
3
|
+
/** Provide something with `query(sql)` returning `{ rows }` (a pg Pool, or a TypeORM DataSource via an adapter). */
|
|
4
|
+
export declare const RLS_GUARDRAIL_DB: unique symbol;
|
|
5
|
+
export interface RlsGuardrailOptions {
|
|
6
|
+
/** `abort` throws at boot (default); `warn` logs loudly. */
|
|
7
|
+
onBypass?: 'abort' | 'warn';
|
|
8
|
+
/** Only enforce `onBypass` when NODE_ENV is production; elsewhere it warns. Default true. */
|
|
9
|
+
productionOnly?: boolean;
|
|
10
|
+
/** Mentioned in the message so whoever reads the log knows what to change. */
|
|
11
|
+
hint?: string;
|
|
12
|
+
/** Environment, for tests. Defaults to `process.env.NODE_ENV`. */
|
|
13
|
+
env?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface RlsDb {
|
|
16
|
+
query(sql: string): Promise<{
|
|
17
|
+
rows: Array<Record<string, unknown>>;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export interface RoleCheck {
|
|
21
|
+
user: string;
|
|
22
|
+
bypassRls: boolean;
|
|
23
|
+
superuser: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Asks Postgres with which role the app connects and whether it skips RLS. */
|
|
26
|
+
export declare function checkAppRole(db: RlsDb): Promise<RoleCheck>;
|
|
27
|
+
/**
|
|
28
|
+
* A role with BYPASSRLS or superuser ignores RLS ALWAYS (even with FORCE) and says nothing: the app
|
|
29
|
+
* keeps "working" while every tenant sees every other tenant's data. Catch it at boot.
|
|
30
|
+
* If the role cannot even be queried, boot is not blocked (it warns).
|
|
31
|
+
*/
|
|
32
|
+
export declare class RlsGuardrail implements OnApplicationBootstrap {
|
|
33
|
+
private readonly db;
|
|
34
|
+
private readonly options;
|
|
35
|
+
private readonly log;
|
|
36
|
+
constructor(db: RlsDb, options?: RlsGuardrailOptions);
|
|
37
|
+
onApplicationBootstrap(): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ScopeOptions, type TenantScope } from './tenancy.options.js';
|
|
2
|
+
/** The only thing the scope needs from a connection: run SQL. Satisfied by pg and TypeORM runners. */
|
|
3
|
+
export type QueryFn = (sql: string, params?: unknown[]) => Promise<unknown>;
|
|
4
|
+
/** Applies the tenant (and actor) GUCs with `set_config(name, value, true)`: transaction-local. */
|
|
5
|
+
export declare function applyScope(query: QueryFn, scope: TenantScope, options?: ScopeOptions): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import { type TenancyOptions } from './tenancy.options.js';
|
|
3
|
+
/** Opens the tenancy store for the request and applies `resolveTenant` / `resolveActor`. */
|
|
4
|
+
export declare class TenancyMiddleware implements NestMiddleware {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(options: TenancyOptions);
|
|
7
|
+
use(req: unknown, _res: unknown, next: () => void): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DynamicModule, type MiddlewareConsumer, type NestModule } from '@nestjs/common';
|
|
2
|
+
import { type RlsDb, type RlsGuardrailOptions } from './rls-guardrail.js';
|
|
3
|
+
import { type TenancyOptions } from './tenancy.options.js';
|
|
4
|
+
export interface TenancyModuleOptions extends TenancyOptions {
|
|
5
|
+
/** Enables the boot-time role check. Needs `db` (anything with `query(sql) => {rows}`). */
|
|
6
|
+
guardrail?: RlsGuardrailOptions & {
|
|
7
|
+
db: RlsDb;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Tenant context + (optional) RLS guardrail.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* TenancyModule.forRoot({
|
|
15
|
+
* gucs: { tenant: 'app.tienda_id', actor: 'app.usuario_id' },
|
|
16
|
+
* failClosed: true,
|
|
17
|
+
* resolveTenant: (req) => req.user?.tiendaId,
|
|
18
|
+
* guardrail: { db: pool, onBypass: 'abort' },
|
|
19
|
+
* })
|
|
20
|
+
* // data access: import { withTenant } from '@miguelmorales13/nestkit/tenancy/pg' (or /typeorm)
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Relation to `database/*`: `database/postgres` and `database/typeorm` keep their
|
|
24
|
+
* `withTenantScope` (hard-wired / free-form GUC map). This module adds the configurable names, the
|
|
25
|
+
* request context, fail-closed and the snapshot; it does not touch them.
|
|
26
|
+
*/
|
|
27
|
+
export declare class TenancyModule implements NestModule {
|
|
28
|
+
private readonly options;
|
|
29
|
+
constructor(options: TenancyOptions);
|
|
30
|
+
configure(consumer: MiddlewareConsumer): void;
|
|
31
|
+
static forRoot(options: TenancyModuleOptions): DynamicModule;
|
|
32
|
+
static forRootAsync(config: {
|
|
33
|
+
imports?: any[];
|
|
34
|
+
inject?: any[];
|
|
35
|
+
useFactory: (...args: any[]) => TenancyModuleOptions | Promise<TenancyModuleOptions>;
|
|
36
|
+
}): DynamicModule;
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const TENANCY_OPTIONS: unique symbol;
|
|
2
|
+
/** Names of the Postgres session variables (GUC) that the RLS policies read. */
|
|
3
|
+
export interface TenancyGucs {
|
|
4
|
+
/** e.g. `app.tienda_id` (Cajón) or `request.jwt.claim.tenant` (Fogón). Must contain a dot. */
|
|
5
|
+
tenant: string;
|
|
6
|
+
/** e.g. `app.usuario_id` or `request.jwt.claim.sub`. Optional: omitted when there is no actor GUC. */
|
|
7
|
+
actor?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface TenancyOptions {
|
|
10
|
+
/** GUC names. They are options, not constants, so existing RLS policies do not change. */
|
|
11
|
+
gucs: TenancyGucs;
|
|
12
|
+
/**
|
|
13
|
+
* When true (default) a scope without tenant throws `TenantRequiredError` instead of running
|
|
14
|
+
* with no tenant set. Without it the RLS would return no rows silently; with it the bug is loud.
|
|
15
|
+
*/
|
|
16
|
+
failClosed?: boolean;
|
|
17
|
+
/** Resolves the tenant at the start of the request (header, subdomain, token…). Optional: a guard can call `TenancyContext.setTenant` later. */
|
|
18
|
+
resolveTenant?: (request: any) => string | undefined;
|
|
19
|
+
/** Same for the actor (user id). */
|
|
20
|
+
resolveActor?: (request: any) => string | undefined;
|
|
21
|
+
/** Mount the context middleware on every route. Defaults to true. */
|
|
22
|
+
middleware?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const DEFAULT_GUCS: TenancyGucs;
|
|
25
|
+
/** Options accepted by the standalone `withTenant` functions. */
|
|
26
|
+
export interface ScopeOptions {
|
|
27
|
+
gucs?: TenancyGucs;
|
|
28
|
+
failClosed?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Who the transaction runs as. Both fall back to the request context when omitted. */
|
|
31
|
+
export interface TenantScope {
|
|
32
|
+
tenantId?: string;
|
|
33
|
+
actorId?: string;
|
|
34
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkLGFHLAY3cjs = require('../../chunk-LGFHLAY3.cjs');
|
|
4
|
+
require('../../chunk-LRX7AMSS.cjs');
|
|
5
|
+
|
|
6
|
+
// src/tenancy/typeorm/with-tenant.ts
|
|
7
|
+
async function run(ds, isolation, scope, fn, options) {
|
|
8
|
+
const runner = ds.createQueryRunner();
|
|
9
|
+
await runner.connect();
|
|
10
|
+
try {
|
|
11
|
+
await runner.startTransaction(isolation);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
await runner.release();
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
if (isolation) await runner.query("SET TRANSACTION READ ONLY");
|
|
18
|
+
await _chunkLGFHLAY3cjs.applyScope.call(void 0, (sql, params) => runner.query(sql, params), scope, options);
|
|
19
|
+
const result = await fn(runner.manager);
|
|
20
|
+
await runner.commitTransaction();
|
|
21
|
+
return result;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
try {
|
|
24
|
+
await runner.rollbackTransaction();
|
|
25
|
+
} catch (e) {
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
} finally {
|
|
29
|
+
await runner.release();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function withTenant(ds, scope, fn, options) {
|
|
33
|
+
return run(ds, void 0, scope, fn, options);
|
|
34
|
+
}
|
|
35
|
+
function withTenantSnapshot(ds, scope, fn, options) {
|
|
36
|
+
return run(ds, "REPEATABLE READ", scope, fn, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
exports.withTenant = withTenant; exports.withTenantSnapshot = withTenantSnapshot;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyScope
|
|
3
|
+
} from "../../chunk-FBNV5X6C.js";
|
|
4
|
+
import "../../chunk-D3DDJWUD.js";
|
|
5
|
+
|
|
6
|
+
// src/tenancy/typeorm/with-tenant.ts
|
|
7
|
+
async function run(ds, isolation, scope, fn, options) {
|
|
8
|
+
const runner = ds.createQueryRunner();
|
|
9
|
+
await runner.connect();
|
|
10
|
+
try {
|
|
11
|
+
await runner.startTransaction(isolation);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
await runner.release();
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
if (isolation) await runner.query("SET TRANSACTION READ ONLY");
|
|
18
|
+
await applyScope((sql, params) => runner.query(sql, params), scope, options);
|
|
19
|
+
const result = await fn(runner.manager);
|
|
20
|
+
await runner.commitTransaction();
|
|
21
|
+
return result;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
try {
|
|
24
|
+
await runner.rollbackTransaction();
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
} finally {
|
|
29
|
+
await runner.release();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function withTenant(ds, scope, fn, options) {
|
|
33
|
+
return run(ds, void 0, scope, fn, options);
|
|
34
|
+
}
|
|
35
|
+
function withTenantSnapshot(ds, scope, fn, options) {
|
|
36
|
+
return run(ds, "REPEATABLE READ", scope, fn, options);
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
withTenant,
|
|
40
|
+
withTenantSnapshot
|
|
41
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ScopeOptions, TenantScope } from '../tenancy.options.js';
|
|
2
|
+
/** Structural `EntityManager`: the caller gets their real one back through the generic. */
|
|
3
|
+
export interface QueryRunnerLike<M = any> {
|
|
4
|
+
manager: M;
|
|
5
|
+
connect(): Promise<unknown>;
|
|
6
|
+
startTransaction(isolationLevel?: string): Promise<void>;
|
|
7
|
+
commitTransaction(): Promise<void>;
|
|
8
|
+
rollbackTransaction(): Promise<void>;
|
|
9
|
+
release(): Promise<void>;
|
|
10
|
+
query(sql: string, params?: any[]): Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
/** Structural `DataSource`. */
|
|
13
|
+
export interface DataSourceLike<M = any> {
|
|
14
|
+
createQueryRunner(): QueryRunnerLike<M>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* TypeORM flavour. Same contract as `database/typeorm#withTenantScope` but takes `{tenantId,
|
|
18
|
+
* actorId}` + GUC names instead of a free-form map, and fails closed without a tenant. The manager
|
|
19
|
+
* handed to `fn` is bound to that one connection/transaction: never leak it past the callback.
|
|
20
|
+
*/
|
|
21
|
+
export declare function withTenant<T, M = any>(ds: DataSourceLike<M>, scope: TenantScope, fn: (manager: M) => Promise<T>, options?: ScopeOptions): Promise<T>;
|
|
22
|
+
/** Read-only `REPEATABLE READ` snapshot (see the `pg` flavour). */
|
|
23
|
+
export declare function withTenantSnapshot<T, M = any>(ds: DataSourceLike<M>, scope: TenantScope, fn: (manager: M) => Promise<T>, options?: ScopeOptions): Promise<T>;
|
package/dist/tiktok/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
4
4
|
|
|
5
5
|
// src/tiktok/tiktok.service.ts
|
|
6
6
|
var _common = require('@nestjs/common');
|
|
@@ -126,7 +126,7 @@ var TikTokService = class {
|
|
|
126
126
|
return json.data;
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
|
-
TikTokService = exports.TikTokService =
|
|
129
|
+
TikTokService = exports.TikTokService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
130
130
|
_common.Injectable.call(void 0, )
|
|
131
131
|
], TikTokService);
|
|
132
132
|
|
|
@@ -156,7 +156,7 @@ var TikTokModule = class {
|
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
|
-
TikTokModule = exports.TikTokModule =
|
|
159
|
+
TikTokModule = exports.TikTokModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
160
160
|
_common.Module.call(void 0, {})
|
|
161
161
|
], TikTokModule);
|
|
162
162
|
|
package/dist/tiktok/index.js
CHANGED
package/dist/tracking/index.cjs
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkKNU5RN3Ocjs = require('../chunk-KNU5RN3O.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
var _chunkSDWHKPXIcjs = require('../chunk-SDWHKPXI.cjs');
|
|
9
|
-
require('../chunk-
|
|
9
|
+
require('../chunk-LRX7AMSS.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
exports.REQUEST_ID_HEADER =
|
|
15
|
+
exports.REQUEST_ID_HEADER = _chunkKNU5RN3Ocjs.REQUEST_ID_HEADER; exports.RequestContext = _chunkSDWHKPXIcjs.RequestContext; exports.RequestIdMiddleware = _chunkKNU5RN3Ocjs.RequestIdMiddleware; exports.TrackingModule = _chunkKNU5RN3Ocjs.TrackingModule;
|
package/dist/tracking/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
REQUEST_ID_HEADER,
|
|
3
3
|
RequestIdMiddleware,
|
|
4
4
|
TrackingModule
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-MUWHGBIB.js";
|
|
6
6
|
import {
|
|
7
7
|
RequestContext
|
|
8
8
|
} from "../chunk-ETRUVZTJ.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-D3DDJWUD.js";
|
|
10
10
|
export {
|
|
11
11
|
REQUEST_ID_HEADER,
|
|
12
12
|
RequestContext,
|
package/dist/umami/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
5
5
|
|
|
6
6
|
// src/umami/umami.module.ts
|
|
7
7
|
var _common = require('@nestjs/common');
|
|
@@ -81,9 +81,9 @@ var UmamiService = class {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
|
-
UmamiService = exports.UmamiService =
|
|
84
|
+
UmamiService = exports.UmamiService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
85
85
|
_common.Injectable.call(void 0, ),
|
|
86
|
-
|
|
86
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, UMAMI_OPTIONS))
|
|
87
87
|
], UmamiService);
|
|
88
88
|
|
|
89
89
|
// src/umami/umami.module.ts
|
|
@@ -99,7 +99,7 @@ var UmamiModule = class {
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
|
-
UmamiModule = exports.UmamiModule =
|
|
102
|
+
UmamiModule = exports.UmamiModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
103
103
|
_common.Module.call(void 0, {})
|
|
104
104
|
], UmamiModule);
|
|
105
105
|
|