@classytic/cart 1.0.0 → 1.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/CHANGELOG.md CHANGED
@@ -3,6 +3,13 @@
3
3
  Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
4
4
  adhering to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
+ ## 1.1.0 - 2026-08-17
7
+
8
+ ### Changed
9
+ - `cleanup/steps.ts`: bare calendar-date `before` param refused — must be a full ISO instant (prevents silent UTC-midnight misfire in non-UTC deployments)
10
+ - `define-cart`: `resolveCartTenant` wired; tenant injection centralised
11
+ - `inject-tenant` refactored; models and repositories simplified
12
+
6
13
  ## 1.0.0 - 2026-07-29
7
14
 
8
15
  ### Changed
@@ -9,7 +9,7 @@ import { money } from "@classytic/primitives/money";
9
9
  import { Repository, customIdPlugin, defineModels, isDuplicateKeyError, multiTenantPlugin, prefixedId, withTransaction } from "@classytic/mongokit";
10
10
  import { CURRENCY_PATTERN, currencyCode } from "@classytic/primitives/currency";
11
11
  import mongoose, { Schema } from "mongoose";
12
- import { resolveTenantConfig } from "@classytic/repo-core/tenant";
12
+ import { assertNoLegacyTenantKeys, resolveTenantConfig } from "@classytic/repo-core/tenant";
13
13
  import { createHash } from "node:crypto";
14
14
  import { InProcessEventBus } from "@classytic/primitives/event-infra";
15
15
  //#region src/domain/ports/common.ts
