@etainabl/nodejs-sdk 1.2.44 → 1.2.45

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 (155) hide show
  1. package/dist/cjs/package.json +2 -2
  2. package/dist/esm/package.json +3 -0
  3. package/dist/index.d.cts +782 -0
  4. package/dist/index.d.ts +782 -0
  5. package/dist/index.js +626 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +588 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +28 -31
  10. package/.prettierrc +0 -11
  11. package/__tests__/reporting.test.ts +0 -88
  12. package/dist/cjs/api.d.ts +0 -111
  13. package/dist/cjs/api.js +0 -318
  14. package/dist/cjs/consumption.d.ts +0 -14
  15. package/dist/cjs/consumption.js +0 -32
  16. package/dist/cjs/db.d.ts +0 -6
  17. package/dist/cjs/db.js +0 -69
  18. package/dist/cjs/etainabl.d.ts +0 -10
  19. package/dist/cjs/etainabl.js +0 -2
  20. package/dist/cjs/index.d.ts +0 -10
  21. package/dist/cjs/index.js +0 -59
  22. package/dist/cjs/logger.d.ts +0 -3
  23. package/dist/cjs/logger.js +0 -14
  24. package/dist/cjs/monitoring.d.ts +0 -1
  25. package/dist/cjs/monitoring.js +0 -31
  26. package/dist/cjs/reporting.d.ts +0 -2
  27. package/dist/cjs/reporting.js +0 -69
  28. package/dist/cjs/slack.d.ts +0 -4
  29. package/dist/cjs/slack.js +0 -28
  30. package/dist/cjs/types/account.d.ts +0 -112
  31. package/dist/cjs/types/account.js +0 -2
  32. package/dist/cjs/types/address.d.ts +0 -11
  33. package/dist/cjs/types/address.js +0 -2
  34. package/dist/cjs/types/asset.d.ts +0 -122
  35. package/dist/cjs/types/asset.js +0 -3
  36. package/dist/cjs/types/automation.d.ts +0 -33
  37. package/dist/cjs/types/automation.js +0 -2
  38. package/dist/cjs/types/company.d.ts +0 -42
  39. package/dist/cjs/types/company.js +0 -2
  40. package/dist/cjs/types/dataIngest.d.ts +0 -8
  41. package/dist/cjs/types/dataIngest.js +0 -2
  42. package/dist/cjs/types/email.d.ts +0 -18
  43. package/dist/cjs/types/email.js +0 -2
  44. package/dist/cjs/types/entity.d.ts +0 -16
  45. package/dist/cjs/types/entity.js +0 -2
  46. package/dist/cjs/types/index.d.ts +0 -19
  47. package/dist/cjs/types/index.js +0 -2
  48. package/dist/cjs/types/invoice.d.ts +0 -118
  49. package/dist/cjs/types/invoice.js +0 -2
  50. package/dist/cjs/types/log.d.ts +0 -10
  51. package/dist/cjs/types/log.js +0 -2
  52. package/dist/cjs/types/portal.d.ts +0 -8
  53. package/dist/cjs/types/portal.js +0 -2
  54. package/dist/cjs/types/reading.d.ts +0 -17
  55. package/dist/cjs/types/reading.js +0 -2
  56. package/dist/cjs/types/report.d.ts +0 -21
  57. package/dist/cjs/types/report.js +0 -2
  58. package/dist/cjs/types/scraperRun.d.ts +0 -15
  59. package/dist/cjs/types/scraperRun.js +0 -2
  60. package/dist/cjs/types/statusHistory.d.ts +0 -5
  61. package/dist/cjs/types/statusHistory.js +0 -2
  62. package/dist/cjs/types/supplier.d.ts +0 -28
  63. package/dist/cjs/types/supplier.js +0 -3
  64. package/dist/cjs/units.d.ts +0 -22
  65. package/dist/cjs/units.js +0 -94
  66. package/dist/mjs/api.d.ts +0 -111
  67. package/dist/mjs/api.js +0 -308
  68. package/dist/mjs/consumption.d.ts +0 -14
  69. package/dist/mjs/consumption.js +0 -22
  70. package/dist/mjs/db.d.ts +0 -6
  71. package/dist/mjs/db.js +0 -53
  72. package/dist/mjs/etainabl.d.ts +0 -10
  73. package/dist/mjs/etainabl.js +0 -1
  74. package/dist/mjs/index.d.ts +0 -10
  75. package/dist/mjs/index.js +0 -10
  76. package/dist/mjs/logger.d.ts +0 -3
  77. package/dist/mjs/logger.js +0 -9
  78. package/dist/mjs/monitoring.d.ts +0 -1
  79. package/dist/mjs/monitoring.js +0 -15
  80. package/dist/mjs/package.json +0 -3
  81. package/dist/mjs/reporting.d.ts +0 -2
  82. package/dist/mjs/reporting.js +0 -62
  83. package/dist/mjs/slack.d.ts +0 -4
  84. package/dist/mjs/slack.js +0 -14
  85. package/dist/mjs/types/account.d.ts +0 -112
  86. package/dist/mjs/types/account.js +0 -1
  87. package/dist/mjs/types/address.d.ts +0 -11
  88. package/dist/mjs/types/address.js +0 -1
  89. package/dist/mjs/types/asset.d.ts +0 -122
  90. package/dist/mjs/types/asset.js +0 -2
  91. package/dist/mjs/types/automation.d.ts +0 -33
  92. package/dist/mjs/types/automation.js +0 -1
  93. package/dist/mjs/types/company.d.ts +0 -42
  94. package/dist/mjs/types/company.js +0 -1
  95. package/dist/mjs/types/dataIngest.d.ts +0 -8
  96. package/dist/mjs/types/dataIngest.js +0 -1
  97. package/dist/mjs/types/email.d.ts +0 -18
  98. package/dist/mjs/types/email.js +0 -1
  99. package/dist/mjs/types/entity.d.ts +0 -16
  100. package/dist/mjs/types/entity.js +0 -1
  101. package/dist/mjs/types/index.d.ts +0 -19
  102. package/dist/mjs/types/index.js +0 -1
  103. package/dist/mjs/types/invoice.d.ts +0 -118
  104. package/dist/mjs/types/invoice.js +0 -1
  105. package/dist/mjs/types/log.d.ts +0 -10
  106. package/dist/mjs/types/log.js +0 -1
  107. package/dist/mjs/types/portal.d.ts +0 -8
  108. package/dist/mjs/types/portal.js +0 -1
  109. package/dist/mjs/types/reading.d.ts +0 -17
  110. package/dist/mjs/types/reading.js +0 -1
  111. package/dist/mjs/types/report.d.ts +0 -21
  112. package/dist/mjs/types/report.js +0 -1
  113. package/dist/mjs/types/scraperRun.d.ts +0 -15
  114. package/dist/mjs/types/scraperRun.js +0 -1
  115. package/dist/mjs/types/statusHistory.d.ts +0 -5
  116. package/dist/mjs/types/statusHistory.js +0 -1
  117. package/dist/mjs/types/supplier.d.ts +0 -28
  118. package/dist/mjs/types/supplier.js +0 -2
  119. package/dist/mjs/units.d.ts +0 -22
  120. package/dist/mjs/units.js +0 -89
  121. package/eslint.config.js +0 -60
  122. package/fixup.sh +0 -11
  123. package/src/api.ts +0 -382
  124. package/src/consumption.ts +0 -40
  125. package/src/db.ts +0 -69
  126. package/src/etainabl.ts +0 -10
  127. package/src/index.ts +0 -21
  128. package/src/logger.ts +0 -13
  129. package/src/monitoring.ts +0 -18
  130. package/src/reporting.ts +0 -78
  131. package/src/slack.ts +0 -16
  132. package/src/types/account.ts +0 -116
  133. package/src/types/address.ts +0 -12
  134. package/src/types/asset.ts +0 -142
  135. package/src/types/automation.ts +0 -35
  136. package/src/types/company.ts +0 -47
  137. package/src/types/dataIngest.ts +0 -8
  138. package/src/types/email.ts +0 -18
  139. package/src/types/entity.ts +0 -17
  140. package/src/types/index.ts +0 -20
  141. package/src/types/invoice.ts +0 -119
  142. package/src/types/log.ts +0 -10
  143. package/src/types/portal.ts +0 -9
  144. package/src/types/reading.ts +0 -17
  145. package/src/types/report.ts +0 -21
  146. package/src/types/scraperRun.ts +0 -15
  147. package/src/types/statusHistory.ts +0 -5
  148. package/src/types/supplier.ts +0 -31
  149. package/src/units.ts +0 -111
  150. package/tsconfig.base.json +0 -31
  151. package/tsconfig.cjs.json +0 -8
  152. package/tsconfig.json +0 -9
  153. package/tsconfig.test.json +0 -13
  154. package/vitest.config.js +0 -10
  155. package/vitest.workspace.js +0 -5
