@dv4resi/dvss-backend-module-offering-im 0.0.11 → 0.0.13

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.js CHANGED
@@ -3685,16 +3685,8 @@ function mapTrybePractitionersToSystemResponse(practitioners, totalCount) {
3685
3685
  }
3686
3686
  __name(mapTrybePractitionersToSystemResponse, "mapTrybePractitionersToSystemResponse");
3687
3687
  function mapTrybeOfferingTypeToBookableItemType(offeringType) {
3688
- switch (offeringType) {
3689
- case TRYBE_OFFERING_TYPE_ENUM.APPOINTMENT:
3690
- return BOOKABLE_ITEM_TYPE_ENUM.APPOINTMENT;
3691
- case TRYBE_OFFERING_TYPE_ENUM.SESSION:
3692
- return BOOKABLE_ITEM_TYPE_ENUM.SESSION;
3693
- case TRYBE_OFFERING_TYPE_ENUM.COURSE:
3694
- return BOOKABLE_ITEM_TYPE_ENUM.COURSE;
3695
- default:
3696
- return BOOKABLE_ITEM_TYPE_ENUM.APPOINTMENT;
3697
- }
3688
+ const normalized = offeringType.toUpperCase();
3689
+ return BOOKABLE_ITEM_TYPE_ENUM[normalized];
3698
3690
  }
3699
3691
  __name(mapTrybeOfferingTypeToBookableItemType, "mapTrybeOfferingTypeToBookableItemType");
3700
3692
  function mapTrybeCouponCodeOfferingToBookableItem(offering, index) {
@@ -3853,7 +3845,7 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
3853
3845
  practitionerIds: request.offeringResources.map((r) => r.externalId),
3854
3846
  durationMinutes: request.durationInMinutes,
3855
3847
  timeIso: request.bookingStartTime.toISOString(),
3856
- sessionId: request.meta.sessionId
3848
+ sessionId: request.meta?.sessionId
3857
3849
  }
3858
3850
  }, integration, loggedInUserId);
3859
3851
  items.push({
@@ -3886,6 +3878,10 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
3886
3878
  }
3887
3879
  }
3888
3880
  async addCustomerToOrder(orderId, customerId, integration, loggedInUserId) {
3881
+ this.logger.info(loggedInUserId, this.addCustomerToOrder.name, this.fileName, "Adding customer to Trybe order", {
3882
+ orderId,
3883
+ customerId
3884
+ });
3889
3885
  const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
3890
3886
  await this.trafficGatewayService.executeIntegrationRequest({
3891
3887
  apiMethod: HTTP_METHOD.POST,
@@ -3897,8 +3893,15 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
3897
3893
  source: "trybe"
3898
3894
  }
3899
3895
  }, validated, loggedInUserId);
3896
+ this.logger.info(loggedInUserId, this.addCustomerToOrder.name, this.fileName, "Successfully added customer to Trybe order", {
3897
+ orderId,
3898
+ customerId
3899
+ });
3900
3900
  }
