@janiscommerce/app-tracking-shift 1.7.0-beta.1 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- import {isArray, isEmptyArray, isNumber} from './utils/helpers';
1
+ import {isArray, isEmptyArray, isNumber} from './helpers';
2
2
  import {INTERNAL_WORKLOGS} from './constant';
3
3
 
4
4
  class Formatter {
@@ -1,6 +1,6 @@
1
1
  import {OFFLINE_DATA} from './constant';
2
2
  import Storage from './db/StorageService';
3
- import {isArray, isEmptyArray} from './utils/helpers';
3
+ import {isArray, isEmptyArray} from './helpers';
4
4
 
5
5
  class OfflineData {
6
6
  get hasData() {
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 './utils/crashlytics';
3
+ import Crashlytics from './helpers/crashlytics';
4
4
  import ShiftWorklogs from './ShiftWorklogs';
5
- import errorParser from './utils/errorParser';
5
+ import errorParser from './helpers/errorParser';
6
6
  import {
7
7
  isArray,
8
8
  isEmptyArray,
@@ -12,8 +12,8 @@ import {
12
12
  isInternetReachable,
13
13
  isValidDate,
14
14
  parseToISOString,
15
- } from './utils/helpers';
16
- import {getStaffAuthorizationData} from './utils/storage';
15
+ } from './helpers';
16
+ import {getStaffAuthorizationData} from './helpers/storage';
17
17
  import {
18
18
  SHIFT_ID,
19
19
  SHIFT_STATUS,
@@ -252,34 +252,34 @@ class Shift {
252
252
  * @param {string} workLog.name => Name related to the work log
253
253
  * @param {string} workLog.type => Type related to the work log
254
254
  * @param {number} workLog.suggestedTime => Suggested time related to the work log
255
- * @param {string|number} metadata.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.
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.
256
256
  * @throws {Error} error
257
257
  * @returns {Promise<string>} workLogId => ID related to the work log that has just been opened for the user
258
258
  */
259
259
 
260
- async openWorkLog(workLog = {}, {startDate} = {}) {
260
+ async openWorkLog(workLog = {}) {
261
261
  let previousWorkLog = {};
262
262
 
263
263
  try {
264
264
  Crashlytics.log('openWorkLog:', workLog);
265
265
 
266
- const currentDate = isValidDate(startDate)
267
- ? parseToISOString(startDate)
268
- : new Date().toISOString();
269
-
270
266
  if (!isValidObject(workLog)) return null;
271
267
 
272
268
  if (!this.hasStaffAuthorization) {
273
269
  this._throwAuthorizationError();
274
270
  }
271
+
272
+ workLog.startDate = isValidDate(workLog.startDate)
273
+ ? parseToISOString(workLog.startDate)
274
+ : new Date().toISOString();
275
+
275
276
  delete workLog.endDate;
276
277
 
277
278
  if (this.hasWorkLogInProgress) {
278
- const {startDate: workLogStart, ...currentRest} = this.getCurrentWorkLog();
279
- previousWorkLog = {
280
- ...currentRest,
281
- endDate: currentDate,
282
- };
279
+ previousWorkLog = this.getCurrentWorkLog();
280
+ delete previousWorkLog.startDate;
281
+
282
+ previousWorkLog.endDate = workLog.startDate;
283
283
  }
284
284
 
285
285
  if (this._hasToPause(workLog.referenceId)) {
@@ -287,7 +287,6 @@ class Shift {
287
287
  }
288
288
 
289
289
  workLog.id = ShiftWorklogs.createId(workLog.referenceId);
290
- workLog.startDate = currentDate;
291
290
  this.setCurrentWorkLog(workLog);
292
291
 
293
292
  const hasInternet = await isInternetReachable();
@@ -326,6 +325,7 @@ class Shift {
326
325
  * Finish a work log in the staff MS and record this event in the time tracking database.
327
326
  * @param {Object} workLog
328
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.
329
329
  * @throws {Error} error
330
330
  * @returns {Promise<string>} workLogId => ID related to the work log that has just been closed for the user
331
331
  */
@@ -352,7 +352,9 @@ class Shift {
352
352
  );
353
353
  }
354
354
 
355
- workLog.endDate = new Date().toISOString();
355
+ workLog.endDate = isValidDate(workLog.endDate)
356
+ ? parseToISOString(workLog.endDate)
357
+ : new Date().toISOString();
356
358
  delete workLog.startDate;
357
359
 
358
360
  if (this.isPaused) {
@@ -1,6 +1,6 @@
1
1
  import {INTERNAL_WORKLOGS} from './constant';
2
2
  import StaffApiServices from './StaffApiServices';
3
- import {generateRandomId, isArray, isEmptyArray} from './utils/helpers';
3
+ import {generateRandomId, isArray, isEmptyArray} from './helpers';
4
4
 
5
5
  class ShiftWorklogs {
6
6
  async open(params) {
@@ -1,5 +1,5 @@
1
- import Request from './utils/request';
2
- import {isValidString} from './utils/helpers';
1
+ import Request from './helpers/request';
2
+ import {isValidString} from './helpers';
3
3
 
4
4
  class StaffApiServices {
5
5
  constructor() {
@@ -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 '../../helpers';
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 '../../helpers';
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 '../../utils/crashlytics';
4
- import errorParser from '../../utils/errorParser';
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 '../utils/provider';
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 '../utils/helpers';
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.1",
3
+ "version": "1.7.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "module": "lib/index.js",
6
6
  "exports": {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes