@orchesty/connector-fapi 1.0.0 → 2.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/README.md +94 -0
- package/dist/Batch/FapiSubscribeWebhooksBatch.js +2 -0
- package/dist/Batch/FapiUnsubscribeWebhooksBatch.js +1 -0
- package/dist/package.json +8 -5
- package/package.json +8 -5
- package/CHANGELOG.md +0 -7
- package/coverage/clover.xml +0 -234
- package/coverage/coverage-final.json +0 -12
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -161
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/Batch/AFapiListBatch.ts.html +0 -373
- package/coverage/lcov-report/src/Batch/FapiGetItemTemplateListBatch.ts.html +0 -295
- package/coverage/lcov-report/src/Batch/FapiGetLabelListBatch.ts.html +0 -154
- package/coverage/lcov-report/src/Batch/FapiGetProjectListBatch.ts.html +0 -211
- package/coverage/lcov-report/src/Batch/FapiGetShippingMethodListBatch.ts.html +0 -238
- package/coverage/lcov-report/src/Batch/FapiSubscribeWebhooksBatch.ts.html +0 -364
- package/coverage/lcov-report/src/Batch/FapiUnsubscribeWebhooksBatch.ts.html +0 -247
- package/coverage/lcov-report/src/Batch/index.html +0 -206
- package/coverage/lcov-report/src/Connector/FapiGetInvoiceConnector.ts.html +0 -652
- package/coverage/lcov-report/src/Connector/FapiPostInvoiceLabelConnector.ts.html +0 -229
- package/coverage/lcov-report/src/Connector/index.html +0 -131
- package/coverage/lcov-report/src/FapiApplication.ts.html +0 -394
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/test/dataProvider.ts.html +0 -187
- package/coverage/lcov-report/test/index.html +0 -116
- package/coverage/lcov.info +0 -380
- package/jest.config.js +0 -13
- package/src/Batch/AFapiListBatch.ts +0 -96
- package/src/Batch/FapiGetItemTemplateListBatch.ts +0 -70
- package/src/Batch/FapiGetLabelListBatch.ts +0 -23
- package/src/Batch/FapiGetProjectListBatch.ts +0 -42
- package/src/Batch/FapiGetShippingMethodListBatch.ts +0 -51
- package/src/Batch/FapiSubscribeWebhooksBatch.ts +0 -93
- package/src/Batch/FapiUnsubscribeWebhooksBatch.ts +0 -54
- package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/input.json +0 -7
- package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/mock.json +0 -55
- package/src/Batch/__tests__/Data/FapiGetItemTemplateListBatch/output.json +0 -11
- package/src/Batch/__tests__/Data/FapiGetLabelListBatch/input.json +0 -7
- package/src/Batch/__tests__/Data/FapiGetLabelListBatch/mock.json +0 -14
- package/src/Batch/__tests__/Data/FapiGetLabelListBatch/output.json +0 -11
- package/src/Batch/__tests__/Data/FapiGetProjectListBatch/input.json +0 -7
- package/src/Batch/__tests__/Data/FapiGetProjectListBatch/mock.json +0 -26
- package/src/Batch/__tests__/Data/FapiGetProjectListBatch/output.json +0 -11
- package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/input.json +0 -7
- package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/mock.json +0 -31
- package/src/Batch/__tests__/Data/FapiGetShippingMethodListBatch/output.json +0 -11
- package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/input.json +0 -7
- package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/mock.json +0 -17
- package/src/Batch/__tests__/Data/FapiSubscribeWebhooksBatch/output.json +0 -6
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/1-mock.json +0 -5
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/input.json +0 -7
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/mock.json +0 -5
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/output.json +0 -9
- package/src/Batch/__tests__/Data/FapiUnsubscribeWebhooksBatch/output1.json +0 -7
- package/src/Batch/__tests__/FapiGetItemTemplateListBatch.ts +0 -17
- package/src/Batch/__tests__/FapiGetLabelListBatch.ts +0 -17
- package/src/Batch/__tests__/FapiGetProjectListBatch.ts +0 -17
- package/src/Batch/__tests__/FapiGetShippingMethodListBatch.ts +0 -17
- package/src/Batch/__tests__/FapiSubscribeWebhooksBatch.ts +0 -45
- package/src/Batch/__tests__/FapiUnsubscribeWebhooksBatch.ts +0 -57
- package/src/Connector/FapiGetInvoiceConnector.ts +0 -189
- package/src/Connector/FapiPostInvoiceLabelConnector.ts +0 -48
- package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/input.json +0 -8
- package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/mock.json +0 -223
- package/src/Connector/__tests__/Data/FapiGetInvoiceConnector/output.json +0 -224
- package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/input.json +0 -11
- package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/mock.json +0 -12
- package/src/Connector/__tests__/Data/FapiPostInvoiceLabelConnector/output.json +0 -13
- package/src/Connector/__tests__/FapiGetInvoiceConnector.ts +0 -17
- package/src/Connector/__tests__/FapiPostInvoiceLabelConnector.ts +0 -17
- package/src/FapiApplication.ts +0 -103
- package/test/dataProvider.ts +0 -34
- package/tsconfig.json +0 -8
- package/tsconfig.prod.json +0 -13
- package/tsconfig.prod.tsbuildinfo +0 -1
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
|
|
2
|
-
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
|
|
3
|
-
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
|
|
4
|
-
import { DateTime } from 'luxon';
|
|
5
|
-
|
|
6
|
-
const LAST_RUN = 'lastRun';
|
|
7
|
-
|
|
8
|
-
export default abstract class AFapiListBatch<IInput, IOutput> extends ABatchNode {
|
|
9
|
-
|
|
10
|
-
protected abstract getUrl(): string;
|
|
11
|
-
|
|
12
|
-
public async processAction(dto: BatchProcessDto<IInput>): Promise<BatchProcessDto<IOutput>> {
|
|
13
|
-
let url = `${this.getUrl()}?limit=${await this.getLimit(dto)}&offset=${await this.getOffset(dto)}`;
|
|
14
|
-
|
|
15
|
-
if (await this.useLastRun(dto)) {
|
|
16
|
-
const lastRun = await this.getLastRun(dto);
|
|
17
|
-
|
|
18
|
-
if (lastRun) {
|
|
19
|
-
url = `${url}&last_modified_after=${lastRun}`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const requestDto = await this.getApplication().getRequestDto(
|
|
24
|
-
dto,
|
|
25
|
-
await this.getApplicationInstallFromProcess(dto),
|
|
26
|
-
HttpMethods.GET,
|
|
27
|
-
url,
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const responseDto = await this.getSender().send<IResponse<IOutput>>(requestDto, [200]);
|
|
31
|
-
const response = responseDto.getJsonBody();
|
|
32
|
-
const items = response[this.getUrl().replace('-', '_')];
|
|
33
|
-
dto.setItemList(items);
|
|
34
|
-
|
|
35
|
-
if (items.length === await this.getLimit(dto)) {
|
|
36
|
-
dto.setBatchCursor((Number(dto.getBatchCursor('1')) + 1).toString());
|
|
37
|
-
} else {
|
|
38
|
-
await this.setLastRun(dto);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return dto as unknown as Promise<BatchProcessDto<IOutput>>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
|
|
45
|
-
protected async getLimit(dto: BatchProcessDto<IInput>): Promise<number> {
|
|
46
|
-
return 1_000;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
protected async getOffset(dto: BatchProcessDto<IInput>): Promise<number> {
|
|
50
|
-
return (Number(dto.getBatchCursor('1')) - 1) * await this.getLimit(dto);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
|
|
54
|
-
protected async getLastRunKey(dto: BatchProcessDto<IInput>): Promise<string> {
|
|
55
|
-
return this.getUrl();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
|
|
59
|
-
protected async useLastRun(dto: BatchProcessDto<IInput>): Promise<boolean> {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
protected async getLastRun(dto: BatchProcessDto<IInput>): Promise<string | undefined> {
|
|
64
|
-
if (!await this.useLastRun(dto)) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const applicationInstall = await this.getApplicationInstallFromProcess(dto);
|
|
69
|
-
const lastRun = applicationInstall.getNonEncryptedSettings()[LAST_RUN]?.[await this.getLastRunKey(dto)];
|
|
70
|
-
|
|
71
|
-
if (!lastRun) {
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return DateTime.fromISO(lastRun).toFormat('yyyy-MM-dd HH:mm:ss');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
protected async setLastRun(dto: BatchProcessDto<IInput>): Promise<void> {
|
|
79
|
-
if (!await this.useLastRun(dto)) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const applicationInstall = await this.getApplicationInstallFromProcess(dto);
|
|
84
|
-
|
|
85
|
-
applicationInstall.addNonEncryptedSettings({
|
|
86
|
-
[LAST_RUN]: {
|
|
87
|
-
[await this.getLastRunKey(dto)]: new Date().toISOString(),
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
await this.getDbClient().getApplicationRepository().update(applicationInstall);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
type IResponse<IOutput> = Record<string, IOutput[]>;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { NAME as APPLICATION_NAME } from '../FapiApplication';
|
|
2
|
-
import AFapiListBatch from './AFapiListBatch';
|
|
3
|
-
|
|
4
|
-
export const NAME = `${APPLICATION_NAME}-get-item-template-list-batch`;
|
|
5
|
-
|
|
6
|
-
export default class FapiGetItemTemplateListBatch extends AFapiListBatch<unknown, IOutput> {
|
|
7
|
-
|
|
8
|
-
public getName(): string {
|
|
9
|
-
return NAME;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
protected getUrl(): string {
|
|
13
|
-
return 'item_templates';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IOutput {
|
|
19
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
20
|
-
id: number;
|
|
21
|
-
hidden: boolean;
|
|
22
|
-
name: string;
|
|
23
|
-
code: string;
|
|
24
|
-
accounting_code: string;
|
|
25
|
-
description: string;
|
|
26
|
-
price_czk: number;
|
|
27
|
-
price_eur: number;
|
|
28
|
-
price_usd: number;
|
|
29
|
-
repayment_amount_czk: number;
|
|
30
|
-
repayment_amount_eur: number;
|
|
31
|
-
repayment_amount_usd: number;
|
|
32
|
-
vat: number;
|
|
33
|
-
including_vat: boolean;
|
|
34
|
-
count: number;
|
|
35
|
-
sold_out: boolean;
|
|
36
|
-
allow_change_count: boolean;
|
|
37
|
-
enable_stock: boolean;
|
|
38
|
-
stock: number;
|
|
39
|
-
show_stock_information: boolean;
|
|
40
|
-
type: string;
|
|
41
|
-
electronically_supplied_service: boolean;
|
|
42
|
-
pohoda_accounting: string;
|
|
43
|
-
pohoda_centre: string;
|
|
44
|
-
pohoda_store: string;
|
|
45
|
-
pohoda_stock_item: string;
|
|
46
|
-
mioweb_eshop: boolean;
|
|
47
|
-
mioweb_eshop_url: string;
|
|
48
|
-
disable_discount: boolean;
|
|
49
|
-
prices: {
|
|
50
|
-
type: string;
|
|
51
|
-
price: number;
|
|
52
|
-
currency_code: string;
|
|
53
|
-
metadata: string;
|
|
54
|
-
repayment_count: number;
|
|
55
|
-
}[];
|
|
56
|
-
triggers: string[];
|
|
57
|
-
periodic: boolean;
|
|
58
|
-
period: string;
|
|
59
|
-
voucher_metadata: string;
|
|
60
|
-
metadata: {
|
|
61
|
-
weight: number;
|
|
62
|
-
live_event_country: boolean;
|
|
63
|
-
is_disable_repayment: boolean;
|
|
64
|
-
min_count: number;
|
|
65
|
-
max_count: number;
|
|
66
|
-
allow_reservations: boolean;
|
|
67
|
-
reservation_event_type: string;
|
|
68
|
-
};
|
|
69
|
-
/* eslint-enable @typescript-eslint/naming-convention */
|
|
70
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { NAME as APPLICATION_NAME } from '../FapiApplication';
|
|
2
|
-
import AFapiListBatch from './AFapiListBatch';
|
|
3
|
-
|
|
4
|
-
export const NAME = `${APPLICATION_NAME}-get-label-list-batch`;
|
|
5
|
-
|
|
6
|
-
export default class FapiGetLabelListBatch extends AFapiListBatch<unknown, IOutput> {
|
|
7
|
-
|
|
8
|
-
public getName(): string {
|
|
9
|
-
return NAME;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
protected getUrl(): string {
|
|
13
|
-
return 'labels';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IOutput {
|
|
19
|
-
id: number,
|
|
20
|
-
user_id: number,
|
|
21
|
-
name: string,
|
|
22
|
-
color: string
|
|
23
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { NAME as APPLICATION_NAME } from '../FapiApplication';
|
|
2
|
-
import AFapiListBatch from './AFapiListBatch';
|
|
3
|
-
|
|
4
|
-
export const NAME = `${APPLICATION_NAME}-get-project-list-batch`;
|
|
5
|
-
|
|
6
|
-
export default class FapiGetProjectListBatch extends AFapiListBatch<unknown, IOutput> {
|
|
7
|
-
|
|
8
|
-
public getName(): string {
|
|
9
|
-
return NAME;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
protected getUrl(): string {
|
|
13
|
-
return 'projects';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IOutput {
|
|
19
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
20
|
-
id: number;
|
|
21
|
-
hidden: boolean;
|
|
22
|
-
name: string;
|
|
23
|
-
code: string;
|
|
24
|
-
email: string;
|
|
25
|
-
is_default: boolean;
|
|
26
|
-
has_different_logo: boolean;
|
|
27
|
-
logo: string;
|
|
28
|
-
has_different_signature: boolean;
|
|
29
|
-
signature: string;
|
|
30
|
-
has_different_bank_account_set: boolean;
|
|
31
|
-
bank_account_set: boolean;
|
|
32
|
-
has_different_sender: boolean;
|
|
33
|
-
sender_email: string;
|
|
34
|
-
sender_name: string;
|
|
35
|
-
sender_reply_to: string;
|
|
36
|
-
forms: {
|
|
37
|
-
id: number;
|
|
38
|
-
name: string;
|
|
39
|
-
path: string;
|
|
40
|
-
}[];
|
|
41
|
-
/* eslint-enable @typescript-eslint/naming-convention */
|
|
42
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { NAME as APPLICATION_NAME } from '../FapiApplication';
|
|
2
|
-
import AFapiListBatch from './AFapiListBatch';
|
|
3
|
-
|
|
4
|
-
export const NAME = `${APPLICATION_NAME}-get-shipping-method-list-batch`;
|
|
5
|
-
|
|
6
|
-
export default class FapiGetShippingMethodListBatch extends AFapiListBatch<unknown, IOutput> {
|
|
7
|
-
|
|
8
|
-
public getName(): string {
|
|
9
|
-
return NAME;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
protected getUrl(): string {
|
|
13
|
-
return 'shipping-methods';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IOutput {
|
|
19
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
20
|
-
id: number;
|
|
21
|
-
user_id: number;
|
|
22
|
-
name: string;
|
|
23
|
-
type: string;
|
|
24
|
-
subtype: string;
|
|
25
|
-
description: string;
|
|
26
|
-
address_prices: {
|
|
27
|
-
address: {
|
|
28
|
-
country_code: string;
|
|
29
|
-
};
|
|
30
|
-
prices: {
|
|
31
|
-
currency_code: string;
|
|
32
|
-
price: number;
|
|
33
|
-
}[];
|
|
34
|
-
}[];
|
|
35
|
-
free_of_charges: {
|
|
36
|
-
price: number;
|
|
37
|
-
currency_code: string;
|
|
38
|
-
}[];
|
|
39
|
-
meta_data: {
|
|
40
|
-
carrier_id?: number;
|
|
41
|
-
is_disable_repayment: boolean;
|
|
42
|
-
accounting_code: string;
|
|
43
|
-
pohoda_accounting: string;
|
|
44
|
-
pohoda_centre: string;
|
|
45
|
-
pohoda_store: string;
|
|
46
|
-
pohoda_stock_item: string;
|
|
47
|
-
};
|
|
48
|
-
including_vat: boolean;
|
|
49
|
-
deleted: boolean;
|
|
50
|
-
/* eslint-enable @typescript-eslint/naming-convention */
|
|
51
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import Webhook from '@orchesty/nodejs-sdk/dist/lib/Application/Database/Webhook';
|
|
2
|
-
import { IWebhookQueryFilter } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/WebhookRepository';
|
|
3
|
-
import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
|
|
4
|
-
import { IPaging, ISorter } from '@orchesty/nodejs-sdk/dist/lib/Storage/Database/Repository';
|
|
5
|
-
import TopologyRunner from '@orchesty/nodejs-sdk/dist/lib/Topology/TopologyRunner';
|
|
6
|
-
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
|
|
7
|
-
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
|
|
8
|
-
import crypto from 'crypto';
|
|
9
|
-
import { StatusCodes } from 'http-status-codes';
|
|
10
|
-
import FapiApplication, { NAME as APPLICATION_NAME } from '../FapiApplication';
|
|
11
|
-
|
|
12
|
-
export const NAME = `${APPLICATION_NAME}-subscribe-webhooks-batch`;
|
|
13
|
-
|
|
14
|
-
export default class FapiSubscribeWebhooksBatch extends ABatchNode {
|
|
15
|
-
|
|
16
|
-
public getName(): string {
|
|
17
|
-
return NAME;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public async processAction(dto: BatchProcessDto): Promise<BatchProcessDto> {
|
|
21
|
-
const application = this.getApplication<FapiApplication>();
|
|
22
|
-
const applicationInstall = await this.getApplicationInstallFromProcess(dto);
|
|
23
|
-
const webhookRepository = this
|
|
24
|
-
.getDbClient()
|
|
25
|
-
.getRepository<Webhook, IWebhookQueryFilter, ISorter, IPaging>(Webhook);
|
|
26
|
-
|
|
27
|
-
const webhookSubscriptions = application.getWebhookSubscriptions().map((webhookSubscription) => ({
|
|
28
|
-
event: webhookSubscription.getName(),
|
|
29
|
-
topology: webhookSubscription.getTopology(),
|
|
30
|
-
node: webhookSubscription.getNode(),
|
|
31
|
-
token: crypto.randomBytes(64).toString('hex'),
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
const subscribedWebhooks = await webhookRepository.findMany({
|
|
35
|
-
users: [applicationInstall.getUser()],
|
|
36
|
-
apps: [applicationInstall.getName()],
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const unsubscribedWebhook = webhookSubscriptions.filter(
|
|
40
|
-
({ event }) => !subscribedWebhooks.find((subscribedWebhook) => subscribedWebhook.getName() === event),
|
|
41
|
-
).shift();
|
|
42
|
-
|
|
43
|
-
if (!unsubscribedWebhook) {
|
|
44
|
-
return dto;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const { event, topology, node, token } = unsubscribedWebhook;
|
|
48
|
-
const requestDto = application.getRequestDto(
|
|
49
|
-
dto,
|
|
50
|
-
applicationInstall,
|
|
51
|
-
HttpMethods.POST,
|
|
52
|
-
'connections',
|
|
53
|
-
{
|
|
54
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
55
|
-
application: 'global-webhook',
|
|
56
|
-
credentials: {
|
|
57
|
-
event,
|
|
58
|
-
url: TopologyRunner.getWebhookUrl(topology, node, token),
|
|
59
|
-
},
|
|
60
|
-
meta_data: {
|
|
61
|
-
description: 'Orchesty Webhook',
|
|
62
|
-
},
|
|
63
|
-
/* eslint-enable @typescript-eslint/naming-convention */
|
|
64
|
-
},
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const responseDto = await this.getSender().send<IResponse>(requestDto, [StatusCodes.CREATED]);
|
|
68
|
-
|
|
69
|
-
await webhookRepository.insert(
|
|
70
|
-
new Webhook()
|
|
71
|
-
.setWebhookId(String(responseDto.getJsonBody().id))
|
|
72
|
-
.setApplication(applicationInstall.getName())
|
|
73
|
-
.setUser(applicationInstall.getUser())
|
|
74
|
-
.setTopology(topology)
|
|
75
|
-
.setNode(node)
|
|
76
|
-
.setToken(token)
|
|
77
|
-
.setName(event),
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
return dto.setBatchCursor('1', true);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
interface IResponse {
|
|
86
|
-
id: number;
|
|
87
|
-
user_id: number;
|
|
88
|
-
application: string;
|
|
89
|
-
credentials: {
|
|
90
|
-
url: string;
|
|
91
|
-
event: string;
|
|
92
|
-
};
|
|
93
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import Webhook from '@orchesty/nodejs-sdk/dist/lib/Application/Database/Webhook';
|
|
2
|
-
import { IWebhookQueryFilter } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/WebhookRepository';
|
|
3
|
-
import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
|
|
4
|
-
import OnRepeatException from '@orchesty/nodejs-sdk/dist/lib/Exception/OnRepeatException';
|
|
5
|
-
import { IPaging, ISorter } from '@orchesty/nodejs-sdk/dist/lib/Storage/Database/Repository';
|
|
6
|
-
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
|
|
7
|
-
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
|
|
8
|
-
import { StatusCodes } from 'http-status-codes';
|
|
9
|
-
import FapiApplication, { NAME as APPLICATION_NAME } from '../FapiApplication';
|
|
10
|
-
|
|
11
|
-
export const NAME = `${APPLICATION_NAME}-unsubscribe-webhooks-batch`;
|
|
12
|
-
|
|
13
|
-
export default class FapiUnsubscribeWebhooksBatch extends ABatchNode {
|
|
14
|
-
|
|
15
|
-
public getName(): string {
|
|
16
|
-
return NAME;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public async processAction(dto: BatchProcessDto): Promise<BatchProcessDto> {
|
|
20
|
-
const application = this.getApplication<FapiApplication>();
|
|
21
|
-
const applicationInstall = await this.getApplicationInstallFromProcess(dto, null);
|
|
22
|
-
const webhookRepository = this
|
|
23
|
-
.getDbClient()
|
|
24
|
-
.getRepository<Webhook, IWebhookQueryFilter, ISorter, IPaging>(Webhook);
|
|
25
|
-
|
|
26
|
-
const subscribedWebhook = await webhookRepository.findOne({
|
|
27
|
-
users: [applicationInstall.getUser()],
|
|
28
|
-
apps: [applicationInstall.getName()],
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
if (subscribedWebhook) {
|
|
32
|
-
const requestDto = application.getRequestDto(
|
|
33
|
-
dto,
|
|
34
|
-
applicationInstall,
|
|
35
|
-
HttpMethods.DELETE,
|
|
36
|
-
`connections/${subscribedWebhook.getWebhookId()}`,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const responseDto = await this.getSender().send(requestDto);
|
|
40
|
-
|
|
41
|
-
if (![StatusCodes.OK, StatusCodes.NOT_FOUND].includes(responseDto.getResponseCode())) {
|
|
42
|
-
await webhookRepository.update(subscribedWebhook.setUnsubscribeFailed(true));
|
|
43
|
-
|
|
44
|
-
throw new OnRepeatException(300, 12, responseDto.getBody());
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await webhookRepository.remove(subscribedWebhook);
|
|
48
|
-
dto.setBatchCursor('1', true);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return dto;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"http": "GET https://api.fapi.cz/item_templates?limit=1000&offset=0",
|
|
3
|
-
"code": 200,
|
|
4
|
-
"body": {
|
|
5
|
-
"item_templates": [
|
|
6
|
-
{
|
|
7
|
-
"id": 12,
|
|
8
|
-
"hidden": false,
|
|
9
|
-
"name": "test",
|
|
10
|
-
"code": "12",
|
|
11
|
-
"accounting_code": null,
|
|
12
|
-
"description": null,
|
|
13
|
-
"price_czk": 1066.0,
|
|
14
|
-
"price_eur": 39.42,
|
|
15
|
-
"price_usd": null,
|
|
16
|
-
"repayment_amount_czk": 1500.0,
|
|
17
|
-
"repayment_amount_eur": null,
|
|
18
|
-
"repayment_amount_usd": null,
|
|
19
|
-
"prices": [
|
|
20
|
-
{
|
|
21
|
-
"type": "one_time",
|
|
22
|
-
"price": 1066.000000,
|
|
23
|
-
"currency_code": "CZK"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"type": "one_time",
|
|
27
|
-
"price": 39.420000,
|
|
28
|
-
"currency_code": "EUR"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"type": "repayment",
|
|
32
|
-
"price": 1500.000000,
|
|
33
|
-
"currency_code": "CZK"
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
"vat": 0,
|
|
37
|
-
"including_vat": false,
|
|
38
|
-
"count": 1,
|
|
39
|
-
"allow_change_count": false,
|
|
40
|
-
"enable_stock": false,
|
|
41
|
-
"stock": 0,
|
|
42
|
-
"show_stock_information": false,
|
|
43
|
-
"type": "electronic-service",
|
|
44
|
-
"pohoda_accounting": null,
|
|
45
|
-
"pohoda_centre": null,
|
|
46
|
-
"pohoda_store": null,
|
|
47
|
-
"pohoda_stock_item": null,
|
|
48
|
-
"mioweb_eshop": false,
|
|
49
|
-
"mioweb_eshop_url": null,
|
|
50
|
-
"disable_discount": false,
|
|
51
|
-
"user": 3
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"headers": {
|
|
3
|
-
"user": "TestUser"
|
|
4
|
-
},
|
|
5
|
-
"data": [
|
|
6
|
-
{
|
|
7
|
-
"body": "{\"id\":12,\"hidden\":false,\"name\":\"test\",\"code\":\"12\",\"accounting_code\":null,\"description\":null,\"price_czk\":1066,\"price_eur\":39.42,\"price_usd\":null,\"repayment_amount_czk\":1500,\"repayment_amount_eur\":null,\"repayment_amount_usd\":null,\"prices\":[{\"type\":\"one_time\",\"price\":1066,\"currency_code\":\"CZK\"},{\"type\":\"one_time\",\"price\":39.42,\"currency_code\":\"EUR\"},{\"type\":\"repayment\",\"price\":1500,\"currency_code\":\"CZK\"}],\"vat\":0,\"including_vat\":false,\"count\":1,\"allow_change_count\":false,\"enable_stock\":false,\"stock\":0,\"show_stock_information\":false,\"type\":\"electronic-service\",\"pohoda_accounting\":null,\"pohoda_centre\":null,\"pohoda_store\":null,\"pohoda_stock_item\":null,\"mioweb_eshop\":false,\"mioweb_eshop_url\":null,\"disable_discount\":false,\"user\":3}",
|
|
8
|
-
"headers": {}
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"http": "GET https://api.fapi.cz/projects?limit=1000&offset=0",
|
|
3
|
-
"code": 200,
|
|
4
|
-
"body": {
|
|
5
|
-
"projects": [
|
|
6
|
-
{
|
|
7
|
-
"id": 5864,
|
|
8
|
-
"hidden": false,
|
|
9
|
-
"name": "A - Test",
|
|
10
|
-
"code": "AT",
|
|
11
|
-
"email": null,
|
|
12
|
-
"is_default": false,
|
|
13
|
-
"has_different_logo": true,
|
|
14
|
-
"logo": 529,
|
|
15
|
-
"has_different_signature": false,
|
|
16
|
-
"signature": null,
|
|
17
|
-
"has_different_bank_account_set": false,
|
|
18
|
-
"bank_account_set": null,
|
|
19
|
-
"has_different_sender": false,
|
|
20
|
-
"sender_email": null,
|
|
21
|
-
"sender_name": null,
|
|
22
|
-
"sender_reply_to": null
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"headers": {
|
|
3
|
-
"user": "TestUser"
|
|
4
|
-
},
|
|
5
|
-
"data": [
|
|
6
|
-
{
|
|
7
|
-
"body": "{\"id\":5864,\"hidden\":false,\"name\":\"A - Test\",\"code\":\"AT\",\"email\":null,\"is_default\":false,\"has_different_logo\":true,\"logo\":529,\"has_different_signature\":false,\"signature\":null,\"has_different_bank_account_set\":false,\"bank_account_set\":null,\"has_different_sender\":false,\"sender_email\":null,\"sender_name\":null,\"sender_reply_to\":null}",
|
|
8
|
-
"headers": {}
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"http": "GET https://api.fapi.cz/shipping-methods?limit=1000&offset=0",
|
|
3
|
-
"code": 200,
|
|
4
|
-
"body": {
|
|
5
|
-
"shipping_methods": [
|
|
6
|
-
{
|
|
7
|
-
"id": 1,
|
|
8
|
-
"user_id": 3,
|
|
9
|
-
"name": "Moje odběrové místo",
|
|
10
|
-
"type": "personal_collection",
|
|
11
|
-
"subtype": null,
|
|
12
|
-
"address_prices": [
|
|
13
|
-
{
|
|
14
|
-
"address": {
|
|
15
|
-
"simple_address": "test adresa"
|
|
16
|
-
},
|
|
17
|
-
"prices": [
|
|
18
|
-
{
|
|
19
|
-
"currency_code": "CZK",
|
|
20
|
-
"price": 100
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"meta_data": null,
|
|
26
|
-
"including_vat": false,
|
|
27
|
-
"description": null
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"headers": {
|
|
3
|
-
"user": "TestUser"
|
|
4
|
-
},
|
|
5
|
-
"data": [
|
|
6
|
-
{
|
|
7
|
-
"body": "{\"id\":1,\"user_id\":3,\"name\":\"Moje odběrové místo\",\"type\":\"personal_collection\",\"subtype\":null,\"address_prices\":[{\"address\":{\"simple_address\":\"test adresa\"},\"prices\":[{\"currency_code\":\"CZK\",\"price\":100}]}],\"meta_data\":null,\"including_vat\":false,\"description\":null}",
|
|
8
|
-
"headers": {}
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"http": "POST https://api.fapi.cz/connections",
|
|
3
|
-
"code": 200,
|
|
4
|
-
"body": {
|
|
5
|
-
"id": 35,
|
|
6
|
-
"user_id": 3,
|
|
7
|
-
"application": "global-webhook",
|
|
8
|
-
"credentials": {
|
|
9
|
-
"url": "https://test.cz/",
|
|
10
|
-
"event": "ordered"
|
|
11
|
-
},
|
|
12
|
-
"fields_mapping": [],
|
|
13
|
-
"meta_data": {
|
|
14
|
-
"description": "Webhook test"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|