Franchise Created
A franchise unit was created in CNA Nexus by activating an opening contract. Full snapshot of the unit; cna-one mirrors it, its address and its partners as employees.
Overview
Fact: a franchise unit now exists in Nexus. The payload is a full snapshot of the aggregate re-read after commit: unit data, statuses, category, economic group, region, address, partners (without roles) and products.
When it is published. CNA NexusCNA NexusServicev1.0.0Franchise network back-office (franchises, economic groups, partners, contracts and amendments, document storage, AI doc...PublishesInviteUser, ContractActivationRequested +15SubscribesContractActivationRequested, AmendmentApplyRequested +5Ownercna-platformMapRepoView docs, in createFranchiseForOpening, the only place a franchise is created: the activation of an OPENING ContractContractEntityv1.0.0A franchise contract in CNA Nexus - opening, renewal or resale - uploaded as a document, analysed by AI, reviewed by a p...Ownercna-platformView docs with no franchise yet (see Contract Activation RequestedContract Activation RequestedEventv1.0.0A user saved a contract for activation. cna-nexus's activation consumer turns it ACTIVE and creates or updates the franc...Ownercna-platformSchemaMapView docs). Registered with manager.afterCommit(), so it goes out only after the unit, its brand, address, territory and partners are committed. The same commit also emits one Franchise Partner AddedFranchise Partner AddedEventv1.2.0A person became a partner of a franchise unit, with their roles and whether they are a primary contact of the unit. One ...Ownercna-platformSchemaMapView docs per partner.
What the consumer does. CNA OneCNA OneServicev1.0.0Franchise operating system (franchises and employees, pricing, products and learning books, school operations, receivabl...PublishesGrantApplicationAccess, EmployeeCreated +19SubscribesInviteUser, FranchiseCreated +17Ownercna-platformMapRepoView docs (franchiseConsumer, handler syncFranchise), in four blocks:
- Franchise: requires and validates
cnpjandlegalName, checks name, slug and e-mail uniqueness, resolveseconomicGroup.id(it must have been mirrored by Economic Group CreatedEconomic Group CreatedEventv1.0.0An economic group was created in CNA Nexus. cna-one mirrors it by id so that franchises can reference it.Ownercna-platformSchemaMapView docs first, otherwise the message fails), maps the enums onto cna-one’s own, derivesstatus(ACTIVEwhenoperationalStatusisOPERATIONAL), keeps only the distinct product sub-categories, and upserts byid. Since 1.1.0 the snapshot also carries the unit’s primary contact (email,whatsapp,phone), which cna-one mirrors into the franchise; the e-mail must be unique among its franchises. Since 2.0.0 the day the unit started and stopped operating travel as calendar days,operationalStartOnandoperationalEndOn(YYYY-MM-DD), in place of theoperationalStartAtandoperationalEndAtinstants; cna-one ignores both. Since 2.1.0taxRegimemay also beMEI, the regime of a microfranchise; cna-one’s enum does not list it yet, so such a snapshot fails this block (unknown_tax_regime). A unit is created with no tax regime, soMEIreaches this event only on a replay of a later snapshot. If this block fails nothing is written. - Address: skipped when absent; requires street, number, neighborhood, postal code and an IBGE
cityIdknown to cna-one; upserts the unit’s address in place. Failure here is logged and skipped. Since 1.2.0 the block also carriescountryId(ISO 3166-1 alpha-2, always present),foreignCityandforeignState(filled only for an address outside Brazil, wherecityId,cityNameandstateare null) and the coordinateslatitudeandlongitudeas decimal text. cna-one ignores the first three; since cna-br/cna-one#902 it turns the coordinates into a PostGIS point when both arrive and are on the globe, and logs half a pair, a value that is not a number or a coordinate off the globe and stores the address without a point. - Cash accounts (cna-br/cna-one#1185): every mirrored franchise gets, once, the physical account and the bank account it receives its payments in; a franchise that already has them keeps them. Failure here is reported and skipped.
- Partners: one per distinct document; each becomes a person, an employee, an employment contract with the
FRANCHISEEjob role and an active staff link, in one transaction. cna-one then publishes its own Employee CreatedEmployee CreatedEventv1.0.0An employee was created in CNA One, with the person it points at. Consumed by cna-auth to provision the account and the ...Ownercna-platformSchemaMapView docs (new employee) or Employee UpdatedEmployee UpdatedEventv1.0.0An employee or the person it points at changed in CNA One. Consumed by cna-auth to update the account and the user, incl...Ownercna-platformSchemaMapView docs (already known), which is what provisions the login in cna-auth. With cna-br/cna-one#1489 (not in production yet) it also publishes a Grant Application AccessGrant Application AccessCommandv1.0.0Asks CNA Auth to give a person access to an application, provisioning the account and user when they are new. Published ...Ownercna-platformSchemaMapView docs for cna-one right after either one, for every partner identified by a CPF: the grant is what makes cna-auth send the first-access e-mail. The snapshot is never run again: a partner whose person another consumer stored during the write, the one failure the Franchise Partner AddedFranchise Partner AddedEventv1.2.0A person became a partner of a franchise unit, with their roles and whether they are a primary contact of the unit. One ...Ownercna-platformSchemaMapView docs handler retries, is reported and skipped here like any other, and the next snapshot brings them in. One bad partner is skipped without stopping the others. Since 1.2.0 each partner is identified byid, the person id the Franchise Partner AddedFranchise Partner AddedEventv1.2.0A person became a partner of a franchise unit, with their roles and whether they are a primary contact of the unit. One ...Ownercna-platformSchemaMapView docs family already carries inperson.id; until 1.1.0 the field waspersonId. cna-one never read it: it correlates partners bydocument.
Failures are logged and reported to Sentry, never rethrown.
Kafka
Topic (aggregateRoot) | Franchise |
Message key (routingKey) | payload.id |
| Contract owner | NEXUS |
metadata.event | FranchiseCreated |
| Consumer group | franchise-franchise-events |
Payload schema
Source of truth
export type FranchisePartnerData = { id: string; document: string; documentType: string; name: string; legalName?: string | null; email?: string | null;};
export type FranchiseAddressData = { street?: string | null; number?: string | null; complement?: string | null; neighborhood?: string | null; postalCode?: string | null; cityId?: number | null; cityName?: string | null; state?: string | null; countryId: string; foreignCity?: string | null; foreignState?: string | null; latitude?: string | null; longitude?: string | null;};
export type FranchisePayload = { id: string; name: string; code?: string | null; cnpj?: string | null; legalName?: string | null; email?: string | null; whatsapp?: string | null; phone?: string | null; stateRegistration?: string | null; taxRegime?: string | null; protheusId?: string | null; conectaEnabled: boolean; openingStatus: string; operationalStatus: string; financialStatus?: string | null; operationalStartOn?: string | null; operationalEndOn?: string | null; firstContractStartsOn?: string | null; category: FranchiseCategoryData; economicGroup?: FranchiseEconomicGroupData | null; operationalRegion?: FranchiseOperationalRegionData | null; address?: FranchiseAddressData | null; partners: FranchisePartnerData[]; products: FranchiseProductData[];};
export class FranchiseCreated extends Event<FranchisePayload> { static readonly owner = 'NEXUS'; static readonly aggregateRoot = 'Franchise'; static readonly routingKey = 'id'; static readonly version = '2.1.0';}Known drift
cna-one api/app/events/nexus/franchise/FranchiseCreated.ts differs from the canonical type. Its copy was aligned to 1.1.0 by cna-br/cna-one#962 and to 1.2.0 by cna-br/cna-one#969 (both in production since v0.4.0) and has none of the 2.0.0 and 2.1.0 changes, so cna-one’s receives is pinned to 1.2.0 until those alignments are in production. Only the tax regime changes what cna-one does: a MEI value fails the sync, while the operational dates below are ignored. Observed 2026-11-17 on cna-one v0.4.0.
| Field | cna-nexus (2.1.0) | cna-one (v0.4.0, 1.2.0) |
|---|---|---|
| operational start and end | operationalStartOn, operationalEndOn (YYYY-MM-DD) | operationalStartAt, operationalEndAt (ignored) |
taxRegime values | SIMPLES_NACIONAL, LUCRO_PRESUMIDO, LUCRO_REAL, MEI | without MEI (rejected) |
Custom properties
| Property | Value |
|---|---|
| Contract Ownerx-contract-owner | NEXUS |
| Kafka Topicx-kafka-topic | Franchise |
| Message Keyx-message-key | id |
| Sourcex-source | cna-nexus api/app/events/nexus/franchise/FranchiseCreated.ts |
| Driftx-drift | cna-one's copy of FranchisePayload matches 1.2.0 (cna-br/cna-one#962 and cna-br/cna-one#969, in production since v0.4.0) and lags 2.0.0 and 2.1.0: the operational dates are still operationalStartAt and operationalEndAt; its FranchiseTaxRegime lacks MEI, so a snapshot with that taxRegime fails the sync. cna-one's receives is pinned to 1.2.0 until the 2.0.0 and 2.1.0 alignments are in production. |
Franchise id (UUID). Kafka message key; cna-one mirrors the unit under this id.
Unit name.
Internal unit code, unique.
Company registration number as stored (no normalisation). cna-one requires and validates it.
Legal company name. cna-one requires it.
Primary contact e-mail of the unit (franchises.email in cna-nexus, not unique there). cna-one mirrors it and requires it to be unique across its franchises.
WhatsApp number in E.164 (+5511912345678). Mirrored by cna-one.
^\+[1-9]\d{6,14}$Primary contact phone in E.164. Mirrored by cna-one.
^\+[1-9]\d{6,14}$State registration number.
Tax regime (FranchiseTaxRegime), typed as string in the class.
SIMPLES_NACIONAL LUCRO_PRESUMIDO LUCRO_REAL MEI Id in the Protheus ERP.
Inter-school sharing enabled.
Lifecycle stage (FranchiseOpeningStatus), typed as string in the class.
CREATED BUILT TRAINED SUSPENDED UNDER_REVIEW DEFAULTINGOperational status (FranchiseOperationalStatus). cna-one maps OPERATIONAL to ACTIVE, anything else to INACTIVE.
OPERATIONAL NON_OPERATIONAL UNDER_DEVELOPMENTFinancial standing (FranchiseFinancialStatus).
ACTIVE INACTIVE SUSPENDED DEFAULTING UNDER_REVIEW YYYY-MM-DD day the unit started operating, or null. Ignored by cna-one.
YYYY-MM-DD day the unit stopped operating, or null. Ignored by cna-one.
YYYY-MM-DD start of the earliest opening contract, or null. Ignored by cna-one.
Size/type category of the unit.
Economic group of the unit, or null. cna-one requires the group to have been mirrored first (EconomicGroupCreated).
Operational region, or null.
Unit address, or null. cna-one requires street, number, neighborhood, postalCode and cityId to mirror it; it ignores countryId, foreignCity, foreignState, latitude and longitude.
People behind the unit. May be empty. Roles are not included; cna-one turns each into a FRANCHISEE employee.
Products the unit is enabled to sell. cna-one keeps only the distinct sub-categories.