@@ -190,6 +190,17 @@ const lineDisplaySubSchema = new Schema({
190
190
  type: Schema.Types.Mixed,
191
191
  default: null
192
192
  },
193
+ /**
194
+ * Per-unit shipping weight. Declared here or mongoose strips it — the failure
195
+ * this repo has paid for with `stockTracked`, `monetizationKind` and the order
196
+ * `payment` block. NO `default: 0`: absent must stay distinguishable from
197
+ * weightless, because a weight-tiered delivery zone prices the cheapest step
198
+ * for a zero and under-charges every unweighed cart.
199
+ */
200
+ weightGrams: {
201
+ type: Number,
202
+ default: null
203
+ },
193
204
  capturedAt: {
194
205
  type: Date,
195
206
  default: () => /* @__PURE__ */ new Date()
@@ -450,15 +461,9 @@ function buildIdempotencySchema() {
450
461
  * own without a mongoose dependency.
451
462
  */
452
463
  function resolveCartTenant(input = {}) {
453
- if (typeof input === "boolean" || input === void 0) return resolveTenantConfig(input);
454
- if ("tenantFieldType" in input || "multiTenant" in input) {
455
- const legacy = input;
456
- return resolveTenantConfig({
457
- enabled: legacy.multiTenant !== false,
458
- fieldType: legacy.tenantFieldType ?? "objectId"
459
- });
460
- }
461
- return resolveTenantConfig(input);
464
+ const resolved = resolveTenantConfig(input);
465
+ if (resolved.strategy === "custom") throw new Error("[cart] tenant.strategy 'custom' is unsupported: cart repositories require one concrete tenant field");
466
+ return resolved;
462
467
  }
463
468
  /**
464
469
  * Inject the tenant field into a Mongoose schema, and (when `enabled` +
@@ -616,10 +621,7 @@ function resolveAutoIndex(key, autoIndex) {
616
621
  * schema and registers nothing until `.bind(connection)`.
617
622
  */
618
623
  function defineCartModels(config = {}) {
619
- const tenant = resolveCartTenant({
620
- multiTenant: config.multiTenant,
621
- tenantFieldType: config.tenantFieldType ?? "objectId"
622
- });
624
+ const tenant = config.tenant ?? resolveCartTenant(true);
623
625
  const prefix = config.collectionPrefix ?? "";
624
626
  return defineModels({
625
627
  models: [
@@ -1941,23 +1943,23 @@ function isNotFound(err) {
1941
1943
  }
1942
1944
  //#endregion
1943
1945
  //#region src/repositories/index.ts
1944
- function tenantPlugin(fieldType = "objectId") {
1946
+ function tenantPlugin(tenant) {
1945
1947
  return multiTenantPlugin({
1946
- tenantField: "organizationId",
1947
- contextKey: "organizationId",
1948
+ tenantField: tenant.tenantField,
1949
+ contextKey: tenant.contextKey,
1948
1950
  required: false,
1949
1951
  skipWhen: (ctx) => ctx.skipTenant === true,
1950
- fieldType
1952
+ fieldType: tenant.fieldType
1951
1953
  });
1952
1954
  }
1953
1955
  function createCartRepositories(models, config) {
1954
- const { kinds, bridges, clock, id, defaultCurrency, events, outbox, plugins = {}, tenantFieldType = "objectId", multiTenant = true, staleOpenCheckoutMs } = config;
1956
+ const { kinds, bridges, clock, id, defaultCurrency, events, outbox, plugins = {}, tenant, staleOpenCheckoutMs } = config;
1955
1957
  const eventPublisher = new CartEventPublisher({
1956
1958
  events,
1957
1959
  outbox,
1958
1960
  clock
1959
1961
  });
1960
- const tenantPlugins = multiTenant ? [tenantPlugin(tenantFieldType)] : [];
1962
+ const tenantPlugins = tenant.enabled ? [tenantPlugin(tenant)] : [];
1961
1963
  const draft = new DraftRepository(models.Draft, [
1962
1964
  ...tenantPlugins,
1963
1965
  customIdPlugin({
@@ -2075,13 +2077,27 @@ function requireKinds(shape) {
2075
2077
  * performs no I/O.
2076
2078
  */
2077
2079
  function defineCart(shape) {
2080
+ /**
2081
+ * The pre-consolidation tenant keys are REFUSED, never absorbed.
2082
+ *
2083
+ * This entry reads `shape.tenant`, so a leftover `multiTenant` is invisible and
2084
+ * the `?? true` default applies repo-core's defaults instead. Both outcomes
2085
+ * return plausible data:
2086
+ * - `multiTenant: false` -> tenancy ON, and the host loses its company-wide reads;
2087
+ * - `multiTenant: { tenantField: 'business' }` -> scoping on `organizationId`,
2088
+ * a field those documents do not carry.
2089
+ *
2090
+ * tsc cannot cover this: excess-property checking does not fire for a typed
2091
+ * variable, a spread, or a shape handed over from a dependency's dist — which is
2092
+ * how every real host composes one. Hence a describe-time check, shared from
2093
+ * repo-core so the nine kernels making this same rename cannot each forget it.
2094
+ */
2095
+ assertNoLegacyTenantKeys(shape, "defineCart", [["tenantFieldType", "tenant.fieldType"]]);
2078
2096
  requireKinds(shape);
2079
- const multiTenant = shape.multiTenant ?? true;
2080
- const tenantFieldType = shape.tenantFieldType ?? "objectId";
2097
+ const tenant = resolveCartTenant(shape.tenant ?? true);
2081
2098
  const defaultCurrency = currencyCode(shape.defaultCurrency ?? "USD");
2082
2099
  const modelBlueprint = defineCartModels({
2083
- multiTenant,
2084
- tenantFieldType,
2100
+ tenant,
2085
2101
  ...shape.autoIndex !== void 0 ? { autoIndex: shape.autoIndex } : {},
2086
2102
  ...shape.collectionPrefix !== void 0 ? { collectionPrefix: shape.collectionPrefix } : {},
2087
2103
  ...shape.forceRecreate !== void 0 ? { forceRecreate: shape.forceRecreate } : {}
@@ -2129,15 +2145,13 @@ function defineCart(shape) {
2129
2145
  events,
2130
2146
  ...runtime.outbox !== void 0 ? { outbox: runtime.outbox } : {},
2131
2147
  ...runtime.repositoryPlugins !== void 0 ? { plugins: runtime.repositoryPlugins } : {},
2132
- tenantFieldType,
2133
- multiTenant,
2148
+ tenant,
2134
2149
  ...staleOpenCheckoutMs !== void 0 ? { staleOpenCheckoutMs } : {}
2135
2150
  });
2136
2151
  assertCartCapabilities(repositories);
2137
2152
  const allowNonTransactional = runtime.allowNonTransactional ?? false;
2138
2153
  const resolved = {
2139
- multiTenant,
2140
- tenantFieldType,
2154
+ tenant,
2141
2155
  forceRecreate: shape.forceRecreate ?? false,
2142
2156
  defaultCurrency,
2143
2157
  allowNonTransactional,
@@ -4,10 +4,10 @@ import { S as CartEvents, _ as CartEventMeta, a as OutboxErrorInfo, b as CartEve
4
4
  import { a as CartEventRegistry, c as defineCartEvent, d as EventValidationResult, f as EventValidator, i as CartEventDefinitionInput, l as EventSchema, n as cartEventsByName, o as PayloadOf, r as CartEventDefinition, s as createCartEventRegistry, t as cartEventDefinitions, u as EventSchemaProperty } from "../cart-event-catalog-Cokx0iOw.mjs";
5
5
  import "./events/index.mjs";
6
6
  import { C as OperationContext, E as PricingSnapshot, S as BridgeStatus, T as PricedLine, _ as CartSnapshot, a as ShippingQuote, c as TaxBridge, d as InventoryBridge, f as ReservationRef, g as AdjustmentSpec, h as ProductSummary, i as ShippingMethod, l as TaxCalculationRequest, m as CatalogBridge, n as systemClock, o as ShippingQuoteRequest, p as ReservationRequest, r as ShippingBridge, s as TaxBreakdown, t as ClockPort, u as TaxCalculationResult, v as PromotionResult, x as BridgeRef, y as PromotionsBridge } from "../clock.port-DrSBrsit.mjs";
7
- import { a as Adjustment, i as Checkout, n as IdempotencyRecord, r as Draft, t as Reservation } from "../reservation.entity-BEeYbRUY.mjs";
8
- import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep, t as CHECKOUT_MACHINE } from "../state-transitions-BQ2Nhxnb.mjs";
9
- import { a as RevalidationResult, c as ValidityPolicy, i as LineLike, l as LineDisplay, n as KindContext, o as StaleBehavior, r as LineKind, s as StaleTrigger, t as KindBridges } from "../line-kind-BW2zLNSr.mjs";
10
- import { a as IdempotencyReplay, c as LineItem, i as IdempotencyIdentity, n as createKindRegistry, o as OperationName, r as CART_REF_NEW, s as TotalsSnapshot, t as KindRegistry } from "../kind-registry-DFvNDb81.mjs";
7
+ import { a as Adjustment, i as Checkout, n as IdempotencyRecord, r as Draft, t as Reservation } from "../reservation.entity-CLRqLD6X.mjs";
8
+ import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep, t as CHECKOUT_MACHINE } from "../state-transitions-B_ozUaqV.mjs";
9
+ import { a as RevalidationResult, c as ValidityPolicy, i as LineLike, l as LineDisplay, n as KindContext, o as StaleBehavior, r as LineKind, s as StaleTrigger, t as KindBridges } from "../line-kind-kYeQzpCy.mjs";
10
+ import { a as IdempotencyReplay, c as LineItem, i as IdempotencyIdentity, n as createKindRegistry, o as OperationName, r as CART_REF_NEW, s as TotalsSnapshot, t as KindRegistry } from "../kind-registry-BkYl0cjc.mjs";
11
11
  import { n as createCounterIdPort, r as cryptoIdPort, t as IdPort } from "../id.port-DzgWy8sy.mjs";
12
12
  import "./ports/index.mjs";
13
13
  import "./saga/index.mjs";
@@ -1,2 +1,2 @@
1
- import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep, t as CHECKOUT_MACHINE } from "../../state-transitions-BQ2Nhxnb.mjs";
1
+ import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep, t as CHECKOUT_MACHINE } from "../../state-transitions-B_ozUaqV.mjs";
2
2
  export { CHECKOUT_MACHINE, CHECKOUT_STATE_TRANSITIONS, type CheckoutFlowState, CheckoutStep, type CheckoutStepNumber, type SagaDependencies, type SagaStepFn, isLegalCheckoutTransition };
@@ -1,3 +1,3 @@
1
1
  import { CartConfigShape, cartConfigSchema, checkoutConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./cart-config.schema.mjs";
2
- import { a as defineCart, c as CartEngine, d as CartShape, f as ResolvedCartConfig, i as createCartDomain, l as CartLogger, n as CartBlueprint, o as CartBridges, r as CartDomainRuntime, s as CartDomain, t as InProcessCartEventBus, u as CartRuntime } from "../internal-event-bus-Bu7Xj7j6.mjs";
2
+ import { a as defineCart, c as CartEngine, d as CartShape, f as ResolvedCartConfig, i as createCartDomain, l as CartLogger, n as CartBlueprint, o as CartBridges, r as CartDomainRuntime, s as CartDomain, t as InProcessCartEventBus, u as CartRuntime } from "../internal-event-bus-Ci5Zpoqu.mjs";
3
3
  export { type CartBlueprint, type CartBridges, type CartConfigShape, type CartDomain, type CartDomainRuntime, type CartEngine, type CartLogger, type CartRuntime, type CartShape, InProcessCartEventBus, type ResolvedCartConfig, cartConfigSchema, checkoutConfigSchema, createCartDomain, defineCart, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
@@ -1,3 +1,3 @@
1
- import { n as defineCart, r as InProcessCartEventBus, t as createCartDomain } from "../define-cart-BPq2kb_V.mjs";
1
+ import { n as defineCart, r as InProcessCartEventBus, t as createCartDomain } from "../define-cart-CYkjJdC7.mjs";
2
2
  import { cartConfigSchema, checkoutConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./cart-config.schema.mjs";
3
3
  export { InProcessCartEventBus, cartConfigSchema, checkoutConfigSchema, createCartDomain, defineCart, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema };
package/dist/index.d.mts CHANGED
@@ -3,14 +3,14 @@ import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "./
3
3
  import { S as CartEvents, _ as CartEventMeta, a as OutboxErrorInfo, b as CartEventName, c as OutboxFailureDecision, d as OutboxStore, f as OutboxStoreWriteOptions, g as CartEventAggregate, h as CartDomainEvent, i as OutboxClaimOptions, l as OutboxFailurePolicy, m as CartAggregateType, n as MemoryOutboxStore, o as OutboxFailOptions, p as OutboxWriteOptions, r as OutboxAcknowledgeOptions, s as OutboxFailureContext, t as InvalidOutboxEventError, u as OutboxOwnershipError, v as createCartEvent, x as CartEventPayload, y as CartEventMap } from "./outbox-store-Br7MHuOz.mjs";
4
4
  import { a as CartEventRegistry, c as defineCartEvent, d as EventValidationResult, f as EventValidator, i as CartEventDefinitionInput, l as EventSchema, n as cartEventsByName, o as PayloadOf, r as CartEventDefinition, s as createCartEventRegistry, t as cartEventDefinitions, u as EventSchemaProperty } from "./cart-event-catalog-Cokx0iOw.mjs";
5
5
  import { C as OperationContext, E as PricingSnapshot, S as BridgeStatus, T as PricedLine, _ as CartSnapshot, a as ShippingQuote, b as Address, c as TaxBridge, d as InventoryBridge, f as ReservationRef, g as AdjustmentSpec, h as ProductSummary, i as ShippingMethod, l as TaxCalculationRequest, m as CatalogBridge, n as systemClock, o as ShippingQuoteRequest, p as ReservationRequest, r as ShippingBridge, s as TaxBreakdown, t as ClockPort, u as TaxCalculationResult, v as PromotionResult, w as PENDING_EVENTS, x as BridgeRef, y as PromotionsBridge } from "./clock.port-DrSBrsit.mjs";
6
- import { a as Adjustment, i as Checkout, n as IdempotencyRecord, r as Draft, t as Reservation } from "./reservation.entity-BEeYbRUY.mjs";
7
- import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep } from "./state-transitions-BQ2Nhxnb.mjs";
8
- import { a as RevalidationResult, c as ValidityPolicy, i as LineLike, l as LineDisplay, n as KindContext, o as StaleBehavior, r as LineKind, s as StaleTrigger, t as KindBridges } from "./line-kind-BW2zLNSr.mjs";
9
- import { a as IdempotencyReplay, c as LineItem, i as IdempotencyIdentity, n as createKindRegistry, o as OperationName, r as CART_REF_NEW, s as TotalsSnapshot, t as KindRegistry } from "./kind-registry-DFvNDb81.mjs";
6
+ import { a as Adjustment, i as Checkout, n as IdempotencyRecord, r as Draft, t as Reservation } from "./reservation.entity-CLRqLD6X.mjs";
7
+ import { a as SagaStepFn, c as CheckoutStepNumber, i as SagaDependencies, n as CHECKOUT_STATE_TRANSITIONS, o as CheckoutFlowState, r as isLegalCheckoutTransition, s as CheckoutStep } from "./state-transitions-B_ozUaqV.mjs";
8
+ import { a as RevalidationResult, c as ValidityPolicy, i as LineLike, l as LineDisplay, n as KindContext, o as StaleBehavior, r as LineKind, s as StaleTrigger, t as KindBridges } from "./line-kind-kYeQzpCy.mjs";
9
+ import { a as IdempotencyReplay, c as LineItem, i as IdempotencyIdentity, n as createKindRegistry, o as OperationName, r as CART_REF_NEW, s as TotalsSnapshot, t as KindRegistry } from "./kind-registry-BkYl0cjc.mjs";
10
10
  import { n as createCounterIdPort, r as cryptoIdPort, t as IdPort } from "./id.port-DzgWy8sy.mjs";
11
11
  import { CartConfigShape, cartConfigSchema, checkoutConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./engine/cart-config.schema.mjs";
12
- import { A as buildReservationSchema, C as DraftRepositoryDeps, D as DefineCartModelsConfig, E as CartModels, F as CheckoutDocument, I as buildCheckoutSchema, M as buildIdempotencySchema, N as DraftDocument, O as defineCartModels, P as buildDraftSchema, S as DraftRepository, T as CartModelName, _ as ReservationRepository, a as defineCart, b as CheckoutRepositoryDeps, c as CartEngine, d as CartShape, f as ResolvedCartConfig, g as createCartRepositories, h as CreateCartRepositoriesConfig, i as createCartDomain, j as IdempotencyDocument, k as ReservationDocument, l as CartLogger, m as CartRepositoryPluginBundle, n as CartBlueprint, o as CartBridges, p as CartRepositories, r as CartDomainRuntime, s as CartDomain, t as InProcessCartEventBus, u as CartRuntime, v as IdempotencyRepository, w as CartEventPublisherDeps, x as DEFAULT_STALE_OPEN_CHECKOUT_MS, y as CheckoutRepository } from "./internal-event-bus-Bu7Xj7j6.mjs";
13
- 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-CClf8MTF.mjs";
12
+ import { A as buildReservationSchema, C as DraftRepositoryDeps, D as DefineCartModelsConfig, E as CartModels, F as CheckoutDocument, I as buildCheckoutSchema, M as buildIdempotencySchema, N as DraftDocument, O as defineCartModels, P as buildDraftSchema, S as DraftRepository, T as CartModelName, _ as ReservationRepository, a as defineCart, b as CheckoutRepositoryDeps, c as CartEngine, d as CartShape, f as ResolvedCartConfig, g as createCartRepositories, h as CreateCartRepositoriesConfig, i as createCartDomain, j as IdempotencyDocument, k as ReservationDocument, l as CartLogger, m as CartRepositoryPluginBundle, n as CartBlueprint, o as CartBridges, p as CartRepositories, r as CartDomainRuntime, s as CartDomain, t as InProcessCartEventBus, u as CartRuntime, v as IdempotencyRepository, w as CartEventPublisherDeps, x as DEFAULT_STALE_OPEN_CHECKOUT_MS, y as CheckoutRepository } from "./internal-event-bus-Ci5Zpoqu.mjs";
13
+ 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-BVmeGR6G.mjs";
14
14
  import { Money, Money as Money$1, addMoney, fromMajor, money, multiplyMoney, subtractMoney, sumMoney, toMajor } from "@classytic/primitives/money";
15
15
  import { DomainEvent, EventHandler, EventTransport, EventTransport as EventTransport$1, PublishManyResult } from "@classytic/primitives/events";
16
16
  import { CurrencyCode } from "@classytic/primitives/currency";
@@ -143,14 +143,20 @@ declare function runPricing(opts: {
143
143
  //#endregion
144
144
  //#region src/models/inject-tenant.d.ts
145
145
  /**
146
- * Accept the same config surface other packages use (TenantConfig | boolean),
147
- * and additionally support the legacy `{ tenantFieldType, multiTenant }` shape
148
- * so the engine factory can forward its own config shorthand.
146
+ * Accept the config surface every kernel uses: `TenantConfig | boolean`.
147
+ *
148
+ * This docblock used to add "and additionally support the legacy
149
+ * `{ tenantFieldType, multiTenant }` shape so the engine factory can forward its
150
+ * own config shorthand". That was never true of this code — the type is
151
+ * `TenantConfig | boolean` and the body delegates straight to
152
+ * `resolveTenantConfig`. A docblock promising back-compat the implementation
153
+ * does not have is worse than no docblock: the next reader composes against the
154
+ * promise, passes the old key, and gets default scoping with no error.
155
+ *
156
+ * The old keys are now REFUSED at the engine's describe-time entry
157
+ * (`assertNoLegacyTenantKeys`). There is no back-compat path by design.
149
158
  */
150
- type CartTenantInput = TenantConfig | boolean | {
151
- tenantFieldType?: 'objectId' | 'string';
152
- multiTenant?: boolean;
153
- };
159
+ type CartTenantInput = TenantConfig | boolean;
154
160
  /** Re-export of primitives' resolved shape under the legacy name. */
155
161
  type ResolvedTenant = ResolvedTenantConfig;
156
162
  //#endregion
package/dist/index.mjs CHANGED
@@ -7,10 +7,10 @@ import { t as StateTransitionError } from "./state-transition.error-BssJiRoW.mjs
7
7
  import { n as CartEvents, t as createCartEvent } from "./domain-event-DBFsiHNJ.mjs";
8
8
  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-DLxCPOUN.mjs";
9
9
  import { n as cryptoIdPort, r as systemClock, t as createCounterIdPort } from "./id.port-DYAnXbfV.mjs";
10
- import { _ as PENDING_EVENTS, a as ReservationRepository, c as runPricing, d as defineCartModels, f as buildReservationSchema, g as flushPending, h as buildCheckoutSchema, i as createCartRepositories, l as CheckoutRepository, m as buildDraftSchema, n as defineCart, o as IdempotencyRepository, p as buildIdempotencySchema, r as InProcessCartEventBus, s as DraftRepository, t as createCartDomain, u as DEFAULT_STALE_OPEN_CHECKOUT_MS } from "./define-cart-BPq2kb_V.mjs";
10
+ import { _ as PENDING_EVENTS, a as ReservationRepository, c as runPricing, d as defineCartModels, f as buildReservationSchema, g as flushPending, h as buildCheckoutSchema, i as createCartRepositories, l as CheckoutRepository, m as buildDraftSchema, n as defineCart, o as IdempotencyRepository, p as buildIdempotencySchema, r as InProcessCartEventBus, s as DraftRepository, t as createCartDomain, u as DEFAULT_STALE_OPEN_CHECKOUT_MS } from "./define-cart-CYkjJdC7.mjs";
11
11
  import { t as createKindRegistry } from "./kind-registry-DQYqRQZU.mjs";
12
12
  import { i as CheckoutStep, n as CHECKOUT_STATE_TRANSITIONS, r as isLegalCheckoutTransition } from "./state-transitions-wunwhjap.mjs";
13
- 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-NmWSslu-.mjs";
13
+ 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-CquIUes6.mjs";
14
14
  import { cartConfigSchema, checkoutConfigSchema, idempotencyConfigSchema, reservationConfigSchema, scopeConfigSchema } from "./engine/cart-config.schema.mjs";
15
15
  import { addMoney, fromMajor, money, multiplyMoney, subtractMoney, sumMoney, toMajor } from "@classytic/primitives/money";
16
16
  //#region src/services/abandonment.service.ts
@@ -206,7 +206,23 @@ function parseParams(ctx, op) {
206
206
  const out = {};
207
207
  const before = p.before;
208
208
  if (before !== void 0) {
209
- if (typeof before !== "string" || Number.isNaN(Date.parse(before))) throw invalidParam(op, "before", before, "an ISO date string");
209
+ if (typeof before !== "string" || Number.isNaN(Date.parse(before))) throw invalidParam(op, "before", before, "a full ISO instant (e.g. 2026-08-01T00:00:00.000Z)");
210
+ /**
211
+ * A DATE-ONLY string is refused, not silently read as UTC midnight.
212
+ *
213
+ * This was `new Date(before)` for both forms. `new Date('2026-08-01')` is
214
+ * UTC midnight — 06:00 that day in Asia/Dhaka — so "remove abandoned carts
215
+ * before 1 August" swept the first six hours of a day the operator had
216
+ * excluded. Nothing errored and a plausible count came back.
217
+ *
218
+ * A kernel cannot fix that by picking a calendar: it does not know the
219
+ * deployment's timezone, and guessing UTC is exactly the bug. So the
220
+ * ambiguity is REFUSED here and resolved by the host, which does know —
221
+ * be-prod converts a civil date through `businessDayStartUtc` before the
222
+ * parameter ever reaches a step. Refusing is what makes that conversion
223
+ * mandatory rather than merely available.
224
+ */
225
+ if (/^\d{4}-\d{2}-\d{2}$/.test(before)) throw invalidParam(op, "before", before, "a full ISO instant — a bare calendar date is ambiguous without a timezone, so the host must resolve it against its business calendar first");
210
226
  out.before = new Date(before);
211
227
  }
212
228
  const org = p.organizationId;
@@ -1,7 +1,7 @@
1
1
  import { b as CartEventName, d as OutboxStore, h as CartDomainEvent, x as CartEventPayload } from "./outbox-store-Br7MHuOz.mjs";
2
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-DrSBrsit.mjs";
3
- import { l as LineDisplay, r as LineKind } from "./line-kind-BW2zLNSr.mjs";
4
- import { c as LineItem, i as IdempotencyIdentity, t as KindRegistry } from "./kind-registry-DFvNDb81.mjs";
3
+ import { l as LineDisplay, r as LineKind } from "./line-kind-kYeQzpCy.mjs";
4
+ import { c as LineItem, i as IdempotencyIdentity, t as KindRegistry } from "./kind-registry-BkYl0cjc.mjs";
5
5
  import { t as IdPort } from "./id.port-DzgWy8sy.mjs";
6
6
  import { CartConfigShape } from "./engine/cart-config.schema.mjs";
7
7
  import { Money } from "@classytic/primitives/money";
@@ -9,6 +9,7 @@ import { EventTransport } from "@classytic/primitives/events";
9
9
  import { ModelBlueprint, PluginType, Repository } from "@classytic/mongokit";
10
10
  import { CurrencyCode } from "@classytic/primitives/currency";
11
11
  import { Connection, Document, Model, Schema, Types } from "mongoose";
12
+ import { ResolvedTenantConfig, TenantConfig } from "@classytic/repo-core/tenant";
12
13
  import { InProcessEventBus } from "@classytic/primitives/event-infra";
13
14
  //#region src/models/checkout.model.d.ts
14
15
  /**
@@ -164,8 +165,7 @@ declare function buildReservationSchema(): Schema<ReservationDocument>;
164
165
  /** Union of all cart model names used as keys in `CartModels`. */
165
166
  type CartModelName = 'Draft' | 'Checkout' | 'Reservation' | 'Idempotency';
166
167
  interface DefineCartModelsConfig {
167
- tenantFieldType?: 'objectId' | 'string';
168
- multiTenant?: boolean;
168
+ tenant?: ResolvedTenantConfig;
169
169
  autoIndex?: boolean | Partial<Record<CartModelName, boolean>>;
170
170
  /**
171
171
  * Optional prefix prepended to every physical collection this package
@@ -582,12 +582,7 @@ interface CreateCartRepositoriesConfig {
582
582
  /** Validated + branded once at the config edge in `defineCart`. */
583
583
  defaultCurrency: CurrencyCode;
584
584
  events: EventTransport;
585
- tenantFieldType?: 'objectId' | 'string';
586
- /**
587
- * When `false`, the tenant plugin is omitted entirely — cart is
588
- * company-wide. Default `true` keeps branch scoping.
589
- */
590
- multiTenant?: boolean;
585
+ tenant: ResolvedTenantConfig;
591
586
  outbox?: OutboxStore;
592
587
  plugins?: CartRepositoryPluginBundle;
593
588
  /** Zombie window for lazy open-checkout expiry. See `CheckoutRepositoryDeps`. */
@@ -639,14 +634,7 @@ interface CartShape extends Partial<CartConfigShape> {
639
634
  * Use when cart is company-wide — a customer's cart follows them across
640
635
  * branches and no tenant filter applies.
641
636
  */
642
- multiTenant?: boolean | undefined;
643
- /**
644
- * Mongoose schema type for the `organizationId` field on all models.
645
- *
646
- * - `'objectId'` (default): `Schema.Types.ObjectId` + `ref: 'organization'`
647
- * - `'string'`: plain `String` — for UUID/slug-based auth
648
- */
649
- tenantFieldType?: 'objectId' | 'string' | undefined;
637
+ tenant?: boolean | TenantConfig | undefined;
650
638
  /**
651
639
  * Control Mongoose `autoIndex` per model or globally.
652
640
  *
@@ -712,8 +700,7 @@ interface CartRuntime {
712
700
  }
713
701
  /** Resolved configuration captured on the bound engine (frozen). */
714
702
  interface ResolvedCartConfig {
715
- multiTenant: boolean;
716
- tenantFieldType: 'objectId' | 'string';
703
+ tenant: ResolvedTenantConfig;
717
704
  forceRecreate: boolean;
718
705
  /** Validated + branded once at the config edge in `defineCart`. */
719
706
  defaultCurrency: CurrencyCode;
@@ -1,4 +1,4 @@
1
- import { l as LineDisplay, r as LineKind } from "./line-kind-BW2zLNSr.mjs";
1
+ import { l as LineDisplay, r as LineKind } from "./line-kind-kYeQzpCy.mjs";
2
2
  import { Money } from "@classytic/primitives/money";
3
3
  //#region src/domain/entities/line-item.entity.d.ts
4
4
  /**
@@ -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-CClf8MTF.mjs";
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-BVmeGR6G.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 };
@@ -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-NmWSslu-.mjs";
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-CquIUes6.mjs";
2
2
  export { bundleKind, bundlePayloadSchema, serviceFeeKind, serviceFeePayloadSchema, skuKind, skuPayloadSchema, timeslotKind, timeslotPayloadSchema, variantKind, variantPayloadSchema };
@@ -39,6 +39,23 @@ interface LineDisplay {
39
39
  variantLabel?: string;
40
40
  /** Compare-at price for strikethrough display. */
41
41
  compareAtPrice?: Money;
42
+ /**
43
+ * Per-unit shipping weight in GRAMS, captured with the rest of the snapshot.
44
+ *
45
+ * Unlike the cosmetic fields around it, this one feeds a PRICE: a checkout
46
+ * pricing delivery by weight tiers sums `weightGrams x quantity` across the
47
+ * cart, and without it every cart looks unweighable and falls back to the flat
48
+ * charge. Carried here so a cart can be priced with no catalog round-trip per
49
+ * line — the whole point of this snapshot.
50
+ *
51
+ * Display drift is tolerated for name and image; for this the SERVER re-derives
52
+ * it at placement from the order's own line snapshot, so a stale or tampered
53
+ * value can never become the charged amount.
54
+ *
55
+ * Absent means UNWEIGHED, never zero — a zone with weight steps must fall back
56
+ * to its flat charge rather than price the cheapest step.
57
+ */
58
+ weightGrams?: number;
42
59
  /**
43
60
  * Timestamp when this snapshot was captured. The UI may show a "refresh"
44
61
  * affordance if the snapshot is older than some threshold.
@@ -1,7 +1,7 @@
1
1
  import { n as DraftStatus, r as ReservationStatus, t as CheckoutState } from "./cart-status.vo-BoVPaSXX.mjs";
2
2
  import { E as PricingSnapshot, g as AdjustmentSpec } from "./clock.port-DrSBrsit.mjs";
3
- import { o as CheckoutFlowState } from "./state-transitions-BQ2Nhxnb.mjs";
4
- import { a as IdempotencyReplay, c as LineItem, o as OperationName } from "./kind-registry-DFvNDb81.mjs";
3
+ import { o as CheckoutFlowState } from "./state-transitions-B_ozUaqV.mjs";
4
+ import { a as IdempotencyReplay, c as LineItem, o as OperationName } from "./kind-registry-BkYl0cjc.mjs";
5
5
  import { Money } from "@classytic/primitives/money";
6
6
  //#region src/domain/entities/adjustment.entity.d.ts
7
7
  /**
@@ -1,6 +1,6 @@
1
1
  import { t as CheckoutState } from "./cart-status.vo-BoVPaSXX.mjs";
2
2
  import { C as OperationContext, t as ClockPort } from "./clock.port-DrSBrsit.mjs";
3
- import { t as KindBridges } from "./line-kind-BW2zLNSr.mjs";
3
+ import { t as KindBridges } from "./line-kind-kYeQzpCy.mjs";
4
4
  import { t as IdPort } from "./id.port-DzgWy8sy.mjs";
5
5
  //#region src/domain/saga/saga-steps.d.ts
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { r as LineKind } from "./line-kind-BW2zLNSr.mjs";
1
+ import { r as LineKind } from "./line-kind-kYeQzpCy.mjs";
2
2
  import { Money } from "@classytic/primitives/money";
3
3
  import { CurrencyCode } from "@classytic/primitives/currency";
4
4
  import { z } from "zod";
@@ -256,6 +256,15 @@ const skuKind = {
256
256
  slug: product.slug,
257
257
  variantLabel: product.variantLabel,
258
258
  compareAtPrice: product.compareAtPrice,
259
+ /**
260
+ * From the catalog bridge, which has carried `weightGrams` all along — the
261
+ * snapshot simply never captured it, so every checkout pricing delivery by
262
+ * weight saw an unweighable cart and fell back to the flat charge.
263
+ *
264
+ * Emitted only when real and positive: absent means unweighed, and a zero
265
+ * would select the cheapest weight step instead of the safe fallback.
266
+ */
267
+ ...typeof product.weightGrams === "number" && product.weightGrams > 0 ? { weightGrams: product.weightGrams } : {},
259
268
  capturedAt: ctx.clock?.now() ?? /* @__PURE__ */ new Date()
260
269
  };
261
270
  }
@@ -428,6 +437,15 @@ const variantKind = {
428
437
  slug: product.slug,
429
438
  variantLabel: product.variantLabel,
430
439
  compareAtPrice: product.compareAtPrice,
440
+ /**
441
+ * From the catalog bridge, which has carried `weightGrams` all along — the
442
+ * snapshot simply never captured it, so every checkout pricing delivery by
443
+ * weight saw an unweighable cart and fell back to the flat charge.
444
+ *
445
+ * Emitted only when real and positive: absent means unweighed, and a zero
446
+ * would select the cheapest weight step instead of the safe fallback.
447
+ */
448
+ ...typeof product.weightGrams === "number" && product.weightGrams > 0 ? { weightGrams: product.weightGrams } : {},
431
449
  capturedAt: ctx.clock?.now() ?? /* @__PURE__ */ new Date()
432
450
  };
433
451
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/cart",
3
- "version": "1.0.0",
3
+ "version": "1.1.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.32.0",
87
- "@classytic/primitives": ">=0.20.0",
88
- "@classytic/repo-core": ">=0.17.0",
86
+ "@classytic/mongokit": ">=3.33.0",
87
+ "@classytic/primitives": ">=0.23.0",
88
+ "@classytic/repo-core": ">=0.24.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": "^3.28.0",
96
- "@classytic/primitives": ">=0.20.0",
97
- "@classytic/repo-core": ">=0.20.0",
95
+ "@classytic/mongokit": "^3.33.0",
96
+ "@classytic/primitives": ">=0.23.0",
97
+ "@classytic/repo-core": ">=0.24.0",
98
98
  "@types/node": "^25.5.0",
99
99
  "knip": "^6.7.0",
100
100
  "mongodb-memory-server": "^10.2.3",