@blackcode_sa/metaestetics-api 1.5.38 → 1.5.40

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.d.mts CHANGED
@@ -6385,6 +6385,18 @@ declare class AppointmentService extends BaseService {
6385
6385
  * @returns Array of available booking slots
6386
6386
  */
6387
6387
  getAvailableBookingSlots(clinicId: string, practitionerId: string, procedureId: string, startDate: Date, endDate: Date): Promise<AvailableSlot[]>;
6388
+ /**
6389
+ * Gets available booking slots for a specific clinic, practitioner, and procedure using HTTP request.
6390
+ * This is an alternative implementation using direct HTTP request instead of callable function.
6391
+ *
6392
+ * @param clinicId ID of the clinic
6393
+ * @param practitionerId ID of the practitioner
6394
+ * @param procedureId ID of the procedure
6395
+ * @param startDate Start date of the time range to check
6396
+ * @param endDate End date of the time range to check
6397
+ * @returns Array of available booking slots
6398
+ */
6399
+ getAvailableBookingSlotsHttp(clinicId: string, practitionerId: string, procedureId: string, startDate: Date, endDate: Date): Promise<AvailableSlot[]>;
6388
6400
  /**
6389
6401
  * Creates a new appointment.
6390
6402
  *
package/dist/index.d.ts CHANGED
@@ -6385,6 +6385,18 @@ declare class AppointmentService extends BaseService {
6385
6385
  * @returns Array of available booking slots
6386
6386
  */
6387
6387
  getAvailableBookingSlots(clinicId: string, practitionerId: string, procedureId: string, startDate: Date, endDate: Date): Promise<AvailableSlot[]>;
6388
+ /**
6389
+ * Gets available booking slots for a specific clinic, practitioner, and procedure using HTTP request.
6390
+ * This is an alternative implementation using direct HTTP request instead of callable function.
6391
+ *
6392
+ * @param clinicId ID of the clinic
6393
+ * @param practitionerId ID of the practitioner
6394
+ * @param procedureId ID of the procedure
6395
+ * @param startDate Start date of the time range to check
6396
+ * @param endDate End date of the time range to check
6397
+ * @returns Array of available booking slots
6398
+ */
6399
+ getAvailableBookingSlotsHttp(clinicId: string, practitionerId: string, procedureId: string, startDate: Date, endDate: Date): Promise<AvailableSlot[]>;
6388
6400
  /**
6389
6401
  * Creates a new appointment.
6390
6402
  *
package/dist/index.js CHANGED
@@ -11786,6 +11786,37 @@ var AppointmentService = class extends BaseService {
11786
11786
  console.log(
11787
11787
  `[APPOINTMENT_SERVICE] Getting available booking slots for clinic: ${clinicId}, practitioner: ${practitionerId}, procedure: ${procedureId}`
11788
11788
  );
11789
+ return this.getAvailableBookingSlotsHttp(
11790
+ clinicId,
11791
+ practitionerId,
11792
+ procedureId,
11793
+ startDate,
11794
+ endDate
11795
+ );
11796
+ } catch (error) {
11797
+ console.error(
11798
+ "[APPOINTMENT_SERVICE] Error getting available booking slots:",
11799
+ error
11800
+ );
11801
+ throw error;
11802
+ }
11803
+ }
11804
+ /**
11805
+ * Gets available booking slots for a specific clinic, practitioner, and procedure using HTTP request.
11806
+ * This is an alternative implementation using direct HTTP request instead of callable function.
11807
+ *
11808
+ * @param clinicId ID of the clinic
11809
+ * @param practitionerId ID of the practitioner
11810
+ * @param procedureId ID of the procedure
11811
+ * @param startDate Start date of the time range to check
11812
+ * @param endDate End date of the time range to check
11813
+ * @returns Array of available booking slots
11814
+ */
11815
+ async getAvailableBookingSlotsHttp(clinicId, practitionerId, procedureId, startDate, endDate) {
11816
+ try {
11817
+ console.log(
11818
+ `[APPOINTMENT_SERVICE] Getting available booking slots via HTTP for clinic: ${clinicId}, practitioner: ${practitionerId}, procedure: ${procedureId}`
11819
+ );
11789
11820
  if (!clinicId || !practitionerId || !procedureId || !startDate || !endDate) {
11790
11821
  throw new Error(
11791
11822
  "Missing required parameters for booking slots calculation"
@@ -11800,14 +11831,12 @@ var AppointmentService = class extends BaseService {
11800
11831
  "User must be authenticated to get available booking slots"
11801
11832
  );
11802
11833
  }
11834
+ const idToken = await currentUser.getIdToken();
11803
11835
  console.log(
11804
- `[APPOINTMENT_SERVICE] Authenticated user ID: ${currentUser.uid}. Preparing to call getAvailableBookingSlots function.`
11836
+ `[APPOINTMENT_SERVICE] Got user token, user ID: ${currentUser.uid}`
11805
11837
  );
11806
- const getAvailableBookingSlotsFunction = (0, import_functions.httpsCallable)(
11807
- this.functions,
11808
- "getAvailableBookingSlots"
11809
- );
11810
- const result = await getAvailableBookingSlotsFunction({
11838
+ const functionUrl = `https://getavailablebookingslotshttp-grqala5m6a-oa.a.run.app`;
11839
+ const requestData = {
11811
11840
  clinicId,
11812
11841
  practitionerId,
11813
11842
  procedureId,
@@ -11816,23 +11845,57 @@ var AppointmentService = class extends BaseService {
11816
11845
  // Convert to timestamp
11817
11846
  end: endDate.getTime()
11818
11847
  }
11848
+ };
11849
+ console.log(
11850
+ `[APPOINTMENT_SERVICE] Making fetch request to ${functionUrl}`
11851
+ );
11852
+ const response = await fetch(functionUrl, {
11853
+ method: "POST",
11854
+ mode: "cors",
11855
+ // Important for cross-origin requests
11856
+ cache: "no-cache",
11857
+ // Don't cache this request
11858
+ credentials: "omit",
11859
+ // Don't send cookies since we're using token auth
11860
+ headers: {
11861
+ "Content-Type": "application/json",
11862
+ Authorization: `Bearer ${idToken}`
11863
+ },
11864
+ redirect: "follow",
11865
+ referrerPolicy: "no-referrer",
11866
+ body: JSON.stringify(requestData)
11819
11867
  });
11820
- const response = result.data;
11821
- if (!response.success) {
11868
+ console.log(
11869
+ `[APPOINTMENT_SERVICE] Received response ${response.status}: ${response.statusText}`
11870
+ );
11871
+ if (!response.ok) {
11872
+ const errorText = await response.text();
11873
+ console.error(
11874
+ `[APPOINTMENT_SERVICE] Error response details: ${errorText}`
11875
+ );
11822
11876
  throw new Error(
11823
- response.error || "Failed to get available booking slots"
11877
+ `Failed to get available booking slots: ${response.status} ${response.statusText} - ${errorText}`
11824
11878
  );
11825
11879
  }
11826
- const slots = response.availableSlots.map((slot) => ({
11827
- start: new Date(slot.start)
11828
- }));
11880
+ const result = await response.json();
11881
+ console.log(`[APPOINTMENT_SERVICE] Response parsed successfully`, result);
11882
+ if (!result.success) {
11883
+ throw new Error(
11884
+ result.error || "Failed to get available booking slots"
11885
+ );
11886
+ }
11887
+ const slots = result.availableSlots.map(
11888
+ (slot) => ({
11889
+ start: new Date(slot.start)
11890
+ })
11891
+ );
11829
11892
  console.log(
11830
- `[APPOINTMENT_SERVICE] Found ${slots.length} available booking slots`
11893
+ `[APPOINTMENT_SERVICE] Found ${slots.length} available booking slots via HTTP`
11831
11894
  );
11832
11895
  return slots;
11833
11896
  } catch (error) {
11834
11897
  console.error(
11835
- "[APPOINTMENT_SERVICE] Error getting available booking slots:",
11898
+ "[APPOINTMENT_SERVICE] Error getting available booking slots via HTTP:",
11836
11899
  error
11837
11900
  );
11838
11901
  throw error;
package/dist/index.mjs CHANGED
@@ -11471,7 +11471,7 @@ var ReviewService = class extends BaseService {
11471
11471
  import {
11472
11472
  Timestamp as Timestamp28
11473
11473
  } from "firebase/firestore";
11474
- import { getFunctions, httpsCallable } from "firebase/functions";
11474
+ import { getFunctions } from "firebase/functions";
11475
11475
 
11476
11476
  // src/services/appointment/utils/appointment.utils.ts
11477
11477
  import {
@@ -11875,6 +11875,37 @@ var AppointmentService = class extends BaseService {
11875
11875
  console.log(
11876
11876
  `[APPOINTMENT_SERVICE] Getting available booking slots for clinic: ${clinicId}, practitioner: ${practitionerId}, procedure: ${procedureId}`
11877
11877
  );
11878
+ return this.getAvailableBookingSlotsHttp(
11879
+ clinicId,
11880
+ practitionerId,
11881
+ procedureId,
11882
+ startDate,
11883
+ endDate
11884
+ );
11885
+ } catch (error) {
11886
+ console.error(
11887
+ "[APPOINTMENT_SERVICE] Error getting available booking slots:",
11888
+ error
11889
+ );
11890
+ throw error;
11891
+ }
11892
+ }
11893
+ /**
11894
+ * Gets available booking slots for a specific clinic, practitioner, and procedure using HTTP request.
11895
+ * This is an alternative implementation using direct HTTP request instead of callable function.
11896
+ *
11897
+ * @param clinicId ID of the clinic
11898
+ * @param practitionerId ID of the practitioner
11899
+ * @param procedureId ID of the procedure
11900
+ * @param startDate Start date of the time range to check
11901
+ * @param endDate End date of the time range to check
11902
+ * @returns Array of available booking slots
11903
+ */
11904
+ async getAvailableBookingSlotsHttp(clinicId, practitionerId, procedureId, startDate, endDate) {
11905
+ try {
11906
+ console.log(
11907
+ `[APPOINTMENT_SERVICE] Getting available booking slots via HTTP for clinic: ${clinicId}, practitioner: ${practitionerId}, procedure: ${procedureId}`
11908
+ );
11878
11909
  if (!clinicId || !practitionerId || !procedureId || !startDate || !endDate) {
11879
11910
  throw new Error(
11880
11911
  "Missing required parameters for booking slots calculation"
@@ -11889,14 +11920,12 @@ var AppointmentService = class extends BaseService {
11889
11920
  "User must be authenticated to get available booking slots"
11890
11921
  );
11891
11922
  }
11923
+ const idToken = await currentUser.getIdToken();
11892
11924
  console.log(
11893
- `[APPOINTMENT_SERVICE] Authenticated user ID: ${currentUser.uid}. Preparing to call getAvailableBookingSlots function.`
11925
+ `[APPOINTMENT_SERVICE] Got user token, user ID: ${currentUser.uid}`
11894
11926
  );
11895
- const getAvailableBookingSlotsFunction = httpsCallable(
11896
- this.functions,
11897
- "getAvailableBookingSlots"
11898
- );
11899
- const result = await getAvailableBookingSlotsFunction({
11927
+ const functionUrl = `https://getavailablebookingslotshttp-grqala5m6a-oa.a.run.app`;
11928
+ const requestData = {
11900
11929
  clinicId,
11901
11930
  practitionerId,
11902
11931
  procedureId,
@@ -11905,23 +11934,57 @@ var AppointmentService = class extends BaseService {
11905
11934
  // Convert to timestamp
11906
11935
  end: endDate.getTime()
11907
11936
  }
11937
+ };
11938
+ console.log(
11939
+ `[APPOINTMENT_SERVICE] Making fetch request to ${functionUrl}`
11940
+ );
11941
+ const response = await fetch(functionUrl, {
11942
+ method: "POST",
11943
+ mode: "cors",
11944
+ // Important for cross-origin requests
11945
+ cache: "no-cache",
11946
+ // Don't cache this request
11947
+ credentials: "omit",
11948
+ // Don't send cookies since we're using token auth
11949
+ headers: {
11950
+ "Content-Type": "application/json",
11951
+ Authorization: `Bearer ${idToken}`
11952
+ },
11953
+ redirect: "follow",
11954
+ referrerPolicy: "no-referrer",
11955
+ body: JSON.stringify(requestData)
11908
11956
  });
11909
- const response = result.data;
11910
- if (!response.success) {
11957
+ console.log(
11958
+ `[APPOINTMENT_SERVICE] Received response ${response.status}: ${response.statusText}`
11959
+ );
11960
+ if (!response.ok) {
11961
+ const errorText = await response.text();
11962
+ console.error(
11963
+ `[APPOINTMENT_SERVICE] Error response details: ${errorText}`
11964
+ );
11911
11965
  throw new Error(
11912
- response.error || "Failed to get available booking slots"
11966
+ `Failed to get available booking slots: ${response.status} ${response.statusText} - ${errorText}`
11913
11967
  );
11914
11968
  }
11915
- const slots = response.availableSlots.map((slot) => ({
11916
- start: new Date(slot.start)
11917
- }));
11969
+ const result = await response.json();
11970
+ console.log(`[APPOINTMENT_SERVICE] Response parsed successfully`, result);
11971
+ if (!result.success) {
11972
+ throw new Error(
11973
+ result.error || "Failed to get available booking slots"
11974
+ );
11975
+ }
11976
+ const slots = result.availableSlots.map(
11977
+ (slot) => ({
11978
+ start: new Date(slot.start)
11979
+ })
11980
+ );
11918
11981
  console.log(
11919
- `[APPOINTMENT_SERVICE] Found ${slots.length} available booking slots`
11982
+ `[APPOINTMENT_SERVICE] Found ${slots.length} available booking slots via HTTP`
11920
11983
  );
11921
11984
  return slots;
11922
11985
  } catch (error) {
11923
11986
  console.error(
11924
- "[APPOINTMENT_SERVICE] Error getting available booking slots:",
11987
+ "[APPOINTMENT_SERVICE] Error getting available booking slots via HTTP:",
11925
11988
  error
11926
11989
  );
11927
11990
  throw error;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.5.38",
4
+ "version": "1.5.40",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -106,6 +106,46 @@ export class AppointmentService extends BaseService {
106
106
  `[APPOINTMENT_SERVICE] Getting available booking slots for clinic: ${clinicId}, practitioner: ${practitionerId}, procedure: ${procedureId}`
107
107
  );
108
108
 
109
+ // Just call our HTTP implementation since the callable function isn't working in the browser
110
+ return this.getAvailableBookingSlotsHttp(
111
+ clinicId,
112
+ practitionerId,
113
+ procedureId,
114
+ startDate,
115
+ endDate
116
+ );
117
+ } catch (error) {
118
+ console.error(
119
+ "[APPOINTMENT_SERVICE] Error getting available booking slots:",
120
+ error
121
+ );
122
+ throw error;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Gets available booking slots for a specific clinic, practitioner, and procedure using HTTP request.
128
+ * This is an alternative implementation using direct HTTP request instead of callable function.
129
+ *
130
+ * @param clinicId ID of the clinic
131
+ * @param practitionerId ID of the practitioner
132
+ * @param procedureId ID of the procedure
133
+ * @param startDate Start date of the time range to check
134
+ * @param endDate End date of the time range to check
135
+ * @returns Array of available booking slots
136
+ */
137
+ async getAvailableBookingSlotsHttp(
138
+ clinicId: string,
139
+ practitionerId: string,
140
+ procedureId: string,
141
+ startDate: Date,
142
+ endDate: Date
143
+ ): Promise<AvailableSlot[]> {
144
+ try {
145
+ console.log(
146
+ `[APPOINTMENT_SERVICE] Getting available booking slots via HTTP for clinic: ${clinicId}, practitioner: ${practitionerId}, procedure: ${procedureId}`
147
+ );
148
+
109
149
  // Validate input parameters
110
150
  if (
111
151
  !clinicId ||
@@ -131,19 +171,21 @@ export class AppointmentService extends BaseService {
131
171
  );
132
172
  }
133
173
 
134
- // Log the authenticated user ID before making the call
174
+ // Get the authenticated user's ID token
175
+ const idToken = await currentUser.getIdToken();
176
+
177
+ // Log that we're getting a token
135
178
  console.log(
136
- `[APPOINTMENT_SERVICE] Authenticated user ID: ${currentUser.uid}. Preparing to call getAvailableBookingSlots function.`
179
+ `[APPOINTMENT_SERVICE] Got user token, user ID: ${currentUser.uid}`
137
180
  );
138
181
 
139
- // Create a callable function reference
140
- const getAvailableBookingSlotsFunction = httpsCallable(
141
- this.functions,
142
- "getAvailableBookingSlots"
143
- );
182
+ // Construct the function URL - using the europe-west6 region
183
+ const functionUrl = `https://getavailablebookingslotshttp-grqala5m6a-oa.a.run.app`;
184
+
185
+ // Alternate URL: europe-west6-metaestetics.cloudfunctions.net/getAvailableBookingSlotsHttp
144
186
 
145
- // Call the cloud function with required parameters
146
- const result = await getAvailableBookingSlotsFunction({
187
+ // Request data
188
+ const requestData = {
147
189
  clinicId,
148
190
  practitionerId,
149
191
  procedureId,
@@ -151,34 +193,67 @@ export class AppointmentService extends BaseService {
151
193
  start: startDate.getTime(), // Convert to timestamp
152
194
  end: endDate.getTime(),
153
195
  },
196
+ };
197
+
198
+ console.log(
199
+ `[APPOINTMENT_SERVICE] Making fetch request to ${functionUrl}`
200
+ );
201
+
202
+ // Make the HTTP request with expanded CORS options for browser
203
+ const response = await fetch(functionUrl, {
204
+ method: "POST",
205
+ mode: "cors", // Important for cross-origin requests
206
+ cache: "no-cache", // Don't cache this request
207
+ credentials: "omit", // Don't send cookies since we're using token auth
208
+ headers: {
209
+ "Content-Type": "application/json",
210
+ Authorization: `Bearer ${idToken}`,
211
+ },
212
+ redirect: "follow",
213
+ referrerPolicy: "no-referrer",
214
+ body: JSON.stringify(requestData),
154
215
  });
155
216
 
156
- // Process the response
157
- const response = result.data as {
158
- success: boolean;
159
- availableSlots: { start: number }[];
160
- error?: string;
161
- };
217
+ console.log(
218
+ `[APPOINTMENT_SERVICE] Received response ${response.status}: ${response.statusText}`
219
+ );
162
220
 
163
- if (!response.success) {
221
+ // Check if the request was successful
222
+ if (!response.ok) {
223
+ const errorText = await response.text();
224
+ console.error(
225
+ `[APPOINTMENT_SERVICE] Error response details: ${errorText}`
226
+ );
164
227
  throw new Error(
165
- response.error || "Failed to get available booking slots"
228
+ `Failed to get available booking slots: ${response.status} ${response.statusText} - ${errorText}`
229
+ );
230
+ }
231
+
232
+ // Parse the response
233
+ const result = await response.json();
234
+ console.log(`[APPOINTMENT_SERVICE] Response parsed successfully`, result);
235
+
236
+ if (!result.success) {
237
+ throw new Error(
238
+ result.error || "Failed to get available booking slots"
166
239
  );
167
240
  }
168
241
 
169
242
  // Convert timestamp numbers to Date objects
170
- const slots: AvailableSlot[] = response.availableSlots.map((slot) => ({
171
- start: new Date(slot.start),
172
- }));
243
+ const slots: AvailableSlot[] = result.availableSlots.map(
244
+ (slot: { start: number }) => ({
245
+ start: new Date(slot.start),
246
+ })
247
+ );
173
248
 
174
249
  console.log(
175
- `[APPOINTMENT_SERVICE] Found ${slots.length} available booking slots`
250
+ `[APPOINTMENT_SERVICE] Found ${slots.length} available booking slots via HTTP`
176
251
  );
177
252
 
178
253
  return slots;
179
254
  } catch (error) {
180
255
  console.error(
181
- "[APPOINTMENT_SERVICE] Error getting available booking slots:",
256
+ "[APPOINTMENT_SERVICE] Error getting available booking slots via HTTP:",
182
257
  error
183
258
  );
184
259
  throw error;