@dimo-network/data-sdk 1.2.3 → 1.2.5
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/README.jp.md +86 -0
- package/README.md +60 -47
- package/README.zh-tw.md +86 -0
- package/dist/api/functions/{getToken.d.ts → getDeveloperJwt.d.ts} +1 -1
- package/dist/api/functions/{getToken.js → getDeveloperJwt.js} +1 -1
- package/dist/api/functions/getVehicleJwt.d.ts +7 -0
- package/dist/api/functions/getVehicleJwt.js +23 -0
- package/dist/api/functions/index.d.ts +3 -2
- package/dist/api/functions/index.js +3 -2
- package/dist/api/resources/Auth/index.js +2 -2
- package/dist/api/resources/TokenExchange/index.js +4 -0
- package/dist/constants.d.ts +4 -1
- package/dist/constants.js +3 -0
- package/dist/dimo.js +1 -1
- package/dist/environments/index.d.ts +0 -6
- package/dist/environments/index.js +0 -6
- package/dist/graphql/Query.js +7 -8
- package/dist/graphql/functions/getVehiclePrivileges.d.ts +6 -0
- package/dist/graphql/functions/getVehiclePrivileges.js +46 -0
- package/dist/graphql/functions/index.d.ts +2 -1
- package/dist/graphql/functions/index.js +2 -1
- package/dist/graphql/resources/Identity/index.d.ts +0 -1
- package/dist/graphql/resources/Identity/index.js +53 -78
- package/dist/graphql/util/paginate.d.ts +9 -0
- package/dist/graphql/util/paginate.js +37 -0
- package/dist/index.cjs +1624 -293
- package/dist/util/decodeJwt.d.ts +1 -0
- package/dist/util/decodeJwt.js +11 -0
- package/dist/util/decodePermissions.d.ts +1 -0
- package/dist/util/decodePermissions.js +12 -0
- package/dist/util/index.d.ts +8 -0
- package/dist/util/index.js +7 -0
- package/package.json +5 -1
package/README.jp.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+
[](https://www.npmjs.com/package/@dimo-network/data-sdk)
|
|
5
|
+
[](https://chat.dimo.zone/)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
# DIMO(智猛)Data SDK
|
|
9
|
+
## 概要
|
|
10
|
+
DIMO Data SDK は、TypeScript で構築された公式ライブラリであり、DIMO API を簡単かつ効率的に利用できるように設計されています。この SDK は、開発者が DIMO プラットフォームと統合する際の複雑さを軽減し、迅速な開発を可能にします。API 呼び出しの抽象化、データ操作の簡素化、そして堅牢な型安全性を提供することで、開発者体験を向上させます。
|
|
11
|
+
|
|
12
|
+
## インストール
|
|
13
|
+
|
|
14
|
+
[npm](https://www.npmjs.com/package/@dimo-network/data-sdk) を使用する場合:
|
|
15
|
+
```bash
|
|
16
|
+
npm install @dimo-network/data-sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
[yarn](https://classic.yarnpkg.com/en/package/@dimo-network/data-sdk) を使用する場合:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @dimo-network/data-sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 単体テスト
|
|
26
|
+
`npm test` または `npm run test` を実行して、Jest テストを実行します。
|
|
27
|
+
|
|
28
|
+
## API ドキュメント
|
|
29
|
+
DIMO での開発や API に関する詳細情報については、DIMO の [開発者向けドキュメント](https://docs.dimo.org/developer-platform) をご覧ください。
|
|
30
|
+
|
|
31
|
+
## SDK の使用方法
|
|
32
|
+
### SDK ライブラリ
|
|
33
|
+
|
|
34
|
+
(TypeScript / ES Modules)
|
|
35
|
+
```ts
|
|
36
|
+
import { DIMO } from '@dimo-network/data-sdk';
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
(CommonJS)
|
|
40
|
+
```js
|
|
41
|
+
const { DIMO } = require('@dimo-network/data-sdk')
|
|
42
|
+
```
|
|
43
|
+
### SDK 初期化
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const dimo = new DIMO('Production');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 開発者登録
|
|
50
|
+
認証プロセスの一環として、[DIMO 開発者コンソール](https://console.dimo.org/) を通じて開発者ライセンスを取得する必要があります。登録を開始するには、以下の手順に従ってください:
|
|
51
|
+
1. [DIMO 開発者コンソール](https://console.dimo.org/) にサインアップします。
|
|
52
|
+
2. 「ライセンスを作成」(Create a License) をクリックし、ライセンスに関する詳細を入力します。
|
|
53
|
+
3. API キー(API Key)を生成し、希望するリダイレクト URI(RedirectURI)を追加します。
|
|
54
|
+
|
|
55
|
+
### 開発者認証
|
|
56
|
+
SDK は、[認証フロー](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication) に必要なすべての手順を提供し、「開発者 JWT」(Developer JWT) を取得し、アプリと共有されている各車両の「車両 JWT」(Vehicle JWT) を取得することができます。
|
|
57
|
+
|
|
58
|
+
#### 認証の前提条件
|
|
59
|
+
1. 開発者ライセンス
|
|
60
|
+
2. API キー、リダイレクト URI(RedirectURI)
|
|
61
|
+
3. 適切な [TypeScript を使用したプロジェクトのセットアップ](https://nodejs.keicode.com/typescript/create-ts-project.php)。
|
|
62
|
+
|
|
63
|
+
#### 開発者 JWT
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const developerJwt = await dimo.auth.getDeveloperJwt({
|
|
67
|
+
client_id: '<client_id>',
|
|
68
|
+
domain: '<domain/redirect_uri>',
|
|
69
|
+
private_key: '<api_key>',
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### 車両 JWT
|
|
74
|
+
消費者から車両データを取得するには、アプリケーションが短期間有効な [車両 JWT](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication#getting-a-jwt) を交換する必要があります。この 車両 JWT は、アプリに権限を付与した車両に対して取得されます。
|
|
75
|
+
|
|
76
|
+
消費者は事前に車両の権限を共有する必要があります。そのためには、[Login with DIMO](https://docs.dimo.org/developer-platform/getting-started/developer-guide/login-with-dimo) や DIMO Mobile のような実装が必要です。この手順が完了すると、車両データを取得できるようになります。
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const vehicleJwt = await dimo.tokenexchange.getVehicleJwt({
|
|
80
|
+
...developerJwt,
|
|
81
|
+
tokenId: 117315
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## SDK への貢献方法
|
|
86
|
+
SDK への貢献についての詳細は、[こちら](https://github.com/DIMO-Network/data-sdk/blob/master/CONTRIBUTING.md)をご覧ください。
|
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ import { DIMO } from '@dimo-network/data-sdk';
|
|
|
37
37
|
|
|
38
38
|
(CommonJS)
|
|
39
39
|
```js
|
|
40
|
-
const { DIMO } = require('@dimo-network/data-sdk
|
|
40
|
+
const { DIMO } = require('@dimo-network/data-sdk')
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
Initiate the SDK:
|
|
@@ -49,39 +49,36 @@ const dimo = new DIMO('Production');
|
|
|
49
49
|
### Developer Registration
|
|
50
50
|
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:
|
|
51
51
|
1. Sign up on the [DIMO Developer Console](https://console.dimo.org/).
|
|
52
|
-
2.
|
|
53
|
-
3.
|
|
54
|
-
4. Generate an API key and add in your preferred redirect URI.
|
|
52
|
+
2. Click on `Create a license` and fill out the details about your license.
|
|
53
|
+
3. Generate an API key and add in your preferred redirect URI.
|
|
55
54
|
|
|
56
55
|
### Authentication
|
|
57
56
|
|
|
58
|
-
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.
|
|
57
|
+
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 & to get Vehicle JWT for each vehicle shared with your app.
|
|
59
58
|
|
|
60
59
|
#### Prerequisites for Authentication
|
|
61
60
|
1. A valid Developer License with a `client_id`
|
|
62
61
|
2. A valid API key, generated via the Developer Console
|
|
63
62
|
3. A proper [project set up with TypeScript](https://www.digitalocean.com/community/tutorials/setting-up-a-node-project-with-typescript).
|
|
64
63
|
|
|
65
|
-
####
|
|
64
|
+
#### Developer JWT
|
|
65
|
+
To get a Developer JWT, you will need a valid Developer License with a `client_id`, a generated `api_key`, and a `domain`/`redirect_uri` you configured on the Developer Console.
|
|
66
66
|
|
|
67
|
-
##### (Option 1 - PREFERRED)
|
|
67
|
+
##### (Option 1 - PREFERRED) getDeveloperJwt Function
|
|
68
68
|
This is a utility function call to get a Developer JWT in one step:
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
|
-
const developerJwt = await dimo.auth.
|
|
71
|
+
const developerJwt = await dimo.auth.getDeveloperJwt({
|
|
72
72
|
client_id: '<client_id>',
|
|
73
|
-
domain: '<domain>',
|
|
73
|
+
domain: '<domain/redirect_uri>',
|
|
74
74
|
private_key: '<api_key>',
|
|
75
75
|
});
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
Once you have the `developerJwt`, you'll have access to the DIMO API
|
|
78
|
+
Once you have the `developerJwt`, you'll have access to the DIMO API as a verified developer. For endpoints that require the authorization headers, you can simply pass the results.
|
|
79
79
|
|
|
80
80
|
```ts
|
|
81
81
|
// Pass the developerJwt object to a protected endpoint
|
|
82
|
-
await dimo.user.get(developerJwt);
|
|
83
|
-
|
|
84
|
-
// Pass the developerJwt object to a protected endpoint with body parameters
|
|
85
82
|
await dimo.tokenexchange.exchange({
|
|
86
83
|
...developerJwt,
|
|
87
84
|
privileges: [4],
|
|
@@ -101,6 +98,54 @@ const developerJwt = await dimo.authenticate();
|
|
|
101
98
|
// The rest would be the same as option 1
|
|
102
99
|
```
|
|
103
100
|
|
|
101
|
+
#### Vehicle JWT
|
|
102
|
+
|
|
103
|
+
To get vehicle data from an end user, your application will need to exchange for a short-lived [Vehicle JWT](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication#getting-a-jwt) for vehicles that have granted permissions to your app.
|
|
104
|
+
|
|
105
|
+
For the end users of your application, they will need to have already shared 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) before you can fetch for their vehicle data.
|
|
106
|
+
|
|
107
|
+
##### (Option 1 - PREFERRED) getVehicleJwt Function
|
|
108
|
+
This is a utility function call to get a Vehicle JWT in one step by inputting your developer JWT obtained earlier with the vehicle's identifier (`tokenId`):
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const vehicleJwt = await dimo.tokenexchange.getVehicleJwt({
|
|
112
|
+
...developerJwt,
|
|
113
|
+
tokenId: 117315
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
##### (Option 2) Manually exchanging for Vehicle JWT
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const vehicle_jwt = await dimo.tokenexchange.exchange({
|
|
121
|
+
...auth,
|
|
122
|
+
privileges: [1, 5],
|
|
123
|
+
tokenId: <vehicle_token_id>
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Once you have the `vehicleJwt`, you'll have access to the vehicle data for a specific vehicle. For endpoints that require the authorization headers, you can pass the results.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
// Vehicle Status uses privId 1
|
|
131
|
+
await dimo.devicedata.getVehicleStatus({
|
|
132
|
+
...vehicle_jwt,
|
|
133
|
+
tokenId: <vehicle_token_id>
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Proof of Movement Verifiable Credentials uses privId 4
|
|
137
|
+
await dimo.attestation.createPomVC({
|
|
138
|
+
...vehicle_jwt,
|
|
139
|
+
tokenId: <vehicle_token_id>
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
// VIN Verifiable Credentials uses privId 5
|
|
143
|
+
await dimo.attestation.createVinVC({
|
|
144
|
+
...vehicle_jwt,
|
|
145
|
+
tokenId: <vehicle_token_id>
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
104
149
|
### Querying the DIMO REST API
|
|
105
150
|
The SDK supports async await and your typical JS Promises. HTTP operations can be utilized in either ways:
|
|
106
151
|
|
|
@@ -146,48 +191,16 @@ dimo.attestation.createVinVC({
|
|
|
146
191
|
})
|
|
147
192
|
```
|
|
148
193
|
|
|
149
|
-
#### Vehicle JWT
|
|
150
|
-
|
|
151
|
-
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).
|
|
152
|
-
|
|
153
|
-
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.
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
const vehicle_jwt = await dimo.tokenexchange.exchange({
|
|
157
|
-
...auth,
|
|
158
|
-
privileges: [1, 5],
|
|
159
|
-
tokenId: <vehicle_token_id>
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// Vehicle Status uses privId 1
|
|
163
|
-
await dimo.devicedata.getVehicleStatus({
|
|
164
|
-
...vehicle_jwt,
|
|
165
|
-
tokenId: <vehicle_token_id>
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// Proof of Movement Verifiable Credentials uses privId 4
|
|
169
|
-
await dimo.attestation.createPomVC({
|
|
170
|
-
...vehicle_jwt,
|
|
171
|
-
tokenId: <vehicle_token_id>
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
// VIN Verifiable Credentials uses privId 5
|
|
175
|
-
await dimo.attestation.createVinVC({
|
|
176
|
-
...vehicle_jwt,
|
|
177
|
-
tokenId: <vehicle_token_id>
|
|
178
|
-
});
|
|
179
|
-
```
|
|
180
|
-
|
|
181
194
|
### Querying the DIMO GraphQL API
|
|
182
195
|
|
|
183
|
-
The SDK accepts any type of valid custom GraphQL queries, but we've also included a few sample queries to help you understand the DIMO GraphQL APIs.
|
|
196
|
+
The SDK accepts any type of valid custom GraphQL queries, but we've also included a few sample queries to help you understand the DIMO GraphQL APIs. There's also a helper function called `paginate` that you can use to paginate through the GraphQL pages, see `getVehiclePrivileges.ts` on how it's being used.
|
|
184
197
|
|
|
185
198
|
#### Authentication for GraphQL API
|
|
186
199
|
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.
|
|
187
200
|
|
|
188
201
|
```ts
|
|
189
202
|
const vehicleJwt = await dimo.tokenexchange.exchange({
|
|
190
|
-
...
|
|
203
|
+
...developerJwt,
|
|
191
204
|
privileges: [1, 3, 4],
|
|
192
205
|
tokenId: <vehicle_token_id>
|
|
193
206
|
});
|
package/README.zh-tw.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+
[](https://www.npmjs.com/package/@dimo-network/data-sdk)
|
|
5
|
+
[](https://chat.dimo.zone/)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
# DIMO(智猛)Data SDK
|
|
9
|
+
## 概述
|
|
10
|
+
DIMO Data SDK 是一個以 TypeScript 構建的官方函式庫,旨在讓開發者能夠簡單且高效地使用 DIMO API。此 SDK 減少了開發者在整合 DIMO 平台時的複雜性,並加速開發過程。透過 API 調用的抽象化、簡化數據操作以及提供強大的型別安全性,提升了開發者的使用體驗。
|
|
11
|
+
|
|
12
|
+
## 安裝
|
|
13
|
+
|
|
14
|
+
使用 [npm](https://www.npmjs.com/package/@dimo-network/data-sdk):
|
|
15
|
+
```bash
|
|
16
|
+
npm install @dimo-network/data-sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
使用 [yarn](https://classic.yarnpkg.com/en/package/@dimo-network/data-sdk):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @dimo-network/data-sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 單元測試
|
|
26
|
+
執行 `npm test` 或 `npm run test` 來運行 Jest 測試。
|
|
27
|
+
|
|
28
|
+
## API 文件
|
|
29
|
+
有關 DIMO 開發或 API 的詳細資訊,請參閱 DIMO 的 [開發者文件](https://docs.dimo.org/developer-platform)。
|
|
30
|
+
|
|
31
|
+
## SDK 使用方法
|
|
32
|
+
### 訪問函式庫
|
|
33
|
+
|
|
34
|
+
(TypeScript / ES Modules)
|
|
35
|
+
```ts
|
|
36
|
+
import { DIMO } from '@dimo-network/data-sdk';
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
(CommonJS)
|
|
40
|
+
```js
|
|
41
|
+
const { DIMO } = require('@dimo-network/data-sdk')
|
|
42
|
+
```
|
|
43
|
+
### SDK 初始化
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const dimo = new DIMO('Production');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 開發者註冊
|
|
50
|
+
作為認證流程的一部分,您需要先通過 [DIMO Developer Console](https://console.dimo.org/) 獲取開發者授權身份。請按照以下步驟開始註冊:
|
|
51
|
+
1. 造訪 [DIMO 開發者主控台](https://console.dimo.org/) 並註冊帳號。
|
|
52
|
+
2. 點擊「創建執照」(Create a License),並輸入您的相關執照詳細資訊。
|
|
53
|
+
3. 生成 API 金鑰(API Key),並新增所需的統一資源識別碼(Redirect URI)。
|
|
54
|
+
|
|
55
|
+
### 開發者認證
|
|
56
|
+
SDK 提供了[認證流程](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication) 所需的所有步驟,幫助您獲取「開發者 JWT」(Developer JWT)以及每輛與應用程式共享的車輛所使用的「車輛 JWT」(Vehicle JWT)。
|
|
57
|
+
|
|
58
|
+
#### 認證的前置條件
|
|
59
|
+
1. 開發者執照
|
|
60
|
+
2. API 金鑰以及至少一組自訂的統一資源識別碼(Redirect URI)
|
|
61
|
+
3. 適當的 [TypeScript 環境設置](https://learn.microsoft.com/zh-tw/visualstudio/javascript/compile-typescript-code-npm?view=vs-2022)。
|
|
62
|
+
|
|
63
|
+
#### 開發者 JWT
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const developerJwt = await dimo.auth.getDeveloperJwt({
|
|
67
|
+
client_id: '<client_id>',
|
|
68
|
+
domain: '<domain/redirect_uri>',
|
|
69
|
+
private_key: '<api_key>',
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### 車輛 JWT
|
|
74
|
+
若要從消費者處獲取車輛數據,應用程式需要交換短期有效的 [車輛 JWT](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication#getting-a-jwt)。此車輛 JWT 是針對授權應用程式的車輛生成的。
|
|
75
|
+
|
|
76
|
+
消費者需要事先與您的應用程式共享車輛授權。為此,您可以透過前端整合 [Login with DIMO](https://docs.dimo.org/developer-platform/getting-started/developer-guide/login-with-dimo) 或開發出類似 DIMO Mobile 全端的功能。完成「分享」此步驟後,您將能夠自由獲取車輛數據。
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const vehicleJwt = await dimo.tokenexchange.getVehicleJwt({
|
|
80
|
+
...developerJwt,
|
|
81
|
+
tokenId: 117315
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## SDK 貢獻
|
|
86
|
+
有關如何貢獻於此 SDK 的詳細資訊,請參閱[此處](https://github.com/DIMO-Network/data-sdk/blob/master/CONTRIBUTING.md)。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DIMO } from '../../dimo';
|
|
2
|
+
import { decodeJwt, decodePermissions } from '../../util';
|
|
3
|
+
export const getVehicleJwt = async (input, env) => {
|
|
4
|
+
const sdk = new DIMO(env);
|
|
5
|
+
const developerJwt = input.headers.Authorization;
|
|
6
|
+
if (!developerJwt || !developerJwt.startsWith('Bearer ')) {
|
|
7
|
+
throw new Error('Invalid Authorization header format');
|
|
8
|
+
}
|
|
9
|
+
// Remove "Bearer " prefix
|
|
10
|
+
const decodedToken = decodeJwt(developerJwt.slice(7));
|
|
11
|
+
const clientId = decodedToken.ethereum_address;
|
|
12
|
+
const privileges = await sdk.identity.getVehiclePrivileges({
|
|
13
|
+
tokenId: input.tokenId,
|
|
14
|
+
clientId: clientId // We want to pass in the clientId
|
|
15
|
+
});
|
|
16
|
+
const decodedPrivileges = decodePermissions(privileges[0].permissions);
|
|
17
|
+
const vehicleJwt = await sdk.tokenexchange.exchange({
|
|
18
|
+
...input,
|
|
19
|
+
privileges: decodedPrivileges,
|
|
20
|
+
tokenId: input.tokenId
|
|
21
|
+
});
|
|
22
|
+
return vehicleJwt;
|
|
23
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDeveloperJwt } from "./getDeveloperJwt";
|
|
2
|
+
import { getVehicleJwt } from "./getVehicleJwt";
|
|
2
3
|
import { signChallenge } from "./signChallenge";
|
|
3
|
-
export {
|
|
4
|
+
export { getDeveloperJwt, getVehicleJwt, signChallenge };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDeveloperJwt } from "./getDeveloperJwt";
|
|
2
|
+
import { getVehicleJwt } from "./getVehicleJwt";
|
|
2
3
|
import { signChallenge } from "./signChallenge";
|
|
3
|
-
export {
|
|
4
|
+
export { getDeveloperJwt, getVehicleJwt, signChallenge };
|
package/dist/constants.d.ts
CHANGED
|
@@ -7,5 +7,8 @@ export declare const DimoConstants: {
|
|
|
7
7
|
readonly NFT_address: "0x45fbCD3ef7361d156e8b16F5538AE36DEdf61Da8";
|
|
8
8
|
readonly RPC_provider: "https://eth.llamarpc.com";
|
|
9
9
|
};
|
|
10
|
+
readonly Query: {
|
|
11
|
+
readonly PAGE_SIZE: 100;
|
|
12
|
+
};
|
|
10
13
|
};
|
|
11
|
-
export type DimoConstants = typeof DimoConstants.Production | typeof DimoConstants.Dev;
|
|
14
|
+
export type DimoConstants = typeof DimoConstants.Production | typeof DimoConstants.Dev | typeof DimoConstants.Query;
|
package/dist/constants.js
CHANGED
package/dist/dimo.js
CHANGED
|
@@ -47,7 +47,7 @@ export class DIMO {
|
|
|
47
47
|
}
|
|
48
48
|
const data = fs.readFileSync('.credentials.json', 'utf8');
|
|
49
49
|
const credentials = JSON.parse(data);
|
|
50
|
-
const authHeader = await this.auth.
|
|
50
|
+
const authHeader = await this.auth.getDeveloperJwt({
|
|
51
51
|
client_id: credentials.client_id,
|
|
52
52
|
domain: credentials.redirect_uri,
|
|
53
53
|
private_key: credentials.private_key,
|
|
@@ -4,13 +4,10 @@ export declare const DimoEnvironment: {
|
|
|
4
4
|
readonly Auth: "https://auth.dimo.zone";
|
|
5
5
|
readonly Identity: "https://identity-api.dimo.zone/query";
|
|
6
6
|
readonly Devices: "https://devices-api.dimo.zone";
|
|
7
|
-
readonly DeviceData: "https://device-data-api.dimo.zone";
|
|
8
7
|
readonly DeviceDefinitions: "https://device-definitions-api.dimo.zone";
|
|
9
|
-
readonly Events: "https://events-api.dimo.zone";
|
|
10
8
|
readonly Telemetry: "https://telemetry-api.dimo.zone/query";
|
|
11
9
|
readonly TokenExchange: "https://token-exchange-api.dimo.zone";
|
|
12
10
|
readonly Trips: "https://trips-api.dimo.zone";
|
|
13
|
-
readonly User: "https://users-api.dimo.zone";
|
|
14
11
|
readonly Valuations: "https://valuations-api.dimo.zone";
|
|
15
12
|
readonly VehicleSignalDecoding: "https://vehicle-signal-decoding.dimo.zone";
|
|
16
13
|
};
|
|
@@ -19,13 +16,10 @@ export declare const DimoEnvironment: {
|
|
|
19
16
|
readonly Auth: "https://auth.dev.dimo.zone";
|
|
20
17
|
readonly Identity: "https://identity-api.dev.dimo.zone/query";
|
|
21
18
|
readonly Devices: "https://devices-api.dev.dimo.zone";
|
|
22
|
-
readonly DeviceData: "https://device-data-api.dev.dimo.zone";
|
|
23
19
|
readonly DeviceDefinitions: "https://device-definitions-api.dev.dimo.zone";
|
|
24
|
-
readonly Events: "https://events-api.dev.dimo.zone";
|
|
25
20
|
readonly Telemetry: "https://telemetry-api.dev.dimo.zone/query";
|
|
26
21
|
readonly TokenExchange: "https://token-exchange-api.dev.dimo.zone";
|
|
27
22
|
readonly Trips: "https://trips-api.dev.dimo.zone";
|
|
28
|
-
readonly User: "https://users-api.dev.dimo.zone";
|
|
29
23
|
readonly Valuations: "https://valuations-api.dev.dimo.zone";
|
|
30
24
|
readonly VehicleSignalDecoding: "https://vehicle-signal-decoding.dev.dimo.zone";
|
|
31
25
|
};
|
|
@@ -4,13 +4,10 @@ export const DimoEnvironment = {
|
|
|
4
4
|
'Auth': 'https://auth.dimo.zone',
|
|
5
5
|
'Identity': 'https://identity-api.dimo.zone/query',
|
|
6
6
|
'Devices': 'https://devices-api.dimo.zone',
|
|
7
|
-
'DeviceData': 'https://device-data-api.dimo.zone',
|
|
8
7
|
'DeviceDefinitions': 'https://device-definitions-api.dimo.zone',
|
|
9
|
-
'Events': 'https://events-api.dimo.zone',
|
|
10
8
|
'Telemetry': 'https://telemetry-api.dimo.zone/query',
|
|
11
9
|
'TokenExchange': 'https://token-exchange-api.dimo.zone',
|
|
12
10
|
'Trips': 'https://trips-api.dimo.zone',
|
|
13
|
-
'User': 'https://users-api.dimo.zone',
|
|
14
11
|
'Valuations': 'https://valuations-api.dimo.zone',
|
|
15
12
|
'VehicleSignalDecoding': 'https://vehicle-signal-decoding.dimo.zone'
|
|
16
13
|
},
|
|
@@ -19,13 +16,10 @@ export const DimoEnvironment = {
|
|
|
19
16
|
'Auth': 'https://auth.dev.dimo.zone',
|
|
20
17
|
'Identity': 'https://identity-api.dev.dimo.zone/query',
|
|
21
18
|
'Devices': 'https://devices-api.dev.dimo.zone',
|
|
22
|
-
'DeviceData': 'https://device-data-api.dev.dimo.zone',
|
|
23
19
|
'DeviceDefinitions': 'https://device-definitions-api.dev.dimo.zone',
|
|
24
|
-
'Events': 'https://events-api.dev.dimo.zone',
|
|
25
20
|
'Telemetry': 'https://telemetry-api.dev.dimo.zone/query',
|
|
26
21
|
'TokenExchange': 'https://token-exchange-api.dev.dimo.zone',
|
|
27
22
|
'Trips': 'https://trips-api.dev.dimo.zone',
|
|
28
|
-
'User': 'https://users-api.dev.dimo.zone',
|
|
29
23
|
'Valuations': 'https://valuations-api.dev.dimo.zone',
|
|
30
24
|
'VehicleSignalDecoding': 'https://vehicle-signal-decoding.dev.dimo.zone'
|
|
31
25
|
}
|
package/dist/graphql/Query.js
CHANGED
|
@@ -45,15 +45,14 @@ export const Query = async (resource, baseUrl, params = {}, env) => {
|
|
|
45
45
|
for (const key in variables) {
|
|
46
46
|
const placeholder = new RegExp(`\\$${key}\\b`, 'g');
|
|
47
47
|
if (variables[key] === true) {
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
48
|
+
if (params[key] === undefined || params[key] === null) {
|
|
49
|
+
// ACC-303: Replace the placeholder with null string to handle pagination
|
|
50
|
+
query = query.replace(placeholder, "null");
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const value = typeof params[key] === 'string' ? `"${params[key]}"` : params[key];
|
|
54
|
+
query = query.replace(placeholder, value);
|
|
54
55
|
}
|
|
55
|
-
const value = typeof params[key] === 'string' ? `"${params[key]}"` : params[key];
|
|
56
|
-
query = query.replace(placeholder, value);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
try {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DIMO } from '../../dimo';
|
|
2
|
+
import { DimoError } from '../../errors';
|
|
3
|
+
import { paginate } from '../util/paginate';
|
|
4
|
+
export const getVehiclePrivileges = async (input, env) => {
|
|
5
|
+
const sdk = new DIMO(env);
|
|
6
|
+
try {
|
|
7
|
+
const getSacds = async (after) => {
|
|
8
|
+
const response = await sdk.identity.listSacdPerVehicleTokenId({
|
|
9
|
+
tokenId: input.tokenId,
|
|
10
|
+
after
|
|
11
|
+
});
|
|
12
|
+
const sacds = response.data?.vehicle?.sacds || [];
|
|
13
|
+
const pageInfo = response.data?.vehicle?.sacds.pageInfo || { endCursor: null };
|
|
14
|
+
const totalCount = response.data?.vehicle?.sacds?.totalCount || null;
|
|
15
|
+
if (input.clientId) {
|
|
16
|
+
const matchingSacd = sacds.nodes.find((sacd) => sacd.grantee === input.clientId);
|
|
17
|
+
if (matchingSacd) {
|
|
18
|
+
return {
|
|
19
|
+
nodes: [matchingSacd],
|
|
20
|
+
pageInfo: { endCursor: null },
|
|
21
|
+
totalCount: 1
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
nodes: sacds,
|
|
27
|
+
pageInfo,
|
|
28
|
+
totalCount
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
if (input.clientId) {
|
|
32
|
+
const { nodes } = await getSacds(undefined);
|
|
33
|
+
if (nodes.length > 0) {
|
|
34
|
+
return nodes;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return await paginate(getSacds);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(error);
|
|
41
|
+
throw new DimoError({
|
|
42
|
+
message: `Error getting vehicle privileges: ${error.message || error}`,
|
|
43
|
+
statusCode: 400
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|