rerobe-js-orm 3.0.11 → 3.0.13

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.
@@ -21,4 +21,10 @@ export default class Utilities {
21
21
  firstName: string;
22
22
  lastName: string;
23
23
  };
24
+ formatTimestamp(timestampMillis: number): {
25
+ createdAtHour: string;
26
+ createdAtDay: string;
27
+ createdAtMonth: string;
28
+ createdAtYear: string;
29
+ };
24
30
  }
@@ -146,5 +146,30 @@ class Utilities {
146
146
  }
147
147
  return res;
148
148
  }
149
+ formatTimestamp(timestampMillis) {
150
+ if (typeof timestampMillis !== 'number' || Number.isNaN(new Date(timestampMillis).valueOf())) {
151
+ return {
152
+ createdAtHour: '',
153
+ createdAtDay: '',
154
+ createdAtMonth: '',
155
+ createdAtYear: '',
156
+ };
157
+ }
158
+ const dateObj = new Date(timestampMillis);
159
+ const year = dateObj.getUTCFullYear();
160
+ const month = (dateObj.getUTCMonth() + 1).toString().padStart(2, '0'); // Months are 0-indexed in JS
161
+ const day = dateObj.getUTCDate().toString().padStart(2, '0');
162
+ const hour = dateObj.getUTCHours().toString().padStart(2, '0');
163
+ const createdAtHour = `${year}-${month}-${day} ${hour}`;
164
+ const createdAtDay = `${year}-${month}-${day}`;
165
+ const createdAtMonth = `${year}-${month}`;
166
+ const createdAtYear = `${year}`;
167
+ return {
168
+ createdAtHour,
169
+ createdAtDay,
170
+ createdAtMonth,
171
+ createdAtYear,
172
+ };
173
+ }
149
174
  }
150
175
  exports.default = Utilities;
@@ -103,11 +103,17 @@ export default class Order extends Base {
103
103
  toObj(): ReRobeOrderObj;
104
104
  generateSchemaForTypesense(name?: string): {
105
105
  default_sorting_field: string;
106
- fields: {
106
+ fields: ({
107
107
  facet: boolean;
108
108
  name: string;
109
109
  type: string;
110
- }[];
110
+ optional?: undefined;
111
+ } | {
112
+ facet: boolean;
113
+ name: string;
114
+ type: string;
115
+ optional: boolean;
116
+ })[];
111
117
  name: string;
112
118
  };
113
119
  toObjForTypesense(): TypesenseOrderObj;
@@ -308,6 +308,24 @@ class Order extends Base_1.default {
308
308
  name: 'merchantId',
309
309
  type: 'string',
310
310
  },
311
+ {
312
+ facet: true,
313
+ name: 'createdAtHour',
314
+ type: 'string',
315
+ optional: true,
316
+ },
317
+ {
318
+ facet: true,
319
+ name: 'createdAtDay',
320
+ type: 'string',
321
+ optional: true,
322
+ },
323
+ {
324
+ facet: true,
325
+ name: 'createdAtMonth',
326
+ type: 'string',
327
+ optional: true,
328
+ },
311
329
  ],
312
330
  name: 'dev_orders_20220809',
313
331
  };
@@ -316,11 +334,17 @@ class Order extends Base_1.default {
316
334
  const image = this.lineItems && this.lineItems[0] && this.lineItems[0].image && this.lineItems[0].image.originalSrc
317
335
  ? this.lineItems[0].image.originalSrc
318
336
  : 'https://res.cloudinary.com/ribbn/image/fetch/e_blur:1000,o_20,q_50/https://cdn.shopify.com/s/files/1/0261/9686/9172/products/7AC16810-F519-4665-8891-7163EB29FBB7_1000x1000.jpg%3Fv%3D1634827512';
337
+ const createdAtTimestamp = this.utilities.sanitizeMillisTimeStamp(this.createdAtTimestamp);
338
+ const { createdAtHour, createdAtDay, createdAtMonth, createdAtYear } = this.utilities.formatTimestamp(createdAtTimestamp);
319
339
  const stagedObj = {
320
340
  id: this.utilities.sanitizeString(this.documentId),
321
341
  documentId: this.utilities.sanitizeString(this.documentId),
322
342
  userId: this.utilities.sanitizeString(this.userId),
323
- createdAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.createdAtTimestamp),
343
+ createdAtTimestamp,
344
+ createdAtHour,
345
+ createdAtDay,
346
+ createdAtMonth,
347
+ createdAtYear,
324
348
  updatedAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.updatedAtTimestamp),
325
349
  merchantId: this.utilities.sanitizeString(this.merchantId),
326
350
  image: this.utilities.sanitizeString(image),
@@ -24,9 +24,9 @@ export default class Product extends Base {
24
24
  optional?: undefined;
25
25
  } | {
26
26
  facet: boolean;
27
- optional: boolean;
28
27
  name: string;
29
28
  type: string;
29
+ optional: boolean;
30
30
  })[];
31
31
  name: string;
32
32
  };
@@ -261,6 +261,8 @@ class Product extends Base_1.default {
261
261
  };
262
262
  }
