@etainabl/nodejs-sdk 1.2.42 → 1.2.44

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.
Files changed (110) hide show
  1. package/dist/cjs/api.d.ts +111 -0
  2. package/dist/cjs/api.js +318 -0
  3. package/dist/cjs/consumption.d.ts +14 -0
  4. package/dist/cjs/consumption.js +32 -0
  5. package/dist/cjs/db.d.ts +6 -0
  6. package/dist/cjs/db.js +69 -0
  7. package/dist/cjs/etainabl.d.ts +10 -0
  8. package/dist/cjs/etainabl.js +2 -0
  9. package/dist/cjs/index.d.ts +10 -0
  10. package/dist/cjs/logger.d.ts +3 -0
  11. package/dist/cjs/logger.js +14 -0
  12. package/dist/cjs/monitoring.d.ts +1 -0
  13. package/dist/cjs/monitoring.js +31 -0
  14. package/dist/cjs/package.json +3 -0
  15. package/dist/cjs/reporting.d.ts +2 -0
  16. package/dist/cjs/reporting.js +69 -0
  17. package/dist/cjs/slack.d.ts +4 -0
  18. package/dist/cjs/slack.js +28 -0
  19. package/dist/cjs/types/account.d.ts +112 -0
  20. package/dist/cjs/types/account.js +2 -0
  21. package/dist/cjs/types/address.d.ts +11 -0
  22. package/dist/cjs/types/address.js +2 -0
  23. package/dist/cjs/types/asset.d.ts +122 -0
  24. package/dist/cjs/types/asset.js +3 -0
  25. package/dist/cjs/types/automation.d.ts +33 -0
  26. package/dist/cjs/types/automation.js +2 -0
  27. package/dist/cjs/types/company.d.ts +42 -0
  28. package/dist/cjs/types/company.js +2 -0
  29. package/dist/cjs/types/dataIngest.d.ts +8 -0
  30. package/dist/cjs/types/dataIngest.js +2 -0
  31. package/dist/cjs/types/email.d.ts +18 -0
  32. package/dist/cjs/types/email.js +2 -0
  33. package/dist/cjs/types/entity.d.ts +16 -0
  34. package/dist/cjs/types/entity.js +2 -0
  35. package/dist/cjs/types/index.d.ts +19 -0
  36. package/dist/cjs/types/index.js +2 -0
  37. package/dist/cjs/types/invoice.d.ts +118 -0
  38. package/dist/cjs/types/invoice.js +2 -0
  39. package/dist/cjs/types/log.d.ts +10 -0
  40. package/dist/cjs/types/log.js +2 -0
  41. package/dist/cjs/types/portal.d.ts +8 -0
  42. package/dist/cjs/types/portal.js +2 -0
  43. package/dist/cjs/types/reading.d.ts +17 -0
  44. package/dist/cjs/types/reading.js +2 -0
  45. package/dist/cjs/types/report.d.ts +21 -0
  46. package/dist/cjs/types/report.js +2 -0
  47. package/dist/cjs/types/scraperRun.d.ts +15 -0
  48. package/dist/cjs/types/scraperRun.js +2 -0
  49. package/dist/cjs/types/statusHistory.d.ts +5 -0
  50. package/dist/cjs/types/statusHistory.js +2 -0
  51. package/dist/cjs/types/supplier.d.ts +28 -0
  52. package/dist/cjs/types/supplier.js +3 -0
  53. package/dist/cjs/units.d.ts +22 -0
  54. package/dist/cjs/units.js +94 -0
  55. package/dist/mjs/api.d.ts +111 -0
  56. package/dist/mjs/api.js +308 -0
  57. package/dist/mjs/consumption.d.ts +14 -0
  58. package/dist/mjs/consumption.js +22 -0
  59. package/dist/mjs/db.d.ts +6 -0
  60. package/dist/mjs/db.js +53 -0
  61. package/dist/mjs/etainabl.d.ts +10 -0
  62. package/dist/mjs/etainabl.js +1 -0
  63. package/dist/mjs/index.d.ts +10 -0
  64. package/dist/mjs/index.js +10 -0
  65. package/dist/mjs/logger.d.ts +3 -0
  66. package/dist/mjs/logger.js +9 -0
  67. package/dist/mjs/monitoring.d.ts +1 -0
  68. package/dist/mjs/monitoring.js +15 -0
  69. package/dist/mjs/package.json +3 -0
  70. package/dist/mjs/reporting.d.ts +2 -0
  71. package/dist/mjs/reporting.js +62 -0
  72. package/dist/mjs/slack.d.ts +4 -0
  73. package/dist/mjs/slack.js +14 -0
  74. package/dist/mjs/types/account.d.ts +112 -0
  75. package/dist/mjs/types/account.js +1 -0
  76. package/dist/mjs/types/address.d.ts +11 -0
  77. package/dist/mjs/types/address.js +1 -0
  78. package/dist/mjs/types/asset.d.ts +122 -0
  79. package/dist/mjs/types/asset.js +2 -0
  80. package/dist/mjs/types/automation.d.ts +33 -0
  81. package/dist/mjs/types/automation.js +1 -0
  82. package/dist/mjs/types/company.d.ts +42 -0
  83. package/dist/mjs/types/company.js +1 -0
  84. package/dist/mjs/types/dataIngest.d.ts +8 -0
  85. package/dist/mjs/types/dataIngest.js +1 -0
  86. package/dist/mjs/types/email.d.ts +18 -0
  87. package/dist/mjs/types/email.js +1 -0
  88. package/dist/mjs/types/entity.d.ts +16 -0
  89. package/dist/mjs/types/entity.js +1 -0
  90. package/dist/mjs/types/index.d.ts +19 -0
  91. package/dist/mjs/types/index.js +1 -0
  92. package/dist/mjs/types/invoice.d.ts +118 -0
  93. package/dist/mjs/types/invoice.js +1 -0
  94. package/dist/mjs/types/log.d.ts +10 -0
  95. package/dist/mjs/types/log.js +1 -0
  96. package/dist/mjs/types/portal.d.ts +8 -0
  97. package/dist/mjs/types/portal.js +1 -0
  98. package/dist/mjs/types/reading.d.ts +17 -0
  99. package/dist/mjs/types/reading.js +1 -0
  100. package/dist/mjs/types/report.d.ts +21 -0
  101. package/dist/mjs/types/report.js +1 -0
  102. package/dist/mjs/types/scraperRun.d.ts +15 -0
  103. package/dist/mjs/types/scraperRun.js +1 -0
  104. package/dist/mjs/types/statusHistory.d.ts +5 -0
  105. package/dist/mjs/types/statusHistory.js +1 -0
  106. package/dist/mjs/types/supplier.d.ts +28 -0
  107. package/dist/mjs/types/supplier.js +2 -0
  108. package/dist/mjs/units.d.ts +22 -0
  109. package/dist/mjs/units.js +89 -0
  110. package/package.json +9 -4
