@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.
Files changed (54) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +115 -132
  3. package/dist/api.d.ts +11690 -0
  4. package/dist/api.js +5113 -0
  5. package/dist/base.d.ts +66 -0
  6. package/dist/base.js +65 -0
  7. package/dist/common.d.ts +66 -0
  8. package/dist/common.js +201 -0
  9. package/dist/configuration.d.ts +93 -0
  10. package/dist/configuration.js +53 -0
  11. package/dist/esm/api.d.ts +11690 -0
  12. package/dist/esm/api.js +5106 -0
  13. package/dist/esm/base.d.ts +66 -0
  14. package/dist/esm/base.js +60 -0
  15. package/dist/esm/common.d.ts +66 -0
  16. package/dist/esm/common.js +189 -0
  17. package/dist/esm/configuration.d.ts +93 -0
  18. package/dist/esm/configuration.js +49 -0
  19. package/dist/esm/index.d.ts +14 -0
  20. package/dist/esm/index.js +16 -0
  21. package/dist/esm/webhook-event-verifier.d.ts +9 -0
  22. package/dist/esm/webhook-event-verifier.js +31 -0
  23. package/dist/index.d.ts +14 -19
  24. package/dist/index.js +31 -553
  25. package/dist/webhook-event-verifier.d.ts +9 -0
  26. package/dist/webhook-event-verifier.js +36 -0
  27. package/package.json +30 -31
  28. package/CHANGELOG.md +0 -121
  29. package/dist/Onfido.d.ts +0 -40
  30. package/dist/OnfidoDownload.d.ts +0 -9
  31. package/dist/Resource.d.ts +0 -22
  32. package/dist/WebhookEventVerifier.d.ts +0 -17
  33. package/dist/errors/OnfidoApiError.d.ts +0 -10
  34. package/dist/errors/OnfidoError.d.ts +0 -3
  35. package/dist/formatting.d.ts +0 -16
  36. package/dist/index.es.js +0 -544
  37. package/dist/index.es.js.map +0 -1
  38. package/dist/index.js.map +0 -1
  39. package/dist/resources/Addresses.d.ts +0 -27
  40. package/dist/resources/Applicants.d.ts +0 -44
  41. package/dist/resources/Autofill.d.ts +0 -37
  42. package/dist/resources/Checks.d.ts +0 -42
  43. package/dist/resources/ConsentsRequest.d.ts +0 -4
  44. package/dist/resources/Documents.d.ts +0 -34
  45. package/dist/resources/IdNumbers.d.ts +0 -10
  46. package/dist/resources/LivePhotos.d.ts +0 -25
  47. package/dist/resources/LiveVideos.d.ts +0 -19
  48. package/dist/resources/Location.d.ts +0 -8
  49. package/dist/resources/MotionCaptures.d.ts +0 -19
  50. package/dist/resources/Reports.d.ts +0 -24
  51. package/dist/resources/SdkTokens.d.ts +0 -12
  52. package/dist/resources/Webhooks.d.ts +0 -26
  53. package/dist/resources/WorkflowRuns.d.ts +0 -48
  54. package/dist/types/formData.d.ts +0 -27
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Onfido
3
+ Copyright (c) 2024 Onfido
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- For npm:
13
+ ### Installation
14
+
15
+ #### Npm
14
16
 
15
17
  ```sh
16
18
  npm install @onfido/api
17
19
  ```
18
20
 
19
- For Yarn:
21
+ #### Yarn
20
22
 
21
23
  ```sh
22
24
  yarn add @onfido/api
23
25
  ```
24
26
 
25
- ## Getting started
27
+ ## Getting Started
26
28
 
27
29
  Require the package:
28
30
 
29
31
  ```js
30
- const { Onfido, Region } = require("@onfido/api");
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 { Onfido, Region, Applicant, OnfidoApiError } from "@onfido/api";
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 Onfido({
43
- apiToken: process.env.ONFIDO_API_TOKEN,
44
- // Supports Region.EU, Region.US and Region.CA
45
- region: Region.EU
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
- Using with `async`/`await` (in an `async function`):
64
+ NB: by default, timeout is set to 30 seconds.
50
65
 
51
- ```js
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
- const check = await onfido.check.create({
63
- applicantId: applicant.id,
64
- reportNames: ["identity_enhanced"]
65
- });
68
+ Using `async`/`await` (in an `async function`):
66
69
 
67
- return check;
68
- } catch (error) {
69
- if (error instanceof OnfidoApiError) {
70
- // An error response was received from the Onfido API, extra info is available.
71
- console.log(error.message);
72
- console.log(error.type);
73
- console.log(error.isClientError());
74
- } else {
75
- // No response was received for some reason e.g. a network error.
76
- console.log(error.message);
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
- Using with promises:
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.applicant
85
- .create({
86
- firstName: "Jane",
87
- lastName: "Doe",
107
+ onfido
108
+ .createApplicant({
109
+ first_name: "Jane",
110
+ last_name: "Doe",
88
111
  location: {
89
- ipAddress: "127.0.0.1",
90
- countryOfResidence: "GBR"
112
+ ip_address: "127.0.0.1",
113
+ country_of_residence: "GBR"
91
114
  }
92
115
  })
93
116
  .then(applicant =>
94
- onfido.check.create({
95
- applicantId: applicant.id,
96
- reportNames: ["identity_enhanced"]
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
- ## Response format
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.document.download(documentId)`, will return instances of `OnfidoDownload`.
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.contentType;
137
+ download.headers["content-type"];
165
138
  ```
166
139
 
167
- Call `asStream()` to get a `Readable` stream of the download. You can read more about [`Readable` streams](https://nodejs.org/api/stream.html#stream_readable_streams).
140
+ Call `slice()` to get a `Blob` of the download:
168
141
 
169
142
  ```js
170
- const readableStream = download.asStream();
143
+ const blob = download.data.slice();
171
144
  ```
172
145
 
173
- ## File upload
146
+ ### File upload
174
147
 
175
- For some common types of streams, like instances of `fs.ReadStream`, you can provide the stream directly in the `file` property:
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.document.upload({
179
- applicantId: "<APPLICANT_ID>",
180
- file: fs.createReadStream("path/to/passport.png"),
181
- type: "passport"
182
- });
151
+ onfido.uploadDocument(
152
+ "passport",
153
+ "<APPLICANT_ID>",
154
+ fs.createReadStream("path/to/passport.png"),
155
+ );
183
156
  ```
184
157
 
185
- Alternatively, you may need to provide some extra information, for example when uploading a Base64 encoded image:
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
- const buffer = Buffer.from(base64Data, "base64");
189
- const bufferStream = new PassThrough();
190
- bufferStream.end(buffer);
191
-
192
- onfido.document.upload({
193
- applicantId: "<APPLICANT_ID>",
194
- file: {
195
- contents: bufferStream,
196
- filepath: "image.png",
197
- contentType: "image/png"
198
- },
199
- type: "passport"
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
- ## More documentation
177
+ ## Contributing
204
178
 
205
- More documentation and code examples can be found at <https://documentation.onfido.com>
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
- ## Support
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
- Should you encounter any technical issues during integration, please contact Onfido’s Customer Support team
210
- via [email](mailto:support@onfido.com), including the word ISSUE: at the start of the subject line.
190
+ ## More documentation
191
+
192
+ More documentation and code examples can be found at <https://documentation.onfido.com>.
211
193
 
212
- Alternatively, you can search the support documentation available via the customer experience
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.