@kiminix/tp-client 1.21.0 → 1.23.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 (81) hide show
  1. package/dist/business/types/get-all.d.ts +17 -0
  2. package/dist/business/types/get-id.d.ts +7 -5
  3. package/dist/cashback/admin/admin-apis.d.ts +7 -0
  4. package/dist/{menus/preset/user-apis.js → cashback/admin/admin-apis.js} +37 -33
  5. package/dist/cashback/admin/types/resp-get-cashback.d.ts +12 -0
  6. package/dist/cashback/index.d.ts +4 -0
  7. package/dist/cashback/index.js +6 -0
  8. package/dist/cashback/user/types/resp-get-cashback.d.ts +10 -0
  9. package/dist/cashback/user/user-apis.d.ts +7 -0
  10. package/dist/cashback/user/user-apis.js +87 -0
  11. package/dist/deals/types.d.ts +4 -3
  12. package/dist/enum.d.ts +11 -5
  13. package/dist/enum.js +14 -7
  14. package/dist/index.d.ts +5 -8
  15. package/dist/index.js +9 -9
  16. package/dist/menus/preset/discounts/admin-apis.d.ts +3 -3
  17. package/dist/menus/preset/discounts/admin-apis.js +3 -3
  18. package/dist/menus/preset/discounts/types/update-discount.d.ts +2 -2
  19. package/dist/menus/preset/index.d.ts +7 -0
  20. package/dist/menus/preset/index.js +9 -0
  21. package/dist/reservations/{admin-apis.d.ts → admin/admin-apis.d.ts} +11 -5
  22. package/dist/reservations/{admin-apis.js → admin/admin-apis.js} +42 -4
  23. package/dist/reservations/admin/types/get-id.d.ts +4 -0
  24. package/dist/reservations/index.d.ts +11 -0
  25. package/dist/reservations/index.js +14 -0
  26. package/dist/reservations/shared/reservation-deal.d.ts +19 -0
  27. package/dist/reservations/shared/reservation-deal.js +13 -0
  28. package/dist/reservations/{types/shared.d.ts → shared/reservation.d.ts} +7 -6
  29. package/dist/reservations/{types/user/reservation-preview.d.ts → user/types/resp-reservation-preview.d.ts} +4 -2
  30. package/dist/reservations/user/types/resp-reservation-preview.js +2 -0
  31. package/dist/reservations/user/types/resp-reservation-settings.d.ts +22 -0
  32. package/dist/reservations/user/types/resp-save-reservation.d.ts +3 -0
  33. package/dist/reservations/user/user-apis.d.ts +21 -7
  34. package/dist/reservations/user/user-apis.js +71 -5
  35. package/dist/statistics/admin-apis.d.ts +2 -2
  36. package/dist/statistics/admin-apis.js +37 -30
  37. package/dist/statistics/types/menus-statistic.d.ts +2 -0
  38. package/dist/utils/request-utils.d.ts +3 -0
  39. package/dist/utils/request-utils.js +81 -0
  40. package/package.json +3 -1
  41. package/dist/deals/types/get-id.d.ts +0 -49
  42. package/dist/deals/types/get-pages.d.ts +0 -30
  43. package/dist/menus/discounts/admin-apis.d.ts +0 -7
  44. package/dist/menus/discounts/admin-apis.js +0 -90
  45. package/dist/menus/discounts/types/update-discount.d.ts +0 -9
  46. package/dist/menus/preset/types/available-menu.d.ts +0 -12
  47. package/dist/menus/preset/user-apis.d.ts +0 -16
  48. package/dist/menus/types/preset-menu.d.ts +0 -22
  49. package/dist/reservations/types/admin/get-page.js +0 -1
  50. package/dist/reservations/types/admin/patch-status.d.ts +0 -6
  51. package/dist/reservations/types/admin/patch-status.js +0 -1
  52. package/dist/reservations/types/admin/reserve-onmenu.d.ts +0 -17
  53. package/dist/reservations/types/admin/reserve-onmenu.js +0 -1
  54. package/dist/reservations/types/shared.js +0 -1
  55. package/dist/reservations/types/types.d.ts +0 -27
  56. package/dist/reservations/types/types.js +0 -2
  57. package/dist/reservations/types/user/get-id.d.ts +0 -4
  58. package/dist/reservations/types/user/get-id.js +0 -1
  59. package/dist/reservations/types/user/get-page.d.ts +0 -7
  60. package/dist/reservations/types/user/get-page.js +0 -1
  61. package/dist/reservations/types/user/reservation-preview.js +0 -1
  62. package/dist/reservations/types/user/reserve-onmenu.d.ts +0 -13
  63. package/dist/reservations/types/user/reserve-onmenu.js +0 -1
  64. package/dist/reservations/types/user/reserve-response.d.ts +0 -3
  65. package/dist/reservations/types/user/reserve-response.js +0 -1
  66. package/dist/reservations/types.d.ts +0 -27
  67. package/dist/reservations/user/types.d.ts +0 -31
  68. package/dist/reservations/user-apis.d.ts +0 -30
  69. package/dist/reservations/user-apis.js +0 -206
  70. /package/dist/{deals/types/get-id.js → cashback/admin/types/resp-get-cashback.js} +0 -0
  71. /package/dist/{deals/types/get-pages.js → cashback/user/types/resp-get-cashback.js} +0 -0
  72. /package/dist/reservations/{types/admin → admin/types}/get-available-transitions.d.ts +0 -0
  73. /package/dist/reservations/{types/admin → admin/types}/get-available-transitions.js +0 -0
  74. /package/dist/reservations/{types/admin → admin/types}/get-id.js +0 -0
  75. /package/dist/{menus/discounts/types/update-discount.js → reservations/shared/reservation.js} +0 -0
  76. /package/dist/reservations/{types/admin/get-id.d.ts → user/types/req-get-by-id.d.ts} +0 -0
  77. /package/dist/reservations/user/{types.js → types/req-get-by-id.js} +0 -0
  78. /package/dist/reservations/{types/admin/get-page.d.ts → user/types/req-get-page-reservation.d.ts} +0 -0
  79. /package/dist/reservations/{types.js → user/types/req-get-page-reservation.js} +0 -0
  80. /package/dist/{menus/preset/types/available-menu.js → reservations/user/types/resp-reservation-settings.js} +0 -0
  81. /package/dist/{menus/types/preset-menu.js → reservations/user/types/resp-save-reservation.js} +0 -0
