sahab-utils 1.8.5 → 1.8.6

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/dist/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export * from './ts/orderActivity';
10
10
  export * from './ts/push';
11
11
  export * from './ts/utils';
12
12
  export * from './ts/wheel';
13
+ export * from './ts/workingHours';
package/dist/index.js CHANGED
@@ -26,3 +26,4 @@ __exportStar(require("./ts/orderActivity"), exports);
26
26
  __exportStar(require("./ts/push"), exports);
27
27
  __exportStar(require("./ts/utils"), exports);
28
28
  __exportStar(require("./ts/wheel"), exports);
29
+ __exportStar(require("./ts/workingHours"), exports);
@@ -0,0 +1,8 @@
1
+ import { Provider, WorkingHours } from '../constants/types';
2
+ export declare const emptyWorkingHours: () => WorkingHours;
3
+ export declare const allDayWorkingHours: () => WorkingHours;
4
+ /**
5
+ * The hours a provider can be booked in. Slot listing and booking validation both read this, so they cannot disagree: a provider
6
+ * who works 24/7 is open every hour of every day whatever weekly schedule is also stored, and one with none stored is never open.
7
+ */
8
+ export declare function resolveWorkingHours(provider?: Pick<Provider, 'working247' | 'workingHoursV2'> | null): WorkingHours;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.allDayWorkingHours = exports.emptyWorkingHours = void 0;
4
+ exports.resolveWorkingHours = resolveWorkingHours;
5
+ /** One shift that covers a whole calendar day; slot building caps a day at midnight, so this is as long as a shift can be. */
6
+ const ALL_DAY_SHIFT = { start: '00:00', end: '23:59' };
7
+ const DAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
8
+ const weekOf = (shifts) => {
9
+ const week = {};
10
+ DAYS.forEach((day) => {
11
+ week[day] = shifts();
12
+ });
13
+ return week;
14
+ };
15
+ const emptyWorkingHours = () => weekOf(() => []);
16
+ exports.emptyWorkingHours = emptyWorkingHours;
17
+ const allDayWorkingHours = () => weekOf(() => [Object.assign({}, ALL_DAY_SHIFT)]);
18
+ exports.allDayWorkingHours = allDayWorkingHours;
19
+ /**
20
+ * The hours a provider can be booked in. Slot listing and booking validation both read this, so they cannot disagree: a provider
21
+ * who works 24/7 is open every hour of every day whatever weekly schedule is also stored, and one with none stored is never open.
22
+ */
23
+ function resolveWorkingHours(provider) {
24
+ var _a;
25
+ if ((provider === null || provider === void 0 ? void 0 : provider.working247) === true)
26
+ return (0, exports.allDayWorkingHours)();
27
+ return (_a = provider === null || provider === void 0 ? void 0 : provider.workingHoursV2) !== null && _a !== void 0 ? _a : (0, exports.emptyWorkingHours)();
28
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "sahab-utils",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "This package contains types and utils functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "deploy": "npm run build && npm publish",
10
- "test": "npm run build && node tests/loyalty.test.js && node tests/gifts.test.js && node tests/cashback.test.js && node tests/utils.test.js && node tests/wheel.test.js && node tests/calcs.test.js && node tests/orderActivity.test.js && node tests/push.test.js && node tests/broadcast.test.js && node tests/iban.test.js && node tests/cash.test.js"
10
+ "test": "npm run build && node tests/loyalty.test.js && node tests/gifts.test.js && node tests/cashback.test.js && node tests/utils.test.js && node tests/wheel.test.js && node tests/calcs.test.js && node tests/orderActivity.test.js && node tests/push.test.js && node tests/broadcast.test.js && node tests/iban.test.js && node tests/cash.test.js && node tests/workingHours.test.js"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",