@dimo-network/data-sdk 1.2.1
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/.credentials.json.example +5 -0
- package/.eslintrc.json +20 -0
- package/.github/workflows/npm-publish.yml +42 -0
- package/CONTRIBUTING.md +82 -0
- package/LICENSE +76 -0
- package/README.md +216 -0
- package/dist/api/Method.d.ts +2 -0
- package/dist/api/Method.js +136 -0
- package/dist/api/Method.test.d.ts +1 -0
- package/dist/api/Method.test.js +67 -0
- package/dist/api/Resource.d.ts +11 -0
- package/dist/api/Resource.js +20 -0
- package/dist/api/functions/getToken.d.ts +7 -0
- package/dist/api/functions/getToken.js +20 -0
- package/dist/api/functions/index.d.ts +3 -0
- package/dist/api/functions/index.js +3 -0
- package/dist/api/functions/signChallenge.d.ts +5 -0
- package/dist/api/functions/signChallenge.js +8 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/resources/Attestation/index.d.ts +5 -0
- package/dist/api/resources/Attestation/index.js +21 -0
- package/dist/api/resources/Auth/index.d.ts +5 -0
- package/dist/api/resources/Auth/index.js +42 -0
- package/dist/api/resources/DeviceDefinitions/index.d.ts +5 -0
- package/dist/api/resources/DeviceDefinitions/index.js +29 -0
- package/dist/api/resources/Devices/index.d.ts +5 -0
- package/dist/api/resources/Devices/index.js +154 -0
- package/dist/api/resources/DimoRestResources.d.ts +9 -0
- package/dist/api/resources/DimoRestResources.js +9 -0
- package/dist/api/resources/TokenExchange/index.d.ts +5 -0
- package/dist/api/resources/TokenExchange/index.js +20 -0
- package/dist/api/resources/Trips/index.d.ts +5 -0
- package/dist/api/resources/Trips/index.js +16 -0
- package/dist/api/resources/Valuations/index.d.ts +5 -0
- package/dist/api/resources/Valuations/index.js +23 -0
- package/dist/api/resources/VehicleSignalDecoding/index.d.ts +5 -0
- package/dist/api/resources/VehicleSignalDecoding/index.js +59 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +10 -0
- package/dist/dimo.d.ts +17 -0
- package/dist/dimo.js +68 -0
- package/dist/dimo.test.d.ts +1 -0
- package/dist/dimo.test.js +57 -0
- package/dist/environments/index.d.ts +33 -0
- package/dist/environments/index.js +32 -0
- package/dist/errors/DimoError.d.ts +9 -0
- package/dist/errors/DimoError.js +27 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/graphql/Query.d.ts +2 -0
- package/dist/graphql/Query.js +104 -0
- package/dist/graphql/Query.test.d.ts +1 -0
- package/dist/graphql/Query.test.js +47 -0
- package/dist/graphql/Resource.d.ts +16 -0
- package/dist/graphql/Resource.js +29 -0
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/index.js +1 -0
- package/dist/graphql/resources/DimoGraphqlResources.d.ts +3 -0
- package/dist/graphql/resources/DimoGraphqlResources.js +3 -0
- package/dist/graphql/resources/Identity/index.d.ts +6 -0
- package/dist/graphql/resources/Identity/index.js +100 -0
- package/dist/graphql/resources/Telemetry/index.d.ts +5 -0
- package/dist/graphql/resources/Telemetry/index.js +39 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/streamr/index.d.ts +0 -0
- package/dist/streamr/index.js +51 -0
- package/jest.config.js +16 -0
- package/package.json +43 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DimoEnvironment } from '../environments';
|
|
2
|
+
export interface Resource {
|
|
3
|
+
[key: string]: (...args: any) => any;
|
|
4
|
+
}
|
|
5
|
+
export declare class Resource {
|
|
6
|
+
api: any;
|
|
7
|
+
resourceName: any;
|
|
8
|
+
env: any;
|
|
9
|
+
constructor(api: any, resourceName: string, env: keyof typeof DimoEnvironment);
|
|
10
|
+
protected setResource(resources: any): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Method } from './Method';
|
|
2
|
+
export class Resource {
|
|
3
|
+
api;
|
|
4
|
+
resourceName;
|
|
5
|
+
env;
|
|
6
|
+
constructor(api, resourceName, env) {
|
|
7
|
+
this.api = api;
|
|
8
|
+
this.resourceName = resourceName;
|
|
9
|
+
this.env = env;
|
|
10
|
+
}
|
|
11
|
+
setResource(resources) {
|
|
12
|
+
Object.keys(resources).forEach(key => {
|
|
13
|
+
this[key] = (params = {}) => Method(resources[key], // Setup the endpoint resources
|
|
14
|
+
this.api, // Setup the base URL
|
|
15
|
+
params, // Pass through the params
|
|
16
|
+
this.env // Identiy the environment
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DIMO } from '../../dimo';
|
|
2
|
+
export const getToken = async (input, env) => {
|
|
3
|
+
const sdk = new DIMO(env);
|
|
4
|
+
const challenge = await sdk.auth.generateChallenge({
|
|
5
|
+
client_id: input.client_id,
|
|
6
|
+
domain: input.domain,
|
|
7
|
+
address: input.client_id
|
|
8
|
+
});
|
|
9
|
+
const sign = await sdk.auth.signChallenge({
|
|
10
|
+
message: challenge.challenge,
|
|
11
|
+
private_key: input.private_key
|
|
12
|
+
});
|
|
13
|
+
const submit = await sdk.auth.submitChallenge({
|
|
14
|
+
client_id: input.client_id,
|
|
15
|
+
domain: input.domain,
|
|
16
|
+
state: challenge.state,
|
|
17
|
+
signature: sign
|
|
18
|
+
});
|
|
19
|
+
return submit;
|
|
20
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Web3 } from 'web3';
|
|
2
|
+
import { DimoConstants } from '../../constants';
|
|
3
|
+
export const signChallenge = async (input, env) => {
|
|
4
|
+
const web3 = new Web3(DimoConstants[env].RPC_provider);
|
|
5
|
+
const formatted_key = '0x' + Buffer.from(input.private_key, 'utf8');
|
|
6
|
+
const response = web3.eth.accounts.sign(input.message, formatted_key);
|
|
7
|
+
return response.signature;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resources/DimoRestResources';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resources/DimoRestResources';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class Attestation extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'Attestation', env);
|
|
5
|
+
this.setResource({
|
|
6
|
+
createVinVC: {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
path: '/v1/vc/vin/:tokenId',
|
|
9
|
+
auth: 'privilege_token',
|
|
10
|
+
queryParams: {
|
|
11
|
+
'force': true
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
createPomVC: {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
path: '/v1/vc/pom/:tokenId',
|
|
17
|
+
auth: 'privilege_token'
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class Auth extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'Auth', env);
|
|
5
|
+
this.setResource({
|
|
6
|
+
generateChallenge: {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
path: '/auth/web3/generate_challenge',
|
|
9
|
+
queryParams: {
|
|
10
|
+
'client_id': true,
|
|
11
|
+
'domain': true,
|
|
12
|
+
'scope': 'openid email',
|
|
13
|
+
'response_type': 'code',
|
|
14
|
+
'address': '$client_id'
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
signChallenge: {
|
|
18
|
+
method: 'FUNCTION',
|
|
19
|
+
path: 'signChallenge'
|
|
20
|
+
},
|
|
21
|
+
submitChallenge: {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
path: '/auth/web3/submit_challenge',
|
|
24
|
+
body: {
|
|
25
|
+
'client_id': true,
|
|
26
|
+
'domain': true,
|
|
27
|
+
'grant_type': 'authorization_code',
|
|
28
|
+
'state': true,
|
|
29
|
+
'signature': true
|
|
30
|
+
},
|
|
31
|
+
headers: {
|
|
32
|
+
'content-type': 'application/x-www-form-urlencoded'
|
|
33
|
+
},
|
|
34
|
+
return: 'access_token'
|
|
35
|
+
},
|
|
36
|
+
getToken: {
|
|
37
|
+
method: 'FUNCTION',
|
|
38
|
+
path: 'getToken'
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class DeviceDefinitions extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'DeviceDefinitions', env);
|
|
5
|
+
this.setResource({
|
|
6
|
+
getByMMY: {
|
|
7
|
+
method: 'GET',
|
|
8
|
+
queryParams: {
|
|
9
|
+
'make': true,
|
|
10
|
+
'model': true,
|
|
11
|
+
'year': true
|
|
12
|
+
},
|
|
13
|
+
path: '/device-definitions'
|
|
14
|
+
},
|
|
15
|
+
getById: {
|
|
16
|
+
method: 'GET',
|
|
17
|
+
path: '/device-definitions/:id'
|
|
18
|
+
},
|
|
19
|
+
listDeviceMakes: {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
path: '/device-makes'
|
|
22
|
+
},
|
|
23
|
+
getDeviceTypeById: {
|
|
24
|
+
method: 'GET',
|
|
25
|
+
path: '/device-types/:id'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class Devices extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'Devices', env);
|
|
5
|
+
this.setResource({
|
|
6
|
+
createVehicle: {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
path: '/v1/user/devices',
|
|
9
|
+
body: {
|
|
10
|
+
countryCode: true,
|
|
11
|
+
deviceDefinitionId: true
|
|
12
|
+
},
|
|
13
|
+
auth: 'access_token'
|
|
14
|
+
},
|
|
15
|
+
createVehicleFromSmartcar: {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
path: '/v1/user/devices/fromsmartcar',
|
|
18
|
+
body: {
|
|
19
|
+
code: true,
|
|
20
|
+
countryCode: true,
|
|
21
|
+
redirectURI: true
|
|
22
|
+
},
|
|
23
|
+
auth: 'access_token'
|
|
24
|
+
},
|
|
25
|
+
createVehicleFromVin: {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
path: '/v1/user/devices/fromvin',
|
|
28
|
+
body: {
|
|
29
|
+
canProtocol: false,
|
|
30
|
+
countryCode: true,
|
|
31
|
+
vin: true
|
|
32
|
+
},
|
|
33
|
+
auth: 'access_token'
|
|
34
|
+
},
|
|
35
|
+
updateVehicleVin: {
|
|
36
|
+
method: 'PATCH',
|
|
37
|
+
path: '/v1/user/devices/:userDeviceId/vin',
|
|
38
|
+
auth: 'access_token'
|
|
39
|
+
},
|
|
40
|
+
getClaimingPayload: {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
path: '/v1/aftermarket/device/by-serial/:serial/commands/claim',
|
|
43
|
+
auth: 'access_token'
|
|
44
|
+
},
|
|
45
|
+
signClaimingPayload: {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
path: '/v1/aftermarket/device/by-serial/:serial/commands/claim',
|
|
48
|
+
body: {
|
|
49
|
+
claimRequest: true
|
|
50
|
+
},
|
|
51
|
+
auth: 'access_token'
|
|
52
|
+
},
|
|
53
|
+
getMintingPayload: {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
path: '/v1/user/devices/:userDeviceId/commands/mint',
|
|
56
|
+
auth: 'access_token'
|
|
57
|
+
},
|
|
58
|
+
signMintingPayload: {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
path: '/v1/user/devices/:userDeviceId/commands/mint',
|
|
61
|
+
body: {
|
|
62
|
+
mintRequest: true
|
|
63
|
+
},
|
|
64
|
+
auth: 'access_token'
|
|
65
|
+
},
|
|
66
|
+
optInShareData: {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
path: '/v1/user/devices/:userDeviceId/commands/opt-in',
|
|
69
|
+
auth: 'access_token'
|
|
70
|
+
},
|
|
71
|
+
refreshSmartcarData: {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
path: '/v1/user/devices/:userDeviceId/commands/refresh',
|
|
74
|
+
auth: 'access_token'
|
|
75
|
+
},
|
|
76
|
+
getPairingPayload: {
|
|
77
|
+
method: 'GET',
|
|
78
|
+
path: '/v1/user/devices/:userDeviceId/aftermarket/commands/pair',
|
|
79
|
+
auth: 'access_token'
|
|
80
|
+
},
|
|
81
|
+
signPairingPayload: {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
path: '/v1/user/devices/:userDeviceId/aftermarket/commands/pair',
|
|
84
|
+
body: {
|
|
85
|
+
userSignature: true
|
|
86
|
+
},
|
|
87
|
+
auth: 'access_token'
|
|
88
|
+
},
|
|
89
|
+
getUnpairingPayload: {
|
|
90
|
+
method: 'GET',
|
|
91
|
+
path: '/v1/user/devices/:userDeviceId/aftermarket/commands/unpair',
|
|
92
|
+
auth: 'access_token'
|
|
93
|
+
},
|
|
94
|
+
signUnpairingPayload: {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
path: '/v1/user/devices/:userDeviceId/aftermarket/commands/unpair',
|
|
97
|
+
body: {
|
|
98
|
+
userSignature: true
|
|
99
|
+
},
|
|
100
|
+
auth: 'access_token'
|
|
101
|
+
},
|
|
102
|
+
lockDoors: {
|
|
103
|
+
method: 'POST',
|
|
104
|
+
path: '/v1/vehicle/:tokenId/commands/doors/lock',
|
|
105
|
+
auth: 'privilege_token'
|
|
106
|
+
},
|
|
107
|
+
unlockDoors: {
|
|
108
|
+
method: 'POST',
|
|
109
|
+
path: '/v1/vehicle/:tokenId/commands/doors/unlock',
|
|
110
|
+
auth: 'privilege_token'
|
|
111
|
+
},
|
|
112
|
+
openFrunk: {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
path: '/v1/vehicle/:tokenId/commands/frunk/open',
|
|
115
|
+
auth: 'privilege_token'
|
|
116
|
+
},
|
|
117
|
+
openTrunk: {
|
|
118
|
+
method: 'POST',
|
|
119
|
+
path: '/v1/vehicle/:tokenId/commands/trunk/open',
|
|
120
|
+
auth: 'privilege_token'
|
|
121
|
+
},
|
|
122
|
+
listErrorCodes: {
|
|
123
|
+
method: 'GET',
|
|
124
|
+
path: '/v1/user/devices/:userDeviceId/error-codes',
|
|
125
|
+
auth: 'access_token'
|
|
126
|
+
},
|
|
127
|
+
submitErrorCodes: {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
path: '/v1/user/devices/:userDeviceId/error-codes',
|
|
130
|
+
body: {
|
|
131
|
+
queryDeviceErrorCodes: true
|
|
132
|
+
},
|
|
133
|
+
auth: 'access_token'
|
|
134
|
+
},
|
|
135
|
+
clearErrorCodes: {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
path: '/v1/user/devices/:userDeviceId/error-codes/clear',
|
|
138
|
+
auth: 'access_token'
|
|
139
|
+
},
|
|
140
|
+
getAftermarketDevice: {
|
|
141
|
+
method: 'GET',
|
|
142
|
+
path: '/v1/aftermarket/device/:tokenId',
|
|
143
|
+
},
|
|
144
|
+
getAftermarketDeviceImage: {
|
|
145
|
+
method: 'GET',
|
|
146
|
+
path: '/v1/aftermarket/device/:tokenId/image',
|
|
147
|
+
},
|
|
148
|
+
getAftermarketDeviceMetadataByAddress: {
|
|
149
|
+
method: 'GET',
|
|
150
|
+
path: '/v1/aftermarket/device/by-address/:address',
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Attestation } from './Attestation';
|
|
2
|
+
import { Auth } from './Auth';
|
|
3
|
+
import { DeviceDefinitions } from './DeviceDefinitions';
|
|
4
|
+
import { Devices } from './Devices';
|
|
5
|
+
import { TokenExchange } from './TokenExchange';
|
|
6
|
+
import { Trips } from './Trips';
|
|
7
|
+
import { Valuations } from './Valuations';
|
|
8
|
+
import { VehicleSignalDecoding } from './VehicleSignalDecoding';
|
|
9
|
+
export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleSignalDecoding };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Attestation } from './Attestation';
|
|
2
|
+
import { Auth } from './Auth';
|
|
3
|
+
import { DeviceDefinitions } from './DeviceDefinitions';
|
|
4
|
+
import { Devices } from './Devices';
|
|
5
|
+
import { TokenExchange } from './TokenExchange';
|
|
6
|
+
import { Trips } from './Trips';
|
|
7
|
+
import { Valuations } from './Valuations';
|
|
8
|
+
import { VehicleSignalDecoding } from './VehicleSignalDecoding';
|
|
9
|
+
export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleSignalDecoding };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
import { DimoConstants } from '../../../constants';
|
|
3
|
+
export class TokenExchange extends Resource {
|
|
4
|
+
constructor(api, env) {
|
|
5
|
+
super(api, 'TokenExchange', env);
|
|
6
|
+
this.setResource({
|
|
7
|
+
exchange: {
|
|
8
|
+
method: 'POST',
|
|
9
|
+
path: '/v1/tokens/exchange',
|
|
10
|
+
body: {
|
|
11
|
+
nftContractAddress: DimoConstants[env].NFT_address,
|
|
12
|
+
privileges: true,
|
|
13
|
+
tokenId: true
|
|
14
|
+
},
|
|
15
|
+
auth: 'access_token',
|
|
16
|
+
return: 'privilege_token'
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class Trips extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'Trips', env);
|
|
5
|
+
this.setResource({
|
|
6
|
+
list: {
|
|
7
|
+
method: 'GET',
|
|
8
|
+
path: '/v1/vehicle/:tokenId/trips',
|
|
9
|
+
queryParams: {
|
|
10
|
+
page: false
|
|
11
|
+
},
|
|
12
|
+
auth: 'privilege_token'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class Valuations extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'Valuations', env);
|
|
5
|
+
this.setResource({
|
|
6
|
+
getValuations: {
|
|
7
|
+
method: 'GET',
|
|
8
|
+
path: '/v1/user/devices/:userDeviceId/valuations',
|
|
9
|
+
auth: 'access_token'
|
|
10
|
+
},
|
|
11
|
+
getInstantOffers: {
|
|
12
|
+
method: 'GET',
|
|
13
|
+
path: '/v1/user/devices/:userDeviceId/instant-offer',
|
|
14
|
+
auth: 'access_token'
|
|
15
|
+
},
|
|
16
|
+
getOffers: {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
path: '/v1/user/devices/:userDeviceId/offers',
|
|
19
|
+
auth: 'access_token'
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class VehicleSignalDecoding extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'VehicleSignalDecoding', env);
|
|
5
|
+
this.setResource({
|
|
6
|
+
listConfigUrlsByVin: {
|
|
7
|
+
method: 'GET',
|
|
8
|
+
path: '/v1/device-config/vin/:vin/urls',
|
|
9
|
+
queryParams: {
|
|
10
|
+
protocol: false
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
listConfigUrlsByAddress: {
|
|
14
|
+
method: 'GET',
|
|
15
|
+
path: '/v1/device-config/eth-addr/:address/urls',
|
|
16
|
+
queryParams: {
|
|
17
|
+
protocol: false
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
getPidConfigs: {
|
|
21
|
+
method: 'GET',
|
|
22
|
+
path: '/v1/device-config/pids/:templateName',
|
|
23
|
+
},
|
|
24
|
+
getDeviceSettings: {
|
|
25
|
+
method: 'GET',
|
|
26
|
+
path: '/v1/device-config/settings/:templateName',
|
|
27
|
+
},
|
|
28
|
+
getDbcText: {
|
|
29
|
+
method: 'GET',
|
|
30
|
+
path: '/v1/device-config/dbc/:templateName'
|
|
31
|
+
},
|
|
32
|
+
getDeviceStatusByAddress: {
|
|
33
|
+
method: 'GET',
|
|
34
|
+
path: '/v1/device-config/eth-addr/:address/status',
|
|
35
|
+
},
|
|
36
|
+
setDeviceStatusByAddress: {
|
|
37
|
+
method: 'PATCH',
|
|
38
|
+
path: '/v1/device-config/eth-addr/:address/status',
|
|
39
|
+
body: {
|
|
40
|
+
config: true
|
|
41
|
+
},
|
|
42
|
+
auth: 'privilege_token'
|
|
43
|
+
},
|
|
44
|
+
getJobsByAddress: {
|
|
45
|
+
method: 'GET',
|
|
46
|
+
path: '/v1/device-config/eth-addr/:address/jobs'
|
|
47
|
+
},
|
|
48
|
+
getPendingJobsByAddress: {
|
|
49
|
+
method: 'GET',
|
|
50
|
+
path: '/v1/device-config/eth-addr/:address/jobs/pending'
|
|
51
|
+
},
|
|
52
|
+
setJobStatusByAddress: {
|
|
53
|
+
method: 'PATCH',
|
|
54
|
+
path: '/v1/device-config/eth-addr/:address/jobs/:jobId/:status',
|
|
55
|
+
auth: 'privilege_token'
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const DimoConstants: {
|
|
2
|
+
readonly Production: {
|
|
3
|
+
readonly NFT_address: "0xbA5738a18d83D41847dfFbDC6101d37C69c9B0cF";
|
|
4
|
+
readonly RPC_provider: "https://eth.llamarpc.com";
|
|
5
|
+
};
|
|
6
|
+
readonly Dev: {
|
|
7
|
+
readonly NFT_address: "0x45fbCD3ef7361d156e8b16F5538AE36DEdf61Da8";
|
|
8
|
+
readonly RPC_provider: "https://eth.llamarpc.com";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type DimoConstants = typeof DimoConstants.Production | typeof DimoConstants.Dev;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const DimoConstants = {
|
|
2
|
+
Production: {
|
|
3
|
+
'NFT_address': '0xbA5738a18d83D41847dfFbDC6101d37C69c9B0cF',
|
|
4
|
+
'RPC_provider': 'https://eth.llamarpc.com',
|
|
5
|
+
},
|
|
6
|
+
Dev: {
|
|
7
|
+
'NFT_address': '0x45fbCD3ef7361d156e8b16F5538AE36DEdf61Da8',
|
|
8
|
+
'RPC_provider': 'https://eth.llamarpc.com',
|
|
9
|
+
}
|
|
10
|
+
};
|
package/dist/dimo.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DimoEnvironment } from './environments';
|
|
2
|
+
import { Identity, Telemetry } from './graphql/resources/DimoGraphqlResources';
|
|
3
|
+
import { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleSignalDecoding } from './api/resources/DimoRestResources';
|
|
4
|
+
export declare class DIMO {
|
|
5
|
+
attestation: Attestation;
|
|
6
|
+
auth: Auth;
|
|
7
|
+
devicedefinitions: DeviceDefinitions;
|
|
8
|
+
devices: Devices;
|
|
9
|
+
identity: Identity;
|
|
10
|
+
telemetry: Telemetry;
|
|
11
|
+
tokenexchange: TokenExchange;
|
|
12
|
+
trips: Trips;
|
|
13
|
+
valuations: Valuations;
|
|
14
|
+
vehiclesignaldecoding: VehicleSignalDecoding;
|
|
15
|
+
constructor(env: keyof typeof DimoEnvironment);
|
|
16
|
+
authenticate(): Promise<any>;
|
|
17
|
+
}
|
package/dist/dimo.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DimoEnvironment } from './environments';
|
|
2
|
+
import { DimoError } from './errors';
|
|
3
|
+
import { Identity, Telemetry } from './graphql/resources/DimoGraphqlResources';
|
|
4
|
+
import { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleSignalDecoding } from './api/resources/DimoRestResources';
|
|
5
|
+
// import { Stream } from './streamr';
|
|
6
|
+
export class DIMO {
|
|
7
|
+
attestation;
|
|
8
|
+
auth;
|
|
9
|
+
devicedefinitions;
|
|
10
|
+
devices;
|
|
11
|
+
identity;
|
|
12
|
+
telemetry;
|
|
13
|
+
tokenexchange;
|
|
14
|
+
trips;
|
|
15
|
+
valuations;
|
|
16
|
+
vehiclesignaldecoding;
|
|
17
|
+
constructor(env) {
|
|
18
|
+
this.identity = new Identity(DimoEnvironment[env].Identity, env);
|
|
19
|
+
this.telemetry = new Telemetry(DimoEnvironment[env].Telemetry, env);
|
|
20
|
+
/**
|
|
21
|
+
* Set up all REST Endpoints
|
|
22
|
+
*/
|
|
23
|
+
this.attestation = new Attestation(DimoEnvironment[env].Attestation, env);
|
|
24
|
+
this.auth = new Auth(DimoEnvironment[env].Auth, env);
|
|
25
|
+
this.devicedefinitions = new DeviceDefinitions(DimoEnvironment[env].DeviceDefinitions, env);
|
|
26
|
+
this.devices = new Devices(DimoEnvironment[env].Devices, env);
|
|
27
|
+
this.tokenexchange = new TokenExchange(DimoEnvironment[env].TokenExchange, env);
|
|
28
|
+
this.trips = new Trips(DimoEnvironment[env].Trips, env);
|
|
29
|
+
this.valuations = new Valuations(DimoEnvironment[env].Valuations, env);
|
|
30
|
+
this.vehiclesignaldecoding = new VehicleSignalDecoding(DimoEnvironment[env].VehicleSignalDecoding, env);
|
|
31
|
+
}
|
|
32
|
+
// Helper Function
|
|
33
|
+
async authenticate() {
|
|
34
|
+
let fs;
|
|
35
|
+
try {
|
|
36
|
+
// Dynamically import fs
|
|
37
|
+
if (typeof process !== 'undefined' && process.versions && process.versions.node) {
|
|
38
|
+
fs = await import('fs');
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Optionally handle the case where 'fs' is not available, returns null
|
|
42
|
+
console.log('Not in Node.js environment; `fs` module is not available.');
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (!fs.existsSync('.credentials.json')) {
|
|
46
|
+
throw new DimoError({
|
|
47
|
+
message: 'Credentials file does not exist'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const data = fs.readFileSync('.credentials.json', 'utf8');
|
|
51
|
+
const credentials = JSON.parse(data);
|
|
52
|
+
const authHeader = await this.auth.getToken({
|
|
53
|
+
client_id: credentials.client_id,
|
|
54
|
+
domain: credentials.redirect_uri,
|
|
55
|
+
private_key: credentials.private_key,
|
|
56
|
+
});
|
|
57
|
+
return authHeader;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// Handle file not existing and other errors
|
|
61
|
+
console.error('Failed to authenticate:', error.message);
|
|
62
|
+
// Decide whether to throw the error or handle it differently
|
|
63
|
+
throw new DimoError({
|
|
64
|
+
message: 'Authentication failed'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|