@@ -0,0 +1,19 @@
1
+ import { Level, ReservationDealKind } from "../../enum";
2
+ export interface Discount {
3
+ type: ReservationDealKind.Discount;
4
+ value: number;
5
+ }
6
+ export interface CashbackEarn {
7
+ type: ReservationDealKind.CashbackEarn;
8
+ value: number;
9
+ level: Level;
10
+ rate: number;
11
+ isInProgress: boolean;
12
+ }
13
+ export interface CashbackApply {
14
+ type: ReservationDealKind.CashBackApply;
15
+ value: number;
16
+ isInProgress: boolean;
17
+ }
18
+ export type ReservationDeal = Discount | CashbackEarn | CashbackApply;
19
+ export declare function parseReservationDeal(json: any): ReservationDeal;
@@ -0,0 +1,13 @@
1
+ import { ReservationDealKind } from "../../enum";
2
+ export function parseReservationDeal(json) {
3
+ switch (json.type) {
4
+ case ReservationDealKind.Discount:
5
+ return json;
6
+ case ReservationDealKind.CashbackEarn:
7
+ return json;
8
+ case ReservationDealKind.CashBackApply:
9
+ return json;
10
+ default:
11
+ throw new Error("Unknown reservation's deal type: ".concat(json.type));
12
+ }
13
+ }
@@ -1,4 +1,5 @@
1
1
  import { CancellationReason, ReservationEventKind, ReservationStatus } from "../../enum";
