rerobe-js-orm 2.5.4 → 2.5.7

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.
@@ -4,5 +4,5 @@ export default abstract class ChatRoomFactory extends Base {
4
4
  abstract createChatRoom(user: {
5
5
  uid: string;
6
6
  displayName: string;
7
- }, admins: ChatRoomUserInfo[], welcomeMessage: LastMessageObj, chatRoomType: ChatRoomType): ChatRoom;
7
+ }, admins: ChatRoomUserInfo[], welcomeMessage: LastMessageObj, chatRoomType: ChatRoomType, merchantId: string): ChatRoom;
8
8
  }
@@ -4,5 +4,5 @@ export default class ChatRoomFromNewUserSignUp extends ChatRoomFactory {
4
4
  createChatRoom(user: {
5
5
  uid: string;
6
6
  displayName: string;
7
- }, admins: ChatRoomUserInfo[], welcomeMessageObj: LastMessageObj, chatRoomType: ChatRoomType): ChatRoom;
7
+ }, admins: ChatRoomUserInfo[], welcomeMessageObj: LastMessageObj, chatRoomType: ChatRoomType, merchantId: string): ChatRoom;
8
8
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ChatRoomFactory_1 = require("./ChatRoomFactory");
4
4
  const ChatRoom_1 = require("../../models/ChatRoom");
5
5
  class ChatRoomFromNewUserSignUp extends ChatRoomFactory_1.default {
6
- createChatRoom(user, admins, welcomeMessageObj, chatRoomType) {
6
+ createChatRoom(user, admins, welcomeMessageObj, chatRoomType, merchantId) {
7
7
  const chatRoomAttributes = {
8
8
  userIdsToBeNotified: [user.uid],
9
9
  type: chatRoomType,
@@ -18,6 +18,7 @@ class ChatRoomFromNewUserSignUp extends ChatRoomFactory_1.default {
18
18
  online: false,
19
19
  typing: false,
20
20
  } }),
21
+ merchantId: merchantId || '',
21
22
  };
22
23
  return new ChatRoom_1.default(Object.assign({}, chatRoomAttributes));
23
24
  }
@@ -89,6 +89,12 @@ class OrderFromFormState extends OrderFactory_1.default {
89
89
  merchantId: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.merchantId) || '',
90
90
  tags: fs.fields.tags.selectedValues || [],
91
91
  refunds: ((_t = fs.props) === null || _t === void 0 ? void 0 : _t.refunds) || [],
92
+ subtotalPricePresentment: fs.props.subtotalPricePresentment,
93
+ totalDiscountPresentment: fs.props.totalDiscountPresentment,
94
+ totalPricePresentment: fs.props.totalPricePresentment,
95
+ totalRefundedPresentment: fs.props.totalRefundedPresentment,
96
+ totalShippingPricePresentment: fs.props.totalShippingPricePresentment,
97
+ totalTaxPresentment: fs.props.totalTaxPresentment,
92
98
  };
93
99
  return new Order_1.default(Object.assign({}, orderAttributes));
94
100
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.productOptions = exports.productIsOnSaleOptions = exports.discountTypeOptions = exports.conditionTypeOptions = exports.salesChannelOptions = exports.unisexJewelry = exports.mensJewelry = exports.jewelry = exports.unisexAccessories = exports.mensAccessories = exports.accessories = exports.unisexBags = exports.mensBags = exports.bags = exports.unisexShoes = exports.mensShoes = exports.shoes = exports.unisexClothing = exports.mensClothing = exports.clothing = exports.productCategories = exports.clothingMaterials = exports.shoeSizes = exports.jeanSizes = exports.gender = exports.conditions = exports.colors = exports.brands = exports.sizeCommentOptions = exports.clothingSizeOptions = exports.statusOptions = exports.publishTypeOptions = exports.availableForSaleOptions = void 0;
3
+ exports.productOptions = exports.productIsOnSaleOptions = exports.discountTypeOptions = exports.salesChannelOptions = exports.unisexJewelry = exports.mensJewelry = exports.jewelry = exports.unisexAccessories = exports.mensAccessories = exports.accessories = exports.unisexBags = exports.mensBags = exports.bags = exports.unisexShoes = exports.mensShoes = exports.shoes = exports.unisexClothing = exports.mensClothing = exports.clothing = exports.productCategories = exports.clothingMaterials = exports.shoeSizes = exports.jeanSizes = exports.gender = exports.conditions = exports.colors = exports.brands = exports.sizeCommentOptions = exports.clothingSizeOptions = exports.statusOptions = exports.publishTypeOptions = exports.availableForSaleOptions = void 0;
4
4
  const ProductStateManager_1 = require("../../models/ProductStateManager");