@@ -0,0 +1,118 @@
1
+ interface Values {
2
+ friendlyInvoiceNumber?: string;
3
+ friendlySupplierRef?: string;
4
+ friendlyStartDate?: string;
5
+ friendlyEndDate?: string;
6
+ friendlyInvoiceDate?: string;
7
+ friendlyMeterPointNumber?: string;
8
+ friendlyMeterPointNumber2?: string;
9
+ friendlyMeterSerialNumber?: string;
10
+ friendlyPipeSize?: string;
11
+ friendlyTotalUnitCost?: number;
12
+ friendlyTotalWaterCost?: number;
13
+ friendlyTotalWasteCost?: number;
14
+ friendlyTotalDaily?: number;
15
+ friendlyTotalLevy?: number;
16
+ friendlyTotalKva?: number;
17
+ friendlyTotalUnits?: number;
18
+ friendlyTotalWaterVolume?: number;
19
+ friendlyTotalWasteVolume?: number;
20
+ friendlyNetTotalCost?: number;
21
+ friendlyTotalTax?: number;
22
+ friendlyTotalCost?: number;
23
+ friendlyMeteredConsumption?: string;
24
+ friendlyCorrectedConsumption?: string;
25
+ friendlyCorrectionFactor?: string;
26
+ friendlyCalorificValue?: string;
27
+ friendlyReadFactor?: string;
28
+ friendlyType?: string;
29
+ friendlyStartRead?: string;
30
+ friendlyEndRead?: string;
31
+ invoiceNumber?: string;
32
+ supplierRef?: string;
33
+ startDate?: Date;
34
+ endDate?: Date;
35
+ invoiceDate?: Date;
36
+ meterPointNumber?: string;
37
+ meterPointNumber2?: string;
38
+ meterSerialNumber?: string;
39
+ pipeSize?: string;
40
+ totalUnitCost?: number;
41
+ totalWaterCost?: number;
42
+ totalWasteCost?: number;
43
+ totalDaily?: number;
44
+ totalLevy?: number;
45
+ totalKva?: number;
46
+ totalUnits?: number;
47
+ totalWaterVolume?: number;
48
+ totalWasteVolume?: number;
49
+ netTotalCost?: number;
50
+ totalTax?: number;
51
+ totalCost?: number;
52
+ meteredConsumption?: string;
53
+ correctedConsumption?: string;
54
+ correctionFactor?: string;
55
+ calorificValue?: string;
56
+ readFactor?: string;
57
+ type?: string;
58
+ startRead?: string;
59
+ endRead?: string;
60
+ }
61
+ interface Rate {
62
+ consumption?: string;
63
+ cost?: string;
64
+ endDate?: Date | null;
65
+ endRead?: string | null;
66
+ endReadType?: string | null;
67
+ rateName?: string | null;
68
+ startDate?: Date | null;
69
+ startRead?: string | null;
70
+ startReadType?: string | null;
71
+ type: RateType | null;
72
+ unitRate?: string | null;
73
+ }
74
+ type InvoiceStatus = 'processing' | 'pending' | 'uploading' | 'queued' | 'captured' | 'error' | 'completed';
75
+ type FinancialStatus = 'approved' | 'new' | 'not-approved' | 'paid' | 'sent-for-payment';
76
+ type RateType = 'unitRate' | 'daily' | 'levy' | 'tax' | 'kva' | 'waterRate' | 'wasteRate' | 'discount';
77
+ export interface Invoice {
78
+ _id: string;
79
+ jobId?: string | null;
80
+ startTime?: Date;
81
+ endTime?: Date | null;
82
+ s3Key: string;
83
+ s3TextractKey?: string | null;
84
+ stampedS3Key: string | null;
85
+ fileName?: string | null;
86
+ status: InvoiceStatus;
87
+ financialStatus: FinancialStatus;
88
+ completed?: boolean;
89
+ type?: string | null;
90
+ tags?: string[];
91
+ manualResults?: Record<string, any>;
92
+ values?: Values;
93
+ rates?: Rate[];
94
+ detailedResults?: Record<string, any>;
95
+ templateVersion?: string | null;
96
+ error?: Record<string, any>;
97
+ isPaid?: boolean;
98
+ isCreditNote?: boolean;
99
+ isConvertedCreditNote?: boolean;
100
+ isManual?: boolean;
101
+ uploaderStatus?: string;
102
+ simulated?: boolean;
103
+ notes?: string | null;
104
+ assignedTo?: string;
105
+ noScrape?: boolean;
106
+ scraperInvoiceId?: string;
107
+ confirmedAt?: Date | null;
108
+ confirmedBy?: string | null;
109
+ supplierId?: string | null;
110
+ sisterId?: string | null;
111
+ batchId?: string | null;
112
+ accountId?: string | null;
113
+ entityId?: string;
114
+ companyId: string;
115
+ userSub: string;
116
+ validation?: any[];
117
+ }
118
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface Log {
2
+ _id: string;
3
+ message: string;
4
+ context?: {};
5
+ linkedId?: string;
6
+ linkedType?: string;
7
+ type: string;
8
+ userSub?: string;
9
+ companyId?: string;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export interface Portal {
2
+ username?: string;
3
+ password?: string;
4
+ scraperEnabled?: boolean;
5
+ url?: string;
6
+ scraperId?: string;
7
+ scraperStartDate?: Date;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ export interface Reading {
2
+ _id: string;
3
+ submittedAt: Date;
4
+ value: number;
5
+ type?: string;
6
+ invoiceStartRead?: number;
7
+ source: string;
8
+ invoiceId?: string;
9
+ rateId?: string;
10
+ contractRateType?: string;
11
+ invoiceBatchId?: string;
12
+ batchId?: string;
13
+ accountId: string;
14
+ entityId: string;
15
+ companyId: string;
16
+ userSub?: string;
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ export interface Report {
2
+ _id: string;
3
+ type: 'dynamic' | 'spreadsheet' | 'table' | 'pdf';
4
+ subType?: string;
5
+ fileFormat: 'pdf' | 'xlsx' | 'csv' | 'png' | 'jpg' | 'chart';
6
+ fileName?: string;
7
+ status: 'preparing' | 'ready';
8
+ scheduled?: boolean;
9
+ version?: number;
10
+ metadata?: Record<string, any>;
11
+ data?: Record<string, any>;
12
+ requestedAt: Date;
13
+ availableAt?: Date;
14
+ s3Key: string | null;
15
+ batchId?: string;
16
+ scheduledReportId?: string;
17
+ reportTemplateId?: string;
18
+ entityId: string;
19
+ companyId: string;
20
+ userSub?: string;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ export interface CreateScraperRunParams {
2
+ supplierId: string;
3
+ accountId: string;
4
+ companyId: string;
5
+ }
6
+ export interface ScraperRun {
7
+ _id: string;
8
+ logs?: {}[];
9
+ supplierId: string;
10
+ accountId: string;
11
+ companyId: string;
12
+ invoiceData?: [];
13
+ status: string[];
14
+ error?: string;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export interface StatusHistory {
2
+ date: Date;
3
+ value: 'active' | 'inactive';
4
+ notes?: string;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { Portal } from './portal.js';
2
+ interface PortalSupplierSchema extends Portal {
3
+ concurrent: boolean;
4
+ checkInvoiceFilenames: boolean;
5
+ supplierRefRequired: boolean;
6
+ }
7
+ interface InvoiceOptionsSchema {
8
+ stampPositionX?: number;
9
+ stampPositionY?: number;
10
+ }
11
+ export interface Supplier {
12
+ _id: string;
13
+ name: string;
14
+ logoUrl?: string;
15
+ websiteUrl?: string;
16
+ portalUrl?: string;
17
+ identifier?: string;
18
+ type: 'supplier' | 'distributor';
19
+ region?: string;
20
+ countryCode: string;
21
+ defaultScraper?: string;
22
+ active: boolean;
23
+ transferSupplier: boolean;
24
+ transferSupplierId?: string;
25
+ portal: PortalSupplierSchema;
26
+ invoiceOptions?: InvoiceOptionsSchema;
27
+ }
28
+ export {};
@@ -0,0 +1,2 @@
1
+ ;
2
+ export {};
@@ -0,0 +1,22 @@
1
+ interface Item {
2
+ units?: string | null;
3
+ unit?: string | null;
4
+ factor?: number | null;
5
+ value: number;
6
+ [key: string]: any;
7
+ }
8
+ export type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'oil' | 'other';
9
+ export type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C' | 'mcuf' | 'hcuf' | 'tcuf' | 'ocuf' | 'hm3' | 'tm3' | 'nm3';
10
+ export type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h' | 'l';
11
+ export declare const accountTypeMap: {
12
+ [key: string]: BaseUnit;
13
+ };
14
+ export declare const accountTypeUnitMap: {
15
+ [key: string]: ETNUnit[];
16
+ };
17
+ export declare const convertItems: (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined) => any;
18
+ export declare const checkAccountTypeVsUnits: (type: string, unit: string, additionalLog?: number | "") => {
19
+ type: AccountType;
20
+ unit: ETNUnit;
21
+ };
22
+ export {};
@@ -0,0 +1,89 @@
1
+ export const accountTypeMap = {
2
+ electricity: 'kwh',
3
+ gas: 'kwh',
4
+ water: 'm3',
5
+ waste: 'kg',
6
+ solar: 'kwh',
7
+ heating: 'kwh',
8
+ flow: 'm3/h',
9
+ cooling: 'kwh',
10
+ temperature: 'C',
11
+ oil: 'l'
12
+ };
13
+ const unitConversionFactors = {
14
+ kwh: {
15
+ kwh: 1,
16
+ mwh: 1000,
17
+ wh: 0.001,
18
+ m3: (39 * 1.02264) / 3.6,
19
+ ft3: (0.0283 * 39 * 1.02264) / 3.6,
20
+ hcf: (2.83 * 39 * 1.02264) / 3.6
21
+ },
22
+ m3: {
23
+ m3: 1,
24
+ l: 0.001
25
+ },
26
+ C: {
27
+ C: 1
28
+ },
29
+ kg: {
30
+ kg: 1,
31
+ lbs: 0.45359237,
32
+ tonnes: 1000
33
+ },
34
+ 'm3/h': {
35
+ 'm3/h': 1
36
+ }
37
+ };
38
+ export const accountTypeUnitMap = {
39
+ electricity: ['kwh', 'mwh', 'wh'],
40
+ gas: ['kwh', 'm3', 'ft3', 'hcf'],
41
+ water: ['m3', 'l'],
42
+ waste: ['kg', 'lbs', 'tonnes'],
43
+ solar: ['kwh', 'mwh', 'wh'],
44
+ heating: ['kwh', 'mwh', 'wh'],
45
+ flow: ['m3/h'],
46
+ cooling: ['kwh', 'mwh', 'wh'],
47
+ temperature: ['C'],
48
+ oil: ['l']
49
+ };
50
+ // Convert units to base format
51
+ export const convertItems = (items, type, defaultUnits, accountFactor) => {
52
+ if (!type)
53
+ throw new Error('Account type is required');
54
+ const baseUnit = accountTypeMap[type];
55
+ if (!baseUnit)
56
+ throw new Error(`Account type ${type} is not supported`);
57
+ const convertedItems = items.map(item => {
58
+ const factor = item.factor || accountFactor || 1;
59
+ const units = item.units || item.unit || defaultUnits || baseUnit;
60
+ const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
61
+ return { ...item, value: convertedValue, units: baseUnit };
62
+ });
63
+ return convertedItems;
64
+ };
65
+ const _getConversionFactor = (fromUnit = 'kwh', toUnit) => {
66
+ const conversionFactors = unitConversionFactors[toUnit];
67
+ if (!conversionFactors) {
68
+ throw new Error(`Conversion factor base unit ${toUnit} is not defined`);
69
+ }
70
+ if (!conversionFactors[fromUnit]) {
71
+ throw new Error(`Conversion factor from unit ${fromUnit} is not defined`);
72
+ }
73
+ return conversionFactors[fromUnit];
74
+ };
75
+ export const checkAccountTypeVsUnits = (type, unit, additionalLog = '') => {
76
+ if (!type)
77
+ throw new Error('Account type is required');
78
+ if (!unit)
79
+ throw new Error('Unit is required');
80
+ const parsedType = type.toLowerCase().trim();
81
+ const accountTypeUnits = accountTypeUnitMap[parsedType];
82
+ if (!accountTypeUnits)
83
+ throw new Error(`Account type "${parsedType}" is not supported ${additionalLog}`);
84
+ const parsedUnit = unit.toLowerCase().trim();
85
+ if (!accountTypeUnits.includes(parsedUnit)) {
86
+ throw new Error(`Account type "${parsedType}" does not support unit "${parsedUnit}" ${additionalLog}`);
87
+ }
88
+ return { type: parsedType, unit: parsedUnit };
89
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etainabl/nodejs-sdk",
3
- "version": "1.2.42",
3
+ "version": "1.2.44",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/mjs/index.js",
6
6
  "types": "dist/mjs/index.d.ts",
@@ -17,16 +17,17 @@
17
17
  "@types/node": "^20.4.5",
18
18
  "@typescript-eslint/eslint-plugin": "^8.29.0",
19
19
  "@typescript-eslint/parser": "^8.29.0",
20
- "eslint": "^9.23.0",
20
+ "eslint": "^8.57.1",
21
21
  "eslint-config-airbnb": "^19.0.4",
22
22
  "eslint-config-airbnb-base": "^15.0.0",
23
23
  "eslint-config-prettier": "^10.1.1",
24
24
  "eslint-plugin-import": "^2.31.0",
25
25
  "prettier-eslint": "^16.3.0",
26
- "vitest": "^2.1.1"
26
+ "typescript": "^4.8.4",
27
+ "vitest": "^3.1.1"
27
28
  },
28
29
  "scripts": {
29
- "process": "vitest run && yarn build && yarn publish",
30
+ "process": "vitest run && npm run build && npm version patch && npm publish",
30
31
  "build": "rm -rf dist/* && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && ./fixup.sh",
31
32
  "test": "vitest",
32
33
  "postinstall": "npm run build"
@@ -36,5 +37,9 @@
36
37
  "import": "./dist/mjs/index.js",
37
38
  "require": "./dist/cjs/index.js"
38
39
  }
40
+ },
41
+ "publishConfig": {
42
+ "registry": "https://registry.npmjs.org/",
43
+ "access": "restricted"
39
44
  }
40
45
  }