2
+ import { ReservationDeal } from "./reservation-deal";
2
3
  export interface Business {
3
4
  id: string;
4
5
  identifier: string;
@@ -24,12 +25,15 @@ export interface OnMenuCommand {
24
25
  title: string;
25
26
  adults: GuestDetails;
26
27
  children?: GuestDetails;
27
- deal: string;
28
28
  }
29
29
  export interface ReservationEvent {
30
30
  kind: ReservationEventKind;
31
31
  at: string;
32
32
  }
33
+ export interface Cancellation {
34
+ reason: CancellationReason;
35
+ notes?: string;
36
+ }
33
37
  export interface Reservation {
34
38
  id: string;
35
39
  isSetByAdmin: boolean;
@@ -40,13 +44,10 @@ export interface Reservation {
40
44
  status: ReservationStatus;
41
45
  total: number;
42
46
  totalBeforeDeal?: number;
43
- onMenuCommands: OnMenuCommand[];
44
47
  deposit?: number;
48
+ deal: ReservationDeal | undefined;
49
+ onMenuCommands: OnMenuCommand[];
45
50
  events?: ReservationEvent[];
46
51
  notes?: string;
47
52
  cancellation?: Cancellation;
48
53
  }
49
- export interface Cancellation {
50
- reason: CancellationReason;
51
- notes?: string;
52
- }
@@ -1,8 +1,10 @@
1
+ import { ReservationDeal } from "../../shared/reservation-deal";
1
2
  export interface ReservationPreviewResponse {
2
3
  datetime: Date;
3
4
  total: number;
4
- totalBeforeDeal: number | undefined;
5
+ totalBeforeDeal: number;
5
6
  commands: CommandPreview[];
7
+ deal: ReservationDeal | undefined;
6
8
  }
7
9
  export interface CommandPreview {
8
10
  menuId: string;
@@ -13,5 +15,5 @@ export interface CommandPreview {
13
15
  export interface CommandEntryPreview {
14
16
  number: number;
15
17
  price: number;
16
- priceBeforeDeal: number | undefined;
18
+ priceBeforeDeal: number;
17
19
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ // END Reservation preview types
@@ -0,0 +1,22 @@
1
+ import { Price } from "../../../menus/preset/types/types";
2
+ export interface ReservationSettings {
3
+ menus: AvailableMenu[];
4
+ deals: AvailableDeal[];
5
+ }
6
+ export interface AvailableDeal {
7
+ id: string;
8
+ label: string;
9
+ isAvailable: boolean;
10
+ }
11
+ export interface AvailableMenu {
12
+ id: string;
13
+ title: string;
14
+ price: Price;
15
+ minBookingTotal: number | undefined;
16
+ discount: AvailableDiscount | undefined;
17
+ isAvailable: boolean;
18
+ }
19
+ export interface AvailableDiscount {
20
+ price: Price;
21
+ minBookingTotal: number | undefined;
22
+ }
@@ -0,0 +1,3 @@
1
+ export interface SaveReservationResponse {
2
+ id: string;
3
+ }
@@ -1,28 +1,42 @@
1
- import { Reservation } from "../types/shared";
2
- import { DealKind } from "../../enum";
3
- import { GetByIdRequest, GetPageRequest, ReservationPreviewResponse, ReservationResponse } from "./types";
1
+ import { ReservationDealKind } from "../../enum";
2
+ import { LocalDate } from "../../types";
3
+ import { Reservation } from "../shared/reservation";
4
+ import { GetByIdAdminRequest, GetPageRequest, ReservationPreviewResponse, ReservationSettings } from "../index";
5
+ import { SaveReservationResponse } from "./types/resp-save-reservation";
4
6
  export declare class ReservationsUserAPIs {
5
7
  static getPage({ token, page, size, direction }: GetPageRequest): Promise<Reservation[]>;
6
- static get({ id, token }: GetByIdRequest): Promise<Reservation>;
8
+ static get({ id, token }: GetByIdAdminRequest): Promise<Reservation>;
7
9
  static cancel(id: string, token?: string): Promise<any>;
10
+ /**
11
+ *
12
+ * @param businessId
13
+ * @param date
14
+ * @returns Available deals & menus for the given business and date.
15
+ * Can fail with bellow errors code: unauthenticated, past_day, expired_licence, internal_error
16
+ */
17
+ static getSettings(props: {
18
+ token?: string;
19
+ businessId: string;
20
+ date: LocalDate;
21
+ }): Promise<ReservationSettings>;
8
22
  static reserve(props: {
9
23
  token?: string;
10
24
  businessId: string;
11
25
  date: Date;
12
26
  time: Date;
13
- dealKind?: DealKind;
27
+ deal: ReservationDealKind | undefined;
14
28
  commands: {
15
29
  menuId: string;
16
30
  adult: number;
17
31
  child?: number;
18
32
  }[];
19
- }): Promise<ReservationResponse>;
33
+ }): Promise<SaveReservationResponse>;
20
34
  static preview(props: {
21
35
  token?: string;
22
36
  businessId: string;
23
37
  date: Date;
24
38
  time: Date;
25
- dealKind?: DealKind;
39
+ deal: ReservationDealKind | undefined;
26
40
  commands: {
27
41
  menuId: string;
28
42
  adult: number;
@@ -38,6 +38,7 @@ import axios from "axios";
38
38
  import { format } from "date-fns";
39
39
  import { base } from "../../constants";
40
40
  import { ErrorWithMetadata } from "../../types";
41
+ import { parseReservationDeal } from "../shared/reservation-deal";
41
42
  var ReservationsUserAPIs = /** @class */ (function () {
42
43
  function ReservationsUserAPIs() {
43
44
  }
@@ -51,7 +52,13 @@ var ReservationsUserAPIs = /** @class */ (function () {
51
52
  'Authorization': "".concat(token)
52
53
  }
53
54
  })
54
- .then(function (response) { return response.data; })
55
+ .then(function (response) {
56
+ var result = response.data;
57
+ for (var i = 0; i < result.length; i++) {
58
+ result[i].deal = result[i].deal ? parseReservationDeal(result[i].deal) : undefined;
59
+ }
60
+ return result;
61
+ })
55
62
  .catch(function (error) {
56
63
  // handle error
57
64
  if (error.response.status == 401)
@@ -75,7 +82,11 @@ var ReservationsUserAPIs = /** @class */ (function () {
75
82
  'Content-Type': 'application/json'
76
83
  }
77
84
  })
78
- .then(function (response) { return response.data; })
85
+ .then(function (response) {
86
+ var result = response.data;
87
+ result.deal = result.deal ? parseReservationDeal(result.deal) : undefined;
88
+ return result;
89
+ })
79
90
  .catch(function (error) {
80
91
  // handle error
81
92
  if (error.response.status == 401)
@@ -119,6 +130,57 @@ var ReservationsUserAPIs = /** @class */ (function () {
119
130
  });
120
131
  });
121
132
  };
133
+ /**
134
+ *
135
+ * @param businessId
136
+ * @param date
137
+ * @returns Available deals & menus for the given business and date.
138
+ * Can fail with bellow errors code: unauthenticated, past_day, expired_licence, internal_error
139
+ */
140
+ ReservationsUserAPIs.getSettings = function (props) {
141
+ var _a, _b;
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var response, error_1, axiosError;
144
+ return __generator(this, function (_c) {
145
+ switch (_c.label) {
146
+ case 0:
147
+ _c.trys.push([0, 2, , 3]);
148
+ return [4 /*yield*/, axios.get(base + "/reservations/user/settings?business=".concat(props.businessId, "&date=").concat(props.date), {
149
+ headers: {
150
+ 'Authorization': "".concat(props.token)
151
+ }
152
+ })];
153
+ case 1:
154
+ response = _c.sent();
155
+ return [2 /*return*/, response.data];
156
+ case 2:
157
+ error_1 = _c.sent();
158
+ axiosError = error_1;
159
+ // The request was made and the server responded with a status code that falls out of the range of 2xx
160
+ if (axiosError && axiosError.response) {
161
+ switch (axiosError.response.status) {
162
+ case 401:
163
+ throw new Error("unauthorized");
164
+ case 400:
165
+ throw new Error((_b = (_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.code);
166
+ default:
167
+ throw new Error('internal_error');
168
+ }
169
+ }
170
+ // The request was made but no response was received
171
+ else if (axiosError && axiosError.request) {
172
+ throw new Error('network_error');
173
+ }
174
+ // Something happened in setting up the request that triggered an Error
175
+ else {
176
+ throw new Error('client_request_setting_error');
177
+ }
178
+ return [3 /*break*/, 3];
179
+ case 3: return [2 /*return*/];
180
+ }
181
+ });
182
+ });
183
+ };
122
184
  ReservationsUserAPIs.reserve = function (props) {
123
185
  return __awaiter(this, void 0, void 0, function () {
124
186
  var datetime;
@@ -130,7 +192,7 @@ var ReservationsUserAPIs = /** @class */ (function () {
130
192
  return [4 /*yield*/, axios.post(base + "/reservations/user", {
131
193
  businessId: props.businessId,
132
194
  datetime: format(datetime, "yyyy-MM-dd'T'HH:mm"),
133
- dealKind: props.dealKind,
195
+ deal: props.deal,
134
196
  commands: props.commands
135
197
  }, {
136
198
  headers: {
@@ -172,7 +234,7 @@ var ReservationsUserAPIs = /** @class */ (function () {
172
234
  return [4 /*yield*/, axios.post(base + "/reservations/user/preview", {
173
235
  businessId: props.businessId,
174
236
  datetime: format(datetime, "yyyy-MM-dd'T'HH:mm"),
175
- dealKind: props.dealKind,
237
+ deal: props.deal,
176
238
  commands: props.commands
177
239
  }, {
178
240
  headers: {
@@ -180,7 +242,11 @@ var ReservationsUserAPIs = /** @class */ (function () {
180
242
  'Content-Type': 'application/json'
181
243
  }
182
244
  })
183
- .then(function (response) { return response.data; })
245
+ .then(function (response) {
246
+ var result = response.data;
247
+ result.deal = result.deal ? parseReservationDeal(result.deal) : undefined;
248
+ return result;
249
+ })
184
250
  .catch(function (error) {
185
251
  // handle error
186
252
  if (error.response.status == 401)
@@ -5,11 +5,11 @@ import { LocalDate } from "../types";
5
5
  import { ReservationStatus } from "../enum";
6
6
  export declare class StatisticsAdminAPIs {
7
7
  static countReservationByStatus({ token, date }: CountReservationByStatusRequest): Promise<CountReservationByStatusResponse[]>;
8
- static menusStatistic({ token, date }: MenusStatisticRequest): Promise<MenuStatisticResponse[]>;
8
+ static menusStatistic({ token, date, status }: MenusStatisticRequest): Promise<MenuStatisticResponse[]>;
9
9
  static countReservationsByMonth(props: {
10
10
  token?: string;
11
11
  date: LocalDate;
12
- status?: ReservationStatus;
12
+ status?: ReservationStatus[];
13
13
  }): Promise<CountByDay[]>;
14
14
  static lastReservations(props: {
15
15
  token?: string;
@@ -63,46 +63,53 @@ var StatisticsAdminAPIs = /** @class */ (function () {
63
63
  });
64
64
  };
65
65
  StatisticsAdminAPIs.menusStatistic = function (_a) {
66
- var token = _a.token, date = _a.date;
66
+ var token = _a.token, date = _a.date, status = _a.status;
67
67
  return __awaiter(this, void 0, void 0, function () {
68
+ var statusParams;
68
69
  return __generator(this, function (_b) {
69
70
  switch (_b.label) {
70
- case 0: return [4 /*yield*/, axios.get(base + "/statistics/menus/".concat(date), {
71
- headers: {
72
- 'Authorization': "".concat(token)
73
- }
74
- })
75
- .then(function (response) { return response.data; })
76
- .catch(function (error) {
77
- // handle error
78
- if (error.response.status == 401)
79
- throw new Error("unauthorized");
80
- else
81
- throw new Error('internal_error', error);
82
- })];
71
+ case 0:
72
+ statusParams = status.map(function (s) { return "status=".concat(s); }).join('&');
73
+ return [4 /*yield*/, axios.get(base + "/statistics/menus/".concat(date, "?").concat(statusParams), {
74
+ headers: {
75
+ 'Authorization': "".concat(token)
76
+ }
77
+ })
78
+ .then(function (response) { return response.data; })
79
+ .catch(function (error) {
80
+ // handle error
81
+ if (error.response.status == 401)
82
+ throw new Error("unauthorized");
83
+ else
84
+ throw new Error('internal_error', error);
85
+ })];
83
86
  case 1: return [2 /*return*/, _b.sent()];
84
87
  }
85
88
  });
86
89
  });
87
90
  };
88
91
  StatisticsAdminAPIs.countReservationsByMonth = function (props) {
92
+ var _a;
89
93
  return __awaiter(this, void 0, void 0, function () {
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0: return [4 /*yield*/, axios.get(base + "/statistics/reservations-by-month/".concat(props.date, "?").concat(props.status ? "status=".concat(props.status) : ''), {
93
- headers: {
94
- 'Authorization': "".concat(props.token)
95
- }
96
- })
97
- .then(function (response) { return response.data; })
98
- .catch(function (error) {
99
- // handle error
100
- if (error.response.status == 401)
101
- throw new Error("unauthorized");
102
- else
103
- throw new Error('internal_error', error);
104
- })];
105
- case 1: return [2 /*return*/, _a.sent()];
94
+ var statusParams;
95
+ return __generator(this, function (_b) {
96
+ switch (_b.label) {
97
+ case 0:
98
+ statusParams = (_a = props.status) === null || _a === void 0 ? void 0 : _a.map(function (s) { return "status=".concat(s); }).join('&');
99
+ return [4 /*yield*/, axios.get(base + "/statistics/reservations-by-month/".concat(props.date, "?").concat(statusParams), {
100
+ headers: {
101
+ 'Authorization': "".concat(props.token)
102
+ }
103
+ })
104
+ .then(function (response) { return response.data; })
105
+ .catch(function (error) {
106
+ // handle error
107
+ if (error.response.status == 401)
108
+ throw new Error("unauthorized");
109
+ else
110
+ throw new Error('internal_error', error);
111
+ })];
112
+ case 1: return [2 /*return*/, _b.sent()];
106
113
  }
107
114
  });
108
115
  });
@@ -1,7 +1,9 @@
1
+ import { ReservationStatus } from "../../enum";
1
2
  import { LocalDate } from "../../types";
2
3
  export interface MenusStatisticRequest {
3
4
  token?: string;
4
5
  date: LocalDate;
6
+ status: ReservationStatus[];
5
7
  }
6
8
  export interface MenuStatisticResponse {
7
9
  id: string;
@@ -0,0 +1,3 @@
1
+ export declare class RequestUtils {
2
+ static send<T>(request: () => Promise<T>): Promise<T>;
3
+ }
@@ -0,0 +1,81 @@
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 { ErrorWithMetadata } from "../types";
38
+ var RequestUtils = /** @class */ (function () {
39
+ function RequestUtils() {
40
+ }
41
+ RequestUtils.send = function (request) {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ var error_1, axiosError, response;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ _a.trys.push([0, 2, , 3]);
48
+ return [4 /*yield*/, request()];
49
+ case 1: return [2 /*return*/, _a.sent()];
50
+ case 2:
51
+ error_1 = _a.sent();
52
+ axiosError = error_1;
53
+ // The request was made and the server responded with a status code that falls out of the range of 2xx
54
+ if (axiosError && axiosError.response) {
55
+ switch (axiosError.response.status) {
56
+ case 401:
57
+ throw new Error("unauthorized");
58
+ case 400:
59
+ response = error_1.response.data;
60
+ throw new ErrorWithMetadata(response.code, response.metadata);
61
+ default:
62
+ throw new Error('internal_error');
63
+ }
64
+ }
65
+ // The request was made but no response was received
66
+ else if (axiosError && axiosError.request) {
67
+ throw new Error('network_error');
68
+ }
69
+ // Something happened in setting up the request that triggered an Error
70
+ else {
71
+ throw new Error('client_request_setting_error');
72
+ }
73
+ return [3 /*break*/, 3];
74
+ case 3: return [2 /*return*/];
75
+ }
76
+ });
77
+ });
78
+ };
79
+ return RequestUtils;
80
+ }());
81
+ export { RequestUtils };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@kiminix/tp-client",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
7
7
  "/dist"
8
8
  ],
9
9
  "scripts": {
10
+ "prebuild": "rimraf dist",
10
11
  "build": "tsc",
11
12
  "test": "echo \"Error: no test specified\" && exit 1"
12
13
  },
@@ -18,6 +19,7 @@
18
19
  "@typescript-eslint/eslint-plugin": "^6.21.0",
19
20
  "@typescript-eslint/parser": "^6.21.0",
20
21
  "eslint": "^8.56.0",
22
+ "rimraf": "^5.0.5",
21
23
  "typescript": "^5.3.3"
22
24
  },
23
25
  "dependencies": {
@@ -1,49 +0,0 @@
1
- export interface Price {
2
- reduced: number;
3
- current: number;
4
- weekend: number;
5
- }
6
- export interface Review {
7
- stars: number;
8
- count: number;
9
- link?: string;
10
- }
11
- export interface SocialNetworks {
12
- facebook?: string;
13
- instagram?: string;
14
- twitter?: string;
15
- }
16
- export interface GoogleMap {
17
- link: string;
18
- image: string;
19
- }
20
- export interface Business {
21
- id: string;
22
- identifier: string;
23
- name: string;
24
- createdAt: string;
25
- address: string;
26
- googleMap?: GoogleMap;
27
- review: Review;
28
- phones: string[];
29
- socialNetworks?: SocialNetworks;
30
- images: string[];
31
- }
32
- export interface Deal {
33
- id: string;
34
- identifier: string;
35
- title: string;
36
- images: string[];
37
- adultPrice: Price;
38
- childPrice: Price;
39
- createdAt: Date;
40
- startAt: Date;
41
- endAt: Date;
42
- isExpired: boolean;
43
- discount: number;
44
- maxGuests: number;
45
- minBookingAmount: number;
46
- maxCoupons: number;
47
- aboutSection: string;
48
- business: Business;
49
- }
@@ -1,30 +0,0 @@
1
- import { Licence } from "../../types";
2
-
3
- export interface Price {
4
- reduced: number;
5
- current: number;
6
- }
7
-
8
- export interface Business {
9
- id: string;
10
- identifier: string;
11
- name: string;
12
- address: string;
13
- licence?: Licence;
14
- }
15
- export interface Deal {
16
- id: string;
17
- identifier: string;
18
- title: string;
19
- isExpired: boolean;
20
- discount: number;
21
- price: Price;
22
- images: string[];
23
- business: Business;
24
- updatedAt: Date;
25
- }
26
- export type GetPage = {
27
- page?: number;
28
- size?: number;
29
- tags?: string[];
30
- };
@@ -1,7 +0,0 @@
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
- }