@kiminix/tp-client 1.8.0 → 1.10.0
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/menus/discounts/admin-apis.d.ts +7 -0
- package/dist/menus/discounts/admin-apis.js +90 -0
- package/dist/menus/discounts/types/update-discount.d.ts +9 -0
- package/dist/menus/discounts/types/update-discount.js +1 -0
- package/dist/menus/preset/admin-apis.d.ts +1 -1
- package/dist/menus/preset/discounts/admin-apis.d.ts +7 -0
- package/dist/menus/preset/discounts/admin-apis.js +90 -0
- package/dist/menus/preset/discounts/types/update-discount.d.ts +9 -0
- package/dist/menus/preset/discounts/types/update-discount.js +1 -0
- package/dist/menus/preset/types/preset-menu.d.ts +2 -0
- package/dist/menus/types/preset-menu.d.ts +22 -0
- package/dist/menus/types/preset-menu.js +1 -0
- package/dist/utils/date-utils.d.ts +14 -2
- package/dist/utils/date-utils.js +19 -7
- package/dist/utils/menu-utils.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Either } from "purify-ts";
|
|
2
|
+
import { PresetMenu } from "../types/preset-menu";
|
|
3
|
+
import { UpdateDiscountRequest } from "./types/update-discount";
|
|
4
|
+
export declare class PresetMenusDiscountAdminAPIs {
|
|
5
|
+
static update({ token, id, // preset menu id
|
|
6
|
+
day, isAvailable, adultPrice, childPrice, minBookingTotal }: UpdateDiscountRequest): Promise<Either<Error, PresetMenu>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import axios from "axios";
|
|
38
|
+
import { base } from "../../constants";
|
|
39
|
+
import { Left, Right } from "purify-ts";
|
|
40
|
+
// preset-menus module admin APIs
|
|
41
|
+
var PresetMenusDiscountAdminAPIs = /** @class */ (function () {
|
|
42
|
+
function PresetMenusDiscountAdminAPIs() {
|
|
43
|
+
}
|
|
44
|
+
PresetMenusDiscountAdminAPIs.update = function (_a) {
|
|
45
|
+
var token = _a.token, id = _a.id, // preset menu id
|
|
46
|
+
day = _a.day, isAvailable = _a.isAvailable, adultPrice = _a.adultPrice, childPrice = _a.childPrice, minBookingTotal = _a.minBookingTotal;
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
return __generator(this, function (_b) {
|
|
49
|
+
switch (_b.label) {
|
|
50
|
+
case 0: return [4 /*yield*/, axios.patch(base + "/preset-menus/admin/discounts", {
|
|
51
|
+
id: id,
|
|
52
|
+
day: day,
|
|
53
|
+
isAvailable: isAvailable,
|
|
54
|
+
adultPrice: adultPrice,
|
|
55
|
+
childPrice: childPrice,
|
|
56
|
+
minBookingTotal: minBookingTotal
|
|
57
|
+
}, {
|
|
58
|
+
headers: {
|
|
59
|
+
'Authorization': "".concat(token)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
.then(function (response) {
|
|
63
|
+
return Right(response.data);
|
|
64
|
+
})
|
|
65
|
+
// handled error
|
|
66
|
+
.catch(function (error) {
|
|
67
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
68
|
+
// unavailable_business
|
|
69
|
+
// unauthorized
|
|
70
|
+
// unauthenticated
|
|
71
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) == 401)
|
|
72
|
+
return (Left(new Error((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.code)));
|
|
73
|
+
else if (((_d = error.response) === null || _d === void 0 ? void 0 : _d.status) == 404)
|
|
74
|
+
return (Left(new Error("not_found")));
|
|
75
|
+
//invalid_child_discount
|
|
76
|
+
//invalid_adult_discount
|
|
77
|
+
//unauthorized_disable_discount
|
|
78
|
+
else if (((_e = error.response) === null || _e === void 0 ? void 0 : _e.status) == 400)
|
|
79
|
+
return (Left(new Error((_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.code)));
|
|
80
|
+
else
|
|
81
|
+
throw new Error('internal_error', error);
|
|
82
|
+
})];
|
|
83
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return PresetMenusDiscountAdminAPIs;
|
|
89
|
+
}());
|
|
90
|
+
export { PresetMenusDiscountAdminAPIs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PresetMenu } from "./types/preset-menu";
|
|
2
1
|
import { UpdatePresetMenuRequest } from "./types/update-preset-menu";
|
|
3
2
|
import { Either } from "purify-ts";
|
|
3
|
+
import { PresetMenu } from "./types/preset-menu";
|
|
4
4
|
export declare class PresetMenusAdminAPIs {
|
|
5
5
|
static getByBusiness(token?: string): Promise<PresetMenu[]>;
|
|
6
6
|
static getByMenuID(menuId: string, token?: string): Promise<PresetMenu>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Either } from "purify-ts";
|
|
2
|
+
import { PresetMenu } from "../types/preset-menu";
|
|
3
|
+
import { UpdateDiscountRequest } from "./types/update-discount";
|
|
4
|
+
export declare class PresetMenusDiscountAdminAPIs {
|
|
5
|
+
static update({ token, id, // preset menu id
|
|
6
|
+
day, isAvailable, adultPrice, childPrice, minBookingTotal }: UpdateDiscountRequest): Promise<Either<Error, PresetMenu>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import axios from "axios";
|
|
38
|
+
import { base } from "../../../constants";
|
|
39
|
+
import { Left, Right } from "purify-ts";
|
|
40
|
+
// preset-menus module admin APIs
|
|
41
|
+
var PresetMenusDiscountAdminAPIs = /** @class */ (function () {
|
|
42
|
+
function PresetMenusDiscountAdminAPIs() {
|
|
43
|
+
}
|
|
44
|
+
PresetMenusDiscountAdminAPIs.update = function (_a) {
|
|
45
|
+
var token = _a.token, id = _a.id, // preset menu id
|
|
46
|
+
day = _a.day, isAvailable = _a.isAvailable, adultPrice = _a.adultPrice, childPrice = _a.childPrice, minBookingTotal = _a.minBookingTotal;
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
return __generator(this, function (_b) {
|
|
49
|
+
switch (_b.label) {
|
|
50
|
+
case 0: return [4 /*yield*/, axios.patch(base + "/preset-menus/admin/discounts", {
|
|
51
|
+
id: id,
|
|
52
|
+
day: day,
|
|
53
|
+
isAvailable: isAvailable,
|
|
54
|
+
adultPrice: adultPrice,
|
|
55
|
+
childPrice: childPrice,
|
|
56
|
+
minBookingTotal: minBookingTotal
|
|
57
|
+
}, {
|
|
58
|
+
headers: {
|
|
59
|
+
'Authorization': "".concat(token)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
.then(function (response) {
|
|
63
|
+
return Right(response.data);
|
|
64
|
+
})
|
|
65
|
+
// handled error
|
|
66
|
+
.catch(function (error) {
|
|
67
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
68
|
+
// unavailable_business
|
|
69
|
+
// unauthorized
|
|
70
|
+
// unauthenticated
|
|
71
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) == 401)
|
|
72
|
+
return (Left(new Error((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.code)));
|
|
73
|
+
else if (((_d = error.response) === null || _d === void 0 ? void 0 : _d.status) == 404)
|
|
74
|
+
return (Left(new Error("not_found")));
|
|
75
|
+
//invalid_child_discount
|
|
76
|
+
//invalid_adult_discount
|
|
77
|
+
//unauthorized_disable_discount
|
|
78
|
+
else if (((_e = error.response) === null || _e === void 0 ? void 0 : _e.status) == 400)
|
|
79
|
+
return (Left(new Error((_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.code)));
|
|
80
|
+
else
|
|
81
|
+
throw new Error('internal_error', error);
|
|
82
|
+
})];
|
|
83
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return PresetMenusDiscountAdminAPIs;
|
|
89
|
+
}());
|
|
90
|
+
export { PresetMenusDiscountAdminAPIs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Available, LocalDate } from "../../types";
|
|
2
|
+
export interface Price {
|
|
3
|
+
adult: number;
|
|
4
|
+
child?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface DailyDiscount {
|
|
7
|
+
isAvailable: boolean;
|
|
8
|
+
price: Price;
|
|
9
|
+
minBookingTotal?: number;
|
|
10
|
+
minPublishedDiscount: number;
|
|
11
|
+
canDisableAfter?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PresetMenu {
|
|
14
|
+
id: string;
|
|
15
|
+
available?: Available;
|
|
16
|
+
excludedDays?: LocalDate[];
|
|
17
|
+
title: string;
|
|
18
|
+
description: string;
|
|
19
|
+
price: Price;
|
|
20
|
+
minBookingTotal?: number;
|
|
21
|
+
discount?: Map<LocalDate, DailyDiscount>;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @returns Get the seconds timestamp of the given date with truncated minutes and seconds (will be updated every one hour)
|
|
4
|
+
*/
|
|
1
5
|
export declare function getTruncatedTimestamp(): number;
|
|
2
6
|
export declare function dateToString(date: string | Date, options: Intl.DateTimeFormatOptions): string;
|
|
3
7
|
export declare function toStringDefault(date: string | Date, options: Intl.DateTimeFormatOptions): string;
|
|
@@ -5,12 +9,20 @@ export declare function isDayBetween(date: Date, start: Date, end: Date): boolea
|
|
|
5
9
|
export declare function isDayAfter(date: Date, dateToCompare: Date, include?: Boolean): boolean;
|
|
6
10
|
export declare function isDayBefore(date: Date, dateToCompare: Date, include?: Boolean): boolean;
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
9
|
-
* ex: if date is in this format: 20/08/2023 , timezone should not be used
|
|
12
|
+
*
|
|
10
13
|
* @param date
|
|
11
14
|
* @param options
|
|
15
|
+
* @return a string representation of the date in the default format like: vend. 20 août 2023
|
|
16
|
+
*
|
|
17
|
+
* @note timezone should not be set for DateTimeFormatOptions for input without timezone like localdate otherwise info will be wrong.
|
|
18
|
+
* ex: if date is in this format: 20/08/2023 , timezone should not be used
|
|
12
19
|
*/
|
|
13
20
|
export declare function toString(date: string | Date, options?: Intl.DateTimeFormatOptions): string;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param date
|
|
24
|
+
* @returns a string default representation of the date in the Tunisia timezone format (without weekday) like: 25 juin 2022 10:30
|
|
25
|
+
*/
|
|
14
26
|
export declare function toTunisiaLocale(date: string | Date): string;
|
|
15
27
|
/**
|
|
16
28
|
*
|
package/dist/utils/date-utils.js
CHANGED
|
@@ -9,8 +9,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import { differenceInCalendarDays, getUnixTime, isSameDay, parseISO, setMinutes, setSeconds } from "date-fns";
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @returns Get the seconds timestamp of the given date with truncated minutes and seconds (will be updated every one hour)
|
|
16
|
+
*/
|
|
14
17
|
export function getTruncatedTimestamp() {
|
|
15
18
|
return getUnixTime(setMinutes(setSeconds(new Date(), 0), 0));
|
|
16
19
|
}
|
|
@@ -35,17 +38,22 @@ export function isDayBetween(date, start, end) {
|
|
|
35
38
|
}
|
|
36
39
|
export function isDayAfter(date, dateToCompare, include) {
|
|
37
40
|
if (include === void 0) { include = false; }
|
|
38
|
-
|
|
41
|
+
//DO NOT USE isAfter because it compare time and not only date
|
|
42
|
+
return differenceInCalendarDays(date, dateToCompare) > 0 || (include && isSameDay(date, dateToCompare));
|
|
39
43
|
}
|
|
40
44
|
export function isDayBefore(date, dateToCompare, include) {
|
|
41
45
|
if (include === void 0) { include = false; }
|
|
42
|
-
|
|
46
|
+
//DO NOT USE isBefore because it compare time and not only date
|
|
47
|
+
return differenceInCalendarDays(date, dateToCompare) < 0 || (include && isSameDay(date, dateToCompare));
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
46
|
-
* ex: if date is in this format: 20/08/2023 , timezone should not be used
|
|
50
|
+
*
|
|
47
51
|
* @param date
|
|
48
52
|
* @param options
|
|
53
|
+
* @return a string representation of the date in the default format like: vend. 20 août 2023
|
|
54
|
+
*
|
|
55
|
+
* @note timezone should not be set for DateTimeFormatOptions for input without timezone like localdate otherwise info will be wrong.
|
|
56
|
+
* ex: if date is in this format: 20/08/2023 , timezone should not be used
|
|
49
57
|
*/
|
|
50
58
|
export function toString(date, options) {
|
|
51
59
|
if (options === void 0) { options = {}; }
|
|
@@ -63,10 +71,14 @@ export function toString(date, options) {
|
|
|
63
71
|
return date.toLocaleDateString("fr-FR", mergedOptions);
|
|
64
72
|
}
|
|
65
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @param date
|
|
77
|
+
* @returns a string default representation of the date in the Tunisia timezone format (without weekday) like: 25 juin 2022 10:30
|
|
78
|
+
*/
|
|
66
79
|
export function toTunisiaLocale(date) {
|
|
67
80
|
// This is how we get Timezone auto from user OS, but for simplicity we will use Africa/Tunis
|
|
68
81
|
// const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
69
|
-
// request a weekday along with a long date. ex: 25 juin 2022 10:30
|
|
70
82
|
var options = {
|
|
71
83
|
year: "numeric",
|
|
72
84
|
month: "long",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DailyDiscount, PresetMenu } from "../menus/preset/types/preset-menu";
|
|
2
1
|
import { Available, LocalDate } from "../types";
|
|
2
|
+
import { DailyDiscount, PresetMenu } from "../menus/preset/types/preset-menu";
|
|
3
3
|
export declare class MenuUtils {
|
|
4
4
|
static isBusinessAvailable(available?: Available): boolean;
|
|
5
5
|
static isMenuAvailableByDay(menu: PresetMenu, date: Date): boolean;
|