@accounty/bloxs 0.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+
2
+ # 0.1.0 (2025-03-21)
3
+
4
+
5
+ ### Features
6
+
7
+ * Implemented Bloxs ([ce5a77c](https://github.com/PalmTreeCoding/Accounty/commit/ce5a77c2899e195101ef17f19f53bbcbaac1e5e8))
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @accounty/bloxs
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@accounty/bloxs",
3
+ "version": "0.1.0",
4
+ "dependencies": {
5
+ "axios": "^1.6.5",
6
+ "bignumber.js": "^9.1.2",
7
+ "date-fns": "^3.6.0",
8
+ "debug": "^4.3.4",
9
+ "deepmerge": "^4.3.1",
10
+ "libphonenumber-js": "^1.10.53",
11
+ "validator": "^13.11.0",
12
+ "@accounty/core": "0.3.1",
13
+ "tslib": "2.6.2"
14
+ },
15
+ "main": "./src/index.js",
16
+ "type": "commonjs"
17
+ }
package/src/bloxs.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import AccountyProviderCore from '@accounty/core';
2
+ import debug from 'debug';
3
+ import type { Company, FetchCompaniesOptions, FetchInvoicesOptions, FetchResponse, SalesInvoice } from '@accounty/core';
4
+ import { BloxsCompany, BloxsCredentials, BloxsInvoice } from './bloxs.interface';
5
+ /**
6
+ * Used docs
7
+ *
8
+ * - PDF provided by provider
9
+ * - https://bloxs.bloxs.io/ODataFeed/$metadata
10
+ */
11
+ export default class Bloxs extends AccountyProviderCore<BloxsCredentials> {
12
+ protected log: debug.Debugger;
13
+ testCredentials(): Promise<boolean>;
14
+ fetchCompanies(options?: FetchCompaniesOptions): Promise<FetchResponse<Array<Company<BloxsCompany>>>>;
15
+ fetchInvoices(options?: FetchInvoicesOptions): Promise<FetchResponse<Array<SalesInvoice<BloxsInvoice>>>>;
16
+ private get;
17
+ }
@@ -0,0 +1,60 @@
1
+ import { RemoteDataJson } from '@accounty/core';
2
+ export interface BloxsCredentials {
3
+ url: string;
4
+ username: string;
5
+ password: string;
6
+ }
7
+ export interface BloxsResponse<Result> {
8
+ value: Result;
9
+ '@odata.nextLink'?: string;
10
+ }
11
+ export interface BloxsInvoice extends RemoteDataJson {
12
+ SalesInvoiceId: 99;
13
+ Reference: '257.2017.00006';
14
+ WorkflowState: string;
15
+ WorkflowStateUpdatedTimeStamp: string;
16
+ InvoiceDate: '2017-04-01T00:00:00+02:00';
17
+ DueDate: '2017-04-01T00:00:00+02:00';
18
+ OwnerId: 832;
19
+ OwnerName: string;
20
+ RelationId: 645;
21
+ RelationName: string;
22
+ Subject: 'Factuur voor periode 1-4-2017 tot en met 30-4-2017';
23
+ TotalValueExcluding: 1400;
24
+ TotalValueIncluding: 1400;
25
+ JournalPostReference: '257.2017.300.00006';
26
+ TotalValueOutstanding: 0;
27
+ FinancialYear: 2017;
28
+ FinancialPeriod: 4;
29
+ SalesContractId: 121;
30
+ FinancingContractId: null;
31
+ PaymentMethod: 'BankTransfer';
32
+ PaymentTermId: 2;
33
+ PaymentTerm: string;
34
+ BankAccountId: number;
35
+ }
36
+ export interface BloxsCompany extends RemoteDataJson {
37
+ RelationId: 100;
38
+ Reference: 'R-00484';
39
+ Type: 'Person' | 'Organisation';
40
+ RelationType: 'Huurder';
41
+ State: 'Inactive';
42
+ ArchiveDate: '2019-10-01T00:00:00+02:00';
43
+ DisplayName: string;
44
+ AddressStreet: string;
45
+ AddressPostalCode: string;
46
+ AddressCity: string;
47
+ Email: string;
48
+ PhoneNumber: string;
49
+ MobileNumber: string;
50
+ AddressId: 98;
51
+ PostalAddressId: null;
52
+ InvoiceAddressId: null;
53
+ CoCNumber: null;
54
+ CoCDescription: null;
55
+ VATNumber: null;
56
+ BankAccountNumber: null;
57
+ BIC: null;
58
+ CommunicationFormId: 2;
59
+ DateOfBirth: '1998-05-12T00:00:00+02:00';
60
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=bloxs.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bloxs.interface.js","sourceRoot":"","sources":["../../../../packages/bloxs/src/bloxs.interface.ts"],"names":[],"mappings":""}
package/src/bloxs.js ADDED
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = tslib_1.__importStar(require("@accounty/core"));
5
+ const axios_1 = tslib_1.__importDefault(require("axios"));
6
+ const format_1 = require("date-fns/format");
7
+ const debug_1 = tslib_1.__importDefault(require("debug"));
8
+ const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
9
+ /**
10
+ * Used docs
11
+ *
12
+ * - PDF provided by provider
13
+ * - https://bloxs.bloxs.io/ODataFeed/$metadata
14
+ */
15
+ class Bloxs extends core_1.default {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.log = (0, debug_1.default)('accounty:bloxs');
19
+ }
20
+ async testCredentials() {
21
+ return Boolean(await this.get('SalesInvoices', {}, false));
22
+ }
23
+ async fetchCompanies(options = {}) {
24
+ return {
25
+ version: new Date().getTime(),
26
+ data: (await this.get('/Relations', {
27
+ $filter: 'State eq 1'
28
+ })).map((company) => {
29
+ const emailAddresses = company.Email?.split(';') ?? [];
30
+ const mainEmailAddress = emailAddresses.shift();
31
+ const hasContactInfo = mainEmailAddress
32
+ || company.PhoneNumber
33
+ || company.MobileNumber;
34
+ // TODO:: Asked if we can get this field
35
+ const country = 'NL';
36
+ return {
37
+ remoteId: `${company.RelationId}`,
38
+ name: company.DisplayName,
39
+ variant: company.Type === 'Person' ? 'PERSON' : 'COMPANY',
40
+ language: null,
41
+ country,
42
+ currency: null,
43
+ reference: `${company.Reference}`,
44
+ registrationNr: company.CoCNumber,
45
+ taxNr: company.VATNumber,
46
+ address: company.AddressStreet
47
+ ? {
48
+ streetName: company.AddressStreet,
49
+ city: company.AddressCity,
50
+ zipcode: company.AddressPostalCode,
51
+ country
52
+ }
53
+ : null,
54
+ postalAddress: null,
55
+ invoiceAddress: null,
56
+ contacts: [
57
+ hasContactInfo && {
58
+ remoteId: `${company.RelationId}`,
59
+ email: core_1.utils.toEmail(mainEmailAddress),
60
+ firstName: null,
61
+ lastName: null,
62
+ phoneNr: core_1.utils.toPhoneNumber(country, company.PhoneNumber, false)
63
+ || core_1.utils.toPhoneNumber(country, company.MobileNumber, false),
64
+ mobileNr: core_1.utils.toPhoneNumber(country, company.MobileNumber, true)
65
+ || core_1.utils.toPhoneNumber(country, company.PhoneNumber, true),
66
+ language: null
67
+ },
68
+ ...emailAddresses
69
+ .map(core_1.utils.toEmail)
70
+ .filter(Boolean)
71
+ .map((emailAddress) => ({
72
+ remoteId: `${company.RelationId}-${emailAddress}`,
73
+ email: emailAddress
74
+ }))
75
+ ].filter(Boolean),
76
+ remoteData: company
77
+ };
78
+ })
79
+ };
80
+ }
81
+ async fetchInvoices(options = {}) {
82
+ return {
83
+ version: new Date().getTime(),
84
+ data: (await this.get('/SalesInvoices', {
85
+ $filter: [
86
+ options.state === 'open' && 'TotalValueOutstanding gt 0',
87
+ options.state === 'overdue' && `DueDate ge DateTime'${(0, format_1.format)(new Date(), 'yyyy-MM-dd')}'`
88
+ // options.version && `LastModified+ge+DateTime'${format(options.version, 'yyyy-MM-dd')}'`
89
+ ].filter(Boolean).join(' and ')
90
+ })).map((invoice) => {
91
+ const centAmount = core_1.utils.toCentAmount(invoice.TotalValueIncluding);
92
+ const centAmountOpen = core_1.utils.toCentAmount(invoice.TotalValueOutstanding);
93
+ return {
94
+ remoteId: `${invoice.SalesInvoiceId}`,
95
+ reference: `${invoice.Reference || invoice.SalesInvoiceId}`,
96
+ centAmount,
97
+ centAmountPaid: centAmount - centAmountOpen,
98
+ centAmountOpen,
99
+ companyId: `${invoice.RelationId}`,
100
+ // Set the invoice date info
101
+ ...this.getInvoiceDateAndDueDate(invoice.InvoiceDate, invoice.DueDate),
102
+ remoteData: invoice
103
+ };
104
+ })
105
+ };
106
+ }
107
+ async get(url, params = {}, enablePaging = true) {
108
+ if (!this.credentials ||
109
+ !this.credentials.url ||
110
+ !this.credentials.username ||
111
+ !this.credentials.password) {
112
+ throw new Error('Missing credentials!');
113
+ }
114
+ const baseURL = `${this.credentials.url}/odatafeed`;
115
+ this.log(`[GET] ${baseURL}${url}?${this.buildQueryParams(params)}`);
116
+ const response = await axios_1.default.request({
117
+ method: 'GET',
118
+ baseURL,
119
+ url,
120
+ headers: {
121
+ Authorization: `Basic ${Buffer.from(`${this.credentials.username}:${this.credentials.password}`).toString('base64')}`
122
+ },
123
+ params
124
+ });
125
+ if (response.data['@odata.nextLink'] && enablePaging) {
126
+ return (0, deepmerge_1.default)(response.data.value, await this.get(response.data['@odata.nextLink']));
127
+ }
128
+ return response.data.value;
129
+ }
130
+ }
131
+ exports.default = Bloxs;
132
+ //# sourceMappingURL=bloxs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bloxs.js","sourceRoot":"","sources":["../../../../packages/bloxs/src/bloxs.ts"],"names":[],"mappings":";;;AAAA,+DAAqG;AACrG,0DAAyB;AACzB,4CAAwC;AACxC,0DAAyB;AACzB,kEAAiC;AAMjC;;;;;GAKG;AACH,MAAqB,KAAM,SAAQ,cAAsC;IAAzE;;QAEY,QAAG,GAAG,IAAA,eAAK,EAAC,gBAAgB,CAAC,CAAA;IAyIzC,CAAC;IAvIQ,KAAK,CAAC,eAAe;QAC1B,OAAO,OAAO,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAA;IAC5D,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,UAAiC,EAAE;QAC7D,OAAO;YACL,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC7B,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,CAAsB,YAA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YACP,GAAG;YACH,OAAO,EAAE;gBACP,aAAa,EAAE,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;aACtH;YACD,MAAM;SACP,CAAC,CAAA;QAEF,IAAI,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,YAAY,EAAE,CAAC;YACrD,OAAO,IAAA,mBAAS,EACd,QAAQ,CAAC,IAAI,CAAC,KAAK,EACnB,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CACjD,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAiB,CAAA;IACxC,CAAC;CAEF;AA3ID,wBA2IC"}
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default } from './bloxs';
2
+ export * from './bloxs.interface';
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var bloxs_1 = require("./bloxs");
6
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return tslib_1.__importDefault(bloxs_1).default; } });
7
+ tslib_1.__exportStar(require("./bloxs.interface"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/bloxs/src/index.ts"],"names":[],"mappings":";;;;AAAA,iCAAiC;AAAxB,yHAAA,OAAO,OAAA;AAChB,4DAAiC"}