@ddd-ts-kit/audit 0.7.0 → 0.9.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 CHANGED
@@ -179,6 +179,23 @@ When the decision concerns another actor than the one of the execution context (
179
179
  sending a command on behalf of a user), the entry names the actor of the decision with type
180
180
  `unknown`: its type and tenant are not in what the hook receives.
181
181
 
182
+ ### a'. Refusals at the edge
183
+
184
+ A request a guard refuses (`HasRole`, `HasScope`, `TenantMember`, a tenant the caller does not
185
+ belong to) never reaches a use case, so the authorization middleware does not see it. The HTTP
186
+ pipeline reports it to `onGuardRefusal`, and `auditGuardRefusals(trail, { clock, ids })` records
187
+ it: category `authorization`, action `http:<operationId>`, outcome `denied`, the code of the
188
+ refusal as `reason` (`FORBIDDEN`, `UNAUTHORIZED`), and the actor, session, tenant and correlation
189
+ of the request. A caller without a credential is not recorded: it is no one to hold to account,
190
+ the tenant it addressed is its own choice, and recording it would let unauthenticated traffic
191
+ write to the trail (and open hash chains) without bound; those refusals belong to the access log
192
+ and to rate limiting. A recorded refusal is in the tenant of the caller's credential. A guard
193
+ that fails instead of refusing (a lookup that threw, not a `DomainError`) is not reported.
194
+
195
+ ```ts
196
+ mountExpress(app, routes, { ...boundary, onGuardRefusal: auditGuardRefusals(trail, { clock, ids }) });
197
+ ```
198
+
182
199
  ### b. Commands, and the unit of work
183
200
 
184
201
  `auditMiddleware` records each command with outcome `succeeded` or `failed`, and the `code` of
@@ -535,6 +552,12 @@ kernel, which `application/` may import, and receives the store bound to it. It
535
552
  filter to the tenant of the actor (an access scope computed by the authorizer), so one tenant
536
553
  never lists another's entries.
537
554
 
555
+ In a multi-tenant project, bind `new TenantAuditReader(store, executionScope)` to
556
+ `AuditReader` instead of the store itself: every search is then confined to the tenant of the
557
+ work whatever its filter says (a filter naming another tenant or another chain finds nothing),
558
+ platform staff read across tenants only under an elevation (`acrossTenants` of the kernel, itself
559
+ recorded), and work that names neither is refused (`NoCurrentTenantError`).
560
+
538
561
  ## Limits
539
562
 
540
563
  - **PostgreSQL only** for the SQL stores: row locks, row comparison for cursors, `jsonb`,
package/dist/index.d.ts CHANGED
@@ -25,6 +25,8 @@ export type { MaskingSubject } from './redaction/masking-subject.js';
25
25
  export { MissingMaskerError } from './redaction/missing-masker-error.js';
26
26
  export type { AllowedReads } from './sources/allowed-reads.js';
27
27
  export { auditDecisions, type AuditDecisionsOptions } from './sources/audit-decisions.js';
28
+ export { auditGuardRefusals } from './sources/audit-guard-refusals.js';
29
+ export type { GuardRefusalOfARoute } from './sources/guard-refusal-of-a-route.js';
28
30
  export type { AuditFact } from './sources/audit-fact.js';
29
31
  export { auditIntegrationEvents, type AuditIntegrationEventsOptions } from './sources/audit-integration-events.js';
30
32
  export { UNEXPECTED_ERROR, auditMiddleware, type AuditMiddlewareOptions } from './sources/audit-middleware.js';
@@ -33,4 +35,5 @@ export type { AuditSource } from './sources/audit-source.js';
33
35
  export type { AuditSubscription } from './sources/audit-subscription.js';
34
36
  export type { AuditedEvents } from './sources/audited-events.js';
35
37
  export type { AuthorizationDecision } from './sources/authorization-decision.js';
