@tryvital/vital-node 1.2.0 → 1.3.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/.github/workflows/deploy.yaml +11 -50
- package/.vscode/settings.json +3 -0
- package/__tests__/activity.test.ts +18 -0
- package/__tests__/arrange.ts +36 -0
- package/__tests__/body.test.ts +17 -0
- package/__tests__/devices.test.ts +15 -0
- package/__tests__/link.test.ts +15 -0
- package/__tests__/profile.test.ts +15 -0
- package/__tests__/sleep.test.ts +31 -0
- package/__tests__/user.test.ts +37 -0
- package/__tests__/vitals.test.ts +17 -0
- package/__tests__/workouts.test.ts +17 -0
- package/client/Activity.ts +2 -2
- package/client/Body.ts +2 -2
- package/client/Sleep.ts +19 -3
- package/client/Testkits.ts +10 -2
- package/client/Vitals.ts +6 -6
- package/client/Workouts.ts +2 -2
- package/client/models/sleep_models.ts +7 -0
- package/client/models/testkit_models.ts +13 -11
- package/client/models/user_models.ts +1 -0
- package/dist/client/Activity.d.ts +2 -2
- package/dist/client/Body.d.ts +2 -2
- package/dist/client/Sleep.d.ts +3 -2
- package/dist/client/Sleep.js +17 -1
- package/dist/client/Testkits.d.ts +2 -1
- package/dist/client/Testkits.js +15 -2
- package/dist/client/Vitals.d.ts +5 -5
- package/dist/client/Workouts.d.ts +2 -2
- package/dist/client/models/sleep_models.d.ts +7 -0
- package/dist/client/models/testkit_models.d.ts +1 -1
- package/dist/client/models/user_models.d.ts +1 -0
- package/dist/index.js +7 -1
- package/dist/lib/config.d.ts +9 -0
- package/dist/lib/config.js +9 -0
- package/dist/lib/models.d.ts +2 -1
- package/index.ts +6 -1
- package/jest.config.js +6 -0
- package/lib/config.ts +9 -0
- package/lib/models.ts +2 -1
- package/package.json +7 -1
- package/tsconfig.json +14 -5
@@ -1,57 +1,18 @@
|
|
1
|
-
name:
|
1
|
+
name: Publish Package to npmjs
|
2
2
|
on:
|
3
|
-
|
4
|
-
|
5
|
-
- "main"
|
3
|
+
release:
|
4
|
+
types: [published]
|
6
5
|
jobs:
|
7
6
|
build:
|
8
|
-
name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}
|
9
|
-
runs-on: ${{ matrix.os }}
|
10
|
-
strategy:
|
11
|
-
matrix:
|
12
|
-
node: ['10.x', '12.x', '14.x']
|
13
|
-
os: [ubuntu-latest, windows-latest, macOS-latest]
|
14
|
-
|
15
|
-
steps:
|
16
|
-
- name: Checkout repo
|
17
|
-
uses: actions/checkout@v2
|
18
|
-
|
19
|
-
- name: Use Node ${{ matrix.node }}
|
20
|
-
uses: actions/setup-node@v1
|
21
|
-
with:
|
22
|
-
node-version: ${{ matrix.node }}
|
23
|
-
|
24
|
-
- name: Install deps and build (with cache)
|
25
|
-
uses: bahmutov/npm-install@v1
|
26
|
-
|
27
|
-
- name: Lint
|
28
|
-
run: yarn lint
|
29
|
-
|
30
|
-
- name: Build
|
31
|
-
run: yarn build
|
32
|
-
publish:
|
33
|
-
needs: build
|
34
|
-
name: Build, lint, and test on Node 10
|
35
7
|
runs-on: ubuntu-latest
|
36
8
|
steps:
|
37
|
-
-
|
38
|
-
|
39
|
-
-
|
40
|
-
uses: actions/setup-node@v1
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
# Setup .npmrc file to publish to npm
|
11
|
+
- uses: actions/setup-node@v2
|
41
12
|
with:
|
42
|
-
node-version:
|
43
|
-
|
44
|
-
|
45
|
-
-
|
46
|
-
run: yarn build
|
47
|
-
- name: 'Automated Version Bump'
|
48
|
-
uses: 'phips28/gh-action-bump-version@master'
|
13
|
+
node-version: '16.x'
|
14
|
+
registry-url: 'https://registry.npmjs.org'
|
15
|
+
- run: npm ci
|
16
|
+
- run: npm publish
|
49
17
|
env:
|
50
|
-
|
51
|
-
with:
|
52
|
-
target-branch: 'main'
|
53
|
-
- uses: JS-DevTools/npm-publish@v1
|
54
|
-
with:
|
55
|
-
token: ${{ secrets.NPM_TOKEN }}
|
56
|
-
access: public
|
57
|
-
|
18
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { testClient, testEuClient, getUserId } from "./arrange";
|
3
|
+
|
4
|
+
|
5
|
+
describe('Activity', () => {
|
6
|
+
it.each([
|
7
|
+
["us", testClient],
|
8
|
+
["eu", testEuClient]
|
9
|
+
])('should return activity data %p', async (region: string, client: VitalClient) => {
|
10
|
+
const userId = await getUserId(client)
|
11
|
+
const data = await client.Activity.get(
|
12
|
+
userId,
|
13
|
+
new Date("2020-01-01"),
|
14
|
+
new Date("2022-01-02"),
|
15
|
+
)
|
16
|
+
expect(data.activity.length).toBeGreaterThan(0)
|
17
|
+
});
|
18
|
+
})
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
require('dotenv').config({
|
3
|
+
path: '.env'
|
4
|
+
})
|
5
|
+
|
6
|
+
export const testClient = new VitalClient({
|
7
|
+
client_id: process.env.TEST_CLIENT_ID,
|
8
|
+
client_secret: process.env.TEST_CLIENT_SECRET,
|
9
|
+
environment: process.env.TEST_ENVIRONMENT as any,
|
10
|
+
region: "us",
|
11
|
+
});
|
12
|
+
|
13
|
+
export const testEuClient = new VitalClient({
|
14
|
+
client_id: process.env.TEST_EU_CLIENT_ID,
|
15
|
+
client_secret: process.env.TEST_EU_CLIENT_SECRET,
|
16
|
+
environment: "development",
|
17
|
+
region: "eu",
|
18
|
+
});
|
19
|
+
|
20
|
+
export const test_user_id = "test_user_1234";
|
21
|
+
|
22
|
+
export const getUserId = async (client: VitalClient, user_id: string = test_user_id) => {
|
23
|
+
const data = await client.User.resolve(user_id);
|
24
|
+
return data.user_id;
|
25
|
+
}
|
26
|
+
|
27
|
+
export function randomString(length: number): string {
|
28
|
+
var result = '';
|
29
|
+
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
30
|
+
var charactersLength = characters.length;
|
31
|
+
for (var i = 0; i < length; i++) {
|
32
|
+
result += characters.charAt(Math.floor(Math.random() *
|
33
|
+
charactersLength));
|
34
|
+
}
|
35
|
+
return result;
|
36
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { getUserId, testClient, testEuClient } from "./arrange";
|
3
|
+
|
4
|
+
describe('Body', () => {
|
5
|
+
it.each([
|
6
|
+
["us", testClient],
|
7
|
+
["eu", testEuClient]
|
8
|
+
])('should return body data %p', async (region: string, client: VitalClient) => {
|
9
|
+
const userId = await getUserId(client)
|
10
|
+
const data = await client.Body.get(
|
11
|
+
userId,
|
12
|
+
new Date("2021-01-01"),
|
13
|
+
new Date("2022-01-02"),
|
14
|
+
)
|
15
|
+
expect(data.body.length).toBeGreaterThan(0)
|
16
|
+
});
|
17
|
+
})
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { testClient, testEuClient, getUserId } from "./arrange";
|
3
|
+
|
4
|
+
describe('Devices', () => {
|
5
|
+
it.each([
|
6
|
+
["us", testClient],
|
7
|
+
["eu", testEuClient]
|
8
|
+
])('should return device data %p', async (region: string, client: VitalClient) => {
|
9
|
+
const userId = await getUserId(client)
|
10
|
+
const data = await client.Devices.get_raw(
|
11
|
+
userId,
|
12
|
+
)
|
13
|
+
expect(data.devices.length).toBeGreaterThan(0)
|
14
|
+
});
|
15
|
+
})
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { getUserId, testClient, testEuClient } from "./arrange";
|
3
|
+
|
4
|
+
describe('Link', () => {
|
5
|
+
it.each([
|
6
|
+
["us", testClient],
|
7
|
+
["eu", testEuClient]
|
8
|
+
])('should create a link token %p', async (region: string, client: VitalClient) => {
|
9
|
+
const userId = await getUserId(client)
|
10
|
+
const data = await client.Link.create(
|
11
|
+
userId,
|
12
|
+
)
|
13
|
+
expect(data.link_token).toBeDefined()
|
14
|
+
});
|
15
|
+
})
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { testClient, testEuClient, getUserId } from "./arrange";
|
3
|
+
|
4
|
+
describe('Profile', () => {
|
5
|
+
it.each([
|
6
|
+
["us", testClient],
|
7
|
+
["eu", testEuClient]
|
8
|
+
])('should return profile data %p', async (region: string, client: VitalClient) => {
|
9
|
+
const userId = await getUserId(client)
|
10
|
+
const data = await client.Profile.get(
|
11
|
+
userId,
|
12
|
+
)
|
13
|
+
expect(data.user_id).toBe(userId)
|
14
|
+
});
|
15
|
+
})
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { testClient, testEuClient, getUserId } from "./arrange";
|
3
|
+
|
4
|
+
describe('Sleep', () => {
|
5
|
+
it.each([
|
6
|
+
["us", testClient],
|
7
|
+
["eu", testEuClient]
|
8
|
+
])('should return sleep data %p', async (region: string, client: VitalClient) => {
|
9
|
+
const userId = await getUserId(client)
|
10
|
+
const data = await client.Sleep.get(
|
11
|
+
userId,
|
12
|
+
new Date("2021-01-01"),
|
13
|
+
new Date("2022-01-02"),
|
14
|
+
)
|
15
|
+
expect(data.sleep.length).toBeGreaterThan(0)
|
16
|
+
});
|
17
|
+
|
18
|
+
it.each([
|
19
|
+
["us", testClient],
|
20
|
+
["eu", testEuClient]
|
21
|
+
])('should return sleep data %p', async (region: string, client: VitalClient) => {
|
22
|
+
const userId = await getUserId(client)
|
23
|
+
const data = await client.Sleep.getSleepWithStream(
|
24
|
+
userId,
|
25
|
+
new Date("2021-01-01"),
|
26
|
+
new Date("2022-01-02"),
|
27
|
+
)
|
28
|
+
expect(data.sleep.length).toBeGreaterThan(0)
|
29
|
+
expect(data.sleep[0].sleep_stream).toBeDefined()
|
30
|
+
});
|
31
|
+
})
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { getUserId, randomString, testClient, testEuClient, test_user_id } from "./arrange";
|
3
|
+
|
4
|
+
describe('User', () => {
|
5
|
+
const user_id = randomString(10);
|
6
|
+
it.each([
|
7
|
+
["us", testClient],
|
8
|
+
["eu", testEuClient]
|
9
|
+
])('should create a user %p', async (region: string, client: VitalClient) => {
|
10
|
+
const user = await client.User.create(
|
11
|
+
user_id,
|
12
|
+
)
|
13
|
+
expect(user.client_user_id).toBe(user_id)
|
14
|
+
});
|
15
|
+
|
16
|
+
it.each([
|
17
|
+
testClient,
|
18
|
+
testEuClient
|
19
|
+
])('should find a user', async (client: VitalClient) => {
|
20
|
+
const user = await client.User.resolve(
|
21
|
+
test_user_id,
|
22
|
+
)
|
23
|
+
expect(user.client_user_id).toBe(test_user_id)
|
24
|
+
});
|
25
|
+
|
26
|
+
it.each([
|
27
|
+
testClient,
|
28
|
+
testEuClient
|
29
|
+
])('should delete a user', async (client: VitalClient) => {
|
30
|
+
const userToDelete = await getUserId(client, user_id);
|
31
|
+
const user = await client.User.delete(
|
32
|
+
userToDelete,
|
33
|
+
)
|
34
|
+
expect(user.success).toBe(true)
|
35
|
+
});
|
36
|
+
|
37
|
+
})
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { testClient, testEuClient, getUserId } from "./arrange";
|
3
|
+
|
4
|
+
describe('Vitals', () => {
|
5
|
+
it.each([
|
6
|
+
["us", testClient],
|
7
|
+
["eu", testEuClient]
|
8
|
+
])('should return glucose data %p', async (region: string, client: VitalClient) => {
|
9
|
+
const userId = await getUserId(client)
|
10
|
+
const data = await client.Vitals.glucose(
|
11
|
+
userId,
|
12
|
+
new Date("2021-01-01"),
|
13
|
+
new Date("2022-01-02"),
|
14
|
+
)
|
15
|
+
expect(data.length).toBeGreaterThan(0)
|
16
|
+
});
|
17
|
+
})
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { VitalClient } from "..";
|
2
|
+
import { testClient, testEuClient, getUserId } from "./arrange";
|
3
|
+
|
4
|
+
describe('Workouts', () => {
|
5
|
+
it.each([
|
6
|
+
["us", testClient],
|
7
|
+
["eu", testEuClient]
|
8
|
+
])('should return workout data %p', async (region: string, client: VitalClient) => {
|
9
|
+
const userId = await getUserId(client)
|
10
|
+
const data = await client.Workouts.get(
|
11
|
+
userId,
|
12
|
+
new Date("2021-01-01"),
|
13
|
+
new Date("2022-01-02"),
|
14
|
+
)
|
15
|
+
expect(data.workouts.length).toBeGreaterThan(0)
|
16
|
+
});
|
17
|
+
})
|
package/client/Activity.ts
CHANGED
@@ -13,7 +13,7 @@ export class ActivityApi {
|
|
13
13
|
public async get(
|
14
14
|
userId: string,
|
15
15
|
startDate: Date,
|
16
|
-
endDate
|
16
|
+
endDate?: Date,
|
17
17
|
provider?: string
|
18
18
|
): Promise<ClientActivityResponse> {
|
19
19
|
const resp = await this.client.get(
|
@@ -28,7 +28,7 @@ export class ActivityApi {
|
|
28
28
|
public async get_raw(
|
29
29
|
userId: string,
|
30
30
|
startDate: Date,
|
31
|
-
endDate
|
31
|
+
endDate?: Date,
|
32
32
|
provider?: string
|
33
33
|
): Promise<ClientActivityRawResponse> {
|
34
34
|
const resp = await this.client.get(
|
package/client/Body.ts
CHANGED
@@ -14,7 +14,7 @@ export class BodyApi {
|
|
14
14
|
public async get(
|
15
15
|
userId: string,
|
16
16
|
startDate: Date,
|
17
|
-
endDate
|
17
|
+
endDate?: Date,
|
18
18
|
provider?: string
|
19
19
|
): Promise<ClientBodyResponse> {
|
20
20
|
const resp = await this.client.get(
|
@@ -29,7 +29,7 @@ export class BodyApi {
|
|
29
29
|
public async get_raw(
|
30
30
|
userId: string,
|
31
31
|
startDate: Date,
|
32
|
-
endDate
|
32
|
+
endDate?: Date,
|
33
33
|
provider?: string
|
34
34
|
): Promise<ClientBodyRawResponse> {
|
35
35
|
const resp = await this.client.get(
|
package/client/Sleep.ts
CHANGED
@@ -16,11 +16,27 @@ export class SleepApi {
|
|
16
16
|
public async get(
|
17
17
|
userId: string,
|
18
18
|
startDate: Date,
|
19
|
-
endDate
|
20
|
-
provider?: string
|
19
|
+
endDate?: Date,
|
20
|
+
provider?: string,
|
21
|
+
with_stream: boolean = false
|
21
22
|
): Promise<ClientSleepResponse> {
|
22
23
|
const resp = await this.client.get(
|
23
24
|
this.baseURL.concat(`/summary/sleep/${userId}`),
|
25
|
+
{
|
26
|
+
params: { start_date: startDate, end_date: endDate, provider, with_stream },
|
27
|
+
}
|
28
|
+
);
|
29
|
+
return resp.data;
|
30
|
+
}
|
31
|
+
|
32
|
+
public async getSleepWithStream(
|
33
|
+
userId: string,
|
34
|
+
startDate: Date,
|
35
|
+
endDate?: Date,
|
36
|
+
provider?: string
|
37
|
+
): Promise<ClientSleepResponse> {
|
38
|
+
const resp = await this.client.get(
|
39
|
+
this.baseURL.concat(`/summary/sleep/${userId}/stream`),
|
24
40
|
{
|
25
41
|
params: { start_date: startDate, end_date: endDate, provider },
|
26
42
|
}
|
@@ -38,7 +54,7 @@ export class SleepApi {
|
|
38
54
|
public async get_raw(
|
39
55
|
userId: string,
|
40
56
|
startDate: Date,
|
41
|
-
endDate
|
57
|
+
endDate?: Date,
|
42
58
|
provider?: string
|
43
59
|
): Promise<ClientSleepRawResponse> {
|
44
60
|
const resp = await this.client.get(
|
package/client/Testkits.ts
CHANGED
@@ -25,12 +25,13 @@ export class TestkitsApi {
|
|
25
25
|
|
26
26
|
public async get_orders(
|
27
27
|
startDate: Date,
|
28
|
-
endDate: Date
|
28
|
+
endDate: Date,
|
29
|
+
status?: string[],
|
29
30
|
): Promise<OrderResponse> {
|
30
31
|
const resp = await this.client.get(
|
31
32
|
this.baseURL.concat('/testkit/orders/'),
|
32
33
|
{
|
33
|
-
params: { start_date: startDate, end_date: endDate },
|
34
|
+
params: { start_date: startDate, end_date: endDate, status: status ? status : null},
|
34
35
|
}
|
35
36
|
);
|
36
37
|
return resp.data;
|
@@ -61,6 +62,13 @@ export class TestkitsApi {
|
|
61
62
|
return resp.data;
|
62
63
|
}
|
63
64
|
|
65
|
+
public async cancel_order(orderId: string): Promise<OrderRequestResponse> {
|
66
|
+
const resp = await this.client.post(
|
67
|
+
this.baseURL.concat(`/testkit/orders/${orderId}/cancel`)
|
68
|
+
);
|
69
|
+
return resp.data;
|
70
|
+
}
|
71
|
+
|
64
72
|
public async get_results(orderId: string): Promise<string> {
|
65
73
|
const resp = await this.client.get(
|
66
74
|
this.baseURL.concat(`/testkit/orders/${orderId}/results`),
|
package/client/Vitals.ts
CHANGED
@@ -13,7 +13,7 @@ export class VitalsApi {
|
|
13
13
|
user_key: string,
|
14
14
|
resource: string,
|
15
15
|
startDate: Date,
|
16
|
-
endDate
|
16
|
+
endDate?: Date,
|
17
17
|
provider?: string
|
18
18
|
): Promise<TimeseriesPoint[]> {
|
19
19
|
const resp = await this.client.get(
|
@@ -29,7 +29,7 @@ export class VitalsApi {
|
|
29
29
|
type: 'ldl' | 'total' | 'triglycerides' | 'hdl',
|
30
30
|
userId: string,
|
31
31
|
startDate: Date,
|
32
|
-
endDate
|
32
|
+
endDate?: Date,
|
33
33
|
provider?: string
|
34
34
|
): Promise<TimeseriesPoint[]> {
|
35
35
|
return this.timeseriesData(
|
@@ -44,7 +44,7 @@ export class VitalsApi {
|
|
44
44
|
public async glucose(
|
45
45
|
userId: string,
|
46
46
|
startDate: Date,
|
47
|
-
endDate
|
47
|
+
endDate?: Date,
|
48
48
|
provider?: string
|
49
49
|
): Promise<TimeseriesPoint[]> {
|
50
50
|
return this.timeseriesData(
|
@@ -59,7 +59,7 @@ export class VitalsApi {
|
|
59
59
|
public async ige(
|
60
60
|
userId: string,
|
61
61
|
startDate: Date,
|
62
|
-
endDate
|
62
|
+
endDate?: Date,
|
63
63
|
provider?: string
|
64
64
|
): Promise<TimeseriesPoint[]> {
|
65
65
|
return this.timeseriesData(userId, 'ige', startDate, endDate, provider);
|
@@ -68,7 +68,7 @@ export class VitalsApi {
|
|
68
68
|
public async igg(
|
69
69
|
userId: string,
|
70
70
|
startDate: Date,
|
71
|
-
endDate
|
71
|
+
endDate?: Date,
|
72
72
|
provider?: string
|
73
73
|
): Promise<TimeseriesPoint[]> {
|
74
74
|
return this.timeseriesData(userId, 'igg', startDate, endDate, provider);
|
@@ -77,7 +77,7 @@ export class VitalsApi {
|
|
77
77
|
public async heartrate(
|
78
78
|
userId: string,
|
79
79
|
startDate: Date,
|
80
|
-
endDate
|
80
|
+
endDate?: Date,
|
81
81
|
provider?: string
|
82
82
|
): Promise<TimeseriesPoint[]> {
|
83
83
|
return this.timeseriesData(
|
package/client/Workouts.ts
CHANGED
@@ -16,7 +16,7 @@ export class WorkoutsApi {
|
|
16
16
|
public async get(
|
17
17
|
userId: string,
|
18
18
|
startDate: Date,
|
19
|
-
endDate
|
19
|
+
endDate?: Date,
|
20
20
|
provider?: string
|
21
21
|
): Promise<ClientWorkoutResponse> {
|
22
22
|
const resp = await this.client.get(
|
@@ -40,7 +40,7 @@ export class WorkoutsApi {
|
|
40
40
|
public async get_raw(
|
41
41
|
userId: string,
|
42
42
|
startDate: Date,
|
43
|
-
endDate
|
43
|
+
endDate?: Date,
|
44
44
|
provider?: string
|
45
45
|
): Promise<ClientWorkoutsRawResponse> {
|
46
46
|
const resp = await this.client.get(
|
@@ -127,6 +127,13 @@ export interface ClientFacingSleep {
|
|
127
127
|
* @memberof ClientFacingSleep
|
128
128
|
*/
|
129
129
|
user_id: string;
|
130
|
+
/**
|
131
|
+
* UTC time when the sleep period started
|
132
|
+
* @type {ClientSleepStreamResponse}
|
133
|
+
* @memberof ClientFacingSleep
|
134
|
+
*
|
135
|
+
*/
|
136
|
+
sleep_stream: ClientSleepStreamResponse[];
|
130
137
|
}
|
131
138
|
|
132
139
|
export interface ClientSleepResponse {
|
@@ -35,17 +35,19 @@ export interface Order {
|
|
35
35
|
created_on: Date;
|
36
36
|
updated_on: Date;
|
37
37
|
status:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
| 'ordered'
|
39
|
+
| 'transit_customer'
|
40
|
+
| 'out_for_delivery'
|
41
|
+
| 'with_customer'
|
42
|
+
| 'transit_lab'
|
43
|
+
| 'delivered_to_lab'
|
44
|
+
| 'processing_lab'
|
45
|
+
| 'completed'
|
46
|
+
| 'failure_to_deliver_to_customer'
|
47
|
+
| 'failure_to_deliver_to_lab'
|
48
|
+
| 'cancelled'
|
49
|
+
| 'do_not_process'
|
50
|
+
| 'unknown';
|
49
51
|
user_key: string;
|
50
52
|
testkit_id: string;
|
51
53
|
testkit: Testkit;
|
@@ -5,6 +5,6 @@ export declare class ActivityApi {
|
|
5
5
|
baseURL: string;
|
6
6
|
client: AxiosInstance;
|
7
7
|
constructor(baseURL: string, axios: AxiosInstance);
|
8
|
-
get(userId: string, startDate: Date, endDate
|
9
|
-
get_raw(userId: string, startDate: Date, endDate
|
8
|
+
get(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<ClientActivityResponse>;
|
9
|
+
get_raw(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<ClientActivityRawResponse>;
|
10
10
|
}
|
package/dist/client/Body.d.ts
CHANGED
@@ -5,6 +5,6 @@ export declare class BodyApi {
|
|
5
5
|
baseURL: string;
|
6
6
|
client: AxiosInstance;
|
7
7
|
constructor(baseURL: string, axios: AxiosInstance);
|
8
|
-
get(userId: string, startDate: Date, endDate
|
9
|
-
get_raw(userId: string, startDate: Date, endDate
|
8
|
+
get(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<ClientBodyResponse>;
|
9
|
+
get_raw(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<ClientBodyRawResponse>;
|
10
10
|
}
|
package/dist/client/Sleep.d.ts
CHANGED
@@ -5,7 +5,8 @@ export declare class SleepApi {
|
|
5
5
|
baseURL: string;
|
6
6
|
client: AxiosInstance;
|
7
7
|
constructor(baseURL: string, axios: AxiosInstance);
|
8
|
-
get(userId: string, startDate: Date, endDate
|
8
|
+
get(userId: string, startDate: Date, endDate?: Date, provider?: string, with_stream?: boolean): Promise<ClientSleepResponse>;
|
9
|
+
getSleepWithStream(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<ClientSleepResponse>;
|
9
10
|
getStream(sleepId: string): Promise<ClientSleepStreamResponse>;
|
10
|
-
get_raw(userId: string, startDate: Date, endDate
|
11
|
+
get_raw(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<ClientSleepRawResponse>;
|
11
12
|
}
|
package/dist/client/Sleep.js
CHANGED
@@ -42,12 +42,28 @@ var SleepApi = /** @class */ (function () {
|
|
42
42
|
this.baseURL = baseURL;
|
43
43
|
this.client = axios;
|
44
44
|
}
|
45
|
-
SleepApi.prototype.get = function (userId, startDate, endDate, provider) {
|
45
|
+
SleepApi.prototype.get = function (userId, startDate, endDate, provider, with_stream) {
|
46
|
+
if (with_stream === void 0) { with_stream = false; }
|
46
47
|
return __awaiter(this, void 0, void 0, function () {
|
47
48
|
var resp;
|
48
49
|
return __generator(this, function (_a) {
|
49
50
|
switch (_a.label) {
|
50
51
|
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat("/summary/sleep/" + userId), {
|
52
|
+
params: { start_date: startDate, end_date: endDate, provider: provider, with_stream: with_stream },
|
53
|
+
})];
|
54
|
+
case 1:
|
55
|
+
resp = _a.sent();
|
56
|
+
return [2 /*return*/, resp.data];
|
57
|
+
}
|
58
|
+
});
|
59
|
+
});
|
60
|
+
};
|
61
|
+
SleepApi.prototype.getSleepWithStream = function (userId, startDate, endDate, provider) {
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
63
|
+
var resp;
|
64
|
+
return __generator(this, function (_a) {
|
65
|
+
switch (_a.label) {
|
66
|
+
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat("/summary/sleep/" + userId + "/stream"), {
|
51
67
|
params: { start_date: startDate, end_date: endDate, provider: provider },
|
52
68
|
})];
|
53
69
|
case 1:
|
@@ -5,9 +5,10 @@ export declare class TestkitsApi {
|
|
5
5
|
client: AxiosInstance;
|
6
6
|
constructor(baseURL: string, axios: AxiosInstance);
|
7
7
|
get(): Promise<TestkitResponse>;
|
8
|
-
get_orders(startDate: Date, endDate: Date): Promise<OrderResponse>;
|
8
|
+
get_orders(startDate: Date, endDate: Date, status?: string[]): Promise<OrderResponse>;
|
9
9
|
order(userId: string, testkitId: string, patientAddress: PatientAdress, patientDetails: PatientDetails): Promise<OrderRequestResponse>;
|
10
10
|
get_order(orderId: string): Promise<Order>;
|
11
|
+
cancel_order(orderId: string): Promise<OrderRequestResponse>;
|
11
12
|
get_results(orderId: string): Promise<string>;
|
12
13
|
getMetadata(orderId: string): Promise<LabResultsMetadata>;
|
13
14
|
getRawResults(orderId: string): Promise<LabResultsRaw>;
|
package/dist/client/Testkits.js
CHANGED
@@ -55,13 +55,13 @@ var TestkitsApi = /** @class */ (function () {
|
|
55
55
|
});
|
56
56
|
});
|
57
57
|
};
|
58
|
-
TestkitsApi.prototype.get_orders = function (startDate, endDate) {
|
58
|
+
TestkitsApi.prototype.get_orders = function (startDate, endDate, status) {
|
59
59
|
return __awaiter(this, void 0, void 0, function () {
|
60
60
|
var resp;
|
61
61
|
return __generator(this, function (_a) {
|
62
62
|
switch (_a.label) {
|
63
63
|
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat('/testkit/orders/'), {
|
64
|
-
params: { start_date: startDate, end_date: endDate },
|
64
|
+
params: { start_date: startDate, end_date: endDate, status: status ? status : null },
|
65
65
|
})];
|
66
66
|
case 1:
|
67
67
|
resp = _a.sent();
|
@@ -101,6 +101,19 @@ var TestkitsApi = /** @class */ (function () {
|
|
101
101
|
});
|
102
102
|
});
|
103
103
|
};
|
104
|
+
TestkitsApi.prototype.cancel_order = function (orderId) {
|
105
|
+
return __awaiter(this, void 0, void 0, function () {
|
106
|
+
var resp;
|
107
|
+
return __generator(this, function (_a) {
|
108
|
+
switch (_a.label) {
|
109
|
+
case 0: return [4 /*yield*/, this.client.post(this.baseURL.concat("/testkit/orders/" + orderId + "/cancel"))];
|
110
|
+
case 1:
|
111
|
+
resp = _a.sent();
|
112
|
+
return [2 /*return*/, resp.data];
|
113
|
+
}
|
114
|
+
});
|
115
|
+
});
|
116
|
+
};
|
104
117
|
TestkitsApi.prototype.get_results = function (orderId) {
|
105
118
|
return __awaiter(this, void 0, void 0, function () {
|
106
119
|
var resp;
|
package/dist/client/Vitals.d.ts
CHANGED
@@ -5,9 +5,9 @@ export declare class VitalsApi {
|
|
5
5
|
client: AxiosInstance;
|
6
6
|
constructor(baseURL: string, axios: AxiosInstance);
|
7
7
|
private timeseriesData;
|
8
|
-
cholesterol(type: 'ldl' | 'total' | 'triglycerides' | 'hdl', userId: string, startDate: Date, endDate
|
9
|
-
glucose(userId: string, startDate: Date, endDate
|
10
|
-
ige(userId: string, startDate: Date, endDate
|
11
|
-
igg(userId: string, startDate: Date, endDate
|
12
|
-
heartrate(userId: string, startDate: Date, endDate
|
8
|
+
cholesterol(type: 'ldl' | 'total' | 'triglycerides' | 'hdl', userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<TimeseriesPoint[]>;
|
9
|
+
glucose(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<TimeseriesPoint[]>;
|
10
|
+
ige(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<TimeseriesPoint[]>;
|
11
|
+
igg(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<TimeseriesPoint[]>;
|
12
|
+
heartrate(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<TimeseriesPoint[]>;
|
13
13
|
}
|
@@ -5,7 +5,7 @@ export declare class WorkoutsApi {
|
|
5
5
|
baseURL: string;
|
6
6
|
client: AxiosInstance;
|
7
7
|
constructor(baseURL: string, axios: AxiosInstance);
|
8
|
-
get(userId: string, startDate: Date, endDate
|
8
|
+
get(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<ClientWorkoutResponse>;
|
9
9
|
getStream(workoutId: string): Promise<ClientWorkoutStreamResponse>;
|
10
|
-
get_raw(userId: string, startDate: Date, endDate
|
10
|
+
get_raw(userId: string, startDate: Date, endDate?: Date, provider?: string): Promise<ClientWorkoutsRawResponse>;
|
11
11
|
}
|
@@ -126,6 +126,13 @@ export interface ClientFacingSleep {
|
|
126
126
|
* @memberof ClientFacingSleep
|
127
127
|
*/
|
128
128
|
user_id: string;
|
129
|
+
/**
|
130
|
+
* UTC time when the sleep period started
|
131
|
+
* @type {ClientSleepStreamResponse}
|
132
|
+
* @memberof ClientFacingSleep
|
133
|
+
*
|
134
|
+
*/
|
135
|
+
sleep_stream: ClientSleepStreamResponse[];
|
129
136
|
}
|
130
137
|
export interface ClientSleepResponse {
|
131
138
|
/**
|
@@ -31,7 +31,7 @@ export interface Order {
|
|
31
31
|
team_id: string;
|
32
32
|
created_on: Date;
|
33
33
|
updated_on: Date;
|
34
|
-
status: 'ordered' | 'transit_customer' | 'out_for_delivery' | 'with_customer' | 'transit_lab' | 'delivered_to_lab' | 'processing_lab' | 'completed' | 'failure_to_deliver_to_customer' | 'failure_to_deliver_to_lab' | 'unknown';
|
34
|
+
status: 'ordered' | 'transit_customer' | 'out_for_delivery' | 'with_customer' | 'transit_lab' | 'delivered_to_lab' | 'processing_lab' | 'completed' | 'failure_to_deliver_to_customer' | 'failure_to_deliver_to_lab' | 'cancelled' | 'do_not_process' | 'unknown';
|
35
35
|
user_key: string;
|
36
36
|
testkit_id: string;
|
37
37
|
testkit: Testkit;
|
package/dist/index.js
CHANGED
@@ -60,7 +60,13 @@ var VitalClient = /** @class */ (function () {
|
|
60
60
|
var _this = this;
|
61
61
|
this.config = config;
|
62
62
|
this.clientCredentials = new credentials_1.ClientCredentials(config);
|
63
|
-
var baseURL
|
63
|
+
var baseURL;
|
64
|
+
if (this.config.region && this.config.region === 'eu') {
|
65
|
+
baseURL = config_1.default.baseEUUrls[config.environment];
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
baseURL = config_1.default.baseUrls[config.environment];
|
69
|
+
}
|
64
70
|
var axiosApiInstance = axios_1.default.create();
|
65
71
|
axios_retry_1.default(axiosApiInstance, {
|
66
72
|
retries: 3,
|
package/dist/lib/config.d.ts
CHANGED
@@ -3,16 +3,25 @@ declare const _default: {
|
|
3
3
|
production: string;
|
4
4
|
prod: string;
|
5
5
|
sandbox: string;
|
6
|
+
development: string;
|
6
7
|
};
|
7
8
|
domains: {
|
8
9
|
production: string;
|
9
10
|
prod: string;
|
10
11
|
sandbox: string;
|
12
|
+
development: string;
|
11
13
|
};
|
12
14
|
baseUrls: {
|
13
15
|
prod: string;
|
14
16
|
production: string;
|
15
17
|
sandbox: string;
|
18
|
+
development: string;
|
19
|
+
};
|
20
|
+
baseEUUrls: {
|
21
|
+
prod: string;
|
22
|
+
production: string;
|
23
|
+
sandbox: string;
|
24
|
+
development: string;
|
16
25
|
};
|
17
26
|
};
|
18
27
|
export default _default;
|
package/dist/lib/config.js
CHANGED
@@ -5,15 +5,24 @@ exports.default = {
|
|
5
5
|
production: 'https://api.tryvital.io',
|
6
6
|
prod: 'https://api.tryvital.io',
|
7
7
|
sandbox: 'https://api.sandbox.tryvital.io',
|
8
|
+
development: 'https://api.tryvital.io/v1',
|
8
9
|
},
|
9
10
|
domains: {
|
10
11
|
production: 'auth.tryvital.io',
|
11
12
|
prod: 'auth.tryvital.io',
|
12
13
|
sandbox: 'auth.sandbox.tryvital.io',
|
14
|
+
development: 'dev-vital-api.us.auth0.com',
|
13
15
|
},
|
14
16
|
baseUrls: {
|
15
17
|
prod: 'https://api.tryvital.io',
|
16
18
|
production: 'https://api.tryvital.io',
|
17
19
|
sandbox: 'https://api.sandbox.tryvital.io',
|
20
|
+
development: 'https://api.dev.tryvital.io',
|
21
|
+
},
|
22
|
+
baseEUUrls: {
|
23
|
+
prod: 'https://api.eu.tryvital.io',
|
24
|
+
production: 'https://api.eu.tryvital.io',
|
25
|
+
sandbox: 'https://api.sandbox.eu.tryvital.io',
|
26
|
+
development: 'https://api.dev.eu.tryvital.io',
|
18
27
|
},
|
19
28
|
};
|
package/dist/lib/models.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
export interface ClientConfig {
|
2
2
|
client_id: string;
|
3
3
|
client_secret: string;
|
4
|
-
environment: 'prod' | 'production' | 'sandbox';
|
4
|
+
environment: 'prod' | 'production' | 'sandbox' | 'development';
|
5
|
+
region?: 'us' | 'eu';
|
5
6
|
}
|
6
7
|
export interface AccessToken {
|
7
8
|
token: string;
|
package/index.ts
CHANGED
@@ -37,7 +37,12 @@ export class VitalClient {
|
|
37
37
|
constructor(config: ClientConfig) {
|
38
38
|
this.config = config;
|
39
39
|
this.clientCredentials = new ClientCredentials(config);
|
40
|
-
|
40
|
+
let baseURL;
|
41
|
+
if (this.config.region && this.config.region === 'eu') {
|
42
|
+
baseURL = CONFIG.baseEUUrls[config.environment];
|
43
|
+
} else {
|
44
|
+
baseURL = CONFIG.baseUrls[config.environment];
|
45
|
+
}
|
41
46
|
const axiosApiInstance = axios.create();
|
42
47
|
|
43
48
|
axiosRetry(axiosApiInstance, {
|
package/jest.config.js
ADDED
package/lib/config.ts
CHANGED
@@ -3,15 +3,24 @@ export default {
|
|
3
3
|
production: 'https://api.tryvital.io',
|
4
4
|
prod: 'https://api.tryvital.io',
|
5
5
|
sandbox: 'https://api.sandbox.tryvital.io',
|
6
|
+
development: 'https://api.tryvital.io/v1',
|
6
7
|
},
|
7
8
|
domains: {
|
8
9
|
production: 'auth.tryvital.io',
|
9
10
|
prod: 'auth.tryvital.io',
|
10
11
|
sandbox: 'auth.sandbox.tryvital.io',
|
12
|
+
development: 'dev-vital-api.us.auth0.com',
|
11
13
|
},
|
12
14
|
baseUrls: {
|
13
15
|
prod: 'https://api.tryvital.io',
|
14
16
|
production: 'https://api.tryvital.io',
|
15
17
|
sandbox: 'https://api.sandbox.tryvital.io',
|
18
|
+
development: 'https://api.dev.tryvital.io',
|
19
|
+
},
|
20
|
+
baseEUUrls: {
|
21
|
+
prod: 'https://api.eu.tryvital.io',
|
22
|
+
production: 'https://api.eu.tryvital.io',
|
23
|
+
sandbox: 'https://api.sandbox.eu.tryvital.io',
|
24
|
+
development: 'https://api.dev.eu.tryvital.io',
|
16
25
|
},
|
17
26
|
};
|
package/lib/models.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tryvital/vital-node",
|
3
|
-
"version": "1.2
|
3
|
+
"version": "1.3.2",
|
4
4
|
"description": "Node client for Vital",
|
5
5
|
"author": "maitham",
|
6
6
|
"keywords": [
|
@@ -17,6 +17,8 @@
|
|
17
17
|
"prepublishOnly": "npm run build",
|
18
18
|
"test": "env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --require ts-node/register './test/**/*.ts'",
|
19
19
|
"test-typescript": "tsc --build types/test",
|
20
|
+
"test-client": "jest --config jest.config.js",
|
21
|
+
"test-single": "jest --config -i __tests__/user.test.ts jest.config.js",
|
20
22
|
"lint": "eslint --ext .js,.jsx,.ts ."
|
21
23
|
},
|
22
24
|
"dependencies": {
|
@@ -28,6 +30,7 @@
|
|
28
30
|
},
|
29
31
|
"devDependencies": {
|
30
32
|
"@testdeck/mocha": "^0.1.2",
|
33
|
+
"@types/jest": "^27.4.1",
|
31
34
|
"@types/mocha": "^9.0.0",
|
32
35
|
"@types/node": "^16.6.1",
|
33
36
|
"@typescript-eslint/eslint-plugin": "^4.29.1",
|
@@ -35,6 +38,7 @@
|
|
35
38
|
"chai": "~4.2.0",
|
36
39
|
"chai-as-promised": "~7.1.1",
|
37
40
|
"coveralls": "^3.0.0",
|
41
|
+
"dotenv": "^16.0.0",
|
38
42
|
"eslint": "^7.32.0",
|
39
43
|
"eslint-config-airbnb-base": "^14.2.1",
|
40
44
|
"eslint-config-prettier": "^4.3.0",
|
@@ -42,11 +46,13 @@
|
|
42
46
|
"eslint-plugin-import": "^2.24.0",
|
43
47
|
"eslint-plugin-prettier": "^3.4.0",
|
44
48
|
"esm": "^3.2.25",
|
49
|
+
"jest": "^27.5.1",
|
45
50
|
"mocha": "^9.2.0",
|
46
51
|
"mocha-junit-reporter": "^2.0.2",
|
47
52
|
"nock": "^13.1.1",
|
48
53
|
"nyc": "^15.1.0",
|
49
54
|
"prettier": "^2.3.2",
|
55
|
+
"ts-jest": "^27.1.3",
|
50
56
|
"ts-node": "^10.2.0",
|
51
57
|
"typescript": "^4.3.5"
|
52
58
|
}
|
package/tsconfig.json
CHANGED
@@ -6,9 +6,18 @@
|
|
6
6
|
"noImplicitAny": true,
|
7
7
|
"outDir": "dist",
|
8
8
|
"rootDir": ".",
|
9
|
-
"
|
10
|
-
"
|
9
|
+
"skipLibCheck": true,
|
10
|
+
"lib": [
|
11
|
+
"es6",
|
12
|
+
"dom"
|
13
|
+
],
|
14
|
+
"typeRoots": [
|
15
|
+
"node_modules/@types"
|
16
|
+
]
|
11
17
|
},
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
"exclude": [
|
19
|
+
"dist",
|
20
|
+
"node_modules/**",
|
21
|
+
"__tests__"
|
22
|
+
]
|
23
|
+
}
|