@orchesty/connector-upgates 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 +302 -0
- package/coverage/coverage-final.json +11 -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/UpgatesCreateWebhooks.ts.html +358 -0
- package/coverage/lcov-report/src/Batch/UpgatesGetOrders.ts.html +727 -0
- package/coverage/lcov-report/src/Batch/UpgatesGetProducts.ts.html +733 -0
- package/coverage/lcov-report/src/Batch/index.html +146 -0
- package/coverage/lcov-report/src/Connector/UpgatesDeleteWebhooks.ts.html +370 -0
- package/coverage/lcov-report/src/Connector/UpgatesGetOrderStates.ts.html +190 -0
- package/coverage/lcov-report/src/Connector/UpgatesGetPayments.ts.html +268 -0
- package/coverage/lcov-report/src/Connector/UpgatesGetProductParameters.ts.html +316 -0
- package/coverage/lcov-report/src/Connector/UpgatesGetShipments.ts.html +274 -0
- package/coverage/lcov-report/src/Connector/index.html +176 -0
- package/coverage/lcov-report/src/UpgatesApplication.ts.html +379 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/test/dataProvider.ts.html +223 -0
- package/coverage/lcov-report/test/index.html +116 -0
- package/coverage/lcov.info +485 -0
- package/dist/Batch/UpgatesCreateWebhooks.d.ts +17 -0
- package/dist/Batch/UpgatesCreateWebhooks.js +61 -0
- package/dist/Batch/UpgatesGetOrders.d.ts +148 -0
- package/dist/Batch/UpgatesGetOrders.js +51 -0
- package/dist/Batch/UpgatesGetProducts.d.ts +146 -0
- package/dist/Batch/UpgatesGetProducts.js +70 -0
- package/dist/Connector/UpgatesDeleteWebhooks.d.ts +15 -0
- package/dist/Connector/UpgatesDeleteWebhooks.js +62 -0
- package/dist/Connector/UpgatesGetOrderStates.d.ts +15 -0
- package/dist/Connector/UpgatesGetOrderStates.js +21 -0
- package/dist/Connector/UpgatesGetPayments.d.ts +38 -0
- package/dist/Connector/UpgatesGetPayments.js +21 -0
- package/dist/Connector/UpgatesGetProductParameters.d.ts +37 -0
- package/dist/Connector/UpgatesGetProductParameters.js +33 -0
- package/dist/Connector/UpgatesGetShipments.d.ts +40 -0
- package/dist/Connector/UpgatesGetShipments.js +21 -0
- package/dist/Connector/UpgatesUpdateOrder.d.ts +37 -0
- package/dist/Connector/UpgatesUpdateOrder.js +24 -0
- package/dist/Connector/UpgatesUpdateStock.d.ts +21 -0
- package/dist/Connector/UpgatesUpdateStock.js +24 -0
- package/dist/UpgatesApplication.d.ts +21 -0
- package/dist/UpgatesApplication.js +105 -0
- package/dist/package.json +27 -0
- package/jest.config.js +13 -0
- package/package.json +27 -0
- package/src/Batch/UpgatesCreateWebhooks.ts +91 -0
- package/src/Batch/UpgatesGetOrders.ts +214 -0
- package/src/Batch/UpgatesGetProducts.ts +216 -0
- package/src/Batch/__tests__/Data/UpgatesCreateWebhooks/input.json +6 -0
- package/src/Batch/__tests__/Data/UpgatesCreateWebhooks/mock.json +14 -0
- package/src/Batch/__tests__/Data/UpgatesCreateWebhooks/output.json +6 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/input.json +6 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/lastRun-input.json +6 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/lastRun-mock.json +191 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/lastRun-output.json +11 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/mock.json +191 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/orderNumber-input.json +8 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/orderNumber-mock.json +191 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/orderNumber-output.json +11 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/orderNumbers-input.json +8 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/orderNumbers-mock.json +191 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/orderNumbers-output.json +11 -0
- package/src/Batch/__tests__/Data/UpgatesGetOrders/output.json +11 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/input.json +6 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/lastRun-input.json +6 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/lastRun-mock.json +147 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/lastRun-output.json +11 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/mock.json +146 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/output.json +11 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/productId-input.json +8 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/productId-mock.json +146 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/productId-output.json +11 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/productIds-input.json +8 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/productIds-mock.json +146 -0
- package/src/Batch/__tests__/Data/UpgatesGetProducts/productIds-output.json +11 -0
- package/src/Batch/__tests__/UpgatesCreateWebhooks.ts +17 -0
- package/src/Batch/__tests__/UpgatesGetOrders.ts +33 -0
- package/src/Batch/__tests__/UpgatesGetProducts.ts +33 -0
- package/src/Connector/UpgatesDeleteWebhooks.ts +95 -0
- package/src/Connector/UpgatesGetOrderStates.ts +35 -0
- package/src/Connector/UpgatesGetPayments.ts +61 -0
- package/src/Connector/UpgatesGetProductParameters.ts +77 -0
- package/src/Connector/UpgatesGetShipments.ts +63 -0
- package/src/Connector/UpgatesUpdateOrder.ts +73 -0
- package/src/Connector/UpgatesUpdateStock.ts +59 -0
- package/src/Connector/__tests__/Data/UpgatesDeleteWebhooks/input.json +6 -0
- package/src/Connector/__tests__/Data/UpgatesDeleteWebhooks/mock.json +16 -0
- package/src/Connector/__tests__/Data/UpgatesDeleteWebhooks/output.json +6 -0
- package/src/Connector/__tests__/Data/UpgatesGetOrderStates/input.json +6 -0
- package/src/Connector/__tests__/Data/UpgatesGetOrderStates/mock.json +14 -0
- package/src/Connector/__tests__/Data/UpgatesGetOrderStates/output.json +15 -0
- package/src/Connector/__tests__/Data/UpgatesGetPayments/input.json +6 -0
- package/src/Connector/__tests__/Data/UpgatesGetPayments/mock.json +42 -0
- package/src/Connector/__tests__/Data/UpgatesGetPayments/output.json +43 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/both-input.json +9 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/both-mock.json +108 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/both-output.json +109 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/input.json +8 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/mock.json +108 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/none-input.json +6 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/none-mock.json +5 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/none-output.json +6 -0
- package/src/Connector/__tests__/Data/UpgatesGetProductParameters/output.json +109 -0
- package/src/Connector/__tests__/Data/UpgatesGetShipments/input.json +6 -0
- package/src/Connector/__tests__/Data/UpgatesGetShipments/mock.json +58 -0
- package/src/Connector/__tests__/Data/UpgatesGetShipments/output.json +59 -0
- package/src/Connector/__tests__/UpgatesDeleteWebhooks.ts +61 -0
- package/src/Connector/__tests__/UpgatesGetOrderStates.ts +18 -0
- package/src/Connector/__tests__/UpgatesGetPayments.ts +18 -0
- package/src/Connector/__tests__/UpgatesGetProductParameters.ts +28 -0
- package/src/Connector/__tests__/UpgatesGetShipments.ts +18 -0
- package/src/UpgatesApplication.ts +98 -0
- package/test/dataProvider.ts +46 -0
- package/tsconfig.json +8 -0
- package/tsconfig.prod.json +13 -0
- package/tsconfig.prod.tsbuildinfo +1 -0
|
@@ -0,0 +1,24 @@
|
|
|
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 UPDATE_STOCK_ENDPOINT = 'api/v2/products';
|
|
10
|
+
exports.NAME = 'upgates-update-stock';
|
|
11
|
+
class UpgatesUpdateStock extends AConnector_1.default {
|
|
12
|
+
getName() {
|
|
13
|
+
return exports.NAME;
|
|
14
|
+
}
|
|
15
|
+
async processAction(dto) {
|
|
16
|
+
const app = this.getApplication();
|
|
17
|
+
const { data, } = dto.getJsonData();
|
|
18
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
19
|
+
const requestDto = app.getRequestDto(dto, appInstall, HttpMethods_1.HttpMethods.PUT, UPDATE_STOCK_ENDPOINT, JSON.stringify(data));
|
|
20
|
+
const { products } = (await this.getSender().send(requestDto)).getJsonBody();
|
|
21
|
+
return dto.setNewJsonData(products);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = UpgatesUpdateStock;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
export declare const NAME = "upgates";
|
|
9
|
+
export declare const UPGATES_URL = "upgatesUrl";
|
|
10
|
+
export default class UpgatesApplication extends ABasicApplication {
|
|
11
|
+
getDescription(): string;
|
|
12
|
+
getName(): string;
|
|
13
|
+
getPublicName(): string;
|
|
14
|
+
getLogo(): string;
|
|
15
|
+
getRequestDto(dto: AProcessDto, applicationInstall: ApplicationInstall, method: HttpMethods | string, url?: string, data?: string): RequestDto;
|
|
16
|
+
getDecoratedUrl(app: ApplicationInstall): string;
|
|
17
|
+
getFormStack(): FormStack;
|
|
18
|
+
isAuthorized(applicationInstall: ApplicationInstall): boolean;
|
|
19
|
+
getIsoDateFromDate(date?: string): string;
|
|
20
|
+
getWebhookSubscriptions(): WebhookSubscription[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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.UPGATES_URL = 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 ABasicApplication_1 = require("@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication");
|
|
46
|
+
const RequestDto_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto"));
|
|
47
|
+
const HttpMethods_1 = require("@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods");
|
|
48
|
+
const Base64_1 = require("@orchesty/nodejs-sdk/dist/lib/Utils/Base64");
|
|
49
|
+
const Headers_1 = require("@orchesty/nodejs-sdk/dist/lib/Utils/Headers");
|
|
50
|
+
exports.NAME = 'upgates';
|
|
51
|
+
exports.UPGATES_URL = 'upgatesUrl';
|
|
52
|
+
class UpgatesApplication extends ABasicApplication_1.ABasicApplication {
|
|
53
|
+
getDescription() {
|
|
54
|
+
return 'Customizable e-shop solution that you can tailor to your needs and ideas';
|
|
55
|
+
}
|
|
56
|
+
getName() {
|
|
57
|
+
return exports.NAME;
|
|
58
|
+
}
|
|
59
|
+
getPublicName() {
|
|
60
|
+
return 'Upgates';
|
|
61
|
+
}
|
|
62
|
+
getLogo() {
|
|
63
|
+
return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IlZyc3R2YV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTAwIDEwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsLXJ1bGU6ZXZlbm9kZDtjbGlwLXJ1bGU6ZXZlbm9kZDtmaWxsOiNGOUEwM0I7fQoJLnN0MXtmaWxsOiNGOUEwM0I7fQo8L3N0eWxlPgo8ZyBpZD0iU3ltYm9sIj4KCTxwYXRoIGlkPSJQYXRoIiBjbGFzcz0ic3QwIiBkPSJNNDEuNCw1OC4zaDE2LjZ2MTIuNGMwLDE2LjEtMTMsMjkuMS0yOS4xLDI5LjFjLTE2LjEsMC0yOS4xLTEzLTI5LjEtMjkuMXYtNTRoMTYuNnY1NAoJCWMwLDYuOSw1LjYsMTIuNCwxMi40LDEyLjRjNi45LDAsMTIuNC01LjYsMTIuNC0xMi40VjU4LjN6Ii8+Cgk8cGF0aCBpZD0iUGF0aC0yIiBjbGFzcz0ic3QwIiBkPSJNNTguMSw1OC4zVjQxLjdoMTIuNGM2LjksMC4xLDEyLjUtNS41LDEyLjYtMTIuNGMwLjEtNi45LTUuNS0xMi41LTEyLjQtMTIuNkgxNi41VjAuMkg3MQoJCWMxNi4xLDAsMjkuMSwxMywyOS4xLDI5LjFjMCwxNi4xLTEzLDI5LjEtMjkuMSwyOS4xYzAsMCwwLDAsMCwwSDU4LjF6Ii8+Cgk8cGF0aCBpZD0iVE0iIGNsYXNzPSJzdDEiIGQ9Ik04OC4xLDk0Ljl2LTUuMmgydi0xLjRoLTUuNXYxLjRoMnY1LjJIODguMXogTTkyLjIsOTQuOXYtNC40bDEuOCw0LjRoMS4ybDEuOC00LjR2NC40aDEuNXYtNi43aC0yCgkJbC0xLjgsNC41bC0xLjgtNC41aC0xLjl2Ni43SDkyLjJ6Ii8+CjwvZz4KPC9zdmc+Cg==';
|
|
64
|
+
}
|
|
65
|
+
getRequestDto(dto, applicationInstall, method, url, data) {
|
|
66
|
+
const settings = applicationInstall.getSettings();
|
|
67
|
+
const base64 = (0, Base64_1.encode)(`${settings[CoreFormsEnum_1.default.AUTHORIZATION_FORM][ABasicApplication_1.USER]?.trim()}:${settings[CoreFormsEnum_1.default.AUTHORIZATION_FORM][ABasicApplication_1.PASSWORD]?.trim()}`);
|
|
68
|
+
const headers = {
|
|
69
|
+
[Headers_1.CommonHeaders.AUTHORIZATION]: `Basic ${base64}`,
|
|
70
|
+
[Headers_1.CommonHeaders.ACCEPT]: Headers_1.JSON_TYPE,
|
|
71
|
+
[Headers_1.CommonHeaders.CONTENT_TYPE]: Headers_1.JSON_TYPE,
|
|
72
|
+
};
|
|
73
|
+
let urlx = url ?? '';
|
|
74
|
+
if (!urlx.startsWith('http')) {
|
|
75
|
+
urlx = `${this.getDecoratedUrl(applicationInstall)}/${urlx}`;
|
|
76
|
+
}
|
|
77
|
+
return new RequestDto_1.default(urlx, (0, HttpMethods_1.parseHttpMethod)(method), dto, data, headers);
|
|
78
|
+
}
|
|
79
|
+
getDecoratedUrl(app) {
|
|
80
|
+
let url = app.getSettings()?.[CoreFormsEnum_1.default.AUTHORIZATION_FORM]?.[exports.UPGATES_URL] ?? '';
|
|
81
|
+
url = url.replace('api/v2', '');
|
|
82
|
+
if (url.endsWith('/')) {
|
|
83
|
+
url = url.substring(0, url.length - 1);
|
|
84
|
+
}
|
|
85
|
+
return url;
|
|
86
|
+
}
|
|
87
|
+
getFormStack() {
|
|
88
|
+
const form = new Form_1.default(CoreFormsEnum_1.default.AUTHORIZATION_FORM, (0, CoreFormsEnum_1.getFormName)(CoreFormsEnum_1.default.AUTHORIZATION_FORM))
|
|
89
|
+
.addField(new Field_1.default(FieldType_1.default.TEXT, ABasicApplication_1.USER, 'Login', undefined, true))
|
|
90
|
+
.addField(new Field_1.default(FieldType_1.default.TEXT, ABasicApplication_1.PASSWORD, 'Klíč API', undefined, true))
|
|
91
|
+
.addField(new Field_1.default(FieldType_1.default.URL, exports.UPGATES_URL, 'Url', undefined, true));
|
|
92
|
+
return new FormStack_1.default().addForm(form);
|
|
93
|
+
}
|
|
94
|
+
isAuthorized(applicationInstall) {
|
|
95
|
+
const authorizationForm = applicationInstall.getSettings()[CoreFormsEnum_1.default.AUTHORIZATION_FORM];
|
|
96
|
+
return authorizationForm?.[ABasicApplication_1.USER] && authorizationForm?.[ABasicApplication_1.PASSWORD] && authorizationForm?.[exports.UPGATES_URL];
|
|
97
|
+
}
|
|
98
|
+
getIsoDateFromDate(date) {
|
|
99
|
+
return date ? new Date(date).toISOString().split('.')[0] : '';
|
|
100
|
+
}
|
|
101
|
+
getWebhookSubscriptions() {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.default = UpgatesApplication;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orchesty/connector-upgates",
|
|
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
|
+
"http-status-codes": "^2.3.0",
|
|
19
|
+
"luxon": "^3.7.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/luxon": "^3.7.1"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=24"
|
|
26
|
+
}
|
|
27
|
+
}
|
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,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orchesty/connector-upgates",
|
|
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
|
+
"http-status-codes": "^2.3.0",
|
|
13
|
+
"luxon": "^3.7.2"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/luxon": "^3.7.1"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=24"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rm -rf dist && rm -rf tsconfig.prod.tsbuildinfo && tsc -d -p tsconfig.prod.json && cp package.json ./dist/package.json",
|
|
23
|
+
"test": "jest --coverage --forceExit --passWithNoTests",
|
|
24
|
+
"lint": "eslint src test --fix",
|
|
25
|
+
"lint-ci": "eslint src test"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
|
|
2
|
+
import Webhook from '@orchesty/nodejs-sdk/dist/lib/Application/Database/Webhook';
|
|
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 ResultCode from '@orchesty/nodejs-sdk/dist/lib/Utils/ResultCode';
|
|
8
|
+
import crypto from 'crypto';
|
|
9
|
+
import UpgatesApplication from '../UpgatesApplication';
|
|
10
|
+
|
|
11
|
+
export const NAME = 'upgates-create-webhooks';
|
|
12
|
+
const UPGATES_CREATE_WEBHOOK_ENDPOINT = 'api/v2/webhooks';
|
|
13
|
+
|
|
14
|
+
export default class UpgatesCreateWebhooks extends ABatchNode {
|
|
15
|
+
|
|
16
|
+
public getName(): string {
|
|
17
|
+
return NAME;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public async processAction(dto: BatchProcessDto): Promise<BatchProcessDto> {
|
|
21
|
+
const app = this.getApplication<UpgatesApplication>();
|
|
22
|
+
|
|
23
|
+
const webhookIndex = Number(dto.getBatchCursor('0'));
|
|
24
|
+
const webhooks = app.getWebhookSubscriptions();
|
|
25
|
+
|
|
26
|
+
if (webhooks.length > 0) {
|
|
27
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
28
|
+
const repo = this.getDbClient().getRepository(Webhook);
|
|
29
|
+
|
|
30
|
+
const token = this.getRandomToken();
|
|
31
|
+
const requestDto = app.getRequestDto(
|
|
32
|
+
dto,
|
|
33
|
+
appInstall,
|
|
34
|
+
HttpMethods.POST,
|
|
35
|
+
UPGATES_CREATE_WEBHOOK_ENDPOINT,
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
name: webhooks[webhookIndex].getName(),
|
|
38
|
+
event: webhooks[webhookIndex].getName(),
|
|
39
|
+
url: TopologyRunner.getWebhookUrl(
|
|
40
|
+
webhooks[webhookIndex].getTopology(),
|
|
41
|
+
webhooks[webhookIndex].getNode(),
|
|
42
|
+
token,
|
|
43
|
+
),
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
let res;
|
|
48
|
+
try {
|
|
49
|
+
res = await this.getSender().send<IResponse>(requestDto);
|
|
50
|
+
const respBody = res.getJsonBody();
|
|
51
|
+
|
|
52
|
+
await repo.insert(new Webhook()
|
|
53
|
+
.setWebhookId(respBody.webhook.id.toString())
|
|
54
|
+
.setUser(appInstall.getUser())
|
|
55
|
+
.setNode(webhooks[webhookIndex].getNode())
|
|
56
|
+
.setToken(token)
|
|
57
|
+
.setApplication(app.getName())
|
|
58
|
+
.setTopology(webhooks[webhookIndex].getTopology())
|
|
59
|
+
.setName(webhooks[webhookIndex].getName()));
|
|
60
|
+
|
|
61
|
+
if (webhooks.length - 1 > webhookIndex) {
|
|
62
|
+
dto.setBatchCursor((webhookIndex + 1).toString());
|
|
63
|
+
}
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
65
|
+
} catch (e) {
|
|
66
|
+
appInstall.setEnabled(false);
|
|
67
|
+
await this.getDbClient().getRepository(ApplicationInstall).update(appInstall);
|
|
68
|
+
|
|
69
|
+
dto.setStopProcess(ResultCode.STOP_AND_FAILED, res?.getBody() ?? 'Webhook could not be registered!');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return dto;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private getRandomToken(): string {
|
|
77
|
+
return crypto.randomBytes(64).toString('hex');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface IResponse {
|
|
83
|
+
webhook: {
|
|
84
|
+
id: number;
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
86
|
+
active_yn: boolean;
|
|
87
|
+
name: string;
|
|
88
|
+
url: string;
|
|
89
|
+
event: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
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
|
+
import UpgatesApplication, { NAME as BASE_NAME } from '../UpgatesApplication';
|
|
6
|
+
|
|
7
|
+
export const NAME = `${BASE_NAME.toLowerCase()}-get-orders`;
|
|
8
|
+
|
|
9
|
+
const LIST_PAGE_ENDPOINT = 'api/v2/orders';
|
|
10
|
+
|
|
11
|
+
export default class UpgatesGetOrders extends ABatchNode {
|
|
12
|
+
|
|
13
|
+
public getName(): string {
|
|
14
|
+
return NAME;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async processAction(dto: BatchProcessDto<IInput>): Promise<BatchProcessDto> {
|
|
18
|
+
const app = this.getApplication<UpgatesApplication>();
|
|
19
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
20
|
+
|
|
21
|
+
const { from, orderNumber, orderNumbers } = dto.getJsonData();
|
|
22
|
+
const pageNumber = dto.getBatchCursor('1');
|
|
23
|
+
|
|
24
|
+
let url: string;
|
|
25
|
+
|
|
26
|
+
if (orderNumbers) {
|
|
27
|
+
url = `${LIST_PAGE_ENDPOINT}?order_numbers=${orderNumbers}`;
|
|
28
|
+
} else if (orderNumber) {
|
|
29
|
+
url = `${LIST_PAGE_ENDPOINT}/${orderNumber}`;
|
|
30
|
+
} else {
|
|
31
|
+
url = `${LIST_PAGE_ENDPOINT}?page=${pageNumber}`;
|
|
32
|
+
|
|
33
|
+
const lastRun = from ?? app.getIsoDateFromDate(appInstall.getNonEncryptedSettings().orderLastRun);
|
|
34
|
+
if (lastRun) {
|
|
35
|
+
url = `${url}&creation_time_from=${lastRun}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const requestDto = app.getRequestDto(dto, appInstall, HttpMethods.GET, url);
|
|
40
|
+
const res = await this.getSender().send<IResponseJson>(requestDto);
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
|
|
44
|
+
number_of_pages,
|
|
45
|
+
orders,
|
|
46
|
+
} = res.getJsonBody();
|
|
47
|
+
|
|
48
|
+
if (Number(pageNumber) < number_of_pages) {
|
|
49
|
+
dto.setBatchCursor((Number(pageNumber) + 1).toString());
|
|
50
|
+
} else if (!orderNumber) {
|
|
51
|
+
appInstall.setNonEncryptedSettings({ orderLastRun: DateTime.now() });
|
|
52
|
+
const repo = this.getDbClient().getApplicationRepository();
|
|
53
|
+
await repo.update(appInstall);
|
|
54
|
+
}
|
|
55
|
+
dto.setItemList(orders);
|
|
56
|
+
|
|
57
|
+
return dto;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface IInput {
|
|
63
|
+
from?: string;
|
|
64
|
+
orderNumber?: string;
|
|
65
|
+
orderNumbers?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
69
|
+
interface IResponseJson extends IOrderJson {
|
|
70
|
+
number_of_pages: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface IOrderJson {
|
|
74
|
+
orders: IOrder[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface IOrder {
|
|
78
|
+
order_number: string;
|
|
79
|
+
external_order_number: string;
|
|
80
|
+
language_id: string;
|
|
81
|
+
prices_with_vat_yn: string;
|
|
82
|
+
status_id: string;
|
|
83
|
+
currency_id: string;
|
|
84
|
+
status: string;
|
|
85
|
+
paid_date: string;
|
|
86
|
+
tracking_code: string;
|
|
87
|
+
resolved_yn: string;
|
|
88
|
+
internal_note: string;
|
|
89
|
+
last_update_time: string;
|
|
90
|
+
creation_time: string;
|
|
91
|
+
variable_symbol: string;
|
|
92
|
+
total_weight: string;
|
|
93
|
+
order_total: string;
|
|
94
|
+
order_total_before_round: string;
|
|
95
|
+
order_total_rest: string;
|
|
96
|
+
invoice_number: string;
|
|
97
|
+
origin: string;
|
|
98
|
+
customer: {
|
|
99
|
+
email: string;
|
|
100
|
+
phone: string;
|
|
101
|
+
firstname_invoice: string;
|
|
102
|
+
surname_invoice: string;
|
|
103
|
+
street_invoice: string;
|
|
104
|
+
city_invoice: string;
|
|
105
|
+
state_invoice: string;
|
|
106
|
+
zip_invoice: string;
|
|
107
|
+
country_id_invoice: string;
|
|
108
|
+
postal_yn: string;
|
|
109
|
+
firstname_postal: string;
|
|
110
|
+
surname_postal: string;
|
|
111
|
+
street_postal: string;
|
|
112
|
+
city_postal: string;
|
|
113
|
+
state_postal: string;
|
|
114
|
+
zip_postal: string;
|
|
115
|
+
country_id_postal: string;
|
|
116
|
+
company_postal: string;
|
|
117
|
+
company_yn: string;
|
|
118
|
+
company: string;
|
|
119
|
+
ico: string;
|
|
120
|
+
dic: string;
|
|
121
|
+
vat_payer_yn: string;
|
|
122
|
+
customer_note: string;
|
|
123
|
+
agreements: {
|
|
124
|
+
name: string;
|
|
125
|
+
valid_to: string;
|
|
126
|
+
status: string;
|
|
127
|
+
}[];
|
|
128
|
+
};
|
|
129
|
+
products: {
|
|
130
|
+
product_id: string;
|
|
131
|
+
option_set_id: string;
|
|
132
|
+
code: string;
|
|
133
|
+
code_supplier: string;
|
|
134
|
+
ean: string;
|
|
135
|
+
title: string;
|
|
136
|
+
unit: string;
|
|
137
|
+
quantity: string;
|
|
138
|
+
price_per_unit: string;
|
|
139
|
+
price: string;
|
|
140
|
+
price_with_vat: string;
|
|
141
|
+
price_without_vat: string;
|
|
142
|
+
vat: string;
|
|
143
|
+
buy_price: string;
|
|
144
|
+
weight: string;
|
|
145
|
+
invoice_info: string;
|
|
146
|
+
parameters: {
|
|
147
|
+
name: string;
|
|
148
|
+
value: string;
|
|
149
|
+
}[];
|
|
150
|
+
configurations: {
|
|
151
|
+
name: string;
|
|
152
|
+
values: {
|
|
153
|
+
value: string;
|
|
154
|
+
operation: string;
|
|
155
|
+
price: string;
|
|
156
|
+
}[];
|
|
157
|
+
}[];
|
|
158
|
+
}[];
|
|
159
|
+
discount_voucher: {
|
|
160
|
+
code: string;
|
|
161
|
+
type: string;
|
|
162
|
+
amount: string;
|
|
163
|
+
discounts: {
|
|
164
|
+
vat: string;
|
|
165
|
+
price: string;
|
|
166
|
+
}[];
|
|
167
|
+
};
|
|
168
|
+
quantity_discount: {
|
|
169
|
+
type: string;
|
|
170
|
+
amount: string;
|
|
171
|
+
discounts: {
|
|
172
|
+
vat: string;
|
|
173
|
+
price: string;
|
|
174
|
+
}[];
|
|
175
|
+
};
|
|
176
|
+
loyalty_points: {
|
|
177
|
+
one_point_for: string;
|
|
178
|
+
amount: string;
|
|
179
|
+
discounts: {
|
|
180
|
+
vat: string;
|
|
181
|
+
price: string;
|
|
182
|
+
}[];
|
|
183
|
+
};
|
|
184
|
+
shipment: {
|
|
185
|
+
id: number;
|
|
186
|
+
code: string;
|
|
187
|
+
name: string;
|
|
188
|
+
price: string;
|
|
189
|
+
vat: string;
|
|
190
|
+
affiliate_id: string;
|
|
191
|
+
affiliate_name: string;
|
|
192
|
+
};
|
|
193
|
+
payment: {
|
|
194
|
+
id: number;
|
|
195
|
+
code: string;
|
|
196
|
+
name: string;
|
|
197
|
+
price: string;
|
|
198
|
+
vat: string;
|
|
199
|
+
eet_yn: string;
|
|
200
|
+
};
|
|
201
|
+
metas: {
|
|
202
|
+
key: string;
|
|
203
|
+
type: string;
|
|
204
|
+
value: string;
|
|
205
|
+
values: {
|
|
206
|
+
cs: {
|
|
207
|
+
language: string;
|
|
208
|
+
value: string;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
}[];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|