263
263
  toObjForTypesense() {
264
+ const createdAtTimestamp = this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.createdAtTimestamp);
265
+ const { createdAtHour, createdAtDay, createdAtMonth, createdAtYear } = this.utilities.formatTimestamp(createdAtTimestamp);
264
266
  const stagedObj = {
265
267
  brand: this.utilities.sanitizeString(this.filterAttributes.brand),
266
268
  size: this.utilities.sanitizeString(this.filterAttributes.size),
@@ -290,7 +292,11 @@ class Product extends Base_1.default {
290
292
  title: this.utilities.sanitizeString(this.attributes.title),
291
293
  vendorName: this.utilities.sanitizeString(this.attributes.vendorName),
292
294
  vendorId: this.utilities.sanitizeString(this.attributes.vendorId),
293
- createdAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.createdAtTimestamp),
295
+ createdAtTimestamp,
296
+ createdAtHour,
297
+ createdAtDay,
298
+ createdAtMonth,
299
+ createdAtYear,
294
300
  updatedAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.updatedAtTimestamp),
295
301
  sellRequestReviewTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellRequestReviewTimestamp),
296
302
  sellRequestReviewDraftTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellRequestReviewDraftTimestamp),
@@ -463,6 +469,7 @@ class Product extends Base_1.default {
463
469
  facet: true,
464
470
  name: 'size',
465
471
  type: 'string',
472
+ optional: true,
466
473
  },
467
474
  {
468
475
  facet: true,
@@ -738,6 +745,24 @@ class Product extends Base_1.default {
738
745
  name: 'materialComposition..*.value',
739
746
  type: 'int32',
740
747
  },
748
+ {
749
+ facet: true,
750
+ name: 'createdAtHour',
751
+ type: 'string',
752
+ optional: true,
753
+ },
754
+ {
755
+ facet: true,
756
+ name: 'createdAtDay',
757
+ type: 'string',
758
+ optional: true,
759
+ },
760
+ {
761
+ facet: true,
762
+ name: 'createdAtMonth',
763
+ type: 'string',
764
+ optional: true,
765
+ },
741
766
  ],
742
767
  name,
743
768
  };
@@ -50,11 +50,17 @@ export default class User extends Base {
50
50
  toCustomerInputObjForRibbn(): RibbnCustomerObj;
51
51
  generateSchemaForTypesense(name?: string): {
52
52
  default_sorting_field: string;
53
- fields: {
53
+ fields: ({
54
54
  facet: boolean;
55
55
  name: string;
56
56
  type: string;
57
- }[];
57
+ optional?: undefined;
58
+ } | {
59
+ facet: boolean;
60
+ name: string;
61
+ type: string;
62
+ optional: boolean;
63
+ })[];
58
64
  name: string;
59
65
  };
60
66
  toObjForTypesense(merchantId: string): TypesenseUserObj;
@@ -295,16 +295,40 @@ class User extends Base_1.default {
295
295
  name: 'registrationSource',
296
296
  type: 'string',
297
297
  },
298
+ {
299
+ facet: true,
300
+ name: 'createdAtHour',
301
+ type: 'string',
302
+ optional: true,
303
+ },
304
+ {
305
+ facet: true,
306
+ name: 'createdAtDay',
307
+ type: 'string',
308
+ optional: true,
309
+ },
310
+ {
311
+ facet: true,
312
+ name: 'createdAtMonth',
313
+ type: 'string',
314
+ optional: true,
315
+ },
298
316
  ],
299
317
  name: 'prod_customers_20220907',
300
318
  };
301
319
  }
302
320
  toObjForTypesense(merchantId) {
321
+ const createdAtTimestamp = this.utilities.sanitizeMillisTimeStamp(this.createdAtTimestamp);
322
+ const { createdAtHour, createdAtDay, createdAtMonth, createdAtYear } = this.utilities.formatTimestamp(createdAtTimestamp);
303
323
  const stagedObj = {
304
324
  id: this.utilities.sanitizeString(this.documentId),
305
325
  documentId: this.utilities.sanitizeString(this.documentId),
306
326
  userId: this.utilities.sanitizeString(this.uid),
307
- createdAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.createdAtTimestamp),
327
+ createdAtTimestamp,
328
+ createdAtHour,
329
+ createdAtDay,
330
+ createdAtMonth,
331
+ createdAtYear,
308
332
  updatedAtTimestamp: this.utilities.sanitizeMillisTimeStamp(this.updatedAtTimestamp),
309
333
  merchantId: this.utilities.sanitizeString(merchantId),
310
334
  firstName: this.utilities.sanitizeString(this.firstName),
@@ -763,4 +763,8 @@ declare type TypesenseOrderObj = {
763
763
  productBrands: string[];
764
764
  tags: string[];
765
765
  merchantId: string;
766
+ createdAtDay: string;
767
+ createdAtMonth: string;
768
+ createdAtHour: string;
769
+ createdAtYear: string;
766
770
  };
@@ -299,5 +299,9 @@ declare type TypesenseProductObj = {
299
299
  reservedBy: string[];
300
300
  'inventoryLocations.ids': string[];
301
301
  'materialComposition.names': string[];
302
+ createdAtDay: string;
303
+ createdAtMonth: string;
304
+ createdAtHour: string;
305
+ createdAtYear: string;
302
306
  [key: string]: any;
303
307
  };
@@ -164,4 +164,8 @@ declare type TypesenseUserObj = {
164
164
  lastOrderTimestamp: number;
165
165
  lastUploadTimestamp: number;
166
166
  registrationSource: string;
167
+ createdAtHour: string;
168
+ createdAtDay: string;
169
+ createdAtMonth: string;
170
+ createdAtYear: string;
167
171
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",