@classytic/cart 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/bundle.kind-BdgnyKZt.d.mts +114 -0
- package/dist/bundle.kind-DFydSxV_.mjs +362 -0
- package/dist/cart-event-catalog-BIbi2Q_n.d.mts +109 -0
- package/dist/cart-event-catalog-BOP9aDhL.mjs +301 -0
- package/dist/cart-status.vo-2iisZGhb.d.mts +46 -0
- package/dist/create-cart-q3CXxPP7.mjs +1751 -0
- package/dist/domain/errors/index.d.mts +2 -0
- package/dist/domain/errors/index.mjs +4 -0
- package/dist/domain/events/index.d.mts +3 -0
- package/dist/domain/events/index.mjs +3 -0
- package/dist/domain/index.d.mts +12 -0
- package/dist/domain/index.mjs +15 -0
- package/dist/domain/ports/index.d.mts +3 -0
- package/dist/domain/ports/index.mjs +2 -0
- package/dist/domain/saga/index.d.mts +2 -0
- package/dist/domain/saga/index.mjs +3 -0
- package/dist/domain-event-DHNkz15G.mjs +57 -0
- package/dist/engine/cart-config.schema.d.mts +41 -0
- package/dist/engine/cart-config.schema.mjs +40 -0
- package/dist/engine/index.d.mts +3 -0
- package/dist/engine/index.mjs +3 -0
- package/dist/errors-CHR9RlbY.mjs +97 -0
- package/dist/id.port-C3rlDAKP.mjs +29 -0
- package/dist/id.port-DPXLrqb2.d.mts +64 -0
- package/dist/idempotency-key.vo-D0lJsvGn.mjs +9 -0
- package/dist/idempotency-record.entity-DIFXjN1V.d.mts +221 -0
- package/dist/index-DEHBdV_z.d.mts +1 -0
- package/dist/index-Doi5uzux.d.mts +231 -0
- package/dist/index.d.mts +103 -0
- package/dist/index.mjs +92 -0
- package/dist/internal-event-bus-IkUfQJxn.d.mts +661 -0
- package/dist/kind-registry-Ba4PO4WC.mjs +35 -0
- package/dist/kind.error-CCjTB6kW.mjs +69 -0
- package/dist/kinds/index.d.mts +2 -0
- package/dist/kinds/index.mjs +2 -0
- package/dist/line-item.entity-B3M_i-pw.d.mts +157 -0
- package/dist/line-kind-Bndo6IS8.d.mts +231 -0
- package/dist/not-found.error-B6WYnAjX.mjs +95 -0
- package/dist/outbox-store-CTWz9pvG.d.mts +155 -0
- package/dist/saga-step-fn-Cyob38iU.d.mts +135 -0
- package/dist/saga-steps-B27LI7xp.mjs +27 -0
- package/dist/shipping.bridge-DD4A_O0O.d.mts +538 -0
- package/dist/state-transitions-CpJpZZTK.mjs +21 -0
- package/package.json +114 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { _ as CartEventMeta, b as CartEventName, h as CartDomainEvent } from "./outbox-store-CTWz9pvG.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/domain/events/event-schema.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* EventSchema — minimal JSON-schema-like shape for event payload validation.
|
|
6
|
+
*
|
|
7
|
+
* Structurally compatible with `@classytic/arc/events` EventSchema so cart
|
|
8
|
+
* event definitions can be registered with arc's EventRegistry without any
|
|
9
|
+
* conversion. Cart does NOT import from arc — compatibility is structural.
|
|
10
|
+
*
|
|
11
|
+
* This is intentionally a lightweight guard, not a full JSON Schema engine.
|
|
12
|
+
* Hosts that want rigorous validation pass a custom validator (AJV, Zod,
|
|
13
|
+
* Temporal's own schema tools, etc.) to their registry factory.
|
|
14
|
+
*/
|
|
15
|
+
interface EventSchema {
|
|
16
|
+
type: 'object';
|
|
17
|
+
properties?: Record<string, EventSchemaProperty>;
|
|
18
|
+
required?: string[];
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface EventSchemaProperty {
|
|
22
|
+
type?: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'null';
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Result returned by a payload validator — structurally compatible with
|
|
27
|
+
* arc's ValidationResult.
|
|
28
|
+
*/
|
|
29
|
+
interface EventValidationResult {
|
|
30
|
+
valid: boolean;
|
|
31
|
+
errors?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A custom validator. Hosts can replace the built-in minimal validator by
|
|
35
|
+
* passing one of these to `createCartEventRegistry({ validate })`.
|
|
36
|
+
*/
|
|
37
|
+
type EventValidator = (schema: EventSchema, payload: unknown) => EventValidationResult;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/domain/events/event-definition.d.ts
|
|
40
|
+
interface CartEventDefinitionInput {
|
|
41
|
+
/** Dotted event name (e.g. `cart.draft.created`). */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Payload schema version — bump when payload shape changes. */
|
|
44
|
+
version?: number;
|
|
45
|
+
/** One-line human description — surfaces in registry/catalog output. */
|
|
46
|
+
description?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Optional JSON-schema-like payload shape.
|
|
49
|
+
* Cart does not validate by default — provide a validator to a registry
|
|
50
|
+
* if you need runtime checks. Shape is kept loose so AJV/Zod/TypeBox all
|
|
51
|
+
* work without adapters.
|
|
52
|
+
*/
|
|
53
|
+
schema?: EventSchema;
|
|
54
|
+
}
|
|
55
|
+
interface CartEventDefinition<TPayload = unknown> {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly version: number;
|
|
58
|
+
readonly description?: string;
|
|
59
|
+
readonly schema?: EventSchema;
|
|
60
|
+
/** Build a CartDomainEvent envelope with this type + auto-gen meta. */
|
|
61
|
+
create(payload: TPayload, meta?: Partial<CartEventMeta>): CartDomainEvent<TPayload>;
|
|
62
|
+
/** Type-brand — pulls the payload type out for consumers. */
|
|
63
|
+
__payload?: TPayload;
|
|
64
|
+
}
|
|
65
|
+
declare function defineCartEvent<TPayload>(input: CartEventDefinitionInput): CartEventDefinition<TPayload>;
|
|
66
|
+
/** Helper — extract the payload type from a definition. */
|
|
67
|
+
type PayloadOf<D> = D extends CartEventDefinition<infer P> ? P : never;
|
|
68
|
+
/**
|
|
69
|
+
* CartEventRegistry — catalog + validator for registered events.
|
|
70
|
+
*
|
|
71
|
+
* Matches arc's EventRegistry interface structurally. Cart apps that
|
|
72
|
+
* already use arc's registry should use arc's directly. Apps without arc
|
|
73
|
+
* get this minimal implementation via `createCartEventRegistry()`.
|
|
74
|
+
*/
|
|
75
|
+
interface CartEventRegistry {
|
|
76
|
+
register(def: CartEventDefinition): void;
|
|
77
|
+
get(name: string, version?: number): CartEventDefinition | undefined;
|
|
78
|
+
catalog(): ReadonlyArray<{
|
|
79
|
+
name: string;
|
|
80
|
+
version: number;
|
|
81
|
+
description?: string;
|
|
82
|
+
schema?: EventSchema;
|
|
83
|
+
}>;
|
|
84
|
+
validate(name: string, payload: unknown): EventValidationResult;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create a minimal event registry. Hosts that want full JSON Schema
|
|
88
|
+
* validation pass an AJV / Zod / custom validator via `options.validate`.
|
|
89
|
+
*
|
|
90
|
+
* Unregistered events pass validation silently (opt-in registry — allows
|
|
91
|
+
* gradual adoption).
|
|
92
|
+
*/
|
|
93
|
+
declare function createCartEventRegistry(options?: {
|
|
94
|
+
validate?: EventValidator;
|
|
95
|
+
}): CartEventRegistry;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/domain/events/cart-event-catalog.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* All cart event definitions as an iterable array. Hosts register them
|
|
100
|
+
* with any arc-compatible event registry in one loop.
|
|
101
|
+
*/
|
|
102
|
+
declare const cartEventDefinitions: ReadonlyArray<CartEventDefinition>;
|
|
103
|
+
/**
|
|
104
|
+
* Fast lookup by event name. Useful for runtime introspection and for
|
|
105
|
+
* cart's own internal emitters.
|
|
106
|
+
*/
|
|
107
|
+
declare const cartEventsByName: Readonly<Record<CartEventName, CartEventDefinition>>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { CartEventRegistry as a, defineCartEvent as c, EventValidationResult as d, EventValidator as f, CartEventDefinitionInput as i, EventSchema as l, cartEventsByName as n, PayloadOf as o, CartEventDefinition as r, createCartEventRegistry as s, cartEventDefinitions as t, EventSchemaProperty as u };
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { n as CartEvents, t as createCartEvent } from "./domain-event-DHNkz15G.mjs";
|
|
2
|
+
import { InvalidOutboxEventError, OutboxOwnershipError } from "@classytic/primitives/outbox";
|
|
3
|
+
//#region src/domain/events/event-definition.ts
|
|
4
|
+
function defineCartEvent(input) {
|
|
5
|
+
const { name, version = 1, description, schema } = input;
|
|
6
|
+
return {
|
|
7
|
+
name,
|
|
8
|
+
version,
|
|
9
|
+
description,
|
|
10
|
+
schema,
|
|
11
|
+
create(payload, meta) {
|
|
12
|
+
return createCartEvent(name, payload, meta, version);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a minimal event registry. Hosts that want full JSON Schema
|
|
18
|
+
* validation pass an AJV / Zod / custom validator via `options.validate`.
|
|
19
|
+
*
|
|
20
|
+
* Unregistered events pass validation silently (opt-in registry — allows
|
|
21
|
+
* gradual adoption).
|
|
22
|
+
*/
|
|
23
|
+
function createCartEventRegistry(options) {
|
|
24
|
+
const custom = options?.validate;
|
|
25
|
+
const defs = /* @__PURE__ */ new Map();
|
|
26
|
+
function key(name, version) {
|
|
27
|
+
return `${name}:v${version}`;
|
|
28
|
+
}
|
|
29
|
+
function latestOf(name) {
|
|
30
|
+
let latest;
|
|
31
|
+
let latestVersion = -1;
|
|
32
|
+
for (const def of defs.values()) if (def.name === name && def.version > latestVersion) {
|
|
33
|
+
latest = def;
|
|
34
|
+
latestVersion = def.version;
|
|
35
|
+
}
|
|
36
|
+
return latest;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
register(def) {
|
|
40
|
+
const k = key(def.name, def.version);
|
|
41
|
+
if (defs.has(k)) throw new Error(`Cart event '${def.name}' v${def.version} is already registered. Use a different version for schema evolution.`);
|
|
42
|
+
defs.set(k, def);
|
|
43
|
+
},
|
|
44
|
+
get(name, version) {
|
|
45
|
+
if (version !== void 0) return defs.get(key(name, version));
|
|
46
|
+
return latestOf(name);
|
|
47
|
+
},
|
|
48
|
+
catalog() {
|
|
49
|
+
return Array.from(defs.values()).map((d) => ({
|
|
50
|
+
name: d.name,
|
|
51
|
+
version: d.version,
|
|
52
|
+
description: d.description,
|
|
53
|
+
schema: d.schema
|
|
54
|
+
}));
|
|
55
|
+
},
|
|
56
|
+
validate(name, payload) {
|
|
57
|
+
const def = latestOf(name);
|
|
58
|
+
if (!def) return { valid: true };
|
|
59
|
+
if (!def.schema) return { valid: true };
|
|
60
|
+
if (custom) return custom(def.schema, payload);
|
|
61
|
+
return builtInMinimalValidate(payload, def.schema);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function builtInMinimalValidate(payload, schema) {
|
|
66
|
+
const errors = [];
|
|
67
|
+
if (schema.type === "object") {
|
|
68
|
+
if (payload === null || payload === void 0 || typeof payload !== "object" || Array.isArray(payload)) return {
|
|
69
|
+
valid: false,
|
|
70
|
+
errors: ["payload must be an object"]
|
|
71
|
+
};
|
|
72
|
+
const record = payload;
|
|
73
|
+
if (schema.required) {
|
|
74
|
+
for (const field of schema.required) if (!(field in record) || record[field] === void 0) errors.push(`missing required field: '${field}'`);
|
|
75
|
+
}
|
|
76
|
+
if (schema.properties) {
|
|
77
|
+
for (const [key, prop] of Object.entries(schema.properties)) if (key in record && record[key] !== void 0 && record[key] !== null) {
|
|
78
|
+
const expected = prop.type;
|
|
79
|
+
if (expected) {
|
|
80
|
+
const actual = Array.isArray(record[key]) ? "array" : typeof record[key];
|
|
81
|
+
if (expected !== actual) errors.push(`field '${key}': expected ${expected}, got ${actual}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return errors.length === 0 ? { valid: true } : {
|
|
87
|
+
valid: false,
|
|
88
|
+
errors
|
|
89
|
+
};
|
|
90
|
+
}
|
|
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
|
+
//#region src/domain/events/cart-event-catalog.ts
|
|
122
|
+
/**
|
|
123
|
+
* Cart event catalog — every cart event defined as a registerable
|
|
124
|
+
* `CartEventDefinition`.
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { createEventRegistry } from '@classytic/arc/events';
|
|
128
|
+
* import { cartEventDefinitions } from '@classytic/cart';
|
|
129
|
+
*
|
|
130
|
+
* const registry = createEventRegistry();
|
|
131
|
+
* for (const def of cartEventDefinitions) registry.register(def);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
const commonProperties = {
|
|
135
|
+
organizationId: { type: "string" },
|
|
136
|
+
actorRef: { type: "string" },
|
|
137
|
+
correlationId: { type: "string" },
|
|
138
|
+
emittedAt: { type: "string" }
|
|
139
|
+
};
|
|
140
|
+
const commonRequired = [
|
|
141
|
+
"organizationId",
|
|
142
|
+
"actorRef",
|
|
143
|
+
"correlationId",
|
|
144
|
+
"emittedAt"
|
|
145
|
+
];
|
|
146
|
+
function schemaFor(extras, extraRequired = []) {
|
|
147
|
+
return {
|
|
148
|
+
type: "object",
|
|
149
|
+
properties: {
|
|
150
|
+
...commonProperties,
|
|
151
|
+
...extras
|
|
152
|
+
},
|
|
153
|
+
required: [...commonRequired, ...extraRequired]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const draftCreated = defineCartEvent({
|
|
157
|
+
name: CartEvents.DRAFT_CREATED,
|
|
158
|
+
description: "A new draft cart was created.",
|
|
159
|
+
schema: schemaFor({ draftId: { type: "string" } }, ["draftId"])
|
|
160
|
+
});
|
|
161
|
+
const draftItemAdded = defineCartEvent({
|
|
162
|
+
name: CartEvents.DRAFT_ITEM_ADDED,
|
|
163
|
+
description: "A line was added to a draft.",
|
|
164
|
+
schema: schemaFor({
|
|
165
|
+
draftId: { type: "string" },
|
|
166
|
+
lineId: { type: "string" },
|
|
167
|
+
kind: { type: "string" },
|
|
168
|
+
quantity: { type: "number" }
|
|
169
|
+
}, [
|
|
170
|
+
"draftId",
|
|
171
|
+
"lineId",
|
|
172
|
+
"kind",
|
|
173
|
+
"quantity"
|
|
174
|
+
])
|
|
175
|
+
});
|
|
176
|
+
const draftItemUpdated = defineCartEvent({
|
|
177
|
+
name: CartEvents.DRAFT_ITEM_UPDATED,
|
|
178
|
+
description: "A line quantity was updated on a draft.",
|
|
179
|
+
schema: schemaFor({
|
|
180
|
+
draftId: { type: "string" },
|
|
181
|
+
lineId: { type: "string" },
|
|
182
|
+
quantity: { type: "number" }
|
|
183
|
+
}, [
|
|
184
|
+
"draftId",
|
|
185
|
+
"lineId",
|
|
186
|
+
"quantity"
|
|
187
|
+
])
|
|
188
|
+
});
|
|
189
|
+
const draftItemRemoved = defineCartEvent({
|
|
190
|
+
name: CartEvents.DRAFT_ITEM_REMOVED,
|
|
191
|
+
description: "A line was removed from a draft.",
|
|
192
|
+
schema: schemaFor({
|
|
193
|
+
draftId: { type: "string" },
|
|
194
|
+
lineId: { type: "string" }
|
|
195
|
+
}, ["draftId", "lineId"])
|
|
196
|
+
});
|
|
197
|
+
const draftPromoApplied = defineCartEvent({
|
|
198
|
+
name: CartEvents.DRAFT_PROMO_APPLIED,
|
|
199
|
+
description: "A promotion code was evaluated against a draft.",
|
|
200
|
+
schema: schemaFor({
|
|
201
|
+
draftId: { type: "string" },
|
|
202
|
+
code: { type: "string" },
|
|
203
|
+
accepted: { type: "boolean" }
|
|
204
|
+
}, [
|
|
205
|
+
"draftId",
|
|
206
|
+
"code",
|
|
207
|
+
"accepted"
|
|
208
|
+
])
|
|
209
|
+
});
|
|
210
|
+
const draftMerged = defineCartEvent({
|
|
211
|
+
name: CartEvents.DRAFT_MERGED,
|
|
212
|
+
description: "A guest draft was merged into an authenticated buyer draft.",
|
|
213
|
+
schema: schemaFor({
|
|
214
|
+
sourceDraftId: { type: "string" },
|
|
215
|
+
targetDraftId: { type: "string" },
|
|
216
|
+
mergedLineCount: { type: "number" }
|
|
217
|
+
}, [
|
|
218
|
+
"sourceDraftId",
|
|
219
|
+
"targetDraftId",
|
|
220
|
+
"mergedLineCount"
|
|
221
|
+
])
|
|
222
|
+
});
|
|
223
|
+
const draftAbandoned = defineCartEvent({
|
|
224
|
+
name: CartEvents.DRAFT_ABANDONED,
|
|
225
|
+
description: "A draft was marked abandoned by the abandonment query.",
|
|
226
|
+
schema: schemaFor({
|
|
227
|
+
draftId: { type: "string" },
|
|
228
|
+
abandonedAt: { type: "string" },
|
|
229
|
+
lineCount: { type: "number" },
|
|
230
|
+
grandTotal: { type: "object" }
|
|
231
|
+
}, [
|
|
232
|
+
"draftId",
|
|
233
|
+
"abandonedAt",
|
|
234
|
+
"lineCount",
|
|
235
|
+
"grandTotal"
|
|
236
|
+
])
|
|
237
|
+
});
|
|
238
|
+
const draftExpired = defineCartEvent({
|
|
239
|
+
name: CartEvents.DRAFT_EXPIRED,
|
|
240
|
+
description: "A draft past its TTL was expired by the engine.",
|
|
241
|
+
schema: schemaFor({ draftId: { type: "string" } }, ["draftId"])
|
|
242
|
+
});
|
|
243
|
+
const checkoutCreated = defineCartEvent({
|
|
244
|
+
name: CartEvents.CHECKOUT_CREATED,
|
|
245
|
+
description: "A checkout snapshot was created from a draft.",
|
|
246
|
+
schema: schemaFor({
|
|
247
|
+
checkoutId: { type: "string" },
|
|
248
|
+
draftId: { type: "string" },
|
|
249
|
+
grandTotal: { type: "object" }
|
|
250
|
+
}, [
|
|
251
|
+
"checkoutId",
|
|
252
|
+
"draftId",
|
|
253
|
+
"grandTotal"
|
|
254
|
+
])
|
|
255
|
+
});
|
|
256
|
+
const checkoutCommitted = defineCartEvent({
|
|
257
|
+
name: CartEvents.CHECKOUT_COMMITTED,
|
|
258
|
+
description: "Host called `checkout.commit()` after its external work succeeded. Terminal success.",
|
|
259
|
+
schema: schemaFor({
|
|
260
|
+
checkoutId: { type: "string" },
|
|
261
|
+
draftId: { type: "string" },
|
|
262
|
+
externalRef: { type: "string" },
|
|
263
|
+
grandTotal: { type: "object" }
|
|
264
|
+
}, [
|
|
265
|
+
"checkoutId",
|
|
266
|
+
"draftId",
|
|
267
|
+
"grandTotal"
|
|
268
|
+
])
|
|
269
|
+
});
|
|
270
|
+
const checkoutCanceled = defineCartEvent({
|
|
271
|
+
name: CartEvents.CHECKOUT_CANCELED,
|
|
272
|
+
description: "Host called `checkout.cancel()` or the checkout was auto-canceled on abandonment.",
|
|
273
|
+
schema: schemaFor({
|
|
274
|
+
checkoutId: { type: "string" },
|
|
275
|
+
reason: { type: "string" }
|
|
276
|
+
}, ["checkoutId", "reason"])
|
|
277
|
+
});
|
|
278
|
+
/**
|
|
279
|
+
* All cart event definitions as an iterable array. Hosts register them
|
|
280
|
+
* with any arc-compatible event registry in one loop.
|
|
281
|
+
*/
|
|
282
|
+
const cartEventDefinitions = Object.freeze([
|
|
283
|
+
draftCreated,
|
|
284
|
+
draftItemAdded,
|
|
285
|
+
draftItemUpdated,
|
|
286
|
+
draftItemRemoved,
|
|
287
|
+
draftPromoApplied,
|
|
288
|
+
draftMerged,
|
|
289
|
+
draftAbandoned,
|
|
290
|
+
draftExpired,
|
|
291
|
+
checkoutCreated,
|
|
292
|
+
checkoutCommitted,
|
|
293
|
+
checkoutCanceled
|
|
294
|
+
]);
|
|
295
|
+
/**
|
|
296
|
+
* Fast lookup by event name. Useful for runtime introspection and for
|
|
297
|
+
* cart's own internal emitters.
|
|
298
|
+
*/
|
|
299
|
+
const cartEventsByName = Object.freeze(Object.fromEntries(cartEventDefinitions.map((def) => [def.name, def])));
|
|
300
|
+
//#endregion
|
|
301
|
+
export { OutboxOwnershipError as a, MemoryOutboxStore as i, cartEventsByName as n, createCartEventRegistry as o, InvalidOutboxEventError as r, defineCartEvent as s, cartEventDefinitions as t };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/domain/value-objects/cart-status.vo.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Draft lifecycle state.
|
|
4
|
+
*
|
|
5
|
+
* active — user can freely mutate lines, adjustments, metadata
|
|
6
|
+
* abandoned — updatedAt past the configured abandonment cutoff
|
|
7
|
+
* (set by the abandonment service, not directly by users)
|
|
8
|
+
* converted — a checkout was committed against this draft; draft is frozen
|
|
9
|
+
* expired — draft TTL window elapsed before conversion
|
|
10
|
+
*/
|
|
11
|
+
type DraftStatus = 'active' | 'abandoned' | 'converted' | 'expired';
|
|
12
|
+
/**
|
|
13
|
+
* Checkout lifecycle state. Intentionally minimal.
|
|
14
|
+
*
|
|
15
|
+
* open — snapshot created from the draft; still editable at the
|
|
16
|
+
* host level (host can swap lines before committing if it
|
|
17
|
+
* wants). Cart just holds the frozen snapshot + pricing.
|
|
18
|
+
* finalized — host called `checkout.commit(id)` after its own external
|
|
19
|
+
* work succeeded (payment, order creation, whatever). Cart's
|
|
20
|
+
* job is done. This is the terminal success state.
|
|
21
|
+
* canceled — host called `checkout.cancel(id)` or auto-canceled on
|
|
22
|
+
* abandonment. Cart releases any held reservations (P2+)
|
|
23
|
+
* and emits `cart.checkout.canceled`.
|
|
24
|
+
*
|
|
25
|
+
* Cart does NOT own payment state. If the host needs `authorized`,
|
|
26
|
+
* `captured`, `capture_failed`, etc., those belong on the host's own
|
|
27
|
+
* order record.
|
|
28
|
+
*
|
|
29
|
+
* Legal transitions:
|
|
30
|
+
*
|
|
31
|
+
* open → finalized
|
|
32
|
+
* open → canceled
|
|
33
|
+
*/
|
|
34
|
+
type CheckoutState = 'open' | 'finalized' | 'canceled';
|
|
35
|
+
/**
|
|
36
|
+
* Reservation lifecycle state. Used only when a LineKind's `reserve()`
|
|
37
|
+
* method creates a hold via an optional inventory bridge (P2+ wires
|
|
38
|
+
* this into the checkout flow explicitly).
|
|
39
|
+
*
|
|
40
|
+
* held — reservation exists, TTL counting down
|
|
41
|
+
* committed — checkout committed, reservation survives for fulfillment
|
|
42
|
+
* released — explicitly released by the host or cancel
|
|
43
|
+
*/
|
|
44
|
+
type ReservationStatus = 'held' | 'committed' | 'released';
|
|
45
|
+
//#endregion
|
|
46
|
+
export { DraftStatus as n, ReservationStatus as r, CheckoutState as t };
|