3901
3901
  async getOrder(orderId, integration, loggedInUserId) {
3902
+ this.logger.info(loggedInUserId, this.getOrder.name, this.fileName, "Fetching Trybe order details", {
3903
+ orderId
3904
+ });
3902
3905
  const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
3903
3906
  const res = await this.trafficGatewayService.executeIntegrationRequest({
3904
3907
  apiMethod: HTTP_METHOD.GET,
@@ -3906,6 +3909,10 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
3906
3909
  baseUrl: validated.config.platformConfig.baseUrl,
3907
3910
  headers: validated.headers
3908
3911
  }, validated, loggedInUserId);
3912
+ this.logger.info(loggedInUserId, this.getOrder.name, this.fileName, "Successfully fetched Trybe order details", {
3913
+ orderId,
3914
+ guestCount: res.data.guests.length
3915
+ });
3909
3916
  return {
3910
3917
  orderId: res.data.id,
3911
3918
  guests: res.data.guests.map((g) => ({
@@ -3931,6 +3938,11 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
3931
3938
  }
3932
3939
  }
3933
3940
  async addItemToOrder(request, integration, loggedInUserId) {
3941
+ this.logger.info(loggedInUserId, this.addItemToOrder.name, this.fileName, "Adding item to Trybe order", {
3942
+ orderId: request.orderId,
3943
+ offeringId: request.item.offeringId,
3944
+ offeringType: request.item.offeringType
3945
+ });
3934
3946
  const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
3935
3947
  const { orderId, item } = request;
3936
3948
  const offeringType = this.mapOfferingTypeToTrybeApi(item.offeringType);
@@ -3978,13 +3990,24 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
3978
3990
  headers: validated.headers,
3979
3991
  body
3980
3992
  }, validated, loggedInUserId);
3981
- const d = res.data;
3982
- return {
3983
- name: d.booking_summary?.offering?.name ?? d.type_name ?? void 0,
3984
- netTotal: d.net_total
3993
+ const data = res.data;
3994
+ const result = {
3995
+ name: data.booking_summary?.offering?.name ?? data.type_name ?? void 0,
3996
+ netTotal: data.net_total
3985
3997
  };
3998
+ this.logger.info(loggedInUserId, this.addItemToOrder.name, this.fileName, "Successfully added item to Trybe order", {
3999
+ orderId,
4000
+ offeringId: item.offeringId,
4001
+ name: result.name,
4002
+ netTotal: result.netTotal
4003
+ });
4004
+ return result;
3986
4005
  }
3987
4006
  async addCustomerCreditsToOrder(orderId, customerCreditId, integration, loggedInUserId) {
4007
+ this.logger.info(loggedInUserId, this.addCustomerCreditsToOrder.name, this.fileName, "Adding customer credits to Trybe order", {
4008
+ orderId,
4009
+ customerCreditId
4010
+ });
3988
4011
  const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
3989
4012
  await this.trafficGatewayService.executeIntegrationRequest({
3990
4013
  apiMethod: HTTP_METHOD.POST,
@@ -3995,8 +4018,15 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
3995
4018
  id: customerCreditId
3996
4019
  }
3997
4020
  }, validated, loggedInUserId);
4021
+ this.logger.info(loggedInUserId, this.addCustomerCreditsToOrder.name, this.fileName, "Successfully added customer credits to Trybe order", {
4022
+ orderId,
4023
+ customerCreditId
4024
+ });
3998
4025
  }
3999
4026
  async submitOrder(orderId, integration, loggedInUserId) {
4027
+ this.logger.info(loggedInUserId, this.submitOrder.name, this.fileName, "Submitting Trybe order", {
4028
+ orderId
4029
+ });
4000
4030
  const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4001
4031
  await this.trafficGatewayService.executeIntegrationRequest({
4002
4032
  apiMethod: HTTP_METHOD.POST,
@@ -4004,8 +4034,14 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
4004
4034
  baseUrl: validated.config.platformConfig.baseUrl,
4005
4035
  headers: validated.headers
4006
4036
  }, validated, loggedInUserId);
4037
+ this.logger.info(loggedInUserId, this.submitOrder.name, this.fileName, "Successfully submitted Trybe order", {
4038
+ orderId
4039
+ });
4007
4040
  }
4008
4041
  async cancelOrder(orderId, integration, loggedInUserId) {
4042
+ this.logger.info(loggedInUserId, this.cancelOrder.name, this.fileName, "Cancelling Trybe order", {
4043
+ orderId
4044
+ });
4009
4045
  const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4010
4046
  await this.trafficGatewayService.executeIntegrationRequest({
4011
4047
  apiMethod: HTTP_METHOD.POST,
@@ -4013,20 +4049,39 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
4013
4049
  baseUrl: validated.config.platformConfig.baseUrl,
4014
4050
  headers: validated.headers
4015
4051
  }, validated, loggedInUserId);
4052
+ this.logger.info(loggedInUserId, this.cancelOrder.name, this.fileName, "Successfully cancelled Trybe order", {
4053
+ orderId
4054
+ });
4016
4055
  }
4017
4056
  async updateOrder(request, integration, loggedInUserId) {
4057
+ this.logger.info(loggedInUserId, this.updateOrder.name, this.fileName, "Updating Trybe order", {
4058
+ orderId: request.orderId,
4059
+ offeringType: request.item.type
4060
+ });
4018
4061
  const order = await this.getOrder(request.orderId, integration, loggedInUserId);
4019
4062
  const itemId = order.items[0]?.id;
4020
4063
  if (!itemId) {
4064
+ this.logger.error(loggedInUserId, this.updateOrder.name, this.fileName, "Item not found in order during update", {
4065
+ orderId: request.orderId
4066
+ });
4021
4067
  throw new Error("Item not found in order");
4022
4068
  }
4023
4069
  const updateResponse = await this.updateOrderItem(request.orderId, itemId, request, integration, loggedInUserId);
4070
+ this.logger.info(loggedInUserId, this.updateOrder.name, this.fileName, "Successfully updated Trybe order", {
4071
+ orderId: request.orderId,
4072
+ itemId
4073
+ });
4024
4074
  return {
4025
4075
  success: Boolean(updateResponse.data.id),
4026
4076
  data: updateResponse.data
4027
4077
  };
4028
4078
  }
4029
4079
  async updateOrderItem(orderId, itemId, request, integration, loggedInUserId) {
4080
+ this.logger.info(loggedInUserId, this.updateOrderItem.name, this.fileName, "Updating Trybe order item", {
4081
+ orderId,
4082
+ itemId,
4083
+ offeringType: request.item.type
4084
+ });
4030
4085
  const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4031
4086
  const offeringType = this.mapOfferingTypeToTrybeApi(request.item.type);
4032
4087
  let body;
@@ -4057,15 +4112,25 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
4057
4112
  } else {
4058
4113
  throw new Error("Course is not updatable");
4059
4114
  }
4060
- return await this.trafficGatewayService.executeIntegrationRequest({
4115
+ const response = await this.trafficGatewayService.executeIntegrationRequest({
4061
4116
  apiMethod: HTTP_METHOD.PUT,
4062
4117
  url: `/shop/orders/${orderId}/items/${itemId}`,
4063
4118
  baseUrl: validated.config.platformConfig.baseUrl,
4064
4119
  headers: validated.headers,
4065
4120
  body
4066
4121
  }, validated, loggedInUserId);
4122
+ this.logger.info(loggedInUserId, this.updateOrderItem.name, this.fileName, "Successfully updated Trybe order item", {
4123
+ orderId,
4124
+ itemId
4125
+ });
4126
+ return response;
4067
4127
  }
4068
4128
  async addPaymentToOrder(request, integration, loggedInUserId) {
4129
+ this.logger.info(loggedInUserId, this.addPaymentToOrder.name, this.fileName, "Adding payment to Trybe order", {
4130
+ orderId: request.orderId,
4131
+ amount: request.amount,
4132
+ paymentTypeId: request.paymentTypeId
4133
+ });
4069
4134
  const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4070
4135
  await this.trafficGatewayService.executeIntegrationRequest({
4071
4136
  apiMethod: HTTP_METHOD.POST,
@@ -4082,211 +4147,279 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
4082
4147
  }
4083
4148
  }
4084
4149
  }, validated, loggedInUserId);
4150
+ this.logger.info(loggedInUserId, this.addPaymentToOrder.name, this.fileName, "Successfully added payment to Trybe order", {
4151
+ orderId: request.orderId,
4152
+ amount: request.amount
4153
+ });
4085
4154
  }
