@zodic/shared 0.0.133 → 0.0.135
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/app/api/astrology/index.ts +80 -23
- package/package.json +1 -1
- package/utils/index.ts +6 -5
|
@@ -1,36 +1,93 @@
|
|
|
1
1
|
import { BackendBindings } from '../../../types';
|
|
2
2
|
|
|
3
|
-
export async function makeAstrologyApiCall(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
) {
|
|
9
|
-
|
|
3
|
+
// export async function makeAstrologyApiCall(
|
|
4
|
+
// path: string,
|
|
5
|
+
// payload: any,
|
|
6
|
+
// env: BackendBindings,
|
|
7
|
+
// language: string
|
|
8
|
+
// ) {
|
|
9
|
+
// const shortLanguage = language.slice(0, 2); // Extracts only "en" or "pt"
|
|
10
|
+
|
|
11
|
+
// const endpoint = `https://astrologyapi.com/api/${path}`;
|
|
12
|
+
// const headers = {
|
|
13
|
+
// Authorization: `Bearer ${env.ASTROLOGY_WESTERN_API_KEY}`,
|
|
14
|
+
// 'Content-Type': 'application/json',
|
|
15
|
+
// 'Accept-Language': shortLanguage, // Sends "en" or "pt"
|
|
16
|
+
// };
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
// try {
|
|
19
|
+
// const response = await fetch(endpoint, {
|
|
20
|
+
// method: 'POST',
|
|
21
|
+
// headers,
|
|
22
|
+
// body: JSON.stringify(payload),
|
|
23
|
+
// });
|
|
17
24
|
|
|
25
|
+
// if (!response.ok) {
|
|
26
|
+
// const error = await response.json();
|
|
27
|
+
// console.error('Astrology API Error:', error);
|
|
28
|
+
// throw new Error(`Astrology API Error: ${response.status}`);
|
|
29
|
+
// }
|
|
30
|
+
|
|
31
|
+
// return await response.json();
|
|
32
|
+
// } catch (err: any) {
|
|
33
|
+
// console.error('Error calling Astrology API:', err.message);
|
|
34
|
+
// throw err;
|
|
35
|
+
// }
|
|
36
|
+
// }
|
|
37
|
+
|
|
38
|
+
export const makeAstrologyApiCall = async (
|
|
39
|
+
path: string,
|
|
40
|
+
payload: Record<string, any>,
|
|
41
|
+
env: BackendBindings,
|
|
42
|
+
language: 'en-us' | 'pt-br'
|
|
43
|
+
) => {
|
|
44
|
+
const shortLanguage = language.slice(0, 2);
|
|
18
45
|
try {
|
|
19
|
-
const
|
|
46
|
+
const url = `https://astrologyapi.com/api/${path}`;
|
|
47
|
+
console.log(`🌍 Making Astrology API Call: ${url}`);
|
|
48
|
+
|
|
49
|
+
const response = await fetch(url, {
|
|
20
50
|
method: 'POST',
|
|
21
|
-
headers
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
'Accept-Language': shortLanguage,
|
|
54
|
+
Authorization: `Bearer ${env.ASTROLOGY_WESTERN_API_KEY}`,
|
|
55
|
+
},
|
|
22
56
|
body: JSON.stringify(payload),
|
|
23
57
|
});
|
|
24
58
|
|
|
59
|
+
// ✅ Log response status
|
|
60
|
+
console.log(`🔄 Response Status (${path}):`, response.status);
|
|
61
|
+
|
|
62
|
+
// ✅ Handle non-OK responses gracefully
|
|
25
63
|
if (!response.ok) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
64
|
+
console.error(
|
|
65
|
+
`❌ API Error (${path}):`,
|
|
66
|
+
response.status,
|
|
67
|
+
await response.text()
|
|
68
|
+
);
|
|
69
|
+
throw new Error(`Failed to fetch astrology data from ${path}`);
|
|
29
70
|
}
|
|
30
71
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
72
|
+
// ✅ Check if response body is empty
|
|
73
|
+
const text = await response.text();
|
|
74
|
+
if (!text) {
|
|
75
|
+
console.error(`❌ API Response Empty (${path})`);
|
|
76
|
+
throw new Error(`Empty response from ${path}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ✅ Try parsing JSON
|
|
80
|
+
try {
|
|
81
|
+
return JSON.parse(text);
|
|
82
|
+
} catch (jsonError) {
|
|
83
|
+
console.error(`❌ JSON Parse Error (${path}):`, jsonError);
|
|
84
|
+
throw new Error(`Invalid JSON response from ${path}`);
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error(
|
|
88
|
+
`❌ Astrology API Call Failed (${path}):`,
|
|
89
|
+
(error as Error).message
|
|
90
|
+
);
|
|
91
|
+
throw error;
|
|
35
92
|
}
|
|
36
|
-
}
|
|
93
|
+
};
|
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -101,17 +101,17 @@ export const verifyToken = async (
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
export const providers: (c: AuthCtx) => Record<Provider, ProviderInfo> = () => ({
|
|
104
|
+
export const providers: (c: AuthCtx) => Record<Provider, ProviderInfo> = (c) => ({
|
|
105
105
|
google: {
|
|
106
106
|
serverUrl: 'https://accounts.google.com/.well-known/openid-configuration', // ✅ Correct Discovery URL
|
|
107
|
-
clientId:
|
|
108
|
-
clientSecret:
|
|
107
|
+
clientId: c.env.GOOGLE_OAUTH_CLIENT_ID!,
|
|
108
|
+
clientSecret: c.env.GOOGLE_OAUTH_CLIENT_SECRET!,
|
|
109
109
|
resourceUrl: 'https://www.googleapis.com/oauth2/v2/userinfo',
|
|
110
110
|
},
|
|
111
111
|
facebook: {
|
|
112
112
|
serverUrl: 'https://www.facebook.com/.well-known/openid-configuration', // ✅ Facebook equivalent
|
|
113
|
-
clientId:
|
|
114
|
-
clientSecret:
|
|
113
|
+
clientId: c.env.FACEBOOK_OAUTH_CLIENT_ID!,
|
|
114
|
+
clientSecret: c.env.FACEBOOK_OAUTH_CLIENT_SECRET!,
|
|
115
115
|
resourceUrl: 'https://graph.facebook.com/me?fields=id,name,email,picture',
|
|
116
116
|
},
|
|
117
117
|
});
|
|
@@ -119,3 +119,4 @@ export const providers: (c: AuthCtx) => Record<Provider, ProviderInfo> = () => (
|
|
|
119
119
|
export function normalizeName(name: string): string {
|
|
120
120
|
return name.toLowerCase().replace(/\s+/g, '-');
|
|
121
121
|
}
|
|
122
|
+
|