@onfido/api 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -2
- package/README.md +2 -2
- package/dist/Onfido.d.ts +36 -0
- package/dist/OnfidoDownload.d.ts +9 -0
- package/dist/Resource.d.ts +22 -0
- package/dist/WebhookEventVerifier.d.ts +16 -0
- package/dist/errors/OnfidoApiError.d.ts +10 -0
- package/dist/errors/OnfidoError.d.ts +3 -0
- package/dist/formatting.d.ts +16 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.es.js +482 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.js +492 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/Addresses.d.ts +27 -0
- package/dist/resources/Applicants.d.ts +37 -0
- package/dist/resources/Autofill.d.ts +37 -0
- package/dist/resources/Checks.d.ts +41 -0
- package/dist/resources/Documents.d.ts +32 -0
- package/dist/resources/IdNumbers.d.ts +10 -0
- package/dist/resources/LivePhotos.d.ts +25 -0
- package/dist/resources/LiveVideos.d.ts +19 -0
- package/dist/resources/Reports.d.ts +24 -0
- package/dist/resources/SdkTokens.d.ts +12 -0
- package/dist/resources/Webhooks.d.ts +25 -0
- package/dist/types/formData.d.ts +27 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.1.1, 6 Jan 2022
|
|
4
|
+
|
|
5
|
+
- Add `validate_image_quality` to document upload request
|
|
6
|
+
|
|
7
|
+
## v2.1.0, 24 June 2021
|
|
8
|
+
|
|
9
|
+
- Updated to use API v3.2
|
|
10
|
+
|
|
11
|
+
## v2.0.2, 25 May 2021
|
|
12
|
+
|
|
13
|
+
- Add `environments` to Webhook object
|
|
14
|
+
|
|
3
15
|
## v2.0.1, 17 May 2021
|
|
4
16
|
|
|
5
|
-
- Add `sub_result` to trigger sandbox pre-determined
|
|
6
|
-
- Add `consider` array functionality for sandbox pre-determined
|
|
17
|
+
- Add `sub_result` to trigger sandbox pre-determined responses for Document report sub-results
|
|
18
|
+
- Add `consider` array functionality for sandbox pre-determined responses
|
|
7
19
|
|
|
8
20
|
## v2.0.0, 9 April 2021
|
|
9
21
|
|
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ The official Node.js library for integrating with the Onfido API.
|
|
|
4
4
|
|
|
5
5
|
Documentation can be found at <https://documentation.onfido.com>
|
|
6
6
|
|
|
7
|
-
This library is only for use on the backend, as it uses Onfido API tokens which must be kept secret. If you do need to collect applicant data in the frontend of your application, we recommend that you use
|
|
7
|
+
This library is only for use on the backend, as it uses Onfido API tokens which must be kept secret. If you do need to collect applicant data in the frontend of your application, we recommend that you use the Onfido SDKs: [iOS](https://github.com/onfido/onfido-ios-sdk), [Android](https://github.com/onfido/onfido-android-sdk), [Web](https://github.com/onfido/onfido-sdk-ui), and [React Native](https://github.com/onfido/react-native-sdk).
|
|
8
8
|
|
|
9
|
-
This version uses Onfido API v3.
|
|
9
|
+
This version uses Onfido API v3.2. Refer to our [API versioning guide](https://developers.onfido.com/guide/api-versioning-policy#client-libraries) for details of which client library versions use which versions of the API.
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
package/dist/Onfido.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { Addresses } from "./resources/Addresses";
|
|
3
|
+
import { Applicants } from "./resources/Applicants";
|
|
4
|
+
import { Autofill } from "./resources/Autofill";
|
|
5
|
+
import { Checks } from "./resources/Checks";
|
|
6
|
+
import { Documents } from "./resources/Documents";
|
|
7
|
+
import { LivePhotos } from "./resources/LivePhotos";
|
|
8
|
+
import { LiveVideos } from "./resources/LiveVideos";
|
|
9
|
+
import { Reports } from "./resources/Reports";
|
|
10
|
+
import { SdkTokens } from "./resources/SdkTokens";
|
|
11
|
+
import { Webhooks } from "./resources/Webhooks";
|
|
12
|
+
export declare enum Region {
|
|
13
|
+
EU = "EU",
|
|
14
|
+
US = "US",
|
|
15
|
+
CA = "CA"
|
|
16
|
+
}
|
|
17
|
+
export declare type OnfidoOptions = {
|
|
18
|
+
apiToken: string;
|
|
19
|
+
region: Region;
|
|
20
|
+
timeout?: number;
|
|
21
|
+
unknownApiUrl?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare class Onfido {
|
|
24
|
+
readonly axiosInstance: AxiosInstance;
|
|
25
|
+
readonly applicant: Applicants;
|
|
26
|
+
readonly document: Documents;
|
|
27
|
+
readonly livePhoto: LivePhotos;
|
|
28
|
+
readonly liveVideo: LiveVideos;
|
|
29
|
+
readonly check: Checks;
|
|
30
|
+
readonly report: Reports;
|
|
31
|
+
readonly address: Addresses;
|
|
32
|
+
readonly webhook: Webhooks;
|
|
33
|
+
readonly sdkToken: SdkTokens;
|
|
34
|
+
readonly autofill: Autofill;
|
|
35
|
+
constructor({ apiToken, region, timeout, unknownApiUrl }: OnfidoOptions);
|
|
36
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage } from "http";
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
export declare class OnfidoDownload {
|
|
5
|
+
private readonly incomingMessage;
|
|
6
|
+
constructor(incomingMessage: IncomingMessage);
|
|
7
|
+
asStream(): Readable;
|
|
8
|
+
get contentType(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { SimpleObject } from "./formatting";
|
|
3
|
+
import { OnfidoDownload } from "./OnfidoDownload";
|
|
4
|
+
export declare enum Method {
|
|
5
|
+
GET = "get",
|
|
6
|
+
POST = "post",
|
|
7
|
+
PUT = "put",
|
|
8
|
+
DELETE = "delete"
|
|
9
|
+
}
|
|
10
|
+
export declare class Resource<T extends SimpleObject> {
|
|
11
|
+
private readonly name;
|
|
12
|
+
private readonly axiosInstance;
|
|
13
|
+
protected constructor(name: string, axiosInstance: AxiosInstance);
|
|
14
|
+
protected request({ method, path, body, query }: {
|
|
15
|
+
method: Method;
|
|
16
|
+
path?: string;
|
|
17
|
+
body?: T;
|
|
18
|
+
query?: SimpleObject;
|
|
19
|
+
}): Promise<any>;
|
|
20
|
+
protected upload(body: T): Promise<any>;
|
|
21
|
+
protected download(path: string): Promise<OnfidoDownload>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare type WebhookEvent = {
|
|
3
|
+
resourceType: string;
|
|
4
|
+
action: string;
|
|
5
|
+
object: {
|
|
6
|
+
id: string;
|
|
7
|
+
status: string;
|
|
8
|
+
href: string;
|
|
9
|
+
completedAtIso8601: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare class WebhookEventVerifier {
|
|
13
|
+
private readonly webhookToken;
|
|
14
|
+
constructor(webhookToken: string);
|
|
15
|
+
readPayload(rawEventBody: string | Buffer, hexSignature: string): WebhookEvent;
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OnfidoError } from "./OnfidoError";
|
|
2
|
+
export declare class OnfidoApiError extends OnfidoError {
|
|
3
|
+
readonly responseBody: unknown;
|
|
4
|
+
readonly statusCode: number;
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly fields: unknown;
|
|
7
|
+
private constructor();
|
|
8
|
+
static fromResponse(responseBody: unknown, statusCode: number): OnfidoApiError;
|
|
9
|
+
isClientError(): boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
import { IFormData } from "./types/formData";
|
|
4
|
+
export declare type SimpleObject = {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
declare type ContentsAndOptions = {
|
|
8
|
+
contents: Readable;
|
|
9
|
+
filepath: string;
|
|
10
|
+
contentType?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type FileLike = Readable | ContentsAndOptions;
|
|
13
|
+
export declare const convertObjectToSnakeCase: (requestBody: unknown) => unknown;
|
|
14
|
+
export declare const convertObjectToCamelCase: (responseBody: SimpleObject) => SimpleObject;
|
|
15
|
+
export declare const toFormData: (object: SimpleObject) => IFormData;
|
|
16
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { Onfido, OnfidoOptions, Region } from "./Onfido";
|
|
2
|
+
export { OnfidoDownload } from "./OnfidoDownload";
|
|
3
|
+
export { OnfidoError } from "./errors/OnfidoError";
|
|
4
|
+
export { OnfidoApiError } from "./errors/OnfidoApiError";
|
|
5
|
+
export { FileLike } from "./formatting";
|
|
6
|
+
export { WebhookEvent, WebhookEventVerifier } from "./WebhookEventVerifier";
|
|
7
|
+
export { Applicant, ApplicantRequest } from "./resources/Applicants";
|
|
8
|
+
export { Address, AddressRequest } from "./resources/Addresses";
|
|
9
|
+
export { IdNumber, IdNumberRequest } from "./resources/IdNumbers";
|
|
10
|
+
export { Document, DocumentRequest } from "./resources/Documents";
|
|
11
|
+
export { LivePhoto, LivePhotoRequest } from "./resources/LivePhotos";
|
|
12
|
+
export { LiveVideo } from "./resources/LiveVideos";
|
|
13
|
+
export { Check, CheckRequest } from "./resources/Checks";
|
|
14
|
+
export { Report } from "./resources/Reports";
|
|
15
|
+
export { Webhook, WebhookRequest } from "./resources/Webhooks";
|
|
16
|
+
export { SdkTokenRequest } from "./resources/SdkTokens";
|
|
17
|
+
export { Autofill, ExtractionResult } from "./resources/Autofill";
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { PassThrough, Readable } from 'stream';
|
|
3
|
+
|
|
4
|
+
var version = "2.1.1";
|
|
5
|
+
|
|
6
|
+
class OnfidoError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "OnfidoError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class OnfidoApiError extends OnfidoError {
|
|
14
|
+
constructor(message, responseBody, statusCode, type, fields) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "OnfidoApiError";
|
|
17
|
+
this.responseBody = responseBody;
|
|
18
|
+
this.statusCode = statusCode;
|
|
19
|
+
this.type = type;
|
|
20
|
+
this.fields = fields;
|
|
21
|
+
}
|
|
22
|
+
static fromResponse(responseBody, statusCode) {
|
|
23
|
+
const innerErrorData = responseBody instanceof Object ? responseBody.error : {};
|
|
24
|
+
const innerError = innerErrorData instanceof Object ? innerErrorData : {};
|
|
25
|
+
const type = `${innerError.type || "unknown"}`;
|
|
26
|
+
const message = `${innerError.message || responseBody}`;
|
|
27
|
+
const fields = innerError.fields;
|
|
28
|
+
const fullMessage = `${message} (status code ${statusCode})` +
|
|
29
|
+
(fields ? ` | ${JSON.stringify(fields)}` : "");
|
|
30
|
+
return new OnfidoApiError(fullMessage, responseBody, statusCode, type, fields);
|
|
31
|
+
}
|
|
32
|
+
isClientError() {
|
|
33
|
+
return this.statusCode < 500;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/*! *****************************************************************************
|
|
38
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
39
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
40
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
41
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
42
|
+
|
|
43
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
44
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
45
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
46
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
47
|
+
|
|
48
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
49
|
+
and limitations under the License.
|
|
50
|
+
***************************************************************************** */
|
|
51
|
+
|
|
52
|
+
function __rest(s, e) {
|
|
53
|
+
var t = {};
|
|
54
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
55
|
+
t[p] = s[p];
|
|
56
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
57
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
58
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
59
|
+
t[p[i]] = s[p[i]];
|
|
60
|
+
}
|
|
61
|
+
return t;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Using require because "form-data" exports this object as a default export which breaks integration when esModuleInterop: false
|
|
65
|
+
// tslint:disable-next-line: no-var-requires
|
|
66
|
+
const FormData = require("form-data");
|
|
67
|
+
const snakeCase = (camelCaseString) => camelCaseString.replace(/[A-Z]/g, char => `_${char.toLowerCase()}`);
|
|
68
|
+
const camelCase = (snakeCaseString) => snakeCaseString
|
|
69
|
+
.replace(/_[0-9]/g, underscoreDigit => underscoreDigit[1])
|
|
70
|
+
.replace(/_[a-z]/g, underscoreChar => underscoreChar[1].toUpperCase());
|
|
71
|
+
const deepMapObjectKeys = (value, f) => {
|
|
72
|
+
if (!(value instanceof Object)) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
else if (Array.isArray(value)) {
|
|
76
|
+
return value.map(item => deepMapObjectKeys(item, f));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
80
|
+
acc[f(key)] = deepMapObjectKeys(value[key], f);
|
|
81
|
+
return acc;
|
|
82
|
+
}, {});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const convertObjectToSnakeCase = (requestBody) => {
|
|
86
|
+
// Converting to JSON and back first handles things like dates, circular references etc.
|
|
87
|
+
requestBody = JSON.parse(JSON.stringify(requestBody));
|
|
88
|
+
return deepMapObjectKeys(requestBody, snakeCase);
|
|
89
|
+
};
|
|
90
|
+
const convertObjectToCamelCase = (responseBody) => deepMapObjectKeys(responseBody, camelCase);
|
|
91
|
+
const toFormData = (object) => {
|
|
92
|
+
return Object.entries(object).reduce((formData, [key, value]) => {
|
|
93
|
+
if (value instanceof Object && "contents" in value) {
|
|
94
|
+
const _a = value, { contents } = _a, options = __rest(_a, ["contents"]);
|
|
95
|
+
formData.append(snakeCase(key), contents, options);
|
|
96
|
+
}
|
|
97
|
+
else if (value !== undefined && value !== null) {
|
|
98
|
+
formData.append(snakeCase(key), value);
|
|
99
|
+
}
|
|
100
|
+
return formData;
|
|
101
|
+
}, new FormData());
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
class OnfidoDownload {
|
|
105
|
+
constructor(incomingMessage) {
|
|
106
|
+
this.incomingMessage = incomingMessage;
|
|
107
|
+
}
|
|
108
|
+
asStream() {
|
|
109
|
+
// Use a PassThrough stream so the IncomingMessage isn't exposed.
|
|
110
|
+
const passThroughStream = new PassThrough();
|
|
111
|
+
this.incomingMessage.pipe(passThroughStream);
|
|
112
|
+
return passThroughStream;
|
|
113
|
+
}
|
|
114
|
+
get contentType() {
|
|
115
|
+
return this.incomingMessage.headers["content-type"];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
var Method;
|
|
120
|
+
(function (Method) {
|
|
121
|
+
Method["GET"] = "get";
|
|
122
|
+
Method["POST"] = "post";
|
|
123
|
+
Method["PUT"] = "put";
|
|
124
|
+
Method["DELETE"] = "delete";
|
|
125
|
+
})(Method || (Method = {}));
|
|
126
|
+
const isJson = (response) => (response.headers["content-type"] || "").includes("application/json");
|
|
127
|
+
const readFullStream = (stream) => new Promise((resolve) => {
|
|
128
|
+
let all = "";
|
|
129
|
+
stream.on("data", data => (all += data));
|
|
130
|
+
stream.on("error", () => resolve("An error occurred reading the response"));
|
|
131
|
+
stream.on("end", () => {
|
|
132
|
+
// Try to parse as JSON, but fall back to just returning the raw text.
|
|
133
|
+
try {
|
|
134
|
+
resolve(JSON.parse(all));
|
|
135
|
+
}
|
|
136
|
+
catch (_a) {
|
|
137
|
+
resolve(all);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
const convertAxiosErrorToOnfidoError = async (error) => {
|
|
142
|
+
if (!error.response) {
|
|
143
|
+
return new OnfidoError(error.message || "An unknown error occurred making the request");
|
|
144
|
+
}
|
|
145
|
+
// Received a 4XX or 5XX response.
|
|
146
|
+
const response = error.response;
|
|
147
|
+
const data = response.data;
|
|
148
|
+
// If we were downloading a file, we will have a stream instead of a string.
|
|
149
|
+
const body = data instanceof Readable ? await readFullStream(data) : data;
|
|
150
|
+
return OnfidoApiError.fromResponse(body, response.status);
|
|
151
|
+
};
|
|
152
|
+
const handleResponse = async (request) => {
|
|
153
|
+
try {
|
|
154
|
+
const response = await request;
|
|
155
|
+
const data = response.data;
|
|
156
|
+
return isJson(response) ? convertObjectToCamelCase(data) : data;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw await convertAxiosErrorToOnfidoError(error);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
class Resource {
|
|
163
|
+
constructor(name, axiosInstance) {
|
|
164
|
+
this.name = name;
|
|
165
|
+
this.axiosInstance = axiosInstance;
|
|
166
|
+
}
|
|
167
|
+
async request({ method, path = "", body, query }) {
|
|
168
|
+
const request = this.axiosInstance({
|
|
169
|
+
method,
|
|
170
|
+
url: `${this.name}/${path}`,
|
|
171
|
+
data: body && convertObjectToSnakeCase(body),
|
|
172
|
+
params: query && convertObjectToSnakeCase(query)
|
|
173
|
+
});
|
|
174
|
+
return handleResponse(request);
|
|
175
|
+
}
|
|
176
|
+
async upload(body) {
|
|
177
|
+
const formData = toFormData(body);
|
|
178
|
+
const request = this.axiosInstance({
|
|
179
|
+
method: Method.POST,
|
|
180
|
+
url: `${this.name}/`,
|
|
181
|
+
data: formData,
|
|
182
|
+
headers: formData.getHeaders()
|
|
183
|
+
});
|
|
184
|
+
return handleResponse(request);
|
|
185
|
+
}
|
|
186
|
+
async download(path) {
|
|
187
|
+
const request = this.axiosInstance({
|
|
188
|
+
method: Method.GET,
|
|
189
|
+
url: `${this.name}/${path}`,
|
|
190
|
+
responseType: "stream",
|
|
191
|
+
// Accept a response with any content type (e.g. image/png, application/pdf, video/mp4)
|
|
192
|
+
headers: { Accept: "*/*" }
|
|
193
|
+
});
|
|
194
|
+
const stream = await handleResponse(request);
|
|
195
|
+
return new OnfidoDownload(stream);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
class Addresses extends Resource {
|
|
200
|
+
constructor(axiosInstance) {
|
|
201
|
+
super("addresses", axiosInstance);
|
|
202
|
+
}
|
|
203
|
+
async pick(postcode) {
|
|
204
|
+
const { addresses } = await this.request({
|
|
205
|
+
method: Method.GET,
|
|
206
|
+
path: "pick",
|
|
207
|
+
query: { postcode }
|
|
208
|
+
});
|
|
209
|
+
return addresses;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
class Applicants extends Resource {
|
|
214
|
+
constructor(axiosInstance) {
|
|
215
|
+
super("applicants", axiosInstance);
|
|
216
|
+
}
|
|
217
|
+
async create(applicantRequest) {
|
|
218
|
+
return this.request({ method: Method.POST, body: applicantRequest });
|
|
219
|
+
}
|
|
220
|
+
async find(id) {
|
|
221
|
+
return this.request({ method: Method.GET, path: id });
|
|
222
|
+
}
|
|
223
|
+
async update(id, applicantRequest) {
|
|
224
|
+
return this.request({
|
|
225
|
+
method: Method.PUT,
|
|
226
|
+
path: id,
|
|
227
|
+
body: applicantRequest
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async delete(id) {
|
|
231
|
+
await this.request({ method: Method.DELETE, path: id });
|
|
232
|
+
}
|
|
233
|
+
async restore(id) {
|
|
234
|
+
await this.request({ method: Method.POST, path: `${id}/restore` });
|
|
235
|
+
}
|
|
236
|
+
async list({ page, perPage, includeDeleted } = {}) {
|
|
237
|
+
const { applicants } = await this.request({
|
|
238
|
+
method: Method.GET,
|
|
239
|
+
query: { page, perPage, includeDeleted }
|
|
240
|
+
});
|
|
241
|
+
return applicants;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
class Autofill extends Resource {
|
|
246
|
+
constructor(axiosInstance) {
|
|
247
|
+
super("extractions", axiosInstance);
|
|
248
|
+
}
|
|
249
|
+
async perform(documentId) {
|
|
250
|
+
return this.request({
|
|
251
|
+
method: Method.POST,
|
|
252
|
+
body: { documentId }
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
class Checks extends Resource {
|
|
258
|
+
constructor(axiosInstance) {
|
|
259
|
+
super("checks", axiosInstance);
|
|
260
|
+
}
|
|
261
|
+
async create(checkRequest) {
|
|
262
|
+
return this.request({ method: Method.POST, body: checkRequest });
|
|
263
|
+
}
|
|
264
|
+
async find(id) {
|
|
265
|
+
return this.request({ method: Method.GET, path: id });
|
|
266
|
+
}
|
|
267
|
+
async list(applicantId) {
|
|
268
|
+
const { checks } = await this.request({
|
|
269
|
+
method: Method.GET,
|
|
270
|
+
query: { applicantId }
|
|
271
|
+
});
|
|
272
|
+
return checks;
|
|
273
|
+
}
|
|
274
|
+
async resume(id) {
|
|
275
|
+
await this.request({ method: Method.POST, path: `${id}/resume` });
|
|
276
|
+
}
|
|
277
|
+
async download(id) {
|
|
278
|
+
return super.download(`${id}/download`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
class Documents extends Resource {
|
|
283
|
+
constructor(axiosInstance) {
|
|
284
|
+
super("documents", axiosInstance);
|
|
285
|
+
}
|
|
286
|
+
async upload(documentRequest) {
|
|
287
|
+
return super.upload(documentRequest);
|
|
288
|
+
}
|
|
289
|
+
async download(id) {
|
|
290
|
+
return super.download(`${id}/download`);
|
|
291
|
+
}
|
|
292
|
+
async find(id) {
|
|
293
|
+
return this.request({ method: Method.GET, path: id });
|
|
294
|
+
}
|
|
295
|
+
async list(applicantId) {
|
|
296
|
+
const { documents } = await this.request({
|
|
297
|
+
method: Method.GET,
|
|
298
|
+
query: { applicantId }
|
|
299
|
+
});
|
|
300
|
+
return documents;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
class LivePhotos extends Resource {
|
|
305
|
+
constructor(axiosInstance) {
|
|
306
|
+
super("live_photos", axiosInstance);
|
|
307
|
+
}
|
|
308
|
+
async upload(livePhotoRequest) {
|
|
309
|
+
return super.upload(livePhotoRequest);
|
|
310
|
+
}
|
|
311
|
+
async download(id) {
|
|
312
|
+
return super.download(`${id}/download`);
|
|
313
|
+
}
|
|
314
|
+
async find(id) {
|
|
315
|
+
return this.request({ method: Method.GET, path: id });
|
|
316
|
+
}
|
|
317
|
+
async list(applicantId) {
|
|
318
|
+
const { livePhotos } = await this.request({
|
|
319
|
+
method: Method.GET,
|
|
320
|
+
query: { applicantId }
|
|
321
|
+
});
|
|
322
|
+
return livePhotos;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
class LiveVideos extends Resource {
|
|
327
|
+
constructor(axiosInstance) {
|
|
328
|
+
super("live_videos", axiosInstance);
|
|
329
|
+
}
|
|
330
|
+
async download(id) {
|
|
331
|
+
return super.download(`${id}/download`);
|
|
332
|
+
}
|
|
333
|
+
async frame(id) {
|
|
334
|
+
return super.download(`${id}/frame`);
|
|
335
|
+
}
|
|
336
|
+
async find(id) {
|
|
337
|
+
return this.request({ method: Method.GET, path: id });
|
|
338
|
+
}
|
|
339
|
+
async list(applicantId) {
|
|
340
|
+
const { liveVideos } = await this.request({
|
|
341
|
+
method: Method.GET,
|
|
342
|
+
query: { applicantId }
|
|
343
|
+
});
|
|
344
|
+
return liveVideos;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
class Reports extends Resource {
|
|
349
|
+
constructor(axiosInstance) {
|
|
350
|
+
super("reports", axiosInstance);
|
|
351
|
+
}
|
|
352
|
+
async find(id) {
|
|
353
|
+
return this.request({ method: Method.GET, path: id });
|
|
354
|
+
}
|
|
355
|
+
async list(checkId) {
|
|
356
|
+
const { reports } = await this.request({
|
|
357
|
+
method: Method.GET,
|
|
358
|
+
query: { checkId }
|
|
359
|
+
});
|
|
360
|
+
return reports;
|
|
361
|
+
}
|
|
362
|
+
async resume(id) {
|
|
363
|
+
await this.request({ method: Method.POST, path: `${id}/resume` });
|
|
364
|
+
}
|
|
365
|
+
async cancel(id) {
|
|
366
|
+
await this.request({ method: Method.POST, path: `${id}/cancel` });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
class SdkTokens extends Resource {
|
|
371
|
+
constructor(axiosInstance) {
|
|
372
|
+
super("sdk_token", axiosInstance);
|
|
373
|
+
}
|
|
374
|
+
async generate(sdkTokenRequest) {
|
|
375
|
+
const { token } = await this.request({
|
|
376
|
+
method: Method.POST,
|
|
377
|
+
body: sdkTokenRequest
|
|
378
|
+
});
|
|
379
|
+
return token;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
class Webhooks extends Resource {
|
|
384
|
+
constructor(axiosInstance) {
|
|
385
|
+
super("webhooks", axiosInstance);
|
|
386
|
+
}
|
|
387
|
+
async create(webhookRequest) {
|
|
388
|
+
return this.request({ method: Method.POST, body: webhookRequest });
|
|
389
|
+
}
|
|
390
|
+
async find(id) {
|
|
391
|
+
return this.request({ method: Method.GET, path: id });
|
|
392
|
+
}
|
|
393
|
+
async update(id, webhookRequest) {
|
|
394
|
+
return this.request({
|
|
395
|
+
method: Method.PUT,
|
|
396
|
+
path: id,
|
|
397
|
+
body: webhookRequest
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
async delete(id) {
|
|
401
|
+
await this.request({ method: Method.DELETE, path: id });
|
|
402
|
+
}
|
|
403
|
+
async list() {
|
|
404
|
+
const { webhooks } = await this.request({ method: Method.GET });
|
|
405
|
+
return webhooks;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
var Region;
|
|
410
|
+
(function (Region) {
|
|
411
|
+
Region["EU"] = "EU";
|
|
412
|
+
Region["US"] = "US";
|
|
413
|
+
Region["CA"] = "CA";
|
|
414
|
+
})(Region || (Region = {}));
|
|
415
|
+
class Onfido {
|
|
416
|
+
constructor({ apiToken, region, timeout = 30000, unknownApiUrl }) {
|
|
417
|
+
if (!apiToken) {
|
|
418
|
+
throw new Error("No apiToken provided");
|
|
419
|
+
}
|
|
420
|
+
if (!region || !Object.values(Region).includes(region)) {
|
|
421
|
+
throw new Error(`Unknown or missing region '${region}'. ` +
|
|
422
|
+
"We previously defaulted to region 'EU', so if you previously didn’t " +
|
|
423
|
+
"set a region or used api.onfido.com, please set your region to 'EU'");
|
|
424
|
+
}
|
|
425
|
+
const regionUrl = `https://api.${region.toLowerCase()}.onfido.com/v3.2/`;
|
|
426
|
+
this.axiosInstance = axios.create({
|
|
427
|
+
baseURL: unknownApiUrl || regionUrl,
|
|
428
|
+
headers: {
|
|
429
|
+
Authorization: `Token token=${apiToken}`,
|
|
430
|
+
Accept: "application/json",
|
|
431
|
+
"User-Agent": `onfido-node/${version}`
|
|
432
|
+
},
|
|
433
|
+
timeout
|
|
434
|
+
});
|
|
435
|
+
// Core resources
|
|
436
|
+
this.applicant = new Applicants(this.axiosInstance);
|
|
437
|
+
this.document = new Documents(this.axiosInstance);
|
|
438
|
+
this.livePhoto = new LivePhotos(this.axiosInstance);
|
|
439
|
+
this.liveVideo = new LiveVideos(this.axiosInstance);
|
|
440
|
+
this.check = new Checks(this.axiosInstance);
|
|
441
|
+
this.report = new Reports(this.axiosInstance);
|
|
442
|
+
// Other endpoints
|
|
443
|
+
this.address = new Addresses(this.axiosInstance);
|
|
444
|
+
this.webhook = new Webhooks(this.axiosInstance);
|
|
445
|
+
this.sdkToken = new SdkTokens(this.axiosInstance);
|
|
446
|
+
this.autofill = new Autofill(this.axiosInstance);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Require crypto instead of importing, because Node can be built without crypto support.
|
|
451
|
+
let crypto;
|
|
452
|
+
try {
|
|
453
|
+
// tslint:disable-next-line: no-var-requires
|
|
454
|
+
crypto = require("crypto");
|
|
455
|
+
}
|
|
456
|
+
catch (_a) {
|
|
457
|
+
// We throw an error when verifying webhooks instead.
|
|
458
|
+
}
|
|
459
|
+
class WebhookEventVerifier {
|
|
460
|
+
constructor(webhookToken) {
|
|
461
|
+
this.webhookToken = webhookToken;
|
|
462
|
+
}
|
|
463
|
+
readPayload(rawEventBody, hexSignature) {
|
|
464
|
+
if (!crypto) {
|
|
465
|
+
throw new Error("Verifying webhook events requires crypto support");
|
|
466
|
+
}
|
|
467
|
+
const givenSignature = Buffer.from(hexSignature, "hex");
|
|
468
|
+
// Compute the the actual HMAC signature from the raw request body.
|
|
469
|
+
const hmac = crypto.createHmac("sha256", this.webhookToken);
|
|
470
|
+
hmac.update(rawEventBody);
|
|
471
|
+
const eventSignature = hmac.digest();
|
|
472
|
+
// Use timingSafeEqual to prevent against timing attacks.
|
|
473
|
+
if (!crypto.timingSafeEqual(givenSignature, eventSignature)) {
|
|
474
|
+
throw new OnfidoError("Invalid signature for webhook event");
|
|
475
|
+
}
|
|
476
|
+
const { payload } = JSON.parse(rawEventBody.toString());
|
|
477
|
+
return convertObjectToCamelCase(payload);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export { Autofill, Onfido, OnfidoApiError, OnfidoDownload, OnfidoError, Region, WebhookEventVerifier };
|
|
482
|
+
//# sourceMappingURL=index.es.js.map
|