rerobe-js-orm 2.4.83 → 2.4.87

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,7 +4,7 @@ const ProductFactory_1 = require("./ProductFactory");
4
4
  const Product_1 = require("../../models/Product");
5
5
  class ProductFromFormState extends ProductFactory_1.default {
6
6
  createProduct(props) {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13;
8
8
  const productAttributes = {
9
9
  availableForSale: props.fields.availableForSale.selectedValue,
10
10
  description: props.fields.description.inputValue,
@@ -76,28 +76,31 @@ class ProductFromFormState extends ProductFactory_1.default {
76
76
  discountValue: props.fields.discountValue.inputValue || '',
77
77
  selectedForClearance: ((_r = props.props) === null || _r === void 0 ? void 0 : _r.selectedForClearance) || '',
78
78
  locationIds: props.fields.locationIds.selectedValues || [],
79
+ inventoryLocations: props.fields.inventoryLocations.selectedValues || [],
79
80
  };
80
81
  const timestampAttributes = {
81
- sellRequestReviewTimestamp: (_s = props.props) === null || _s === void 0 ? void 0 : _s.sellRequestReviewTimestamp,
82
- sellRequestReviewDraftTimestamp: (_t = props.props) === null || _t === void 0 ? void 0 : _t.sellRequestReviewDraftTimestamp,
83
- rejectedTimestamp: (_u = props.props) === null || _u === void 0 ? void 0 : _u.rejectedTimestamp,
84
- holdTimestamp: (_v = props.props) === null || _v === void 0 ? void 0 : _v.holdTimestamp,
85
- acceptedTimestamp: (_w = props.props) === null || _w === void 0 ? void 0 : _w.acceptedTimestamp,
86
- sellerToDropOffTimestamp: (_x = props.props) === null || _x === void 0 ? void 0 : _x.sellerToDropOffTimestamp,
87
- sellerToShipTimestamp: (_y = props.props) === null || _y === void 0 ? void 0 : _y.sellerToShipTimestamp,
88
- sellerToGetPickUpTimestamp: (_z = props.props) === null || _z === void 0 ? void 0 : _z.sellerToGetPickUpTimestamp,
89
- qualityControlTimestamp: (_0 = props.props) === null || _0 === void 0 ? void 0 : _0.qualityControlTimestamp,
90
- pendingPublicationTimestamp: (_1 = props.props) === null || _1 === void 0 ? void 0 : _1.pendingPublicationTimestamp,
91
- listedTimestamp: (_2 = props.props) === null || _2 === void 0 ? void 0 : _2.listedTimestamp,
92
- clearanceTimestamp: (_3 = props.props) === null || _3 === void 0 ? void 0 : _3.clearanceTimestamp,
93
- reservedTimestamp: (_4 = props.props) === null || _4 === void 0 ? void 0 : _4.reservedTimestamp,
94
- soldTimestamp: (_5 = props.props) === null || _5 === void 0 ? void 0 : _5.soldTimestamp,
95
- returnedTimestamp: (_6 = props.props) === null || _6 === void 0 ? void 0 : _6.returnedTimestamp,
96
- soldSellerToBePaidTimestamp: (_7 = props.props) === null || _7 === void 0 ? void 0 : _7.soldSellerToBePaidTimestamp,
97
- soldSellerPaidTimestamp: (_8 = props.props) === null || _8 === void 0 ? void 0 : _8.soldSellerPaidTimestamp,
98
- sellerSelfRejectTimestamp: (_9 = props.props) === null || _9 === void 0 ? void 0 : _9.sellerSelfRejectTimestamp,
99
- liquidationRequestedTimestamp: (_10 = props.props) === null || _10 === void 0 ? void 0 : _10.liquidationRequestedTimestamp,
100
- sellerLiquidatedTimestamp: (_11 = props.props) === null || _11 === void 0 ? void 0 : _11.sellerLiquidatedTimestamp,
82
+ createdAtTimestamp: (_s = props.props) === null || _s === void 0 ? void 0 : _s.createdAtTimestamp,
83
+ updatedAtTimestamp: (_t = props.props) === null || _t === void 0 ? void 0 : _t.updatedAtTimestamp,
84
+ sellRequestReviewTimestamp: (_u = props.props) === null || _u === void 0 ? void 0 : _u.sellRequestReviewTimestamp,
85
+ sellRequestReviewDraftTimestamp: (_v = props.props) === null || _v === void 0 ? void 0 : _v.sellRequestReviewDraftTimestamp,
86
+ rejectedTimestamp: (_w = props.props) === null || _w === void 0 ? void 0 : _w.rejectedTimestamp,
87
+ holdTimestamp: (_x = props.props) === null || _x === void 0 ? void 0 : _x.holdTimestamp,
88
+ acceptedTimestamp: (_y = props.props) === null || _y === void 0 ? void 0 : _y.acceptedTimestamp,
89
+ sellerToDropOffTimestamp: (_z = props.props) === null || _z === void 0 ? void 0 : _z.sellerToDropOffTimestamp,
90
+ sellerToShipTimestamp: (_0 = props.props) === null || _0 === void 0 ? void 0 : _0.sellerToShipTimestamp,
91
+ sellerToGetPickUpTimestamp: (_1 = props.props) === null || _1 === void 0 ? void 0 : _1.sellerToGetPickUpTimestamp,
92
+ qualityControlTimestamp: (_2 = props.props) === null || _2 === void 0 ? void 0 : _2.qualityControlTimestamp,
93
+ pendingPublicationTimestamp: (_3 = props.props) === null || _3 === void 0 ? void 0 : _3.pendingPublicationTimestamp,
94
+ listedTimestamp: (_4 = props.props) === null || _4 === void 0 ? void 0 : _4.listedTimestamp,
95
+ clearanceTimestamp: (_5 = props.props) === null || _5 === void 0 ? void 0 : _5.clearanceTimestamp,
96
+ reservedTimestamp: (_6 = props.props) === null || _6 === void 0 ? void 0 : _6.reservedTimestamp,
97
+ soldTimestamp: (_7 = props.props) === null || _7 === void 0 ? void 0 : _7.soldTimestamp,
98
+ returnedTimestamp: (_8 = props.props) === null || _8 === void 0 ? void 0 : _8.returnedTimestamp,
99
+ soldSellerToBePaidTimestamp: (_9 = props.props) === null || _9 === void 0 ? void 0 : _9.soldSellerToBePaidTimestamp,
100
+ soldSellerPaidTimestamp: (_10 = props.props) === null || _10 === void 0 ? void 0 : _10.soldSellerPaidTimestamp,
101
+ sellerSelfRejectTimestamp: (_11 = props.props) === null || _11 === void 0 ? void 0 : _11.sellerSelfRejectTimestamp,
102
+ liquidationRequestedTimestamp: (_12 = props.props) === null || _12 === void 0 ? void 0 : _12.liquidationRequestedTimestamp,
103
+ sellerLiquidatedTimestamp: (_13 = props.props) === null || _13 === void 0 ? void 0 : _13.sellerLiquidatedTimestamp,
101
104
  };
102
105
  return new Product_1.default(Object.assign(Object.assign(Object.assign(Object.assign({}, productAttributes), productFilterAttributes), consignmentAttributes), timestampAttributes));
103
106
  }
@@ -24,5 +24,6 @@ export default class ProductFormState extends FormState {
24
24
  private discountTypeChangeHandler;
25
25
  private discountValueChangeHandler;
26
26
  private calculateSalePrice;
27
+ private inventoryLocationsChangeHandler;
27
28
  private fieldFactory;
28
29
  }
@@ -71,6 +71,7 @@ class ProductFormState extends FormState_1.default {
71
71
  this.fields.vendorName = this.fieldFactory('singleSelect', 'vendorName');
72
72
  this.fields.rfidTag = this.fieldFactory('textInput', 'rfidTag');
73
73
  this.fields.locationIds = this.fieldFactory('multiSelect', 'locationIds');
74
+ this.fields.inventoryLocations = this.fieldFactory('multiSelect', 'inventoryLocations');
74
75
  this.fields.featuredCollections = this.fieldFactory('multiSelect', 'featuredCollections');
75
76
  this.fields.tags = this.fieldFactory('multiSelect', 'tags');
76
77
  }
@@ -413,6 +414,24 @@ class ProductFormState extends FormState_1.default {
413
414
  }
414
415
  return '';
415
416
  }
417
+ inventoryLocationsChangeHandler(val) {
418
+ const { id, incomingAmount, availableAmount } = val;
419
+ const existingIds = this.fields.inventoryLocations.selectedValues.map((i) => i.id);
420
+ if (existingIds.includes(id)) {
421
+ const foundInd = this.fields.inventoryLocations.selectedValues.findIndex((i) => i.id === id);
422
+ const foundI = this.fields.inventoryLocations.selectedValues[foundInd];
423
+ // Delete case: val is exact same object
424
+ if (incomingAmount === foundI.incomingAmount && availableAmount === foundI.availableAmount) {
425
+ this.fields.inventoryLocations.selectedValues.splice(foundInd, 1);
426
+ }
427
+ else {
428
+ this.fields.inventoryLocations.selectedValues.splice(foundInd, 1, val);
429
+ }
430
+ }
431
+ else {
432
+ this.multiSelectChangeHandler('inventoryLocations', val);
433
+ }
434
+ }
416
435
  fieldFactory(fieldType, fieldKey, fieldOptions) {
417
436
  let options = fieldOptions || [];
418
437
  let hidden = false;
@@ -499,6 +518,7 @@ class ProductFormState extends FormState_1.default {
499
518
  };
500
519
  }
501
520
  if (fieldType === 'multiSelect') {
521
+ let onChangeHandler = (val) => this.multiSelectChangeHandler(fieldKey, val);
502
522
  if (fieldKey === 'productStyle') {
503
523
  options = this.setProductStylesFromCategoryAndType(this.props.productCategory, this.props.productType);
504
524
  if (this.props.productStyle && this.props.productStyle.length > 0) {
@@ -608,12 +628,15 @@ class ProductFormState extends FormState_1.default {
608
628
  }
609
629
  hidden = this.props.productCategory !== 'Clothing' || this.props.productType === 'Jeans';
610
630
  }
631
+ if (fieldKey === 'inventoryLocations') {
632
+ onChangeHandler = (val) => this.inventoryLocationsChangeHandler(val);
633
+ }
611
634
  return {
612
635
  options,
613
636
  hidden,
614
637
  selectedValues: this.props[fieldKey] || [],
615
638
  valid: this.props[fieldKey].length > 0,
616
- onChangeHandler: (val) => this.multiSelectChangeHandler(fieldKey, val),
639
+ onChangeHandler,
617
640
  };
618
641
  }
619
642
  if (fieldType === 'textInput') {
@@ -226,7 +226,7 @@ class ReRobeProductHelpers {
226
226
  static createTimestampsForStates(productObj) {
227
227
  const docFieldsToUpdate = {};
228
228
  if (productObj) {
229
- const { dateSold, status, sellRequestReviewDraftTimestamp, sellRequestReviewTimestamp, rejectedTimestamp, holdTimestamp, acceptedTimestamp, sellerToDropOffTimestamp, sellerToShipTimestamp, sellerToGetPickUpTimestamp, qualityControlTimestamp, pendingPublicationTimestamp, listedTimestamp, clearanceTimestamp, reservedTimestamp, soldTimestamp, soldSellerToBePaidTimestamp, soldSellerPaidTimestamp, returnedTimestamp, sellerSelfRejectTimestamp, liquidationRequestedTimestamp, sellerLiquidatedTimestamp, } = productObj;
229
+ const { status, sellRequestReviewDraftTimestamp, sellRequestReviewTimestamp, rejectedTimestamp, holdTimestamp, acceptedTimestamp, sellerToDropOffTimestamp, sellerToShipTimestamp, sellerToGetPickUpTimestamp, qualityControlTimestamp, pendingPublicationTimestamp, listedTimestamp, clearanceTimestamp, reservedTimestamp, soldTimestamp, soldSellerToBePaidTimestamp, soldSellerPaidTimestamp, returnedTimestamp, sellerSelfRejectTimestamp, liquidationRequestedTimestamp, sellerLiquidatedTimestamp, } = productObj;
230
230
  if (status === ProductStateManager_1.default.PRODUCT_STATES.sellRequestReviewDraft && !sellRequestReviewDraftTimestamp) {
231
231
  docFieldsToUpdate.sellRequestReviewDraftTimestamp = new Date().getTime();
232
232
  }
@@ -7,6 +7,11 @@ export default class Utilities {
7
7
  getWeekNumberFromDate(dateString: string): string;
8
8
  capitalizeString(s: string): string;
9
9
  startCase(s: string): string;
10
+ camelCase(s: string): string;
10
11
  constantCase(str: string): any;
11
12
  makeRandId(length: number): string;
13
+ sanitizeString(v: any): string;
14
+ sanitzeStringArr(v: any): string[];
15
+ sanitizeNumber(v: any, to?: number): number;
16
+ sanitizeMillisTimeStamp(t: any): number;
12
17
  }
@@ -47,6 +47,9 @@ class Utilities {
47
47
  startCase(s) {
48
48
  return lodash_1.startCase(s);
49
49
  }
50
+ camelCase(s) {
51
+ return lodash_1.camelCase(s);
52
+ }
50
53
  constantCase(str) {
51
54
  return lodash_1.snakeCase(str).toUpperCase();
52
55
  }
@@ -60,5 +63,26 @@ class Utilities {
60
63
  }
61
64
  return result;
62
65
  }
66
+ sanitizeString(v) {
67
+ if (v && (typeof v === 'string' || typeof v === 'number')) {
68
+ return String(v);
69
+ }
70
+ return '';
71
+ }
72
+ sanitzeStringArr(v) {
73
+ if (v && Array.isArray(v)) {
74
+ return v.filter((e) => e).map((e) => String(e));
75
+ }
76
+ return [];
77
+ }
78
+ sanitizeNumber(v, to = 1) {
79
+ return Number.isNaN(parseFloat(String(v))) ? Number(to) : parseFloat(String(v));
80
+ }
81
+ sanitizeMillisTimeStamp(t) {
82
+ if (t && typeof t === 'number') {
83
+ return t;
84
+ }
85
+ return 0;
86
+ }
63
87
  }
64
88
  exports.default = Utilities;
@@ -10,11 +10,29 @@ export default class Product extends Base {
10
10
  toObj(): CompleteProduct;
11
11
  toProductInputObjForShopify(location?: string): any;
12
12
  toObjForTextTranslation(): TranslatableAttributes;
13
+ toObjForTypesense(): TypesenseProductObj;
13
14
  updateSelfFromTranslatedTextArray(translatedTextArray?: string[]): void;
14
15
  autoCreateTitle(): string;
15
16
  autoCreateDescriptionHTML(): string;
17
+ generateSchemaForTypesense(name?: string): {
18
+ default_sorting_field: string;
19
+ fields: ({
20
+ facet: boolean;
21
+ name: string;
22
+ type: string;
23
+ optional?: undefined;
24
+ } | {
25
+ facet: boolean;
26
+ optional: boolean;
27
+ name: string;
28
+ type: string;
29
+ })[];
30
+ name: string;
31
+ };
16
32
  private materialCompTagsArrayForShopify;
17
33
  private materialCompJoinedString;
18
34
  private measurementsJoinedString;
19
35
  private convertMaterialCompJoinedStrToObj;
36
+ private sanitizeMaterialComp;
37
+ private sanitizeCommission;
20
38
  }
@@ -80,8 +80,11 @@ class Product extends Base_1.default {
80
80
  discountValue: (props === null || props === void 0 ? void 0 : props.discountValue) || '',
81
81
  selectedForClearance: (props === null || props === void 0 ? void 0 : props.selectedForClearance) || '',
82
82
  locationIds: (props === null || props === void 0 ? void 0 : props.locationIds) || [],
83
+ inventoryLocations: (props === null || props === void 0 ? void 0 : props.inventoryLocations) || [],
83
84
  };
84
85
  this.timestampAttributes = {
86
+ createdAtTimestamp: (props === null || props === void 0 ? void 0 : props.createdAtTimestamp) ? Number(props === null || props === void 0 ? void 0 : props.createdAtTimestamp) : null,
87
+ updatedAtTimestamp: (props === null || props === void 0 ? void 0 : props.updatedAtTimestamp) ? Number(props === null || props === void 0 ? void 0 : props.updatedAtTimestamp) : null,
85
88
  sellRequestReviewDraftTimestamp: (props === null || props === void 0 ? void 0 : props.sellRequestReviewDraftTimestamp)
86
89
  ? Number(props === null || props === void 0 ? void 0 : props.sellRequestReviewDraftTimestamp)
87
90
  : null,
@@ -114,7 +117,7 @@ class Product extends Base_1.default {
114
117
  }
115
118
  toPartialObj() {
116
119
  return Object.assign(Object.assign({}, this.attributes), this.filterAttributes);
117
- }
120
+ } // ToDo: Deprecate soon
118
121
  toObj() {
119
122
  return Object.assign(Object.assign(Object.assign(Object.assign({}, this.attributes), this.filterAttributes), this.consignmentAttributes), this.timestampAttributes);
120
123
  }
@@ -225,6 +228,85 @@ class Product extends Base_1.default {
225
228
  condition: this.filterAttributes.condition || this.FIELD_NOT_TRANSLATABLE_KEY,
226
229
  };
227
230
  }
231
+ toObjForTypesense() {
232
+ const stagedObj = {
233
+ brand: this.utilities.sanitizeString(this.filterAttributes.brand),
234
+ clothingSize: this.utilities.sanitzeStringArr(this.filterAttributes.clothingSize),
235
+ jeanSize: this.utilities.sanitizeString(this.filterAttributes.jeanSize),
236
+ shoeSize: this.utilities.sanitizeString(this.filterAttributes.shoeSize),
237
+ condition: this.utilities.sanitizeString(this.filterAttributes.condition),
238
+ featuredCollections: this.utilities.sanitzeStringArr(this.filterAttributes.featuredCollections),
239
+ isOnSale: this.utilities.sanitizeString(this.consignmentAttributes.isOnSale),
240
+ merchants: this.utilities.sanitzeStringArr(this.attributes.merchants),
241
+ price: this.utilities.sanitizeNumber(this.attributes.price),
242
+ suggestedResalePrice: this.utilities.sanitizeNumber(this.consignmentAttributes.suggestedResalePrice),
243
+ salePrice: this.utilities.sanitizeNumber(this.consignmentAttributes.salePrice),
244
+ compareAtPrice: this.utilities.sanitizeNumber(this.attributes.compareAtPrice),
245
+ costPerItem: this.utilities.sanitizeNumber(this.attributes.costPerItem),
246
+ priceRange: this.utilities.sanitizeString(this.filterAttributes.priceRange),
247
+ productCategory: this.utilities.sanitizeString(this.filterAttributes.productCategory),
248
+ productType: this.utilities.sanitizeString(this.filterAttributes.productType),
249
+ productStyle: this.utilities.sanitzeStringArr(this.filterAttributes.productStyle),
250
+ reRobeCommission: this.sanitizeCommission(),
251
+ rfidTag: this.utilities.sanitizeString(this.attributes.rfidTag),
252
+ salesChannel: this.utilities.sanitzeStringArr(this.consignmentAttributes.salesChannel),
253
+ status: this.utilities.sanitizeString(this.consignmentAttributes.status),
254
+ tags: this.utilities.sanitzeStringArr(this.filterAttributes.tags),
255
+ title: this.utilities.sanitizeString(this.attributes.title),
256
+ vendorName: this.utilities.sanitizeString(this.attributes.vendorName),
257
+ vendorId: this.utilities.sanitizeString(this.attributes.vendorId),
258
+ createdAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.createdAtTimestamp),
259
+ updatedAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.updatedAtTimestamp),
260
+ sellRequestReviewTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellRequestReviewTimestamp),
261
+ sellRequestReviewDraftTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellRequestReviewDraftTimestamp),
262
+ rejectedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.rejectedTimestamp),
263
+ holdTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.holdTimestamp),
264
+ acceptedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.acceptedTimestamp),
265
+ sellerToDropOffTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerToDropOffTimestamp),
266
+ sellerToShipTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerToShipTimestamp),
267
+ sellerToGetPickUpTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerToGetPickUpTimestamp),
268
+ qualityControlTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.qualityControlTimestamp),
269
+ pendingPublicationTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.pendingPublicationTimestamp),
270
+ listedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.listedTimestamp),
271
+ clearanceTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.clearanceTimestamp),
272
+ reservedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.reservedTimestamp),
273
+ soldTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.soldTimestamp),
274
+ returnedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.returnedTimestamp),
275
+ soldSellerToBePaidTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.soldSellerToBePaidTimestamp),
276
+ soldSellerPaidTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.soldSellerPaidTimestamp),
277
+ sellerSelfRejectTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerSelfRejectTimestamp),
278
+ liquidationRequestedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.liquidationRequestedTimestamp),
279
+ sellerLiquidatedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerLiquidatedTimestamp),
280
+ availableForSale: !!this.attributes.availableForSale,
281
+ color: this.utilities.sanitizeString(this.filterAttributes.color),
282
+ description: this.utilities.sanitizeString(this.attributes.description),
283
+ discountType: this.utilities.sanitizeString(this.consignmentAttributes.discountType),
284
+ discountValue: this.utilities.sanitizeNumber(this.consignmentAttributes.discountValue, 0),
285
+ id: this.utilities.sanitizeString(this.filterAttributes.documentId),
286
+ documentId: this.utilities.sanitizeString(this.filterAttributes.documentId),
287
+ gender: this.utilities.sanitizeString(this.filterAttributes.gender),
288
+ handle: this.utilities.sanitizeString(this.attributes.handle),
289
+ imageUrls: this.utilities.sanitzeStringArr(this.attributes.imageUrls),
290
+ sellRequestImageUrls: this.utilities.sanitzeStringArr(this.consignmentAttributes.sellRequestImageUrls),
291
+ reservedBy: this.utilities.sanitzeStringArr(this.attributes.reservedBy),
292
+ 'materialComposition.names': Object.keys(this.sanitizeMaterialComp()),
293
+ 'inventoryLocations.ids': this.consignmentAttributes.inventoryLocations && Array.isArray(this.consignmentAttributes.inventoryLocations)
294
+ ? this.consignmentAttributes.inventoryLocations.map((c) => String(c.id))
295
+ : [],
296
+ };
297
+ this.consignmentAttributes.inventoryLocations.forEach((l) => {
298
+ if (l.id) {
299
+ stagedObj[`inventoryLocations.${l.id}.availableAmount`] = l.availableAmount || 0;
300
+ stagedObj[`inventoryLocations.${l.id}.incomingAmount`] = l.incomingAmount || 0;
301
+ }
302
+ });
303
+ Object.values(this.sanitizeMaterialComp()).forEach((v, i) => {
304
+ if (v) {
305
+ stagedObj[`materialComposition.${Object.keys(this.sanitizeMaterialComp())[i]}.value`] = v;
306
+ }
307
+ });
308
+ return stagedObj;
309
+ }
228
310
  updateSelfFromTranslatedTextArray(translatedTextArray = []) {
229
311
  const checkFieldTranslated = (val) => {
230
312
  return val !== this.FIELD_NOT_TRANSLATABLE_KEY;
@@ -323,6 +405,271 @@ class Product extends Base_1.default {
323
405
  return acc;
324
406
  }, '');
325
407
  }