4086
4155
  async fetchAppointments(request, integration, loggedInUserId) {
4087
4156
  this.logger.info(loggedInUserId, this.fetchAppointments.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchAppointments.name} Called`, {
4088
4157
  request
4089
4158
  });
4090
- const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4091
- const siteId = validatedIntegration.config.integrationConfig.siteId;
4092
- if (request.shouldFetchAllAppointments && request.options?.page !== void 0) {
4093
- throw new Error("Pagination options are not supported when fetching all appointments.");
4094
- }
4095
- const query = new URLSearchParams();
4096
- if (request.options?.page != null) {
4097
- query.set("page", String(request.options.page));
4098
- }
4099
- if (request.options?.count != null) {
4100
- query.set("per_page", String(request.options.count));
4159
+ try {
4160
+ const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4161
+ const siteId = validatedIntegration.config.integrationConfig.siteId;
4162
+ if (request.shouldFetchAllAppointments && request.options?.page !== void 0) {
4163
+ throw new Error("Pagination options are not supported when fetching all appointments.");
4164
+ }
4165
+ const query = new URLSearchParams();
4166
+ if (request.options?.page != null) {
4167
+ query.set("page", String(request.options.page));
4168
+ }
4169
+ if (request.options?.count != null) {
4170
+ query.set("per_page", String(request.options.count));
4171
+ }
4172
+ const queryString = query.toString();
4173
+ const apiUrl = `/shop/appointment-types?site_id=${siteId}` + (request.practitionerIds && request.practitionerIds.length > 0 ? `&practitioner_id=${request.practitionerIds.join(",")}` : "") + (queryString ? `&${queryString}` : "");
4174
+ const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4175
+ apiMethod: HTTP_METHOD.GET,
4176
+ url: apiUrl,
4177
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4178
+ headers: validatedIntegration.headers
4179
+ }, validatedIntegration, loggedInUserId);
4180
+ const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllAppointments, (page) => this.trafficGatewayService.executeIntegrationRequest({
4181
+ apiMethod: HTTP_METHOD.GET,
4182
+ url: `${apiUrl}&page=${page}`,
4183
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4184
+ headers: validatedIntegration.headers
4185
+ }, validatedIntegration, loggedInUserId));
4186
+ this.logger.info(loggedInUserId, this.fetchAppointments.name, this.fileName, "Successfully fetched Trybe appointments", {
4187
+ totalRecords: firstPageResponse.meta.total
4188
+ });
4189
+ return mapTrybeAppointmentsToSystemResponse(records, firstPageResponse.meta.total);
4190
+ } catch (err) {
4191
+ this.logger.error(loggedInUserId, this.fetchAppointments.name, this.fileName, "Error fetching Trybe appointments", err);
4192
+ throw err;
4101
4193
  }
4102
- const queryString = query.toString();
4103
- const apiUrl = `/shop/appointment-types?site_id=${siteId}` + (request.practitionerIds && request.practitionerIds.length > 0 ? `&practitioner_id=${request.practitionerIds.join(",")}` : "") + (queryString ? `&${queryString}` : "");
4104
- const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4105
- apiMethod: HTTP_METHOD.GET,
4106
- url: apiUrl,
4107
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4108
- headers: validatedIntegration.headers
4109
- }, validatedIntegration, loggedInUserId);
4110
- const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllAppointments, (page) => this.trafficGatewayService.executeIntegrationRequest({
4111
- apiMethod: HTTP_METHOD.GET,
4112
- url: `${apiUrl}&page=${page}`,
4113
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4114
- headers: validatedIntegration.headers
4115
- }, validatedIntegration, loggedInUserId));
4116
- return mapTrybeAppointmentsToSystemResponse(records, firstPageResponse.meta.total);
4117
4194
  }
4118
4195
  async fetchSessions(request, integration, loggedInUserId) {
4119
4196
  this.logger.info(loggedInUserId, this.fetchSessions.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchSessions.name} Called`, {
4120
4197
  request
4121
4198
  });
