Skip to content

Commit

Permalink
nv: link up
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeri Buchinski committed Oct 3, 2023
1 parent 0d34ea5 commit ae0ec37
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
72 changes: 72 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "@signpdf/utils",
"version": "3.0.0",
"description": "Utilities for the @signpdf packages.",
"repository": {
"type": "git",
"url": "https://github.com/vbuch/node-signpdf"
},
"license": "MIT",
"keywords": [
"sign",
"pdf",
"node",
"nodejs",
"esign",
"adobe",
"ppklite",
"sign detached",
"pkcs7",
"pkcs#7",
"pades",
"digital signature"
],
"main": "dist/signpdf.js",
"files": [
"dist",
"LICENSE",
"README.md"
],
"engines": {
"node": ">=12"
},
"scripts": {
"test:coverage": "./node_modules/.bin/jest --coverage",
"test": "./node_modules/.bin/jest",
"test:watch": "./node_modules/.bin/jest --watch",
"build": "rm -rf ./dist/* & ./node_modules/.bin/babel ./src -d ./dist --ignore \"**/*.test.js\" & tsc",
"build:watch": "./node_modules/.bin/babel --watch ./src -d ./dist --ignore \"**/*.test.js\"",
"lint": "./node_modules/.bin/eslint -c .eslintrc --ignore-path .eslintignore ./",
"prepare": "husky install"
},
"peerDependencies": {
"node-forge": "^1.2.1"
},
"devDependencies": {
"@signpdf/signpdf": "workspace:^",
"@signpdf/placeholder-pdfkit10": "workspace:^",

"@babel/cli": "^7.0.0",
"@babel/core": "^7.4.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/node": "^7.0.0",
"@babel/plugin-syntax-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.4.2",
"@types/node": ">=12.0.0",
"@types/node-forge": "^1.2.1",
"assertion-error": "^1.1.0",
"babel-jest": "^27.3.1",
"babel-plugin-module-resolver": "^3.1.1",
"coveralls": "^3.0.2",
"eslint": "^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.2.4",
"husky": "^7.0.4",
"jest": "^27.3.1",
"node-forge": "^1.2.1",
"pdfkit": "^0.10.0",
"typescript": "^5.2.2"
}
}
19 changes: 19 additions & 0 deletions packages/utils/src/SignPdfError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const ERROR_TYPE_UNKNOWN = 1;
export const ERROR_TYPE_INPUT = 2;
export const ERROR_TYPE_PARSE = 3;
export const ERROR_VERIFY_SIGNATURE = 4;

class SignPdfError extends Error {
constructor(msg, type = ERROR_TYPE_UNKNOWN) {
super(msg);
this.type = type;
}
}

// Shorthand
SignPdfError.TYPE_UNKNOWN = ERROR_TYPE_UNKNOWN;
SignPdfError.TYPE_INPUT = ERROR_TYPE_INPUT;
SignPdfError.TYPE_PARSE = ERROR_TYPE_PARSE;
SignPdfError.VERIFY_SIGNATURE = ERROR_VERIFY_SIGNATURE;

export default SignPdfError;
26 changes: 26 additions & 0 deletions packages/utils/src/SignPdfError.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import SignPdfError, {
ERROR_TYPE_UNKNOWN,
ERROR_TYPE_INPUT,
ERROR_TYPE_PARSE,
} from './SignPdfError';

describe('SignPdfError', () => {
it('SignPdfError extends Error', () => {
const instance = new SignPdfError('Whatever message');
expect(instance instanceof Error).toBe(true);
});
it('type defaults to UNKNOWN', () => {
const instance = new SignPdfError('Whatever message');
expect(instance.type).toBe(ERROR_TYPE_UNKNOWN);
});
it('type can be specified', () => {
[
ERROR_TYPE_UNKNOWN,
ERROR_TYPE_INPUT,
ERROR_TYPE_PARSE,
].forEach((type) => {
const instance = new SignPdfError('Whatever message', type);
expect(instance.type).toBe(type);
});
});
});

0 comments on commit ae0ec37

Please sign in to comment.