@taskmagic/apps-polydoc 0.0.1

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.
Files changed (35) hide show
  1. package/README.md +3 -0
  2. package/package.json +47 -0
  3. package/src/index.d.ts +4 -0
  4. package/src/index.js +55 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/actions/capture-screenshot.d.ts +23 -0
  7. package/src/lib/actions/capture-screenshot.js +108 -0
  8. package/src/lib/actions/capture-screenshot.js.map +1 -0
  9. package/src/lib/actions/convert-pdf.d.ts +27 -0
  10. package/src/lib/actions/convert-pdf.js +107 -0
  11. package/src/lib/actions/convert-pdf.js.map +1 -0
  12. package/src/lib/actions/generate-einvoice.d.ts +20 -0
  13. package/src/lib/actions/generate-einvoice.js +107 -0
  14. package/src/lib/actions/generate-einvoice.js.map +1 -0
  15. package/src/lib/common/auth.d.ts +4 -0
  16. package/src/lib/common/auth.js +62 -0
  17. package/src/lib/common/auth.js.map +1 -0
  18. package/src/lib/common/build-request-body.d.ts +10 -0
  19. package/src/lib/common/build-request-body.js +172 -0
  20. package/src/lib/common/build-request-body.js.map +1 -0
  21. package/src/lib/common/client.d.ts +23 -0
  22. package/src/lib/common/client.js +68 -0
  23. package/src/lib/common/client.js.map +1 -0
  24. package/src/lib/common/constants.d.ts +40 -0
  25. package/src/lib/common/constants.js +28 -0
  26. package/src/lib/common/constants.js.map +1 -0
  27. package/src/lib/common/output.d.ts +23 -0
  28. package/src/lib/common/output.js +53 -0
  29. package/src/lib/common/output.js.map +1 -0
  30. package/src/lib/common/props.d.ts +19 -0
  31. package/src/lib/common/props.js +144 -0
  32. package/src/lib/common/props.js.map +1 -0
  33. package/src/lib/common/types.d.ts +36 -0
  34. package/src/lib/common/types.js +3 -0
  35. package/src/lib/common/types.js.map +1 -0
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeDeep = mergeDeep;
4
+ exports.buildRequestBody = buildRequestBody;
5
+ exports.defaultFilename = defaultFilename;
6
+ const constants_1 = require("./constants");
7
+ /**
8
+ * Pure assembly of the PolyDoc request body from resolved action params. No I/O
9
+ * and no framework references, so it is unit-testable in isolation and stays
10
+ * the single source of truth for the request shape across all actions.
11
+ */
12
+ function isPlainObject(value) {
13
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
14
+ }
15
+ /** Deep-merge `source` into `target` (source wins). Arrays and scalars overwrite. */
16
+ function mergeDeep(target, source) {
17
+ const out = Object.assign({}, target);
18
+ for (const [key, value] of Object.entries(source)) {
19
+ if (isPlainObject(value) && isPlainObject(out[key])) {
20
+ out[key] = mergeDeep(out[key], value);
21
+ }
22
+ else {
23
+ out[key] = value;
24
+ }
25
+ }
26
+ return out;
27
+ }
28
+ function resolveSource(params) {
29
+ var _a, _b, _c;
30
+ switch (params.sourceType) {
31
+ case 'url':
32
+ return (_a = params.url) !== null && _a !== void 0 ? _a : '';
33
+ case 'html':
34
+ return (_b = params.html) !== null && _b !== void 0 ? _b : '';
35
+ case 'template':
36
+ return `[template:${(_c = params.templateId) !== null && _c !== void 0 ? _c : ''}]`;
37
+ default:
38
+ return '';
39
+ }
40
+ }
41
+ function buildLayout(opts) {
42
+ var _a, _b, _c, _d;
43
+ const layout = {};
44
+ if (typeof opts['format'] === 'string' && opts['format'] !== '') {
45
+ layout['format'] = opts['format'];
46
+ }
47
+ for (const flag of ['landscape', 'printBackground', 'outline', 'tagged']) {
48
+ if (typeof opts[flag] === 'boolean') {
49
+ layout[flag] = opts[flag];
50
+ }
51
+ }
52
+ if (typeof opts['scale'] === 'number') {
53
+ layout['scale'] = opts['scale'];
54
+ }
55
+ if (typeof opts['pageRanges'] === 'string' && opts['pageRanges'] !== '') {
56
+ layout['pageRanges'] = opts['pageRanges'];
57
+ }
58
+ const margins = ['marginTop', 'marginRight', 'marginBottom', 'marginLeft'];
59
+ if (margins.some((m) => opts[m] !== undefined && opts[m] !== '')) {
60
+ layout['margin'] = {
61
+ top: (_a = opts['marginTop']) !== null && _a !== void 0 ? _a : '2',
62
+ right: (_b = opts['marginRight']) !== null && _b !== void 0 ? _b : '1',
63
+ bottom: (_c = opts['marginBottom']) !== null && _c !== void 0 ? _c : '2',
64
+ left: (_d = opts['marginLeft']) !== null && _d !== void 0 ? _d : '1',
65
+ };
66
+ }
67
+ return Object.keys(layout).length > 0 ? layout : undefined;
68
+ }
69
+ function buildScreenshot(opts) {
70
+ const shot = {};
71
+ if (typeof opts['imageType'] === 'string' && opts['imageType'] !== '') {
72
+ shot['type'] = opts['imageType'];
73
+ }
74
+ if (typeof opts['fullPage'] === 'boolean') {
75
+ shot['fullPage'] = opts['fullPage'];
76
+ }
77
+ if (typeof opts['quality'] === 'number') {
78
+ shot['quality'] = opts['quality'];
79
+ }
80
+ if (opts['encoding'] === 'base64') {
81
+ shot['encoding'] = 'base64';
82
+ }
83
+ const hasViewportWidth = typeof opts['viewportWidth'] === 'number';
84
+ const hasViewportHeight = typeof opts['viewportHeight'] === 'number';
85
+ if (hasViewportWidth !== hasViewportHeight) {
86
+ throw new Error('Both viewport width and height are required to set a custom viewport.');
87
+ }
88
+ if (hasViewportWidth && hasViewportHeight) {
89
+ const viewport = {
90
+ width: opts['viewportWidth'],
91
+ height: opts['viewportHeight'],
92
+ };
93
+ if (typeof opts['devicePixelRatio'] === 'number' && opts['devicePixelRatio'] > 0) {
94
+ viewport['devicePixelRatio'] = opts['devicePixelRatio'];
95
+ }
96
+ shot['viewport'] = viewport;
97
+ }
98
+ return Object.keys(shot).length > 0 ? shot : undefined;
99
+ }
100
+ /**
101
+ * Assemble the PolyDoc request body. Returns the endpoint to call, the body to
102
+ * send, and whether the default (binary) delivery is in effect.
103
+ */
104
+ function buildRequestBody(params) {
105
+ var _a, _b;
106
+ const endpoint = params.operation === 'screenshot' ? constants_1.SCREENSHOT_CONVERT_PATH : constants_1.PDF_CONVERT_PATH;
107
+ const body = {
108
+ source: resolveSource(params),
109
+ };
110
+ if (params.templateData && Object.keys(params.templateData).length > 0) {
111
+ body['templateData'] = params.templateData;
112
+ }
113
+ if (params.filename) {
114
+ body['filename'] = params.filename;
115
+ }
116
+ if (params.tag) {
117
+ body['tag'] = params.tag;
118
+ }
119
+ if (typeof params.timeout === 'number' && params.timeout > 0) {
120
+ body['timeout'] = params.timeout;
121
+ }
122
+ if (params.operation === 'pdf') {
123
+ const layout = params.pdfOptions ? buildLayout(params.pdfOptions) : undefined;
124
+ if (layout) {
125
+ body['layout'] = layout;
126
+ }
127
+ }
128
+ if (params.operation === 'screenshot') {
129
+ const shot = params.screenshotOptions ? buildScreenshot(params.screenshotOptions) : undefined;
130
+ if (shot) {
131
+ body['screenshot'] = shot;
132
+ }
133
+ }
134
+ if (params.operation === 'einvoice') {
135
+ const eInvoice = {
136
+ standard: params.eInvoiceStandard,
137
+ profile: params.eInvoiceProfile,
138
+ invoice: (_a = params.invoice) !== null && _a !== void 0 ? _a : {},
139
+ };
140
+ if (typeof params.eInvoiceVerify === 'boolean') {
141
+ eInvoice['verify'] = params.eInvoiceVerify;
142
+ }
143
+ body['eInvoice'] = eInvoice;
144
+ }
145
+ const delivery = (_b = params.delivery) !== null && _b !== void 0 ? _b : { mode: 'download' };
146
+ const isBinary = delivery.mode === 'download';
147
+ if (delivery.mode === 'cloudStorage' && delivery.presignedUrl) {
148
+ body['cloudStorage'] = {
149
+ presignedUrl: delivery.presignedUrl,
150
+ };
151
+ }
152
+ if (delivery.mode === 'webhook' && delivery.webhook) {
153
+ body['webhook'] = delivery.webhook;
154
+ }
155
+ const merged = params.advanced && Object.keys(params.advanced).length > 0
156
+ ? mergeDeep(body, params.advanced)
157
+ : body;
158
+ return {
159
+ endpoint,
160
+ body: merged,
161
+ isBinary,
162
+ };
163
+ }
164
+ /** Default output filename when the user did not set one. */
165
+ function defaultFilename(operation, imageType) {
166
+ if (operation === 'screenshot') {
167
+ const ext = imageType === 'jpeg' ? 'jpg' : (imageType !== null && imageType !== void 0 ? imageType : 'png');
168
+ return `screenshot.${ext}`;
169
+ }
170
+ return 'document.pdf';
171
+ }
172
+ //# sourceMappingURL=build-request-body.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-request-body.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/polydoc/src/lib/common/build-request-body.ts"],"names":[],"mappings":";;AAcA,8BAUC;AAgFD,4CAkEC;AAGD,0CAMC;AAnLD,2CAAwE;AAGxE;;;;GAIG;AAEH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,qFAAqF;AACrF,SAAgB,SAAS,CAAC,MAAkB,EAAE,MAAkB;IAC9D,MAAM,GAAG,qBAAoB,MAAM,CAAE,CAAC;IACtC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACpD,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAe,EAAE,KAAK,CAAC,CAAC;QACtD,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,aAAa,CAAC,MAAqB;;IAC1C,QAAQ,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1B,KAAK,KAAK;YACR,OAAO,MAAA,MAAM,CAAC,GAAG,mCAAI,EAAE,CAAC;QAC1B,KAAK,MAAM;YACT,OAAO,MAAA,MAAM,CAAC,IAAI,mCAAI,EAAE,CAAC;QAC3B,KAAK,UAAU;YACb,OAAO,aAAa,MAAA,MAAM,CAAC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3
+ export interface PolyDocAuthValue {
4
+ apiKey: string;
5
+ sandbox?: boolean;
6
+ }
7
+ export interface PolyDocResponse {
8
+ status: number;
9
+ headers: HttpHeaders;
10
+ body: unknown;
11
+ }
12
+ /**
13
+ * Perform an authenticated PolyDoc API call. Sets the Bearer token and the
14
+ * per-request X-Sandbox header, and requests bytes or JSON depending on the
15
+ * delivery mode. Returns the full response so callers can read binary bytes +
16
+ * headers or the JSON delivery confirmation.
17
+ */
18
+ export declare function polyDocRequest(auth: PolyDocAuthValue, request: PolyDocRequest): Promise<PolyDocResponse>;
19
+ /**
20
+ * Best-effort extraction of PolyDoc's `{ error, message }` from a thrown HTTP
21
+ * error, including the binary path where the error body arrives as bytes.
22
+ */
23
+ export declare function extractApiErrorMessage(error: unknown): string | undefined;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polyDocRequest = polyDocRequest;
4
+ exports.extractApiErrorMessage = extractApiErrorMessage;
5
+ const tslib_1 = require("tslib");
6
+ const pieces_common_1 = require("@taskmagic/pieces-common");
7
+ const constants_1 = require("./constants");
8
+ /**
9
+ * Perform an authenticated PolyDoc API call. Sets the Bearer token and the
10
+ * per-request X-Sandbox header, and requests bytes or JSON depending on the
11
+ * delivery mode. Returns the full response so callers can read binary bytes +
12
+ * headers or the JSON delivery confirmation.
13
+ */
14
+ function polyDocRequest(auth, request) {
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ var _a;
17
+ const baseUrl = constants_1.DEFAULT_BASE_URL.replace(/\/+$/, '');
18
+ const res = yield pieces_common_1.httpClient.sendRequest({
19
+ method: pieces_common_1.HttpMethod.POST,
20
+ url: `${baseUrl}${request.endpoint}`,
21
+ headers: {
22
+ Authorization: `Bearer ${auth.apiKey}`,
23
+ 'Content-Type': 'application/json',
24
+ 'X-Sandbox': auth.sandbox ? 'true' : 'false',
25
+ },
26
+ body: request.body,
27
+ responseType: request.isBinary ? 'arraybuffer' : 'json',
28
+ });
29
+ return { status: res.status, headers: (_a = res.headers) !== null && _a !== void 0 ? _a : {}, body: res.body };
30
+ });
31
+ }
32
+ /**
33
+ * Best-effort extraction of PolyDoc's `{ error, message }` from a thrown HTTP
34
+ * error, including the binary path where the error body arrives as bytes.
35
+ */
36
+ function extractApiErrorMessage(error) {
37
+ var _a;
38
+ const err = error;
39
+ let payload = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.body;
40
+ if (payload instanceof ArrayBuffer) {
41
+ payload = Buffer.from(payload).toString('utf8');
42
+ }
43
+ else if (Buffer.isBuffer(payload)) {
44
+ payload = payload.toString('utf8');
45
+ }
46
+ if (typeof payload === 'string') {
47
+ const text = payload;
48
+ try {
49
+ payload = JSON.parse(text);
50
+ }
51
+ catch (_b) {
52
+ return text || undefined;
53
+ }
54
+ }
55
+ if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
56
+ const p = payload;
57
+ const message = p['message'];
58
+ if (typeof message === 'string') {
59
+ return message;
60
+ }
61
+ const errorField = p['error'];
62
+ if (typeof errorField === 'string') {
63
+ return errorField;
64
+ }
65
+ }
66
+ return undefined;
67
+ }
68
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/polydoc/src/lib/common/client.ts"],"names":[],"mappings":";;AAqBA,wCAiBC;AAMD,wDA4BC;;AAxED,4DAAoF;AACpF,2CAA+C;AAc/C;;;;;GAKG;AACH,SAAsB,cAAc,CAClC,IAAsB,EACtB,OAAuB;;;QAEvB,MAAM,OAAO,GAAG,4BAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACrD,MAAM,GAAG,GAAG,MAAM,0BAAU,CAAC,WAAW,CAAC;YACvC,MAAM,EAAE,0BAAU,CAAC,IAAI;YACvB,GAAG,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE;YACpC,OAA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AAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACtE,MAAM,CAAC,GAAG,OAAqB,CAAC;QAChC,MAAM,OAAO,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;QAC7B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,40 @@
1
+ export declare const DEFAULT_BASE_URL = "https://api.polydoc.tech";
2
+ export declare const PDF_CONVERT_PATH = "/pdf/convert";
3
+ export declare const SCREENSHOT_CONVERT_PATH = "/screenshot/convert";
4
+ export declare const SOURCE_TYPES: readonly [{
5
+ readonly label: "URL (render a web page)";
6
+ readonly value: "url";
7
+ }, {
8
+ readonly label: "HTML (render an inline HTML string)";
9
+ readonly value: "html";
10
+ }, {
11
+ readonly label: "Template (render a saved PolyDoc template by ID)";
12
+ readonly value: "template";
13
+ }];
14
+ export declare const DELIVERY_MODES: readonly [{
15
+ readonly label: "Download (return the file)";
16
+ readonly value: "download";
17
+ }, {
18
+ readonly label: "Cloud Storage (upload to a presigned URL)";
19
+ readonly value: "cloudStorage";
20
+ }, {
21
+ readonly label: "Webhook (deliver the file to a URL)";
22
+ readonly value: "webhook";
23
+ }];
24
+ export declare const PAGE_FORMATS: readonly ["A3", "A4", "A5", "Ledger", "Legal", "Letter", "Tabloid"];
25
+ export declare const IMAGE_TYPES: readonly ["png", "jpeg", "webp"];
26
+ export declare const SCREENSHOT_OUTPUT_ENCODINGS: readonly [{
27
+ readonly label: "Binary file (write the image to a file)";
28
+ readonly value: "binaryFile";
29
+ }, {
30
+ readonly label: "Base64 (return the image as a base64 string)";
31
+ readonly value: "base64";
32
+ }];
33
+ export declare const EINVOICE_STANDARDS: readonly [{
34
+ readonly label: "ZUGFeRD (Germany / EU)";
35
+ readonly value: "zugferd";
36
+ }, {
37
+ readonly label: "Factur-X (France / EU)";
38
+ readonly value: "facturx";
39
+ }];
40
+ export declare const EINVOICE_PROFILES: readonly ["minimum", "basicwl", "basic", "en16931", "extended"];
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EINVOICE_PROFILES = exports.EINVOICE_STANDARDS = exports.SCREENSHOT_OUTPUT_ENCODINGS = exports.IMAGE_TYPES = exports.PAGE_FORMATS = exports.DELIVERY_MODES = exports.SOURCE_TYPES = exports.SCREENSHOT_CONVERT_PATH = exports.PDF_CONVERT_PATH = exports.DEFAULT_BASE_URL = void 0;
4
+ exports.DEFAULT_BASE_URL = 'https://api.polydoc.tech';
5
+ exports.PDF_CONVERT_PATH = '/pdf/convert';
6
+ exports.SCREENSHOT_CONVERT_PATH = '/screenshot/convert';
7
+ exports.SOURCE_TYPES = [
8
+ { label: 'URL (render a web page)', value: 'url' },
9
+ { label: 'HTML (render an inline HTML string)', value: 'html' },
10
+ { label: 'Template (render a saved PolyDoc template by ID)', value: 'template' },
11
+ ];
12
+ exports.DELIVERY_MODES = [
13
+ { label: 'Download (return the file)', value: 'download' },
14
+ { label: 'Cloud Storage (upload to a presigned URL)', value: 'cloudStorage' },
15
+ { label: 'Webhook (deliver the file to a URL)', value: 'webhook' },
16
+ ];
17
+ exports.PAGE_FORMATS = ['A3', 'A4', 'A5', 'Ledger', 'Legal', 'Letter', 'Tabloid'];
18
+ exports.IMAGE_TYPES = ['png', 'jpeg', 'webp'];
19
+ exports.SCREENSHOT_OUTPUT_ENCODINGS = [
20
+ { label: 'Binary file (write the image to a file)', value: 'binaryFile' },
21
+ { label: 'Base64 (return the image as a base64 string)', value: 'base64' },
22
+ ];
23
+ exports.EINVOICE_STANDARDS = [
24
+ { label: 'ZUGFeRD (Germany / EU)', value: 'zugferd' },
25
+ { label: 'Factur-X (France / EU)', value: 'facturx' },
26
+ ];
27
+ exports.EINVOICE_PROFILES = ['minimum', 'basicwl', 'basic', 'en16931', 'extended'];
28
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/polydoc/src/lib/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,0BAA0B,CAAC;AAE9C,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAClC,QAAA,uBAAuB,GAAG,qBAAqB,CAAC;AAEhD,QAAA,YAAY,GAAG;IAC1B,EAAE,KAAK,EAAE,yBAAyB,EAAE,KAAK,EAAE,KAAK,EAAE;IAClD,EAAE,KAAK,EAAE,qCAAqC,EAAE,KAAK,EAAE,MAAM,EAAE;IAC/D,EAAE,KAAK,EAAE,kDAAkD,EAAE,KAAK,EAAE,UAAU,EAAE;CACxE,CAAC;AAEE,QAAA,cAAc,GAAG;IAC5B,EAAE,KAAK,EAAE,4BAA4B,EAAE,KAAK,EAAE,UAAU,EAAE;IAC1D,EAAE,KAAK,EAAE,2CAA2C,EAAE,KAAK,EAAE,cAAc,EAAE;IAC7E,EAAE,KAAK,EAAE,qCAAqC,EAAE,KAAK,EAAE,SAAS,EAAE;CAC1D,CAAC;AAEE,QAAA,YAAY,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC;AAEnF,QAAA,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAE/C,QAAA,2BAA2B,GAAG;IACzC,EAAE,KAAK,EAAE,yCAAyC,EAAE,KAAK,EAAE,YAAY,EAAE;IACzE,EAAE,KAAK,EAAE,8CAA8C,EAAE,KAAK,EAAE,QAAQ,EAAE;CAClE,CAAC;AAEE,QAAA,kBAAkB,GAAG;IAChC,EAAE,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,SAAS,EAAE;IACrD,EAAE,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,SAAS,EAAE;CAC7C,CAAC;AAEE,QAAA,iBAAiB,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { PolyDocResponse } from './client';
2
+ import type { PolyDocOperation } from './types';
3
+ interface FilesWriter {
4
+ write(params: {
5
+ fileName: string;
6
+ data: Buffer;
7
+ }): Promise<string>;
8
+ }
9
+ interface ShapeOutputParams {
10
+ response: PolyDocResponse;
11
+ isBinary: boolean;
12
+ files: FilesWriter;
13
+ operation: PolyDocOperation;
14
+ filename?: string;
15
+ imageType?: string;
16
+ }
17
+ /**
18
+ * Turn a PolyDoc API response into an action result. Binary deliveries are
19
+ * written to a file (returning a file handle plus metadata); cloud-storage,
20
+ * webhook, and screenshot-base64 deliveries return the API's JSON as-is.
21
+ */
22
+ export declare function shapeOutput(params: ShapeOutputParams): Promise<unknown>;
23
+ export {};
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shapeOutput = shapeOutput;
4
+ const tslib_1 = require("tslib");
5
+ const build_request_body_1 = require("./build-request-body");
6
+ /**
7
+ * Turn a PolyDoc API response into an action result. Binary deliveries are
8
+ * written to a file (returning a file handle plus metadata); cloud-storage,
9
+ * webhook, and screenshot-base64 deliveries return the API's JSON as-is.
10
+ */
11
+ function shapeOutput(params) {
12
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
+ var _a, _b;
14
+ const { response, isBinary, files, operation, filename, imageType } = params;
15
+ if (!isBinary) {
16
+ return (_a = response.body) !== null && _a !== void 0 ? _a : { success: true };
17
+ }
18
+ const contentType = ((_b = headerValue(response.headers['content-type'])) !== null && _b !== void 0 ? _b : 'application/octet-stream')
19
+ .split(';')[0]
20
+ .trim();
21
+ const buffer = toBuffer(response.body);
22
+ const fileName = filename || (0, build_request_body_1.defaultFilename)(operation, imageType);
23
+ const file = yield files.write({ fileName, data: buffer });
24
+ return {
25
+ success: true,
26
+ file,
27
+ fileName,
28
+ contentType,
29
+ sizeBytes: buffer.length,
30
+ conversionId: headerValue(response.headers['x-conversion-id']),
31
+ creditUsed: headerValue(response.headers['x-credit-used']),
32
+ };
33
+ });
34
+ }
35
+ function headerValue(value) {
36
+ return Array.isArray(value) ? value[0] : value;
37
+ }
38
+ function toBuffer(body) {
39
+ if (Buffer.isBuffer(body)) {
40
+ return body;
41
+ }
42
+ if (body instanceof ArrayBuffer) {
43
+ return Buffer.from(body);
44
+ }
45
+ if (ArrayBuffer.isView(body)) {
46
+ return Buffer.from(body.buffer, body.byteOffset, body.byteLength);
47
+ }
48
+ if (typeof body === 'string') {
49
+ return Buffer.from(body, 'binary');
50
+ }
51
+ throw new Error('PolyDoc returned an unexpected response body for a binary delivery; expected file bytes.');
52
+ }
53
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/polydoc/src/lib/common/output.ts"],"names":[],"mappings":";;AAsBA,kCAuBC;;AA7CD,6DAAuD;AAiBvD;;;;GAIG;AACH,SAAsB,WAAW,CAAC,MAAyB;;;QACzD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAE7E,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,MAAA,QAAQ,CAAC,IAAI,mCAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC5C,CAAC;QAED,MAAM,WAAW,GAAG,CAAC,MAAA,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,mCAAI,0BAA0B,CAAC;aAC9F,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QAAQ,EAAE,CAAC;QAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { JsonObject, PolyDocDelivery, PolyDocParams, PolyDocSourceType } from './types';
2
+ export declare const sourceTypeProp: (defaultValue?: PolyDocSourceType) => import("@taskmagic/pieces-framework").StaticDropdownProperty<"url" | "html" | "template", true>;
3
+ export declare const sourceProp: import("@taskmagic/pieces-framework").LongTextProperty<true>;
4
+ export declare const templateDataProp: import("@taskmagic/pieces-framework").JsonProperty<false>;
5
+ export declare const deliveryModeProp: import("@taskmagic/pieces-framework").StaticDropdownProperty<"download" | "cloudStorage" | "webhook", true>;
6
+ export declare const presignedUrlProp: import("@taskmagic/pieces-framework").ShortTextProperty<false>;
7
+ export declare const webhookUrlProp: import("@taskmagic/pieces-framework").ShortTextProperty<false>;
8
+ export declare const webhookOptionsProp: import("@taskmagic/pieces-framework").JsonProperty<false>;
9
+ export declare const filenameProp: import("@taskmagic/pieces-framework").ShortTextProperty<false>;
10
+ export declare const tagProp: import("@taskmagic/pieces-framework").ShortTextProperty<false>;
11
+ export declare const timeoutProp: import("@taskmagic/pieces-framework").NumberProperty<false>;
12
+ export declare const advancedProp: import("@taskmagic/pieces-framework").JsonProperty<false>;
13
+ /** Coerce a Property.Json / object / JSON-string value into a non-empty plain object. */
14
+ export declare function asJsonObject(value: unknown): JsonObject | undefined;
15
+ type Props = Record<string, unknown>;
16
+ export declare function resolveSourceParams(props: Props): Pick<PolyDocParams, 'sourceType' | 'url' | 'html' | 'templateId' | 'templateData'>;
17
+ export declare function resolveDelivery(props: Props): PolyDocDelivery;
18
+ export declare function resolveMetadata(props: Props): Pick<PolyDocParams, 'filename' | 'tag' | 'timeout' | 'advanced'>;
19
+ export {};
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.advancedProp = exports.timeoutProp = exports.tagProp = exports.filenameProp = exports.webhookOptionsProp = exports.webhookUrlProp = exports.presignedUrlProp = exports.deliveryModeProp = exports.templateDataProp = exports.sourceProp = exports.sourceTypeProp = void 0;
4
+ exports.asJsonObject = asJsonObject;
5
+ exports.resolveSourceParams = resolveSourceParams;
6
+ exports.resolveDelivery = resolveDelivery;
7
+ exports.resolveMetadata = resolveMetadata;
8
+ const pieces_framework_1 = require("@taskmagic/pieces-framework");
9
+ const constants_1 = require("./constants");
10
+ // The framework has no n8n-style conditional show/hide for static props and its
11
+ // DynamicProperties cannot render a multiline (LongText) field, so the source
12
+ // and delivery inputs are flat optional props resolved at run time by the
13
+ // selected Source Type / Delivery mode.
14
+ const sourceTypeProp = (defaultValue = 'url') => pieces_framework_1.Property.StaticDropdown({
15
+ displayName: 'Source Type',
16
+ description: 'Where the content comes from',
17
+ required: true,
18
+ defaultValue,
19
+ options: {
20
+ disabled: false,
21
+ options: constants_1.SOURCE_TYPES.map((o) => ({ label: o.label, value: o.value })),
22
+ },
23
+ });
24
+ exports.sourceTypeProp = sourceTypeProp;
25
+ exports.sourceProp = pieces_framework_1.Property.LongText({
26
+ displayName: 'Source',
27
+ description: 'The URL, inline HTML, or saved template ID, matching the Source Type above.',
28
+ required: true,
29
+ });
30
+ exports.templateDataProp = pieces_framework_1.Property.Json({
31
+ displayName: 'Template Data',
32
+ description: 'Data passed to the Liquid template renderer (used only when Source Type is Template).',
33
+ required: false,
34
+ defaultValue: {},
35
+ });
36
+ exports.deliveryModeProp = pieces_framework_1.Property.StaticDropdown({
37
+ displayName: 'Delivery',
38
+ description: 'How the generated file is returned',
39
+ required: true,
40
+ defaultValue: 'download',
41
+ options: {
42
+ disabled: false,
43
+ options: constants_1.DELIVERY_MODES.map((o) => ({ label: o.label, value: o.value })),
44
+ },
45
+ });
46
+ exports.presignedUrlProp = pieces_framework_1.Property.ShortText({
47
+ displayName: 'Presigned URL',
48
+ description: 'HTTP PUT presigned URL from your storage provider (required for Cloud Storage delivery).',
49
+ required: false,
50
+ });
51
+ exports.webhookUrlProp = pieces_framework_1.Property.ShortText({
52
+ displayName: 'Webhook URL',
53
+ description: 'URL the generated file is delivered to (required for Webhook delivery).',
54
+ required: false,
55
+ });
56
+ exports.webhookOptionsProp = pieces_framework_1.Property.Json({
57
+ displayName: 'Webhook Options',
58
+ description: 'Extra webhook settings merged with the URL: async, method, headers, retries, retryDelay, timeout.',
59
+ required: false,
60
+ defaultValue: {},
61
+ });
62
+ exports.filenameProp = pieces_framework_1.Property.ShortText({
63
+ displayName: 'Filename',
64
+ description: 'Output filename (overrides the default).',
65
+ required: false,
66
+ });
67
+ exports.tagProp = pieces_framework_1.Property.ShortText({
68
+ displayName: 'Tag',
69
+ description: 'Label for logging and analytics (max 30 characters).',
70
+ required: false,
71
+ });
72
+ exports.timeoutProp = pieces_framework_1.Property.Number({
73
+ displayName: 'Timeout (ms)',
74
+ description: 'Conversion timeout in milliseconds.',
75
+ required: false,
76
+ });
77
+ exports.advancedProp = pieces_framework_1.Property.Json({
78
+ displayName: 'Advanced (JSON)',
79
+ description: 'Raw fields deep-merged into the request body for any API option not exposed above (e.g. pdf.watermark, pdf.pdfa, render, request).',
80
+ required: false,
81
+ defaultValue: {},
82
+ });
83
+ /** Coerce a Property.Json / object / JSON-string value into a non-empty plain object. */
84
+ function asJsonObject(value) {
85
+ let candidate = value;
86
+ if (typeof candidate === 'string') {
87
+ const trimmed = candidate.trim();
88
+ if (trimmed === '') {
89
+ return undefined;
90
+ }
91
+ try {
92
+ candidate = JSON.parse(trimmed);
93
+ }
94
+ catch (_a) {
95
+ return undefined;
96
+ }
97
+ }
98
+ if (candidate && typeof candidate === 'object' && !Array.isArray(candidate)) {
99
+ const obj = candidate;
100
+ return Object.keys(obj).length > 0 ? obj : undefined;
101
+ }
102
+ return undefined;
103
+ }
104
+ function resolveSourceParams(props) {
105
+ var _a, _b;
106
+ const sourceType = ((_a = props['sourceType']) !== null && _a !== void 0 ? _a : 'url');
107
+ const source = (_b = props['source']) !== null && _b !== void 0 ? _b : '';
108
+ if (sourceType === 'html') {
109
+ return { sourceType, html: source };
110
+ }
111
+ if (sourceType === 'template') {
112
+ return { sourceType, templateId: source, templateData: asJsonObject(props['templateData']) };
113
+ }
114
+ return { sourceType, url: source };
115
+ }
116
+ function resolveDelivery(props) {
117
+ var _a, _b, _c, _d;
118
+ const mode = ((_a = props['deliveryMode']) !== null && _a !== void 0 ? _a : 'download');
119
+ if (mode === 'cloudStorage') {
120
+ const presignedUrl = (_b = props['presignedUrl']) !== null && _b !== void 0 ? _b : '';
121
+ if (!presignedUrl) {
122
+ throw new Error('Cloud Storage delivery requires a Presigned URL.');
123
+ }
124
+ return { mode, presignedUrl };
125
+ }
126
+ if (mode === 'webhook') {
127
+ const url = (_c = props['webhookUrl']) !== null && _c !== void 0 ? _c : '';
128
+ if (!url) {
129
+ throw new Error('Webhook delivery requires a Webhook URL.');
130
+ }
131
+ const extra = (_d = asJsonObject(props['webhookOptions'])) !== null && _d !== void 0 ? _d : {};
132
+ return { mode, webhook: Object.assign({ url }, extra) };
133
+ }
134
+ return { mode: 'download' };
135
+ }
136
+ function resolveMetadata(props) {
137
+ return {
138
+ filename: props['filename'] || undefined,
139
+ tag: props['tag'] || undefined,
140
+ timeout: typeof props['timeout'] === 'number' ? props['timeout'] : undefined,
141
+ advanced: asJsonObject(props['advanced']),
142
+ };
143
+ }
144
+ //# sourceMappingURL=props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/polydoc/src/lib/common/props.ts"],"names":[],"mappings":";;;AAiGA,oCAkBC;AAID,kDAYC;AAED,0CAkBC;AAED,0CASC;AAlKD,kEAAuD;AACvD,2CAA2D;AAS3D,gFAAgF;AAChF,8EAA8E;AAC9E,0EAA0E;AAC1E,wCAAwC;AAEjC,MAAM,cAAc,GAAG,CAAC,eAAkC,KAAK,EAA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E,CAAC;QAC7D,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IAChC,CAAC;IACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,MAAC,KAAK,CAAC,YAAY,CAAY,mCAAI,EAAE,CAAC;QAClD,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,KAAK,GAAG,MAAA,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,mCAAI,EAAE,CAAC;QAC1D,OAAO,EAAE,IAAI,EAAE,OAAO,kBAAI,GAAG,IAAK,KAAK,CAAE,EAAE,CAAC;IAC9C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9B,CAAC;AAED,SAAgB,eAAe,CAC7B,KAAY;IAEZ,OAAO;QACL,QAAQ,EAAG,KAAK,CAAC,UAAU,CAAY,IAAI,SAAS;QACpD,GAAG,EAAG,KAAK,CAAC,KAAK,CAAY,IAAI,SAAS;QAC1C,OAAO,EAAE,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAE,KAAK,CAAC,SAAS,CAAY,CAAC,CAAC,CAAC,SAAS;QACxF,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;KAC1C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ export type PolyDocOperation = 'pdf' | 'screenshot' | 'einvoice';
2
+ export type PolyDocSourceType = 'url' | 'html' | 'template';
3
+ export type PolyDocDeliveryMode = 'download' | 'cloudStorage' | 'webhook';
4
+ export type JsonObject = Record<string, unknown>;
5
+ export interface PolyDocDelivery {
6
+ mode: PolyDocDeliveryMode;
7
+ presignedUrl?: string;
8
+ webhook?: JsonObject;
9
+ }
10
+ export interface PolyDocParams {
11
+ operation: PolyDocOperation;
12
+ sourceType: PolyDocSourceType;
13
+ url?: string;
14
+ html?: string;
15
+ templateId?: string;
16
+ templateData?: JsonObject;
17
+ filename?: string;
18
+ tag?: string;
19
+ timeout?: number;
20
+ /** PDF UI options: format, landscape, printBackground, scale, pageRanges, outline, tagged, margin* */
21
+ pdfOptions?: JsonObject;
22
+ /** Screenshot UI options: imageType, fullPage, quality, encoding, viewportWidth, viewportHeight, devicePixelRatio */
23
+ screenshotOptions?: JsonObject;
24
+ eInvoiceStandard?: 'facturx' | 'zugferd';
25
+ eInvoiceProfile?: string;
26
+ eInvoiceVerify?: boolean;
27
+ invoice?: JsonObject;
28
+ /** Raw object deep-merged into the request body for any field not surfaced as a control. */
29
+ advanced?: JsonObject;
30
+ delivery: PolyDocDelivery;
31
+ }
32
+ export interface PolyDocRequest {
33
+ endpoint: string;
34
+ body: JsonObject;
35
+ isBinary: boolean;
36
+ }