Preview all configuration drafts safely
This Dealops 2 / Dealops 3 PR makes synthetic configuration previews generate order forms from unpublished formula, binding, flow, catalog, and approval drafts without letting real quotes opt into draft behavior.
Configuration preview now stays valid for order-form formula drafts and order-form spec/template-binding drafts, not just pricing/catalog/flow drafts.
Admins can generate a recorded order form from a verified synthetic preview.
The stored synthetic opportunity becomes the preview authority. URL flags, quote names, and mutable input.isPreview stamps no longer activate drafts for real quotes.
Draft approval rules and draft formulas are evaluated together for previews, while published approval evidence continues to require immutable published formula revisions.
Synthetic previews can generate test order forms, but CRM writeback, automatic writeback, approval submission, and signature sends remain blocked for preview quotes.
1. Why this exists
- Preview eligibility could expire when the only remaining drafts were order-form formulas or template bindings.
- Preview links disabled order-form generation even when the admin wanted a test document.
- Draft approval rules could be evaluated against published formula versions.
- A copied/renamed preview option could lose its input preview stamp.
- Any draft reported by
v3Admin.getDraftStatuskeeps preview mode alive. - Verified synthetic previews can run
GenerateOrderFormandSaveAndQuit. - Approval previews resolve draft workflow rules and draft formula versions from one source.
- Stored quote/opportunity identity, not mutable URL/input markers, decides preview status.
2. What changes
The client stops enumerating a fixed draft list and treats any truthy draft flag as active:
Object.values(draftData?.drafts ?? {}).some(Boolean)
This picks up new keys like orderFormFormulas and orderFormSpec.
Preview checks move to shared identity helpers such as resolveQuotePreview, resolveQuotePreviews, and isPreviewOpportunity.
The server verifies organization ownership and the quote/opportunity link before enabling draft behavior.
Client and server share decideOrderFormGeneration from packages/types/v2/flows/FinishSpec.
The server re-runs the gate at export dispatch and worker execution.
| Area | Representative files | Reviewer signal |
|---|---|---|
| Client |
PricingFlowPage.tsx,
CreateSubmitQuoteModal.tsx,
OrderFormVersionsDrawer.tsx,
useGenerateOrderForm.tsx
|
Preview behavior comes from the loaded opportunity, not from ?preview=true. Generate is enabled only through the shared policy. |
| Identity |
dealops3/preview/identity.ts,
packages/types/v2/crmOpportunity.ts
|
The stored synthetic opportunity is the single authority. Real quotes cannot spoof preview behavior with a quote input flag. |
| Approvals |
PricingQuoteApprovalController.ts,
approvals/formulas.ts,
approvals/v2Bridge.ts
|
Approval bundles carry resolved isPreview. Draft predictions do not produce published formula evidence. |
| Formula versions |
formulas/persistence/resolveVersion.ts,
formulaReleaseValidation.ts,
approvalFormulaDrafts.ts
|
Draft and published formula metadata share validation. Draft runtime formulas retain revision: null. |
| Export |
pricingQuoteExport/specContext.ts,
pricingQuoteExport/exportPolicy.ts,
orderFormFormula/persistence/source.ts,
previewBinding.ts
|
One export context supplies draft pricing/catalog/flow overrides and draft order-form bindings/formulas. |
| Tests + lint |
approvalDraftPreview.e2e.ts,
configurationPreview.e2e.ts,
eslint.config.js
|
New E2E coverage exercises draft approvals, formula-only drafts, copied preview options, export regressions, and hard-coded preview-prefix prevention. |
3. How it works
Preview authority flow
Components now pass the loaded opportunity into order-form generation:
const isPreview = isPreviewOpportunity(opportunity);
decideOrderFormGeneration({
gateEnabled,
approvalsEnabled,
isPreview,
activeStatus,
predictedGroupCount,
});
A preview URL alone can still show the admin preview route, but it does not make a real quote draft-aware or generation-eligible.
Recorded order-form generation goes through one export policy boundary:
if (!isRecordedOrderFormGeneration(args)) return;
await assertOrderFormGenerationAllowed(args);
The same check runs before queuing and again inside the export worker, so stale queued work cannot bypass approval requirements.
Approval formula resolution
resolveFormulaVersion; drafts keep revision: null.buildFormulaEvidence rejects draft decisions so draft predictions cannot become approval audit evidence.Order-form export snapshot
resolveQuotePreviews returns per-quote identity.loadExportSpecContext chooses draft or published pricing, datasheet, and flow data.A copied pricing option can lose the original input.isPreview stamp and still remain a preview if it is stored under the synthetic opportunity.
A real quote with input.isPreview: true, a renamed option, or a preview URL continues to use published configuration and live approval requirements.
Client and server lint now block new literal PREVIEW- usage outside tests and fixtures. Code should use the shared predicate or prefix constant.
4. Validation added
New visible lines across approvalDraftPreview.e2e.ts and configurationPreview.e2e.ts.
- Formula-only drafts.
- Draft rules + draft formulas.
- New never-published formulas.
- Rollback manifest behavior.
- Copied preview option export regression.
orderFormApprovalGate.test.ts verifies the same generation policy the client uses.
- Preview generation allowed.
- Approved live quote allowed.
- Pending/rejected/unsubmitted live quote predicts and forbids when groups are required.
14,236Mocha server tests.3,557Jest server tests.109order-form E2E tests, including13draft approval scenarios.10attribute-approval E2E tests.
5. What it doesn't change
- Does not publish draft formulas, order-form bindings, pricing specs, datasheets, flow specs, or catalog products during preview export.
- Does not allow preview quotes to be submitted for approval.
- Does not allow synthetic previews to write back to CRM or trigger automatic CRM writeback.
- Does not allow signature sends from synthetic preview flows.
- Does not let URL flags, quote names, or mutable input stamps bypass approval requirements on real quotes.
- Does not convert new Dealops 2 APIs to REST; touched routes remain tRPC/server service paths.
- Does not add a Prisma migration in the visible file list.
- Does not remove existing unrecorded document previews before approval; those are intentionally preserved.
6. Risks / rollback / open questions
resolveQuotePreview would affect approvals, export context, and writeback blocking. The PR adds targeted identity tests and E2E coverage for copied options, wrong organizations, and mismatched opportunities.