4122
- const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4123
- const siteId = validatedIntegration.config.integrationConfig.siteId;
4124
- if (request.shouldFetchAllSessions && request.options?.page !== void 0) {
4125
- throw new Error("Pagination options are not supported when fetching all sessions.");
4126
- }
4127
- const query = new URLSearchParams();
4128
- if (request.options?.page != null) {
4129
- query.set("page", String(request.options.page));
4130
- }
4131
- if (request.options?.count != null) {
4132
- query.set("per_page", String(request.options.count));
4199
+ try {
4200
+ const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4201
+ const siteId = validatedIntegration.config.integrationConfig.siteId;
4202
+ if (request.shouldFetchAllSessions && request.options?.page !== void 0) {
4203
+ throw new Error("Pagination options are not supported when fetching all sessions.");
4204
+ }
4205
+ const query = new URLSearchParams();
4206
+ if (request.options?.page != null) {
4207
+ query.set("page", String(request.options.page));
4208
+ }
4209
+ if (request.options?.count != null) {
4210
+ query.set("per_page", String(request.options.count));
4211
+ }
4212
+ const queryString = query.toString();
4213
+ const apiUrl = `/shop/session-types?site_id=${siteId}` + (request.practitionerIds && request.practitionerIds.length > 0 ? `&practitioner_id=${request.practitionerIds.join(",")}` : "") + (queryString ? `&${queryString}` : "");
4214
+ const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4215
+ apiMethod: HTTP_METHOD.GET,
4216
+ url: apiUrl,
4217
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4218
+ headers: validatedIntegration.headers
4219
+ }, validatedIntegration, loggedInUserId);
4220
+ const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllSessions, (page) => this.trafficGatewayService.executeIntegrationRequest({
4221
+ apiMethod: HTTP_METHOD.GET,
4222
+ url: `${apiUrl}&page=${page}`,
4223
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4224
+ headers: validatedIntegration.headers
4225
+ }, validatedIntegration, loggedInUserId));
4226
+ this.logger.info(loggedInUserId, this.fetchSessions.name, this.fileName, "Successfully fetched Trybe sessions", {
4227
+ totalRecords: firstPageResponse.meta.total
4228
+ });
4229
+ return mapTrybeSessionsToSystemResponse(records, firstPageResponse.meta.total);
4230
+ } catch (err) {
4231
+ this.logger.error(loggedInUserId, this.fetchSessions.name, this.fileName, "Error fetching Trybe sessions", err);
4232
+ throw err;
4133
4233
  }
4134
- const queryString = query.toString();
4135
- const apiUrl = `/shop/session-types?site_id=${siteId}` + (request.practitionerIds && request.practitionerIds.length > 0 ? `&practitioner_id=${request.practitionerIds.join(",")}` : "") + (queryString ? `&${queryString}` : "");
4136
- const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4137
- apiMethod: HTTP_METHOD.GET,
4138
- url: apiUrl,
4139
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4140
- headers: validatedIntegration.headers
4141
- }, validatedIntegration, loggedInUserId);
4142
- const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllSessions, (page) => this.trafficGatewayService.executeIntegrationRequest({
4143
- apiMethod: HTTP_METHOD.GET,
4144
- url: `${apiUrl}&page=${page}`,
4145
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4146
- headers: validatedIntegration.headers
4147
- }, validatedIntegration, loggedInUserId));
4148
- return mapTrybeSessionsToSystemResponse(records, firstPageResponse.meta.total);
4149
4234
  }
