@zodic/shared 0.0.37 → 0.0.38

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.
@@ -0,0 +1,37 @@
1
+ import { BackendBindings } from '@zodic/shared';
2
+
3
+ export async function makeAstrologyApiCall(
4
+ path: string,
5
+ payload: any | null,
6
+ env: BackendBindings
7
+ ): Promise<any> {
8
+ const auth = `Basic ${btoa(
9
+ `${env.ASTROLOGY_WESTERN_USER_ID}:${env.ASTROLOGY_WESTERN_API_KEY}`
10
+ )}`;
11
+
12
+ const url = `https://json.astrologyapi.com/v1/${path}`
13
+
14
+ try {
15
+ const response = await fetch(url, {
16
+ method: payload ? 'POST' : 'GET',
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ Authorization: auth,
20
+ 'Accept-Language': 'en',
21
+ },
22
+ body: payload ? JSON.stringify(payload) : undefined,
23
+ });
24
+
25
+ if (!response.ok) {
26
+ const errorText = await response.text();
27
+ throw new Error(
28
+ `Astrology API call failed: ${response.statusText} - ${errorText}`
29
+ );
30
+ }
31
+
32
+ return await response.json();
33
+ } catch (error) {
34
+ console.error(`Error calling Astrology API: ${url}`, error);
35
+ throw new Error('Failed to fetch astrology data');
36
+ }
37
+ }