@tryvital/vital-node 1.3.3 → 1.3.6

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.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  Node client for using Vital API.
4
4
 
5
-
6
5
  ### Install
7
6
 
8
7
  With npm:
@@ -17,22 +16,6 @@ With yarn
17
16
  yarn add @tryvital/vital-node
18
17
  ```
19
18
 
20
-
21
19
  ## Documentation
22
20
 
23
- The official [Vital Link docs](https://docs.tryvital.io) provide a full reference on using this library.
24
-
25
-
26
- ### Examples
27
- ```
28
- const { VitalClient } = require("Vital");
29
-
30
- const client = new VitalClient({
31
- client_id: <CLIENT_ID>,
32
- client_secret: <CLIENT_SECRET>,
33
- environment: "sandbox",
34
- });
35
-
36
- const resp = await client.User.getUser(user_key)
37
- const data = await resp.data
38
- ```
21
+ Please refer to the official [Vital docs](https://docs.tryvital.io) provide a full reference on using this library.
@@ -1,11 +1,12 @@
1
1
  import { VitalClient } from "..";
2
- import { testClient, testEuClient, getUserId } from "./arrange";
2
+ import { testClient, testEuClient, testApiKeyClient, getUserId } from "./arrange";
3
3
 
4
4
 
5
5
  describe('Activity', () => {
6
6
  it.each([
7
7
  ["us", testClient],
8
- ["eu", testEuClient]
8
+ ["eu", testEuClient],
9
+ ["us_api_key", testApiKeyClient],
9
10
  ])('should return activity data %p', async (region: string, client: VitalClient) => {
10
11
  const userId = await getUserId(client)
11
12
  const data = await client.Activity.get(
@@ -17,6 +17,12 @@ export const testEuClient = new VitalClient({
17
17
  region: "eu",
18
18
  });
19
19
 
20
+ export const testApiKeyClient = new VitalClient({
21
+ api_key: process.env.TEST_API_KEY,
22
+ environment: process.env.TEST_ENVIRONMENT as any,
23
+ region: "us",
24
+ });
25
+
20
26
  export const test_user_id = "test_user_1234";
21
27
 
22
28
  export const getUserId = async (client: VitalClient, user_id: string = test_user_id) => {
@@ -1,10 +1,11 @@
1
1
  import { VitalClient } from "..";
2
- import { getUserId, testClient, testEuClient } from "./arrange";
2
+ import { getUserId, testApiKeyClient, testClient, testEuClient } from "./arrange";
3
3
 
4
4
  describe('Body', () => {
5
5
  it.each([
6
6
  ["us", testClient],
7
- ["eu", testEuClient]
7
+ ["eu", testEuClient],
8
+ ["us_api_key", testApiKeyClient],
8
9
  ])('should return body data %p', async (region: string, client: VitalClient) => {
9
10
  const userId = await getUserId(client)
10
11
  const data = await client.Body.get(
@@ -1,10 +1,11 @@
1
1
  import { VitalClient } from "..";
2
- import { testClient, testEuClient, getUserId } from "./arrange";
2
+ import { testClient, testEuClient, getUserId, testApiKeyClient } from "./arrange";
3
3
 
4
4
  describe('Devices', () => {
5
5
  it.each([
6
6
  ["us", testClient],
7
- ["eu", testEuClient]
7
+ ["eu", testEuClient],
8
+ ["us_api_key", testApiKeyClient],
8
9
  ])('should return device data %p', async (region: string, client: VitalClient) => {
9
10
  const userId = await getUserId(client)
10
11
  const data = await client.Devices.get_raw(
@@ -1,10 +1,11 @@
1
1
  import { VitalClient } from "..";
2
- import { getUserId, testClient, testEuClient } from "./arrange";
2
+ import { getUserId, testApiKeyClient, testClient, testEuClient } from "./arrange";
3
3
 
4
4
  describe('Link', () => {
5
5
  it.each([
6
6
  ["us", testClient],
7
- ["eu", testEuClient]
7
+ ["eu", testEuClient],
8
+ ["us_api_key", testApiKeyClient],
8
9
  ])('should create a link token %p', async (region: string, client: VitalClient) => {
9
10
  const userId = await getUserId(client)
10
11
  const data = await client.Link.create(
@@ -1,10 +1,11 @@
1
1
  import { VitalClient } from "..";
2
- import { testClient, testEuClient, getUserId } from "./arrange";
2
+ import { testClient, testEuClient, getUserId, testApiKeyClient } from "./arrange";
3
3
 
4
4
  describe('Profile', () => {
5
5
  it.each([
6
6
  ["us", testClient],
7
- ["eu", testEuClient]
7
+ ["eu", testEuClient],
8
+ ["us_api_key", testApiKeyClient],
8
9
  ])('should return profile data %p', async (region: string, client: VitalClient) => {
9
10
  const userId = await getUserId(client)
10
11
  const data = await client.Profile.get(
@@ -0,0 +1,6 @@
1
+ import { testApiKeyClient } from "./arrange";
2
+
3
+ it('should return supported providers', async () => {
4
+ const data = await testApiKeyClient.Providers.getSupportedProviders()
5
+ expect(data.length).toBeGreaterThan(0)
6
+ })
@@ -1,10 +1,11 @@
1
1
  import { VitalClient } from "..";
2
- import { testClient, testEuClient, getUserId } from "./arrange";
2
+ import { testClient, testEuClient, getUserId, testApiKeyClient } from "./arrange";
3
3
 
4
4
  describe('Sleep', () => {
5
5
  it.each([
6
6
  ["us", testClient],
7
- ["eu", testEuClient]
7
+ ["eu", testEuClient],
8
+ ["us_api_key", testApiKeyClient],
8
9
  ])('should return sleep data %p', async (region: string, client: VitalClient) => {
9
10
  const userId = await getUserId(client)
10
11
  const data = await client.Sleep.get(
@@ -17,13 +18,14 @@ describe('Sleep', () => {
17
18
 
18
19
  it.each([
19
20
  ["us", testClient],
20
- ["eu", testEuClient]
21
- ])('should return sleep data %p', async (region: string, client: VitalClient) => {
21
+ ["eu", testEuClient],
22
+ ["us_api_key", testApiKeyClient],
23
+ ])('should return sleep stream data %p', async (region: string, client: VitalClient) => {
22
24
  const userId = await getUserId(client)
23
25
  const data = await client.Sleep.getSleepWithStream(
24
26
  userId,
25
- new Date("2021-01-01"),
26
- new Date("2022-01-02"),
27
+ new Date("2021-09-10"),
28
+ new Date("2021-10-10"),
27
29
  )
28
30
  expect(data.sleep.length).toBeGreaterThan(0)
29
31
  expect(data.sleep[0].sleep_stream).toBeDefined()
@@ -1,11 +1,12 @@
1
1
  import { VitalClient } from "..";
2
- import { getUserId, randomString, testClient, testEuClient, test_user_id } from "./arrange";
2
+ import { getUserId, randomString, testApiKeyClient, testClient, testEuClient, test_user_id } from "./arrange";
3
3
 
4
4
  describe('User', () => {
5
5
  const user_id = randomString(10);
6
6
  it.each([
7
7
  ["us", testClient],
8
- ["eu", testEuClient]
8
+ ["eu", testEuClient],
9
+ ["us_api_key", testApiKeyClient],
9
10
  ])('should create a user %p', async (region: string, client: VitalClient) => {
10
11
  const user = await client.User.create(
11
12
  user_id,
@@ -15,7 +16,8 @@ describe('User', () => {
15
16
 
16
17
  it.each([
17
18
  testClient,
18
- testEuClient
19
+ testEuClient,
20
+ testApiKeyClient
19
21
  ])('should find a user', async (client: VitalClient) => {
20
22
  const user = await client.User.resolve(
21
23
  test_user_id,
@@ -25,7 +27,8 @@ describe('User', () => {
25
27
 
26
28
  it.each([
27
29
  testClient,
28
- testEuClient
30
+ testEuClient,
31
+ testApiKeyClient
29
32
  ])('should delete a user', async (client: VitalClient) => {
30
33
  const userToDelete = await getUserId(client, user_id);
31
34
  const user = await client.User.delete(
@@ -1,10 +1,11 @@
1
1
  import { VitalClient } from "..";
2
- import { testClient, testEuClient, getUserId } from "./arrange";
2
+ import { testClient, testEuClient, getUserId, testApiKeyClient } from "./arrange";
3
3
 
4
4
  describe('Vitals', () => {
5
5
  it.each([
6
6
  ["us", testClient],
7
- ["eu", testEuClient]
7
+ ["eu", testEuClient],
8
+ ["us_api_key", testApiKeyClient],
8
9
  ])('should return glucose data %p', async (region: string, client: VitalClient) => {
9
10
  const userId = await getUserId(client)
10
11
  const data = await client.Vitals.glucose(
@@ -1,10 +1,11 @@
1
1
  import { VitalClient } from "..";
2
- import { testClient, testEuClient, getUserId } from "./arrange";
2
+ import { testClient, testEuClient, getUserId, testApiKeyClient } from "./arrange";
3
3
 
4
4
  describe('Workouts', () => {
5
5
  it.each([
6
6
  ["us", testClient],
7
- ["eu", testEuClient]
7
+ ["eu", testEuClient],
8
+ ["us_api_key", testApiKeyClient],
8
9
  ])('should return workout data %p', async (region: string, client: VitalClient) => {
9
10
  const userId = await getUserId(client)
10
11
  const data = await client.Workouts.get(
@@ -1,7 +1,7 @@
1
1
  export interface PatientAdress {
2
2
  receiver_name: string;
3
- street_number: string;
4
- street: string;
3
+ first_line: string;
4
+ second_line?: string;
5
5
  city: string;
6
6
  state: string;
7
7
  zip: string;
@@ -1,7 +1,7 @@
1
1
  export interface PatientAdress {
2
2
  receiver_name: string;
3
- street_number: string;
4
- street: string;
3
+ first_line: string;
4
+ second_line?: string;
5
5
  city: string;
6
6
  state: string;
7
7
  zip: string;
package/dist/index.js CHANGED
@@ -59,7 +59,14 @@ var VitalClient = /** @class */ (function () {
59
59
  function VitalClient(config) {
60
60
  var _this = this;
61
61
  this.config = config;
62
- this.clientCredentials = new credentials_1.ClientCredentials(config);
62
+ if (!config.api_key) {
63
+ try {
64
+ this.clientCredentials = new credentials_1.ClientCredentials(config);
65
+ }
66
+ catch (error) {
67
+ throw new Error("You must provide either an API key or a client ID and secret");
68
+ }
69
+ }
63
70
  var baseURL;
64
71
  if (this.config.region && this.config.region === 'eu') {
65
72
  baseURL = config_1.default.baseEUUrls[config.environment];
@@ -73,13 +80,22 @@ var VitalClient = /** @class */ (function () {
73
80
  retryDelay: axios_retry_1.default.exponentialDelay,
74
81
  });
75
82
  axiosApiInstance.interceptors.request.use(function (config) { return __awaiter(_this, void 0, void 0, function () {
76
- var token;
83
+ var headers, token;
77
84
  return __generator(this, function (_a) {
78
85
  switch (_a.label) {
79
- case 0: return [4 /*yield*/, this.clientCredentials.access_token()];
80
- case 1:
86
+ case 0:
87
+ headers = config.headers;
88
+ if (!this.config.api_key) return [3 /*break*/, 1];
89
+ headers["x-vital-api-key"] = this.config.api_key;
90
+ return [3 /*break*/, 3];
91
+ case 1: return [4 /*yield*/, this.clientCredentials.access_token()];
92
+ case 2:
81
93
  token = _a.sent();
82
- config.headers = __assign(__assign({}, config.headers), { 'x-vital-client-id': this.config.client_id, Authorization: "Bearer " + token });
94
+ headers["Authorization"] = "Bearer " + token;
95
+ headers["x-vital-client-id"] = this.config.client_id;
96
+ _a.label = 3;
97
+ case 3:
98
+ config.headers = __assign({}, headers);
83
99
  return [2 /*return*/, config];
84
100
  }
85
101
  });
@@ -1,6 +1,7 @@
1
1
  export interface ClientConfig {
2
- client_id: string;
3
- client_secret: string;
2
+ client_id?: string;
3
+ client_secret?: string;
4
+ api_key?: string;
4
5
  environment: 'prod' | 'production' | 'sandbox' | 'development';
5
6
  region?: 'us' | 'eu';
6
7
  }
package/index.ts CHANGED
@@ -36,7 +36,13 @@ export class VitalClient {
36
36
 
37
37
  constructor(config: ClientConfig) {
38
38
  this.config = config;
39
- this.clientCredentials = new ClientCredentials(config);
39
+ if(!config.api_key){
40
+ try {
41
+ this.clientCredentials = new ClientCredentials(config);
42
+ } catch (error) {
43
+ throw new Error("You must provide either an API key or a client ID and secret");
44
+ }
45
+ }
40
46
  let baseURL;
41
47
  if (this.config.region && this.config.region === 'eu') {
42
48
  baseURL = CONFIG.baseEUUrls[config.environment];
@@ -52,11 +58,16 @@ export class VitalClient {
52
58
 
53
59
  axiosApiInstance.interceptors.request.use(
54
60
  async (config) => {
55
- const token = await this.clientCredentials.access_token();
61
+ const headers = config.headers;
62
+ if(this.config.api_key){
63
+ headers["x-vital-api-key"] = this.config.api_key;
64
+ } else {
65
+ const token = await this.clientCredentials.access_token();
66
+ headers["Authorization"] = `Bearer ${token}`;
67
+ headers["x-vital-client-id"] = this.config.client_id;
68
+ }
56
69
  config.headers = {
57
- ...config.headers,
58
- 'x-vital-client-id': this.config.client_id,
59
- Authorization: `Bearer ${token}`,
70
+ ...headers,
60
71
  };
61
72
  return config;
62
73
  },
package/lib/models.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export interface ClientConfig {
2
- client_id: string;
3
- client_secret: string;
2
+ client_id?: string;
3
+ client_secret?: string;
4
+ api_key?: string;
4
5
  environment: 'prod' | 'production' | 'sandbox' | 'development';
5
6
  region?: 'us' | 'eu';
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvital/vital-node",
3
- "version": "1.3.3",
3
+ "version": "1.3.6",
4
4
  "description": "Node client for Vital",
5
5
  "author": "maitham",
6
6
  "keywords": [
@@ -56,4 +56,4 @@
56
56
  "ts-node": "^10.2.0",
57
57
  "typescript": "^4.3.5"
58
58
  }
59
- }
59
+ }