fix(core): update

This commit is contained in:
Philipp Kunz 2018-10-06 17:35:26 +02:00
parent 665bcba84e
commit da421e29be
6 changed files with 55 additions and 57 deletions

View File

@ -1,8 +1,6 @@
{ {
"npmci": { "npmci": {
"npmGlobalTools": [ "npmGlobalTools": [],
"@gitzone/npmts", "npmAccessLevel": "public"
"ts-node"
]
} }
} }

42
package-lock.json generated
View File

@ -1,5 +1,5 @@
{ {
"name": "smartpdf", "name": "@pushrocks/smartpdf",
"version": "1.0.1", "version": "1.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
@ -154,6 +154,17 @@
"which": "^1.3.1" "which": "^1.3.1"
} }
}, },
"@pushrocks/smartunique": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@pushrocks/smartunique/-/smartunique-3.0.1.tgz",
"integrity": "sha512-xBu9ZB4C0BA0S/pbFFZn2ItPfnodPKpzrYIq1yN5XDs6OaookwcDF/iBwfS9+EYMSPENC9wAsOxg2RGMm4Qicw==",
"requires": {
"@types/shortid": "^0.0.29",
"@types/uuid": "^3.0.0",
"shortid": "^2.2.8",
"uuid": "^3.1.0"
}
},
"@pushrocks/tapbundle": { "@pushrocks/tapbundle": {
"version": "3.0.7", "version": "3.0.7",
"resolved": "https://registry.npmjs.org/@pushrocks/tapbundle/-/tapbundle-3.0.7.tgz", "resolved": "https://registry.npmjs.org/@pushrocks/tapbundle/-/tapbundle-3.0.7.tgz",
@ -266,9 +277,9 @@
"integrity": "sha512-ojnbBiKkZFYRfQpmtnnWTMw+rzGp/JiystjluW9jgN3VzRwilXddJ6aGQ9V/7iuDG06SBgn7ozW9k3zcAnYjYQ==" "integrity": "sha512-ojnbBiKkZFYRfQpmtnnWTMw+rzGp/JiystjluW9jgN3VzRwilXddJ6aGQ9V/7iuDG06SBgn7ozW9k3zcAnYjYQ=="
}, },
"@types/puppeteer": { "@types/puppeteer": {
"version": "1.8.0", "version": "1.9.0",
"resolved": "https://registry.npmjs.org/@types/puppeteer/-/puppeteer-1.8.0.tgz", "resolved": "https://registry.npmjs.org/@types/puppeteer/-/puppeteer-1.9.0.tgz",
"integrity": "sha512-YR6aEjBY87BNj3k8wrtieU39ljyVAceKqO08fI9EMBDkYu5Sp6vioTKiAIsrNqDyB0u249lqLmmhwwq6qLNqww==", "integrity": "sha512-ZP3wL4Lqpgu4xZbz/0vQhbIZnllNEawVW3oTpEXyJg+uhf/YQgL8oeTrfoUwj9JXE9UUe53eqmgLl29/d2gjqQ==",
"requires": { "requires": {
"@types/node": "*" "@types/node": "*"
} }
@ -1148,9 +1159,9 @@
"integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=" "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4="
}, },
"puppeteer": { "puppeteer": {
"version": "1.8.0", "version": "1.9.0",
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.8.0.tgz", "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.9.0.tgz",
"integrity": "sha512-wJ7Fxs03l4dy/ZXQACUKBBobIuJaS4NHq44q7/QinpAXFMwJMJFEIPjzoksVzUhZxQe+RXnjXH69mg13yMh0BA==", "integrity": "sha512-GH4PmhJf9wBRAPvtJkEJLAvdNNOofZortmBZSj8cGWYni98GUFqsf66blOEfJbo5B8l0KG5HR2d/W2MejnUrzg==",
"requires": { "requires": {
"debug": "^3.1.0", "debug": "^3.1.0",
"extract-zip": "^1.6.6", "extract-zip": "^1.6.6",
@ -1326,18 +1337,6 @@
"chai-string": "^1.4.0" "chai-string": "^1.4.0"
} }
}, },
"smartunique": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/smartunique/-/smartunique-2.0.0.tgz",
"integrity": "sha512-OkJIrjAeH5NBDCrx2mX23huCoQoCCcwIbzznWIYqLn7Q+FezPjGzqGWk62IQJ3OvAGWt3j+INmpZygJks1F5MQ==",
"requires": {
"@types/shortid": "^0.0.29",
"@types/uuid": "^3.0.0",
"shortid": "^2.2.8",
"typings-global": "^1.0.16",
"uuid": "^3.1.0"
}
},
"source-map": { "source-map": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
@ -1464,11 +1463,6 @@
"integrity": "sha512-Veu0w4dTc/9wlWNf2jeRInNodKlcdLgemvPsrNpfu5Pq39sgfFjvIIgTsvUHCoLBnMhPoUA+tFxsXjU6VexVRQ==", "integrity": "sha512-Veu0w4dTc/9wlWNf2jeRInNodKlcdLgemvPsrNpfu5Pq39sgfFjvIIgTsvUHCoLBnMhPoUA+tFxsXjU6VexVRQ==",
"dev": true "dev": true
}, },
"typings-global": {
"version": "1.0.28",
"resolved": "https://registry.npmjs.org/typings-global/-/typings-global-1.0.28.tgz",
"integrity": "sha512-6VOwJWEY2971HOMHu/7sURzUXiD4/LiMJPsMAOqkHHAtS3MVpLFE5gzTiHilsH9KY5VE1mBQirWIgWFsDuo90A=="
},
"universalify": { "universalify": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",

View File

@ -1,14 +1,16 @@
{ {
"name": "smartpdf", "name": "@pushrocks/smartpdf",
"version": "1.0.1", "version": "1.0.1",
"private": false,
"description": "create pdfs on the fly", "description": "create pdfs on the fly",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "tstest test/", "test": "(tstest test/)",
"format": "(gitzone format)" "format": "(gitzone format)",
"build": "(tsbuild)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.0.22",
@ -21,10 +23,10 @@
"@pushrocks/smartfile": "^6.0.8", "@pushrocks/smartfile": "^6.0.8",
"@pushrocks/smartnetwork": "^1.1.0", "@pushrocks/smartnetwork": "^1.1.0",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartunique": "^3.0.1",
"@types/express": "^4.16.0", "@types/express": "^4.16.0",
"@types/puppeteer": "^1.8.0", "@types/puppeteer": "^1.9.0",
"express": "^4.16.3", "express": "^4.16.3",
"puppeteer": "^1.8.0", "puppeteer": "^1.9.0"
"smartunique": "^2.0.0"
} }
} }

