@btps/sdk 1.2.0-rc.2 → 1.2.0-rc.3.1
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/CHANGELOG.md +87 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +7 -1
- package/dist/core/crypto/decryptVerify.js +6 -2
- package/dist/core/crypto/types.d.ts +3 -0
- package/dist/core/server/constants/btps-protocol.js +4 -2
- package/dist/core/server/constants/currency.d.ts +6 -0
- package/dist/core/server/constants/currency.js +27 -2
- package/dist/core/server/constants/limits.d.ts +25 -0
- package/dist/core/server/constants/limits.js +27 -0
- package/dist/core/server/constants/permissions.d.ts +1 -1
- package/dist/core/server/schemas/boundView.d.ts +9 -0
- package/dist/core/server/schemas/boundView.js +28 -0
- package/dist/core/server/schemas/boundViewBindings.d.ts +40 -0
- package/dist/core/server/schemas/boundViewBindings.js +128 -0
- package/dist/core/server/schemas/boundViewChecks.d.ts +49 -0
- package/dist/core/server/schemas/boundViewChecks.js +344 -0
- package/dist/core/server/schemas/boundViewSchema.d.ts +1637 -0
- package/dist/core/server/schemas/boundViewSchema.js +186 -0
- package/dist/core/server/schemas/btpsDocsSchema.d.ts +36528 -9259
- package/dist/core/server/schemas/btpsDocsSchema.js +48 -35
- package/dist/core/server/schemas/helpers.d.ts +11119 -2337
- package/dist/server/btpsServer.d.ts +2 -1
- package/dist/server/btpsServer.js +10 -2
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +9 -1
- package/dist/server/types.d.ts +23 -26
- package/package.json +14 -1
|
@@ -11,6 +11,8 @@ import { BTPS_FIELD_LIMITS } from "../constants/limits.js";
|
|
|
11
11
|
import { BtpSignatureSchema, identitySchema } from "./shared.js";
|
|
12
12
|
import { boundedArray, boundedRecord } from "./bounded.js";
|
|
13
13
|
import { BtpKeyChainSchema } from "./keyChainSchema.js";
|
|
14
|
+
import { BtpBoundViewSchema } from "./boundViewSchema.js";
|
|
15
|
+
import { bindingProblem } from "./boundViewBindings.js";
|
|
14
16
|
const {
|
|
15
17
|
trustRequest,
|
|
16
18
|
trustResponse,
|
|
@@ -135,7 +137,7 @@ const {
|
|
|
135
137
|
}, BtpReceiptDocV1_1Schema = BtpInvoiceDocV1_1Schema.omit({
|
|
136
138
|
dueAt: !0,
|
|
137
139
|
paymentLink: !0
|
|
138
|
-
}).extend(receiptFields).strict(), httpsUrl = z.string().max(BTPS_FIELD_LIMITS.url).url().refine((url) => url.startsWith("https://"), "must be an https URL"),
|
|
140
|
+
}).extend(receiptFields).strict(), httpsUrl = z.string().max(BTPS_FIELD_LIMITS.url).url().refine((url) => url.startsWith("https://"), "must be an https URL"), { signature } = BTPS_FIELD_LIMITS, HIDDEN = new Set([
|
|
139
141
|
8203,
|
|
140
142
|
8204,
|
|
141
143
|
8205,
|
|
@@ -175,42 +177,41 @@ const {
|
|
|
175
177
|
message: `a drawn signature has at most ${signature.points} points`,
|
|
176
178
|
path: ["strokes"]
|
|
177
179
|
});
|
|
178
|
-
},
|
|
180
|
+
}, BtpVisualSignatureSchema = z.union([
|
|
179
181
|
z.object({ type: z.literal("typed"), text: signatureText }).strict(),
|
|
180
182
|
z.object({ type: z.literal("drawn"), strokes }).strict().superRefine(strokesOnCanvas)
|
|
181
|
-
]),
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}).strict(), templateSchema = (withValues) => z.object({
|
|
187
|
-
name: z.string(),
|
|
188
|
-
data: boundedRecord(z.unknown(), recordKeys).pipe(
|
|
189
|
-
z.object({
|
|
190
|
-
version: semver.optional(),
|
|
191
|
-
sha256: sha256Hex.optional(),
|
|
192
|
-
source: httpsUrl.optional(),
|
|
193
|
-
logo: z.object({ sha256: sha256Hex, source: httpsUrl }).strict().optional(),
|
|
194
|
-
values: withValues ? BtpTemplateValuesSchema.optional() : z.undefined({
|
|
195
|
-
invalid_type_error: "values are only on a letter's or an agreement's template"
|
|
196
|
-
})
|
|
197
|
-
}).catchall(z.unknown()).refine((data) => data.source === void 0 || data.sha256 !== void 0, {
|
|
198
|
-
message: "a source comes with the sha256 of what it serves",
|
|
199
|
-
path: ["sha256"]
|
|
200
|
-
})
|
|
201
|
-
)
|
|
202
|
-
}), BtpTemplateSchema = templateSchema(!1), BtpLetterTemplateSchema = templateSchema(!0), BtpDiscountSchema = z.union([
|
|
183
|
+
]), BtpSignatorySchema = z.object({
|
|
184
|
+
name: signatureText,
|
|
185
|
+
title: signatureText.optional(),
|
|
186
|
+
visualSignature: BtpVisualSignatureSchema.optional()
|
|
187
|
+
}).strict(), BtpRecipientSchema = z.object({ name: z.string().min(1).max(BTPS_FIELD_LIMITS.recipientName) }).strict(), BtpDiscountSchema = z.union([
|
|
203
188
|
z.object({ amount: z.number().int().safe().positive() }).strict(),
|
|
204
189
|
z.object({ percent: z.number().int().min(1).max(1e4) }).strict()
|
|
205
|
-
]), BtpDiscountedLineItemsSchema = BtpLineItemsSchema.
|
|
190
|
+
]), LINE_ROLES = ["description", "quantity", "unitPrice", "discount", "tax", "lineTotal"], BtpDiscountedLineItemsSchema = BtpLineItemsSchema.extend({
|
|
191
|
+
roles: boundedRecord(z.enum(LINE_ROLES), lineItems.columns).optional()
|
|
192
|
+
}).refine(
|
|
206
193
|
({ rows }) => rows.every(
|
|
207
194
|
(row) => row.discount === void 0 || typeof row.discount == "number" && row.discount >= 0
|
|
208
195
|
),
|
|
209
196
|
{ message: "a line discount is an integer of at least 0", path: ["rows"] }
|
|
210
|
-
)
|
|
197
|
+
).refine(
|
|
198
|
+
({ columns, roles }) => roles === void 0 || Object.keys(roles).every((column) => columns.includes(column)) && new Set(Object.values(roles)).size === Object.keys(roles).length,
|
|
199
|
+
{ message: "each role names one of columns, and appears at most once", path: ["roles"] }
|
|
200
|
+
), viewFields1_2 = {
|
|
201
|
+
recipient: BtpRecipientSchema.optional(),
|
|
202
|
+
boundView: BtpBoundViewSchema.optional()
|
|
203
|
+
}, documentFields1_2 = {
|
|
204
|
+
...viewFields1_2,
|
|
211
205
|
description: BtpNoteSchema(note).optional(),
|
|
212
206
|
discount: BtpDiscountSchema.optional(),
|
|
213
|
-
|
|
207
|
+
subtotalAmount: BtpMoneySchema.optional(),
|
|
208
|
+
taxAmount: BtpMoneySchema.optional(),
|
|
209
|
+
|
|
210
|
+
template: z.never({
|
|
211
|
+
errorMap: () => ({
|
|
212
|
+
message: "template is 1.1.0 only; in 1.2.0 a document's look is its boundView"
|
|
213
|
+
})
|
|
214
|
+
}).optional()
|
|
214
215
|
}, BtpInvoiceDocSchema = BtpInvoiceDocV1_1Schema.extend({
|
|
215
216
|
...documentFields1_2,
|
|
216
217
|
lineItems: BtpDiscountedLineItemsSchema
|
|
@@ -296,9 +297,10 @@ const {
|
|
|
296
297
|
references: boundedArray(BtpDocReferenceSchema, letter.references).optional(),
|
|
297
298
|
metadata: metadataSchema.optional()
|
|
298
299
|
}).strict(), BtpPayslipDocSchema = BtpPayslipDocV1_1Schema.extend({
|
|
299
|
-
|
|
300
|
+
boundView: BtpBoundViewSchema.optional()
|
|
300
301
|
}).strict(), BtpLetterDocSchema = BtpLetterDocV1_1Schema.extend({
|
|
301
|
-
|
|
302
|
+
...viewFields1_2,
|
|
303
|
+
signatory: BtpSignatorySchema.optional()
|
|
302
304
|
}).strict(), BtpDocumentV1_1Schema = z.discriminatedUnion("type", [
|
|
303
305
|
BtpInvoiceDocV1_1Schema,
|
|
304
306
|
BtpReceiptDocV1_1Schema,
|
|
@@ -325,12 +327,23 @@ const {
|
|
|
325
327
|
BtpLetterDocSchema,
|
|
326
328
|
BtpAgreementDocSchema
|
|
327
329
|
]).superRefine((document, ctx) => {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
330
|
+
const issue = (message2, path) => ctx.addIssue({ code: z.ZodIssueCode.custom, message: message2, path });
|
|
331
|
+
if (document.type === "agreement") {
|
|
332
|
+
const attached = new Set(document.attachments?.map(({ sha256 }) => sha256));
|
|
333
|
+
document.acceptance.terms.some((term) => !attached.has(term)) && issue("each term is the sha256 of one of its attachments", ["acceptance", "terms"]);
|
|
334
|
+
}
|
|
335
|
+
if (document.type === "invoice" || document.type === "receipt")
|
|
336
|
+
for (const field of ["subtotalAmount", "taxAmount"]) {
|
|
337
|
+
const currency = document[field]?.currency;
|
|
338
|
+
currency !== void 0 && currency !== document.totalAmount.currency && issue("is in the currency of totalAmount", [field, "currency"]);
|
|
339
|
+
}
|
|
340
|
+
document.boundView?.elements.forEach((element, index) => {
|
|
341
|
+
if (element.type === "text") {
|
|
342
|
+
const problem = bindingProblem(document, element.bind);
|
|
343
|
+
problem !== void 0 && issue(problem, ["boundView", "elements", index, "bind"]);
|
|
344
|
+
}
|
|
345
|
+
const signatory = "signatory" in document ? document.signatory : void 0;
|
|
346
|
+
element.type === "signature" && signatory?.visualSignature === void 0 && issue("a signature is drawn from the signatory's visualSignature", ["boundView", "elements", index]);
|
|
334
347
|
});
|
|
335
348
|
}), lifecycleEventFields = {
|
|
336
349
|
type: z.literal("lifecycle_event"),
|