idea-html2pdf
Advanced tools
Comparing version 2.0.8 to 2.1.0
@@ -43,3 +43,3 @@ /// <reference types="node" /> | ||
*/ | ||
createViaS3Bucket(params: HTML2PDFCreateViaS3BucketParameters): Promise<Buffer>; | ||
createViaS3Bucket(params: HTML2PDFCreateViaS3BucketParameters): Promise<any>; | ||
/** | ||
@@ -46,0 +46,0 @@ * Create the signedURL to a new PDF created by an HTML source. |
@@ -27,7 +27,10 @@ "use strict"; | ||
exports.PDF_DEFAULT_TEMPLATE = exports.HTML2PDF = void 0; | ||
const aws_sdk_1 = require("aws-sdk"); | ||
const client_s3_1 = require("@aws-sdk/client-s3"); | ||
const lib_storage_1 = require("@aws-sdk/lib-storage"); | ||
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner"); | ||
const client_lambda_1 = require("@aws-sdk/client-lambda"); | ||
const Handlebars = __importStar(require("handlebars")); | ||
const idea_toolbox_1 = require("idea-toolbox"); | ||
const s3 = new aws_sdk_1.S3({ apiVersion: '2006-03-01', signatureVersion: 'v4' }); | ||
const lambda = new aws_sdk_1.Lambda(); | ||
const s3 = new client_s3_1.S3Client(); | ||
const lambda = new client_lambda_1.LambdaClient(); | ||
/** | ||
@@ -37,2 +40,3 @@ * A custom class that takes advantage of the `idea_html2pdf` Lambda function to easily manage the creation of PDFs. | ||
class HTML2PDF { | ||
options; | ||
constructor(options = {}) { | ||
@@ -122,10 +126,9 @@ this.options = options; | ||
try { | ||
const result = await lambda | ||
.invoke({ | ||
const command = new client_lambda_1.InvokeCommand({ | ||
FunctionName: this.options.lambdaFnName, | ||
InvocationType: 'RequestResponse', | ||
Payload: JSON.stringify(params) | ||
}) | ||
.promise(); | ||
return Buffer.from(result.Payload, 'base64'); | ||
}); | ||
const { Payload } = await lambda.send(command); | ||
return Buffer.from(Payload.transformToString(), 'base64'); | ||
} | ||
@@ -146,12 +149,12 @@ catch (err) { | ||
try { | ||
const result = await lambda | ||
.invoke({ | ||
const invokeCommand = new client_lambda_1.InvokeCommand({ | ||
FunctionName: this.options.lambdaFnViaS3BucketName, | ||
InvocationType: 'RequestResponse', | ||
Payload: JSON.stringify(params) | ||
}) | ||
.promise(); | ||
const s3params = JSON.parse(result.Payload); | ||
const s3Obj = await s3.getObject(s3params).promise(); | ||
return s3Obj.Body; | ||
}); | ||
const { Payload } = await lambda.send(invokeCommand); | ||
const s3params = JSON.parse(Payload.transformToString()); | ||
const getObjCommand = new client_s3_1.GetObjectCommand(s3params); | ||
const { Body } = await s3.send(getObjCommand); | ||
return Buffer.from(await Body.transformToString(), 'base64'); | ||
} | ||
@@ -170,7 +173,9 @@ catch (err) { | ||
const pdfData = await this.create(params); | ||
const Bucket = params.s3Bucket; | ||
const Key = params.s3Prefix.concat('/', new Date().getTime().toString().concat(Math.random().toString(36).slice(2)), '.pdf'); | ||
const Bucket = params.s3Bucket; | ||
const Expires = 120; | ||
await s3.upload({ Bucket, Key, Body: pdfData }).promise(); | ||
return new idea_toolbox_1.SignedURL({ url: s3.getSignedUrl('getObject', { Bucket, Key, Expires }) }); | ||
const upload = new lib_storage_1.Upload({ client: s3, params: { Bucket, Key, Body: pdfData } }); | ||
await upload.done(); | ||
const getCommand = new client_s3_1.GetObjectCommand({ Bucket, Key }); | ||
const url = await (0, s3_request_presigner_1.getSignedUrl)(s3, getCommand, { expiresIn: 120 }); | ||
return new idea_toolbox_1.SignedURL({ url }); | ||
} | ||
@@ -177,0 +182,0 @@ } |
{ | ||
"name": "idea-html2pdf", | ||
"version": "2.0.8", | ||
"version": "2.1.0", | ||
"description": "IDEA helper for generating a PDF from HTML contents", | ||
@@ -35,15 +35,17 @@ "engines": { | ||
"handlebars": "^4.7.8", | ||
"idea-toolbox": "^6.7.3" | ||
"idea-toolbox": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/node16": "^1.0.3", | ||
"@types/aws-lambda": "^8.10.101", | ||
"@types/node": "^18.6.3", | ||
"@typescript-eslint/eslint-plugin": "^5.32.0", | ||
"@typescript-eslint/parser": "^5.32.0", | ||
"aws-sdk": "^2.1187.0", | ||
"eslint": "^8.21.0", | ||
"typedoc": "^0.23.10", | ||
"typescript": "^4.7.4" | ||
"@aws-sdk/client-lambda": "^3.388.0", | ||
"@aws-sdk/client-s3": "^3.388.0", | ||
"@aws-sdk/lib-storage": "^3.388.0", | ||
"@aws-sdk/s3-request-presigner": "^3.388.0", | ||
"@tsconfig/node18": "^18.2.0", | ||
"@types/node": "^18.17.4", | ||
"@typescript-eslint/eslint-plugin": "^5.47.0", | ||
"@typescript-eslint/parser": "^5.47.0", | ||
"eslint": "^8.46.0", | ||
"typedoc": "^0.24.8", | ||
"typescript": "^5.1.6" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27297
536
11
+ Addedidea-toolbox@7.0.9(transitive)
+ Addedmarked@13.0.3(transitive)
- Removedidea-toolbox@6.7.3(transitive)
- Removedmarked@4.3.0(transitive)
Updatedidea-toolbox@^7.0.0