@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DIMO } from './dimo';
|
|
2
|
+
const PROD = 'Production';
|
|
3
|
+
const DEV = 'Dev';
|
|
4
|
+
const dimo = new DIMO(PROD);
|
|
5
|
+
const devDimo = new DIMO(DEV);
|
|
6
|
+
describe('Production Environment', () => {
|
|
7
|
+
test('Production resources are initialized with the correct environment', () => {
|
|
8
|
+
expect(dimo.attestation.env).toBe(PROD);
|
|
9
|
+
expect(dimo.auth.env).toBe(PROD);
|
|
10
|
+
expect(dimo.devicedefinitions.env).toBe(PROD);
|
|
11
|
+
expect(dimo.devices.env).toBe(PROD);
|
|
12
|
+
expect(dimo.identity.env).toBe(PROD);
|
|
13
|
+
expect(dimo.telemetry.env).toBe(PROD);
|
|
14
|
+
expect(dimo.tokenexchange.env).toBe(PROD);
|
|
15
|
+
expect(dimo.trips.env).toBe(PROD);
|
|
16
|
+
expect(dimo.valuations.env).toBe(PROD);
|
|
17
|
+
expect(dimo.vehiclesignaldecoding.env).toBe(PROD);
|
|
18
|
+
});
|
|
19
|
+
test('Production API endpoints are defined', () => {
|
|
20
|
+
expect(dimo.attestation.api).toBeDefined;
|
|
21
|
+
expect(dimo.auth.api).toBeDefined;
|
|
22
|
+
expect(dimo.devicedefinitions.api).toBeDefined;
|
|
23
|
+
expect(dimo.devices.api).toBeDefined;
|
|
24
|
+
expect(dimo.identity.api).toBeDefined;
|
|
25
|
+
expect(dimo.telemetry.api).toBeDefined;
|
|
26
|
+
expect(dimo.tokenexchange.api).toBeDefined;
|
|
27
|
+
expect(dimo.trips.api).toBeDefined;
|
|
28
|
+
expect(dimo.valuations.api).toBeDefined;
|
|
29
|
+
expect(dimo.vehiclesignaldecoding.api).toBeDefined;
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('Dev Environment', () => {
|
|
33
|
+
test('Dev resources are initialized with the correct environment', () => {
|
|
34
|
+
expect(devDimo.attestation.env).toBe(DEV);
|
|
35
|
+
expect(devDimo.auth.env).toBe(DEV);
|
|
36
|
+
expect(devDimo.devicedefinitions.env).toBe(DEV);
|
|
37
|
+
expect(devDimo.devices.env).toBe(DEV);
|
|
38
|
+
expect(devDimo.identity.env).toBe(DEV);
|
|
39
|
+
expect(devDimo.telemetry.env).toBe(DEV);
|
|
40
|
+
expect(devDimo.tokenexchange.env).toBe(DEV);
|
|
41
|
+
expect(devDimo.trips.env).toBe(DEV);
|
|
42
|
+
expect(devDimo.valuations.env).toBe(DEV);
|
|
43
|
+
expect(devDimo.vehiclesignaldecoding.env).toBe(DEV);
|
|
44
|
+
});
|
|
45
|
+
test('Dev API endpoints are defined', () => {
|
|
46
|
+
expect(devDimo.attestation.api).toBeDefined;
|
|
47
|
+
expect(devDimo.auth.api).toBeDefined;
|
|
48
|
+
expect(devDimo.devicedefinitions.api).toBeDefined;
|
|
49
|
+
expect(devDimo.devices.api).toBeDefined;
|
|
50
|
+
expect(devDimo.identity.api).toBeDefined;
|
|
51
|
+
expect(devDimo.telemetry.api).toBeDefined;
|
|
52
|
+
expect(devDimo.tokenexchange.api).toBeDefined;
|
|
53
|
+
expect(devDimo.trips.api).toBeDefined;
|
|
54
|
+
expect(devDimo.valuations.api).toBeDefined;
|
|
55
|
+
expect(devDimo.vehiclesignaldecoding.api).toBeDefined;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const DimoEnvironment: {
|
|
2
|
+
readonly Production: {
|
|
3
|
+
readonly Attestation: "https://attestation-api.dimo.zone";
|
|
4
|
+
readonly Auth: "https://auth.dimo.zone";
|
|
5
|
+
readonly Identity: "https://identity-api.dimo.zone/query";
|
|
6
|
+
readonly Devices: "https://devices-api.dimo.zone";
|
|
7
|
+
readonly DeviceData: "https://device-data-api.dimo.zone";
|
|
8
|
+
readonly DeviceDefinitions: "https://device-definitions-api.dimo.zone";
|
|
9
|
+
readonly Events: "https://events-api.dimo.zone";
|
|
10
|
+
readonly Telemetry: "https://telemetry-api.dimo.zone/query";
|
|
11
|
+
readonly TokenExchange: "https://token-exchange-api.dimo.zone";
|
|
12
|
+
readonly Trips: "https://trips-api.dimo.zone";
|
|
13
|
+
readonly User: "https://users-api.dimo.zone";
|
|
14
|
+
readonly Valuations: "https://valuations-api.dimo.zone";
|
|
15
|
+
readonly VehicleSignalDecoding: "https://vehicle-signal-decoding.dimo.zone";
|
|
16
|
+
};
|
|
17
|
+
readonly Dev: {
|
|
18
|
+
readonly Attestation: "https://attestation-api.dev.dimo.zone";
|
|
19
|
+
readonly Auth: "https://auth.dev.dimo.zone";
|
|
20
|
+
readonly Identity: "https://identity-api.dev.dimo.zone/query";
|
|
21
|
+
readonly Devices: "https://devices-api.dev.dimo.zone";
|
|
22
|
+
readonly DeviceData: "https://device-data-api.dev.dimo.zone";
|
|
23
|
+
readonly DeviceDefinitions: "https://device-definitions-api.dev.dimo.zone";
|
|
24
|
+
readonly Events: "https://events-api.dev.dimo.zone";
|
|
25
|
+
readonly Telemetry: "https://telemetry-api.dev.dimo.zone/query";
|
|
26
|
+
readonly TokenExchange: "https://token-exchange-api.dev.dimo.zone";
|
|
27
|
+
readonly Trips: "https://trips-api.dev.dimo.zone";
|
|
28
|
+
readonly User: "https://users-api.dev.dimo.zone";
|
|
29
|
+
readonly Valuations: "https://valuations-api.dev.dimo.zone";
|
|
30
|
+
readonly VehicleSignalDecoding: "https://vehicle-signal-decoding.dev.dimo.zone";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type DimoEnvironment = typeof DimoEnvironment.Production | typeof DimoEnvironment.Dev;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const DimoEnvironment = {
|
|
2
|
+
Production: {
|
|
3
|
+
'Attestation': 'https://attestation-api.dimo.zone',
|
|
4
|
+
'Auth': 'https://auth.dimo.zone',
|
|
5
|
+
'Identity': 'https://identity-api.dimo.zone/query',
|
|
6
|
+
'Devices': 'https://devices-api.dimo.zone',
|
|
7
|
+
'DeviceData': 'https://device-data-api.dimo.zone',
|
|
8
|
+
'DeviceDefinitions': 'https://device-definitions-api.dimo.zone',
|
|
9
|
+
'Events': 'https://events-api.dimo.zone',
|
|
10
|
+
'Telemetry': 'https://telemetry-api.dimo.zone/query',
|
|
11
|
+
'TokenExchange': 'https://token-exchange-api.dimo.zone',
|
|
12
|
+
'Trips': 'https://trips-api.dimo.zone',
|
|
13
|
+
'User': 'https://users-api.dimo.zone',
|
|
14
|
+
'Valuations': 'https://valuations-api.dimo.zone',
|
|
15
|
+
'VehicleSignalDecoding': 'https://vehicle-signal-decoding.dimo.zone'
|
|
16
|
+
},
|
|
17
|
+
Dev: {
|
|
18
|
+
'Attestation': 'https://attestation-api.dev.dimo.zone',
|
|
19
|
+
'Auth': 'https://auth.dev.dimo.zone',
|
|
20
|
+
'Identity': 'https://identity-api.dev.dimo.zone/query',
|
|
21
|
+
'Devices': 'https://devices-api.dev.dimo.zone',
|
|
22
|
+
'DeviceData': 'https://device-data-api.dev.dimo.zone',
|
|
23
|
+
'DeviceDefinitions': 'https://device-definitions-api.dev.dimo.zone',
|
|
24
|
+
'Events': 'https://events-api.dev.dimo.zone',
|
|
25
|
+
'Telemetry': 'https://telemetry-api.dev.dimo.zone/query',
|
|
26
|
+
'TokenExchange': 'https://token-exchange-api.dev.dimo.zone',
|
|
27
|
+
'Trips': 'https://trips-api.dev.dimo.zone',
|
|
28
|
+
'User': 'https://users-api.dev.dimo.zone',
|
|
29
|
+
'Valuations': 'https://valuations-api.dev.dimo.zone',
|
|
30
|
+
'VehicleSignalDecoding': 'https://vehicle-signal-decoding.dev.dimo.zone'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class DimoError extends Error {
|
|
2
|
+
statusCode;
|
|
3
|
+
body;
|
|
4
|
+
constructor({ message, statusCode, body }) {
|
|
5
|
+
super(buildMessage({ message, statusCode, body }));
|
|
6
|
+
Object.setPrototypeOf(this, DimoError.prototype);
|
|
7
|
+
if (statusCode != null) {
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
}
|
|
10
|
+
if (body !== undefined) {
|
|
11
|
+
this.body = body;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function buildMessage({ message, statusCode, body, }) {
|
|
16
|
+
let lines = [];
|
|
17
|
+
if (message != null) {
|
|
18
|
+
lines.push(message);
|
|
19
|
+
}
|
|
20
|
+
if (statusCode != null) {
|
|
21
|
+
lines.push(`Status code: ${statusCode.toString()}`);
|
|
22
|
+
}
|
|
23
|
+
if (body != null) {
|
|
24
|
+
lines.push(`Body: ${JSON.stringify(body, undefined, 2)}`);
|
|
25
|
+
}
|
|
26
|
+
return lines.join('\n');
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DimoError';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DimoError';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { DimoError } from '../errors';
|
|
3
|
+
// GraphQL query factory function
|
|
4
|
+
export const Query = async (resource, baseUrl, params = {}) => {
|
|
5
|
+
/**
|
|
6
|
+
* Headers
|
|
7
|
+
*/
|
|
8
|
+
let headers = {};
|
|
9
|
+
if (['access_token', 'privilege_token'].includes(resource.auth)) {
|
|
10
|
+
if (params.headers.Authorization) {
|
|
11
|
+
headers = params.headers;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
throw new DimoError({
|
|
15
|
+
message: `Access token not provided for ${resource.auth} authentication`,
|
|
16
|
+
statusCode: 401
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
headers = {
|
|
21
|
+
...headers,
|
|
22
|
+
...{
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
'User-Agent': 'dimo-node-sdk'
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const variables = resource.params || {};
|
|
28
|
+
let query = resource.query;
|
|
29
|
+
for (const key in variables) {
|
|
30
|
+
const placeholder = new RegExp(`\\$${key}\\b`, 'g');
|
|
31
|
+
if (variables[key] === true) {
|
|
32
|
+
if (!params[key]) {
|
|
33
|
+
console.error(`Missing required input: ${key}`);
|
|
34
|
+
throw new DimoError({
|
|
35
|
+
message: `Missing required input: ${key}`,
|
|
36
|
+
statusCode: 400
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const value = typeof params[key] === 'string' ? `"${params[key]}"` : params[key];
|
|
40
|
+
query = query.replace(placeholder, value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const response = await axios({
|
|
45
|
+
method: 'POST',
|
|
46
|
+
url: baseUrl,
|
|
47
|
+
headers: headers,
|
|
48
|
+
data: {
|
|
49
|
+
query
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return response.data;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error('Error executing GraphQL query:', error);
|
|
56
|
+
throw new DimoError({
|
|
57
|
+
message: `Error`,
|
|
58
|
+
statusCode: 400
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export const CustomQuery = async (resource, baseUrl, params = {}) => {
|
|
63
|
+
/**
|
|
64
|
+
* Headers
|
|
65
|
+
*/
|
|
66
|
+
let headers = {};
|
|
67
|
+
if (['access_token', 'privilege_token'].includes(resource.auth)) {
|
|
68
|
+
if (params.headers.Authorization) {
|
|
69
|
+
headers = params.headers;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
throw new DimoError({
|
|
73
|
+
message: `Access token not provided for ${resource.auth} authentication`,
|
|
74
|
+
statusCode: 401
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
headers = {
|
|
79
|
+
...headers,
|
|
80
|
+
...{
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
'User-Agent': 'dimo-node-sdk'
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const query = params.query || {};
|
|
86
|
+
try {
|
|
87
|
+
const response = await axios({
|
|
88
|
+
method: 'POST',
|
|
89
|
+
url: baseUrl,
|
|
90
|
+
headers: headers,
|
|
91
|
+
data: {
|
|
92
|
+
query
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return response.data;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error('Error executing Custom GraphQL query:', error);
|
|
99
|
+
throw new DimoError({
|
|
100
|
+
message: 'Error executing Custom GraphQL query',
|
|
101
|
+
statusCode: 400
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { CustomQuery, Query } from './Query'; // Import the Query function to be tested
|
|
3
|
+
import { DimoError } from '../errors';
|
|
4
|
+
import { DimoEnvironment } from '../environments';
|
|
5
|
+
const RESOURCE = {
|
|
6
|
+
method: 'POST',
|
|
7
|
+
path: '',
|
|
8
|
+
queryParams: { param1: true },
|
|
9
|
+
};
|
|
10
|
+
const PARAM = { query: `{
|
|
11
|
+
vehicles (first:10) {
|
|
12
|
+
totalCount
|
|
13
|
+
}
|
|
14
|
+
}` };
|
|
15
|
+
describe('Query Function', () => {
|
|
16
|
+
test('Valid API Call - Identity API Server is up and returning data', async () => {
|
|
17
|
+
jest.spyOn(axios, 'request').mockResolvedValue({ query: `{
|
|
18
|
+
vehicles (first:10) {
|
|
19
|
+
totalCount
|
|
20
|
+
}
|
|
21
|
+
}` });
|
|
22
|
+
const devResponse = await CustomQuery(RESOURCE, DimoEnvironment.Dev.Identity, PARAM);
|
|
23
|
+
const prodResponse = await CustomQuery(RESOURCE, DimoEnvironment.Production.Identity, PARAM);
|
|
24
|
+
// Assertion - Check if the response data is defined
|
|
25
|
+
expect(devResponse.data).toBeDefined();
|
|
26
|
+
expect(prodResponse.data).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
test('Missing Required Query Parameter - Throws Error', async () => {
|
|
29
|
+
// Mock input data with missing required query parameter
|
|
30
|
+
const devResource = {
|
|
31
|
+
Query: 'POST',
|
|
32
|
+
path: '',
|
|
33
|
+
queryParams: { expectedParam: true },
|
|
34
|
+
};
|
|
35
|
+
const prodResource = {
|
|
36
|
+
Query: 'POST',
|
|
37
|
+
path: '',
|
|
38
|
+
queryParams: { expectedParam: true },
|
|
39
|
+
};
|
|
40
|
+
const params = { unexpectedParam: 'value1' };
|
|
41
|
+
// 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);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 setQueries(resources: any): void;
|
|
11
|
+
/**
|
|
12
|
+
* Custom GraphQL Queries
|
|
13
|
+
* @param resources
|
|
14
|
+
*/
|
|
15
|
+
query(resources: any): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CustomQuery, Query } from './Query';
|
|
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
|
+
setQueries(resources) {
|
|
12
|
+
Object.keys(resources).forEach(key => {
|
|
13
|
+
this[key] = (params = {}) => Query(resources[key], // Setup the endpoint resources
|
|
14
|
+
this.api, // Setup the base URL
|
|
15
|
+
params);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Custom GraphQL Queries
|
|
20
|
+
* @param resources
|
|
21
|
+
*/
|
|
22
|
+
query(resources) {
|
|
23
|
+
Object.keys(resources).forEach(key => {
|
|
24
|
+
this[key] = (params = {}) => CustomQuery(resources, // Setup the endpoint resources
|
|
25
|
+
this.api, // Setup the base URL
|
|
26
|
+
params);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resources/DimoGraphqlResources';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resources/DimoGraphqlResources';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
import { DimoEnvironment } from '../../../environments';
|
|
3
|
+
export declare class Identity extends Resource {
|
|
4
|
+
constructor(api: any, env: keyof typeof DimoEnvironment);
|
|
5
|
+
}
|
|
6
|
+
export declare const listVehicleDefinitionsPerAddress: (address: string, limit: number) => string;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class Identity extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'Identity', env);
|
|
5
|
+
this.query({
|
|
6
|
+
query: true
|
|
7
|
+
}),
|
|
8
|
+
this.setQueries({
|
|
9
|
+
countDimoVehicles: {
|
|
10
|
+
query: `
|
|
11
|
+
{
|
|
12
|
+
vehicles (first:10) {
|
|
13
|
+
totalCount,
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`
|
|
17
|
+
},
|
|
18
|
+
listVehicleDefinitionsPerAddress: {
|
|
19
|
+
params: {
|
|
20
|
+
address: true,
|
|
21
|
+
limit: true
|
|
22
|
+
},
|
|
23
|
+
query: `
|
|
24
|
+
{
|
|
25
|
+
vehicles(filterBy: {owner: $address}, first: $limit) {
|
|
26
|
+
nodes {
|
|
27
|
+
aftermarketDevice {
|
|
28
|
+
tokenId
|
|
29
|
+
address
|
|
30
|
+
}
|
|
31
|
+
syntheticDevice {
|
|
32
|
+
address
|
|
33
|
+
tokenId
|
|
34
|
+
}
|
|
35
|
+
definition {
|
|
36
|
+
make
|
|
37
|
+
model
|
|
38
|
+
year
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export const listVehicleDefinitionsPerAddress = (address, limit) => `
|
|
49
|
+
{
|
|
50
|
+
vehicles(filterBy: {owner: "${address}"}, first: ${limit}) {
|
|
51
|
+
nodes {
|
|
52
|
+
aftermarketDevice {
|
|
53
|
+
tokenId
|
|
54
|
+
address
|
|
55
|
+
}
|
|
56
|
+
syntheticDevice {
|
|
57
|
+
address
|
|
58
|
+
tokenId
|
|
59
|
+
}
|
|
60
|
+
definition {
|
|
61
|
+
make
|
|
62
|
+
model
|
|
63
|
+
year
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
// export const getVehicleDetailsByTokenId = (tokenId: number) => `
|
|
70
|
+
// {
|
|
71
|
+
// vehicle (tokenId: ${tokenId}) {
|
|
72
|
+
// aftermarketDevice {
|
|
73
|
+
// tokenId
|
|
74
|
+
// address
|
|
75
|
+
// }
|
|
76
|
+
// syntheticDevice {
|
|
77
|
+
// address
|
|
78
|
+
// tokenId
|
|
79
|
+
// }
|
|
80
|
+
// definition {
|
|
81
|
+
// make
|
|
82
|
+
// model
|
|
83
|
+
// year
|
|
84
|
+
// }
|
|
85
|
+
// }
|
|
86
|
+
// }
|
|
87
|
+
// `;
|
|
88
|
+
// export const test = () => `
|
|
89
|
+
// {
|
|
90
|
+
// vehicles(filterBy: {owner: "0xf9D26323Ab49179A6d57C26515B01De018553787"}, first: 10) {
|
|
91
|
+
// nodes {
|
|
92
|
+
// definition {
|
|
93
|
+
// make
|
|
94
|
+
// model
|
|
95
|
+
// year
|
|
96
|
+
// }
|
|
97
|
+
// }
|
|
98
|
+
// }
|
|
99
|
+
// }
|
|
100
|
+
// `;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Resource } from '../../Resource';
|
|
2
|
+
export class Telemetry extends Resource {
|
|
3
|
+
constructor(api, env) {
|
|
4
|
+
super(api, 'Telemetry', env);
|
|
5
|
+
this.query({
|
|
6
|
+
auth: 'privilege_token',
|
|
7
|
+
query: true,
|
|
8
|
+
}),
|
|
9
|
+
this.setQueries({
|
|
10
|
+
getLatestSignals: {
|
|
11
|
+
auth: 'privilege_token',
|
|
12
|
+
params: {
|
|
13
|
+
tokenId: true
|
|
14
|
+
},
|
|
15
|
+
query: `
|
|
16
|
+
query {
|
|
17
|
+
SignalsLatest(tokenID: $tokenId){
|
|
18
|
+
powertrainTransmissionTravelledDistance {
|
|
19
|
+
timestamp
|
|
20
|
+
value
|
|
21
|
+
}
|
|
22
|
+
exteriorAirTemperature {
|
|
23
|
+
timestamp
|
|
24
|
+
value
|
|
25
|
+
}
|
|
26
|
+
speed{
|
|
27
|
+
timestamp
|
|
28
|
+
value
|
|
29
|
+
}
|
|
30
|
+
powertrainType{
|
|
31
|
+
timestamp
|
|
32
|
+
value
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}`
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* _..-------++._
|
|
3
|
+
* _.-'/ | _|| \"--._
|
|
4
|
+
* __.--'`._/_\j_____/_||___\ `----.
|
|
5
|
+
* _.--'_____ | D I M O \ _____ /
|
|
6
|
+
* _j /,---.\ | S D K =o| /,---.\ |_
|
|
7
|
+
* [__]==// .-. \\==`===========/==// .-. \\=[__]
|
|
8
|
+
* `-._|\ `-' /|___\_________/___|\ `-' /|_.'
|
|
9
|
+
* `---' `---'
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
export * from './api';
|
|
14
|
+
export * from './environments';
|
|
15
|
+
export * from './errors';
|
|
16
|
+
export * from './graphql';
|
|
17
|
+
export * from './constants';
|
|
18
|
+
export * from './dimo';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* _..-------++._
|
|
3
|
+
* _.-'/ | _|| \"--._
|
|
4
|
+
* __.--'`._/_\j_____/_||___\ `----.
|
|
5
|
+
* _.--'_____ | D I M O \ _____ /
|
|
6
|
+
* _j /,---.\ | S D K =o| /,---.\ |_
|
|
7
|
+
* [__]==// .-. \\==`===========/==// .-. \\=[__]
|
|
8
|
+
* `-._|\ `-' /|___\_________/___|\ `-' /|_.'
|
|
9
|
+
* `---' `---'
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
export * from './api';
|
|
14
|
+
export * from './environments';
|
|
15
|
+
export * from './errors';
|
|
16
|
+
export * from './graphql';
|
|
17
|
+
export * from './constants';
|
|
18
|
+
export * from './dimo';
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import StreamrClient from '@streamr/sdk';
|
|
3
|
+
// import { DimoError } from '../errors';
|
|
4
|
+
// import { Observable } from 'rxjs';
|
|
5
|
+
// import { catchError, finalize } from 'rxjs/operators';
|
|
6
|
+
// type StreamOptions = {
|
|
7
|
+
// streamId: string,
|
|
8
|
+
// clientId: string,
|
|
9
|
+
// privateKey: string,
|
|
10
|
+
// log?: string
|
|
11
|
+
// };
|
|
12
|
+
// export const Stream = async ({ streamId, clientId, privateKey, log }: StreamOptions) => {
|
|
13
|
+
// return new Observable(observer => {
|
|
14
|
+
// const client = new StreamrClient({
|
|
15
|
+
// logLevel: 'info' || log,
|
|
16
|
+
// auth: {
|
|
17
|
+
// //this is the signer private key the developer adds
|
|
18
|
+
// privateKey: privateKey
|
|
19
|
+
// },
|
|
20
|
+
// });
|
|
21
|
+
// const setupStream = async () => {
|
|
22
|
+
// try {
|
|
23
|
+
// const stream = await client.getStream(streamId);
|
|
24
|
+
// await client.subscribe({
|
|
25
|
+
// streamId,
|
|
26
|
+
// erc1271Contract: clientId,
|
|
27
|
+
// }, (msg) => {
|
|
28
|
+
// observer.next(msg);
|
|
29
|
+
// });
|
|
30
|
+
// } catch (error) {
|
|
31
|
+
// console.error('Streamr connection failed:', error);
|
|
32
|
+
// observer.error(new DimoError({
|
|
33
|
+
// message: 'Streamr connection failure'
|
|
34
|
+
// }));
|
|
35
|
+
// observer.complete();
|
|
36
|
+
// }
|
|
37
|
+
// };
|
|
38
|
+
// setupStream();
|
|
39
|
+
// return async () => {
|
|
40
|
+
// await client.unsubscribe(streamId);
|
|
41
|
+
// }
|
|
42
|
+
// }).pipe(
|
|
43
|
+
// catchError(error => {
|
|
44
|
+
// console.error('Streamr subscription error:', error);
|
|
45
|
+
// return new Observable();
|
|
46
|
+
// }),
|
|
47
|
+
// finalize(() => {
|
|
48
|
+
// console.log('Cleaning up Stream listeners');
|
|
49
|
+
// })
|
|
50
|
+
// );
|
|
51
|
+
// }
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
roots: ['<rootDir>/src'],
|
|
5
|
+
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
|
|
6
|
+
transform: {
|
|
7
|
+
'^.+\\.tsx?$': 'ts-jest', // Transform TypeScript files
|
|
8
|
+
'^.+\\.mjs$': 'babel-jest', // Transform .mjs files using Babel
|
|
9
|
+
'^.+\\.js$': 'babel-jest', // Transform JavaScript files
|
|
10
|
+
},
|
|
11
|
+
transformIgnorePatterns: ['<rootDir>/node_modules/'],
|
|
12
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node', 'mjs'],
|
|
13
|
+
moduleNameMapper: {
|
|
14
|
+
'^@/(.*)$': '<rootDir>/src/$1' // Adjust this if you're using path aliases
|
|
15
|
+
}
|
|
16
|
+
};
|