@orchesty/connector-wflow 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/dist/Batch/WflowSubscribeWebhookBatch.d.ts +7 -0
- package/dist/Batch/WflowSubscribeWebhookBatch.js +52 -0
- package/dist/Batch/WflowUnsubscribeWebhookBatch.d.ts +7 -0
- package/dist/Batch/WflowUnsubscribeWebhookBatch.js +42 -0
- package/dist/Connector/WflowGetDocumentConnector.d.ts +310 -0
- package/dist/Connector/WflowGetDocumentConnector.js +25 -0
- package/dist/Connector/WflowGetOrganizationsConnector.d.ts +15 -0
- package/dist/Connector/WflowGetOrganizationsConnector.js +27 -0
- package/dist/Connector/WflowPutDocumentConnector.d.ts +117 -0
- package/dist/Connector/WflowPutDocumentConnector.js +32 -0
- package/dist/Connector/WflowUpdateDocumentStateConnector.d.ts +11 -0
- package/dist/Connector/WflowUpdateDocumentStateConnector.js +25 -0
- package/dist/WflowApplication.d.ts +40 -0
- package/dist/WflowApplication.js +126 -0
- package/dist/package.json +22 -0
- package/jest.config.js +13 -0
- package/package.json +22 -0
- package/src/Batch/WflowSubscribeWebhookBatch.ts +80 -0
- package/src/Batch/WflowUnsubscribeWebhookBatch.ts +55 -0
- package/src/Batch/__tests__/Data/WflowSubscribeWebhookBatch/input.json +6 -0
- package/src/Batch/__tests__/Data/WflowSubscribeWebhookBatch/mock.json +5 -0
- package/src/Batch/__tests__/Data/WflowSubscribeWebhookBatch/output.json +6 -0
- package/src/Batch/__tests__/Data/WflowUnsubscribeWebhookBatch/input.json +6 -0
- package/src/Batch/__tests__/Data/WflowUnsubscribeWebhookBatch/mock.json +5 -0
- package/src/Batch/__tests__/Data/WflowUnsubscribeWebhookBatch/output.json +6 -0
- package/src/Batch/__tests__/WflowSubscribeWebhookBatch.ts +17 -0
- package/src/Batch/__tests__/WflowUnsubscribeWebhookBatch.ts +17 -0
- package/src/Connector/WflowGetDocumentConnector.ts +341 -0
- package/src/Connector/WflowGetOrganizationsConnector.ts +40 -0
- package/src/Connector/WflowPutDocumentConnector.ts +152 -0
- package/src/Connector/WflowUpdateDocumentStateConnector.ts +39 -0
- package/src/Connector/__tests__/Data/WflowGetDocumentConnector/input.json +9 -0
- package/src/Connector/__tests__/Data/WflowGetDocumentConnector/mock.json +449 -0
- package/src/Connector/__tests__/Data/WflowGetDocumentConnector/output.json +450 -0
- package/src/Connector/__tests__/Data/WflowGetOrganizationsConnector/input.json +6 -0
- package/src/Connector/__tests__/Data/WflowGetOrganizationsConnector/mock.json +12 -0
- package/src/Connector/__tests__/Data/WflowGetOrganizationsConnector/output.json +13 -0
- package/src/Connector/__tests__/Data/WflowPutDocumentConnector/input.json +9 -0
- package/src/Connector/__tests__/Data/WflowPutDocumentConnector/mock.json +5 -0
- package/src/Connector/__tests__/Data/WflowPutDocumentConnector/output.json +9 -0
- package/src/Connector/__tests__/Data/WflowUpdateDocumentState/input.json +8 -0
- package/src/Connector/__tests__/Data/WflowUpdateDocumentState/mock.json +5 -0
- package/src/Connector/__tests__/Data/WflowUpdateDocumentState/output.json +8 -0
- package/src/Connector/__tests__/WflowGetDocumentConnector.ts +17 -0
- package/src/Connector/__tests__/WflowGetOrganizationsConnector.ts +17 -0
- package/src/Connector/__tests__/WflowPutDocumentConnector.ts +17 -0
- package/src/Connector/__tests__/WflowUpdateDocumentState.ts +17 -0
- package/src/WflowApplication.ts +140 -0
- package/test/dataProvider.ts +55 -0
- package/tsconfig.json +9 -0
- package/tsconfig.prod.json +10 -0
- package/tsconfig.prod.tsbuildinfo +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
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 WflowApplication_1 = require("../WflowApplication");
|
|
10
|
+
exports.NAME = `${WflowApplication_1.NAME}-get-organizations-connector`;
|
|
11
|
+
class WflowGetOrganizationsConnector extends AConnector_1.default {
|
|
12
|
+
useInForm;
|
|
13
|
+
constructor(useInForm = false) {
|
|
14
|
+
super();
|
|
15
|
+
this.useInForm = useInForm;
|
|
16
|
+
}
|
|
17
|
+
getName() {
|
|
18
|
+
return exports.NAME;
|
|
19
|
+
}
|
|
20
|
+
async processAction(dto) {
|
|
21
|
+
const app = this.getApplication();
|
|
22
|
+
const request = await app.getRequestDto(dto, await this.getApplicationInstallFromProcess(dto, this.useInForm ? null : true), HttpMethods_1.HttpMethods.GET, '/user/myorganizations');
|
|
23
|
+
const response = (await this.getSender().send(request)).getJsonBody();
|
|
24
|
+
return dto.setNewJsonData(response);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = WflowGetOrganizationsConnector;
|
|
@@ -0,0 +1,117 @@
|
|
|
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 = "wflow-put-document-connector";
|
|
4
|
+
export default class WflowPutDocumentConnector extends AConnector {
|
|
5
|
+
getName(): string;
|
|
6
|
+
processAction(dto: ProcessDto<IInput>): Promise<ProcessDto<IOutput>>;
|
|
7
|
+
}
|
|
8
|
+
interface UpdateRegister {
|
|
9
|
+
id: string;
|
|
10
|
+
externalId: string;
|
|
11
|
+
code: string;
|
|
12
|
+
}
|
|
13
|
+
export interface IInput {
|
|
14
|
+
id: string;
|
|
15
|
+
externalId?: string;
|
|
16
|
+
ignoreLock?: boolean;
|
|
17
|
+
setAsFilled?: boolean;
|
|
18
|
+
type?: {
|
|
19
|
+
id?: string;
|
|
20
|
+
kind?: 'IncomingInvoice' | 'OutgoingInvoice' | 'ExpenditureCashSlip' | 'SupplierOrder' | 'CustomerOrder' | 'Other' | 'Contract' | 'IncomeCashReceipt';
|
|
21
|
+
};
|
|
22
|
+
number?: string;
|
|
23
|
+
internalCode?: string;
|
|
24
|
+
vatDocumentCode?: string;
|
|
25
|
+
variableSymbol?: string;
|
|
26
|
+
constantSymbol?: string;
|
|
27
|
+
specificSymbol?: string;
|
|
28
|
+
issueDate?: string;
|
|
29
|
+
dueDate?: string;
|
|
30
|
+
vatDate?: string;
|
|
31
|
+
acceptDate?: string;
|
|
32
|
+
caseDate?: string;
|
|
33
|
+
validFrom?: string;
|
|
34
|
+
validTo?: string;
|
|
35
|
+
effectiveFrom?: string;
|
|
36
|
+
effectiveTo?: string;
|
|
37
|
+
signatureDate?: string;
|
|
38
|
+
reviewDate?: string;
|
|
39
|
+
accountTerm?: string;
|
|
40
|
+
vatTerm?: string;
|
|
41
|
+
totalAmount?: number;
|
|
42
|
+
roundingAmount?: number;
|
|
43
|
+
totalAmountFC?: number;
|
|
44
|
+
advanceAmount?: number;
|
|
45
|
+
currency?: string;
|
|
46
|
+
partnerIC?: string;
|
|
47
|
+
partnerVAT?: string;
|
|
48
|
+
partnerLocalVAT?: string;
|
|
49
|
+
partnerName?: string;
|
|
50
|
+
partnerAddress?: string;
|
|
51
|
+
partnerEmail?: string;
|
|
52
|
+
accountNo?: string;
|
|
53
|
+
bankCode?: string;
|
|
54
|
+
iban?: string;
|
|
55
|
+
bic?: string;
|
|
56
|
+
meIC?: string;
|
|
57
|
+
exchangeRate?: number;
|
|
58
|
+
exchangeRateUnits?: number;
|
|
59
|
+
tag?: string;
|
|
60
|
+
orderNo?: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
contactPersonName?: string;
|
|
63
|
+
contactPersonEmail?: string;
|
|
64
|
+
invoiceType?: 'TaxInvoice' | 'CreditNote' | 'DebitNote' | 'Proforma' | 'TaxInvoicePayment';
|
|
65
|
+
expectedDeliveryDate?: string;
|
|
66
|
+
deliveryLocation?: UpdateRegister;
|
|
67
|
+
series?: string;
|
|
68
|
+
serie?: UpdateRegister;
|
|
69
|
+
accountCode?: string;
|
|
70
|
+
doNotPay?: boolean;
|
|
71
|
+
partner?: {
|
|
72
|
+
id: string;
|
|
73
|
+
};
|
|
74
|
+
vaTs?: {
|
|
75
|
+
type: 'Exempt' | 'FirstReduced' | 'SecondReduced' | 'Basic';
|
|
76
|
+
rate?: number;
|
|
77
|
+
base?: number;
|
|
78
|
+
tax?: number;
|
|
79
|
+
}[];
|
|
80
|
+
lines?: {
|
|
81
|
+
id?: string;
|
|
82
|
+
totalAmount?: number;
|
|
83
|
+
totalAmountFC?: number;
|
|
84
|
+
accountCode?: string;
|
|
85
|
+
currency?: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
quantity?: number;
|
|
88
|
+
unitPrice?: number;
|
|
89
|
+
measureUnit?: string;
|
|
90
|
+
order?: number;
|
|
91
|
+
}[];
|
|
92
|
+
accounting?: {
|
|
93
|
+
businessItemCode?: string;
|
|
94
|
+
accountingRule?: UpdateRegister;
|
|
95
|
+
activity?: UpdateRegister;
|
|
96
|
+
businessCase?: UpdateRegister;
|
|
97
|
+
cardDocumentType?: UpdateRegister;
|
|
98
|
+
cashDocumentType?: UpdateRegister;
|
|
99
|
+
cashRegister?: UpdateRegister;
|
|
100
|
+
contraAccount?: UpdateRegister;
|
|
101
|
+
contract?: UpdateRegister;
|
|
102
|
+
costCenter?: UpdateRegister;
|
|
103
|
+
employee?: UpdateRegister;
|
|
104
|
+
paymentMethod?: UpdateRegister;
|
|
105
|
+
project?: UpdateRegister;
|
|
106
|
+
vatControlStatementLine?: UpdateRegister;
|
|
107
|
+
vatReturnLine?: UpdateRegister;
|
|
108
|
+
vatReverseChargeCode?: UpdateRegister;
|
|
109
|
+
vehicle?: UpdateRegister;
|
|
110
|
+
vatSupplyModeCode?: 'Normal' | 'TravelService' | 'UsedGoods';
|
|
111
|
+
vatApplyReductionCoefficient?: boolean;
|
|
112
|
+
vatFixedAssets?: boolean;
|
|
113
|
+
vatMode?: 'Standard' | 'ReverseChargeDomestic' | 'ReverseCharge' | 'Excluded' | 'InForeignCurrency';
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export type IOutput = IInput;
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
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 WflowApplication_1 = require("../WflowApplication");
|
|
10
|
+
exports.NAME = `${WflowApplication_1.NAME}-put-document-connector`;
|
|
11
|
+
class WflowPutDocumentConnector extends AConnector_1.default {
|
|
12
|
+
getName() {
|
|
13
|
+
return exports.NAME;
|
|
14
|
+
}
|
|
15
|
+
async processAction(dto) {
|
|
16
|
+
const app = this.getApplication();
|
|
17
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
18
|
+
const { externalId, ignoreLock, setAsFilled } = dto.getJsonData();
|
|
19
|
+
const query = new URLSearchParams();
|
|
20
|
+
if (externalId)
|
|
21
|
+
query.set('externalId', externalId);
|
|
22
|
+
if (ignoreLock)
|
|
23
|
+
query.set('ignoreLock', ignoreLock.toString());
|
|
24
|
+
if (setAsFilled)
|
|
25
|
+
query.set('setAsFilled', setAsFilled.toString());
|
|
26
|
+
const organization = appInstall.getSettings()[WflowApplication_1.ORGANIZATION_FORM]?.[WflowApplication_1.ORGANIZATION];
|
|
27
|
+
const request = await app.getRequestDto(dto, appInstall, HttpMethods_1.HttpMethods.PUT, `/${organization}/documents${query.size ? `?${query}` : ''}`, dto.getJsonData());
|
|
28
|
+
await this.getSender().send(request);
|
|
29
|
+
return dto;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = WflowPutDocumentConnector;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 = "wflow-update-document-state-connector";
|
|
4
|
+
export default class WflowUpdateDocumentStateConnector extends AConnector {
|
|
5
|
+
getName(): string;
|
|
6
|
+
processAction(dto: ProcessDto<IInput>): Promise<ProcessDto<IOutput>>;
|
|
7
|
+
}
|
|
8
|
+
export interface IInput {
|
|
9
|
+
documentId: string;
|
|
10
|
+
}
|
|
11
|
+
export type IOutput = IInput;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 WflowApplication_1 = require("../WflowApplication");
|
|
10
|
+
exports.NAME = `${WflowApplication_1.NAME}-update-document-state-connector`;
|
|
11
|
+
class WflowUpdateDocumentStateConnector extends AConnector_1.default {
|
|
12
|
+
getName() {
|
|
13
|
+
return exports.NAME;
|
|
14
|
+
}
|
|
15
|
+
async processAction(dto) {
|
|
16
|
+
const app = this.getApplication();
|
|
17
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
18
|
+
const { documentId } = dto.getJsonData();
|
|
19
|
+
const organization = appInstall.getSettings()[WflowApplication_1.ORGANIZATION_FORM]?.[WflowApplication_1.ORGANIZATION];
|
|
20
|
+
const request = await app.getRequestDto(dto, appInstall, HttpMethods_1.HttpMethods.PUT, `/${organization}/documents/${documentId}/task/Export/processed`);
|
|
21
|
+
await this.getSender().send(request, [200]);
|
|
22
|
+
return dto;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.default = WflowUpdateDocumentStateConnector;
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { OAuth2Provider } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Provider/OAuth2/OAuth2Provider';
|
|
5
|
+
import AOAuth2Application from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/AOAuth2Application';
|
|
6
|
+
import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
|
|
7
|
+
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
|
|
8
|
+
import AProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/AProcessDto';
|
|
9
|
+
import WflowGetOrganizationsConnector from './Connector/WflowGetOrganizationsConnector';
|
|
10
|
+
export declare const NAME = "wflow";
|
|
11
|
+
export declare const ORGANIZATION_FORM = "organization-form";
|
|
12
|
+
export declare const ORGANIZATION = "organization";
|
|
13
|
+
export declare enum WebhookType {
|
|
14
|
+
DOCUMENT_READY_TO_EXTRACT = "DocumentReadyToExtract",
|
|
15
|
+
DOCUMENT_READY_TO_EXPORT = "DocumentReadyToExport",
|
|
16
|
+
DOCUMENT_UPDATED = "DocumentUpdated",
|
|
17
|
+
DOCUMENT_APPROVAL_PROCESS_FINISHED = "DocumentApprovalProcessFinished",
|
|
18
|
+
DOCUMENT_DELETED = "DocumentDeleted",
|
|
19
|
+
DOCUMENT_READY_TO_REVIEW = "DocumentReadyToReview",
|
|
20
|
+
DOCUMENT_CREATED = "DocumentCreated",
|
|
21
|
+
DOCUMENT_REVIEWED = "DocumentReviewed",
|
|
22
|
+
REGISTER_UPDATED = "RegisterUpdated",
|
|
23
|
+
ALL = "All"
|
|
24
|
+
}
|
|
25
|
+
export default class WflowApplication extends AOAuth2Application {
|
|
26
|
+
private readonly wflowGetOrganizationsConnector;
|
|
27
|
+
constructor(provider: OAuth2Provider, wflowGetOrganizationsConnector: WflowGetOrganizationsConnector);
|
|
28
|
+
getName(): string;
|
|
29
|
+
getPublicName(): string;
|
|
30
|
+
getDescription(): string;
|
|
31
|
+
getLogo(): string;
|
|
32
|
+
getFormStack(): FormStack;
|
|
33
|
+
getRequestDto(dto: AProcessDto, applicationInstall: ApplicationInstall, method: HttpMethods, path?: string, data?: unknown): RequestDto;
|
|
34
|
+
getAuthUrl(): string;
|
|
35
|
+
getTokenUrl(): string;
|
|
36
|
+
getScopes(): string[];
|
|
37
|
+
getScopesSeparator(): string;
|
|
38
|
+
getWebhookSubscriptions(): WebhookSubscription[];
|
|
39
|
+
protected customFormReplace(formStack: FormStack, applicationInstall: ApplicationInstall): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.WebhookType = exports.ORGANIZATION = exports.ORGANIZATION_FORM = exports.NAME = void 0;
|
|
40
|
+
const CoreFormsEnum_1 = __importStar(require("@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum"));
|
|
41
|
+
const Field_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Field"));
|
|
42
|
+
const FieldType_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FieldType"));
|
|
43
|
+
const Form_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Form"));
|
|
44
|
+
const FormStack_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack"));
|
|
45
|
+
const ScopeSeparatorEnum_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Authorization/ScopeSeparatorEnum"));
|
|
46
|
+
const AOAuth2Application_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/AOAuth2Application"));
|
|
47
|
+
const IOAuth2Application_1 = require("@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/IOAuth2Application");
|
|
48
|
+
const RequestDto_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto"));
|
|
49
|
+
const Headers_1 = require("@orchesty/nodejs-sdk/dist/lib/Utils/Headers");
|
|
50
|
+
const ProcessDto_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto"));
|
|
51
|
+
exports.NAME = 'wflow';
|
|
52
|
+
exports.ORGANIZATION_FORM = 'organization-form';
|
|
53
|
+
exports.ORGANIZATION = 'organization';
|
|
54
|
+
var WebhookType;
|
|
55
|
+
(function (WebhookType) {
|
|
56
|
+
WebhookType["DOCUMENT_READY_TO_EXTRACT"] = "DocumentReadyToExtract";
|
|
57
|
+
WebhookType["DOCUMENT_READY_TO_EXPORT"] = "DocumentReadyToExport";
|
|
58
|
+
WebhookType["DOCUMENT_UPDATED"] = "DocumentUpdated";
|
|
59
|
+
WebhookType["DOCUMENT_APPROVAL_PROCESS_FINISHED"] = "DocumentApprovalProcessFinished";
|
|
60
|
+
WebhookType["DOCUMENT_DELETED"] = "DocumentDeleted";
|
|
61
|
+
WebhookType["DOCUMENT_READY_TO_REVIEW"] = "DocumentReadyToReview";
|
|
62
|
+
WebhookType["DOCUMENT_CREATED"] = "DocumentCreated";
|
|
63
|
+
WebhookType["DOCUMENT_REVIEWED"] = "DocumentReviewed";
|
|
64
|
+
WebhookType["REGISTER_UPDATED"] = "RegisterUpdated";
|
|
65
|
+
WebhookType["ALL"] = "All";
|
|
66
|
+
})(WebhookType || (exports.WebhookType = WebhookType = {}));
|
|
67
|
+
class WflowApplication extends AOAuth2Application_1.default {
|
|
68
|
+
wflowGetOrganizationsConnector;
|
|
69
|
+
constructor(provider, wflowGetOrganizationsConnector) {
|
|
70
|
+
super(provider);
|
|
71
|
+
this.wflowGetOrganizationsConnector = wflowGetOrganizationsConnector;
|
|
72
|
+
}
|
|
73
|
+
getName() {
|
|
74
|
+
return exports.NAME;
|
|
75
|
+
}
|
|
76
|
+
getPublicName() {
|
|
77
|
+
return 'wflow';
|
|
78
|
+
}
|
|
79
|
+
getDescription() {
|
|
80
|
+
return 'Digital accounting that saves you time and money';
|
|
81
|
+
}
|
|
82
|
+
getLogo() {
|
|
83
|
+
return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjMyIiBoZWlnaHQ9IjMyIj4KPHBhdGggZD0iTTAgMCBDMC43OTAxOTUzMSAtMC4wMzI4NzEwOSAxLjU4MDM5MDYyIC0wLjA2NTc0MjE5IDIuMzk0NTMxMjUgLTAuMDk5NjA5MzggQzYuNjA1Njk3ODUgLTAuMTM4MTQ3NTEgOS4zMDEwNTA4NCAwLjEzMzY1NzY0IDEyLjYzMjgxMjUgMi44Mzk4NDM3NSBDMTYuNjgyNDM3MDIgNy4wNjA4NDczNiAxNi40MDIyMzg0NSAxMC41NzA2NTQ2OSAxNi41IDE2LjE4NzUgQzE2LjU1NjA3NDIyIDE3LjM4NjMyODEyIDE2LjU1NjA3NDIyIDE3LjM4NjMyODEyIDE2LjYxMzI4MTI1IDE4LjYwOTM3NSBDMTYuNjc2MTMxNSAyMi44NTUyNTgyMiAxNi40NjEwNzg3MyAyNS41ODk3MzAzMSAxMy43MjY1NjI1IDI4Ljk1MzEyNSBDOS40NjIyNTk1MyAzMy4wMjUzNDIyNSA1Ljk2NTc4NTI5IDMyLjY1MTkxNjc3IDAuMzEyNSAzMi42ODc1IEMtMC40OTUwOTc2NiAzMi43MDgxMjUgLTEuMzAyNjk1MzEgMzIuNzI4NzUgLTIuMTM0NzY1NjIgMzIuNzUgQy02Ljg0NzEzMDIxIDMyLjc4MDg3NTQ0IC0xMC4xMjA3NjIwMiAzMi42MTI1MTI2OSAtMTMuODc1IDI5LjQzNzUgQy0xNi43ODkwMzM3NSAyNS43NjYzNDU3IC0xNi4yMDU0NDYxNiAyMC45Njg1OTM2NCAtMTYuMTg3NSAxNi41IEMtMTYuMjAzNjEzMjggMTUuNzAxNDI1NzggLTE2LjIxOTcyNjU2IDE0LjkwMjg1MTU2IC0xNi4yMzYzMjgxMiAxNC4wODAwNzgxMiBDLTE2LjI0MDE5OTA1IDkuNDA3ODczMTMgLTE2LjAwNTk4MDQ2IDYuMTYyMTY1MjUgLTEyLjg3NSAyLjQzNzUgQy05LjIxNTYxOTk1IC0wLjQ0MjcyOTc1IC00LjQ1MjE5NDAxIDAuMDMyMzY2NTIgMCAwIFogIiBmaWxsPSIjMUM0RUZGIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgxNS44NzUsLTAuNDM3NSkiLz4KPHBhdGggZD0iTTAgMCBDMi4xNTgyMDM4MiAxLjcwODU3ODAzIDIuOTQzMDQzNDkgMi41MzE2OTA4OSAzLjI4MTI1IDUuMzEyNSBDMi45Mzk5MTY3OCA4LjU3NDEyODUzIDEuODk4Mzg4NDIgMTAuMTYyNjY2MTYgMCAxMi44MTI1IEMtMC41NTY4NzUgMTMuNjAyNjk1MzEgLTEuMTEzNzUgMTQuMzkyODkwNjIgLTEuNjg3NSAxNS4yMDcwMzEyNSBDLTIuMzM3MTg3NSAxNi4wOTQ1NTA3OCAtMi4zMzcxODc1IDE2LjA5NDU1MDc4IC0zIDE3IEMtNi44NzUgMTMuMjUgLTYuODc1IDEzLjI1IC04IDExIEMtOS45OCAxMy45NyAtOS45OCAxMy45NyAtMTIgMTcgQy0xMy4zMiAxNS4zNSAtMTQuNjQgMTMuNyAtMTYgMTIgQy0xNS4xMDE3Nzg4MiAxMC4zMjMzMjA0NiAtMTQuMTgwNzg0MzkgOC42NTg4MjM2NyAtMTMuMjUgNyBDLTEyLjczOTUzMTI1IDYuMDcxODc1IC0xMi4yMjkwNjI1IDUuMTQzNzUgLTExLjcwMzEyNSA0LjE4NzUgQy0xMC44NjAwNzgxMiAzLjEwNDY4NzUgLTEwLjg2MDA3ODEyIDMuMTA0Njg3NSAtMTAgMiBDLTguNjggMiAtNy4zNiAyIC02IDIgQy01LjM0IDMuMzIgLTQuNjggNC42NCAtNCA2IEMtMi42OCA0LjAyIC0xLjM2IDIuMDQgMCAwIFogIiBmaWxsPSIjRTlFRUZGIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgyNCw4KSIvPgo8cGF0aCBkPSJNMCAwIEMwLjk5IDAuMzMgMS45OCAwLjY2IDMgMSBDMy43MTQ4NDM3NSAzLjE2Nzk2ODc1IDMuNzE0ODQzNzUgMy4xNjc5Njg3NSA0IDYgQzIuNTY2NDA2MjUgOC42NzU3ODEyNSAyLjU2NjQwNjI1IDguNjc1NzgxMjUgMC41NjI1IDExLjMxMjUgQy0wLjA5NjIxMDk0IDEyLjE5NTUwNzgxIC0wLjc1NDkyMTg4IDEzLjA3ODUxNTYzIC0xLjQzMzU5Mzc1IDEzLjk4ODI4MTI1IEMtMi4yMDg5NjQ4NCAxNC45ODQwODIwMyAtMi4yMDg5NjQ4NCAxNC45ODQwODIwMyAtMyAxNiBDLTQuMzIgMTQuMzUgLTUuNjQgMTIuNyAtNyAxMSBDLTYuMDIyNjIyMzEgOS4zNTMxMDM2NSAtNS4wNDMwNDY4IDcuNzA3NTExNDYgLTQuMDYyNSA2LjA2MjUgQy0zLjUxNzIyNjU2IDUuMTQ1OTc2NTYgLTIuOTcxOTUzMTIgNC4yMjk0NTMxMiAtMi40MTAxNTYyNSAzLjI4NTE1NjI1IEMtMSAxIC0xIDEgMCAwIFogIiBmaWxsPSIjRjRGNkZGIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgxNSw5KSIvPgo8cGF0aCBkPSJNMCAwIEMxLjU2MjUgMS4xMjUgMS41NjI1IDEuMTI1IDMgMyBDMi42ODc1IDYuMTg3NSAyLjY4NzUgNi4xODc1IDIgOSBDMS4wMSA5LjMzIDAuMDIgOS42NiAtMSAxMCBDLTIuMzgxMjUwMTggNy4yMzc0OTk2NCAtMi4xOTA3OTMwNiA1LjA1MjY4OTAxIC0yIDIgQy0xLjM0IDEuMzQgLTAuNjggMC42OCAwIDAgWiAiIGZpbGw9IiNFRUYyRkYiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDcsOCkiLz4KPC9zdmc+Cg==';
|
|
84
|
+
}
|
|
85
|
+
getFormStack() {
|
|
86
|
+
return new FormStack_1.default()
|
|
87
|
+
.addForm(new Form_1.default(CoreFormsEnum_1.default.AUTHORIZATION_FORM, (0, CoreFormsEnum_1.getFormName)(CoreFormsEnum_1.default.AUTHORIZATION_FORM))
|
|
88
|
+
.addField(new Field_1.default(FieldType_1.default.TEXT, IOAuth2Application_1.CLIENT_ID, 'Client Id', null, false))
|
|
89
|
+
.addField(new Field_1.default(FieldType_1.default.TEXT, IOAuth2Application_1.CLIENT_SECRET, 'Client Secret', null, false)))
|
|
90
|
+
.addForm(new Form_1.default(exports.ORGANIZATION_FORM, 'Organization settings'));
|
|
91
|
+
}
|
|
92
|
+
getRequestDto(dto, applicationInstall, method, path, data) {
|
|
93
|
+
const headers = {
|
|
94
|
+
[Headers_1.CommonHeaders.ACCEPT]: Headers_1.JSON_TYPE,
|
|
95
|
+
[Headers_1.CommonHeaders.AUTHORIZATION]: `Bearer ${this.getAccessToken(applicationInstall)}`,
|
|
96
|
+
};
|
|
97
|
+
const url = new URL(`/api${path ?? ''}`, 'https://api.wflow.com').href;
|
|
98
|
+
return new RequestDto_1.default(url, method, dto, data, headers);
|
|
99
|
+
}
|
|
100
|
+
getAuthUrl() {
|
|
101
|
+
return 'https://account.wflow.com/connect/authorize';
|
|
102
|
+
}
|
|
103
|
+
getTokenUrl() {
|
|
104
|
+
return 'https://account.wflow.com/connect/token';
|
|
105
|
+
}
|
|
106
|
+
getScopes() {
|
|
107
|
+
return ['uccl_common_api'];
|
|
108
|
+
}
|
|
109
|
+
getScopesSeparator() {
|
|
110
|
+
return ScopeSeparatorEnum_1.default.SPACE;
|
|
111
|
+
}
|
|
112
|
+
getWebhookSubscriptions() {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
async customFormReplace(formStack, applicationInstall) {
|
|
116
|
+
const organizations = (await this.wflowGetOrganizationsConnector.processAction(ProcessDto_1.default.createForFormRequest(exports.NAME, applicationInstall.getUser(), crypto.randomUUID(), 'form'))).getJsonData();
|
|
117
|
+
const form = formStack.getForms().find((item) => item.getKey() === exports.ORGANIZATION_FORM);
|
|
118
|
+
const settings = applicationInstall.getSettings()[exports.ORGANIZATION_FORM];
|
|
119
|
+
if (!form) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const choices = organizations.map((organization) => ({ [organization.subdomain]: organization.name }));
|
|
123
|
+
form.addField(new Field_1.default(FieldType_1.default.SELECT_BOX, exports.ORGANIZATION, 'Organization name', settings?.[exports.ORGANIZATION], true).setChoices(choices));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.default = WflowApplication;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orchesty/connector-wflow",
|
|
3
|
+
"description": "",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"url": "https://github.com/Orchesty/orchesty-nodejs-connectors",
|
|
7
|
+
"repository": "https://github.com/Orchesty/orchesty-nodejs-connectors",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "rm -rf dist && rm -rf tsconfig.prod.tsbuildinfo && tsc -d -p tsconfig.prod.json && cp package.json ./dist/package.json",
|
|
10
|
+
"test": "jest --coverage --forceExit --passWithNoTests",
|
|
11
|
+
"lint": "eslint src test --fix",
|
|
12
|
+
"lint-ci": "eslint src test"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "info@hanaboso.com",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@orchesty/nodejs-sdk": "^4.3.6"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=24"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const baseConfig = require('../../jest.config.js');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
...baseConfig,
|
|
5
|
+
roots: ["<rootDir>/src"],
|
|
6
|
+
setupFiles: ["<rootDir>/../../.jest/testEnvs.ts"],
|
|
7
|
+
setupFilesAfterEnv: ["<rootDir>/../../.jest/testLifecycle.ts"],
|
|
8
|
+
globalSetup: "<rootDir>/../../.jest/globalSetup.ts",
|
|
9
|
+
moduleNameMapper: {
|
|
10
|
+
"^@orchesty/nodejs-connectors/test/(.*)$": "<rootDir>/../../test/$1",
|
|
11
|
+
"^@orchesty/nodejs-connectors/lib/(.*)$": "<rootDir>/../../lib/$1",
|
|
12
|
+
},
|
|
13
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orchesty/connector-wflow",
|
|
3
|
+
"description": "",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"url": "https://github.com/Orchesty/orchesty-nodejs-connectors",
|
|
7
|
+
"repository": "https://github.com/Orchesty/orchesty-nodejs-connectors",
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"author": "info@hanaboso.com",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@orchesty/nodejs-sdk": "^4.3.6"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=24"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "rm -rf dist && rm -rf tsconfig.prod.tsbuildinfo && tsc -d -p tsconfig.prod.json && cp package.json ./dist/package.json",
|
|
18
|
+
"test": "jest --coverage --forceExit --passWithNoTests",
|
|
19
|
+
"lint": "eslint src test --fix",
|
|
20
|
+
"lint-ci": "eslint src test"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import Webhook from '@orchesty/nodejs-sdk/dist/lib/Application/Database/Webhook';
|
|
2
|
+
import WebhookRepository from '@orchesty/nodejs-sdk/dist/lib/Application/Database/WebhookRepository';
|
|
3
|
+
import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
|
|
4
|
+
import TopologyRunner from '@orchesty/nodejs-sdk/dist/lib/Topology/TopologyRunner';
|
|
5
|
+
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
|
|
6
|
+
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
|
|
7
|
+
import crypto from 'crypto';
|
|
8
|
+
import WflowApplication, { NAME as WFLOW_APP_NAME, ORGANIZATION, ORGANIZATION_FORM } from '../WflowApplication';
|
|
9
|
+
|
|
10
|
+
export const NAME = `${WFLOW_APP_NAME}-subscribe-webhooks-batch`;
|
|
11
|
+
|
|
12
|
+
export default class WflowSubscribeWebhookBatch extends ABatchNode {
|
|
13
|
+
|
|
14
|
+
public getName(): string {
|
|
15
|
+
return NAME;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async processAction(dto: BatchProcessDto): Promise<BatchProcessDto> {
|
|
19
|
+
const app = this.getApplication<WflowApplication>();
|
|
20
|
+
const subscriptions = app.getWebhookSubscriptions();
|
|
21
|
+
|
|
22
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
23
|
+
const repository = this.getDbClient().getRepository(Webhook) as WebhookRepository;
|
|
24
|
+
|
|
25
|
+
const registeredEvents = (await repository.findMany({
|
|
26
|
+
users: [appInstall.getUser()],
|
|
27
|
+
apps: [appInstall.getName()],
|
|
28
|
+
})).map((webhook) => webhook.getName());
|
|
29
|
+
|
|
30
|
+
const unsubscribed = subscriptions.find(
|
|
31
|
+
(subscription) => !registeredEvents.some(
|
|
32
|
+
(event) => subscription.getName() === event,
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (!unsubscribed) {
|
|
37
|
+
return dto;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const organization: string | undefined
|
|
41
|
+
= appInstall.getSettings()[ORGANIZATION_FORM]?.[ORGANIZATION];
|
|
42
|
+
if (!organization) {
|
|
43
|
+
return dto;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const token = crypto.randomBytes(64).toString('hex');
|
|
47
|
+
const request = app.getRequestDto(
|
|
48
|
+
dto,
|
|
49
|
+
appInstall,
|
|
50
|
+
HttpMethods.PUT,
|
|
51
|
+
`/${organization}/webhookregistrations`,
|
|
52
|
+
{
|
|
53
|
+
actions: [unsubscribed.getName()],
|
|
54
|
+
webhookUri: TopologyRunner.getWebhookUrl(
|
|
55
|
+
unsubscribed.getTopology(),
|
|
56
|
+
unsubscribed.getNode(),
|
|
57
|
+
token,
|
|
58
|
+
),
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const id = (
|
|
63
|
+
await this.getSender().send<string>(request)
|
|
64
|
+
).getJsonBody();
|
|
65
|
+
|
|
66
|
+
await repository.insert(
|
|
67
|
+
new Webhook()
|
|
68
|
+
.setWebhookId(id)
|
|
69
|
+
.setUser(appInstall.getUser())
|
|
70
|
+
.setNode(unsubscribed.getNode())
|
|
71
|
+
.setToken(token)
|
|
72
|
+
.setApplication(appInstall.getName())
|
|
73
|
+
.setTopology(unsubscribed.getTopology())
|
|
74
|
+
.setName(unsubscribed.getName()),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return dto.setBatchCursor('1', true);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Webhook from '@orchesty/nodejs-sdk/dist/lib/Application/Database/Webhook';
|
|
2
|
+
import WebhookRepository 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 { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
|
|
6
|
+
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
|
|
7
|
+
import WflowApplication, { NAME as WFLOW_APP_NAME, ORGANIZATION, ORGANIZATION_FORM } from '../WflowApplication';
|
|
8
|
+
|
|
9
|
+
export const NAME = `${WFLOW_APP_NAME}-unsubscribe-webhooks-batch`;
|
|
10
|
+
|
|
11
|
+
export default class WflowUnsubscribeWebhookBatch extends ABatchNode {
|
|
12
|
+
|
|
13
|
+
public getName(): string {
|
|
14
|
+
return NAME;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async processAction(dto: BatchProcessDto): Promise<BatchProcessDto> {
|
|
18
|
+
const app = this.getApplication<WflowApplication>();
|
|
19
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto, null);
|
|
20
|
+
const repository = this.getDbClient().getRepository(Webhook) as WebhookRepository;
|
|
21
|
+
|
|
22
|
+
const webhook = await repository.findOne({
|
|
23
|
+
users: [appInstall.getUser()],
|
|
24
|
+
apps: [appInstall.getName()],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (!webhook) {
|
|
28
|
+
return dto;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const organization: string | undefined
|
|
32
|
+
= appInstall.getSettings()[ORGANIZATION_FORM]?.[ORGANIZATION];
|
|
33
|
+
if (!organization) {
|
|
34
|
+
return dto;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const request = app.getRequestDto(
|
|
38
|
+
dto,
|
|
39
|
+
appInstall,
|
|
40
|
+
HttpMethods.DELETE,
|
|
41
|
+
`/${organization}/webhookregistrations/${webhook.getWebhookId()}`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const response = await this.getSender().send(request);
|
|
45
|
+
|
|
46
|
+
if (response.getResponseCode() as number !== 200) {
|
|
47
|
+
await repository.update(webhook.setUnsubscribeFailed(true));
|
|
48
|
+
throw new OnRepeatException(300, 12, response.getBody());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
await repository.remove(webhook);
|
|
52
|
+
return dto.setBatchCursor('1', true);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
@@ -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 WFLOW_SUBSCRIBE_WEBHOOK_BATCH } from '../WflowSubscribeWebhookBatch';
|
|
5
|
+
|
|
6
|
+
let tester: NodeTester;
|
|
7
|
+
|
|
8
|
+
describe('Tests for WflowSubscribeWebhookBatch', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
tester = new NodeTester(container, __filename);
|
|
11
|
+
init();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('process - ok', async () => {
|
|
15
|
+
await tester.testBatch(WFLOW_SUBSCRIBE_WEBHOOK_BATCH);
|
|
16
|
+
});
|
|
17
|
+
});
|