@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,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;
|
package/dist/security/index.cjs
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (typeof ts !== "number" || !Number.isFinite(ts) || Date.now() - ts >= ttl) return null;
|
|
29
|
-
const { ts: _ts, nonce: _nonce, ...rest } = parsed;
|
|
30
|
-
return rest;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
exports.readState = readState; exports.signState = signState;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunk33KFVAUZcjs = require('../chunk-33KFVAUZ.cjs');
|
|
14
|
+
require('../chunk-LRX7AMSS.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.constantTimeEqual = _chunk33KFVAUZcjs.constantTimeEqual; exports.hashSha256 = _chunk33KFVAUZcjs.hashSha256; exports.maskEmail = _chunk33KFVAUZcjs.maskEmail; exports.maskFields = _chunk33KFVAUZcjs.maskFields; exports.maskPhone = _chunk33KFVAUZcjs.maskPhone; exports.maskToken = _chunk33KFVAUZcjs.maskToken; exports.readState = _chunk33KFVAUZcjs.readState; exports.shapeOf = _chunk33KFVAUZcjs.shapeOf; exports.signGrant = _chunk33KFVAUZcjs.signGrant; exports.signState = _chunk33KFVAUZcjs.signState; exports.verifyGrant = _chunk33KFVAUZcjs.verifyGrant;
|
package/dist/security/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/security/index.js
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const [b64, sig] = parts;
|
|
16
|
-
const expected = createHmac("sha256", options.secret).update(b64).digest("base64url");
|
|
17
|
-
const provided = Buffer.from(sig);
|
|
18
|
-
const wanted = Buffer.from(expected);
|
|
19
|
-
if (provided.length !== wanted.length || !timingSafeEqual(provided, wanted)) return null;
|
|
20
|
-
let parsed;
|
|
21
|
-
try {
|
|
22
|
-
parsed = JSON.parse(Buffer.from(b64, "base64url").toString());
|
|
23
|
-
} catch {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
const ts = parsed.ts;
|
|
27
|
-
const ttl = options.ttlMs ?? 10 * 6e4;
|
|
28
|
-
if (typeof ts !== "number" || !Number.isFinite(ts) || Date.now() - ts >= ttl) return null;
|
|
29
|
-
const { ts: _ts, nonce: _nonce, ...rest } = parsed;
|
|
30
|
-
return rest;
|
|
31
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
constantTimeEqual,
|
|
3
|
+
hashSha256,
|
|
4
|
+
maskEmail,
|
|
5
|
+
maskFields,
|
|
6
|
+
maskPhone,
|
|
7
|
+
maskToken,
|
|
8
|
+
readState,
|
|
9
|
+
shapeOf,
|
|
10
|
+
signGrant,
|
|
11
|
+
signState,
|
|
12
|
+
verifyGrant
|
|
13
|
+
} from "../chunk-LU3HO7B3.js";
|
|
14
|
+
import "../chunk-D3DDJWUD.js";
|
|
32
15
|
export {
|
|
16
|
+
constantTimeEqual,
|
|
17
|
+
hashSha256,
|
|
18
|
+
maskEmail,
|
|
19
|
+
maskFields,
|
|
20
|
+
maskPhone,
|
|
21
|
+
maskToken,
|
|
33
22
|
readState,
|
|
34
|
-
|
|
23
|
+
shapeOf,
|
|
24
|
+
signGrant,
|
|
25
|
+
signState,
|
|
26
|
+
verifyGrant
|
|
35
27
|
};
|
|
@@ -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;
|
package/dist/storage/index.cjs
CHANGED
|
@@ -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
|
|
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 =
|
|
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);
|
package/dist/storage/index.js
CHANGED
package/dist/stripe/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ require('../chunk-PNK5WMPP.cjs');
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
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 =
|
|
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
|
-
|
|
64
|
+
_chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
65
65
|
_common.Post.call(void 0, ),
|
|
66
|
-
|
|
67
|
-
|
|
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 =
|
|
69
|
+
StripeWebhookControllerHost = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
70
70
|
_common.Controller.call(void 0, _nullishCoalesce(options.path, () => ( "stripe/webhook"))),
|
|
71
|
-
|
|
71
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, STRIPE_CLIENT))
|
|
72
72
|
], StripeWebhookControllerHost);
|
|
73
73
|
return StripeWebhookControllerHost;
|
|
74
74
|
}
|
package/dist/stripe/index.js
CHANGED
package/dist/telegram/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
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 =
|
|
11
|
+
TelegramModule = exports.TelegramModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
12
12
|
_common.Module.call(void 0, {
|
|
13
13
|
providers: [
|
|
14
14
|
{
|
package/dist/telegram/index.js
CHANGED
|
@@ -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[];
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkLGFHLAY3cjs = require('../chunk-LGFHLAY3.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
12
|
+
|
|
13
|
+
// src/tenancy/tenancy.module.ts
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _common = require('@nestjs/common');
|
|
19
|
+
|
|
20
|
+
// src/tenancy/rls-guardrail.ts
|
|
21
|
+
|
|
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 = _nullishCoalesce(rows[0], () => ( {}));
|
|
31
|
+
return {
|
|
32
|
+
user: String(_nullishCoalesce(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 (0, _common.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 = _nullishCoalesce(this.options.env, () => ( process.env.NODE_ENV));
|
|
57
|
+
const enforce = !(_nullishCoalesce(this.options.productionOnly, () => ( true))) || env === "production";
|
|
58
|
+
if (enforce && (_nullishCoalesce(this.options.onBypass, () => ( "abort"))) === "abort") {
|
|
59
|
+
throw new Error(`BOOT ABORTED - ${message}`);
|
|
60
|
+
}
|
|
61
|
+
this.log.error(message);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
RlsGuardrail = exports.RlsGuardrail = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
65
|
+
_common.Injectable.call(void 0, ),
|
|
66
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, RLS_GUARDRAIL_DB)),
|
|
67
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, RLS_GUARDRAIL_OPTIONS))
|
|
68
|
+
], RlsGuardrail);
|
|
69
|
+
|
|
70
|
+
// src/tenancy/tenancy.middleware.ts
|
|
71
|
+
|
|
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 = _optionalChain([this, 'access', _ => _.options, 'access', _2 => _2.resolveTenant, 'optionalCall', _3 => _3(req)]);
|
|
81
|
+
actorId = _optionalChain([this, 'access', _4 => _4.options, 'access', _5 => _5.resolveActor, 'optionalCall', _6 => _6(req)]);
|
|
82
|
+
} catch (e2) {
|
|
83
|
+
}
|
|
84
|
+
_chunkLGFHLAY3cjs.TenancyContext.run(() => next(), { tenantId, actorId });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
TenancyMiddleware = exports.TenancyMiddleware = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
88
|
+
_common.Injectable.call(void 0, ),
|
|
89
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, _chunkLGFHLAY3cjs.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: _chunkLGFHLAY3cjs.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: [_chunkLGFHLAY3cjs.TENANCY_OPTIONS] };
|
|
115
|
+
}
|
|
116
|
+
static forRootAsync(config) {
|
|
117
|
+
const raw = { provide: "TENANCY_RAW", useFactory: config.useFactory, inject: _nullishCoalesce(config.inject, () => ( [])) };
|
|
118
|
+
const list = [
|
|
119
|
+
raw,
|
|
120
|
+
{ provide: _chunkLGFHLAY3cjs.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) => _optionalChain([o, 'access', _7 => _7.guardrail, 'optionalAccess', _8 => _8.db]), inject: ["TENANCY_RAW"] },
|
|
126
|
+
{
|
|
127
|
+
provide: RLS_GUARDRAIL_OPTIONS,
|
|
128
|
+
useFactory: (o) => {
|
|
129
|
+
const { db: _d, ...rest } = _nullishCoalesce(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: _nullishCoalesce(config.imports, () => ( [])), providers: list, exports: [_chunkLGFHLAY3cjs.TENANCY_OPTIONS] };
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
TenancyModule = exports.TenancyModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
145
|
+
_common.Global.call(void 0, ),
|
|
146
|
+
_common.Module.call(void 0, {}),
|
|
147
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, _chunkLGFHLAY3cjs.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 = _nullishCoalesce(_optionalChain([e, 'optionalAccess', _9 => _9.code]), () => ( _optionalChain([e, 'optionalAccess', _10 => _10.driverError, 'optionalAccess', _11 => _11.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
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
exports.DEFAULT_GUCS = _chunkLGFHLAY3cjs.DEFAULT_GUCS; exports.RLS_GUARDRAIL_DB = RLS_GUARDRAIL_DB; exports.RLS_GUARDRAIL_OPTIONS = RLS_GUARDRAIL_OPTIONS; exports.RlsGuardrail = RlsGuardrail; exports.TENANCY_OPTIONS = _chunkLGFHLAY3cjs.TENANCY_OPTIONS; exports.TenancyContext = _chunkLGFHLAY3cjs.TenancyContext; exports.TenancyMiddleware = TenancyMiddleware; exports.TenancyModule = TenancyModule; exports.TenantRequiredError = _chunkLGFHLAY3cjs.TenantRequiredError; exports.applyScope = _chunkLGFHLAY3cjs.applyScope; exports.checkAppRole = checkAppRole; exports.ensureAppRole = ensureAppRole; exports.pgSqlState = pgSqlState; exports.updatedRows = updatedRows;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { TenancyModule } from './tenancy.module.js';
|
|
2
|
+
export type { TenancyModuleOptions } from './tenancy.module.js';
|
|
3
|
+
export { TENANCY_OPTIONS, DEFAULT_GUCS } from './tenancy.options.js';
|
|
4
|
+
export type { TenancyOptions, TenancyGucs, ScopeOptions, TenantScope } from './tenancy.options.js';
|
|
5
|
+
export { TenancyContext } from './request-context.js';
|
|
6
|
+
export { TenancyMiddleware } from './tenancy.middleware.js';
|
|
7
|
+
export { TenantRequiredError } from './tenancy.errors.js';
|
|
8
|
+
export { applyScope } from './scope.js';
|
|
9
|
+
export type { QueryFn } from './scope.js';
|
|
10
|
+
export { RlsGuardrail, checkAppRole, RLS_GUARDRAIL_DB, RLS_GUARDRAIL_OPTIONS } from './rls-guardrail.js';
|
|
11
|
+
export type { RlsGuardrailOptions, RlsDb, RoleCheck } from './rls-guardrail.js';
|
|
12
|
+
export { ensureAppRole } from './app-role.js';
|
|
13
|
+
export type { EnsureAppRoleOptions, AdminLike } from './app-role.js';
|
|
14
|
+
export { pgSqlState, updatedRows } from './db-helpers.js';
|