@onfido/api 2.9.0 → 3.0.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.
- package/LICENSE +1 -1
- package/README.md +115 -132
- package/dist/api.d.ts +11690 -0
- package/dist/api.js +5113 -0
- package/dist/base.d.ts +66 -0
- package/dist/base.js +65 -0
- package/dist/common.d.ts +66 -0
- package/dist/common.js +201 -0
- package/dist/configuration.d.ts +93 -0
- package/dist/configuration.js +53 -0
- package/dist/esm/api.d.ts +11690 -0
- package/dist/esm/api.js +5106 -0
- package/dist/esm/base.d.ts +66 -0
- package/dist/esm/base.js +60 -0
- package/dist/esm/common.d.ts +66 -0
- package/dist/esm/common.js +189 -0
- package/dist/esm/configuration.d.ts +93 -0
- package/dist/esm/configuration.js +49 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/webhook-event-verifier.d.ts +9 -0
- package/dist/esm/webhook-event-verifier.js +31 -0
- package/dist/index.d.ts +14 -19
- package/dist/index.js +31 -553
- package/dist/webhook-event-verifier.d.ts +9 -0
- package/dist/webhook-event-verifier.js +36 -0
- package/package.json +30 -31
- package/CHANGELOG.md +0 -121
- package/dist/Onfido.d.ts +0 -40
- package/dist/OnfidoDownload.d.ts +0 -9
- package/dist/Resource.d.ts +0 -22
- package/dist/WebhookEventVerifier.d.ts +0 -17
- package/dist/errors/OnfidoApiError.d.ts +0 -10
- package/dist/errors/OnfidoError.d.ts +0 -3
- package/dist/formatting.d.ts +0 -16
- package/dist/index.es.js +0 -544
- package/dist/index.es.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/resources/Addresses.d.ts +0 -27
- package/dist/resources/Applicants.d.ts +0 -44
- package/dist/resources/Autofill.d.ts +0 -37
- package/dist/resources/Checks.d.ts +0 -42
- package/dist/resources/ConsentsRequest.d.ts +0 -4
- package/dist/resources/Documents.d.ts +0 -34
- package/dist/resources/IdNumbers.d.ts +0 -10
- package/dist/resources/LivePhotos.d.ts +0 -25
- package/dist/resources/LiveVideos.d.ts +0 -19
- package/dist/resources/Location.d.ts +0 -8
- package/dist/resources/MotionCaptures.d.ts +0 -19
- package/dist/resources/Reports.d.ts +0 -24
- package/dist/resources/SdkTokens.d.ts +0 -12
- package/dist/resources/Webhooks.d.ts +0 -26
- package/dist/resources/WorkflowRuns.d.ts +0 -48
- package/dist/types/formData.d.ts +0 -27
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -2,98 +2,121 @@
|
|
|
2
2
|
|
|
3
3
|
The official Node.js library for integrating with the Onfido API.
|
|
4
4
|
|
|
5
|
-
Documentation can be found at <https://documentation.onfido.com
|
|
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 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).
|
|
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
9
|
This version uses Onfido API v3.6. 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
|
-
## Installation
|
|
11
|
+
## Installation & Usage
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Installation
|
|
14
|
+
|
|
15
|
+
#### Npm
|
|
14
16
|
|
|
15
17
|
```sh
|
|
16
18
|
npm install @onfido/api
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
#### Yarn
|
|
20
22
|
|
|
21
23
|
```sh
|
|
22
24
|
yarn add @onfido/api
|
|
23
25
|
```
|
|
24
26
|
|
|
25
|
-
## Getting
|
|
27
|
+
## Getting Started
|
|
26
28
|
|
|
27
29
|
Require the package:
|
|
28
30
|
|
|
29
31
|
```js
|
|
30
|
-
const {
|
|
32
|
+
const {
|
|
33
|
+
DefaultApi,
|
|
34
|
+
Configuration,
|
|
35
|
+
WebhookEventVerifier,
|
|
36
|
+
} = require("@onfido/api");
|
|
37
|
+
const { isAxiosError } = require("axios");
|
|
31
38
|
```
|
|
32
39
|
|
|
33
40
|
For TypeScript users, types are available as well:
|
|
34
41
|
|
|
35
42
|
```ts
|
|
36
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
DefaultApi,
|
|
45
|
+
Configuration,
|
|
46
|
+
Region,
|
|
47
|
+
WebhookEventVerifier,
|
|
48
|
+
} from "@onfido/api";
|
|
49
|
+
import { isAxiosError } from "axios";
|
|
37
50
|
```
|
|
38
51
|
|
|
39
52
|
Configure with your API token and region:
|
|
40
53
|
|
|
41
54
|
```js
|
|
42
|
-
const onfido = new
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
55
|
+
const onfido = new DefaultApi(
|
|
56
|
+
new Configuration({
|
|
57
|
+
apiToken: process.env.ONFIDO_API_TOKEN,
|
|
58
|
+
region: Region.EU, // Supports Region.EU, Region.US and Region.CA
|
|
59
|
+
baseOptions: { timeout: 60_000 }, // Additional Axios options (timeout, etc.)
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
47
62
|
```
|
|
48
63
|
|
|
49
|
-
|
|
64
|
+
NB: by default, timeout is set to 30 seconds.
|
|
50
65
|
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
const applicant = await onfido.applicant.create({
|
|
54
|
-
firstName: "Jane",
|
|
55
|
-
lastName: "Doe",
|
|
56
|
-
location: {
|
|
57
|
-
ipAddress: "127.0.0.1",
|
|
58
|
-
countryOfResidence: "GBR"
|
|
59
|
-
}
|
|
60
|
-
});
|
|
66
|
+
### Making a call to the API
|
|
61
67
|
|
|
62
|
-
|
|
63
|
-
applicantId: applicant.id,
|
|
64
|
-
reportNames: ["identity_enhanced"]
|
|
65
|
-
});
|
|
68
|
+
Using `async`/`await` (in an `async function`):
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
```js
|
|
71
|
+
(async () => {
|
|
72
|
+
try {
|
|
73
|
+
const applicant = await onfido.createApplicant({
|
|
74
|
+
first_name: "Jane",
|
|
75
|
+
last_name: "Doe",
|
|
76
|
+
location: {
|
|
77
|
+
ip_address: "127.0.0.1",
|
|
78
|
+
country_of_residence: "GBR",
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// ...
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (isAxiosError(error)) {
|
|
85
|
+
console.log(`status code: ${error.response?.status}`);
|
|
86
|
+
const error_details = error.response?.data.error;
|
|
87
|
+
// An error response was received from the Onfido API, extra info is available.
|
|
88
|
+
if (error_details) {
|
|
89
|
+
console.log(error_details.message);
|
|
90
|
+
console.log(error_details.type);
|
|
91
|
+
} else {
|
|
92
|
+
// No response was received for some reason e.g. a network error.
|
|
93
|
+
console.log(error.message);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
console.log(error.message);
|
|
97
|
+
}
|
|
77
98
|
}
|
|
78
|
-
}
|
|
99
|
+
})();
|
|
79
100
|
```
|
|
80
101
|
|
|
81
|
-
|
|
102
|
+
Please find more information regarding Axios errors in library [documentation](https://axios-http.com/docs/handling_errors).
|
|
103
|
+
|
|
104
|
+
Using promises:
|
|
82
105
|
|
|
83
106
|
```js
|
|
84
|
-
onfido
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
onfido
|
|
108
|
+
.createApplicant({
|
|
109
|
+
first_name: "Jane",
|
|
110
|
+
last_name: "Doe",
|
|
88
111
|
location: {
|
|
89
|
-
|
|
90
|
-
|
|
112
|
+
ip_address: "127.0.0.1",
|
|
113
|
+
country_of_residence: "GBR"
|
|
91
114
|
}
|
|
92
115
|
})
|
|
93
116
|
.then(applicant =>
|
|
94
|
-
onfido.
|
|
95
|
-
|
|
96
|
-
|
|
117
|
+
onfido.createCheck({
|
|
118
|
+
applicant_id: applicant.data.id,
|
|
119
|
+
report_names: ["identity_enhanced"]
|
|
97
120
|
})
|
|
98
121
|
)
|
|
99
122
|
.then(check =>
|
|
@@ -104,111 +127,71 @@ onfido.applicant
|
|
|
104
127
|
});
|
|
105
128
|
```
|
|
106
129
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
Most responses will be normal JavaScript objects. Property names will be in camelCase rather than snake_case, including property names in nested objects.
|
|
110
|
-
|
|
111
|
-
```js
|
|
112
|
-
const applicant = await onfido.applicant.create({
|
|
113
|
-
firstName: "Jane",
|
|
114
|
-
lastName: "Doe",
|
|
115
|
-
address: {
|
|
116
|
-
flatNumber: "12",
|
|
117
|
-
postcode: "S2 2DF",
|
|
118
|
-
country: "GBR",
|
|
119
|
-
},
|
|
120
|
-
location: {
|
|
121
|
-
ipAddress: "127.0.0.1",
|
|
122
|
-
countryOfResidence: "GBR",
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
console.log(applicant);
|
|
127
|
-
{
|
|
128
|
-
id: "<APPLICANT_ID>",
|
|
129
|
-
createdAt: "2020-01-22T10:44:01Z",
|
|
130
|
-
firstName: "Jane",
|
|
131
|
-
lastName: "Doe",
|
|
132
|
-
email: null,
|
|
133
|
-
dob: null,
|
|
134
|
-
deleteAt: null,
|
|
135
|
-
href: "/v3/applicants/<APPLICANT_ID>",
|
|
136
|
-
address: {
|
|
137
|
-
flatNumber: "12",
|
|
138
|
-
buildingNumber: null,
|
|
139
|
-
buildingName: null,
|
|
140
|
-
street: null,
|
|
141
|
-
subStreet: null,
|
|
142
|
-
town: null,
|
|
143
|
-
state: null,
|
|
144
|
-
postcode: "S2 2DF",
|
|
145
|
-
country: "GBR",
|
|
146
|
-
line1: null,
|
|
147
|
-
line2: null,
|
|
148
|
-
line3: null
|
|
149
|
-
},
|
|
150
|
-
idNumbers: [],
|
|
151
|
-
phoneNumber: null,
|
|
152
|
-
location: {
|
|
153
|
-
ipAddress: "127.0.0.1",
|
|
154
|
-
countryOfResidence: "GBR"
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
```
|
|
130
|
+
### File download
|
|
158
131
|
|
|
159
|
-
File downloads, for example `onfido.
|
|
132
|
+
File downloads, for example `onfido.downloadDocument(documentId, {responseType: 'arraybuffer'})`, will return an instance of a specific object for this endpoint.
|
|
160
133
|
|
|
161
134
|
These objects will have a content type, e.g. `image/png`.
|
|
162
135
|
|
|
163
136
|
```js
|
|
164
|
-
download.
|
|
137
|
+
download.headers["content-type"];
|
|
165
138
|
```
|
|
166
139
|
|
|
167
|
-
Call `
|
|
140
|
+
Call `slice()` to get a `Blob` of the download:
|
|
168
141
|
|
|
169
142
|
```js
|
|
170
|
-
const
|
|
143
|
+
const blob = download.data.slice();
|
|
171
144
|
```
|
|
172
145
|
|
|
173
|
-
|
|
146
|
+
### File upload
|
|
174
147
|
|
|
175
|
-
For some common types of streams, like instances of `fs.ReadStream`, you can provide the stream directly
|
|
148
|
+
For some common types of streams, like instances of `fs.ReadStream`, you can provide the stream directly:
|
|
176
149
|
|
|
177
150
|
```js
|
|
178
|
-
onfido.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
151
|
+
onfido.uploadDocument(
|
|
152
|
+
"passport",
|
|
153
|
+
"<APPLICANT_ID>",
|
|
154
|
+
fs.createReadStream("path/to/passport.png"),
|
|
155
|
+
);
|
|
183
156
|
```
|
|
184
157
|
|
|
185
|
-
|
|
158
|
+
### Webhook event verification
|
|
159
|
+
|
|
160
|
+
Webhook events payload needs to be verified before it can be accessed. Library allows to easily decode the payload and verify its signature before returning it as an object for user convenience:
|
|
186
161
|
|
|
187
162
|
```js
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
});
|
|
163
|
+
(async () => {
|
|
164
|
+
try {
|
|
165
|
+
const verifier = new WebhookEventVerifier("_ABC123abc...3ABC123_");
|
|
166
|
+
const signature = "a0...760e";
|
|
167
|
+
|
|
168
|
+
const event = verifier.readPayload(`{"payload":{"r...3"}}`, signature);
|
|
169
|
+
} catch (e) {
|
|
170
|
+
if (e instanceof OnfidoInvalidSignatureError) {
|
|
171
|
+
// Invalid webhook signature
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
})();
|
|
201
175
|
```
|
|
202
176
|
|
|
203
|
-
##
|
|
177
|
+
## Contributing
|
|
204
178
|
|
|
205
|
-
|
|
179
|
+
This library is automatically generated using [OpenAPI Generator](https://openapi-generator.tech) - version: 7.5.0; therefore all the contributions, except tests files, should target [Onfido OpenAPI specification repository](https://github.com/onfido/onfido-openapi-spec/tree/master) instead of this repository.
|
|
206
180
|
|
|
207
|
-
|
|
181
|
+
For contributions to the tests instead, please follow the steps below:
|
|
182
|
+
|
|
183
|
+
1. [Fork](<https://github.com/onfido/onfido-node/fork>) repository
|
|
184
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
185
|
+
3. Make your changes
|
|
186
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
|
187
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
|
188
|
+
6. Create a new Pull Request
|
|
208
189
|
|
|
209
|
-
|
|
210
|
-
|
|
190
|
+
## More documentation
|
|
191
|
+
|
|
192
|
+
More documentation and code examples can be found at <https://documentation.onfido.com>.
|
|
211
193
|
|
|
212
|
-
|
|
213
|
-
portal, [public.support.onfido.com](http://public.support.onfido.com).
|
|
194
|
+
## Support
|
|
214
195
|
|
|
196
|
+
Should you encounter any technical issues during integration, please contact Onfido's Customer Support team
|
|
197
|
+
via the [Customer Experience Portal](https://public.support.onfido.com/) which also includes support documentation.
|