@dainamite/cpq 0.4.0 → 0.6.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 +70 -0
- package/MIGRATION.md +101 -0
- package/dist/modules/cpq/acl.js +1 -0
- package/dist/modules/cpq/acl.js.map +2 -2
- package/dist/modules/cpq/api/_helpers/adjustmentCommandRoute.js +45 -0
- package/dist/modules/cpq/api/_helpers/adjustmentCommandRoute.js.map +7 -0
- package/dist/modules/cpq/api/_helpers/handleArcError.js +2 -2
- package/dist/modules/cpq/api/_helpers/handleArcError.js.map +2 -2
- package/dist/modules/cpq/api/_helpers/quoteMutationGuard.js +23 -0
- package/dist/modules/cpq/api/_helpers/quoteMutationGuard.js.map +7 -0
- package/dist/modules/cpq/api/_helpers/quoteRouteOpenApi.js +19 -0
- package/dist/modules/cpq/api/_helpers/quoteRouteOpenApi.js.map +7 -0
- package/dist/modules/cpq/api/orders/[orderId]/activate/route.js +2 -2
- package/dist/modules/cpq/api/orders/[orderId]/activate/route.js.map +2 -2
- package/dist/modules/cpq/api/orders/[orderId]/route.js +19 -3
- package/dist/modules/cpq/api/orders/[orderId]/route.js.map +2 -2
- package/dist/modules/cpq/api/orders/[orderId]/status/route.js +2 -2
- package/dist/modules/cpq/api/orders/[orderId]/status/route.js.map +2 -2
- package/dist/modules/cpq/api/orders/route.js +49 -4
- package/dist/modules/cpq/api/orders/route.js.map +2 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/clone/route.js +2 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/clone/route.js.map +2 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/items/[lineId]/restore/route.js +54 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/items/[lineId]/restore/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/items/[lineId]/route.js +45 -5
- package/dist/modules/cpq/api/quotes/[quoteId]/items/[lineId]/route.js.map +2 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/items/route.js +27 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/items/route.js.map +2 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/price-adjustments/[adjustmentId]/route.js +47 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/price-adjustments/[adjustmentId]/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/price-adjustments/preview/route.js +30 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/price-adjustments/preview/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/price-adjustments/route.js +47 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/price-adjustments/route.js.map +7 -0
- package/dist/modules/cpq/api/quotes/[quoteId]/recalculate/route.js +34 -4
- package/dist/modules/cpq/api/quotes/[quoteId]/recalculate/route.js.map +2 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/route.js +2 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/route.js.map +2 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/status/route.js +33 -2
- package/dist/modules/cpq/api/quotes/[quoteId]/status/route.js.map +2 -2
- package/dist/modules/cpq/api/quotes/price/route.js +43 -3
- package/dist/modules/cpq/api/quotes/price/route.js.map +2 -2
- package/dist/modules/cpq/api/quotes/route.js +2 -2
- package/dist/modules/cpq/api/quotes/route.js.map +2 -2
- package/dist/modules/cpq/backend/cpq/inventory/AssetsTable.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/inventory/SubscriptionsTable.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/inventory/page.meta.js +1 -1
- package/dist/modules/cpq/backend/cpq/inventory/page.meta.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.js +22 -8
- package/dist/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.js.map +2 -2
- package/dist/modules/cpq/backend/cpq/offerings/page.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/orders/[id]/page.js +89 -232
- package/dist/modules/cpq/backend/cpq/orders/[id]/page.js.map +2 -2
- package/dist/modules/cpq/backend/cpq/orders/page.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/orders/page.meta.js +1 -1
- package/dist/modules/cpq/backend/cpq/orders/page.meta.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/price-rules/page.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/pricing/page.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/PriceAdjustmentDialog.js +205 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/PriceAdjustmentDialog.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/PriceAdjustmentsPanel.js +79 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/PriceAdjustmentsPanel.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/arcLineRemoval.js +53 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/arcLineRemoval.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/priceAdjustmentContext.js +107 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/priceAdjustmentContext.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/usePriceAdjustments.js +130 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/_components/usePriceAdjustments.js.map +7 -0
- package/dist/modules/cpq/backend/cpq/quotes/[id]/page.js +144 -221
- package/dist/modules/cpq/backend/cpq/quotes/[id]/page.js.map +3 -3
- package/dist/modules/cpq/backend/cpq/quotes/page.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/quotes/page.meta.js +1 -1
- package/dist/modules/cpq/backend/cpq/quotes/page.meta.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/specifications/page.js.map +1 -1
- package/dist/modules/cpq/backend/cpq/wizards/page.js.map +1 -1
- package/dist/modules/cpq/ce.js +8 -0
- package/dist/modules/cpq/ce.js.map +2 -2
- package/dist/modules/cpq/cli.js +34 -1
- package/dist/modules/cpq/cli.js.map +2 -2
- package/dist/modules/cpq/commands/price-adjustments.js +107 -0
- package/dist/modules/cpq/commands/price-adjustments.js.map +7 -0
- package/dist/modules/cpq/components/ArcLineDiff.js +53 -0
- package/dist/modules/cpq/components/ArcLineDiff.js.map +7 -0
- package/dist/modules/cpq/components/ChargeBreakdownTable.js +154 -0
- package/dist/modules/cpq/components/ChargeBreakdownTable.js.map +7 -0
- package/dist/modules/cpq/components/CpqListView.js.map +2 -2
- package/dist/modules/cpq/components/PriceWaterfall.js +66 -0
- package/dist/modules/cpq/components/PriceWaterfall.js.map +7 -0
- package/dist/modules/cpq/components/PricingSummaryCard.js +117 -0
- package/dist/modules/cpq/components/PricingSummaryCard.js.map +7 -0
- package/dist/modules/cpq/components/useGrantedFeatures.js +27 -0
- package/dist/modules/cpq/components/useGrantedFeatures.js.map +7 -0
- package/dist/modules/cpq/data/entities.js +97 -0
- package/dist/modules/cpq/data/entities.js.map +2 -2
- package/dist/modules/cpq/data/price-adjustments.js +70 -0
- package/dist/modules/cpq/data/price-adjustments.js.map +7 -0
- package/dist/modules/cpq/data/validators.js +4 -0
- package/dist/modules/cpq/data/validators.js.map +2 -2
- package/dist/modules/cpq/di.js +6 -0
- package/dist/modules/cpq/di.js.map +2 -2
- package/dist/modules/cpq/events.js +47 -0
- package/dist/modules/cpq/events.js.map +2 -2
- package/dist/modules/cpq/index.js +1 -1
- package/dist/modules/cpq/index.js.map +2 -2
- package/dist/modules/cpq/lib/auditActor.js +10 -0
- package/dist/modules/cpq/lib/auditActor.js.map +7 -0
- package/dist/modules/cpq/lib/formatMoney.js +7 -0
- package/dist/modules/cpq/lib/formatMoney.js.map +7 -0
- package/dist/modules/cpq/lib/priceAdjustmentDefaults.js +60 -0
- package/dist/modules/cpq/lib/priceAdjustmentDefaults.js.map +7 -0
- package/dist/modules/cpq/lib/priceAdjustmentView.js +169 -0
- package/dist/modules/cpq/lib/priceAdjustmentView.js.map +7 -0
- package/dist/modules/cpq/lib/quotePermissions.js +13 -0
- package/dist/modules/cpq/lib/quotePermissions.js.map +7 -0
- package/dist/modules/cpq/lib/quoteSummaryView.js +28 -0
- package/dist/modules/cpq/lib/quoteSummaryView.js.map +7 -0
- package/dist/modules/cpq/migrations/Migration20261110213052.js +22 -0
- package/dist/modules/cpq/migrations/Migration20261110213052.js.map +7 -0
- package/dist/modules/cpq/services/arcLineRemoval.js +53 -0
- package/dist/modules/cpq/services/arcLineRemoval.js.map +7 -0
- package/dist/modules/cpq/services/arcPriceFreeze.js +79 -0
- package/dist/modules/cpq/services/arcPriceFreeze.js.map +7 -0
- package/dist/modules/cpq/services/cpqOrderService.js +34 -30
- package/dist/modules/cpq/services/cpqOrderService.js.map +2 -2
- package/dist/modules/cpq/services/cpqPricingService.js +7 -0
- package/dist/modules/cpq/services/cpqPricingService.js.map +2 -2
- package/dist/modules/cpq/services/cpqQuotingService.js +339 -111
- package/dist/modules/cpq/services/cpqQuotingService.js.map +2 -2
- package/dist/modules/cpq/services/orderPricingSummary.js +26 -0
- package/dist/modules/cpq/services/orderPricingSummary.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/adjustmentService.js +264 -0
- package/dist/modules/cpq/services/priceAdjustments/adjustmentService.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/chargeWaterfall.js +25 -0
- package/dist/modules/cpq/services/priceAdjustments/chargeWaterfall.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/loadQuoteAdjustments.js +38 -0
- package/dist/modules/cpq/services/priceAdjustments/loadQuoteAdjustments.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/pricingSnapshot.js +104 -0
- package/dist/modules/cpq/services/priceAdjustments/pricingSnapshot.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/quoteAdjustmentLifecycle.js +102 -0
- package/dist/modules/cpq/services/priceAdjustments/quoteAdjustmentLifecycle.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/quotePricingEvents.js +52 -0
- package/dist/modules/cpq/services/priceAdjustments/quotePricingEvents.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/quotePricingWrite.js +37 -0
- package/dist/modules/cpq/services/priceAdjustments/quotePricingWrite.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/resolveManualAdjustments.js +107 -0
- package/dist/modules/cpq/services/priceAdjustments/resolveManualAdjustments.js.map +7 -0
- package/dist/modules/cpq/services/priceAdjustments/storedAdjustmentFailure.js +30 -0
- package/dist/modules/cpq/services/priceAdjustments/storedAdjustmentFailure.js.map +7 -0
- package/dist/modules/cpq/services/types.js.map +2 -2
- package/dist/modules/cpq/setup.js +6 -0
- package/dist/modules/cpq/setup.js.map +2 -2
- package/package.json +9 -9
- package/src/modules/cpq/__integration__/TC-CPQ-002.spec.ts +8 -5
- package/src/modules/cpq/__integration__/TC-CPQ-ARC-012.spec.ts +134 -0
- package/src/modules/cpq/acl.ts +1 -0
- package/src/modules/cpq/api/__tests__/adjustmentRoutes.test.ts +79 -0
- package/src/modules/cpq/api/__tests__/quoteWriteGuards.test.ts +100 -0
- package/src/modules/cpq/api/_helpers/__tests__/quoteMutationGuard.test.ts +48 -0
- package/src/modules/cpq/api/_helpers/adjustmentCommandRoute.ts +45 -0
- package/src/modules/cpq/api/_helpers/handleArcError.ts +12 -12
- package/src/modules/cpq/api/_helpers/quoteMutationGuard.ts +38 -0
- package/src/modules/cpq/api/_helpers/quoteRouteOpenApi.ts +19 -0
- package/src/modules/cpq/api/orders/[orderId]/activate/route.ts +2 -2
- package/src/modules/cpq/api/orders/[orderId]/route.ts +20 -2
- package/src/modules/cpq/api/orders/[orderId]/status/route.ts +2 -2
- package/src/modules/cpq/api/orders/route.ts +53 -3
- package/src/modules/cpq/api/quotes/[quoteId]/clone/route.ts +2 -2
- package/src/modules/cpq/api/quotes/[quoteId]/items/[lineId]/restore/route.ts +56 -0
- package/src/modules/cpq/api/quotes/[quoteId]/items/[lineId]/route.ts +51 -4
- package/src/modules/cpq/api/quotes/[quoteId]/items/route.ts +31 -1
- package/src/modules/cpq/api/quotes/[quoteId]/price-adjustments/[adjustmentId]/route.ts +39 -0
- package/src/modules/cpq/api/quotes/[quoteId]/price-adjustments/preview/route.ts +24 -0
- package/src/modules/cpq/api/quotes/[quoteId]/price-adjustments/route.ts +40 -0
- package/src/modules/cpq/api/quotes/[quoteId]/recalculate/__tests__/route.test.ts +95 -0
- package/src/modules/cpq/api/quotes/[quoteId]/recalculate/route.ts +42 -3
- package/src/modules/cpq/api/quotes/[quoteId]/route.ts +2 -2
- package/src/modules/cpq/api/quotes/[quoteId]/status/__tests__/route.test.ts +74 -0
- package/src/modules/cpq/api/quotes/[quoteId]/status/route.ts +37 -1
- package/src/modules/cpq/api/quotes/price/__tests__/route.test.ts +37 -0
- package/src/modules/cpq/api/quotes/price/route.ts +28 -2
- package/src/modules/cpq/api/quotes/route.ts +2 -2
- package/src/modules/cpq/backend/cpq/inventory/AssetsTable.tsx +1 -1
- package/src/modules/cpq/backend/cpq/inventory/SubscriptionsTable.tsx +1 -1
- package/src/modules/cpq/backend/cpq/inventory/page.meta.ts +1 -1
- package/src/modules/cpq/backend/cpq/inventory/subscriptions/[id]/page.tsx +32 -10
- package/src/modules/cpq/backend/cpq/offerings/page.tsx +1 -1
- package/src/modules/cpq/backend/cpq/orders/[id]/page.tsx +60 -269
- package/src/modules/cpq/backend/cpq/orders/page.meta.ts +1 -1
- package/src/modules/cpq/backend/cpq/orders/page.tsx +1 -1
- package/src/modules/cpq/backend/cpq/price-rules/page.tsx +1 -1
- package/src/modules/cpq/backend/cpq/pricing/page.tsx +1 -1
- package/src/modules/cpq/backend/cpq/quotes/[id]/_components/PriceAdjustmentDialog.tsx +260 -0
- package/src/modules/cpq/backend/cpq/quotes/[id]/_components/PriceAdjustmentsPanel.tsx +124 -0
- package/src/modules/cpq/backend/cpq/quotes/[id]/_components/__tests__/PriceAdjustmentsPanel.test.tsx +76 -0
- package/src/modules/cpq/backend/cpq/quotes/[id]/_components/arcLineRemoval.tsx +76 -0
- package/src/modules/cpq/backend/cpq/quotes/[id]/_components/priceAdjustmentContext.tsx +133 -0
- package/src/modules/cpq/backend/cpq/quotes/[id]/_components/usePriceAdjustments.tsx +165 -0
- package/src/modules/cpq/backend/cpq/quotes/[id]/page.tsx +178 -266
- package/src/modules/cpq/backend/cpq/quotes/page.meta.ts +1 -1
- package/src/modules/cpq/backend/cpq/quotes/page.tsx +1 -1
- package/src/modules/cpq/backend/cpq/specifications/page.tsx +1 -1
- package/src/modules/cpq/backend/cpq/wizards/page.tsx +1 -1
- package/src/modules/cpq/ce.ts +8 -0
- package/src/modules/cpq/cli.ts +48 -1
- package/src/modules/cpq/commands/__tests__/price-adjustments.test.ts +54 -0
- package/src/modules/cpq/commands/price-adjustments.ts +90 -0
- package/src/modules/cpq/components/ArcLineDiff.tsx +87 -0
- package/src/modules/cpq/components/ChargeBreakdownTable.tsx +201 -0
- package/src/modules/cpq/components/CpqListView.tsx +2 -1
- package/src/modules/cpq/components/PriceWaterfall.tsx +94 -0
- package/src/modules/cpq/components/PricingSummaryCard.tsx +128 -0
- package/src/modules/cpq/components/__tests__/PriceWaterfall.test.tsx +38 -0
- package/src/modules/cpq/components/useGrantedFeatures.ts +35 -0
- package/src/modules/cpq/data/__tests__/price-adjustment-migration.test.ts +11 -0
- package/src/modules/cpq/data/__tests__/price-adjustments.test.ts +26 -0
- package/src/modules/cpq/data/entities.ts +83 -0
- package/src/modules/cpq/data/price-adjustments.ts +67 -0
- package/src/modules/cpq/data/validators.ts +3 -0
- package/src/modules/cpq/di.ts +6 -0
- package/src/modules/cpq/events.ts +53 -2
- package/src/modules/cpq/index.ts +1 -1
- package/src/modules/cpq/lib/__tests__/auditActor.test.ts +12 -0
- package/src/modules/cpq/lib/__tests__/priceAdjustmentDefaults.test.ts +37 -0
- package/src/modules/cpq/lib/__tests__/priceAdjustmentView.test.ts +152 -0
- package/src/modules/cpq/lib/__tests__/quotePermissions.test.ts +30 -0
- package/src/modules/cpq/lib/__tests__/quoteSummaryView.test.ts +56 -0
- package/src/modules/cpq/lib/auditActor.ts +13 -0
- package/src/modules/cpq/lib/formatMoney.ts +4 -0
- package/src/modules/cpq/lib/priceAdjustmentDefaults.ts +36 -0
- package/src/modules/cpq/lib/priceAdjustmentView.ts +259 -0
- package/src/modules/cpq/lib/quotePermissions.ts +22 -0
- package/src/modules/cpq/lib/quoteSummaryView.ts +51 -0
- package/src/modules/cpq/migrations/.snapshot-open-mercato.json +3298 -2423
- package/src/modules/cpq/migrations/Migration20261110213052.ts +22 -0
- package/src/modules/cpq/services/__tests__/_helpers/mockEm.ts +9 -2
- package/src/modules/cpq/services/__tests__/adjustmentService.test.ts +183 -0
- package/src/modules/cpq/services/__tests__/arcLineRemoval.test.ts +109 -0
- package/src/modules/cpq/services/__tests__/arcPriceFreeze.test.ts +141 -0
- package/src/modules/cpq/services/__tests__/chargeWaterfall.test.ts +28 -0
- package/src/modules/cpq/services/__tests__/cpqOrderService.test.ts +35 -2
- package/src/modules/cpq/services/__tests__/cpqPricingService.test.ts +57 -0
- package/src/modules/cpq/services/__tests__/cpqQuotingService.arc.test.ts +237 -0
- package/src/modules/cpq/services/__tests__/cpqQuotingService.test.ts +58 -3
- package/src/modules/cpq/services/__tests__/errorBrands.test.ts +72 -0
- package/src/modules/cpq/services/__tests__/orderPricingSummary.test.ts +50 -0
- package/src/modules/cpq/services/__tests__/pricingSnapshot.test.ts +62 -0
- package/src/modules/cpq/services/__tests__/quoteAdjustmentLifecycle.test.ts +35 -0
- package/src/modules/cpq/services/__tests__/quoteAdjustmentPricing.test.ts +65 -0
- package/src/modules/cpq/services/__tests__/quoteCloneAdjustments.test.ts +45 -0
- package/src/modules/cpq/services/__tests__/quoteDetachTargetAdjustments.test.ts +54 -0
- package/src/modules/cpq/services/__tests__/quoteEventsService.test.ts +72 -0
- package/src/modules/cpq/services/__tests__/quotePricingEvents.test.ts +126 -0
- package/src/modules/cpq/services/__tests__/quotePricingIsolation.test.ts +52 -0
- package/src/modules/cpq/services/__tests__/quotePricingWrite.test.ts +74 -0
- package/src/modules/cpq/services/__tests__/resolveManualAdjustments.test.ts +90 -0
- package/src/modules/cpq/services/__tests__/storedAdjustmentFailure.test.ts +9 -0
- package/src/modules/cpq/services/arcLineRemoval.ts +87 -0
- package/src/modules/cpq/services/arcPriceFreeze.ts +165 -0
- package/src/modules/cpq/services/cpqOrderService.ts +32 -28
- package/src/modules/cpq/services/cpqPricingService.ts +8 -0
- package/src/modules/cpq/services/cpqQuotingService.ts +388 -125
- package/src/modules/cpq/services/orderPricingSummary.ts +47 -0
- package/src/modules/cpq/services/priceAdjustments/adjustmentService.ts +249 -0
- package/src/modules/cpq/services/priceAdjustments/chargeWaterfall.ts +28 -0
- package/src/modules/cpq/services/priceAdjustments/loadQuoteAdjustments.ts +25 -0
- package/src/modules/cpq/services/priceAdjustments/pricingSnapshot.ts +86 -0
- package/src/modules/cpq/services/priceAdjustments/quoteAdjustmentLifecycle.ts +68 -0
- package/src/modules/cpq/services/priceAdjustments/quotePricingEvents.ts +94 -0
- package/src/modules/cpq/services/priceAdjustments/quotePricingWrite.ts +51 -0
- package/src/modules/cpq/services/priceAdjustments/resolveManualAdjustments.ts +116 -0
- package/src/modules/cpq/services/priceAdjustments/storedAdjustmentFailure.ts +31 -0
- package/src/modules/cpq/services/types.ts +34 -1
- package/src/modules/cpq/setup.ts +7 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const transitionStatus = jest.fn()
|
|
2
|
+
const runCpqMutationGuards = jest.fn()
|
|
3
|
+
const runAfterSuccess = jest.fn()
|
|
4
|
+
|
|
5
|
+
jest.mock('../../../../context', () => ({
|
|
6
|
+
resolveCpqRouteContext: jest.fn().mockResolvedValue({
|
|
7
|
+
auth: { sub: '77777777-7777-4777-8777-777777777777', tenantId: 't-1' },
|
|
8
|
+
organizationId: 'org-1',
|
|
9
|
+
tenantId: 't-1',
|
|
10
|
+
}),
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
jest.mock('../../../../resolveQuotingService', () => ({
|
|
14
|
+
resolveQuotingService: () => ({ transitionStatus }),
|
|
15
|
+
}))
|
|
16
|
+
|
|
17
|
+
jest.mock('../../../../_helpers/quoteMutationGuard', () => ({
|
|
18
|
+
CPQ_QUOTE_RESOURCE_KIND: 'cpq.quote',
|
|
19
|
+
runCpqMutationGuards: (...args: unknown[]) => runCpqMutationGuards(...args),
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
import { POST } from '../route'
|
|
23
|
+
|
|
24
|
+
function postStatus(targetStatus: string): Request {
|
|
25
|
+
return new Request('http://localhost/api/cpq/quotes/cpq-1/status', {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: { 'Content-Type': 'application/json' },
|
|
28
|
+
body: JSON.stringify({ targetStatus }),
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const params = { params: Promise.resolve({ quoteId: 'cpq-1' }) }
|
|
33
|
+
|
|
34
|
+
describe('POST /api/cpq/quotes/{quoteId}/status — mutation guards', () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
transitionStatus.mockReset()
|
|
37
|
+
transitionStatus.mockResolvedValue({ id: 'cpq-1', cpqStatus: 'with_customer' })
|
|
38
|
+
runAfterSuccess.mockReset()
|
|
39
|
+
runCpqMutationGuards.mockReset()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('transitions when the guards pass and then runs their after-success hooks', async () => {
|
|
43
|
+
runCpqMutationGuards.mockResolvedValue({ ok: true, runAfterSuccess })
|
|
44
|
+
|
|
45
|
+
const res = await POST(postStatus('with_customer'), params)
|
|
46
|
+
|
|
47
|
+
expect(res.status).toBe(200)
|
|
48
|
+
expect(runCpqMutationGuards).toHaveBeenCalledWith(
|
|
49
|
+
expect.anything(),
|
|
50
|
+
expect.any(Request),
|
|
51
|
+
{
|
|
52
|
+
resourceKind: 'cpq.quote',
|
|
53
|
+
resourceId: 'cpq-1',
|
|
54
|
+
operation: 'custom',
|
|
55
|
+
mutationPayload: { action: 'transition_status', targetStatus: 'with_customer' },
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
expect(transitionStatus).toHaveBeenCalledWith('cpq-1', 'with_customer', { organizationId: 'org-1', tenantId: 't-1' }, '77777777-7777-4777-8777-777777777777')
|
|
59
|
+
expect(runAfterSuccess).toHaveBeenCalledTimes(1)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('returns the guard response and leaves the status unchanged when a project guard blocks', async () => {
|
|
63
|
+
runCpqMutationGuards.mockResolvedValue({
|
|
64
|
+
ok: false,
|
|
65
|
+
response: Response.json({ error: 'Discount above 15% needs approval' }, { status: 422 }),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const res = await POST(postStatus('with_customer'), params)
|
|
69
|
+
|
|
70
|
+
expect(res.status).toBe(422)
|
|
71
|
+
expect(await res.json()).toEqual({ error: 'Discount above 15% needs approval' })
|
|
72
|
+
expect(transitionStatus).not.toHaveBeenCalled()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server'
|
|
2
2
|
import { resolveCpqRouteContext } from '../../../context'
|
|
3
|
+
import { resolveAuditActor } from '../../../../lib/auditActor'
|
|
3
4
|
import { cpqTransitionStatusSchema } from '../../../../data/validators'
|
|
4
5
|
import { resolveQuotingService } from '../../../resolveQuotingService'
|
|
5
6
|
import { handleArcError } from '../../../_helpers/handleArcError'
|
|
7
|
+
import { CPQ_QUOTE_RESOURCE_KIND, runCpqMutationGuards } from '../../../_helpers/quoteMutationGuard'
|
|
8
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
9
|
+
import { cpqErrorDoc, cpqQuoteIdPathParams } from '../../../_helpers/quoteRouteOpenApi'
|
|
6
10
|
|
|
7
11
|
export const metadata = {
|
|
8
12
|
POST: { requireAuth: true, requireFeatures: ['cpq.quotes.manage'] },
|
|
@@ -17,10 +21,42 @@ export async function POST(req: Request, { params }: { params: Promise<{ quoteId
|
|
|
17
21
|
const body = cpqTransitionStatusSchema.parse(await req.json())
|
|
18
22
|
const scope = { organizationId: ctx.organizationId, tenantId: ctx.tenantId }
|
|
19
23
|
|
|
24
|
+
// Projects enforce approval rules here (e.g. block `ready → with_customer`
|
|
25
|
+
// until a discounted quote is approved).
|
|
26
|
+
const guard = await runCpqMutationGuards(ctx, req, {
|
|
27
|
+
resourceKind: CPQ_QUOTE_RESOURCE_KIND,
|
|
28
|
+
resourceId: quoteId,
|
|
29
|
+
operation: 'custom',
|
|
30
|
+
mutationPayload: { action: 'transition_status', targetStatus: body.targetStatus },
|
|
31
|
+
})
|
|
32
|
+
if (!guard.ok) return guard.response
|
|
33
|
+
|
|
20
34
|
const service = resolveQuotingService(ctx)
|
|
21
|
-
const result = await service.transitionStatus(quoteId, body.targetStatus, scope)
|
|
35
|
+
const result = await service.transitionStatus(quoteId, body.targetStatus, scope, resolveAuditActor(ctx.auth))
|
|
36
|
+
await guard.runAfterSuccess()
|
|
22
37
|
return NextResponse.json(result)
|
|
23
38
|
} catch (err) {
|
|
24
39
|
return handleArcError(err, 'cpq/quotes/[quoteId]/status.POST')
|
|
25
40
|
}
|
|
26
41
|
}
|
|
42
|
+
|
|
43
|
+
export const openApi: OpenApiRouteDoc = {
|
|
44
|
+
tag: 'CPQ Quotes',
|
|
45
|
+
summary: 'CPQ quote status',
|
|
46
|
+
pathParams: cpqQuoteIdPathParams,
|
|
47
|
+
methods: {
|
|
48
|
+
POST: {
|
|
49
|
+
summary: 'Transition a CPQ quote to another status',
|
|
50
|
+
description:
|
|
51
|
+
'Operator-driven status change. Registered mutation guards (resource kind `cpq.quote`, action `transition_status`) run first — projects use them to enforce approvals.',
|
|
52
|
+
requestBody: { schema: cpqTransitionStatusSchema },
|
|
53
|
+
responses: [{ status: 200, description: 'Quote with its new status' }],
|
|
54
|
+
errors: [
|
|
55
|
+
cpqErrorDoc(400, 'Validation error'),
|
|
56
|
+
cpqErrorDoc(404, 'Quote not found'),
|
|
57
|
+
cpqErrorDoc(409, 'Transition not allowed'),
|
|
58
|
+
cpqErrorDoc(422, 'ARC validation failed or blocked by a mutation guard'),
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const resolveProductCharges = jest.fn()
|
|
2
|
+
jest.mock('../../../context', () => ({ resolveCpqRouteContext: async () => ({ auth: { sub: 'user' }, tenantId: 'tenant', organizationId: 'org', container: { resolve: () => ({ resolveProductCharges }) } }) }))
|
|
3
|
+
import { POST, openApi } from '../route'
|
|
4
|
+
const offeringId = '11111111-1111-4111-8111-111111111111'
|
|
5
|
+
const charge = { chargeCode: 'fee', chargeName: 'Fee', chargeType: 'mrc', pricingMethod: 'flat', quantity: 1,
|
|
6
|
+
unitPrice: 90, totalPrice: 90, currencyCode: 'USD', listUnitPrice: 100, listTotalPrice: 100, standardUnitPrice: 90, standardTotalPrice: 90,
|
|
7
|
+
adjustments: [{ origin: 'rule', ruleCode: 'volume', ruleName: 'Volume', ruleType: 'discount_percent', value: 10, unitPriceBefore: 100, unitPriceAfter: 90, delta: -10 }] }
|
|
8
|
+
const body = { primaryItem: { offeringId, configuration: {} }, childItems: [{ offeringId, configuration: {} }], currencyCode: 'USD' }
|
|
9
|
+
function request(input: unknown) { return new Request('http://localhost/api/cpq/quotes/price', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input) }) }
|
|
10
|
+
beforeEach(() => { resolveProductCharges.mockReset(); resolveProductCharges.mockResolvedValue([charge]) })
|
|
11
|
+
it('keeps waterfall fields out of primary and child prices by default while tagging rules', async () => {
|
|
12
|
+
const response = await POST(request(body))
|
|
13
|
+
expect(response.status).toBe(200)
|
|
14
|
+
const result = await response.json()
|
|
15
|
+
for (const item of [result.primaryCharges[0], result.childItems[0].charges[0]]) {
|
|
16
|
+
expect(item).not.toHaveProperty('listUnitPrice')
|
|
17
|
+
expect(item).not.toHaveProperty('listTotalPrice')
|
|
18
|
+
expect(item).not.toHaveProperty('standardUnitPrice')
|
|
19
|
+
expect(item).not.toHaveProperty('standardTotalPrice')
|
|
20
|
+
expect(item.adjustments[0].origin).toBe('rule')
|
|
21
|
+
}
|
|
22
|
+
expect(result.totals.mrcTotal).toBe(180)
|
|
23
|
+
})
|
|
24
|
+
it('returns list and standard fields only with explicit includeWaterfall', async () => {
|
|
25
|
+
const result = await (await POST(request({ ...body, includeWaterfall: true }))).json()
|
|
26
|
+
expect(result.primaryCharges[0]).toEqual(charge)
|
|
27
|
+
expect(result.childItems[0].charges[0]).toEqual(charge)
|
|
28
|
+
})
|
|
29
|
+
it('never forwards draft adjustments to the catalog engine', async () => {
|
|
30
|
+
await POST(request({ ...body, priceAdjustments: [{ value: 80 }] }))
|
|
31
|
+
expect(resolveProductCharges).toHaveBeenCalledWith({ offeringId, productId: undefined, configuration: {}, currencyCode: 'USD', tenantId: 'tenant', organizationId: 'org' })
|
|
32
|
+
})
|
|
33
|
+
it('rejects malformed waterfall flags and documents the request contract', async () => {
|
|
34
|
+
expect((await POST(request({ ...body, includeWaterfall: 'yes' }))).status).toBe(400)
|
|
35
|
+
expect(resolveProductCharges).not.toHaveBeenCalled()
|
|
36
|
+
expect(openApi.methods.POST?.requestBody).toBeDefined()
|
|
37
|
+
})
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server'
|
|
2
2
|
import { z } from 'zod'
|
|
3
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
|
+
import { cpqErrorDoc } from '../../_helpers/quoteRouteOpenApi'
|
|
3
5
|
import { resolveCpqRouteContext } from '../../context'
|
|
4
6
|
import { cpqPricePreviewSchema } from '../../../data/validators'
|
|
5
7
|
import type { DefaultCpqPricingService } from '../../../services/cpqPricingService'
|
|
6
8
|
import type { ResolvedCharge } from '../../../services/types'
|
|
7
9
|
import { getBaseCurrencyCode } from '../../../services/types'
|
|
10
|
+
import { withChargeWaterfall, withoutChargeWaterfall } from '../../../services/priceAdjustments/chargeWaterfall'
|
|
8
11
|
|
|
9
12
|
export const metadata = {
|
|
10
13
|
POST: { requireAuth: true, requireFeatures: ['cpq.quotes.view'] },
|
|
@@ -65,9 +68,10 @@ export async function POST(req: Request) {
|
|
|
65
68
|
note: c.note ?? 'Usage-based charge — billed on actual consumption.',
|
|
66
69
|
}))
|
|
67
70
|
|
|
71
|
+
const presentCharge = body.includeWaterfall ? withChargeWaterfall : withoutChargeWaterfall
|
|
68
72
|
return NextResponse.json({
|
|
69
|
-
primaryCharges,
|
|
70
|
-
childItems,
|
|
73
|
+
primaryCharges: primaryCharges.map(presentCharge),
|
|
74
|
+
childItems: childItems.map((item) => ({ ...item, charges: item.charges.map(presentCharge) })),
|
|
71
75
|
totals: { nrcTotal, mrcTotal, usageCharges },
|
|
72
76
|
currencyCode,
|
|
73
77
|
})
|
|
@@ -79,3 +83,25 @@ export async function POST(req: Request) {
|
|
|
79
83
|
return NextResponse.json({ error: 'Internal error' }, { status: 500 })
|
|
80
84
|
}
|
|
81
85
|
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
const chargeDoc = z.object({
|
|
89
|
+
chargeCode: z.string(), chargeName: z.string(), chargeType: z.enum(['nrc', 'mrc', 'usage']),
|
|
90
|
+
pricingMethod: z.enum(['flat', 'per_unit', 'volume', 'tiered']), currencyCode: z.string(),
|
|
91
|
+
unitPrice: z.number(), quantity: z.number().nullable(), totalPrice: z.number().nullable(),
|
|
92
|
+
listUnitPrice: z.number().optional(), listTotalPrice: z.number().nullable().optional(),
|
|
93
|
+
standardUnitPrice: z.number().optional(), standardTotalPrice: z.number().nullable().optional(),
|
|
94
|
+
adjustments: z.array(z.object({ origin: z.literal('rule'), ruleCode: z.string(), ruleName: z.string(),
|
|
95
|
+
ruleType: z.string(), value: z.number(), unitPriceBefore: z.number(), unitPriceAfter: z.number(), delta: z.number() }).passthrough()).nullish(),
|
|
96
|
+
}).passthrough()
|
|
97
|
+
export const openApi: OpenApiRouteDoc = { tag: 'CPQ Pricing', methods: { POST: {
|
|
98
|
+
summary: 'Calculate catalog prices and price rules without saving',
|
|
99
|
+
description: 'Manual quote adjustments are never applied. Set includeWaterfall=true to return list and standard prices; these fields are omitted by default.',
|
|
100
|
+
requestBody: { schema: cpqPricePreviewSchema },
|
|
101
|
+
responses: [{ status: 200, description: 'Resolved rule prices and optional waterfall', schema: z.object({
|
|
102
|
+
primaryCharges: z.array(chargeDoc),
|
|
103
|
+
childItems: z.array(z.object({ offeringId: z.string().nullable(), productId: z.string().nullable(), charges: z.array(chargeDoc) })),
|
|
104
|
+
totals: z.object({ nrcTotal: z.number(), mrcTotal: z.number(), usageCharges: z.array(z.unknown()) }), currencyCode: z.string(),
|
|
105
|
+
}) }],
|
|
106
|
+
errors: [cpqErrorDoc(400, 'Invalid pricing request'), cpqErrorDoc(500, 'Price calculation failed')],
|
|
107
|
+
} } }
|
|
@@ -2,7 +2,7 @@ import { NextResponse } from 'next/server'
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import { resolveCpqRouteContext } from '../context'
|
|
4
4
|
import { cpqCreateQuoteSchema } from '../../data/validators'
|
|
5
|
-
import {
|
|
5
|
+
import { isQuotingError } from '../../services/cpqQuotingService'
|
|
6
6
|
import { resolveQuotingService } from '../resolveQuotingService'
|
|
7
7
|
import { CpqQuoteConfiguration } from '../../data/entities'
|
|
8
8
|
import { SalesQuote } from '@open-mercato/core/modules/sales/data/entities'
|
|
@@ -104,7 +104,7 @@ function handleError(err: unknown, context: string) {
|
|
|
104
104
|
if (err instanceof z.ZodError) {
|
|
105
105
|
return NextResponse.json({ error: 'Validation error', details: err.issues }, { status: 400 })
|
|
106
106
|
}
|
|
107
|
-
if (err
|
|
107
|
+
if (isQuotingError(err)) {
|
|
108
108
|
const body: Record<string, unknown> = { error: err.message }
|
|
109
109
|
if (err.cpqStatus) body.cpqStatus = err.cpqStatus
|
|
110
110
|
return NextResponse.json(body, { status: err.status })
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
4
4
|
import { useRouter } from 'next/navigation'
|
|
5
|
-
import type { ColumnDef } from '@tanstack/react-table'
|
|
5
|
+
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
6
6
|
import { DataTable } from '@open-mercato/ui/backend/DataTable'
|
|
7
7
|
import { RowActions } from '@open-mercato/ui/backend/RowActions'
|
|
8
8
|
import type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
4
4
|
import { useRouter } from 'next/navigation'
|
|
5
|
-
import type { ColumnDef } from '@tanstack/react-table'
|
|
5
|
+
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
6
6
|
import { DataTable } from '@open-mercato/ui/backend/DataTable'
|
|
7
7
|
import { RowActions } from '@open-mercato/ui/backend/RowActions'
|
|
8
8
|
import type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'
|
|
@@ -10,7 +10,7 @@ export const metadata = {
|
|
|
10
10
|
pageTitleKey: 'cpq.inventory.title',
|
|
11
11
|
pageGroup: 'CPQ',
|
|
12
12
|
pageGroupKey: 'customers~sales~cpq.nav.group',
|
|
13
|
-
pageOrder:
|
|
13
|
+
pageOrder: 3,
|
|
14
14
|
icon: inventoryIcon,
|
|
15
15
|
breadcrumb: [{ label: 'CPQ Subscriptions', labelKey: 'cpq.inventory.title' }],
|
|
16
16
|
} as const
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
type SubscriptionStatus,
|
|
12
12
|
} from '../../../../../components/statusMaps'
|
|
13
13
|
import { StatusPath } from '../../../../../components/StatusPath'
|
|
14
|
+
import { DepthBadge, PriceWaterfall } from '../../../../../components/PriceWaterfall'
|
|
15
|
+
import { parseStoredCharge } from '../../../../../lib/priceAdjustmentView'
|
|
14
16
|
|
|
15
17
|
// XD-250 — ARC integration on subscription detail.
|
|
16
18
|
// • header buttons (Amend / Renew / Cancel) call /from-subscription
|
|
@@ -682,21 +684,41 @@ export default function SubscriptionDetailPage(props: { params?: { id?: string }
|
|
|
682
684
|
<tr className="text-muted-foreground">
|
|
683
685
|
<th className="text-left py-1 font-medium">Charge</th>
|
|
684
686
|
<th className="text-left py-1 font-medium">Type</th>
|
|
685
|
-
<th className="text-right py-1 font-medium">
|
|
687
|
+
<th className="text-right py-1 font-medium">List</th>
|
|
688
|
+
<th className="text-right py-1 font-medium">Offer</th>
|
|
686
689
|
<th className="text-right py-1 font-medium">Qty</th>
|
|
687
690
|
<th className="text-right py-1 font-medium">Total</th>
|
|
688
691
|
</tr>
|
|
689
692
|
</thead>
|
|
690
693
|
<tbody>
|
|
691
|
-
{item.charges.map((
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
<
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
694
|
+
{item.charges.map((raw, i) => {
|
|
695
|
+
const c = parseStoredCharge(raw)
|
|
696
|
+
if (!c) return null
|
|
697
|
+
return (
|
|
698
|
+
<React.Fragment key={i}>
|
|
699
|
+
<tr className="border-t border-dashed border-border/50">
|
|
700
|
+
<td className="py-1">{c.chargeName}</td>
|
|
701
|
+
<td className="py-1 uppercase">{c.chargeType}</td>
|
|
702
|
+
<td className="py-1 text-right font-mono text-muted-foreground">{fmt(c.listUnitPrice ?? c.unitPrice, currency)}</td>
|
|
703
|
+
<td className="py-1 text-right font-mono">
|
|
704
|
+
<span className="inline-flex items-center gap-1">
|
|
705
|
+
<DepthBadge before={c.listUnitPrice ?? c.unitPrice} after={c.unitPrice} />
|
|
706
|
+
{fmt(c.unitPrice, currency)}
|
|
707
|
+
</span>
|
|
708
|
+
</td>
|
|
709
|
+
<td className="py-1 text-right font-mono">{c.quantity ?? '—'}</td>
|
|
710
|
+
<td className="py-1 text-right font-mono">{c.totalPrice != null ? fmt(c.totalPrice, currency) : '—'}</td>
|
|
711
|
+
</tr>
|
|
712
|
+
{(c.adjustments?.length ?? 0) > 0 && (
|
|
713
|
+
<tr>
|
|
714
|
+
<td colSpan={6} className="pb-2 pl-4">
|
|
715
|
+
<PriceWaterfall charge={c} currency={currency} />
|
|
716
|
+
</td>
|
|
717
|
+
</tr>
|
|
718
|
+
)}
|
|
719
|
+
</React.Fragment>
|
|
720
|
+
)
|
|
721
|
+
})}
|
|
700
722
|
</tbody>
|
|
701
723
|
</table>
|
|
702
724
|
</div>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
4
4
|
import { useRouter } from 'next/navigation'
|
|
5
|
-
import type { ColumnDef } from '@tanstack/react-table'
|
|
5
|
+
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
6
6
|
import { type BulkAction } from '@open-mercato/ui/backend/DataTable'
|
|
7
7
|
import { Button } from '@open-mercato/ui/primitives/button'
|
|
8
8
|
import { Checkbox } from '@open-mercato/ui/primitives/checkbox'
|