Skip to content

Commit

Permalink
import using rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaran16 committed Aug 19, 2020
1 parent 12ddeab commit 99fe2af
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -42,6 +42,7 @@
}
},
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@types/jest": "^25.1.4",
"jest": "^25.2.4",
"nock": "^11.7.0",
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.ts
@@ -1,3 +1,4 @@
import json from "@rollup/plugin-json";
import typescript from "rollup-plugin-typescript2";

export default {
Expand All @@ -14,6 +15,6 @@ export default {
sourcemap: true
}
],
plugins: [typescript()],
plugins: [json(), typescript()],
external: ["axios", "form-data", "stream"]
};
5 changes: 2 additions & 3 deletions 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";
Expand Down Expand Up @@ -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
});
Expand Down
7 changes: 2 additions & 5 deletions test/Onfido.test.ts
Expand Up @@ -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+$/
);
});

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -8,7 +8,8 @@
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
"esModuleInterop": true
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": ["src/**/*"]
}
28 changes: 27 additions & 1 deletion yarn.lock
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit 99fe2af

Please sign in to comment.