@financica/ubl 0.18.1 → 0.19.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.19.0
4
+
5
+ ### Changed
6
+
7
+ - **Requires `@financica/peppol` 0.9.0, so a Swedish VAT number is no longer a participant identifier.** `resolveVatEndpoint` returns `undefined` for it instead of `9955:SE…`, a scheme withdrawn from the EAS code list.
8
+
9
+ ### Added
10
+
11
+ - **`listPeppolReceiverIdentifierCandidates` reaches a Swedish customer by organisationsnummer.** A Swedish VAT number is the organisationsnummer plus `01`, so it now yields `0007:<orgnr>`, Sweden's registration scheme, the way a Belgian one yields `0208:<enterprise number>`.
12
+
13
+ ## 0.18.2
14
+
15
+ ### Fixed
16
+
17
+ - **The parser unwraps a Peppol `StandardBusinessDocument` envelope.** `parseUblInvoice`, `normalizeUblResponse` and `extractUblEmbeddedAttachments` now read the Invoice/CreditNote inside an SBDH root, the form an access point delivers and its portal exports. They returned "not a UBL Invoice or CreditNote" before.
18
+
3
19
  ## 0.18.1
4
20
 
5
21
  ### Fixed
package/README.md CHANGED
@@ -27,6 +27,7 @@ const xml = `<?xml version="1.0"?>
27
27
  </Invoice>`;
28
28
 
29
29
  const invoice = parseUblInvoice(xml);
30
+ // Accepts a bare document or one wrapped in a Peppol StandardBusinessDocument envelope.
30
31
  // invoice.id => "INV-001"
31
32
  // invoice.seller.name => "Acme BV"
32
33
  // invoice.lines[0].description => "Consulting services"
@@ -270,6 +270,8 @@ declare const extractCustomerTaxIdentifiers: (taxIds: readonly CustomerTaxIdInpu
270
270
  * {@link resolveVatEndpoint});
271
271
  * 4. for Belgium, the enterprise number (VAT digits without the `BE` prefix)
272
272
  * under EAS `0208` — many Belgian entities register only under that;
273
+ * for Sweden, the organisationsnummer inside the VAT number under `0007`,
274
+ * Sweden's only scheme since SE:VAT (`9955`) was withdrawn;
273
275
  * 5. a generic tax/registration number under its country's company-ID scheme.
274
276
  *
