@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/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- import { ClientSession, Connection, Document, Model, Schema, Types } from "mongoose";
2
- import { PluginType, Repository } from "@classytic/mongokit";
3
- import { DomainEvent, EventHandler, EventTransport } from "@classytic/primitives/events";
1
+ import { a as ScoreComputed, c as supplierPerformanceEventDefinitions, d as PerformanceEventType, f as PerformanceEventTypeValue, i as EventRecorded, l as SupplierPerformanceEventPayloads, m as SupplierPerformanceEvents, n as createEvent, o as SupplierPerformanceEventDefinition, p as SupplierPerformanceEventName, r as SupplierPerformanceContext, s as SupplierPerformanceEventSchema, t as InProcessSupplierPerformanceBus, u as PERFORMANCE_EVENT_TYPE_VALUES } from "./in-process-bus.js";
2
+ import { PluginType, Repository, RepositoryContext } from "@classytic/mongokit";
4
3
  import { ResolvedTenantConfig, TenantConfig } from "@classytic/repo-core/tenant";
4
+ import { ClientSession, Connection, Document, Model, Schema, Types } from "mongoose";
5
+ import { EventTransport } from "@classytic/primitives/events";
6
+ import { OutboxStore } from "@classytic/primitives/outbox";
7
+ import { HttpError } from "@classytic/repo-core/errors";
5
8
 
6
9
  //#region src/models/performance-event.model.d.ts
