@kiminix/tp-client 1.0.0 → 1.2.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 (85) 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 +12 -0
  56. package/dist/reservations/admin-apis.js +145 -0
  57. package/dist/reservations/types/admin/get-available-transitions.d.ts +4 -0
  58. package/dist/reservations/types/admin/get-available-transitions.js +1 -0
  59. package/dist/reservations/types/admin/get-id.d.ts +4 -0
  60. package/dist/reservations/types/admin/get-id.js +1 -0
  61. package/dist/reservations/types/admin/get-page.d.ts +7 -0
  62. package/dist/reservations/types/admin/get-page.js +1 -0
  63. package/dist/reservations/types/admin/patch-status.d.ts +6 -0
  64. package/dist/reservations/types/admin/patch-status.js +1 -0
  65. package/dist/reservations/types/get-id.d.ts +4 -0
  66. package/dist/reservations/types/get-id.js +1 -0
  67. package/dist/reservations/types/shared.d.ts +46 -0
  68. package/dist/reservations/types/shared.js +1 -0
  69. package/dist/reservations/types/user/get-id.d.ts +4 -0
  70. package/dist/reservations/types/user/get-id.js +1 -0
  71. package/dist/reservations/types/user/get-page.d.ts +7 -0
  72. package/dist/reservations/types/user/get-page.js +1 -0
  73. package/dist/reservations/types/user/reserve-onmenu.d.ts +13 -0
  74. package/dist/reservations/types/user/reserve-onmenu.js +1 -0
  75. package/dist/reservations/user-apis.d.ts +10 -0
  76. package/dist/reservations/user-apis.js +170 -0
  77. package/dist/sitemap/apis.d.ts +3 -0
  78. package/dist/sitemap/apis.js +58 -0
  79. package/dist/types.d.ts +4 -0
  80. package/dist/types.js +1 -0
  81. package/dist/utils/date-utils.d.ts +29 -0
  82. package/dist/utils/date-utils.js +101 -0
  83. package/dist/utils/menu-utils.d.ts +10 -0
  84. package/dist/utils/menu-utils.js +76 -0
  85. package/package.json +20 -3
