rerobe-js-orm 2.4.2 → 2.4.8
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/lib/factories/FormState/Address/AddressFormStateFactory.d.ts +1 -1
- package/lib/factories/FormState/Address/AddressFormStateFactory.js +1 -1
- package/lib/factories/FormState/Merchant/MerchantFormStateFactory.d.ts +1 -1
- package/lib/factories/FormState/Merchant/MerchantFormStateFactory.js +1 -1
- package/lib/factories/FormState/Order/OrderFormStateFactory.d.ts +1 -1
- package/lib/factories/FormState/Order/OrderFormStateFactory.js +1 -1
- package/lib/factories/FormState/Order/RefundFormStateFactory.d.ts +5 -0
- package/lib/factories/FormState/Order/RefundFormStateFactory.js +10 -0
- package/lib/factories/FormState/PickUp/PickUpFormStateFactory.d.ts +1 -1
- package/lib/factories/FormState/PickUp/PickUpFormStateFactory.js +1 -1
- package/lib/factories/FormState/Product/ProductFormStateFactory.d.ts +2 -2
- package/lib/factories/FormState/Product/ProductFormStateFactory.js +3 -3
- package/lib/factories/FormState/ProductCollection/ProductCollectionFormStateFactory.d.ts +5 -0
- package/lib/factories/FormState/ProductCollection/ProductCollectionFormStateFactory.js +10 -0
- package/lib/factories/FormState/SellRequest/SellRequestFormStateFactory.d.ts +1 -1
- package/lib/factories/FormState/SellRequest/SellRequestFormStateFactory.js +1 -1
- package/lib/factories/FormState/User/UserFormStateFactory.d.ts +1 -1
- package/lib/factories/FormState/User/UserFormStateFactory.js +1 -1
- package/lib/factories/Merchant/MerchantFactory.d.ts +1 -1
- package/lib/factories/Merchant/MerchantFromFormState.d.ts +1 -1
- package/lib/factories/Merchant/MerchantFromFormState.js +13 -1
- package/lib/factories/Order/OrderFactory.d.ts +1 -1
- package/lib/factories/Order/OrderFromApp.js +4 -2
- package/lib/factories/Order/OrderFromFormState.d.ts +1 -1
- package/lib/factories/Order/OrderFromFormState.js +17 -15
- package/lib/factories/Order/OrderFromShopifyWebhook.js +126 -10
- package/lib/factories/Order/RefundFactory.d.ts +5 -0
- package/lib/factories/Order/RefundFactory.js +6 -0
- package/lib/factories/Order/RefundFromFormState.d.ts +5 -0
- package/lib/factories/Order/RefundFromFormState.js +29 -0
- package/lib/factories/PayoutAccount/PayoutAccountFromFormState.d.ts +1 -1
- package/lib/factories/Product/ProductFactory.d.ts +1 -1
- package/lib/factories/Product/ProductFromFormState.d.ts +1 -1
- package/lib/factories/Product/ProductFromFormState.js +29 -3
- package/lib/factories/ProductCollection/ProductCollectionFactory.d.ts +5 -0
- package/lib/factories/ProductCollection/ProductCollectionFactory.js +6 -0
- package/lib/factories/ProductCollection/ProductCollectionFromFormState.d.ts +5 -0
- package/lib/factories/ProductCollection/ProductCollectionFromFormState.js +29 -0
- package/lib/factories/User/UserFactory.d.ts +1 -1
- package/lib/factories/User/UserFromFormState.d.ts +1 -1
- package/lib/{models/FormStates → form-states}/Address/AddressFormState.d.ts +0 -0
- package/lib/{models/FormStates → form-states}/Address/AddressFormState.js +1 -3
- package/lib/{models/FormStates → form-states}/FormState.d.ts +1 -1
- package/lib/{models/FormStates → form-states}/FormState.js +1 -1
- package/lib/{models/FormStates → form-states}/Merchant/MerchantFormState.d.ts +1 -1
- package/lib/{models/FormStates → form-states}/Merchant/MerchantFormState.js +19 -4
- package/lib/form-states/Merchant/WebhookFormState.d.ts +8 -0
- package/lib/form-states/Merchant/WebhookFormState.js +49 -0
- package/lib/{models/FormStates → form-states}/Merchant/options.d.ts +8 -0
- package/lib/{models/FormStates → form-states}/Merchant/options.js +15 -2
- package/lib/{models/FormStates → form-states}/Order/OrderFormState.d.ts +2 -2
- package/lib/{models/FormStates → form-states}/Order/OrderFormState.js +12 -13
- package/lib/form-states/Order/RefundFormState.d.ts +17 -0
- package/lib/form-states/Order/RefundFormState.js +122 -0
- package/lib/{models/FormStates → form-states}/Order/options.d.ts +0 -0
- package/lib/{models/FormStates → form-states}/Order/options.js +1 -1
- package/lib/{models/FormStates → form-states}/PayoutAccount/PayoutAccountFormState.d.ts +1 -1
- package/lib/{models/FormStates → form-states}/PayoutAccount/PayoutAccountFormState.js +2 -2
- package/lib/{models/FormStates → form-states}/PayoutAccount/options.d.ts +0 -0
- package/lib/{models/FormStates → form-states}/PayoutAccount/options.js +0 -0
- package/lib/{models/FormStates → form-states}/PickUp/PickUpFormState.d.ts +0 -0
- package/lib/{models/FormStates → form-states}/PickUp/PickUpFormState.js +0 -0
- package/lib/{models/FormStates → form-states}/Product/ProductFormState.d.ts +8 -2
- package/lib/{models/FormStates → form-states}/Product/ProductFormState.js +24 -4
- package/lib/{models/FormStates → form-states}/Product/options.d.ts +0 -0
- package/lib/form-states/Product/options.js +3455 -0
- package/lib/form-states/ProductCollection/ProductCollectionFormState.d.ts +12 -0
- package/lib/form-states/ProductCollection/ProductCollectionFormState.js +80 -0
- package/lib/{models/FormStates → form-states}/SellRequest/SellRequestFormState.d.ts +0 -0
- package/lib/{models/FormStates → form-states}/SellRequest/SellRequestFormState.js +1 -1
- package/lib/{models/FormStates → form-states}/User/UserFormState.d.ts +1 -1
- package/lib/{models/FormStates → form-states}/User/UserFormState.js +2 -2
- package/lib/helpers/AnalyticsHelpers.js +3 -3
- package/lib/helpers/OrderHelpers.d.ts +5 -0
- package/lib/helpers/OrderHelpers.js +107 -0
- package/lib/helpers/ProductCollectionHelpers.d.ts +4 -0
- package/lib/helpers/ProductCollectionHelpers.js +27 -0
- package/lib/helpers/ReRobeProductHelpers.d.ts +6 -0
- package/lib/helpers/ReRobeProductHelpers.js +221 -41
- package/lib/helpers/Utilities.d.ts +1 -0
- package/lib/helpers/Utilities.js +10 -0
- package/lib/index.d.ts +7 -3
- package/lib/index.js +11 -3
- package/lib/models/Merchant.d.ts +16 -0
- package/lib/models/Merchant.js +40 -0
- package/lib/models/Order.d.ts +4 -0
- package/lib/models/Order.js +7 -1
- package/lib/models/Product.d.ts +1 -0
- package/lib/models/Product.js +37 -3
- package/lib/models/ProductCollection.d.ts +15 -0
- package/lib/models/ProductCollection.js +34 -0
- package/lib/models/Refund.d.ts +13 -0
- package/lib/models/Refund.js +40 -0
- package/lib/models/User.js +7 -2
- package/lib/types/merchant-types.d.ts +46 -13
- package/lib/types/product-collection-types.d.ts +63 -0
- package/lib/types/product-collection-types.js +13 -0
- package/lib/types/rerobe-order-types.d.ts +88 -26
- package/lib/types/rerobe-product-types.d.ts +30 -0
- package/lib/types/rerobe-user-types.d.ts +27 -21
- package/lib/types/rerobe-user-types.js +0 -1
- package/package.json +3 -2
- package/lib/models/FormStates/Product/options.js +0 -3453
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FormStateFactory from '../FormStateFactory';
|
|
2
|
-
import AddressFormState from '../../../
|
|
2
|
+
import AddressFormState from '../../../form-states/Address/AddressFormState';
|
|
3
3
|
export default class AddressFormStateFactory extends FormStateFactory {
|
|
4
4
|
createFormState(props?: AddressInput): AddressFormState;
|
|
5
5
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
-
const AddressFormState_1 = require("../../../
|
|
4
|
+
const AddressFormState_1 = require("../../../form-states/Address/AddressFormState");
|
|
5
5
|
class AddressFormStateFactory extends FormStateFactory_1.default {
|
|
6
6
|
createFormState(props) {
|
|
7
7
|
return new AddressFormState_1.default(props);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FormStateFactory from '../FormStateFactory';
|
|
2
|
-
import MerchantFormState from '../../../
|
|
2
|
+
import MerchantFormState from '../../../form-states/Merchant/MerchantFormState';
|
|
3
3
|
export default class MerchantFormStateFactory extends FormStateFactory {
|
|
4
4
|
createFormState(props?: MerchantObj): MerchantFormState;
|
|
5
5
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
-
const MerchantFormState_1 = require("../../../
|
|
4
|
+
const MerchantFormState_1 = require("../../../form-states/Merchant/MerchantFormState");
|
|
5
5
|
class MerchantFormStateFactory extends FormStateFactory_1.default {
|
|
6
6
|
createFormState(props) {
|
|
7
7
|
return new MerchantFormState_1.default(props);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FormStateFactory from '../FormStateFactory';
|
|
2
|
-
import OrderFormState from '../../../
|
|
2
|
+
import OrderFormState from '../../../form-states/Order/OrderFormState';
|
|
3
3
|
export default class OrderFormStateFactory extends FormStateFactory {
|
|
4
4
|
createFormState(props?: any, opts?: any): OrderFormState;
|
|
5
5
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
-
const OrderFormState_1 = require("../../../
|
|
4
|
+
const OrderFormState_1 = require("../../../form-states/Order/OrderFormState");
|
|
5
5
|
class OrderFormStateFactory extends FormStateFactory_1.default {
|
|
6
6
|
createFormState(props, opts) {
|
|
7
7
|
return new OrderFormState_1.default(props, opts);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
+
const RefundFormState_1 = require("../../../form-states/Order/RefundFormState");
|
|
5
|
+
class RefundFormStateFactory extends FormStateFactory_1.default {
|
|
6
|
+
createFormState(props, opts) {
|
|
7
|
+
return new RefundFormState_1.default(props);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.default = RefundFormStateFactory;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FormStateFactory from '../FormStateFactory';
|
|
2
|
-
import PickUpFormState from '../../../
|
|
2
|
+
import PickUpFormState from '../../../form-states/PickUp/PickUpFormState';
|
|
3
3
|
export default class PickUpFormStateFactory extends FormStateFactory {
|
|
4
4
|
createFormState(props?: PickUp): PickUpFormState;
|
|
5
5
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
-
const PickUpFormState_1 = require("../../../
|
|
4
|
+
const PickUpFormState_1 = require("../../../form-states/PickUp/PickUpFormState");
|
|
5
5
|
class PickUpFormStateFactory extends FormStateFactory_1.default {
|
|
6
6
|
createFormState(props) {
|
|
7
7
|
return new PickUpFormState_1.default(props);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FormStateFactory from '../FormStateFactory';
|
|
2
|
-
import ProductFormState from '../../../
|
|
2
|
+
import ProductFormState from '../../../form-states/Product/ProductFormState';
|
|
3
3
|
export default class ProductFormStateFactory extends FormStateFactory {
|
|
4
|
-
createFormState(props?: CompleteProduct): ProductFormState;
|
|
4
|
+
createFormState(props?: CompleteProduct, opts?: any): ProductFormState;
|
|
5
5
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
-
const ProductFormState_1 = require("../../../
|
|
4
|
+
const ProductFormState_1 = require("../../../form-states/Product/ProductFormState");
|
|
5
5
|
class ProductFormStateFactory extends FormStateFactory_1.default {
|
|
6
|
-
createFormState(props) {
|
|
7
|
-
return new ProductFormState_1.default(props);
|
|
6
|
+
createFormState(props, opts) {
|
|
7
|
+
return new ProductFormState_1.default(props, opts);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.default = ProductFormStateFactory;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import FormStateFactory from '../FormStateFactory';
|
|
2
|
+
import ProductCollectionFormState from '../../../form-states/ProductCollection/ProductCollectionFormState';
|
|
3
|
+
export default class ProductCollectionFormStateFactory extends FormStateFactory {
|
|
4
|
+
createFormState(props?: any, opts?: any): ProductCollectionFormState;
|
|
5
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
+
const ProductCollectionFormState_1 = require("../../../form-states/ProductCollection/ProductCollectionFormState");
|
|
5
|
+
class ProductCollectionFormStateFactory extends FormStateFactory_1.default {
|
|
6
|
+
createFormState(props, opts) {
|
|
7
|
+
return new ProductCollectionFormState_1.default(props, opts);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.default = ProductCollectionFormStateFactory;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FormStateFactory from '../FormStateFactory';
|
|
2
|
-
import SellRequestFormState from '../../../
|
|
2
|
+
import SellRequestFormState from '../../../form-states/SellRequest/SellRequestFormState';
|
|
3
3
|
export default class SellRequestFormStateFactory extends FormStateFactory {
|
|
4
4
|
createFormState(props?: SellRequest): SellRequestFormState;
|
|
5
5
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
-
const SellRequestFormState_1 = require("../../../
|
|
4
|
+
const SellRequestFormState_1 = require("../../../form-states/SellRequest/SellRequestFormState");
|
|
5
5
|
class SellRequestFormStateFactory extends FormStateFactory_1.default {
|
|
6
6
|
createFormState(props) {
|
|
7
7
|
return new SellRequestFormState_1.default(props);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FormStateFactory from '../FormStateFactory';
|
|
2
|
-
import UserFormState from '../../../
|
|
2
|
+
import UserFormState from '../../../form-states/User/UserFormState';
|
|
3
3
|
export default class UserFormStateFactory extends FormStateFactory {
|
|
4
4
|
createFormState(props?: UserAttributes): UserFormState;
|
|
5
5
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const FormStateFactory_1 = require("../FormStateFactory");
|
|
4
|
-
const UserFormState_1 = require("../../../
|
|
4
|
+
const UserFormState_1 = require("../../../form-states/User/UserFormState");
|
|
5
5
|
class UserFormStateFactory extends FormStateFactory_1.default {
|
|
6
6
|
createFormState(props) {
|
|
7
7
|
return new UserFormState_1.default(props);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Merchant from '../../models/Merchant';
|
|
2
|
-
import MerchantFormState from '../../
|
|
2
|
+
import MerchantFormState from '../../form-states/Merchant/MerchantFormState';
|
|
3
3
|
import Base from '../../Base';
|
|
4
4
|
export default abstract class MerchantFactory extends Base {
|
|
5
5
|
abstract createMerchant(props: MerchantFormState): Merchant;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import MerchantFactory from './MerchantFactory';
|
|
2
2
|
import Merchant from '../../models/Merchant';
|
|
3
|
-
import MerchantFormState from '../../
|
|
3
|
+
import MerchantFormState from '../../form-states/Merchant/MerchantFormState';
|
|
4
4
|
export default class MerchantFromFormState extends MerchantFactory {
|
|
5
5
|
createMerchant(fs: MerchantFormState): Merchant;
|
|
6
6
|
}
|
|
@@ -4,7 +4,7 @@ const MerchantFactory_1 = require("./MerchantFactory");
|
|
|
4
4
|
const Merchant_1 = require("../../models/Merchant");
|
|
5
5
|
class MerchantFromFormState extends MerchantFactory_1.default {
|
|
6
6
|
createMerchant(fs) {
|
|
7
|
-
var _a;
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
8
8
|
const merchantAttributes = {
|
|
9
9
|
id: ((_a = fs.props) === null || _a === void 0 ? void 0 : _a.id) || '',
|
|
10
10
|
name: fs.fields.name.inputValue,
|
|
@@ -18,7 +18,19 @@ class MerchantFromFormState extends MerchantFactory_1.default {
|
|
|
18
18
|
currency: fs.fields.currency.selectedValue,
|
|
19
19
|
timeZone: fs.fields.timeZone.selectedValue,
|
|
20
20
|
unitSystem: fs.fields.unitSystem.selectedValue,
|
|
21
|
+
paymentTier: fs.fields.paymentTier.selectedValue,
|
|
21
22
|
defaultWeightUnit: fs.fields.defaultWeightUnit.selectedValue,
|
|
23
|
+
defaultLocation: (_b = fs.props) === null || _b === void 0 ? void 0 : _b.defaultLocation,
|
|
24
|
+
documentId: (_c = fs.props) === null || _c === void 0 ? void 0 : _c.documentId,
|
|
25
|
+
numCustomers: (_d = fs.props) === null || _d === void 0 ? void 0 : _d.numCustomers,
|
|
26
|
+
numFiles: (_e = fs.props) === null || _e === void 0 ? void 0 : _e.numFiles,
|
|
27
|
+
numOrders: (_f = fs.props) === null || _f === void 0 ? void 0 : _f.numOrders,
|
|
28
|
+
numProducts: (_g = fs.props) === null || _g === void 0 ? void 0 : _g.numProducts,
|
|
29
|
+
orderTags: (_h = fs.props) === null || _h === void 0 ? void 0 : _h.orderTags,
|
|
30
|
+
theme: (_j = fs.props) === null || _j === void 0 ? void 0 : _j.theme,
|
|
31
|
+
webshopTenantId: (_k = fs.props) === null || _k === void 0 ? void 0 : _k.webshopTenantId,
|
|
32
|
+
webhooks: fs.fields.webhooks.selectedValues,
|
|
33
|
+
sharedSecret: (_l = fs.props) === null || _l === void 0 ? void 0 : _l.sharedSecret,
|
|
22
34
|
};
|
|
23
35
|
return new Merchant_1.default(Object.assign({}, merchantAttributes));
|
|
24
36
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Base from '../../Base';
|
|
2
|
-
import OrderFormState from '../../
|
|
2
|
+
import OrderFormState from '../../form-states/Order/OrderFormState';
|
|
3
3
|
import Order from '../../models/Order';
|
|
4
4
|
export default abstract class OrderFactory extends Base {
|
|
5
5
|
abstract createOrder(order: ShopifyStorefrontOrderObj | ShopifyAdminOrderObj | ShopifyRestApiOrderObj | OrderFormState | OrderInput): ReRobeOrderObj | Order;
|
|
@@ -6,7 +6,7 @@ const OrderHelpers_1 = require("../../helpers/OrderHelpers");
|
|
|
6
6
|
const orderHelpers = new OrderHelpers_1.default();
|
|
7
7
|
class OrderFromApp extends OrderFactory_1.default {
|
|
8
8
|
createOrder(order) {
|
|
9
|
-
const { id, orderNumber, amount, currencyCode = 'SEK', shippingDetails, appliedDiscount, products, paymentType, paymentMethod, shippingType, shopifyId, shopifyOrderNumber, state, userId, email, salesChannel, tags, paymentDetails, financialStatus, fulfillmentStatus, } = order;
|
|
9
|
+
const { id, orderNumber, amount, currencyCode = 'SEK', shippingDetails, appliedDiscount, products, paymentType, paymentMethod, shippingType, shopifyId, ribbnOrderNumber, shopifyOrderNumber, state, userId, email, customerName, salesChannel, tags, paymentDetails, financialStatus, fulfillmentStatus, } = order;
|
|
10
10
|
let discount = 0;
|
|
11
11
|
let shippingFee = 0;
|
|
12
12
|
let subTotal = 0;
|
|
@@ -35,7 +35,7 @@ class OrderFromApp extends OrderFactory_1.default {
|
|
|
35
35
|
amount: discount.toFixed(2),
|
|
36
36
|
currencyCode,
|
|
37
37
|
};
|
|
38
|
-
const lineItems = products.map((product) =>
|
|
38
|
+
const lineItems = products.map((product) => orderHelpers.buildLineItemFromProduct(product, currencyCode));
|
|
39
39
|
const rerobeOrder = new Order_1.default({
|
|
40
40
|
id,
|
|
41
41
|
appliedDiscount,
|
|
@@ -52,12 +52,14 @@ class OrderFromApp extends OrderFactory_1.default {
|
|
|
52
52
|
paymentType: paymentType ? this.utilities.constantCase(paymentType) : Order_1.default.PAYMENT_TYPES.creditCard,
|
|
53
53
|
shippingType: shippingType ? this.utilities.constantCase(shippingType) : Order_1.default.SHIPPING_TYPES.localPickUp,
|
|
54
54
|
shopifyId,
|
|
55
|
+
ribbnOrderNumber,
|
|
55
56
|
shopifyOrderNumber,
|
|
56
57
|
shippingAddress: shippingDetails && shippingDetails.deliveryAddress ? shippingDetails.deliveryAddress : null,
|
|
57
58
|
lineItems,
|
|
58
59
|
state,
|
|
59
60
|
userId,
|
|
60
61
|
email,
|
|
62
|
+
customerName,
|
|
61
63
|
paymentDetails,
|
|
62
64
|
tags,
|
|
63
65
|
salesChannel,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import OrderFactory from './OrderFactory';
|
|
2
|
-
import OrderFormState from '../../
|
|
2
|
+
import OrderFormState from '../../form-states/Order/OrderFormState';
|
|
3
3
|
export default class OrderFromFormState extends OrderFactory {
|
|
4
4
|
createOrder(fs: OrderFormState): ReRobeOrderObj;
|
|
5
5
|
}
|
|
@@ -4,7 +4,7 @@ const OrderFactory_1 = require("./OrderFactory");
|
|
|
4
4
|
const Order_1 = require("../../models/Order");
|
|
5
5
|
class OrderFromFormState extends OrderFactory_1.default {
|
|
6
6
|
createOrder(fs) {
|
|
7
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
8
8
|
const currencyCode = fs.fields.currencyCode.inputValue || 'SEK';
|
|
9
9
|
const customer = fs.fields.customer.selectedValue || {};
|
|
10
10
|
const firstName = fs.fields.firstName.inputValue;
|
|
@@ -12,18 +12,19 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
12
12
|
const orderAttributes = {
|
|
13
13
|
id: ((_a = fs.props) === null || _a === void 0 ? void 0 : _a.id) || '',
|
|
14
14
|
appliedDiscount: ((_b = fs.props) === null || _b === void 0 ? void 0 : _b.appliedDiscount) || {
|
|
15
|
-
amount: 0
|
|
15
|
+
amount: 0,
|
|
16
16
|
},
|
|
17
17
|
documentId: ((_c = fs.props) === null || _c === void 0 ? void 0 : _c.documentId) || '',
|
|
18
18
|
name: ((_d = fs.props) === null || _d === void 0 ? void 0 : _d.name) || '',
|
|
19
19
|
orderNumber: (_e = fs.props) === null || _e === void 0 ? void 0 : _e.orderNumber,
|
|
20
|
-
|
|
20
|
+
ribbnOrderNumber: (_f = fs.props) === null || _f === void 0 ? void 0 : _f.ribbnOrderNumber,
|
|
21
|
+
state: ((_g = fs.props) === null || _g === void 0 ? void 0 : _g.state) || Order_1.default.ORDER_STATES.draft,
|
|
21
22
|
currencyCode: fs.fields.currencyCode.inputValue,
|
|
22
|
-
statusUrl: ((
|
|
23
|
-
processedAt: ((
|
|
23
|
+
statusUrl: ((_h = fs.props) === null || _h === void 0 ? void 0 : _h.statusUrl) || '',
|
|
24
|
+
processedAt: ((_j = fs.props) === null || _j === void 0 ? void 0 : _j.processedAt) || new Date().toUTCString(),
|
|
24
25
|
financialStatus: fs.fields.financialStatus.selectedValue,
|
|
25
26
|
fulfillmentStatus: fs.fields.fulfillmentStatus.selectedValue,
|
|
26
|
-
fulfillments: ((
|
|
27
|
+
fulfillments: ((_k = fs.props) === null || _k === void 0 ? void 0 : _k.fulfillments) || [],
|
|
27
28
|
shippingAddress: fs.fields.shippingAddress.selectedValue || {
|
|
28
29
|
id: '',
|
|
29
30
|
address1: '',
|
|
@@ -34,7 +35,7 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
34
35
|
province: '',
|
|
35
36
|
zip: '',
|
|
36
37
|
},
|
|
37
|
-
shippingDiscountAllocations: ((
|
|
38
|
+
shippingDiscountAllocations: ((_l = fs.props) === null || _l === void 0 ? void 0 : _l.shippingDiscountAllocations) || [],
|
|
38
39
|
shippingLine: fs.fields.shippingLine
|
|
39
40
|
? fs.fields.shippingLine.selectedValue
|
|
40
41
|
: {
|
|
@@ -55,9 +56,9 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
55
56
|
originalTotalPrice: { amount: fs.fields.originalTotalPrice.inputValue || 0, currencyCode },
|
|
56
57
|
lineItems: fs.fields.lineItems.selectedValues || [],
|
|
57
58
|
cancelReason: fs.fields.cancelReason.selectedValue || '',
|
|
58
|
-
canceledAt: ((
|
|
59
|
-
customerUrl: ((
|
|
60
|
-
discountApplications: ((
|
|
59
|
+
canceledAt: ((_m = fs.props) === null || _m === void 0 ? void 0 : _m.canceledAt) || '',
|
|
60
|
+
customerUrl: ((_o = fs.props) === null || _o === void 0 ? void 0 : _o.customerUrl) || '',
|
|
61
|
+
discountApplications: ((_p = fs.props) === null || _p === void 0 ? void 0 : _p.discountApplications) || [],
|
|
61
62
|
physicalLocation: fs.fields.physicalLocation.selectedValue || {
|
|
62
63
|
id: '',
|
|
63
64
|
activatable: true,
|
|
@@ -76,16 +77,17 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
76
77
|
},
|
|
77
78
|
notes: fs.fields.notes.inputValue || '',
|
|
78
79
|
userId: (customer === null || customer === void 0 ? void 0 : customer.uid) || '',
|
|
79
|
-
customerName: ((
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
customerName: ((_q = fs.props) === null || _q === void 0 ? void 0 : _q.customerName) ||
|
|
81
|
+
(customer.displayName ? customer.displayName : '') ||
|
|
82
|
+
(customer.firstName && customer.lastName ? `${customer.firstName} ${customer.lastName}` : '') ||
|
|
83
|
+
(firstName && lastName ? `${firstName} ${lastName}` : ''),
|
|
83
84
|
email: (customer === null || customer === void 0 ? void 0 : customer.email) || fs.fields.email.inputValue || '',
|
|
84
85
|
phone: (customer === null || customer === void 0 ? void 0 : customer.phone) || fs.fields.phone.inputValue || '',
|
|
85
86
|
paymentMethod: fs.fields.paymentMethod.selectedValue || '',
|
|
86
87
|
paymentDetails: fs.fields.paymentDetails.selectedValue || {},
|
|
87
|
-
merchantId: ((
|
|
88
|
+
merchantId: ((_r = fs.props) === null || _r === void 0 ? void 0 : _r.merchantId) || '',
|
|
88
89
|
tags: fs.fields.tags.selectedValues || [],
|
|
90
|
+
refunds: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.refunds) || [],
|
|
89
91
|
};
|
|
90
92
|
return new Order_1.default(Object.assign({}, orderAttributes));
|
|
91
93
|
}
|
|
@@ -4,6 +4,18 @@ const OrderFactory_1 = require("./OrderFactory");
|
|
|
4
4
|
const Order_1 = require("../../models/Order");
|
|
5
5
|
const OrderHelpers_1 = require("../../helpers/OrderHelpers");
|
|
6
6
|
const orderHelpers = new OrderHelpers_1.default();
|
|
7
|
+
const fulfillmentStatusRestMapping = {
|
|
8
|
+
fulfilled: 'FULFILLED',
|
|
9
|
+
null: '',
|
|
10
|
+
partial: 'PARTIALLY_FULFILLED',
|
|
11
|
+
restocked: 'RESTOCKED',
|
|
12
|
+
pending: 'PENDING_FULFILLMENT',
|
|
13
|
+
open: 'OPEN',
|
|
14
|
+
success: 'SUCCESS',
|
|
15
|
+
cancelled: 'CANCELED',
|
|
16
|
+
error: 'ERROR',
|
|
17
|
+
failure: 'FAILURE',
|
|
18
|
+
};
|
|
7
19
|
class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
8
20
|
createOrder(order) {
|
|
9
21
|
const { id, financial_status, fulfillment_status, cancel_reason, line_items, discount_applications, shipping_address, subtotal_price_set, total_price_set, total_shipping_price_set, currency, cancelled_at, closed_at, created_at, order_number, processed_at, updated_at, shipping_lines, tax_lines, name, total_discounts, tags = '', } = order;
|
|
@@ -78,23 +90,123 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
78
90
|
}
|
|
79
91
|
: null;
|
|
80
92
|
const fulfillments = order.fulfillments
|
|
81
|
-
? order.fulfillments.map((item) => (
|
|
93
|
+
? order.fulfillments.map((item) => ({
|
|
94
|
+
name: item.name,
|
|
95
|
+
id: item.id,
|
|
96
|
+
createdAt: item.created_at,
|
|
97
|
+
updatedAt: item.updated_at,
|
|
98
|
+
location: {
|
|
82
99
|
id: item.location_id || '',
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
|
|
100
|
+
},
|
|
101
|
+
shipmentStatus: item.shipment_status ? item.shipment_status.toUpperCase() : '',
|
|
102
|
+
service: {
|
|
86
103
|
serviceType: item.service ? item.service.toUpperCase() : '',
|
|
87
|
-
},
|
|
104
|
+
},
|
|
105
|
+
status: item.status ? item.status.toUpperCase() : '',
|
|
106
|
+
trackingInfo: {
|
|
88
107
|
company: item.tracking_company,
|
|
89
108
|
number: item.tracking_numbers && !!item.tracking_numbers.length ? item.tracking_numbers[0] : '',
|
|
90
109
|
url: item.tracking_urls && !!item.tracking_urls.length ? item.tracking_urls[0] : '',
|
|
91
|
-
},
|
|
110
|
+
},
|
|
111
|
+
fulfillmentLineItems: item.line_items
|
|
92
112
|
? item.line_items.map((lineItem) => ({
|
|
93
|
-
lineItem,
|
|
113
|
+
lineItem: { shopifyProductId: lineItem === null || lineItem === void 0 ? void 0 : lineItem.product_id },
|
|
94
114
|
quantity: lineItem.quantity,
|
|
95
115
|
}))
|
|
96
|
-
: []
|
|
116
|
+
: [],
|
|
117
|
+
}))
|
|
118
|
+
: [];
|
|
119
|
+
const refunds = order.refunds
|
|
120
|
+
? order.refunds.map((rawRefundItem) => {
|
|
121
|
+
const currencyCode = currency;
|
|
122
|
+
const refundedShippingAmount = !rawRefundItem.order_adjustments.length
|
|
123
|
+
? 0
|
|
124
|
+
: rawRefundItem.order_adjustments.reduce((result, item) => {
|
|
125
|
+
if (item.kind === 'shipping_refund') {
|
|
126
|
+
result = result - Number(item.amount);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}, 0);
|
|
130
|
+
const totalRefundedAmount = !rawRefundItem.transactions.length
|
|
131
|
+
? 0
|
|
132
|
+
: rawRefundItem.transactions.reduce((result, item) => {
|
|
133
|
+
if (item.kind === 'refund') {
|
|
134
|
+
result = result + Number(item.amount);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}, 0);
|
|
138
|
+
let refundDiscountAmount = 0;
|
|
139
|
+
const subtotalRefundedAmount = !rawRefundItem.refund_line_items.length
|
|
140
|
+
? 0
|
|
141
|
+
: rawRefundItem.refund_line_items.reduce((result, item) => {
|
|
142
|
+
if (item.line_item) {
|
|
143
|
+
const itemSubtotal = Number(Number(item.line_item.price) * item.quantity);
|
|
144
|
+
result = result + itemSubtotal;
|
|
145
|
+
refundDiscountAmount = refundDiscountAmount + itemSubtotal - Number(item.subtotal);
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}, 0);
|
|
149
|
+
let refundLineItems = !rawRefundItem.refund_line_items || !rawRefundItem.refund_line_items.length
|
|
150
|
+
? []
|
|
151
|
+
: rawRefundItem.refund_line_items.map((item) => {
|
|
152
|
+
var _a, _b;
|
|
153
|
+
const quantityRefund = !item.location_id ? item.quantity : 0;
|
|
154
|
+
const quantityCancel = item.location_id ? item.quantity : 0;
|
|
155
|
+
const discountRefundAmount = Number(Number((_a = item.line_item) === null || _a === void 0 ? void 0 : _a.price) * item.quantity) - Number(item.subtotal);
|
|
156
|
+
const subtotalRefundAmount = !item.location_id ? item.subtotal : 0;
|
|
157
|
+
const subtotalCanceledAmount = item.location_id ? item.subtotal : 0;
|
|
158
|
+
return {
|
|
159
|
+
lineItem: { shopifyProductId: (_b = item.line_item) === null || _b === void 0 ? void 0 : _b.product_id },
|
|
160
|
+
quantityRefund,
|
|
161
|
+
quantityCancel,
|
|
162
|
+
discountRefund: { currencyCode, amount: discountRefundAmount },
|
|
163
|
+
subtotalRefund: { currencyCode, amount: subtotalRefundAmount },
|
|
164
|
+
subtotalCanceled: { currencyCode, amount: subtotalCanceledAmount },
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
if (refundLineItems.length) {
|
|
168
|
+
refundLineItems = refundLineItems.reduce((result, item) => {
|
|
169
|
+
var _a;
|
|
170
|
+
const existedLineItemsIds = !result.length ? [] : result.map((itm) => itm.lineItem.shopifyProductId);
|
|
171
|
+
const existedLineItemIdx = existedLineItemsIds.indexOf((_a = item.lineItem) === null || _a === void 0 ? void 0 : _a.shopifyProductId);
|
|
172
|
+
if (existedLineItemIdx < 0) {
|
|
173
|
+
result.push(item);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
result[existedLineItemIdx] = {
|
|
177
|
+
lineItem: result[existedLineItemIdx].lineItem,
|
|
178
|
+
quantityRefund: result[existedLineItemIdx].quantityRefund + item.quantityRefund,
|
|
179
|
+
quantityCancel: result[existedLineItemIdx].quantityCancel + item.quantityCancel,
|
|
180
|
+
discountRefund: Object.assign(Object.assign({}, result[existedLineItemIdx].discountRefund), { amount: result[existedLineItemIdx].discountRefund.amount + item.discountRefund.amount }),
|
|
181
|
+
subtotalRefund: Object.assign(Object.assign({}, result[existedLineItemIdx].subtotalRefund), { amount: result[existedLineItemIdx].subtotalRefund.amount + item.subtotalRefund.amount }),
|
|
182
|
+
subtotalCanceled: Object.assign(Object.assign({}, result[existedLineItemIdx].subtotalCanceled), { amount: result[existedLineItemIdx].subtotalCanceled.amount + item.subtotalCanceled.amount }),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}, []);
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
documentId: rawRefundItem.id,
|
|
190
|
+
createdAt: rawRefundItem.created_at,
|
|
191
|
+
note: rawRefundItem.note,
|
|
192
|
+
totalRefunded: { amount: totalRefundedAmount, currencyCode },
|
|
193
|
+
subtotalRefunded: { amount: subtotalRefundedAmount, currencyCode },
|
|
194
|
+
refundDiscount: { amount: refundDiscountAmount, currencyCode },
|
|
195
|
+
refundShipping: { amount: refundedShippingAmount, currencyCode },
|
|
196
|
+
totalTax: { amount: 0, currencyCode },
|
|
197
|
+
refundLineItems,
|
|
198
|
+
};
|
|
199
|
+
})
|
|
97
200
|
: [];
|
|
201
|
+
const totalRefunded = {
|
|
202
|
+
currencyCode: currency,
|
|
203
|
+
amount: !refunds || !refunds.length
|
|
204
|
+
? 0
|
|
205
|
+
: refunds.reduce((result, item) => {
|
|
206
|
+
result = result + Number(item.totalRefunded.amount);
|
|
207
|
+
return result;
|
|
208
|
+
}, 0),
|
|
209
|
+
};
|
|
98
210
|
const taxLines = tax_lines
|
|
99
211
|
? tax_lines.map((item) => ({
|
|
100
212
|
rate: item.rate,
|
|
@@ -150,13 +262,17 @@ class OrderFromShopifyWebhook extends OrderFactory_1.default {
|
|
|
150
262
|
},
|
|
151
263
|
source: '',
|
|
152
264
|
};
|
|
153
|
-
|
|
265
|
+
// @ts-ignore
|
|
266
|
+
const fulfillmentStatus = !fulfillment_status ? '' : fulfillmentStatusRestMapping[fulfillment_status];
|
|
267
|
+
const rerobeOrder = new Order_1.default(Object.assign(Object.assign({}, order), { id: orderHelpers.getOrderIdFromShopifyObj(order), shopifyId: `gid://shopify/Order/${id}`, shopifyOrderNumber: name ? Number(name.split('#')[1]) : 0, financialStatus: financial_status ? financial_status.toUpperCase() : '', fulfillmentStatus, cancelReason: cancel_reason ? cancel_reason.toUpperCase() : '', lineItems,
|
|
154
268
|
subtotalPrice,
|
|
155
269
|
totalPrice,
|
|
156
270
|
totalShippingPrice,
|
|
157
|
-
totalDiscount,
|
|
271
|
+
totalDiscount,
|
|
272
|
+
totalRefunded, canceledAt: cancelled_at, closedAt: closed_at, createdAt: created_at, orderNumber: order_number, processedAt: processed_at, updatedAt: updated_at, shippingAddress,
|
|
158
273
|
discountApplications,
|
|
159
274
|
fulfillments,
|
|
275
|
+
refunds,
|
|
160
276
|
taxLines,
|
|
161
277
|
shippingLine, state: Order_1.default.ORDER_STATES.completed, shippingType: orderHelpers.getShippingTypeFromShopifyObj(shipping_lines), paymentType: orderHelpers.getPaymentTypeUsingTags(tags), salesChannel: orderHelpers.getSalesChannelUsingTags(tags), tags: tags ? tags.split(', ') : [] }));
|
|
162
278
|
return rerobeOrder.toObj();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Refund_1 = require("../../models/Refund");
|
|
4
|
+
const RefundFactory_1 = require("./RefundFactory");
|
|
5
|
+
class RefundFromFormState extends RefundFactory_1.default {
|
|
6
|
+
createRefund(fs) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
let currencyCode = fs.props.totalRefunded.currencyCode || '';
|
|
9
|
+
if (!currencyCode && fs.fields.refundLineItems.selectedValues.length) {
|
|
10
|
+
currencyCode = ((_a = fs.fields.refundLineItems.selectedValues[0].subtotalRefund) === null || _a === void 0 ? void 0 : _a.currencyCode) || '';
|
|
11
|
+
}
|
|
12
|
+
const subtotalRefundedAmount = fs.fields.subtotalRefunded.inputValue;
|
|
13
|
+
const preparedRefundLineItems = !fs.fields.refundLineItems.selectedValues.length
|
|
14
|
+
? []
|
|
15
|
+
: fs.fields.refundLineItems.selectedValues.filter(({ quantityRefund, quantityCancel }) => quantityRefund + quantityCancel > 0);
|
|
16
|
+
const refundAttributes = {
|
|
17
|
+
documentId: ((_b = fs.props) === null || _b === void 0 ? void 0 : _b.documentId) || '',
|
|
18
|
+
totalRefunded: { amount: fs.fields.totalRefunded.inputValue || 0, currencyCode },
|
|
19
|
+
subtotalRefunded: { amount: subtotalRefundedAmount, currencyCode },
|
|
20
|
+
refundDiscount: { amount: fs.fields.refundDiscount.inputValue || 0, currencyCode },
|
|
21
|
+
refundShipping: { amount: fs.fields.refundShipping.inputValue || 0, currencyCode },
|
|
22
|
+
totalTax: { amount: fs.fields.totalTax.inputValue || 0, currencyCode },
|
|
23
|
+
refundLineItems: preparedRefundLineItems,
|
|
24
|
+
note: fs.fields.note.inputValue || '',
|
|
25
|
+
};
|
|
26
|
+
return new Refund_1.default(Object.assign({}, refundAttributes));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = RefundFromFormState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import PayoutAccountFactory from './PayoutAccountFactory';
|
|
2
2
|
import PayoutAccount from '../../models/PayoutAccount';
|
|
3
|
-
import PayoutAccountFormState from '../../
|
|
3
|
+
import PayoutAccountFormState from '../../form-states/PayoutAccount/PayoutAccountFormState';
|
|
4
4
|
export default class PayoutAccountFromFormState extends PayoutAccountFactory {
|
|
5
5
|
createPayoutAccount(props: PayoutAccountFormState): PayoutAccount;
|
|
6
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Product from '../../models/Product';
|
|
2
|
-
import ProductFormState from '../../
|
|
2
|
+
import ProductFormState from '../../form-states/Product/ProductFormState';
|
|
3
3
|
import Base from '../../Base';
|
|
4
4
|
export default abstract class ProductFactory extends Base {
|
|
5
5
|
abstract createProduct(props: ProductRespFromShopifyWebhook | ProductRespFromShopifyJSClient | ProductRespFromAlgolia | ProductFormState): Product;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ProductFactory from './ProductFactory';
|
|
2
2
|
import Product from '../../models/Product';
|
|
3
|
-
import ProductFormState from '../../
|
|
3
|
+
import ProductFormState from '../../form-states/Product/ProductFormState';
|
|
4
4
|
export default class ProductFromFormState extends ProductFactory {
|
|
5
5
|
createProduct(props: ProductFormState): Product;
|
|
6
6
|
}
|