4150
4235
  async fetchCourses(request, integration, loggedInUserId) {
4151
4236
  this.logger.info(loggedInUserId, this.fetchCourses.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchCourses.name} Called`, {
4152
4237
  request
4153
4238
  });
4154
- const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4155
- const organisationId = validatedIntegration.config.integrationConfig.organisationId;
4156
- if (request.shouldFetchAllCourses && request.options?.page !== void 0) {
4157
- throw new Error("Pagination options are not supported when fetching all courses.");
4158
- }
4159
- const query = new URLSearchParams();
4160
- if (request.options?.page != null) {
4161
- query.set("page", String(request.options.page));
4162
- }
4163
- if (request.options?.count != null) {
4164
- query.set("per_page", String(request.options.count));
4239
+ try {
4240
+ const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4241
+ const organisationId = validatedIntegration.config.integrationConfig.organisationId;
4242
+ if (request.shouldFetchAllCourses && request.options?.page !== void 0) {
4243
+ throw new Error("Pagination options are not supported when fetching all courses.");
4244
+ }
4245
+ const query = new URLSearchParams();
4246
+ if (request.options?.page != null) {
4247
+ query.set("page", String(request.options.page));
4248
+ }
4249
+ if (request.options?.count != null) {
4250
+ query.set("per_page", String(request.options.count));
4251
+ }
4252
+ const queryString = query.toString();
4253
+ const apiUrl = `/shop/course-types?organisation_id=${organisationId}` + (queryString ? `&${queryString}` : "");
4254
+ const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4255
+ apiMethod: HTTP_METHOD.GET,
4256
+ url: apiUrl,
4257
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4258
+ headers: validatedIntegration.headers
4259
+ }, validatedIntegration, loggedInUserId);
4260
+ const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllCourses, (page) => this.trafficGatewayService.executeIntegrationRequest({
4261
+ apiMethod: HTTP_METHOD.GET,
4262
+ url: `${apiUrl}&page=${page}`,
4263
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4264
+ headers: validatedIntegration.headers
4265
+ }, validatedIntegration, loggedInUserId));
4266
+ this.logger.info(loggedInUserId, this.fetchCourses.name, this.fileName, "Successfully fetched Trybe courses", {
4267
+ totalRecords: firstPageResponse.meta.total
4268
+ });
4269
+ return mapTrybeCoursesToSystemResponse(records, firstPageResponse.meta.total);
4270
+ } catch (err) {
4271
+ this.logger.error(loggedInUserId, this.fetchCourses.name, this.fileName, "Error fetching Trybe courses", err);
4272
+ throw err;
4165
4273
  }
4166
- const queryString = query.toString();
4167
- const apiUrl = `/shop/course-types?organisation_id=${organisationId}` + (queryString ? `&${queryString}` : "");
4168
- const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4169
- apiMethod: HTTP_METHOD.GET,
4170
- url: apiUrl,
4171
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4172
- headers: validatedIntegration.headers
4173
- }, validatedIntegration, loggedInUserId);
4174
- const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllCourses, (page) => this.trafficGatewayService.executeIntegrationRequest({
4175
- apiMethod: HTTP_METHOD.GET,
4176
- url: `${apiUrl}&page=${page}`,
4177
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4178
- headers: validatedIntegration.headers
4179
- }, validatedIntegration, loggedInUserId));
4180
- return mapTrybeCoursesToSystemResponse(records, firstPageResponse.meta.total);
4181
4274
  }
4182
4275
  async fetchPractitioners(request, integration, loggedInUserId) {
4183
4276
  this.logger.info(loggedInUserId, this.fetchPractitioners.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchPractitioners.name} Called`, {
4184
4277
  request
4185
4278
  });
4186
- const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4187
- const siteId = validatedIntegration.config.integrationConfig.siteId;
4188
- const apiUrl = `/shop/practitioners/?site_id=${siteId}`;
4189
- const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4190
- apiMethod: HTTP_METHOD.GET,
4191
- url: apiUrl,
4192
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4193
- headers: validatedIntegration.headers
4194
- }, validatedIntegration, loggedInUserId);
4195
- const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllPractitioners, (page) => this.trafficGatewayService.executeIntegrationRequest({
4196
- apiMethod: HTTP_METHOD.GET,
4197
- url: `${apiUrl}&page=${page}`,
4198
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4199
- headers: validatedIntegration.headers
4200
- }, validatedIntegration, loggedInUserId));
4201
- return mapTrybePractitionersToSystemResponse(records, firstPageResponse.meta.total);
4279
+ try {
4280
+ const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4281
+ const siteId = validatedIntegration.config.integrationConfig.siteId;
4282
+ const apiUrl = `/shop/practitioners/?site_id=${siteId}`;
4283
+ const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4284
+ apiMethod: HTTP_METHOD.GET,
4285
+ url: apiUrl,
4286
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4287
+ headers: validatedIntegration.headers
4288
+ }, validatedIntegration, loggedInUserId);
4289
+ const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllPractitioners, (page) => this.trafficGatewayService.executeIntegrationRequest({
4290
+ apiMethod: HTTP_METHOD.GET,
4291
+ url: `${apiUrl}&page=${page}`,
4292
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4293
+ headers: validatedIntegration.headers
4294
+ }, validatedIntegration, loggedInUserId));
4295
+ this.logger.info(loggedInUserId, this.fetchPractitioners.name, this.fileName, "Successfully fetched Trybe practitioners", {
4296
+ totalRecords: firstPageResponse.meta.total
4297
+ });
4298
+ return mapTrybePractitionersToSystemResponse(records, firstPageResponse.meta.total);
4299
+ } catch (err) {
4300
+ this.logger.error(loggedInUserId, this.fetchPractitioners.name, this.fileName, "Error fetching Trybe practitioners", err);
4301
+ throw err;
4302
+ }
4202
4303
  }