38
+ export { TenantAuditReader } from './tenancy/tenant-audit-reader.js';
36
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EACV,UAAU,EACV,aAAa,EACb,WAAW,EACX,YAAY,EACZ,UAAU,EACV,yBAAyB,EACzB,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,EACd,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,O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,EAAE,MAAM,uCAAuC,CAAC;AACnH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC/G,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,YAAY,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACzE,YAAY,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,YAAY,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC"}
package/dist/index.js CHANGED
@@ -12,7 +12,9 @@ export { hmacMasker } from './redaction/hmac-masker.js';
12
12
  export { masked } from './redaction/masked.js';
13
13
  export { MissingMaskerError } from './redaction/missing-masker-error.js';
14
14
  export { auditDecisions } from './sources/audit-decisions.js';
15
+ export { auditGuardRefusals } from './sources/audit-guard-refusals.js';
15
16
  export { auditIntegrationEvents } from './sources/audit-integration-events.js';
16
17
  export { UNEXPECTED_ERROR, auditMiddleware } from './sources/audit-middleware.js';
17
18
  export { auditRecordOf } from './sources/audit-record-of.js';
19
+ export { TenantAuditReader } from './tenancy/tenant-audit-reader.js';
18
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAmB7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AAGhE,OAAO,EAAE,kB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AACtE,OAAO,EAAE,UAAU,EAA0B,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EAAE,cAAc,EAA8B,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAGvE,OAAO,EAAE,sBAAsB,EAAsC,MAAM,uCAAuC,CAAC;AACnH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAA+B,MAAM,+BAA+B,CAAC;AAC/G,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAK7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type AuditTrail } from '@ddd-ts-kit/kernel';
2
+ import type { AuditSource } from './audit-source.js';
3
+ import type { GuardRefusalOfARoute } from './guard-refusal-of-a-route.js';
4
+ /**
5
+ * The `onGuardRefusal` hook of the HTTP pipeline: a request a guard refused at the edge
6
+ * (`HasRole`, `HasScope`, `TenantMember`, a tenant the caller does not belong to) is a denied
7
+ * authorization decision like one of the use cases, recorded with action `http:<operationId>`,
8
+ * the code of the refusal as reason, and who, in which session and tenant, from the request.
9
+ *
10
+ * A caller that presented no credential is not recorded: it is no one to hold to account, its
11
+ * tenant is whatever it addressed, and recording it would let unauthenticated traffic write to
12
+ * the trail without bound. Those refusals belong to the access log and to rate limiting. A
13
+ * recorded refusal is in the tenant of the credential of the caller, never in the one it asked.
14
+ */
15
+ export declare function auditGuardRefusals(trail: AuditTrail, source: Omit<AuditSource, 'scope'>): (refusal: GuardRefusalOfARoute) => Promise<void>;
16
+ //# sourceMappingURL=audit-guard-refusals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-guard-refusals.d.ts","sourceRoot":"","sources":["../../src/sources/audit-guard-refusals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAG1E;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,GACjC,CAAC,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAelD"}
@@ -0,0 +1,27 @@
1
+ import { isAnonymous } from '@ddd-ts-kit/kernel';
2
+ import { recordIn } from './record-in.js';
3
+ /**
4
+ * The `onGuardRefusal` hook of the HTTP pipeline: a request a guard refused at the edge
5
+ * (`HasRole`, `HasScope`, `TenantMember`, a tenant the caller does not belong to) is a denied
6
+ * authorization decision like one of the use cases, recorded with action `http:<operationId>`,
7
+ * the code of the refusal as reason, and who, in which session and tenant, from the request.
8
+ *
9
+ * A caller that presented no credential is not recorded: it is no one to hold to account, its
10
+ * tenant is whatever it addressed, and recording it would let unauthenticated traffic write to
11
+ * the trail without bound. Those refusals belong to the access log and to rate limiting. A
12
+ * recorded refusal is in the tenant of the credential of the caller, never in the one it asked.
13
+ */
14
+ export function auditGuardRefusals(trail, source) {
15
+ return async (refusal) => {
16
+ if (isAnonymous(refusal.execution.actor)) {
17
+ return;
18
+ }
19
+ await trail.record(recordIn(refusal.execution, source, {
20
+ category: 'authorization',
21
+ action: `http:${refusal.operationId}`,
22
+ outcome: 'denied',
23
+ reason: refusal.problem.code ?? (refusal.problem.status === 401 ? 'UNAUTHORIZED' : 'FORBIDDEN'),
24
+ }));
25
+ };
26
+ }
27
+ //# sourceMappingURL=audit-guard-refusals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-guard-refusals.js","sourceRoot":"","sources":["../../src/sources/audit-guard-refusals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmB,MAAM,oBAAoB,CAAC;AAGlE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAiB,EACjB,MAAkC;IAElC,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,IAAI,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,OAAO;QACT,CAAC;QAED,MAAM,KAAK,CAAC,MAAM,CAChB,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE;YAClC,QAAQ,EAAE,eAAe;YACzB,MAAM,EAAE,QAAQ,OAAO,CAAC,WAAW,EAAE;YACrC,OAAO,EAAE,QAAQ;YACjB,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,WAAW,CAAC;SAChG,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ExecutionContext } from '@ddd-ts-kit/kernel';
2
+ /**
3
+ * What the `onGuardRefusal` hook of `@ddd-ts-kit/http` hands over, restated structurally so that
4
+ * this package does not depend on it. Any `GuardRefusal` fits.
5
+ */
6
+ export interface GuardRefusalOfARoute {
7
+ readonly operationId: string;
8
+ readonly problem: {
9
+ readonly code?: string;
10
+ readonly status: number;
11
+ };
12
+ readonly execution: ExecutionContext;
13
+ }
14
+ //# sourceMappingURL=guard-refusal-of-a-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard-refusal-of-a-route.d.ts","sourceRoot":"","sources":["../../src/sources/guard-refusal-of-a-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;CACtC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=guard-refusal-of-a-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard-refusal-of-a-route.js","sourceRoot":"","sources":["../../src/sources/guard-refusal-of-a-route.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { type AuditEntry, type AuditFilter, type AuditReader, type AuditSortField, type ExecutionScope, type Page, type PageRequest } from '@ddd-ts-kit/kernel';
2
+ /**
3
+ * The trail as a tenant may read it: every search is confined to the tenant of the work in
4
+ * progress, whatever the filter says, and a filter that names another tenant or another chain
5
+ * finds nothing. Platform staff read across tenants under an elevation (`acrossTenants`): over
6
+ * `all`, the filter as it is; over a list, a search names one tenant of the list. Work that names
7
+ * no tenant and no elevation is refused (`NoCurrentTenantError`).
8
+ */
9
+ export declare class TenantAuditReader implements AuditReader {
10
+ private readonly reader;
11
+ private readonly scope;
12
+ constructor(reader: AuditReader, scope: ExecutionScope);
13
+ search(filter: AuditFilter, page: PageRequest<AuditSortField>): Promise<Page<AuditEntry>>;
14
+ /** The filter within the reach of the work, or `undefined` when it can only find another tenant's entries. */
15
+ private confined;
16
+ }
17
+ //# sourceMappingURL=tenant-audit-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-audit-reader.d.ts","sourceRoot":"","sources":["../../src/tenancy/tenant-audit-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,IAAI,EACT,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,qBAAa,iBAAkB,YAAW,WAAW;IAEjD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFxB,YACmB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,cAAc,EACpC;IAEE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAI9F;IAED,8GAA8G;IAC9G,OAAO,CAAC,QAAQ;CAejB"}
@@ -0,0 +1,35 @@
1
+ import { pageOf, tenantReachOf, } from '@ddd-ts-kit/kernel';
2
+ /**
3
+ * The trail as a tenant may read it: every search is confined to the tenant of the work in
4
+ * progress, whatever the filter says, and a filter that names another tenant or another chain
5
+ * finds nothing. Platform staff read across tenants under an elevation (`acrossTenants`): over
6
+ * `all`, the filter as it is; over a list, a search names one tenant of the list. Work that names
7
+ * no tenant and no elevation is refused (`NoCurrentTenantError`).
8
+ */
9
+ export class TenantAuditReader {
10
+ reader;
11
+ scope;
12
+ constructor(reader, scope) {
13
+ this.reader = reader;
14
+ this.scope = scope;
15
+ }
16
+ async search(filter, page) {
17
+ const confined = this.confined(filter);
18
+ return confined === undefined ? pageOf([], { total: 0 }) : this.reader.search(confined, page);
19
+ }
20
+ /** The filter within the reach of the work, or `undefined` when it can only find another tenant's entries. */
21
+ confined(filter) {
22
+ const reach = tenantReachOf(this.scope);
23
+ if (reach.kind === 'elevated') {
24
+ return reach.tenants === 'all' || reachesListed(filter, reach.tenants) ? filter : undefined;
25
+ }
26
+ const { tenantId } = reach;
27
+ const elsewhere = (filter.tenantId !== undefined && filter.tenantId !== tenantId) ||
28
+ (filter.chain !== undefined && filter.chain !== `tenant:${tenantId}`);
29
+ return elsewhere ? undefined : { ...filter, tenantId };
30
+ }
31
+ }
32
+ function reachesListed(filter, tenants) {
33
+ return filter.tenantId !== undefined && tenants.includes(filter.tenantId);
34
+ }
35
+ //# sourceMappingURL=tenant-audit-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-audit-reader.js","sourceRoot":"","sources":["../../src/tenancy/tenant-audit-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,aAAa,GAQd,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAET,MAAM;IACN,KAAK;IAFxB,YACmB,MAAmB,EACnB,KAAqB;sBADrB,MAAM;qBACN,KAAK;IACrB,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,MAAmB,EAAE,IAAiC;QACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAEvC,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAa,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC5G,CAAC;IAED,8GAA8G;IACtG,QAAQ,CAAC,MAAmB;QAClC,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAExC,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC,OAAO,KAAK,KAAK,IAAI,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9F,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;QAE3B,MAAM,SAAS,GACb,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC;YAC/D,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,KAAK,UAAU,QAAQ,EAAE,CAAC,CAAC;QAExE,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,CAAC;IACzD,CAAC;CACF;AAED,SAAS,aAAa,CAAC,MAAmB,EAAE,OAA0B;IACpE,OAAO,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC5E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts-kit/audit",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Tamper-evident audit trail fed from outside the use cases: authorization decisions, executed commands and integration events, as hash-chained append-only entries.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,12 +38,12 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "@ddd-ts-kit/kernel": "0.7.0"
41
+ "@ddd-ts-kit/kernel": "0.9.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "knex": "^3.0.0",
45
45
  "drizzle-orm": ">=0.40.0",
46
- "@ddd-ts-kit/testing": "0.7.0"
46
+ "@ddd-ts-kit/testing": "0.9.0"
47
47
  },
48
48
  "peerDependenciesMeta": {
49
49
  "knex": {
@@ -63,10 +63,10 @@
63
63
  "@types/pg": "^8.23.1",
64
64
  "@electric-sql/pglite": "0.5.9",
65
65
  "@electric-sql/pglite-socket": "0.2.12",
66
- "@ddd-ts-kit/auth": "0.7.0",
67
- "@ddd-ts-kit/events": "0.7.0",
68
- "@ddd-ts-kit/knex": "0.7.0",
69
- "@ddd-ts-kit/drizzle": "0.7.0",
70
- "@ddd-ts-kit/testing": "0.7.0"
66
+ "@ddd-ts-kit/auth": "0.9.0",
67
+ "@ddd-ts-kit/events": "0.9.0",
68
+ "@ddd-ts-kit/knex": "0.9.0",
69
+ "@ddd-ts-kit/drizzle": "0.9.0",
70
+ "@ddd-ts-kit/testing": "0.9.0"
71
71
  }
72
72
  }