@tryvital/vital-node 1.2.0 → 1.3.0

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "jest.autoEnable": false
3
+ }
@@ -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,17 @@
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
+ })
@@ -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
+ })
@@ -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`),
@@ -35,17 +35,19 @@ export interface Order {
35
35
  created_on: Date;
36
36
  updated_on: Date;
37
37
  status:
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
- | 'unknown';
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;
@@ -36,6 +36,7 @@ export interface ClientFacingUser {
36
36
  client_user_id: string;
37
37
  created_on: string;
38
38
  connecte_sources: Array<ConnectedSourceClientFacing>;
39
+ user_id: string;
39
40
  }
40
41
 
41
42
  export enum Providers {
@@ -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>;
@@ -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;
@@ -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;
@@ -30,6 +30,7 @@ export interface ClientFacingUser {
30
30
  client_user_id: string;
31
31
  created_on: string;
32
32
  connecte_sources: Array<ConnectedSourceClientFacing>;
33
+ user_id: string;
33
34
  }
34
35
  export declare enum Providers {
35
36
  Oura = "oura",
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 = config_1.default.baseUrls[config.environment];
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,
@@ -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;
@@ -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
  };
@@ -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
- const baseURL = CONFIG.baseUrls[config.environment];
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
@@ -0,0 +1,6 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ modulePathIgnorePatterns: ["__tests__/arrange.ts"]
6
+ };
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
@@ -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
 
7
8
  export interface AccessToken {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvital/vital-node",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
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
- "lib": ["es6", "dom"],
10
- "typeRoots": ["node_modules/@types"]
9
+ "skipLibCheck": true,
10
+ "lib": [
11
+ "es6",
12
+ "dom"
13
+ ],
14
+ "typeRoots": [
15
+ "node_modules/@types"
16
+ ]
11
17
  },
12
-
13
- "exclude": ["dist", "node_modules"]
14
- }
18
+ "exclude": [
19
+ "dist",
20
+ "node_modules/**",
21
+ "__tests__"
22
+ ]
23
+ }