@dimo-network/data-sdk 1.2.1 → 1.2.2

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/CONTRIBUTING.md CHANGED
@@ -64,19 +64,17 @@ If you find a bug or have a suggestion for improving an existing example, please
64
64
  2. Under the `constructor`, locate a `this.setResource()` function call
65
65
  3. Update the endpoint of interest accordingly
66
66
 
67
- [Note] Some Vehicle Signal Decoding API endpoints uses `eth-addr` as one of the query parameters, for clarification and style purposes, please use `address` as the key when you pass a query parameter.
68
-
69
- ### Updating SDK Functions
70
- 1. Locate the functions under `/src/api/functions`
71
- 2. Update existing functions or create new functions
72
- 3. Export the modified function(s) in `/src/api/functions/index.ts`
73
- 4. Locate the resource mapping under `/src/api/resources/<directory>/index.ts`
74
- 5. Apply the new changes under `this.setResource()` function call
75
-
76
67
  ### Updating GraphQL Queries
77
68
  1. Locate the queries under `/src/graphql/resources/<directory>/index.ts`
78
69
  2. Under the `constructor`, locate a `this.setQueries()` function call
79
70
  3. Update the query of interest accordingly
80
71
 
72
+ ### Updating SDK Utility Functions
73
+ 1. Locate the functions under `/src/api/functions` or `/src/graphql/functions`
74
+ 2. Update existing functions or create new functions
75
+ 3. Export the modified function(s) in `/src/api/functions/index.ts` or `/src/graphql/functions/index.ts`
76
+ 4. Locate the resource mapping under `/src/api/resources/<directory>/index.ts` or `/src/graphql/resources/<directory>/index.ts`
77
+ 5. Apply the new changes under `this.setResource()` for REST API or `this.setQueries()` for GraphQL API
78
+
81
79
  ### Translating the README
