From 99fe2af1c944e0643a52c4adc3c54ee4ada9aa5c Mon Sep 17 00:00:00 2001 From: Ciaran Lawlor Date: Wed, 19 Aug 2020 16:45:08 +0100 Subject: [PATCH] import using rollup --- package.json | 1 + rollup.config.ts | 3 ++- src/Onfido.ts | 5 ++--- test/Onfido.test.ts | 7 ++----- tsconfig.json | 3 ++- yarn.lock | 28 +++++++++++++++++++++++++++- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index e1d9273..88ea233 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ } }, "devDependencies": { + "@rollup/plugin-json": "^4.1.0", "@types/jest": "^25.1.4", "jest": "^25.2.4", "nock": "^11.7.0", diff --git a/rollup.config.ts b/rollup.config.ts index ccaac78..10f06d2 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -1,3 +1,4 @@ +import json from "@rollup/plugin-json"; import typescript from "rollup-plugin-typescript2"; export default { @@ -14,6 +15,6 @@ export default { sourcemap: true } ], - plugins: [typescript()], + plugins: [json(), typescript()], external: ["axios", "form-data", "stream"] }; diff --git a/src/Onfido.ts b/src/Onfido.ts index 22b28ba..e3ed9bc 100644 --- a/src/Onfido.ts +++ b/src/Onfido.ts @@ -1,4 +1,5 @@ import axios, { AxiosInstance } from "axios"; +import { version } from "../package.json"; import { Addresses } from "./resources/Addresses"; import { Applicants } from "./resources/Applicants"; import { Autofill } from "./resources/Autofill"; @@ -59,14 +60,12 @@ export class Onfido { throw new Error("Unknown region " + region); } - const packageVersion = require("../package.json").version; - this.axiosInstance = axios.create({ baseURL: unknownApiUrl || regionUrl, headers: { Authorization: `Token token=${apiToken}`, Accept: "application/json", - "User-Agent": `onfido-node/${packageVersion}` + "User-Agent": `onfido-node/${version}` }, timeout }); diff --git a/test/Onfido.test.ts b/test/Onfido.test.ts index 5c359a0..2843e34 100644 --- a/test/Onfido.test.ts +++ b/test/Onfido.test.ts @@ -8,12 +8,9 @@ it("sets the authorization header from the given token", () => { }); it("contains a user agent header", () => { - jest.mock("../package.json", () => { - return { version: "1.0.0" }; - }); const onfido = new Onfido({ apiToken: "api_token" }); - expect(onfido.axiosInstance.defaults.headers["User-Agent"]).toBe( - "onfido-node/1.0.0" + expect(onfido.axiosInstance.defaults.headers["User-Agent"]).toMatch( + /^onfido-node\/\d+\.\d+\.\d+$/ ); }); diff --git a/tsconfig.json b/tsconfig.json index 63e0c2e..0a7f15d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,8 @@ "moduleResolution": "node", "sourceMap": true, "declaration": true, - "esModuleInterop": true + "esModuleInterop": true, + "resolveJsonModule": true }, "include": ["src/**/*"] } diff --git a/yarn.lock b/yarn.lock index 840e55a..6040b4d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -502,6 +502,22 @@ "@types/yargs" "^15.0.0" chalk "^3.0.0" +"@rollup/plugin-json@^4.1.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3" + integrity sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw== + dependencies: + "@rollup/pluginutils" "^3.0.8" + +"@rollup/pluginutils@^3.0.8": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" + integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== + dependencies: + "@types/estree" "0.0.39" + estree-walker "^1.0.1" + picomatch "^2.2.2" + "@sinonjs/commons@^1.7.0": version "1.7.1" resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1" @@ -552,6 +568,11 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.40.tgz#0e6cb9b9bbd098031fa19e4b4e8131bc70e5de13" integrity sha512-p3KZgMto/JyxosKGmnLDJ/dG5wf+qTRMUjHJcspC2oQKa4jP7mz+tv0ND56lLBu3ojHlhzY33Ol+khLyNmilkA== +"@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff" @@ -1303,6 +1324,11 @@ estree-walker@^0.6.1: resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362" integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w== +estree-walker@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" + integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== + esutils@^2.0.2: version "2.0.3" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" @@ -2815,7 +2841,7 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= -picomatch@^2.0.4, picomatch@^2.0.5: +picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.2: version "2.2.2" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad" integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==