408
+ generateSchemaForTypesense(name = 'prod_products_202101061') {
409
+ return {
410
+ default_sorting_field: 'createdAtTimestamp',
411
+ fields: [
412
+ {
413
+ facet: true,
414
+ name: 'brand',
415
+ type: 'string',
416
+ },
417
+ {
418
+ facet: true,
419
+ name: 'clothingSize',
420
+ type: 'string[]',
421
+ },
422
+ {
423
+ facet: true,
424
+ name: 'jeanSize',
425
+ type: 'string',
426
+ },
427
+ {
428
+ facet: true,
429
+ name: 'shoeSize',
430
+ type: 'string',
431
+ },
432
+ {
433
+ facet: true,
434
+ name: 'condition',
435
+ type: 'string',
436
+ },
437
+ {
438
+ facet: true,
439
+ optional: true,
440
+ name: 'featuredCollections',
441
+ type: 'string[]',
442
+ },
443
+ {
444
+ facet: true,
445
+ optional: true,
446
+ name: 'isOnSale',
447
+ type: 'string',
448
+ },
449
+ {
450
+ facet: false,
451
+ optional: false,
452
+ name: 'merchants',
453
+ type: 'string[]',
454
+ },
455
+ {
456
+ facet: true,
457
+ name: 'price',
458
+ type: 'float',
459
+ },
460
+ {
461
+ facet: true,
462
+ optional: true,
463
+ name: 'suggestedResalePrice',
464
+ type: 'float',
465
+ },
466
+ {
467
+ facet: true,
468
+ optional: true,
469
+ name: 'salePrice',
470
+ type: 'float',
471
+ },
472
+ {
473
+ facet: false,
474
+ optional: true,
475
+ name: 'compareAtPrice',
476
+ type: 'float',
477
+ },
478
+ {
479
+ facet: false,
480
+ optional: true,
481
+ name: 'costPerItem',
482
+ type: 'float',
483
+ },
484
+ {
485
+ facet: true,
486
+ name: 'priceRange',
487
+ type: 'string',
488
+ },
489
+ {
490
+ facet: true,
491
+ name: 'productCategory',
492
+ type: 'string',
493
+ },
494
+ {
495
+ facet: true,
496
+ name: 'productType',
497
+ type: 'string',
498
+ },
499
+ {
500
+ facet: true,
501
+ name: 'productStyle',
502
+ type: 'string[]',
503
+ },
504
+ {
505
+ facet: true,
506
+ name: 'reRobeCommission',
507
+ type: 'float',
508
+ },
509
+ {
510
+ facet: true,
511
+ optional: true,
512
+ name: 'rfidTag',
513
+ type: 'string',
514
+ },
515
+ {
516
+ facet: true,
517
+ optional: true,
518
+ name: 'salesChannel',
519
+ type: 'string[]',
520
+ },
521
+ {
522
+ facet: true,
523
+ name: 'status',
524
+ type: 'string',
525
+ },
526
+ {
527
+ facet: true,
528
+ optional: true,
529
+ name: 'tags',
530
+ type: 'string[]',
531
+ },
532
+ {
533
+ facet: false,
534
+ name: 'title',
535
+ type: 'string',
536
+ },
537
+ {
538
+ facet: true,
539
+ name: 'vendorName',
540
+ type: 'string',
541
+ },
542
+ {
543
+ facet: true,
544
+ name: 'vendorId',
545
+ type: 'string',
546
+ },
547
+ {
548
+ facet: false,
549
+ optional: true,
550
+ name: '.*Timestamp',
551
+ type: 'int32',
552
+ },
553
+ {
554
+ facet: false,
555
+ name: 'createdAtTimestamp',
556
+ type: 'int32',
557
+ },
558
+ {
559
+ facet: false,
560
+ name: 'updatedAtTimestamp',
561
+ type: 'int32',
562
+ },
563
+ {
564
+ facet: false,
565
+ name: 'availableForSale',
566
+ type: 'bool',
567
+ },
568
+ {
569
+ facet: true,
570
+ name: 'color',
571
+ type: 'string',
572
+ },
573
+ {
574
+ facet: false,
575
+ name: 'description',
576
+ type: 'string',
577
+ },
578
+ {
579
+ facet: false,
580
+ optional: true,
581
+ name: 'discountType',
582
+ type: 'string',
583
+ },
584
+ {
585
+ facet: false,
586
+ optional: true,
587
+ name: 'discountValue',
588
+ type: 'string',
589
+ },
590
+ {
591
+ facet: false,
592
+ name: 'id',
593
+ type: 'string',
594
+ },
595
+ {
596
+ facet: false,
597
+ name: 'documentId',
598
+ type: 'string',
599
+ },
600
+ {
601
+ facet: true,
602
+ name: 'gender',
603
+ type: 'string',
604
+ },
605
+ {
606
+ facet: false,
607
+ optional: true,
608
+ name: 'handle',
609
+ type: 'string',
610
+ },
611
+ {
612
+ facet: false,
613
+ name: 'imageUrls',
614
+ type: 'string[]',
615
+ },
616
+ {
617
+ facet: false,
618
+ name: 'sellRequestImageUrls',
619
+ type: 'string[]',
620
+ },
621
+ {
622
+ facet: false,
623
+ optional: true,
624
+ name: 'notesForProductionTeam',
625
+ type: 'string',
626
+ },
627
+ {
628
+ facet: false,
629
+ optional: true,
630
+ name: 'nextAvailableSeason',
631
+ type: 'string',
632
+ },
633
+ {
634
+ facet: false,
635
+ optional: true,
636
+ name: 'reservedBy',
637
+ type: 'string[]',
638
+ },
639
+ {
640
+ facet: true,
641
+ optional: true,
642
+ name: 'inventoryLocations.ids',
643
+ type: 'string[]',
644
+ },
645
+ {
646
+ facet: true,
647
+ optional: true,
648
+ name: 'inventoryLocations..*.availableAmount',
649
+ type: 'int32',
650
+ },
651
+ {
652
+ facet: true,
653
+ optional: true,
654
+ name: 'inventoryLocations..*.incomingAmount',
655
+ type: 'int32',
656
+ },
657
+ {
658
+ facet: true,
659
+ optional: true,
660
+ name: 'materialComposition.names',
661
+ type: 'string[]',
662
+ },
663
+ {
664
+ facet: true,
665
+ optional: true,
666
+ name: 'materialComposition..*.value',
667
+ type: 'int32',
668
+ },
669
+ ],
670
+ name,
671
+ };
672
+ }
326
673
  materialCompTagsArrayForShopify() {
327
674
  return Object.keys(this.filterAttributes.materialComposition).reduce((acc, cur, idx) => {
328
675
  acc.push(`${cur} ${Object.values(this.filterAttributes.materialComposition)[idx]}`);
@@ -364,5 +711,41 @@ class Product extends Base_1.default {
364
711
  }
365
712
  return materialObj;
366
713
  }
714
+ sanitizeMaterialComp() {
715
+ let materialComp = this.filterAttributes.materialComposition;
716
+ if (materialComp && Array.isArray(materialComp)) {
717
+ materialComp = materialComp.reduce((acc, cur) => {
718
+ const camelKey = this.utilities.camelCase(cur);
719
+ acc[camelKey] = 100;
720
+ return acc;
721
+ }, {});
722
+ }
723
+ if (typeof materialComp !== 'object') {
724
+ materialComp = {};
725
+ }
726
+ if (materialComp && Object.keys(materialComp).length > 0) {
727
+ const mcKeys = Object.keys(materialComp);
728
+ const mcValues = Object.values(materialComp);
729
+ materialComp = mcKeys.reduce((acc, curr, ind) => {
730
+ if (curr.charCodeAt(0) >= 65 && curr.charCodeAt(0) <= 90) {
731
+ return acc;
732
+ }
733
+ const camelKey = this.utilities.camelCase(curr);
734
+ acc[camelKey] = Number(mcValues[ind]);
735
+ return acc;
736
+ }, {});
737
+ }
738
+ return materialComp;
739
+ }
740
+ sanitizeCommission() {
741
+ const com = this.consignmentAttributes.reRobeCommission;
742
+ if (Number.isNaN(parseFloat(String(com)))) {
743
+ return 0.5;
744
+ }
745
+ if (parseFloat(String(com)) <= 1) {
746
+ return parseFloat(String(com));
747
+ }
748
+ return parseFloat(String(com)) / 100;
749
+ }
367
750
  }
368
751
  exports.default = Product;
@@ -69,8 +69,11 @@ declare type ProductConsignmentAttributes = {
69
69
  discountValue: string;
70
70
  selectedForClearance: string;
71
71
  locationIds?: string[];
72
+ inventoryLocations: InventoryLocation[];
72
73
  };
73
74
  declare type ProductTimestampAttributes = {
75
+ createdAtTimestamp: number | null;
76
+ updatedAtTimestamp: number | null;
74
77
  sellRequestReviewTimestamp: number | null;
75
78
  sellRequestReviewDraftTimestamp: number | null;
76
79
  rejectedTimestamp: number | null;
@@ -188,6 +191,7 @@ declare type ProductConsignmentAttributesFormFields = {
188
191
  discountType: SingleSelectFormField<string>;
189
192
  discountValue: TextInputFormField<string>;
190
193
  locationIds: MultiSelectFormField<string>;
194
+ inventoryLocations: MultiSelectFormField<InventoryLocation>;
191
195
  };
192
196
  declare type ProductFormFields = ProductAttributesFormFields & ProductFilterAttributesFormFields & ProductConsignmentAttributesFormFields;
193
197
  interface ParamsForBuildProductInputObjForShopify {
@@ -221,3 +225,73 @@ declare type ProductLineItem = {
221
225
  image: string;
222
226
  quantity: number;
223
227
  };
228
+ declare type InventoryLocation = {
229
+ id: string;
230
+ name: string;
231
+ incomingAmount: number;
232
+ availableAmount: number;
233
+ };
234
+ declare type TypesenseProductObj = {
235
+ brand: string;
236
+ clothingSize: string[];
237
+ jeanSize: string;
238
+ shoeSize: string;
239
+ condition: string;
240
+ featuredCollections: string[];
241
+ isOnSale: string;
242
+ merchants: string[];
243
+ price: number;
244
+ suggestedResalePrice: number;
245
+ salePrice: number;
246
+ compareAtPrice: number;
247
+ costPerItem: number;
248
+ priceRange: string;
249
+ productCategory: string;
250
+ productType: string;
251
+ productStyle: string[];
252
+ reRobeCommission: number;
253
+ rfidTag: string;
254
+ salesChannel: string[];
255
+ status: string;
256
+ tags: string[];
257
+ title: string;
258
+ vendorName: string;
259
+ vendorId: string;
260
+ createdAtTimestamp: number;
261
+ updatedAtTimestamp: number;
262
+ sellRequestReviewTimestamp: number;
263
+ sellRequestReviewDraftTimestamp: number;
264
+ rejectedTimestamp: number;
265
+ holdTimestamp: number;
266
+ acceptedTimestamp: number;
267
+ sellerToDropOffTimestamp: number;
268
+ sellerToShipTimestamp: number;
269
+ sellerToGetPickUpTimestamp: number;
270
+ qualityControlTimestamp: number;
271
+ pendingPublicationTimestamp: number;
272
+ listedTimestamp: number;
273
+ clearanceTimestamp: number;
274
+ reservedTimestamp: number;
275
+ soldTimestamp: number;
276
+ returnedTimestamp: number;
277
+ soldSellerToBePaidTimestamp: number;
278
+ soldSellerPaidTimestamp: number;
279
+ sellerSelfRejectTimestamp: number;
280
+ liquidationRequestedTimestamp: number;
281
+ sellerLiquidatedTimestamp: number;
282
+ availableForSale: boolean;
283
+ color: string;
284
+ description: string;
285
+ discountType: string;
286
+ discountValue: number;
287
+ id: string;
288
+ documentId: string;
289
+ gender: string;
290
+ handle: string;
291
+ imageUrls: string[];
292
+ sellRequestImageUrls: string[];
293
+ reservedBy: string[];
294
+ 'inventoryLocations.ids': string[];
295
+ 'materialComposition.names': string[];
296
+ [key: string]: any;
297
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "2.4.83",
3
+ "version": "2.4.87",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",