@@ -1,118 +0,0 @@
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 {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- export interface Portal {
2
- username?: string;
3
- password?: string;
4
- scraperEnabled?: boolean;
5
- url?: string;
6
- scraperId?: string;
7
- scraperStartDate?: Date;
8
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export interface StatusHistory {
2
- date: Date;
3
- value: 'active' | 'inactive';
4
- notes?: string;
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
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 {};
@@ -1,2 +0,0 @@
1
- ;
2
- export {};
@@ -1,22 +0,0 @@
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 {};
package/dist/mjs/units.js DELETED
@@ -1,89 +0,0 @@
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/eslint.config.js DELETED
@@ -1,60 +0,0 @@
1
- import tseslint from '@typescript-eslint/eslint-plugin';
2
- import tsParser from '@typescript-eslint/parser';
3
-
4
- export default [
5
- {
6
- ignores: [
7
- 'node_modules/**',
8
- 'dist/**',
9
- 'coverage/**',
10
- 'logs/**',
11
- '*.log',
12
- '.DS_Store'
13
- ]
14
- },
15
- {
16
- files: ['**/*.js', '**/*.ts'],
17
- plugins: {
18
- '@typescript-eslint': tseslint
19
- },
20
- languageOptions: {
21
- parser: tsParser,
22
- ecmaVersion: 2020,
23
- sourceType: 'module',
24
- parserOptions: {
25
- ecmaVersion: 2020,
26
- sourceType: 'module'
27
- }
28
- },
29
- linterOptions: {
30
- reportUnusedDisableDirectives: true
31
- },
32
- rules: {
33
- 'no-console': 'off',
34
- 'comma-dangle': ['error', 'never'],
35
- 'arrow-parens': ['error', 'as-needed'],
36
- 'linebreak-style': 'off',
37
- 'padded-blocks': 'off',
38
- 'no-underscore-dangle': 'off',
39
- 'no-param-reassign': ['error', { props: false }],
40
- 'new-cap': ['error', { capIsNewExceptions: ['Router', 'ObjectId'] }],
41
- 'no-tabs': 'error',
42
- 'max-len': ['warn', 150],
43
- 'no-plusplus': 'off',
44
- 'generator-star-spacing': 'off',
45
- 'class-methods-use-this': 'off',
46
- 'import/extensions': 'off',
47
- 'import/no-unresolved': 'off',
48
- 'prefer-destructuring': 'off',
49
- 'no-use-before-define': 'off',
50
- 'import/prefer-default-export': 'off'
51
- },
52
- settings: {
53
- 'import/resolver': {
54
- node: {
55
- extensions: ['.js', '.ts']
56
- }
57
- }
58
- }
59
- }
60
- ];
package/fixup.sh DELETED
@@ -1,11 +0,0 @@
1
- cat >dist/cjs/package.json <<!EOF
2
- {
3
- "type": "commonjs"
4
- }
5
- !EOF
6
-
7
- cat >dist/mjs/package.json <<!EOF
8
- {
9
- "type": "module"
10
- }
11
- !EOF