5
5
  const lodash_1 = require("lodash");
6
6
  const availableForSaleOptions = [
@@ -9,4 +9,8 @@ export default class OrderHelpers {
9
9
  getOrderInfoWithRefundsAndFulfillments(order: CompleteOrder): OrderWithRefundsAndFulfillmentsInfoObj;
10
10
  getUpdatedOrderObjWithRefunds(orderObj: CompleteOrder, refundObj: OrderRefund): CompleteOrder;
11
11
  getUpdatedOrderObjWithFulfillment(orderObj: CompleteOrder, fulfillmentObj: FulfillmentAdmin, totalUnfulfilledItems: number): CompleteOrder;
12
+ getSubtotalPrice(lineItems: ReRobeOrderLineItem[] | any[], userAvailableCredit?: number | string): number;
13
+ getCreditDiscount(lineItems: ReRobeOrderLineItem[] | undefined, userAvailableCredit: number | string): number;
14
+ getSaleDiscount(lineItems?: ReRobeOrderLineItem[]): number;
15
+ getDiscountAmount(lineItems?: ReRobeOrderLineItem[], userAvailableCredit?: number | string): number;
12
16
  }
@@ -84,6 +84,9 @@ class OrderHelpers {
84
84
  },
85
85
  shopifyProductId: product.shopifyId || null,
86
86
  productId: product.documentId,
87
+ status: product.status || '',
88
+ isOnSale: product.isOnSale || '',
89
+ salePrice: product.salePrice || '',
87
90
  };
88
91
  }
