@orchesty/connector-woocommerce 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 +12 -0
- package/LICENSE +190 -0
- package/coverage/clover.xml +404 -0
- package/coverage/coverage-final.json +21 -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/WooCommerceGetOrders.ts.html +640 -0
- package/coverage/lcov-report/src/Batch/WooCommerceGetProducts.ts.html +532 -0
- package/coverage/lcov-report/src/Batch/WooCommerceGetVariants.ts.html +433 -0
- package/coverage/lcov-report/src/Batch/index.html +146 -0
- package/coverage/lcov-report/src/Connector/WooCommerceAddNote.ts.html +220 -0
- package/coverage/lcov-report/src/Connector/WooCommerceCreateProduct.ts.html +178 -0
- package/coverage/lcov-report/src/Connector/WooCommerceCreateProductCategory.ts.html +307 -0
- package/coverage/lcov-report/src/Connector/WooCommerceGetOrderNotes.ts.html +274 -0
- package/coverage/lcov-report/src/Connector/WooCommerceGetOrderStatuses.ts.html +175 -0
- package/coverage/lcov-report/src/Connector/WooCommerceGetPaymentGateways.ts.html +295 -0
- package/coverage/lcov-report/src/Connector/WooCommerceGetProduct.ts.html +181 -0
- package/coverage/lcov-report/src/Connector/WooCommerceGetProductVariant.ts.html +496 -0
- package/coverage/lcov-report/src/Connector/WooCommerceGetProductsBySku.ts.html +226 -0
- package/coverage/lcov-report/src/Connector/WooCommerceGetSettingsGeneral.ts.html +238 -0
- package/coverage/lcov-report/src/Connector/WooCommerceGetShippingMethods.ts.html +478 -0
- package/coverage/lcov-report/src/Connector/WooCommerceUpdateOrder.ts.html +193 -0
- package/coverage/lcov-report/src/Connector/WooCommerceUpdateProduct.ts.html +199 -0
- package/coverage/lcov-report/src/Connector/WooCommerceUpdateProductQuantity.ts.html +220 -0
- package/coverage/lcov-report/src/Connector/WooCommerceUpdateProductVariant.ts.html +199 -0
- package/coverage/lcov-report/src/Connector/index.html +326 -0
- package/coverage/lcov-report/src/WooCommerceApplication.ts.html +364 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/test/dataProvider.ts.html +427 -0
- package/coverage/lcov-report/test/index.html +116 -0
- package/coverage/lcov.info +661 -0
- package/dist/Batch/WooCommerceGetOrders.d.ts +133 -0
- package/dist/Batch/WooCommerceGetOrders.js +44 -0
- package/dist/Batch/WooCommerceGetProducts.d.ts +108 -0
- package/dist/Batch/WooCommerceGetProducts.js +36 -0
- package/dist/Batch/WooCommerceGetVariants.d.ts +81 -0
- package/dist/Batch/WooCommerceGetVariants.js +30 -0
- package/dist/Connector/WooCommerceAddNote.d.ts +18 -0
- package/dist/Connector/WooCommerceAddNote.js +23 -0
- package/dist/Connector/WooCommerceCreateProduct.d.ts +10 -0
- package/dist/Connector/WooCommerceCreateProduct.js +20 -0
- package/dist/Connector/WooCommerceCreateProductCategory.d.ts +41 -0
- package/dist/Connector/WooCommerceCreateProductCategory.js +28 -0
- package/dist/Connector/WooCommerceGetOrderNotes.d.ts +33 -0
- package/dist/Connector/WooCommerceGetOrderNotes.js +24 -0
- package/dist/Connector/WooCommerceGetOrderStatuses.d.ts +11 -0
- package/dist/Connector/WooCommerceGetOrderStatuses.js +20 -0
- package/dist/Connector/WooCommerceGetPaymentGateways.d.ts +48 -0
- package/dist/Connector/WooCommerceGetPaymentGateways.js +20 -0
- package/dist/Connector/WooCommerceGetProduct.d.ts +11 -0
- package/dist/Connector/WooCommerceGetProduct.js +21 -0
- package/dist/Connector/WooCommerceGetProductVariant.d.ts +12 -0
- package/dist/Connector/WooCommerceGetProductVariant.js +46 -0
- package/dist/Connector/WooCommerceGetProductsBySku.d.ts +12 -0
- package/dist/Connector/WooCommerceGetProductsBySku.js +34 -0
- package/dist/Connector/WooCommerceGetSettingsGeneral.d.ts +29 -0
- package/dist/Connector/WooCommerceGetSettingsGeneral.js +21 -0
- package/dist/Connector/WooCommerceGetShippingMethods.d.ts +82 -0
- package/dist/Connector/WooCommerceGetShippingMethods.js +36 -0
- package/dist/Connector/WooCommerceRegisterWebhook.d.ts +7 -0
- package/dist/Connector/WooCommerceRegisterWebhook.js +65 -0
- package/dist/Connector/WooCommerceUnsubscribeWebhooks.d.ts +6 -0
- package/dist/Connector/WooCommerceUnsubscribeWebhooks.js +59 -0
- package/dist/Connector/WooCommerceUpdateOrder.d.ts +12 -0
- package/dist/Connector/WooCommerceUpdateOrder.js +23 -0
- package/dist/Connector/WooCommerceUpdateProduct.d.ts +12 -0
- package/dist/Connector/WooCommerceUpdateProduct.js +25 -0
- package/dist/Connector/WooCommerceUpdateProductQuantity.d.ts +16 -0
- package/dist/Connector/WooCommerceUpdateProductQuantity.js +22 -0
- package/dist/Connector/WooCommerceUpdateProductVariant.d.ts +13 -0
- package/dist/Connector/WooCommerceUpdateProductVariant.js +21 -0
- package/dist/WooCommerceApplication.d.ts +21 -0
- package/dist/WooCommerceApplication.js +101 -0
- package/dist/package.json +28 -0
- package/jest.config.js +13 -0
- package/package.json +28 -0
- package/src/Batch/WooCommerceGetOrders.ts +185 -0
- package/src/Batch/WooCommerceGetProducts.ts +149 -0
- package/src/Batch/WooCommerceGetVariants.ts +116 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/ids-input.json +8 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/ids-mock.json +319 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/ids-output.json +16 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/input.json +6 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/lastRun-input.json +6 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/lastRun-mock.json +319 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/lastRun-output.json +15 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/mock.json +319 -0
- package/src/Batch/__tests__/Data/WooCommerceGetOrders/output.json +15 -0
- package/src/Batch/__tests__/Data/WooCommerceGetProducts/input.json +7 -0
- package/src/Batch/__tests__/Data/WooCommerceGetProducts/mock.json +170 -0
- package/src/Batch/__tests__/Data/WooCommerceGetProducts/output.json +11 -0
- package/src/Batch/__tests__/Data/WooCommerceGetProducts/withAfter-input.json +7 -0
- package/src/Batch/__tests__/Data/WooCommerceGetProducts/withAfter-mock.json +170 -0
- package/src/Batch/__tests__/Data/WooCommerceGetProducts/withAfter-output.json +11 -0
- package/src/Batch/__tests__/Data/WooCommerceGetVariants/input.json +169 -0
- package/src/Batch/__tests__/Data/WooCommerceGetVariants/mock.json +160 -0
- package/src/Batch/__tests__/Data/WooCommerceGetVariants/output.json +11 -0
- package/src/Batch/__tests__/WooCommerceGetOrders.ts +42 -0
- package/src/Batch/__tests__/WooCommerceGetProducts.ts +37 -0
- package/src/Batch/__tests__/WooCommerceGetVariants.ts +32 -0
- package/src/Connector/WooCommerceAddNote.ts +45 -0
- package/src/Connector/WooCommerceCreateProduct.ts +31 -0
- package/src/Connector/WooCommerceCreateProductCategory.ts +74 -0
- package/src/Connector/WooCommerceGetOrderNotes.ts +63 -0
- package/src/Connector/WooCommerceGetOrderStatuses.ts +30 -0
- package/src/Connector/WooCommerceGetPaymentGateways.ts +70 -0
- package/src/Connector/WooCommerceGetProduct.ts +32 -0
- package/src/Connector/WooCommerceGetProductVariant.ts +137 -0
- package/src/Connector/WooCommerceGetProductsBySku.ts +47 -0
- package/src/Connector/WooCommerceGetSettingsGeneral.ts +51 -0
- package/src/Connector/WooCommerceGetShippingMethods.ts +131 -0
- package/src/Connector/WooCommerceRegisterWebhook.ts +106 -0
- package/src/Connector/WooCommerceUnsubscribeWebhooks.ts +91 -0
- package/src/Connector/WooCommerceUpdateOrder.ts +36 -0
- package/src/Connector/WooCommerceUpdateProduct.ts +38 -0
- package/src/Connector/WooCommerceUpdateProductQuantity.ts +45 -0
- package/src/Connector/WooCommerceUpdateProductVariant.ts +38 -0
- package/src/Connector/__tests__/Data/WooCommerceAddNote/input.json +11 -0
- package/src/Connector/__tests__/Data/WooCommerceAddNote/mock.json +22 -0
- package/src/Connector/__tests__/Data/WooCommerceAddNote/output.json +23 -0
- package/src/Connector/__tests__/Data/WooCommerceCreateProduct/input.json +28 -0
- package/src/Connector/__tests__/Data/WooCommerceCreateProduct/mock.json +125 -0
- package/src/Connector/__tests__/Data/WooCommerceCreateProduct/output.json +126 -0
- package/src/Connector/__tests__/Data/WooCommerceCreateProductCategory/input.json +11 -0
- package/src/Connector/__tests__/Data/WooCommerceCreateProductCategory/mock.json +36 -0
- package/src/Connector/__tests__/Data/WooCommerceCreateProductCategory/output.json +37 -0
- package/src/Connector/__tests__/Data/WooCommerceGetOrderNotes/input.json +8 -0
- package/src/Connector/__tests__/Data/WooCommerceGetOrderNotes/mock.json +81 -0
- package/src/Connector/__tests__/Data/WooCommerceGetOrderNotes/output.json +82 -0
- package/src/Connector/__tests__/Data/WooCommerceGetOrderStatuses/input.json +6 -0
- package/src/Connector/__tests__/Data/WooCommerceGetOrderStatuses/mock.json +41 -0
- package/src/Connector/__tests__/Data/WooCommerceGetOrderStatuses/output.json +42 -0
- package/src/Connector/__tests__/Data/WooCommerceGetPaymentGateways/input.json +6 -0
- package/src/Connector/__tests__/Data/WooCommerceGetPaymentGateways/mock.json +350 -0
- package/src/Connector/__tests__/Data/WooCommerceGetPaymentGateways/output.json +351 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProduct/input.json +8 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProduct/mock.json +125 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProduct/output.json +126 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductVariant/input.json +37 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductVariant/mock.json +81 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductVariant/mock1.json +81 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductVariant/nok-input.json +22 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductVariant/nok-mock.json +81 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductVariant/nok-output.json +24 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductVariant/output.json +37 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductsBySku/input.json +8 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductsBySku/mock.json +170 -0
- package/src/Connector/__tests__/Data/WooCommerceGetProductsBySku/output.json +169 -0
- package/src/Connector/__tests__/Data/WooCommerceGetSettingsGeneral/input.json +6 -0
- package/src/Connector/__tests__/Data/WooCommerceGetSettingsGeneral/mock.json +3459 -0
- package/src/Connector/__tests__/Data/WooCommerceGetSettingsGeneral/output.json +3460 -0
- package/src/Connector/__tests__/Data/WooCommerceGetSettingsGeneral/with-id-input.json +8 -0
- package/src/Connector/__tests__/Data/WooCommerceGetSettingsGeneral/with-id-mock.json +30 -0
- package/src/Connector/__tests__/Data/WooCommerceGetSettingsGeneral/with-id-output.json +31 -0
- package/src/Connector/__tests__/Data/WooCommerceGetShippingMethods/input.json +6 -0
- package/src/Connector/__tests__/Data/WooCommerceGetShippingMethods/mock.json +50 -0
- package/src/Connector/__tests__/Data/WooCommerceGetShippingMethods/mock1.json +187 -0
- package/src/Connector/__tests__/Data/WooCommerceGetShippingMethods/mock2.json +187 -0
- package/src/Connector/__tests__/Data/WooCommerceGetShippingMethods/output.json +373 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateOrder/input.json +9 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateOrder/mock.json +169 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateOrder/output.json +170 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProduct/input.json +9 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProduct/mock.json +125 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProduct/output.json +126 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProductQuantity/input.json +20 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProductQuantity/mock.json +162 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProductQuantity/output.json +6 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProductVariant/input.json +10 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProductVariant/mock.json +125 -0
- package/src/Connector/__tests__/Data/WooCommerceUpdateProductVariant/output.json +126 -0
- package/src/Connector/__tests__/WooCommerceAddNote.ts +18 -0
- package/src/Connector/__tests__/WooCommerceCreateProduct.ts +18 -0
- package/src/Connector/__tests__/WooCommerceCreateProductCategory.ts +18 -0
- package/src/Connector/__tests__/WooCommerceGetOrderNotes.ts +18 -0
- package/src/Connector/__tests__/WooCommerceGetOrderStatuses.ts +18 -0
- package/src/Connector/__tests__/WooCommerceGetPaymentGateways.ts +18 -0
- package/src/Connector/__tests__/WooCommerceGetProduct.ts +18 -0
- package/src/Connector/__tests__/WooCommerceGetProductVariant.ts +25 -0
- package/src/Connector/__tests__/WooCommerceGetProductsBySku.ts +18 -0
- package/src/Connector/__tests__/WooCommerceGetSettingsGeneral.ts +25 -0
- package/src/Connector/__tests__/WooCommerceGetShippingMethods.ts +18 -0
- package/src/Connector/__tests__/WooCommerceUpdateOrder.ts +18 -0
- package/src/Connector/__tests__/WooCommerceUpdateProduct.ts +18 -0
- package/src/Connector/__tests__/WooCommerceUpdateProductQuantity.ts +18 -0
- package/src/Connector/__tests__/WooCommerceUpdateProductVariant.ts +18 -0
- package/src/WooCommerceApplication.ts +93 -0
- package/test/dataProvider.ts +114 -0
- package/tsconfig.json +8 -0
- package/tsconfig.prod.json +13 -0
- package/tsconfig.prod.tsbuildinfo +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import AConnector from '@orchesty/nodejs-sdk/dist/lib/Connector/AConnector';
|
|
2
|
+
import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
|
|
3
|
+
import { IVariant } from '../Batch/WooCommerceGetVariants';
|
|
4
|
+
export declare const NAME = "woo-commerce-update-product-variant";
|
|
5
|
+
export default class WooCommerceUpdateProductVariant extends AConnector {
|
|
6
|
+
getName(): string;
|
|
7
|
+
processAction(dto: ProcessDto<IInput>): Promise<ProcessDto<IOutput>>;
|
|
8
|
+
}
|
|
9
|
+
export interface IInput extends Partial<IVariant> {
|
|
10
|
+
id: number;
|
|
11
|
+
productId: number;
|
|
12
|
+
}
|
|
13
|
+
export type IOutput = IVariant;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
exports.NAME = 'woo-commerce-update-product-variant';
|
|
10
|
+
class WooCommerceUpdateProductVariant extends AConnector_1.default {
|
|
11
|
+
getName() {
|
|
12
|
+
return exports.NAME;
|
|
13
|
+
}
|
|
14
|
+
async processAction(dto) {
|
|
15
|
+
const { productId, id, ...rest } = dto.getJsonData();
|
|
16
|
+
const req = await this.getApplication().getRequestDto(dto, await this.getApplicationInstallFromProcess(dto), HttpMethods_1.HttpMethods.PUT, `wp-json/wc/v3/products/${productId}/variations/${id}`, JSON.stringify(rest));
|
|
17
|
+
const resp = await this.getSender().send(req, [200]);
|
|
18
|
+
return dto.setNewJsonData(resp.getJsonBody());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = WooCommerceUpdateProductVariant;
|
|
@@ -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 WOOCOMMERCE_URL = "woocommerceUrl";
|
|
9
|
+
export declare const NAME = "woocommerce";
|
|
10
|
+
export default class WooCommerceApplication 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?: unknown): RequestDto;
|
|
16
|
+
getIsoDateFromDate(date?: string): string;
|
|
17
|
+
getDecoratedUrl(app: ApplicationInstall): string;
|
|
18
|
+
getFormStack(): FormStack;
|
|
19
|
+
isAuthorized(applicationInstall: ApplicationInstall): boolean;
|
|
20
|
+
getWebhookSubscriptions(): WebhookSubscription[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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.NAME = exports.WOOCOMMERCE_URL = 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.WOOCOMMERCE_URL = 'woocommerceUrl';
|
|
51
|
+
exports.NAME = 'woocommerce';
|
|
52
|
+
class WooCommerceApplication extends ABasicApplication_1.ABasicApplication {
|
|
53
|
+
getDescription() {
|
|
54
|
+
return 'Open-source e-commerce plugin for WordPress, designed for small to large-sized online merchants';
|
|
55
|
+
}
|
|
56
|
+
getName() {
|
|
57
|
+
return exports.NAME;
|
|
58
|
+
}
|
|
59
|
+
getPublicName() {
|
|
60
|
+
return 'WooCommerce';
|
|
61
|
+
}
|
|
62
|
+
getLogo() {
|
|
63
|
+
return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIKCSBpZD0iVnJzdHZhXzEiIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgoJIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTAwIDEwMCIKCSBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAxMDAgMTAwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+CjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+Cgkuc3Qwe2ZpbGw6IzdGNTRCMzt9Cgkuc3Qxe2ZpbGw6I0ZGRkZGRjt9Cjwvc3R5bGU+CjxnPgoJPHBhdGggY2xhc3M9InN0MCIgZD0iTTkuMywyMC4zaDgxLjNjNS4xLDAsOS4zLDQuMiw5LjMsOS4zdjMxYzAsNS4xLTQuMiw5LjMtOS4zLDkuM0g2MS40bDQsOS44bC0xNy42LTkuOEg5LjQKCQljLTUuMSwwLTkuMy00LjItOS4zLTkuM3YtMzFDMCwyNC41LDQuMiwyMC4zLDkuMywyMC4zTDkuMywyMC4zeiIvPgoJPHBhdGggY2xhc3M9InN0MSIgZD0iTTUuNywyOC44YzAuNi0wLjgsMS40LTEuMiwyLjYtMS4zYzIuMS0wLjIsMy4yLDAuOCwzLjUsMi45YzEuMyw4LjUsMi42LDE1LjcsNC4xLDIxLjZsOC45LTE2LjkKCQljMC44LTEuNSwxLjgtMi40LDMtMi40YzEuOC0wLjEsMi45LDEsMy4zLDMuNGMxLDUuNCwyLjMsMTAsMy45LDEzLjljMS4xLTEwLjMsMi44LTE3LjcsNS40LTIyLjNjMC42LTEuMSwxLjUtMS43LDIuNy0xLjgKCQljMC45LTAuMSwxLjgsMC4yLDIuNiwwLjhjMC44LDAuNiwxLjIsMS40LDEuMywyLjNjMCwwLjctMC4xLDEuMy0wLjQsMS45Yy0xLjYsMi45LTIuOSw3LjgtMy45LDE0LjdjLTEsNi42LTEuNCwxMS44LTEuMSwxNS41CgkJYzAuMSwxLTAuMSwxLjktMC41LDIuN2MtMC41LDAuOS0xLjIsMS40LTIuMiwxLjVjLTEuMSwwLjEtMi4yLTAuNC0zLjItMS41Yy0zLjgtMy45LTYuOC05LjYtOS0xNy4zQzI0LDUxLjUsMjIsNTUuNCwyMC43LDU4CgkJYy0yLjQsNC42LTQuNCw2LjktNi4xLDcuMWMtMS4xLDAuMS0yLTAuOS0yLjgtMi44QzkuNyw1Nyw3LjUsNDYuNyw1LjEsMzEuNUM0LjksMzAuNCw1LjIsMjkuNSw1LjcsMjguOEw1LjcsMjguOHogTTkzLDM1LjEKCQljLTEuNS0yLjYtMy42LTQuMS02LjUtNC43Yy0wLjgtMC4yLTEuNS0wLjItMi4yLTAuMmMtMy45LDAtNy4xLDItOS41LDYuMWMtMi4xLDMuNC0zLjIsNy4zLTMuMiwxMS40YzAsMy4xLDAuNiw1LjgsMS45LDgKCQljMS41LDIuNiwzLjYsNC4xLDYuNSw0LjdjMC44LDAuMiwxLjUsMC4yLDIuMiwwLjJjMy45LDAsNy4xLTIsOS41LTYuMWMyLjEtMy41LDMuMi03LjMsMy4yLTExLjVDOTQuOSw0MCw5NC4zLDM3LjMsOTMsMzUuMXoKCQkgTTg3LjgsNDYuNGMtMC42LDIuNy0xLjYsNC43LTMuMSw2Yy0xLjIsMS4xLTIuMywxLjUtMy4zLDEuM2MtMS0wLjItMS44LTEuMS0yLjQtMi42Yy0wLjUtMS4zLTAuNy0yLjUtMC43LTMuN2MwLTEsMC4xLTIsMC4zLTMKCQljMC40LTEuNywxLjEtMy4zLDIuMi00LjhjMS4zLTIsMi44LTIuOCw0LjItMi41YzEsMC4yLDEuOCwxLjEsMi40LDIuNmMwLjUsMS4zLDAuNywyLjUsMC43LDMuN0M4OC4xLDQ0LjQsODgsNDUuNCw4Ny44LDQ2LjQKCQlMODcuOCw0Ni40eiBNNjcuNSwzNS4xYy0xLjUtMi42LTMuNy00LjEtNi41LTQuN2MtMC44LTAuMi0xLjUtMC4yLTIuMi0wLjJjLTMuOSwwLTcuMSwyLTkuNSw2LjFjLTIuMSwzLjQtMy4yLDcuMy0zLjIsMTEuNAoJCWMwLDMuMSwwLjYsNS44LDEuOSw4YzEuNSwyLjYsMy42LDQuMSw2LjUsNC43YzAuOCwwLjIsMS41LDAuMiwyLjIsMC4yYzMuOSwwLDcuMS0yLDkuNS02LjFjMi4xLTMuNSwzLjItNy4zLDMuMi0xMS41CgkJQzY5LjUsNDAsNjguOCwzNy4zLDY3LjUsMzUuMXogTTYyLjQsNDYuNGMtMC42LDIuNy0xLjYsNC43LTMuMSw2Yy0xLjIsMS4xLTIuMywxLjUtMy4zLDEuM2MtMS0wLjItMS44LTEuMS0yLjQtMi42CgkJYy0wLjUtMS4zLTAuNy0yLjUtMC43LTMuN2MwLTEsMC4xLTIsMC4zLTNjMC40LTEuNywxLjEtMy4zLDIuMi00LjhjMS4zLTIsMi44LTIuOCw0LjItMi41YzEsMC4yLDEuOCwxLjEsMi40LDIuNgoJCWMwLjUsMS4zLDAuNywyLjUsMC43LDMuN0M2Mi43LDQ0LjQsNjIuNiw0NS40LDYyLjQsNDYuNEw2Mi40LDQ2LjR6Ii8+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]}:${settings[CoreFormsEnum_1.default.AUTHORIZATION_FORM][ABasicApplication_1.PASSWORD]}`);
|
|
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
|
+
getIsoDateFromDate(date) {
|
|
80
|
+
return date ? new Date(date).toISOString() : '';
|
|
81
|
+
}
|
|
82
|
+
getDecoratedUrl(app) {
|
|
83
|
+
return app
|
|
84
|
+
.getSettings()?.[CoreFormsEnum_1.default.AUTHORIZATION_FORM]?.[exports.WOOCOMMERCE_URL] ?? '';
|
|
85
|
+
}
|
|
86
|
+
getFormStack() {
|
|
87
|
+
const form = 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, ABasicApplication_1.USER, 'User', undefined, true))
|
|
89
|
+
.addField(new Field_1.default(FieldType_1.default.TEXT, ABasicApplication_1.PASSWORD, 'Password', undefined, true))
|
|
90
|
+
.addField(new Field_1.default(FieldType_1.default.URL, exports.WOOCOMMERCE_URL, 'Url', undefined, true));
|
|
91
|
+
return new FormStack_1.default().addForm(form);
|
|
92
|
+
}
|
|
93
|
+
isAuthorized(applicationInstall) {
|
|
94
|
+
const authorizationForm = applicationInstall.getSettings()[CoreFormsEnum_1.default.AUTHORIZATION_FORM];
|
|
95
|
+
return authorizationForm?.[ABasicApplication_1.USER] && authorizationForm?.[ABasicApplication_1.PASSWORD] && authorizationForm?.[exports.WOOCOMMERCE_URL];
|
|
96
|
+
}
|
|
97
|
+
getWebhookSubscriptions() {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.default = WooCommerceApplication;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orchesty/connector-woocommerce",
|
|
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/connector-authentica": "workspace:*",
|
|
18
|
+
"@orchesty/nodejs-sdk": "^4.3.6",
|
|
19
|
+
"luxon": "^3.7.2",
|
|
20
|
+
"http-status-codes": "^2.3.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/luxon": "^3.7.1"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=24"
|
|
27
|
+
}
|
|
28
|
+
}
|
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,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orchesty/connector-woocommerce",
|
|
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
|
+
"luxon": "^3.7.2",
|
|
13
|
+
"http-status-codes": "^2.3.0",
|
|
14
|
+
"@orchesty/connector-authentica": "1.0.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/luxon": "^3.7.1"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=24"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "rm -rf dist && rm -rf tsconfig.prod.tsbuildinfo && tsc -d -p tsconfig.prod.json && cp package.json ./dist/package.json",
|
|
24
|
+
"test": "jest --coverage --forceExit --passWithNoTests",
|
|
25
|
+
"lint": "eslint src test --fix",
|
|
26
|
+
"lint-ci": "eslint src test"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
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 WooCommerceApplication, { NAME as BASE_NAME } from '../WooCommerceApplication';
|
|
6
|
+
|
|
7
|
+
export const NAME = `${BASE_NAME.toLowerCase()}-get-orders`;
|
|
8
|
+
|
|
9
|
+
const WOOCOMMERCE_GET_ORDERS_ENDPOINT = 'wp-json/wc/v3/orders?per_page=100&page=';
|
|
10
|
+
|
|
11
|
+
export default class WooCommerceGetOrders extends ABatchNode {
|
|
12
|
+
|
|
13
|
+
public getName(): string {
|
|
14
|
+
return NAME;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async processAction(dto: BatchProcessDto<IInput>): Promise<BatchProcessDto> {
|
|
18
|
+
const { ids } = dto.getJsonData();
|
|
19
|
+
const pageNumber = dto.getBatchCursor('1');
|
|
20
|
+
const app = this.getApplication<WooCommerceApplication>();
|
|
21
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
22
|
+
|
|
23
|
+
let after;
|
|
24
|
+
if (!ids) {
|
|
25
|
+
after = app.getIsoDateFromDate(appInstall.getNonEncryptedSettings().orderLastRun);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const requestDto = app.getRequestDto(
|
|
29
|
+
dto,
|
|
30
|
+
appInstall,
|
|
31
|
+
HttpMethods.GET,
|
|
32
|
+
`${WOOCOMMERCE_GET_ORDERS_ENDPOINT}${pageNumber}${after ? `&after=${after}` : ''}${ids ? `&include=${ids}` : ''}`,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const res = await this.getSender().send<IResponseJson[]>(requestDto, [200, 404]);
|
|
36
|
+
const totalPages = res.getHeaders()['x-wp-totalpages'];
|
|
37
|
+
if (Number(totalPages) > Number(pageNumber)) {
|
|
38
|
+
dto.setBatchCursor((Number(pageNumber) + 1).toString());
|
|
39
|
+
} else {
|
|
40
|
+
appInstall.setNonEncryptedSettings({ orderLastRun: DateTime.now() });
|
|
41
|
+
const repo = this.getDbClient().getApplicationRepository();
|
|
42
|
+
await repo.update(appInstall);
|
|
43
|
+
}
|
|
44
|
+
this.setItemsListToDto(dto, res.getJsonBody());
|
|
45
|
+
|
|
46
|
+
return dto;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected setItemsListToDto(dto: BatchProcessDto, responseBody: IResponseJson[]): void {
|
|
50
|
+
dto.setItemList(responseBody);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface IInput {
|
|
56
|
+
ids?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
60
|
+
interface IOrdersJson {
|
|
61
|
+
id: number;
|
|
62
|
+
parent_id: number;
|
|
63
|
+
number: string;
|
|
64
|
+
order_key: string;
|
|
65
|
+
created_via: string;
|
|
66
|
+
version: string;
|
|
67
|
+
status: string;
|
|
68
|
+
currency: string;
|
|
69
|
+
date_created: string;
|
|
70
|
+
date_created_gmt: string;
|
|
71
|
+
date_modified: string;
|
|
72
|
+
date_modified_gmt: string;
|
|
73
|
+
discount_total: string;
|
|
74
|
+
discount_tax: string;
|
|
75
|
+
shipping_total: string;
|
|
76
|
+
shipping_tax: string;
|
|
77
|
+
cart_tax: string;
|
|
78
|
+
total: string;
|
|
79
|
+
total_tax: string;
|
|
80
|
+
prices_include_tax: boolean;
|
|
81
|
+
customer_id: number;
|
|
82
|
+
customer_ip_address: string;
|
|
83
|
+
customer_user_agent: string;
|
|
84
|
+
customer_note: string;
|
|
85
|
+
billing: {
|
|
86
|
+
first_name: string;
|
|
87
|
+
last_name: string;
|
|
88
|
+
company: string;
|
|
89
|
+
address_1: string;
|
|
90
|
+
address_2: string;
|
|
91
|
+
city: string;
|
|
92
|
+
state: string;
|
|
93
|
+
postcode: string;
|
|
94
|
+
country: string;
|
|
95
|
+
email: string;
|
|
96
|
+
phone: string;
|
|
97
|
+
};
|
|
98
|
+
shipping: {
|
|
99
|
+
first_name: string;
|
|
100
|
+
last_name: string;
|
|
101
|
+
company: string;
|
|
102
|
+
address_1: string;
|
|
103
|
+
address_2: string;
|
|
104
|
+
city: string;
|
|
105
|
+
state: string;
|
|
106
|
+
postcode: string;
|
|
107
|
+
country: string;
|
|
108
|
+
};
|
|
109
|
+
payment_method: string;
|
|
110
|
+
payment_method_title: string;
|
|
111
|
+
transaction_id: string;
|
|
112
|
+
date_paid: string;
|
|
113
|
+
date_paid_gmt: string;
|
|
114
|
+
date_completed: string;
|
|
115
|
+
date_completed_gmt: string;
|
|
116
|
+
cart_hash: string;
|
|
117
|
+
meta_data: {
|
|
118
|
+
id: number;
|
|
119
|
+
key: string;
|
|
120
|
+
value: string;
|
|
121
|
+
}[];
|
|
122
|
+
line_items: ILineItems[];
|
|
123
|
+
tax_lines: {
|
|
124
|
+
id: number;
|
|
125
|
+
rate_code: string;
|
|
126
|
+
rate_id: number;
|
|
127
|
+
label: string;
|
|
128
|
+
compound: boolean;
|
|
129
|
+
tax_total: string;
|
|
130
|
+
shipping_tax_total: string;
|
|
131
|
+
meta_data: [];
|
|
132
|
+
}[];
|
|
133
|
+
shipping_lines: {
|
|
134
|
+
id: number;
|
|
135
|
+
method_title: string;
|
|
136
|
+
method_id: string;
|
|
137
|
+
instance_id: string;
|
|
138
|
+
total: string;
|
|
139
|
+
total_tax: string;
|
|
140
|
+
taxes: [];
|
|
141
|
+
meta_data: [];
|
|
142
|
+
}[];
|
|
143
|
+
fee_lines: [];
|
|
144
|
+
coupon_lines: [];
|
|
145
|
+
refunds: [];
|
|
146
|
+
_links: {
|
|
147
|
+
self: {
|
|
148
|
+
href: string;
|
|
149
|
+
}[];
|
|
150
|
+
collection: {
|
|
151
|
+
href: string;
|
|
152
|
+
}[];
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface ILineItems {
|
|
157
|
+
id: number;
|
|
158
|
+
name: string;
|
|
159
|
+
product_id: number;
|
|
160
|
+
variation_id: number;
|
|
161
|
+
quantity: number;
|
|
162
|
+
tax_class: string;
|
|
163
|
+
subtotal: string;
|
|
164
|
+
subtotal_tax: string;
|
|
165
|
+
total: string;
|
|
166
|
+
total_tax: string;
|
|
167
|
+
taxes: {
|
|
168
|
+
id: number;
|
|
169
|
+
total: string;
|
|
170
|
+
subtotal: string;
|
|
171
|
+
}[];
|
|
172
|
+
meta_data: IMetaData[];
|
|
173
|
+
sku: string;
|
|
174
|
+
price: number;
|
|
175
|
+
authentica_price: number;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type IResponseJson = IOrdersJson;
|
|
179
|
+
|
|
180
|
+
export interface IMetaData {
|
|
181
|
+
display_key: string;
|
|
182
|
+
display_value: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
@@ -0,0 +1,149 @@
|
|
|
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 WooCommerceApplication, { NAME as BASE_NAME } from '../WooCommerceApplication';
|
|
6
|
+
|
|
7
|
+
export const NAME = `${BASE_NAME.toLowerCase()}-get-products`;
|
|
8
|
+
|
|
9
|
+
export default class WooCommerceGetProducts extends ABatchNode {
|
|
10
|
+
|
|
11
|
+
public getName(): string {
|
|
12
|
+
return NAME;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async processAction(dto: BatchProcessDto): Promise<BatchProcessDto> {
|
|
16
|
+
const pageNumber = dto.getBatchCursor('1');
|
|
17
|
+
const app = this.getApplication<WooCommerceApplication>();
|
|
18
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
19
|
+
const after = app.getIsoDateFromDate(appInstall.getNonEncryptedSettings().productLastRun);
|
|
20
|
+
|
|
21
|
+
const requestDto = app.getRequestDto(
|
|
22
|
+
dto,
|
|
23
|
+
appInstall,
|
|
24
|
+
HttpMethods.GET,
|
|
25
|
+
`wp-json/wc/v3/products?per_page=100&page=${pageNumber}${after ? `&after=${after}` : ''}`,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const res = await this.getSender().send<IOutput[]>(requestDto, [200, 404]);
|
|
29
|
+
const totalPages = res.getHeaders()['x-wp-totalpages'];
|
|
30
|
+
if (Number(totalPages) > Number(pageNumber)) {
|
|
31
|
+
dto.setBatchCursor((Number(pageNumber) + 1).toString());
|
|
32
|
+
} else {
|
|
33
|
+
appInstall.setNonEncryptedSettings({ productLastRun: DateTime.now() });
|
|
34
|
+
const repo = this.getDbClient().getApplicationRepository();
|
|
35
|
+
await repo.update(appInstall);
|
|
36
|
+
}
|
|
37
|
+
dto.setItemList(res.getJsonBody());
|
|
38
|
+
|
|
39
|
+
return dto;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
45
|
+
export interface IImage {
|
|
46
|
+
src: string;
|
|
47
|
+
id?: number;
|
|
48
|
+
date_created?: Date;
|
|
49
|
+
date_created_gmt?: Date;
|
|
50
|
+
date_modified?: Date;
|
|
51
|
+
date_modified_gmt?: Date;
|
|
52
|
+
name?: string;
|
|
53
|
+
alt?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface IAttribute {
|
|
57
|
+
id?: number;
|
|
58
|
+
name?: string;
|
|
59
|
+
position?: number;
|
|
60
|
+
visible?: boolean;
|
|
61
|
+
variation?: boolean;
|
|
62
|
+
options?: string[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface IOutput {
|
|
66
|
+
id: number;
|
|
67
|
+
categories: {
|
|
68
|
+
id: number;
|
|
69
|
+
name: string;
|
|
70
|
+
slug: string;
|
|
71
|
+
}[];
|
|
72
|
+
images: IImage[];
|
|
73
|
+
name?: string;
|
|
74
|
+
slug?: string;
|
|
75
|
+
permalink?: string;
|
|
76
|
+
date_created?: Date;
|
|
77
|
+
date_created_gmt?: Date;
|
|
78
|
+
date_modified?: Date;
|
|
79
|
+
date_modified_gmt?: Date;
|
|
80
|
+
type?: string;
|
|
81
|
+
status?: string;
|
|
82
|
+
featured?: boolean;
|
|
83
|
+
catalog_visibility?: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
short_description?: string;
|
|
86
|
+
sku?: string;
|
|
87
|
+
price?: string;
|
|
88
|
+
regular_price?: string;
|
|
89
|
+
sale_price?: string;
|
|
90
|
+
price_html?: string;
|
|
91
|
+
on_sale?: boolean;
|
|
92
|
+
purchasable?: boolean;
|
|
93
|
+
total_sales?: number;
|
|
94
|
+
virtual?: boolean;
|
|
95
|
+
downloadable?: boolean;
|
|
96
|
+
downloads?: undefined[];
|
|
97
|
+
download_limit?: number;
|
|
98
|
+
download_expiry?: number;
|
|
99
|
+
external_url?: string;
|
|
100
|
+
button_text?: string;
|
|
101
|
+
tax_status?: string;
|
|
102
|
+
tax_class?: string;
|
|
103
|
+
manage_stock?: boolean;
|
|
104
|
+
stock_status?: string;
|
|
105
|
+
backorders?: string;
|
|
106
|
+
backorders_allowed?: boolean;
|
|
107
|
+
backordered?: boolean;
|
|
108
|
+
sold_individually?: boolean;
|
|
109
|
+
weight?: string;
|
|
110
|
+
dimensions?: {
|
|
111
|
+
length?: string;
|
|
112
|
+
width?: string;
|
|
113
|
+
height?: string;
|
|
114
|
+
};
|
|
115
|
+
shipping_required?: boolean;
|
|
116
|
+
shipping_taxable?: boolean;
|
|
117
|
+
shipping_class?: string;
|
|
118
|
+
shipping_class_id?: number;
|
|
119
|
+
reviews_allowed?: boolean;
|
|
120
|
+
average_rating?: string;
|
|
121
|
+
rating_count?: number;
|
|
122
|
+
related_ids?: number[];
|
|
123
|
+
upsell_ids?: number[];
|
|
124
|
+
cross_sell_ids?: number[];
|
|
125
|
+
parent_id?: number;
|
|
126
|
+
purchase_note?: string;
|
|
127
|
+
tags?: undefined[];
|
|
128
|
+
attributes?: IAttribute[];
|
|
129
|
+
default_attributes?: IAttribute[];
|
|
130
|
+
variations?: number[];
|
|
131
|
+
grouped_products?: number[];
|
|
132
|
+
menu_order?: number;
|
|
133
|
+
meta_data?: undefined[];
|
|
134
|
+
_links?: {
|
|
135
|
+
self?: {
|
|
136
|
+
href?: string;
|
|
137
|
+
}[];
|
|
138
|
+
collection?: {
|
|
139
|
+
href?: string;
|
|
140
|
+
}[];
|
|
141
|
+
};
|
|
142
|
+
stock_quantity?: number;
|
|
143
|
+
date_on_sale_from?: Date;
|
|
144
|
+
date_on_sale_from_gmt?: Date;
|
|
145
|
+
date_on_sale_to?: Date;
|
|
146
|
+
date_on_sale_to_gmt?: Date;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
@@ -0,0 +1,116 @@
|
|
|
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 WooCommerceApplication, { NAME as BASE_NAME } from '../WooCommerceApplication';
|
|
5
|
+
import { IOutput as IInput } from './WooCommerceGetProducts';
|
|
6
|
+
|
|
7
|
+
export const NAME = `${BASE_NAME.toLowerCase()}-get-variants`;
|
|
8
|
+
|
|
9
|
+
export default class WooCommerceGetVariants extends ABatchNode {
|
|
10
|
+
|
|
11
|
+
public async processAction(dto: BatchProcessDto<IInput>): Promise<BatchProcessDto> {
|
|
12
|
+
const pageNumber = dto.getBatchCursor('1');
|
|
13
|
+
const app = this.getApplication<WooCommerceApplication>();
|
|
14
|
+
const appInstall = await this.getApplicationInstallFromProcess(dto);
|
|
15
|
+
const product = dto.getJsonData();
|
|
16
|
+
|
|
17
|
+
const requestDto = app.getRequestDto(
|
|
18
|
+
dto,
|
|
19
|
+
appInstall,
|
|
20
|
+
HttpMethods.GET,
|
|
21
|
+
`wp-json/wc/v3/products/${product.id}/variations/?per_page=100&page=${pageNumber}`,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const res = await this.getSender().send<IVariant[]>(requestDto, [200, 404]);
|
|
25
|
+
const totalPages = res.getHeaders()['x-wp-totalpages'];
|
|
26
|
+
if (Number(totalPages) > Number(pageNumber)) {
|
|
27
|
+
dto.setBatchCursor((Number(pageNumber) + 1).toString());
|
|
28
|
+
}
|
|
29
|
+
dto.setItemList([{ product, variants: res.getJsonBody() }]);
|
|
30
|
+
|
|
31
|
+
return dto;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public getName(): string {
|
|
35
|
+
return NAME;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface IOutput {
|
|
41
|
+
product: IInput;
|
|
42
|
+
variants: IVariant[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
46
|
+
export interface IVariant {
|
|
47
|
+
id: number;
|
|
48
|
+
date_created: Date;
|
|
49
|
+
date_created_gmt: Date;
|
|
50
|
+
date_modified: Date;
|
|
51
|
+
date_modified_gmt: Date;
|
|
52
|
+
description: string;
|
|
53
|
+
permalink: string;
|
|
54
|
+
sku: string;
|
|
55
|
+
price: string;
|
|
56
|
+
regular_price: string;
|
|
57
|
+
sale_price: string;
|
|
58
|
+
on_sale: boolean;
|
|
59
|
+
status: string;
|
|
60
|
+
purchasable: boolean;
|
|
61
|
+
virtual: boolean;
|
|
62
|
+
downloadable: boolean;
|
|
63
|
+
downloads: undefined[];
|
|
64
|
+
download_limit: number;
|
|
65
|
+
download_expiry: number;
|
|
66
|
+
tax_status: string;
|
|
67
|
+
tax_class: string;
|
|
68
|
+
manage_stock: boolean;
|
|
69
|
+
stock_status: string;
|
|
70
|
+
backorders: string;
|
|
71
|
+
backorders_allowed: boolean;
|
|
72
|
+
backordered: boolean;
|
|
73
|
+
weight: string;
|
|
74
|
+
dimensions: {
|
|
75
|
+
length: string;
|
|
76
|
+
width: string;
|
|
77
|
+
height: string;
|
|
78
|
+
};
|
|
79
|
+
shipping_class: string;
|
|
80
|
+
shipping_class_id: number;
|
|
81
|
+
image: {
|
|
82
|
+
id: number;
|
|
83
|
+
date_created: Date;
|
|
84
|
+
date_created_gmt: Date;
|
|
85
|
+
date_modified: Date;
|
|
86
|
+
date_modified_gmt: Date;
|
|
87
|
+
src: string;
|
|
88
|
+
name: string;
|
|
89
|
+
alt: string;
|
|
90
|
+
};
|
|
91
|
+
attributes: {
|
|
92
|
+
id: number;
|
|
93
|
+
name: string;
|
|
94
|
+
option: string;
|
|
95
|
+
}[];
|
|
96
|
+
menu_order: number;
|
|
97
|
+
meta_data: undefined[];
|
|
98
|
+
_links: {
|
|
99
|
+
self: {
|
|
100
|
+
href: string;
|
|
101
|
+
}[];
|
|
102
|
+
collection: {
|
|
103
|
+
href: string;
|
|
104
|
+
}[];
|
|
105
|
+
up: {
|
|
106
|
+
href: string;
|
|
107
|
+
}[];
|
|
108
|
+
};
|
|
109
|
+
date_on_sale_from?: Date;
|
|
110
|
+
date_on_sale_from_gmt?: Date;
|
|
111
|
+
date_on_sale_to?: Date;
|
|
112
|
+
date_on_sale_to_gmt?: Date;
|
|
113
|
+
stock_quantity?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|