@wildo-ai/framework-knowledge 1.1.9 → 1.1.10
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/dist/claude-marketplace/.claude-plugin/marketplace.json +1 -1
- package/dist/claude-marketplace/plugins/wildo/.claude-plugin/plugin.json +1 -1
- package/dist/claude-marketplace/plugins/wildo/references/acceptance.md +11 -0
- package/dist/claude-marketplace/plugins/wildo/references/expert-personas-and-deliberations.md +26 -7
- package/dist/claude-marketplace/plugins/wildo/references/runs-judges-and-questions.md +4 -2
- package/dist/claude-marketplace/plugins/wildo/skills/accept/SKILL.md +4 -2
- package/dist/claude-marketplace/plugins/wildo/skills/why/SKILL.md +9 -3
- package/dist/esm/framework-knowledge.definitions.d.ts +1 -1
- package/dist/esm/framework-knowledge.definitions.d.ts.map +1 -1
- package/dist/esm/framework-knowledge.definitions.js +84 -4
- package/dist/esm/framework-knowledge.definitions.js.map +1 -1
- package/dist/esm/framework-knowledge.loader.d.ts.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.assemble-verify/playbook.definition.d.ts +1 -1
- package/dist/esm/playbooks/bottom_up.assemble-verify/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.assemble-verify/playbook.definition.js +1 -1
- package/dist/esm/playbooks/bottom_up.assemble-verify/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/bottom_up.build/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.build-decompose/playbook.definition.d.ts +39 -1
- package/dist/esm/playbooks/bottom_up.build-decompose/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.build-decompose/playbook.definition.js +132 -20
- package/dist/esm/playbooks/bottom_up.build-decompose/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/bottom_up.build-dispatch/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.conception/playbook.definition.d.ts +8 -4
- package/dist/esm/playbooks/bottom_up.conception/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.conception/playbook.definition.js +13 -6
- package/dist/esm/playbooks/bottom_up.conception/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/bottom_up.domain-plan/playbook.definition.d.ts +2 -1
- package/dist/esm/playbooks/bottom_up.domain-plan/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.domain-plan/playbook.definition.js +85 -8
- package/dist/esm/playbooks/bottom_up.domain-plan/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/bottom_up.experience-plan/playbook.definition.d.ts +4 -3
- package/dist/esm/playbooks/bottom_up.experience-plan/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.experience-plan/playbook.definition.js +4 -3
- package/dist/esm/playbooks/bottom_up.experience-plan/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/bottom_up.placement-plan/playbook.definition.d.ts +12 -3
- package/dist/esm/playbooks/bottom_up.placement-plan/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.placement-plan/playbook.definition.js +8 -4
- package/dist/esm/playbooks/bottom_up.placement-plan/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/bottom_up.website-plan/playbook.definition.d.ts +4 -1
- package/dist/esm/playbooks/bottom_up.website-plan/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/bottom_up.website-plan/playbook.definition.js +2 -1
- package/dist/esm/playbooks/bottom_up.website-plan/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/cross_cutting.application-creation/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/cross_cutting.compliance/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/cross_cutting.feature-development/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/cross_cutting.refinement/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/refinement.compliance-document-candidate/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/refinement.document-facts/playbook.definition.d.ts +1 -1
- package/dist/esm/playbooks/refinement.document-facts/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/refinement.document-facts/playbook.definition.js +13 -1
- package/dist/esm/playbooks/refinement.document-facts/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/refinement.feature-contribution/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/refinement.governance-document-candidate/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.brand-identity/playbook.definition.d.ts +2 -2
- package/dist/esm/playbooks/top_down.brand-identity/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.brand-identity/playbook.definition.js +10 -4
- package/dist/esm/playbooks/top_down.brand-identity/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/top_down.brand-name-research/playbook.definition.d.ts +2 -1
- package/dist/esm/playbooks/top_down.brand-name-research/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.brand-name-research/playbook.definition.js +5 -3
- package/dist/esm/playbooks/top_down.brand-name-research/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/top_down.brand-name-screening-produce/playbook.definition.d.ts +2 -1
- package/dist/esm/playbooks/top_down.brand-name-screening-produce/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.brand-name-screening-produce/playbook.definition.js +11 -9
- package/dist/esm/playbooks/top_down.brand-name-screening-produce/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/top_down.brand-naming/playbook.definition.d.ts +17 -3
- package/dist/esm/playbooks/top_down.brand-naming/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.brand-naming/playbook.definition.js +19 -2
- package/dist/esm/playbooks/top_down.brand-naming/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/top_down.business-model/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.capability-map/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.compliance-analysis/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.compliance-conception/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.compliance-evidence-adequacy/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.compliance-posture/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.compliance-research/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.definition/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.expert-personas/playbook.definition.d.ts +27 -6
- package/dist/esm/playbooks/top_down.expert-personas/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.expert-personas/playbook.definition.js +32 -12
- package/dist/esm/playbooks/top_down.expert-personas/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/top_down.feature-drafts/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.market-analysis/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.market-evidence-adequacy/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.market-research/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.market-snapshot-produce/playbook.definition.d.ts +2 -1
- package/dist/esm/playbooks/top_down.market-snapshot-produce/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.market-snapshot-produce/playbook.definition.js +13 -5
- package/dist/esm/playbooks/top_down.market-snapshot-produce/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/top_down.phase-gate/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.phase-gate/playbook.definition.js +38 -3
- package/dist/esm/playbooks/top_down.phase-gate/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/top_down.requirements-definition/playbook.definition.d.ts +2 -1
- package/dist/esm/playbooks/top_down.requirements-definition/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.requirements-definition/playbook.definition.js +23 -8
- package/dist/esm/playbooks/top_down.requirements-definition/playbook.definition.js.map +1 -1
- package/dist/esm/playbooks/top_down.risk-register/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.scope-roadmap/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.value-proposition/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.vision-elicitation/playbook.definition.d.ts.map +1 -1
- package/dist/esm/playbooks/top_down.vision-elicitation/playbook.definition.js +11 -0
- package/dist/esm/playbooks/top_down.vision-elicitation/playbook.definition.js.map +1 -1
- package/dist/knowledge/assurance-authority-bases/wildo-safe-baseline-v1/external-framework-mapping.json +1 -1
- package/dist/knowledge/manifest.json +7 -7
- package/dist/knowledge/playbooks/bottom_up.assemble-verify/playbook.json +1 -1
- package/dist/knowledge/playbooks/bottom_up.build-decompose/evaluation-protocol.json +1 -1
- package/dist/knowledge/playbooks/bottom_up.build-decompose/evaluation-treatment.json +1 -1
- package/dist/knowledge/playbooks/bottom_up.build-decompose/method.md +149 -11
- package/dist/knowledge/playbooks/bottom_up.build-decompose/playbook.json +40 -2
- package/dist/knowledge/playbooks/bottom_up.build-dispatch/method.md +55 -0
- package/dist/knowledge/playbooks/bottom_up.build-dispatch/playbook.json +1 -1
- package/dist/knowledge/playbooks/bottom_up.conception/playbook.json +10 -2
- package/dist/knowledge/playbooks/bottom_up.domain-plan/evaluation-protocol.json +1 -1
- package/dist/knowledge/playbooks/bottom_up.domain-plan/evaluation-treatment.json +1 -1
- package/dist/knowledge/playbooks/bottom_up.domain-plan/method.md +107 -11
- package/dist/knowledge/playbooks/bottom_up.domain-plan/playbook.json +4 -2
- package/dist/knowledge/playbooks/bottom_up.experience-plan/method.md +28 -6
- package/dist/knowledge/playbooks/bottom_up.experience-plan/playbook.json +5 -4
- package/dist/knowledge/playbooks/bottom_up.placement-plan/method.md +50 -0
- package/dist/knowledge/playbooks/bottom_up.placement-plan/playbook.json +16 -4
- package/dist/knowledge/playbooks/bottom_up.website-plan/method.md +19 -0
- package/dist/knowledge/playbooks/bottom_up.website-plan/playbook.json +5 -2
- package/dist/knowledge/playbooks/refinement.compliance-document-candidate/method.md +2 -1
- package/dist/knowledge/playbooks/refinement.compliance-document-candidate/playbook.json +1 -1
- package/dist/knowledge/playbooks/refinement.document-facts/method.md +8 -0
- package/dist/knowledge/playbooks/refinement.document-facts/playbook.json +3 -2
- package/dist/knowledge/playbooks/refinement.feature-contribution/method.md +5 -2
- package/dist/knowledge/playbooks/refinement.feature-contribution/playbook.json +1 -1
- package/dist/knowledge/playbooks/top_down.brand-identity/evaluation-protocol.json +1 -1
- package/dist/knowledge/playbooks/top_down.brand-identity/evaluation-treatment.json +1 -1
- package/dist/knowledge/playbooks/top_down.brand-identity/method.md +7 -3
- package/dist/knowledge/playbooks/top_down.brand-identity/playbook.json +3 -3
- package/dist/knowledge/playbooks/top_down.brand-name-research/method.md +56 -16
- package/dist/knowledge/playbooks/top_down.brand-name-research/playbook.json +6 -4
- package/dist/knowledge/playbooks/top_down.brand-name-screening-produce/evaluation-protocol.json +1 -1
- package/dist/knowledge/playbooks/top_down.brand-name-screening-produce/evaluation-treatment.json +1 -1
- package/dist/knowledge/playbooks/top_down.brand-name-screening-produce/method.md +30 -9
- package/dist/knowledge/playbooks/top_down.brand-name-screening-produce/playbook.json +5 -3
- package/dist/knowledge/playbooks/top_down.brand-naming/playbook.json +12 -1
- package/dist/knowledge/playbooks/top_down.capability-map/method.md +10 -9
- package/dist/knowledge/playbooks/top_down.capability-map/playbook.json +1 -1
- package/dist/knowledge/playbooks/top_down.expert-personas/playbook.json +16 -2
- package/dist/knowledge/playbooks/top_down.feature-drafts/method.md +5 -2
- package/dist/knowledge/playbooks/top_down.feature-drafts/playbook.json +1 -1
- package/dist/knowledge/playbooks/top_down.market-snapshot-produce/evaluation-protocol.json +1 -1
- package/dist/knowledge/playbooks/top_down.market-snapshot-produce/evaluation-treatment.json +1 -1
- package/dist/knowledge/playbooks/top_down.market-snapshot-produce/method.md +26 -0
- package/dist/knowledge/playbooks/top_down.market-snapshot-produce/playbook.json +4 -2
- package/dist/knowledge/playbooks/top_down.phase-gate/evaluation-protocol.json +1 -1
- package/dist/knowledge/playbooks/top_down.phase-gate/evaluation-treatment.json +1 -1
- package/dist/knowledge/playbooks/top_down.phase-gate/playbook.json +1 -1
- package/dist/knowledge/playbooks/top_down.requirements-definition/evaluation-protocol.json +1 -1
- package/dist/knowledge/playbooks/top_down.requirements-definition/evaluation-treatment.json +1 -1
- package/dist/knowledge/playbooks/top_down.requirements-definition/method.md +84 -9
- package/dist/knowledge/playbooks/top_down.requirements-definition/playbook.json +6 -3
- package/dist/knowledge/playbooks/top_down.vision-elicitation/method.md +19 -0
- package/dist/knowledge/playbooks/top_down.vision-elicitation/playbook.json +19 -1
- package/dist/knowledge/references/brand.name-choice.config.md +20 -3
- package/dist/knowledge/references/brand.name-screening.config.md +58 -3
- package/dist/knowledge/references/build-plan.task-graph.config.md +55 -0
- package/dist/knowledge/references/companion.market.prompt-renderer.md +11 -6
- package/dist/knowledge/references/example.authorization.application-roles.office-and-field.md +44 -0
- package/dist/knowledge/references/example.backend.custom-operation.audit-event.md +81 -0
- package/dist/knowledge/references/example.backend.custom-operation.child-line-total.md +258 -0
- package/dist/knowledge/references/example.backend.custom-operation.computed-total.md +153 -0
- package/dist/knowledge/references/example.backend.custom-operation.create-related-resource.md +107 -0
- package/dist/knowledge/references/example.data-seeding.minimal.md +10 -9
- package/dist/knowledge/references/example.data-seeding.row-reference.md +80 -0
- package/dist/knowledge/references/example.email.template.minimal.md +1 -1
- package/dist/knowledge/references/example.resource.config-wiring.retention-policy-operations.md +74 -0
- package/dist/knowledge/references/example.resource.personal-data.free-text-field.md +19 -0
- package/dist/knowledge/references/example.resource.personal-data.person-without-account.md +27 -0
- package/dist/knowledge/references/example.resource.status-lifecycle.quote.md +152 -0
- package/dist/knowledge/references/example.resource.ui-behavior.filter-presets.md +15 -0
- package/dist/knowledge/references/example.resource.ui-behavior.operation-icon.md +8 -0
- package/dist/knowledge/references/example.views.app-level.home-definition.md +13 -0
- package/dist/knowledge/references/example.views.chart-definition.shared.md +83 -0
- package/dist/knowledge/references/experience-plan.config.md +60 -7
- package/dist/knowledge/references/market.context-block.builder.md +1 -1
- package/dist/knowledge/references/placement-plan.config.md +43 -0
- package/dist/knowledge/references/requirements.functional-requirement.config.md +8 -2
- package/dist/knowledge/references/requirements.non-functional-requirement.config.md +2 -0
- package/dist/knowledge/references/requirements.references.conventions.md +1 -1
- package/dist/knowledge/references/requirements.snapshot.config.md +57 -1
- package/dist/knowledge/references/requirements.snapshot.validation.md +35 -1
- package/dist/knowledge/references/saas.backend.audit-logs.log-event.md +63 -0
- package/dist/knowledge/references/saas.backend.document-sequence.issue-in-operation.md +60 -0
- package/dist/knowledge/references/saas.backend.document-sequence.raise-floor.md +156 -0
- package/dist/knowledge/references/saas.backend.email.send.md +77 -0
- package/dist/knowledge/references/saas.backend.notifications.operation-email-template-ref.md +60 -0
- package/dist/knowledge/references/saas.data-seeding.computed-entry.md +43 -0
- package/dist/knowledge/references/saas.data-seeding.definition-input.md +8 -2
- package/dist/knowledge/references/saas.data-seeding.row-reference.md +93 -0
- package/dist/knowledge/references/saas.frontend.collection-filter-presets.md +124 -0
- package/dist/knowledge/references/saas.frontend.launcher.item-refs.md +316 -0
- package/dist/knowledge/references/saas.frontend.launcher.merge-rules.md +106 -0
- package/dist/knowledge/references/saas.frontend.launcher.runtime-availability.md +60 -0
- package/dist/knowledge/references/saas.frontend.resource-label-params.md +52 -0
- package/dist/knowledge/references/saas.frontend.resource-operation-frontend-config.md +47 -18
- package/dist/knowledge/references/saas.frontend.resource-ui-behavior-config.md +4 -1
- package/dist/knowledge/references/saas.frontend.settings-hub.engine-destination-roles.md +25 -0
- package/dist/knowledge/references/saas.frontend.settings-hub.placement.md +2 -2
- package/dist/knowledge/references/saas.models.audit.trail-config.md +45 -0
- package/dist/knowledge/references/saas.models.notifications.user-notification-definition.md +5 -3
- package/dist/knowledge/references/saas.models.resource-config.builder-parameters.md +26 -0
- package/dist/knowledge/references/saas.models.roles.definition.md +61 -0
- package/dist/knowledge/references/saas.models.roles.organization-defaults.md +97 -0
- package/dist/knowledge/references/saas.public-runtime.contract.md +26 -0
- package/dist/knowledge/references/saas.website.astro.bridge.md +10 -0
- package/dist/knowledge/references/saas.website.astro.label-loader.md +3 -0
- package/dist/knowledge/references/saas.website.astro.llms-txt-server.md +14 -1
- package/dist/knowledge/references/saas.website.astro.site-context.md +13 -0
- package/dist/knowledge/references/saas.website.blog.bridge.md +4 -0
- package/dist/knowledge/references/saas.website.config.site-context-loader.md +3 -0
- package/dist/knowledge/references/saas.website.legal.public-document-links.md +76 -0
- package/dist/knowledge/references/saas.website.root-config.seo.md +2 -1
- package/dist/knowledge/references/saas.website.runtime.context.md +7 -0
- package/dist/knowledge/references/saas.website.seo.llms-txt-config.md +2 -0
- package/dist/knowledge/references/website-plan.config.md +26 -0
- package/dist/knowledge/references/zod.decorators.chainable-runtime.md +13 -0
- package/dist/knowledge/references/zod.decorators.decorator-vocabulary.md +7 -0
- package/dist/knowledge/references/zod.decorators.document-sequence.md +65 -0
- package/dist/knowledge/references/zod.decorators.schema-metadata.md +1 -0
- package/dist/knowledge/references/zod.decorators.shared-structural-methods.md +21 -0
- package/dist/knowledge/references/zod.factories.bigdecimal.md +1 -0
- package/dist/knowledge/references/zod.factories.code.md +1 -0
- package/dist/knowledge/references/zod.factories.duration.md +1 -0
- package/dist/knowledge/references/zod.factories.money.md +1 -0
- package/dist/knowledge/registries/assurance-authority-bases.json +1 -1
- package/dist/knowledge/registries/framework-topics.json +337 -1
- package/dist/knowledge/registries/playbooks.json +18 -18
- package/dist/knowledge/registries/source-tags.json +1435 -873
- package/dist/knowledge/rules/live-context-door.md +1 -1
- package/dist/knowledge/skills/INDEX.md +3 -1
- package/dist/knowledge/skills/application-consumer-documentation-authoring/SKILL.md +16 -3
- package/dist/knowledge/skills/application-database-migrations/SKILL.md +14 -3
- package/dist/knowledge/skills/application-roles-authoring/SKILL.md +158 -0
- package/dist/knowledge/skills/application-roles-authoring/references/framework-application-roles-api.md +169 -0
- package/dist/knowledge/skills/application-roles-authoring/references/office-and-field-worked-example.md +63 -0
- package/dist/knowledge/skills/authorization-unit-narrowing/SKILL.md +6 -1
- package/dist/knowledge/skills/backend-custom-operation/SKILL.md +256 -9
- package/dist/knowledge/skills/backend-custom-operation/references/after-the-operation.md +42 -0
- package/dist/knowledge/skills/backend-custom-operation/references/framework-audit-log-event-api.md +220 -0
- package/dist/knowledge/skills/brand-logo-authoring/SKILL.md +5 -0
- package/dist/knowledge/skills/brand-name-screening/SKILL.md +33 -9
- package/dist/knowledge/skills/brand-name-screening/references/framework-brand-name-screening-api.md +78 -6
- package/dist/knowledge/skills/brand-name-screening/references/screening-procedure.md +30 -8
- package/dist/knowledge/skills/compliance-document-authoring/references/document-composition-privacy-notice.md +2 -1
- package/dist/knowledge/skills/config-app-shell/SKILL.md +58 -5
- package/dist/knowledge/skills/config-app-shell/references/framework-launcher-items-api.md +461 -0
- package/dist/knowledge/skills/config-app-shell/references/framework-launcher-visibility-api.md +80 -0
- package/dist/knowledge/skills/config-design-system/SKILL.md +28 -6
- package/dist/knowledge/skills/config-navigation/SKILL.md +14 -3
- package/dist/knowledge/skills/config-saas/SKILL.md +25 -11
- package/dist/knowledge/skills/config-saas/references/compliance-declarations.md +51 -1
- package/dist/knowledge/skills/config-saas/references/framework-audit-trail-config-api.md +62 -2
- package/dist/knowledge/skills/config-saas-backend/SKILL.md +6 -1
- package/dist/knowledge/skills/configure-billing/SKILL.md +18 -4
- package/dist/knowledge/skills/email-add-template/SKILL.md +27 -5
- package/dist/knowledge/skills/email-add-template/references/email-artifact-paths.md +1 -1
- package/dist/knowledge/skills/email-add-template/references/framework-email-send-api.md +128 -0
- package/dist/knowledge/skills/email-add-template/references/framework-operation-email-template-ref-api.md +99 -0
- package/dist/knowledge/skills/engine-component-registration/SKILL.md +6 -1
- package/dist/knowledge/skills/engine-product-definitions/SKILL.md +21 -8
- package/dist/knowledge/skills/flows-actors-chat-assistant/SKILL.md +10 -2
- package/dist/knowledge/skills/flows-actors-llm-agent-invocation/SKILL.md +18 -4
- package/dist/knowledge/skills/frontend-component-catalog/SKILL.md +11 -3
- package/dist/knowledge/skills/frontend-component-catalog/references/framework-component-catalog.md +2 -1
- package/dist/knowledge/skills/frontend-component-catalog/references/framework-component-usage.md +8 -0
- package/dist/knowledge/skills/i18n-rerun-pipeline/SKILL.md +18 -4
- package/dist/knowledge/skills/i18n-translation-rerun/SKILL.md +10 -2
- package/dist/knowledge/skills/infra-environment-config/SKILL.md +6 -1
- package/dist/knowledge/skills/local-environment-bootstrap/SKILL.md +6 -1
- package/dist/knowledge/skills/market-add-feature-benefit/SKILL.md +10 -2
- package/dist/knowledge/skills/market-alternatives/SKILL.md +10 -2
- package/dist/knowledge/skills/market-authoring-overview/SKILL.md +10 -2
- package/dist/knowledge/skills/market-category/SKILL.md +21 -7
- package/dist/knowledge/skills/market-channels/SKILL.md +6 -1
- package/dist/knowledge/skills/market-companion-prompt-enrichment/SKILL.md +11 -3
- package/dist/knowledge/skills/market-companion-prompt-enrichment/references/framework-companion-behavior-api.md +1 -1
- package/dist/knowledge/skills/market-generation-cli/SKILL.md +21 -11
- package/dist/knowledge/skills/market-generation-cli/references/framework-market-generation-cli.md +11 -6
- package/dist/knowledge/skills/market-icp/SKILL.md +10 -2
- package/dist/knowledge/skills/market-jobs-pains-gains/SKILL.md +6 -1
- package/dist/knowledge/skills/market-message-templates-authoring/SKILL.md +6 -1
- package/dist/knowledge/skills/market-persona/SKILL.md +14 -3
- package/dist/knowledge/skills/market-positioning-authoring/SKILL.md +6 -1
- package/dist/knowledge/skills/market-proof-and-objection/SKILL.md +10 -2
- package/dist/knowledge/skills/market-scoring-interpretation/SKILL.md +6 -1
- package/dist/knowledge/skills/market-snapshot-validation/SKILL.md +14 -3
- package/dist/knowledge/skills/market-tone-of-voice/SKILL.md +6 -1
- package/dist/knowledge/skills/model-cost-attribution/references/framework-work-unit-api.md +26 -0
- package/dist/knowledge/skills/module-companion-exports/SKILL.md +7 -1
- package/dist/knowledge/skills/module-relationships/SKILL.md +31 -4
- package/dist/knowledge/skills/pdf-template-authoring/SKILL.md +4 -2
- package/dist/knowledge/skills/provider-address-lookup/SKILL.md +14 -3
- package/dist/knowledge/skills/provider-frontend-file-picker/SKILL.md +6 -1
- package/dist/knowledge/skills/provider-operation-calls/SKILL.md +14 -3
- package/dist/knowledge/skills/rate-limit-authoring/SKILL.md +10 -2
- package/dist/knowledge/skills/resource-add-field/SKILL.md +10 -2
- package/dist/knowledge/skills/resource-add-field/references/framework-field-cross-layer-api.md +46 -17
- package/dist/knowledge/skills/resource-add-resource/SKILL.md +14 -2
- package/dist/knowledge/skills/resource-add-resource/references/framework-new-resource-core-config-api.md +26 -0
- package/dist/knowledge/skills/resource-config-wiring/SKILL.md +29 -3
- package/dist/knowledge/skills/resource-config-wiring/references/framework-collection-operation-declarations.md +19 -4
- package/dist/knowledge/skills/resource-config-wiring/references/framework-operation-audit-api.md +5 -2
- package/dist/knowledge/skills/resource-config-wiring/references/framework-personal-data-declaration-api.md +103 -0
- package/dist/knowledge/skills/resource-config-wiring/references/framework-retention-policy-operations.md +135 -0
- package/dist/knowledge/skills/resource-config-wiring/references/framework-saas-models-resource-config-api.md +26 -0
- package/dist/knowledge/skills/resource-config-wiring/references/framework-user-notifications-api.md +26 -7
- package/dist/knowledge/skills/resource-custom-view/SKILL.md +10 -2
- package/dist/knowledge/skills/resource-custom-view/references/custom-view-contracts.md +46 -17
- package/dist/knowledge/skills/resource-external-data/references/erasure-suppression.md +2 -2
- package/dist/knowledge/skills/resource-retention-binding/SKILL.md +5 -1
- package/dist/knowledge/skills/resource-schema-authoring/SKILL.md +15 -1
- package/dist/knowledge/skills/resource-schema-authoring/references/computed-totals.md +569 -0
- package/dist/knowledge/skills/resource-schema-authoring/references/document-numbers.md +358 -0
- package/dist/knowledge/skills/resource-schema-authoring/references/framework-decorator-vocabulary-api.md +8 -0
- package/dist/knowledge/skills/resource-schema-authoring/references/framework-shared-decorator-methods-api.md +21 -0
- package/dist/knowledge/skills/resource-schema-authoring/references/framework-special-factories-api.md +7 -2
- package/dist/knowledge/skills/resource-schema-authoring/references/framework-zod-lifecycle-and-chainable-api.md +13 -0
- package/dist/knowledge/skills/resource-status-lifecycle/SKILL.md +153 -0
- package/dist/knowledge/skills/resource-status-lifecycle/references/commercial-documents.md +46 -0
- package/dist/knowledge/skills/resource-status-lifecycle/references/quote-lifecycle-worked-example.md +198 -0
- package/dist/knowledge/skills/resource-ui-behavior/SKILL.md +30 -4
- package/dist/knowledge/skills/resource-ui-behavior/references/framework-collection-filter-presets-api.md +157 -0
- package/dist/knowledge/skills/resource-ui-behavior/references/framework-frontend-resource-ui-contracts-api.md +101 -19
- package/dist/knowledge/skills/seeding-authoring/SKILL.md +155 -40
- package/dist/knowledge/skills/seeding-authoring/references/cross-seed-row-references.md +67 -0
- package/dist/knowledge/skills/seeding-authoring/references/framework-data-seeding-api.md +148 -4
- package/dist/knowledge/skills/seeding-authoring/references/seed-row-overlay.md +22 -0
- package/dist/knowledge/skills/settings-placement-authoring/references/framework-settings-destinations-catalog.md +43 -0
- package/dist/knowledge/skills/settings-placement-authoring/references/framework-settings-placement-api.md +2 -2
- package/dist/knowledge/skills/spec-companion-exports/SKILL.md +6 -1
- package/dist/knowledge/skills/spec-component-update/SKILL.md +10 -2
- package/dist/knowledge/skills/spec-composite-view-update/SKILL.md +2 -2
- package/dist/knowledge/skills/spec-family-update/SKILL.md +71 -66
- package/dist/knowledge/skills/spec-family-update/references/family-spec-routing.md +1 -1
- package/dist/knowledge/skills/spec-resource-update/SKILL.md +30 -10
- package/dist/knowledge/skills/spec-resource-update/references/resource-spec-field-routing.md +28 -0
- package/dist/knowledge/skills/spec-update-after-change/SKILL.md +22 -5
- package/dist/knowledge/skills/views-add-composite-view/SKILL.md +6 -1
- package/dist/knowledge/skills/views-add-custom-view/SKILL.md +10 -2
- package/dist/knowledge/skills/views-app-level/SKILL.md +13 -3
- package/dist/knowledge/skills/views-app-level/references/application-home.md +56 -0
- package/dist/knowledge/skills/views-chart-authoring/SKILL.md +221 -37
- package/dist/knowledge/skills/views-composite-authoring/SKILL.md +22 -5
- package/dist/knowledge/skills/views-execution-authoring/SKILL.md +1 -1
- package/dist/knowledge/skills/website-anonymous-session/SKILL.md +32 -2
- package/dist/knowledge/skills/website-blog-authoring/SKILL.md +16 -3
- package/dist/knowledge/skills/website-blog-authoring/references/blog-adapter-api.md +4 -0
- package/dist/knowledge/skills/website-bundle-discipline/SKILL.md +7 -1
- package/dist/knowledge/skills/website-consent-gate-overrides/SKILL.md +13 -1
- package/dist/knowledge/skills/website-factory-advanced/SKILL.md +10 -2
- package/dist/knowledge/skills/website-inbound-contact-forms/SKILL.md +13 -1
- package/dist/knowledge/skills/website-layout-overrides/SKILL.md +6 -1
- package/dist/knowledge/skills/website-marketing-metadata-extension/SKILL.md +19 -1
- package/dist/knowledge/skills/website-navigation-authoring/SKILL.md +55 -18
- package/dist/knowledge/skills/website-navigation-authoring/references/framework-public-document-links-api.md +98 -0
- package/dist/knowledge/skills/website-navigation-authoring/references/worked-examples-header-footer.md +8 -11
- package/dist/knowledge/skills/website-page-authoring/SKILL.md +16 -5
- package/dist/knowledge/skills/website-page-authoring/references/framework-site-context-loader-api.md +3 -0
- package/dist/knowledge/skills/website-primitive-overrides/SKILL.md +6 -1
- package/dist/knowledge/skills/website-section-faq/SKILL.md +6 -1
- package/dist/knowledge/skills/website-section-feature-benefit-summary/SKILL.md +6 -1
- package/dist/knowledge/skills/website-section-feature-detail/SKILL.md +10 -2
- package/dist/knowledge/skills/website-section-hero/SKILL.md +6 -1
- package/dist/knowledge/skills/website-section-pricing/SKILL.md +6 -1
- package/dist/knowledge/skills/website-section-social-proof/SKILL.md +12 -2
- package/dist/knowledge/skills/website-seo-aeo-geo/SKILL.md +15 -3
- package/dist/knowledge/skills/website-seo-aeo-geo/references/geo-api.md +16 -1
- package/dist/knowledge/skills/website-seo-aeo-geo/references/seo-api.md +2 -1
- package/dist/knowledge/topic-index.json +1441 -269
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -112,19 +112,26 @@ export class MarketPromptUnknownPlaceholderError extends Error {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
/*
|
|
116
|
+
* The three errors below describe the CALLER's request — a flag it did not pass, a ref or template it
|
|
117
|
+
* named that the snapshot does not hold — so they extend `IntrospectionInputValidationError` and carry
|
|
118
|
+
* its name across the subprocess boundary: the controller answers 400 with the message instead of a
|
|
119
|
+
* sanitized 500 (#2365). They keep their own classes for `instanceof`; their `name` is the contract.
|
|
120
|
+
* `MarketPromptUnknownPlaceholderError` above stays a plain error: an unknown placeholder is a fault in
|
|
121
|
+
* the AUTHORED template, which no change to the request can fix.
|
|
122
|
+
*/
|
|
123
|
+
export class MarketPromptMissingRequiredInputError extends IntrospectionInputValidationError {
|
|
116
124
|
public readonly missing: MarketMessageRequiredInput[];
|
|
117
125
|
constructor(templateRef: string, missing: MarketMessageRequiredInput[]) {
|
|
118
126
|
super(
|
|
119
127
|
`Template \`${templateRef}\` declares requiredInputs ${missing.map(m => `\`${m}\``).join(', ')} `
|
|
120
128
|
+ `but the caller did not provide them. Pass the matching CLI flag(s) (e.g. \`--icp\`, \`--benefit\`, \`--objection\`, \`--channel\`).`,
|
|
121
129
|
);
|
|
122
|
-
this.name = 'MarketPromptMissingRequiredInputError';
|
|
123
130
|
this.missing = missing;
|
|
124
131
|
}
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
export class MarketPromptUnknownRefError extends
|
|
134
|
+
export class MarketPromptUnknownRefError extends IntrospectionInputValidationError {
|
|
128
135
|
public readonly entityKind: string;
|
|
129
136
|
public readonly providedRef: string;
|
|
130
137
|
constructor(entityKind: string, providedRef: string, knownRefs: string[]) {
|
|
@@ -132,19 +139,17 @@ export class MarketPromptUnknownRefError extends Error {
|
|
|
132
139
|
`No ${entityKind} found with ref \`${providedRef}\` in the authored MarketSnapshot. `
|
|
133
140
|
+ `Known ${entityKind} refs: ${knownRefs.length > 0 ? knownRefs.map(r => `\`${r}\``).join(', ') : '(none)'}.`,
|
|
134
141
|
);
|
|
135
|
-
this.name = 'MarketPromptUnknownRefError';
|
|
136
142
|
this.entityKind = entityKind;
|
|
137
143
|
this.providedRef = providedRef;
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
|
|
141
|
-
export class MarketPromptTemplateNotFoundError extends
|
|
147
|
+
export class MarketPromptTemplateNotFoundError extends IntrospectionInputValidationError {
|
|
142
148
|
constructor(templateRef: string, knownRefs: string[]) {
|
|
143
149
|
super(
|
|
144
150
|
`No MarketMessageTemplate found with ref \`${templateRef}\`. `
|
|
145
151
|
+ `Known templates: ${knownRefs.length > 0 ? knownRefs.map(r => `\`${r}\``).join(', ') : '(none — author one in `specifications/src/market/messaging/`)'}.`,
|
|
146
152
|
);
|
|
147
|
-
this.name = 'MarketPromptTemplateNotFoundError';
|
|
148
153
|
}
|
|
149
154
|
}
|
|
150
155
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# example.authorization.application-roles.office-and-field
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Usage Example
|
|
5
|
+
|
|
6
|
+
```typescript
|
|
7
|
+
*
|
|
8
|
+
* A trade business with office staff and field technicians. Everything below imports from
|
|
9
|
+
* `@wildo-ai/saas-models`.
|
|
10
|
+
*
|
|
11
|
+
* 1. `shared-lib/src/engine/roles.ts` declares the field role. Office staff need no new role: they hold
|
|
12
|
+
* the core `ORG_MEMBER`, so administrators and owners keep everything office staff can do. The field
|
|
13
|
+
* role inherits `ORG_GUEST`, the bottom of the chain, so it starts from almost nothing.
|
|
14
|
+
*/
|
|
15
|
+
export const CUSTOM_ROLES_CONFIGURATION: RolesConfiguration = {
|
|
16
|
+
FIELD_TECHNICIAN: {
|
|
17
|
+
role: 'FIELD_TECHNICIAN',
|
|
18
|
+
inheritFrom: CORE_ORG_ROLES.ORG_GUEST,
|
|
19
|
+
isSystemRole: false,
|
|
20
|
+
relatedPrimaryScope: ResourcePrimaryScope.ORGANIZATIONS,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 2. `wildo.saas.config.ts` → `organizationTypes.<type>.availableOrgRoles` offers it. Omitted, the list
|
|
26
|
+
* defaults to owner, admin and member only, so the field role could never be given to anyone.
|
|
27
|
+
*/
|
|
28
|
+
export const workspaceAvailableOrgRoles: Roles[] = [
|
|
29
|
+
CORE_ORG_ROLES.ORG_OWNER,
|
|
30
|
+
CORE_ORG_ROLES.ORG_ADMIN,
|
|
31
|
+
CORE_ORG_ROLES.ORG_MEMBER,
|
|
32
|
+
'FIELD_TECHNICIAN',
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 3. Each operation variant's `roles` names who may call it. A holder satisfies a role it holds OR one
|
|
37
|
+
* up its `inheritFrom` chain, so `ORG_MEMBER` here admits office staff, managers, admins and owners,
|
|
38
|
+
* and the field role must be named explicitly wherever technicians are admitted.
|
|
39
|
+
*/
|
|
40
|
+
/** Jobs: technicians read the jobs and record progress on them. */
|
|
41
|
+
export const jobReadAndProgressRoles: Roles[] = ['FIELD_TECHNICIAN', CORE_ORG_ROLES.ORG_MEMBER];
|
|
42
|
+
/** Quotes and invoices: office only. A technician holding only the field role is refused. */
|
|
43
|
+
export const quoteAndInvoiceRoles: Roles[] = [CORE_ORG_ROLES.ORG_MEMBER];
|
|
44
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# example.backend.custom-operation.audit-event
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Usage Example
|
|
5
|
+
|
|
6
|
+
```typescript
|
|
7
|
+
import { AuditEventCategory, AuditEventSeverity, ResourceOperationRiskLevel, ResourceOperationVariantType } from '@wildo-ai/saas-models';
|
|
8
|
+
import {
|
|
9
|
+
createResourceCustomServiceImplementation,
|
|
10
|
+
SAAS_SERVICE_TYPES,
|
|
11
|
+
type AuditLogsBackendService,
|
|
12
|
+
type InversifyContainer,
|
|
13
|
+
type ResourceCustomServiceImplementationFactory,
|
|
14
|
+
type ResourcesRegistryBackendService,
|
|
15
|
+
} from '@wildo-ai/saas-backend-lib';
|
|
16
|
+
|
|
17
|
+
/** In an application these come from its shared-lib (`Sales_ResourceType`, `Quotes_Operations`). */
|
|
18
|
+
enum Sales_ResourceType {
|
|
19
|
+
QUOTES = 'quotes',
|
|
20
|
+
}
|
|
21
|
+
enum Quotes_Operations {
|
|
22
|
+
ISSUE = 'issue',
|
|
23
|
+
}
|
|
24
|
+
/** The application's OWN event types, named once so the trail and every reader agree on the words. */
|
|
25
|
+
enum Sales_AuditEventType {
|
|
26
|
+
QUOTE_ISSUED = 'SALES_QUOTE_ISSUED',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* How each of those event types is classified, declared ONCE as `auditTrail.applicationEventTypes` in the backend
|
|
31
|
+
* configuration (`backend-api/src/saas-config.backend.ts`). Rows of a declared type are recorded and routed to the
|
|
32
|
+
* SIEM with its category and severity, and the labelling pipeline plans its word; an undeclared type is recorded as
|
|
33
|
+
* `data_access` / `info`. Total over the enum by its type, so a new event type without a classification fails to compile.
|
|
34
|
+
*/
|
|
35
|
+
export const salesAuditEventTypes = {
|
|
36
|
+
[Sales_AuditEventType.QUOTE_ISSUED]: { category: AuditEventCategory.DATA_ACCESS, severity: AuditEventSeverity.WARNING },
|
|
37
|
+
} satisfies Record<Sales_AuditEventType, { category: AuditEventCategory; severity: AuditEventSeverity }>;
|
|
38
|
+
|
|
39
|
+
const quotesIssueCustomImpl: ResourceCustomServiceImplementationFactory = (
|
|
40
|
+
resourcesRegistryService: ResourcesRegistryBackendService,
|
|
41
|
+
container: InversifyContainer,
|
|
42
|
+
) => {
|
|
43
|
+
const operationPath = {
|
|
44
|
+
resourceIdentifier: Sales_ResourceType.QUOTES,
|
|
45
|
+
operationIdentifier: Quotes_Operations.ISSUE,
|
|
46
|
+
variantType: ResourceOperationVariantType.API_CALL,
|
|
47
|
+
isOperationDefault: true,
|
|
48
|
+
};
|
|
49
|
+
const requestDtoSchema = resourcesRegistryService.getRequestDtoFromPath(operationPath);
|
|
50
|
+
const responseDtoSchema = resourcesRegistryService.getResponseDtoFromPath(operationPath);
|
|
51
|
+
|
|
52
|
+
// Resolved on first use, never in the factory body: factories run while the container is still being populated.
|
|
53
|
+
let auditLogs: AuditLogsBackendService | undefined;
|
|
54
|
+
|
|
55
|
+
return createResourceCustomServiceImplementation<typeof requestDtoSchema, typeof responseDtoSchema>({
|
|
56
|
+
operationPath,
|
|
57
|
+
requestDtoSchema,
|
|
58
|
+
responseDtoSchema,
|
|
59
|
+
handlers: {
|
|
60
|
+
// The quote's ISSUE transition: the event is recorded once the issued state is the result.
|
|
61
|
+
postfixCoreOperations: async (id, result, executionContext, _operationPath, utils) => {
|
|
62
|
+
auditLogs ??= container.get<AuditLogsBackendService>(SAAS_SERVICE_TYPES.AuditLogsService);
|
|
63
|
+
// The event names WHO acted and WHICH organization it is about: the row is assembled from what you pass, and an
|
|
64
|
+
// organization's audit view lists only rows carrying its id. The context (second argument) adds what kind of
|
|
65
|
+
// principal acted (person, agent, machine), the correlation id and the organization's SIEM routing.
|
|
66
|
+
await auditLogs.logEvent({
|
|
67
|
+
eventType: Sales_AuditEventType.QUOTE_ISSUED,
|
|
68
|
+
riskLevel: ResourceOperationRiskLevel.MEDIUM,
|
|
69
|
+
userId: executionContext.initiatorIds?.userId,
|
|
70
|
+
organizationId: executionContext.initiatorIds?.organizationId,
|
|
71
|
+
eventData: { quoteId: id, quoteNumber: (result as { number?: string } | undefined)?.number },
|
|
72
|
+
}, executionContext);
|
|
73
|
+
utils.logger.debug('Recorded the quote issue in the audit trail');
|
|
74
|
+
return result;
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default quotesIssueCustomImpl;
|
|
81
|
+
```
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# example.backend.custom-operation.child-line-total
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Usage Example
|
|
5
|
+
|
|
6
|
+
```typescript
|
|
7
|
+
// The pure total function and line type of the computed-total recipe (array lines), shared rather than copied.
|
|
8
|
+
import { computeQuoteTotal, type QuoteLine } from './computed-total.example';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { CurrencyAllowed, CurrencySchema, z_money } from '@wildo-ai/zod-decorators';
|
|
11
|
+
import {
|
|
12
|
+
CORE_ORG_ROLES,
|
|
13
|
+
CoreResourceOperation,
|
|
14
|
+
CoreResourceType,
|
|
15
|
+
ErrorCustomMessageReference,
|
|
16
|
+
ErrorType,
|
|
17
|
+
RelationshipNature,
|
|
18
|
+
ResourceOperationRiskLevel,
|
|
19
|
+
ResourceOperationVariantType,
|
|
20
|
+
ResourceRelationshipAccessScopeStrategy,
|
|
21
|
+
ResourceRelationshipCardinality,
|
|
22
|
+
createResourceConfiguration_Initialization,
|
|
23
|
+
createResourcesRelationship,
|
|
24
|
+
type ResourceRelationship,
|
|
25
|
+
type ResourceType,
|
|
26
|
+
} from '@wildo-ai/saas-models';
|
|
27
|
+
import {
|
|
28
|
+
createResourceCustomServiceImplementation,
|
|
29
|
+
type ExecutionContext,
|
|
30
|
+
type ResourceCustomServiceImplementationFactory,
|
|
31
|
+
type ResourceOperation_CustomImplementation_Utils,
|
|
32
|
+
type ResourcesRegistryBackendService,
|
|
33
|
+
} from '@wildo-ai/saas-backend-lib';
|
|
34
|
+
|
|
35
|
+
// ── shared-lib: the two resources ───────────────────────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
/** In an application these come from its shared-lib. */
|
|
38
|
+
export enum Sales_ResourceType {
|
|
39
|
+
QUOTES = 'quotes',
|
|
40
|
+
QUOTE_LINES = 'quoteLines',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export enum Quote_Status {
|
|
44
|
+
DRAFT = 'draft',
|
|
45
|
+
SENT = 'sent',
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export enum Quote_Operations {
|
|
49
|
+
/** Moves a DRAFT quote to SENT. After it, the quote and its lines are what the customer received. */
|
|
50
|
+
SEND = 'send',
|
|
51
|
+
/** Internal only: recomputes `total` from the quote's lines. Never offered to a client. */
|
|
52
|
+
RECOMPUTE_TOTAL = 'recompute_total',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const Quote_Schema = z.object({
|
|
56
|
+
_id: z.string().min(1).isPrimaryKey(),
|
|
57
|
+
organizationId: z.string().min(1).isDBIndexed().isForeignKey().excludeFromUpdate(),
|
|
58
|
+
title: z.string().trim().min(1).max(200).isSummaryField(),
|
|
59
|
+
// Fixed at create: the total and every line are in this currency, so changing it would strand them.
|
|
60
|
+
currency: CurrencySchema.excludeFromUpdate(),
|
|
61
|
+
// Changed only by the SEND transition: a plain UPDATE that could set it back to DRAFT would unfreeze the lines.
|
|
62
|
+
status: z.enum(Quote_Status).default(Quote_Status.DRAFT).excludeFromCreate().excludeFromUpdate(),
|
|
63
|
+
total: z_money({ currenciesAllowed: [CurrencyAllowed.FIAT] }).optional().isSummaryField().excludeFromCreate().excludeFromUpdate(),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/** One line, its own resource: a COMPOSITION child of its quote. `quoteId` never moves to another quote. */
|
|
67
|
+
export const QuoteLine_Schema = z.object({
|
|
68
|
+
_id: z.string().min(1).isPrimaryKey(),
|
|
69
|
+
organizationId: z.string().min(1).isDBIndexed().isForeignKey().excludeFromUpdate(),
|
|
70
|
+
quoteId: z.string().min(1).isDBIndexed().isForeignKey().excludeFromUpdate(),
|
|
71
|
+
description: z.string().trim().min(1).max(500),
|
|
72
|
+
quantity: z.number().int().min(1),
|
|
73
|
+
unitPrice: z_money({ currenciesAllowed: [CurrencyAllowed.FIAT] }),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const sales_ResourceRelationships: ResourceRelationship[] = [
|
|
77
|
+
createResourcesRelationship(CoreResourceType.ORGANIZATIONS, Sales_ResourceType.QUOTES as ResourceType,
|
|
78
|
+
ResourceRelationshipCardinality.ONE, ResourceRelationshipCardinality.MANY,
|
|
79
|
+
{ nature: RelationshipNature.COMPOSITION, isPrimaryScope: true, foreignKeyField: 'organizationId' }),
|
|
80
|
+
createResourcesRelationship(CoreResourceType.ORGANIZATIONS, Sales_ResourceType.QUOTE_LINES as ResourceType,
|
|
81
|
+
ResourceRelationshipCardinality.ONE, ResourceRelationshipCardinality.MANY,
|
|
82
|
+
{ accessScopeStrategy: ResourceRelationshipAccessScopeStrategy.STANDALONE, isPrimaryScope: true, nature: RelationshipNature.REFERENCE, contextPolicy: { enabled: false }, foreignKeyField: 'organizationId' }),
|
|
83
|
+
createResourcesRelationship(Sales_ResourceType.QUOTES as ResourceType, Sales_ResourceType.QUOTE_LINES as ResourceType,
|
|
84
|
+
ResourceRelationshipCardinality.ONE, ResourceRelationshipCardinality.MANY,
|
|
85
|
+
{ nature: RelationshipNature.COMPOSITION, foreignKeyField: 'quoteId' }),
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
/** Every client-facing operation here: one API_CALL variant for organization members. */
|
|
89
|
+
const apiCall = <const R extends ResourceOperationRiskLevel>(riskLevel: R) => ({
|
|
90
|
+
variants: [{ variantType: ResourceOperationVariantType.API_CALL as const, isDefault: true, roles: [CORE_ORG_ROLES.ORG_MEMBER], riskLevel }],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
type Quote_CoreOperations = CoreResourceOperation.READ | CoreResourceOperation.LIST | CoreResourceOperation.CREATE | CoreResourceOperation.UPDATE;
|
|
94
|
+
export const quote_ResourceConfiguration_InitializationFactory = (relationships: ResourceRelationship[]) =>
|
|
95
|
+
createResourceConfiguration_Initialization<typeof Quote_Operations, Quote_CoreOperations, typeof Quote_Schema>({
|
|
96
|
+
mainSchema: Quote_Schema,
|
|
97
|
+
resourceIdentifier: Sales_ResourceType.QUOTES,
|
|
98
|
+
resourceFieldIdentifier: 'quoteId',
|
|
99
|
+
resourceRelationships: relationships,
|
|
100
|
+
coreOperations: [CoreResourceOperation.READ, CoreResourceOperation.LIST, CoreResourceOperation.CREATE, CoreResourceOperation.UPDATE],
|
|
101
|
+
customOperation: Quote_Operations,
|
|
102
|
+
operationsConfiguration: {
|
|
103
|
+
[CoreResourceOperation.READ]: apiCall(ResourceOperationRiskLevel.LOW),
|
|
104
|
+
[CoreResourceOperation.LIST]: apiCall(ResourceOperationRiskLevel.LOW),
|
|
105
|
+
[CoreResourceOperation.CREATE]: apiCall(ResourceOperationRiskLevel.MEDIUM),
|
|
106
|
+
[CoreResourceOperation.UPDATE]: apiCall(ResourceOperationRiskLevel.MEDIUM),
|
|
107
|
+
[Quote_Operations.SEND]: {
|
|
108
|
+
variants: [{
|
|
109
|
+
variantType: ResourceOperationVariantType.API_CALL,
|
|
110
|
+
isDefault: true,
|
|
111
|
+
roles: [CORE_ORG_ROLES.ORG_MEMBER],
|
|
112
|
+
riskLevel: ResourceOperationRiskLevel.HIGH,
|
|
113
|
+
resourceOperationLike: CoreResourceOperation.UPDATE,
|
|
114
|
+
requestDto: z.object({}),
|
|
115
|
+
enabledCondition: ({ currentObject }) => currentObject.status === Quote_Status.DRAFT,
|
|
116
|
+
basicPrefixOperation: () => ({ status: Quote_Status.SENT }),
|
|
117
|
+
authoritativeFields: ['status'],
|
|
118
|
+
}],
|
|
119
|
+
},
|
|
120
|
+
[Quote_Operations.RECOMPUTE_TOTAL]: {
|
|
121
|
+
variants: [{
|
|
122
|
+
// INTERNAL_CALL: no route, no button. Only the line operations' hooks call it.
|
|
123
|
+
variantType: ResourceOperationVariantType.INTERNAL_CALL,
|
|
124
|
+
isDefault: true,
|
|
125
|
+
roles: [CORE_ORG_ROLES.ORG_MEMBER],
|
|
126
|
+
riskLevel: ResourceOperationRiskLevel.LOW,
|
|
127
|
+
resourceOperationLike: CoreResourceOperation.UPDATE,
|
|
128
|
+
requestDto: z.object({}),
|
|
129
|
+
// An INTERNAL_CALL variant has no `enabledCondition`: the "only while DRAFT" guard is the prefix's refusal below.
|
|
130
|
+
}],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
type QuoteLine_CoreOperations = CoreResourceOperation.READ | CoreResourceOperation.LIST | CoreResourceOperation.CREATE | CoreResourceOperation.UPDATE | CoreResourceOperation.DELETE;
|
|
136
|
+
export const quoteLine_ResourceConfiguration_InitializationFactory = (relationships: ResourceRelationship[]) =>
|
|
137
|
+
createResourceConfiguration_Initialization<undefined, QuoteLine_CoreOperations, typeof QuoteLine_Schema>({
|
|
138
|
+
mainSchema: QuoteLine_Schema,
|
|
139
|
+
resourceIdentifier: Sales_ResourceType.QUOTE_LINES,
|
|
140
|
+
resourceFieldIdentifier: 'quoteLineId',
|
|
141
|
+
resourceRelationships: relationships,
|
|
142
|
+
coreOperations: [CoreResourceOperation.READ, CoreResourceOperation.LIST, CoreResourceOperation.CREATE, CoreResourceOperation.UPDATE, CoreResourceOperation.DELETE],
|
|
143
|
+
operationsConfiguration: {
|
|
144
|
+
[CoreResourceOperation.READ]: apiCall(ResourceOperationRiskLevel.LOW),
|
|
145
|
+
[CoreResourceOperation.LIST]: apiCall(ResourceOperationRiskLevel.LOW),
|
|
146
|
+
[CoreResourceOperation.CREATE]: apiCall(ResourceOperationRiskLevel.LOW),
|
|
147
|
+
[CoreResourceOperation.UPDATE]: apiCall(ResourceOperationRiskLevel.LOW),
|
|
148
|
+
[CoreResourceOperation.DELETE]: apiCall(ResourceOperationRiskLevel.LOW),
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// ── backend-api: the recompute, and the hooks that call it ──────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Every line of a quote. An internal `list` with no pagination returns the full set: that is the engine's internal-call
|
|
156
|
+
* contract, because a total that stopped at a page boundary would be wrong with nothing saying so. (Pass a page only
|
|
157
|
+
* when completeness is not needed; an explicit page is capped by the LIST operation's ceiling.)
|
|
158
|
+
*/
|
|
159
|
+
async function readAllQuoteLines(quoteId: string, executionContext: ExecutionContext<any>, utils: ResourceOperation_CustomImplementation_Utils): Promise<QuoteLine[]> {
|
|
160
|
+
const listed = await utils.servicesRegistry.list<QuoteLine>(
|
|
161
|
+
Sales_ResourceType.QUOTE_LINES as ResourceType,
|
|
162
|
+
await utils.executionContextCreator.createForSubCall(executionContext, Sales_ResourceType.QUOTE_LINES as ResourceType, CoreResourceOperation.LIST, utils.serviceOptions),
|
|
163
|
+
{ quoteId },
|
|
164
|
+
undefined,
|
|
165
|
+
utils.serviceOptions,
|
|
166
|
+
);
|
|
167
|
+
return Array.isArray(listed) ? listed : listed.data;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The quote's `recompute_total`: owns `total` (`authoritativeFields`), computes it from every line inside the caller's
|
|
172
|
+
* transaction (each read forwards `utils.serviceOptions`), and refuses a total it cannot compute honestly.
|
|
173
|
+
*/
|
|
174
|
+
export const quotesRecomputeTotal: ResourceCustomServiceImplementationFactory = (resourcesRegistryService: ResourcesRegistryBackendService) => {
|
|
175
|
+
const operationPath = {
|
|
176
|
+
resourceIdentifier: Sales_ResourceType.QUOTES,
|
|
177
|
+
operationIdentifier: Quote_Operations.RECOMPUTE_TOTAL,
|
|
178
|
+
variantType: ResourceOperationVariantType.INTERNAL_CALL,
|
|
179
|
+
isOperationDefault: true,
|
|
180
|
+
};
|
|
181
|
+
const requestDtoSchema = resourcesRegistryService.getRequestDtoFromPath(operationPath);
|
|
182
|
+
const responseDtoSchema = resourcesRegistryService.getResponseDtoFromPath(operationPath);
|
|
183
|
+
return createResourceCustomServiceImplementation<typeof requestDtoSchema, typeof responseDtoSchema>({
|
|
184
|
+
operationPath,
|
|
185
|
+
requestDtoSchema,
|
|
186
|
+
responseDtoSchema,
|
|
187
|
+
authoritativeFields: ['total'],
|
|
188
|
+
handlers: {
|
|
189
|
+
prefixCoreOperations: async (quoteId, input, executionContext, _operationPath, utils) => {
|
|
190
|
+
const quote = utils.currentObject as { currency: string; status: Quote_Status };
|
|
191
|
+
// The one guard for every line change: a sent quote's lines are what the customer received. Refusing here fails
|
|
192
|
+
// the line operation's transaction, so the line write is rolled back with it, whichever operation it was.
|
|
193
|
+
if (quote.status !== Quote_Status.DRAFT) {
|
|
194
|
+
throw utils.errorBuilder.buildError(ErrorType.CONFLICT, executionContext, {
|
|
195
|
+
customMessageReference: ErrorCustomMessageReference.CONFLICT,
|
|
196
|
+
context: { field: 'status', reason: 'quote_not_draft' },
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// Two lines written to one quote at the same moment take turns here, so the second sees the first's line. This
|
|
200
|
+
// operation targets the quote's row, so the framework read `utils.currentObject` with the quote's write lock
|
|
201
|
+
// before this prefix ran (PostgreSQL; on MongoDB a write conflict aborts the second instead). Nothing to add.
|
|
202
|
+
const lines = await readAllQuoteLines(String(quoteId), executionContext, utils);
|
|
203
|
+
const total = computeQuoteTotal(lines, 0, quote.currency);
|
|
204
|
+
if ('refusal' in total) {
|
|
205
|
+
throw utils.errorBuilder.buildError(ErrorType.VALIDATION, executionContext, {
|
|
206
|
+
customMessageReference: ErrorCustomMessageReference.SERVICE_RESOURCE_VALIDATION_FAILED,
|
|
207
|
+
context: { field: 'total', reason: total.refusal },
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return { ...input, total: total.total } as typeof input;
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* One factory per line operation. `transactionalCore` puts the line write and the quote's recompute in ONE transaction,
|
|
218
|
+
* with the quote declared as a participant: a refused recompute (a sent quote, a line in another currency) rolls the
|
|
219
|
+
* line write back, so a line never changes without its quote's total.
|
|
220
|
+
*/
|
|
221
|
+
function quoteLinesRecompute(operationIdentifier: CoreResourceOperation.CREATE | CoreResourceOperation.UPDATE | CoreResourceOperation.DELETE): ResourceCustomServiceImplementationFactory {
|
|
222
|
+
// No DTO schemas: the postfix passes the core result through untouched, and DELETE's result (the deletion envelope)
|
|
223
|
+
// is not the response DTO's shape, so declaring one would fail the parse after the row is already gone.
|
|
224
|
+
return () => createResourceCustomServiceImplementation({
|
|
225
|
+
operationPath: {
|
|
226
|
+
resourceIdentifier: Sales_ResourceType.QUOTE_LINES,
|
|
227
|
+
operationIdentifier,
|
|
228
|
+
variantType: ResourceOperationVariantType.API_CALL,
|
|
229
|
+
isOperationDefault: true,
|
|
230
|
+
},
|
|
231
|
+
transactionalCore: true,
|
|
232
|
+
transactionParticipants: { quote: Sales_ResourceType.QUOTES as ResourceType },
|
|
233
|
+
handlers: {
|
|
234
|
+
postfixCoreOperations: async (_id, result, executionContext, _operationPath, utils) => {
|
|
235
|
+
// CREATE: the written line. UPDATE and DELETE: `utils.currentObject`, the stored line read before the write
|
|
236
|
+
// (`quoteId` never changes, and after a DELETE the row is gone).
|
|
237
|
+
const quoteId = (utils.currentObject as QuoteLine & { quoteId?: string } | undefined)?.quoteId
|
|
238
|
+
?? (result as unknown as { quoteId: string }).quoteId;
|
|
239
|
+
await utils.servicesRegistry.executeCustomOperation(
|
|
240
|
+
Sales_ResourceType.QUOTES as ResourceType,
|
|
241
|
+
Quote_Operations.RECOMPUTE_TOTAL,
|
|
242
|
+
await utils.executionContextCreator.createForSubCall(
|
|
243
|
+
executionContext, Sales_ResourceType.QUOTES as ResourceType, Quote_Operations.RECOMPUTE_TOTAL, utils.serviceOptions,
|
|
244
|
+
),
|
|
245
|
+
quoteId,
|
|
246
|
+
{},
|
|
247
|
+
utils.serviceOptions,
|
|
248
|
+
);
|
|
249
|
+
return result;
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export const quoteLinesCreateRecompute: ResourceCustomServiceImplementationFactory = quoteLinesRecompute(CoreResourceOperation.CREATE);
|
|
256
|
+
export const quoteLinesUpdateRecompute: ResourceCustomServiceImplementationFactory = quoteLinesRecompute(CoreResourceOperation.UPDATE);
|
|
257
|
+
export const quoteLinesDeleteRecompute: ResourceCustomServiceImplementationFactory = quoteLinesRecompute(CoreResourceOperation.DELETE);
|
|
258
|
+
```
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# example.backend.custom-operation.computed-total
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Usage Example
|
|
5
|
+
|
|
6
|
+
```typescript
|
|
7
|
+
import { CoreResourceOperation, ErrorCustomMessageReference, ErrorType, ResourceOperationVariantType } from '@wildo-ai/saas-models';
|
|
8
|
+
import {
|
|
9
|
+
currencyMinorUnitDecimals,
|
|
10
|
+
MoneyMinorUnitConversionError,
|
|
11
|
+
MoneyMinorUnitConversionFailure,
|
|
12
|
+
toCurrencyMinorUnitAmountOrThrow,
|
|
13
|
+
type MoneyValue,
|
|
14
|
+
} from '@wildo-ai/zod-decorators';
|
|
15
|
+
import {
|
|
16
|
+
createResourceCustomServiceImplementation,
|
|
17
|
+
type ResourceCustomServiceImplementationFactory,
|
|
18
|
+
type ResourcesRegistryBackendService,
|
|
19
|
+
} from '@wildo-ai/saas-backend-lib';
|
|
20
|
+
|
|
21
|
+
/** In an application this comes from its shared-lib. */
|
|
22
|
+
enum Sales_ResourceType {
|
|
23
|
+
QUOTES = 'quotes',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A quote line as the schema declares it: `lines: z.array(z.object({ description, quantity: z.number().int().min(1),
|
|
28
|
+
* unitPrice: z_money() }))`. Whole quantities only: for hours or metres, price per smallest unit you sell (a quarter
|
|
29
|
+
* hour, a centimetre) so the product stays an integer, instead of rounding here.
|
|
30
|
+
*/
|
|
31
|
+
export interface QuoteLine {
|
|
32
|
+
readonly description: string;
|
|
33
|
+
readonly quantity: number;
|
|
34
|
+
readonly unitPrice: MoneyValue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Why a total cannot be computed honestly. Each is a different fix for the person who sent the quote. */
|
|
38
|
+
export enum QuoteTotalRefusal {
|
|
39
|
+
/** A line is priced in another currency than the quote's: a sum across currencies is not a total. */
|
|
40
|
+
LINE_CURRENCY_DIFFERS = 'line_currency_differs_from_quote',
|
|
41
|
+
/** The quote's currency has no minor unit this framework resolves (`XXX`, `XDR`). */
|
|
42
|
+
CURRENCY_HAS_NO_MINOR_UNIT = 'currency_has_no_minor_unit',
|
|
43
|
+
/** A unit price is authored more finely than the currency allows (1.005 EUR): rounding it would invent money. */
|
|
44
|
+
PRICE_FINER_THAN_CURRENCY = 'price_finer_than_currency',
|
|
45
|
+
/** A unit price is too large to convert exactly at the currency's scale. */
|
|
46
|
+
PRICE_TOO_LARGE = 'price_too_large',
|
|
47
|
+
/** A quantity is not a whole number of at least 1. */
|
|
48
|
+
QUANTITY_NOT_WHOLE = 'quantity_not_whole',
|
|
49
|
+
/** The discount is outside 0–100 %. */
|
|
50
|
+
DISCOUNT_OUT_OF_RANGE = 'discount_out_of_range',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The quote's total in the quote's own currency, at that currency's scale.
|
|
55
|
+
*
|
|
56
|
+
* A `MoneyValue` carries its own AUTHORED scale (`decimals`), which need not be the currency's: `1005n` with 3
|
|
57
|
+
* decimals is 1.005. So every line is first converted exactly to the currency's scale, and refused when that would
|
|
58
|
+
* lose a fraction; only then are amounts summed, all in `bigint`, with nothing rounded until the discount.
|
|
59
|
+
*/
|
|
60
|
+
export function computeQuoteTotal(
|
|
61
|
+
lines: readonly QuoteLine[],
|
|
62
|
+
discountPercent: number,
|
|
63
|
+
currency: string,
|
|
64
|
+
): { readonly total: MoneyValue } | { readonly refusal: QuoteTotalRefusal } {
|
|
65
|
+
const decimals = currencyMinorUnitDecimals(currency);
|
|
66
|
+
if (decimals === undefined) return { refusal: QuoteTotalRefusal.CURRENCY_HAS_NO_MINOR_UNIT };
|
|
67
|
+
if (!(discountPercent >= 0 && discountPercent <= 100)) return { refusal: QuoteTotalRefusal.DISCOUNT_OUT_OF_RANGE };
|
|
68
|
+
let gross = 0n;
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
if (line.unitPrice.currency !== currency) return { refusal: QuoteTotalRefusal.LINE_CURRENCY_DIFFERS };
|
|
71
|
+
// The schema says `.int().min(1)`, but a total must not trust that every caller went through it.
|
|
72
|
+
if (!Number.isSafeInteger(line.quantity) || line.quantity < 1) return { refusal: QuoteTotalRefusal.QUANTITY_NOT_WHOLE };
|
|
73
|
+
try {
|
|
74
|
+
gross += BigInt(toCurrencyMinorUnitAmountOrThrow(line.unitPrice, 'a quote line price')) * BigInt(line.quantity);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (!(error instanceof MoneyMinorUnitConversionError)) throw error;
|
|
77
|
+
// Each reason is a different fix, so each gets its own refusal.
|
|
78
|
+
switch (error.reason) {
|
|
79
|
+
case MoneyMinorUnitConversionFailure.PRECISION_LOSS:
|
|
80
|
+
return { refusal: QuoteTotalRefusal.PRICE_FINER_THAN_CURRENCY };
|
|
81
|
+
case MoneyMinorUnitConversionFailure.UNSAFE_MAGNITUDE:
|
|
82
|
+
return { refusal: QuoteTotalRefusal.PRICE_TOO_LARGE };
|
|
83
|
+
case MoneyMinorUnitConversionFailure.UNKNOWN_MINOR_UNIT:
|
|
84
|
+
return { refusal: QuoteTotalRefusal.CURRENCY_HAS_NO_MINOR_UNIT };
|
|
85
|
+
}
|
|
86
|
+
// A reason added later must not fall through and silently leave this line out of the total.
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Basis points keep the discount in integers, floored so a discount never exceeds what was declared (10.006 % is
|
|
91
|
+
// 1000 bp); the division then drops the discount's fraction of the smallest unit for the same reason.
|
|
92
|
+
const basisPoints = BigInt(Math.floor(discountPercent * 100));
|
|
93
|
+
const net = gross - (gross * basisPoints) / 10_000n;
|
|
94
|
+
return { total: { amount: net, currency, decimals } };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The same prefix on every operation that can change a line, the discount or the currency: CREATE and UPDATE, and
|
|
99
|
+
* their bulk companions if the resource offers them (a bulk operation is a separate registration). In an application
|
|
100
|
+
* each is its own `quotes.<operation>.<variant>.operation.ts` whose DEFAULT export is the factory, which is what the
|
|
101
|
+
* scanner registers. The schema marks `total` `.excludeFromCreate().excludeFromUpdate()`, so a client can never send
|
|
102
|
+
* it. `authoritativeFields: ['total']` keeps the prefix's value when a caller reaches the service with `total` already
|
|
103
|
+
* in its payload (an MCP tool, another service), where the strict re-parse would otherwise drop it.
|
|
104
|
+
*
|
|
105
|
+
* `transactionalCore: true` makes the prefix read the stored row inside the write's transaction, with its write lock,
|
|
106
|
+
* so two partial UPDATEs arriving together (one editing lines, one the discount) never both commit a total computed from
|
|
107
|
+
* the row before the other: PostgreSQL makes the second wait and re-read, MongoDB aborts it with a write conflict.
|
|
108
|
+
*/
|
|
109
|
+
function quotesTotalCustomImpl(operationIdentifier: CoreResourceOperation.CREATE | CoreResourceOperation.UPDATE): ResourceCustomServiceImplementationFactory {
|
|
110
|
+
return (resourcesRegistryService: ResourcesRegistryBackendService) => {
|
|
111
|
+
const operationPath = {
|
|
112
|
+
resourceIdentifier: Sales_ResourceType.QUOTES,
|
|
113
|
+
operationIdentifier,
|
|
114
|
+
variantType: ResourceOperationVariantType.API_CALL,
|
|
115
|
+
isOperationDefault: true,
|
|
116
|
+
};
|
|
117
|
+
const requestDtoSchema = resourcesRegistryService.getRequestDtoFromPath(operationPath);
|
|
118
|
+
const responseDtoSchema = resourcesRegistryService.getResponseDtoFromPath(operationPath);
|
|
119
|
+
|
|
120
|
+
return createResourceCustomServiceImplementation<typeof requestDtoSchema, typeof responseDtoSchema>({
|
|
121
|
+
operationPath,
|
|
122
|
+
requestDtoSchema,
|
|
123
|
+
responseDtoSchema,
|
|
124
|
+
authoritativeFields: ['total'],
|
|
125
|
+
transactionalCore: true,
|
|
126
|
+
transactionParticipants: {},
|
|
127
|
+
handlers: {
|
|
128
|
+
prefixCoreOperations: async (_id, input, executionContext, _operationPath, utils) => {
|
|
129
|
+
// An UPDATE may carry only the discount, or only the lines: merge with the stored row before computing.
|
|
130
|
+
const request = input as { lines?: QuoteLine[]; discountPercent?: number; currency?: string };
|
|
131
|
+
const stored = (utils.currentObject ?? {}) as { lines?: QuoteLine[]; discountPercent?: number; currency?: string };
|
|
132
|
+
const total = computeQuoteTotal(
|
|
133
|
+
request.lines ?? stored.lines ?? [],
|
|
134
|
+
request.discountPercent ?? stored.discountPercent ?? 0,
|
|
135
|
+
// `currency` is a required field of the quote (`CurrencySchema`), so one of the two is always present.
|
|
136
|
+
(request.currency ?? stored.currency) as string,
|
|
137
|
+
);
|
|
138
|
+
if ('refusal' in total) {
|
|
139
|
+
throw utils.errorBuilder.buildError(ErrorType.VALIDATION, executionContext, {
|
|
140
|
+
customMessageReference: ErrorCustomMessageReference.SERVICE_RESOURCE_VALIDATION_FAILED,
|
|
141
|
+
context: { field: 'total', reason: total.refusal },
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return { ...request, total: total.total } as typeof input;
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const quotesCreateTotal: ResourceCustomServiceImplementationFactory = quotesTotalCustomImpl(CoreResourceOperation.CREATE);
|
|
152
|
+
export const quotesUpdateTotal: ResourceCustomServiceImplementationFactory = quotesTotalCustomImpl(CoreResourceOperation.UPDATE);
|
|
153
|
+
```
|