89
92
  toFixedPointPrice(price) {
@@ -193,5 +196,49 @@ class OrderHelpers {
193
196
  totalUnfulfilledItems - fulfilledItemsQuantity > 0 ? 'PARTIALLY_FULFILLED' : 'FULFILLED';
194
197
  return updatedOrder;
195
198
  }
199
+ getSubtotalPrice(lineItems, userAvailableCredit = 0) {
200
+ // Get subtotal without saleDiscount (products on sale) and creditDiscount (userAvailableCredit)
201
+ if (!lineItems || !lineItems.length) {
202
+ return 0;
203
+ }
204
+ const subtotalWithoutSaleDiscount = lineItems.reduce((acc, lineItem) => {
205
+ var _a;
206
+ const isSaleItem = lineItem.isOnSale === 'yes' && (lineItem.status === 'CLEARANCE' || lineItem.status === 'RESERVED');
207
+ const itemPrice = isSaleItem ? lineItem.salePrice : (_a = lineItem.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.amount;
208
+ return acc + Number(itemPrice);
209
+ }, 0);
210
+ let subtotal = subtotalWithoutSaleDiscount;
211
+ if (userAvailableCredit && Number(userAvailableCredit) > 0) {
212
+ subtotal = subtotalWithoutSaleDiscount - Number(userAvailableCredit);
213
+ }
214
+ if (subtotal < 0) {
215
+ subtotal = 0;
216
+ }
217
+ return Number(Number(subtotal).toFixed(2));
218
+ }
219
+ getCreditDiscount(lineItems = [], userAvailableCredit) {
220
+ if (!userAvailableCredit || Number(userAvailableCredit) <= 0) {
221
+ return 0;
222
+ }
223
+ const subtotal = this.getSubtotalPrice(lineItems);
224
+ return subtotal > userAvailableCredit ? Number(userAvailableCredit) : subtotal;
225
+ }
226
+ getSaleDiscount(lineItems = []) {
227
+ return lineItems.reduce((acc, cur) => {
228
+ var _a;
229
+ const isSaleItem = cur.isOnSale === 'yes' && (cur.status === 'CLEARANCE' || cur.status === 'RESERVED');
230
+ let prodDiscount = 0;
231
+ if (isSaleItem) {
232
+ prodDiscount = Number((Number((_a = cur.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.amount) - Number(cur.salePrice)).toFixed(2));
233
+ }
234
+ return acc + prodDiscount;
235
+ }, 0);
236
+ }
237
+ getDiscountAmount(lineItems = [], userAvailableCredit = 0) {
238
+ const creditDiscount = this.getCreditDiscount(lineItems, userAvailableCredit);
239
+ const saleDiscount = this.getSaleDiscount(lineItems);
240
+ const discount = Number(Number(creditDiscount + saleDiscount).toFixed(2));
241
+ return discount;
242
+ }
196
243
  }
197
244
  exports.default = OrderHelpers;
@@ -6,19 +6,19 @@ const options_1 = require("../form-states/Product/options");
6
6
  const ProductStateManager_1 = require("../models/ProductStateManager");
7
7
  class ReRobeProductHelpers {
8
8
  static calculateProductionFee(commission) {
9
- if (commission >= 0.5 || commission === 0.2 || commission === 0.15 || commission === 0) {
10
- return 0;
11
- }
12
9
  if (commission === 0.16) {
13
10
  return 19;
14
11
  }
15
- return 40;
12
+ if (commission === 0.35) {
13
+ return 40;
14
+ }
15
+ return 0;
16
16
  }
17
17
  static calculateFulfillmentFee(commission) {
18
- if (commission >= 0.5 || commission === 0.2 || commission === 0.15 || commission === 0 || commission === 0.16) {
19
- return 0;
18
+ if (commission === 0.35) {
19
+ return 24;
20
20
  }
21
- return 24;
21
+ return 0;
22
22
  }
23
23
  static buildReRobeEarnings(arrayLike) {
24
24
  const products = Array.isArray(arrayLike) ? arrayLike : [arrayLike];
@@ -1,10 +1,22 @@
1
1
  import Base from '../Base';
2
2
  export default class ChatRoom extends Base {
3
+ documentId: string;
3
4
  userIdsToBeNotified: string[];
4
5
  type: ChatRoomType;
5
6
  lastMessage: LastMessageObj;
6
7
  userIds: string[];
7
8
  userInfo: ChatRoomUserInfoObj;
9
+ merchantId: string;
8
10
  constructor(props?: any);
9
11
  toObj(): ChatRoomAttributes;
12
+ generateSchemaForTypesense(name?: string): {
13
+ default_sorting_field: string;
14
+ fields: {
15
+ facet: boolean;
16
+ name: string;
17
+ type: string;
18
+ }[];
19
+ name: string;
20
+ };
21
+ toObjForTypesense(): TypesenseChatRoomObj;
10
22
  }
@@ -4,20 +4,112 @@ const Base_1 = require("../Base");
4
4
  class ChatRoom extends Base_1.default {
5
5
  constructor(props) {
6
6
  super();
7
+ this.documentId = (props === null || props === void 0 ? void 0 : props.documentId) || this.utilities.makeRandId(28);
7
8
  this.userIdsToBeNotified = (props === null || props === void 0 ? void 0 : props.userIdsToBeNotified) || [];
8
9
  this.type = (props === null || props === void 0 ? void 0 : props.type) || 'CUSTOMER_SUPPORT';
9
10
  this.lastMessage = (props === null || props === void 0 ? void 0 : props.lastMessage) || {};
10
11
  this.userIds = (props === null || props === void 0 ? void 0 : props.userIds) || [];
11
12
  this.userInfo = (props === null || props === void 0 ? void 0 : props.userInfo) || {};
13
+ this.merchantId = (props === null || props === void 0 ? void 0 : props.merchantId) || '';
12
14
  }
13
15
  toObj() {
14
16
  return {
17
+ documentId: this.documentId,
15
18
  userIdsToBeNotified: this.userIdsToBeNotified,
16
19
  type: this.type,
17
20
  lastMessage: this.lastMessage,
18
21
  userIds: this.userIds,
19
22
  userInfo: this.userInfo,
23
+ merchantId: this.merchantId,
20
24
  };
21
25
  }
26
+ generateSchemaForTypesense(name = 'prod_chatRooms_20220704') {
27
+ return {
28
+ default_sorting_field: 'lastMessage.createdAtTimestamp',
29
+ fields: [
30
+ {
31
+ facet: false,
32
+ name: 'documentId',
33
+ type: 'string',
34
+ },
35
+ {
36
+ facet: true,
37
+ name: 'type',
38
+ type: 'string',
39
+ },
40
+ {
41
+ facet: false,
42
+ name: 'userIds',
43
+ type: 'string[]',
44
+ },
45
+ {
46
+ facet: false,
47
+ name: 'userIdsToBeNotified',
48
+ type: 'string[]',
49
+ },
50
+ {
51
+ facet: false,
52
+ name: 'lastMessage.authorId',
53
+ type: 'string',
54
+ },
55
+ {
56
+ facet: true,
57
+ name: 'lastMessage.authorName',
58
+ type: 'string',
59
+ },
60
+ {
61
+ facet: false,
62
+ name: 'lastMessage.content',
63
+ type: 'string',
64
+ },
65
+ {
66
+ facet: true,
67
+ name: 'lastMessage.createdAtTimestamp',
68
+ type: 'int64',
69
+ },
70
+ {
71
+ facet: true,
72
+ name: 'adminMemberNames',
73
+ type: 'string[]',
74
+ },
75
+ {
76
+ facet: true,
77
+ name: 'userNames',
78
+ type: 'string[]',
79
+ },
80
+ {
81
+ facet: true,
82
+ name: 'merchantId',
83
+ type: 'string',
84
+ },
85
+ ],
86
+ name,
87
+ };
88
+ }
89
+ toObjForTypesense() {
90
+ const userNames = [];
91
+ const sanitizedAdminMembersNames = Object.keys(this.userInfo).reduce((result, key) => {
92
+ const currentUserInfo = this.userInfo[key];
93
+ userNames.push(this.utilities.sanitizeString(currentUserInfo.displayName));
94
+ if (currentUserInfo.isChatAdmin) {
95
+ result.push(this.utilities.sanitizeString(currentUserInfo.displayName));
96
+ }
97
+ return result;
98
+ }, []);
99
+ const stagedObj = {
100
+ documentId: this.utilities.sanitizeString(this.documentId),
101
+ type: this.utilities.sanitizeString(this.type),
102
+ userIds: this.utilities.sanitzeStringArr(this.userIds),
103
+ userIdsToBeNotified: this.utilities.sanitzeStringArr(this.userIdsToBeNotified),
104
+ 'lastMessage.authorId': this.utilities.sanitizeString(this.lastMessage.authorId),
105
+ 'lastMessage.authorName': this.utilities.sanitizeString(this.lastMessage.authorName),
106
+ 'lastMessage.content': this.utilities.sanitizeString(this.lastMessage.content),
107
+ 'lastMessage.createdAtTimestamp': this.utilities.sanitizeMillisTimeStamp(this.lastMessage.createdAt),
108
+ adminMemberNames: sanitizedAdminMembersNames,
109
+ userNames,
110
+ merchantId: this.utilities.sanitizeString(this.merchantId),
111
+ };
112
+ return stagedObj;
113
+ }
22
114
  }
23
115
  exports.default = ChatRoom;
@@ -82,6 +82,12 @@ export default class Order extends Base {
82
82
  customerName: string;
83
83
  merchantId: string;
84
84
  refunds: OrderRefund[];
85
+ subtotalPricePresentment: Money;
86
+ totalDiscountPresentment: Money;
87
+ totalPricePresentment: Money;
88
+ totalRefundedPresentment: Money;
89
+ totalShippingPricePresentment: Money;
90
+ totalTaxPresentment: Money;
85
91
  constructor(props?: any);
86
92
  toObj(): ReRobeOrderObj;
87
93
  }
@@ -105,6 +105,24 @@ class Order extends Base_1.default {
105
105
  this.customerName = (props === null || props === void 0 ? void 0 : props.customerName) || '';
106
106
  this.merchantId = (props === null || props === void 0 ? void 0 : props.merchantId) || '';
107
107
  this.refunds = (props === null || props === void 0 ? void 0 : props.refunds) || [];
108
+ this.subtotalPricePresentment = (props === null || props === void 0 ? void 0 : props.subtotalPricePresentment) || {
109
+ amount: 0,
110
+ };
111
+ this.totalDiscountPresentment = (props === null || props === void 0 ? void 0 : props.totalDiscountPresentment) || {
112
+ amount: 0,
113
+ };
114
+ this.totalPricePresentment = (props === null || props === void 0 ? void 0 : props.totalPricePresentment) || {
115
+ amount: 0,
116
+ };
117
+ this.totalRefundedPresentment = (props === null || props === void 0 ? void 0 : props.totalRefundedPresentment) || {
118
+ amount: 0,
119
+ };
120
+ this.totalShippingPricePresentment = (props === null || props === void 0 ? void 0 : props.totalShippingPricePresentment) || {
121
+ amount: 0,
122
+ };
123
+ this.totalTaxPresentment = (props === null || props === void 0 ? void 0 : props.totalTaxPresentment) || {
124
+ amount: 0,
125
+ };
108
126
  }
109
127
  toObj() {
110
128
  const orderObj = {
@@ -150,6 +168,12 @@ class Order extends Base_1.default {
150
168
  customerName: this.customerName,
151
169
  merchantId: this.merchantId,
152
170
  refunds: this.refunds,
171
+ subtotalPricePresentment: this.subtotalPricePresentment,
172
+ totalDiscountPresentment: this.totalDiscountPresentment,
173
+ totalPricePresentment: this.totalPricePresentment,
174
+ totalRefundedPresentment: this.totalRefundedPresentment,
175
+ totalShippingPricePresentment: this.totalShippingPricePresentment,
176
+ totalTaxPresentment: this.totalTaxPresentment,
153
177
  };
154
178
  if (this.paymentType) {
155
179
  orderObj.paymentType = this.paymentType;
@@ -1,9 +1,11 @@
1
1
  declare type ChatRoomAttributes = {
2
+ documentId: string;
2
3
  userIdsToBeNotified: string[];
3
4
  type: ChatRoomType;
4
5
  lastMessage: LastMessageObj;
5
6
  userIds: string[];
6
7
  userInfo: ChatRoomUserInfoObj;
8
+ merchantId: string;
7
9
  };
8
10
  declare type ChatRoomType = 'CUSTOMER_SUPPORT' | 'SELLER_CONCIERGE';
9
11
  declare type LastMessageObj = {
@@ -23,5 +25,19 @@ declare type ChatRoomUserInfo = {
23
25
  typing: boolean;
24
26
  isChatAdmin?: boolean;
25
27
  isReRobeStaff?: boolean;
28
+ isSeller?: boolean;
26
29
  firstName?: string;
27
30
  };
31
+ declare type TypesenseChatRoomObj = {
32
+ documentId: string;
33
+ type: string;
34
+ userIds: string[];
35
+ userIdsToBeNotified: string[];
36
+ 'lastMessage.authorId': string;
37
+ 'lastMessage.authorName': string;
38
+ 'lastMessage.content': string;
39
+ 'lastMessage.createdAtTimestamp': number;
40
+ adminMemberNames: string[];
41
+ userNames: string[];
42
+ merchantId: string;
43
+ };
@@ -63,6 +63,12 @@ declare type ReRobeOrderObj = {
63
63
  refunds?: OrderRefund[];
64
64
  createdAt?: string;
65
65
  updatedAt?: string;
66
+ subtotalPricePresentment?: Money;
67
+ totalDiscountPresentment?: Money;
68
+ totalPricePresentment?: Money;
69
+ totalRefundedPresentment?: Money;
70
+ totalShippingPricePresentment?: Money;
71
+ totalTaxPresentment?: Money;
66
72
  };
67
73
  declare type OrderWithRefundsAndFulfillmentsInfoObj = {
68
74
  documentId?: string;
@@ -213,6 +219,9 @@ interface ReRobeOrderLineItem extends OrderLineItem {
213
219
  canceledQuantity?: number | string;
214
220
  fulfilledQuantity?: number | string;
215
221
  unfulfilledQuantity?: number | string;
222
+ status?: ProductSellStatusKeys | string;
223
+ isOnSale?: string;
224
+ salePrice?: string;
216
225
  }
217
226
  declare type OrderLineItemConnection = {
218
227
  edges: OrderLineItemEdge[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "2.5.4",
3
+ "version": "2.5.7",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",