@kiminix/tp-client 1.0.0 → 1.1.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.
Files changed (77) hide show
  1. package/dist/business/apis.d.ts +6 -0
  2. package/dist/business/apis.js +82 -0
  3. package/dist/business/get-all/cache/client.d.ts +2 -0
  4. package/dist/business/get-all/cache/client.js +58 -0
  5. package/dist/business/get-all/client.d.ts +2 -0
  6. package/dist/business/get-all/client.js +53 -0
  7. package/dist/business/get-all/no-cache/client.d.ts +7 -0
  8. package/dist/business/get-all/no-cache/client.js +64 -0
  9. package/dist/business/get-all/types.d.ts +13 -0
  10. package/dist/business/get-all/types.js +1 -0
  11. package/dist/business/types/get-all.d.ts +13 -0
  12. package/dist/business/types/get-all.js +1 -0
  13. package/dist/business/types/get-id.d.ts +28 -0
  14. package/dist/business/types/get-id.js +1 -0
  15. package/dist/constants.d.ts +2 -0
  16. package/dist/constants.js +3 -0
  17. package/dist/contants.d.ts +2 -0
  18. package/dist/contants.js +3 -0
  19. package/dist/deals/apis.d.ts +7 -0
  20. package/dist/deals/apis.js +96 -0
  21. package/dist/deals/types/get-id.d.ts +49 -0
  22. package/dist/deals/types/get-id.js +1 -0
  23. package/dist/deals/types/get-pages.d.ts +40 -0
  24. package/dist/deals/types/get-pages.js +1 -0
  25. package/dist/enum.d.ts +15 -0
  26. package/dist/enum.js +18 -0
  27. package/dist/iam/admin-apis.d.ts +4 -0
  28. package/dist/iam/admin-apis.js +66 -0
  29. package/dist/iam/types/business-signin.d.ts +11 -0
  30. package/dist/iam/types/business-signin.js +1 -0
  31. package/dist/iam/types/me.d.ts +12 -0
  32. package/dist/iam/types/me.js +1 -0
  33. package/dist/iam/types/reset-password.d.ts +5 -0
  34. package/dist/iam/types/reset-password.js +1 -0
  35. package/dist/iam/types/update-profile.d.ts +29 -0
  36. package/dist/iam/types/update-profile.js +1 -0
  37. package/dist/iam/types/user-signin.d.ts +12 -0
  38. package/dist/iam/types/user-signin.js +1 -0
  39. package/dist/iam/types/user-signup-validate.d.ts +5 -0
  40. package/dist/iam/types/user-signup-validate.js +1 -0
  41. package/dist/iam/types/user-signup.d.ts +20 -0
  42. package/dist/iam/types/user-signup.js +1 -0
  43. package/dist/iam/user-apis.d.ts +16 -0
  44. package/dist/iam/user-apis.js +279 -0
  45. package/dist/index.d.ts +14 -0
  46. package/dist/index.js +15 -0
  47. package/dist/menus/apis.d.ts +4 -0
  48. package/dist/menus/apis.js +61 -0
  49. package/dist/menus/types/get-menus.d.ts +20 -0
  50. package/dist/menus/types/get-menus.js +1 -0
  51. package/dist/notify/apis.d.ts +4 -0
  52. package/dist/notify/apis.js +80 -0
  53. package/dist/others/apis.d.ts +3 -0
  54. package/dist/others/apis.js +58 -0
  55. package/dist/reservations/admin-apis.d.ts +7 -0
  56. package/dist/reservations/admin-apis.js +95 -0
  57. package/dist/reservations/types/get-id.d.ts +4 -0
  58. package/dist/reservations/types/get-id.js +1 -0
  59. package/dist/reservations/types/shared.d.ts +46 -0
  60. package/dist/reservations/types/shared.js +1 -0
  61. package/dist/reservations/types/user/get-id.d.ts +4 -0
  62. package/dist/reservations/types/user/get-id.js +1 -0
  63. package/dist/reservations/types/user/get-page.d.ts +7 -0
  64. package/dist/reservations/types/user/get-page.js +1 -0
  65. package/dist/reservations/types/user/reserve-onmenu.d.ts +13 -0
  66. package/dist/reservations/types/user/reserve-onmenu.js +1 -0
  67. package/dist/reservations/user-apis.d.ts +10 -0
  68. package/dist/reservations/user-apis.js +170 -0
  69. package/dist/sitemap/apis.d.ts +3 -0
  70. package/dist/sitemap/apis.js +58 -0
  71. package/dist/types.d.ts +4 -0
  72. package/dist/types.js +1 -0
  73. package/dist/utils/date-utils.d.ts +28 -0
  74. package/dist/utils/date-utils.js +98 -0
  75. package/dist/utils/menu-utils.d.ts +10 -0
  76. package/dist/utils/menu-utils.js +76 -0
  77. package/package.json +20 -3
