@openlup/platform 0.18.0 → 0.20.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 +146 -0
- package/README.md +34 -11
- package/dist/catalog/adminBundleReadHandler.d.ts +2 -1
- package/dist/catalog/adminBundleReadHandler.js +4 -4
- package/dist/catalog/bundleCatalogReadPort.d.ts +8 -1
- package/dist/catalog/bundleCatalogStore.d.ts +3 -1
- package/dist/catalog/bundleCatalogStore.js +5 -1
- package/dist/catalog/bundlePriceSelection.d.ts +13 -0
- package/dist/catalog/bundlePriceSelection.js +26 -0
- package/dist/catalog/contracts/bundleRead.d.ts +18 -0
- package/dist/catalog/contracts/draft.js +1 -1
- package/dist/catalog/effectiveBundleCatalogQueries.d.ts +8 -0
- package/dist/catalog/effectiveBundleCatalogQueries.js +79 -0
- package/dist/catalog/effectiveBundleCatalogStore.d.ts +4 -0
- package/dist/catalog/effectiveBundleCatalogStore.js +156 -0
- package/dist/catalog/index.d.ts +1 -0
- package/dist/catalog/index.js +1 -0
- package/dist/composition/index.d.ts +2 -0
- package/dist/composition/index.js +2 -0
- package/dist/composition/inventoryContribution.d.ts +16 -0
- package/dist/composition/inventoryContribution.js +17 -0
- package/dist/composition/shippingContribution.d.ts +16 -0
- package/dist/composition/shippingContribution.js +17 -0
- package/dist/inventory/bindings.d.ts +35 -0
- package/dist/inventory/bindings.js +45 -0
- package/dist/inventory/index.d.ts +1 -0
- package/dist/inventory/index.js +1 -0
- package/dist/pricing/commercePriceAuthority.d.ts +2 -0
- package/dist/pricing/commercePriceAuthority.js +61 -0
- package/dist/pricing/commerceQuoteHandler.d.ts +7 -3
- package/dist/pricing/commerceQuoteHandler.js +16 -4
- package/dist/pricing/dbBackedCommerceQuotePort.d.ts +8 -0
- package/dist/pricing/dbBackedCommerceQuotePort.js +46 -29
- package/dist/pricing/index.d.ts +2 -1
- package/dist/pricing/index.js +1 -1
- package/dist/pricing/offerPolicySchemas.d.ts +2 -2
- package/dist/pricing/offerPricingSchemas.d.ts +2 -2
- package/dist/pricing/pricingPolicyToken.d.ts +2 -2
- package/dist/pricing/quoteSchemas.d.ts +18 -18
- package/dist/pricing/quoteShippingPromotions.d.ts +20 -0
- package/dist/pricing/quoteShippingPromotions.js +1 -0
- package/dist/promotions/adminPromotionCodesContracts.d.ts +7 -7
- package/dist/promotions/commerceQuoteReadPreparation.d.ts +3 -0
- package/dist/promotions/commerceQuoteReadPreparation.js +27 -0
- package/dist/promotions/index.d.ts +3 -0
- package/dist/promotions/index.js +1 -0
- package/dist/promotions/promotionQuoteAcceptance.d.ts +5 -0
- package/dist/promotions/promotionQuoteAcceptance.js +12 -12
- package/dist/promotions/promotionQuoteBinding.d.ts +4 -2
- package/dist/promotions/promotionQuoteBinding.js +5 -3
- package/dist/promotions/quoteAcquisitionBinding.d.ts +6 -0
- package/dist/promotions/quoteAcquisitionBinding.js +1 -0
- package/dist/promotions/quoteAutomaticPromotions.d.ts +3 -1
- package/dist/promotions/quoteAutomaticPromotions.js +28 -4
- package/dist/promotions/quotePromoDiscounts.d.ts +5 -1
- package/dist/promotions/quotePromoDiscounts.js +8 -2
- package/dist/promotions/quotePromotionV2.d.ts +7 -6
- package/dist/promotions/quotePromotionV2.js +15 -3
- package/dist/promotions/quoteShippingPolicy.d.ts +23 -0
- package/dist/promotions/quoteShippingPolicy.js +47 -0
- package/dist/shipping/bindings.d.ts +62 -0
- package/dist/shipping/bindings.js +56 -0
- package/dist/shipping/contracts/index.d.ts +1 -0
- package/dist/shipping/contracts/threshold.d.ts +22 -0
- package/dist/shipping/contracts/threshold.js +1 -0
- package/dist/shipping/index.d.ts +17 -0
- package/dist/shipping/index.js +7 -0
- package/dist/shipping/thresholdPolicy.d.ts +42 -0
- package/dist/shipping/thresholdPolicy.js +60 -0
- package/package.json +2 -2
- package/release-gates.json +136 -134
- package/sql/20261021200000_shipping_flat_rate_seed.sql +1 -0
- package/src/catalog/adminBundleReadHandler.ts +6 -4
- package/src/catalog/bundleCatalogReadPort.ts +6 -2
- package/src/catalog/bundleCatalogStore.ts +5 -0
- package/src/catalog/bundlePriceSelection.ts +25 -0
- package/src/catalog/contracts/bundleRead.ts +2 -2
- package/src/catalog/contracts/draft.ts +1 -1
- package/src/catalog/effectiveBundleCatalogQueries.ts +80 -0
- package/src/catalog/effectiveBundleCatalogStore.ts +208 -0
- package/src/catalog/index.ts +1 -0
- package/src/composition/index.ts +2 -0
- package/src/composition/inventoryContribution.ts +24 -0
- package/src/composition/shippingContribution.ts +24 -0
- package/src/inventory/bindings.ts +61 -0
- package/src/inventory/index.ts +1 -0
- package/src/pricing/commercePriceAuthority.ts +65 -0
- package/src/pricing/commerceQuoteHandler.ts +20 -5
- package/src/pricing/dbBackedCommerceQuotePort.ts +50 -30
- package/src/pricing/index.ts +2 -1
- package/src/pricing/quoteShippingPromotions.ts +21 -0
- package/src/promotions/commerceQuoteReadPreparation.ts +29 -0
- package/src/promotions/index.ts +3 -0
- package/src/promotions/promotionQuoteAcceptance.ts +17 -10
- package/src/promotions/promotionQuoteBinding.ts +7 -2
- package/src/promotions/quoteAcquisitionBinding.ts +7 -0
- package/src/promotions/quoteAutomaticPromotions.ts +30 -4
- package/src/promotions/quotePromoDiscounts.ts +11 -2
- package/src/promotions/quotePromotionV2.ts +20 -4
- package/src/promotions/quoteShippingPolicy.ts +61 -0
- package/src/shipping/bindings.ts +90 -0
- package/src/shipping/contracts/index.ts +1 -0
- package/src/shipping/contracts/threshold.ts +22 -0
- package/src/shipping/index.ts +9 -0
- package/src/shipping/thresholdPolicy.ts +65 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,152 @@ SemVer promise.
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.20.0]
|
|
12
|
+
|
|
13
|
+
- Publishable on the npm `latest` dist-tag as `0.20.0`, from tag
|
|
14
|
+
`openlup-platform-v0.20.0`.
|
|
15
|
+
|
|
16
|
+
- Refresh release size-gate baselines from the published `0.19.0` tarballs; all caps remain unchanged.
|
|
17
|
+
|
|
18
|
+
- Keep active subscriptions active on portable dunning exhaustion (invariant repair).
|
|
19
|
+
|
|
20
|
+
Migration: apply the complete portable catalogue through
|
|
21
|
+
`20261021120000_dunning_lifecycle_active_repair.sql` at position 71. Previously,
|
|
22
|
+
NULL next retry expired the case and paused an active subscription; it now leaves
|
|
23
|
+
the case open and repairable, retains the final notice and exhaustion event, and
|
|
24
|
+
changes no subscription or cycle dates. Existing rows are not rewritten. Pass
|
|
25
|
+
NULL only when `isDunningLadderExhausted` holds; a class-terminated rung-one refusal
|
|
26
|
+
still must not be passed as NULL. There is no managed twin yet; the managed
|
|
27
|
+
baseline still needs a separate forward.
|
|
28
|
+
|
|
29
|
+
- Add the readiness-gated native flat-rate binding; the host supplies the named
|
|
30
|
+
role-free lane and fixed-key rate port, as in the reference composition.
|
|
31
|
+
- Require the native port and Core readiness for the shipping seed migration.
|
|
32
|
+
- Refuse missing-row saves; native audit remains explicitly unsupported and best effort.
|
|
33
|
+
|
|
34
|
+
Migration:
|
|
35
|
+
Apply the complete portable chain through 20261021200000_shipping_flat_rate_seed.
|
|
36
|
+
The seed preserves an existing rate and inserts zero only when absent; no ACL or
|
|
37
|
+
role changes are made. New code on an unmigrated schema keeps refusing. Older code
|
|
38
|
+
reads the seeded zero as it read an absent row. An application rollback does not reverse either forward
|
|
39
|
+
(positions 71 and 72), and older runners refuse the extended ledger.
|
|
40
|
+
Managed host-save authority remains pending.
|
|
41
|
+
|
|
42
|
+
- Add the shipping `SHIPPING_MIGRATIONS` export and the optional
|
|
43
|
+
`nativeRateReadiness` / `nativeRateSchema` binding dependencies.
|
|
44
|
+
|
|
45
|
+
Migration: upgrade the complete `@openlup/*` set from `0.19.0` to `0.20.0`
|
|
46
|
+
for exact internal pins. Native rate bindings require the selected port plus
|
|
47
|
+
Core readiness and a same-database schema observation of the applied seed.
|
|
48
|
+
Install the complete canonical migration catalogue, never sparse package
|
|
49
|
+
projections as an installation chain.
|
|
50
|
+
|
|
51
|
+
### Cumulative M06 status
|
|
52
|
+
|
|
53
|
+
- M06 remains incomplete: inventory and shipping are development-preview
|
|
54
|
+
surfaces, with managed-host proof classes pending.
|
|
55
|
+
- Inventory and shipping contracts, stock/ATP reads, reserve/release/expire
|
|
56
|
+
operations, subscription forecasts, delivery selection, address and flat-rate
|
|
57
|
+
handlers first shipped in `0.18.0`. Opt-in inventory/shipping/composition
|
|
58
|
+
bindings (P5a/P5b) first shipped in `0.19.0`. M06's only new behaviour in
|
|
59
|
+
`0.20.0` is native flat-rate save behind readiness; the portable dunning
|
|
60
|
+
invariant repair is separate from M06. Host-owned policy and unsupported
|
|
61
|
+
operations retain their explicit boundaries.
|
|
62
|
+
|
|
63
|
+
### Known limitations
|
|
64
|
+
|
|
65
|
+
- The portable dunning invariant repair has no managed twin in this set. The
|
|
66
|
+
managed baseline pauses active subscriptions on exhaustion; keeping them active
|
|
67
|
+
requires a separate managed forward. Portable proof does not establish managed parity.
|
|
68
|
+
|
|
69
|
+
- D8-1: native advisory v2 promo-code candidates and rejection details are not supported on the native backend.
|
|
70
|
+
- D8-2: native mounted v2 code issue/honor/fallback is not supported on the native backend.
|
|
71
|
+
- D8-3: acquisition-only mounted issuance/honor is not supported on the native backend.
|
|
72
|
+
- D8-4: full native/managed eligibility equivalence is not supported on the native backend.
|
|
73
|
+
- Bundle-1: independent database human-only actor-kind enforcement is not supported on the native backend and is the first item of a future native-backend parity round.
|
|
74
|
+
- Bundle-2: managed-equivalent actor-kind/email history is not supported on the native backend.
|
|
75
|
+
- Bundle-3 remains closed for M05 mounted admin/feed readback with an injected stock reader, while native new-purchase stock reads remain unsupported despite P5a's installed native inventory-store read proof.
|
|
76
|
+
- Bundle-4 establishes only incumbent real-PostgreSQL contention characterization and provides no exactly-once guarantee.
|
|
77
|
+
- The managed baseline schema and its pgTAP tests retain the incumbent legacy value `44.404`; removing it needs a forward migration and an owner decision, while reference composition supplies that value to application code.
|
|
78
|
+
- A1 evidence is offline only: account verification, hosted-time behaviour and owner TEST certification are not claimed, and the `communications/klaviyo` adapter's capabilities stay verification-pending.
|
|
79
|
+
- M05 parity seams are opt-in and omitted bindings preserve incumbent defaults, outputs, read order, scheduling, refusals, acceptance-token bytes and exported SQL.
|
|
80
|
+
- Native inventory adjustment remains unsupported; native address writes refuse
|
|
81
|
+
required-capability readiness. Native flat-rate save is supported only behind
|
|
82
|
+
the selected port, Core readiness and applied-seed schema observation.
|
|
83
|
+
- Native new-purchase stock read is deferred to the native-backend parity round
|
|
84
|
+
(owner 2026-10-21), second after M05 bundle-1; required readiness still refuses
|
|
85
|
+
honestly.
|
|
86
|
+
- Native shipping-rate save has no durable audit: audit is explicitly unsupported,
|
|
87
|
+
and the incumbent handler swallows the best-effort audit failure.
|
|
88
|
+
- Native flat-rate value bounds (integer, 0 <= value <= the host request schema's
|
|
89
|
+
maximum) are enforced by that schema, not a database CHECK; the reference
|
|
90
|
+
maximum is 100,000 minor units.
|
|
91
|
+
- Managed host ATP/forecast/dated-supply/pagination readback is not proved and
|
|
92
|
+
remains pending in the M06 ledger; no managed-host parity is claimed.
|
|
93
|
+
- Managed two-session lock order/concurrency and uncovered compensation paths
|
|
94
|
+
are not proved on a managed host and remain pending; no equivalence is claimed.
|
|
95
|
+
- Managed exact-prefix upgrade/ledger is not proved on a managed host and remains
|
|
96
|
+
pending; no managed installation equivalence is claimed.
|
|
97
|
+
- Managed address adapter idempotency/conflict/readback is not proved on a managed
|
|
98
|
+
host and remains pending; no fixture-to-host equivalence is claimed.
|
|
99
|
+
- Managed successful flat-rate read/save remains pending host authority and is
|
|
100
|
+
not proved on a managed host; no successful managed host-save claim is made.
|
|
101
|
+
- M06 adopter stock-wait lifecycle, durable subscription timing and staging
|
|
102
|
+
control observations retain their separate C5/C6 evidence gates. Busy/try-gate
|
|
103
|
+
protocol, durable stock-wait continuity and staging flag/TTL rows transferred
|
|
104
|
+
to C5 adopter evidence are dispositions, not PASS.
|
|
105
|
+
- Shipping contracts retain national-registry address fields and
|
|
106
|
+
`canonicalAddressKey` retains a locale-specific character fold. M16 owns their
|
|
107
|
+
move behind a host-supplied market pack with a canonical-key migration plan.
|
|
108
|
+
- Reference shipping UI copy remains locale-specific until M16.
|
|
109
|
+
|
|
110
|
+
## [0.19.0]
|
|
111
|
+
|
|
112
|
+
- Publishable on the npm `latest` dist-tag as `0.19.0`, from tag
|
|
113
|
+
`openlup-platform-v0.19.0`.
|
|
114
|
+
|
|
115
|
+
### 0.18.0 → 0.19.0 set scope
|
|
116
|
+
|
|
117
|
+
- Prepare the complete development-preview minor set at `0.19.0`, including everything on main since `0.18.0`; core and outbox are unchanged republications, and UI stays private `0.0.0`.
|
|
118
|
+
- M05 parity adds opt-in shipping-promise consent, post-discount threshold shipping and acquisition orchestration to the experimental pricing, promotions and shipping entries; financial policy and acquisition capability remain host supplied.
|
|
119
|
+
- M05 parity adds effective native bundle selection and an authoritative preview hook, optional resolved-target/detail/feed context fields and `selectEffectiveBundleTargetPrice`; effective feeds require unambiguous gross unit anchors and whole-BOM readiness.
|
|
120
|
+
- Add `createConcurrentCommercePriceAuthorityPort` with concurrent history scheduling, selected-list identity and base-refusal precedence; browser additions are type-only.
|
|
121
|
+
- Catalog/contracts draft canonical JSON detects lone surrogates without regex lookbehind so it loads in Safari before 16.4, with unchanged behavior.
|
|
122
|
+
- M06 P5a adds explicit inventory store/provider bindings and structural inventory contribution, keeping reference catalog-stock composition inert and managed authorization intact; native new-purchase stock reads remain unsupported pending an owner decision and native adjustment still refuses.
|
|
123
|
+
- M06 P5a retains focused installed-consumer, runtime-role, managed FEFO/adjustment and consume/refund replay evidence with unproved parity gates retained in the M06 ledger.
|
|
124
|
+
- M06 P5b adds opt-in shipping selection, address and flat-rate bindings with injected validation and authority; native address writes remain unsupported and refuse required readiness.
|
|
125
|
+
- M06 P5b adds the final isolated installed inventory/shipping consumer, preserving incumbent selection errors and flat-rate behavior.
|
|
126
|
+
- M06 in progress: inventory and shipping entries are early surfaces; module not complete
|
|
127
|
+
- Supporting main changes sort platform registration lists one item per line and use the database clock in the M05 P7 quote witness; neither adds runtime behavior.
|
|
128
|
+
|
|
129
|
+
Migration: upgrade the complete `@openlup/*` set from `0.18.0` to `0.19.0` for exact internal pins; existing bindings need no change and new module adoption remains explicit and experimental. Hosts selecting shipping promises must forward `shippingTerms` through both acceptance callbacks and use a context schema that preserves the selected terms. Bind `resolveQuoteShippingPromotions` to the promotions factory to select the bounded two-pass threshold path; financial policy and acquisition capability remain host supplied. The additive APIs require a minor set and introduce no activation. For both M05 24b and M06 P5b, the pricing and promotions API reports reorder existing enum/union members because declaration emit order changed (24b follows the catalog-to-pricing import); no member is added, removed or changed and callers need no migration for that reorder. Install the complete canonical migration catalogue, never sparse package projections as an installation chain; this preparation adds no SQL migration.
|
|
130
|
+
|
|
131
|
+
### Known limitations
|
|
132
|
+
|
|
133
|
+
- D8-1: native advisory v2 promo-code candidates and rejection details are not supported on the native backend.
|
|
134
|
+
- D8-2: native mounted v2 code issue/honor/fallback is not supported on the native backend.
|
|
135
|
+
- D8-3: acquisition-only mounted issuance/honor is not supported on the native backend.
|
|
136
|
+
- D8-4: full native/managed eligibility equivalence is not supported on the native backend.
|
|
137
|
+
- Bundle-1: independent database human-only actor-kind enforcement is not supported on the native backend and is the first item of a future native-backend parity round.
|
|
138
|
+
- Bundle-2: managed-equivalent actor-kind/email history is not supported on the native backend.
|
|
139
|
+
- Bundle-3 remains closed for M05 mounted admin/feed readback with an injected stock reader, while native new-purchase stock reads remain unsupported despite P5a's installed native inventory-store read proof.
|
|
140
|
+
- Bundle-4 establishes only incumbent real-PostgreSQL contention characterization and provides no exactly-once guarantee.
|
|
141
|
+
- The managed baseline schema and its pgTAP tests retain the incumbent legacy value `44.404`; removing it needs a forward migration and an owner decision, while reference composition supplies that value to application code.
|
|
142
|
+
- A1 evidence is offline only: account verification, hosted-time behaviour and owner TEST certification are not claimed, and the `communications/klaviyo` adapter's capabilities stay verification-pending.
|
|
143
|
+
- M05 parity seams are opt-in and omitted bindings preserve incumbent defaults, outputs, read order, scheduling, refusals, acceptance-token bytes and exported SQL.
|
|
144
|
+
- Native inventory adjustment remains unsupported; native address writes and flat-rate saves refuse required-capability readiness.
|
|
145
|
+
- M06 managed host ATP/forecast/supply/pagination, remaining compensation/concurrency/lock-order, exact-prefix upgrade/ledger, address idempotency/conflict/readback and runtime rate authority remain pending in the M06 ledger.
|
|
146
|
+
- M06 adopter stock-wait lifecycle, durable subscription timing and staging control observations retain their separate C5/C6 evidence gates.
|
|
147
|
+
|
|
148
|
+
### Size note
|
|
149
|
+
|
|
150
|
+
Only platform `pack.docs.maxPackedBytes` rises from 40,960 to 49,152 B; all other caps and budgets remain unchanged. All three baselines use integrity-verified published `0.18.0` tarballs.
|
|
151
|
+
|
|
152
|
+
Question (2026-10-21): "The platform package's root docs (README + CHANGELOG) will exceed their 40,960 B gzip cap at the next release. What should we do?"
|
|
153
|
+
Owner's answer: "Raise to 49,152 B (Recommended)"
|
|
154
|
+
Option description shown to the owner: "Same figure as core. Unblocks the next few releases; the CHANGELOG grows every release, so this cap would otherwise block each one."
|
|
155
|
+
Recorded as an owner decision taken through the coordinator's question on 2026-10-21.
|
|
156
|
+
|
|
11
157
|
## [0.18.0]
|
|
12
158
|
|
|
13
159
|
- Publishable on the npm `latest` dist-tag as `0.18.0`, from tag
|
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# @openlup/platform
|
|
2
2
|
|
|
3
|
-
Development preview. This package
|
|
3
|
+
Development preview. This package is part of the publishable set with core and outbox; preparation does not establish a registry release or a stable API. Its repository-directory publish command refuses publication; the authorized package-release workflow owns publication.
|
|
4
4
|
|
|
5
5
|
It holds the runnable server substrate an OpenLup application composes: the Node HTTP runtime, BFF dispatch, scheduling and job leases, blob storage, data gateways, the node-postgres migration runner and bundle composition. Ports and their contracts stay in `@openlup/core/platform-runtime`.
|
|
6
6
|
|
|
7
|
-
For the prepared `0.
|
|
8
|
-
limitations](CHANGELOG.md#
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
For the prepared `0.20.0` set, read the [adjacent-release migration and known
|
|
8
|
+
limitations](CHANGELOG.md#0200) before selecting the opt-in M05 parity seams or
|
|
9
|
+
M06 composition bindings. M06 remains incomplete: inventory and shipping entries
|
|
10
|
+
are development-preview surfaces, with managed-host proof classes pending in the
|
|
11
|
+
[M06 parity ledger](../../docs/platform/plans/oss-m06-stock-reservations-delivery.md#parity-pending-rows).
|
|
12
|
+
The size gate compares the prepared `0.20.0` set with the published `0.19.0` tarball;
|
|
11
13
|
preparation, offline adapter evidence and a passing size cap grant no publication
|
|
12
14
|
or provider-account certification.
|
|
13
15
|
|
|
@@ -37,16 +39,24 @@ or provider-account certification.
|
|
|
37
39
|
| `./pricing/contracts` | Dependency-free authority, money, quote and offer DTOs and version constants |
|
|
38
40
|
| `./promotions` | Experimental promotion application, admin handlers, native read/sweep, SQL projections and acceptance |
|
|
39
41
|
| `./promotions/contracts` | Dependency-free preview and admin DTOs |
|
|
40
|
-
| `./shipping` | Experimental delivery ports, injected-schema handlers, summary
|
|
42
|
+
| `./shipping` | Experimental delivery ports, injected-schema handlers, summary/evidence; native flat-rate port + Core schema readiness |
|
|
41
43
|
| `./shipping/contracts` | Type-only delivery, pickup-point, summary and evidence DTOs |
|
|
42
44
|
|
|
43
45
|
## Shipping
|
|
44
46
|
|
|
45
47
|
Shipping handlers require injected host schemas; contracts are type-only with opaque provider/carrier strings.
|
|
46
48
|
No vendor code, inventory import, activation or parity claim.
|
|
49
|
+
Native flat-rate save requires the rate port, a ready Core report and
|
|
50
|
+
`nativeRateSchema`, a same-database Core `SchemaObservation` proving the applied
|
|
51
|
+
seed identity and settings objects. A candidate schema label is not proof;
|
|
52
|
+
later forwards do not invalidate an applied seed. The reference host exposes
|
|
53
|
+
`observeNativeRateSchema()` for this ledger/object observation and retains
|
|
54
|
+
caller-declared schema requirements. Missing proof keeps the named refusal.
|
|
47
55
|
|
|
48
56
|
## Inventory
|
|
49
57
|
|
|
58
|
+
`createInventoryBindings` selects one store with exact host provider validation. Native new-purchase reads refuse as `inventory_native_new_purchase_stock_read_unsupported`; `createInventoryContribution` declares selected callables without activation.
|
|
59
|
+
|
|
50
60
|
`INVENTORY_MIGRATIONS` projects canonical units 27/33 byte-for-byte; install the full catalogue. Store support and pending proof: [M06 parity](../../docs/platform/plans/oss-m06-stock-reservations-delivery.md#parity-pending-rows).
|
|
51
61
|
|
|
52
62
|
## Promotions
|
|
@@ -65,8 +75,8 @@ require the floor. No factory supplies a default financial policy.
|
|
|
65
75
|
the host's exact request-binding projection; `promoCodes` also binds separately.
|
|
66
76
|
Its four issue/verify functions retain public-money projection, section diagnostics,
|
|
67
77
|
TTL and rotation. Explicit `acquisitionTerms` binds the full server-selected promise.
|
|
68
|
-
The pricing quote handler passes
|
|
69
|
-
acceptance callbacks. A host must forward them to the acceptance helper. With no
|
|
78
|
+
The pricing quote handler passes resolved acquisition terms to both
|
|
79
|
+
acceptance callbacks. An opt-in shipping binding appends shipping terms. A host must forward them to the acceptance helper. With no
|
|
70
80
|
acquisition configuration, terms are absent and historical token bytes stay equal.
|
|
71
81
|
This opt-in signature addition does not activate acquisition-only mounted issuance.
|
|
72
82
|
|
|
@@ -113,6 +123,10 @@ full native/managed eligibility matrix are accepted native-backend capability
|
|
|
113
123
|
gaps, without a parity claim, in the
|
|
114
124
|
[module ledger](../../docs/platform/plans/oss-m05-catalog-offers-pricing.md#d8-pending-outcome-ledger).
|
|
115
125
|
|
|
126
|
+
Opt-in `shippingTerms` also binds shipping-only promises. `createQuoteShippingPromotions`
|
|
127
|
+
resolves post-discount thresholds; optional `acquisition` bindings select host policy.
|
|
128
|
+
Omission preserves incumbent behavior. See [parity seams](../../docs/platform/CANONICAL_CONTRACTS.md#m05-parity-seams).
|
|
129
|
+
|
|
116
130
|
## Pricing
|
|
117
131
|
|
|
118
132
|
`./pricing` provides the existing OpenLup strict commerce price authority,
|
|
@@ -122,7 +136,9 @@ price-list, base-entry, legacy-entry and policy-history reads. The authority
|
|
|
122
136
|
validates the base before reading history and uses the observed base's
|
|
123
137
|
`priceListId` for that lookup. History excludes legacy fallback even when no
|
|
124
138
|
revision is currently effective. Digest, interval, ambiguity and amount-kind
|
|
125
|
-
refusals retain their existing identities and precedence.
|
|
139
|
+
refusals retain their existing identities and precedence. The opt-in
|
|
140
|
+
`createConcurrentCommercePriceAuthorityPort` instead schedules history alongside
|
|
141
|
+
base reads using the selected list ID, with base-refusal precedence.
|
|
126
142
|
|
|
127
143
|
`./pricing/contracts` contains dependency-free authority observations, policy
|
|
128
144
|
DTOs and version constants; its only external type comes from the exact
|
|
@@ -186,7 +202,9 @@ terms can join the existing acceptance money projection and totals section;
|
|
|
186
202
|
absence contributes no property. Quote/batch refusal mapping and unsigned-terms
|
|
187
203
|
fallback checks require explicit acquisition configuration. Reference composition
|
|
188
204
|
supplies none: existing schemas, headers, reads, error details and token bytes
|
|
189
|
-
are preserved.
|
|
205
|
+
are preserved. Threshold shipping is supplied by the separate
|
|
206
|
+
[parity seam](../../docs/platform/CANONICAL_CONTRACTS.md#m05-parity-seams).
|
|
207
|
+
Checkout admission, claims, finalization,
|
|
190
208
|
promotion implementation, stores, SQL, routes and activation remain outside
|
|
191
209
|
this API.
|
|
192
210
|
|
|
@@ -198,6 +216,10 @@ in the application. The existing cold consumer exercises both entries and
|
|
|
198
216
|
compiles installed declarations without optional provider peers.
|
|
199
217
|
|
|
200
218
|
## Catalog
|
|
219
|
+
Opt-in `priceAuthority: "effective"` on the native bundle store and the admin
|
|
220
|
+
`effectiveTarget` hook provide [effective bundle parity](../../docs/platform/CANONICAL_CONTRACTS.md#m05-parity-seams);
|
|
221
|
+
`selectEffectiveBundleTargetPrice` is exported. Omitted seams preserve defaults.
|
|
222
|
+
|
|
201
223
|
The native envelope and dark draft adapters now live in this entry as
|
|
202
224
|
`createPostgresCatalogSkuEnvelopeReadPort` and `createPostgresCatalogDraftStore`.
|
|
203
225
|
They accept an injected executor and retain the existing mapping, errors and SQL
|
|
@@ -210,7 +232,8 @@ The composition entry adds `createCatalogContribution` and its structural input
|
|
|
210
232
|
interface. It describes actual catalog, pricing and promotions callables under
|
|
211
233
|
those existing module identities, with no environment discovery, client creation
|
|
212
234
|
or registration. It imports only readiness types: composition gains no catalog
|
|
213
|
-
edge, and catalog
|
|
235
|
+
edge, and catalog keeps its type-only data edge plus one pricing value edge for
|
|
236
|
+
the effective-window selector. Package boundary
|
|
214
237
|
checks pin those imports and peer-free composition declarations. The packed
|
|
215
238
|
consumer exercises both new stores and the descriptor without optional peers;
|
|
216
239
|
its synthetic executor proves named refusal, not durable storage behavior.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { BundleAdminBindings, AuthorizeAdmin } from "./adminBindings.js";
|
|
2
2
|
import type { BundleAvailabilityService } from "./bundleAvailabilityService.js";
|
|
3
|
-
import type { BundleCatalogReadPort } from "./bundleCatalogReadPort.js";
|
|
3
|
+
import type { BundleCatalogReadPort, BundleDetail, BundleTargetPriceRow } from "./bundleCatalogReadPort.js";
|
|
4
4
|
export interface AdminBundleReadHandlerDeps {
|
|
5
|
+
effectiveTarget?: (bundle: BundleDetail) => BundleTargetPriceRow | null;
|
|
5
6
|
readPort: BundleCatalogReadPort;
|
|
6
7
|
authorizeAdmin: AuthorizeAdmin;
|
|
7
8
|
readsEnabled: boolean;
|
|
@@ -107,7 +107,7 @@ export function createAdminBundleReadHandlers({ bundleSpec, BundleRpcError, COMM
|
|
|
107
107
|
});
|
|
108
108
|
if (!bundle)
|
|
109
109
|
throw new BundleRpcError("P0002", "bundle_not_found");
|
|
110
|
-
return previewBundlePrice(bundle, input);
|
|
110
|
+
return previewBundlePrice(bundle, input, deps.effectiveTarget);
|
|
111
111
|
}, (preview) => ({ contractVersion: COMMERCE_CONTRACT_VERSION, preview }), previewBundlePriceResponseSchema, "Invalid bundle price preview response");
|
|
112
112
|
}
|
|
113
113
|
/** The detail the transport carries: the port's internal variant id stays server-side. */
|
|
@@ -140,7 +140,7 @@ export function createAdminBundleReadHandlers({ bundleSpec, BundleRpcError, COMM
|
|
|
140
140
|
* no priced list (P0002), an unpriced component or an empty set (P0001), and the
|
|
141
141
|
* kernel's own three failure codes (P0001).
|
|
142
142
|
*/
|
|
143
|
-
function previewBundlePrice(bundle, input) {
|
|
143
|
+
function previewBundlePrice(bundle, input, effectiveTarget) {
|
|
144
144
|
if (!bundle.resolvedPriceListId || !bundle.resolvedCurrency) {
|
|
145
145
|
throw new BundleRpcError("P0002", "no_active_price_list");
|
|
146
146
|
}
|
|
@@ -151,7 +151,7 @@ export function createAdminBundleReadHandlers({ bundleSpec, BundleRpcError, COMM
|
|
|
151
151
|
if (unpriced.length > 0) {
|
|
152
152
|
throw new BundleRpcError("P0001", `component_unpriced:${unpriced[0].sku}`);
|
|
153
153
|
}
|
|
154
|
-
const activePrice = bundle.prices.find((price) => price.active && (!input.mode || price.mode === input.mode));
|
|
154
|
+
const activePrice = effectiveTarget ? effectiveTarget(bundle) : bundle.prices.find((price) => price.active && (!input.mode || price.mode === input.mode));
|
|
155
155
|
const targetPriceMinor = input.targetPriceMinor ?? activePrice?.targetPriceMinor;
|
|
156
156
|
if (targetPriceMinor === undefined)
|
|
157
157
|
throw new BundleRpcError("P0002", "no_active_target_price");
|
|
@@ -170,7 +170,7 @@ export function createAdminBundleReadHandlers({ bundleSpec, BundleRpcError, COMM
|
|
|
170
170
|
return {
|
|
171
171
|
bundleCode: bundle.code,
|
|
172
172
|
priceListId: bundle.resolvedPriceListId,
|
|
173
|
-
mode: input.mode ?? activePrice?.mode ?? "any",
|
|
173
|
+
mode: input.mode ?? activePrice?.mode ?? (effectiveTarget ? "one_time" : "any"),
|
|
174
174
|
currency: bundle.resolvedCurrency,
|
|
175
175
|
referenceTotalMinor: allocation.referenceTotalMinor,
|
|
176
176
|
targetPriceMinor: allocation.targetPriceMinor,
|
|
@@ -91,6 +91,8 @@ export interface BundleDetail extends BundleSummary {
|
|
|
91
91
|
metadata: Record<string, unknown>;
|
|
92
92
|
components: BundleComponentRow[];
|
|
93
93
|
prices: BundleTargetPriceRow[];
|
|
94
|
+
/** Present only when the host selects effective price authority. */
|
|
95
|
+
resolvedTargetPrice?: BundleTargetPriceRow | null;
|
|
94
96
|
/** The currency whose list resolved `referenceUnitPriceMinor`; `null` if none did. */
|
|
95
97
|
resolvedCurrency: string | null;
|
|
96
98
|
/**
|
|
@@ -108,8 +110,10 @@ export interface GetBundleInput {
|
|
|
108
110
|
* only currency an operator has actually chosen for it.
|
|
109
111
|
*/
|
|
110
112
|
currency?: string;
|
|
111
|
-
/** Narrow the target price whose list is selected; omitted means any mode. */
|
|
113
|
+
/** Narrow the target price whose list is selected; omitted means any mode (the opt-in effective store defaults to one_time). */
|
|
112
114
|
mode?: string;
|
|
115
|
+
regionCode?: string;
|
|
116
|
+
atTime?: string;
|
|
113
117
|
}
|
|
114
118
|
/**
|
|
115
119
|
* One live, sellable bundle: active status, an active target price, and its
|
|
@@ -156,6 +160,9 @@ export interface BundleCatalogReadPort {
|
|
|
156
160
|
*/
|
|
157
161
|
listActiveBundleCompositions(input?: {
|
|
158
162
|
currency?: string;
|
|
163
|
+
regionCode?: string;
|
|
164
|
+
mode?: "one_time" | "subscription";
|
|
165
|
+
atTime?: string;
|
|
159
166
|
}): Promise<ActiveBundleComposition[]>;
|
|
160
167
|
/**
|
|
161
168
|
* The operator trail for one bundle. The two chains answer from different
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { BundleCatalogReadPort } from "./bundleCatalogReadPort.js";
|
|
2
2
|
import type { PgQueryExecutor } from "../data/index.js";
|
|
3
|
-
export declare function createPostgresBundleCatalogStore(executor: PgQueryExecutor
|
|
3
|
+
export declare function createPostgresBundleCatalogStore(executor: PgQueryExecutor, options?: {
|
|
4
|
+
priceAuthority?: "effective";
|
|
5
|
+
}): BundleCatalogReadPort;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { createEffectiveBundleCatalogStore } from "./effectiveBundleCatalogStore.js";
|
|
1
2
|
import { BundleCatalogReadError, } from "./bundleCatalogReadPort.js";
|
|
2
3
|
import { LIST_SQL, COUNT_SQL, DETAIL_SQL, COMPONENT_SQL, FEED_COMPONENT_SQL, PRICE_SQL, OWN_LIST_SQL, CURRENCY_LIST_SQL, FEED_SQL, HISTORY_SQL, HISTORY_COUNT_SQL, } from "./bundleCatalogQueries.js";
|
|
3
|
-
export function createPostgresBundleCatalogStore(executor) {
|
|
4
|
+
export function createPostgresBundleCatalogStore(executor, options) {
|
|
5
|
+
if (options?.priceAuthority === "effective") {
|
|
6
|
+
return createEffectiveBundleCatalogStore(executor, createPostgresBundleCatalogStore(executor));
|
|
7
|
+
}
|
|
4
8
|
async function rows(sql, values) {
|
|
5
9
|
// A driver failure becomes the port's own read error, so a caller sees the
|
|
6
10
|
// same distinction between "found nothing" and "could not ask" on both chains.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type BundleTargetPriceRow } from "./bundleCatalogReadPort.js";
|
|
2
|
+
export declare function uniqueBundlePrice<T extends {
|
|
3
|
+
mode: string;
|
|
4
|
+
}>(rows: readonly T[], mode: string): T | null;
|
|
5
|
+
export declare function selectEffectiveBundleTargetPrice(rows: readonly {
|
|
6
|
+
price: BundleTargetPriceRow;
|
|
7
|
+
priceListId: string;
|
|
8
|
+
}[], context: {
|
|
9
|
+
priceListId: string | null;
|
|
10
|
+
currency: string | null;
|
|
11
|
+
mode: string;
|
|
12
|
+
atTime: string;
|
|
13
|
+
}): BundleTargetPriceRow | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { selectUniqueEffectivePriceList } from "../pricing/index.js";
|
|
2
|
+
import { BundleCatalogReadError } from "./bundleCatalogReadPort.js";
|
|
3
|
+
/** Half-open windows share the price authority's effective-time rule. */
|
|
4
|
+
function bundlePriceEffective(row, atTime) {
|
|
5
|
+
try {
|
|
6
|
+
selectUniqueEffectivePriceList([{ value: "row", ...row }], atTime);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function uniqueBundlePrice(rows, mode) {
|
|
14
|
+
const exact = rows.filter(row => row.mode === mode);
|
|
15
|
+
const candidates = exact.length ? exact : rows.filter(row => row.mode === "any");
|
|
16
|
+
if (candidates.length > 1)
|
|
17
|
+
throw new BundleCatalogReadError("bundle_price_ambiguous");
|
|
18
|
+
return candidates[0] ?? null;
|
|
19
|
+
}
|
|
20
|
+
export function selectEffectiveBundleTargetPrice(rows, context) {
|
|
21
|
+
if (context.priceListId === null || context.currency === null)
|
|
22
|
+
return null;
|
|
23
|
+
return uniqueBundlePrice(rows.filter(row => row.priceListId === context.priceListId
|
|
24
|
+
&& row.price.currency === context.currency && row.price.active && row.price.amountKind === "gross"
|
|
25
|
+
&& row.price.targetPriceMinor > 0 && bundlePriceEffective(row.price, context.atTime)).map(row => row.price), context.mode);
|
|
26
|
+
}
|
|
@@ -65,6 +65,15 @@ export type GetBundleResponse = {
|
|
|
65
65
|
validFrom: string;
|
|
66
66
|
validTo: string | null;
|
|
67
67
|
}[];
|
|
68
|
+
resolvedTargetPrice?: {
|
|
69
|
+
mode: string;
|
|
70
|
+
targetPriceMinor: number;
|
|
71
|
+
currency: string;
|
|
72
|
+
amountKind: string;
|
|
73
|
+
active: boolean;
|
|
74
|
+
validFrom: string;
|
|
75
|
+
validTo: string | null;
|
|
76
|
+
} | null;
|
|
68
77
|
resolvedCurrency: string | null;
|
|
69
78
|
availability: {
|
|
70
79
|
sellableNow: number | null;
|
|
@@ -113,6 +122,15 @@ export type BundleDetailView = {
|
|
|
113
122
|
validFrom: string;
|
|
114
123
|
validTo: string | null;
|
|
115
124
|
}[];
|
|
125
|
+
resolvedTargetPrice?: {
|
|
126
|
+
mode: string;
|
|
127
|
+
targetPriceMinor: number;
|
|
128
|
+
currency: string;
|
|
129
|
+
amountKind: string;
|
|
130
|
+
active: boolean;
|
|
131
|
+
validFrom: string;
|
|
132
|
+
validTo: string | null;
|
|
133
|
+
} | null;
|
|
116
134
|
resolvedCurrency: string | null;
|
|
117
135
|
availability: {
|
|
118
136
|
sellableNow: number | null;
|
|
@@ -7,7 +7,7 @@ export function canonicalCatalogDraftJson(input) {
|
|
|
7
7
|
if (depth > 48)
|
|
8
8
|
throw new Error("draft_json_depth");
|
|
9
9
|
if (typeof value === "string") {
|
|
10
|
-
if (value.includes("\u0000") || /[\uD800-\
|
|
10
|
+
if (value.includes("\u0000") || /[\uD800-\uDFFF]/u.test(value))
|
|
11
11
|
throw new Error("draft_json_invalid");
|
|
12
12
|
return value;
|
|
13
13
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const COMPONENT_SQL: string;
|
|
2
|
+
export declare const FEED_COMPONENT_SQL: string;
|
|
3
|
+
export declare const PRICE_SQL = "\n SELECT p.mode, p.price_list_id, p.target_price_minor, list.currency, p.amount_kind, p.active, p.valid_from, p.valid_to\n FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id\n WHERE p.bundle_id = $1::uuid ORDER BY p.valid_from DESC";
|
|
4
|
+
export declare const OWN_LIST_SQL = "\n SELECT list.id, list.currency, list.region_code, p.mode\n FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id\n WHERE p.bundle_id = $1::uuid AND p.active AND p.amount_kind = 'gross'\n AND (p.mode = $2::text OR p.mode = 'any') AND list.status = 'active'\n AND p.valid_from <= $3::timestamptz AND (p.valid_to IS NULL OR p.valid_to > $3::timestamptz)\n AND list.valid_from <= $3::timestamptz AND (list.valid_to IS NULL OR list.valid_to > $3::timestamptz)\n ORDER BY p.valid_from DESC";
|
|
5
|
+
export declare const CURRENCY_LIST_SQL = "\n SELECT id, currency, region_code FROM public.price_lists\n WHERE currency = $1::text AND status = 'active' AND ($2::text IS NULL OR region_code = $2::text)\n AND valid_from <= $3::timestamptz AND (valid_to IS NULL OR valid_to > $3::timestamptz)";
|
|
6
|
+
export declare const FEED_SQL = "\n SELECT b.id, b.code, b.title, b.fulfillment_mode, p.mode, p.target_price_minor, p.price_list_id, list.currency, list.region_code\n FROM public.catalog_bundles b\n JOIN public.catalog_bundle_prices p ON p.bundle_id = b.id AND p.active\n JOIN public.price_lists list ON list.id = p.price_list_id\n WHERE b.status = 'active' AND p.amount_kind = 'gross' AND p.target_price_minor > 0\n AND list.status = 'active' AND ($1::text IS NULL OR list.currency = $1::text)\n AND ($2::text IS NULL OR list.region_code = $2::text) AND (p.mode = $4::text OR p.mode = 'any')\n AND p.valid_from <= $3::timestamptz AND (p.valid_to IS NULL OR p.valid_to > $3::timestamptz)\n AND list.valid_from <= $3::timestamptz AND (list.valid_to IS NULL OR list.valid_to > $3::timestamptz)\n ORDER BY b.code, p.valid_from DESC";
|
|
7
|
+
export declare const DETAIL_SQL = "SELECT b.id, b.code, b.title, b.status, b.fulfillment_mode, b.updated_at,\n b.composition_constraint, b.metadata,\n (SELECT count(*) FROM public.catalog_bundle_components c WHERE c.bundle_id = b.id) AS component_count,\n EXISTS (SELECT 1 FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id\n WHERE p.bundle_id = b.id AND p.active AND p.amount_kind = 'gross' AND p.target_price_minor > 0\n AND p.mode IN ('one_time', 'any') AND list.status = 'active'\n AND p.valid_from <= CURRENT_TIMESTAMP AND (p.valid_to IS NULL OR p.valid_to > CURRENT_TIMESTAMP)\n AND list.valid_from <= CURRENT_TIMESTAMP AND (list.valid_to IS NULL OR list.valid_to > CURRENT_TIMESTAMP)) AS has_active_target_price FROM public.catalog_bundles b WHERE b.code = $1";
|
|
8
|
+
export declare const LIST_SQL = "SELECT b.id, b.code, b.title, b.status, b.fulfillment_mode, b.updated_at,\n b.composition_constraint, b.metadata,\n (SELECT count(*) FROM public.catalog_bundle_components c WHERE c.bundle_id = b.id) AS component_count,\n EXISTS (SELECT 1 FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id\n WHERE p.bundle_id = b.id AND p.active AND p.amount_kind = 'gross' AND p.target_price_minor > 0\n AND p.mode IN ('one_time', 'any') AND list.status = 'active'\n AND p.valid_from <= CURRENT_TIMESTAMP AND (p.valid_to IS NULL OR p.valid_to > CURRENT_TIMESTAMP)\n AND list.valid_from <= CURRENT_TIMESTAMP AND (list.valid_to IS NULL OR list.valid_to > CURRENT_TIMESTAMP)) AS has_active_target_price FROM public.catalog_bundles b\n WHERE ($1::text = 'all' OR b.status = $1::text)\n AND ($2::text IS NULL OR b.code ILIKE '%' || $2 || '%' OR b.title ILIKE '%' || $2 || '%')\n ORDER BY b.code LIMIT $3 OFFSET $4";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Effective-authority SQL is isolated from the incumbent exported statements. */
|
|
2
|
+
const ANCHORS = `SELECT pe.unit_price_minor FROM public.price_entries pe
|
|
3
|
+
WHERE pe.variant_id = s.id AND pe.price_list_id = %LIST% AND pe.active
|
|
4
|
+
AND pe.min_qty = 1 AND pe.amount_kind = 'gross'
|
|
5
|
+
AND pe.valid_from <= $3::timestamptz AND (pe.valid_to IS NULL OR pe.valid_to > $3::timestamptz)
|
|
6
|
+
AND (pe.mode = $4::text OR (pe.mode = 'any' AND NOT EXISTS (
|
|
7
|
+
SELECT 1 FROM public.price_entries exact WHERE exact.variant_id = s.id
|
|
8
|
+
AND exact.price_list_id = pe.price_list_id AND exact.active AND exact.min_qty = 1
|
|
9
|
+
AND exact.amount_kind = 'gross' AND exact.mode = $4::text
|
|
10
|
+
AND exact.valid_from <= $3::timestamptz AND (exact.valid_to IS NULL OR exact.valid_to > $3::timestamptz))))`;
|
|
11
|
+
const FACTS = `s.status AS sku_status, s.sellable_standalone, s.sellable_in_subscription,
|
|
12
|
+
s.net_weight_g, pr.status AS product_status,
|
|
13
|
+
(pr.primary_sku_id IS NOT NULL AND revision.id IS NOT NULL) AS document_ready,
|
|
14
|
+
COALESCE((SELECT jsonb_agg(jsonb_build_object('issuer', identifier.issuer, 'normalizedValue', identifier.normalized_value,
|
|
15
|
+
'kind', identifier.identifier_kind, 'packKind', identifier.pack_kind, 'packQuantity', identifier.quantity, 'isPrimary', identifier.is_primary))
|
|
16
|
+
FROM public.catalog_sku_identifiers identifier WHERE identifier.catalog_sku_id = s.id), '[]'::jsonb) AS identifiers`;
|
|
17
|
+
const REFERENCE = `(SELECT (array_agg(candidate.unit_price_minor))[1] FROM (${ANCHORS}) candidate)`;
|
|
18
|
+
const COUNT = `(SELECT count(*) FROM (${ANCHORS}) candidate)`;
|
|
19
|
+
export const COMPONENT_SQL = `
|
|
20
|
+
SELECT c.bundle_id, s.sku, s.title, pr.slug AS product_slug, s.id AS variant_id,
|
|
21
|
+
c.quantity, c.is_addon, c.sort_order, ${FACTS},
|
|
22
|
+
${REFERENCE.replace("%LIST%", "$2::uuid")} AS reference_unit_price_minor,
|
|
23
|
+
${COUNT.replace("%LIST%", "$2::uuid")} AS reference_price_count
|
|
24
|
+
FROM public.catalog_bundle_components c
|
|
25
|
+
JOIN public.catalog_skus s ON s.id = c.catalog_sku_id
|
|
26
|
+
JOIN public.catalog_products pr ON pr.id = s.product_id
|
|
27
|
+
LEFT JOIN public.catalog_product_document_revisions revision ON revision.id = pr.current_document_revision_id AND revision.product_id = pr.id
|
|
28
|
+
WHERE c.bundle_id = $1::uuid ORDER BY c.sort_order, s.sku`;
|
|
29
|
+
export const FEED_COMPONENT_SQL = `
|
|
30
|
+
SELECT c.bundle_id, s.sku, s.title, pr.slug AS product_slug, s.id AS variant_id,
|
|
31
|
+
c.quantity, c.is_addon, c.sort_order, ${FACTS},
|
|
32
|
+
${REFERENCE.replace("%LIST%", "selected.price_list_id")} AS reference_unit_price_minor,
|
|
33
|
+
${COUNT.replace("%LIST%", "selected.price_list_id")} AS reference_price_count
|
|
34
|
+
FROM unnest($1::uuid[], $2::uuid[]) AS selected(bundle_id, price_list_id)
|
|
35
|
+
JOIN public.catalog_bundle_components c ON c.bundle_id = selected.bundle_id
|
|
36
|
+
JOIN public.catalog_skus s ON s.id = c.catalog_sku_id
|
|
37
|
+
JOIN public.catalog_products pr ON pr.id = s.product_id
|
|
38
|
+
LEFT JOIN public.catalog_product_document_revisions revision ON revision.id = pr.current_document_revision_id AND revision.product_id = pr.id
|
|
39
|
+
ORDER BY c.bundle_id, c.sort_order, s.sku`;
|
|
40
|
+
export const PRICE_SQL = `
|
|
41
|
+
SELECT p.mode, p.price_list_id, p.target_price_minor, list.currency, p.amount_kind, p.active, p.valid_from, p.valid_to
|
|
42
|
+
FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id
|
|
43
|
+
WHERE p.bundle_id = $1::uuid ORDER BY p.valid_from DESC`;
|
|
44
|
+
export const OWN_LIST_SQL = `
|
|
45
|
+
SELECT list.id, list.currency, list.region_code, p.mode
|
|
46
|
+
FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id
|
|
47
|
+
WHERE p.bundle_id = $1::uuid AND p.active AND p.amount_kind = 'gross'
|
|
48
|
+
AND (p.mode = $2::text OR p.mode = 'any') AND list.status = 'active'
|
|
49
|
+
AND p.valid_from <= $3::timestamptz AND (p.valid_to IS NULL OR p.valid_to > $3::timestamptz)
|
|
50
|
+
AND list.valid_from <= $3::timestamptz AND (list.valid_to IS NULL OR list.valid_to > $3::timestamptz)
|
|
51
|
+
ORDER BY p.valid_from DESC`;
|
|
52
|
+
export const CURRENCY_LIST_SQL = `
|
|
53
|
+
SELECT id, currency, region_code FROM public.price_lists
|
|
54
|
+
WHERE currency = $1::text AND status = 'active' AND ($2::text IS NULL OR region_code = $2::text)
|
|
55
|
+
AND valid_from <= $3::timestamptz AND (valid_to IS NULL OR valid_to > $3::timestamptz)`;
|
|
56
|
+
export const FEED_SQL = `
|
|
57
|
+
SELECT b.id, b.code, b.title, b.fulfillment_mode, p.mode, p.target_price_minor, p.price_list_id, list.currency, list.region_code
|
|
58
|
+
FROM public.catalog_bundles b
|
|
59
|
+
JOIN public.catalog_bundle_prices p ON p.bundle_id = b.id AND p.active
|
|
60
|
+
JOIN public.price_lists list ON list.id = p.price_list_id
|
|
61
|
+
WHERE b.status = 'active' AND p.amount_kind = 'gross' AND p.target_price_minor > 0
|
|
62
|
+
AND list.status = 'active' AND ($1::text IS NULL OR list.currency = $1::text)
|
|
63
|
+
AND ($2::text IS NULL OR list.region_code = $2::text) AND (p.mode = $4::text OR p.mode = 'any')
|
|
64
|
+
AND p.valid_from <= $3::timestamptz AND (p.valid_to IS NULL OR p.valid_to > $3::timestamptz)
|
|
65
|
+
AND list.valid_from <= $3::timestamptz AND (list.valid_to IS NULL OR list.valid_to > $3::timestamptz)
|
|
66
|
+
ORDER BY b.code, p.valid_from DESC`;
|
|
67
|
+
const SUMMARY_COLUMNS = `b.id, b.code, b.title, b.status, b.fulfillment_mode, b.updated_at,
|
|
68
|
+
b.composition_constraint, b.metadata,
|
|
69
|
+
(SELECT count(*) FROM public.catalog_bundle_components c WHERE c.bundle_id = b.id) AS component_count,
|
|
70
|
+
EXISTS (SELECT 1 FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id
|
|
71
|
+
WHERE p.bundle_id = b.id AND p.active AND p.amount_kind = 'gross' AND p.target_price_minor > 0
|
|
72
|
+
AND p.mode IN ('one_time', 'any') AND list.status = 'active'
|
|
73
|
+
AND p.valid_from <= CURRENT_TIMESTAMP AND (p.valid_to IS NULL OR p.valid_to > CURRENT_TIMESTAMP)
|
|
74
|
+
AND list.valid_from <= CURRENT_TIMESTAMP AND (list.valid_to IS NULL OR list.valid_to > CURRENT_TIMESTAMP)) AS has_active_target_price`;
|
|
75
|
+
export const DETAIL_SQL = `SELECT ${SUMMARY_COLUMNS} FROM public.catalog_bundles b WHERE b.code = $1`;
|
|
76
|
+
export const LIST_SQL = `SELECT ${SUMMARY_COLUMNS} FROM public.catalog_bundles b
|
|
77
|
+
WHERE ($1::text = 'all' OR b.status = $1::text)
|
|
78
|
+
AND ($2::text IS NULL OR b.code ILIKE '%' || $2 || '%' OR b.title ILIKE '%' || $2 || '%')
|
|
79
|
+
ORDER BY b.code LIMIT $3 OFFSET $4`;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PgQueryExecutor } from "../data/index.js";
|
|
2
|
+
import { type BundleCatalogReadPort } from "./bundleCatalogReadPort.js";
|
|
3
|
+
/** Selected only by the explicit effective-authority option. */
|
|
4
|
+
export declare function createEffectiveBundleCatalogStore(executor: PgQueryExecutor, incumbent: BundleCatalogReadPort): BundleCatalogReadPort;
|