rerobe-js-orm 2.4.85 → 2.4.86

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.
@@ -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
  }
@@ -117,7 +117,7 @@ class Product extends Base_1.default {
117
117
  }
118
118
  toPartialObj() {
119
119
  return Object.assign(Object.assign({}, this.attributes), this.filterAttributes);
120
- }
120
+ } // ToDo: Deprecate soon
121
121
  toObj() {
122
122
  return Object.assign(Object.assign(Object.assign(Object.assign({}, this.attributes), this.filterAttributes), this.consignmentAttributes), this.timestampAttributes);
123
123
  }
@@ -228,6 +228,83 @@ class Product extends Base_1.default {
228
228
  condition: this.filterAttributes.condition || this.FIELD_NOT_TRANSLATABLE_KEY,
229
229
  };
230
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
+ createdAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.createdAtTimestamp),
258
+ updatedAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.updatedAtTimestamp),
259
+ sellRequestReviewTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellRequestReviewTimestamp),
260
+ sellRequestReviewDraftTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellRequestReviewDraftTimestamp),
261
+ rejectedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.rejectedTimestamp),
262
+ holdTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.holdTimestamp),
263
+ acceptedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.acceptedTimestamp),
264
+ sellerToDropOffTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerToDropOffTimestamp),
265
+ sellerToShipTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerToShipTimestamp),
266
+ sellerToGetPickUpTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerToGetPickUpTimestamp),
267
+ qualityControlTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.qualityControlTimestamp),
268
+ pendingPublicationTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.pendingPublicationTimestamp),
269
+ listedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.listedTimestamp),
270
+ clearanceTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.clearanceTimestamp),
271
+ reservedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.reservedTimestamp),
272
+ soldTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.soldTimestamp),
273
+ returnedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.returnedTimestamp),
274
+ soldSellerToBePaidTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.soldSellerToBePaidTimestamp),
275
+ soldSellerPaidTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.soldSellerPaidTimestamp),
276
+ sellerSelfRejectTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerSelfRejectTimestamp),
277
+ liquidationRequestedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.liquidationRequestedTimestamp),
278
+ sellerLiquidatedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerLiquidatedTimestamp),
279
+ availableForSale: !!this.attributes.availableForSale,
280
+ color: this.utilities.sanitizeString(this.filterAttributes.color),
281
+ description: this.utilities.sanitizeString(this.attributes.description),
282
+ discountType: this.utilities.sanitizeString(this.consignmentAttributes.discountType),
283
+ discountValue: this.utilities.sanitizeNumber(this.consignmentAttributes.discountValue, 0),
284
+ id: this.utilities.sanitizeString(this.filterAttributes.documentId),
285
+ gender: this.utilities.sanitizeString(this.filterAttributes.gender),
286
+ handle: this.utilities.sanitizeString(this.attributes.handle),
287
+ imageUrls: this.utilities.sanitzeStringArr(this.attributes.imageUrls),
288
+ sellRequestImageUrls: this.utilities.sanitzeStringArr(this.consignmentAttributes.sellRequestImageUrls),
289
+ reservedBy: this.utilities.sanitzeStringArr(this.attributes.reservedBy),
290
+ 'materialComposition.names': Object.keys(this.sanitizeMaterialComp()),
291
+ 'inventoryLocations.ids': this.consignmentAttributes.inventoryLocations && Array.isArray(this.consignmentAttributes.inventoryLocations)
292
+ ? this.consignmentAttributes.inventoryLocations.map((c) => String(c.id))
293
+ : [],
294
+ };
295
+ this.consignmentAttributes.inventoryLocations.forEach((l) => {
296
+ if (l.id) {
297
+ stagedObj[`inventoryLocations.${l.id}.availableAmount`] = l.availableAmount || 0;
298
+ stagedObj[`inventoryLocations.${l.id}.incomingAmount`] = l.incomingAmount || 0;
299
+ }
300
+ });
301
+ Object.values(this.sanitizeMaterialComp()).forEach((v, i) => {
302
+ if (v) {
303
+ stagedObj[`materialComposition.${Object.keys(this.sanitizeMaterialComp())[i]}.value`] = v;
304
+ }
305
+ });
306
+ return stagedObj;
307
+ }
231
308
  updateSelfFromTranslatedTextArray(translatedTextArray = []) {
232
309
  const checkFieldTranslated = (val) => {
233
310
  return val !== this.FIELD_NOT_TRANSLATABLE_KEY;
@@ -326,6 +403,261 @@ class Product extends Base_1.default {
326
403
  return acc;
327
404
  }, '');
328
405
  }
