@12-apps/fiscal 1.0.0 → 1.1.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/README.md +152 -7
- package/dist/chunk-27B4HNO6.js +574 -0
- package/dist/chunk-27B4HNO6.js.map +1 -0
- package/dist/chunk-3SDXLSG4.js +24 -0
- package/dist/chunk-3SDXLSG4.js.map +1 -0
- package/dist/chunk-ALABGVPO.js +247 -0
- package/dist/chunk-ALABGVPO.js.map +1 -0
- package/dist/chunk-FOFIN5M7.js +14 -0
- package/dist/chunk-FOFIN5M7.js.map +1 -0
- package/dist/chunk-HQ2NXSTX.js +85 -0
- package/dist/chunk-HQ2NXSTX.js.map +1 -0
- package/dist/chunk-PNTKG3DZ.js +47 -0
- package/dist/chunk-PNTKG3DZ.js.map +1 -0
- package/dist/chunk-RRFKYVLZ.js +192 -0
- package/dist/chunk-RRFKYVLZ.js.map +1 -0
- package/dist/chunk-V5ZQAAJT.js +210 -0
- package/dist/chunk-V5ZQAAJT.js.map +1 -0
- package/dist/chunk-X6MRDUYH.js +21 -0
- package/dist/chunk-X6MRDUYH.js.map +1 -0
- package/dist/chunk-XQGW5HUG.js +30 -0
- package/dist/chunk-XQGW5HUG.js.map +1 -0
- package/dist/context-ChnWR4Kb.d.ts +455 -0
- package/dist/danfe/en-US.d.ts +12 -0
- package/dist/danfe/en-US.js +51 -0
- package/dist/danfe/en-US.js.map +1 -0
- package/dist/danfe/index.d.ts +50 -0
- package/dist/danfe/index.js +18 -0
- package/dist/danfe/index.js.map +1 -0
- package/dist/danfe/pt-BR.d.ts +11 -0
- package/dist/danfe/pt-BR.js +51 -0
- package/dist/danfe/pt-BR.js.map +1 -0
- package/dist/documents/index.d.ts +169 -0
- package/dist/documents/index.js +1228 -0
- package/dist/documents/index.js.map +1 -0
- package/dist/engine/index.d.ts +3 -246
- package/dist/http.d.ts +73 -0
- package/dist/http.js +16 -0
- package/dist/http.js.map +1 -0
- package/dist/issuer/index.d.ts +43 -0
- package/dist/issuer/index.js +131 -0
- package/dist/issuer/index.js.map +1 -0
- package/dist/jobs.d.ts +74 -0
- package/dist/jobs.js +22 -0
- package/dist/jobs.js.map +1 -0
- package/dist/labels-BNvflT0h.d.ts +44 -0
- package/dist/manifest/index.d.ts +30 -16
- package/dist/manifest/index.js +11 -17
- package/dist/manifest/index.js.map +1 -1
- package/dist/manifest/server.d.ts +57 -0
- package/dist/manifest/server.js +25 -0
- package/dist/manifest/server.js.map +1 -0
- package/dist/notifications.d.ts +93 -0
- package/dist/notifications.js +41 -0
- package/dist/notifications.js.map +1 -0
- package/dist/port-DpRFK56U.d.ts +238 -0
- package/dist/sale/index.d.ts +243 -0
- package/dist/sale/index.js +1 -0
- package/dist/sale/index.js.map +1 -0
- package/dist/service-KTjH7AxW.d.ts +139 -0
- package/dist/sidecar/index.d.ts +216 -0
- package/dist/sidecar/index.js +8 -0
- package/dist/sidecar/index.js.map +1 -0
- package/dist/types-B1b8LIWX.d.ts +247 -0
- package/package.json +63 -5
- package/prisma/fiscal.prisma +158 -0
- package/prisma/migrations/20261113220000_fiscal_documents/migration.sql +201 -0
- package/sidecar/.dockerignore +5 -0
- package/sidecar/Dockerfile +68 -0
- package/sidecar/README.md +149 -0
- package/sidecar/composer.json +30 -0
- package/sidecar/composer.lock +2224 -0
- package/sidecar/docker/apache.conf +14 -0
- package/sidecar/docker/icp-brasil.pem +8031 -0
- package/sidecar/docker/mpm.conf +17 -0
- package/sidecar/docker/openssl.cnf +16 -0
- package/sidecar/docker/php.ini +19 -0
- package/sidecar/public/index.php +15 -0
- package/sidecar/schema/sale-for-document.schema.json +401 -0
- package/sidecar/src/ErrorClass.php +31 -0
- package/sidecar/src/Http/Request.php +48 -0
- package/sidecar/src/Http/Response.php +32 -0
- package/sidecar/src/Http/Router.php +59 -0
- package/sidecar/src/Kernel.php +99 -0
- package/sidecar/src/Module.php +31 -0
- package/sidecar/src/Nfe/Classifier.php +89 -0
- package/sidecar/src/Nfe/Credentials.php +52 -0
- package/sidecar/src/Nfe/DocumentMapper.php +383 -0
- package/sidecar/src/Nfe/DocumentSchema.php +39 -0
- package/sidecar/src/Nfe/Input.php +125 -0
- package/sidecar/src/Nfe/Model.php +17 -0
- package/sidecar/src/Nfe/NfeModule.php +62 -0
- package/sidecar/src/Nfe/NfeService.php +504 -0
- package/sidecar/src/Nfe/Sefaz.php +49 -0
- package/sidecar/src/Nfe/SefazReply.php +81 -0
- package/sidecar/src/Nfe/Transport/CurlTransport.php +198 -0
- package/sidecar/src/Nfe/Transport/SoapAdapter.php +57 -0
- package/sidecar/src/Nfe/Transport/Transport.php +20 -0
- package/sidecar/src/Nfe/Transport/TransportFailure.php +42 -0
- package/sidecar/src/RequestLog.php +54 -0
- package/sidecar/src/ServiceError.php +69 -0
- package/src/danfe/en-US.ts +53 -0
- package/src/danfe/index.ts +11 -0
- package/src/danfe/labels.ts +49 -0
- package/src/danfe/pt-BR.ts +52 -0
- package/src/danfe/render.ts +265 -0
- package/src/danfe/xml.ts +45 -0
- package/src/documents/context.ts +260 -0
- package/src/documents/errors.ts +41 -0
- package/src/documents/helpers.ts +128 -0
- package/src/documents/index.ts +39 -0
- package/src/documents/lines.ts +63 -0
- package/src/documents/machine-steps.ts +260 -0
- package/src/documents/machine.ts +128 -0
- package/src/documents/memory.ts +138 -0
- package/src/documents/nfe-proc.ts +51 -0
- package/src/documents/ports.ts +130 -0
- package/src/documents/profile-input.ts +168 -0
- package/src/documents/profile.ts +98 -0
- package/src/documents/service-profile.ts +104 -0
- package/src/documents/service.ts +296 -0
- package/src/documents/settle.ts +121 -0
- package/src/documents/signing.ts +61 -0
- package/src/documents/sql-rows.ts +180 -0
- package/src/documents/sql-store.ts +242 -0
- package/src/documents/sql.ts +18 -0
- package/src/documents/steps.ts +173 -0
- package/src/documents/tests/integration/pglite.ts +73 -0
- package/src/documents/types.ts +193 -0
- package/src/http.ts +264 -0
- package/src/issuer/index.ts +9 -0
- package/src/issuer/port.ts +109 -0
- package/src/issuer/sidecar.ts +171 -0
- package/src/jobs.ts +115 -0
- package/src/manifest/index.ts +25 -16
- package/src/manifest/server.ts +20 -0
- package/src/notifications.ts +120 -0
- package/src/sale/index.ts +8 -0
- package/src/sale/types.ts +292 -0
- package/src/sidecar/index.ts +9 -0
- package/src/sidecar/types.ts +243 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reference {@link FiscalStore}: in memory, for tests and harnesses —
|
|
3
|
+
* the role `createMemory*Store` plays in the packages that own storage seams.
|
|
4
|
+
* It keeps the same promises as the SQL store (`./sql-store`): a draw and the
|
|
5
|
+
* insert built from it commit together (a `build` that throws leaves the
|
|
6
|
+
* counter untouched), a replaced document is advanced before its replacement
|
|
7
|
+
* is inserted, and a subject has at most one live document per model.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { FiscalDocumentError } from "./errors";
|
|
11
|
+
import type { FiscalStore, NumberRequest } from "./ports";
|
|
12
|
+
import type { EmitterProfile, IssuingPoint } from "./profile";
|
|
13
|
+
import { type FiscalDocument, type FiscalDocumentEvent, OWED_VOIDS, isLive } from "./types";
|
|
14
|
+
|
|
15
|
+
const MAX_NUMBER = 999_999_999;
|
|
16
|
+
|
|
17
|
+
export interface MemoryFiscalStore extends FiscalStore {
|
|
18
|
+
/** Every event, in order, for assertions. */
|
|
19
|
+
readonly events: FiscalDocumentEvent[];
|
|
20
|
+
/** The next number each counter would hand out, keyed `cnpj|environment|model|series`. */
|
|
21
|
+
readonly counters: Map<string, number>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function counterKey(request: Pick<NumberRequest, "issuerCnpj" | "environment" | "model" | "series">): string {
|
|
25
|
+
return `${request.issuerCnpj}|${request.environment}|${request.model}|${request.series}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface State {
|
|
29
|
+
readonly counters: Map<string, number>;
|
|
30
|
+
readonly seriesOwner: Map<string, string>;
|
|
31
|
+
readonly documents: Map<string, FiscalDocument>;
|
|
32
|
+
readonly events: FiscalDocumentEvent[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Open a series' counter in both environments; a series belongs to one issuing point. */
|
|
36
|
+
function openCounter(state: State, point: IssuingPoint, issuerCnpj: string, series: number, first: number): void {
|
|
37
|
+
for (const environment of ["homologacao", "producao"] as const) {
|
|
38
|
+
const key = counterKey({ issuerCnpj, environment, model: point.model, series });
|
|
39
|
+
const owner = state.seriesOwner.get(key);
|
|
40
|
+
if (owner !== undefined && owner !== point.id) {
|
|
41
|
+
throw new FiscalDocumentError("INVALID_INPUT", `series ${series} already belongs to issuing point ${owner}.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const environment of ["homologacao", "producao"] as const) {
|
|
45
|
+
const key = counterKey({ issuerCnpj, environment, model: point.model, series });
|
|
46
|
+
state.seriesOwner.set(key, point.id);
|
|
47
|
+
state.counters.set(key, first);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isDue(document: FiscalDocument, now: string): boolean {
|
|
52
|
+
if (document.attention || document.nextAttemptAt === null || document.nextAttemptAt > now) return false;
|
|
53
|
+
return document.status === "PENDING" || document.status === "SUBMITTED" || OWED_VOIDS.includes(document.numberVoid ?? "INUTILIZED");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function save(state: State, previous: FiscalDocument, transition: { document: FiscalDocument; event: FiscalDocumentEvent }): boolean {
|
|
57
|
+
const stored = state.documents.get(previous.id);
|
|
58
|
+
if (stored === undefined || stored.updatedAt !== previous.updatedAt || stored.status !== previous.status) return false;
|
|
59
|
+
state.documents.set(transition.document.id, transition.document);
|
|
60
|
+
state.events.push(transition.event);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function hasLive(state: State, document: FiscalDocument): boolean {
|
|
65
|
+
return [...state.documents.values()].some(
|
|
66
|
+
(other) => other.ownerId === document.ownerId && other.subjectId === document.subjectId && other.model === document.model && isLive(other),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function createMemoryFiscalStore(): MemoryFiscalStore {
|
|
71
|
+
const profiles = new Map<string, EmitterProfile>();
|
|
72
|
+
const points = new Map<string, IssuingPoint>();
|
|
73
|
+
const state: State = { counters: new Map(), seriesOwner: new Map(), documents: new Map(), events: [] };
|
|
74
|
+
const ordered = (key: (d: FiscalDocument) => string) =>
|
|
75
|
+
[...state.documents.values()].sort((a, b) => key(a).localeCompare(key(b)));
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
events: state.events,
|
|
79
|
+
counters: state.counters,
|
|
80
|
+
getProfile: async (ownerId) => profiles.get(ownerId) ?? null,
|
|
81
|
+
saveProfile: async (profile) => void profiles.set(profile.ownerId, profile),
|
|
82
|
+
async getIssuingPoint(ownerId, id) {
|
|
83
|
+
const point = points.get(id);
|
|
84
|
+
return point?.ownerId === ownerId ? point : null;
|
|
85
|
+
},
|
|
86
|
+
listIssuingPoints: async (ownerId) => [...points.values()].filter((point) => point.ownerId === ownerId),
|
|
87
|
+
async createIssuingPoint(point, issuerCnpj, firstNumber) {
|
|
88
|
+
if (points.has(point.id)) throw new FiscalDocumentError("INVALID_INPUT", `issuing point ${point.id} exists.`);
|
|
89
|
+
openCounter(state, point, issuerCnpj, point.onlineSeries, firstNumber.online);
|
|
90
|
+
if (point.contingencySeries !== null) openCounter(state, point, issuerCnpj, point.contingencySeries, firstNumber.contingency);
|
|
91
|
+
points.set(point.id, point);
|
|
92
|
+
},
|
|
93
|
+
async createDocument(request, build, replace) {
|
|
94
|
+
const key = counterKey(request);
|
|
95
|
+
const number = state.counters.get(key);
|
|
96
|
+
if (number === undefined || state.seriesOwner.get(key) !== request.issuingPointId) {
|
|
97
|
+
throw new FiscalDocumentError("NOT_FOUND", `no counter for series ${request.series} on issuing point ${request.issuingPointId}.`);
|
|
98
|
+
}
|
|
99
|
+
if (number > MAX_NUMBER) throw new FiscalDocumentError("SERIES_EXHAUSTED", `series ${request.series} has no number left.`);
|
|
100
|
+
const document = build(number);
|
|
101
|
+
if (state.documents.has(document.id)) throw new FiscalDocumentError("INVALID_INPUT", `document ${document.id} exists.`);
|
|
102
|
+
const snapshot = new Map(state.documents);
|
|
103
|
+
if (replace !== undefined && !save(state, replace.previous, replace.transition)) {
|
|
104
|
+
throw new FiscalDocumentError("CONFLICT", `document ${replace.previous.id} moved before it was replaced.`);
|
|
105
|
+
}
|
|
106
|
+
if (hasLive(state, document)) {
|
|
107
|
+
// The replace and the insert are one transaction: undo the replace.
|
|
108
|
+
state.documents.clear();
|
|
109
|
+
for (const [id, kept] of snapshot) state.documents.set(id, kept);
|
|
110
|
+
if (replace !== undefined) state.events.pop();
|
|
111
|
+
throw new FiscalDocumentError("SUBJECT_HAS_DOCUMENT", `subject ${document.subjectId} already has a live ${document.model}.`);
|
|
112
|
+
}
|
|
113
|
+
state.counters.set(key, number + 1);
|
|
114
|
+
state.documents.set(document.id, document);
|
|
115
|
+
return document;
|
|
116
|
+
},
|
|
117
|
+
async getDocument(ownerId, id) {
|
|
118
|
+
const document = state.documents.get(id);
|
|
119
|
+
return document?.ownerId === ownerId ? document : null;
|
|
120
|
+
},
|
|
121
|
+
listBySubject: async (ownerId, subjectId, model) =>
|
|
122
|
+
ordered((d) => d.createdAt).filter((d) => d.ownerId === ownerId && d.subjectId === subjectId && d.model === model),
|
|
123
|
+
listEvents: async (documentId) => state.events.filter((event) => event.documentId === documentId),
|
|
124
|
+
saveTransition: async (previous, transition) => save(state, previous, transition),
|
|
125
|
+
listDue: async ({ now, limit }) =>
|
|
126
|
+
ordered((d) => d.nextAttemptAt ?? "").filter((document) => isDue(document, now)).slice(0, limit),
|
|
127
|
+
listContingency: async ({ now, limit }) =>
|
|
128
|
+
ordered((d) => d.nextAttemptAt ?? "")
|
|
129
|
+
.filter((d) => d.status === "CONTINGENCY" && !d.attention && d.nextAttemptAt !== null && d.nextAttemptAt <= now)
|
|
130
|
+
.slice(0, limit),
|
|
131
|
+
listContingencyDeadline: async ({ signedBefore, limit }) =>
|
|
132
|
+
ordered((d) => d.createdAt)
|
|
133
|
+
.filter((d) => d.status === "CONTINGENCY" && d.deadlineWarnedAt === null && Date.parse(d.contingency?.since ?? "") < Date.parse(signedBefore))
|
|
134
|
+
.slice(0, limit),
|
|
135
|
+
listExpiringCertificates: async (before) =>
|
|
136
|
+
[...profiles.values()].filter((p) => p.certificateExpiresAt !== null && p.certificateExpiresAt < before),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `nfeProc` — what an authorised document is stored as — assembled from
|
|
3
|
+
* the signed XML the service built and the `protNFe` a lookup answered, for a
|
|
4
|
+
* document whose sending went unanswered and was then found authorised.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { element } from "../danfe/xml";
|
|
8
|
+
|
|
9
|
+
const PROTOCOL = /<protNFe\b[^>]*>[\s\S]*?<\/protNFe>/;
|
|
10
|
+
const NFE = /<NFe\b[^>]*>[\s\S]*<\/NFe>/;
|
|
11
|
+
/** The signed XML's own digest (`DigestValue`), which SEFAZ quotes back as the protocol's `digVal`. */
|
|
12
|
+
export function digestOf(signedXml: string): string | null {
|
|
13
|
+
return /<DigestValue>([^<]+)<\/DigestValue>/.exec(signedXml)?.[1]?.trim() ?? null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The protocol a SEFAZ reply carries, with its `digVal`, or `null`. */
|
|
17
|
+
export function protocolDigestOf(sefazReply: string): string | null {
|
|
18
|
+
const protocol = PROTOCOL.exec(sefazReply)?.[0];
|
|
19
|
+
const infProt = protocol === undefined ? null : element(protocol, "infProt");
|
|
20
|
+
return infProt === null ? null : (element(infProt, "digVal")?.trim() ?? null);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The `cStat`s of a protocol that authorises (100, 150 late) or denies (110, 301–303) the use of the key. */
|
|
24
|
+
const SETTLING = new Set(["100", "150", "110", "301", "302", "303"]);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `null` unless the reply carries a protocol for exactly this key with a
|
|
28
|
+
* settling status, the signed XML is the document's, AND the protocol's
|
|
29
|
+
* `digVal` is that XML's `DigestValue` — the protocol certifies THAT XML and
|
|
30
|
+
* no other built under the same key (the fiscal service's own `issued()`
|
|
31
|
+
* refuses the same mismatch). Never a guess.
|
|
32
|
+
*/
|
|
33
|
+
/** Whether this protocol certifies this signed XML under this key, with a settling status. */
|
|
34
|
+
function certifies(infProt: string, nfe: string, accessKey: string): boolean {
|
|
35
|
+
const digest = digestOf(nfe);
|
|
36
|
+
return (
|
|
37
|
+
element(infProt, "chNFe") === accessKey &&
|
|
38
|
+
SETTLING.has(element(infProt, "cStat") ?? "") &&
|
|
39
|
+
nfe.includes(`Id="NFe${accessKey}"`) &&
|
|
40
|
+
digest !== null &&
|
|
41
|
+
element(infProt, "digVal")?.trim() === digest
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function assembleNfeProc(input: { readonly signedXml: string; readonly sefazReply: string; readonly accessKey: string }): string | null {
|
|
46
|
+
const protocol = PROTOCOL.exec(input.sefazReply)?.[0];
|
|
47
|
+
const nfe = NFE.exec(input.signedXml)?.[0];
|
|
48
|
+
const infProt = protocol === undefined ? null : element(protocol, "infProt");
|
|
49
|
+
if (protocol === undefined || nfe === undefined || infProt === null || !certifies(infProt, nfe, input.accessKey)) return null;
|
|
50
|
+
return `<?xml version="1.0" encoding="UTF-8"?><nfeProc versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe">${nfe}${protocol}</nfeProc>`;
|
|
51
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ports a host implements for the document module. None has a default:
|
|
3
|
+
* where the bytes live, how a secret is encrypted, what a sale is and where
|
|
4
|
+
* the rows are stored are the host's answers, asked for by name.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { SaleForDocument } from "../sale/types";
|
|
8
|
+
import type { SefazEnvironment } from "../sidecar/types";
|
|
9
|
+
import type { EmitterProfile, IssuingPoint } from "./profile";
|
|
10
|
+
import type { FiscalDocument, FiscalDocumentEvent, FiscalDocumentModel, SeriesKind } from "./types";
|
|
11
|
+
import type { Transition } from "./machine";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Encrypts the certificate, its password and the CSC at rest — the
|
|
15
|
+
* `{ encrypt, decrypt }` shape `@12-apps/payments-backend` takes. Synchronous
|
|
16
|
+
* or not, as the host's cipher is.
|
|
17
|
+
*/
|
|
18
|
+
export interface Cipher {
|
|
19
|
+
encrypt(plaintext: string): string | Promise<string>;
|
|
20
|
+
decrypt(ciphertext: string): string | Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Where the XMLs live (object storage, retained as the law asks: five years). */
|
|
24
|
+
export interface DocumentStorage {
|
|
25
|
+
put(key: string, body: string, contentType: string): Promise<void>;
|
|
26
|
+
get(key: string): Promise<string | null>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The host's sale in the package's neutral shape — everything but what the
|
|
31
|
+
* package fills: the issuer (from the profile), the series and number (from
|
|
32
|
+
* its counter), the key code and the issue time.
|
|
33
|
+
*/
|
|
34
|
+
export type SaleDraft = Omit<SaleForDocument, "series" | "number" | "keyCode" | "issuer" | "issuedAt">;
|
|
35
|
+
|
|
36
|
+
export interface SaleSource {
|
|
37
|
+
saleFor(input: { readonly ownerId: string; readonly subjectId: string; readonly model: FiscalDocumentModel }): Promise<SaleDraft>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Which counter a new document draws from. SEFAZ numbers by the issuer's
|
|
42
|
+
* CNPJ, the model and the series, so the counter is keyed by them: one CNPJ
|
|
43
|
+
* can serve several owners, and they share its series.
|
|
44
|
+
*/
|
|
45
|
+
export interface NumberRequest {
|
|
46
|
+
readonly ownerId: string;
|
|
47
|
+
readonly issuerCnpj: string;
|
|
48
|
+
readonly issuingPointId: string;
|
|
49
|
+
readonly environment: SefazEnvironment;
|
|
50
|
+
readonly model: FiscalDocumentModel;
|
|
51
|
+
readonly seriesKind: SeriesKind;
|
|
52
|
+
readonly series: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The rows. `createPrismaFiscalStore` (`./sql-store`) is the package's own
|
|
57
|
+
* implementation over the host's Prisma client; `createMemoryFiscalStore`
|
|
58
|
+
* the reference for tests. Every method that writes is one transaction:
|
|
59
|
+
*
|
|
60
|
+
* - `createDocument` draws the next number of the series AND inserts the
|
|
61
|
+
* document built from it, together — a refused insert gives the number
|
|
62
|
+
* back, so the sequence has no gap a failed write made. With `replace`, the
|
|
63
|
+
* document it replaces is advanced in the SAME transaction, before the
|
|
64
|
+
* insert, so a crash can never leave both live. A second LIVE document for
|
|
65
|
+
* the same (owner, subject, model) is refused with `SUBJECT_HAS_DOCUMENT`
|
|
66
|
+
* (`isLive`), and nothing is drawn;
|
|
67
|
+
* - `saveTransition` writes the document and appends its event, and refuses
|
|
68
|
+
* (`false`) when the stored row's `updatedAt` or `status` is no longer the
|
|
69
|
+
* one the transition started from, so two workers never both advance it.
|
|
70
|
+
*/
|
|
71
|
+
export interface FiscalStore {
|
|
72
|
+
getProfile(ownerId: string): Promise<EmitterProfile | null>;
|
|
73
|
+
saveProfile(profile: EmitterProfile): Promise<void>;
|
|
74
|
+
getIssuingPoint(ownerId: string, issuingPointId: string): Promise<IssuingPoint | null>;
|
|
75
|
+
listIssuingPoints(ownerId: string): Promise<IssuingPoint[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates the point and its counters under the issuer's CNPJ, in both
|
|
78
|
+
* environments, starting at `firstNumber` (a store moving from another
|
|
79
|
+
* system continues its sequence). A series another point holds is refused.
|
|
80
|
+
*/
|
|
81
|
+
createIssuingPoint(
|
|
82
|
+
point: IssuingPoint,
|
|
83
|
+
issuerCnpj: string,
|
|
84
|
+
firstNumber: { readonly online: number; readonly contingency: number },
|
|
85
|
+
): Promise<void>;
|
|
86
|
+
createDocument(
|
|
87
|
+
request: NumberRequest,
|
|
88
|
+
build: (number: number) => FiscalDocument,
|
|
89
|
+
replace?: { readonly previous: FiscalDocument; readonly transition: Transition },
|
|
90
|
+
): Promise<FiscalDocument>;
|
|
91
|
+
getDocument(ownerId: string, documentId: string): Promise<FiscalDocument | null>;
|
|
92
|
+
/** The subject's documents of a model, oldest first. */
|
|
93
|
+
listBySubject(ownerId: string, subjectId: string, model: FiscalDocumentModel): Promise<FiscalDocument[]>;
|
|
94
|
+
listEvents(documentId: string): Promise<FiscalDocumentEvent[]>;
|
|
95
|
+
saveTransition(previous: FiscalDocument, transition: Transition): Promise<boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* Documents the sweep owes a step, across owners, whose `nextAttemptAt` has
|
|
98
|
+
* come: `PENDING` or `SUBMITTED`, and those whose `numberVoid` is still owed.
|
|
99
|
+
* Never one waiting for a person. Ordered by `nextAttemptAt`, so a row that
|
|
100
|
+
* keeps failing moves back and never pins the head. At most `limit`.
|
|
101
|
+
*/
|
|
102
|
+
listDue(input: { readonly now: string; readonly limit: number }): Promise<FiscalDocument[]>;
|
|
103
|
+
/** `CONTINGENCY` documents owed a transmission, the same way. */
|
|
104
|
+
listContingency(input: { readonly now: string; readonly limit: number }): Promise<FiscalDocument[]>;
|
|
105
|
+
/** `CONTINGENCY` documents signed before `signedBefore` whose deadline warning has not gone out. */
|
|
106
|
+
listContingencyDeadline(input: { readonly signedBefore: string; readonly limit: number }): Promise<FiscalDocument[]>;
|
|
107
|
+
/** Profiles whose certificate expires before `before`, across owners. */
|
|
108
|
+
listExpiringCertificates(before: string): Promise<EmitterProfile[]>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* DECLARED, NOT IMPLEMENTED (FUT-4717): what an offline register needs from
|
|
113
|
+
* the package that owns every number. A register that cannot reach the server
|
|
114
|
+
* signs on a block of its contingency series reserved in advance; back
|
|
115
|
+
* online, it hands in what it signed, and the known rest of a finished block
|
|
116
|
+
* is voided — an unknown range never is. The interface is named now so the
|
|
117
|
+
* register's ticket builds against it; nothing in this release calls it.
|
|
118
|
+
*/
|
|
119
|
+
export interface ContingencyBlockSource {
|
|
120
|
+
/** Reserve the next `size` numbers of the point's contingency series for one register. */
|
|
121
|
+
reserveBlock(input: { readonly ownerId: string; readonly issuingPointId: string; readonly size: number }): Promise<{
|
|
122
|
+
readonly series: number;
|
|
123
|
+
readonly from: number;
|
|
124
|
+
readonly to: number;
|
|
125
|
+
}>;
|
|
126
|
+
/** Record an XML the register signed offline as a CONTINGENCY document of the block. */
|
|
127
|
+
recordSigned(input: { readonly ownerId: string; readonly subjectId: string; readonly signedXml: string }): Promise<FiscalDocument>;
|
|
128
|
+
/** The block is finished: void the numbers known unused (`sequenceUsed` tells which were). */
|
|
129
|
+
closeBlock(input: { readonly ownerId: string; readonly series: number; readonly from: number; readonly sequenceUsed: number }): Promise<void>;
|
|
130
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the emitter profile and the certificate upload off a request body:
|
|
3
|
+
* every field required (an absent value is `null`), unknown keys refused, and
|
|
4
|
+
* every refusal a {@link FiscalDocumentError} `INVALID_INPUT` naming the
|
|
5
|
+
* field — never its value, since the certificate upload carries secrets.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { TaxRegime } from "../engine/types";
|
|
9
|
+
import type { Address, IssuerTaxRegime, Uf } from "../sale/types";
|
|
10
|
+
import type { SefazEnvironment } from "../sidecar/types";
|
|
11
|
+
import { FiscalDocumentError } from "./errors";
|
|
12
|
+
import { DOCUMENT_POLICIES, type DocumentPolicy, SIGNING_IDENTITY_KINDS, type SigningIdentityKind } from "./profile";
|
|
13
|
+
import { FISCAL_DOCUMENT_MODELS, type FiscalDocumentModel } from "./types";
|
|
14
|
+
|
|
15
|
+
/** The profile fields a host writes; the secrets arrive through their own calls. */
|
|
16
|
+
export interface EmitterProfileInput {
|
|
17
|
+
readonly cnpj: string;
|
|
18
|
+
readonly stateRegistration: string;
|
|
19
|
+
readonly municipalRegistration: string | null;
|
|
20
|
+
readonly cnae: string | null;
|
|
21
|
+
readonly legalName: string;
|
|
22
|
+
readonly tradeName: string | null;
|
|
23
|
+
readonly taxRegime: IssuerTaxRegime;
|
|
24
|
+
readonly regime: TaxRegime;
|
|
25
|
+
readonly regimeEffectiveFrom: string;
|
|
26
|
+
readonly restaurantRegime: boolean;
|
|
27
|
+
readonly address: Address & { readonly postalCode: string };
|
|
28
|
+
readonly environment: SefazEnvironment;
|
|
29
|
+
readonly documentPolicy: DocumentPolicy;
|
|
30
|
+
readonly signingIdentity: SigningIdentityKind;
|
|
31
|
+
readonly cscId: string | null;
|
|
32
|
+
/** The CSC token in clear, encrypted on arrival; `null` keeps the stored one. */
|
|
33
|
+
readonly cscToken: string | null;
|
|
34
|
+
readonly consentRecordedAt: string | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface CertificateUpload {
|
|
38
|
+
readonly pfxBase64: string;
|
|
39
|
+
readonly password: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IssuingPointInput {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly model: FiscalDocumentModel;
|
|
45
|
+
readonly onlineSeries: number;
|
|
46
|
+
readonly contingencySeries: number | null;
|
|
47
|
+
readonly firstOnlineNumber: number;
|
|
48
|
+
readonly firstContingencyNumber: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type Body = Record<string, unknown>;
|
|
52
|
+
|
|
53
|
+
const UFS: readonly Uf[] = [
|
|
54
|
+
"AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA", "MG", "MS", "MT", "PA",
|
|
55
|
+
"PB", "PE", "PI", "PR", "RJ", "RN", "RO", "RR", "RS", "SC", "SE", "SP", "TO",
|
|
56
|
+
];
|
|
57
|
+
const TAX_REGIMES: readonly IssuerTaxRegime[] = ["SIMPLES", "SIMPLES_EXCESS", "NORMAL", "MEI"];
|
|
58
|
+
const ENGINE_REGIMES: readonly TaxRegime[] = ["SIMPLES", "SIMPLES_IBS_CBS_REGULAR", "REGIME_REGULAR", "MEI", "NAO_CONTRIBUINTE"];
|
|
59
|
+
const ENVIRONMENTS: readonly SefazEnvironment[] = ["homologacao", "producao"];
|
|
60
|
+
|
|
61
|
+
function invalid(field: string, why: string): never {
|
|
62
|
+
throw new FiscalDocumentError("INVALID_INPUT", `${field} ${why}.`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function objectOf(value: unknown, field: string, keys: readonly string[]): Body {
|
|
66
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) invalid(field, "must be an object");
|
|
67
|
+
const unknown = Object.keys(value).filter((key) => !keys.includes(key));
|
|
68
|
+
if (unknown.length > 0) invalid(field, `has unknown keys: ${unknown.join(", ")}`);
|
|
69
|
+
const missing = keys.filter((key) => !(key in value));
|
|
70
|
+
if (missing.length > 0) invalid(field, `is missing: ${missing.join(", ")}`);
|
|
71
|
+
return value as Body;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function text(body: Body, key: string, pattern = /^.{1,200}$/s): string {
|
|
75
|
+
const value = body[key];
|
|
76
|
+
if (typeof value !== "string" || !pattern.test(value)) invalid(key, "is not valid");
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function nullableText(body: Body, key: string, pattern?: RegExp): string | null {
|
|
81
|
+
return body[key] === null ? null : text(body, key, pattern);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function oneOf<T extends string>(body: Body, key: string, values: readonly T[]): T {
|
|
85
|
+
const value = body[key];
|
|
86
|
+
if (typeof value !== "string" || !values.includes(value as T)) invalid(key, `must be one of ${values.join(", ")}`);
|
|
87
|
+
return value as T;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function integer(body: Body, key: string, min: number, max: number): number {
|
|
91
|
+
const value = body[key];
|
|
92
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) invalid(key, `must be an integer from ${min} to ${max}`);
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
97
|
+
const INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
|
|
98
|
+
const ADDRESS_KEYS = ["street", "number", "complement", "district", "municipalityIbge", "municipalityName", "uf", "postalCode", "phone"];
|
|
99
|
+
|
|
100
|
+
function addressOf(value: unknown): Address & { readonly postalCode: string } {
|
|
101
|
+
const body = objectOf(value, "address", ADDRESS_KEYS);
|
|
102
|
+
return {
|
|
103
|
+
street: text(body, "street"),
|
|
104
|
+
number: text(body, "number", /^.{1,60}$/),
|
|
105
|
+
complement: nullableText(body, "complement"),
|
|
106
|
+
district: text(body, "district"),
|
|
107
|
+
municipalityIbge: text(body, "municipalityIbge", /^\d{7}$/),
|
|
108
|
+
municipalityName: text(body, "municipalityName"),
|
|
109
|
+
uf: oneOf(body, "uf", UFS),
|
|
110
|
+
postalCode: text(body, "postalCode", /^\d{8}$/),
|
|
111
|
+
phone: nullableText(body, "phone", /^\d{6,14}$/),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const PROFILE_KEYS = [
|
|
116
|
+
"cnpj", "stateRegistration", "municipalRegistration", "cnae", "legalName", "tradeName", "taxRegime", "regime",
|
|
117
|
+
"regimeEffectiveFrom", "restaurantRegime", "address", "environment", "documentPolicy", "signingIdentity", "cscId",
|
|
118
|
+
"cscToken", "consentRecordedAt",
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
export function parseProfileInput(value: unknown): EmitterProfileInput {
|
|
122
|
+
const body = objectOf(value, "profile", PROFILE_KEYS);
|
|
123
|
+
if (typeof body["restaurantRegime"] !== "boolean") invalid("restaurantRegime", "must be a boolean");
|
|
124
|
+
return {
|
|
125
|
+
cnpj: text(body, "cnpj", /^[0-9A-Z]{12}\d{2}$/),
|
|
126
|
+
stateRegistration: text(body, "stateRegistration", /^(\d{2,14}|ISENTO)$/),
|
|
127
|
+
municipalRegistration: nullableText(body, "municipalRegistration", /^[0-9A-Za-z]{1,15}$/),
|
|
128
|
+
cnae: nullableText(body, "cnae", /^\d{7}$/),
|
|
129
|
+
legalName: text(body, "legalName", /^.{2,60}$/s),
|
|
130
|
+
tradeName: nullableText(body, "tradeName", /^.{1,60}$/s),
|
|
131
|
+
taxRegime: oneOf(body, "taxRegime", TAX_REGIMES),
|
|
132
|
+
regime: oneOf(body, "regime", ENGINE_REGIMES),
|
|
133
|
+
regimeEffectiveFrom: text(body, "regimeEffectiveFrom", DATE),
|
|
134
|
+
restaurantRegime: body["restaurantRegime"],
|
|
135
|
+
address: addressOf(body["address"]),
|
|
136
|
+
environment: oneOf(body, "environment", ENVIRONMENTS),
|
|
137
|
+
documentPolicy: oneOf(body, "documentPolicy", DOCUMENT_POLICIES),
|
|
138
|
+
signingIdentity: oneOf(body, "signingIdentity", SIGNING_IDENTITY_KINDS),
|
|
139
|
+
cscId: nullableText(body, "cscId", /^\d{1,6}$/),
|
|
140
|
+
cscToken: nullableText(body, "cscToken", /^[0-9A-Za-z]{16,36}$/),
|
|
141
|
+
consentRecordedAt: nullableText(body, "consentRecordedAt", INSTANT),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function parseCertificateUpload(value: unknown): CertificateUpload {
|
|
146
|
+
const body = objectOf(value, "certificate", ["pfxBase64", "password"]);
|
|
147
|
+
return {
|
|
148
|
+
pfxBase64: text(body, "pfxBase64", /^[A-Za-z0-9+/]{100,}={0,2}$/),
|
|
149
|
+
password: text(body, "password", /^.{1,200}$/s),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function parseIssuingPointInput(value: unknown): IssuingPointInput {
|
|
154
|
+
const body = objectOf(value, "issuingPoint", [
|
|
155
|
+
"id", "model", "onlineSeries", "contingencySeries", "firstOnlineNumber", "firstContingencyNumber",
|
|
156
|
+
]);
|
|
157
|
+
const onlineSeries = integer(body, "onlineSeries", 0, 889);
|
|
158
|
+
const contingencySeries = body["contingencySeries"] === null ? null : integer(body, "contingencySeries", 0, 889);
|
|
159
|
+
if (contingencySeries === onlineSeries) invalid("contingencySeries", "must differ from onlineSeries");
|
|
160
|
+
return {
|
|
161
|
+
id: text(body, "id", /^[A-Za-z0-9_-]{1,64}$/),
|
|
162
|
+
model: oneOf(body, "model", FISCAL_DOCUMENT_MODELS),
|
|
163
|
+
onlineSeries,
|
|
164
|
+
contingencySeries,
|
|
165
|
+
firstOnlineNumber: integer(body, "firstOnlineNumber", 1, 999_999_999),
|
|
166
|
+
firstContingencyNumber: integer(body, "firstContingencyNumber", 1, 999_999_999),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The emitter profile and its issuing points — what moved INTO this package
|
|
3
|
+
* from the host's tax profile (FUT-2231's decision block): the company data,
|
|
4
|
+
* the address, the regime, the environment, the document policy, who signs,
|
|
5
|
+
* the certificate (as ciphertext), the CSC (as ciphertext) and the series.
|
|
6
|
+
*
|
|
7
|
+
* Keyed by an opaque `ownerId` the host maps to its own tenant. What stays in
|
|
8
|
+
* the host: the link to its tenant, where the settings screen sits, the CNPJ
|
|
9
|
+
* lookup, the accountant, and the plan-driven DEFAULT of `documentPolicy`
|
|
10
|
+
* (this package knows no plans, so it takes the value and never invents it).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { TaxRegime } from "../engine/types";
|
|
14
|
+
import type { Address, IssuerTaxRegime } from "../sale/types";
|
|
15
|
+
import type { SefazEnvironment } from "../sidecar/types";
|
|
16
|
+
import type { FiscalDocumentModel } from "./types";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* - `ISSUED_HERE`: this package issues the store's documents.
|
|
20
|
+
* - `ISSUED_ELSEWHERE`: the store issues in its own system and the host
|
|
21
|
+
* records the access key it types.
|
|
22
|
+
* - `NONE`: no document.
|
|
23
|
+
*/
|
|
24
|
+
export type DocumentPolicy = "ISSUED_HERE" | "ISSUED_ELSEWHERE" | "NONE";
|
|
25
|
+
export const DOCUMENT_POLICIES: readonly DocumentPolicy[] = ["ISSUED_HERE", "ISSUED_ELSEWHERE", "NONE"];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Who signs. `STORE_CERTIFICATE`: the store's own A1, held encrypted through
|
|
29
|
+
* the host's cipher. `PLATFORM`: the platform signing on the store's behalf
|
|
30
|
+
* (LC 214/2025 art. 22 §12) — declared, answering `NOT_SUPPORTED` until it is
|
|
31
|
+
* decided how that signature works (FUT-2229 q4). Its own field from the start,
|
|
32
|
+
* so enabling it is an adapter, not a migration.
|
|
33
|
+
*/
|
|
34
|
+
export type SigningIdentityKind = "STORE_CERTIFICATE" | "PLATFORM";
|
|
35
|
+
export const SIGNING_IDENTITY_KINDS: readonly SigningIdentityKind[] = ["STORE_CERTIFICATE", "PLATFORM"];
|
|
36
|
+
|
|
37
|
+
export interface EmitterProfile {
|
|
38
|
+
readonly ownerId: string;
|
|
39
|
+
/** 14 characters; the 2026 alphanumeric CNPJ is accepted. */
|
|
40
|
+
readonly cnpj: string;
|
|
41
|
+
/** IE digits, or `ISENTO`. */
|
|
42
|
+
readonly stateRegistration: string;
|
|
43
|
+
readonly municipalRegistration: string | null;
|
|
44
|
+
readonly cnae: string | null;
|
|
45
|
+
readonly legalName: string;
|
|
46
|
+
readonly tradeName: string | null;
|
|
47
|
+
/** `CRT` on the document. */
|
|
48
|
+
readonly taxRegime: IssuerTaxRegime;
|
|
49
|
+
/** The IBS/CBS engine's regime, and the day it took effect (the Simples option is by semester). */
|
|
50
|
+
readonly regime: TaxRegime;
|
|
51
|
+
readonly regimeEffectiveFrom: string;
|
|
52
|
+
/** LC 214/2025 arts. 273–276 apply to the store's prepared food. */
|
|
53
|
+
readonly restaurantRegime: boolean;
|
|
54
|
+
readonly address: Address & { readonly postalCode: string };
|
|
55
|
+
readonly environment: SefazEnvironment;
|
|
56
|
+
readonly documentPolicy: DocumentPolicy;
|
|
57
|
+
readonly signingIdentity: SigningIdentityKind;
|
|
58
|
+
/** The `.pfx` bytes (base64) through the host's cipher. Never in clear, never on the wire. */
|
|
59
|
+
readonly certificateCiphertext: string | null;
|
|
60
|
+
readonly certificatePasswordCiphertext: string | null;
|
|
61
|
+
readonly certificateExpiresAt: string | null;
|
|
62
|
+
readonly cscId: string | null;
|
|
63
|
+
/** The CSC token through the host's cipher. */
|
|
64
|
+
readonly cscCiphertext: string | null;
|
|
65
|
+
/** The store's consent to `PLATFORM` signing (art. 22 §12). */
|
|
66
|
+
readonly consentRecordedAt: string | null;
|
|
67
|
+
readonly updatedAt: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Where documents are issued from: an opaque id the host maps (a register, the
|
|
72
|
+
* online store). A register has an ONLINE and a CONTINGENCY series; a point
|
|
73
|
+
* that never goes offline has no contingency series. The package owns every
|
|
74
|
+
* series' counter; no host keeps a second one.
|
|
75
|
+
*/
|
|
76
|
+
export interface IssuingPoint {
|
|
77
|
+
readonly id: string;
|
|
78
|
+
readonly ownerId: string;
|
|
79
|
+
readonly model: FiscalDocumentModel;
|
|
80
|
+
readonly onlineSeries: number;
|
|
81
|
+
readonly contingencySeries: number | null;
|
|
82
|
+
readonly createdAt: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The profile as the HTTP surface answers it: no ciphertext leaves the server. */
|
|
86
|
+
export type EmitterProfileView = Omit<
|
|
87
|
+
EmitterProfile,
|
|
88
|
+
"certificateCiphertext" | "certificatePasswordCiphertext" | "cscCiphertext"
|
|
89
|
+
> & { readonly hasCertificate: boolean; readonly hasCsc: boolean };
|
|
90
|
+
|
|
91
|
+
export function viewOf(profile: EmitterProfile): EmitterProfileView {
|
|
92
|
+
const { certificateCiphertext, certificatePasswordCiphertext, cscCiphertext, ...rest } = profile;
|
|
93
|
+
return {
|
|
94
|
+
...rest,
|
|
95
|
+
hasCertificate: certificateCiphertext !== null && certificatePasswordCiphertext !== null,
|
|
96
|
+
hasCsc: cscCiphertext !== null && profile.cscId !== null,
|
|
97
|
+
};
|
|
98
|
+
}
|