4203
4304
  async fetchCategories(request, integration, loggedInUserId) {
4204
4305
  this.logger.info(loggedInUserId, this.fetchCategories.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchCategories.name} Called`, {
4205
4306
  request
4206
4307
  });
4207
- const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4208
- const organisationId = validatedIntegration.config.integrationConfig.organisationId;
4209
- if (request.shouldFetchAllCategories && request.options?.page !== void 0) {
4210
- throw new Error("Pagination options are not supported when fetching all categories.");
4211
- }
4212
- const query = new URLSearchParams();
4213
- if (request.options?.page != null) {
4214
- query.set("page", String(request.options.page));
4215
- }
4216
- if (request.options?.count != null) {
4217
- query.set("per_page", String(request.options.count));
4308
+ try {
4309
+ const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4310
+ const organisationId = validatedIntegration.config.integrationConfig.organisationId;
4311
+ if (request.shouldFetchAllCategories && request.options?.page !== void 0) {
4312
+ throw new Error("Pagination options are not supported when fetching all categories.");
4313
+ }
4314
+ const query = new URLSearchParams();
4315
+ if (request.options?.page != null) {
4316
+ query.set("page", String(request.options.page));
4317
+ }
4318
+ if (request.options?.count != null) {
4319
+ query.set("per_page", String(request.options.count));
4320
+ }
4321
+ const queryString = query.toString();
4322
+ const apiUrl = `/shop/organisations/${organisationId}/categories` + (queryString ? `?${queryString}` : "");
4323
+ const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4324
+ apiMethod: HTTP_METHOD.GET,
4325
+ url: apiUrl,
4326
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4327
+ headers: validatedIntegration.headers
4328
+ }, validatedIntegration, loggedInUserId);
4329
+ const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllCategories, (page) => this.trafficGatewayService.executeIntegrationRequest({
4330
+ apiMethod: HTTP_METHOD.GET,
4331
+ url: `${apiUrl}${apiUrl.includes("?") ? "&" : "?"}page=${page}`,
4332
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4333
+ headers: validatedIntegration.headers
4334
+ }, validatedIntegration, loggedInUserId));
4335
+ this.logger.info(loggedInUserId, this.fetchCategories.name, this.fileName, "Successfully fetched Trybe categories", {
4336
+ totalRecords: firstPageResponse.meta.total
4337
+ });
4338
+ return mapTrybeCategoriesToSystemResponse(records, firstPageResponse.meta.total);
4339
+ } catch (err) {
4340
+ this.logger.error(loggedInUserId, this.fetchCategories.name, this.fileName, "Error fetching Trybe categories", err);
4341
+ throw err;
4218
4342
  }
4219
- const queryString = query.toString();
4220
- const apiUrl = `/shop/organisations/${organisationId}/categories` + (queryString ? `?${queryString}` : "");
4221
- const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
4222
- apiMethod: HTTP_METHOD.GET,
4223
- url: apiUrl,
4224
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4225
- headers: validatedIntegration.headers
4226
- }, validatedIntegration, loggedInUserId);
4227
- const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllCategories, (page) => this.trafficGatewayService.executeIntegrationRequest({
4228
- apiMethod: HTTP_METHOD.GET,
4229
- url: `${apiUrl}${apiUrl.includes("?") ? "&" : "?"}page=${page}`,
4230
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4231
- headers: validatedIntegration.headers
4232
- }, validatedIntegration, loggedInUserId));
4233
- return mapTrybeCategoriesToSystemResponse(records, firstPageResponse.meta.total);
4234
4343
  }
4235
4344
  async fetchBookableItemsFromCredit(request, integration, loggedInUserId) {
4236
4345
  this.logger.info(loggedInUserId, this.fetchBookableItemsFromCredit.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchBookableItemsFromCredit.name} Called`, {
4237
4346
  request
4238
4347
  });