@@ -0,0 +1,58 @@
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
+ // others module APIs
40
+ var SitemapAPIs = /** @class */ (function () {
41
+ function SitemapAPIs() {
42
+ }
43
+ SitemapAPIs.get = function () {
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0: return [4 /*yield*/, axios.get(base + "/sitemap")
48
+ .then(function (response) {
49
+ return response.data;
50
+ })];
51
+ case 1: return [2 /*return*/, _a.sent()];
52
+ }
53
+ });
54
+ });
55
+ };
56
+ return SitemapAPIs;
57
+ }());
58
+ export { SitemapAPIs };
@@ -0,0 +1,4 @@
1
+ export interface ApiError {
2
+ message: string;
3
+ code?: string;
4
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ export declare function getTruncatedTimestamp(): number;
2
+ export declare function dateToString(date: string | Date, options: Intl.DateTimeFormatOptions): string;
3
+ export declare function toStringDefault(date: string, options: Intl.DateTimeFormatOptions): string;
4
+ export declare function isBetween(date: Date, start: Date, end: Date): boolean;
5
+ export declare function isDayAfter(date: Date, dateToCompare: Date, include?: Boolean): boolean;
6
+ export declare function isDayBefore(date: Date, dateToCompare: Date, include?: Boolean): boolean;
7
+ /**
8
+ * timezone {timeZone: 'Africa/Tunis'} should not be set for date without timezone otherwise info will be wrong
9
+ * ex: if date is in this format: 20/08/2023 , timezone should not be used
10
+ * @param date
11
+ * @param options
12
+ */
13
+ export declare function toString(date: string, options?: Intl.DateTimeFormatOptions): string;
14
+ export declare function toLocaleTime(date: string): string;
15
+ /**
16
+ *
17
+ * @param date
18
+ * return a date in this format 'yyyy-MM-dd' ex: 2022-06-25
19
+ */
20
+ export declare function toLocaleDate(date: Date): string;
21
+ export declare class Time {
22
+ hours: number;
23
+ minutes: number;
24
+ seconds: number;
25
+ constructor(hours: number, minutes: number, seconds: number);
26
+ static from(date: Date): Time;
27
+ toMinutes(): number;
28
+ toString(): string;
29
+ }
@@ -0,0 +1,101 @@
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 toStringDefault(date, options) {
26
+ return parseISO(date).toLocaleDateString("fr-FR", options);
27
+ }
28
+ export function isBetween(date, start, end) {
29
+ return (isSameDay(date, start) || isSameDay(date, end) || (isAfter(date, start) && isBefore(date, end)));
30
+ }
31
+ export function isDayAfter(date, dateToCompare, include) {
32
+ if (include === void 0) { include = false; }
33
+ return (differenceInCalendarDays(date, dateToCompare) > 0 || (include && differenceInCalendarDays(date, dateToCompare) === 0));
34
+ }
35
+ export function isDayBefore(date, dateToCompare, include) {
36
+ if (include === void 0) { include = false; }
37
+ return (differenceInCalendarDays(date, dateToCompare) < 0 || (include && differenceInCalendarDays(date, dateToCompare) === 0));
38
+ }
39
+ /**
40
+ * timezone {timeZone: 'Africa/Tunis'} should not be set for date without timezone otherwise info will be wrong
41
+ * ex: if date is in this format: 20/08/2023 , timezone should not be used
42
+ * @param date
43
+ * @param options
44
+ */
45
+ export function toString(date, options) {
46
+ if (options === void 0) { options = {}; }
47
+ var mergedOptions = __assign(__assign({
48
+ weekday: "short",
49
+ year: "numeric",
50
+ month: "long",
51
+ day: "numeric"
52
+ }, options), { timeZone: undefined } // should be keep in last position to force reset to undefined
53
+ );
54
+ return parseISO(date).toLocaleDateString("fr-FR", mergedOptions);
55
+ }
56
+ export function toLocaleTime(date) {
57
+ // request a weekday along with a long date. ex: 25 juin 2022 10:30
58
+ var options = {
59
+ year: "numeric",
60
+ month: "long",
61
+ day: "numeric",
62
+ hour: '2-digit',
63
+ minute: '2-digit',
64
+ timeZone: 'Africa/Tunis' // Set the timezone to Tunisia
65
+ };
66
+ return parseISO(date).toLocaleTimeString("fr-FR", options);
67
+ }
68
+ /**
69
+ *
70
+ * @param date
71
+ * return a date in this format 'yyyy-MM-dd' ex: 2022-06-25
72
+ */
73
+ export function toLocaleDate(date) {
74
+ var options = {
75
+ year: 'numeric',
76
+ month: '2-digit',
77
+ day: '2-digit'
78
+ };
79
+ // fr-CA is required to get the correct output format date in 'yyyy-MM-dd' ex: 2022-06-25
80
+ return date.toLocaleDateString("fr-CA", options);
81
+ }
82
+ var Time = /** @class */ (function () {
83
+ function Time(hours, minutes, seconds) {
84
+ this.hours = hours;
85
+ this.minutes = minutes;
86
+ this.seconds = seconds;
87
+ }
88
+ Time.from = function (date) {
89
+ return new Time(date.getHours(), date.getMinutes(), date.getSeconds());
90
+ };
91
+ Time.prototype.toMinutes = function () {
92
+ return this.hours * 60 + this.minutes;
93
+ };
94
+ Time.prototype.toString = function () {
95
+ var minutes = this.minutes < 10 ? "0".concat(this.minutes) : "".concat(this.minutes);
96
+ var hours = this.hours < 10 ? "0".concat(this.hours) : "".concat(this.hours);
97
+ return "".concat(hours, ":").concat(minutes);
98
+ };
99
+ return Time;
100
+ }());
101
+ 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.2.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
  }