406
+ generateSchemaForTypesense(name = 'prod_products_202101061') {
407
+ return {
408
+ default_sorting_field: 'createdAtTimestamp',
409
+ fields: [
410
+ {
411
+ facet: true,
412
+ name: 'brand',
413
+ type: 'string',
414
+ },
415
+ {
416
+ facet: true,
417
+ name: 'clothingSize',
418
+ type: 'string[]',
419
+ },
420
+ {
421
+ facet: true,
422
+ name: 'jeanSize',
423
+ type: 'string',
424
+ },
425
+ {
426
+ facet: true,
427
+ name: 'shoeSize',
428
+ type: 'string',
429
+ },
430
+ {
431
+ facet: true,
432
+ name: 'condition',
433
+ type: 'string',
434
+ },
435
+ {
436
+ facet: true,
437
+ optional: true,
438
+ name: 'featuredCollections',
439
+ type: 'string[]',
440
+ },
441
+ {
442
+ facet: true,
443
+ optional: true,
444
+ name: 'isOnSale',
445
+ type: 'string',
446
+ },
447
+ {
448
+ facet: false,
449
+ optional: false,
450
+ name: 'merchants',
451
+ type: 'string[]',
452
+ },
453
+ {
454
+ facet: true,
455
+ name: 'price',
456
+ type: 'float',
457
+ },
458
+ {
459
+ facet: true,
460
+ optional: true,
461
+ name: 'suggestedResalePrice',
462
+ type: 'float',
463
+ },
464
+ {
465
+ facet: true,
466
+ optional: true,
467
+ name: 'salePrice',
468
+ type: 'float',
469
+ },
470
+ {
471
+ facet: false,
472
+ optional: true,
473
+ name: 'compareAtPrice',
474
+ type: 'float',
475
+ },
476
+ {
477
+ facet: false,
478
+ optional: true,
479
+ name: 'costPerItem',
480
+ type: 'float',
481
+ },
482
+ {
483
+ facet: true,
484
+ name: 'priceRange',
485
+ type: 'string',
486
+ },
487
+ {
488
+ facet: true,
489
+ name: 'productCategory',
490
+ type: 'string',
491
+ },
492
+ {
493
+ facet: true,
494
+ name: 'productType',
495
+ type: 'string',
496
+ },
497
+ {
498
+ facet: true,
499
+ name: 'productStyle',
500
+ type: 'string[]',
501
+ },
502
+ {
503
+ facet: true,
504
+ name: 'reRobeCommission',
505
+ type: 'float',
506
+ },
507
+ {
508
+ facet: true,
509
+ optional: true,
510
+ name: 'rfidTag',
511
+ type: 'string',
512
+ },
513
+ {
514
+ facet: true,
515
+ optional: true,
516
+ name: 'salesChannel',
517
+ type: 'string[]',
518
+ },
519
+ {
520
+ facet: true,
521
+ name: 'status',
522
+ type: 'string',
523
+ },
524
+ {
525
+ facet: true,
526
+ optional: true,
527
+ name: 'tags',
528
+ type: 'string[]',
529
+ },
530
+ {
531
+ facet: false,
532
+ name: 'title',
533
+ type: 'string',
534
+ },
535
+ {
536
+ facet: true,
537
+ name: 'vendorName',
538
+ type: 'string',
539
+ },
540
+ {
541
+ facet: false,
542
+ optional: true,
543
+ name: '.*Timestamp',
544
+ type: 'int32',
545
+ },
546
+ {
547
+ facet: false,
548
+ name: 'createdAtTimestamp',
549
+ type: 'int32',
550
+ },
551
+ {
552
+ facet: false,
553
+ name: 'updatedAtTimestamp',
554
+ type: 'int32',
555
+ },
556
+ {
557
+ facet: false,
558
+ name: 'availableForSale',
559
+ type: 'bool',
560
+ },
561
+ {
562
+ facet: true,
563
+ name: 'color',
564
+ type: 'string',
565
+ },
566
+ {
567
+ facet: false,
568
+ name: 'description',
569
+ type: 'string',
570
+ },
571
+ {
572
+ facet: false,
573
+ optional: true,
574
+ name: 'discountType',
575
+ type: 'string',
576
+ },
577
+ {
578
+ facet: false,
579
+ optional: true,
580
+ name: 'discountValue',
581
+ type: 'string',
582
+ },
583
+ {
584
+ facet: false,
585
+ name: 'id',
586
+ type: 'string',
587
+ },
588
+ {
589
+ facet: true,
590
+ name: 'gender',
591
+ type: 'string',
592
+ },
593
+ {
594
+ facet: false,
595
+ optional: true,
596
+ name: 'handle',
597
+ type: 'string',
598
+ },
599
+ {
600
+ facet: false,
601
+ name: 'imageUrls',
602
+ type: 'string[]',
603
+ },
604
+ {
605
+ facet: false,
606
+ name: 'sellRequestImageUrls',
607
+ type: 'string[]',
608
+ },
609
+ {
610
+ facet: false,
611
+ optional: true,
612
+ name: 'notesForProductionTeam',
613
+ type: 'string',
614
+ },
615
+ {
616
+ facet: false,
617
+ optional: true,
618
+ name: 'nextAvailableSeason',
619
+ type: 'string',
620
+ },
621
+ {
622
+ facet: false,
623
+ optional: true,
624
+ name: 'reservedBy',
625
+ type: 'string[]',
626
+ },
627
+ {
628
+ facet: true,
629
+ optional: true,
630
+ name: 'inventoryLocations.ids',
631
+ type: 'string[]',
632
+ },
633
+ {
634
+ facet: true,
635
+ optional: true,
636
+ name: 'inventoryLocations..*.availableAmount',
637
+ type: 'int32',
638
+ },
639
+ {
640
+ facet: true,
641
+ optional: true,
642
+ name: 'inventoryLocations..*.incomingAmount',
643
+ type: 'int32',
644
+ },
645
+ {
646
+ facet: true,
647
+ optional: true,
648
+ name: 'materialComposition.names',
649
+ type: 'string[]',
650
+ },
651
+ {
652
+ facet: true,
653
+ optional: true,
654
+ name: 'materialComposition..*.value',
655
+ type: 'int32',
656
+ },
657
+ ],
658
+ name,
659
+ };
660
+ }
329
661
  materialCompTagsArrayForShopify() {
330
662
  return Object.keys(this.filterAttributes.materialComposition).reduce((acc, cur, idx) => {
331
663
  acc.push(`${cur} ${Object.values(this.filterAttributes.materialComposition)[idx]}`);
@@ -367,5 +699,41 @@ class Product extends Base_1.default {
367
699
  }
368
700
  return materialObj;
369
701
  }
702
+ sanitizeMaterialComp() {
703
+ let materialComp = this.filterAttributes.materialComposition;
704
+ if (materialComp && Array.isArray(materialComp)) {
705
+ materialComp = materialComp.reduce((acc, cur) => {
706
+ const camelKey = this.utilities.camelCase(cur);
707
+ acc[camelKey] = 100;
708
+ return acc;
709
+ }, {});
710
+ }
711
+ if (typeof materialComp !== 'object') {
712
+ materialComp = {};
713
+ }
714
+ if (materialComp && Object.keys(materialComp).length > 0) {
715
+ const mcKeys = Object.keys(materialComp);
716
+ const mcValues = Object.values(materialComp);
717
+ materialComp = mcKeys.reduce((acc, curr, ind) => {
718
+ if (curr.charCodeAt(0) >= 65 && curr.charCodeAt(0) <= 90) {
719
+ return acc;
720
+ }
721
+ const camelKey = this.utilities.camelCase(curr);
722
+ acc[camelKey] = Number(mcValues[ind]);
723
+ return acc;
724
+ }, {});
725
+ }
726
+ return materialComp;
727
+ }
728
+ sanitizeCommission() {
729
+ const com = this.consignmentAttributes.reRobeCommission;
730
+ if (Number.isNaN(parseFloat(String(com)))) {
731
+ return 0.5;
732
+ }
733
+ if (parseFloat(String(com)) <= 1) {
734
+ return parseFloat(String(com));
735
+ }
736
+ return parseFloat(String(com)) / 100;
737
+ }
370
738
  }
371
739
  exports.default = Product;
@@ -231,3 +231,65 @@ declare type InventoryLocation = {
231
231
  incomingAmount: number;
232
232
  availableAmount: number;
233
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
+ createdAtTimestamp: number;
260
+ updatedAtTimestamp: number;
261
+ sellRequestReviewTimestamp: number;
262
+ sellRequestReviewDraftTimestamp: number;
263
+ rejectedTimestamp: number;
264
+ holdTimestamp: number;
265
+ acceptedTimestamp: number;
266
+ sellerToDropOffTimestamp: number;
267
+ sellerToShipTimestamp: number;
268
+ sellerToGetPickUpTimestamp: number;
269
+ qualityControlTimestamp: number;
270
+ pendingPublicationTimestamp: number;
271
+ listedTimestamp: number;
272
+ clearanceTimestamp: number;
273
+ reservedTimestamp: number;
274
+ soldTimestamp: number;
275
+ returnedTimestamp: number;
276
+ soldSellerToBePaidTimestamp: number;
277
+ soldSellerPaidTimestamp: number;
278
+ sellerSelfRejectTimestamp: number;
279
+ liquidationRequestedTimestamp: number;
280
+ sellerLiquidatedTimestamp: number;
281
+ availableForSale: boolean;
282
+ color: string;
283
+ description: string;
284
+ discountType: string;
285
+ discountValue: number;
286
+ id: string;
287
+ gender: string;
288
+ handle: string;
289
+ imageUrls: string[];
290
+ sellRequestImageUrls: string[];
291
+ reservedBy: string[];
292
+ 'inventoryLocations.ids': string[];
293
+ 'materialComposition.names': string[];
294
+ [key: string]: any;
295
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "2.4.85",
3
+ "version": "2.4.86",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",