@ireceipt.pro/js 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.
package/CHANGELOG.md ADDED
File without changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Siarhei Dudko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # @ireceipt-pro/js
2
+
3
+ Create PDF files or images from your HTML template.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@ireceipt.pro/js.svg)](https://www.npmjs.com/package/@ireceipt.pro/js)
6
+ [![npm](https://img.shields.io/npm/dy/@ireceipt.pro/js.svg)](https://www.npmjs.com/package/@ireceipt.pro/js)
7
+ [![NpmLicense](https://img.shields.io/npm/l/@ireceipt.pro/js.svg)](https://www.npmjs.com/package/@ireceipt.pro/js)
8
+ ![GitHub last commit](https://img.shields.io/github/last-commit/ireceipt-pro/js.svg)
9
+ ![GitHub release](https://img.shields.io/github/release/ireceipt-pro/js.svg)
10
+
11
+ ## Get Started
12
+
13
+ For the library to work, you will need an API key, which you can get at <https://dashboard.ireceipt.pro>. You can also find public template IDs there or create your own.
14
+
15
+ ```ts
16
+ import { IReceiptPRO } from '@ireceipt.pro/js';
17
+
18
+ const irp = new IReceiptPRO(process.env.IRETAILPRO_API_KEY);
19
+
20
+ irp.createJpgFromPublicTemplate("invoice_template_1", {
21
+ "invoice": {
22
+ "number": "13",
23
+ "date": "2023-10-03",
24
+ "table": {
25
+ "headers": [
26
+ "NAME",
27
+ "PRICE",
28
+ "QTY",
29
+ "AMOUNT"
30
+ ],
31
+ "rows": [
32
+ {
33
+ "values": [
34
+ "Gorgeous Fresh Car",
35
+ "$100.99",
36
+ "6",
37
+ "$605.94"
38
+ ]
39
+ },
40
+ {
41
+ "values": [
42
+ "Incredible Rubber Bike",
43
+ "$356.00",
44
+ "1",
45
+ "$356.00"
46
+ ]
47
+ },
48
+ {
49
+ "values": [
50
+ "UX Services",
51
+ "$100.00",
52
+ "2",
53
+ "$200.00"
54
+ ]
55
+ },
56
+ {
57
+ "values": [
58
+ "Development Service",
59
+ "$2000.00",
60
+ "1",
61
+ "$2000.00"
62
+ ]
63
+ }
64
+ ]
65
+ },
66
+ "total": "$3161.94",
67
+ "terms": [
68
+ "Payment is due within 5 days",
69
+ "Payment method CARD",
70
+ "Card Details:",
71
+ "Card Number: 4242-4242-4242-4242",
72
+ "Sergey Dudko"
73
+ ]
74
+ },
75
+ "from": {
76
+ "companyName": "IReceipt PRO",
77
+ "lines": [
78
+ "Identification Number: 55891434",
79
+ "911 Reece Freeway",
80
+ "32390 Kraig Station",
81
+ "East Rhea",
82
+ "IR",
83
+ "support@ireceipt.pro"
84
+ ]
85
+ },
86
+ "to": {
87
+ "companyName": "Morissette - Bogisich",
88
+ "lines": [
89
+ "969 Harber Expressway",
90
+ "South Aishaton",
91
+ "GB"
92
+ ]
93
+ },
94
+ "localization": {
95
+ "invoice": "INVOICE",
96
+ "bill_to": "BILL TO",
97
+ "date": "DATE",
98
+ "total": "Total",
99
+ "terms_and_conditions": "TERMS & CONDITIONS"
100
+ }
101
+ }, {
102
+ "width": 796,
103
+ "height": 1126
104
+ })
105
+ ```
106
+
107
+ ## Use
108
+
109
+ Available methods for generating PDF files and JPG, PNG, WEBP images from public or your personal templates:
110
+
111
+ | method | description |
112
+ | --- | --- |
113
+ | `createJpgFromPublicTemplate` | Create JPG Image from public template |
114
+ | `createPdfFromPublicTemplate` | Create PDF File from public template |
115
+ | `createPngFromPublicTemplate` | Create PNG Image from public template |
116
+ | `createWebpFromPublicTemplate` | Create WEBP Image from public template |
117
+ | `createJpgFromPrivateTemplate` | Create JPG Image from private template |
118
+ | `createPdfFromPrivateTemplate` | Create PDF File from private template |
119
+ | `createPngFromPrivateTemplate` | Create PNG Image from private template |
120
+ | `createWebpFromPrivateTemplate` | Create WEBP Image from private template |
121
+
122
+ All methods have the same arguments, for example:
123
+
124
+ ```ts
125
+ const buffer: Buffer | ArrayBuffer = await createJpgFromPublicTemplate(templateId, args, size);
126
+ ```
127
+
128
+ | argument | description | required | example |
129
+ | --- | --- | --- | --- |
130
+ | `templateId` | template id, you can find it on <https://dashboard.ireceipt.pro> | true | `gift_card_template_1` |
131
+ | `args` | arguments for substitution in the template | true | `{"amount": "$25","name": "Gift Card","code": "#1234567890","color": "#ebfdff"}` |
132
+ | `size` | the size of the file being created | false | `{"width": 796,"height": 1126}` |
133
+
134
+ ## Project outline
135
+
136
+ The scheme of work looks like this:
137
+ ![IReceipt PRO Flow](https://ireceipt.pro/assets/images/main-flow-landscape.drawio.svg)
138
+
139
+ ## LICENSE
140
+
141
+ MIT
@@ -0,0 +1,4 @@
1
+ {
2
+ "base": [],
3
+ "dev": ["@types/node"]
4
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,130 @@
1
+ export declare class IReceiptPRO {
2
+ /**
3
+ *
4
+ * @param apiKey - IReceipt PRO API KEY, you can get it on <https://dashboard.ireceipt.pro>
5
+ */
6
+ constructor(apiKey: string);
7
+ private apiKey;
8
+ /**
9
+ *
10
+ * @param apiKey - IReceipt PRO API KEY, you can get it on <https://dashboard.ireceipt.pro>
11
+ * @returns
12
+ */
13
+ static useApiKey(apiKey: string): IReceiptPRO;
14
+ /**
15
+ * Create JPG Image from public template
16
+ *
17
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
18
+ * @param args - arguments for substitution in the template
19
+ * @param size - the size of the file being created
20
+ * @returns
21
+ */
22
+ createJpgFromPublicTemplate(templateId: string, args: {
23
+ [key: string]: unknown;
24
+ }, size?: {
25
+ width: number;
26
+ height: number;
27
+ }): Promise<ArrayBuffer>;
28
+ /**
29
+ * Create PDF File from public template
30
+ *
31
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
32
+ * @param args - arguments for substitution in the template
33
+ * @param size - the size of the file being created
34
+ * @returns
35
+ */
36
+ createPdfFromPublicTemplate(templateId: string, args: {
37
+ [key: string]: unknown;
38
+ }, size?: {
39
+ width: number;
40
+ height: number;
41
+ }): Promise<ArrayBuffer>;
42
+ /**
43
+ * Create PNG Image from public template
44
+ *
45
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
46
+ * @param args - arguments for substitution in the template
47
+ * @param size - the size of the file being created
48
+ * @returns
49
+ */
50
+ createPngFromPublicTemplate(templateId: string, args: {
51
+ [key: string]: unknown;
52
+ }, size?: {
53
+ width: number;
54
+ height: number;
55
+ }): Promise<ArrayBuffer>;
56
+ /**
57
+ * Create WEBP Image from public template
58
+ *
59
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
60
+ * @param args - arguments for substitution in the template
61
+ * @param size - the size of the file being created
62
+ * @returns
63
+ */
64
+ createWebpFromPublicTemplate(templateId: string, args: {
65
+ [key: string]: unknown;
66
+ }, size?: {
67
+ width: number;
68
+ height: number;
69
+ }): Promise<ArrayBuffer>;
70
+ /**
71
+ * Create JPG Image from private template,
72
+ * you can manage it on <https://dashboard.ireceipt.pro>
73
+ *
74
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
75
+ * @param args - arguments for substitution in the template
76
+ * @param size - the size of the file being created
77
+ * @returns
78
+ */
79
+ createJpgFromPrivateTemplate(templateId: string, args: {
80
+ [key: string]: unknown;
81
+ }, size?: {
82
+ width: number;
83
+ height: number;
84
+ }): Promise<ArrayBuffer>;
85
+ /**
86
+ * Create PDF File from private template,
87
+ * you can manage it on <https://dashboard.ireceipt.pro>
88
+ *
89
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
90
+ * @param args - arguments for substitution in the template
91
+ * @param size - the size of the file being created
92
+ * @returns
93
+ */
94
+ createPdfFromPrivateTemplate(templateId: string, args: {
95
+ [key: string]: unknown;
96
+ }, size?: {
97
+ width: number;
98
+ height: number;
99
+ }): Promise<ArrayBuffer>;
100
+ /**
101
+ * Create PNG Image from private template,
102
+ * you can manage it on <https://dashboard.ireceipt.pro>
103
+ *
104
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
105
+ * @param args - arguments for substitution in the template
106
+ * @param size - the size of the file being created
107
+ * @returns
108
+ */
109
+ createPngFromPrivateTemplate(templateId: string, args: {
110
+ [key: string]: unknown;
111
+ }, size?: {
112
+ width: number;
113
+ height: number;
114
+ }): Promise<ArrayBuffer>;
115
+ /**
116
+ * Create WEBP Image from private template,
117
+ * you can manage it on <https://dashboard.ireceipt.pro>
118
+ *
119
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
120
+ * @param args - arguments for substitution in the template
121
+ * @param size - the size of the file being created
122
+ * @returns
123
+ */
124
+ createWebpFromPrivateTemplate(templateId: string, args: {
125
+ [key: string]: unknown;
126
+ }, size?: {
127
+ width: number;
128
+ height: number;
129
+ }): Promise<ArrayBuffer>;
130
+ }
package/lib/index.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IReceiptPRO = void 0;
4
+ const methods_1 = require("./methods");
5
+ class IReceiptPRO {
6
+ /**
7
+ *
8
+ * @param apiKey - IReceipt PRO API KEY, you can get it on <https://dashboard.ireceipt.pro>
9
+ */
10
+ constructor(apiKey) {
11
+ this.apiKey = apiKey;
12
+ }
13
+ /**
14
+ *
15
+ * @param apiKey - IReceipt PRO API KEY, you can get it on <https://dashboard.ireceipt.pro>
16
+ * @returns
17
+ */
18
+ static useApiKey(apiKey) {
19
+ return new IReceiptPRO(apiKey);
20
+ }
21
+ /**
22
+ * Create JPG Image from public template
23
+ *
24
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
25
+ * @param args - arguments for substitution in the template
26
+ * @param size - the size of the file being created
27
+ * @returns
28
+ */
29
+ createJpgFromPublicTemplate(templateId, args, size) {
30
+ if (!this.apiKey)
31
+ throw new Error("Initialization is required before use");
32
+ return (0, methods_1.createFile)(this.apiKey, "jpg", "public", templateId, args, size);
33
+ }
34
+ /**
35
+ * Create PDF File from public template
36
+ *
37
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
38
+ * @param args - arguments for substitution in the template
39
+ * @param size - the size of the file being created
40
+ * @returns
41
+ */
42
+ createPdfFromPublicTemplate(templateId, args, size) {
43
+ if (!this.apiKey)
44
+ throw new Error("Initialization is required before use");
45
+ return (0, methods_1.createFile)(this.apiKey, "pdf", "public", templateId, args, size);
46
+ }
47
+ /**
48
+ * Create PNG Image from public template
49
+ *
50
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
51
+ * @param args - arguments for substitution in the template
52
+ * @param size - the size of the file being created
53
+ * @returns
54
+ */
55
+ createPngFromPublicTemplate(templateId, args, size) {
56
+ if (!this.apiKey)
57
+ throw new Error("Initialization is required before use");
58
+ return (0, methods_1.createFile)(this.apiKey, "png", "public", templateId, args, size);
59
+ }
60
+ /**
61
+ * Create WEBP Image from public template
62
+ *
63
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
64
+ * @param args - arguments for substitution in the template
65
+ * @param size - the size of the file being created
66
+ * @returns
67
+ */
68
+ createWebpFromPublicTemplate(templateId, args, size) {
69
+ if (!this.apiKey)
70
+ throw new Error("Initialization is required before use");
71
+ return (0, methods_1.createFile)(this.apiKey, "webp", "public", templateId, args, size);
72
+ }
73
+ /**
74
+ * Create JPG Image from private template,
75
+ * you can manage it on <https://dashboard.ireceipt.pro>
76
+ *
77
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
78
+ * @param args - arguments for substitution in the template
79
+ * @param size - the size of the file being created
80
+ * @returns
81
+ */
82
+ createJpgFromPrivateTemplate(templateId, args, size) {
83
+ if (!this.apiKey)
84
+ throw new Error("Initialization is required before use");
85
+ return (0, methods_1.createFile)(this.apiKey, "jpg", "private", templateId, args, size);
86
+ }
87
+ /**
88
+ * Create PDF File from private template,
89
+ * you can manage it on <https://dashboard.ireceipt.pro>
90
+ *
91
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
92
+ * @param args - arguments for substitution in the template
93
+ * @param size - the size of the file being created
94
+ * @returns
95
+ */
96
+ createPdfFromPrivateTemplate(templateId, args, size) {
97
+ if (!this.apiKey)
98
+ throw new Error("Initialization is required before use");
99
+ return (0, methods_1.createFile)(this.apiKey, "pdf", "private", templateId, args, size);
100
+ }
101
+ /**
102
+ * Create PNG Image from private template,
103
+ * you can manage it on <https://dashboard.ireceipt.pro>
104
+ *
105
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
106
+ * @param args - arguments for substitution in the template
107
+ * @param size - the size of the file being created
108
+ * @returns
109
+ */
110
+ createPngFromPrivateTemplate(templateId, args, size) {
111
+ if (!this.apiKey)
112
+ throw new Error("Initialization is required before use");
113
+ return (0, methods_1.createFile)(this.apiKey, "png", "private", templateId, args, size);
114
+ }
115
+ /**
116
+ * Create WEBP Image from private template,
117
+ * you can manage it on <https://dashboard.ireceipt.pro>
118
+ *
119
+ * @param templateId - template id, you can find it on <https://dashboard.ireceipt.pro>
120
+ * @param args - arguments for substitution in the template
121
+ * @param size - the size of the file being created
122
+ * @returns
123
+ */
124
+ createWebpFromPrivateTemplate(templateId, args, size) {
125
+ if (!this.apiKey)
126
+ throw new Error("Initialization is required before use");
127
+ return (0, methods_1.createFile)(this.apiKey, "webp", "private", templateId, args, size);
128
+ }
129
+ }
130
+ exports.IReceiptPRO = IReceiptPRO;
131
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AAEvC,MAAa,WAAW;IACtB;;;OAGG;IACH,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAID;;;;OAIG;IACI,MAAM,CAAC,SAAS,CAAC,MAAc;QACpC,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;;OAOG;IACI,2BAA2B,CAChC,UAAkB,EAClB,IAAgC,EAChC,IAAwC;QAExC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3E,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;;;OAOG;IACI,2BAA2B,CAChC,UAAkB,EAClB,IAAgC,EAChC,IAAwC;QAExC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3E,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;;;OAOG;IACI,2BAA2B,CAChC,UAAkB,EAClB,IAAgC,EAChC,IAAwC;QAExC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3E,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;;;OAOG;IACI,4BAA4B,CACjC,UAAkB,EAClB,IAAgC,EAChC,IAAwC;QAExC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3E,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;OAQG;IACI,4BAA4B,CACjC,UAAkB,EAClB,IAAgC,EAChC,IAAwC;QAExC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3E,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;OAQG;IACI,4BAA4B,CACjC,UAAkB,EAClB,IAAgC,EAChC,IAAwC;QAExC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3E,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;OAQG;IACI,4BAA4B,CACjC,UAAkB,EAClB,IAAgC,EAChC,IAAwC;QAExC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3E,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;OAQG;IACI,6BAA6B,CAClC,UAAkB,EAClB,IAAgC,EAChC,IAAwC;QAExC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3E,OAAO,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5E,CAAC;CACF;AA/JD,kCA+JC"}
@@ -0,0 +1,6 @@
1
+ export declare const createFile: (apiKey: string, type: "jpg" | "png" | "webp" | "pdf", templateType: "public" | "private", templateId: string, args: {
2
+ [key: string]: unknown;
3
+ }, size?: {
4
+ width: number;
5
+ height: number;
6
+ }) => Promise<ArrayBuffer>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFile = void 0;
4
+ const axios_1 = require("axios");
5
+ const constants_1 = require("../utils/constants");
6
+ const handleError_1 = require("../utils/handleError");
7
+ const createFile = async (apiKey, type, templateType, templateId, args, size) => {
8
+ let attempt = 1;
9
+ let buffer;
10
+ let error;
11
+ while (attempt <= 5 && !buffer) {
12
+ try {
13
+ const res = await axios_1.default.post(`${constants_1.apiUrl}${type}/${templateType}/${templateId}`, {
14
+ variables: args || {},
15
+ size,
16
+ }, {
17
+ headers: {
18
+ Authorization: `Bearer ${apiKey}`,
19
+ "User-Agent": "IReceipt PRO JS Library",
20
+ },
21
+ responseType: "arraybuffer",
22
+ });
23
+ if (res.status === 201) {
24
+ buffer = res.data;
25
+ }
26
+ else {
27
+ error = new Error(res.data);
28
+ }
29
+ }
30
+ catch (err) {
31
+ error = (0, handleError_1.handleError)(err);
32
+ }
33
+ attempt++;
34
+ if (!buffer)
35
+ await new Promise((res) => {
36
+ setTimeout(res, attempt * 1000);
37
+ });
38
+ }
39
+ if (!buffer)
40
+ throw error;
41
+ return buffer;
42
+ };
43
+ exports.createFile = createFile;
44
+ //# sourceMappingURL=createFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFile.js","sourceRoot":"","sources":["../../src/methods/createFile.ts"],"names":[],"mappings":";;;AAAA,iCAA0B;AAC1B,kDAA4C;AAC5C,sDAAmD;AAE5C,MAAM,UAAU,GAAG,KAAK,EAC7B,MAAc,EACd,IAAoC,EACpC,YAAkC,EAClC,UAAkB,EAClB,IAAgC,EAChC,IAAwC,EAClB,EAAE;IACxB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,MAA+B,CAAC;IACpC,IAAI,KAAwB,CAAC;IAC7B,OAAO,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC/B,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,IAAI,CAC1B,GAAG,kBAAM,GAAG,IAAI,IAAI,YAAY,IAAI,UAAU,EAAE,EAChD;gBACE,SAAS,EAAE,IAAI,IAAI,EAAE;gBACrB,IAAI;aACL,EACD;gBACE,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,MAAM,EAAE;oBACjC,YAAY,EAAE,yBAAyB;iBACxC;gBACD,YAAY,EAAE,aAAa;aAC5B,CACF,CAAC;YACF,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACvB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,KAAK,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,KAAK,GAAG,IAAA,yBAAW,EAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,EAAE,CAAC;QACV,IAAI,CAAC,MAAM;YACT,MAAM,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACxB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC,CAAC;YAClC,CAAC,CAAC,CAAC;IACP,CAAC;IACD,IAAI,CAAC,MAAM;QAAE,MAAM,KAAK,CAAC;IACzB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA3CW,QAAA,UAAU,cA2CrB"}
@@ -0,0 +1,2 @@
1
+ import { createFile } from "./createFile";
2
+ export { createFile };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFile = void 0;
4
+ const createFile_1 = require("./createFile");
5
+ Object.defineProperty(exports, "createFile", { enumerable: true, get: function () { return createFile_1.createFile; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/methods/index.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAEjC,2FAFA,uBAAU,OAEA"}
@@ -0,0 +1 @@
1
+ export declare const apiUrl = "https://api.ireceipt.pro/v1/";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiUrl = void 0;
4
+ exports.apiUrl = "https://api.ireceipt.pro/v1/";
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG,8BAA8B,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { AxiosError } from "axios";
2
+ export declare const handleError: (err: AxiosError | Error | any) => Error;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleError = void 0;
4
+ const axios_1 = require("axios");
5
+ const handleError = (err) => {
6
+ if (err instanceof axios_1.AxiosError) {
7
+ try {
8
+ const respText = err.response?.data?.toString();
9
+ const respJSON = respText
10
+ ? JSON.parse(respText)
11
+ : { message: `Unknown error with status code ${err.code}` };
12
+ return new Error(respJSON.message);
13
+ }
14
+ catch (e) {
15
+ return new Error(`Unknown error with status code ${err.code}`);
16
+ }
17
+ }
18
+ if (err instanceof Error)
19
+ return err;
20
+ return new Error(err?.message || `Unknown error with status code ${err?.code}`);
21
+ };
22
+ exports.handleError = handleError;
23
+ //# sourceMappingURL=handleError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleError.js","sourceRoot":"","sources":["../../src/utils/handleError.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AAE5B,MAAM,WAAW,GAAG,CAAC,GAA6B,EAAE,EAAE;IAC3D,IAAI,GAAG,YAAY,kBAAU,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;YAChD,MAAM,QAAQ,GAAG,QAAQ;gBACvB,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAyB;gBAC/C,CAAC,CAAC,EAAE,OAAO,EAAE,kCAAkC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9D,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,IAAI,KAAK,CAAC,kCAAkC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IACD,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC;IACrC,OAAO,IAAI,KAAK,CACd,GAAG,EAAE,OAAO,IAAI,kCAAkC,GAAG,EAAE,IAAI,EAAE,CAC9D,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,WAAW,eAgBtB"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@ireceipt.pro/js",
3
+ "version": "0.0.1",
4
+ "description": "Create PDF files or images from your HTML template.",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "scripts": {
8
+ "test": "node_modules/.bin/mocha test/**/*.test.js",
9
+ "cov": "node_modules/.bin/nyc npm run test",
10
+ "prebuild": "node_modules/.bin/eslint -c .eslintrc.js --ext .ts src",
11
+ "build": "rm -rf lib && node_modules/.bin/tsc --declaration",
12
+ "update": "eval \"$(node -e 'const t = require(`./package.json`);const ignore = require(`./ignoreUpdatesModules.json`);console.log(`npm i ${(Object.keys(t.dependencies || {}).filter((e)=>ignore.base.indexOf(e) === -1).map((e)=>(`${e}@latest`)).join(` `))} --save&&npm i ${(Object.keys(t.devDependencies || {}).filter((e)=>ignore.dev.indexOf(e) === -1).map((e)=>(`${e}@latest`)).join(` `))} --save-dev`);')\""
13
+ },
14
+ "author": "Siarhei Dudko",
15
+ "funding": [
16
+ {
17
+ "type": "buymeacoffee",
18
+ "url": "https://www.buymeacoffee.com/dudko.dev"
19
+ },
20
+ {
21
+ "type": "paypal",
22
+ "url": "https://paypal.me/dudkodev"
23
+ },
24
+ {
25
+ "type": "patreon",
26
+ "url": "https://patreon.com/dudko_dev"
27
+ }
28
+ ],
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "github:ireceipt-pro/js"
33
+ },
34
+ "keywords": [
35
+ "PDF",
36
+ "JPG",
37
+ "JPEG",
38
+ "PNG",
39
+ "WEBP",
40
+ "IMAGE",
41
+ "template",
42
+ "templates",
43
+ "mustache",
44
+ "invoice",
45
+ "giftcard"
46
+ ],
47
+ "homepage": "https://www.npmjs.com/package/@ireceipt-pro/js",
48
+ "devDependencies": {
49
+ "@types/node": "^20.8.4",
50
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
51
+ "@typescript-eslint/parser": "^6.20.0",
52
+ "eslint": "^8.56.0",
53
+ "eslint-config-prettier": "^9.1.0",
54
+ "eslint-plugin-import": "^2.29.1",
55
+ "mocha": "^10.2.0",
56
+ "nyc": "^15.1.0",
57
+ "typescript": "^5.3.3"
58
+ },
59
+ "engines": {
60
+ "node": ">=14"
61
+ },
62
+ "directorie": {
63
+ "test": "./test/"
64
+ },
65
+ "dependencies": {
66
+ "axios": "^1.6.7"
67
+ }
68
+ }