4239
- const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4240
- const query = new URLSearchParams();
4241
- if (request.options?.page != null) {
4242
- query.set("page", String(request.options.page));
4243
- }
4244
- if (request.options?.count != null) {
4245
- query.set("per_page", String(request.options.count));
4348
+ try {
4349
+ const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4350
+ const query = new URLSearchParams();
4351
+ if (request.options?.page != null) {
4352
+ query.set("page", String(request.options.page));
4353
+ }
4354
+ if (request.options?.count != null) {
4355
+ query.set("per_page", String(request.options.count));
4356
+ }
4357
+ const queryString = query.toString();
4358
+ const apiUrl = `/shop/coupon-codes/${request.couponCodeId}/offering-discounts` + (queryString ? `?${queryString}` : "");
4359
+ const response = await this.trafficGatewayService.executeIntegrationRequest({
4360
+ apiMethod: HTTP_METHOD.GET,
4361
+ url: apiUrl,
4362
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4363
+ headers: validatedIntegration.headers
4364
+ }, validatedIntegration, loggedInUserId);
4365
+ this.logger.info(loggedInUserId, this.fetchBookableItemsFromCredit.name, this.fileName, "Successfully fetched bookable items from credit", {
4366
+ couponCodeId: request.couponCodeId
4367
+ });
4368
+ return mapTrybeCouponCodeOfferingsToSystemResponse(response.data.offerings);
4369
+ } catch (err) {
4370
+ this.logger.error(loggedInUserId, this.fetchBookableItemsFromCredit.name, this.fileName, "Error fetching bookable items from credit", err);
4371
+ throw err;
4246
4372
  }
4247
- const queryString = query.toString();
4248
- const apiUrl = `/shop/coupon-codes/${request.couponCodeId}/offering-discounts` + (queryString ? `?${queryString}` : "");
4249
- const response = await this.trafficGatewayService.executeIntegrationRequest({
4250
- apiMethod: HTTP_METHOD.GET,
4251
- url: apiUrl,
4252
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4253
- headers: validatedIntegration.headers
4254
- }, validatedIntegration, loggedInUserId);
4255
- return mapTrybeCouponCodeOfferingsToSystemResponse(response.data.offerings);
4256
4373
  }
4257
4374
  async fetchSessionAvailabilityForOffering(request, integration, loggedInUserId) {
4258
4375
  this.logger.info(loggedInUserId, this.fetchSessionAvailabilityForOffering.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchSessionAvailabilityForOffering.name} Called`, {
4259
4376
  request
4260
4377
  });
4261
- const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4262
- const siteId = validatedIntegration.config.integrationConfig.siteId;
4263
- const formattedDateTimeFrom = formatDateForTrybe(request.dateTimeFrom, true);
4264
- const formattedDateTimeTo = formatDateForTrybe(request.dateTimeTo, false);
4265
- const apiUrl = `/shop/item-availability/sessions/${siteId}/${request.externalOfferingBookableItemId}?date_time_from=${encodeURIComponent(formattedDateTimeFrom)}&date_time_to=${encodeURIComponent(formattedDateTimeTo)}&offeringId=${request.externalOfferingBookableItemId}`;
4266
- const response = await this.trafficGatewayService.executeIntegrationRequest({
4267
- apiMethod: HTTP_METHOD.GET,
4268
- url: apiUrl,
4269
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4270
- headers: validatedIntegration.headers
4271
- }, validatedIntegration, loggedInUserId);
4272
- return mapTrybeSessionAvailabilityToSystemResponse(response.data);
4378
+ try {
4379
+ const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4380
+ const siteId = validatedIntegration.config.integrationConfig.siteId;
4381
+ const formattedDateTimeFrom = formatDateForTrybe(request.dateTimeFrom, true);
4382
+ const formattedDateTimeTo = formatDateForTrybe(request.dateTimeTo, false);
4383
+ const apiUrl = `/shop/item-availability/sessions/${siteId}/${request.externalOfferingBookableItemId}?date_time_from=${encodeURIComponent(formattedDateTimeFrom)}&date_time_to=${encodeURIComponent(formattedDateTimeTo)}&offeringId=${request.externalOfferingBookableItemId}`;
4384
+ const response = await this.trafficGatewayService.executeIntegrationRequest({
4385
+ apiMethod: HTTP_METHOD.GET,
4386
+ url: apiUrl,
4387
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4388
+ headers: validatedIntegration.headers
4389
+ }, validatedIntegration, loggedInUserId);
4390
+ this.logger.info(loggedInUserId, this.fetchSessionAvailabilityForOffering.name, this.fileName, "Successfully fetched session availability for offering", {
4391
+ externalOfferingBookableItemId: request.externalOfferingBookableItemId
4392
+ });
4393
+ return mapTrybeSessionAvailabilityToSystemResponse(response.data);
4394
+ } catch (err) {
4395
+ this.logger.error(loggedInUserId, this.fetchSessionAvailabilityForOffering.name, this.fileName, "Error fetching session availability for offering", err);
4396
+ throw err;
4397
+ }
4273
4398
  }
4274
4399
  async fetchAppointmentAvailabilityForOffering(request, integration, loggedInUserId) {
4275
4400
  this.logger.info(loggedInUserId, this.fetchAppointmentAvailabilityForOffering.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchAppointmentAvailabilityForOffering.name} Called`, {
4276
4401
  request
4277
4402
  });
