@orchesty/connector-fapi 1.0.0

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 (99) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +190 -0
  3. package/coverage/clover.xml +234 -0
  4. package/coverage/coverage-final.json +12 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +87 -0
  7. package/coverage/lcov-report/favicon.png +0 -0
  8. package/coverage/lcov-report/index.html +161 -0
  9. package/coverage/lcov-report/prettify.css +1 -0
  10. package/coverage/lcov-report/prettify.js +2 -0
  11. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  12. package/coverage/lcov-report/sorter.js +210 -0
  13. package/coverage/lcov-report/src/Batch/AFapiListBatch.ts.html +373 -0
  14. package/coverage/lcov-report/src/Batch/FapiGetItemTemplateListBatch.ts.html +295 -0
  15. package/coverage/lcov-report/src/Batch/FapiGetLabelListBatch.ts.html +154 -0
  16. package/coverage/lcov-report/src/Batch/FapiGetProjectListBatch.ts.html +211 -0
  17. package/coverage/lcov-report/src/Batch/FapiGetShippingMethodListBatch.ts.html +238 -0
  18. package/coverage/lcov-report/src/Batch/FapiSubscribeWebhooksBatch.ts.html +364 -0
  19. package/coverage/lcov-report/src/Batch/FapiUnsubscribeWebhooksBatch.ts.html +247 -0
  20. package/coverage/lcov-report/src/Batch/index.html +206 -0
  21. package/coverage/lcov-report/src/Connector/FapiGetInvoiceConnector.ts.html +652 -0
  22. package/coverage/lcov-report/src/Connector/FapiPostInvoiceLabelConnector.ts.html +229 -0
  23. package/coverage/lcov-report/src/Connector/index.html +131 -0
  24. package/coverage/lcov-report/src/FapiApplication.ts.html +394 -0
  25. package/coverage/lcov-report/src/index.html +116 -0
  26. package/coverage/lcov-report/test/dataProvider.ts.html +187 -0
  27. package/coverage/lcov-report/test/index.html +116 -0
  28. package/coverage/lcov.info +380 -0
  29. package/dist/Batch/AFapiListBatch.d.ts +12 -0
  30. package/dist/Batch/AFapiListBatch.js +68 -0
  31. package/dist/Batch/FapiGetItemTemplateListBatch.d.ts +57 -0
  32. package/dist/Batch/FapiGetItemTemplateListBatch.js +18 -0
  33. package/dist/Batch/FapiGetLabelListBatch.d.ts +12 -0
  34. package/dist/Batch/FapiGetLabelListBatch.js +18 -0
  35. package/dist/Batch/FapiGetProjectListBatch.d.ts +29 -0
  36. package/dist/Batch/FapiGetProjectListBatch.js +18 -0
  37. package/dist/Batch/FapiGetShippingMethodListBatch.d.ts +38 -0
  38. package/dist/Batch/FapiGetShippingMethodListBatch.js +18 -0
  39. package/dist/Batch/FapiSubscribeWebhooksBatch.d.ts +7 -0
  40. package/dist/Batch/FapiSubscribeWebhooksBatch.js +62 -0
  41. package/dist/Batch/FapiUnsubscribeWebhooksBatch.d.ts +7 -0
  42. package/dist/Batch/FapiUnsubscribeWebhooksBatch.js +41 -0
  43. package/dist/Connector/FapiGetInvoiceConnector.d.ts +159 -0
  44. package/dist/Connector/FapiGetInvoiceConnector.js +26 -0
  45. package/dist/Connector/FapiPostInvoiceLabelConnector.d.ts +17 -0
  46. package/dist/Connector/FapiPostInvoiceLabelConnector.js +28 -0
  47. package/dist/FapiApplication.d.ts +24 -0
  48. package/dist/FapiApplication.js +99 -0
  49. package/dist/package.json +28 -0
  50. package/jest.config.js +13 -0
  51. package/package.json +28 -0
  52. package/src/Batch/AFapiListBatch.ts +96 -0
  53. package/src/Batch/FapiGetItemTemplateListBatch.ts +70 -0
  54. package/src/Batch/FapiGetLabelListBatch.ts +23 -0
  55. package/src/Batch/FapiGetProjectListBatch.ts +42 -0
  56. package/src/Batch/FapiGetShippingMethodListBatch.ts +51 -0
  57. package/src/Batch/FapiSubscribeWebhooksBatch.ts +93 -0
  58. package/src/Batch/FapiUnsubscribeWebhooksBatch.ts +54 -0
  59. package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/input.json +7 -0
  60. package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/mock.json +55 -0
  61. package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/output.json +11 -0
  62. package/src/Batch/__tests__/Data/FapiGetLabelListBatch/input.json +7 -0
  63. package/src/Batch/__tests__/Data/FapiGetLabelListBatch/mock.json +14 -0
  64. package/src/Batch/__tests__/Data/FapiGetLabelListBatch/output.json +11 -0
  65. package/src/Batch/__tests__/Data/FapiGetProjectListBatch/input.json +7 -0
  66. package/src/Batch/__tests__/Data/FapiGetProjectListBatch/mock.json +26 -0
  67. package/src/Batch/__tests__/Data/FapiGetProjectListBatch/output.json +11 -0
  68. package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/input.json +7 -0
  69. package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/mock.json +31 -0
  70. package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/output.json +11 -0
  71. package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/input.json +7 -0
  72. package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/mock.json +17 -0
  73. package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/output.json +6 -0
  74. package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/1-mock.json +5 -0
  75. package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/input.json +7 -0
  76. package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/mock.json +5 -0
  77. package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/output.json +9 -0
  78. package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/output1.json +7 -0
  79. package/src/Batch/__tests__/FapiGetItemTemplateListBatch.ts +17 -0
  80. package/src/Batch/__tests__/FapiGetLabelListBatch.ts +17 -0
  81. package/src/Batch/__tests__/FapiGetProjectListBatch.ts +17 -0
  82. package/src/Batch/__tests__/FapiGetShippingMethodListBatch.ts +17 -0
  83. package/src/Batch/__tests__/FapiSubscribeWebhooksBatch.ts +45 -0
  84. package/src/Batch/__tests__/FapiUnsubscribeWebhooksBatch.ts +57 -0
  85. package/src/Connector/FapiGetInvoiceConnector.ts +189 -0
  86. package/src/Connector/FapiPostInvoiceLabelConnector.ts +48 -0
  87. package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/input.json +8 -0
  88. package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/mock.json +223 -0
  89. package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/output.json +224 -0
  90. package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/input.json +11 -0
  91. package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/mock.json +12 -0
  92. package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/output.json +13 -0
  93. package/src/Connector/__tests__/FapiGetInvoiceConnector.ts +17 -0
  94. package/src/Connector/__tests__/FapiPostInvoiceLabelConnector.ts +17 -0
  95. package/src/FapiApplication.ts +103 -0
  96. package/test/dataProvider.ts +34 -0
  97. package/tsconfig.json +8 -0
  98. package/tsconfig.prod.json +13 -0
  99. package/tsconfig.prod.tsbuildinfo +1 -0
