@tryvital/vital-node 1.6.3 → 1.6.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/.github/workflows/test-build.yaml +18 -0
- package/client/LabTests.ts +120 -0
- package/client/Link.ts +1 -1
- package/client/Provider.ts +1 -1
- package/client/Testkits.ts +2 -2
- package/client/User.ts +1 -1
- package/client/index.ts +2 -1
- package/client/models/lab_tests_model.ts +129 -0
- package/client/models/testkit_models.ts +8 -2
- package/dist/client/LabTests.d.ts +26 -0
- package/dist/client/LabTests.js +172 -0
- package/dist/client/Link.js +1 -1
- package/dist/client/Provider.js +1 -1
- package/dist/client/Testkits.js +1 -1
- package/dist/client/User.js +1 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.js +5 -3
- package/dist/client/models/lab_tests_model.d.ts +102 -0
- package/dist/client/models/lab_tests_model.js +2 -0
- package/dist/client/models/testkit_models.d.ts +7 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +6 -25
- package/index.ts +5 -17
- package/package.json +2 -3
- package/dist/lib/credentials.d.ts +0 -8
- package/dist/lib/credentials.js +0 -87
- package/lib/credentials.ts +0 -36
@@ -0,0 +1,18 @@
|
|
1
|
+
on:
|
2
|
+
push:
|
3
|
+
branches-ignore:
|
4
|
+
- master
|
5
|
+
|
6
|
+
name: Test compile
|
7
|
+
jobs:
|
8
|
+
test-build:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
# Setup .npmrc file to publish to npm
|
13
|
+
- uses: actions/setup-node@v2
|
14
|
+
with:
|
15
|
+
node-version: '16.x'
|
16
|
+
registry-url: 'https://registry.npmjs.org'
|
17
|
+
- run: npm ci
|
18
|
+
- run: npm run build
|
@@ -0,0 +1,120 @@
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
2
|
+
import {
|
3
|
+
ClientFacingLabTest,
|
4
|
+
LabResultsMetadata,
|
5
|
+
LabResultsResponse,
|
6
|
+
Order,
|
7
|
+
OrderRequestResponse,
|
8
|
+
PatientAdress,
|
9
|
+
PatientDetails,
|
10
|
+
Physician,
|
11
|
+
} from './models/lab_tests_model';
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
export class OrdersApi {
|
16
|
+
baseURL: string;
|
17
|
+
client: AxiosInstance;
|
18
|
+
constructor(baseURL: string, axios: AxiosInstance) {
|
19
|
+
this.baseURL = baseURL;
|
20
|
+
this.client = axios;
|
21
|
+
}
|
22
|
+
|
23
|
+
// Create new order
|
24
|
+
public async create_order(
|
25
|
+
user_id: string,
|
26
|
+
patient_details: PatientDetails,
|
27
|
+
patient_address: PatientAdress,
|
28
|
+
lab_test_id: string,
|
29
|
+
physician?: Physician,
|
30
|
+
): Promise<OrderRequestResponse> {
|
31
|
+
const resp = await this.client.post(
|
32
|
+
this.baseURL.concat('/order'),
|
33
|
+
{
|
34
|
+
params: {
|
35
|
+
user_id: user_id,
|
36
|
+
patient_details: patient_details,
|
37
|
+
patient_address: patient_address,
|
38
|
+
lab_test_id: lab_test_id,
|
39
|
+
physician: physician ? physician : null
|
40
|
+
},
|
41
|
+
}
|
42
|
+
);
|
43
|
+
return resp.data;
|
44
|
+
}
|
45
|
+
|
46
|
+
// Get order status.
|
47
|
+
public async getOrder(orderId: string): Promise<Order> {
|
48
|
+
const resp = await this.client.get(
|
49
|
+
this.baseURL.concat(`/order/${orderId}`)
|
50
|
+
);
|
51
|
+
return resp.data;
|
52
|
+
}
|
53
|
+
|
54
|
+
// Cancels order.
|
55
|
+
public async cancelOrder(orderId: string): Promise<OrderRequestResponse> {
|
56
|
+
const resp = await this.client.post(
|
57
|
+
this.baseURL.concat(`/order/${orderId}/cancel`)
|
58
|
+
);
|
59
|
+
return resp.data;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
export class ResultsApi {
|
64
|
+
baseURL: string;
|
65
|
+
client: AxiosInstance;
|
66
|
+
constructor(baseURL: string, axios: AxiosInstance) {
|
67
|
+
this.baseURL = baseURL;
|
68
|
+
this.client = axios;
|
69
|
+
}
|
70
|
+
// GET both metadata and raw json test data.
|
71
|
+
public async getResults(orderId: string): Promise<LabResultsResponse> {
|
72
|
+
const resp = await this.client.get(
|
73
|
+
this.baseURL.concat(`/order/${orderId}/result`)
|
74
|
+
);
|
75
|
+
return resp.data;
|
76
|
+
}
|
77
|
+
|
78
|
+
// GET gets the lab result for the order in PDF format.
|
79
|
+
// TODO Check response type for PDF
|
80
|
+
public async getResultsPdf(orderId: string): Promise<string> {
|
81
|
+
const resp = await this.client.get(
|
82
|
+
this.baseURL.concat(`/order/${orderId}/result/pdf`)
|
83
|
+
);
|
84
|
+
return resp.data;
|
85
|
+
}
|
86
|
+
|
87
|
+
// GET metadata related to order results, such as
|
88
|
+
// lab metadata, provider and sample dates.
|
89
|
+
public async getResultsMetadata(orderId: string): Promise<LabResultsMetadata> {
|
90
|
+
const resp = await this.client.get(
|
91
|
+
this.baseURL.concat(`/order/${orderId}/result/metadata`)
|
92
|
+
);
|
93
|
+
return resp.data;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
export class LabTestsApi {
|
102
|
+
baseURL: string;
|
103
|
+
client: AxiosInstance;
|
104
|
+
Orders: OrdersApi;
|
105
|
+
Results: ResultsApi;
|
106
|
+
|
107
|
+
constructor(baseURL: string, axios: AxiosInstance) {
|
108
|
+
this.baseURL = baseURL;
|
109
|
+
this.client = axios;
|
110
|
+
this.Orders = new OrdersApi(baseURL, axios)
|
111
|
+
this.Results = new ResultsApi(baseURL, axios)
|
112
|
+
|
113
|
+
}
|
114
|
+
public async getTests(): Promise<ClientFacingLabTest> {
|
115
|
+
const resp = await this.client.get(
|
116
|
+
this.baseURL.concat(`/lab_tests`)
|
117
|
+
);
|
118
|
+
return resp.data;
|
119
|
+
}
|
120
|
+
}
|
package/client/Link.ts
CHANGED
package/client/Provider.ts
CHANGED
@@ -11,7 +11,7 @@ export class ProviderApi {
|
|
11
11
|
}
|
12
12
|
|
13
13
|
public async getSupportedProviders(): Promise<Provider[]> {
|
14
|
-
const resp = await this.client.get(this.baseURL.concat('/providers
|
14
|
+
const resp = await this.client.get(this.baseURL.concat('/providers'));
|
15
15
|
return resp.data;
|
16
16
|
}
|
17
17
|
}
|
package/client/Testkits.ts
CHANGED
@@ -33,7 +33,7 @@ export class TestkitsApi {
|
|
33
33
|
size?: number
|
34
34
|
): Promise<OrderResponse> {
|
35
35
|
const resp = await this.client.get(
|
36
|
-
this.baseURL.concat('/testkit/orders
|
36
|
+
this.baseURL.concat('/testkit/orders'),
|
37
37
|
{
|
38
38
|
params: {
|
39
39
|
start_date: startDate,
|
@@ -104,4 +104,4 @@ export class TestkitsApi {
|
|
104
104
|
);
|
105
105
|
return resp.data;
|
106
106
|
}
|
107
|
-
}
|
107
|
+
}
|
package/client/User.ts
CHANGED
@@ -35,7 +35,7 @@ export class UserApi {
|
|
35
35
|
limit = 100,
|
36
36
|
offset = 0,
|
37
37
|
}: GetTeamUsersParams = {}): Promise<GetTeamUsersResponse> {
|
38
|
-
const url = new URL(this.baseURL.concat('/user
|
38
|
+
const url = new URL(this.baseURL.concat('/user'));
|
39
39
|
|
40
40
|
url.searchParams.set('limit', String(limit));
|
41
41
|
url.searchParams.set('offset', String(offset));
|
package/client/index.ts
CHANGED
@@ -5,7 +5,8 @@ export { SleepApi } from './Sleep';
|
|
5
5
|
export { UserApi } from './User';
|
6
6
|
export { WebhooksApi } from './Webhooks';
|
7
7
|
export { WorkoutsApi } from './Workouts';
|
8
|
-
export {
|
8
|
+
export { LabTestsApi } from './LabTests';
|
9
9
|
export { ProfileApi } from './Profile';
|
10
10
|
export { DevicesAPI } from './Devices';
|
11
11
|
export { MealsApi } from './Meals';
|
12
|
+
export { TestkitsApi } from "./Testkits";
|
@@ -0,0 +1,129 @@
|
|
1
|
+
export interface PatientAdress {
|
2
|
+
receiver_name: string;
|
3
|
+
city: string;
|
4
|
+
state: string;
|
5
|
+
zip: string;
|
6
|
+
country: string;
|
7
|
+
street_number?: string;
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface PatientDetails {
|
11
|
+
dob: string;
|
12
|
+
gender: string;
|
13
|
+
email?: string;
|
14
|
+
first_name: string;
|
15
|
+
phone_number: string;
|
16
|
+
last_name: string;
|
17
|
+
}
|
18
|
+
|
19
|
+
export interface Physician {
|
20
|
+
first_name: string;
|
21
|
+
last_name: string;
|
22
|
+
npi: string;
|
23
|
+
email?: string;
|
24
|
+
licensed_states?: string[];
|
25
|
+
created_at?: string;
|
26
|
+
updated_at?: string;
|
27
|
+
}
|
28
|
+
|
29
|
+
export interface Marker {
|
30
|
+
name: string;
|
31
|
+
slug: string;
|
32
|
+
description?: string;
|
33
|
+
}
|
34
|
+
|
35
|
+
export interface Testkit {
|
36
|
+
id: string;
|
37
|
+
name: string;
|
38
|
+
description: string;
|
39
|
+
markers: Marker[];
|
40
|
+
turnaround_time_lower: number;
|
41
|
+
turnaround_time_upper: number;
|
42
|
+
price: number;
|
43
|
+
}
|
44
|
+
|
45
|
+
export interface TestkitEvent {
|
46
|
+
id: number;
|
47
|
+
created_at: string;
|
48
|
+
status: string;
|
49
|
+
}
|
50
|
+
|
51
|
+
export interface Order {
|
52
|
+
user_id: string;
|
53
|
+
id: string;
|
54
|
+
team_id: string;
|
55
|
+
patient_details: PatientDetails;
|
56
|
+
patient_address: PatientAdress;
|
57
|
+
lab_test: Testkit;
|
58
|
+
// TODO CHECK WHAT DETAILS IS
|
59
|
+
details: Object;
|
60
|
+
created_at: string;
|
61
|
+
updated_at: string;
|
62
|
+
events: TestkitEvent;
|
63
|
+
user_key?: string;
|
64
|
+
sample_id?: string;
|
65
|
+
notes?: string;
|
66
|
+
status?:
|
67
|
+
| 'ordered'
|
68
|
+
| 'transit_customer'
|
69
|
+
| 'out_for_delivery'
|
70
|
+
| 'with_customer'
|
71
|
+
| 'transit_lab'
|
72
|
+
| 'delivered_to_lab'
|
73
|
+
| 'processing_lab'
|
74
|
+
| 'completed'
|
75
|
+
| 'failure_to_deliver_to_customer'
|
76
|
+
| 'failure_to_deliver_to_lab'
|
77
|
+
| 'cancelled'
|
78
|
+
| 'do_not_process'
|
79
|
+
| 'unknown'
|
80
|
+
| 'rejected'
|
81
|
+
| 'lost';
|
82
|
+
}
|
83
|
+
|
84
|
+
export interface OrderRequestResponse {
|
85
|
+
order: Order;
|
86
|
+
status: string;
|
87
|
+
message: string;
|
88
|
+
}
|
89
|
+
|
90
|
+
export interface LabClientFacing {
|
91
|
+
slug: string;
|
92
|
+
name: string;
|
93
|
+
first_line_address: string;
|
94
|
+
city: string;
|
95
|
+
zipcode: string;
|
96
|
+
}
|
97
|
+
|
98
|
+
export interface ClientFacingLabTest {
|
99
|
+
id: string;
|
100
|
+
slug: string;
|
101
|
+
name: string;
|
102
|
+
sample_type: string;
|
103
|
+
method: string;
|
104
|
+
price: number;
|
105
|
+
is_active: boolean;
|
106
|
+
lab: LabClientFacing;
|
107
|
+
markers: Marker;
|
108
|
+
}
|
109
|
+
export interface TestkitResponse {
|
110
|
+
testkits: Testkit[];
|
111
|
+
}
|
112
|
+
|
113
|
+
export interface LabResultsMetadata {
|
114
|
+
age: string;
|
115
|
+
dob: string;
|
116
|
+
patient: string;
|
117
|
+
date_reported: string;
|
118
|
+
date_collected: string;
|
119
|
+
specimen_number: string;
|
120
|
+
clia?: string;
|
121
|
+
provider?: string;
|
122
|
+
laboratory?: string;
|
123
|
+
date_received?: string;
|
124
|
+
}
|
125
|
+
|
126
|
+
export interface LabResultsResponse {
|
127
|
+
metadata: LabResultsMetadata;
|
128
|
+
results: Object;
|
129
|
+
}
|
@@ -34,6 +34,12 @@ export interface Order {
|
|
34
34
|
team_id: string;
|
35
35
|
created_on: Date;
|
36
36
|
updated_on: Date;
|
37
|
+
patient_details: PatientDetails;
|
38
|
+
patient_address: PatientAdress;
|
39
|
+
created_at: string;
|
40
|
+
updated_at: string;
|
41
|
+
sample_id?: string;
|
42
|
+
notes?: string;
|
37
43
|
status:
|
38
44
|
| 'ordered'
|
39
45
|
| 'transit_customer'
|
@@ -92,5 +98,5 @@ export interface LabResultsMetadata {
|
|
92
98
|
|
93
99
|
export interface LabResultsRaw {
|
94
100
|
metadata: LabResultsMetadata;
|
95
|
-
|
96
|
-
}
|
101
|
+
results: Record<string, string>;
|
102
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
2
|
+
import { ClientFacingLabTest, LabResultsMetadata, LabResultsResponse, Order, OrderRequestResponse, PatientAdress, PatientDetails, Physician } from './models/lab_tests_model';
|
3
|
+
export declare class OrdersApi {
|
4
|
+
baseURL: string;
|
5
|
+
client: AxiosInstance;
|
6
|
+
constructor(baseURL: string, axios: AxiosInstance);
|
7
|
+
create_order(user_id: string, patient_details: PatientDetails, patient_address: PatientAdress, lab_test_id: string, physician?: Physician): Promise<OrderRequestResponse>;
|
8
|
+
getOrder(orderId: string): Promise<Order>;
|
9
|
+
cancelOrder(orderId: string): Promise<OrderRequestResponse>;
|
10
|
+
}
|
11
|
+
export declare class ResultsApi {
|
12
|
+
baseURL: string;
|
13
|
+
client: AxiosInstance;
|
14
|
+
constructor(baseURL: string, axios: AxiosInstance);
|
15
|
+
getResults(orderId: string): Promise<LabResultsResponse>;
|
16
|
+
getResultsPdf(orderId: string): Promise<string>;
|
17
|
+
getResultsMetadata(orderId: string): Promise<LabResultsMetadata>;
|
18
|
+
}
|
19
|
+
export declare class LabTestsApi {
|
20
|
+
baseURL: string;
|
21
|
+
client: AxiosInstance;
|
22
|
+
Orders: OrdersApi;
|
23
|
+
Results: ResultsApi;
|
24
|
+
constructor(baseURL: string, axios: AxiosInstance);
|
25
|
+
getTests(): Promise<ClientFacingLabTest>;
|
26
|
+
}
|
@@ -0,0 +1,172 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (_) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
+
exports.LabTestsApi = exports.ResultsApi = exports.OrdersApi = void 0;
|
40
|
+
var OrdersApi = /** @class */ (function () {
|
41
|
+
function OrdersApi(baseURL, axios) {
|
42
|
+
this.baseURL = baseURL;
|
43
|
+
this.client = axios;
|
44
|
+
}
|
45
|
+
// Create new order
|
46
|
+
OrdersApi.prototype.create_order = function (user_id, patient_details, patient_address, lab_test_id, physician) {
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
48
|
+
var resp;
|
49
|
+
return __generator(this, function (_a) {
|
50
|
+
switch (_a.label) {
|
51
|
+
case 0: return [4 /*yield*/, this.client.post(this.baseURL.concat('/order'), {
|
52
|
+
params: {
|
53
|
+
user_id: user_id,
|
54
|
+
patient_details: patient_details,
|
55
|
+
patient_address: patient_address,
|
56
|
+
lab_test_id: lab_test_id,
|
57
|
+
physician: physician ? physician : null
|
58
|
+
},
|
59
|
+
})];
|
60
|
+
case 1:
|
61
|
+
resp = _a.sent();
|
62
|
+
return [2 /*return*/, resp.data];
|
63
|
+
}
|
64
|
+
});
|
65
|
+
});
|
66
|
+
};
|
67
|
+
// Get order status.
|
68
|
+
OrdersApi.prototype.getOrder = function (orderId) {
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
70
|
+
var resp;
|
71
|
+
return __generator(this, function (_a) {
|
72
|
+
switch (_a.label) {
|
73
|
+
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat("/order/" + orderId))];
|
74
|
+
case 1:
|
75
|
+
resp = _a.sent();
|
76
|
+
return [2 /*return*/, resp.data];
|
77
|
+
}
|
78
|
+
});
|
79
|
+
});
|
80
|
+
};
|
81
|
+
// Cancels order.
|
82
|
+
OrdersApi.prototype.cancelOrder = function (orderId) {
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
84
|
+
var resp;
|
85
|
+
return __generator(this, function (_a) {
|
86
|
+
switch (_a.label) {
|
87
|
+
case 0: return [4 /*yield*/, this.client.post(this.baseURL.concat("/order/" + orderId + "/cancel"))];
|
88
|
+
case 1:
|
89
|
+
resp = _a.sent();
|
90
|
+
return [2 /*return*/, resp.data];
|
91
|
+
}
|
92
|
+
});
|
93
|
+
});
|
94
|
+
};
|
95
|
+
return OrdersApi;
|
96
|
+
}());
|
97
|
+
exports.OrdersApi = OrdersApi;
|
98
|
+
var ResultsApi = /** @class */ (function () {
|
99
|
+
function ResultsApi(baseURL, axios) {
|
100
|
+
this.baseURL = baseURL;
|
101
|
+
this.client = axios;
|
102
|
+
}
|
103
|
+
// GET both metadata and raw json test data.
|
104
|
+
ResultsApi.prototype.getResults = 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.get(this.baseURL.concat("/order/" + orderId + "/result"))];
|
110
|
+
case 1:
|
111
|
+
resp = _a.sent();
|
112
|
+
return [2 /*return*/, resp.data];
|
113
|
+
}
|
114
|
+
});
|
115
|
+
});
|
116
|
+
};
|
117
|
+
// GET gets the lab result for the order in PDF format.
|
118
|
+
// TODO Check response type for PDF
|
119
|
+
ResultsApi.prototype.getResultsPdf = function (orderId) {
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
121
|
+
var resp;
|
122
|
+
return __generator(this, function (_a) {
|
123
|
+
switch (_a.label) {
|
124
|
+
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat("/order/" + orderId + "/result/pdf"))];
|
125
|
+
case 1:
|
126
|
+
resp = _a.sent();
|
127
|
+
return [2 /*return*/, resp.data];
|
128
|
+
}
|
129
|
+
});
|
130
|
+
});
|
131
|
+
};
|
132
|
+
// GET metadata related to order results, such as
|
133
|
+
// lab metadata, provider and sample dates.
|
134
|
+
ResultsApi.prototype.getResultsMetadata = function (orderId) {
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
136
|
+
var resp;
|
137
|
+
return __generator(this, function (_a) {
|
138
|
+
switch (_a.label) {
|
139
|
+
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat("/order/" + orderId + "/result/metadata"))];
|
140
|
+
case 1:
|
141
|
+
resp = _a.sent();
|
142
|
+
return [2 /*return*/, resp.data];
|
143
|
+
}
|
144
|
+
});
|
145
|
+
});
|
146
|
+
};
|
147
|
+
return ResultsApi;
|
148
|
+
}());
|
149
|
+
exports.ResultsApi = ResultsApi;
|
150
|
+
var LabTestsApi = /** @class */ (function () {
|
151
|
+
function LabTestsApi(baseURL, axios) {
|
152
|
+
this.baseURL = baseURL;
|
153
|
+
this.client = axios;
|
154
|
+
this.Orders = new OrdersApi(baseURL, axios);
|
155
|
+
this.Results = new ResultsApi(baseURL, axios);
|
156
|
+
}
|
157
|
+
LabTestsApi.prototype.getTests = function () {
|
158
|
+
return __awaiter(this, void 0, void 0, function () {
|
159
|
+
var resp;
|
160
|
+
return __generator(this, function (_a) {
|
161
|
+
switch (_a.label) {
|
162
|
+
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat("/lab_tests"))];
|
163
|
+
case 1:
|
164
|
+
resp = _a.sent();
|
165
|
+
return [2 /*return*/, resp.data];
|
166
|
+
}
|
167
|
+
});
|
168
|
+
});
|
169
|
+
};
|
170
|
+
return LabTestsApi;
|
171
|
+
}());
|
172
|
+
exports.LabTestsApi = LabTestsApi;
|
package/dist/client/Link.js
CHANGED
@@ -60,7 +60,7 @@ var LinkApi = /** @class */ (function () {
|
|
60
60
|
// @ts-ignore
|
61
61
|
default_params['filter_on_providers'] = filter_on_providers;
|
62
62
|
}
|
63
|
-
return [4 /*yield*/, this.client.post(this.baseURL.concat('/link/token
|
63
|
+
return [4 /*yield*/, this.client.post(this.baseURL.concat('/link/token'), default_params)];
|
64
64
|
case 1:
|
65
65
|
resp = _a.sent();
|
66
66
|
return [2 /*return*/, resp.data];
|
package/dist/client/Provider.js
CHANGED
@@ -47,7 +47,7 @@ var ProviderApi = /** @class */ (function () {
|
|
47
47
|
var resp;
|
48
48
|
return __generator(this, function (_a) {
|
49
49
|
switch (_a.label) {
|
50
|
-
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat('/providers
|
50
|
+
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat('/providers'))];
|
51
51
|
case 1:
|
52
52
|
resp = _a.sent();
|
53
53
|
return [2 /*return*/, resp.data];
|
package/dist/client/Testkits.js
CHANGED
@@ -71,7 +71,7 @@ var TestkitsApi = /** @class */ (function () {
|
|
71
71
|
var resp;
|
72
72
|
return __generator(this, function (_a) {
|
73
73
|
switch (_a.label) {
|
74
|
-
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat('/testkit/orders
|
74
|
+
case 0: return [4 /*yield*/, this.client.get(this.baseURL.concat('/testkit/orders'), {
|
75
75
|
params: __assign(__assign({ start_date: startDate, end_date: endDate, status: status ? status : null, user_id: userId ? userId : null, patient_name: patientName ? patientName : null }, (page && { page: page })), (size && { size: size })),
|
76
76
|
})];
|
77
77
|
case 1:
|
package/dist/client/User.js
CHANGED
@@ -77,7 +77,7 @@ var UserApi = /** @class */ (function () {
|
|
77
77
|
return __generator(this, function (_e) {
|
78
78
|
switch (_e.label) {
|
79
79
|
case 0:
|
80
|
-
url = new URL(this.baseURL.concat('/user
|
80
|
+
url = new URL(this.baseURL.concat('/user'));
|
81
81
|
url.searchParams.set('limit', String(limit));
|
82
82
|
url.searchParams.set('offset', String(offset));
|
83
83
|
return [4 /*yield*/, this.client.get(url.toString())];
|
package/dist/client/index.d.ts
CHANGED
@@ -5,7 +5,8 @@ export { SleepApi } from './Sleep';
|
|
5
5
|
export { UserApi } from './User';
|
6
6
|
export { WebhooksApi } from './Webhooks';
|
7
7
|
export { WorkoutsApi } from './Workouts';
|
8
|
-
export {
|
8
|
+
export { LabTestsApi } from './LabTests';
|
9
9
|
export { ProfileApi } from './Profile';
|
10
10
|
export { DevicesAPI } from './Devices';
|
11
11
|
export { MealsApi } from './Meals';
|
12
|
+
export { TestkitsApi } from "./Testkits";
|
package/dist/client/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.MealsApi = exports.DevicesAPI = exports.ProfileApi = exports.
|
3
|
+
exports.TestkitsApi = exports.MealsApi = exports.DevicesAPI = exports.ProfileApi = exports.LabTestsApi = exports.WorkoutsApi = exports.WebhooksApi = exports.UserApi = exports.SleepApi = exports.LinkApi = exports.BodyApi = exports.ActivityApi = void 0;
|
4
4
|
var Activity_1 = require("./Activity");
|
5
5
|
Object.defineProperty(exports, "ActivityApi", { enumerable: true, get: function () { return Activity_1.ActivityApi; } });
|
6
6
|
var Body_1 = require("./Body");
|
@@ -15,11 +15,13 @@ var Webhooks_1 = require("./Webhooks");
|
|
15
15
|
Object.defineProperty(exports, "WebhooksApi", { enumerable: true, get: function () { return Webhooks_1.WebhooksApi; } });
|
16
16
|
var Workouts_1 = require("./Workouts");
|
17
17
|
Object.defineProperty(exports, "WorkoutsApi", { enumerable: true, get: function () { return Workouts_1.WorkoutsApi; } });
|
18
|
-
var
|
19
|
-
Object.defineProperty(exports, "
|
18
|
+
var LabTests_1 = require("./LabTests");
|
19
|
+
Object.defineProperty(exports, "LabTestsApi", { enumerable: true, get: function () { return LabTests_1.LabTestsApi; } });
|
20
20
|
var Profile_1 = require("./Profile");
|
21
21
|
Object.defineProperty(exports, "ProfileApi", { enumerable: true, get: function () { return Profile_1.ProfileApi; } });
|
22
22
|
var Devices_1 = require("./Devices");
|
23
23
|
Object.defineProperty(exports, "DevicesAPI", { enumerable: true, get: function () { return Devices_1.DevicesAPI; } });
|
24
24
|
var Meals_1 = require("./Meals");
|
25
25
|
Object.defineProperty(exports, "MealsApi", { enumerable: true, get: function () { return Meals_1.MealsApi; } });
|
26
|
+
var Testkits_1 = require("./Testkits");
|
27
|
+
Object.defineProperty(exports, "TestkitsApi", { enumerable: true, get: function () { return Testkits_1.TestkitsApi; } });
|
@@ -0,0 +1,102 @@
|
|
1
|
+
export interface PatientAdress {
|
2
|
+
receiver_name: string;
|
3
|
+
city: string;
|
4
|
+
state: string;
|
5
|
+
zip: string;
|
6
|
+
country: string;
|
7
|
+
street_number?: string;
|
8
|
+
}
|
9
|
+
export interface PatientDetails {
|
10
|
+
dob: string;
|
11
|
+
gender: string;
|
12
|
+
email?: string;
|
13
|
+
first_name: string;
|
14
|
+
phone_number: string;
|
15
|
+
last_name: string;
|
16
|
+
}
|
17
|
+
export interface Physician {
|
18
|
+
first_name: string;
|
19
|
+
last_name: string;
|
20
|
+
npi: string;
|
21
|
+
email?: string;
|
22
|
+
licensed_states?: string[];
|
23
|
+
created_at?: string;
|
24
|
+
updated_at?: string;
|
25
|
+
}
|
26
|
+
export interface Marker {
|
27
|
+
name: string;
|
28
|
+
slug: string;
|
29
|
+
description?: string;
|
30
|
+
}
|
31
|
+
export interface Testkit {
|
32
|
+
id: string;
|
33
|
+
name: string;
|
34
|
+
description: string;
|
35
|
+
markers: Marker[];
|
36
|
+
turnaround_time_lower: number;
|
37
|
+
turnaround_time_upper: number;
|
38
|
+
price: number;
|
39
|
+
}
|
40
|
+
export interface TestkitEvent {
|
41
|
+
id: number;
|
42
|
+
created_at: string;
|
43
|
+
status: string;
|
44
|
+
}
|
45
|
+
export interface Order {
|
46
|
+
user_id: string;
|
47
|
+
id: string;
|
48
|
+
team_id: string;
|
49
|
+
patient_details: PatientDetails;
|
50
|
+
patient_address: PatientAdress;
|
51
|
+
lab_test: Testkit;
|
52
|
+
details: Object;
|
53
|
+
created_at: string;
|
54
|
+
updated_at: string;
|
55
|
+
events: TestkitEvent;
|
56
|
+
user_key?: string;
|
57
|
+
sample_id?: string;
|
58
|
+
notes?: string;
|
59
|
+
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' | 'rejected' | 'lost';
|
60
|
+
}
|
61
|
+
export interface OrderRequestResponse {
|
62
|
+
order: Order;
|
63
|
+
status: string;
|
64
|
+
message: string;
|
65
|
+
}
|
66
|
+
export interface LabClientFacing {
|
67
|
+
slug: string;
|
68
|
+
name: string;
|
69
|
+
first_line_address: string;
|
70
|
+
city: string;
|
71
|
+
zipcode: string;
|
72
|
+
}
|
73
|
+
export interface ClientFacingLabTest {
|
74
|
+
id: string;
|
75
|
+
slug: string;
|
76
|
+
name: string;
|
77
|
+
sample_type: string;
|
78
|
+
method: string;
|
79
|
+
price: number;
|
80
|
+
is_active: boolean;
|
81
|
+
lab: LabClientFacing;
|
82
|
+
markers: Marker;
|
83
|
+
}
|
84
|
+
export interface TestkitResponse {
|
85
|
+
testkits: Testkit[];
|
86
|
+
}
|
87
|
+
export interface LabResultsMetadata {
|
88
|
+
age: string;
|
89
|
+
dob: string;
|
90
|
+
patient: string;
|
91
|
+
date_reported: string;
|
92
|
+
date_collected: string;
|
93
|
+
specimen_number: string;
|
94
|
+
clia?: string;
|
95
|
+
provider?: string;
|
96
|
+
laboratory?: string;
|
97
|
+
date_received?: string;
|
98
|
+
}
|
99
|
+
export interface LabResultsResponse {
|
100
|
+
metadata: LabResultsMetadata;
|
101
|
+
results: Object;
|
102
|
+
}
|
@@ -31,6 +31,12 @@ export interface Order {
|
|
31
31
|
team_id: string;
|
32
32
|
created_on: Date;
|
33
33
|
updated_on: Date;
|
34
|
+
patient_details: PatientDetails;
|
35
|
+
patient_address: PatientAdress;
|
36
|
+
created_at: string;
|
37
|
+
updated_at: string;
|
38
|
+
sample_id?: string;
|
39
|
+
notes?: string;
|
34
40
|
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' | "rejected" | "lost";
|
35
41
|
user_key: string;
|
36
42
|
testkit_id: string;
|
@@ -69,5 +75,5 @@ export interface LabResultsMetadata {
|
|
69
75
|
}
|
70
76
|
export interface LabResultsRaw {
|
71
77
|
metadata: LabResultsMetadata;
|
72
|
-
|
78
|
+
results: Record<string, string>;
|
73
79
|
}
|
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
import { ActivityApi, BodyApi, LinkApi, SleepApi,
|
1
|
+
import { ActivityApi, BodyApi, LinkApi, SleepApi, UserApi, WebhooksApi, WorkoutsApi, ProfileApi, DevicesAPI, MealsApi, TestkitsApi } from './client';
|
2
2
|
import { ClientConfig } from './lib/models';
|
3
|
-
import { ClientCredentials } from './lib/credentials';
|
4
3
|
import { VitalsApi } from './client/Vitals';
|
5
4
|
import { ProviderApi } from './client/Provider';
|
6
5
|
export declare class VitalClient {
|
7
6
|
config: ClientConfig;
|
8
|
-
clientCredentials: ClientCredentials;
|
9
7
|
Activity: ActivityApi;
|
10
8
|
Link: LinkApi;
|
11
9
|
Body: BodyApi;
|
package/dist/index.js
CHANGED
@@ -52,21 +52,14 @@ var axios_1 = require("axios");
|
|
52
52
|
var axios_retry_1 = require("axios-retry");
|
53
53
|
var client_1 = require("./client");
|
54
54
|
var config_1 = require("./lib/config");
|
55
|
-
var credentials_1 = require("./lib/credentials");
|
56
55
|
var Vitals_1 = require("./client/Vitals");
|
57
56
|
var Provider_1 = require("./client/Provider");
|
58
|
-
;
|
59
57
|
var VitalClient = /** @class */ (function () {
|
60
58
|
function VitalClient(config) {
|
61
59
|
var _this = this;
|
62
60
|
this.config = config;
|
63
61
|
if (!config.api_key) {
|
64
|
-
|
65
|
-
this.clientCredentials = new credentials_1.ClientCredentials(config);
|
66
|
-
}
|
67
|
-
catch (error) {
|
68
|
-
throw new Error("You must provide either an API key or a client ID and secret");
|
69
|
-
}
|
62
|
+
throw new Error("You must provide an API key");
|
70
63
|
}
|
71
64
|
var baseURL;
|
72
65
|
if (this.config.region && this.config.region === 'eu') {
|
@@ -81,24 +74,12 @@ var VitalClient = /** @class */ (function () {
|
|
81
74
|
retryDelay: axios_retry_1.default.exponentialDelay,
|
82
75
|
});
|
83
76
|
axiosApiInstance.interceptors.request.use(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
84
|
-
var headers
|
77
|
+
var headers;
|
85
78
|
return __generator(this, function (_a) {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
headers["x-vital-api-key"] = this.config.api_key;
|
91
|
-
return [3 /*break*/, 3];
|
92
|
-
case 1: return [4 /*yield*/, this.clientCredentials.access_token()];
|
93
|
-
case 2:
|
94
|
-
token = _a.sent();
|
95
|
-
headers["Authorization"] = "Bearer " + token;
|
96
|
-
headers["x-vital-client-id"] = this.config.client_id;
|
97
|
-
_a.label = 3;
|
98
|
-
case 3:
|
99
|
-
config.headers = __assign({}, headers);
|
100
|
-
return [2 /*return*/, config];
|
101
|
-
}
|
79
|
+
headers = config.headers;
|
80
|
+
headers["x-vital-api-key"] = this.config.api_key;
|
81
|
+
config.headers = __assign({}, headers);
|
82
|
+
return [2 /*return*/, config];
|
102
83
|
});
|
103
84
|
}); }, function (error) {
|
104
85
|
Promise.reject(error);
|
package/index.ts
CHANGED
@@ -5,23 +5,21 @@ import {
|
|
5
5
|
BodyApi,
|
6
6
|
LinkApi,
|
7
7
|
SleepApi,
|
8
|
-
TestkitsApi,
|
9
8
|
UserApi,
|
10
9
|
WebhooksApi,
|
11
10
|
WorkoutsApi,
|
12
11
|
ProfileApi,
|
13
12
|
DevicesAPI,
|
14
|
-
MealsApi
|
13
|
+
MealsApi,
|
14
|
+
TestkitsApi
|
15
15
|
} from './client';
|
16
16
|
import { ClientConfig } from './lib/models';
|
17
17
|
import CONFIG from './lib/config';
|
18
|
-
import { ClientCredentials } from './lib/credentials';
|
19
18
|
import { VitalsApi } from './client/Vitals';
|
20
|
-
import { ProviderApi } from './client/Provider'
|
19
|
+
import { ProviderApi } from './client/Provider';
|
21
20
|
|
22
21
|
export class VitalClient {
|
23
22
|
config: ClientConfig;
|
24
|
-
clientCredentials: ClientCredentials;
|
25
23
|
Activity: ActivityApi;
|
26
24
|
Link: LinkApi;
|
27
25
|
Body: BodyApi;
|
@@ -39,11 +37,7 @@ export class VitalClient {
|
|
39
37
|
constructor(config: ClientConfig) {
|
40
38
|
this.config = config;
|
41
39
|
if(!config.api_key){
|
42
|
-
|
43
|
-
this.clientCredentials = new ClientCredentials(config);
|
44
|
-
} catch (error) {
|
45
|
-
throw new Error("You must provide either an API key or a client ID and secret");
|
46
|
-
}
|
40
|
+
throw new Error("You must provide an API key");
|
47
41
|
}
|
48
42
|
let baseURL;
|
49
43
|
if (this.config.region && this.config.region === 'eu') {
|
@@ -61,13 +55,7 @@ export class VitalClient {
|
|
61
55
|
axiosApiInstance.interceptors.request.use(
|
62
56
|
async (config) => {
|
63
57
|
const headers = config.headers;
|
64
|
-
|
65
|
-
headers["x-vital-api-key"] = this.config.api_key;
|
66
|
-
} else {
|
67
|
-
const token = await this.clientCredentials.access_token();
|
68
|
-
headers["Authorization"] = `Bearer ${token}`;
|
69
|
-
headers["x-vital-client-id"] = this.config.client_id;
|
70
|
-
}
|
58
|
+
headers["x-vital-api-key"] = this.config.api_key;
|
71
59
|
config.headers = {
|
72
60
|
...headers,
|
73
61
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tryvital/vital-node",
|
3
|
-
"version": "1.6.
|
3
|
+
"version": "1.6.5",
|
4
4
|
"description": "Node client for Vital",
|
5
5
|
"author": "maitham",
|
6
6
|
"keywords": [
|
@@ -22,7 +22,6 @@
|
|
22
22
|
"lint": "eslint --ext .js,.jsx,.ts ."
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"auth0": "^2.35.1",
|
26
25
|
"axios": ">=0.21.2 <1.0.0",
|
27
26
|
"axios-retry": "^3.2.4",
|
28
27
|
"crypto": "^1.0.1",
|
@@ -56,4 +55,4 @@
|
|
56
55
|
"ts-node": "^10.2.0",
|
57
56
|
"typescript": "^4.3.5"
|
58
57
|
}
|
59
|
-
}
|
58
|
+
}
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { AccessToken, ClientConfig } from './models';
|
2
|
-
export declare class ClientCredentials {
|
3
|
-
config: ClientConfig;
|
4
|
-
private accessToken;
|
5
|
-
constructor(config: ClientConfig);
|
6
|
-
getAccessToken: () => Promise<AccessToken>;
|
7
|
-
access_token: () => Promise<string>;
|
8
|
-
}
|
package/dist/lib/credentials.js
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
-
function step(op) {
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
17
|
-
while (_) try {
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
-
switch (op[0]) {
|
21
|
-
case 0: case 1: t = op; break;
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
-
default:
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
-
if (t[2]) _.ops.pop();
|
31
|
-
_.trys.pop(); continue;
|
32
|
-
}
|
33
|
-
op = body.call(thisArg, _);
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
-
}
|
37
|
-
};
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.ClientCredentials = void 0;
|
40
|
-
var config_1 = require("./config");
|
41
|
-
var AuthenticationClient = require('auth0').AuthenticationClient; // eslint-disable-line
|
42
|
-
var ClientCredentials = /** @class */ (function () {
|
43
|
-
function ClientCredentials(config) {
|
44
|
-
var _this = this;
|
45
|
-
this.getAccessToken = function () { return __awaiter(_this, void 0, void 0, function () {
|
46
|
-
var auth0, resp;
|
47
|
-
return __generator(this, function (_a) {
|
48
|
-
switch (_a.label) {
|
49
|
-
case 0:
|
50
|
-
auth0 = new AuthenticationClient({
|
51
|
-
domain: config_1.default.domains[this.config.environment],
|
52
|
-
clientId: this.config.client_id,
|
53
|
-
clientSecret: this.config.client_secret,
|
54
|
-
});
|
55
|
-
return [4 /*yield*/, auth0.clientCredentialsGrant({
|
56
|
-
audience: config_1.default.audiences[this.config.environment],
|
57
|
-
})];
|
58
|
-
case 1:
|
59
|
-
resp = _a.sent();
|
60
|
-
return [2 /*return*/, {
|
61
|
-
token: resp.access_token,
|
62
|
-
exp: +new Date() + resp.expires_in - 20,
|
63
|
-
}];
|
64
|
-
}
|
65
|
-
});
|
66
|
-
}); };
|
67
|
-
this.access_token = function () { return __awaiter(_this, void 0, void 0, function () {
|
68
|
-
var currentTime, _a;
|
69
|
-
return __generator(this, function (_b) {
|
70
|
-
switch (_b.label) {
|
71
|
-
case 0:
|
72
|
-
currentTime = +new Date();
|
73
|
-
if (!(!this.accessToken || currentTime >= this.accessToken.exp)) return [3 /*break*/, 2];
|
74
|
-
_a = this;
|
75
|
-
return [4 /*yield*/, this.getAccessToken()];
|
76
|
-
case 1:
|
77
|
-
_a.accessToken = _b.sent();
|
78
|
-
return [2 /*return*/, this.accessToken.token];
|
79
|
-
case 2: return [2 /*return*/, this.accessToken.token];
|
80
|
-
}
|
81
|
-
});
|
82
|
-
}); };
|
83
|
-
this.config = config;
|
84
|
-
}
|
85
|
-
return ClientCredentials;
|
86
|
-
}());
|
87
|
-
exports.ClientCredentials = ClientCredentials;
|
package/lib/credentials.ts
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
import { AccessToken, ClientConfig } from './models';
|
2
|
-
import CONFIG from './config';
|
3
|
-
|
4
|
-
const AuthenticationClient = require('auth0').AuthenticationClient; // eslint-disable-line
|
5
|
-
|
6
|
-
export class ClientCredentials {
|
7
|
-
config: ClientConfig;
|
8
|
-
private accessToken: AccessToken;
|
9
|
-
constructor(config: ClientConfig) {
|
10
|
-
this.config = config;
|
11
|
-
}
|
12
|
-
|
13
|
-
public getAccessToken = async (): Promise<AccessToken> => {
|
14
|
-
const auth0 = new AuthenticationClient({
|
15
|
-
domain: CONFIG.domains[this.config.environment],
|
16
|
-
clientId: this.config.client_id,
|
17
|
-
clientSecret: this.config.client_secret,
|
18
|
-
});
|
19
|
-
const resp = await auth0.clientCredentialsGrant({
|
20
|
-
audience: CONFIG.audiences[this.config.environment],
|
21
|
-
});
|
22
|
-
return {
|
23
|
-
token: resp.access_token,
|
24
|
-
exp: +new Date() + resp.expires_in - 20,
|
25
|
-
};
|
26
|
-
};
|
27
|
-
|
28
|
-
access_token: () => Promise<string> = async () => {
|
29
|
-
const currentTime = +new Date();
|
30
|
-
if (!this.accessToken || currentTime >= this.accessToken.exp) {
|
31
|
-
this.accessToken = await this.getAccessToken();
|
32
|
-
return this.accessToken.token;
|
33
|
-
}
|
34
|
-
return this.accessToken.token;
|
35
|
-
};
|
36
|
-
}
|