@things-factory/integration-headless 9.0.0-beta.27 → 9.0.0-beta.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/engine/index.d.ts +1 -0
- package/dist-server/engine/index.js +4 -0
- package/dist-server/engine/index.js.map +1 -0
- package/dist-server/engine/task/headless-pdf-capture-board.d.ts +59 -0
- package/dist-server/engine/task/headless-pdf-capture-board.js +146 -0
- package/dist-server/engine/task/headless-pdf-capture-board.js.map +1 -0
- package/dist-server/engine/task/headless-pdf-capture-markdown.d.ts +52 -0
- package/dist-server/engine/task/headless-pdf-capture-markdown.js +44 -0
- package/dist-server/engine/task/headless-pdf-capture-markdown.js.map +1 -0
- package/dist-server/engine/task/headless-pdf-capture.d.ts +52 -0
- package/dist-server/engine/task/headless-pdf-capture.js +36 -0
- package/dist-server/engine/task/headless-pdf-capture.js.map +1 -0
- package/dist-server/engine/task/headless-pdf-open.d.ts +1 -0
- package/dist-server/engine/task/headless-pdf-open.js +88 -0
- package/dist-server/engine/task/headless-pdf-open.js.map +1 -0
- package/dist-server/engine/task/headless-pdf-save.d.ts +1 -0
- package/dist-server/engine/task/headless-pdf-save.js +70 -0
- package/dist-server/engine/task/headless-pdf-save.js.map +1 -0
- package/dist-server/engine/task/index.d.ts +8 -0
- package/dist-server/engine/task/index.js +12 -0
- package/dist-server/engine/task/index.js.map +1 -0
- package/dist-server/engine/task/pdf-capture-util.d.ts +96 -0
- package/dist-server/engine/task/pdf-capture-util.js +262 -0
- package/dist-server/engine/task/pdf-capture-util.js.map +1 -0
- package/dist-server/index.d.ts +2 -0
- package/dist-server/index.js +6 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +6 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './task';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/engine/index.ts"],"names":[],"mappings":";;AAAA,kBAAe","sourcesContent":["import './task'\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare function HeadlessPDFCaptureBoard(step: any, context: any): Promise<{
|
|
2
|
+
data: any;
|
|
3
|
+
}>;
|
|
4
|
+
export declare namespace HeadlessPDFCaptureBoard {
|
|
5
|
+
var parameterSpec: ({
|
|
6
|
+
type: string;
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
property?: undefined;
|
|
10
|
+
description?: undefined;
|
|
11
|
+
placeholder?: undefined;
|
|
12
|
+
defaultValue?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
type: string;
|
|
15
|
+
name: string;
|
|
16
|
+
label: string;
|
|
17
|
+
property: {
|
|
18
|
+
options: {
|
|
19
|
+
display: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
description: string;
|
|
24
|
+
placeholder?: undefined;
|
|
25
|
+
defaultValue?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
type: string;
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
placeholder: string;
|
|
31
|
+
description: string;
|
|
32
|
+
property?: undefined;
|
|
33
|
+
defaultValue?: undefined;
|
|
34
|
+
} | {
|
|
35
|
+
type: string;
|
|
36
|
+
name: string;
|
|
37
|
+
label: string;
|
|
38
|
+
defaultValue: number;
|
|
39
|
+
description: string;
|
|
40
|
+
property?: undefined;
|
|
41
|
+
placeholder?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
type: string;
|
|
44
|
+
name: string;
|
|
45
|
+
label: string;
|
|
46
|
+
defaultValue: boolean;
|
|
47
|
+
description: string;
|
|
48
|
+
property?: undefined;
|
|
49
|
+
placeholder?: undefined;
|
|
50
|
+
} | {
|
|
51
|
+
type: string;
|
|
52
|
+
name: string;
|
|
53
|
+
label: string;
|
|
54
|
+
property: {
|
|
55
|
+
queryName: string;
|
|
56
|
+
};
|
|
57
|
+
})[];
|
|
58
|
+
var help: string;
|
|
59
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeadlessPDFCaptureBoard = HeadlessPDFCaptureBoard;
|
|
4
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
5
|
+
const pdf_capture_util_1 = require("./pdf-capture-util");
|
|
6
|
+
const board_service_1 = require("@things-factory/board-service");
|
|
7
|
+
const utils_1 = require("@things-factory/utils");
|
|
8
|
+
const PAGE_FORMATS = {
|
|
9
|
+
A4: { width: 595.28, height: 841.89 },
|
|
10
|
+
A3: { width: 841.89, height: 1190.55 },
|
|
11
|
+
Letter: { width: 612, height: 792 },
|
|
12
|
+
Legal: { width: 612, height: 1008 }
|
|
13
|
+
};
|
|
14
|
+
function convertToPixels(value) {
|
|
15
|
+
const dpi = 96; // PDF에서 기본적으로 사용하는 DPI
|
|
16
|
+
if (value.endsWith('px')) {
|
|
17
|
+
return parseFloat(value);
|
|
18
|
+
}
|
|
19
|
+
else if (value.endsWith('in')) {
|
|
20
|
+
const inches = parseFloat(value);
|
|
21
|
+
return inches * dpi;
|
|
22
|
+
}
|
|
23
|
+
else if (value.endsWith('cm')) {
|
|
24
|
+
const cm = parseFloat(value);
|
|
25
|
+
return cm * (dpi / 2.54);
|
|
26
|
+
}
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
async function HeadlessPDFCaptureBoard(step, context) {
|
|
30
|
+
const pdfUtil = new pdf_capture_util_1.PDFCaptureUtil(context);
|
|
31
|
+
await pdfUtil.initBrowser(step.connection);
|
|
32
|
+
try {
|
|
33
|
+
var { board: boardObject, accessor, boardAccessor, draft, format = 'A4', width, height, landscape, marginLeft = 0, marginRight = 0, marginTop = 0, marginBottom = 0 } = step.params;
|
|
34
|
+
var { domain, data, user, logger } = context;
|
|
35
|
+
const boardId = boardAccessor ? (0, utils_1.access)(boardAccessor, data) : boardObject === null || boardObject === void 0 ? void 0 : boardObject.id;
|
|
36
|
+
if (!boardId) {
|
|
37
|
+
throw new Error('The board property must be set');
|
|
38
|
+
}
|
|
39
|
+
const boardInput = (0, utils_1.access)(accessor, data);
|
|
40
|
+
const { model, base } = await board_service_1.BoardFunc.headlessModel({ domain, id: boardId }, draft);
|
|
41
|
+
const [fontsToUse, fontStyles] = await board_service_1.BoardFunc.fonts(domain);
|
|
42
|
+
model.fonts = fontsToUse;
|
|
43
|
+
model.fontStyles = fontStyles;
|
|
44
|
+
var widthN = width ? convertToPixels(width) : 0;
|
|
45
|
+
var heightN = height ? convertToPixels(height) : 0;
|
|
46
|
+
if (!widthN && !heightN && PAGE_FORMATS[format]) {
|
|
47
|
+
const pageDimensions = PAGE_FORMATS[format];
|
|
48
|
+
widthN = pageDimensions.width * (96 / 72);
|
|
49
|
+
heightN = pageDimensions.height * (96 / 72);
|
|
50
|
+
}
|
|
51
|
+
if (landscape && widthN && heightN) {
|
|
52
|
+
;
|
|
53
|
+
[widthN, heightN] = [heightN, widthN];
|
|
54
|
+
}
|
|
55
|
+
marginLeft = convertToPixels(marginLeft);
|
|
56
|
+
marginTop = convertToPixels(marginTop);
|
|
57
|
+
marginBottom = convertToPixels(marginBottom);
|
|
58
|
+
marginRight = convertToPixels(marginRight);
|
|
59
|
+
const contentWidth = widthN - marginLeft - marginRight;
|
|
60
|
+
const contentHeight = heightN - marginTop - marginBottom;
|
|
61
|
+
const page = await pdfUtil.browser.newPage();
|
|
62
|
+
await page.setViewport({ width: Math.round(contentWidth), height: Math.round(contentHeight) });
|
|
63
|
+
await page.setRequestInterception(true);
|
|
64
|
+
await page.setDefaultTimeout(10000);
|
|
65
|
+
page.on('console', async (msg) => {
|
|
66
|
+
console.log(`[browser ${msg.type()}] ${msg.text()}`);
|
|
67
|
+
});
|
|
68
|
+
page.on('requestfailed', request => {
|
|
69
|
+
console.log('Request failed:', request.url());
|
|
70
|
+
});
|
|
71
|
+
const protocol = 'http';
|
|
72
|
+
const host = 'localhost';
|
|
73
|
+
const port = process.env.PORT ? `:${process.env.PORT}` : '';
|
|
74
|
+
const path = '/internal-board-service-view';
|
|
75
|
+
const url = `${protocol}://${host}${port}${path}`;
|
|
76
|
+
const token = await (user === null || user === void 0 ? void 0 : user.sign());
|
|
77
|
+
page.on('request', request => {
|
|
78
|
+
if (request.url() === url) {
|
|
79
|
+
request.continue({
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: {
|
|
82
|
+
'Content-Type': 'application/json',
|
|
83
|
+
'x-things-factory-domain': domain === null || domain === void 0 ? void 0 : domain.subdomain,
|
|
84
|
+
Authorization: 'Bearer ' + token
|
|
85
|
+
},
|
|
86
|
+
postData: JSON.stringify({
|
|
87
|
+
model,
|
|
88
|
+
base
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
else if (request.url().startsWith(`${protocol}://${host}${port}`)) {
|
|
93
|
+
request.continue({
|
|
94
|
+
headers: Object.assign(Object.assign({}, request.headers()), { 'x-things-factory-domain': domain === null || domain === void 0 ? void 0 : domain.subdomain, Authorization: 'Bearer ' + token })
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
request.continue();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
await page.goto(url);
|
|
102
|
+
await page.evaluate(data => {
|
|
103
|
+
//@ts-ignore
|
|
104
|
+
s.data = data;
|
|
105
|
+
return new Promise(resolve => {
|
|
106
|
+
requestAnimationFrame(() => resolve(0));
|
|
107
|
+
});
|
|
108
|
+
}, boardInput);
|
|
109
|
+
await pdfUtil.processPageAndGeneratePDF(step.params, null, page);
|
|
110
|
+
return {
|
|
111
|
+
data: context.__headless_pdf
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
await pdfUtil.closeBrowser();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
HeadlessPDFCaptureBoard.parameterSpec = [
|
|
122
|
+
...(0, pdf_capture_util_1.getCommonParameterSpec)(),
|
|
123
|
+
{
|
|
124
|
+
type: 'string',
|
|
125
|
+
name: 'boardAccessor',
|
|
126
|
+
label: 'board-accessor'
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: 'resource-object',
|
|
130
|
+
name: 'board',
|
|
131
|
+
label: 'board',
|
|
132
|
+
property: {
|
|
133
|
+
queryName: 'boards'
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: 'boolean',
|
|
138
|
+
name: 'draft',
|
|
139
|
+
label: 'board-draft',
|
|
140
|
+
defaultValue: false,
|
|
141
|
+
description: 'Set whether to get the current working version or the last released version'
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
HeadlessPDFCaptureBoard.help = 'integration/task/headless-pdf-capture-board';
|
|
145
|
+
integration_base_1.TaskRegistry.registerTaskHandler('headless-pdf-capture-board', HeadlessPDFCaptureBoard);
|
|
146
|
+
//# sourceMappingURL=headless-pdf-capture-board.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless-pdf-capture-board.js","sourceRoot":"","sources":["../../../server/engine/task/headless-pdf-capture-board.ts"],"names":[],"mappings":";;AA4BA,0DA6HC;AAzJD,uEAA+D;AAC/D,yDAA2E;AAC3E,iEAAyD;AACzD,iDAA8C;AAE9C,MAAM,YAAY,GAAG;IACnB,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;IACrC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IACtC,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IACnC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;CACpC,CAAA;AAED,SAAS,eAAe,CAAC,K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AAA;YACb,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;gBAC3B,qBAAqB,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;YACzC,CAAC,CAAC,CAAA;QACJ,CAAC,EAAE,UAAU,CAAC,CAAA;QAEd,MAAM,OAAO,CAAC,yBAAyB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QAEhE,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,cAAc;SAC7B,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAA;IACb,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,YAAY,EAAE,CAAA;IAC9B,CAAC;AACH,CAAC;AAED,uBAAuB,CAAC,aAAa,GAAG;IACtC,GAAG,IAAA,yCAAsB,GAAE;IAC3B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,gBAAgB;KACxB;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;QACd,QAAQ,EAAE;YACR,SAAS,EAAE,QAAQ;SACpB;KACF;IACD;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,aAAa;QACpB,YAAY,EAAE,KAAK;QACnB,WAAW,EAAE,6EAA6E;KAC3F;CACF,CAAA;AAED,uBAAuB,CAAC,IAAI,GAAG,6CAA6C,CAAA;AAE5E,+BAAY,CAAC,mBAAmB,CAAC,4BAA4B,EAAE,uBAAuB,CAAC,CAAA","sourcesContent":["import { TaskRegistry } from '@things-factory/integration-base'\nimport { PDFCaptureUtil, getCommonParameterSpec } from './pdf-capture-util'\nimport { BoardFunc } from '@things-factory/board-service'\nimport { access } from '@things-factory/utils'\n\nconst PAGE_FORMATS = {\n A4: { width: 595.28, height: 841.89 },\n A3: { width: 841.89, height: 1190.55 },\n Letter: { width: 612, height: 792 },\n Legal: { width: 612, height: 1008 }\n}\n\nfunction convertToPixels(value: string): number {\n const dpi = 96 // PDF에서 기본적으로 사용하는 DPI\n\n if (value.endsWith('px')) {\n return parseFloat(value)\n } else if (value.endsWith('in')) {\n const inches = parseFloat(value)\n return inches * dpi\n } else if (value.endsWith('cm')) {\n const cm = parseFloat(value)\n return cm * (dpi / 2.54)\n }\n\n return 0\n}\n\nexport async function HeadlessPDFCaptureBoard(step, context) {\n const pdfUtil = new PDFCaptureUtil(context)\n await pdfUtil.initBrowser(step.connection)\n\n try {\n var {\n board: boardObject,\n accessor,\n boardAccessor,\n draft,\n format = 'A4',\n width,\n height,\n landscape,\n marginLeft = 0,\n marginRight = 0,\n marginTop = 0,\n marginBottom = 0\n } = step.params\n var { domain, data, user, logger } = context\n\n const boardId = boardAccessor ? access(boardAccessor, data) : boardObject?.id\n\n if (!boardId) {\n throw new Error('The board property must be set')\n }\n\n const boardInput = access(accessor, data)\n\n const { model, base } = await BoardFunc.headlessModel({ domain, id: boardId }, draft)\n const [fontsToUse, fontStyles] = await BoardFunc.fonts(domain)\n\n model.fonts = fontsToUse\n model.fontStyles = fontStyles\n\n var widthN = width ? convertToPixels(width) : 0\n var heightN = height ? convertToPixels(height) : 0\n\n if (!widthN && !heightN && PAGE_FORMATS[format]) {\n const pageDimensions = PAGE_FORMATS[format]\n widthN = pageDimensions.width * (96 / 72)\n heightN = pageDimensions.height * (96 / 72)\n }\n\n if (landscape && widthN && heightN) {\n ;[widthN, heightN] = [heightN, widthN]\n }\n\n marginLeft = convertToPixels(marginLeft)\n marginTop = convertToPixels(marginTop)\n marginBottom = convertToPixels(marginBottom)\n marginRight = convertToPixels(marginRight)\n\n const contentWidth = widthN - marginLeft - marginRight\n const contentHeight = heightN - marginTop - marginBottom\n\n const page = await pdfUtil.browser!.newPage()\n\n await page.setViewport({ width: Math.round(contentWidth), height: Math.round(contentHeight) })\n await page.setRequestInterception(true)\n await page.setDefaultTimeout(10000)\n\n page.on('console', async msg => {\n console.log(`[browser ${msg.type()}] ${msg.text()}`)\n })\n\n page.on('requestfailed', request => {\n console.log('Request failed:', request.url())\n })\n\n const protocol = 'http'\n const host = 'localhost'\n const port = process.env.PORT ? `:${process.env.PORT}` : ''\n const path = '/internal-board-service-view'\n const url = `${protocol}://${host}${port}${path}`\n\n const token = await user?.sign()\n\n page.on('request', request => {\n if (request.url() === url) {\n request.continue({\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-things-factory-domain': domain?.subdomain,\n Authorization: 'Bearer ' + token\n },\n postData: JSON.stringify({\n model,\n base\n })\n })\n } else if (request.url().startsWith(`${protocol}://${host}${port}`)) {\n request.continue({\n headers: {\n ...request.headers(),\n 'x-things-factory-domain': domain?.subdomain,\n Authorization: 'Bearer ' + token\n }\n })\n } else {\n request.continue()\n }\n })\n\n await page.goto(url)\n\n await page.evaluate(data => {\n //@ts-ignore\n s.data = data\n return new Promise(resolve => {\n requestAnimationFrame(() => resolve(0))\n })\n }, boardInput)\n\n await pdfUtil.processPageAndGeneratePDF(step.params, null, page)\n\n return {\n data: context.__headless_pdf\n }\n } catch (error) {\n throw error\n } finally {\n await pdfUtil.closeBrowser()\n }\n}\n\nHeadlessPDFCaptureBoard.parameterSpec = [\n ...getCommonParameterSpec(),\n {\n type: 'string',\n name: 'boardAccessor',\n label: 'board-accessor'\n },\n {\n type: 'resource-object',\n name: 'board',\n label: 'board',\n property: {\n queryName: 'boards'\n }\n },\n {\n type: 'boolean',\n name: 'draft',\n label: 'board-draft',\n defaultValue: false,\n description: 'Set whether to get the current working version or the last released version'\n }\n]\n\nHeadlessPDFCaptureBoard.help = 'integration/task/headless-pdf-capture-board'\n\nTaskRegistry.registerTaskHandler('headless-pdf-capture-board', HeadlessPDFCaptureBoard)\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare function HeadlessPDFCaptureMarkdown(step: any, context: any): Promise<{
|
|
2
|
+
data: any;
|
|
3
|
+
}>;
|
|
4
|
+
export declare namespace HeadlessPDFCaptureMarkdown {
|
|
5
|
+
var parameterSpec: ({
|
|
6
|
+
type: string;
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
property?: undefined;
|
|
10
|
+
description?: undefined;
|
|
11
|
+
placeholder?: undefined;
|
|
12
|
+
defaultValue?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
type: string;
|
|
15
|
+
name: string;
|
|
16
|
+
label: string;
|
|
17
|
+
property: {
|
|
18
|
+
options: {
|
|
19
|
+
display: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
description: string;
|
|
24
|
+
placeholder?: undefined;
|
|
25
|
+
defaultValue?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
type: string;
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
placeholder: string;
|
|
31
|
+
description: string;
|
|
32
|
+
property?: undefined;
|
|
33
|
+
defaultValue?: undefined;
|
|
34
|
+
} | {
|
|
35
|
+
type: string;
|
|
36
|
+
name: string;
|
|
37
|
+
label: string;
|
|
38
|
+
defaultValue: number;
|
|
39
|
+
description: string;
|
|
40
|
+
property?: undefined;
|
|
41
|
+
placeholder?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
type: string;
|
|
44
|
+
name: string;
|
|
45
|
+
label: string;
|
|
46
|
+
defaultValue: boolean;
|
|
47
|
+
description: string;
|
|
48
|
+
property?: undefined;
|
|
49
|
+
placeholder?: undefined;
|
|
50
|
+
})[];
|
|
51
|
+
var help: string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeadlessPDFCaptureMarkdown = HeadlessPDFCaptureMarkdown;
|
|
4
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
5
|
+
const utils_1 = require("@things-factory/utils");
|
|
6
|
+
const marked_1 = require("marked");
|
|
7
|
+
const pdf_capture_util_1 = require("./pdf-capture-util");
|
|
8
|
+
async function HeadlessPDFCaptureMarkdown(step, context) {
|
|
9
|
+
const pdfUtil = new pdf_capture_util_1.PDFCaptureUtil(context);
|
|
10
|
+
await pdfUtil.initBrowser(step.connection);
|
|
11
|
+
try {
|
|
12
|
+
const { accessor, markdownContent, markdownContentAccessor } = step.params;
|
|
13
|
+
const templateInput = (0, utils_1.access)(accessor, context.data);
|
|
14
|
+
const markdownTemplate = markdownContentAccessor ? (0, utils_1.access)(markdownContentAccessor, context.data) : markdownContent;
|
|
15
|
+
const renderedMarkdown = pdfUtil.renderTemplate(markdownTemplate, templateInput);
|
|
16
|
+
const htmlContent = (0, marked_1.marked)(renderedMarkdown);
|
|
17
|
+
await pdfUtil.processPageAndGeneratePDF(step.params, htmlContent);
|
|
18
|
+
return {
|
|
19
|
+
data: context.__headless_pdf
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
await pdfUtil.closeBrowser();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
HeadlessPDFCaptureMarkdown.parameterSpec = [
|
|
30
|
+
...(0, pdf_capture_util_1.getCommonParameterSpec)(),
|
|
31
|
+
{
|
|
32
|
+
type: 'scenario-step-input',
|
|
33
|
+
name: 'markdownContentAccessor',
|
|
34
|
+
label: 'markdown-content-accessor'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'textarea',
|
|
38
|
+
name: 'markdownContent',
|
|
39
|
+
label: 'markdown-content'
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
HeadlessPDFCaptureMarkdown.help = 'integration/task/headless-pdf-capture-markdown';
|
|
43
|
+
integration_base_1.TaskRegistry.registerTaskHandler('headless-pdf-capture-markdown', HeadlessPDFCaptureMarkdown);
|
|
44
|
+
//# sourceMappingURL=headless-pdf-capture-markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless-pdf-capture-markdown.js","sourceRoot":"","sources":["../../../server/engine/task/headless-pdf-capture-markdown.ts"],"names":[],"mappings":";;AAMA,gEAsBC;AA5BD,uEAA+D;AAC/D,iDAA8C;AAC9C,mCAA+B;AAE/B,yDAA2E;AAEpE,KAAK,UAAU,0BAA0B,CAAC,IAAI,EAAE,OAAO;IAC5D,MAAM,OAAO,GAAG,IAAI,iCAAc,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAE1C,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,uBAAuB,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAC1E,MAAM,aAAa,GAAG,IAAA,cAAM,EAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QACpD,MAAM,gBAAgB,GAAG,uBAAuB,CAAC,CAAC,CAAC,IAAA,cAAM,EAAC,uBAAuB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,CAAA;QAElH,MAAM,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA;QAChF,MAAM,WAAW,GAAG,IAAA,eAAM,EAAC,gBAAgB,CAAC,CAAA;QAE5C,MAAM,OAAO,CAAC,yBAAyB,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QAEjE,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,cAAc;SAC7B,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAA;IACb,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,YAAY,EAAE,CAAA;IAC9B,CAAC;AACH,CAAC;AAED,0BAA0B,CAAC,aAAa,GAAG;IACzC,GAAG,IAAA,yCAAsB,GAAE;IAC3B;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,yBAAyB;QAC/B,KAAK,EAAE,2BAA2B;KACnC;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,iBAAiB;QACvB,KAAK,EAAE,kBAAkB;KAC1B;CACF,CAAA;AAED,0BAA0B,CAAC,IAAI,GAAG,gDAAgD,CAAA;AAElF,+BAAY,CAAC,mBAAmB,CAAC,+BAA+B,EAAE,0BAA0B,CAAC,CAAA","sourcesContent":["import { TaskRegistry } from '@things-factory/integration-base'\nimport { access } from '@things-factory/utils'\nimport { marked } from 'marked'\n\nimport { PDFCaptureUtil, getCommonParameterSpec } from './pdf-capture-util'\n\nexport async function HeadlessPDFCaptureMarkdown(step, context) {\n const pdfUtil = new PDFCaptureUtil(context)\n await pdfUtil.initBrowser(step.connection)\n\n try {\n const { accessor, markdownContent, markdownContentAccessor } = step.params\n const templateInput = access(accessor, context.data)\n const markdownTemplate = markdownContentAccessor ? access(markdownContentAccessor, context.data) : markdownContent\n\n const renderedMarkdown = pdfUtil.renderTemplate(markdownTemplate, templateInput)\n const htmlContent = marked(renderedMarkdown)\n\n await pdfUtil.processPageAndGeneratePDF(step.params, htmlContent)\n\n return {\n data: context.__headless_pdf\n }\n } catch (error) {\n throw error\n } finally {\n await pdfUtil.closeBrowser()\n }\n}\n\nHeadlessPDFCaptureMarkdown.parameterSpec = [\n ...getCommonParameterSpec(),\n {\n type: 'scenario-step-input',\n name: 'markdownContentAccessor',\n label: 'markdown-content-accessor'\n },\n {\n type: 'textarea',\n name: 'markdownContent',\n label: 'markdown-content'\n }\n]\n\nHeadlessPDFCaptureMarkdown.help = 'integration/task/headless-pdf-capture-markdown'\n\nTaskRegistry.registerTaskHandler('headless-pdf-capture-markdown', HeadlessPDFCaptureMarkdown)\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare function HeadlessPDFCapture(step: any, context: any): Promise<{
|
|
2
|
+
data: any;
|
|
3
|
+
}>;
|
|
4
|
+
export declare namespace HeadlessPDFCapture {
|
|
5
|
+
var parameterSpec: ({
|
|
6
|
+
type: string;
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
property?: undefined;
|
|
10
|
+
description?: undefined;
|
|
11
|
+
placeholder?: undefined;
|
|
12
|
+
defaultValue?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
type: string;
|
|
15
|
+
name: string;
|
|
16
|
+
label: string;
|
|
17
|
+
property: {
|
|
18
|
+
options: {
|
|
19
|
+
display: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
description: string;
|
|
24
|
+
placeholder?: undefined;
|
|
25
|
+
defaultValue?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
type: string;
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
placeholder: string;
|
|
31
|
+
description: string;
|
|
32
|
+
property?: undefined;
|
|
33
|
+
defaultValue?: undefined;
|
|
34
|
+
} | {
|
|
35
|
+
type: string;
|
|
36
|
+
name: string;
|
|
37
|
+
label: string;
|
|
38
|
+
defaultValue: number;
|
|
39
|
+
description: string;
|
|
40
|
+
property?: undefined;
|
|
41
|
+
placeholder?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
type: string;
|
|
44
|
+
name: string;
|
|
45
|
+
label: string;
|
|
46
|
+
defaultValue: boolean;
|
|
47
|
+
description: string;
|
|
48
|
+
property?: undefined;
|
|
49
|
+
placeholder?: undefined;
|
|
50
|
+
})[];
|
|
51
|
+
var help: string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeadlessPDFCapture = HeadlessPDFCapture;
|
|
4
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
5
|
+
const utils_1 = require("@things-factory/utils");
|
|
6
|
+
const pdf_capture_util_1 = require("./pdf-capture-util");
|
|
7
|
+
async function HeadlessPDFCapture(step, context) {
|
|
8
|
+
const pdfUtil = new pdf_capture_util_1.PDFCaptureUtil(context);
|
|
9
|
+
await pdfUtil.initBrowser(step.connection);
|
|
10
|
+
try {
|
|
11
|
+
const { accessor, htmlContent } = step.params;
|
|
12
|
+
const templateInput = (0, utils_1.access)(accessor, context.data);
|
|
13
|
+
const renderedHtmlContent = pdfUtil.renderTemplate(htmlContent, templateInput);
|
|
14
|
+
await pdfUtil.processPageAndGeneratePDF(step.params, renderedHtmlContent);
|
|
15
|
+
return {
|
|
16
|
+
data: context.__headless_pdf
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
await pdfUtil.closeBrowser();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
HeadlessPDFCapture.parameterSpec = [
|
|
27
|
+
...(0, pdf_capture_util_1.getCommonParameterSpec)(),
|
|
28
|
+
{
|
|
29
|
+
type: 'textarea',
|
|
30
|
+
name: 'htmlContent',
|
|
31
|
+
label: 'html-content'
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
HeadlessPDFCapture.help = 'integration/task/headless-pdf-capture';
|
|
35
|
+
integration_base_1.TaskRegistry.registerTaskHandler('headless-pdf-capture', HeadlessPDFCapture);
|
|
36
|
+
//# sourceMappingURL=headless-pdf-capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless-pdf-capture.js","sourceRoot":"","sources":["../../../server/engine/task/headless-pdf-capture.ts"],"names":[],"mappings":";;AAKA,gDAoBC;AAzBD,uEAA+D;AAC/D,iDAA8C;AAE9C,yDAA2E;AAEpE,KAAK,UAAU,kBAAkB,CAAC,IAAI,EAAE,OAAO;IACpD,MAAM,OAAO,GAAG,IAAI,iCAAc,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAE1C,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAC7C,MAAM,aAAa,GAAG,IAAA,cAAM,EAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAEpD,MAAM,mBAAmB,GAAG,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;QAE9E,MAAM,OAAO,CAAC,yBAAyB,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;QAEzE,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,cAAc;SAC7B,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAA;IACb,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,YAAY,EAAE,CAAA;IAC9B,CAAC;AACH,CAAC;AAED,kBAAkB,CAAC,aAAa,GAAG;IACjC,GAAG,IAAA,yCAAsB,GAAE;IAC3B;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,cAAc;KACtB;CACF,CAAA;AAED,kBAAkB,CAAC,IAAI,GAAG,uCAAuC,CAAA;AAEjE,+BAAY,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,CAAA","sourcesContent":["import { TaskRegistry } from '@things-factory/integration-base'\nimport { access } from '@things-factory/utils'\n\nimport { PDFCaptureUtil, getCommonParameterSpec } from './pdf-capture-util'\n\nexport async function HeadlessPDFCapture(step, context) {\n const pdfUtil = new PDFCaptureUtil(context)\n await pdfUtil.initBrowser(step.connection)\n\n try {\n const { accessor, htmlContent } = step.params\n const templateInput = access(accessor, context.data)\n\n const renderedHtmlContent = pdfUtil.renderTemplate(htmlContent, templateInput)\n\n await pdfUtil.processPageAndGeneratePDF(step.params, renderedHtmlContent)\n\n return {\n data: context.__headless_pdf\n }\n } catch (error) {\n throw error\n } finally {\n await pdfUtil.closeBrowser()\n }\n}\n\nHeadlessPDFCapture.parameterSpec = [\n ...getCommonParameterSpec(),\n {\n type: 'textarea',\n name: 'htmlContent',\n label: 'html-content'\n }\n]\n\nHeadlessPDFCapture.help = 'integration/task/headless-pdf-capture'\n\nTaskRegistry.registerTaskHandler('headless-pdf-capture', HeadlessPDFCapture)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pdf_lib_1 = require("pdf-lib");
|
|
4
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
5
|
+
const utils_1 = require("@things-factory/utils");
|
|
6
|
+
const pdf_capture_util_1 = require("./pdf-capture-util");
|
|
7
|
+
async function HeadlessPDFOpen(step, context) {
|
|
8
|
+
const { connection: connectionName, params: stepOptions } = step;
|
|
9
|
+
const { accessor, coverPage, lastPage, header, footer, watermark, fileName } = stepOptions || {};
|
|
10
|
+
const { data } = context;
|
|
11
|
+
// Create a new PDF document using pdf-lib
|
|
12
|
+
const pdfDoc = await pdf_lib_1.PDFDocument.create();
|
|
13
|
+
try {
|
|
14
|
+
const fileNameEncoded = fileName ? new TextEncoder().encode((0, utils_1.access)(fileName, data)) : undefined;
|
|
15
|
+
const pdfInfo = {
|
|
16
|
+
pdfDoc,
|
|
17
|
+
watermark,
|
|
18
|
+
fileName: fileNameEncoded,
|
|
19
|
+
pageCount: 0
|
|
20
|
+
};
|
|
21
|
+
context.__headless_pdf = pdfInfo;
|
|
22
|
+
var pdfUtil = new pdf_capture_util_1.PDFCaptureUtil(context);
|
|
23
|
+
await pdfUtil.initBrowser(connectionName);
|
|
24
|
+
const templateInput = (0, utils_1.access)(accessor, data);
|
|
25
|
+
// Convert Cover Page to PDF and add it to the document (if provided)
|
|
26
|
+
if (coverPage) {
|
|
27
|
+
const renderedCoverPage = pdfUtil.renderTemplate(coverPage, templateInput);
|
|
28
|
+
await pdfUtil.processPageAndGeneratePDF(stepOptions, renderedCoverPage);
|
|
29
|
+
}
|
|
30
|
+
var lastPageBuffer;
|
|
31
|
+
// Process Last Page (if provided) but add it later in the save task
|
|
32
|
+
if (lastPage) {
|
|
33
|
+
const renderedLastPage = pdfUtil.renderTemplate(lastPage, templateInput);
|
|
34
|
+
lastPageBuffer = await pdfUtil.generateLastPageBuffer(stepOptions, renderedLastPage);
|
|
35
|
+
}
|
|
36
|
+
pdfInfo.lastPageBuffer = lastPageBuffer;
|
|
37
|
+
pdfInfo.pageCount = pdfDoc.getPageCount();
|
|
38
|
+
pdfInfo.header = header;
|
|
39
|
+
pdfInfo.footer = footer;
|
|
40
|
+
return {
|
|
41
|
+
data: pdfInfo
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
await (pdfUtil === null || pdfUtil === void 0 ? void 0 : pdfUtil.closeBrowser());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
HeadlessPDFOpen.parameterSpec = [
|
|
52
|
+
...(0, pdf_capture_util_1.getCommonParameterSpec)(),
|
|
53
|
+
{
|
|
54
|
+
type: 'textarea',
|
|
55
|
+
name: 'coverPage',
|
|
56
|
+
label: 'pdf-cover-page'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'textarea',
|
|
60
|
+
name: 'lastPage',
|
|
61
|
+
label: 'pdf-last-page'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'string',
|
|
65
|
+
name: 'header',
|
|
66
|
+
label: 'header',
|
|
67
|
+
placeholder: 'Page <%= pageNumber %> of <%= totalPages %>'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'string',
|
|
71
|
+
name: 'footer',
|
|
72
|
+
label: 'footer',
|
|
73
|
+
placeholder: 'Page <%= pageNumber %> of <%= totalPages %>'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: 'string',
|
|
77
|
+
name: 'watermark',
|
|
78
|
+
label: 'watermark'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: 'string',
|
|
82
|
+
name: 'fileName',
|
|
83
|
+
label: 'filename'
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
HeadlessPDFOpen.help = 'integration/task/headless-pdf-open';
|
|
87
|
+
integration_base_1.TaskRegistry.registerTaskHandler('headless-pdf-open', HeadlessPDFOpen);
|
|
88
|
+
//# sourceMappingURL=headless-pdf-open.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless-pdf-open.js","sourceRoot":"","sources":["../../../server/engine/task/headless-pdf-open.ts"],"names":[],"mappings":";;AAAA,qCAAqC;AACrC,uEAA+D;AAC/D,iDAA8C;AAC9C,yDAA2E;AAE3E,KAAK,UAAU,eAAe,CAAC,IAAI,EAAE,OAAO;IAC1C,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAChE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAEhG,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;IAExB,0CAA0C;IAC1C,MAAM,MAAM,GAAG,MAAM,qBAAW,CAAC,MAAM,EAAE,CAAA;IAEzC,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAA,cAAM,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAE/F,MAAM,OAAO,GAAG;YACd,MAAM;YACN,SAAS;YACT,QAAQ,EAAE,eAAe;YACzB,SAAS,EA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EAAE,WAAW;QACjB,KAAK,EAAE,gBAAgB;KACxB;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,eAAe;KACvB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,6CAA6C;KAC3D;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,6CAA6C;KAC3D;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW;KACnB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;CACF,CAAA;AAED,eAAe,CAAC,IAAI,GAAG,oCAAoC,CAAA;AAE3D,+BAAY,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAA","sourcesContent":["import { PDFDocument } from 'pdf-lib'\nimport { TaskRegistry } from '@things-factory/integration-base'\nimport { access } from '@things-factory/utils'\nimport { PDFCaptureUtil, getCommonParameterSpec } from './pdf-capture-util'\n\nasync function HeadlessPDFOpen(step, context) {\n const { connection: connectionName, params: stepOptions } = step\n const { accessor, coverPage, lastPage, header, footer, watermark, fileName } = stepOptions || {}\n\n const { data } = context\n\n // Create a new PDF document using pdf-lib\n const pdfDoc = await PDFDocument.create()\n\n try {\n const fileNameEncoded = fileName ? new TextEncoder().encode(access(fileName, data)) : undefined\n\n const pdfInfo = {\n pdfDoc,\n watermark,\n fileName: fileNameEncoded,\n pageCount: 0\n } as any\n context.__headless_pdf = pdfInfo\n\n var pdfUtil = new PDFCaptureUtil(context)\n await pdfUtil.initBrowser(connectionName)\n\n const templateInput = access(accessor, data)\n\n // Convert Cover Page to PDF and add it to the document (if provided)\n if (coverPage) {\n const renderedCoverPage = pdfUtil.renderTemplate(coverPage, templateInput)\n await pdfUtil.processPageAndGeneratePDF(stepOptions, renderedCoverPage)\n }\n\n var lastPageBuffer\n\n // Process Last Page (if provided) but add it later in the save task\n if (lastPage) {\n const renderedLastPage = pdfUtil.renderTemplate(lastPage, templateInput)\n lastPageBuffer = await pdfUtil.generateLastPageBuffer(stepOptions, renderedLastPage)\n }\n\n pdfInfo.lastPageBuffer = lastPageBuffer\n pdfInfo.pageCount = pdfDoc.getPageCount()\n pdfInfo.header = header\n pdfInfo.footer = footer\n\n return {\n data: pdfInfo\n }\n } catch (error) {\n throw error\n } finally {\n await pdfUtil?.closeBrowser()\n }\n}\n\nHeadlessPDFOpen.parameterSpec = [\n ...getCommonParameterSpec(),\n {\n type: 'textarea',\n name: 'coverPage',\n label: 'pdf-cover-page'\n },\n {\n type: 'textarea',\n name: 'lastPage',\n label: 'pdf-last-page'\n },\n {\n type: 'string',\n name: 'header',\n label: 'header',\n placeholder: 'Page <%= pageNumber %> of <%= totalPages %>'\n },\n {\n type: 'string',\n name: 'footer',\n label: 'footer',\n placeholder: 'Page <%= pageNumber %> of <%= totalPages %>'\n },\n {\n type: 'string',\n name: 'watermark',\n label: 'watermark'\n },\n {\n type: 'string',\n name: 'fileName',\n label: 'filename'\n }\n]\n\nHeadlessPDFOpen.help = 'integration/task/headless-pdf-open'\n\nTaskRegistry.registerTaskHandler('headless-pdf-open', HeadlessPDFOpen)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pdf_lib_1 = require("pdf-lib");
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
6
|
+
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
7
|
+
const shell_1 = require("@things-factory/shell");
|
|
8
|
+
async function HeadlessPDFSave(step, context) {
|
|
9
|
+
const { domain, user, __headless_pdf } = context;
|
|
10
|
+
if (!__headless_pdf || !__headless_pdf.pdfDoc) {
|
|
11
|
+
throw new Error('No PDF document found. Ensure that headless-pdf-open and headless-pdf-capture tasks are executed before saving.');
|
|
12
|
+
}
|
|
13
|
+
const pdfDoc = __headless_pdf.pdfDoc;
|
|
14
|
+
// Add last page if it exists
|
|
15
|
+
if (__headless_pdf.lastPageBuffer) {
|
|
16
|
+
await appendLastPageToPDF(pdfDoc, __headless_pdf.lastPageBuffer);
|
|
17
|
+
}
|
|
18
|
+
const pdfBytes = await pdfDoc.save();
|
|
19
|
+
const finalFileName = generateFileName(__headless_pdf.fileName);
|
|
20
|
+
const savedAttachment = await savePDFToFile(pdfBytes, finalFileName, domain, user);
|
|
21
|
+
const attachment = await getAttachmentDetails(savedAttachment.id);
|
|
22
|
+
return {
|
|
23
|
+
data: {
|
|
24
|
+
id: attachment.id,
|
|
25
|
+
name: attachment.name,
|
|
26
|
+
path: attachment.path,
|
|
27
|
+
mimetype: attachment.mimetype,
|
|
28
|
+
refBy: attachment.refBy,
|
|
29
|
+
fullpath: attachment.fullpath
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function appendLastPageToPDF(pdfDoc, lastPageBuffer) {
|
|
34
|
+
const lastPageDoc = await pdf_lib_1.PDFDocument.load(lastPageBuffer);
|
|
35
|
+
const copiedLastPages = await pdfDoc.copyPages(lastPageDoc, lastPageDoc.getPageIndices());
|
|
36
|
+
copiedLastPages.forEach(page => pdfDoc.addPage(page));
|
|
37
|
+
}
|
|
38
|
+
function generateFileName(fileName) {
|
|
39
|
+
return fileName || `document-${Date.now()}.pdf`;
|
|
40
|
+
}
|
|
41
|
+
async function savePDFToFile(pdfBytes, finalFileName, domain, user) {
|
|
42
|
+
return await (0, attachment_base_1.createAttachment)(null, {
|
|
43
|
+
attachment: {
|
|
44
|
+
file: {
|
|
45
|
+
createReadStream: () => new stream_1.Readable({
|
|
46
|
+
read() {
|
|
47
|
+
this.push(pdfBytes);
|
|
48
|
+
this.push(null);
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
filename: finalFileName,
|
|
52
|
+
mimetype: 'application/pdf',
|
|
53
|
+
encoding: 'binary'
|
|
54
|
+
},
|
|
55
|
+
refType: 'headless-pdf-save',
|
|
56
|
+
refBy: 'pdf-published'
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
state: { domain, user }
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function getAttachmentDetails(attachmentId) {
|
|
63
|
+
return await (0, shell_1.getRepository)(attachment_base_1.Attachment).findOne({
|
|
64
|
+
where: { id: attachmentId }
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
HeadlessPDFSave.parameterSpec = [];
|
|
68
|
+
HeadlessPDFSave.help = 'integration/task/headless-pdf-save';
|
|
69
|
+
integration_base_1.TaskRegistry.registerTaskHandler('headless-pdf-save', HeadlessPDFSave);
|
|
70
|
+
//# sourceMappingURL=headless-pdf-save.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless-pdf-save.js","sourceRoot":"","sources":["../../../server/engine/task/headless-pdf-save.ts"],"names":[],"mappings":";;AAAA,qCAAqC;AACrC,mCAAiC;AACjC,uEAA+D;AAC/D,qEAA8E;AAC9E,iDAAqD;AAErD,KAAK,UAAU,eAAe,CAAC,IAAI,EAAE,OAAO;IAC1C,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,OAAO,CAAA;IAEhD,IAAI,CAAC,cAAc,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAA;IAEpC,6BAA6B;IAC7B,IAAI,cAAc,CAAC,cAAc,EAAE,CAAC;QAClC,MAAM,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC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,gBAAgB,EAAE,GAAG,EAAE,CACrB,IAAI,iBAAQ,CAAC;oBACX,IAAI;wBACF,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;wBACnB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oBACjB,CAAC;iBACF,CAAC;gBACJ,QAAQ,EAAE,aAAa;gBACvB,QAAQ,EAAE,iBAAiB;gBAC3B,QAAQ,EAAE,QAAQ;aACnB;YACD,OAAO,EAAE,mBAAmB;YAC5B,KAAK,EAAE,eAAe;SACvB;KACF,EACD;QACE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;KACxB,CACF,CAAA;AACH,CAAC;AAED,KAAK,UAAU,oBAAoB,CAAC,YAAY;IAC9C,OAAO,MAAM,IAAA,qBAAa,EAAC,4BAAU,CAAC,CAAC,OAAO,CAAC;QAC7C,KAAK,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE;KAC5B,CAAC,CAAA;AACJ,CAAC;AAED,eAAe,CAAC,aAAa,GAAG,EAAE,CAAA;AAElC,eAAe,CAAC,IAAI,GAAG,oCAAoC,CAAA;AAE3D,+BAAY,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAA","sourcesContent":["import { PDFDocument } from 'pdf-lib'\nimport { Readable } from 'stream'\nimport { TaskRegistry } from '@things-factory/integration-base'\nimport { Attachment, createAttachment } from '@things-factory/attachment-base'\nimport { getRepository } from '@things-factory/shell'\n\nasync function HeadlessPDFSave(step, context) {\n const { domain, user, __headless_pdf } = context\n\n if (!__headless_pdf || !__headless_pdf.pdfDoc) {\n throw new Error(\n 'No PDF document found. Ensure that headless-pdf-open and headless-pdf-capture tasks are executed before saving.'\n )\n }\n\n const pdfDoc = __headless_pdf.pdfDoc\n\n // Add last page if it exists\n if (__headless_pdf.lastPageBuffer) {\n await appendLastPageToPDF(pdfDoc, __headless_pdf.lastPageBuffer)\n }\n\n const pdfBytes = await pdfDoc.save()\n const finalFileName = generateFileName(__headless_pdf.fileName)\n\n const savedAttachment = await savePDFToFile(pdfBytes, finalFileName, domain, user)\n const attachment = await getAttachmentDetails(savedAttachment.id)\n\n return {\n data: {\n id: attachment.id,\n name: attachment.name,\n path: attachment.path,\n mimetype: attachment.mimetype,\n refBy: attachment.refBy,\n fullpath: attachment.fullpath\n }\n }\n}\n\nasync function appendLastPageToPDF(pdfDoc, lastPageBuffer) {\n const lastPageDoc = await PDFDocument.load(lastPageBuffer)\n const copiedLastPages = await pdfDoc.copyPages(lastPageDoc, lastPageDoc.getPageIndices())\n copiedLastPages.forEach(page => pdfDoc.addPage(page))\n}\n\nfunction generateFileName(fileName) {\n return fileName || `document-${Date.now()}.pdf`\n}\n\nasync function savePDFToFile(pdfBytes, finalFileName, domain, user) {\n return await createAttachment(\n null,\n {\n attachment: {\n file: {\n createReadStream: () =>\n new Readable({\n read() {\n this.push(pdfBytes)\n this.push(null)\n }\n }),\n filename: finalFileName,\n mimetype: 'application/pdf',\n encoding: 'binary'\n },\n refType: 'headless-pdf-save',\n refBy: 'pdf-published'\n }\n },\n {\n state: { domain, user }\n }\n )\n}\n\nasync function getAttachmentDetails(attachmentId) {\n return await getRepository(Attachment).findOne({\n where: { id: attachmentId }\n })\n}\n\nHeadlessPDFSave.parameterSpec = []\n\nHeadlessPDFSave.help = 'integration/task/headless-pdf-save'\n\nTaskRegistry.registerTaskHandler('headless-pdf-save', HeadlessPDFSave)\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import './headless-pdf-capture';
|
|
2
|
+
import './headless-pdf-capture-markdown';
|
|
3
|
+
import './headless-pdf-capture-board';
|
|
4
|
+
import './headless-pdf-open';
|
|
5
|
+
import './headless-pdf-save';
|
|
6
|
+
import './pdf-capture-util';
|
|
7
|
+
export * from './pdf-capture-util';
|
|
8
|
+
export * from './headless-pdf-capture-board';
|