@@ -0,0 +1,223 @@
1
+ {
2
+ "http": "GET https://api.fapi.cz/invoices/1",
3
+ "code": 200,
4
+ "body": {
5
+ "id": 239,
6
+ "number": "20180020",
7
+ "created_on": "2018-08-31 15:04:59",
8
+ "last_modified_on": "2018-08-31 15:08:08",
9
+ "create_date": "2018-08-31",
10
+ "automatic_charge_date": null,
11
+ "payday_date": "2018-09-10",
12
+ "client": 23,
13
+ "type": "simplified_invoice",
14
+ "payment_type": "wire",
15
+ "currency": "CZK",
16
+ "exchange_rate_czk": "1.00000000000000000000",
17
+ "exchange_rate": "1.00000000000000000000",
18
+ "language": "pl",
19
+ "paid": true,
20
+ "cancelled": false,
21
+ "cancellation_reason": null,
22
+ "reverse_charge": false,
23
+ "tax_exempt": false,
24
+ "round_function": "floor",
25
+ "round_precision": 0,
26
+ "vat_recapitulation_algorithm": "pohoda",
27
+ "payment_confirmation_mode": "default",
28
+ "preserve_vat_date_on_invoice": false,
29
+ "has_credit_note": false,
30
+ "create_invoice_automatically": true,
31
+ "create_payment_confirmation": true,
32
+ "create_simplified_invoice": true,
33
+ "path": "eg20z2nd8wbhosoabxz64p9a4k0mv6kdlpwhurhr",
34
+ "recurring_gopay_payment_id": null,
35
+ "campaign_code": null,
36
+ "periodic_invoice": null,
37
+ "periodic_invoice_number": null,
38
+ "locked": false,
39
+ "proforma": false,
40
+ "payment_confirmation": false,
41
+ "simplified_invoice": true,
42
+ "credit_note": false,
43
+ "show_vat_info": false,
44
+ "paid_on": "2018-08-31 00:00:00",
45
+ "variable_symbol": "20180020",
46
+ "vat_date": "2018-08-31",
47
+ "supplier": {
48
+ "name": "TESTER s.r.o.",
49
+ "ic": "61989100",
50
+ "dic": "CZ683555119",
51
+ "ic_dph": "SK1212121218",
52
+ "swift": "GIBACZPX",
53
+ "iban": "CZ8508000000002677686023",
54
+ "bank_account": "test",
55
+ "address": {
56
+ "street": "Testovací 32",
57
+ "city": "Hong Kong",
58
+ "zip": "544 00W",
59
+ "country": "CZ"
60
+ }
61
+ },
62
+ "customer": {
63
+ "name": "slischkaj@seznam.com",
64
+ "email": "slischkaj@seznam.com",
65
+ "address": {
66
+ "country": "CZ"
67
+ }
68
+ },
69
+ "form": 16,
70
+ "items": [
71
+ {
72
+ "id": 600,
73
+ "invoice": 239,
74
+ "name": "simple",
75
+ "code": "86096",
76
+ "accounting_code": null,
77
+ "price": 1066,
78
+ "count": 1,
79
+ "round_item": false,
80
+ "correction_item": false,
81
+ "type": "good",
82
+ "moss": false,
83
+ "pohoda_accounting": null,
84
+ "pohoda_centre": null,
85
+ "pohoda_store": null,
86
+ "pohoda_stock_item": null,
87
+ "vat": 21,
88
+ "including_vat": false
89
+ },
90
+ {
91
+ "id": 601,
92
+ "invoice": 239,
93
+ "name": "Zaokrouhlení",
94
+ "code": null,
95
+ "accounting_code": null,
96
+ "price": -0.71,
97
+ "count": 1,
98
+ "round_item": true,
99
+ "correction_item": false,
100
+ "type": "good",
101
+ "moss": false,
102
+ "pohoda_accounting": null,
103
+ "pohoda_centre": null,
104
+ "pohoda_store": null,
105
+ "pohoda_stock_item": null,
106
+ "vat": 21,
107
+ "including_vat": false
108
+ }
109
+ ],
110
+ "custom_fields": [
111
+ {
112
+ "invoice_custom_fields_data_id": 4632174,
113
+ "custom_field_id": 1117,
114
+ "value": "hodnota",
115
+ "name": "a",
116
+ "type": "text"
117
+ },
118
+ {
119
+ "invoice_custom_fields_data_id": 4632174,
120
+ "custom_field_id": 1253,
121
+ "value": "[\"test 1\"]",
122
+ "name": "test multicheckbox",
123
+ "type": "multi_checkbox"
124
+ },
125
+ {
126
+ "invoice_custom_fields_data_id": 4632174,
127
+ "custom_field_id": 2903,
128
+ "value": "partner 1",
129
+ "name": "Partner",
130
+ "type": "radio"
131
+ },
132
+ {
133
+ "invoice_custom_fields_data_id": 4632174,
134
+ "custom_field_id": 2904,
135
+ "value": "partner 2",
136
+ "name": "Partner",
137
+ "type": "select_box"
138
+ },
139
+ {
140
+ "invoice_custom_fields_data_id": 4632174,
141
+ "custom_field_id": 3282,
142
+ "value": "hodnota",
143
+ "name": "B2BZasilka",
144
+ "type": "text"
145
+ }
146
+ ],
147
+ "shipping_method": {
148
+ "id": 2743,
149
+ "user_id": 7678,
150
+ "name": "Výdení místa zásilkovna",
151
+ "type": "packatery",
152
+ "subtype": "packatery_personal_collection",
153
+ "address_prices": [
154
+ {
155
+ "address": {
156
+ "country_code": "CZ"
157
+ },
158
+ "prices": [
159
+ {
160
+ "currency_code": "CZK",
161
+ "price": 99
162
+ }
163
+ ]
164
+ },
165
+ {
166
+ "address": {
167
+ "country_code": "SK"
168
+ },
169
+ "prices": [
170
+ {
171
+ "currency_code": "EUR",
172
+ "price": 4.9
173
+ }
174
+ ]
175
+ },
176
+ {
177
+ "address": {
178
+ "country_code": "PL"
179
+ },
180
+ "prices": [
181
+ {
182
+ "currency_code": "EUR",
183
+ "price": 1
184
+ }
185
+ ]
186
+ },
187
+ {
188
+ "address": {
189
+ "country_code": "DE"
190
+ },
191
+ "prices": [
192
+ {
193
+ "currency_code": "EUR",
194
+ "price": 1
195
+ }
196
+ ]
197
+ }
198
+ ],
199
+ "free_of_charges": "[]",
200
+ "meta_data": null,
201
+ "including_vat": 0,
202
+ "description": null,
203
+ "disable_discount": 0,
204
+ "deleted": 0
205
+ },
206
+ "total": 1289,
207
+ "total_vat": 223.71,
208
+ "total_czk": 1289,
209
+ "total_vat_czk": 223.71,
210
+ "total_native": 1289,
211
+ "total_vat_native": 223.71,
212
+ "user": 3,
213
+ "form_url": "http://web.fapi.log/forms/preview/16?projectId=all",
214
+ "session_id": null,
215
+ "labels": [
216
+ {
217
+ "id": 5,
218
+ "name": "test_label",
219
+ "color": "#ff0000"
220
+ }
221
+ ]
222
+ }
223
+ }
@@ -0,0 +1,224 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "automatic_charge_date": null,
7
+ "campaign_code": null,
8
+ "cancellation_reason": null,
9
+ "cancelled": false,
10
+ "client": 23,
11
+ "create_date": "2018-08-31",
12
+ "create_invoice_automatically": true,
13
+ "create_payment_confirmation": true,
14
+ "create_simplified_invoice": true,
15
+ "created_on": "2018-08-31 15:04:59",
16
+ "credit_note": false,
17
+ "currency": "CZK",
18
+ "custom_fields": [
19
+ {
20
+ "custom_field_id": 1117,
21
+ "invoice_custom_fields_data_id": 4632174,
22
+ "name": "a",
23
+ "type": "text",
24
+ "value": "hodnota"
25
+ },
26
+ {
27
+ "custom_field_id": 1253,
28
+ "invoice_custom_fields_data_id": 4632174,
29
+ "name": "test multicheckbox",
30
+ "type": "multi_checkbox",
31
+ "value": "[\"test 1\"]"
32
+ },
33
+ {
34
+ "custom_field_id": 2903,
35
+ "invoice_custom_fields_data_id": 4632174,
36
+ "name": "Partner",
37
+ "type": "radio",
38
+ "value": "partner 1"
39
+ },
40
+ {
41
+ "custom_field_id": 2904,
42
+ "invoice_custom_fields_data_id": 4632174,
43
+ "name": "Partner",
44
+ "type": "select_box",
45
+ "value": "partner 2"
46
+ },
47
+ {
48
+ "custom_field_id": 3282,
49
+ "invoice_custom_fields_data_id": 4632174,
50
+ "name": "B2BZasilka",
51
+ "type": "text",
52
+ "value": "hodnota"
53
+ }
54
+ ],
55
+ "customer": {
56
+ "address": {
57
+ "country": "CZ"
58
+ },
59
+ "email": "slischkaj@seznam.com",
60
+ "name": "slischkaj@seznam.com"
61
+ },
62
+ "exchange_rate": "1.00000000000000000000",
63
+ "exchange_rate_czk": "1.00000000000000000000",
64
+ "form": 16,
65
+ "form_url": "http://web.fapi.log/forms/preview/16?projectId=all",
66
+ "has_credit_note": false,
67
+ "id": 239,
68
+ "items": [
69
+ {
70
+ "accounting_code": null,
71
+ "code": "86096",
72
+ "correction_item": false,
73
+ "count": 1,
74
+ "id": 600,
75
+ "including_vat": false,
76
+ "invoice": 239,
77
+ "moss": false,
78
+ "name": "simple",
79
+ "pohoda_accounting": null,
80
+ "pohoda_centre": null,
81
+ "pohoda_stock_item": null,
82
+ "pohoda_store": null,
83
+ "price": 1066,
84
+ "round_item": false,
85
+ "type": "good",
86
+ "vat": 21
87
+ },
88
+ {
89
+ "accounting_code": null,
90
+ "code": null,
91
+ "correction_item": false,
92
+ "count": 1,
93
+ "id": 601,
94
+ "including_vat": false,
95
+ "invoice": 239,
96
+ "moss": false,
97
+ "name": "Zaokrouhlení",
98
+ "pohoda_accounting": null,
99
+ "pohoda_centre": null,
100
+ "pohoda_stock_item": null,
101
+ "pohoda_store": null,
102
+ "price": -0.71,
103
+ "round_item": true,
104
+ "type": "good",
105
+ "vat": 21
106
+ }
107
+ ],
108
+ "labels": [
109
+ {
110
+ "color": "#ff0000",
111
+ "id": 5,
112
+ "name": "test_label"
113
+ }
114
+ ],
115
+ "language": "pl",
116
+ "last_modified_on": "2018-08-31 15:08:08",
117
+ "locked": false,
118
+ "number": "20180020",
119
+ "paid": true,
120
+ "paid_on": "2018-08-31 00:00:00",
121
+ "path": "eg20z2nd8wbhosoabxz64p9a4k0mv6kdlpwhurhr",
122
+ "payday_date": "2018-09-10",
123
+ "payment_confirmation": false,
124
+ "payment_confirmation_mode": "default",
125
+ "payment_type": "wire",
126
+ "periodic_invoice": null,
127
+ "periodic_invoice_number": null,
128
+ "preserve_vat_date_on_invoice": false,
129
+ "proforma": false,
130
+ "recurring_gopay_payment_id": null,
131
+ "reverse_charge": false,
132
+ "round_function": "floor",
133
+ "round_precision": 0,
134
+ "session_id": null,
135
+ "shipping_method": {
136
+ "address_prices": [
137
+ {
138
+ "address": {
139
+ "country_code": "CZ"
140
+ },
141
+ "prices": [
142
+ {
143
+ "currency_code": "CZK",
144
+ "price": 99
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ "address": {
150
+ "country_code": "SK"
151
+ },
152
+ "prices": [
153
+ {
154
+ "currency_code": "EUR",
155
+ "price": 4.9
156
+ }
157
+ ]
158
+ },
159
+ {
160
+ "address": {
161
+ "country_code": "PL"
162
+ },
163
+ "prices": [
164
+ {
165
+ "currency_code": "EUR",
166
+ "price": 1
167
+ }
168
+ ]
169
+ },
170
+ {
171
+ "address": {
172
+ "country_code": "DE"
173
+ },
174
+ "prices": [
175
+ {
176
+ "currency_code": "EUR",
177
+ "price": 1
178
+ }
179
+ ]
180
+ }
181
+ ],
182
+ "deleted": 0,
183
+ "description": null,
184
+ "disable_discount": 0,
185
+ "free_of_charges": "[]",
186
+ "id": 2743,
187
+ "including_vat": 0,
188
+ "meta_data": null,
189
+ "name": "Výdení místa zásilkovna",
190
+ "subtype": "packatery_personal_collection",
191
+ "type": "packatery",
192
+ "user_id": 7678
193
+ },
194
+ "show_vat_info": false,
195
+ "simplified_invoice": true,
196
+ "supplier": {
197
+ "address": {
198
+ "city": "Hong Kong",
199
+ "country": "CZ",
200
+ "street": "Testovací 32",
201
+ "zip": "544 00W"
202
+ },
203
+ "bank_account": "test",
204
+ "dic": "CZ683555119",
205
+ "iban": "CZ8508000000002677686023",
206
+ "ic": "61989100",
207
+ "ic_dph": "SK1212121218",
208
+ "name": "TESTER s.r.o.",
209
+ "swift": "GIBACZPX"
210
+ },
211
+ "tax_exempt": false,
212
+ "total": 1289,
213
+ "total_czk": 1289,
214
+ "total_native": 1289,
215
+ "total_vat": 223.71,
216
+ "total_vat_czk": 223.71,
217
+ "total_vat_native": 223.71,
218
+ "type": "simplified_invoice",
219
+ "user": 3,
220
+ "variable_symbol": "20180020",
221
+ "vat_date": "2018-08-31",
222
+ "vat_recapitulation_algorithm": "pohoda"
223
+ }
224
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "id": 1,
7
+ "labels": [
8
+ 1
9
+ ]
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "http": "POST https://api.fapi.cz/invoice-labels/1",
3
+ "code": 200,
4
+ "body": {
5
+ "status": "success",
6
+ "message": "success",
7
+ "invoice_id": 1,
8
+ "labels": [
9
+ 1
10
+ ]
11
+ }
12
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "status": "success",
7
+ "message": "success",
8
+ "invoice_id": 1,
9
+ "labels": [
10
+ 1
11
+ ]
12
+ }
13
+ }
@@ -0,0 +1,17 @@
1
+ import { container } from '@orchesty/nodejs-connectors/test/TestAbstract';
2
+ import NodeTester from '@orchesty/nodejs-sdk/dist/test/Testers/NodeTester';
3
+ import init from '../../../test/dataProvider';
4
+ import { NAME as FAPI_GET_INVOICE_CONNECTOR } from '../FapiGetInvoiceConnector';
5
+
6
+ let tester: NodeTester;
7
+
8
+ describe('Tests for FapiGetInvoiceConnector', () => {
9
+ beforeEach(() => {
10
+ tester = new NodeTester(container, __filename);
11
+ init();
12
+ });
13
+
14
+ it('process - ok', async () => {
15
+ await tester.testConnector(FAPI_GET_INVOICE_CONNECTOR);
16
+ });
17
+ });
@@ -0,0 +1,17 @@
1
+ import { container } from '@orchesty/nodejs-connectors/test/TestAbstract';
2
+ import NodeTester from '@orchesty/nodejs-sdk/dist/test/Testers/NodeTester';
3
+ import init from '../../../test/dataProvider';
4
+ import { NAME as FAPI_POST_INVOICE_LABEL_CONNECTOR } from '../FapiPostInvoiceLabelConnector';
5
+
6
+ let tester: NodeTester;
7
+
8
+ describe('Tests for FapiPostInvoiceLabelConnector', () => {
9
+ beforeEach(() => {
10
+ tester = new NodeTester(container, __filename);
11
+ init();
12
+ });
13
+
14
+ it('process - ok', async () => {
15
+ await tester.testConnector(FAPI_POST_INVOICE_LABEL_CONNECTOR);
16
+ });
17
+ });
@@ -0,0 +1,103 @@
1
+ import CoreFormsEnum, { getFormName } from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
2
+ import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
3
+ import Field from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Field';
4
+ import FieldType from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FieldType';
5
+ import Form from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Form';
6
+ import FormStack from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack';
7
+ import WebhookSubscription from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Webhook/WebhookSubscription';
8
+ import {
9
+ ABasicApplication,
10
+ PASSWORD,
11
+ USER,
12
+ } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication';
13
+ import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
14
+ import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
15
+ import AProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/AProcessDto';
16
+ import { encode } from '@orchesty/nodejs-sdk/dist/lib/Utils/Base64';
17
+ import { CommonHeaders, JSON_TYPE } from '@orchesty/nodejs-sdk/dist/lib/Utils/Headers';
18
+ import { AxiosResponse } from 'axios';
19
+
20
+ export const NAME = 'fapi';
21
+
22
+ export enum WebhookTypes {
23
+ ORDERED = 'ordered',
24
+ UPDATED = 'invoice_update',
25
+ PAID = 'paid',
26
+ }
27
+
28
+ export default class FapiApplication extends ABasicApplication {
29
+
30
+ public getName(): string {
31
+ return NAME;
32
+ }
33
+
34
+ public getDescription(): string {
35
+ return 'Jednoduchý online prodej';
36
+ }
37
+
38
+ public getPublicName(): string {
39
+ return 'Fapi';
40
+ }
41
+
42
+ public getLogo(): string {
43
+ return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPwAAABXBAMAAADSXjV5AAAACXBIWXMAAAsSAAALEgHS3X78AAAAJFBMVEVHcEwAbtsAbtsAbtsAbtsAbtsAbtsAbtsAbtsAbtsAbtsAbtstx4spAAAAC3RSTlMAwUCBX5wl2hDxsRVwA1oAAARZSURBVGjetZq/b9NQEMdffjlJWQIrS1QQQrAE2oksXhiQl4pKFSiLV5SlEkVC8mKBUFV1CVKFomap2rELifOjrv85aJvY78fd+2H7vS1+5/vEz1/f3TubEOfdY2TshoQbzvv7iX2fwAPwtb/bxeyuXEJaTxN0nHFntQbriWkI0hFfX13EbuWTZiIZ3B8/TifGIB7zFR8gdmPiyfCH7GmDdGIK4nFfT2C7iFzL8Ev2juHr8jAk9/ETaLeSnZIkM8Z7jZq5gPAB7il2QTsTfBtdl/WQuYpAOxO8h3jTwid7RfG0TFbG+EVBvMNMuaZ46vJz4WvM1IUxPiqGZ4PKjTE+e1h18Yy+XzNTc3P8d1P8CI559w+yOT4yxffoPCHPBxr42DfDL2jfdfw51sSnV6OHP3dl6ezGHD+W4Yl8DDlfcxk+PfQ8AG5+HvyAv5NaeFKl+NP8+NaEX0pfC09+iafkwNdlOUSGp5fNzY2vbMy+4QUXjD8WInUOfKq8j7j2YHxVKN5y4Pvp/QvQnAvjKcTf3PhJCh2g2kPwHp/CzPH1bMmHqPYQ/KPi+K0s2FVQ7SH4Ch93zPHUJddQ7SH4WnF8P3t0W2i9Zw9Py/0a0541fJXOwR5UDljFN+jyqw0WQzh+qzD+dGPUof/LXA/f5JO0Md6jk4aD7XMR/LDwc7+JeXHIbBF9LXyfr5xN8Q5b/fUR7cF4qlIYadd6q0tIeTN2NUc6+EZ2uGNQalIh/YTNmE1EezDeE0pdLfwc8NBj88+tBr6uWWwJyw+0I3xux+Gr8X3Ro16dHwrKm/I7/Z4K3/qgW2jjO1Ihx3lw6ys7dWc93gTQjtUQ3+YzfBvWnmqXs5cP7/HnN2DtqfB+Pvw1f8SBtaegL0guvCM+CwGovXLbCz6vvEh8mg6tNVdiIWEuxSQ208fPzVpLC0F5HbF4XVhrrI2FPaILRNLQUltx6vNNnTgEGj2uLr6nwO8wY9cXrnQB7ZpHmvgzVUsZqzXakMw86KCEPvXz4ofQQ9aGlgSnr7okLz5d58vtbLyCtIdfu0vy4sWmToK1tjGTI7wkVeLrilh2qMD/vnop2Qsq8U0FfqkstEkR/FA3j9nB91WN4tAqfqIqIlybeJXyaO1ZwFeU+KVN/FCJX9jE95X42CY+UOIz7ZWPVyuPKoLKx29p4Jf28Kca+Mge3tPAx/bwWcx7u82OZ6L2SsdXodAu/LOOLXwDfqXIvaNZ2sKfIF8SsPEwsoX3EriRwNYhK1v4IMHax0xEcu3gHdlLw5bsBVkp+EaCtW9B7ZWNb0s/VvAkjfJS8F6Cv7IEtFc2fiD7WID+lMUvjI+l34B15cLssuaxHE/ZDZD+LGs3VbzS77K/bzU/BbjNYpdUXH9AN1+4feYQD5FwvJxlwQO6u5t337ELv2WYsMqX+oIC1n+79Vb5CNzdfn6gHyB+fgbs/lnmix60nXOXvX3E8MfdZIg7upt+Qa2HzBcR7f4BpkgWeCA6iDMAAAAASUVORK5CYII=';
44
+ }
45
+
46
+ public getFormStack(): FormStack {
47
+ return new FormStack()
48
+ .addForm(
49
+ new Form(CoreFormsEnum.AUTHORIZATION_FORM, getFormName(CoreFormsEnum.AUTHORIZATION_FORM))
50
+ .addField(new Field(FieldType.TEXT, USER, 'User', undefined, true))
51
+ .addField(new Field(FieldType.TEXT, PASSWORD, 'Password', undefined, true)),
52
+ );
53
+ }
54
+
55
+ public getRequestDto(
56
+ dto: AProcessDto,
57
+ applicationInstall: ApplicationInstall,
58
+ method: HttpMethods,
59
+ url?: string,
60
+ data?: unknown,
61
+ ): RequestDto {
62
+ const { user, password } = applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM];
63
+
64
+ const requestDto = new RequestDto(
65
+ `https://api.fapi.cz/${url}`,
66
+ method,
67
+ dto,
68
+ undefined,
69
+ {
70
+ [CommonHeaders.CONTENT_TYPE]: JSON_TYPE,
71
+ [CommonHeaders.ACCEPT]: JSON_TYPE,
72
+ [CommonHeaders.AUTHORIZATION]: `Basic ${encode(`${user}:${password}`)}`,
73
+ },
74
+ );
75
+
76
+ if (data) {
77
+ requestDto.setJsonBody(data);
78
+ }
79
+
80
+ return requestDto;
81
+ }
82
+
83
+ public getWebhookSubscriptions(): WebhookSubscription[] {
84
+ return [];
85
+ }
86
+
87
+ }
88
+
89
+ // eslint-disable-next-line @typescript-eslint/require-await
90
+ export async function getErrorInResponse(response: AxiosResponse, body: string): Promise<string> {
91
+ const data = JSON.parse(body) as IErrorResponse;
92
+
93
+ if ('type' in data && 'message' in data) {
94
+ return `Error: ${data.type}: ${data.message}`;
95
+ }
96
+
97
+ return body;
98
+ }
99
+
100
+ interface IErrorResponse {
101
+ type: string;
102
+ message: string;
103
+ }
@@ -0,0 +1,34 @@
1
+ import { appInstall, DEFAULT_PASSWORD, DEFAULT_USER } from '@orchesty/nodejs-connectors/test/DataProvider';
2
+ import { container } from '@orchesty/nodejs-connectors/test/TestAbstract';
3
+ import CoreFormsEnum from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
4
+ import { PASSWORD, USER } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication';
5
+ import FapiGetItemTemplateListBatch from '../src/Batch/FapiGetItemTemplateListBatch';
6
+ import FapiGetLabelListBatch from '../src/Batch/FapiGetLabelListBatch';
7
+ import FapiGetProjectListBatch from '../src/Batch/FapiGetProjectListBatch';
8
+ import FapiGetShippingMethodListBatch from '../src/Batch/FapiGetShippingMethodListBatch';
9
+ import FapiSubscribeWebhooksBatch from '../src/Batch/FapiSubscribeWebhooksBatch';
10
+ import FapiUnsubscribeWebhooksBatch from '../src/Batch/FapiUnsubscribeWebhooksBatch';
11
+ import FapiGetInvoiceConnector from '../src/Connector/FapiGetInvoiceConnector';
12
+ import FapiPostInvoiceLabelConnector from '../src/Connector/FapiPostInvoiceLabelConnector';
13
+ import FapiApplication, { NAME as FAPI_APPLICATION } from '../src/FapiApplication';
14
+
15
+ export default function init(): void {
16
+ appInstall(FAPI_APPLICATION, DEFAULT_USER, {
17
+ [CoreFormsEnum.AUTHORIZATION_FORM]: {
18
+ [USER]: DEFAULT_USER,
19
+ [PASSWORD]: DEFAULT_PASSWORD,
20
+ },
21
+ });
22
+
23
+ const fapiApplication = new FapiApplication();
24
+ container.setApplication(fapiApplication);
25
+
26
+ container.setNode(new FapiGetItemTemplateListBatch(), fapiApplication);
27
+ container.setNode(new FapiGetLabelListBatch(), fapiApplication);
28
+ container.setNode(new FapiGetProjectListBatch(), fapiApplication);
29
+ container.setNode(new FapiGetShippingMethodListBatch(), fapiApplication);
30
+ container.setNode(new FapiSubscribeWebhooksBatch(), fapiApplication);
31
+ container.setNode(new FapiUnsubscribeWebhooksBatch(), fapiApplication);
32
+ container.setNode(new FapiGetInvoiceConnector(), fapiApplication);
33
+ container.setNode(new FapiPostInvoiceLabelConnector(), fapiApplication);
34
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "composite": true
6
+ },
7
+ "include": ["src", "test", "../../test"]
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ },
6
+ "include": [
7
+ "src",
8
+ ],
9
+ "exclude": [
10
+ "node_modules",
11
+ "src/**/__tests__",
12
+ ]
13
+ }