@janiscommerce/app-tracking-shift 1.7.0-beta.2 → 1.7.0-beta.3

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/Formatter.js CHANGED
@@ -1,4 +1,4 @@
1
- import {isArray, isEmptyArray, isNumber} from './helpers';
1
+ import {isArray, isEmptyArray, isNumber} from '@janiscommerce/apps-helpers';
2
2
  import {INTERNAL_WORKLOGS} from './constant';
3
3
 
4
4
  class Formatter {
@@ -1,6 +1,6 @@
1
+ import {isArray, isEmptyArray} from '@janiscommerce/apps-helpers';
1
2
  import {OFFLINE_DATA} from './constant';
2
3
  import Storage from './db/StorageService';
3
- import {isArray, isEmptyArray} from './helpers';
4
4
 
5
5
  class OfflineData {
6
6
  get hasData() {
package/lib/Shift.js CHANGED
@@ -1,18 +1,10 @@
1
+ import {isArray, isEmptyArray, isNumber} from '@janiscommerce/apps-helpers';
1
2
  import StaffService from './StaffApiServices';
2
3
  import Storage from './db/StorageService';
3
4
  import Crashlytics from './helpers/crashlytics';
4
5
  import ShiftWorklogs from './ShiftWorklogs';
5
6
  import errorParser from './helpers/errorParser';
6
- import {
7
- isArray,
8
- isEmptyArray,
9
- isNumber,
10
- isValidObject,
11
- isApiError,
12
- isInternetReachable,
13
- isValidDate,
14
- parseToISOString,
15
- } from './helpers';
7
+ import {isApiError, isInternetReachable, isValidDate, parseToISOString} from './helpers';
16
8
  import {getStaffAuthorizationData} from './helpers/storage';
17
9
  import {
18
10
  SHIFT_ID,
@@ -263,7 +255,7 @@ class Shift {
263
255
  try {
264
256
  Crashlytics.log('openWorkLog:', workLog);
265
257
 
266
- if (!isValidObject(workLog)) return null;
258
+ if (!ShiftWorklogs.isValidWorkLog(workLog)) return null;
267
259
 
268
260
  if (!this.hasStaffAuthorization) {
269
261
  this._throwAuthorizationError();
@@ -334,7 +326,7 @@ class Shift {
334
326
  try {
335
327
  Crashlytics.log('finishWorkLog:', workLog);
336
328
 
337
- if (!isValidObject(workLog)) return null;
329
+ if (!ShiftWorklogs.isValidWorkLog(workLog)) return null;
338
330
 
339
331
  if (!this.hasStaffAuthorization) {
340
332
  this._throwAuthorizationError();
@@ -342,7 +334,7 @@ class Shift {
342
334
 
343
335
  const currentWorkLog = this.getCurrentWorkLog();
344
336
 
345
- if (!isValidObject(currentWorkLog)) {
337
+ if (!ShiftWorklogs.isValidWorkLog(currentWorkLog)) {
346
338
  throw new Error('There is no active worklog to close');
347
339
  }
348
340
 
@@ -408,7 +400,7 @@ class Shift {
408
400
 
409
401
  return {
410
402
  ...(!!id && {id}),
411
- ...(isValidObject(data) && {...data}),
403
+ ...(ShiftWorklogs.isValidWorkLog(data) && {...data}),
412
404
  };
413
405
  }
414
406
 
@@ -1,6 +1,12 @@
1
+ import {
2
+ isObject,
3
+ isEmptyObject,
4
+ isArray,
5
+ isEmptyArray,
6
+ generateRandomId,
7
+ } from '@janiscommerce/apps-helpers';
1
8
  import {INTERNAL_WORKLOGS} from './constant';
2
9
  import StaffApiServices from './StaffApiServices';
3
- import {generateRandomId, isArray, isEmptyArray} from './helpers';
4
10
 
5
11
  class ShiftWorklogs {
6
12
  async open(params) {
@@ -101,6 +107,10 @@ class ShiftWorklogs {
101
107
  })
102
108
  .filter(Boolean);
103
109
  }
110
+
111
+ isValidWorkLog(workLog = {}) {
112
+ return isObject(workLog) && !isEmptyObject(workLog);
113
+ }
104
114
  }
105
115
 
106
116
  export default new ShiftWorklogs();
@@ -1,5 +1,5 @@
1
+ import {isString} from '@janiscommerce/apps-helpers';
1
2
  import Request from './helpers/request';
2
- import {isValidString} from './helpers';
3
3
 
4
4
  class StaffApiServices {
5
5
  constructor() {
@@ -19,7 +19,7 @@ class StaffApiServices {
19
19
  service: this.service,
20
20
  namespace: 'shift-open',
21
21
  body: {
22
- ...(isValidString(warehouseId) && {warehouseId}),
22
+ ...(isString(warehouseId) && !!warehouseId && {warehouseId}),
23
23
  },
24
24
  });
25
25
  } catch (error) {
@@ -40,7 +40,7 @@ class StaffApiServices {
40
40
  service: this.service,
41
41
  namespace: 'shift-update',
42
42
  body: {
43
- ...(isValidString(warehouseId) && {warehouseId}),
43
+ ...(isString(warehouseId) && !!warehouseId && {warehouseId}),
44
44
  },
45
45
  });
46
46
  } catch (error) {
@@ -1,49 +1,30 @@
1
+ import {isNumber, isString} from '@janiscommerce/apps-helpers';
2
+
1
3
  export {default as isApiError} from './isApiError';
2
4
 
3
5
  export {default as isInternetReachable} from './isInternetReachable';
4
6
 
5
- export const generateRandomId = () => Math.random().toString(32).slice(2);
6
-
7
- export const isFunction = (fn) => !!({}.toString.call(fn) === '[object Function]');
8
-
9
- export const isObject = (obj) => !!(obj && obj.constructor === Object);
10
-
11
- export const isEmptyObject = (obj) => isObject(obj) && !Object.keys(obj).length;
12
-
13
- export const promiseWrapper = (promise) =>
14
- promise.then((data) => [data, null]).catch((error) => Promise.resolve([null, error]));
15
-
16
- export const isArray = (arr) => Array.isArray(arr);
17
-
18
- export const isEmptyArray = (arr) => isArray(arr) && !arr.length;
19
-
20
7
  export const reverseArray = (arr) => arr.slice().reverse();
21
8
 
22
- export const isNumber = (num) => typeof num === 'number' && !Number.isNaN(Number(num));
23
-
24
- export const isValidObject = (obj) => isObject(obj) && !!Object.keys(obj).length;
25
-
26
- export const isValidString = (str) => typeof str === 'string' && str.length > 0;
27
-
28
9
  const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
29
- export const isIsoStringDate = (str) => ISO_DATE_REGEX.test(str);
10
+ const isIsoStringDate = (str) => ISO_DATE_REGEX.test(str);
30
11
 
31
12
  export const isValidDate = (date = '') => {
32
13
  if (isNumber(date) && date > 0) {
33
14
  const dateTime = new Date(date).getTime();
34
- return !Number.isNaN(dateTime);
15
+ return isNumber(dateTime);
35
16
  }
36
- if (!isValidString(date)) return false;
17
+ if (!isString(date) || !date?.length) return false;
37
18
 
38
19
  if (!isIsoStringDate(date)) return false;
39
20
 
40
21
  const dateTime = new Date(date).getTime();
41
- return !Number.isNaN(dateTime);
22
+ return isNumber(dateTime);
42
23
  };
43
24
 
44
25
  export const parseToISOString = (date = '') => {
45
26
  if (isNumber(date) && date > 0) return new Date(date).toISOString();
46
- if (!isValidString(date)) return '';
27
+ if (!isString(date) || !date?.length) return '';
47
28
 
48
29
  return date;
49
30
  };
@@ -1,9 +1,9 @@
1
+ import {isFunction} from '@janiscommerce/apps-helpers';
1
2
  import Shift from '../../../Shift';
2
3
  import {getWorkLogTypesData} from '../../storage';
3
4
  import {WORKLOG_TYPES_DATA, WORKLOG_TYPES_EXPIRATION_TIME} from '../../../constant';
4
5
  import Storage from '../../../db/StorageService';
5
6
  import Crashlytics from '../../crashlytics';
6
- import {isFunction} from '../..';
7
7
  import errorParser from '../../errorParser';
8
8
 
9
9
  const downloadWorkLogTypes = async (onDownloadError) => {
@@ -1,7 +1,7 @@
1
+ import {isFunction} from '@janiscommerce/apps-helpers';
1
2
  import Crashlytics from '../../crashlytics';
2
3
  import getUserId from '../../userInfo/getUserId';
3
4
  import Shift from '../../../Shift';
4
- import {isFunction} from '../..';
5
5
  import errorParser from '../../errorParser';
6
6
 
7
7
  const openShift = async ({onOpenShiftError, warehouseId}) => {
@@ -1,4 +1,5 @@
1
1
  import React, {useEffect, useMemo, useState} from 'react';
2
+ import {promiseWrapper} from '@janiscommerce/apps-helpers';
2
3
  import {useStorageValue} from '../hooks/useStorageValue';
3
4
  import ShiftTrackingContext from '../context/ShiftTrackingContext';
4
5
  import {
@@ -17,8 +18,8 @@ import {
17
18
  STAFF_AUTH,
18
19
  WORKLOG_TYPES_DATA,
19
20
  } from '../constant';
20
- import {isValidObject, promiseWrapper} from '../helpers';
21
21
  import Shift from '../Shift';
22
+ import ShiftWorklogs from '../ShiftWorklogs';
22
23
 
23
24
  /**
24
25
  * ShiftTrackingProvider component
@@ -145,11 +146,11 @@ const ShiftTrackingProvider = ({children, additionalInfo = {}, onError = null})
145
146
  const [currentWorkLog = {}] = openWorkLogs;
146
147
  const isExcludedWork = EXCLUDED_WORKLOG_TYPES.includes(currentWorkLog?.referenceId);
147
148
 
148
- if (isValidObject(currentWorkLog)) {
149
+ if (ShiftWorklogs.isValidWorkLog(currentWorkLog)) {
149
150
  Shift.setCurrentWorkLog(currentWorkLog);
150
151
  }
151
152
 
152
- if (isValidObject(currentWorkLog) && !isExcludedWork) {
153
+ if (ShiftWorklogs.isValidWorkLog(currentWorkLog) && !isExcludedWork) {
153
154
  Shift.status = 'paused';
154
155
  }
155
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janiscommerce/app-tracking-shift",
3
- "version": "1.7.0-beta.2",
3
+ "version": "1.7.0-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "module": "lib/index.js",
6
6
  "exports": {
@@ -60,6 +60,7 @@
60
60
  "@janiscommerce/app-crashlytics": "^2.1.0",
61
61
  "@janiscommerce/app-request": "^2.6.0",
62
62
  "@janiscommerce/app-storage": "^1.1.0",
63
+ "@janiscommerce/apps-helpers": "^2.2.0",
63
64
  "@janiscommerce/oauth-native": "^1.10.2",
64
65
  "@testing-library/react": "^16.3.0",
65
66
  "@testing-library/react-native": "^12.0.1",
@@ -81,8 +82,8 @@
81
82
  "react": "18.2.0",
82
83
  "react-native": "0.71.6",
83
84
  "react-native-device-info": "^10.12.0",
84
- "react-native-mmkv": "2.12.2",
85
85
  "react-native-inappbrowser-reborn": "^3.7.0",
86
+ "react-native-mmkv": "2.12.2",
86
87
  "react-test-renderer": "18.2.0"
87
88
  }
88
89
  }