4278
- const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4279
- const siteId = validatedIntegration.config.integrationConfig.siteId;
4280
- const formattedDateTimeFrom = formatDateForTrybe(request.dateTimeFrom, true);
4281
- const formattedDateTimeTo = formatDateForTrybe(request.dateTimeTo, false);
4282
- const apiUrl = `/shop/item-availability/appointment-slots/${siteId}/${request.externalOfferingBookableItemId}?date_time_from=${encodeURIComponent(formattedDateTimeFrom)}&date_time_to=${encodeURIComponent(formattedDateTimeTo)}&OfferingID=${request.externalOfferingBookableItemId}`;
4283
- const response = await this.trafficGatewayService.executeIntegrationRequest({
4284
- apiMethod: HTTP_METHOD.GET,
4285
- url: apiUrl,
4286
- baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4287
- headers: validatedIntegration.headers
4288
- }, validatedIntegration, loggedInUserId);
4289
- return mapTrybeAppointmentAvailabilityToSystemResponse(response.data);
4403
+ try {
4404
+ const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
4405
+ const siteId = validatedIntegration.config.integrationConfig.siteId;
4406
+ const formattedDateTimeFrom = formatDateForTrybe(request.dateTimeFrom, true);
4407
+ const formattedDateTimeTo = formatDateForTrybe(request.dateTimeTo, false);
4408
+ const apiUrl = `/shop/item-availability/appointment-slots/${siteId}/${request.externalOfferingBookableItemId}?date_time_from=${encodeURIComponent(formattedDateTimeFrom)}&date_time_to=${encodeURIComponent(formattedDateTimeTo)}&OfferingID=${request.externalOfferingBookableItemId}`;
4409
+ const response = await this.trafficGatewayService.executeIntegrationRequest({
4410
+ apiMethod: HTTP_METHOD.GET,
4411
+ url: apiUrl,
4412
+ baseUrl: validatedIntegration.config.platformConfig.baseUrl,
4413
+ headers: validatedIntegration.headers
4414
+ }, validatedIntegration, loggedInUserId);
4415
+ this.logger.info(loggedInUserId, this.fetchAppointmentAvailabilityForOffering.name, this.fileName, "Successfully fetched appointment availability for offering", {
4416
+ externalOfferingBookableItemId: request.externalOfferingBookableItemId
4417
+ });
4418
+ return mapTrybeAppointmentAvailabilityToSystemResponse(response.data);
4419
+ } catch (err) {
4420
+ this.logger.error(loggedInUserId, this.fetchAppointmentAvailabilityForOffering.name, this.fileName, "Error fetching appointment availability for offering", err);
4421
+ throw err;
4422
+ }
4290
4423
  }
4291
4424
  };
4292
4425
  exports.TrybeWellnessManagement = _ts_decorate18([
@@ -4431,12 +4564,6 @@ exports.TrybeIntegrationResourceManagementService = class TrybeIntegrationResour
4431
4564
  resourceMappingConfig.catalogingBy !== TRYBE_CATALOGING_BY_ENUM.PEOPLE_RESOURCE) {
4432
4565
  throw new dvssBackendModuleUtility.CustomException(dvssBackendModuleUtility.ERROR_NAMES.BAD_REQUEST, "Invalid Trybe resource mapping config: catalogingBy must be PEOPLE_RESOURCE");
4433
4566
  }
4434
- if (resourceMappingConfig.isExternalCmsIntegrationEnabled === void 0 || typeof resourceMappingConfig.isExternalCmsIntegrationEnabled !== "boolean" || resourceMappingConfig.isExternalCmsIntegrationEnabled === false) {
4435
- throw new dvssBackendModuleUtility.CustomException(dvssBackendModuleUtility.ERROR_NAMES.BAD_REQUEST, "Invalid Trybe resource mapping config: isExternalCmsIntegrationEnabled must be true");
4436
- }
4437
- if (!resourceMappingConfig.externalCmsUrl || !isValidHttpUrl(resourceMappingConfig.externalCmsUrl)) {
4438
- throw new dvssBackendModuleUtility.CustomException(dvssBackendModuleUtility.ERROR_NAMES.BAD_REQUEST, "Invalid Trybe resource mapping config: externalCmsUrl must be a valid HTTP(S) URL");
4439
- }
4440
4567
  if (!resourceMappingConfig.supportedJourneys.some((journey) => VALID_JOURNEY_VALUES.has(journey))) {
4441
4568
  throw new dvssBackendModuleUtility.CustomException(dvssBackendModuleUtility.ERROR_NAMES.BAD_REQUEST, "Invalid Trybe resource mapping config: supportedJourneys must contain at least one of SESSION, COURSE, APPOINTMENT");
4442
4569
  }