@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.
- package/CHANGELOG.md +7 -0
- package/LICENSE +190 -0
- package/coverage/clover.xml +234 -0
- package/coverage/coverage-final.json +12 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +161 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/src/Batch/AFapiListBatch.ts.html +373 -0
- package/coverage/lcov-report/src/Batch/FapiGetItemTemplateListBatch.ts.html +295 -0
- package/coverage/lcov-report/src/Batch/FapiGetLabelListBatch.ts.html +154 -0
- package/coverage/lcov-report/src/Batch/FapiGetProjectListBatch.ts.html +211 -0
- package/coverage/lcov-report/src/Batch/FapiGetShippingMethodListBatch.ts.html +238 -0
- package/coverage/lcov-report/src/Batch/FapiSubscribeWebhooksBatch.ts.html +364 -0
- package/coverage/lcov-report/src/Batch/FapiUnsubscribeWebhooksBatch.ts.html +247 -0
- package/coverage/lcov-report/src/Batch/index.html +206 -0
- package/coverage/lcov-report/src/Connector/FapiGetInvoiceConnector.ts.html +652 -0
- package/coverage/lcov-report/src/Connector/FapiPostInvoiceLabelConnector.ts.html +229 -0
- package/coverage/lcov-report/src/Connector/index.html +131 -0
- package/coverage/lcov-report/src/FapiApplication.ts.html +394 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/test/dataProvider.ts.html +187 -0
- package/coverage/lcov-report/test/index.html +116 -0
- package/coverage/lcov.info +380 -0
- package/dist/Batch/AFapiListBatch.d.ts +12 -0
- package/dist/Batch/AFapiListBatch.js +68 -0
- package/dist/Batch/FapiGetItemTemplateListBatch.d.ts +57 -0
- package/dist/Batch/FapiGetItemTemplateListBatch.js +18 -0
- package/dist/Batch/FapiGetLabelListBatch.d.ts +12 -0
- package/dist/Batch/FapiGetLabelListBatch.js +18 -0
- package/dist/Batch/FapiGetProjectListBatch.d.ts +29 -0
- package/dist/Batch/FapiGetProjectListBatch.js +18 -0
- package/dist/Batch/FapiGetShippingMethodListBatch.d.ts +38 -0
- package/dist/Batch/FapiGetShippingMethodListBatch.js +18 -0
- package/dist/Batch/FapiSubscribeWebhooksBatch.d.ts +7 -0
- package/dist/Batch/FapiSubscribeWebhooksBatch.js +62 -0
- package/dist/Batch/FapiUnsubscribeWebhooksBatch.d.ts +7 -0
- package/dist/Batch/FapiUnsubscribeWebhooksBatch.js +41 -0
- package/dist/Connector/FapiGetInvoiceConnector.d.ts +159 -0
- package/dist/Connector/FapiGetInvoiceConnector.js +26 -0
- package/dist/Connector/FapiPostInvoiceLabelConnector.d.ts +17 -0
- package/dist/Connector/FapiPostInvoiceLabelConnector.js +28 -0
- package/dist/FapiApplication.d.ts +24 -0
- package/dist/FapiApplication.js +99 -0
- package/dist/package.json +28 -0
- package/jest.config.js +13 -0
- package/package.json +28 -0
- package/src/Batch/AFapiListBatch.ts +96 -0
- package/src/Batch/FapiGetItemTemplateListBatch.ts +70 -0
- package/src/Batch/FapiGetLabelListBatch.ts +23 -0
- package/src/Batch/FapiGetProjectListBatch.ts +42 -0
- package/src/Batch/FapiGetShippingMethodListBatch.ts +51 -0
- package/src/Batch/FapiSubscribeWebhooksBatch.ts +93 -0
- package/src/Batch/FapiUnsubscribeWebhooksBatch.ts +54 -0
- package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/input.json +7 -0
- package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/mock.json +55 -0
- package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/output.json +11 -0
- package/src/Batch/__tests__/Data/FapiGetLabelListBatch/input.json +7 -0
- package/src/Batch/__tests__/Data/FapiGetLabelListBatch/mock.json +14 -0
- package/src/Batch/__tests__/Data/FapiGetLabelListBatch/output.json +11 -0
- package/src/Batch/__tests__/Data/FapiGetProjectListBatch/input.json +7 -0
- package/src/Batch/__tests__/Data/FapiGetProjectListBatch/mock.json +26 -0
- package/src/Batch/__tests__/Data/FapiGetProjectListBatch/output.json +11 -0
- package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/input.json +7 -0
- package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/mock.json +31 -0
- package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/output.json +11 -0
- package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/input.json +7 -0
- package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/mock.json +17 -0
- package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/output.json +6 -0
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/1-mock.json +5 -0
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/input.json +7 -0
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/mock.json +5 -0
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/output.json +9 -0
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/output1.json +7 -0
- package/src/Batch/__tests__/FapiGetItemTemplateListBatch.ts +17 -0
- package/src/Batch/__tests__/FapiGetLabelListBatch.ts +17 -0
- package/src/Batch/__tests__/FapiGetProjectListBatch.ts +17 -0
- package/src/Batch/__tests__/FapiGetShippingMethodListBatch.ts +17 -0
- package/src/Batch/__tests__/FapiSubscribeWebhooksBatch.ts +45 -0
- package/src/Batch/__tests__/FapiUnsubscribeWebhooksBatch.ts +57 -0
- package/src/Connector/FapiGetInvoiceConnector.ts +189 -0
- package/src/Connector/FapiPostInvoiceLabelConnector.ts +48 -0
- package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/input.json +8 -0
- package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/mock.json +223 -0
- package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/output.json +224 -0
- package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/input.json +11 -0
- package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/mock.json +12 -0
- package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/output.json +13 -0
- package/src/Connector/__tests__/FapiGetInvoiceConnector.ts +17 -0
- package/src/Connector/__tests__/FapiPostInvoiceLabelConnector.ts +17 -0
- package/src/FapiApplication.ts +103 -0
- package/test/dataProvider.ts +34 -0
- package/tsconfig.json +8 -0
- package/tsconfig.prod.json +13 -0
- package/tsconfig.prod.tsbuildinfo +1 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ABatchNode_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode"));
|
|
7
|
+
const HttpMethods_1 = require("@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods");
|
|
8
|
+
const luxon_1 = require("luxon");
|
|
9
|
+
const LAST_RUN = 'lastRun';
|
|
10
|
+
class AFapiListBatch extends ABatchNode_1.default {
|
|
11
|
+
async processAction(dto) {
|
|
12
|
+
let url = `${this.getUrl()}?limit=${await this.getLimit(dto)}&offset=${await this.getOffset(dto)}`;
|
|
13
|
+
if (await this.useLastRun(dto)) {
|
|
14
|
+
const lastRun = await this.getLastRun(dto);
|
|
15
|
+
if (lastRun) {
|
|
16
|
+
url = `${url}&last_modified_after=${lastRun}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const requestDto = await this.getApplication().getRequestDto(dto, await this.getApplicationInstallFromProcess(dto), HttpMethods_1.HttpMethods.GET, url);
|
|
20
|
+
const responseDto = await this.getSender().send(requestDto, [200]);
|
|
21
|
+
const response = responseDto.getJsonBody();
|
|
22
|
+
const items = response[this.getUrl().replace('-', '_')];
|
|
23
|
+
dto.setItemList(items);
|
|
24
|
+
if (items.length === await this.getLimit(dto)) {
|
|
25
|
+
dto.setBatchCursor((Number(dto.getBatchCursor('1')) + 1).toString());
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
await this.setLastRun(dto);
|
|
29
|
+
}
|
|
30
|
+
return dto;
|
|
31
|
+
}
|
|
32
|
+
async getLimit(dto) {
|
|
33
|
+
return 1_000;
|
|
34
|
+
}
|
|
35
|
+
async getOffset(dto) {
|
|
36
|
+
return (Number(dto.getBatchCursor('1')) - 1) * await this.getLimit(dto);
|
|
37
|
+
}
|
|
38
|
+
async getLastRunKey(dto) {
|
|
39
|
+
return this.getUrl();
|
|
40
|
+
}
|
|
41
|
+
async useLastRun(dto) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
async getLastRun(dto) {
|
|
45
|
+
if (!await this.useLastRun(dto)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const applicationInstall = await this.getApplicationInstallFromProcess(dto);
|
|
49
|
+
const lastRun = applicationInstall.getNonEncryptedSettings()[LAST_RUN]?.[await this.getLastRunKey(dto)];
|
|
50
|
+
if (!lastRun) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return luxon_1.DateTime.fromISO(lastRun).toFormat('yyyy-MM-dd HH:mm:ss');
|
|
54
|
+
}
|
|
55
|
+
async setLastRun(dto) {
|
|
56
|
+
if (!await this.useLastRun(dto)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const applicationInstall = await this.getApplicationInstallFromProcess(dto);
|
|
60
|
+
applicationInstall.addNonEncryptedSettings({
|
|
61
|
+
[LAST_RUN]: {
|
|
62
|
+
[await this.getLastRunKey(dto)]: new Date().toISOString(),
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
await this.getDbClient().getApplicationRepository().update(applicationInstall);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.default = AFapiListBatch;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import AFapiListBatch from './AFapiListBatch';
|
|
2
|
+
export declare const NAME = "fapi-get-item-template-list-batch";
|
|
3
|
+
export default class FapiGetItemTemplateListBatch extends AFapiListBatch<unknown, IOutput> {
|
|
4
|
+
getName(): string;
|
|
5
|
+
protected getUrl(): string;
|
|
6
|
+
}
|
|
7
|
+
export interface IOutput {
|
|
8
|
+
id: number;
|
|
9
|
+
hidden: boolean;
|
|
10
|
+
name: string;
|
|
11
|
+
code: string;
|
|
12
|
+
accounting_code: string;
|
|
13
|
+
description: string;
|
|
14
|
+
price_czk: number;
|
|
15
|
+
price_eur: number;
|
|
16
|
+
price_usd: number;
|
|
17
|
+
repayment_amount_czk: number;
|
|
18
|
+
repayment_amount_eur: number;
|
|
19
|
+
repayment_amount_usd: number;
|
|
20
|
+
vat: number;
|
|
21
|
+
including_vat: boolean;
|
|
22
|
+
count: number;
|
|
23
|
+
sold_out: boolean;
|
|
24
|
+
allow_change_count: boolean;
|
|
25
|
+
enable_stock: boolean;
|
|
26
|
+
stock: number;
|
|
27
|
+
show_stock_information: boolean;
|
|
28
|
+
type: string;
|
|
29
|
+
electronically_supplied_service: boolean;
|
|
30
|
+
pohoda_accounting: string;
|
|
31
|
+
pohoda_centre: string;
|
|
32
|
+
pohoda_store: string;
|
|
33
|
+
pohoda_stock_item: string;
|
|
34
|
+
mioweb_eshop: boolean;
|
|
35
|
+
mioweb_eshop_url: string;
|
|
36
|
+
disable_discount: boolean;
|
|
37
|
+
prices: {
|
|
38
|
+
type: string;
|
|
39
|
+
price: number;
|
|
40
|
+
currency_code: string;
|
|
41
|
+
metadata: string;
|
|
42
|
+
repayment_count: number;
|
|
43
|
+
}[];
|
|
44
|
+
triggers: string[];
|
|
45
|
+
periodic: boolean;
|
|
46
|
+
period: string;
|
|
47
|
+
voucher_metadata: string;
|
|
48
|
+
metadata: {
|
|
49
|
+
weight: number;
|
|
50
|
+
live_event_country: boolean;
|
|
51
|
+
is_disable_repayment: boolean;
|
|
52
|
+
min_count: number;
|
|
53
|
+
max_count: number;
|
|
54
|
+
allow_reservations: boolean;
|
|
55
|
+
reservation_event_type: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NAME = void 0;
|
|
7
|
+
const FapiApplication_1 = require("../FapiApplication");
|
|
8
|
+
const AFapiListBatch_1 = __importDefault(require("./AFapiListBatch"));
|
|
9
|
+
exports.NAME = `${FapiApplication_1.NAME}-get-item-template-list-batch`;
|
|
10
|
+
class FapiGetItemTemplateListBatch extends AFapiListBatch_1.default {
|
|
11
|
+
getName() {
|
|
12
|
+
return exports.NAME;
|
|
13
|
+
}
|
|
14
|
+
getUrl() {
|
|
15
|
+
return 'item_templates';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = FapiGetItemTemplateListBatch;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import AFapiListBatch from './AFapiListBatch';
|
|
2
|
+
export declare const NAME = "fapi-get-label-list-batch";
|
|
3
|
+
export default class FapiGetLabelListBatch extends AFapiListBatch<unknown, IOutput> {
|
|
4
|
+
getName(): string;
|
|
5
|
+
protected getUrl(): string;
|
|
6
|
+
}
|
|
7
|
+
export interface IOutput {
|
|
8
|
+
id: number;
|
|
9
|
+
user_id: number;
|
|
10
|
+
name: string;
|
|
11
|
+
color: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NAME = void 0;
|
|
7
|
+
const FapiApplication_1 = require("../FapiApplication");
|
|
8
|
+
const AFapiListBatch_1 = __importDefault(require("./AFapiListBatch"));
|
|
9
|
+
exports.NAME = `${FapiApplication_1.NAME}-get-label-list-batch`;
|
|
10
|
+
class FapiGetLabelListBatch extends AFapiListBatch_1.default {
|
|
11
|
+
getName() {
|
|
12
|
+
return exports.NAME;
|
|
13
|
+
}
|
|
14
|
+
getUrl() {
|
|
15
|
+
return 'labels';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = FapiGetLabelListBatch;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import AFapiListBatch from './AFapiListBatch';
|
|
2
|
+
export declare const NAME = "fapi-get-project-list-batch";
|
|
3
|
+
export default class FapiGetProjectListBatch extends AFapiListBatch<unknown, IOutput> {
|
|
4
|
+
getName(): string;
|
|
5
|
+
protected getUrl(): string;
|
|
6
|
+
}
|
|
7
|
+
export interface IOutput {
|
|
8
|
+
id: number;
|
|
9
|
+
hidden: boolean;
|
|
10
|
+
name: string;
|
|
11
|
+
code: string;
|
|
12
|
+
email: string;
|
|
13
|
+
is_default: boolean;
|
|
14
|
+
has_different_logo: boolean;
|
|
15
|
+
logo: string;
|
|
16
|
+
has_different_signature: boolean;
|
|
17
|
+
signature: string;
|
|
18
|
+
has_different_bank_account_set: boolean;
|
|
19
|
+
bank_account_set: boolean;
|
|
20
|
+
has_different_sender: boolean;
|
|
21
|
+
sender_email: string;
|
|
22
|
+
sender_name: string;
|
|
23
|
+
sender_reply_to: string;
|
|
24
|
+
forms: {
|
|
25
|
+
id: number;
|
|
26
|
+
name: string;
|
|
27
|
+
path: string;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NAME = void 0;
|
|
7
|
+
const FapiApplication_1 = require("../FapiApplication");
|
|
8
|
+
const AFapiListBatch_1 = __importDefault(require("./AFapiListBatch"));
|
|
9
|
+
exports.NAME = `${FapiApplication_1.NAME}-get-project-list-batch`;
|
|
10
|
+
class FapiGetProjectListBatch extends AFapiListBatch_1.default {
|
|
11
|
+
getName() {
|
|
12
|
+
return exports.NAME;
|
|
13
|
+
}
|
|
14
|
+
getUrl() {
|
|
15
|
+
return 'projects';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = FapiGetProjectListBatch;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import AFapiListBatch from './AFapiListBatch';
|
|
2
|
+
export declare const NAME = "fapi-get-shipping-method-list-batch";
|
|
3
|
+
export default class FapiGetShippingMethodListBatch extends AFapiListBatch<unknown, IOutput> {
|
|
4
|
+
getName(): string;
|
|
5
|
+
protected getUrl(): string;
|
|
6
|
+
}
|
|
7
|
+
export interface IOutput {
|
|
8
|
+
id: number;
|
|
9
|
+
user_id: number;
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
subtype: string;
|
|
13
|
+
description: string;
|
|
14
|
+
address_prices: {
|
|
15
|
+
address: {
|
|
16
|
+
country_code: string;
|
|
17
|
+
};
|
|
18
|
+
prices: {
|
|
19
|
+
currency_code: string;
|
|
20
|
+
price: number;
|
|
21
|
+
}[];
|
|
22
|
+
}[];
|
|
23
|
+
free_of_charges: {
|
|
24
|
+
price: number;
|
|
25
|
+
currency_code: string;
|
|
26
|
+
}[];
|
|
27
|
+
meta_data: {
|
|
28
|
+
carrier_id?: number;
|
|
29
|
+
is_disable_repayment: boolean;
|
|
30
|
+
accounting_code: string;
|
|
31
|
+
pohoda_accounting: string;
|
|
32
|
+
pohoda_centre: string;
|
|
33
|
+
pohoda_store: string;
|
|
34
|
+
pohoda_stock_item: string;
|
|
35
|
+
};
|
|
36
|
+
including_vat: boolean;
|
|
37
|
+
deleted: boolean;
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NAME = void 0;
|
|
7
|
+
const FapiApplication_1 = require("../FapiApplication");
|
|
8
|
+
const AFapiListBatch_1 = __importDefault(require("./AFapiListBatch"));
|
|
9
|
+
exports.NAME = `${FapiApplication_1.NAME}-get-shipping-method-list-batch`;
|
|
10
|
+
class FapiGetShippingMethodListBatch extends AFapiListBatch_1.default {
|
|
11
|
+
getName() {
|
|
12
|
+
return exports.NAME;
|
|
13
|
+
}
|
|
14
|
+
getUrl() {
|
|
15
|
+
return 'shipping-methods';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = FapiGetShippingMethodListBatch;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
|
|
2
|
+
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
|
|
3
|
+
export declare const NAME = "fapi-subscribe-webhooks-batch";
|
|
4
|
+
export default class FapiSubscribeWebhooksBatch extends ABatchNode {
|
|
5
|
+
getName(): string;
|
|
6
|
+
processAction(dto: BatchProcessDto): Promise<BatchProcessDto>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NAME = void 0;
|
|
7
|
+
const Webhook_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Database/Webhook"));
|
|
8
|
+
const ABatchNode_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode"));
|
|
9
|
+
const TopologyRunner_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Topology/TopologyRunner"));
|
|
10
|
+
const HttpMethods_1 = require("@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods");
|
|
11
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
12
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
13
|
+
const FapiApplication_1 = require("../FapiApplication");
|
|
14
|
+
exports.NAME = `${FapiApplication_1.NAME}-subscribe-webhooks-batch`;
|
|
15
|
+
class FapiSubscribeWebhooksBatch extends ABatchNode_1.default {
|
|
16
|
+
getName() {
|
|
17
|
+
return exports.NAME;
|
|
18
|
+
}
|
|
19
|
+
async processAction(dto) {
|
|
20
|
+
const application = this.getApplication();
|
|
21
|
+
const applicationInstall = await this.getApplicationInstallFromProcess(dto);
|
|
22
|
+
const webhookRepository = this
|
|
23
|
+
.getDbClient()
|
|
24
|
+
.getRepository(Webhook_1.default);
|
|
25
|
+
const webhookSubscriptions = application.getWebhookSubscriptions().map((webhookSubscription) => ({
|
|
26
|
+
event: webhookSubscription.getName(),
|
|
27
|
+
topology: webhookSubscription.getTopology(),
|
|
28
|
+
node: webhookSubscription.getNode(),
|
|
29
|
+
token: crypto_1.default.randomBytes(64).toString('hex'),
|
|
30
|
+
}));
|
|
31
|
+
const subscribedWebhooks = await webhookRepository.findMany({
|
|
32
|
+
users: [applicationInstall.getUser()],
|
|
33
|
+
apps: [applicationInstall.getName()],
|
|
34
|
+
});
|
|
35
|
+
const unsubscribedWebhook = webhookSubscriptions.filter(({ event }) => !subscribedWebhooks.find((subscribedWebhook) => subscribedWebhook.getName() === event)).shift();
|
|
36
|
+
if (!unsubscribedWebhook) {
|
|
37
|
+
return dto;
|
|
38
|
+
}
|
|
39
|
+
const { event, topology, node, token } = unsubscribedWebhook;
|
|
40
|
+
const requestDto = application.getRequestDto(dto, applicationInstall, HttpMethods_1.HttpMethods.POST, 'connections', {
|
|
41
|
+
application: 'global-webhook',
|
|
42
|
+
credentials: {
|
|
43
|
+
event,
|
|
44
|
+
url: TopologyRunner_1.default.getWebhookUrl(topology, node, token),
|
|
45
|
+
},
|
|
46
|
+
meta_data: {
|
|
47
|
+
description: 'Orchesty Webhook',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
const responseDto = await this.getSender().send(requestDto, [http_status_codes_1.StatusCodes.CREATED]);
|
|
51
|
+
await webhookRepository.insert(new Webhook_1.default()
|
|
52
|
+
.setWebhookId(String(responseDto.getJsonBody().id))
|
|
53
|
+
.setApplication(applicationInstall.getName())
|
|
54
|
+
.setUser(applicationInstall.getUser())
|
|
55
|
+
.setTopology(topology)
|
|
56
|
+
.setNode(node)
|
|
57
|
+
.setToken(token)
|
|
58
|
+
.setName(event));
|
|
59
|
+
return dto.setBatchCursor('1', true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.default = FapiSubscribeWebhooksBatch;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
|
|
2
|
+
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
|
|
3
|
+
export declare const NAME = "fapi-unsubscribe-webhooks-batch";
|
|
4
|
+
export default class FapiUnsubscribeWebhooksBatch extends ABatchNode {
|
|
5
|
+
getName(): string;
|
|
6
|
+
processAction(dto: BatchProcessDto): Promise<BatchProcessDto>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NAME = void 0;
|
|
7
|
+
const Webhook_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Database/Webhook"));
|
|
8
|
+
const ABatchNode_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode"));
|
|
9
|
+
const OnRepeatException_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Exception/OnRepeatException"));
|
|
10
|
+
const HttpMethods_1 = require("@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods");
|
|
11
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
12
|
+
const FapiApplication_1 = require("../FapiApplication");
|
|
13
|
+
exports.NAME = `${FapiApplication_1.NAME}-unsubscribe-webhooks-batch`;
|
|
14
|
+
class FapiUnsubscribeWebhooksBatch extends ABatchNode_1.default {
|
|
15
|
+
getName() {
|
|
16
|
+
return exports.NAME;
|
|
17
|
+
}
|
|
18
|
+
async processAction(dto) {
|
|
19
|
+
const application = this.getApplication();
|
|
20
|
+
const applicationInstall = await this.getApplicationInstallFromProcess(dto, null);
|
|
21
|
+
const webhookRepository = this
|
|
22
|
+
.getDbClient()
|
|
23
|
+
.getRepository(Webhook_1.default);
|
|
24
|
+
const subscribedWebhook = await webhookRepository.findOne({
|
|
25
|
+
users: [applicationInstall.getUser()],
|
|
26
|
+
apps: [applicationInstall.getName()],
|
|
27
|
+
});
|
|
28
|
+
if (subscribedWebhook) {
|
|
29
|
+
const requestDto = application.getRequestDto(dto, applicationInstall, HttpMethods_1.HttpMethods.DELETE, `connections/${subscribedWebhook.getWebhookId()}`);
|
|
30
|
+
const responseDto = await this.getSender().send(requestDto);
|
|
31
|
+
if (![http_status_codes_1.StatusCodes.OK, http_status_codes_1.StatusCodes.NOT_FOUND].includes(responseDto.getResponseCode())) {
|
|
32
|
+
await webhookRepository.update(subscribedWebhook.setUnsubscribeFailed(true));
|
|
33
|
+
throw new OnRepeatException_1.default(300, 12, responseDto.getBody());
|
|
34
|
+
}
|
|
35
|
+
await webhookRepository.remove(subscribedWebhook);
|
|
36
|
+
dto.setBatchCursor('1', true);
|
|
37
|
+
}
|
|
38
|
+
return dto;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.default = FapiUnsubscribeWebhooksBatch;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import AConnector from '@orchesty/nodejs-sdk/dist/lib/Connector/AConnector';
|
|
2
|
+
import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
|
|
3
|
+
export declare const NAME = "fapi-get-invoice-connector";
|
|
4
|
+
export default class FapiGetInvoiceConnector extends AConnector {
|
|
5
|
+
getName(): string;
|
|
6
|
+
processAction(dto: ProcessDto<IInput>): Promise<ProcessDto<IOutput>>;
|
|
7
|
+
}
|
|
8
|
+
export interface IInput {
|
|
9
|
+
id: number;
|
|
10
|
+
}
|
|
11
|
+
export interface IOutput {
|
|
12
|
+
id: number;
|
|
13
|
+
number: string;
|
|
14
|
+
created_on: string;
|
|
15
|
+
last_modified_on: string;
|
|
16
|
+
create_date: string;
|
|
17
|
+
automatic_charge_date: string;
|
|
18
|
+
payday_date: string;
|
|
19
|
+
client: number;
|
|
20
|
+
type: string;
|
|
21
|
+
payment_type: string;
|
|
22
|
+
currency: string;
|
|
23
|
+
exchange_rate_czk: string;
|
|
24
|
+
exchange_rate: string;
|
|
25
|
+
language: string;
|
|
26
|
+
paid: boolean;
|
|
27
|
+
cancelled: boolean;
|
|
28
|
+
cancellation_reason: string;
|
|
29
|
+
reverse_charge: boolean;
|
|
30
|
+
tax_exempt: boolean;
|
|
31
|
+
round_function: string;
|
|
32
|
+
round_precision: number;
|
|
33
|
+
vat_recapitulation_algorithm: string;
|
|
34
|
+
payment_confirmation_mode: string;
|
|
35
|
+
preserve_vat_date_on_invoice: boolean;
|
|
36
|
+
has_credit_note: boolean;
|
|
37
|
+
create_invoice_automatically: boolean;
|
|
38
|
+
create_payment_confirmation: boolean;
|
|
39
|
+
create_simplified_invoice: boolean;
|
|
40
|
+
path: string;
|
|
41
|
+
recurring_gopay_payment_id: string;
|
|
42
|
+
campaign_code: string;
|
|
43
|
+
periodic_invoice: string;
|
|
44
|
+
periodic_invoice_number: string;
|
|
45
|
+
locked: boolean;
|
|
46
|
+
proforma: boolean;
|
|
47
|
+
payment_confirmation: boolean;
|
|
48
|
+
simplified_invoice: boolean;
|
|
49
|
+
credit_note: boolean;
|
|
50
|
+
show_vat_info: boolean;
|
|
51
|
+
shipping_method_id: number;
|
|
52
|
+
shipping_metadata: {
|
|
53
|
+
packatery_branch_name: string;
|
|
54
|
+
packatery_branch_id: number;
|
|
55
|
+
} | null;
|
|
56
|
+
paid_on: string;
|
|
57
|
+
variable_symbol: string;
|
|
58
|
+
vat_date: string;
|
|
59
|
+
supplier: {
|
|
60
|
+
name: string;
|
|
61
|
+
ic: string;
|
|
62
|
+
dic: string;
|
|
63
|
+
ic_dph: string;
|
|
64
|
+
swift: string;
|
|
65
|
+
iban: string;
|
|
66
|
+
bank_account: string;
|
|
67
|
+
address: {
|
|
68
|
+
street: string;
|
|
69
|
+
city: string;
|
|
70
|
+
zip: string;
|
|
71
|
+
country: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
customer: {
|
|
75
|
+
name: string;
|
|
76
|
+
first_name: string;
|
|
77
|
+
last_name: string;
|
|
78
|
+
email: string;
|
|
79
|
+
phone: string;
|
|
80
|
+
address: {
|
|
81
|
+
street: string;
|
|
82
|
+
city: string;
|
|
83
|
+
zip: string;
|
|
84
|
+
country: string;
|
|
85
|
+
};
|
|
86
|
+
shipping_address: {
|
|
87
|
+
name: string;
|
|
88
|
+
surname: string;
|
|
89
|
+
street: string;
|
|
90
|
+
city: string;
|
|
91
|
+
zip: string;
|
|
92
|
+
country: string;
|
|
93
|
+
} | null;
|
|
94
|
+
};
|
|
95
|
+
form: number;
|
|
96
|
+
items: {
|
|
97
|
+
id: number;
|
|
98
|
+
invoice: number;
|
|
99
|
+
name: string;
|
|
100
|
+
code: string;
|
|
101
|
+
accounting_code: string;
|
|
102
|
+
price: number;
|
|
103
|
+
count: number;
|
|
104
|
+
round_item: boolean;
|
|
105
|
+
correction_item: boolean;
|
|
106
|
+
type: string;
|
|
107
|
+
moss: boolean;
|
|
108
|
+
pohoda_accounting: string;
|
|
109
|
+
pohoda_centre: string;
|
|
110
|
+
pohoda_store: string;
|
|
111
|
+
pohoda_stock_item: string;
|
|
112
|
+
vat: number;
|
|
113
|
+
including_vat: boolean;
|
|
114
|
+
}[];
|
|
115
|
+
custom_fields: {
|
|
116
|
+
invoice_custom_fields_data_id: number;
|
|
117
|
+
custom_field_id: number;
|
|
118
|
+
value: string;
|
|
119
|
+
name: string;
|
|
120
|
+
type: string;
|
|
121
|
+
}[];
|
|
122
|
+
shipping_method: {
|
|
123
|
+
id: number;
|
|
124
|
+
user_id: number;
|
|
125
|
+
name: string;
|
|
126
|
+
type: string;
|
|
127
|
+
subtype: string;
|
|
128
|
+
address_prices: {
|
|
129
|
+
address: {
|
|
130
|
+
country_code: string;
|
|
131
|
+
};
|
|
132
|
+
prices: {
|
|
133
|
+
currency_code: string;
|
|
134
|
+
price: number;
|
|
135
|
+
}[];
|
|
136
|
+
}[];
|
|
137
|
+
free_of_charges: string;
|
|
138
|
+
meta_data: string;
|
|
139
|
+
including_vat: number;
|
|
140
|
+
description: string;
|
|
141
|
+
disable_discount: number;
|
|
142
|
+
deleted: number;
|
|
143
|
+
};
|
|
144
|
+
total: number;
|
|
145
|
+
total_vat: number;
|
|
146
|
+
total_czk: number;
|
|
147
|
+
total_vat_czk: number;
|
|
148
|
+
total_native: number;
|
|
149
|
+
total_vat_native: number;
|
|
150
|
+
user: number;
|
|
151
|
+
form_url: string;
|
|
152
|
+
session_id: string;
|
|
153
|
+
labels: {
|
|
154
|
+
id: number;
|
|
155
|
+
name: string;
|
|
156
|
+
color: string;
|
|
157
|
+
}[];
|
|
158
|
+
parent?: string;
|
|
159
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NAME = void 0;
|
|
7
|
+
const AConnector_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Connector/AConnector"));
|
|
8
|
+
const HttpMethods_1 = require("@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods");
|
|
9
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
10
|
+
const FapiApplication_1 = require("../FapiApplication");
|
|
11
|
+
exports.NAME = `${FapiApplication_1.NAME}-get-invoice-connector`;
|
|
12
|
+
class FapiGetInvoiceConnector extends AConnector_1.default {
|
|
13
|
+
getName() {
|
|
14
|
+
return exports.NAME;
|
|
15
|
+
}
|
|
16
|
+
async processAction(dto) {
|
|
17
|
+
const { id } = dto.getJsonData();
|
|
18
|
+
const requestDto = await this.getApplication().getRequestDto(dto, await this.getApplicationInstallFromProcess(dto), HttpMethods_1.HttpMethods.GET, `invoices/${id}`);
|
|
19
|
+
const responseDto = await this.getSender().send(requestDto, {
|
|
20
|
+
success: http_status_codes_1.StatusCodes.OK,
|
|
21
|
+
stopAndFail: http_status_codes_1.StatusCodes.NOT_FOUND,
|
|
22
|
+
}, undefined, undefined, FapiApplication_1.getErrorInResponse);
|
|
23
|
+
return dto.setNewJsonData(responseDto.getJsonBody());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = FapiGetInvoiceConnector;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AConnector from '@orchesty/nodejs-sdk/dist/lib/Connector/AConnector';
|
|
2
|
+
import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
|
|
3
|
+
export declare const NAME = "fapi-post-invoice-label-connector";
|
|
4
|
+
export default class FapiPostInvoiceLabelConnector extends AConnector {
|
|
5
|
+
getName(): string;
|
|
6
|
+
processAction(dto: ProcessDto<IInput>): Promise<ProcessDto<IOutput>>;
|
|
7
|
+
}
|
|
8
|
+
export interface IInput {
|
|
9
|
+
id: number;
|
|
10
|
+
labels: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface IOutput {
|
|
13
|
+
status: string;
|
|
14
|
+
message: string;
|
|
15
|
+
invoice_id: number;
|
|
16
|
+
labels: number[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NAME = void 0;
|
|
7
|
+
const AConnector_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Connector/AConnector"));
|
|
8
|
+
const HttpMethods_1 = require("@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods");
|
|
9
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
10
|
+
const FapiApplication_1 = require("../FapiApplication");
|
|
11
|
+
exports.NAME = `${FapiApplication_1.NAME}-post-invoice-label-connector`;
|
|
12
|
+
class FapiPostInvoiceLabelConnector extends AConnector_1.default {
|
|
13
|
+
getName() {
|
|
14
|
+
return exports.NAME;
|
|
15
|
+
}
|
|
16
|
+
async processAction(dto) {
|
|
17
|
+
const { id, labels } = dto.getJsonData();
|
|
18
|
+
const requestDto = await this.getApplication().getRequestDto(dto, await this.getApplicationInstallFromProcess(dto), HttpMethods_1.HttpMethods.POST, `invoice-labels/${id}`, {
|
|
19
|
+
labels,
|
|
20
|
+
});
|
|
21
|
+
const responseDto = await this.getSender().send(requestDto, {
|
|
22
|
+
success: http_status_codes_1.StatusCodes.OK,
|
|
23
|
+
stopAndFail: [http_status_codes_1.StatusCodes.BAD_REQUEST, http_status_codes_1.StatusCodes.NOT_FOUND],
|
|
24
|
+
}, undefined, undefined, FapiApplication_1.getErrorInResponse);
|
|
25
|
+
return dto.setNewJsonData(responseDto.getJsonBody());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = FapiPostInvoiceLabelConnector;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
|
|
2
|
+
import FormStack from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack';
|
|
3
|
+
import WebhookSubscription from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Webhook/WebhookSubscription';
|
|
4
|
+
import { ABasicApplication } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication';
|
|
5
|
+
import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
|
|
6
|
+
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
|
|
7
|
+
import AProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/AProcessDto';
|
|
8
|
+
import { AxiosResponse } from 'axios';
|
|
9
|
+
export declare const NAME = "fapi";
|
|
10
|
+
export declare enum WebhookTypes {
|
|
11
|
+
ORDERED = "ordered",
|
|
12
|
+
UPDATED = "invoice_update",
|
|
13
|
+
PAID = "paid"
|
|
14
|
+
}
|
|
15
|
+
export default class FapiApplication extends ABasicApplication {
|
|
16
|
+
getName(): string;
|
|
17
|
+
getDescription(): string;
|
|
18
|
+
getPublicName(): string;
|
|
19
|
+
getLogo(): string;
|
|
20
|
+
getFormStack(): FormStack;
|
|
21
|
+
getRequestDto(dto: AProcessDto, applicationInstall: ApplicationInstall, method: HttpMethods, url?: string, data?: unknown): RequestDto;
|
|
22
|
+
getWebhookSubscriptions(): WebhookSubscription[];
|
|
23
|
+
}
|
|
24
|
+
export declare function getErrorInResponse(response: AxiosResponse, body: string): Promise<string>;
|