@@ -0,0 +1,98 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { differenceInCalendarDays, getUnixTime, isAfter, isBefore, isSameDay, parseISO, setMinutes, setSeconds } from "date-fns";
13
+ // timestamp will be updated every one hour
14
+ export function getTruncatedTimestamp() {
15
+ return getUnixTime(setMinutes(setSeconds(new Date(), 0), 0));
16
+ }
17
+ export function dateToString(date, options) {
18
+ if (typeof date == 'string') {
19
+ return parseISO(date).toLocaleDateString("fr-FR", options);
20
+ }
21
+ else {
22
+ return date.toLocaleDateString("fr-FR", options);
23
+ }
24
+ }
25
+ export function isBetween(date, start, end) {
26
+ return (isSameDay(date, start) || isSameDay(date, end) || (isAfter(date, start) && isBefore(date, end)));
27
+ }
28
+ export function isDayAfter(date, dateToCompare, include) {
29
+ if (include === void 0) { include = false; }
30
+ return (differenceInCalendarDays(date, dateToCompare) > 0 || (include && differenceInCalendarDays(date, dateToCompare) === 0));
31
+ }
32
+ export function isDayBefore(date, dateToCompare, include) {
33
+ if (include === void 0) { include = false; }
34
+ return (differenceInCalendarDays(date, dateToCompare) < 0 || (include && differenceInCalendarDays(date, dateToCompare) === 0));
35
+ }
36
+ /**
37
+ * timezone {timeZone: 'Africa/Tunis'} should not be set for date without timezone otherwise info will be wrong
38
+ * ex: if date is in this format: 20/08/2023 , timezone should not be used
39
+ * @param date
40
+ * @param options
41
+ */
42
+ export function toString(date, options) {
43
+ if (options === void 0) { options = {}; }
44
+ var mergedOptions = __assign(__assign({
45
+ weekday: "short",
46
+ year: "numeric",
47
+ month: "long",
48
+ day: "numeric"
49
+ }, options), { timeZone: undefined } // should be keep in last position to force reset to undefined
50
+ );
51
+ return parseISO(date).toLocaleDateString("fr-FR", mergedOptions);
52
+ }
53
+ export function toLocaleTime(date) {
54
+ // request a weekday along with a long date. ex: 25 juin 2022 10:30
55
+ var options = {
56
+ year: "numeric",
57
+ month: "long",
58
+ day: "numeric",
59
+ hour: '2-digit',
60
+ minute: '2-digit',
61
+ timeZone: 'Africa/Tunis' // Set the timezone to Tunisia
62
+ };
63
+ return parseISO(date).toLocaleTimeString("fr-FR", options);
64
+ }
65
+ /**
66
+ *
67
+ * @param date
68
+ * return a date in this format 'yyyy-MM-dd' ex: 2022-06-25
69
+ */
70
+ export function toLocaleDate(date) {
71
+ var options = {
72
+ year: 'numeric',
73
+ month: '2-digit',
74
+ day: '2-digit'
75
+ };
76
+ // fr-CA is required to get the correct output format date in 'yyyy-MM-dd' ex: 2022-06-25
77
+ return date.toLocaleDateString("fr-CA", options);
78
+ }
79
+ var Time = /** @class */ (function () {
80
+ function Time(hours, minutes, seconds) {
81
+ this.hours = hours;
82
+ this.minutes = minutes;
83
+ this.seconds = seconds;
84
+ }
85
+ Time.from = function (date) {
86
+ return new Time(date.getHours(), date.getMinutes(), date.getSeconds());
87
+ };
88
+ Time.prototype.toMinutes = function () {
89
+ return this.hours * 60 + this.minutes;
90
+ };
91
+ Time.prototype.toString = function () {
92
+ var minutes = this.minutes < 10 ? "0".concat(this.minutes) : "".concat(this.minutes);
93
+ var hours = this.hours < 10 ? "0".concat(this.hours) : "".concat(this.hours);
94
+ return "".concat(hours, ":").concat(minutes);
95
+ };
96
+ return Time;
97
+ }());
98
+ export { Time };
@@ -0,0 +1,10 @@
1
+ import { DailyDiscount, LocalDate, PresetMenu } from "../menus/types/get-menus";
2
+ export declare class MenuUtils {
3
+ static isMenuAvailable(menu: PresetMenu): boolean;
4
+ static isMenuAvailableByDay(menu: PresetMenu, date: Date): boolean;
5
+ static getDiscounts(menu: PresetMenu): Map<LocalDate, DailyDiscount>;
6
+ static getAvailableDiscounts(menu: PresetMenu): Map<LocalDate, DailyDiscount>;
7
+ static getMinAvailablePrice(menu: PresetMenu): number;
8
+ static getAvailableDiscountByDay(menu: PresetMenu, date: Date): DailyDiscount | undefined;
9
+ static getDiscountByDay(menu: PresetMenu, date: Date): DailyDiscount | undefined;
10
+ }
@@ -0,0 +1,76 @@
1
+ import { parseISO } from "date-fns";
2
+ import { isDayAfter, isDayBefore, toLocaleDate } from "./date-utils";
3
+ var MenuUtils = /** @class */ (function () {
4
+ function MenuUtils() {
5
+ }
6
+ // check if the menu is still available ( from today )
7
+ MenuUtils.isMenuAvailable = function (menu) {
8
+ var today = new Date();
9
+ var endAt = menu.availableUntil ? parseISO(menu.availableUntil) : undefined;
10
+ return endAt ? isDayBefore(today, endAt, true) : true;
11
+ };
12
+ MenuUtils.isMenuAvailableByDay = function (menu, date) {
13
+ var _a, _b;
14
+ var localDate = toLocaleDate(date);
15
+ // check if the menu is available for this day
16
+ var endAt = menu.availableUntil ? parseISO(menu.availableUntil) : undefined;
17
+ var isMenuAvailable = endAt ? isDayBefore(date, endAt, true) : true;
18
+ var isExcluded = (_b = (_a = menu.excludedDays) === null || _a === void 0 ? void 0 : _a.includes(localDate)) !== null && _b !== void 0 ? _b : false;
19
+ return isMenuAvailable && !isExcluded;
20
+ };
21
+ MenuUtils.getDiscounts = function (menu) {
22
+ var _a;
23
+ var today = new Date();
24
+ // correct way to get daily discounts Map instance
25
+ var discounts_ = (_a = menu.discount) !== null && _a !== void 0 ? _a : {};
26
+ var discounts = new Map(Object.entries(discounts_));
27
+ var result = Array.from(discounts.entries())
28
+ .filter(function (entry) {
29
+ var dateAsString = entry[0], dailyDiscount = entry[1];
30
+ var discountDate = parseISO(dateAsString);
31
+ // check if discount date is available and not in the past
32
+ return isDayAfter(discountDate, today, true);
33
+ });
34
+ return new Map(result);
35
+ };
36
+ MenuUtils.getAvailableDiscounts = function (menu) {
37
+ var _a;
38
+ var today = new Date();
39
+ // correct way to get daily discount Map instance
40
+ var discounts_ = (_a = menu.discount) !== null && _a !== void 0 ? _a : {};
41
+ var discounts = new Map(Object.entries(discounts_));
42
+ var result = Array.from(discounts.entries())
43
+ .filter(function (entry) {
44
+ var dateAsString = entry[0], dailyDiscount = entry[1];
45
+ var discountDate = parseISO(dateAsString);
46
+ // check if discount date is available and not in the past
47
+ return dailyDiscount.isAvailable && isDayAfter(discountDate, today, true);
48
+ });
49
+ return new Map(result);
50
+ };
51
+ // return min available price for the menu ( from today )
52
+ MenuUtils.getMinAvailablePrice = function (menu) {
53
+ var availableDiscounts = MenuUtils.getAvailableDiscounts(menu);
54
+ var discounts = Array.from(availableDiscounts.values());
55
+ // search if there is a lower price in the daily settings
56
+ return discounts
57
+ .reduce(function (min, dailyDiscount) {
58
+ var _a;
59
+ return Math.min(min, (_a = dailyDiscount === null || dailyDiscount === void 0 ? void 0 : dailyDiscount.price) === null || _a === void 0 ? void 0 : _a.adult);
60
+ }, menu.price.adult);
61
+ };
62
+ MenuUtils.getAvailableDiscountByDay = function (menu, date) {
63
+ // correct way to get daily discount Map instance
64
+ var discounts = MenuUtils.getAvailableDiscounts(menu);
65
+ var localDate = toLocaleDate(date);
66
+ return discounts.get(localDate);
67
+ };
68
+ MenuUtils.getDiscountByDay = function (menu, date) {
69
+ // correct way to get daily discount Map instance
70
+ var discounts = MenuUtils.getDiscounts(menu);
71
+ var localDate = toLocaleDate(date);
72
+ return discounts.get(localDate);
73
+ };
74
+ return MenuUtils;
75
+ }());
76
+ export { MenuUtils };
package/package.json CHANGED
@@ -1,11 +1,28 @@
1
1
  {
2
2
  "name": "@kiminix/tp-client",
3
- "version": "1.0.0",
4
- "main": "index.js",
3
+ "version": "1.1.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "/dist"
8
+ ],
5
9
  "scripts": {
10
+ "build": "tsc",
6
11
  "test": "echo \"Error: no test specified\" && exit 1"
7
12
  },
8
13
  "author": "",
9
14
  "license": "ISC",
10
- "description": ""
15
+ "description": "",
16
+ "devDependencies": {
17
+ "@types/node": "20.11.16",
18
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
19
+ "@typescript-eslint/parser": "^6.21.0",
20
+ "eslint": "^8.56.0",
21
+ "typescript": "^5.3.3"
22
+ },
23
+ "dependencies": {
24
+ "axios": "^1.6.7",
25
+ "date-fns": "^3.3.1",
26
+ "purify-ts": "^2.0.3"
27
+ }
11
28
  }