@classytic/cart 0.1.0 → 0.1.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/README.md +1 -10
- package/dist/{create-cart-q3CXxPP7.mjs → create-cart-DRYSw5Bj.mjs} +585 -539
- package/dist/domain/errors/index.d.mts +1 -1
- package/dist/domain/errors/index.mjs +2 -2
- package/dist/domain/events/index.mjs +1 -1
- package/dist/domain/index.d.mts +8 -8
- package/dist/domain/index.mjs +5 -5
- package/dist/domain/ports/index.d.mts +2 -2
- package/dist/domain/saga/index.d.mts +2 -2
- package/dist/domain/saga/index.mjs +2 -2
- package/dist/engine/index.d.mts +1 -1
- package/dist/engine/index.mjs +1 -1
- package/dist/{errors-CHR9RlbY.mjs → errors-iFWUnl8m.mjs} +26 -26
- package/dist/{index-Doi5uzux.d.mts → index-PD-kf5pR.d.mts} +67 -67
- package/dist/index.d.mts +70 -55
- package/dist/index.mjs +44 -44
- package/dist/{internal-event-bus-IkUfQJxn.d.mts → internal-event-bus-BGcwAeqK.d.mts} +108 -83
- package/dist/{line-item.entity-B3M_i-pw.d.mts → kind-registry-CqOJHV-2.d.mts} +52 -52
- package/dist/kinds/index.d.mts +1 -1
- package/dist/kinds/index.mjs +1 -1
- package/dist/{line-kind-Bndo6IS8.d.mts → line-kind-DOYygKG4.d.mts} +1 -1
- package/dist/{cart-event-catalog-BOP9aDhL.mjs → outbox-store-bP30uBXd.mjs} +30 -30
- package/dist/{idempotency-record.entity-DIFXjN1V.d.mts → reservation.entity-gmeCFe8a.d.mts} +71 -71
- package/dist/{saga-steps-B27LI7xp.mjs → saga-steps-aP8iTHT3.mjs} +1 -2
- package/dist/{shipping.bridge-DD4A_O0O.d.mts → shipping.bridge-_VwuKCSE.d.mts} +82 -82
- package/dist/{not-found.error-B6WYnAjX.mjs → state-transition.error-CML7cQSd.mjs} +22 -22
- package/dist/{saga-step-fn-Cyob38iU.d.mts → state-transitions-CbPYzeca.d.mts} +20 -29
- package/dist/{bundle.kind-DFydSxV_.mjs → variant.kind-BpEzENX-.mjs} +132 -132
- package/dist/{bundle.kind-BdgnyKZt.d.mts → variant.kind-CCwwWAB6.d.mts} +51 -51
- package/package.json +12 -5
- /package/dist/{id.port-DPXLrqb2.d.mts → id.port-CpYO7sc1.d.mts} +0 -0
- /package/dist/{index-DEHBdV_z.d.mts → index-DNLi60D-.d.mts} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,54 +1,17 @@
|
|
|
1
1
|
import { t as CART_REF_NEW } from "./idempotency-key.vo-D0lJsvGn.mjs";
|
|
2
2
|
import { n as UnknownKindError, r as CartError, t as KindError } from "./kind.error-CCjTB6kW.mjs";
|
|
3
|
-
import { i as ConcurrencyError, n as
|
|
4
|
-
import { a as ReservationError, i as
|
|
3
|
+
import { i as ConcurrencyError, n as PriceChangedError, r as NotFoundError, t as StateTransitionError } from "./state-transition.error-CML7cQSd.mjs";
|
|
4
|
+
import { a as ReservationError, i as SagaError, n as IdempotencyBusyError, r as IdempotencyStorageError, t as StaleQuoteError } from "./errors-iFWUnl8m.mjs";
|
|
5
5
|
import { n as CartEvents, t as createCartEvent } from "./domain-event-DHNkz15G.mjs";
|
|
6
|
-
import { a as
|
|
6
|
+
import { a as cartEventsByName, i as cartEventDefinitions, n as MemoryOutboxStore, o as createCartEventRegistry, r as OutboxOwnershipError, s as defineCartEvent, t as InvalidOutboxEventError } from "./outbox-store-bP30uBXd.mjs";
|
|
7
7
|
import { n as cryptoIdPort, r as systemClock, t as createCounterIdPort } from "./id.port-C3rlDAKP.mjs";
|
|
8
8
|
import { t as createKindRegistry } from "./kind-registry-Ba4PO4WC.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { t as CheckoutStep } from "./saga-steps-aP8iTHT3.mjs";
|
|
10
10
|
import { n as isLegalCheckoutTransition, t as CHECKOUT_STATE_TRANSITIONS } from "./state-transitions-CpJpZZTK.mjs";
|
|
11
|
-
import { a as
|
|
12
|
-
import { a as
|
|
11
|
+
import { a as IdempotencyRepository, c as CheckoutRepository, d as createIdempotencyModel, f as createDraftModel, i as ReservationRepository, l as createCartModels, n as InProcessCartEventBus, o as DraftRepository, p as createCheckoutModel, r as createCartRepositories, s as runPricing, t as createCart, u as createReservationModel } from "./create-cart-DRYSw5Bj.mjs";
|
|
12
|
+
import { a as skuKind, c as bundlePayloadSchema, i as timeslotPayloadSchema, n as variantPayloadSchema, o as skuPayloadSchema, r as timeslotKind, s as bundleKind, t as variantKind } from "./variant.kind-BpEzENX-.mjs";
|
|
13
13
|
import { cartConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./engine/cart-config.schema.mjs";
|
|
14
14
|
import { addMoney, fromMajor, money, multiplyMoney, subtractMoney, sumMoney, toMajor } from "@classytic/primitives/money";
|
|
15
|
-
//#region src/services/merge.service.ts
|
|
16
|
-
/**
|
|
17
|
-
* Merge a guest (session-scoped) draft into an authenticated user's
|
|
18
|
-
* active draft on login.
|
|
19
|
-
*
|
|
20
|
-
* Merge strategy: iterate the source's lines. For each line, if a line
|
|
21
|
-
* with the same `(kind, skuRef)` exists in the target, increment the
|
|
22
|
-
* target's quantity. Otherwise, append. Display snapshots carry over
|
|
23
|
-
* from the source since they're already captured.
|
|
24
|
-
*
|
|
25
|
-
* After merging, the source draft is marked `abandoned` so it's no
|
|
26
|
-
* longer active.
|
|
27
|
-
*/
|
|
28
|
-
async function mergeDrafts(opts) {
|
|
29
|
-
const { repo, sourcePublicId, targetActorRef, ctx } = opts;
|
|
30
|
-
const source = await repo.findByPublicId(sourcePublicId, ctx);
|
|
31
|
-
if (!source || source.status !== "active") throw new Error(`Source draft '${sourcePublicId}' not found or not active`);
|
|
32
|
-
const targetCtx = {
|
|
33
|
-
...ctx,
|
|
34
|
-
actorRef: targetActorRef
|
|
35
|
-
};
|
|
36
|
-
const target = await repo.findActiveByActor(targetActorRef, targetCtx);
|
|
37
|
-
if (!target) return repo.updateWithVersion(source._id, source.version, {
|
|
38
|
-
actorRef: targetActorRef,
|
|
39
|
-
actorKind: "user"
|
|
40
|
-
}, ctx);
|
|
41
|
-
const sourceLines = source.lines;
|
|
42
|
-
const currentTargetLines = target.lines;
|
|
43
|
-
const mergedLines = repo.mergeLines(currentTargetLines, sourceLines);
|
|
44
|
-
const updated = await repo.replaceLines({
|
|
45
|
-
draftPublicId: target.publicId,
|
|
46
|
-
lines: mergedLines
|
|
47
|
-
}, targetCtx);
|
|
48
|
-
await repo.markAbandoned(source._id, ctx);
|
|
49
|
-
return updated;
|
|
50
|
-
}
|
|
51
|
-
//#endregion
|
|
52
15
|
//#region src/services/abandonment.service.ts
|
|
53
16
|
/**
|
|
54
17
|
* Abandonment query primitives. Hosts call these from their own cron
|
|
@@ -89,4 +52,41 @@ async function markAbandoned(opts) {
|
|
|
89
52
|
return count;
|
|
90
53
|
}
|
|
91
54
|
//#endregion
|
|
92
|
-
|
|
55
|
+
//#region src/services/merge.service.ts
|
|
56
|
+
/**
|
|
57
|
+
* Merge a guest (session-scoped) draft into an authenticated user's
|
|
58
|
+
* active draft on login.
|
|
59
|
+
*
|
|
60
|
+
* Merge strategy: iterate the source's lines. For each line, if a line
|
|
61
|
+
* with the same `(kind, skuRef)` exists in the target, increment the
|
|
62
|
+
* target's quantity. Otherwise, append. Display snapshots carry over
|
|
63
|
+
* from the source since they're already captured.
|
|
64
|
+
*
|
|
65
|
+
* After merging, the source draft is marked `abandoned` so it's no
|
|
66
|
+
* longer active.
|
|
67
|
+
*/
|
|
68
|
+
async function mergeDrafts(opts) {
|
|
69
|
+
const { repo, sourcePublicId, targetActorRef, ctx } = opts;
|
|
70
|
+
const source = await repo.findByPublicId(sourcePublicId, ctx);
|
|
71
|
+
if (!source || source.status !== "active") throw new Error(`Source draft '${sourcePublicId}' not found or not active`);
|
|
72
|
+
const targetCtx = {
|
|
73
|
+
...ctx,
|
|
74
|
+
actorRef: targetActorRef
|
|
75
|
+
};
|
|
76
|
+
const target = await repo.findActiveByActor(targetActorRef, targetCtx);
|
|
77
|
+
if (!target) return repo.updateWithVersion(source._id, source.version, {
|
|
78
|
+
actorRef: targetActorRef,
|
|
79
|
+
actorKind: "user"
|
|
80
|
+
}, ctx);
|
|
81
|
+
const sourceLines = source.lines;
|
|
82
|
+
const currentTargetLines = target.lines;
|
|
83
|
+
const mergedLines = repo.mergeLines(currentTargetLines, sourceLines);
|
|
84
|
+
const updated = await repo.replaceLines({
|
|
85
|
+
draftPublicId: target.publicId,
|
|
86
|
+
lines: mergedLines
|
|
87
|
+
}, targetCtx);
|
|
88
|
+
await repo.markAbandoned(source._id, ctx);
|
|
89
|
+
return updated;
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { CART_REF_NEW, CHECKOUT_STATE_TRANSITIONS, CartError, CartEvents, CheckoutRepository, CheckoutStep, ConcurrencyError, DraftRepository, IdempotencyBusyError, IdempotencyRepository, IdempotencyStorageError, InProcessCartEventBus, InvalidOutboxEventError, KindError, MemoryOutboxStore, NotFoundError, OutboxOwnershipError, PriceChangedError, ReservationError, ReservationRepository, SagaError, StaleQuoteError, StateTransitionError, UnknownKindError, addMoney, bundleKind, bundlePayloadSchema, cartConfigSchema, cartEventDefinitions, cartEventsByName, createCart, createCartEvent, createCartEventRegistry, createCartModels, createCartRepositories, createCheckoutModel, createCounterIdPort, createDraftModel, createIdempotencyModel, createKindRegistry, createReservationModel, cryptoIdPort, defineCartEvent, findAbandonedDrafts, fromMajor, idempotencyConfigSchema, isLegalCheckoutTransition, markAbandoned, mergeDrafts, money, multiplyMoney, reservationConfigSchema, runPricing, scopeConfigSchema, skuKind, skuPayloadSchema, subtractMoney, sumMoney, systemClock, timeslotKind, timeslotPayloadSchema, toMajor, variantKind, variantPayloadSchema };
|
|
@@ -1,45 +1,14 @@
|
|
|
1
1
|
import { b as CartEventName, d as OutboxStore, h as CartDomainEvent, x as CartEventPayload } from "./outbox-store-CTWz9pvG.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { i as ClockPort, t as IdPort } from "./id.port-
|
|
2
|
+
import { _ as PromotionsBridge, f as CatalogBridge, l as InventoryBridge, o as TaxBridge, t as ShippingBridge, x as OperationContext } from "./shipping.bridge-_VwuKCSE.mjs";
|
|
3
|
+
import { l as LineDisplay, r as LineKind } from "./line-kind-DOYygKG4.mjs";
|
|
4
|
+
import { c as LineItem, i as IdempotencyIdentity, t as KindRegistry } from "./kind-registry-CqOJHV-2.mjs";
|
|
5
|
+
import { i as ClockPort, t as IdPort } from "./id.port-CpYO7sc1.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
9
|
import { Connection, Document, Model, Types } from "mongoose";
|
|
10
10
|
import { PluginType, Repository } from "@classytic/mongokit";
|
|
11
11
|
|
|
12
|
-
//#region src/models/draft.model.d.ts
|
|
13
|
-
/**
|
|
14
|
-
* DraftDocument — Mongoose persistence shape for cart drafts.
|
|
15
|
-
*
|
|
16
|
-
* Mirrors the pure domain `Draft` entity in
|
|
17
|
-
* `domain/entities/draft.entity.ts` but carries Mongoose-specific details
|
|
18
|
-
* (subdocument schemas, indexes, defaults). Repositories return these
|
|
19
|
-
* lean objects; services cast to the domain type at the service boundary.
|
|
20
|
-
*/
|
|
21
|
-
interface DraftDocument extends Document {
|
|
22
|
-
publicId: string;
|
|
23
|
-
organizationId: string;
|
|
24
|
-
actorRef: string;
|
|
25
|
-
actorKind: 'user' | 'session';
|
|
26
|
-
status: 'active' | 'abandoned' | 'converted' | 'expired';
|
|
27
|
-
lines: Array<Record<string, unknown>>;
|
|
28
|
-
adjustments: Array<Record<string, unknown>>;
|
|
29
|
-
currency: string;
|
|
30
|
-
pricing: Record<string, unknown> | null;
|
|
31
|
-
version: number;
|
|
32
|
-
expiresAt?: Date | null;
|
|
33
|
-
lastIdempotencyKey?: string;
|
|
34
|
-
metadata?: Record<string, unknown>;
|
|
35
|
-
privateMetadata?: Record<string, unknown>;
|
|
36
|
-
createdAt: Date;
|
|
37
|
-
updatedAt: Date;
|
|
38
|
-
}
|
|
39
|
-
declare function createDraftModel(connection: Connection, opts?: {
|
|
40
|
-
collectionPrefix?: string | undefined;
|
|
41
|
-
}): Model<DraftDocument>;
|
|
42
|
-
//#endregion
|
|
43
12
|
//#region src/models/checkout.model.d.ts
|
|
44
13
|
/**
|
|
45
14
|
* CheckoutDocument — locked snapshot with a minimal state field.
|
|
@@ -72,38 +41,36 @@ declare function createCheckoutModel(connection: Connection, opts?: {
|
|
|
72
41
|
collectionPrefix?: string | undefined;
|
|
73
42
|
}): Model<CheckoutDocument>;
|
|
74
43
|
//#endregion
|
|
75
|
-
//#region src/models/
|
|
44
|
+
//#region src/models/draft.model.d.ts
|
|
76
45
|
/**
|
|
77
|
-
*
|
|
46
|
+
* DraftDocument — Mongoose persistence shape for cart drafts.
|
|
78
47
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
48
|
+
* Mirrors the pure domain `Draft` entity in
|
|
49
|
+
* `domain/entities/draft.entity.ts` but carries Mongoose-specific details
|
|
50
|
+
* (subdocument schemas, indexes, defaults). Repositories return these
|
|
51
|
+
* lean objects; services cast to the domain type at the service boundary.
|
|
83
52
|
*/
|
|
84
|
-
interface
|
|
53
|
+
interface DraftDocument extends Document {
|
|
85
54
|
publicId: string;
|
|
86
55
|
organizationId: string;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
quantity: number;
|
|
95
|
-
status: 'held' | 'committed' | 'released' | 'expired';
|
|
96
|
-
heldAt: Date;
|
|
97
|
-
expiresAt: Date;
|
|
98
|
-
releasedAt?: Date | null;
|
|
99
|
-
releaseReason?: 'compensation' | 'expired' | 'canceled' | 'manual' | null;
|
|
56
|
+
actorRef: string;
|
|
57
|
+
actorKind: 'user' | 'session';
|
|
58
|
+
status: 'active' | 'abandoned' | 'converted' | 'expired';
|
|
59
|
+
lines: Array<Record<string, unknown>>;
|
|
60
|
+
adjustments: Array<Record<string, unknown>>;
|
|
61
|
+
currency: string;
|
|
62
|
+
pricing: Record<string, unknown> | null;
|
|
100
63
|
version: number;
|
|
64
|
+
expiresAt?: Date | null;
|
|
65
|
+
lastIdempotencyKey?: string;
|
|
66
|
+
metadata?: Record<string, unknown>;
|
|
67
|
+
privateMetadata?: Record<string, unknown>;
|
|
101
68
|
createdAt: Date;
|
|
102
69
|
updatedAt: Date;
|
|
103
70
|
}
|
|
104
|
-
declare function
|
|
71
|
+
declare function createDraftModel(connection: Connection, opts?: {
|
|
105
72
|
collectionPrefix?: string | undefined;
|
|
106
|
-
}): Model<
|
|
73
|
+
}): Model<DraftDocument>;
|
|
107
74
|
//#endregion
|
|
108
75
|
//#region src/models/idempotency.model.d.ts
|
|
109
76
|
/**
|
|
@@ -137,6 +104,39 @@ declare function createIdempotencyModel(connection: Connection, opts?: {
|
|
|
137
104
|
collectionPrefix?: string | undefined;
|
|
138
105
|
}): Model<IdempotencyDocument>;
|
|
139
106
|
//#endregion
|
|
107
|
+
//#region src/models/reservation.model.d.ts
|
|
108
|
+
/**
|
|
109
|
+
* ReservationDocument — one hold produced by InventoryBridge.reserve().
|
|
110
|
+
*
|
|
111
|
+
* Lives in its own collection so the host can run keyset-paginated
|
|
112
|
+
* scans without materialising the whole checkout. The TTL index is a
|
|
113
|
+
* garbage-collector backstop for already-released docs — the explicit
|
|
114
|
+
* sweeper is the release mechanism (see plan §4).
|
|
115
|
+
*/
|
|
116
|
+
interface ReservationDocument extends Document {
|
|
117
|
+
publicId: string;
|
|
118
|
+
organizationId: string;
|
|
119
|
+
checkoutId: Types.ObjectId;
|
|
120
|
+
lineId: string;
|
|
121
|
+
bridgeRef: {
|
|
122
|
+
id: string;
|
|
123
|
+
payload: unknown;
|
|
124
|
+
};
|
|
125
|
+
skuRef: string;
|
|
126
|
+
quantity: number;
|
|
127
|
+
status: 'held' | 'committed' | 'released' | 'expired';
|
|
128
|
+
heldAt: Date;
|
|
129
|
+
expiresAt: Date;
|
|
130
|
+
releasedAt?: Date | null;
|
|
131
|
+
releaseReason?: 'compensation' | 'expired' | 'canceled' | 'manual' | null;
|
|
132
|
+
version: number;
|
|
133
|
+
createdAt: Date;
|
|
134
|
+
updatedAt: Date;
|
|
135
|
+
}
|
|
136
|
+
declare function createReservationModel(connection: Connection, opts?: {
|
|
137
|
+
collectionPrefix?: string | undefined;
|
|
138
|
+
}): Model<ReservationDocument>;
|
|
139
|
+
//#endregion
|
|
140
140
|
//#region src/models/index.d.ts
|
|
141
141
|
/** Union of all cart model names used as keys in `CartModels`. */
|
|
142
142
|
type CartModelName = 'Draft' | 'Checkout' | 'Reservation' | 'Idempotency';
|
|
@@ -345,35 +345,34 @@ declare class CheckoutRepository extends Repository<CheckoutDocument> {
|
|
|
345
345
|
reason: string;
|
|
346
346
|
}, ctx: OperationContext): Promise<CheckoutDocument>;
|
|
347
347
|
updateWithVersion(checkoutId: Types.ObjectId | string, expectedVersion: number, updates: Record<string, unknown>, ctx: OperationContext): Promise<CheckoutDocument>;
|
|
348
|
-
private readOptions;
|
|
349
|
-
private writeOptions;
|
|
350
|
-
private requireCheckout;
|
|
351
|
-
}
|
|
352
|
-
//#endregion
|
|
353
|
-
//#region src/repositories/reservation.repository.d.ts
|
|
354
|
-
/**
|
|
355
|
-
* ReservationRepository — extends mongokit's `Repository<ReservationDocument>`.
|
|
356
|
-
*
|
|
357
|
-
* Tenant scoping is enforced by `multiTenantPlugin`; `publicId` comes from
|
|
358
|
-
* `customIdPlugin`. The TTL index on `expiresAt` is a backstop — the
|
|
359
|
-
* sweeper drives the active release loop via `findExpiredHeld`.
|
|
360
|
-
*/
|
|
361
|
-
declare class ReservationRepository extends Repository<ReservationDocument> {
|
|
362
|
-
constructor(model: Model<ReservationDocument>, plugins: PluginType[]);
|
|
363
|
-
/** All reservations belonging to a checkout. */
|
|
364
|
-
findByCheckout(checkoutId: Types.ObjectId | string, ctx: OperationContext): Promise<ReservationDocument[]>;
|
|
365
348
|
/**
|
|
366
|
-
*
|
|
367
|
-
*
|
|
349
|
+
* Transition `open` checkouts older than `maxAgeMs` to `canceled` with
|
|
350
|
+
* `canceledReason: 'expired'`. Pure business expiry — host-driven, no
|
|
351
|
+
* TTL.
|
|
352
|
+
*
|
|
353
|
+
* Why this exists: a checkout left in `open` (browser closed before
|
|
354
|
+
* commit/cancel, mobile app crash, network drop after the freeze step)
|
|
355
|
+
* holds the partial-unique slot for that draft. Without expiry, the
|
|
356
|
+
* customer's next attempt collides with their own zombie. Hosts should
|
|
357
|
+
* call this from a periodic job (cron, Streamline, etc.) at whatever
|
|
358
|
+
* cadence matches their checkout completion SLA.
|
|
359
|
+
*
|
|
360
|
+
* Returns the count of rows expired. Caller scopes the operation via
|
|
361
|
+
* `ctx` — pass `ctx.organizationId` to scope to one tenant, or use
|
|
362
|
+
* `skipTenant: true` to expire across the board (only safe for the
|
|
363
|
+
* platform's own background worker, not an end-user request).
|
|
364
|
+
*
|
|
365
|
+
* Does NOT emit `CHECKOUT_CANCELED` events for the expired rows.
|
|
366
|
+
* Expiry is a janitorial action; if hosts need an event for analytics
|
|
367
|
+
* they can subscribe to a downstream tail of the audit trail or wrap
|
|
368
|
+
* this method.
|
|
368
369
|
*/
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
/** Atomic transition `held → committed` on saga step 10. */
|
|
373
|
-
markCommitted(reservationId: Types.ObjectId | string, expectedVersion: number, ctx: OperationContext): Promise<ReservationDocument | null>;
|
|
374
|
-
private atomicTransition;
|
|
370
|
+
expireStaleOpenCheckouts(maxAgeMs: number, ctx: OperationContext): Promise<{
|
|
371
|
+
count: number;
|
|
372
|
+
}>;
|
|
375
373
|
private readOptions;
|
|
376
374
|
private writeOptions;
|
|
375
|
+
private requireCheckout;
|
|
377
376
|
}
|
|
378
377
|
//#endregion
|
|
379
378
|
//#region src/repositories/idempotency.repository.d.ts
|
|
@@ -422,6 +421,32 @@ declare class IdempotencyRepository extends Repository<IdempotencyDocument> {
|
|
|
422
421
|
}, ctx: OperationContext): Promise<IdempotencyDocument | null>;
|
|
423
422
|
}
|
|
424
423
|
//#endregion
|
|
424
|
+
//#region src/repositories/reservation.repository.d.ts
|
|
425
|
+
/**
|
|
426
|
+
* ReservationRepository — extends mongokit's `Repository<ReservationDocument>`.
|
|
427
|
+
*
|
|
428
|
+
* Tenant scoping is enforced by `multiTenantPlugin`; `publicId` comes from
|
|
429
|
+
* `customIdPlugin`. The TTL index on `expiresAt` is a backstop — the
|
|
430
|
+
* sweeper drives the active release loop via `findExpiredHeld`.
|
|
431
|
+
*/
|
|
432
|
+
declare class ReservationRepository extends Repository<ReservationDocument> {
|
|
433
|
+
constructor(model: Model<ReservationDocument>, plugins: PluginType[]);
|
|
434
|
+
/** All reservations belonging to a checkout. */
|
|
435
|
+
findByCheckout(checkoutId: Types.ObjectId | string, ctx: OperationContext): Promise<ReservationDocument[]>;
|
|
436
|
+
/**
|
|
437
|
+
* Expired held reservations for the sweeper. Routed through `getAll` so
|
|
438
|
+
* the multi-tenant plugin scopes the query at POLICY priority.
|
|
439
|
+
*/
|
|
440
|
+
findExpiredHeld(asOf: Date, limit: number, ctx: OperationContext): Promise<ReservationDocument[]>;
|
|
441
|
+
/** Atomic transition `held → released` via version check. */
|
|
442
|
+
markReleased(reservationId: Types.ObjectId | string, expectedVersion: number, reason: 'compensation' | 'expired' | 'canceled' | 'manual', ctx: OperationContext): Promise<ReservationDocument | null>;
|
|
443
|
+
/** Atomic transition `held → committed` on saga step 10. */
|
|
444
|
+
markCommitted(reservationId: Types.ObjectId | string, expectedVersion: number, ctx: OperationContext): Promise<ReservationDocument | null>;
|
|
445
|
+
private atomicTransition;
|
|
446
|
+
private readOptions;
|
|
447
|
+
private writeOptions;
|
|
448
|
+
}
|
|
449
|
+
//#endregion
|
|
425
450
|
//#region src/repositories/index.d.ts
|
|
426
451
|
/**
|
|
427
452
|
* CartRepositories — the bundle returned by `createCartRepositories()`.
|
|
@@ -658,4 +683,4 @@ declare class InProcessCartEventBus implements EventTransport {
|
|
|
658
683
|
close(): Promise<void>;
|
|
659
684
|
}
|
|
660
685
|
//#endregion
|
|
661
|
-
export {
|
|
686
|
+
export { IdempotencyDocument as C, CheckoutDocument as D, createDraftModel as E, createCheckoutModel as O, createReservationModel as S, DraftDocument as T, CartModelName as _, CartEngine as a, createCartModels as b, CreateCartRepositoriesConfig as c, IdempotencyRepository as d, CheckoutRepository as f, CartEventPublisherDeps as g, DraftRepositoryDeps as h, CartConfig as i, createCartRepositories as l, DraftRepository as m, createCart as n, CartRepositories as o, CheckoutRepositoryDeps as p, CartBridges as r, CartRepositoryPluginBundle as s, InProcessCartEventBus as t, ReservationRepository as u, CartModels as v, createIdempotencyModel as w, ReservationDocument as x, CreateCartModelsOptions as y };
|
|
@@ -1,7 +1,57 @@
|
|
|
1
|
-
import { l as LineDisplay, r as LineKind } from "./line-kind-
|
|
1
|
+
import { l as LineDisplay, r as LineKind } from "./line-kind-DOYygKG4.mjs";
|
|
2
2
|
import * as _$_classytic_primitives_money0 from "@classytic/primitives/money";
|
|
3
3
|
import { Money } from "@classytic/primitives/money";
|
|
4
4
|
|
|
5
|
+
//#region src/domain/entities/line-item.entity.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* LineItem — a single row inside a Draft or Checkout.
|
|
8
|
+
*
|
|
9
|
+
* Structurally identical on both entities (drafts carry mutable lines;
|
|
10
|
+
* checkouts carry frozen snapshots). The `kind` field selects which
|
|
11
|
+
* LineKind strategy owns the payload's schema, validation, pricing,
|
|
12
|
+
* reservation, and finalization.
|
|
13
|
+
*
|
|
14
|
+
* `payload` is intentionally `unknown` at the entity layer — the kind's
|
|
15
|
+
* zod schema narrows it at the boundary. Downstream consumers that know
|
|
16
|
+
* the kind cast via helpers.
|
|
17
|
+
*
|
|
18
|
+
* **`display` is the denormalized UI snapshot.** Populated by
|
|
19
|
+
* `LineKind.displayOf()` at add-time, it lets the UI render the cart
|
|
20
|
+
* without a second catalog call per line. See `LineDisplay` for the
|
|
21
|
+
* full contract.
|
|
22
|
+
*/
|
|
23
|
+
interface LineItem<TPayload = unknown> {
|
|
24
|
+
/** Stable line ID — ObjectId string form, generated at creation. */
|
|
25
|
+
lineId: string;
|
|
26
|
+
/** Kind name — key into the KindRegistry. */
|
|
27
|
+
kind: string;
|
|
28
|
+
/**
|
|
29
|
+
* Opaque kind-specific data. Validated by the kind's payloadSchema at
|
|
30
|
+
* the draft service boundary.
|
|
31
|
+
*/
|
|
32
|
+
payload: TPayload;
|
|
33
|
+
/** Units. Always a positive integer. */
|
|
34
|
+
quantity: number;
|
|
35
|
+
/**
|
|
36
|
+
* Optional unit-price override — when the host wants to force a price
|
|
37
|
+
* regardless of what the kind would compute. Used by admin tools and
|
|
38
|
+
* special-deal flows. Kinds that honor overrides do so in their price()
|
|
39
|
+
* implementation; kinds that reject overrides throw KindError.
|
|
40
|
+
*/
|
|
41
|
+
overrideUnitPrice?: _$_classytic_primitives_money0.Money;
|
|
42
|
+
/**
|
|
43
|
+
* Denormalized display snapshot for UI rendering. Populated by the
|
|
44
|
+
* kind's `displayOf()` method at add-time. Kept fresh via
|
|
45
|
+
* `LineKind.revalidate()` when the line becomes stale. Optional —
|
|
46
|
+
* hosts that prefer live-read rendering can leave it unset.
|
|
47
|
+
*/
|
|
48
|
+
display?: LineDisplay;
|
|
49
|
+
/** Created-at timestamp. */
|
|
50
|
+
addedAt: Date;
|
|
51
|
+
/** Optional metadata — public-facing. */
|
|
52
|
+
metadata?: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
5
55
|
//#region src/domain/value-objects/idempotency-key.vo.d.ts
|
|
6
56
|
/**
|
|
7
57
|
* The closed set of operations that participate in the idempotency contract.
|
|
@@ -104,54 +154,4 @@ interface KindRegistry {
|
|
|
104
154
|
*/
|
|
105
155
|
declare function createKindRegistry(kinds: readonly LineKind[]): KindRegistry;
|
|
106
156
|
//#endregion
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* LineItem — a single row inside a Draft or Checkout.
|
|
110
|
-
*
|
|
111
|
-
* Structurally identical on both entities (drafts carry mutable lines;
|
|
112
|
-
* checkouts carry frozen snapshots). The `kind` field selects which
|
|
113
|
-
* LineKind strategy owns the payload's schema, validation, pricing,
|
|
114
|
-
* reservation, and finalization.
|
|
115
|
-
*
|
|
116
|
-
* `payload` is intentionally `unknown` at the entity layer — the kind's
|
|
117
|
-
* zod schema narrows it at the boundary. Downstream consumers that know
|
|
118
|
-
* the kind cast via helpers.
|
|
119
|
-
*
|
|
120
|
-
* **`display` is the denormalized UI snapshot.** Populated by
|
|
121
|
-
* `LineKind.displayOf()` at add-time, it lets the UI render the cart
|
|
122
|
-
* without a second catalog call per line. See `LineDisplay` for the
|
|
123
|
-
* full contract.
|
|
124
|
-
*/
|
|
125
|
-
interface LineItem<TPayload = unknown> {
|
|
126
|
-
/** Stable line ID — ObjectId string form, generated at creation. */
|
|
127
|
-
lineId: string;
|
|
128
|
-
/** Kind name — key into the KindRegistry. */
|
|
129
|
-
kind: string;
|
|
130
|
-
/**
|
|
131
|
-
* Opaque kind-specific data. Validated by the kind's payloadSchema at
|
|
132
|
-
* the draft service boundary.
|
|
133
|
-
*/
|
|
134
|
-
payload: TPayload;
|
|
135
|
-
/** Units. Always a positive integer. */
|
|
136
|
-
quantity: number;
|
|
137
|
-
/**
|
|
138
|
-
* Optional unit-price override — when the host wants to force a price
|
|
139
|
-
* regardless of what the kind would compute. Used by admin tools and
|
|
140
|
-
* special-deal flows. Kinds that honor overrides do so in their price()
|
|
141
|
-
* implementation; kinds that reject overrides throw KindError.
|
|
142
|
-
*/
|
|
143
|
-
overrideUnitPrice?: _$_classytic_primitives_money0.Money;
|
|
144
|
-
/**
|
|
145
|
-
* Denormalized display snapshot for UI rendering. Populated by the
|
|
146
|
-
* kind's `displayOf()` method at add-time. Kept fresh via
|
|
147
|
-
* `LineKind.revalidate()` when the line becomes stale. Optional —
|
|
148
|
-
* hosts that prefer live-read rendering can leave it unset.
|
|
149
|
-
*/
|
|
150
|
-
display?: LineDisplay;
|
|
151
|
-
/** Created-at timestamp. */
|
|
152
|
-
addedAt: Date;
|
|
153
|
-
/** Optional metadata — public-facing. */
|
|
154
|
-
metadata?: Record<string, unknown>;
|
|
155
|
-
}
|
|
156
|
-
//#endregion
|
|
157
|
-
export { IdempotencyIdentity as a, TotalsSnapshot as c, CART_REF_NEW as i, KindRegistry as n, IdempotencyReplay as o, createKindRegistry as r, OperationName as s, LineItem as t };
|
|
157
|
+
export { IdempotencyReplay as a, LineItem as c, IdempotencyIdentity as i, createKindRegistry as n, OperationName as o, CART_REF_NEW as r, TotalsSnapshot as s, KindRegistry as t };
|
package/dist/kinds/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as timeslotKind, c as skuKind, d as BundlePayload, f as bundleKind, i as TimeslotPayload, l as skuPayloadSchema, n as variantKind, o as timeslotPayloadSchema, p as bundlePayloadSchema, r as variantPayloadSchema, s as SkuPayload, t as VariantPayload, u as BundleComponent } from "../variant.kind-CCwwWAB6.mjs";
|
|
2
2
|
export { type BundleComponent, type BundlePayload, type SkuPayload, type TimeslotPayload, type VariantPayload, bundleKind, bundlePayloadSchema, skuKind, skuPayloadSchema, timeslotKind, timeslotPayloadSchema, variantKind, variantPayloadSchema };
|
package/dist/kinds/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as skuKind, c as bundlePayloadSchema, i as timeslotPayloadSchema, n as variantPayloadSchema, o as skuPayloadSchema, r as timeslotKind, s as bundleKind, t as variantKind } from "../variant.kind-BpEzENX-.mjs";
|
|
2
2
|
export { bundleKind, bundlePayloadSchema, skuKind, skuPayloadSchema, timeslotKind, timeslotPayloadSchema, variantKind, variantPayloadSchema };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as PricedLine,
|
|
1
|
+
import { S as PricedLine, _ as PromotionsBridge, f as CatalogBridge, l as InventoryBridge, o as TaxBridge, t as ShippingBridge, u as ReservationRef, x as OperationContext } from "./shipping.bridge-_VwuKCSE.mjs";
|
|
2
2
|
import { Money } from "@classytic/primitives/money";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
@@ -89,35 +89,6 @@ function builtInMinimalValidate(payload, schema) {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
//#endregion
|
|
92
|
-
//#region src/domain/events/outbox-store.ts
|
|
93
|
-
/**
|
|
94
|
-
* In-memory OutboxStore for tests and local dev. Not for production.
|
|
95
|
-
*
|
|
96
|
-
* Implements the required trio (`save` / `getPending` / `acknowledge`) plus
|
|
97
|
-
* optional `purge`. The lease-based methods (`claimPending` / `fail` /
|
|
98
|
-
* `getDeadLettered`) are intentionally omitted — single-process tests don't
|
|
99
|
-
* need them, and cart's publisher only calls `save()`.
|
|
100
|
-
*/
|
|
101
|
-
var MemoryOutboxStore = class {
|
|
102
|
-
events = [];
|
|
103
|
-
async save(event, _options) {
|
|
104
|
-
this.events.push({ event });
|
|
105
|
-
}
|
|
106
|
-
async getPending(limit) {
|
|
107
|
-
return this.events.filter((e) => !e.acknowledgedAt).slice(0, limit).map((e) => e.event);
|
|
108
|
-
}
|
|
109
|
-
async acknowledge(eventId, _options) {
|
|
110
|
-
const entry = this.events.find((e) => e.event.meta.id === eventId);
|
|
111
|
-
if (entry) entry.acknowledgedAt = /* @__PURE__ */ new Date();
|
|
112
|
-
}
|
|
113
|
-
async purge(olderThanMs) {
|
|
114
|
-
const cutoff = Date.now() - olderThanMs;
|
|
115
|
-
const before = this.events.length;
|
|
116
|
-
this.events = this.events.filter((e) => !e.acknowledgedAt || e.acknowledgedAt.getTime() >= cutoff);
|
|
117
|
-
return before - this.events.length;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
//#endregion
|
|
121
92
|
//#region src/domain/events/cart-event-catalog.ts
|
|
122
93
|
/**
|
|
123
94
|
* Cart event catalog — every cart event defined as a registerable
|
|
@@ -298,4 +269,33 @@ const cartEventDefinitions = Object.freeze([
|
|
|
298
269
|
*/
|
|
299
270
|
const cartEventsByName = Object.freeze(Object.fromEntries(cartEventDefinitions.map((def) => [def.name, def])));
|
|
300
271
|
//#endregion
|
|
301
|
-
|
|
272
|
+
//#region src/domain/events/outbox-store.ts
|
|
273
|
+
/**
|
|
274
|
+
* In-memory OutboxStore for tests and local dev. Not for production.
|
|
275
|
+
*
|
|
276
|
+
* Implements the required trio (`save` / `getPending` / `acknowledge`) plus
|
|
277
|
+
* optional `purge`. The lease-based methods (`claimPending` / `fail` /
|
|
278
|
+
* `getDeadLettered`) are intentionally omitted — single-process tests don't
|
|
279
|
+
* need them, and cart's publisher only calls `save()`.
|
|
280
|
+
*/
|
|
281
|
+
var MemoryOutboxStore = class {
|
|
282
|
+
events = [];
|
|
283
|
+
async save(event, _options) {
|
|
284
|
+
this.events.push({ event });
|
|
285
|
+
}
|
|
286
|
+
async getPending(limit) {
|
|
287
|
+
return this.events.filter((e) => !e.acknowledgedAt).slice(0, limit).map((e) => e.event);
|
|
288
|
+
}
|
|
289
|
+
async acknowledge(eventId, _options) {
|
|
290
|
+
const entry = this.events.find((e) => e.event.meta.id === eventId);
|
|
291
|
+
if (entry) entry.acknowledgedAt = /* @__PURE__ */ new Date();
|
|
292
|
+
}
|
|
293
|
+
async purge(olderThanMs) {
|
|
294
|
+
const cutoff = Date.now() - olderThanMs;
|
|
295
|
+
const before = this.events.length;
|
|
296
|
+
this.events = this.events.filter((e) => !e.acknowledgedAt || e.acknowledgedAt.getTime() >= cutoff);
|
|
297
|
+
return before - this.events.length;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
//#endregion
|
|
301
|
+
export { cartEventsByName as a, cartEventDefinitions as i, MemoryOutboxStore as n, createCartEventRegistry as o, OutboxOwnershipError as r, defineCartEvent as s, InvalidOutboxEventError as t };
|