@baruk/core 0.3.1 → 0.5.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/.baruk-provenance.json +10 -0
- package/CHANGELOG.md +127 -0
- package/dist/audit/repository.d.ts +33 -1
- package/dist/audit/repository.d.ts.map +1 -1
- package/dist/audit/repository.js +41 -7
- package/dist/audit/repository.js.map +1 -1
- package/dist/auth/password-reset.d.ts +30 -1
- package/dist/auth/password-reset.d.ts.map +1 -1
- package/dist/auth/password-reset.js +139 -11
- package/dist/auth/password-reset.js.map +1 -1
- package/dist/auth/service.d.ts +60 -2
- package/dist/auth/service.d.ts.map +1 -1
- package/dist/auth/service.js +121 -11
- package/dist/auth/service.js.map +1 -1
- package/dist/billing/ar-repository.d.ts +374 -0
- package/dist/billing/ar-repository.d.ts.map +1 -0
- package/dist/billing/ar-repository.js +783 -0
- package/dist/billing/ar-repository.js.map +1 -0
- package/dist/billing/auto-generation.d.ts +87 -0
- package/dist/billing/auto-generation.d.ts.map +1 -0
- package/dist/billing/auto-generation.js +181 -0
- package/dist/billing/auto-generation.js.map +1 -0
- package/dist/billing/live-guard.d.ts +64 -0
- package/dist/billing/live-guard.d.ts.map +1 -0
- package/dist/billing/live-guard.js +68 -0
- package/dist/billing/live-guard.js.map +1 -0
- package/dist/billing/payment-means-catalog.d.ts +17 -0
- package/dist/billing/payment-means-catalog.d.ts.map +1 -0
- package/dist/billing/payment-means-catalog.js +21 -0
- package/dist/billing/payment-means-catalog.js.map +1 -0
- package/dist/billing/payment-means.d.ts +38 -0
- package/dist/billing/payment-means.d.ts.map +1 -0
- package/dist/billing/payment-means.js +29 -0
- package/dist/billing/payment-means.js.map +1 -0
- package/dist/billing/payment-rail.d.ts +118 -0
- package/dist/billing/payment-rail.d.ts.map +1 -0
- package/dist/billing/payment-rail.js +295 -0
- package/dist/billing/payment-rail.js.map +1 -0
- package/dist/billing/provider/asaas.d.ts +46 -1
- package/dist/billing/provider/asaas.d.ts.map +1 -1
- package/dist/billing/provider/asaas.js +194 -14
- package/dist/billing/provider/asaas.js.map +1 -1
- package/dist/billing/provider/manual.js +1 -1
- package/dist/billing/provider/manual.js.map +1 -1
- package/dist/billing/provider/types.d.ts +115 -8
- package/dist/billing/provider/types.d.ts.map +1 -1
- package/dist/billing/provider-account.d.ts +127 -0
- package/dist/billing/provider-account.d.ts.map +1 -0
- package/dist/billing/provider-account.js +217 -0
- package/dist/billing/provider-account.js.map +1 -0
- package/dist/billing/provider-onboarding.d.ts +67 -0
- package/dist/billing/provider-onboarding.d.ts.map +1 -0
- package/dist/billing/provider-onboarding.js +234 -0
- package/dist/billing/provider-onboarding.js.map +1 -0
- package/dist/billing/receivable.d.ts +5 -1
- package/dist/billing/receivable.d.ts.map +1 -1
- package/dist/billing/reconcile.d.ts +58 -0
- package/dist/billing/reconcile.d.ts.map +1 -0
- package/dist/billing/reconcile.js +138 -0
- package/dist/billing/reconcile.js.map +1 -0
- package/dist/billing/repository.d.ts +134 -1
- package/dist/billing/repository.d.ts.map +1 -1
- package/dist/billing/repository.js +193 -20
- package/dist/billing/repository.js.map +1 -1
- package/dist/cjs/audit/repository.js +41 -7
- package/dist/cjs/audit/repository.js.map +1 -1
- package/dist/cjs/auth/password-reset.js +141 -11
- package/dist/cjs/auth/password-reset.js.map +1 -1
- package/dist/cjs/auth/service.js +121 -10
- package/dist/cjs/auth/service.js.map +1 -1
- package/dist/cjs/billing/ar-repository.js +804 -0
- package/dist/cjs/billing/ar-repository.js.map +1 -0
- package/dist/cjs/billing/auto-generation.js +186 -0
- package/dist/cjs/billing/auto-generation.js.map +1 -0
- package/dist/cjs/billing/live-guard.js +72 -0
- package/dist/cjs/billing/live-guard.js.map +1 -0
- package/dist/cjs/billing/payment-means-catalog.js +25 -0
- package/dist/cjs/billing/payment-means-catalog.js.map +1 -0
- package/dist/cjs/billing/payment-means.js +33 -0
- package/dist/cjs/billing/payment-means.js.map +1 -0
- package/dist/cjs/billing/payment-rail.js +301 -0
- package/dist/cjs/billing/payment-rail.js.map +1 -0
- package/dist/cjs/billing/provider/asaas.js +194 -14
- package/dist/cjs/billing/provider/asaas.js.map +1 -1
- package/dist/cjs/billing/provider/manual.js +1 -1
- package/dist/cjs/billing/provider/manual.js.map +1 -1
- package/dist/cjs/billing/provider-account.js +229 -0
- package/dist/cjs/billing/provider-account.js.map +1 -0
- package/dist/cjs/billing/provider-onboarding.js +239 -0
- package/dist/cjs/billing/provider-onboarding.js.map +1 -0
- package/dist/cjs/billing/reconcile.js +143 -0
- package/dist/cjs/billing/reconcile.js.map +1 -0
- package/dist/cjs/billing/repository.js +197 -19
- package/dist/cjs/billing/repository.js.map +1 -1
- package/dist/cjs/clients/ibge.js +103 -0
- package/dist/cjs/clients/ibge.js.map +1 -0
- package/dist/cjs/clients/repository.js +276 -23
- package/dist/cjs/clients/repository.js.map +1 -1
- package/dist/cjs/collection/branding.js +330 -0
- package/dist/cjs/collection/branding.js.map +1 -0
- package/dist/cjs/collection/channel-accounts.js +137 -0
- package/dist/cjs/collection/channel-accounts.js.map +1 -0
- package/dist/cjs/collection/channel.js +17 -0
- package/dist/cjs/collection/channel.js.map +1 -0
- package/dist/cjs/collection/clearance-store.js +74 -0
- package/dist/cjs/collection/clearance-store.js.map +1 -0
- package/dist/cjs/collection/communication-bridge.js +140 -0
- package/dist/cjs/collection/communication-bridge.js.map +1 -0
- package/dist/cjs/collection/communication-runtime.js +256 -0
- package/dist/cjs/collection/communication-runtime.js.map +1 -0
- package/dist/cjs/collection/consent-repository.js +84 -0
- package/dist/cjs/collection/consent-repository.js.map +1 -0
- package/dist/cjs/collection/copy.js +125 -0
- package/dist/cjs/collection/copy.js.map +1 -0
- package/dist/cjs/collection/delivery-callback.js +151 -0
- package/dist/cjs/collection/delivery-callback.js.map +1 -0
- package/dist/cjs/collection/email-layout.js +252 -0
- package/dist/cjs/collection/email-layout.js.map +1 -0
- package/dist/cjs/collection/engine.js +434 -0
- package/dist/cjs/collection/engine.js.map +1 -0
- package/dist/cjs/collection/format.js +76 -0
- package/dist/cjs/collection/format.js.map +1 -0
- package/dist/cjs/collection/payment-block.js +3 -0
- package/dist/cjs/collection/payment-block.js.map +1 -0
- package/dist/cjs/collection/policy.js +175 -0
- package/dist/cjs/collection/policy.js.map +1 -0
- package/dist/cjs/collection/repository.js +260 -0
- package/dist/cjs/collection/repository.js.map +1 -0
- package/dist/cjs/collection/subject.js +104 -0
- package/dist/cjs/collection/subject.js.map +1 -0
- package/dist/cjs/collection/template-catalog.js +165 -0
- package/dist/cjs/collection/template-catalog.js.map +1 -0
- package/dist/cjs/collection/template.js +78 -0
- package/dist/cjs/collection/template.js.map +1 -0
- package/dist/cjs/communication/adapters/email.js +132 -0
- package/dist/cjs/communication/adapters/email.js.map +1 -0
- package/dist/cjs/communication/adapters/sms.js +127 -0
- package/dist/cjs/communication/adapters/sms.js.map +1 -0
- package/dist/cjs/communication/adapters/whatsapp-language.js +39 -0
- package/dist/cjs/communication/adapters/whatsapp-language.js.map +1 -0
- package/dist/cjs/communication/adapters/whatsapp-templates.js +100 -0
- package/dist/cjs/communication/adapters/whatsapp-templates.js.map +1 -0
- package/dist/cjs/communication/adapters/whatsapp.js +213 -0
- package/dist/cjs/communication/adapters/whatsapp.js.map +1 -0
- package/dist/cjs/communication/audit.js +61 -0
- package/dist/cjs/communication/audit.js.map +1 -0
- package/dist/cjs/communication/capabilities.js +76 -0
- package/dist/cjs/communication/capabilities.js.map +1 -0
- package/dist/cjs/communication/channel.js +53 -0
- package/dist/cjs/communication/channel.js.map +1 -0
- package/dist/cjs/communication/claim.js +228 -0
- package/dist/cjs/communication/claim.js.map +1 -0
- package/dist/cjs/communication/clearance.js +18 -0
- package/dist/cjs/communication/clearance.js.map +1 -0
- package/dist/cjs/communication/consent.js +43 -0
- package/dist/cjs/communication/consent.js.map +1 -0
- package/dist/cjs/communication/context.js +45 -0
- package/dist/cjs/communication/context.js.map +1 -0
- package/dist/cjs/communication/credentials.js +121 -0
- package/dist/cjs/communication/credentials.js.map +1 -0
- package/dist/cjs/communication/dry-run-scenario.js +166 -0
- package/dist/cjs/communication/dry-run-scenario.js.map +1 -0
- package/dist/cjs/communication/dry-run.js +97 -0
- package/dist/cjs/communication/dry-run.js.map +1 -0
- package/dist/cjs/communication/engine.js +495 -0
- package/dist/cjs/communication/engine.js.map +1 -0
- package/dist/cjs/communication/graph.js +50 -0
- package/dist/cjs/communication/graph.js.map +1 -0
- package/dist/cjs/communication/idempotency.js +26 -0
- package/dist/cjs/communication/idempotency.js.map +1 -0
- package/dist/cjs/communication/identity.js +110 -0
- package/dist/cjs/communication/identity.js.map +1 -0
- package/dist/cjs/communication/index.js +135 -0
- package/dist/cjs/communication/index.js.map +1 -0
- package/dist/cjs/communication/onboarding.js +297 -0
- package/dist/cjs/communication/onboarding.js.map +1 -0
- package/dist/cjs/communication/policy.js +16 -0
- package/dist/cjs/communication/policy.js.map +1 -0
- package/dist/cjs/communication/routing.js +77 -0
- package/dist/cjs/communication/routing.js.map +1 -0
- package/dist/cjs/communication/sender-profile.js +128 -0
- package/dist/cjs/communication/sender-profile.js.map +1 -0
- package/dist/cjs/communication/status.js +86 -0
- package/dist/cjs/communication/status.js.map +1 -0
- package/dist/cjs/communication/stores/onboarding.js +135 -0
- package/dist/cjs/communication/stores/onboarding.js.map +1 -0
- package/dist/cjs/communication/stores/postgres.js +458 -0
- package/dist/cjs/communication/stores/postgres.js.map +1 -0
- package/dist/cjs/communication/stores/routing.js +334 -0
- package/dist/cjs/communication/stores/routing.js.map +1 -0
- package/dist/cjs/communication/stores/secrets.js +126 -0
- package/dist/cjs/communication/stores/secrets.js.map +1 -0
- package/dist/cjs/communication/template-provider.js +22 -0
- package/dist/cjs/communication/template-provider.js.map +1 -0
- package/dist/cjs/communication/template.js +63 -0
- package/dist/cjs/communication/template.js.map +1 -0
- package/dist/cjs/communication/webhook-subscription.js +258 -0
- package/dist/cjs/communication/webhook-subscription.js.map +1 -0
- package/dist/cjs/communication/webhook.js +292 -0
- package/dist/cjs/communication/webhook.js.map +1 -0
- package/dist/cjs/competence/business-days.js +155 -0
- package/dist/cjs/competence/business-days.js.map +1 -0
- package/dist/cjs/competence/catalog-validation.js +174 -0
- package/dist/cjs/competence/catalog-validation.js.map +1 -0
- package/dist/cjs/competence/obligation-preview.js +190 -0
- package/dist/cjs/competence/obligation-preview.js.map +1 -0
- package/dist/cjs/competence/repository.js +622 -0
- package/dist/cjs/competence/repository.js.map +1 -0
- package/dist/cjs/contacts/phone.js +192 -0
- package/dist/cjs/contacts/phone.js.map +1 -0
- package/dist/cjs/dashboard/pilot-panel.js +90 -0
- package/dist/cjs/dashboard/pilot-panel.js.map +1 -0
- package/dist/cjs/dashboard/repository.js +11 -1
- package/dist/cjs/dashboard/repository.js.map +1 -1
- package/dist/cjs/db/client.js +17 -11
- package/dist/cjs/db/client.js.map +1 -1
- package/dist/cjs/db/provision-e2e-identity.js +111 -0
- package/dist/cjs/db/provision-e2e-identity.js.map +1 -0
- package/dist/cjs/db/seed-catalog.js +48 -0
- package/dist/cjs/db/seed-catalog.js.map +1 -0
- package/dist/cjs/db/seed.js +15 -7
- package/dist/cjs/db/seed.js.map +1 -1
- package/dist/cjs/documents/repository.js +244 -0
- package/dist/cjs/documents/repository.js.map +1 -0
- package/dist/cjs/documents/requests.js +136 -0
- package/dist/cjs/documents/requests.js.map +1 -0
- package/dist/cjs/fiscal/applicability.js +164 -0
- package/dist/cjs/fiscal/applicability.js.map +1 -0
- package/dist/cjs/fiscal/conditions.js +198 -0
- package/dist/cjs/fiscal/conditions.js.map +1 -0
- package/dist/cjs/fiscal/contracts/nfse-adn-contract.js +390 -0
- package/dist/cjs/fiscal/contracts/nfse-adn-contract.js.map +1 -0
- package/dist/cjs/fiscal/contracts/nfse-adn-endpoint.js +108 -0
- package/dist/cjs/fiscal/contracts/nfse-adn-endpoint.js.map +1 -0
- package/dist/cjs/fiscal/contracts/nfse-adn-envelope.js +220 -0
- package/dist/cjs/fiscal/contracts/nfse-adn-envelope.js.map +1 -0
- package/dist/cjs/fiscal/coverage/model.js +127 -0
- package/dist/cjs/fiscal/coverage/model.js.map +1 -0
- package/dist/cjs/fiscal/coverage/requests.js +99 -0
- package/dist/cjs/fiscal/coverage/requests.js.map +1 -0
- package/dist/cjs/fiscal/credentials/material.js +168 -0
- package/dist/cjs/fiscal/credentials/material.js.map +1 -0
- package/dist/cjs/fiscal/credentials/readiness.js +163 -0
- package/dist/cjs/fiscal/credentials/readiness.js.map +1 -0
- package/dist/cjs/fiscal/eligibility.js +199 -0
- package/dist/cjs/fiscal/eligibility.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/__fixtures__/nfse.js +128 -0
- package/dist/cjs/fiscal/ingestion/__fixtures__/nfse.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/adn-transport.js +229 -0
- package/dist/cjs/fiscal/ingestion/adn-transport.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/direction.js +36 -0
- package/dist/cjs/fiscal/ingestion/direction.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/nfse-adn.js +228 -0
- package/dist/cjs/fiscal/ingestion/nfse-adn.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/pipeline.js +704 -0
- package/dist/cjs/fiscal/ingestion/pipeline.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/provider.js +51 -0
- package/dist/cjs/fiscal/ingestion/provider.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/repository.js +132 -0
- package/dist/cjs/fiscal/ingestion/repository.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/synthetic-provider.js +103 -0
- package/dist/cjs/fiscal/ingestion/synthetic-provider.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/synthetic-transport-types.js +13 -0
- package/dist/cjs/fiscal/ingestion/synthetic-transport-types.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/synthetic-transport.js +61 -0
- package/dist/cjs/fiscal/ingestion/synthetic-transport.js.map +1 -0
- package/dist/cjs/fiscal/ingestion/xml-reader.js +121 -0
- package/dist/cjs/fiscal/ingestion/xml-reader.js.map +1 -0
- package/dist/cjs/fiscal/repository.js +470 -0
- package/dist/cjs/fiscal/repository.js.map +1 -0
- package/dist/cjs/fiscal/sync/circuit.js +124 -0
- package/dist/cjs/fiscal/sync/circuit.js.map +1 -0
- package/dist/cjs/fiscal/sync/intervention.js +140 -0
- package/dist/cjs/fiscal/sync/intervention.js.map +1 -0
- package/dist/cjs/fiscal/sync/lease.js +146 -0
- package/dist/cjs/fiscal/sync/lease.js.map +1 -0
- package/dist/cjs/fiscal/sync/observability.js +244 -0
- package/dist/cjs/fiscal/sync/observability.js.map +1 -0
- package/dist/cjs/fiscal/sync/orchestrator.js +490 -0
- package/dist/cjs/fiscal/sync/orchestrator.js.map +1 -0
- package/dist/cjs/fiscal/sync/policy.js +143 -0
- package/dist/cjs/fiscal/sync/policy.js.map +1 -0
- package/dist/cjs/fiscal/sync/reprocess.js +241 -0
- package/dist/cjs/fiscal/sync/reprocess.js.map +1 -0
- package/dist/cjs/fiscal/sync/retry.js +183 -0
- package/dist/cjs/fiscal/sync/retry.js.map +1 -0
- package/dist/cjs/fiscal/sync/secret-boundary.js +123 -0
- package/dist/cjs/fiscal/sync/secret-boundary.js.map +1 -0
- package/dist/cjs/fiscal/transport/https.js +309 -0
- package/dist/cjs/fiscal/transport/https.js.map +1 -0
- package/dist/cjs/fiscal/transport/synthetic-tls.js +328 -0
- package/dist/cjs/fiscal/transport/synthetic-tls.js.map +1 -0
- package/dist/cjs/fiscal/transport/types.js +93 -0
- package/dist/cjs/fiscal/transport/types.js.map +1 -0
- package/dist/cjs/import/br-documents.js +85 -0
- package/dist/cjs/import/br-documents.js.map +1 -0
- package/dist/cjs/import/clients-import.js +347 -40
- package/dist/cjs/import/clients-import.js.map +1 -1
- package/dist/cjs/index.js +711 -39
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/legal/documents.js +224 -17
- package/dist/cjs/legal/documents.js.map +1 -1
- package/dist/cjs/legal/index.js +3 -1
- package/dist/cjs/legal/index.js.map +1 -1
- package/dist/cjs/legal/types.js +1 -0
- package/dist/cjs/legal/types.js.map +1 -1
- package/dist/cjs/mail/auth-templates.js +29 -0
- package/dist/cjs/mail/auth-templates.js.map +1 -0
- package/dist/cjs/mail/dedup-store.js +12 -51
- package/dist/cjs/mail/dedup-store.js.map +1 -1
- package/dist/cjs/mail/index.js +16 -4
- package/dist/cjs/mail/index.js.map +1 -1
- package/dist/cjs/mail/provider.js +12 -247
- package/dist/cjs/mail/provider.js.map +1 -1
- package/dist/cjs/mail/resend.js +14 -18
- package/dist/cjs/mail/resend.js.map +1 -1
- package/dist/cjs/mail/sender-resolver.js +12 -11
- package/dist/cjs/mail/sender-resolver.js.map +1 -1
- package/dist/cjs/mail/template-renderer.js +11 -16
- package/dist/cjs/mail/template-renderer.js.map +1 -1
- package/dist/cjs/mail/transactional-outbound.js +117 -0
- package/dist/cjs/mail/transactional-outbound.js.map +1 -0
- package/dist/cjs/mail/types.js +8 -35
- package/dist/cjs/mail/types.js.map +1 -1
- package/dist/cjs/onboarding/persistence.js +4 -4
- package/dist/cjs/onboarding/persistence.js.map +1 -1
- package/dist/cjs/pilot/go-live-checklist.js +212 -0
- package/dist/cjs/pilot/go-live-checklist.js.map +1 -0
- package/dist/cjs/pilot/milestone.js +79 -0
- package/dist/cjs/pilot/milestone.js.map +1 -0
- package/dist/cjs/platform/capabilities.js +144 -0
- package/dist/cjs/platform/capabilities.js.map +1 -0
- package/dist/cjs/platform/job-contract.js +411 -0
- package/dist/cjs/platform/job-contract.js.map +1 -0
- package/dist/cjs/portal/provisioning.js +144 -0
- package/dist/cjs/portal/provisioning.js.map +1 -0
- package/dist/cjs/pricing-engine/canonical.js +42 -0
- package/dist/cjs/pricing-engine/canonical.js.map +1 -0
- package/dist/cjs/pricing-engine/errors.js +6 -1
- package/dist/cjs/pricing-engine/errors.js.map +1 -1
- package/dist/cjs/pricing-engine/index.js +12 -1
- package/dist/cjs/pricing-engine/index.js.map +1 -1
- package/dist/cjs/pricing-engine/pipeline.js +200 -26
- package/dist/cjs/pricing-engine/pipeline.js.map +1 -1
- package/dist/cjs/pricing-engine/shadow-adapter.js +79 -0
- package/dist/cjs/pricing-engine/shadow-adapter.js.map +1 -0
- package/dist/cjs/pricing-engine/shadow-diff.js +55 -0
- package/dist/cjs/pricing-engine/shadow-diff.js.map +1 -0
- package/dist/cjs/pricing-engine/shadow-facade.js +85 -0
- package/dist/cjs/pricing-engine/shadow-facade.js.map +1 -0
- package/dist/cjs/pricing-engine/shadow-legacy-types.js +19 -0
- package/dist/cjs/pricing-engine/shadow-legacy-types.js.map +1 -0
- package/dist/cjs/pricing-engine/shadow-metrics.js +34 -0
- package/dist/cjs/pricing-engine/shadow-metrics.js.map +1 -0
- package/dist/cjs/pricing-engine/shadow-normalizer.js +42 -0
- package/dist/cjs/pricing-engine/shadow-normalizer.js.map +1 -0
- package/dist/cjs/rbac/authorize.js +28 -0
- package/dist/cjs/rbac/authorize.js.map +1 -1
- package/dist/cjs/rbac/catalog.js +101 -1
- package/dist/cjs/rbac/catalog.js.map +1 -1
- package/dist/cjs/rbac/workload-provisioning.js +160 -0
- package/dist/cjs/rbac/workload-provisioning.js.map +1 -0
- package/dist/cjs/rbac/workload.js +191 -0
- package/dist/cjs/rbac/workload.js.map +1 -0
- package/dist/cjs/storage/checksum.js +15 -0
- package/dist/cjs/storage/checksum.js.map +1 -0
- package/dist/cjs/storage/key.js +72 -0
- package/dist/cjs/storage/key.js.map +1 -0
- package/dist/cjs/storage/local.js +100 -0
- package/dist/cjs/storage/local.js.map +1 -0
- package/dist/cjs/storage/r2.js +181 -0
- package/dist/cjs/storage/r2.js.map +1 -0
- package/dist/cjs/storage/registry.js +41 -0
- package/dist/cjs/storage/registry.js.map +1 -0
- package/dist/cjs/storage/types.js +50 -0
- package/dist/cjs/storage/types.js.map +1 -0
- package/dist/cjs/subscription-billing/index.js +2 -1
- package/dist/cjs/subscription-billing/index.js.map +1 -1
- package/dist/cjs/subscription-billing/provider/asaas.js +32 -7
- package/dist/cjs/subscription-billing/provider/asaas.js.map +1 -1
- package/dist/cjs/subscription-billing/provider/disabled.js +8 -0
- package/dist/cjs/subscription-billing/provider/disabled.js.map +1 -1
- package/dist/cjs/subscription-billing/provider/registry.js +17 -0
- package/dist/cjs/subscription-billing/provider/registry.js.map +1 -1
- package/dist/cjs/subscription-billing/service.js +208 -83
- package/dist/cjs/subscription-billing/service.js.map +1 -1
- package/dist/cjs/subscription-billing/types.js.map +1 -1
- package/dist/cjs/tenancy/features.js +131 -0
- package/dist/cjs/tenancy/features.js.map +1 -0
- package/dist/cjs/tenancy/provisioning.js +32 -8
- package/dist/cjs/tenancy/provisioning.js.map +1 -1
- package/dist/cjs/tenancy/settings.js +224 -0
- package/dist/cjs/tenancy/settings.js.map +1 -0
- package/dist/cjs/users/repository.js +143 -3
- package/dist/cjs/users/repository.js.map +1 -1
- package/dist/cjs/vault/repository.js +81 -0
- package/dist/cjs/vault/repository.js.map +1 -1
- package/dist/clients/ibge.d.ts +17 -0
- package/dist/clients/ibge.d.ts.map +1 -0
- package/dist/clients/ibge.js +98 -0
- package/dist/clients/ibge.js.map +1 -0
- package/dist/clients/repository.d.ts +196 -0
- package/dist/clients/repository.d.ts.map +1 -1
- package/dist/clients/repository.js +270 -24
- package/dist/clients/repository.js.map +1 -1
- package/dist/collection/branding.d.ts +137 -0
- package/dist/collection/branding.d.ts.map +1 -0
- package/dist/collection/branding.js +322 -0
- package/dist/collection/branding.js.map +1 -0
- package/dist/collection/channel-accounts.d.ts +57 -0
- package/dist/collection/channel-accounts.d.ts.map +1 -0
- package/dist/collection/channel-accounts.js +133 -0
- package/dist/collection/channel-accounts.js.map +1 -0
- package/dist/collection/channel.d.ts +24 -0
- package/dist/collection/channel.d.ts.map +1 -0
- package/dist/collection/channel.js +16 -0
- package/dist/collection/channel.js.map +1 -0
- package/dist/collection/clearance-store.d.ts +39 -0
- package/dist/collection/clearance-store.d.ts.map +1 -0
- package/dist/collection/clearance-store.js +69 -0
- package/dist/collection/clearance-store.js.map +1 -0
- package/dist/collection/communication-bridge.d.ts +66 -0
- package/dist/collection/communication-bridge.d.ts.map +1 -0
- package/dist/collection/communication-bridge.js +134 -0
- package/dist/collection/communication-bridge.js.map +1 -0
- package/dist/collection/communication-runtime.d.ts +132 -0
- package/dist/collection/communication-runtime.d.ts.map +1 -0
- package/dist/collection/communication-runtime.js +249 -0
- package/dist/collection/communication-runtime.js.map +1 -0
- package/dist/collection/consent-repository.d.ts +32 -0
- package/dist/collection/consent-repository.d.ts.map +1 -0
- package/dist/collection/consent-repository.js +79 -0
- package/dist/collection/consent-repository.js.map +1 -0
- package/dist/collection/copy.d.ts +50 -0
- package/dist/collection/copy.d.ts.map +1 -0
- package/dist/collection/copy.js +122 -0
- package/dist/collection/copy.js.map +1 -0
- package/dist/collection/delivery-callback.d.ts +49 -0
- package/dist/collection/delivery-callback.d.ts.map +1 -0
- package/dist/collection/delivery-callback.js +147 -0
- package/dist/collection/delivery-callback.js.map +1 -0
- package/dist/collection/email-layout.d.ts +45 -0
- package/dist/collection/email-layout.d.ts.map +1 -0
- package/dist/collection/email-layout.js +247 -0
- package/dist/collection/email-layout.js.map +1 -0
- package/dist/collection/engine.d.ts +200 -0
- package/dist/collection/engine.d.ts.map +1 -0
- package/dist/collection/engine.js +427 -0
- package/dist/collection/engine.js.map +1 -0
- package/dist/collection/format.d.ts +32 -0
- package/dist/collection/format.d.ts.map +1 -0
- package/dist/collection/format.js +70 -0
- package/dist/collection/format.js.map +1 -0
- package/dist/collection/payment-block.d.ts +24 -0
- package/dist/collection/payment-block.d.ts.map +1 -0
- package/dist/collection/payment-block.js +2 -0
- package/dist/collection/payment-block.js.map +1 -0
- package/dist/collection/policy.d.ts +78 -0
- package/dist/collection/policy.d.ts.map +1 -0
- package/dist/collection/policy.js +168 -0
- package/dist/collection/policy.js.map +1 -0
- package/dist/collection/repository.d.ts +129 -0
- package/dist/collection/repository.d.ts.map +1 -0
- package/dist/collection/repository.js +246 -0
- package/dist/collection/repository.js.map +1 -0
- package/dist/collection/subject.d.ts +66 -0
- package/dist/collection/subject.d.ts.map +1 -0
- package/dist/collection/subject.js +99 -0
- package/dist/collection/subject.js.map +1 -0
- package/dist/collection/template-catalog.d.ts +16 -0
- package/dist/collection/template-catalog.d.ts.map +1 -0
- package/dist/collection/template-catalog.js +162 -0
- package/dist/collection/template-catalog.js.map +1 -0
- package/dist/collection/template.d.ts +37 -0
- package/dist/collection/template.d.ts.map +1 -0
- package/dist/collection/template.js +73 -0
- package/dist/collection/template.js.map +1 -0
- package/dist/communication/adapters/email.d.ts +28 -0
- package/dist/communication/adapters/email.d.ts.map +1 -0
- package/dist/communication/adapters/email.js +129 -0
- package/dist/communication/adapters/email.js.map +1 -0
- package/dist/communication/adapters/sms.d.ts +95 -0
- package/dist/communication/adapters/sms.d.ts.map +1 -0
- package/dist/communication/adapters/sms.js +121 -0
- package/dist/communication/adapters/sms.js.map +1 -0
- package/dist/communication/adapters/whatsapp-language.d.ts +34 -0
- package/dist/communication/adapters/whatsapp-language.d.ts.map +1 -0
- package/dist/communication/adapters/whatsapp-language.js +36 -0
- package/dist/communication/adapters/whatsapp-language.js.map +1 -0
- package/dist/communication/adapters/whatsapp-templates.d.ts +18 -0
- package/dist/communication/adapters/whatsapp-templates.d.ts.map +1 -0
- package/dist/communication/adapters/whatsapp-templates.js +97 -0
- package/dist/communication/adapters/whatsapp-templates.js.map +1 -0
- package/dist/communication/adapters/whatsapp.d.ts +29 -0
- package/dist/communication/adapters/whatsapp.d.ts.map +1 -0
- package/dist/communication/adapters/whatsapp.js +210 -0
- package/dist/communication/adapters/whatsapp.js.map +1 -0
- package/dist/communication/audit.d.ts +105 -0
- package/dist/communication/audit.d.ts.map +1 -0
- package/dist/communication/audit.js +56 -0
- package/dist/communication/audit.js.map +1 -0
- package/dist/communication/capabilities.d.ts +88 -0
- package/dist/communication/capabilities.d.ts.map +1 -0
- package/dist/communication/capabilities.js +72 -0
- package/dist/communication/capabilities.js.map +1 -0
- package/dist/communication/channel.d.ts +125 -0
- package/dist/communication/channel.d.ts.map +1 -0
- package/dist/communication/channel.js +47 -0
- package/dist/communication/channel.js.map +1 -0
- package/dist/communication/claim.d.ts +368 -0
- package/dist/communication/claim.d.ts.map +1 -0
- package/dist/communication/claim.js +224 -0
- package/dist/communication/claim.js.map +1 -0
- package/dist/communication/clearance.d.ts +53 -0
- package/dist/communication/clearance.d.ts.map +1 -0
- package/dist/communication/clearance.js +15 -0
- package/dist/communication/clearance.js.map +1 -0
- package/dist/communication/consent.d.ts +65 -0
- package/dist/communication/consent.d.ts.map +1 -0
- package/dist/communication/consent.js +40 -0
- package/dist/communication/consent.js.map +1 -0
- package/dist/communication/context.d.ts +48 -0
- package/dist/communication/context.d.ts.map +1 -0
- package/dist/communication/context.js +41 -0
- package/dist/communication/context.js.map +1 -0
- package/dist/communication/credentials.d.ts +74 -0
- package/dist/communication/credentials.d.ts.map +1 -0
- package/dist/communication/credentials.js +115 -0
- package/dist/communication/credentials.js.map +1 -0
- package/dist/communication/dry-run-scenario.d.ts +37 -0
- package/dist/communication/dry-run-scenario.d.ts.map +1 -0
- package/dist/communication/dry-run-scenario.js +163 -0
- package/dist/communication/dry-run-scenario.js.map +1 -0
- package/dist/communication/dry-run.d.ts +40 -0
- package/dist/communication/dry-run.d.ts.map +1 -0
- package/dist/communication/dry-run.js +92 -0
- package/dist/communication/dry-run.js.map +1 -0
- package/dist/communication/engine.d.ts +163 -0
- package/dist/communication/engine.d.ts.map +1 -0
- package/dist/communication/engine.js +492 -0
- package/dist/communication/engine.js.map +1 -0
- package/dist/communication/graph.d.ts +38 -0
- package/dist/communication/graph.d.ts.map +1 -0
- package/dist/communication/graph.js +45 -0
- package/dist/communication/graph.js.map +1 -0
- package/dist/communication/idempotency.d.ts +33 -0
- package/dist/communication/idempotency.d.ts.map +1 -0
- package/dist/communication/idempotency.js +23 -0
- package/dist/communication/idempotency.js.map +1 -0
- package/dist/communication/identity.d.ts +127 -0
- package/dist/communication/identity.d.ts.map +1 -0
- package/dist/communication/identity.js +105 -0
- package/dist/communication/identity.js.map +1 -0
- package/dist/communication/index.d.ts +66 -0
- package/dist/communication/index.d.ts.map +1 -0
- package/dist/communication/index.js +42 -0
- package/dist/communication/index.js.map +1 -0
- package/dist/communication/onboarding.d.ts +223 -0
- package/dist/communication/onboarding.d.ts.map +1 -0
- package/dist/communication/onboarding.js +287 -0
- package/dist/communication/onboarding.js.map +1 -0
- package/dist/communication/policy.d.ts +115 -0
- package/dist/communication/policy.d.ts.map +1 -0
- package/dist/communication/policy.js +13 -0
- package/dist/communication/policy.js.map +1 -0
- package/dist/communication/routing.d.ts +99 -0
- package/dist/communication/routing.d.ts.map +1 -0
- package/dist/communication/routing.js +73 -0
- package/dist/communication/routing.js.map +1 -0
- package/dist/communication/sender-profile.d.ts +100 -0
- package/dist/communication/sender-profile.d.ts.map +1 -0
- package/dist/communication/sender-profile.js +123 -0
- package/dist/communication/sender-profile.js.map +1 -0
- package/dist/communication/status.d.ts +48 -0
- package/dist/communication/status.d.ts.map +1 -0
- package/dist/communication/status.js +79 -0
- package/dist/communication/status.js.map +1 -0
- package/dist/communication/stores/onboarding.d.ts +88 -0
- package/dist/communication/stores/onboarding.d.ts.map +1 -0
- package/dist/communication/stores/onboarding.js +127 -0
- package/dist/communication/stores/onboarding.js.map +1 -0
- package/dist/communication/stores/postgres.d.ts +81 -0
- package/dist/communication/stores/postgres.d.ts.map +1 -0
- package/dist/communication/stores/postgres.js +453 -0
- package/dist/communication/stores/postgres.js.map +1 -0
- package/dist/communication/stores/routing.d.ts +169 -0
- package/dist/communication/stores/routing.d.ts.map +1 -0
- package/dist/communication/stores/routing.js +324 -0
- package/dist/communication/stores/routing.js.map +1 -0
- package/dist/communication/stores/secrets.d.ts +89 -0
- package/dist/communication/stores/secrets.d.ts.map +1 -0
- package/dist/communication/stores/secrets.js +122 -0
- package/dist/communication/stores/secrets.js.map +1 -0
- package/dist/communication/template-provider.d.ts +85 -0
- package/dist/communication/template-provider.d.ts.map +1 -0
- package/dist/communication/template-provider.js +21 -0
- package/dist/communication/template-provider.js.map +1 -0
- package/dist/communication/template.d.ts +87 -0
- package/dist/communication/template.d.ts.map +1 -0
- package/dist/communication/template.js +59 -0
- package/dist/communication/template.js.map +1 -0
- package/dist/communication/webhook-subscription.d.ts +156 -0
- package/dist/communication/webhook-subscription.d.ts.map +1 -0
- package/dist/communication/webhook-subscription.js +252 -0
- package/dist/communication/webhook-subscription.js.map +1 -0
- package/dist/communication/webhook.d.ts +121 -0
- package/dist/communication/webhook.d.ts.map +1 -0
- package/dist/communication/webhook.js +283 -0
- package/dist/communication/webhook.js.map +1 -0
- package/dist/competence/business-days.d.ts +51 -0
- package/dist/competence/business-days.d.ts.map +1 -0
- package/dist/competence/business-days.js +145 -0
- package/dist/competence/business-days.js.map +1 -0
- package/dist/competence/catalog-validation.d.ts +86 -0
- package/dist/competence/catalog-validation.d.ts.map +1 -0
- package/dist/competence/catalog-validation.js +168 -0
- package/dist/competence/catalog-validation.js.map +1 -0
- package/dist/competence/obligation-preview.d.ts +103 -0
- package/dist/competence/obligation-preview.d.ts.map +1 -0
- package/dist/competence/obligation-preview.js +184 -0
- package/dist/competence/obligation-preview.js.map +1 -0
- package/dist/competence/repository.d.ts +285 -0
- package/dist/competence/repository.d.ts.map +1 -0
- package/dist/competence/repository.js +602 -0
- package/dist/competence/repository.js.map +1 -0
- package/dist/contacts/phone.d.ts +70 -0
- package/dist/contacts/phone.d.ts.map +1 -0
- package/dist/contacts/phone.js +186 -0
- package/dist/contacts/phone.js.map +1 -0
- package/dist/dashboard/pilot-panel.d.ts +100 -0
- package/dist/dashboard/pilot-panel.d.ts.map +1 -0
- package/dist/dashboard/pilot-panel.js +87 -0
- package/dist/dashboard/pilot-panel.js.map +1 -0
- package/dist/dashboard/repository.d.ts.map +1 -1
- package/dist/dashboard/repository.js +11 -1
- package/dist/dashboard/repository.js.map +1 -1
- package/dist/db/client.d.ts +45 -0
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +16 -11
- package/dist/db/client.js.map +1 -1
- package/dist/db/migrate.d.ts +36 -1
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +208 -35
- package/dist/db/migrate.js.map +1 -1
- package/dist/db/provision-e2e-identity.d.ts +2 -0
- package/dist/db/provision-e2e-identity.d.ts.map +1 -0
- package/dist/db/provision-e2e-identity.js +109 -0
- package/dist/db/provision-e2e-identity.js.map +1 -0
- package/dist/db/seed-catalog.d.ts +18 -0
- package/dist/db/seed-catalog.d.ts.map +1 -0
- package/dist/db/seed-catalog.js +45 -0
- package/dist/db/seed-catalog.js.map +1 -0
- package/dist/db/seed.js +16 -8
- package/dist/db/seed.js.map +1 -1
- package/dist/documents/repository.d.ts +97 -0
- package/dist/documents/repository.d.ts.map +1 -0
- package/dist/documents/repository.js +236 -0
- package/dist/documents/repository.js.map +1 -0
- package/dist/documents/requests.d.ts +73 -0
- package/dist/documents/requests.d.ts.map +1 -0
- package/dist/documents/requests.js +127 -0
- package/dist/documents/requests.js.map +1 -0
- package/dist/fiscal/applicability.d.ts +73 -0
- package/dist/fiscal/applicability.d.ts.map +1 -0
- package/dist/fiscal/applicability.js +160 -0
- package/dist/fiscal/applicability.js.map +1 -0
- package/dist/fiscal/conditions.d.ts +99 -0
- package/dist/fiscal/conditions.d.ts.map +1 -0
- package/dist/fiscal/conditions.js +190 -0
- package/dist/fiscal/conditions.js.map +1 -0
- package/dist/fiscal/contracts/nfse-adn-contract.d.ts +315 -0
- package/dist/fiscal/contracts/nfse-adn-contract.d.ts.map +1 -0
- package/dist/fiscal/contracts/nfse-adn-contract.js +386 -0
- package/dist/fiscal/contracts/nfse-adn-contract.js.map +1 -0
- package/dist/fiscal/contracts/nfse-adn-endpoint.d.ts +13 -0
- package/dist/fiscal/contracts/nfse-adn-endpoint.d.ts.map +1 -0
- package/dist/fiscal/contracts/nfse-adn-endpoint.js +103 -0
- package/dist/fiscal/contracts/nfse-adn-endpoint.js.map +1 -0
- package/dist/fiscal/contracts/nfse-adn-envelope.d.ts +77 -0
- package/dist/fiscal/contracts/nfse-adn-envelope.d.ts.map +1 -0
- package/dist/fiscal/contracts/nfse-adn-envelope.js +215 -0
- package/dist/fiscal/contracts/nfse-adn-envelope.js.map +1 -0
- package/dist/fiscal/coverage/model.d.ts +86 -0
- package/dist/fiscal/coverage/model.d.ts.map +1 -0
- package/dist/fiscal/coverage/model.js +120 -0
- package/dist/fiscal/coverage/model.js.map +1 -0
- package/dist/fiscal/coverage/requests.d.ts +70 -0
- package/dist/fiscal/coverage/requests.d.ts.map +1 -0
- package/dist/fiscal/coverage/requests.js +95 -0
- package/dist/fiscal/coverage/requests.js.map +1 -0
- package/dist/fiscal/credentials/material.d.ts +81 -0
- package/dist/fiscal/credentials/material.d.ts.map +1 -0
- package/dist/fiscal/credentials/material.js +164 -0
- package/dist/fiscal/credentials/material.js.map +1 -0
- package/dist/fiscal/credentials/readiness.d.ts +92 -0
- package/dist/fiscal/credentials/readiness.d.ts.map +1 -0
- package/dist/fiscal/credentials/readiness.js +159 -0
- package/dist/fiscal/credentials/readiness.js.map +1 -0
- package/dist/fiscal/eligibility.d.ts +106 -0
- package/dist/fiscal/eligibility.d.ts.map +1 -0
- package/dist/fiscal/eligibility.js +194 -0
- package/dist/fiscal/eligibility.js.map +1 -0
- package/dist/fiscal/ingestion/__fixtures__/nfse.d.ts +57 -0
- package/dist/fiscal/ingestion/__fixtures__/nfse.d.ts.map +1 -0
- package/dist/fiscal/ingestion/__fixtures__/nfse.js +121 -0
- package/dist/fiscal/ingestion/__fixtures__/nfse.js.map +1 -0
- package/dist/fiscal/ingestion/adn-transport.d.ts +123 -0
- package/dist/fiscal/ingestion/adn-transport.d.ts.map +1 -0
- package/dist/fiscal/ingestion/adn-transport.js +220 -0
- package/dist/fiscal/ingestion/adn-transport.js.map +1 -0
- package/dist/fiscal/ingestion/direction.d.ts +60 -0
- package/dist/fiscal/ingestion/direction.d.ts.map +1 -0
- package/dist/fiscal/ingestion/direction.js +32 -0
- package/dist/fiscal/ingestion/direction.js.map +1 -0
- package/dist/fiscal/ingestion/nfse-adn.d.ts +91 -0
- package/dist/fiscal/ingestion/nfse-adn.d.ts.map +1 -0
- package/dist/fiscal/ingestion/nfse-adn.js +222 -0
- package/dist/fiscal/ingestion/nfse-adn.js.map +1 -0
- package/dist/fiscal/ingestion/pipeline.d.ts +168 -0
- package/dist/fiscal/ingestion/pipeline.d.ts.map +1 -0
- package/dist/fiscal/ingestion/pipeline.js +699 -0
- package/dist/fiscal/ingestion/pipeline.js.map +1 -0
- package/dist/fiscal/ingestion/provider.d.ts +206 -0
- package/dist/fiscal/ingestion/provider.d.ts.map +1 -0
- package/dist/fiscal/ingestion/provider.js +47 -0
- package/dist/fiscal/ingestion/provider.js.map +1 -0
- package/dist/fiscal/ingestion/repository.d.ts +82 -0
- package/dist/fiscal/ingestion/repository.d.ts.map +1 -0
- package/dist/fiscal/ingestion/repository.js +127 -0
- package/dist/fiscal/ingestion/repository.js.map +1 -0
- package/dist/fiscal/ingestion/synthetic-provider.d.ts +92 -0
- package/dist/fiscal/ingestion/synthetic-provider.d.ts.map +1 -0
- package/dist/fiscal/ingestion/synthetic-provider.js +99 -0
- package/dist/fiscal/ingestion/synthetic-provider.js.map +1 -0
- package/dist/fiscal/ingestion/synthetic-transport-types.d.ts +19 -0
- package/dist/fiscal/ingestion/synthetic-transport-types.d.ts.map +1 -0
- package/dist/fiscal/ingestion/synthetic-transport-types.js +9 -0
- package/dist/fiscal/ingestion/synthetic-transport-types.js.map +1 -0
- package/dist/fiscal/ingestion/synthetic-transport.d.ts +55 -0
- package/dist/fiscal/ingestion/synthetic-transport.d.ts.map +1 -0
- package/dist/fiscal/ingestion/synthetic-transport.js +57 -0
- package/dist/fiscal/ingestion/synthetic-transport.js.map +1 -0
- package/dist/fiscal/ingestion/xml-reader.d.ts +55 -0
- package/dist/fiscal/ingestion/xml-reader.d.ts.map +1 -0
- package/dist/fiscal/ingestion/xml-reader.js +112 -0
- package/dist/fiscal/ingestion/xml-reader.js.map +1 -0
- package/dist/fiscal/repository.d.ts +220 -0
- package/dist/fiscal/repository.d.ts.map +1 -0
- package/dist/fiscal/repository.js +449 -0
- package/dist/fiscal/repository.js.map +1 -0
- package/dist/fiscal/sync/circuit.d.ts +86 -0
- package/dist/fiscal/sync/circuit.d.ts.map +1 -0
- package/dist/fiscal/sync/circuit.js +118 -0
- package/dist/fiscal/sync/circuit.js.map +1 -0
- package/dist/fiscal/sync/intervention.d.ts +81 -0
- package/dist/fiscal/sync/intervention.d.ts.map +1 -0
- package/dist/fiscal/sync/intervention.js +135 -0
- package/dist/fiscal/sync/intervention.js.map +1 -0
- package/dist/fiscal/sync/lease.d.ts +118 -0
- package/dist/fiscal/sync/lease.d.ts.map +1 -0
- package/dist/fiscal/sync/lease.js +139 -0
- package/dist/fiscal/sync/lease.js.map +1 -0
- package/dist/fiscal/sync/observability.d.ts +148 -0
- package/dist/fiscal/sync/observability.d.ts.map +1 -0
- package/dist/fiscal/sync/observability.js +239 -0
- package/dist/fiscal/sync/observability.js.map +1 -0
- package/dist/fiscal/sync/orchestrator.d.ts +132 -0
- package/dist/fiscal/sync/orchestrator.d.ts.map +1 -0
- package/dist/fiscal/sync/orchestrator.js +487 -0
- package/dist/fiscal/sync/orchestrator.js.map +1 -0
- package/dist/fiscal/sync/policy.d.ts +87 -0
- package/dist/fiscal/sync/policy.d.ts.map +1 -0
- package/dist/fiscal/sync/policy.js +136 -0
- package/dist/fiscal/sync/policy.js.map +1 -0
- package/dist/fiscal/sync/reprocess.d.ts +76 -0
- package/dist/fiscal/sync/reprocess.d.ts.map +1 -0
- package/dist/fiscal/sync/reprocess.js +237 -0
- package/dist/fiscal/sync/reprocess.js.map +1 -0
- package/dist/fiscal/sync/retry.d.ts +82 -0
- package/dist/fiscal/sync/retry.d.ts.map +1 -0
- package/dist/fiscal/sync/retry.js +176 -0
- package/dist/fiscal/sync/retry.js.map +1 -0
- package/dist/fiscal/sync/secret-boundary.d.ts +169 -0
- package/dist/fiscal/sync/secret-boundary.d.ts.map +1 -0
- package/dist/fiscal/sync/secret-boundary.js +116 -0
- package/dist/fiscal/sync/secret-boundary.js.map +1 -0
- package/dist/fiscal/transport/https.d.ts +86 -0
- package/dist/fiscal/transport/https.d.ts.map +1 -0
- package/dist/fiscal/transport/https.js +303 -0
- package/dist/fiscal/transport/https.js.map +1 -0
- package/dist/fiscal/transport/synthetic-tls.d.ts +80 -0
- package/dist/fiscal/transport/synthetic-tls.d.ts.map +1 -0
- package/dist/fiscal/transport/synthetic-tls.js +323 -0
- package/dist/fiscal/transport/synthetic-tls.js.map +1 -0
- package/dist/fiscal/transport/types.d.ts +134 -0
- package/dist/fiscal/transport/types.d.ts.map +1 -0
- package/dist/fiscal/transport/types.js +88 -0
- package/dist/fiscal/transport/types.js.map +1 -0
- package/dist/import/br-documents.d.ts +26 -0
- package/dist/import/br-documents.d.ts.map +1 -0
- package/dist/import/br-documents.js +78 -0
- package/dist/import/br-documents.js.map +1 -0
- package/dist/import/clients-import.d.ts +122 -4
- package/dist/import/clients-import.d.ts.map +1 -1
- package/dist/import/clients-import.js +341 -41
- package/dist/import/clients-import.js.map +1 -1
- package/dist/index.d.ts +217 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +196 -11
- package/dist/index.js.map +1 -1
- package/dist/legal/documents.d.ts +12 -1
- package/dist/legal/documents.d.ts.map +1 -1
- package/dist/legal/documents.js +222 -16
- package/dist/legal/documents.js.map +1 -1
- package/dist/legal/index.d.ts +2 -2
- package/dist/legal/index.d.ts.map +1 -1
- package/dist/legal/index.js +1 -1
- package/dist/legal/index.js.map +1 -1
- package/dist/legal/types.d.ts +69 -3
- package/dist/legal/types.d.ts.map +1 -1
- package/dist/legal/types.js +1 -0
- package/dist/legal/types.js.map +1 -1
- package/dist/mail/auth-templates.d.ts +15 -0
- package/dist/mail/auth-templates.d.ts.map +1 -0
- package/dist/mail/auth-templates.js +26 -0
- package/dist/mail/auth-templates.js.map +1 -0
- package/dist/mail/dedup-store.d.ts +1 -24
- package/dist/mail/dedup-store.d.ts.map +1 -1
- package/dist/mail/dedup-store.js +9 -48
- package/dist/mail/dedup-store.js.map +1 -1
- package/dist/mail/index.d.ts +2 -1
- package/dist/mail/index.d.ts.map +1 -1
- package/dist/mail/index.js +13 -2
- package/dist/mail/index.js.map +1 -1
- package/dist/mail/provider.d.ts +2 -30
- package/dist/mail/provider.d.ts.map +1 -1
- package/dist/mail/provider.js +10 -246
- package/dist/mail/provider.js.map +1 -1
- package/dist/mail/resend.d.ts +2 -12
- package/dist/mail/resend.d.ts.map +1 -1
- package/dist/mail/resend.js +11 -17
- package/dist/mail/resend.js.map +1 -1
- package/dist/mail/sender-resolver.d.ts +1 -7
- package/dist/mail/sender-resolver.d.ts.map +1 -1
- package/dist/mail/sender-resolver.js +11 -10
- package/dist/mail/sender-resolver.js.map +1 -1
- package/dist/mail/template-renderer.d.ts +1 -9
- package/dist/mail/template-renderer.d.ts.map +1 -1
- package/dist/mail/template-renderer.js +10 -15
- package/dist/mail/template-renderer.js.map +1 -1
- package/dist/mail/transactional-outbound.d.ts +115 -0
- package/dist/mail/transactional-outbound.d.ts.map +1 -0
- package/dist/mail/transactional-outbound.js +113 -0
- package/dist/mail/transactional-outbound.js.map +1 -0
- package/dist/mail/types.d.ts +2 -142
- package/dist/mail/types.d.ts.map +1 -1
- package/dist/mail/types.js +1 -33
- package/dist/mail/types.js.map +1 -1
- package/dist/onboarding/persistence.d.ts +10 -1
- package/dist/onboarding/persistence.d.ts.map +1 -1
- package/dist/onboarding/persistence.js +4 -4
- package/dist/onboarding/persistence.js.map +1 -1
- package/dist/pilot/go-live-checklist.d.ts +41 -0
- package/dist/pilot/go-live-checklist.d.ts.map +1 -0
- package/dist/pilot/go-live-checklist.js +209 -0
- package/dist/pilot/go-live-checklist.js.map +1 -0
- package/dist/pilot/milestone.d.ts +56 -0
- package/dist/pilot/milestone.d.ts.map +1 -0
- package/dist/pilot/milestone.js +74 -0
- package/dist/pilot/milestone.js.map +1 -0
- package/dist/platform/capabilities.d.ts +88 -0
- package/dist/platform/capabilities.d.ts.map +1 -0
- package/dist/platform/capabilities.js +140 -0
- package/dist/platform/capabilities.js.map +1 -0
- package/dist/platform/job-contract.d.ts +232 -0
- package/dist/platform/job-contract.d.ts.map +1 -0
- package/dist/platform/job-contract.js +403 -0
- package/dist/platform/job-contract.js.map +1 -0
- package/dist/portal/provisioning.d.ts +58 -0
- package/dist/portal/provisioning.d.ts.map +1 -0
- package/dist/portal/provisioning.js +139 -0
- package/dist/portal/provisioning.js.map +1 -0
- package/dist/pricing-engine/canonical.d.ts +14 -0
- package/dist/pricing-engine/canonical.d.ts.map +1 -0
- package/dist/pricing-engine/canonical.js +39 -0
- package/dist/pricing-engine/canonical.js.map +1 -0
- package/dist/pricing-engine/errors.d.ts.map +1 -1
- package/dist/pricing-engine/errors.js +6 -1
- package/dist/pricing-engine/errors.js.map +1 -1
- package/dist/pricing-engine/index.d.ts +12 -2
- package/dist/pricing-engine/index.d.ts.map +1 -1
- package/dist/pricing-engine/index.js +6 -1
- package/dist/pricing-engine/index.js.map +1 -1
- package/dist/pricing-engine/pipeline.d.ts.map +1 -1
- package/dist/pricing-engine/pipeline.js +202 -28
- package/dist/pricing-engine/pipeline.js.map +1 -1
- package/dist/pricing-engine/shadow-adapter.d.ts +37 -0
- package/dist/pricing-engine/shadow-adapter.d.ts.map +1 -0
- package/dist/pricing-engine/shadow-adapter.js +75 -0
- package/dist/pricing-engine/shadow-adapter.js.map +1 -0
- package/dist/pricing-engine/shadow-diff.d.ts +26 -0
- package/dist/pricing-engine/shadow-diff.d.ts.map +1 -0
- package/dist/pricing-engine/shadow-diff.js +52 -0
- package/dist/pricing-engine/shadow-diff.js.map +1 -0
- package/dist/pricing-engine/shadow-facade.d.ts +42 -0
- package/dist/pricing-engine/shadow-facade.d.ts.map +1 -0
- package/dist/pricing-engine/shadow-facade.js +82 -0
- package/dist/pricing-engine/shadow-facade.js.map +1 -0
- package/dist/pricing-engine/shadow-legacy-types.d.ts +64 -0
- package/dist/pricing-engine/shadow-legacy-types.d.ts.map +1 -0
- package/dist/pricing-engine/shadow-legacy-types.js +18 -0
- package/dist/pricing-engine/shadow-legacy-types.js.map +1 -0
- package/dist/pricing-engine/shadow-metrics.d.ts +33 -0
- package/dist/pricing-engine/shadow-metrics.d.ts.map +1 -0
- package/dist/pricing-engine/shadow-metrics.js +31 -0
- package/dist/pricing-engine/shadow-metrics.js.map +1 -0
- package/dist/pricing-engine/shadow-normalizer.d.ts +17 -0
- package/dist/pricing-engine/shadow-normalizer.d.ts.map +1 -0
- package/dist/pricing-engine/shadow-normalizer.js +39 -0
- package/dist/pricing-engine/shadow-normalizer.js.map +1 -0
- package/dist/pricing-engine/types.d.ts +2 -0
- package/dist/pricing-engine/types.d.ts.map +1 -1
- package/dist/rbac/authorize.d.ts +12 -0
- package/dist/rbac/authorize.d.ts.map +1 -1
- package/dist/rbac/authorize.js +27 -0
- package/dist/rbac/authorize.js.map +1 -1
- package/dist/rbac/catalog.d.ts.map +1 -1
- package/dist/rbac/catalog.js +101 -1
- package/dist/rbac/catalog.js.map +1 -1
- package/dist/rbac/workload-provisioning.d.ts +66 -0
- package/dist/rbac/workload-provisioning.d.ts.map +1 -0
- package/dist/rbac/workload-provisioning.js +153 -0
- package/dist/rbac/workload-provisioning.js.map +1 -0
- package/dist/rbac/workload.d.ts +124 -0
- package/dist/rbac/workload.d.ts.map +1 -0
- package/dist/rbac/workload.js +184 -0
- package/dist/rbac/workload.js.map +1 -0
- package/dist/storage/checksum.d.ts +9 -0
- package/dist/storage/checksum.d.ts.map +1 -0
- package/dist/storage/checksum.js +12 -0
- package/dist/storage/checksum.js.map +1 -0
- package/dist/storage/key.d.ts +37 -0
- package/dist/storage/key.d.ts.map +1 -0
- package/dist/storage/key.js +67 -0
- package/dist/storage/key.js.map +1 -0
- package/dist/storage/local.d.ts +40 -0
- package/dist/storage/local.d.ts.map +1 -0
- package/dist/storage/local.js +96 -0
- package/dist/storage/local.js.map +1 -0
- package/dist/storage/r2.d.ts +43 -0
- package/dist/storage/r2.d.ts.map +1 -0
- package/dist/storage/r2.js +177 -0
- package/dist/storage/r2.js.map +1 -0
- package/dist/storage/registry.d.ts +23 -0
- package/dist/storage/registry.d.ts.map +1 -0
- package/dist/storage/registry.js +37 -0
- package/dist/storage/registry.js.map +1 -0
- package/dist/storage/types.d.ts +67 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +45 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/subscription-billing/index.d.ts +6 -5
- package/dist/subscription-billing/index.d.ts.map +1 -1
- package/dist/subscription-billing/index.js +3 -3
- package/dist/subscription-billing/index.js.map +1 -1
- package/dist/subscription-billing/provider/asaas.d.ts +14 -0
- package/dist/subscription-billing/provider/asaas.d.ts.map +1 -1
- package/dist/subscription-billing/provider/asaas.js +32 -7
- package/dist/subscription-billing/provider/asaas.js.map +1 -1
- package/dist/subscription-billing/provider/disabled.d.ts +9 -0
- package/dist/subscription-billing/provider/disabled.d.ts.map +1 -1
- package/dist/subscription-billing/provider/disabled.js +8 -0
- package/dist/subscription-billing/provider/disabled.js.map +1 -1
- package/dist/subscription-billing/provider/registry.d.ts +10 -0
- package/dist/subscription-billing/provider/registry.d.ts.map +1 -1
- package/dist/subscription-billing/provider/registry.js +17 -0
- package/dist/subscription-billing/provider/registry.js.map +1 -1
- package/dist/subscription-billing/service.d.ts +38 -1
- package/dist/subscription-billing/service.d.ts.map +1 -1
- package/dist/subscription-billing/service.js +147 -23
- package/dist/subscription-billing/service.js.map +1 -1
- package/dist/subscription-billing/types.d.ts +13 -0
- package/dist/subscription-billing/types.d.ts.map +1 -1
- package/dist/subscription-billing/types.js.map +1 -1
- package/dist/tenancy/features.d.ts +69 -0
- package/dist/tenancy/features.d.ts.map +1 -0
- package/dist/tenancy/features.js +123 -0
- package/dist/tenancy/features.js.map +1 -0
- package/dist/tenancy/provisioning.d.ts.map +1 -1
- package/dist/tenancy/provisioning.js +32 -8
- package/dist/tenancy/provisioning.js.map +1 -1
- package/dist/tenancy/settings.d.ts +63 -0
- package/dist/tenancy/settings.d.ts.map +1 -0
- package/dist/tenancy/settings.js +218 -0
- package/dist/tenancy/settings.js.map +1 -0
- package/dist/users/repository.d.ts +54 -1
- package/dist/users/repository.d.ts.map +1 -1
- package/dist/users/repository.js +142 -4
- package/dist/users/repository.js.map +1 -1
- package/dist/vault/repository.d.ts +67 -0
- package/dist/vault/repository.d.ts.map +1 -1
- package/dist/vault/repository.js +78 -0
- package/dist/vault/repository.js.map +1 -1
- package/package.json +20 -4
- package/src/db/migrations/0023_user_invite_activation.sql +15 -0
- package/src/db/migrations/0024_set_user_password_function.sql +32 -0
- package/src/db/migrations/0025_revoke_user_session_function.sql +28 -0
- package/src/db/migrations/0026_documents_and_competence.sql +353 -0
- package/src/db/migrations/0027_receivable_client_isolation.sql +58 -0
- package/src/db/migrations/0028_collection_engine.sql +94 -0
- package/src/db/migrations/0029_payment_rail.sql +107 -0
- package/src/db/migrations/0030_provider_account_uniqueness.sql +22 -0
- package/src/db/migrations/0031_provider_account_environment_scope.sql +21 -0
- package/src/db/migrations/0032_settlement_reversal.sql +76 -0
- package/src/db/migrations/0033_receivable_idempotency.sql +28 -0
- package/src/db/migrations/0034_payment_customer_reconcile.sql +30 -0
- package/src/db/migrations/0035_payment_account_environments.sql +61 -0
- package/src/db/migrations/0036_primary_backfill_under_force_rls.sql +41 -0
- package/src/db/migrations/0037_receivable_generation_source.sql +29 -0
- package/src/db/migrations/0038_notification_channels.sql +175 -0
- package/src/db/migrations/0039_communication_dispatch_claim.sql +193 -0
- package/src/db/migrations/0040_communication_unknown_outcome.sql +99 -0
- package/src/db/migrations/0041_channel_binding_routing.sql +146 -0
- package/src/db/migrations/0042_channel_route_read_isolation.sql +165 -0
- package/src/db/migrations/0043_workload_identity.sql +105 -0
- package/src/db/migrations/0044_channel_onboarding_session.sql +96 -0
- package/src/db/migrations/0045_role_write_scope.sql +122 -0
- package/src/db/migrations/0046_pilot_activation_model.sql +184 -0
- package/src/db/migrations/0047_recipient_clearance.sql +89 -0
- package/src/db/migrations/0048_item_type_note.sql +16 -0
- package/src/db/migrations/0049_national_fiscal_engine.sql +279 -0
- package/src/db/migrations/0050_fiscal_vocabulary_readonly.sql +29 -0
- package/src/db/migrations/0051_seed_rules_from_catalog.sql +72 -0
- package/src/db/migrations/0052_fiscal_rule_delete_scope.sql +57 -0
- package/src/db/migrations/0053_rule_validity_lower_bound.sql +44 -0
- package/src/db/migrations/0054_tenant_profile_and_rule_source.sql +89 -0
- package/src/db/migrations/0055_job_capability_contract.sql +300 -0
- package/src/db/migrations/0056_fiscal_document_ingestion.sql +337 -0
- package/src/db/migrations/0057_fiscal_pending_event_inbox.sql +228 -0
- package/src/db/migrations/0058_fiscal_operational_engine.sql +516 -0
- package/src/db/migrations/0059_fiscal_contract_version.sql +59 -0
- package/dist/cjs/mail/resend-client.js +0 -103
- package/dist/cjs/mail/resend-client.js.map +0 -1
- package/dist/mail/resend-client.d.ts +0 -16
- package/dist/mail/resend-client.d.ts.map +0 -1
- package/dist/mail/resend-client.js +0 -100
- package/dist/mail/resend-client.js.map +0 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureSaasPlanCatalog = exports.getPlan = exports.listPublicPlans = void 0;
|
|
4
4
|
exports.seedSaasPlans = seedSaasPlans;
|
|
5
|
+
exports.provisionAccountingOffice = provisionAccountingOffice;
|
|
5
6
|
exports.signupSelfService = signupSelfService;
|
|
6
7
|
exports.standingFor = standingFor;
|
|
7
8
|
exports.entitlementsForPlan = entitlementsForPlan;
|
|
@@ -21,17 +22,19 @@ const shared_1 = require("@baruk/shared");
|
|
|
21
22
|
const context_js_1 = require("../db/context.js");
|
|
22
23
|
const audit_js_1 = require("../audit/audit.js");
|
|
23
24
|
const password_js_1 = require("../auth/password.js");
|
|
25
|
+
const repository_js_1 = require("../users/repository.js");
|
|
24
26
|
const provisioning_js_1 = require("../tenancy/provisioning.js");
|
|
25
|
-
const
|
|
27
|
+
const repository_js_2 = require("../products/repository.js");
|
|
26
28
|
const derive_js_1 = require("../entitlements/derive.js");
|
|
27
|
-
const
|
|
29
|
+
const transactional_outbound_js_1 = require("../mail/transactional-outbound.js");
|
|
28
30
|
const reconcile_js_1 = require("./reconcile.js");
|
|
29
31
|
const dunning_js_1 = require("./dunning.js");
|
|
32
|
+
const live_guard_js_1 = require("../billing/live-guard.js");
|
|
30
33
|
const registry_js_1 = require("./provider/registry.js");
|
|
31
|
-
const
|
|
32
|
-
Object.defineProperty(exports, "ensureSaasPlanCatalog", { enumerable: true, get: function () { return
|
|
33
|
-
Object.defineProperty(exports, "getPlan", { enumerable: true, get: function () { return
|
|
34
|
-
Object.defineProperty(exports, "listPublicPlans", { enumerable: true, get: function () { return
|
|
34
|
+
const repository_js_3 = require("./repository.js");
|
|
35
|
+
Object.defineProperty(exports, "ensureSaasPlanCatalog", { enumerable: true, get: function () { return repository_js_3.ensureSaasPlanCatalog; } });
|
|
36
|
+
Object.defineProperty(exports, "getPlan", { enumerable: true, get: function () { return repository_js_3.getPlan; } });
|
|
37
|
+
Object.defineProperty(exports, "listPublicPlans", { enumerable: true, get: function () { return repository_js_3.listPublicPlans; } });
|
|
35
38
|
const plans_js_1 = require("./plans.js");
|
|
36
39
|
const product_config_js_1 = require("./product-config.js");
|
|
37
40
|
function asRegistry(source) {
|
|
@@ -86,8 +89,70 @@ async function syncTenantStatus(tx, tenantId, status) {
|
|
|
86
89
|
}
|
|
87
90
|
/** Seed do catálogo padrão (chamado pelo seed do core). */
|
|
88
91
|
async function seedSaasPlans(db) {
|
|
89
|
-
await (0,
|
|
90
|
-
await (0,
|
|
92
|
+
await (0, repository_js_2.ensureProductCatalog)(db);
|
|
93
|
+
await (0, repository_js_3.ensureSaasPlanCatalog)(db, plans_js_1.SAAS_PLANS);
|
|
94
|
+
}
|
|
95
|
+
async function provisionAccountingOffice(db, input, nowIso) {
|
|
96
|
+
const email = input.ownerEmail.trim().toLowerCase();
|
|
97
|
+
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email))
|
|
98
|
+
throw new shared_1.ValidationError('E-mail inválido');
|
|
99
|
+
if (!input.companyName.trim())
|
|
100
|
+
throw new shared_1.ValidationError('Nome do escritório é obrigatório');
|
|
101
|
+
if (!input.ownerFullName.trim())
|
|
102
|
+
throw new shared_1.ValidationError('Nome do responsável é obrigatório');
|
|
103
|
+
const planKey = input.planKey ?? plans_js_1.SAAS_PLANS.find((p) => p.isActive && p.isPublic)?.key;
|
|
104
|
+
if (!planKey)
|
|
105
|
+
throw new shared_1.ValidationError('Nenhum plano ativo disponível');
|
|
106
|
+
const plan = await (0, repository_js_3.getPlan)(db, planKey);
|
|
107
|
+
if (!plan || !plan.isActive)
|
|
108
|
+
throw new shared_1.ValidationError(`Plano indisponível: ${planKey}`);
|
|
109
|
+
const code = await uniqueTenantCode(db, input.companyName);
|
|
110
|
+
const tenantId = await (0, provisioning_js_1.ensureTenant)(db, {
|
|
111
|
+
code,
|
|
112
|
+
displayName: input.companyName.trim(),
|
|
113
|
+
status: 'trial',
|
|
114
|
+
primaryProduct: plans_js_1.DEFAULT_PRODUCT_KEY,
|
|
115
|
+
});
|
|
116
|
+
await (0, provisioning_js_1.ensureOrganization)(db, tenantId, input.companyName.trim());
|
|
117
|
+
await (0, repository_js_2.ensureProductCatalog)(db);
|
|
118
|
+
await (0, repository_js_2.ensureTenantProduct)(db, tenantId, plans_js_1.DEFAULT_PRODUCT_KEY);
|
|
119
|
+
const trialEndsAt = addDays(nowIso, plan.trialDays > 0 ? plan.trialDays : plans_js_1.DEFAULT_TRIAL_DAYS);
|
|
120
|
+
const { subscription, domainEvents } = (0, reconcile_js_1.startTrial)(tenantId, plan.key, trialEndsAt, nowIso);
|
|
121
|
+
/*
|
|
122
|
+
* Contexto do TENANT NOVO com o usuário da OPERADORA.
|
|
123
|
+
*
|
|
124
|
+
* O operador não é membro deste escritório e nunca será — ele abre o contexto
|
|
125
|
+
* para criar o convite e sai. O `invited_by` aponta para ele, que é a
|
|
126
|
+
* resposta honesta a "quem colocou esta pessoa aqui".
|
|
127
|
+
*/
|
|
128
|
+
return (0, context_js_1.withContext)(db, { tenantId, userId: input.operatorUserId }, async (tx) => {
|
|
129
|
+
const invited = await (0, repository_js_1.inviteUser)(tx, {
|
|
130
|
+
email,
|
|
131
|
+
fullName: input.ownerFullName.trim(),
|
|
132
|
+
roleKey: 'owner',
|
|
133
|
+
invitedBy: input.operatorUserId,
|
|
134
|
+
});
|
|
135
|
+
const row = await (0, repository_js_3.upsertSubscription)(tx, { tenantId, planKey: plan.key, subscription });
|
|
136
|
+
await (0, repository_js_3.appendDomainEvents)(tx, row.rowId, domainEvents);
|
|
137
|
+
await (0, audit_js_1.appendAudit)(tx, {
|
|
138
|
+
actorId: input.operatorUserId,
|
|
139
|
+
action: 'tenant.provisioned_by_operator',
|
|
140
|
+
resourceType: 'tenant',
|
|
141
|
+
resourceId: tenantId,
|
|
142
|
+
metadata: { planKey: plan.key, trialEndsAt, tenantCode: code, ownerEmail: email },
|
|
143
|
+
ip: input.ip ?? null,
|
|
144
|
+
userAgent: input.userAgent ?? null,
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
tenantId,
|
|
148
|
+
tenantCode: code,
|
|
149
|
+
ownerUserId: invited.userId,
|
|
150
|
+
ownerEmail: invited.email,
|
|
151
|
+
planKey: plan.key,
|
|
152
|
+
trialEndsAt,
|
|
153
|
+
activationToken: invited.activationToken,
|
|
154
|
+
};
|
|
155
|
+
});
|
|
91
156
|
}
|
|
92
157
|
function slugify(name) {
|
|
93
158
|
return name
|
|
@@ -98,6 +163,31 @@ function slugify(name) {
|
|
|
98
163
|
.replace(/^-+|-+$/g, '')
|
|
99
164
|
.slice(0, 40);
|
|
100
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Código do escritório a partir do nome, único na base.
|
|
168
|
+
*
|
|
169
|
+
* Extraído do signup quando o provisionamento pela operadora passou a precisar
|
|
170
|
+
* do mesmo cálculo. Duas cópias da regra de colisão renderiam dois códigos
|
|
171
|
+
* diferentes para o mesmo nome dependendo de por qual porta o escritório
|
|
172
|
+
* entrou — e o código aparece em referência de cobrança já emitida.
|
|
173
|
+
*/
|
|
174
|
+
async function uniqueTenantCode(db, companyName) {
|
|
175
|
+
const base = slugify(companyName) || 'escritorio';
|
|
176
|
+
let code = base;
|
|
177
|
+
for (let i = 2;; i += 1) {
|
|
178
|
+
const clash = await db `
|
|
179
|
+
SELECT id FROM tenant WHERE lower(code) = lower(${code}) AND deleted_at IS NULL
|
|
180
|
+
`;
|
|
181
|
+
if (!clash[0])
|
|
182
|
+
break;
|
|
183
|
+
code = `${base}-${i}`;
|
|
184
|
+
if (i > 50) {
|
|
185
|
+
code = `${base}-${(0, shared_1.uuidv7)().slice(-6)}`;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return code;
|
|
190
|
+
}
|
|
101
191
|
/**
|
|
102
192
|
* Cadastro self-service (Fase 17): cria usuário + tenant em TRIAL + organização +
|
|
103
193
|
* membership com papel `owner` + entitlement do produto + assinatura `trialing`.
|
|
@@ -111,7 +201,7 @@ async function signupSelfService(db, input, nowIso) {
|
|
|
111
201
|
throw new shared_1.ValidationError('Senha deve ter ao menos 8 caracteres');
|
|
112
202
|
if (!input.companyName.trim())
|
|
113
203
|
throw new shared_1.ValidationError('Nome da empresa é obrigatório');
|
|
114
|
-
const plan = await (0,
|
|
204
|
+
const plan = await (0, repository_js_3.getPlan)(db, input.planKey);
|
|
115
205
|
if (!plan || !plan.isActive || !plan.isPublic) {
|
|
116
206
|
throw new shared_1.ValidationError(`Plano indisponível: ${input.planKey}`);
|
|
117
207
|
}
|
|
@@ -122,20 +212,7 @@ async function signupSelfService(db, input, nowIso) {
|
|
|
122
212
|
throw new shared_1.ConflictError('Já existe uma conta com este e-mail. Faça login para continuar.');
|
|
123
213
|
}
|
|
124
214
|
// Código único do tenant a partir do nome (sufixo em caso de colisão).
|
|
125
|
-
const
|
|
126
|
-
let code = base;
|
|
127
|
-
for (let i = 2;; i += 1) {
|
|
128
|
-
const clash = await db `
|
|
129
|
-
SELECT id FROM tenant WHERE lower(code) = lower(${code}) AND deleted_at IS NULL
|
|
130
|
-
`;
|
|
131
|
-
if (!clash[0])
|
|
132
|
-
break;
|
|
133
|
-
code = `${base}-${i}`;
|
|
134
|
-
if (i > 50) {
|
|
135
|
-
code = `${base}-${(0, shared_1.uuidv7)().slice(-6)}`;
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
215
|
+
const code = await uniqueTenantCode(db, input.companyName);
|
|
139
216
|
// INSERT puro (não upsert): o papel de app pode CRIAR credencial, nunca
|
|
140
217
|
// sobrescrever (REVOKE UPDATE em user_credential — anti account-takeover).
|
|
141
218
|
// A checagem de e-mail acima já garante que o usuário é novo.
|
|
@@ -158,13 +235,13 @@ async function signupSelfService(db, input, nowIso) {
|
|
|
158
235
|
await (0, provisioning_js_1.ensureOrganization)(db, tenantId, input.companyName.trim());
|
|
159
236
|
await (0, provisioning_js_1.ensureMembership)(db, tenantId, user.id);
|
|
160
237
|
await (0, provisioning_js_1.assignSystemRole)(db, tenantId, user.id, 'owner');
|
|
161
|
-
await (0,
|
|
162
|
-
await (0,
|
|
238
|
+
await (0, repository_js_2.ensureProductCatalog)(db);
|
|
239
|
+
await (0, repository_js_2.ensureTenantProduct)(db, tenantId, 'contabil');
|
|
163
240
|
const trialEndsAt = addDays(nowIso, plan.trialDays > 0 ? plan.trialDays : 14);
|
|
164
241
|
const { subscription, domainEvents } = (0, reconcile_js_1.startTrial)(tenantId, plan.key, trialEndsAt, nowIso);
|
|
165
242
|
await (0, context_js_1.withContext)(db, { tenantId, userId: user.id }, async (tx) => {
|
|
166
|
-
const row = await (0,
|
|
167
|
-
await (0,
|
|
243
|
+
const row = await (0, repository_js_3.upsertSubscription)(tx, { tenantId, planKey: plan.key, subscription });
|
|
244
|
+
await (0, repository_js_3.appendDomainEvents)(tx, row.rowId, domainEvents);
|
|
168
245
|
await (0, audit_js_1.appendAudit)(tx, {
|
|
169
246
|
actorId: user.id,
|
|
170
247
|
action: 'signup',
|
|
@@ -211,16 +288,16 @@ function entitlementsForPlan(sub, plan, nowIso) {
|
|
|
211
288
|
}
|
|
212
289
|
async function subscriptionOverview(db, ctx, nowIso) {
|
|
213
290
|
const { sub, invoices, events } = await (0, context_js_1.withContext)(db, ctx, async (tx) => {
|
|
214
|
-
const sub0 = await (0,
|
|
291
|
+
const sub0 = await (0, repository_js_3.getSubscription)(tx);
|
|
215
292
|
return {
|
|
216
293
|
sub: sub0,
|
|
217
|
-
invoices: sub0 ? await (0,
|
|
218
|
-
events: sub0 ? await (0,
|
|
294
|
+
invoices: sub0 ? await (0, repository_js_3.listInvoices)(tx) : [],
|
|
295
|
+
events: sub0 ? await (0, repository_js_3.listBillingEvents)(tx, 20) : [],
|
|
219
296
|
};
|
|
220
297
|
});
|
|
221
298
|
// Fora da transação: getPlan usa outra conexão do pool — dentro dela seria
|
|
222
299
|
// um segundo checkout de conexão com transação aberta (deadlock de pool).
|
|
223
|
-
const plan = sub ? await (0,
|
|
300
|
+
const plan = sub ? await (0, repository_js_3.getPlan)(db, sub.planKey) : null;
|
|
224
301
|
return {
|
|
225
302
|
subscription: sub,
|
|
226
303
|
plan,
|
|
@@ -237,7 +314,7 @@ async function subscriptionOverview(db, ctx, nowIso) {
|
|
|
237
314
|
* manual (backoffice) — nunca cobra por falta de configuração.
|
|
238
315
|
*/
|
|
239
316
|
async function startCheckout(db, ctx, source, planKey, _nowIso, productKey = plans_js_1.DEFAULT_PRODUCT_KEY) {
|
|
240
|
-
const plan = await (0,
|
|
317
|
+
const plan = await (0, repository_js_3.getPlan)(db, planKey, productKey);
|
|
241
318
|
if (!plan || !plan.isActive || !plan.isPublic) {
|
|
242
319
|
throw new shared_1.ValidationError(`Plano indisponível: ${planKey}`);
|
|
243
320
|
}
|
|
@@ -254,6 +331,13 @@ async function startCheckout(db, ctx, source, planKey, _nowIso, productKey = pla
|
|
|
254
331
|
if (provider.mode === 'disabled') {
|
|
255
332
|
return { mode: 'disabled', provider: provider.name, url: null };
|
|
256
333
|
}
|
|
334
|
+
// Chave geral, no ponto em que dívida real nasce — e ANTES de qualquer
|
|
335
|
+
// chamada ao gateway. O modo lido é o EFETIVO (a fábrica rebaixa para
|
|
336
|
+
// `disabled` quem não tem credencial), então só um provedor genuinamente
|
|
337
|
+
// live é barrado aqui.
|
|
338
|
+
if (provider.mode === 'live') {
|
|
339
|
+
(0, live_guard_js_1.assertLiveProviderAllowed)('live', (0, live_guard_js_1.readLiveRuntime)(), 'charge');
|
|
340
|
+
}
|
|
257
341
|
// 1) Leitura curta (transação própria) — nada de rede com transação aberta.
|
|
258
342
|
const snapshot = await (0, context_js_1.withContext)(db, ctx, async (tx) => {
|
|
259
343
|
const tenantRows = await tx `
|
|
@@ -262,7 +346,7 @@ async function startCheckout(db, ctx, source, planKey, _nowIso, productKey = pla
|
|
|
262
346
|
const userRows = await tx `
|
|
263
347
|
SELECT email FROM "user" WHERE id = ${ctx.userId}
|
|
264
348
|
`;
|
|
265
|
-
const sub = await (0,
|
|
349
|
+
const sub = await (0, repository_js_3.getSubscription)(tx);
|
|
266
350
|
return {
|
|
267
351
|
tenantName: tenantRows[0]?.display_name ?? 'Tenant Baruk',
|
|
268
352
|
email: userRows[0]?.email ?? null,
|
|
@@ -289,8 +373,8 @@ async function startCheckout(db, ctx, source, planKey, _nowIso, productKey = pla
|
|
|
289
373
|
// 3) Persistência curta: SOMENTE as referências de provider (nunca o estado
|
|
290
374
|
// da assinatura — um webhook pode tê-la mudado durante a chamada de rede).
|
|
291
375
|
await (0, context_js_1.withContext)(db, ctx, async (tx) => {
|
|
292
|
-
await (0,
|
|
293
|
-
await (0,
|
|
376
|
+
await (0, repository_js_3.lockTenantBilling)(tx, ctx.tenantId);
|
|
377
|
+
await (0, repository_js_3.setSubscriptionProviderRefs)(tx, ctx.tenantId, provider.name, customer.externalId);
|
|
294
378
|
await (0, audit_js_1.appendAudit)(tx, {
|
|
295
379
|
actorId: ctx.userId,
|
|
296
380
|
action: 'checkout_started',
|
|
@@ -347,7 +431,7 @@ async function processWebhook(db, source, headers, rawBody, payload, nowIso, pro
|
|
|
347
431
|
const event = provider.parseWebhookEvent(payload);
|
|
348
432
|
if (!event)
|
|
349
433
|
return { outcome: 'ignored' };
|
|
350
|
-
const webhookId = await (0,
|
|
434
|
+
const webhookId = await (0, repository_js_3.insertWebhookEvent)(db, {
|
|
351
435
|
provider: provider.name,
|
|
352
436
|
externalEventId: event.externalEventId,
|
|
353
437
|
eventType: event.eventType,
|
|
@@ -364,7 +448,7 @@ async function processWebhook(db, source, headers, rawBody, payload, nowIso, pro
|
|
|
364
448
|
async function reconcileStoredWebhookEvent(db, provider, event, webhookId, nowIso, expectedProductKey = plans_js_1.DEFAULT_PRODUCT_KEY) {
|
|
365
449
|
const attribution = parseAttribution(event);
|
|
366
450
|
if (!attribution) {
|
|
367
|
-
await (0,
|
|
451
|
+
await (0, repository_js_3.markWebhookEvent)(db, webhookId, 'ignored', null, 'externalReference ausente/inválida');
|
|
368
452
|
return { outcome: 'ignored' };
|
|
369
453
|
}
|
|
370
454
|
// ISOLAMENTO FINANCEIRO: a conta que assinou o webhook é a conta de UM
|
|
@@ -372,15 +456,15 @@ async function reconcileStoredWebhookEvent(db, provider, event, webhookId, nowIs
|
|
|
372
456
|
// errada no gateway — ou é tentativa de mover dinheiro entre produtos.
|
|
373
457
|
// Recusar é obrigatório: reconciliar aqui escreveria na assinatura errada.
|
|
374
458
|
if (attribution.productKey !== expectedProductKey) {
|
|
375
|
-
await (0,
|
|
459
|
+
await (0, repository_js_3.markWebhookEvent)(db, webhookId, 'ignored', null, `produto divergente: evento=${attribution.productKey} conta=${expectedProductKey}`);
|
|
376
460
|
return { outcome: 'ignored' };
|
|
377
461
|
}
|
|
378
462
|
try {
|
|
379
|
-
const plan = await (0,
|
|
463
|
+
const plan = await (0, repository_js_3.getPlan)(db, attribution.planKey, attribution.productKey);
|
|
380
464
|
const { tenantId } = attribution;
|
|
381
465
|
const applied = await (0, context_js_1.withContext)(db, { tenantId }, async (tx) => {
|
|
382
|
-
await (0,
|
|
383
|
-
const current = await (0,
|
|
466
|
+
await (0, repository_js_3.lockTenantBilling)(tx, tenantId);
|
|
467
|
+
const current = await (0, repository_js_3.getSubscription)(tx);
|
|
384
468
|
// Guarda de ordenação (webhook atrasado): um OVERDUE que chega DEPOIS do
|
|
385
469
|
// pagamento do mesmo ciclo (período corrente ainda vigente) é obsoleto —
|
|
386
470
|
// aplicá-lo marcaria past_due uma assinatura em dia. Política de
|
|
@@ -440,7 +524,7 @@ async function reconcileStoredWebhookEvent(db, provider, event, webhookId, nowIs
|
|
|
440
524
|
currentPeriodEnd: addMonths(nowIso, plan.periodicity === 'yearly' ? 12 : 3),
|
|
441
525
|
};
|
|
442
526
|
}
|
|
443
|
-
const row = await (0,
|
|
527
|
+
const row = await (0, repository_js_3.upsertSubscription)(tx, {
|
|
444
528
|
tenantId,
|
|
445
529
|
planKey: effectivePlanKey ?? current?.planKey ?? next.items[0]?.planKey ?? 'starter',
|
|
446
530
|
subscription: next,
|
|
@@ -448,9 +532,9 @@ async function reconcileStoredWebhookEvent(db, provider, event, webhookId, nowIs
|
|
|
448
532
|
providerCustomerId: event.externalCustomerId ?? null,
|
|
449
533
|
providerSubscriptionId: event.subscription?.externalId ?? null,
|
|
450
534
|
});
|
|
451
|
-
await (0,
|
|
535
|
+
await (0, repository_js_3.appendDomainEvents)(tx, row.rowId, domainEvents);
|
|
452
536
|
if (event.invoice) {
|
|
453
|
-
await (0,
|
|
537
|
+
await (0, repository_js_3.upsertInvoice)(tx, {
|
|
454
538
|
tenantId,
|
|
455
539
|
subscriptionRowId: row.rowId,
|
|
456
540
|
provider: provider.name,
|
|
@@ -478,25 +562,25 @@ async function reconcileStoredWebhookEvent(db, provider, event, webhookId, nowIs
|
|
|
478
562
|
return null;
|
|
479
563
|
});
|
|
480
564
|
if (applied !== null) {
|
|
481
|
-
await (0,
|
|
565
|
+
await (0, repository_js_3.markWebhookEvent)(db, webhookId, 'ignored', attribution.tenantId, applied);
|
|
482
566
|
return { outcome: 'ignored', tenantId: attribution.tenantId };
|
|
483
567
|
}
|
|
484
|
-
await (0,
|
|
568
|
+
await (0, repository_js_3.markWebhookEvent)(db, webhookId, 'processed', attribution.tenantId);
|
|
485
569
|
return { outcome: 'processed', tenantId: attribution.tenantId };
|
|
486
570
|
}
|
|
487
571
|
catch (err) {
|
|
488
|
-
await (0,
|
|
572
|
+
await (0, repository_js_3.markWebhookEvent)(db, webhookId, 'failed', attribution.tenantId, err instanceof Error ? err.message : String(err));
|
|
489
573
|
return { outcome: 'failed', tenantId: attribution.tenantId };
|
|
490
574
|
}
|
|
491
575
|
}
|
|
492
576
|
// ── Gestão da assinatura (tenant) ────────────────────────────────────────────
|
|
493
577
|
async function changePlanForTenant(db, ctx, newPlanKey, nowIso) {
|
|
494
|
-
const plan = await (0,
|
|
578
|
+
const plan = await (0, repository_js_3.getPlan)(db, newPlanKey);
|
|
495
579
|
if (!plan || !plan.isActive)
|
|
496
580
|
throw new shared_1.ValidationError(`Plano desconhecido: ${newPlanKey}`);
|
|
497
581
|
return (0, context_js_1.withContext)(db, ctx, async (tx) => {
|
|
498
|
-
await (0,
|
|
499
|
-
const current = await (0,
|
|
582
|
+
await (0, repository_js_3.lockTenantBilling)(tx, ctx.tenantId);
|
|
583
|
+
const current = await (0, repository_js_3.getSubscription)(tx);
|
|
500
584
|
if (!current)
|
|
501
585
|
throw new shared_1.NotFoundError('Nenhuma assinatura para este tenant');
|
|
502
586
|
if (current.status === 'canceled') {
|
|
@@ -505,12 +589,12 @@ async function changePlanForTenant(db, ctx, newPlanKey, nowIso) {
|
|
|
505
589
|
if (current.planKey === plan.key)
|
|
506
590
|
return current;
|
|
507
591
|
const { subscription, domainEvents } = (0, reconcile_js_1.changePlan)(current, plan.key, nowIso);
|
|
508
|
-
const row = await (0,
|
|
592
|
+
const row = await (0, repository_js_3.upsertSubscription)(tx, {
|
|
509
593
|
tenantId: ctx.tenantId,
|
|
510
594
|
planKey: plan.key,
|
|
511
595
|
subscription,
|
|
512
596
|
});
|
|
513
|
-
await (0,
|
|
597
|
+
await (0, repository_js_3.appendDomainEvents)(tx, row.rowId, domainEvents);
|
|
514
598
|
await (0, audit_js_1.appendAudit)(tx, {
|
|
515
599
|
actorId: ctx.userId,
|
|
516
600
|
action: 'plan_changed',
|
|
@@ -521,27 +605,64 @@ async function changePlanForTenant(db, ctx, newPlanKey, nowIso) {
|
|
|
521
605
|
return row;
|
|
522
606
|
});
|
|
523
607
|
}
|
|
524
|
-
|
|
608
|
+
/**
|
|
609
|
+
* Cancelamento — GATEWAY-FIRST.
|
|
610
|
+
*
|
|
611
|
+
* A recorrência é cancelada no provider ANTES de o estado local virar
|
|
612
|
+
* `canceled`. A ordem inversa produzia o pior resultado possível: a aplicação
|
|
613
|
+
* dizia "cancelado", o acesso era suspenso, e o ASAAS seguia emitindo cobrança
|
|
614
|
+
* mensal — cliente pagando por serviço que já não usa.
|
|
615
|
+
*
|
|
616
|
+
* Se o gateway falhar, o erro sobe e o estado local NÃO é consolidado: melhor o
|
|
617
|
+
* usuário ver a falha e tentar de novo do que acreditar num cancelamento que não
|
|
618
|
+
* aconteceu. A operação é segura para retry porque `cancelSubscription` do
|
|
619
|
+
* provider é idempotente — cancelar o que já está cancelado devolve sucesso.
|
|
620
|
+
*
|
|
621
|
+
* Assinatura sem `providerSubscriptionId` (trial que nunca chegou ao checkout)
|
|
622
|
+
* não tem o que cancelar no gateway: segue direto para o estado local.
|
|
623
|
+
*/
|
|
624
|
+
async function cancelForTenant(db, ctx, source, nowIso, productKey = plans_js_1.DEFAULT_PRODUCT_KEY) {
|
|
625
|
+
// Fora da transação: chamada de rede não pode segurar o lock do tenant.
|
|
626
|
+
const existing = await (0, context_js_1.withContext)(db, ctx, (tx) => (0, repository_js_3.getSubscription)(tx, productKey));
|
|
627
|
+
if (!existing)
|
|
628
|
+
throw new shared_1.NotFoundError('Nenhuma assinatura para este tenant');
|
|
629
|
+
let providerOutcome = 'skipped_no_provider_id';
|
|
630
|
+
if (existing.status !== 'canceled' && existing.providerSubscriptionId) {
|
|
631
|
+
// Mesma resolução por produto usada no checkout: a conta de gateway sai do
|
|
632
|
+
// PRODUTO, nunca de configuração global. Cancelar na conta errada seria tão
|
|
633
|
+
// grave quanto cobrar na conta errada.
|
|
634
|
+
const cfg = asRegistry(source).resolve({ productKey, tenantId: ctx.tenantId });
|
|
635
|
+
const provider = providerFor(cfg);
|
|
636
|
+
if (provider.cancelSubscription) {
|
|
637
|
+
const res = await provider.cancelSubscription(existing.providerSubscriptionId);
|
|
638
|
+
providerOutcome = res.alreadyCanceled ? 'already_canceled' : 'canceled';
|
|
639
|
+
}
|
|
640
|
+
}
|
|
525
641
|
return (0, context_js_1.withContext)(db, ctx, async (tx) => {
|
|
526
|
-
await (0,
|
|
527
|
-
const current = await (0,
|
|
642
|
+
await (0, repository_js_3.lockTenantBilling)(tx, ctx.tenantId);
|
|
643
|
+
const current = await (0, repository_js_3.getSubscription)(tx, productKey);
|
|
528
644
|
if (!current)
|
|
529
645
|
throw new shared_1.NotFoundError('Nenhuma assinatura para este tenant');
|
|
646
|
+
// Idempotência: cancelar o que já está cancelado devolve o estado, sem erro
|
|
647
|
+
// e sem novo evento — inclusive quando dois pedidos correm em paralelo.
|
|
530
648
|
if (current.status === 'canceled')
|
|
531
649
|
return current;
|
|
532
650
|
const { subscription, domainEvents } = (0, reconcile_js_1.cancelSubscription)(current, nowIso);
|
|
533
|
-
const row = await (0,
|
|
651
|
+
const row = await (0, repository_js_3.upsertSubscription)(tx, {
|
|
534
652
|
tenantId: ctx.tenantId,
|
|
535
653
|
planKey: current.planKey,
|
|
536
654
|
subscription,
|
|
537
655
|
});
|
|
538
|
-
await (0,
|
|
656
|
+
await (0, repository_js_3.appendDomainEvents)(tx, row.rowId, domainEvents);
|
|
539
657
|
await syncTenantStatus(tx, ctx.tenantId, subscription.status);
|
|
540
658
|
await (0, audit_js_1.appendAudit)(tx, {
|
|
541
659
|
actorId: ctx.userId,
|
|
542
660
|
action: 'subscription_canceled',
|
|
543
661
|
resourceType: 'saas_subscription',
|
|
544
662
|
resourceId: row.rowId,
|
|
663
|
+
// Registra o que aconteceu no gateway: auditoria de cancelamento sem isso
|
|
664
|
+
// não distingue "cancelei a recorrência" de "não havia recorrência".
|
|
665
|
+
diff: { providerOutcome, productKey },
|
|
545
666
|
});
|
|
546
667
|
return row;
|
|
547
668
|
});
|
|
@@ -552,7 +673,7 @@ async function cancelForTenant(db, ctx, nowIso) {
|
|
|
552
673
|
* devolve o checkout; em modo 'disabled' a reativação é manual (backoffice).
|
|
553
674
|
*/
|
|
554
675
|
async function reactivateForTenant(db, ctx, source, nowIso, productKey = plans_js_1.DEFAULT_PRODUCT_KEY) {
|
|
555
|
-
const sub = await (0, context_js_1.withContext)(db, ctx, (tx) => (0,
|
|
676
|
+
const sub = await (0, context_js_1.withContext)(db, ctx, (tx) => (0, repository_js_3.getSubscription)(tx, productKey));
|
|
556
677
|
if (!sub)
|
|
557
678
|
throw new shared_1.NotFoundError('Nenhuma assinatura para este tenant');
|
|
558
679
|
if (sub.status === 'active' || sub.status === 'trialing') {
|
|
@@ -562,10 +683,10 @@ async function reactivateForTenant(db, ctx, source, nowIso, productKey = plans_j
|
|
|
562
683
|
}
|
|
563
684
|
// ── Backoffice (operadora) ───────────────────────────────────────────────────
|
|
564
685
|
async function backofficeListSubscriptions(db, filter = {}) {
|
|
565
|
-
return (0,
|
|
686
|
+
return (0, repository_js_3.withOperatorContext)(db, (tx) => (0, repository_js_3.listAllSubscriptions)(tx, filter));
|
|
566
687
|
}
|
|
567
688
|
async function backofficeOverview(db) {
|
|
568
|
-
return (0,
|
|
689
|
+
return (0, repository_js_3.withOperatorContext)(db, (tx) => (0, repository_js_3.backofficeSummary)(tx));
|
|
569
690
|
}
|
|
570
691
|
async function backofficeListWebhookEvents(db, limit = 100) {
|
|
571
692
|
const rows = await db `
|
|
@@ -590,12 +711,12 @@ async function backofficeListWebhookEvents(db, limit = 100) {
|
|
|
590
711
|
* nenhuma transição de estado fora do domínio puro.
|
|
591
712
|
*/
|
|
592
713
|
async function backofficeActivateSubscription(db, operatorEmail, tenantId, planKey, nowIso) {
|
|
593
|
-
const plan = await (0,
|
|
714
|
+
const plan = await (0, repository_js_3.getPlan)(db, planKey);
|
|
594
715
|
if (!plan)
|
|
595
716
|
throw new shared_1.ValidationError(`Plano desconhecido: ${planKey}`);
|
|
596
717
|
return (0, context_js_1.withContext)(db, { tenantId }, async (tx) => {
|
|
597
|
-
await (0,
|
|
598
|
-
const current = await (0,
|
|
718
|
+
await (0, repository_js_3.lockTenantBilling)(tx, tenantId);
|
|
719
|
+
const current = await (0, repository_js_3.getSubscription)(tx);
|
|
599
720
|
const manualEvent = {
|
|
600
721
|
externalEventId: `manual_${(0, shared_1.uuidv7)()}`,
|
|
601
722
|
eventType: 'manual.activation',
|
|
@@ -616,14 +737,14 @@ async function backofficeActivateSubscription(db, operatorEmail, tenantId, planK
|
|
|
616
737
|
event: manualEvent,
|
|
617
738
|
now: nowIso,
|
|
618
739
|
});
|
|
619
|
-
const row = await (0,
|
|
740
|
+
const row = await (0, repository_js_3.upsertSubscription)(tx, {
|
|
620
741
|
tenantId,
|
|
621
742
|
planKey: plan.key,
|
|
622
743
|
subscription,
|
|
623
744
|
provider: 'manual',
|
|
624
745
|
});
|
|
625
|
-
await (0,
|
|
626
|
-
await (0,
|
|
746
|
+
await (0, repository_js_3.appendDomainEvents)(tx, row.rowId, domainEvents);
|
|
747
|
+
await (0, repository_js_3.upsertInvoice)(tx, {
|
|
627
748
|
tenantId,
|
|
628
749
|
subscriptionRowId: row.rowId,
|
|
629
750
|
provider: 'manual',
|
|
@@ -652,14 +773,14 @@ async function backofficeActivateSubscription(db, operatorEmail, tenantId, planK
|
|
|
652
773
|
async function retryFailedWebhookEvents(db, source, nowIso, limit = 25, productKey = plans_js_1.DEFAULT_PRODUCT_KEY) {
|
|
653
774
|
const cfg = asRegistry(source).resolve({ productKey });
|
|
654
775
|
const provider = providerFor(cfg);
|
|
655
|
-
const failed = await (0,
|
|
776
|
+
const failed = await (0, repository_js_3.listFailedWebhookEvents)(db, limit);
|
|
656
777
|
let recovered = 0;
|
|
657
778
|
for (const row of failed) {
|
|
658
779
|
if (row.provider !== provider.name)
|
|
659
780
|
continue;
|
|
660
781
|
const event = provider.parseWebhookEvent(row.payload);
|
|
661
782
|
if (!event) {
|
|
662
|
-
await (0,
|
|
783
|
+
await (0, repository_js_3.markWebhookEvent)(db, row.id, 'ignored', null, 'payload não parseável no reprocessamento');
|
|
663
784
|
continue;
|
|
664
785
|
}
|
|
665
786
|
const result = await reconcileStoredWebhookEvent(db, provider, event, row.id, nowIso, productKey);
|
|
@@ -703,7 +824,7 @@ async function runBillingCron(db, source, nowIso) {
|
|
|
703
824
|
report.webhooksRetried += retry.retried;
|
|
704
825
|
report.webhooksRecovered += retry.recovered;
|
|
705
826
|
}
|
|
706
|
-
const subs = await (0,
|
|
827
|
+
const subs = await (0, repository_js_3.withOperatorContext)(db, (tx) => (0, repository_js_3.listSubscriptionsForCron)(tx, today));
|
|
707
828
|
report.examined = subs.length;
|
|
708
829
|
for (const sub of subs) {
|
|
709
830
|
// Isolamento de falha: um tenant quebrado não pode derrubar a régua dos demais.
|
|
@@ -713,8 +834,8 @@ async function runBillingCron(db, source, nowIso) {
|
|
|
713
834
|
// assinatura — nunca de uma configuração global compartilhada.
|
|
714
835
|
const cfg = registry.resolve({ productKey: sub.productKey, tenantId: sub.tenantId });
|
|
715
836
|
await (0, context_js_1.withContext)(db, { tenantId: sub.tenantId }, async (tx) => {
|
|
716
|
-
await (0,
|
|
717
|
-
const loaded = await (0,
|
|
837
|
+
await (0, repository_js_3.lockTenantBilling)(tx, sub.tenantId);
|
|
838
|
+
const loaded = await (0, repository_js_3.getSubscription)(tx, sub.productKey);
|
|
718
839
|
if (!loaded)
|
|
719
840
|
return; // sumiu entre o scan e o lock (ex.: tenant removido)
|
|
720
841
|
let current = loaded;
|
|
@@ -756,30 +877,30 @@ async function runBillingCron(db, source, nowIso) {
|
|
|
756
877
|
...subscription,
|
|
757
878
|
currentPeriodEnd: subscription.currentPeriodEnd ?? reference,
|
|
758
879
|
};
|
|
759
|
-
const row = await (0,
|
|
880
|
+
const row = await (0, repository_js_3.upsertSubscription)(tx, {
|
|
760
881
|
tenantId: current.tenantId,
|
|
761
882
|
planKey: current.planKey,
|
|
762
883
|
subscription: next,
|
|
763
884
|
});
|
|
764
|
-
await (0,
|
|
885
|
+
await (0, repository_js_3.appendDomainEvents)(tx, row.rowId, domainEvents);
|
|
765
886
|
await (0, audit_js_1.appendAudit)(tx, {
|
|
766
887
|
actorType: 'automation',
|
|
767
888
|
action: trialExpired ? 'trial_expired' : 'period_expired',
|
|
768
889
|
resourceType: 'saas_subscription',
|
|
769
890
|
resourceId: row.rowId,
|
|
770
891
|
});
|
|
771
|
-
current = (await (0,
|
|
892
|
+
current = (await (0, repository_js_3.getSubscription)(tx));
|
|
772
893
|
}
|
|
773
894
|
}
|
|
774
895
|
// 2. Régua de inadimplência (idempotente por stepKey + reference_date).
|
|
775
896
|
if (current.status === 'past_due') {
|
|
776
897
|
const reference = current.currentPeriodEnd ?? current.trialEndsAt ?? today;
|
|
777
|
-
const executed = await (0,
|
|
898
|
+
const executed = await (0, repository_js_3.listExecutedDunningSteps)(tx, current.rowId, reference);
|
|
778
899
|
const events = (0, dunning_js_1.dunningStepsAsEvents)({ ...current, currentPeriodEnd: reference }, today, executed);
|
|
779
900
|
for (const ev of events) {
|
|
780
901
|
const stepKey = ev.data.dunningStep?.stepKey ??
|
|
781
902
|
`step_${ev.sequence}`;
|
|
782
|
-
await (0,
|
|
903
|
+
await (0, repository_js_3.recordDunningStep)(tx, {
|
|
783
904
|
tenantId: current.tenantId,
|
|
784
905
|
subscriptionRowId: current.rowId,
|
|
785
906
|
stepKey,
|
|
@@ -788,9 +909,9 @@ async function runBillingCron(db, source, nowIso) {
|
|
|
788
909
|
report.dunningStepsExecuted += 1;
|
|
789
910
|
}
|
|
790
911
|
if (events.length > 0) {
|
|
791
|
-
await (0,
|
|
912
|
+
await (0, repository_js_3.appendDomainEvents)(tx, current.rowId, events);
|
|
792
913
|
dunningEmailTo = await ownerEmailForTenant(tx, current.tenantId);
|
|
793
|
-
await (0,
|
|
914
|
+
await (0, repository_js_3.upsertSubscription)(tx, {
|
|
794
915
|
tenantId: current.tenantId,
|
|
795
916
|
planKey: current.planKey,
|
|
796
917
|
subscription: { ...current, sequence: current.sequence + events.length },
|
|
@@ -818,11 +939,15 @@ async function runBillingCron(db, source, nowIso) {
|
|
|
818
939
|
});
|
|
819
940
|
// Envio FORA da transação (best-effort com timeout): rede nunca segura o banco.
|
|
820
941
|
if (dunningEmailTo) {
|
|
821
|
-
const sent = await (0,
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
942
|
+
const sent = await (0, transactional_outbound_js_1.sendTransactionalOutbound)({
|
|
943
|
+
kind: 'subscription_dunning',
|
|
944
|
+
apiKey: cfg.resendApiKey,
|
|
945
|
+
message: {
|
|
946
|
+
from: cfg.emailFrom,
|
|
947
|
+
to: dunningEmailTo,
|
|
948
|
+
subject: 'Sua assinatura Baruk está com pagamento pendente',
|
|
949
|
+
html: `<p>Olá,</p><p>Identificamos uma pendência na assinatura da sua conta Baruk.</p><p>Regularize para manter seus serviços ativos: <a href="${cfg.webBaseUrl}/assinatura">gerenciar assinatura</a>.</p><p>Se o pagamento já foi feito, desconsidere este aviso.</p>`,
|
|
950
|
+
},
|
|
826
951
|
});
|
|
827
952
|
if (sent)
|
|
828
953
|
report.emailsSent += 1;
|