82
80
  DIMO welcomes translation work done on the SDK.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  ![X (formerly Twitter) URL](https://img.shields.io/twitter/url?url=https%3A%2F%2Ftwitter.com%2FDIMO_Network&style=social)
7
7
 
8
8
  # DIMO Data SDK
9
- This is an official DIMO Data SDK written in NodeJS/TypeScript. The objective of this project is to make our API more accessible to the general public.
9
+ This is an official DIMO Data SDK written in TypeScript. The objective of this project is to make our API more accessible to the general public.
10
10
 
11
11
  ## Installation
12
12
  Use [npm](https://www.npmjs.com/package/@dimo-network/data-sdk):
@@ -33,53 +33,50 @@ Import the SDK library:
33
33
  import { DIMO } from '@dimo-network/data-sdk';
34
34
  ```
35
35
 
36
- Initiate the SDK depending on the environment of your interest, we currently support both `Production` and `Dev` environments:
36
+ Initiate the SDK:
37
37
 
38
38
  ```ts
39
39
  const dimo = new DIMO('Production');
40
40
  ```
41
- or
42
41
 
43
- ```ts
44
- const dimo = new DIMO('Dev');
45
- ```
46
42
  ### Developer Registration
47
43
  As part of the authentication process, you will need to obtain a Developer License via the [DIMO Developer Console](https://console.dimo.org/). To get started with registration, follow the steps below:
48
44
  1. Sign up on the [DIMO Developer Console](https://console.dimo.org/).
49
- 2. Get DIMO Credits either by paying in your local currency (via Stripe) or paying with a balance (if you have one).
45
+ 2. Get DIMO Credits (DCX) either by paying in your local currency (via Stripe) or paying with a balance (if you have one).
50
46
  3. Click on `Create app` and fill out the details about your project namespace (external-facing, e.g. `Drive2Survive LLC.`) and your application name (internal, e.g. `app-prod`)
51
- 4. Generate an API key and add in your preferred redirect URI
47
+ 4. Generate an API key and add in your preferred redirect URI.
52
48
 
53
49
  ### Authentication
54
50
 
55
- The SDK provides you with all the steps needed in the [Authentication Flow](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication) to obtain an `access_token`.
51
+ The SDK provides you with all the steps needed in the [Authentication Flow](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication) to obtain a Developer JWT.
56
52
 
57
53
  #### Prerequisites for Authentication
58
- 1. A valid Developer License
59
- 2. A valid API key
54
+ 1. A valid Developer License with a `client_id`
55
+ 2. A valid API key, generated via the Developer Console
56
+ 3. A proper [project set up with TypeScript](https://www.digitalocean.com/community/tutorials/setting-up-a-node-project-with-typescript).
60
57
 
61
58
  #### API Authentication
62
59
 
63
60
  ##### (Option 1 - PREFERRED) getToken Function
64
- As mentioned earlier, this is the streamlined function call to directly get the `access_token`. The `address` field in challenge generation is omitted since it is essentially the `client_id` of your application per Developer License:
61
+ This is a utility function call to get a Developer JWT in one step:
65
62
 
66
63
  ```ts
67
- const authHeader = await dimo.auth.getToken({
64
+ const developerJwt = await dimo.auth.getToken({
68
65
  client_id: '<client_id>',
69
66
  domain: '<domain>',
70
- private_key: '<private_key>',
67
+ private_key: '<api_key>',
71
68
  });
72
69
  ```
73
70
 
74
- Once you have the `authHeader`, you'll have access to the DIMO API endpoints. For endpoints that require the authorization headers, you can simply pass the results.
71
+ Once you have the `developerJwt`, you'll have access to the DIMO API endpoints. For endpoints that require the authorization headers, you can simply pass the results.
75
72
 
76
73
  ```ts
77
- // Pass the auth object to a protected endpoint
78
- await dimo.user.get(auth);
74
+ // Pass the developerJwt object to a protected endpoint
75
+ await dimo.user.get(developerJwt);
79
76
 
80
- // Pass the auth object to a protected endpoint with body parameters
77
+ // Pass the developerJwt object to a protected endpoint with body parameters
81
78
  await dimo.tokenexchange.exchange({
82
- ...auth,
79
+ ...developerJwt,
83
80
  privileges: [4],
84
81
  tokenId: <vehicle_token_id>
85
82
  });
@@ -93,7 +90,7 @@ Start by navigating to the SDK directory that was installed, if you used NPM, yo
93
90
 
94
91
  ```ts
95
92
  // After .credentials.json are provided
96
- const authHeader = await dimo.authenticate();
93
+ const developerJwt = await dimo.authenticate();
97
94
  // The rest would be the same as option 1
98
95
  ```
99
96
 
@@ -102,20 +99,20 @@ The SDK supports async await and your typical JS Promises. HTTP operations can b
102
99
 
103
100
  ```ts
104
101
  // Async Await
105
- async function getAllDeviceMakes() {
102
+ async function countCars() {
106
103
  try {
107
- let response = await dimo.devicedefinitions.listDeviceMakes();
104
+ let response = await dimo.identity.countDimoVehicles();
108
105
  // Do something with the response
109
106
  }
110
107
  catch (err) { /* ... */ }
111
108
  }
112
- getAllDeviceMakes();
109
+ countCars();
113
110
  ```
114
111
 
115
112
  ```js
116
113
  // JS Promises
117
- dimo.devicedefinitions.listDeviceMakes().then((result) => {
118
- return result.device_makes.length;
114
+ dimo.identity.countDimoVehicles().then((result) => {
115
+ return result;
119
116
  }).catch((err) => {
120
117
  /* ...handle the error... */
121
118
  });
@@ -125,9 +122,9 @@ dimo.devicedefinitions.listDeviceMakes().then((result) => {
125
122
 
126
123
  For query parameters, simply feed in an input that matches with the expected query parameters:
127
124
  ```ts
128
- dimo.devicedefinitions.getByMMY({
129
- make: '<vehicle_make>',
130
- model: '<vehicle_model',
125
+ dimo.devicedefinitions.search({
126
+ query: '<query>',
127
+ makeSlug: '<makeSlug>',
131
128
  year: 2021
132
129
  });
133
130
  ```
@@ -135,17 +132,21 @@ dimo.devicedefinitions.getByMMY({
135
132
 
136
133
  For path parameters, simply feed in an input that matches with the expected path parameters:
137
134
  ```ts
138
- dimo.devicedefinitions.getById({ id: '26G4j1YDKZhFeCsn12MAlyU3Y2H' })
135
+ dimo.attestation.createVinVC({
136
+ ...vehicle_jwt,
137
+ tokenId: 117315,
138
+ force: false
139
+ })
139
140
  ```
140
141
 
141
- #### Permission Tokens
142
+ #### Vehicle JWT
142
143
 
143
- As the 2nd leg of the API authentication, applications may exchange for short-lived [permissions JWT](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication#getting-a-jwt) for specific vehicles that granted permissions to the app. This uses the [DIMO Token Exchange API](https://docs.dimo.org/developer-platform/api-references/dimo-protocol/token-exchange-api/token-exchange-api-endpoints).
144
+ As the 2nd leg of the API authentication, applications may exchange for short-lived [Vehicle JWT](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication#getting-a-jwt) for specific vehicles that granted permissions to the app. This uses the [DIMO Token Exchange API](https://docs.dimo.org/developer-platform/api-references/dimo-protocol/token-exchange-api/token-exchange-api-endpoints).
144
145
 
145
- For the end users of your application, they will need to share their vehicle permissions via the DIMO Mobile App or via your implementation of [Login with DIMO](https://docs.dimo.org/developer-platform/getting-started/developer-guide/login-with-dimo). Once vehicles are shared, you will be able to get a permissions JWT.
146
+ For the end users of your application, they will need to share their vehicle permissions via the DIMO Mobile App or via your implementation of [Login with DIMO](https://docs.dimo.org/developer-platform/getting-started/developer-guide/login-with-dimo) or even by sharing on the Vehicle NFT directly. Once vehicles are shared, you will be able to get a Vehicle JWT.
146
147
 
147
148
  ```ts
148
- const privToken = await dimo.tokenexchange.exchange({
149
+ const vehicle_jwt = await dimo.tokenexchange.exchange({
149
150
  ...auth,
150
151
  privileges: [1, 5],
151
152
  tokenId: <vehicle_token_id>
@@ -153,19 +154,19 @@ const privToken = await dimo.tokenexchange.exchange({
153
154
 
154
155
  // Vehicle Status uses privId 1
155
156
  await dimo.devicedata.getVehicleStatus({
156
- ...privToken,
157
+ ...vehicle_jwt,
157
158
  tokenId: <vehicle_token_id>
158
159
  });
159
160
 
160
161
  // Proof of Movement Verifiable Credentials uses privId 4
161
162
  await dimo.attestation.createPomVC({
162
- ...privToken,
163
+ ...vehicle_jwt,
163
164
  tokenId: <vehicle_token_id>
164
165
  })
165
166
 
166
167
  // VIN Verifiable Credentials uses privId 5
167
168
  await dimo.attestation.createVinVC({
168
- ...privToken,
169
+ ...vehicle_jwt,
169
170
  tokenId: <vehicle_token_id>
170
171
  });
171
172
  ```
@@ -178,14 +179,14 @@ The SDK accepts any type of valid custom GraphQL queries, but we've also include
178
179
  The GraphQL entry points are designed almost identical to the REST API entry points. For any GraphQL API that requires auth headers (Telemetry API for example), you can use the same pattern as you would in the REST protected endpoints.
179
180
 
180
181
  ```ts
181
- const privToken = await dimo.tokenexchange.exchange({
182
- ...auth,
182
+ const vehicleJwt = await dimo.tokenexchange.exchange({
183
+ ...vehicleJwt,
183
184
  privileges: [1, 3, 4],
184
185
  tokenId: <vehicle_token_id>
185
186
  });
186
187
 
187
- const tele = await dimo.telemetry.query({
188
- ...privToken,
188
+ const something = await dimo.telemetry.query({
189
+ ...vehicleJwt,
189
190
  query: `
190
191
  query {
191
192
  some_valid_GraphQL_query
@@ -193,11 +194,24 @@ const tele = await dimo.telemetry.query({
193
194
  `
194
195
  });
195
196
  ```
197
+ #### Getting a Vehicle's VIN
198
+ In order to get to the VIN of a given vehicle, your application (aka Developer License) will need [permissions to view VIN credentials (Privilege ID: 5)](https://docs.dimo.org/developer-platform/api-references/token-exchange-api#privilege-definitions). As long as you have permissions to view the vehicle's VIN, simply call the `getVin` utility function.
199
+
200
+ ```ts
201
+ const getVin = async(vehicle_jwt: any) => {
202
+ return await dimo.telemetry.getVin({
203
+ ...vehicle_jwt,
204
+ tokenId: <vehicle_token_id>
205
+ });
206
+ }
207
+ ```
208
+
209
+ This utility function streamlines two calls: [Creating a VIN VC on Attestation API](https://docs.dimo.org/developer-platform/api-references/attestation-api#create-a-vehicle-vin-vc) and [Getting the Latest VIN VC on Telemetry API](https://docs.dimo.org/developer-platform/api-references/attestation-api#create-a-vehicle-vin-vc).
196
210
 
197
211
  #### Send a custom GraphQL query
198
212
  To send a custom GraphQL query, you can simply call the `query` function on any GraphQL API Endpoints and pass in any valid GraphQL query. To check whether your GraphQL query is valid, please visit our [Identity API GraphQL Playground](https://identity-api.dimo.zone/) or [Telemetry API GraphQL Playground](https://telemetry-api.dimo.zone/).
199
213
 
200
- ```js
214
+ ```ts
201
215
  const yourQuery = `{
202
216
  vehicles (first:10) {
203
217
  totalCount
@@ -6,7 +6,7 @@ export const Method = async (resource, baseUrl, params = {}, env) => {
6
6
  * Headers
7
7
  */
8
8
  let headers = {};
9
- if (['access_token', 'privilege_token'].includes(resource.auth)) {
9
+ if (['developer_jwt', 'vehicle_jwt'].includes(resource.auth)) {
10
10
  if (params.headers.Authorization) {
11
11
  headers = params.headers;
12
12
  }
@@ -115,12 +115,12 @@ export const Method = async (resource, baseUrl, params = {}, env) => {
115
115
  if (!resource.return) {
116
116
  return response.data;
117
117
  }
118
- // Special returns for access_token & privilege token
118
+ // Special returns for different JWTs
119
119
  let authHeader = {};
120
- if (resource.return === 'access_token') {
120
+ if (resource.return === 'developer_jwt') {
121
121
  authHeader = { Authorization: `Bearer ${response.data.access_token}` };
122
122
  }
123
- else if (resource.return === 'privilege_token') {
123
+ else if (resource.return === 'vehicle_jwt') {
124
124
  authHeader = { Authorization: `Bearer ${response.data.token}` };
125
125
  }
126
126
  return { headers: authHeader };
@@ -6,15 +6,15 @@ export class Attestation extends Resource {
6
6
  createVinVC: {
7
7
  method: 'POST',
8
8
  path: '/v1/vc/vin/:tokenId',
9
- auth: 'privilege_token',
9
+ auth: 'vehicle_jwt',
10
10
  queryParams: {
11
- 'force': true
11
+ 'force': false
12
12
  }
13
13
  },
14
14
  createPomVC: {
15
15
  method: 'POST',
16
16
  path: '/v1/vc/pom/:tokenId',
17
- auth: 'privilege_token'
17
+ auth: 'vehicle_jwt'
18
18
  }
19
19
  });
20
20
  }
@@ -31,7 +31,7 @@ export class Auth extends Resource {
31
31
  headers: {
32
32
  'content-type': 'application/x-www-form-urlencoded'
33
33
  },
34
- return: 'access_token'
34
+ return: 'developer_jwt'
35
35
  },
36
36
  getToken: {
37
37
  method: 'FUNCTION',
@@ -3,26 +3,26 @@ export class DeviceDefinitions extends Resource {
3
3
  constructor(api, env) {
4
4
  super(api, 'DeviceDefinitions', env);
5
5
  this.setResource({
6
- getByMMY: {
7
- method: 'GET',
8
- queryParams: {
9
- 'make': true,
10
- 'model': true,
11
- 'year': true
6
+ decodeVin: {
7
+ method: 'POST',
8
+ path: '/device-definitions/decode-vin',
9
+ body: {
10
+ countryCode: true,
11
+ vin: true
12
12
  },
13
- path: '/device-definitions'
14
- },
15
- getById: {
16
- method: 'GET',
17
- path: '/device-definitions/:id'
13
+ auth: 'developer_jwt'
18
14
  },
19
- listDeviceMakes: {
15
+ search: {
20
16
  method: 'GET',
21
- path: '/device-makes'
22
- },
23
- getDeviceTypeById: {
24
- method: 'GET',
25
- path: '/device-types/:id'
17
+ path: '/device-definitions/search',
18
+ queryParams: {
19
+ query: true,
20
+ makeSlug: false,
21
+ modelSlug: false,
22
+ year: false,
23
+ page: false,
24
+ pageSize: false
25
+ }
26
26
  }
27
27
  });
28
28
  }
@@ -2,153 +2,6 @@ import { Resource } from '../../Resource';
2
2
  export class Devices extends Resource {
3
3
  constructor(api, env) {
4
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
- });
5
+ this.setResource({});
153
6
  }
154
7
  }
@@ -5,5 +5,4 @@ import { Devices } from './Devices';
5
5
  import { TokenExchange } from './TokenExchange';
6
6
  import { Trips } from './Trips';
7
7
  import { Valuations } from './Valuations';
8
- import { VehicleSignalDecoding } from './VehicleSignalDecoding';
9
- export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleSignalDecoding };
8
+ export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations };
@@ -5,5 +5,4 @@ import { Devices } from './Devices';
5
5
  import { TokenExchange } from './TokenExchange';
6
6
  import { Trips } from './Trips';
7
7
  import { Valuations } from './Valuations';
8
- import { VehicleSignalDecoding } from './VehicleSignalDecoding';
9
- export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleSignalDecoding };
8
+ export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations };
@@ -12,8 +12,8 @@ export class TokenExchange extends Resource {
12
12
  privileges: true,
13
13
  tokenId: true
14
14
  },
15
- auth: 'access_token',
16
- return: 'privilege_token'
15
+ auth: 'developer_jwt',
16
+ return: 'vehicle_jwt'
17
17
  }
18
18
  });
19
19
  }
@@ -9,7 +9,7 @@ export class Trips extends Resource {
9
9
  queryParams: {
10
10
  page: false
11
11
  },
12
- auth: 'privilege_token'
12
+ auth: 'vehicle_jwt'
13
13
  }
14
14
  });
15
15
  }
@@ -5,18 +5,18 @@ export class Valuations extends Resource {
5
5
  this.setResource({
6
6
  getValuations: {
7
7
  method: 'GET',
8
- path: '/v1/user/devices/:userDeviceId/valuations',
9
- auth: 'access_token'
8
+ path: '/v2/vehicles/:tokenId/valuations',
9
+ auth: 'vehicle_jwt'
10
10
  },
11
11
  getInstantOffers: {
12
12
  method: 'GET',
13
- path: '/v1/user/devices/:userDeviceId/instant-offer',
14
- auth: 'access_token'
13
+ path: '/v2/vehicles/:tokenId/instant-offer',
14
+ auth: 'vehicle_jwt'
15
15
  },
16
16
  getOffers: {
17
17
  method: 'GET',
18
- path: '/v1/user/devices/:userDeviceId/offers',
19
- auth: 'access_token'
18
+ path: '/v2/vehicles/:tokenId/offers',
19
+ auth: 'vehicle_jwt'
20
20
  }
21
21
  });
22
22
  }
package/dist/dimo.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DimoEnvironment } from './environments';
2
2
  import { Identity, Telemetry } from './graphql/resources/DimoGraphqlResources';
3
- import { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleSignalDecoding } from './api/resources/DimoRestResources';
3
+ import { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations } from './api/resources/DimoRestResources';
4
4
  export declare class DIMO {
5
5
  attestation: Attestation;
6
6
  auth: Auth;
@@ -11,7 +11,6 @@ export declare class DIMO {
11
11
  tokenexchange: TokenExchange;
12
12
  trips: Trips;
13
13
  valuations: Valuations;
14
- vehiclesignaldecoding: VehicleSignalDecoding;
15
14
  constructor(env: keyof typeof DimoEnvironment);
16
15
  authenticate(): Promise<any>;
17
16
  }
package/dist/dimo.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DimoEnvironment } from './environments';
2
2
  import { DimoError } from './errors';
3
3
  import { Identity, Telemetry } from './graphql/resources/DimoGraphqlResources';
4
- import { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleSignalDecoding } from './api/resources/DimoRestResources';
4
+ import { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations } from './api/resources/DimoRestResources';
5
5
  // import { Stream } from './streamr';
6
6
  export class DIMO {
7
7
  attestation;
@@ -13,7 +13,6 @@ export class DIMO {
13
13
  tokenexchange;
14
14
  trips;
15
15
  valuations;
16
- vehiclesignaldecoding;
17
16
  constructor(env) {
18
17
  this.identity = new Identity(DimoEnvironment[env].Identity, env);
19
18
  this.telemetry = new Telemetry(DimoEnvironment[env].Telemetry, env);
@@ -27,7 +26,6 @@ export class DIMO {
27
26
  this.tokenexchange = new TokenExchange(DimoEnvironment[env].TokenExchange, env);
28
27
  this.trips = new Trips(DimoEnvironment[env].Trips, env);
29
28
  this.valuations = new Valuations(DimoEnvironment[env].Valuations, env);
30
- this.vehiclesignaldecoding = new VehicleSignalDecoding(DimoEnvironment[env].VehicleSignalDecoding, env);
31
29
  }
32
30
  // Helper Function
33
31
  async authenticate() {
package/dist/dimo.test.js CHANGED
@@ -14,7 +14,6 @@ describe('Production Environment', () => {
14
14
  expect(dimo.tokenexchange.env).toBe(PROD);
15
15
  expect(dimo.trips.env).toBe(PROD);
16
16
  expect(dimo.valuations.env).toBe(PROD);
17
- expect(dimo.vehiclesignaldecoding.env).toBe(PROD);
18
17
  });
19
18
  test('Production API endpoints are defined', () => {
20
19
  expect(dimo.attestation.api).toBeDefined;
@@ -26,7 +25,6 @@ describe('Production Environment', () => {
26
25
  expect(dimo.tokenexchange.api).toBeDefined;
27
26
  expect(dimo.trips.api).toBeDefined;
28
27
  expect(dimo.valuations.api).toBeDefined;
29
- expect(dimo.vehiclesignaldecoding.api).toBeDefined;
30
28
  });
31
29
  });
32
30
  describe('Dev Environment', () => {
@@ -40,7 +38,6 @@ describe('Dev Environment', () => {
40
38
  expect(devDimo.tokenexchange.env).toBe(DEV);
41
39
  expect(devDimo.trips.env).toBe(DEV);
42
40
  expect(devDimo.valuations.env).toBe(DEV);
43
- expect(devDimo.vehiclesignaldecoding.env).toBe(DEV);
44
41
  });
45
42
  test('Dev API endpoints are defined', () => {
46
43
  expect(devDimo.attestation.api).toBeDefined;
@@ -52,6 +49,5 @@ describe('Dev Environment', () => {
52
49
  expect(devDimo.tokenexchange.api).toBeDefined;
53
50
  expect(devDimo.trips.api).toBeDefined;
54
51
  expect(devDimo.valuations.api).toBeDefined;
55
- expect(devDimo.vehiclesignaldecoding.api).toBeDefined;
56
52
  });
57
53
  });
@@ -1,2 +1,3 @@
1
- export declare const Query: (resource: any, baseUrl: any, params?: any) => Promise<any>;
1
+ import { DimoEnvironment } from '../environments';
2
+ export declare const Query: (resource: any, baseUrl: any, params: any, env: keyof typeof DimoEnvironment) => Promise<any>;
2
3
  export declare const CustomQuery: (resource: any, baseUrl: string, params?: any) => Promise<any>;
@@ -1,12 +1,13 @@
1
1
  import axios from 'axios';
2
+ import * as functionIndex from '../graphql/functions/';
2
3
  import { DimoError } from '../errors';
3
4
  // GraphQL query factory function
4
- export const Query = async (resource, baseUrl, params = {}) => {
5
+ export const Query = async (resource, baseUrl, params = {}, env) => {
5
6
  /**
6
7
  * Headers
7
8
  */
8
9
  let headers = {};
9
- if (['access_token', 'privilege_token'].includes(resource.auth)) {
10
+ if (['developer_jwt', 'vehicle_jwt'].includes(resource.auth)) {
10
11
  if (params.headers.Authorization) {
11
12
  headers = params.headers;
12
13
  }
@@ -24,6 +25,21 @@ export const Query = async (resource, baseUrl, params = {}) => {
24
25
  'User-Agent': 'dimo-node-sdk'
25
26
  }
26
27
  };
28
+ // If resource.method is 'FUNCTION', call the function defined
29
+ if (resource.method === 'FUNCTION') {
30
+ const functionName = resource.path;
31
+ const dynamicFunction = functionIndex[functionName];
32
+ if (typeof dynamicFunction === 'function') {
33
+ // Call the dynamic function with params and pass the necessary arguments
34
+ return dynamicFunction(params, env);
35
+ }
36
+ else {
37
+ throw new DimoError({
38
+ message: `Function in ${resource.path} is not a valid function.`,
39
+ statusCode: 400
40
+ });
41
+ }
42
+ }
27
43
  const variables = resource.params || {};
28
44
  let query = resource.query;
29
45
  for (const key in variables) {
@@ -64,7 +80,7 @@ export const CustomQuery = async (resource, baseUrl, params = {}) => {
64
80
  * Headers
65
81
  */
66
82
  let headers = {};
67
- if (['access_token', 'privilege_token'].includes(resource.auth)) {
83
+ if (['developer_jwt', 'vehicle_jwt'].includes(resource.auth)) {
68
84
  if (params.headers.Authorization) {
69
85
  headers = params.headers;
70
86
  }
@@ -2,6 +2,8 @@ import axios from 'axios';
2
2
  import { CustomQuery, Query } from './Query'; // Import the Query function to be tested
3
3
  import { DimoError } from '../errors';
4
4
  import { DimoEnvironment } from '../environments';
5
+ const PROD = 'Production';
6
+ const DEV = 'Dev';
5
7
  const RESOURCE = {
6
8
  method: 'POST',
7
9
  path: '',
@@ -39,9 +41,9 @@ describe('Query Function', () => {
39
41
  };
40
42
  const params = { unexpectedParam: 'value1' };
41
43
  // Call the Query function and expect it to throw an error
42
- await expect(Query(devResource, DimoEnvironment.Dev.Identity, params)).rejects.toThrow(DimoError);
43
- await expect(Query(prodResource, DimoEnvironment.Production.Identity, params)).rejects.toThrow(DimoError);
44
- await expect(Query(devResource, DimoEnvironment.Dev.Telemetry, params)).rejects.toThrow(DimoError);
45
- await expect(Query(prodResource, DimoEnvironment.Production.Telemetry, params)).rejects.toThrow(DimoError);
44
+ await expect(Query(devResource, DimoEnvironment.Dev.Identity, params, DEV)).rejects.toThrow(DimoError);
45
+ await expect(Query(prodResource, DimoEnvironment.Production.Identity, params, PROD)).rejects.toThrow(DimoError);
46
+ await expect(Query(devResource, DimoEnvironment.Dev.Telemetry, params, DEV)).rejects.toThrow(DimoError);
47
+ await expect(Query(prodResource, DimoEnvironment.Production.Telemetry, params, PROD)).rejects.toThrow(DimoError);
46
48
  });
47
49
  });
@@ -12,7 +12,8 @@ export class Resource {
12
12
  Object.keys(resources).forEach(key => {
13
13
  this[key] = (params = {}) => Query(resources[key], // Setup the endpoint resources
14
14
  this.api, // Setup the base URL
15
- params);
15
+ params, // Pass through the params
16
+ this.env);
16
17
  });
17
18
  }
18
19
  /**
@@ -0,0 +1,5 @@
1
+ import { DimoEnvironment } from '../../environments';
2
+ export declare const getVin: (input: {
3
+ headers: any;
4
+ tokenId: string;
5
+ }, env: keyof typeof DimoEnvironment) => Promise<any>;
@@ -0,0 +1,33 @@
1
+ import { DIMO } from '../../dimo';
2
+ import { DimoError } from '../../errors';
3
+ export const getVin = async (input, env) => {
4
+ const sdk = new DIMO(env);
5
+ let result;
6
+ try {
7
+ const getVinVC = await sdk.attestation.createVinVC({
8
+ headers: input.headers,
9
+ tokenId: input.tokenId
10
+ });
11
+ if (getVinVC) {
12
+ const vin = await sdk.telemetry.getLatestVinVC({
13
+ headers: input.headers,
14
+ tokenId: input.tokenId
15
+ });
16
+ result = vin.data.vinVCLatest.vin;
17
+ return result;
18
+ }
19
+ else {
20
+ throw new DimoError({
21
+ message: `Error getting attestation, make sure that you have the correct permissions.`,
22
+ statusCode: 400
23
+ });
24
+ }
25
+ }
26
+ catch (error) {
27
+ console.error(error);
28
+ throw new DimoError({
29
+ message: `Error getting VIN: ${error}`,
30
+ statusCode: 400
31
+ });
32
+ }
33
+ };
@@ -0,0 +1,2 @@
1
+ import { getVin } from "./getVin";
2
+ export { getVin };
@@ -0,0 +1,2 @@
1
+ import { getVin } from "./getVin";
2
+ export { getVin };
@@ -3,12 +3,12 @@ export class Telemetry extends Resource {
3
3
  constructor(api, env) {
4
4
  super(api, 'Telemetry', env);
5
5
  this.query({
6
- auth: 'privilege_token',
6
+ auth: 'vehicle_jwt',
7
7
  query: true,
8
8
  }),
9
9
  this.setQueries({
10
10
  getLatestSignals: {
11
- auth: 'privilege_token',
11
+ auth: 'vehicle_jwt',
12
12
  params: {
13
13
  tokenId: true
14
14
  },
@@ -33,6 +33,23 @@ export class Telemetry extends Resource {
33
33
  }
34
34
  }
35
35
  }`
36
+ },
37
+ getLatestVinVC: {
38
+ auth: 'vehicle_jwt',
39
+ params: {
40
+ tokenId: true
41
+ },
42
+ query: `
43
+ query {
44
+ vinVCLatest(tokenId: $tokenId) {
45
+ vin
46
+ }
47
+ }`
48
+ },
49
+ getVin: {
50
+ auth: 'vehicle_jwt',
51
+ method: 'FUNCTION',
52
+ path: 'getVin',
36
53
  }
37
54
  });
38
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimo-network/data-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "DIMO Data SDK for JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "author": "James Li",
@@ -8,7 +8,7 @@
8
8
  "license": "Apache-2.0",
9
9
  "type": "module",
10
10
  "keywords": [
11
- "data-sdk"
11
+ "data-sdk", "dimo", "dimo-network"
12
12
  ],
13
13
  "homepage": "https://dimo.org/developers",
14
14
  "bugs": {
@@ -1,5 +0,0 @@
1
- import { Resource } from '../../Resource';
2
- import { DimoEnvironment } from '../../../environments';
3
- export declare class VehicleSignalDecoding extends Resource {
4
- constructor(api: any, env: keyof typeof DimoEnvironment);
5
- }
@@ -1,59 +0,0 @@
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
- }