@janiscommerce/app-tracking-shift 1.7.0-beta.0 → 1.7.0-beta.2
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 +1 -1
- package/lib/OfflineData.js +1 -1
- package/lib/Shift.js +23 -16
- package/lib/ShiftWorklogs.js +1 -1
- package/lib/StaffApiServices.js +2 -2
- package/lib/{utils/helpers → helpers}/index.js +23 -0
- package/lib/{utils → helpers}/provider/downloadWorkLogTypes/index.js +1 -1
- package/lib/{utils → helpers}/provider/openShift/index.js +1 -1
- package/lib/hooks/useStorageValue/index.js +2 -2
- package/lib/provider/ShiftTrackingProvider.js +2 -2
- package/package.json +3 -5
- /package/lib/{utils → helpers}/crashlytics/index.js +0 -0
- /package/lib/{utils → helpers}/errorParser/index.js +0 -0
- /package/lib/{utils/helpers → helpers}/isApiError/index.js +0 -0
- /package/lib/{utils/helpers → helpers}/isInternetReachable/index.js +0 -0
- /package/lib/{utils → helpers}/provider/getShiftWorkLogsFromJanis/index.js +0 -0
- /package/lib/{utils → helpers}/provider/index.js +0 -0
- /package/lib/{utils → helpers}/provider/isAuthorizedToUseStaffMS/index.js +0 -0
- /package/lib/{utils → helpers}/request/index.js +0 -0
- /package/lib/{utils → helpers}/storage/getStaffAuthorizationData/index.js +0 -0
- /package/lib/{utils → helpers}/storage/getWorkLogTypesData/index.js +0 -0
- /package/lib/{utils → helpers}/storage/index.js +0 -0
- /package/lib/{utils → helpers}/userInfo/getUserId/index.js +0 -0
package/lib/Formatter.js
CHANGED
package/lib/OfflineData.js
CHANGED
package/lib/Shift.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import StaffService from './StaffApiServices';
|
|
2
2
|
import Storage from './db/StorageService';
|
|
3
|
-
import Crashlytics from './
|
|
3
|
+
import Crashlytics from './helpers/crashlytics';
|
|
4
4
|
import ShiftWorklogs from './ShiftWorklogs';
|
|
5
|
-
import errorParser from './
|
|
5
|
+
import errorParser from './helpers/errorParser';
|
|
6
6
|
import {
|
|
7
7
|
isArray,
|
|
8
8
|
isEmptyArray,
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
isValidObject,
|
|
11
11
|
isApiError,
|
|
12
12
|
isInternetReachable,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
isValidDate,
|
|
14
|
+
parseToISOString,
|
|
15
|
+
} from './helpers';
|
|
16
|
+
import {getStaffAuthorizationData} from './helpers/storage';
|
|
16
17
|
import {
|
|
17
18
|
SHIFT_ID,
|
|
18
19
|
SHIFT_STATUS,
|
|
@@ -251,13 +252,13 @@ class Shift {
|
|
|
251
252
|
* @param {string} workLog.name => Name related to the work log
|
|
252
253
|
* @param {string} workLog.type => Type related to the work log
|
|
253
254
|
* @param {number} workLog.suggestedTime => Suggested time related to the work log
|
|
255
|
+
* @param {string|number} workLog.startDate => Start date related to the work log. Accepts an ISO 8601 string (e.g. "2026-03-05T10:00:00.000Z") or milliseconds since epoch (e.g. 1709636400000). Defaults to current date if omitted or invalid.
|
|
254
256
|
* @throws {Error} error
|
|
255
257
|
* @returns {Promise<string>} workLogId => ID related to the work log that has just been opened for the user
|
|
256
258
|
*/
|
|
257
259
|
|
|
258
260
|
async openWorkLog(workLog = {}) {
|
|
259
261
|
let previousWorkLog = {};
|
|
260
|
-
const currentDate = new Date().toISOString();
|
|
261
262
|
|
|
262
263
|
try {
|
|
263
264
|
Crashlytics.log('openWorkLog:', workLog);
|
|
@@ -267,14 +268,18 @@ class Shift {
|
|
|
267
268
|
if (!this.hasStaffAuthorization) {
|
|
268
269
|
this._throwAuthorizationError();
|
|
269
270
|
}
|
|
271
|
+
|
|
272
|
+
workLog.startDate = isValidDate(workLog.startDate)
|
|
273
|
+
? parseToISOString(workLog.startDate)
|
|
274
|
+
: new Date().toISOString();
|
|
275
|
+
|
|
270
276
|
delete workLog.endDate;
|
|
271
277
|
|
|
272
278
|
if (this.hasWorkLogInProgress) {
|
|
273
|
-
|
|
274
|
-
previousWorkLog
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
};
|
|
279
|
+
previousWorkLog = this.getCurrentWorkLog();
|
|
280
|
+
delete previousWorkLog.startDate;
|
|
281
|
+
|
|
282
|
+
previousWorkLog.endDate = workLog.startDate;
|
|
278
283
|
}
|
|
279
284
|
|
|
280
285
|
if (this._hasToPause(workLog.referenceId)) {
|
|
@@ -282,7 +287,6 @@ class Shift {
|
|
|
282
287
|
}
|
|
283
288
|
|
|
284
289
|
workLog.id = ShiftWorklogs.createId(workLog.referenceId);
|
|
285
|
-
workLog.startDate = currentDate;
|
|
286
290
|
this.setCurrentWorkLog(workLog);
|
|
287
291
|
|
|
288
292
|
const hasInternet = await isInternetReachable();
|
|
@@ -321,6 +325,7 @@ class Shift {
|
|
|
321
325
|
* Finish a work log in the staff MS and record this event in the time tracking database.
|
|
322
326
|
* @param {Object} workLog
|
|
323
327
|
* @param {string} workLog.referenceId => Reference ID related to the work log
|
|
328
|
+
* @param {string|number} workLog.endDate => End date related to the work log. Accepts an ISO 8601 string (e.g. "2026-03-05T10:00:00.000Z") or milliseconds since epoch (e.g. 1709636400000). Defaults to current date if omitted or invalid.
|
|
324
329
|
* @throws {Error} error
|
|
325
330
|
* @returns {Promise<string>} workLogId => ID related to the work log that has just been closed for the user
|
|
326
331
|
*/
|
|
@@ -347,7 +352,9 @@ class Shift {
|
|
|
347
352
|
);
|
|
348
353
|
}
|
|
349
354
|
|
|
350
|
-
workLog.endDate =
|
|
355
|
+
workLog.endDate = isValidDate(workLog.endDate)
|
|
356
|
+
? parseToISOString(workLog.endDate)
|
|
357
|
+
: new Date().toISOString();
|
|
351
358
|
delete workLog.startDate;
|
|
352
359
|
|
|
353
360
|
if (this.isPaused) {
|
|
@@ -448,15 +455,15 @@ class Shift {
|
|
|
448
455
|
if (!this.hasPendingData) return null;
|
|
449
456
|
|
|
450
457
|
const storageData = this._getOffLineWorkLogs();
|
|
451
|
-
const
|
|
458
|
+
const formattedWorkLogs = ShiftWorklogs.formatForJanis(storageData);
|
|
452
459
|
|
|
453
|
-
if (isEmptyArray(
|
|
460
|
+
if (isEmptyArray(formattedWorkLogs)) return null;
|
|
454
461
|
|
|
455
462
|
if (this.isClosed()) {
|
|
456
463
|
await this.reOpen();
|
|
457
464
|
}
|
|
458
465
|
|
|
459
|
-
await ShiftWorklogs.batch(
|
|
466
|
+
await ShiftWorklogs.batch(formattedWorkLogs);
|
|
460
467
|
OfflineData.deleteAll();
|
|
461
468
|
return null;
|
|
462
469
|
} catch (error) {
|
package/lib/ShiftWorklogs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {INTERNAL_WORKLOGS} from './constant';
|
|
2
2
|
import StaffApiServices from './StaffApiServices';
|
|
3
|
-
import {generateRandomId, isArray, isEmptyArray} from './
|
|
3
|
+
import {generateRandomId, isArray, isEmptyArray} from './helpers';
|
|
4
4
|
|
|
5
5
|
class ShiftWorklogs {
|
|
6
6
|
async open(params) {
|
package/lib/StaffApiServices.js
CHANGED
|
@@ -24,3 +24,26 @@ export const isNumber = (num) => typeof num === 'number' && !Number.isNaN(Number
|
|
|
24
24
|
export const isValidObject = (obj) => isObject(obj) && !!Object.keys(obj).length;
|
|
25
25
|
|
|
26
26
|
export const isValidString = (str) => typeof str === 'string' && str.length > 0;
|
|
27
|
+
|
|
28
|
+
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);
|
|
30
|
+
|
|
31
|
+
export const isValidDate = (date = '') => {
|
|
32
|
+
if (isNumber(date) && date > 0) {
|
|
33
|
+
const dateTime = new Date(date).getTime();
|
|
34
|
+
return !Number.isNaN(dateTime);
|
|
35
|
+
}
|
|
36
|
+
if (!isValidString(date)) return false;
|
|
37
|
+
|
|
38
|
+
if (!isIsoStringDate(date)) return false;
|
|
39
|
+
|
|
40
|
+
const dateTime = new Date(date).getTime();
|
|
41
|
+
return !Number.isNaN(dateTime);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const parseToISOString = (date = '') => {
|
|
45
|
+
if (isNumber(date) && date > 0) return new Date(date).toISOString();
|
|
46
|
+
if (!isValidString(date)) return '';
|
|
47
|
+
|
|
48
|
+
return date;
|
|
49
|
+
};
|
|
@@ -3,7 +3,7 @@ import {getWorkLogTypesData} from '../../storage';
|
|
|
3
3
|
import {WORKLOG_TYPES_DATA, WORKLOG_TYPES_EXPIRATION_TIME} from '../../../constant';
|
|
4
4
|
import Storage from '../../../db/StorageService';
|
|
5
5
|
import Crashlytics from '../../crashlytics';
|
|
6
|
-
import {isFunction} from '
|
|
6
|
+
import {isFunction} from '../..';
|
|
7
7
|
import errorParser from '../../errorParser';
|
|
8
8
|
|
|
9
9
|
const downloadWorkLogTypes = async (onDownloadError) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Crashlytics from '../../crashlytics';
|
|
2
2
|
import getUserId from '../../userInfo/getUserId';
|
|
3
3
|
import Shift from '../../../Shift';
|
|
4
|
-
import {isFunction} from '
|
|
4
|
+
import {isFunction} from '../..';
|
|
5
5
|
import errorParser from '../../errorParser';
|
|
6
6
|
|
|
7
7
|
const openShift = async ({onOpenShiftError, warehouseId}) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useEffect, useState, useCallback} from 'react';
|
|
2
2
|
import Storage from '../../db/StorageService';
|
|
3
|
-
import Crashlytics from '../../
|
|
4
|
-
import errorParser from '../../
|
|
3
|
+
import Crashlytics from '../../helpers/crashlytics';
|
|
4
|
+
import errorParser from '../../helpers/errorParser';
|
|
5
5
|
|
|
6
6
|
export const useStorageValue = (key, defaultValue = null) => {
|
|
7
7
|
const readValue = useCallback(() => {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
downloadWorkLogTypes,
|
|
7
7
|
isAuthorizedToUseStaffMS,
|
|
8
8
|
getShiftWorkLogsFromJanis,
|
|
9
|
-
} from '../
|
|
9
|
+
} from '../helpers/provider';
|
|
10
10
|
import {
|
|
11
11
|
CURRENT_WORKLOG_DATA,
|
|
12
12
|
CURRENT_WORKLOG_ID,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
STAFF_AUTH,
|
|
18
18
|
WORKLOG_TYPES_DATA,
|
|
19
19
|
} from '../constant';
|
|
20
|
-
import {isValidObject, promiseWrapper} from '../
|
|
20
|
+
import {isValidObject, promiseWrapper} from '../helpers';
|
|
21
21
|
import Shift from '../Shift';
|
|
22
22
|
|
|
23
23
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@janiscommerce/app-tracking-shift",
|
|
3
|
-
"version": "1.7.0-beta.
|
|
3
|
+
"version": "1.7.0-beta.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -49,9 +49,8 @@
|
|
|
49
49
|
"@janiscommerce/app-device-info": "^1.1.0",
|
|
50
50
|
"@janiscommerce/app-request": ">=2.0.0",
|
|
51
51
|
"@janiscommerce/app-storage": ">=1.1.0",
|
|
52
|
-
"react": ">=17.0.2 <
|
|
53
|
-
"react-
|
|
54
|
-
"react-native": ">=0.71.5 <0.82.0"
|
|
52
|
+
"react": ">=17.0.2 <19",
|
|
53
|
+
"react-native": ">=0.67.5 <0.75"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
56
|
"@babel/core": "^7.0.0",
|
|
@@ -80,7 +79,6 @@
|
|
|
80
79
|
"jest-environment-jsdom": "^29.0.0",
|
|
81
80
|
"prettier": "^2.8.8",
|
|
82
81
|
"react": "18.2.0",
|
|
83
|
-
"react-dom": "18.2.0",
|
|
84
82
|
"react-native": "0.71.6",
|
|
85
83
|
"react-native-device-info": "^10.12.0",
|
|
86
84
|
"react-native-mmkv": "2.12.2",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|