From 037ca013d477a32e22462b1a45fb735c2280eae9 Mon Sep 17 00:00:00 2001 From: Michael Mok Date: Wed, 6 Apr 2022 12:38:50 +0200 Subject: [PATCH] chore: release v3.1.0 (#43) --- package.json | 8 ++++---- src/bankid.ts | 42 ++++++++++++++++++++++++++---------------- tsconfig.json | 2 +- yarn.lock | 40 ++++++++++++++++++++-------------------- 4 files changed, 51 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 79f56cc..d67933f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bankid", "authentication" ], - "version": "3.0.0", + "version": "3.1.0", "main": "lib/bankid.js", "repository": { "type": "git", @@ -24,11 +24,11 @@ "url": "https://github.com/anyfin/bankid/issues" }, "dependencies": { - "axios": "^0.21.1" + "axios": "^0.26.1" }, "devDependencies": { - "@types/node": "^14.14.22", - "typescript": "^4.1.3", + "@types/node": "^14.18.12", + "typescript": "4.6.3", "prettier": "^2.2.1" }, "peerDependencies": { diff --git a/src/bankid.ts b/src/bankid.ts index 763d3ff..3f626cf 100644 --- a/src/bankid.ts +++ b/src/bankid.ts @@ -2,7 +2,8 @@ import * as fs from "fs"; import * as https from "https"; import * as path from "path"; -import axios, { AxiosError, AxiosInstance } from "axios"; +import type { AxiosInstance } from "axios"; +import axios from "axios"; // // Type definitions for /auth @@ -35,6 +36,7 @@ interface AuthOptionalRequirements { export interface SignRequest extends AuthRequest { userVisibleData: string; + userVisibleDataFormat?: "simpleMarkdownV1"; userNonVisibleData?: string; } @@ -200,7 +202,7 @@ export class BankIdClient { if (this.options.production) { if (!options?.pfx || !options?.passphrase) { - throw Error( + throw new Error( "BankId requires the pfx and passphrase in production mode", ); } @@ -235,7 +237,7 @@ export class BankIdClient { authenticate(parameters: AuthRequest): Promise { if (!parameters.endUserIp) { - throw Error("Missing required argument endUserIp."); + throw new Error("Missing required argument endUserIp."); } return this._call(BankIdMethod.auth, parameters); @@ -243,7 +245,15 @@ export class BankIdClient { sign(parameters: SignRequest): Promise { if (!parameters.endUserIp || !parameters.userVisibleData) { - throw Error("Missing required arguments: endUserIp, userVisibleData."); + throw new Error( + "Missing required arguments: endUserIp, userVisibleData.", + ); + } + if ( + parameters.userVisibleDataFormat != null && + parameters.userVisibleDataFormat !== "simpleMarkdownV1" + ) { + throw new Error("userVisibleDataFormat can only be simpleMarkdownV1."); } parameters = { @@ -318,18 +328,18 @@ export class BankIdClient { .then(response => { resolve(response.data); }) - .catch((error: AxiosError) => { - let thrownError; - - if (error.response) { - thrownError = new BankIdError( - error.response.data.errorCode, - error.response.data.details, - ); - } else if (error.request) { - thrownError = new RequestError(error.request); - } else { - thrownError = error; + .catch((error: unknown) => { + let thrownError = error; + + if (axios.isAxiosError(error)) { + if (error.response) { + thrownError = new BankIdError( + error.response.data.errorCode, + error.response.data.details, + ); + } else if (error.request) { + thrownError = new RequestError(error.request); + } } reject(thrownError); diff --git a/tsconfig.json b/tsconfig.json index b3505be..f7aec93 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,6 @@ "strict": true, "target": "ES2018" }, - "include": ["src/**/*"], + "include": ["src"], "exclude": ["node_modules", "**/*.spec.ts"] } diff --git a/yarn.lock b/yarn.lock index d29c6ec..459f156 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,29 +2,29 @@ # yarn lockfile v1 -"@types/node@^14.14.22": - version "14.14.22" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.22.tgz#0d29f382472c4ccf3bd96ff0ce47daf5b7b84b18" - integrity sha512-g+f/qj/cNcqKkc3tFqlXOYjrmZA+jNBiDzbP3kH+B+otKFqAdPgVTGP1IeKRdMml/aE69as5S4FqtxAbl+LaMw== +"@types/node@^14.18.12": + version "14.18.12" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.12.tgz#0d4557fd3b94497d793efd4e7d92df2f83b4ef24" + integrity sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A== -axios@^0.21.1: - version "0.21.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.2.tgz#21297d5084b2aeeb422f5d38e7be4fbb82239017" - integrity sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg== +axios@^0.26.1: + version "0.26.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9" + integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA== dependencies: - follow-redirects "^1.14.0" + follow-redirects "^1.14.8" -follow-redirects@^1.14.0: - version "1.14.8" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc" - integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA== +follow-redirects@^1.14.8: + version "1.14.9" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" + integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w== prettier@^2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5" - integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== + version "2.6.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032" + integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew== -typescript@^4.1.3: - version "4.1.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" - integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== +typescript@4.6.3: + version "4.6.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.3.tgz#eefeafa6afdd31d725584c67a0eaba80f6fc6c6c" + integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==