@onfido/api
Advanced tools
Comparing version 1.6.0 to 2.0.0
# Changelog | ||
## v2.0.0, 9 April 2021 | ||
- Updated to use API v3.1 | ||
- Region is now a required argument when constructing an `Onfido` instance. The region previously defaulted to `Region.EU` | ||
- Add support for downloading a check | ||
## v1.6.0, 8 March 2021 | ||
- Add `privacy_notices_read_consent_given` to the type for creating a chec | ||
## v1.5.4, 12 January 2021 | ||
@@ -7,3 +17,2 @@ | ||
## v1.5.3, 3 December 2020 | ||
@@ -13,3 +22,2 @@ | ||
## v1.5.2, 3 September 2020 | ||
@@ -19,3 +27,2 @@ | ||
## v1.5.1, 20 August 2020 | ||
@@ -25,3 +32,2 @@ | ||
## v1.5.0, 14 August 2020 | ||
@@ -31,3 +37,2 @@ | ||
## v1.4.0, 15 July 2020 | ||
@@ -37,3 +42,2 @@ | ||
## v1.3.0, 30 June 2020 | ||
@@ -43,3 +47,2 @@ | ||
## v1.2.0, 23 June 2020 | ||
@@ -51,3 +54,2 @@ | ||
## v1.1.0, 2 April 2020 | ||
@@ -57,5 +59,4 @@ | ||
## v1.0.0, 23 January 2020 | ||
- The initial release of this library, which uses v3 of the Onfido API |
import axios from 'axios'; | ||
import { PassThrough, Readable } from 'stream'; | ||
var version = "1.6.0"; | ||
var version = "2.0.0"; | ||
@@ -67,4 +67,6 @@ class OnfidoError extends Error { | ||
const FormData = require("form-data"); | ||
const snakeCase = (s) => s.replace(/[A-Z]/g, char => `_${char.toLowerCase()}`); | ||
const camelCase = (s) => s.replace(/_[a-z]/g, underscoreChar => underscoreChar[1].toUpperCase()); | ||
const snakeCase = (camelCaseString) => camelCaseString.replace(/[A-Z]/g, char => `_${char.toLowerCase()}`); | ||
const camelCase = (snakeCaseString) => snakeCaseString | ||
.replace(/_[0-9]/g, underscoreDigit => underscoreDigit[1]) | ||
.replace(/_[a-z]/g, underscoreChar => underscoreChar[1].toUpperCase()); | ||
const deepMapObjectKeys = (value, f) => { | ||
@@ -276,2 +278,5 @@ if (!(value instanceof Object)) { | ||
} | ||
async download(id) { | ||
return super.download(`${id}/download`); | ||
} | ||
} | ||
@@ -412,16 +417,13 @@ | ||
})(Region || (Region = {})); | ||
const apiUrls = { | ||
[Region.EU]: "https://api.onfido.com/v3/", | ||
[Region.US]: "https://api.us.onfido.com/v3/", | ||
[Region.CA]: "https://api.ca.onfido.com/v3/" | ||
}; | ||
class Onfido { | ||
constructor({ apiToken, region = Region.EU, timeout = 30000, unknownApiUrl }) { | ||
constructor({ apiToken, region, timeout = 30000, unknownApiUrl }) { | ||
if (!apiToken) { | ||
throw new Error("No apiToken provided"); | ||
} | ||
const regionUrl = apiUrls[region]; | ||
if (!regionUrl) { | ||
throw new Error("Unknown region " + region); | ||
if (!region || !Object.values(Region).includes(region)) { | ||
throw new Error(`Unknown or missing region '${region}'. ` + | ||
"We previously defaulted to region 'EU', so if you previously didn’t " + | ||
"set a region or used api.onfido.com, please set your region to 'EU'"); | ||
} | ||
const regionUrl = `https://api.${region.toLowerCase()}.onfido.com/v3.1/`; | ||
this.axiosInstance = axios.create({ | ||
@@ -428,0 +430,0 @@ baseURL: unknownApiUrl || regionUrl, |
@@ -10,3 +10,3 @@ 'use strict'; | ||
var version = "1.6.0"; | ||
var version = "2.0.0"; | ||
@@ -74,4 +74,6 @@ class OnfidoError extends Error { | ||
const FormData = require("form-data"); | ||
const snakeCase = (s) => s.replace(/[A-Z]/g, char => `_${char.toLowerCase()}`); | ||
const camelCase = (s) => s.replace(/_[a-z]/g, underscoreChar => underscoreChar[1].toUpperCase()); | ||
const snakeCase = (camelCaseString) => camelCaseString.replace(/[A-Z]/g, char => `_${char.toLowerCase()}`); | ||
const camelCase = (snakeCaseString) => snakeCaseString | ||
.replace(/_[0-9]/g, underscoreDigit => underscoreDigit[1]) | ||
.replace(/_[a-z]/g, underscoreChar => underscoreChar[1].toUpperCase()); | ||
const deepMapObjectKeys = (value, f) => { | ||
@@ -283,2 +285,5 @@ if (!(value instanceof Object)) { | ||
} | ||
async download(id) { | ||
return super.download(`${id}/download`); | ||
} | ||
} | ||
@@ -418,16 +423,13 @@ | ||
})(exports.Region || (exports.Region = {})); | ||
const apiUrls = { | ||
[exports.Region.EU]: "https://api.onfido.com/v3/", | ||
[exports.Region.US]: "https://api.us.onfido.com/v3/", | ||
[exports.Region.CA]: "https://api.ca.onfido.com/v3/" | ||
}; | ||
class Onfido { | ||
constructor({ apiToken, region = exports.Region.EU, timeout = 30000, unknownApiUrl }) { | ||
constructor({ apiToken, region, timeout = 30000, unknownApiUrl }) { | ||
if (!apiToken) { | ||
throw new Error("No apiToken provided"); | ||
} | ||
const regionUrl = apiUrls[region]; | ||
if (!regionUrl) { | ||
throw new Error("Unknown region " + region); | ||
if (!region || !Object.values(exports.Region).includes(region)) { | ||
throw new Error(`Unknown or missing region '${region}'. ` + | ||
"We previously defaulted to region 'EU', so if you previously didn’t " + | ||
"set a region or used api.onfido.com, please set your region to 'EU'"); | ||
} | ||
const regionUrl = `https://api.${region.toLowerCase()}.onfido.com/v3.1/`; | ||
this.axiosInstance = axios.create({ | ||
@@ -434,0 +436,0 @@ baseURL: unknownApiUrl || regionUrl, |
@@ -19,3 +19,3 @@ import { AxiosInstance } from "axios"; | ||
apiToken: string; | ||
region?: Region; | ||
region: Region; | ||
timeout?: number; | ||
@@ -22,0 +22,0 @@ unknownApiUrl?: string; |
import { AxiosInstance } from "axios"; | ||
import { OnfidoDownload } from "../OnfidoDownload"; | ||
import { Resource } from "../Resource"; | ||
@@ -13,2 +14,3 @@ export declare type CheckRequest = { | ||
privacyNoticesReadConsentGiven?: boolean; | ||
webhookIds?: string[] | null; | ||
}; | ||
@@ -28,2 +30,4 @@ export declare type Check = { | ||
resultsUri: string; | ||
privacyNoticesReadConsentGiven: boolean; | ||
webhookIds: string[] | null; | ||
}; | ||
@@ -36,2 +40,3 @@ export declare class Checks extends Resource<CheckRequest> { | ||
resume(id: string): Promise<void>; | ||
download(id: string): Promise<OnfidoDownload>; | ||
} |
{ | ||
"name": "@onfido/api", | ||
"version": "1.6.0", | ||
"version": "2.0.0", | ||
"description": "Node.js library for the Onfido API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -9,2 +9,4 @@ # Onfido Node.js Library | ||
This version uses Onfido API v3.1. 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. | ||
## Installation | ||
@@ -38,9 +40,9 @@ | ||
Configure with your API token, and region if necessary: | ||
Configure with your API token and region: | ||
```js | ||
const onfido = new Onfido({ | ||
apiToken: process.env.ONFIDO_API_TOKEN | ||
// Defaults to Region.EU (api.onfido.com), supports Region.US and Region.CA | ||
// region: Region.US | ||
apiToken: process.env.ONFIDO_API_TOKEN, | ||
// Supports Region.EU, Region.US and Region.CA | ||
region: Region.EU | ||
}); | ||
@@ -47,0 +49,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
134517
1366
189