View File

@ -1,12 +1,12 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartpdf from '../ts/index' import * as smartpdf from '../ts/index';
let testSmartPdf: smartpdf.SmartPdf; let testSmartPdf: smartpdf.SmartPdf;
tap.test('should create a valid instance of smartpdf', async () => { tap.test('should create a valid instance of smartpdf', async () => {
testSmartPdf = new smartpdf.SmartPdf(); testSmartPdf = new smartpdf.SmartPdf();
expect(testSmartPdf).to.be.instanceof(smartpdf.SmartPdf); expect(testSmartPdf).to.be.instanceof(smartpdf.SmartPdf);
}) });
tap.test('should create a pdf from html string', async () => { tap.test('should create a pdf from html string', async () => {
await testSmartPdf.getPdfForHtmlString('hi'); await testSmartPdf.getPdfForHtmlString('hi');
@ -16,4 +16,8 @@ tap.test('should create a pdf from website', async () => {
await testSmartPdf.getPdfForWebsite('https://wikipedia.org'); await testSmartPdf.getPdfForWebsite('https://wikipedia.org');
}); });
tap.start() tap.test('should be able to close properly', async () => {
await testSmartPdf.close();
});
tap.start();

View File

@ -8,7 +8,7 @@ export class SmartPdf {
serverPort: number; serverPort: number;
headlessBrowser: plugins.puppeteer.Browser; headlessBrowser: plugins.puppeteer.Browser;
private _readyDeferred: plugins.smartpromise.Deferred<void>; private _readyDeferred: plugins.smartpromise.Deferred<void>;
private _candidates: {[key: string]: PdfCandidate} = {}; private _candidates: { [key: string]: PdfCandidate } = {};
constructor() { constructor() {
this._readyDeferred = new plugins.smartpromise.Deferred(); this._readyDeferred = new plugins.smartpromise.Deferred();
@ -34,6 +34,15 @@ export class SmartPdf {
}); });
} }
async close () {
const done = plugins.smartpromise.defer<void>();
this.htmlServerInstance.close(() => {
done.resolve();
});
await this.headlessBrowser.close();
await done.promise;
}
/** /**
* returns a pdf for a given html string; * returns a pdf for a given html string;
*/ */
@ -42,15 +51,17 @@ export class SmartPdf {
const pdfCandidate = new PdfCandidate(htmlStringArg); const pdfCandidate = new PdfCandidate(htmlStringArg);
this._candidates[pdfCandidate.pdfId] = pdfCandidate; this._candidates[pdfCandidate.pdfId] = pdfCandidate;
const page = await this.headlessBrowser.newPage(); const page = await this.headlessBrowser.newPage();
const response = await page.goto(`http://localhost:3210/${pdfCandidate.pdfId}`, { waitUntil: 'networkidle2' }); const response = await page.goto(`http://localhost:3210/${pdfCandidate.pdfId}`, {
waitUntil: 'networkidle2'
});
const headers = response.headers(); const headers = response.headers();
if(headers['pdf-id'] !== pdfCandidate.pdfId) { if (headers['pdf-id'] !== pdfCandidate.pdfId) {
console.log('Error! Headers do not match. For security reasons no pdf is being emitted!'); console.log('Error! Headers do not match. For security reasons no pdf is being emitted!');
return return;
} else { } else {
console.log(`id security check passed for ${pdfCandidate.pdfId}`); console.log(`id security check passed for ${pdfCandidate.pdfId}`);
} }
await page.pdf({ await page.pdf({
path: plugins.path.join(paths.pdfDir, `${pdfCandidate.pdfId}.pdf`), path: plugins.path.join(paths.pdfDir, `${pdfCandidate.pdfId}.pdf`),
format: 'A4' format: 'A4'

View File

@ -2,29 +2,18 @@
import * as http from 'http'; import * as http from 'http';
import * as path from 'path'; import * as path from 'path';
export { export { http, path };
http,
path
}
// @pushrocks // @pushrocks
import * as smartfile from '@pushrocks/smartfile'; import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartnetwork from '@pushrocks/smartnetwork'; import * as smartnetwork from '@pushrocks/smartnetwork';
import * as smartunique from 'smartunique'; import * as smartunique from '@pushrocks/smartunique';
export { export { smartfile, smartpromise, smartunique, smartnetwork };
smartfile,
smartpromise,
smartunique,
smartnetwork
}
// thirdparty // thirdparty
import * as express from 'express'; import * as express from 'express';
import * as puppeteer from 'puppeteer'; import * as puppeteer from 'puppeteer';
export { export { express, puppeteer };
express,
puppeteer
}