7
10
  interface PerformanceEventDocument extends Document {
@@ -49,51 +52,19 @@ declare class SupplierScoreModelCollisionError extends Error {
49
52
  }
50
53
  declare function createSupplierScoreModel(connection: Connection, tenant: ResolvedTenantConfig, config?: SupplierScoreModelConfig): Model<SupplierScoreDocument>;
51
54
  //#endregion
52
- //#region src/models/inject-tenant.d.ts
53
- type SupplierPerformanceTenantInput = TenantConfig | boolean | {
54
- tenantFieldType?: 'objectId' | 'string';
55
- multiTenant?: boolean;
56
- };
57
- declare function resolveSupplierPerformanceTenant(input?: SupplierPerformanceTenantInput): ResolvedTenantConfig;
58
- /**
59
- * Inject the tenant field into a Mongoose schema and prepend it to every
60
- * existing compound index (so queries are index-efficient under
61
- * multi-tenant scoping). Identical algorithm to commission's helper.
62
- */
63
- //#endregion
64
55
  //#region src/models/create-models.d.ts
65
56
  interface SupplierPerformanceModelBundle {
66
57
  PerformanceEvent: ReturnType<typeof createPerformanceEventModel>;
67
58
  SupplierScore: ReturnType<typeof createSupplierScoreModel>;
68
59
  }
69
60
  interface CreateSupplierPerformanceModelsOptions {
70
- tenant?: ResolvedTenantConfig | TenantConfig | boolean | SupplierPerformanceTenantInput;
61
+ /** Resolved tenant config, or a `TenantConfig` / boolean to resolve. */
62
+ tenant?: ResolvedTenantConfig | TenantConfig | boolean;
71
63
  collectionPrefix?: string | undefined;
72
64
  forceRecreate?: boolean | undefined;
73
65
  }
74
66
  declare function createSupplierPerformanceModels(connection: Connection, options?: CreateSupplierPerformanceModelsOptions): SupplierPerformanceModelBundle;
75
67
  //#endregion
76
- //#region src/domain/ports/common.d.ts
77
- /**
78
- * Per-call context. Carries tenant, actor, and tracing signals. Opaque
79
- * `session` slot avoids importing mongoose here so this port file stays
80
- * framework-agnostic.
81
- */
82
- interface SupplierPerformanceContext {
83
- /** Tenant scope. */
84
- organizationId: string;
85
- /** Actor reference (user id, system id, cron id). */
86
- actorRef: string;
87
- /** Actor kind. */
88
- actorKind: 'user' | 'system' | 'integration';
89
- /** Correlation id propagated through events. */
90
- correlationId: string;
91
- /** Optional mongoose ClientSession — narrowed at the repo boundary. */
92
- session?: unknown;
93
- /** Optional idempotency key for the operation. */
94
- idempotencyKey?: string;
95
- }
96
- //#endregion
97
68
  //#region src/repositories/performance-event.repository.d.ts
98
69
  interface PerformanceEventRepositoryConfig {
99
70
  model: Model<PerformanceEventDocument>;
@@ -197,30 +168,6 @@ declare class SupplierScoreRepository extends Repository<SupplierScoreDocument>
197
168
  findLatest(supplierId: string, ctx: SupplierPerformanceContext): Promise<SupplierScoreDocument | null>;
198
169
  }
199
170
  //#endregion
200
- //#region src/domain/enums/event-type.enum.d.ts
201
- /**
202
- * Performance event types — what happened on a single supplier interaction.
203
- *
204
- * The catalog is intentionally small. Each type contributes to one or more
205
- * scorecard metrics:
206
- *
207
- * - `delivery_received` → on-time rate, average delay
208
- * - `delivery_late` → on-time rate, average delay
209
- * - `defect_reported` → defect rate
210
- * - `price_variance` → price variance %
211
- *
212
- * Hosts that need a domain-specific signal (e.g. `quality_audit`) can
213
- * extend by adding a constant + payload. Pure data; no FSM.
214
- */
215
- declare const PerformanceEventType: {
216
- readonly delivery_received: "delivery_received";
217
- readonly delivery_late: "delivery_late";
218
- readonly defect_reported: "defect_reported";
219
- readonly price_variance: "price_variance";
220
- };
221
- type PerformanceEventTypeValue = (typeof PerformanceEventType)[keyof typeof PerformanceEventType];
222
- declare const PERFORMANCE_EVENT_TYPE_VALUES: readonly PerformanceEventTypeValue[];
223
- //#endregion
224
171
  //#region src/domain/entities/performance-event.entity.d.ts
225
172
  interface PerformanceEvent {
226
173
  _id: Types.ObjectId;
@@ -295,14 +242,20 @@ interface ScoreServiceConfig {
295
242
  events: PerformanceEventRepository;
296
243
  scores: SupplierScoreRepository;
297
244
  eventTransport?: EventTransport | undefined;
245
+ /**
246
+ * Optional durable outbox. Required for calling verbs under a
247
+ * host-owned ctx.session — see UnmanagedSessionError (§P8.1).
248
+ */
249
+ outbox?: OutboxStore | undefined;
298
250
  logger?: {
299
251
  error(message: string, ...args: unknown[]): void;
300
- };
252
+ } | undefined;
301
253
  }
302
254
  declare class ScoreService {
303
255
  private events;
304
256
  private scores;
305
- private eventTransport?;
257
+ private eventTransport;
258
+ private outbox;
306
259
  private logger;
307
260
  constructor(config: ScoreServiceConfig);
308
261
  /**
@@ -326,18 +279,34 @@ declare class ScoreService {
326
279
  * implicitly (callers know when their data has changed).
327
280
  */
328
281
  getScorecard(supplierId: string, ctx: SupplierPerformanceContext, period?: ScorePeriod): Promise<SupplierScoreDocument | null>;
282
+ /**
283
+ * P8 dispatch. Outbox save (when wired) runs first, session-bound, and
284
+ * failures PROPAGATE; the transport publish is best-effort (swallowed)
285
+ * and skipped under a host session — the relay delivers the durable
286
+ * row post-commit (§P8.1). A host session with NO outbox throws
287
+ * `UnmanagedSessionError` before any side effect: the pre-guard
288
+ * fire-and-forget publish could leak ghost events on rollback.
289
+ */
329
290
  private publish;
330
291
  }
331
- declare class RecordEventValidationError extends Error {
332
- readonly name = "RecordEventValidationError";
333
- readonly code: "SUPPLIER_PERFORMANCE_VALIDATION";
334
- constructor(message: string);
335
- }
336
292
  //#endregion
337
293
  //#region src/engine/engine-types.d.ts
338
294
  interface SupplierPerformanceLogger {
339
295
  error(message: string, ...args: unknown[]): void;
340
296
  }
297
+ /**
298
+ * Tenant scoping config. Extends repo-core's `TenantConfig` with the
299
+ * mongokit-runtime knobs `multiTenantPlugin` accepts beyond the static
300
+ * vocabulary (forwarded only when the host sets them — the fail-closed
301
+ * 3.16 defaults stay in charge otherwise, rule 9.3 / 9.5).
302
+ */
303
+ interface SupplierPerformanceTenantOptions extends TenantConfig {
304
+ skipOperations?: string[] | undefined;
305
+ skipWhen?: ((context: RepositoryContext, operation: string) => boolean) | undefined;
306
+ resolveContext?: (() => string | undefined) | undefined;
307
+ allowDataInjection?: boolean | undefined;
308
+ onMismatch?: 'throw' | 'overwrite' | undefined;
309
+ }
341
310
  interface SupplierPerformanceConfig {
342
311
  /** Shared mongoose connection. */
343
312
  connection: Connection;
@@ -347,11 +316,19 @@ interface SupplierPerformanceConfig {
347
316
  * the bundled `InProcessSupplierPerformanceBus`. Omit to skip event
348
317
  * emission entirely.
349
318
  */
319
+ /** Optional durable outbox — enables host-session (relay-only) mode. */
320
+ outbox?: OutboxStore | undefined;
350
321
  eventTransport?: EventTransport | undefined;
351
322
  /**
352
- * Tenant scoping config. Defaults to `{ fieldType: 'string' }`.
323
+ * Tenant scoping config — `TenantConfig` from `@classytic/repo-core/tenant`
324
+ * (plus mongokit-runtime knobs) or a boolean shorthand. One resolved value
325
+ * drives BOTH the model factory (schema field type + index prefixing) and
326
+ * `multiTenantPlugin` (query casting + fail-closed scoping), so they can't
327
+ * drift (rule 9.2). Defaults follow repo-core: `tenantField: 'organizationId'`,
328
+ * `fieldType: 'objectId'`, required. Hosts with string/UUID org ids pass
329
+ * `{ fieldType: 'string' }`.
353
330
  */
354
- tenant?: TenantConfig | boolean | undefined;
331
+ tenant?: SupplierPerformanceTenantOptions | boolean | undefined;
355
332
  /** Optional collection name prefix (PACKAGE_RULES §20.1). */
356
333
  collectionPrefix?: string | undefined;
357
334
  /** Hot-reload / test fixtures only. Default `false`. */
@@ -373,7 +350,7 @@ interface SupplierPerformanceEngine {
373
350
  services: {
374
351
  score: ScoreService;
375
352
  };
376
- events?: EventTransport;
353
+ events: EventTransport;
377
354
  syncIndexes(): Promise<void>;
378
355
  destroy(): Promise<void>;
379
356
  }
@@ -381,6 +358,22 @@ interface SupplierPerformanceEngine {
381
358
  //#region src/engine/create-supplier-performance.d.ts
382
359
  declare function createSupplierPerformance(config: SupplierPerformanceConfig): Promise<SupplierPerformanceEngine>;
383
360
  //#endregion
361
+ //#region src/domain/errors/supplier-performance.errors.d.ts
362
+ declare class SupplierPerformanceError extends Error implements HttpError {
363
+ readonly code: string;
364
+ readonly status: number;
365
+ constructor(message: string, code: string, status: number);
366
+ }
367
+ /**
368
+ * Thrown when a host passes ctx.session but no OutboxStore is wired —
369
+ * publishing mid-transaction would leak ghost events on rollback (§P8.1).
370
+ */
371
+
372
+ /** Invalid input to `recordEvent` / `computeScore` (missing supplierId, bad period). */
373
+ declare class SupplierPerformanceValidationError extends SupplierPerformanceError {
374
+ constructor(message: string);
375
+ }
376
+ //#endregion
384
377
  //#region src/calc/score-calculator.d.ts
385
378
  /**
386
379
  * Aggregate raw performance events into a scorecard. Events outside the
@@ -389,6 +382,19 @@ declare function createSupplierPerformance(config: SupplierPerformanceConfig): P
389
382
  */
390
383
  declare function scoreFromEvents(events: ReadonlyArray<PerformanceEvent>, period: ScorePeriod): ScoreMetrics;
391
384
  //#endregion
385
+ //#region src/models/inject-tenant.d.ts
386
+ /**
387
+ * Resolve the package's tenant config. Accepts a repo-core `TenantConfig`
388
+ * or boolean shorthand — no package-local shapes. Pure passthrough to
389
+ * `resolveTenantConfig` so defaults can't drift from the org standard.
390
+ */
391
+ declare function resolveSupplierPerformanceTenant(input?: TenantConfig | boolean): ResolvedTenantConfig;
392
+ /**
393
+ * Inject the tenant field into a Mongoose schema and prepend it to every
394
+ * existing compound index (so queries are index-efficient under
395
+ * multi-tenant scoping, rule 36).
396
+ */
397
+ //#endregion
392
398
  //#region src/repositories/repo-options.d.ts
393
399
  interface RepoOptions {
394
400
  organizationId: string;
@@ -397,47 +403,10 @@ interface RepoOptions {
397
403
  correlationId: string;
398
404
  session?: ClientSession;
399
405
  idempotencyKey?: string;
406
+ signal?: AbortSignal;
407
+ retryPolicy?: unknown;
400
408
  [key: string]: unknown;
401
409
  }
402
410
  declare function repoOptionsFromCtx(ctx: SupplierPerformanceContext): RepoOptions;
403
411
  //#endregion
404
- //#region src/events/event-constants.d.ts
405
- /**
406
- * Canonical event names emitted by `@classytic/supplier-performance`.
407
- *
408
- * Prefix `supplier_performance:` matches the sibling-package convention
409
- * (`order:...`, `commission:...`). Hosts wiring an Arc transport can
410
- * pattern-match on `supplier_performance:*`.
411
- */
412
- declare const SupplierPerformanceEvents: {
413
- readonly EVENT_RECORDED: "supplier_performance:event.recorded";
414
- readonly SCORE_COMPUTED: "supplier_performance:score.computed";
415
- };
416
- type SupplierPerformanceEventName = (typeof SupplierPerformanceEvents)[keyof typeof SupplierPerformanceEvents];
417
- //#endregion
418
- //#region src/events/in-process-bus.d.ts
419
- interface InProcessBusOptions {
420
- logger?: {
421
- error(message: string, ...args: unknown[]): void;
422
- };
423
- }
424
- /**
425
- * Zero-dep in-process event bus. Subscribers can use glob patterns
426
- * (`supplier_performance:*`, `*`, exact type). Subscriber errors are
427
- * caught and logged — they never break the emitter or sibling
428
- * subscribers.
429
- *
430
- * Drop-in compatible with any `EventTransport` — hosts replace it by
431
- * passing their own at `createSupplierPerformance({ eventTransport })`.
432
- */
433
- declare class InProcessSupplierPerformanceBus implements EventTransport {
434
- readonly name = "in-process-supplier-performance";
435
- private patterns;
436
- private logger;
437
- constructor(options?: InProcessBusOptions);
438
- publish(event: DomainEvent): Promise<void>;
439
- subscribe(pattern: string, handler: EventHandler): Promise<() => void>;
440
- }
441
- //#endregion
442
- export { type ComputeScoreInput, type CreateSupplierPerformanceModelsOptions, InProcessSupplierPerformanceBus, PERFORMANCE_EVENT_TYPE_VALUES, type PerformanceEvent, type PerformanceEventDocument, PerformanceEventModelCollisionError, PerformanceEventRepository, type PerformanceEventRepositoryConfig, PerformanceEventType, type PerformanceEventTypeValue, type PerformanceMetrics, type RecordEventInput, RecordEventValidationError, type RepoOptions, type ScoreMetrics, type ScorePeriod, ScoreService, type ScoreServiceConfig, type SupplierPerformanceConfig, type SupplierPerformanceContext, type SupplierPerformanceEngine, type SupplierPerformanceEventName, SupplierPerformanceEvents, type SupplierPerformanceLogger, type SupplierPerformanceModelBundle, type SupplierPerformanceRepositories, type SupplierPerformanceTenantInput, type SupplierScore, type SupplierScoreDocument, SupplierScoreModelCollisionError, SupplierScoreRepository, type SupplierScoreRepositoryConfig, type UpsertScoreInput, createPerformanceEventModel, createSupplierPerformance, createSupplierPerformanceModels, createSupplierScoreModel, repoOptionsFromCtx, resolveSupplierPerformanceTenant, scoreFromEvents };
443
- //# sourceMappingURL=index.d.ts.map
412
+ export { type ComputeScoreInput, type CreateSupplierPerformanceModelsOptions, EventRecorded, InProcessSupplierPerformanceBus, PERFORMANCE_EVENT_TYPE_VALUES, type PerformanceEvent, type PerformanceEventDocument, PerformanceEventModelCollisionError, PerformanceEventRepository, type PerformanceEventRepositoryConfig, PerformanceEventType, type PerformanceEventTypeValue, type PerformanceMetrics, type RecordEventInput, type RepoOptions, ScoreComputed, type ScoreMetrics, type ScorePeriod, ScoreService, type ScoreServiceConfig, type SupplierPerformanceConfig, type SupplierPerformanceContext, type SupplierPerformanceEngine, SupplierPerformanceError, type SupplierPerformanceEventDefinition, type SupplierPerformanceEventName, type SupplierPerformanceEventPayloads, type SupplierPerformanceEventSchema, SupplierPerformanceEvents, type SupplierPerformanceLogger, type SupplierPerformanceModelBundle, type SupplierPerformanceRepositories, type SupplierPerformanceTenantOptions, SupplierPerformanceValidationError, type SupplierScore, type SupplierScoreDocument, SupplierScoreModelCollisionError, SupplierScoreRepository, type SupplierScoreRepositoryConfig, type UpsertScoreInput, createEvent, createPerformanceEventModel, createSupplierPerformance, createSupplierPerformanceModels, createSupplierScoreModel, repoOptionsFromCtx, resolveSupplierPerformanceTenant, scoreFromEvents, supplierPerformanceEventDefinitions };