typescript-evnex 1.0.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.
@@ -0,0 +1,67 @@
1
+ import type { EvnexChargePoint, EvnexChargePointDetail, EvnexChargePointLoadSchedule, EvnexChargePointOverrideConfig, EvnexChargePointSolarConfig, EvnexChargeProfileSegment, EvnexChargePointTransaction, EvnexChargePointStatusResponse } from "./schema/charge_points";
2
+ import type { EvnexCommandResponse } from "./schema/commands";
3
+ import type { EvnexOrgInsightEntry, EvnexOrgSummaryStatus } from "./schema/org";
4
+ import type { EvnexUserDetail } from "./schema/user";
5
+ import type { EvnexChargePointDetail as EvnexChargePointDetailV3, EvnexChargePointSession } from "./schema/v3/charge_points";
6
+ import type { EvnexV3APIResponse } from "./schema/v3/generic";
7
+ export interface EvnexConfig {
8
+ baseUrl?: string;
9
+ cognitoUserPoolId?: string;
10
+ cognitoClientId?: string;
11
+ cognitoRegion?: string;
12
+ orgId?: string;
13
+ }
14
+ export interface EvnexTokens {
15
+ idToken: string;
16
+ accessToken: string;
17
+ refreshToken: string;
18
+ }
19
+ export declare class Evnex {
20
+ private client;
21
+ private tokens;
22
+ private orgId?;
23
+ private readonly username;
24
+ private readonly password;
25
+ private readonly clientId;
26
+ private readonly cognito;
27
+ constructor(username: string, password: string, tokens?: EvnexTokens, config?: EvnexConfig);
28
+ /**
29
+ * Authenticate with Cognito and populate tokens.
30
+ * Call this after constructing if you don't have existing tokens.
31
+ *
32
+ * @throws NotAuthorizedException
33
+ */
34
+ authenticate(): Promise<void>;
35
+ /**
36
+ * Refresh tokens using the stored refresh token.
37
+ *
38
+ * @throws NotAuthorizedException
39
+ */
40
+ refreshTokens(): Promise<void>;
41
+ get accessToken(): string;
42
+ get idToken(): string;
43
+ get refreshToken(): string;
44
+ private get commonHeaders();
45
+ private checkApiResponse;
46
+ getUserDetail(): Promise<EvnexUserDetail>;
47
+ getOrgChargePoints(orgId?: string): Promise<EvnexChargePoint[]>;
48
+ getOrgInsight(days: number, orgId?: string, tzOffset?: number): Promise<EvnexOrgInsightEntry[]>;
49
+ getOrgSummaryStatus(orgId?: string): Promise<EvnexOrgSummaryStatus>;
50
+ /** @deprecated Use getChargePointDetailV3 */
51
+ getChargePointDetail(chargePointId: string): Promise<EvnexChargePointDetail>;
52
+ getChargePointDetailV3(chargePointId: string): Promise<EvnexV3APIResponse<EvnexChargePointDetailV3>>;
53
+ getChargePointSolarConfig(chargePointId: string): Promise<EvnexChargePointSolarConfig>;
54
+ getChargePointOverride(chargePointId: string): Promise<EvnexChargePointOverrideConfig>;
55
+ setChargePointOverride(chargePointId: string, chargeNow: boolean, connectorId?: number): Promise<true>;
56
+ getChargePointStatus(chargePointId: string): Promise<EvnexChargePointStatusResponse>;
57
+ /** @deprecated Use getChargePointSessions */
58
+ getChargePointTransactions(chargePointId: string): Promise<EvnexChargePointTransaction[]>;
59
+ getChargePointSessions(chargePointId: string): Promise<EvnexChargePointSession[]>;
60
+ stopChargePoint(chargePointId: string, orgId?: string, connectorId?: string, timeout?: number): Promise<EvnexCommandResponse>;
61
+ enableCharger(orgId: string, chargePointId: string, connectorId?: number | string): Promise<EvnexCommandResponse>;
62
+ disableCharger(orgId: string, chargePointId: string, connectorId?: number | string): Promise<EvnexCommandResponse>;
63
+ setChargerAvailability(orgId: string, chargePointId: string, available?: boolean, connectorId?: number | string, timeout?: number): Promise<EvnexCommandResponse>;
64
+ unlockCharger(chargePointId: string, available?: boolean, connectorId?: string, timeout?: number): Promise<EvnexCommandResponse>;
65
+ setChargerLoadProfile(chargePointId: string, chargingProfilePeriods: EvnexChargeProfileSegment[], enabled?: boolean, duration?: number, units?: string, timeout?: number): Promise<EvnexChargePointLoadSchedule>;
66
+ setChargePointSchedule(chargePointId: string, chargingProfilePeriods: EvnexChargeProfileSegment[], enabled?: boolean, duration?: number, timeout?: number): Promise<EvnexChargePointLoadSchedule>;
67
+ }
@@ -0,0 +1,3 @@
1
+ export declare class NotAuthorizedException extends Error {
2
+ constructor(message?: string);
3
+ }
@@ -0,0 +1,2 @@
1
+ export { Evnex } from "./api";
2
+ export type { EvnexConfig, EvnexTokens } from "./api";
@@ -0,0 +1,9 @@
1
+ export default class Logger {
2
+ private readonly prefix;
3
+ constructor(prefix: string);
4
+ private format;
5
+ debug(msg: string): void;
6
+ info(msg: string): void;
7
+ warn(msg: string): void;
8
+ error(msg: string): void;
9
+ }
@@ -0,0 +1,10 @@
1
+ export interface EvnexModelInfo {
2
+ name: string;
3
+ connector: string;
4
+ cableLength: string;
5
+ colour: string;
6
+ power: string;
7
+ powerSensor: string;
8
+ configuration: string;
9
+ }
10
+ export declare function parseModel(modelId: string): EvnexModelInfo;
@@ -0,0 +1,183 @@
1
+ import type { EvnexCost } from "./cost";
2
+ export declare enum ChargingLogic {
3
+ UNAVAILABLE = "Unavailable",
4
+ NOVEHICLE = "NoVehicle",
5
+ VEHICLE = "Vehicle",
6
+ TRANSFER = "Transfer",
7
+ FAULT = "Fault"
8
+ }
9
+ export declare enum ChargingCurrentControl {
10
+ FULLPOWER = "FullPower",
11
+ THERMALLIMITED = "ThermalLimited",
12
+ LLMLIMITED = "LLMLimited",
13
+ WAITINGSCHEDULE = "WaitingSchedule",
14
+ WAITINGSOLAR = "WaitingSolar",
15
+ SOLARCONTROL = "SolarControl",
16
+ SCHEDULELIMITED = "ScheduleLimited",
17
+ SUPPLYLIMITED = "SupplyLimited"
18
+ }
19
+ export declare enum E2LEDState {
20
+ OFF = "Off",
21
+ IDLE = "Idle",
22
+ CHARGING = "Charging",
23
+ CHARGENOWCHARGING = "ChargeNowCharging",
24
+ CHARGENOWNOTCHARGING = "ChargeNowNotCharging",
25
+ FAULT = "Fault",
26
+ DISABLED = "Disabled",
27
+ WAITSCHEDULE = "WaitSchedule",
28
+ WAITSOLAR = "WaitSolar",
29
+ WAITVEHICLE = "WaitVehicle",
30
+ SHUTTINGDOWN = "ShuttingDown"
31
+ }
32
+ export declare enum AntiSleepState {
33
+ DISABLED = "Disabled",
34
+ ENABLED = "Enabled",
35
+ ACTIVE = "Active",
36
+ NA = "NA"
37
+ }
38
+ export interface ChargePointStatus {
39
+ chargeNow: boolean;
40
+ chargingLogic: ChargingLogic;
41
+ chargingCurrentControl: ChargingCurrentControl;
42
+ LEDState: E2LEDState;
43
+ AntiSleep: AntiSleepState;
44
+ }
45
+ export interface EvnexChargePointConnectorMeter {
46
+ powerType: string;
47
+ updatedDate: Date;
48
+ power: number;
49
+ register: number;
50
+ frequency: number;
51
+ }
52
+ export interface Coordinates {
53
+ latitude: number;
54
+ longitude: number;
55
+ }
56
+ export interface EvnexAddress {
57
+ address1: string;
58
+ address2?: string | null;
59
+ city?: string | null;
60
+ postCode?: string | null;
61
+ state?: string | null;
62
+ country: string;
63
+ }
64
+ export interface EvnexLocation {
65
+ id: string;
66
+ name: string;
67
+ createdDate: Date;
68
+ updatedDate: Date;
69
+ address?: EvnexAddress | null;
70
+ coordinates?: Coordinates | null;
71
+ chargePointCount: number;
72
+ }
73
+ export interface EvnexChargePointConnector {
74
+ powerType: string;
75
+ connectorId: string;
76
+ evseId: string;
77
+ updatedDate: Date;
78
+ connectorType: string;
79
+ amperage: number;
80
+ voltage: number;
81
+ connectorFormat: string;
82
+ ocppStatus: string;
83
+ status: string;
84
+ ocppCode: string;
85
+ meter: EvnexChargePointConnectorMeter;
86
+ }
87
+ export interface EvnexChargePointDetails {
88
+ model: string;
89
+ vendor: string;
90
+ firmware: string;
91
+ iccid?: string | null;
92
+ }
93
+ export interface EvnexChargePointSolarConfig {
94
+ solarWithSchedule: boolean;
95
+ powerSensorInstalled: boolean;
96
+ solarStartExportPower: number;
97
+ solarStopImportPower: number;
98
+ }
99
+ export interface EvnexChargePointOverrideConfig {
100
+ chargeNow: boolean | "NotSupported";
101
+ }
102
+ export interface EvnexChargePointStatus {
103
+ commandResultStatus: string;
104
+ chargePointStatus?: ChargePointStatus | null;
105
+ }
106
+ export interface EvnexChargePointStatusResponse {
107
+ data: EvnexChargePointStatus;
108
+ }
109
+ export interface EvnexChargePointBase {
110
+ id: string;
111
+ createdDate: Date;
112
+ updatedDate: Date;
113
+ networkStatusUpdatedDate: Date;
114
+ name: string;
115
+ ocppChargePointId: string;
116
+ serial: string;
117
+ networkStatus: string;
118
+ location: EvnexLocation;
119
+ }
120
+ export interface EvnexChargePoint extends EvnexChargePointBase {
121
+ details: EvnexChargePointDetails;
122
+ connectors?: EvnexChargePointConnector[] | null;
123
+ lastHeard?: Date | null;
124
+ maxCurrent: number;
125
+ tokenRequired: boolean;
126
+ needsRegistrationInformation: boolean;
127
+ }
128
+ export interface EvnexGetChargePointsItem {
129
+ items: EvnexChargePoint[];
130
+ }
131
+ export interface EvnexGetChargePointsResponse {
132
+ data: EvnexGetChargePointsItem;
133
+ }
134
+ export interface EvnexElectricityCostSegment {
135
+ cost: number;
136
+ start: number;
137
+ }
138
+ export interface EvnexChargeProfileSegment {
139
+ limit: number;
140
+ start: number;
141
+ }
142
+ export interface EvnexElectricityCost {
143
+ currency: string;
144
+ duration?: number | null;
145
+ costs: EvnexElectricityCostSegment[];
146
+ }
147
+ export interface EvnexChargePointConfiguration {
148
+ maxCurrent: number;
149
+ plugAndCharge: boolean;
150
+ }
151
+ export interface EvnexChargePointLoadSchedule {
152
+ duration: number;
153
+ enabled: boolean;
154
+ timezone: string;
155
+ units: string;
156
+ chargingProfilePeriods: EvnexChargeProfileSegment[];
157
+ }
158
+ export interface EvnexChargePointDetail extends EvnexChargePointBase {
159
+ configuration: EvnexChargePointConfiguration;
160
+ electricityCost: EvnexElectricityCost;
161
+ loadSchedule: EvnexChargePointLoadSchedule;
162
+ connectors: EvnexChargePointConnector[];
163
+ }
164
+ export interface EvnexGetChargePointDetailResponse {
165
+ data: EvnexChargePointDetail;
166
+ }
167
+ export interface EvnexChargePointTransaction {
168
+ id: string;
169
+ connectorId: string;
170
+ endDate?: Date | null;
171
+ evseId: string;
172
+ powerUsage: number;
173
+ reason?: string | null;
174
+ startDate: Date;
175
+ carbonOffset?: number | null;
176
+ electricityCost?: EvnexCost | null;
177
+ }
178
+ export interface EvnexChargePointTransactions {
179
+ items: EvnexChargePointTransaction[];
180
+ }
181
+ export interface EvnexGetChargePointTransactionsResponse {
182
+ data: EvnexChargePointTransactions;
183
+ }
@@ -0,0 +1,4 @@
1
+ export interface EvnexCommandResponse {
2
+ message: string;
3
+ status: string;
4
+ }
@@ -0,0 +1,4 @@
1
+ export interface EvnexCost {
2
+ currency: string;
3
+ cost: number;
4
+ }
@@ -0,0 +1,38 @@
1
+ import type { EvnexCost } from "./cost";
2
+ export interface EvnexOrgBrief {
3
+ id: string;
4
+ isDefault: boolean;
5
+ role: number;
6
+ createdDate: Date;
7
+ name: string;
8
+ slug: string;
9
+ tier: number;
10
+ tierDetails: any | null;
11
+ updatedDate: Date;
12
+ }
13
+ export interface EvnexOrgInsightEntry {
14
+ carbonOffset: number;
15
+ cost: EvnexCost;
16
+ duration: number;
17
+ powerUsage: number;
18
+ sessions: number;
19
+ startDate: Date;
20
+ }
21
+ export interface EvnexInsightAttributeWrapper {
22
+ attributes: EvnexOrgInsightEntry;
23
+ }
24
+ export interface EvnexOrgSummaryStatus {
25
+ charging: number;
26
+ available: number;
27
+ disabled: number;
28
+ faulted: number;
29
+ occupied: number;
30
+ offline: number;
31
+ reserved: number;
32
+ }
33
+ export interface EvnexGetOrgInsights {
34
+ data: EvnexInsightAttributeWrapper[];
35
+ }
36
+ export interface EvnexGetOrgSummaryStatusResponse {
37
+ data: EvnexOrgSummaryStatus;
38
+ }
@@ -0,0 +1,13 @@
1
+ import type { EvnexOrgBrief } from "./org";
2
+ export interface EvnexUserDetail {
3
+ id: string;
4
+ createdDate: Date;
5
+ updatedDate: Date;
6
+ name: string;
7
+ email: string;
8
+ organisations: EvnexOrgBrief[];
9
+ type: "User" | "Installer";
10
+ }
11
+ export interface EvnexGetUserResponse {
12
+ data: EvnexUserDetail;
13
+ }
@@ -0,0 +1,99 @@
1
+ import type { EvnexRelationships } from "./relationships";
2
+ import type { EvnexElectricityCost, EvnexElectricityCostTotal } from "./cost";
3
+ export interface EvnexEnergyTransaction {
4
+ meterStart: number;
5
+ startDate: Date;
6
+ meterStop?: number | null;
7
+ endDate?: Date | null;
8
+ reason?: string | null;
9
+ }
10
+ export interface EvnexEnergyUsage {
11
+ total: number;
12
+ distributionByTariff?: any | null;
13
+ distributionByEnergySource?: any | null;
14
+ }
15
+ export interface EvnexChargeSchedulePeriod {
16
+ limit: number;
17
+ startPeriod: number;
18
+ }
19
+ export interface EvnexChargeSchedule {
20
+ enabled: boolean;
21
+ chargingSchedulePeriods: EvnexChargeSchedulePeriod[];
22
+ }
23
+ export interface EvnexChargeProfile {
24
+ chargeSchedule?: EvnexChargeSchedule | null;
25
+ }
26
+ export interface EvnexChargePointConnectorMeter {
27
+ currentL1?: number | null;
28
+ currentL2?: number | null;
29
+ currentL3?: number | null;
30
+ frequency: number;
31
+ power: number;
32
+ register: number;
33
+ updatedDate: Date;
34
+ temperature?: number | null;
35
+ voltageL1N?: number | null;
36
+ voltageL2N?: number | null;
37
+ voltageL3N?: number | null;
38
+ }
39
+ export interface EvnexChargePointConnector {
40
+ evseId: string;
41
+ connectorFormat: string;
42
+ connectorType: string;
43
+ ocppStatus: string;
44
+ powerType: string;
45
+ connectorId: string;
46
+ ocppCode: string;
47
+ updatedDate: Date;
48
+ meter: EvnexChargePointConnectorMeter;
49
+ maxVoltage: number;
50
+ maxAmperage: number;
51
+ }
52
+ export interface EvnexChargePointDetail {
53
+ connectors: EvnexChargePointConnector[];
54
+ createdDate: Date;
55
+ electricityCost: EvnexElectricityCost;
56
+ firmware: string;
57
+ maxCurrent: number;
58
+ model: string;
59
+ name: string;
60
+ networkStatus: string;
61
+ networkStatusUpdatedDate: Date;
62
+ ocppChargePointId: string;
63
+ profiles: EvnexChargeProfile;
64
+ serial: string;
65
+ timeZone: string;
66
+ tokenRequired: boolean;
67
+ updatedDate: Date;
68
+ vendor: string;
69
+ iccid?: string | null;
70
+ }
71
+ export interface EvnexChargePointSessionAttributes {
72
+ totalCarbonUsage?: number | null;
73
+ chargingStarted?: Date | null;
74
+ chargingStopped?: Date | null;
75
+ connectorId?: string | null;
76
+ createdDate?: Date | null;
77
+ evseId?: string | null;
78
+ sessionStatus?: string | null;
79
+ startDate?: Date | null;
80
+ updatedDate?: Date | null;
81
+ authorizationMethod?: string | null;
82
+ electricityCost?: EvnexElectricityCost | null;
83
+ endDate?: Date | null;
84
+ totalChargingTime?: number | null;
85
+ totalDuration?: number | null;
86
+ totalEnergyUsage?: EvnexEnergyUsage | null;
87
+ totalCost?: EvnexElectricityCostTotal | null;
88
+ totalPowerUsage?: number | null;
89
+ transaction?: EvnexEnergyTransaction | null;
90
+ }
91
+ export interface EvnexChargePointSession {
92
+ attributes: EvnexChargePointSessionAttributes;
93
+ id: string;
94
+ type: string;
95
+ relationships?: EvnexRelationships | null;
96
+ }
97
+ export interface EvnexGetChargePointSessionsResponse {
98
+ data: EvnexChargePointSession[];
99
+ }
@@ -0,0 +1,4 @@
1
+ export interface EvnexCommandResponse {
2
+ message: string;
3
+ status: string;
4
+ }
@@ -0,0 +1,16 @@
1
+ export interface EvnexElectricityTariff {
2
+ start: number;
3
+ rate: number;
4
+ type: string;
5
+ }
6
+ export interface EvnexElectricityCost {
7
+ currency: string;
8
+ tariffs: EvnexElectricityTariff[];
9
+ tariffType: string;
10
+ cost?: number | null;
11
+ }
12
+ export interface EvnexElectricityCostTotal {
13
+ currency: string;
14
+ amount: number;
15
+ distribution?: any;
16
+ }
@@ -0,0 +1,16 @@
1
+ import type { EvnexRelationships } from "./relationships";
2
+ export interface EvnexV3Include {
3
+ id: string;
4
+ type: string;
5
+ attributes: Record<string, unknown>;
6
+ }
7
+ export interface EvnexV3Data<T> {
8
+ id: string;
9
+ type: string;
10
+ attributes: T;
11
+ relationships: EvnexRelationships;
12
+ }
13
+ export interface EvnexV3APIResponse<T> {
14
+ data: EvnexV3Data<T>;
15
+ included?: EvnexV3Include[] | null;
16
+ }
@@ -0,0 +1,12 @@
1
+ export interface EvnexRelationship {
2
+ id: string;
3
+ type: string;
4
+ }
5
+ export interface EvnexRelationshipWrapper {
6
+ data?: EvnexRelationship | null;
7
+ }
8
+ export interface EvnexRelationships {
9
+ chargePoint?: EvnexRelationshipWrapper | null;
10
+ location?: EvnexRelationshipWrapper | null;
11
+ organisation?: EvnexRelationshipWrapper | null;
12
+ }
@@ -0,0 +1,13 @@
1
+ export declare enum DeviceStatus {
2
+ OFFLINE = "OFFLINE",
3
+ AVAILABLE = "AVAILABLE",
4
+ PREPARING = "PREPARING",
5
+ CHARGING = "CHARGING",
6
+ SUSPENDED_EVSE = "SUSPENDED_EVSE",
7
+ SUSPENDED_EV = "SUSPENDED_EV",
8
+ FINISHING = "FINISHING",
9
+ RESERVED = "RESERVED",
10
+ UNAVAILABLE = "UNAVAILABLE",
11
+ FAULTED = "FAULTED"
12
+ }
13
+ export declare const ConnectorOcppStatus: Record<DeviceStatus, string>;
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "typescript-evnex",
3
+ "author": "Ben Lawrence",
4
+ "description": "A TypeScript library for interacting with the Evnex API",
5
+ "license": "MIT",
6
+ "version": "1.0.0",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
16
+ "files": ["dist"],
17
+ "scripts": {
18
+ "build": "bun build ./src/index.ts --outdir ./dist --target node --format esm && tsc -p tsconfig.build.json"
19
+ },
20
+ "devDependencies": {
21
+ "@types/bun": "latest",
22
+ "typescript": "^5"
23
+ },
24
+ "dependencies": {
25
+ "@aws-sdk/client-cognito-identity-provider": "^3.1000.0",
26
+ "axios": "^1.13.6",
27
+ "zod": "^4.3.6"
28
+ }
29
+ }