275
277
  * `countryCode` (the customer's country, when known) disambiguates schemes for
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/build/ubl/constants.ts","../../src/build/ubl/serialize.ts","../../src/build/address.ts","../../src/build/party.ts","../../src/build/attachment.ts","../../src/build/identifiers.ts","../../src/build/numeric.ts","../../src/build/tax-category.ts","../../src/build/tax-totals.ts","../../src/build/xml.ts","../../src/build/index.ts"],"mappings":";;;;cAGa;;cAIA;;cAGA;;cAEA;;cAGA;;cAGA;;cAGA;cAEA;cACA;cAEA;cAEA;;;;;;;;;;;;;;;;;;;;;;cC42BA,sBAAmB,KAAS;;cAuH5B,6BAAoB;;;;;;;;;;;UC9+BhB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;cAYY,mBAAgB,SACnB,iCAA+B,oCACN,iCAEhC;;;;;;;;;;;;;;;;;KCxBS;;;;;;;UAQK;;EAEhB;;EAEA;;;;;EAKA,SAAS;;EAET;;EAEA;;EAEA,WAAW;;EAEX;;;cAIY,qBAAkB,UAAc,gBAAc;;;;;;;;UAsB1C;;EAEhB;;EAEA,SAAS;;;;;;;EAOT;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;cAcY,qBAAkB,UACpB,aAAW,mBACF,uBACjB;;;;;;;;cCnGU,qBAAkB;EAC9B;EACA,OAAO;;EAEP;MACG;;;;;cAWS,8BAA2B,KAAS,eAAa;;;;;;;cCLjD,mCAAgC,wCACN;;;;;;;;;;;cAmB1B,yBAAsB;EAClC;EACA;;;;;;;cAuBY,iBAAc;EAC1B;EACA;MACG;;;;;;;;;;;;;;;cA4BS,qBAAkB;EAC9B;EACA;MACG;;;;;;;;cAyBS,sBAAmB,wCAE7B;UAWc;EAChB;EACA;EACA;EACA;;;;;;;UAQgB;EAChB;EACA;;;;;;;;;cAaY,gCAA6B,iBACxB,4CACf;;;;;;;;;;;;;;;;;;;;cAkDU,yCAAsC,UACxC,QAAQ,yBAAuB;;;;cCtN7B,gBAAa;;cAIb,iBAAc;;UAGV;;EAEhB;;;;;;EAMA;;;;;;;;;;;;;;;;;;;;cAqBY,kBAAe,kBAAoB,qBAAqB;;;;;;;cC7BxD,2BAAyB;UAsBrB;EAChB;EACA;EACA;;;;;;;;;;;;;cAiBY,8BAA2B;EACvC;EACA;EACA;MACG;;;;;;;cA8CS,mCAAgC,YAChC,iBAAe,iBAEzB;;;;;;;cAiCU,kCAA+B,OACpC,WAAS,WACL,mBAAiB,wCAE1B;;;;;;;;;;;;;cCpHU,4BAAyB,OAC9B,WAAS,sCAEd;UAqCc;EAChB,UAAU;EACV,eAAe;;UAGC;;;;;;EAMhB;;EAEA;;;;;;;EAOA,mBAAmB;;;;;;;;;;;;;;;;;;;;;cAsBP,iBAAc,OACnB,WAAS,UACN,0BACR;;;;;;;;;;;;cAkGU,8BAA2B,gBACzB,OACP,WAAS,UACN,KAAK,qEACb;;;;;;;;;;;KC1MS,WAAW;UAEN;EAChB;EACA,QAAQ;;EAER;;EAEA,WAAW;;;KAIP,YAAY;;;;;;;;cASJ,KAAE,cACF,QACJ,iBAAe,mCACY,gBACjC;;cAgDU,oBAAiB,MAAU;;;;KC1C5B,cAAc;;KAEd,YAAY"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/build/ubl/constants.ts","../../src/build/ubl/serialize.ts","../../src/build/address.ts","../../src/build/party.ts","../../src/build/attachment.ts","../../src/build/identifiers.ts","../../src/build/numeric.ts","../../src/build/tax-category.ts","../../src/build/tax-totals.ts","../../src/build/xml.ts","../../src/build/index.ts"],"mappings":";;;;cAGa;;cAIA;;cAGA;;cAEA;;cAGA;;cAGA;;cAGA;cAEA;cACA;cAEA;cAEA;;;;;;;;;;;;;;;;;;;;;;cC42BA,sBAAmB,KAAS;;cAuH5B,6BAAoB;;;;;;;;;;;UC9+BhB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;E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sBP,iBAAc,OACnB,WAAS,UACN,0BACR;;;;;;;;;;;;cAkGU,8BAA2B,gBACzB,OACP,WAAS,UACN,KAAK,qEACb;;;;;;;;;;;KC1MS,WAAW;UAEN;EAChB;EACA,QAAQ;;EAER;;EAEA,WAAW;;;KAIP,YAAY;;;;;;;;cASJ,KAAE,cACF,QACJ,iBAAe,mCACY,gBACjC;;cAgDU,oBAAiB,MAAU;;;;KC1C5B,cAAc;;KAEd,YAAY"}
@@ -674,6 +674,8 @@ const extractCustomerTaxIdentifiers = (taxIds) => {
674
674
  * {@link resolveVatEndpoint});
675
675
  * 4. for Belgium, the enterprise number (VAT digits without the `BE` prefix)
676
676
  * under EAS `0208` — many Belgian entities register only under that;
677
+ * for Sweden, the organisationsnummer inside the VAT number under `0007`,
678
+ * Sweden's only scheme since SE:VAT (`9955`) was withdrawn;
677
679
  * 5. a generic tax/registration number under its country's company-ID scheme.
678
680
  *
679
681
  * `countryCode` (the customer's country, when known) disambiguates schemes for
@@ -700,6 +702,11 @@ const listPeppolReceiverIdentifierCandidates = (customer, countryCode) => {
700
702
  countryCode: "BE",
701
703
  companyNumber: customer.vatNumber ?? null
702
704
  }));
705
+ const swedishOrgNumber = /^SE(\d{10})01$/.exec((customer.vatNumber ?? "").replace(/[^A-Za-z0-9]/g, "").toUpperCase())?.[1];
706
+ if (swedishOrgNumber) add({
707
+ scheme: "0007",
708
+ value: swedishOrgNumber
709
+ });
703
710
  const tax = normalizeString(customer.taxNumber);
704
711
  if (tax) add(buildCompanyId({
705
712
  countryCode: countryCode ?? null,