@classytic/supplier-performance 0.1.1 → 0.2.1
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/CHANGELOG.md +72 -0
- package/README.md +37 -5
- package/dist/event-catalog.js +170 -0
- package/dist/events.d.ts +2 -0
- package/dist/events.js +2 -0
- package/dist/in-process-bus.d.ts +163 -0
- package/dist/index.d.ts +80 -111
- package/dist/index.js +115 -205
- package/package.json +15 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
Patch — outbox support, §P8.1 session guard, awaited publish, tenant-isolation fix.
|
|
6
|
+
|
|
7
|
+
## 0.2.0
|
|
8
|
+
|
|
9
|
+
Stack upgrade + tenant-isolation fix + PACKAGE_RULES compliance + real test
|
|
10
|
+
coverage. No new features.
|
|
11
|
+
|
|
12
|
+
### Fixed (security)
|
|
13
|
+
|
|
14
|
+
- **Cross-tenant leak — `multiTenantPlugin` was never wired.** Both
|
|
15
|
+
repositories were constructed with only `methodRegistryPlugin()`, so reads
|
|
16
|
+
and writes were NOT tenant-scoped despite the schema carrying an
|
|
17
|
+
`organizationId` field. The engine now derives one resolved tenant config
|
|
18
|
+
(via repo-core's `resolveTenantConfig`) and wires `multiTenantPlugin` on
|
|
19
|
+
every repo — scoping is enforced at POLICY priority and missing
|
|
20
|
+
`organizationId` throws (fail-closed). A `tenant-plugin-probe` integration
|
|
21
|
+
test plus an end-to-end isolation test guard this.
|
|
22
|
+
|
|
23
|
+
### Changed (breaking)
|
|
24
|
+
|
|
25
|
+
- **Peers:** `@classytic/mongokit` `>=3.13.0` → `>=3.16.0`; **added**
|
|
26
|
+
`@classytic/repo-core >=0.6.0` (rule 11 — the code imports
|
|
27
|
+
`@classytic/repo-core/tenant` and `/errors`); **added** `zod >=4.0.0`
|
|
28
|
+
(event catalog). `@classytic/primitives` stays `>=0.5.0` (devDep bumped to
|
|
29
|
+
`^0.7.2`).
|
|
30
|
+
- **Tenant config clean break.** Dropped the legacy
|
|
31
|
+
`{ tenantFieldType, multiTenant }` shape and the `'string'` default. Tenant
|
|
32
|
+
config is now a repo-core `TenantConfig` (or boolean), defaulting to
|
|
33
|
+
repo-core's standard `fieldType: 'objectId'`, `required: true`. Hosts with
|
|
34
|
+
string/UUID org ids pass `{ fieldType: 'string' }`. Mongokit-runtime knobs
|
|
35
|
+
(`skipWhen`, `resolveContext`, `allowDataInjection`, `onMismatch`,
|
|
36
|
+
`skipOperations`) forward through the `tenant` object.
|
|
37
|
+
- **Errors.** Removed `RecordEventValidationError extends Error`. Validation now
|
|
38
|
+
throws `SupplierPerformanceValidationError implements HttpError` (status 400,
|
|
39
|
+
code `supplier_performance.validation.invalid_input`) so arc serializes it
|
|
40
|
+
correctly.
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- **Zod event catalog (rule 18):** `supplierPerformanceEventDefinitions`
|
|
45
|
+
exported from the package root AND the new `./events` subpath; per-event Zod
|
|
46
|
+
schemas (`z.iso.datetime()` timestamps), a no-drift invariant test, and
|
|
47
|
+
safeParse happy/rejection tests.
|
|
48
|
+
- **Cancellation / retry threading:** `SupplierPerformanceContext` now carries
|
|
49
|
+
`signal` / `retryPolicy`, forwarded to repo calls via `repoOptionsFromCtx`.
|
|
50
|
+
- **Test coverage** raised from one unit file to five files / 21 tests:
|
|
51
|
+
event-catalog no-drift, tenant probe + isolation, computeScore aggregation +
|
|
52
|
+
idempotency (re-run does not double-aggregate, exactly one snapshot row),
|
|
53
|
+
model-collision policy.
|
|
54
|
+
|
|
55
|
+
### Build hygiene
|
|
56
|
+
|
|
57
|
+
- `tsconfig.json`: enabled `exactOptionalPropertyTypes`; disabled
|
|
58
|
+
`declarationMap` and `sourceMap` (no source leaks). `InProcessSupplierPerformanceBus`
|
|
59
|
+
gained `close()`. `CHANGELOG.md` added to published `files`.
|
|
60
|
+
|
|
61
|
+
### Notes (verified, intentionally NOT changed)
|
|
62
|
+
|
|
63
|
+
- **No outbox / P8 dispatch machinery.** Durable delivery is host-composed
|
|
64
|
+
(§5.5 / §16); only a transport is wired, so publish failures are swallowed
|
|
65
|
+
(rule 14). Not a gap.
|
|
66
|
+
- **No capabilities boot gate.** The package uses no transactions — every verb
|
|
67
|
+
is a single-doc read/write/upsert — so the gate (transactions-only) does not
|
|
68
|
+
apply.
|
|
69
|
+
- **No rating-state CAS.** Scorecards are recomputable snapshots, not a state
|
|
70
|
+
machine; `computeScore` idempotency rests on the unique index + upsert.
|
|
71
|
+
- **`recordEvent` dedup stays host-owned** by design (hosts key differently:
|
|
72
|
+
PO-line vs PO+SKU). The kernel does not enforce a metric-dedup unique index.
|
package/README.md
CHANGED
|
@@ -27,9 +27,11 @@ Peer deps:
|
|
|
27
27
|
|
|
28
28
|
| | |
|
|
29
29
|
|---|---|
|
|
30
|
-
| `@classytic/mongokit` | `>=3.
|
|
31
|
-
| `@classytic/
|
|
30
|
+
| `@classytic/mongokit` | `>=3.16.0` |
|
|
31
|
+
| `@classytic/repo-core` | `>=0.6.0` |
|
|
32
|
+
| `@classytic/primitives` | `>=0.5.0` |
|
|
32
33
|
| `mongoose` | `>=9.4.1` |
|
|
34
|
+
| `zod` | `>=4.0.0` |
|
|
33
35
|
|
|
34
36
|
## Quick start
|
|
35
37
|
|
|
@@ -140,17 +142,43 @@ supplier_performance:score.computed
|
|
|
140
142
|
|
|
141
143
|
Use any `EventTransport`-shaped bus (Arc's MemoryEventTransport, Redis, Kafka, …). The bundled `InProcessSupplierPerformanceBus` is a zero-dep default.
|
|
142
144
|
|
|
145
|
+
A Zod event catalog ships at the `@classytic/supplier-performance/events`
|
|
146
|
+
subpath (`supplierPerformanceEventDefinitions`) — hosts register it with arc's
|
|
147
|
+
`EventRegistry` for publish-time validation and OpenAPI introspection:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { supplierPerformanceEventDefinitions } from '@classytic/supplier-performance/events';
|
|
151
|
+
for (const def of supplierPerformanceEventDefinitions) registry.register(def);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
There is no package-owned outbox — durable delivery is host-composed
|
|
155
|
+
(`PACKAGE_RULES §5.5 / §16`). A transport publish failure is logged and
|
|
156
|
+
swallowed; hosts wanting at-least-once wire their own transport + relay.
|
|
157
|
+
|
|
143
158
|
### Multi-tenant
|
|
144
159
|
|
|
145
|
-
|
|
160
|
+
Every repository is wired with `multiTenantPlugin` — reads and writes are
|
|
161
|
+
tenant-scoped at POLICY priority, so cross-tenant access is impossible (the
|
|
162
|
+
plugin throws when `organizationId` is missing from the call context).
|
|
163
|
+
Resolution drives off `@classytic/repo-core/tenant`; defaults follow repo-core:
|
|
164
|
+
`tenantField: 'organizationId'`, `fieldType: 'objectId'`, required.
|
|
146
165
|
|
|
147
166
|
```ts
|
|
167
|
+
// ObjectId org ids (Better Auth) — the default:
|
|
168
|
+
const engine = await createSupplierPerformance({ connection });
|
|
169
|
+
|
|
170
|
+
// String / UUID org ids:
|
|
148
171
|
const engine = await createSupplierPerformance({
|
|
149
172
|
connection,
|
|
150
|
-
tenant: { fieldType: '
|
|
173
|
+
tenant: { fieldType: 'string' },
|
|
151
174
|
});
|
|
152
175
|
```
|
|
153
176
|
|
|
177
|
+
Mongokit 3.16 plugin defaults are fail-closed (`onMismatch: 'throw'`,
|
|
178
|
+
`allowDataInjection: false`); a host can forward `skipWhen` / `resolveContext` /
|
|
179
|
+
`allowDataInjection` / `onMismatch` through the `tenant` object when its trust
|
|
180
|
+
model justifies it.
|
|
181
|
+
|
|
154
182
|
### Indexes
|
|
155
183
|
|
|
156
184
|
| Collection | Index | Purpose |
|
|
@@ -164,7 +192,11 @@ The tenant field is prepended to compound indexes via `injectTenantField` when s
|
|
|
164
192
|
|
|
165
193
|
### Soft delete
|
|
166
194
|
|
|
167
|
-
|
|
195
|
+
Not wired by default — soft delete is host policy, not package policy
|
|
196
|
+
(`PACKAGE_RULES §10`). The event log is append-only and scorecards are
|
|
197
|
+
recomputable, so neither collection needs reversible delete out of the box.
|
|
198
|
+
Hosts that want it pass a `softDeletePlugin()` instance through
|
|
199
|
+
`repositoryPlugins.performanceEvent` / `repositoryPlugins.supplierScore`.
|
|
168
200
|
|
|
169
201
|
## Why a service (and not just repos)?
|
|
170
202
|
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { createEvent, matchEventPattern } from "@classytic/primitives/events";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/domain/enums/event-type.enum.ts
|
|
4
|
+
/**
|
|
5
|
+
* Performance event types — what happened on a single supplier interaction.
|
|
6
|
+
*
|
|
7
|
+
* The catalog is intentionally small. Each type contributes to one or more
|
|
8
|
+
* scorecard metrics:
|
|
9
|
+
*
|
|
10
|
+
* - `delivery_received` → on-time rate, average delay
|
|
11
|
+
* - `delivery_late` → on-time rate, average delay
|
|
12
|
+
* - `defect_reported` → defect rate
|
|
13
|
+
* - `price_variance` → price variance %
|
|
14
|
+
*
|
|
15
|
+
* Hosts that need a domain-specific signal (e.g. `quality_audit`) can
|
|
16
|
+
* extend by adding a constant + payload. Pure data; no FSM.
|
|
17
|
+
*/
|
|
18
|
+
const PerformanceEventType = {
|
|
19
|
+
delivery_received: "delivery_received",
|
|
20
|
+
delivery_late: "delivery_late",
|
|
21
|
+
defect_reported: "defect_reported",
|
|
22
|
+
price_variance: "price_variance"
|
|
23
|
+
};
|
|
24
|
+
const PERFORMANCE_EVENT_TYPE_VALUES = Object.values(PerformanceEventType);
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/events/event-constants.ts
|
|
27
|
+
/**
|
|
28
|
+
* Canonical event names emitted by `@classytic/supplier-performance`.
|
|
29
|
+
*
|
|
30
|
+
* Prefix `supplier_performance:` matches the sibling-package convention
|
|
31
|
+
* (`order:...`, `commission:...`). Hosts wiring an Arc transport can
|
|
32
|
+
* pattern-match on `supplier_performance:*`.
|
|
33
|
+
*/
|
|
34
|
+
const SupplierPerformanceEvents = {
|
|
35
|
+
EVENT_RECORDED: "supplier_performance:event.recorded",
|
|
36
|
+
SCORE_COMPUTED: "supplier_performance:score.computed"
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/events/helpers.ts
|
|
40
|
+
/**
|
|
41
|
+
* Thin typed wrapper around `@classytic/primitives/events.createEvent`
|
|
42
|
+
* (PACKAGE_RULES rule 14 shape: `createEvent(type, payload, ctx?, meta?)`).
|
|
43
|
+
*
|
|
44
|
+
* Value-add over primitives:
|
|
45
|
+
* - narrows `type` to `SupplierPerformanceEventName`
|
|
46
|
+
* - fills `meta.userId` / `meta.organizationId` / `meta.correlationId`
|
|
47
|
+
* from the supplier-performance context so every event stays scoped to
|
|
48
|
+
* the originating actor and tenant.
|
|
49
|
+
*
|
|
50
|
+
* Shape, id generation, timestamp — all owned by primitives / arc.
|
|
51
|
+
*/
|
|
52
|
+
function createEvent$1(type, payload, ctx, meta) {
|
|
53
|
+
return createEvent(type, payload, {
|
|
54
|
+
...ctx !== void 0 && ctx.actorKind === "user" ? { userId: String(ctx.actorRef) } : {},
|
|
55
|
+
...ctx?.organizationId !== void 0 ? { organizationId: String(ctx.organizationId) } : {},
|
|
56
|
+
...ctx?.correlationId !== void 0 ? { correlationId: ctx.correlationId } : {},
|
|
57
|
+
...meta
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/events/in-process-bus.ts
|
|
62
|
+
/**
|
|
63
|
+
* Zero-dep in-process event bus. Subscribers can use glob patterns
|
|
64
|
+
* (`supplier_performance:*`, `*`, exact type). Subscriber errors are
|
|
65
|
+
* caught and logged — they never break the emitter or sibling
|
|
66
|
+
* subscribers.
|
|
67
|
+
*
|
|
68
|
+
* Drop-in compatible with any `EventTransport` — hosts replace it by
|
|
69
|
+
* passing their own at `createSupplierPerformance({ eventTransport })`.
|
|
70
|
+
*/
|
|
71
|
+
var InProcessSupplierPerformanceBus = class {
|
|
72
|
+
name = "in-process-supplier-performance";
|
|
73
|
+
patterns = /* @__PURE__ */ new Map();
|
|
74
|
+
logger;
|
|
75
|
+
constructor(options = {}) {
|
|
76
|
+
this.logger = options.logger ?? console;
|
|
77
|
+
}
|
|
78
|
+
async publish(event) {
|
|
79
|
+
for (const [pattern, handlers] of this.patterns) {
|
|
80
|
+
if (!matchEventPattern(pattern, event.type)) continue;
|
|
81
|
+
for (const fn of handlers) try {
|
|
82
|
+
await fn(event);
|
|
83
|
+
} catch (err) {
|
|
84
|
+
this.logger.error(`[supplier-performance] subscriber threw on ${event.type}: ${err.message}`, err);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async subscribe(pattern, handler) {
|
|
89
|
+
let set = this.patterns.get(pattern);
|
|
90
|
+
if (!set) {
|
|
91
|
+
set = /* @__PURE__ */ new Set();
|
|
92
|
+
this.patterns.set(pattern, set);
|
|
93
|
+
}
|
|
94
|
+
set.add(handler);
|
|
95
|
+
return () => {
|
|
96
|
+
const s = this.patterns.get(pattern);
|
|
97
|
+
s?.delete(handler);
|
|
98
|
+
if (s && s.size === 0) this.patterns.delete(pattern);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async close() {
|
|
102
|
+
this.patterns.clear();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/events/event-catalog.ts
|
|
107
|
+
/**
|
|
108
|
+
* Zod-source event catalog (PACKAGE_RULES rule 18).
|
|
109
|
+
*
|
|
110
|
+
* One Zod schema per event is the source of truth — runtime validation,
|
|
111
|
+
* static types, and Arc introspection all derive from it. Hosts wire the
|
|
112
|
+
* definitions into arc's `EventRegistry`:
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* for (const def of supplierPerformanceEventDefinitions) registry.register(def);
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* which lights up publish-time validation (`eventPlugin({ registry,
|
|
119
|
+
* validateMode: 'reject' })`), OpenAPI event introspection, and
|
|
120
|
+
* `arc describe` output — with zero arc imports here (the definition shape
|
|
121
|
+
* is structurally identical to arc's `EventDefinitionOutput`).
|
|
122
|
+
*
|
|
123
|
+
* Timestamps are `z.iso.datetime()` (rule 25): `z.toJSONSchema()` throws on
|
|
124
|
+
* `z.coerce.date()`, and events serialize to JSON over the wire anyway.
|
|
125
|
+
*/
|
|
126
|
+
function defineSupplierPerformanceEvent(input) {
|
|
127
|
+
const { name, description, version = 1, zodSchema } = input;
|
|
128
|
+
return {
|
|
129
|
+
name,
|
|
130
|
+
version,
|
|
131
|
+
description,
|
|
132
|
+
zodSchema,
|
|
133
|
+
schema: z.toJSONSchema(zodSchema),
|
|
134
|
+
create(payload, meta) {
|
|
135
|
+
return createEvent(name, payload, {
|
|
136
|
+
resource: "supplier-performance",
|
|
137
|
+
source: "supplier-performance",
|
|
138
|
+
...meta
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const eventRecordedSchema = z.object({
|
|
144
|
+
supplierId: z.string(),
|
|
145
|
+
type: z.enum(PERFORMANCE_EVENT_TYPE_VALUES),
|
|
146
|
+
occurredAt: z.iso.datetime(),
|
|
147
|
+
sourceRef: z.string().optional()
|
|
148
|
+
});
|
|
149
|
+
const EventRecorded = defineSupplierPerformanceEvent({
|
|
150
|
+
name: SupplierPerformanceEvents.EVENT_RECORDED,
|
|
151
|
+
description: "recordEvent() appended one supplier signal to the event log.",
|
|
152
|
+
zodSchema: eventRecordedSchema
|
|
153
|
+
});
|
|
154
|
+
const scoreComputedSchema = z.object({
|
|
155
|
+
supplierId: z.string(),
|
|
156
|
+
period: z.object({
|
|
157
|
+
start: z.iso.datetime(),
|
|
158
|
+
end: z.iso.datetime()
|
|
159
|
+
}),
|
|
160
|
+
compositeScore: z.number(),
|
|
161
|
+
eventCount: z.number().int().min(0)
|
|
162
|
+
});
|
|
163
|
+
const ScoreComputed = defineSupplierPerformanceEvent({
|
|
164
|
+
name: SupplierPerformanceEvents.SCORE_COMPUTED,
|
|
165
|
+
description: "computeScore() aggregated the window and upserted a scorecard snapshot.",
|
|
166
|
+
zodSchema: scoreComputedSchema
|
|
167
|
+
});
|
|
168
|
+
const supplierPerformanceEventDefinitions = [EventRecorded, ScoreComputed];
|
|
169
|
+
//#endregion
|
|
170
|
+
export { createEvent$1 as a, PerformanceEventType as c, InProcessSupplierPerformanceBus as i, ScoreComputed as n, SupplierPerformanceEvents as o, supplierPerformanceEventDefinitions as r, PERFORMANCE_EVENT_TYPE_VALUES as s, EventRecorded as t };
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ScoreComputed, c as supplierPerformanceEventDefinitions, i as EventRecorded, l as SupplierPerformanceEventPayloads, m as SupplierPerformanceEvents, n as createEvent, o as SupplierPerformanceEventDefinition, p as SupplierPerformanceEventName, s as SupplierPerformanceEventSchema, t as InProcessSupplierPerformanceBus } from "./in-process-bus.js";
|
|
2
|
+
export { EventRecorded, InProcessSupplierPerformanceBus, ScoreComputed, type SupplierPerformanceEventDefinition, type SupplierPerformanceEventName, type SupplierPerformanceEventPayloads, type SupplierPerformanceEventSchema, SupplierPerformanceEvents, createEvent, supplierPerformanceEventDefinitions };
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as createEvent, i as InProcessSupplierPerformanceBus, n as ScoreComputed, o as SupplierPerformanceEvents, r as supplierPerformanceEventDefinitions, t as EventRecorded } from "./event-catalog.js";
|
|
2
|
+
export { EventRecorded, InProcessSupplierPerformanceBus, ScoreComputed, SupplierPerformanceEvents, createEvent, supplierPerformanceEventDefinitions };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { DomainEvent, EventHandler, EventMeta, EventTransport } from "@classytic/primitives/events";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/events/event-constants.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Canonical event names emitted by `@classytic/supplier-performance`.
|
|
8
|
+
*
|
|
9
|
+
* Prefix `supplier_performance:` matches the sibling-package convention
|
|
10
|
+
* (`order:...`, `commission:...`). Hosts wiring an Arc transport can
|
|
11
|
+
* pattern-match on `supplier_performance:*`.
|
|
12
|
+
*/
|
|
13
|
+
declare const SupplierPerformanceEvents: {
|
|
14
|
+
readonly EVENT_RECORDED: "supplier_performance:event.recorded";
|
|
15
|
+
readonly SCORE_COMPUTED: "supplier_performance:score.computed";
|
|
16
|
+
};
|
|
17
|
+
type SupplierPerformanceEventName = (typeof SupplierPerformanceEvents)[keyof typeof SupplierPerformanceEvents];
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/domain/enums/event-type.enum.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Performance event types — what happened on a single supplier interaction.
|
|
22
|
+
*
|
|
23
|
+
* The catalog is intentionally small. Each type contributes to one or more
|
|
24
|
+
* scorecard metrics:
|
|
25
|
+
*
|
|
26
|
+
* - `delivery_received` → on-time rate, average delay
|
|
27
|
+
* - `delivery_late` → on-time rate, average delay
|
|
28
|
+
* - `defect_reported` → defect rate
|
|
29
|
+
* - `price_variance` → price variance %
|
|
30
|
+
*
|
|
31
|
+
* Hosts that need a domain-specific signal (e.g. `quality_audit`) can
|
|
32
|
+
* extend by adding a constant + payload. Pure data; no FSM.
|
|
33
|
+
*/
|
|
34
|
+
declare const PerformanceEventType: {
|
|
35
|
+
readonly delivery_received: "delivery_received";
|
|
36
|
+
readonly delivery_late: "delivery_late";
|
|
37
|
+
readonly defect_reported: "defect_reported";
|
|
38
|
+
readonly price_variance: "price_variance";
|
|
39
|
+
};
|
|
40
|
+
type PerformanceEventTypeValue = (typeof PerformanceEventType)[keyof typeof PerformanceEventType];
|
|
41
|
+
declare const PERFORMANCE_EVENT_TYPE_VALUES: readonly PerformanceEventTypeValue[];
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/events/event-payloads.d.ts
|
|
44
|
+
/**
|
|
45
|
+
* Payload shapes for every `supplier_performance:*` event. Subscribers
|
|
46
|
+
* type-narrow on `eventType` and read `payload` as the matching entry.
|
|
47
|
+
*
|
|
48
|
+
* Timestamps are ISO-8601 strings on the wire (rule 25). Subscribers
|
|
49
|
+
* wanting a `Date` call `new Date(payload.occurredAt)`.
|
|
50
|
+
*/
|
|
51
|
+
interface SupplierPerformanceEventPayloads {
|
|
52
|
+
'supplier_performance:event.recorded': {
|
|
53
|
+
supplierId: string;
|
|
54
|
+
type: PerformanceEventTypeValue;
|
|
55
|
+
/** ISO-8601 — when the signal happened in the real world. */
|
|
56
|
+
occurredAt: string;
|
|
57
|
+
sourceRef?: string;
|
|
58
|
+
};
|
|
59
|
+
'supplier_performance:score.computed': {
|
|
60
|
+
supplierId: string;
|
|
61
|
+
period: {
|
|
62
|
+
/** ISO-8601 inclusive start. */
|
|
63
|
+
start: string;
|
|
64
|
+
/** ISO-8601 exclusive end. */
|
|
65
|
+
end: string;
|
|
66
|
+
};
|
|
67
|
+
compositeScore: number;
|
|
68
|
+
eventCount: number;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/events/event-catalog.d.ts
|
|
73
|
+
/** JSON-Schema object produced by `z.toJSONSchema` — what arc's registry consumes. */
|
|
74
|
+
type SupplierPerformanceEventSchema = Record<string, unknown>;
|
|
75
|
+
/** Structurally identical to arc's `EventDefinitionOutput` — do NOT import arc. */
|
|
76
|
+
interface SupplierPerformanceEventDefinition<TSchema extends z.ZodType = z.ZodType> {
|
|
77
|
+
name: SupplierPerformanceEventName;
|
|
78
|
+
version: number;
|
|
79
|
+
description: string;
|
|
80
|
+
zodSchema: TSchema;
|
|
81
|
+
schema: SupplierPerformanceEventSchema;
|
|
82
|
+
create(payload: z.infer<TSchema>, meta?: Partial<EventMeta>): DomainEvent<z.infer<TSchema>>;
|
|
83
|
+
}
|
|
84
|
+
declare const EventRecorded: SupplierPerformanceEventDefinition<z.ZodObject<{
|
|
85
|
+
supplierId: z.ZodString;
|
|
86
|
+
type: z.ZodEnum<{
|
|
87
|
+
[x: string]: string;
|
|
88
|
+
}>;
|
|
89
|
+
occurredAt: z.ZodISODateTime;
|
|
90
|
+
sourceRef: z.ZodOptional<z.ZodString>;
|
|
91
|
+
}, z.core.$strip>>;
|
|
92
|
+
declare const ScoreComputed: SupplierPerformanceEventDefinition<z.ZodObject<{
|
|
93
|
+
supplierId: z.ZodString;
|
|
94
|
+
period: z.ZodObject<{
|
|
95
|
+
start: z.ZodISODateTime;
|
|
96
|
+
end: z.ZodISODateTime;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
compositeScore: z.ZodNumber;
|
|
99
|
+
eventCount: z.ZodNumber;
|
|
100
|
+
}, z.core.$strip>>;
|
|
101
|
+
declare const supplierPerformanceEventDefinitions: ReadonlyArray<SupplierPerformanceEventDefinition>;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/domain/ports/common.d.ts
|
|
104
|
+
/**
|
|
105
|
+
* Per-call context. Carries tenant, actor, and tracing signals. Opaque
|
|
106
|
+
* `session` slot avoids importing mongoose here so this port file stays
|
|
107
|
+
* framework-agnostic.
|
|
108
|
+
*/
|
|
109
|
+
interface SupplierPerformanceContext {
|
|
110
|
+
/** Tenant scope. */
|
|
111
|
+
organizationId: string;
|
|
112
|
+
/** Actor reference (user id, system id, cron id). */
|
|
113
|
+
actorRef: string;
|
|
114
|
+
/** Actor kind. */
|
|
115
|
+
actorKind: 'user' | 'system' | 'integration';
|
|
116
|
+
/** Correlation id propagated through events. */
|
|
117
|
+
correlationId: string;
|
|
118
|
+
/** Optional mongoose ClientSession — narrowed at the repo boundary. */
|
|
119
|
+
session?: unknown;
|
|
120
|
+
/** Optional idempotency key for the operation. */
|
|
121
|
+
idempotencyKey?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Optional cancellation signal. Threaded to repo calls via
|
|
124
|
+
* `repoOptionsFromCtx`; mongokit checks it at every op boundary and
|
|
125
|
+
* stops before the next round-trip.
|
|
126
|
+
*/
|
|
127
|
+
signal?: AbortSignal;
|
|
128
|
+
/**
|
|
129
|
+
* Optional retry policy forwarded to repo calls. Mongokit wraps driver
|
|
130
|
+
* round-trips in `withRetry` when present.
|
|
131
|
+
*/
|
|
132
|
+
retryPolicy?: unknown;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/events/helpers.d.ts
|
|
136
|
+
declare function createEvent$1<T>(type: SupplierPerformanceEventName, payload: T, ctx?: SupplierPerformanceContext, meta?: Partial<EventMeta>): DomainEvent<T>;
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/events/in-process-bus.d.ts
|
|
139
|
+
interface InProcessBusOptions {
|
|
140
|
+
logger?: {
|
|
141
|
+
error(message: string, ...args: unknown[]): void;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Zero-dep in-process event bus. Subscribers can use glob patterns
|
|
146
|
+
* (`supplier_performance:*`, `*`, exact type). Subscriber errors are
|
|
147
|
+
* caught and logged — they never break the emitter or sibling
|
|
148
|
+
* subscribers.
|
|
149
|
+
*
|
|
150
|
+
* Drop-in compatible with any `EventTransport` — hosts replace it by
|
|
151
|
+
* passing their own at `createSupplierPerformance({ eventTransport })`.
|
|
152
|
+
*/
|
|
153
|
+
declare class InProcessSupplierPerformanceBus implements EventTransport {
|
|
154
|
+
readonly name = "in-process-supplier-performance";
|
|
155
|
+
private patterns;
|
|
156
|
+
private logger;
|
|
157
|
+
constructor(options?: InProcessBusOptions);
|
|
158
|
+
publish(event: DomainEvent): Promise<void>;
|
|
159
|
+
subscribe(pattern: string, handler: EventHandler): Promise<() => void>;
|
|
160
|
+
close(): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
export { ScoreComputed as a, supplierPerformanceEventDefinitions as c, PerformanceEventType as d, PerformanceEventTypeValue as f, EventRecorded as i, SupplierPerformanceEventPayloads as l, SupplierPerformanceEvents as m, createEvent$1 as n, SupplierPerformanceEventDefinition as o, SupplierPerformanceEventName as p, SupplierPerformanceContext as r, SupplierPerformanceEventSchema as s, InProcessSupplierPerformanceBus as t, PERFORMANCE_EVENT_TYPE_VALUES as u };
|