@classytic/cart 0.1.3 → 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 +83 -0
- package/README.md +12 -2
- package/dist/{clock.port-BUe6Dk_M.d.mts → clock.port-CNu2wgdA.d.mts} +13 -1
- package/dist/{create-cart-4wql1XGi.mjs → create-cart-BeW0xAqD.mjs} +302 -30
- package/dist/domain/errors/index.d.mts +2 -2
- package/dist/domain/errors/index.mjs +2 -2
- package/dist/domain/index.d.mts +7 -7
- package/dist/domain/index.mjs +4 -4
- package/dist/domain/ports/index.d.mts +1 -1
- package/dist/domain/saga/index.d.mts +1 -1
- package/dist/domain/saga/index.mjs +1 -1
- package/dist/engine/cart-config.schema.d.mts +7 -1
- package/dist/engine/cart-config.schema.mjs +12 -2
- package/dist/engine/index.d.mts +1 -1
- package/dist/engine/index.mjs +1 -1
- package/dist/{index-qfN8dZN9.d.mts → index-BB0XzkXF.d.mts} +45 -2
- package/dist/index.d.mts +52 -15
- package/dist/index.mjs +83 -26
- package/dist/{internal-event-bus-DhSLiZHi.d.mts → internal-event-bus-DhQKi9KS.d.mts} +104 -6
- package/dist/{kind-registry-D03c2VV5.d.mts → kind-registry-DG2iCCH1.d.mts} +1 -1
- package/dist/kinds/index.d.mts +1 -1
- package/dist/kinds/index.mjs +1 -1
- package/dist/{line-kind-CKOWafK0.d.mts → line-kind-B1mU1iJp.d.mts} +1 -1
- package/dist/{reservation.entity-WdaZCJg9.d.mts → reservation.entity-DLMxgpLE.d.mts} +3 -3
- package/dist/{state-transitions-D8CRykBv.d.mts → state-transitions-D19wZe-w.d.mts} +2 -2
- package/dist/{stale-quote.error-BkFLXWo5.mjs → unmanaged-session.error-C9Z1Yh9j.mjs} +31 -1
- package/dist/{variant.kind-z2gwH9Vo.mjs → variant.kind-BHiivO9B.mjs} +2 -1
- package/dist/{variant.kind-Cpo_Hh7G.d.mts → variant.kind-q-yv-vnQ.d.mts} +1 -1
- package/package.json +6 -6
- /package/dist/{kind-registry-C99h_-8t.mjs → kind-registry-Bvrj3P1Q.mjs} +0 -0
- /package/dist/{state-transitions-Bm3lC2Uv.mjs → state-transitions-Defw8gAt.mjs} +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { b as CartEventName, d as OutboxStore, h as CartDomainEvent, x as CartEventPayload } from "./outbox-store-CBt9fSYh.mjs";
|
|
2
|
-
import { C as OperationContext, c as TaxBridge, d as InventoryBridge, m as CatalogBridge, r as ShippingBridge, t as ClockPort, y as PromotionsBridge } from "./clock.port-
|
|
3
|
-
import { l as LineDisplay, r as LineKind } from "./line-kind-
|
|
4
|
-
import { c as LineItem, i as IdempotencyIdentity, t as KindRegistry } from "./kind-registry-
|
|
2
|
+
import { C as OperationContext, c as TaxBridge, d as InventoryBridge, m as CatalogBridge, r as ShippingBridge, t as ClockPort, y as PromotionsBridge } from "./clock.port-CNu2wgdA.mjs";
|
|
3
|
+
import { l as LineDisplay, r as LineKind } from "./line-kind-B1mU1iJp.mjs";
|
|
4
|
+
import { c as LineItem, i as IdempotencyIdentity, t as KindRegistry } from "./kind-registry-DG2iCCH1.mjs";
|
|
5
5
|
import { t as IdPort } from "./id.port-DitjeoHg.mjs";
|
|
6
6
|
import { CartConfigShape } from "./engine/cart-config.schema.mjs";
|
|
7
7
|
import { Money } from "@classytic/primitives/money";
|
|
8
8
|
import { DomainEvent, EventHandler, EventTransport, PublishManyResult } from "@classytic/primitives/events";
|
|
9
|
-
import { Connection, Document, Model, Types } from "mongoose";
|
|
10
9
|
import { PluginType, Repository } from "@classytic/mongokit";
|
|
10
|
+
import { Connection, Document, Model, Types } from "mongoose";
|
|
11
11
|
|
|
12
12
|
//#region src/models/checkout.model.d.ts
|
|
13
13
|
/**
|
|
@@ -184,11 +184,15 @@ interface CartEventPublisherDeps {
|
|
|
184
184
|
events: EventTransport;
|
|
185
185
|
outbox?: OutboxStore;
|
|
186
186
|
clock: ClockPort;
|
|
187
|
+
logger?: {
|
|
188
|
+
error(message: string, ...args: unknown[]): void;
|
|
189
|
+
} | undefined;
|
|
187
190
|
}
|
|
188
191
|
declare class CartEventPublisher {
|
|
189
192
|
private readonly events;
|
|
190
193
|
private readonly outbox?;
|
|
191
194
|
private readonly clock;
|
|
195
|
+
private readonly logger;
|
|
192
196
|
constructor(deps: CartEventPublisherDeps);
|
|
193
197
|
emit<E extends CartEventName>(type: E, payload: Omit<CartEventPayload<E>, 'emittedAt' | 'correlationId' | 'organizationId' | 'actorRef'>, ctx: OperationContext, options?: EmitOptions): Promise<void>;
|
|
194
198
|
}
|
|
@@ -209,6 +213,20 @@ interface DraftRepositoryDeps {
|
|
|
209
213
|
* Multi-tenant scoping is enforced by `multiTenantPlugin` at POLICY priority;
|
|
210
214
|
* `publicId` is generated by `customIdPlugin`. Optimistic concurrency runs
|
|
211
215
|
* through mongokit's `update()` so all hooks (audit, observability) fire.
|
|
216
|
+
*
|
|
217
|
+
* ## Concurrency invariant — read-modify-write on `lines` is CAS-safe
|
|
218
|
+
*
|
|
219
|
+
* Every line mutation (addItem, updateItemQuantity, removeItem, clear,
|
|
220
|
+
* replaceLines) rebuilds the FULL `lines` array in memory from a single
|
|
221
|
+
* read and persists it via `updateWithVersion`, which only matches when
|
|
222
|
+
* the stored `version` still equals the version of that read. Any
|
|
223
|
+
* concurrent mutation bumps `version`, so the stale rebuild can never
|
|
224
|
+
* land — the loser gets a typed `ConcurrencyError` and retries from a
|
|
225
|
+
* fresh read. Do NOT "optimize" these paths into positional `$push` /
|
|
226
|
+
* `$set('lines.$')` array operators: pricing snapshots are derived from
|
|
227
|
+
* the whole line set, so a partial array write would let `lines` and
|
|
228
|
+
* `pricing` drift apart. The version CAS is what makes the in-memory
|
|
229
|
+
* rebuild safe; the rebuild is what keeps pricing consistent.
|
|
212
230
|
*/
|
|
213
231
|
declare class DraftRepository extends Repository<DraftDocument> {
|
|
214
232
|
private readonly kinds;
|
|
@@ -266,8 +284,16 @@ declare class DraftRepository extends Repository<DraftDocument> {
|
|
|
266
284
|
/**
|
|
267
285
|
* Atomic transition `active → abandoned`. Returns null if the draft was
|
|
268
286
|
* already in a non-active state.
|
|
287
|
+
*
|
|
288
|
+
* Pass `opts.expectedVersion` to ALSO compare-and-set on `version` —
|
|
289
|
+
* the merge service uses this to guarantee the source draft's line set
|
|
290
|
+
* it captured is exactly the line set being retired (a concurrent
|
|
291
|
+
* add-to-cart bumps `version`, the CAS misses, and the merge retries
|
|
292
|
+
* from a fresh read instead of silently dropping the new line).
|
|
269
293
|
*/
|
|
270
|
-
markAbandoned(draftId: Types.ObjectId | string, ctx: OperationContext
|
|
294
|
+
markAbandoned(draftId: Types.ObjectId | string, ctx: OperationContext, opts?: {
|
|
295
|
+
expectedVersion?: number;
|
|
296
|
+
}): Promise<DraftDocument | null>;
|
|
271
297
|
/**
|
|
272
298
|
* Mark a draft as converted (called from CheckoutRepository.commit).
|
|
273
299
|
* Best-effort: a missed update is reconciled by the next getOrCreate.
|
|
@@ -277,10 +303,18 @@ declare class DraftRepository extends Repository<DraftDocument> {
|
|
|
277
303
|
* Replace the line collection atomically and refresh the pricing snapshot.
|
|
278
304
|
* Internal services use this to keep merge-like flows inside repository
|
|
279
305
|
* concurrency + pricing rules instead of hand-writing persistence logic.
|
|
306
|
+
*
|
|
307
|
+
* Pass `expectedVersion` when `lines` was computed from an EARLIER read
|
|
308
|
+
* of the draft: the CAS then pins to that read's version, so any
|
|
309
|
+
* mutation that landed in between (concurrent add-to-cart during a
|
|
310
|
+
* merge) surfaces as `ConcurrencyError` instead of being overwritten.
|
|
311
|
+
* Without it, the CAS pins to this method's own fresh read — safe for
|
|
312
|
+
* callers whose `lines` doesn't derive from draft state.
|
|
280
313
|
*/
|
|
281
314
|
replaceLines(input: {
|
|
282
315
|
draftPublicId: string;
|
|
283
316
|
lines: readonly LineItem[];
|
|
317
|
+
expectedVersion?: number;
|
|
284
318
|
}, ctx: OperationContext): Promise<DraftDocument>;
|
|
285
319
|
mergeLines(existing: readonly LineItem[], incoming: readonly LineItem[]): LineItem[];
|
|
286
320
|
private readOptions;
|
|
@@ -309,7 +343,20 @@ interface CheckoutRepositoryDeps {
|
|
|
309
343
|
draftRepo: DraftRepository;
|
|
310
344
|
clock: ClockPort;
|
|
311
345
|
eventPublisher: CartEventPublisher;
|
|
346
|
+
/**
|
|
347
|
+
* Age (ms) past which an `open` checkout is considered a zombie and is
|
|
348
|
+
* lazily expired by `createFromDraft` instead of being returned as the
|
|
349
|
+
* idempotent dedup hit. Default: `DEFAULT_STALE_OPEN_CHECKOUT_MS`.
|
|
350
|
+
*/
|
|
351
|
+
staleOpenCheckoutMs?: number | undefined;
|
|
312
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Default zombie window for open checkouts — matches the package's
|
|
355
|
+
* existing expiry default (`reservationConfigSchema.defaultTtlSeconds`,
|
|
356
|
+
* 600s): once any reservation hold backing the checkout has lapsed, the
|
|
357
|
+
* open snapshot has no claim on anything and is safe to self-expire.
|
|
358
|
+
*/
|
|
359
|
+
declare const DEFAULT_STALE_OPEN_CHECKOUT_MS = 600000;
|
|
313
360
|
/**
|
|
314
361
|
* CheckoutRepository — extends mongokit's `Repository<CheckoutDocument>`.
|
|
315
362
|
*
|
|
@@ -322,6 +369,7 @@ declare class CheckoutRepository extends Repository<CheckoutDocument> {
|
|
|
322
369
|
private readonly draftRepo;
|
|
323
370
|
private readonly clock;
|
|
324
371
|
private readonly eventPublisher;
|
|
372
|
+
private readonly staleOpenCheckoutMs;
|
|
325
373
|
constructor(model: Model<CheckoutDocument>, plugins: PluginType[], deps: CheckoutRepositoryDeps);
|
|
326
374
|
findByPublicId(publicId: string, ctx: OperationContext): Promise<CheckoutDocument | null>;
|
|
327
375
|
findByDraft(draftId: Types.ObjectId | string, ctx: OperationContext): Promise<CheckoutDocument | null>;
|
|
@@ -340,6 +388,15 @@ declare class CheckoutRepository extends Repository<CheckoutDocument> {
|
|
|
340
388
|
checkoutPublicId: string;
|
|
341
389
|
externalRef?: string;
|
|
342
390
|
}, ctx: OperationContext): Promise<CheckoutDocument>;
|
|
391
|
+
/**
|
|
392
|
+
* Transition open → canceled and record the reason.
|
|
393
|
+
*
|
|
394
|
+
* ⚠ Cart does NOT release inventory holds here — the HOST owns that
|
|
395
|
+
* compensation (it owns the reserve/commit sequencing too). Subscribe to
|
|
396
|
+
* `cart.checkout.canceled` and call `inventory.release(reservationRefs)`,
|
|
397
|
+
* or call it inline right after this method. Forgetting this strands
|
|
398
|
+
* holds until their TTL backstop — the classic integration leak.
|
|
399
|
+
*/
|
|
343
400
|
cancel(input: {
|
|
344
401
|
checkoutPublicId: string;
|
|
345
402
|
reason: string;
|
|
@@ -357,6 +414,13 @@ declare class CheckoutRepository extends Repository<CheckoutDocument> {
|
|
|
357
414
|
* call this from a periodic job (cron, Streamline, etc.) at whatever
|
|
358
415
|
* cadence matches their checkout completion SLA.
|
|
359
416
|
*
|
|
417
|
+
* This is the BULK sweep. `createFromDraft` additionally self-heals
|
|
418
|
+
* lazily: when it finds an open checkout older than
|
|
419
|
+
* `staleOpenCheckoutMs`, it CAS-expires that one zombie inline and
|
|
420
|
+
* creates a fresh checkout — so a customer is never stuck waiting for
|
|
421
|
+
* the next cron tick. Keep both: lazy healing fixes the active
|
|
422
|
+
* customer's path; the cron reclaims abandoned rows nobody revisits.
|
|
423
|
+
*
|
|
360
424
|
* Returns the count of rows expired. Caller scopes the operation via
|
|
361
425
|
* `ctx` — pass `ctx.organizationId` to scope to one tenant, or use
|
|
362
426
|
* `skipTenant: true` to expire across the board (only safe for the
|
|
@@ -370,6 +434,18 @@ declare class CheckoutRepository extends Repository<CheckoutDocument> {
|
|
|
370
434
|
expireStaleOpenCheckouts(maxAgeMs: number, ctx: OperationContext): Promise<{
|
|
371
435
|
count: number;
|
|
372
436
|
}>;
|
|
437
|
+
/** Is this open checkout past the zombie window? */
|
|
438
|
+
private isStaleOpen;
|
|
439
|
+
/**
|
|
440
|
+
* CAS-expire a zombie open checkout: `open → canceled` with
|
|
441
|
+
* `canceledReason: 'expired'` — same terminal shape the cron
|
|
442
|
+
* (`expireStaleOpenCheckouts`) writes, so audit history is uniform.
|
|
443
|
+
* The `{ state: 'open', version }` filter makes the transition atomic:
|
|
444
|
+
* a concurrent commit/cancel/expiry wins and this call is a no-op
|
|
445
|
+
* (returns false). No CHECKOUT_CANCELED event — expiry is janitorial,
|
|
446
|
+
* matching the cron method's contract.
|
|
447
|
+
*/
|
|
448
|
+
private expireZombie;
|
|
373
449
|
private readOptions;
|
|
374
450
|
private writeOptions;
|
|
375
451
|
private requireCheckout;
|
|
@@ -487,6 +563,8 @@ interface CreateCartRepositoriesConfig {
|
|
|
487
563
|
multiTenant?: boolean;
|
|
488
564
|
outbox?: OutboxStore;
|
|
489
565
|
plugins?: CartRepositoryPluginBundle;
|
|
566
|
+
/** Zombie window for lazy open-checkout expiry. See `CheckoutRepositoryDeps`. */
|
|
567
|
+
staleOpenCheckoutMs?: number;
|
|
490
568
|
}
|
|
491
569
|
declare function createCartRepositories(models: CartModels, config: CreateCartRepositoriesConfig): CartRepositories;
|
|
492
570
|
//#endregion
|
|
@@ -607,6 +685,12 @@ interface CartConfig extends Partial<CartConfigShape> {
|
|
|
607
685
|
* (`mongoose.createConnection(...)`). See PACKAGE_RULES.md §21.
|
|
608
686
|
*/
|
|
609
687
|
forceRecreate?: boolean | undefined;
|
|
688
|
+
/**
|
|
689
|
+
* Allow `engine.withTransaction` to fall back to non-transactional
|
|
690
|
+
* execution on standalone Mongo (local dev). Partial-write risk across
|
|
691
|
+
* the wrapped writes — explicit opt-in only.
|
|
692
|
+
*/
|
|
693
|
+
allowNonTransactional?: boolean | undefined;
|
|
610
694
|
}
|
|
611
695
|
/**
|
|
612
696
|
* CartEngine — the result of `createCart()`.
|
|
@@ -650,6 +734,20 @@ interface CartEngine {
|
|
|
650
734
|
* repositories are populated.
|
|
651
735
|
*/
|
|
652
736
|
readonly mode: 'lite' | 'full';
|
|
737
|
+
/**
|
|
738
|
+
* Run cart writes in one atomic unit-of-work: transaction + post-commit
|
|
739
|
+
* event publish. Events emitted inside the unit are queued and flushed to
|
|
740
|
+
* the in-process transport only AFTER commit — a rollback can't leak
|
|
741
|
+
* ghost events. Outbox rows (when wired) commit with the transaction.
|
|
742
|
+
*
|
|
743
|
+
* ```ts
|
|
744
|
+
* await cart.withTransaction(ctx, (txCtx) =>
|
|
745
|
+
* cart.repositories.checkout.createFromDraft(input, txCtx));
|
|
746
|
+
* ```
|
|
747
|
+
*
|
|
748
|
+
* Full mode only — throws in `'lite'` mode (no real connection).
|
|
749
|
+
*/
|
|
750
|
+
withTransaction<T>(ctx: OperationContext, body: (txCtx: OperationContext) => Promise<T>): Promise<T>;
|
|
653
751
|
/**
|
|
654
752
|
* Explicitly create indexes on all cart models.
|
|
655
753
|
*
|
|
@@ -683,4 +781,4 @@ declare class InProcessCartEventBus implements EventTransport {
|
|
|
683
781
|
close(): Promise<void>;
|
|
684
782
|
}
|
|
685
783
|
//#endregion
|
|
686
|
-
export {
|
|
784
|
+
export { createReservationModel as C, createDraftModel as D, DraftDocument as E, CheckoutDocument as O, ReservationDocument as S, createIdempotencyModel as T, CartEventPublisherDeps as _, CartEngine as a, CreateCartModelsOptions as b, CreateCartRepositoriesConfig as c, IdempotencyRepository as d, CheckoutRepository as f, DraftRepositoryDeps as g, DraftRepository as h, CartConfig as i, createCheckoutModel as k, createCartRepositories as l, DEFAULT_STALE_OPEN_CHECKOUT_MS as m, createCart as n, CartRepositories as o, CheckoutRepositoryDeps as p, CartBridges as r, CartRepositoryPluginBundle as s, InProcessCartEventBus as t, ReservationRepository as u, CartModelName as v, IdempotencyDocument as w, createCartModels as x, CartModels as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as LineDisplay, r as LineKind } from "./line-kind-
|
|
1
|
+
import { l as LineDisplay, r as LineKind } from "./line-kind-B1mU1iJp.mjs";
|
|
2
2
|
import * as _$_classytic_primitives_money0 from "@classytic/primitives/money";
|
|
3
3
|
import { Money } from "@classytic/primitives/money";
|
|
4
4
|
|
package/dist/kinds/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as timeslotKind, c as skuKind, d as serviceFeeKind, f as serviceFeePayloadSchema, g as bundlePayloadSchema, h as bundleKind, i as TimeslotPayload, l as skuPayloadSchema, m as BundlePayload, n as variantKind, o as timeslotPayloadSchema, p as BundleComponent, r as variantPayloadSchema, s as SkuPayload, t as VariantPayload, u as ServiceFeePayload } from "../variant.kind-
|
|
1
|
+
import { a as timeslotKind, c as skuKind, d as serviceFeeKind, f as serviceFeePayloadSchema, g as bundlePayloadSchema, h as bundleKind, i as TimeslotPayload, l as skuPayloadSchema, m as BundlePayload, n as variantKind, o as timeslotPayloadSchema, p as BundleComponent, r as variantPayloadSchema, s as SkuPayload, t as VariantPayload, u as ServiceFeePayload } from "../variant.kind-q-yv-vnQ.mjs";
|
|
2
2
|
export { type BundleComponent, type BundlePayload, type ServiceFeePayload, type SkuPayload, type TimeslotPayload, type VariantPayload, bundleKind, bundlePayloadSchema, serviceFeeKind, serviceFeePayloadSchema, skuKind, skuPayloadSchema, timeslotKind, timeslotPayloadSchema, variantKind, variantPayloadSchema };
|
package/dist/kinds/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as skuKind, c as serviceFeePayloadSchema, i as timeslotPayloadSchema, l as bundleKind, n as variantPayloadSchema, o as skuPayloadSchema, r as timeslotKind, s as serviceFeeKind, t as variantKind, u as bundlePayloadSchema } from "../variant.kind-
|
|
1
|
+
import { a as skuKind, c as serviceFeePayloadSchema, i as timeslotPayloadSchema, l as bundleKind, n as variantPayloadSchema, o as skuPayloadSchema, r as timeslotKind, s as serviceFeeKind, t as variantKind, u as bundlePayloadSchema } from "../variant.kind-BHiivO9B.mjs";
|
|
2
2
|
export { bundleKind, bundlePayloadSchema, serviceFeeKind, serviceFeePayloadSchema, skuKind, skuPayloadSchema, timeslotKind, timeslotPayloadSchema, variantKind, variantPayloadSchema };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as OperationContext, c as TaxBridge, d as InventoryBridge, f as ReservationRef, m as CatalogBridge, r as ShippingBridge, t as ClockPort,
|
|
1
|
+
import { C as OperationContext, T as PricedLine, c as TaxBridge, d as InventoryBridge, f as ReservationRef, m as CatalogBridge, r as ShippingBridge, t as ClockPort, y as PromotionsBridge } from "./clock.port-CNu2wgdA.mjs";
|
|
2
2
|
import { Money } from "@classytic/primitives/money";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "./cart-status.vo-CNJw4aaB.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { o as CheckoutFlowState } from "./state-transitions-
|
|
4
|
-
import { a as IdempotencyReplay, c as LineItem, o as OperationName } from "./kind-registry-
|
|
2
|
+
import { E as PricingSnapshot, g as AdjustmentSpec } from "./clock.port-CNu2wgdA.mjs";
|
|
3
|
+
import { o as CheckoutFlowState } from "./state-transitions-D19wZe-w.mjs";
|
|
4
|
+
import { a as IdempotencyReplay, c as LineItem, o as OperationName } from "./kind-registry-DG2iCCH1.mjs";
|
|
5
5
|
import { Money } from "@classytic/primitives/money";
|
|
6
6
|
|
|
7
7
|
//#region src/domain/entities/adjustment.entity.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as CheckoutState } from "./cart-status.vo-CNJw4aaB.mjs";
|
|
2
|
-
import { C as OperationContext, t as ClockPort } from "./clock.port-
|
|
3
|
-
import { t as KindBridges } from "./line-kind-
|
|
2
|
+
import { C as OperationContext, t as ClockPort } from "./clock.port-CNu2wgdA.mjs";
|
|
3
|
+
import { t as KindBridges } from "./line-kind-B1mU1iJp.mjs";
|
|
4
4
|
import { t as IdPort } from "./id.port-DitjeoHg.mjs";
|
|
5
5
|
import * as _$_classytic_primitives_state_machine0 from "@classytic/primitives/state-machine";
|
|
6
6
|
|
|
@@ -94,4 +94,34 @@ var StaleQuoteError = class extends CartError {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
//#endregion
|
|
97
|
-
|
|
97
|
+
//#region src/domain/errors/unmanaged-session.error.ts
|
|
98
|
+
/**
|
|
99
|
+
* The caller owns the outer transaction (`ctx.session`) but gave cart no way
|
|
100
|
+
* to coordinate event publishing:
|
|
101
|
+
*
|
|
102
|
+
* - no `OutboxStore` (durable row that commits WITH the transaction), AND
|
|
103
|
+
* - no `[PENDING_EVENTS]` queue (post-commit in-process flush).
|
|
104
|
+
*
|
|
105
|
+
* Publishing to in-process subscribers mid-transaction would leak ghost
|
|
106
|
+
* events on rollback, and silently dropping the event loses it entirely —
|
|
107
|
+
* both are worse than failing fast. Safe patterns:
|
|
108
|
+
*
|
|
109
|
+
* 1. `engine.withTransaction(ctx, (txCtx) => …)` — cart owns the unit of
|
|
110
|
+
* work, queues events, and flushes them after commit.
|
|
111
|
+
* 2. Wire an `outbox` — the row commits with your transaction and the
|
|
112
|
+
* host relay delivers post-commit.
|
|
113
|
+
* 3. Manage it yourself: attach `{ ...ctx, [PENDING_EVENTS]: queue }` and
|
|
114
|
+
* call `flushPending(transport, queue)` after your commit.
|
|
115
|
+
*
|
|
116
|
+
* `PENDING_EVENTS` and `flushPending` are exported from '@classytic/cart'.
|
|
117
|
+
*/
|
|
118
|
+
var UnmanagedSessionError = class extends CartError {
|
|
119
|
+
code = "cart/transaction_unmanaged_session";
|
|
120
|
+
category = "system";
|
|
121
|
+
retryable = false;
|
|
122
|
+
constructor() {
|
|
123
|
+
super("ctx.session was provided without an outbox or a PENDING_EVENTS queue — cart cannot publish events safely inside a transaction it does not own. Use engine.withTransaction(ctx, fn), wire an OutboxStore, or attach a PENDING_EVENTS queue and flushPending() after commit.");
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
//#endregion
|
|
127
|
+
export { ConcurrencyError as a, NotFoundError as i, StaleQuoteError as n, PriceChangedError as r, UnmanagedSessionError as t };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { t as KindError } from "./kind.error-DIaJpdUb.mjs";
|
|
2
|
+
import { CURRENCY_PATTERN } from "@classytic/primitives/currency";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
//#region src/kinds/bundle.kind.ts
|
|
4
5
|
const bundlePayloadSchema = z.object({
|
|
@@ -117,7 +118,7 @@ const serviceFeePayloadSchema = z.object({
|
|
|
117
118
|
label: z.string().min(1).max(120),
|
|
118
119
|
unitPrice: z.object({
|
|
119
120
|
amount: z.number().int().nonnegative(),
|
|
120
|
-
currency: z.string().
|
|
121
|
+
currency: z.string().regex(CURRENCY_PATTERN, "ISO 4217 (3 uppercase letters)")
|
|
121
122
|
})
|
|
122
123
|
});
|
|
123
124
|
const serviceFeeKind = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/cart",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Framework-agnostic universal cart engine for commerce — drafts, checkouts, reservations, the LineKind strategy, and a disciplined finalization saga. Powered by MongoDB via @classytic/mongokit. Zero framework deps — usable from Arc, Express, Nest, Next.js, or raw Node.",
|
|
5
5
|
"author": "Classytic",
|
|
6
6
|
"type": "module",
|
|
@@ -83,18 +83,18 @@
|
|
|
83
83
|
"release": "npm run push -- main && npm run release:tag && npm publish"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@classytic/mongokit": ">=3.
|
|
87
|
-
"@classytic/primitives": ">=0.
|
|
88
|
-
"@classytic/repo-core": ">=0.
|
|
86
|
+
"@classytic/mongokit": ">=3.18.0",
|
|
87
|
+
"@classytic/primitives": ">=0.9.1",
|
|
88
|
+
"@classytic/repo-core": ">=0.7.0",
|
|
89
89
|
"mongoose": ">=9.4.1",
|
|
90
90
|
"zod": ">=4.0.0"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@biomejs/biome": "^2.4.13",
|
|
94
94
|
"@classytic/dev-tools": "^0.2.0",
|
|
95
|
-
"@classytic/mongokit": "
|
|
95
|
+
"@classytic/mongokit": "^3.18.0",
|
|
96
96
|
"@classytic/primitives": ">=0.5.0",
|
|
97
|
-
"@classytic/repo-core": "
|
|
97
|
+
"@classytic/repo-core": "^0.7.0",
|
|
98
98
|
"@types/node": "^25.5.0",
|
|
99
99
|
"knip": "^6.7.0",
|
|
100
100
|
"mongodb-memory-server": "^10.2.3",
|
|
File without changes
|
|
File without changes
|