@upeex/ads-sdk 0.1.3 → 0.1.5
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/AdBanner.d.ts +2 -1
- package/dist/core.d.ts +2 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +99 -35
- package/package.json +1 -1
package/dist/AdBanner.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ type Props = {
|
|
|
4
4
|
baseUrl?: string;
|
|
5
5
|
theme?: 'light' | 'dark';
|
|
6
6
|
style?: object;
|
|
7
|
+
debug?: boolean;
|
|
7
8
|
};
|
|
8
|
-
export default function AdBanner({ client, slot, baseUrl, theme, style, }: Props): any;
|
|
9
|
+
export default function AdBanner({ client, slot, baseUrl, theme, style, debug, }: Props): any;
|
|
9
10
|
export {};
|
package/dist/core.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ type LoadAdParams = {
|
|
|
3
3
|
client: string;
|
|
4
4
|
slot: string;
|
|
5
5
|
display?: string;
|
|
6
|
+
debug?: boolean;
|
|
6
7
|
};
|
|
7
|
-
export declare function fetchAd({ baseUrl, client, slot, display, }: LoadAdParams): Promise<any>;
|
|
8
|
-
export declare function countView(baseUrl: string, token: string): Promise<void>;
|
|
8
|
+
export declare function fetchAd({ baseUrl, client, slot, display, debug, }: LoadAdParams): Promise<any>;
|
|
9
9
|
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useEffect } from 'react';
|
|
3
|
-
import { Platform, Dimensions, StyleSheet,
|
|
3
|
+
import { Platform, Dimensions, StyleSheet, View, Text, TouchableOpacity, Image, Linking } from 'react-native';
|
|
4
4
|
|
|
5
5
|
async function getSignals() {
|
|
6
6
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -39,8 +39,12 @@ async function getSignals() {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
async function fetchAd({ baseUrl, client, slot, display = 'BANNER', }) {
|
|
42
|
+
async function fetchAd({ baseUrl, client, slot, display = 'BANNER', debug = false, }) {
|
|
43
43
|
const signals = await getSignals();
|
|
44
|
+
if (debug) {
|
|
45
|
+
console.log('[ADS] signals:', signals);
|
|
46
|
+
}
|
|
47
|
+
// 1️⃣ chama o make
|
|
44
48
|
const res = await fetch(`${baseUrl}/make`, {
|
|
45
49
|
method: 'POST',
|
|
46
50
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -52,62 +56,122 @@ async function fetchAd({ baseUrl, client, slot, display = 'BANNER', }) {
|
|
|
52
56
|
...signals,
|
|
53
57
|
}),
|
|
54
58
|
});
|
|
55
|
-
if (!res.ok)
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
if (debug)
|
|
61
|
+
console.error('[ADS] make error:', res.status);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
// make retorna UMA URL
|
|
65
|
+
const showUrl = await res.text();
|
|
66
|
+
if (debug) {
|
|
67
|
+
console.log('[ADS] showUrl:', showUrl);
|
|
68
|
+
}
|
|
69
|
+
// 2️⃣ faz GET nessa URL
|
|
70
|
+
const adRes = await fetch(showUrl);
|
|
71
|
+
if (!adRes.ok) {
|
|
72
|
+
if (debug)
|
|
73
|
+
console.error('[ADS] show error:', adRes.status);
|
|
56
74
|
return null;
|
|
57
|
-
return res.json();
|
|
58
|
-
}
|
|
59
|
-
async function countView(baseUrl, token) {
|
|
60
|
-
try {
|
|
61
|
-
await fetch(`${baseUrl}/count/views`, {
|
|
62
|
-
method: 'POST',
|
|
63
|
-
headers: { 'Content-Type': 'application/json' },
|
|
64
|
-
body: JSON.stringify({ token }),
|
|
65
|
-
});
|
|
66
75
|
}
|
|
67
|
-
|
|
76
|
+
const adData = await adRes.json();
|
|
77
|
+
if (debug) {
|
|
78
|
+
console.log('[ADS] adData:', adData);
|
|
79
|
+
}
|
|
80
|
+
return adData;
|
|
68
81
|
}
|
|
69
82
|
|
|
70
|
-
function AdBanner({ client, slot, baseUrl = 'https://
|
|
83
|
+
function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br/ad', theme = 'light', style = {}, debug = false, }) {
|
|
71
84
|
const [ad, setAd] = useState(null);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
const [error, setError] = useState(null);
|
|
86
|
+
const log = (...args) => {
|
|
87
|
+
if (debug)
|
|
88
|
+
console.log('[UPEEX ADS]', ...args);
|
|
89
|
+
};
|
|
90
|
+
async function loadAd() {
|
|
91
|
+
try {
|
|
92
|
+
log('Carregando anúncio', { client, slot, baseUrl });
|
|
93
|
+
const data = await fetchAd({
|
|
94
|
+
baseUrl,
|
|
95
|
+
client,
|
|
96
|
+
slot,
|
|
97
|
+
debug,
|
|
98
|
+
});
|
|
99
|
+
log('Resposta do anúncio', data);
|
|
100
|
+
if (!(data === null || data === void 0 ? void 0 : data.image) || !(data === null || data === void 0 ? void 0 : data.clickUrl)) {
|
|
101
|
+
setError('Anúncio inválido ou vazio');
|
|
102
|
+
setAd(null);
|
|
75
103
|
return;
|
|
104
|
+
}
|
|
76
105
|
setAd(data);
|
|
77
|
-
|
|
78
|
-
}
|
|
106
|
+
setError(null);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
console.error('[UPEEX ADS] Erro ao carregar anúncio', err);
|
|
110
|
+
setError('Erro ao carregar anúncio');
|
|
111
|
+
setAd(null);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!client || !slot) {
|
|
116
|
+
log('client ou slot não informado');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
loadAd();
|
|
79
120
|
}, [client, slot, baseUrl]);
|
|
80
|
-
|
|
81
|
-
|
|
121
|
+
// 🔁 auto refresh (se backend enviar)
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (!(ad === null || ad === void 0 ? void 0 : ad.refresh))
|
|
124
|
+
return;
|
|
125
|
+
log('Auto refresh em', ad.refresh, 'segundos');
|
|
126
|
+
const timer = setTimeout(loadAd, ad.refresh * 1000);
|
|
127
|
+
return () => clearTimeout(timer);
|
|
128
|
+
}, [ad === null || ad === void 0 ? void 0 : ad.refresh]);
|
|
129
|
+
// ❌ nada pra renderizar
|
|
130
|
+
if (!ad) {
|
|
131
|
+
return debug ? (jsx(View, { style: [styles.container, styles.debug], children: jsx(Text, { style: styles.debugText, children: error !== null && error !== void 0 ? error : 'Nenhum anúncio carregado' }) })) : null;
|
|
132
|
+
}
|
|
82
133
|
const handlePress = () => {
|
|
134
|
+
log('Clique no anúncio', ad.clickUrl);
|
|
83
135
|
if (Platform.OS === 'web') {
|
|
84
|
-
window.open(ad.
|
|
136
|
+
window.open(ad.clickUrl, '_blank');
|
|
85
137
|
}
|
|
86
138
|
else {
|
|
87
|
-
Linking.openURL(ad.
|
|
139
|
+
Linking.openURL(ad.clickUrl);
|
|
88
140
|
}
|
|
89
141
|
};
|
|
90
|
-
return (jsxs(TouchableOpacity, {
|
|
142
|
+
return (jsxs(TouchableOpacity, { activeOpacity: 0.9, onPress: handlePress, style: [
|
|
143
|
+
styles.container,
|
|
144
|
+
theme === 'dark' && styles.dark,
|
|
145
|
+
style,
|
|
146
|
+
], children: [jsx(Image, { source: { uri: ad.image }, style: {
|
|
147
|
+
width: ad.width || 320,
|
|
148
|
+
height: ad.height || 50,
|
|
149
|
+
}, resizeMode: "contain" }), debug && (jsxs(Text, { style: styles.debugInfo, children: ["client: ", client, " | slot: ", slot] }))] }));
|
|
91
150
|
}
|
|
92
151
|
const styles = StyleSheet.create({
|
|
93
152
|
container: {
|
|
153
|
+
alignItems: 'center',
|
|
154
|
+
justifyContent: 'center',
|
|
94
155
|
backgroundColor: '#f2f2f2',
|
|
95
|
-
|
|
96
|
-
borderTopWidth: 1,
|
|
97
|
-
borderColor: '#ddd',
|
|
156
|
+
paddingVertical: 4,
|
|
98
157
|
},
|
|
99
158
|
dark: {
|
|
100
159
|
backgroundColor: '#121212',
|
|
101
160
|
},
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
marginBottom: 4,
|
|
161
|
+
debug: {
|
|
162
|
+
padding: 10,
|
|
163
|
+
backgroundColor: '#fff3f3',
|
|
106
164
|
},
|
|
107
|
-
|
|
165
|
+
debugText: {
|
|
108
166
|
fontSize: 11,
|
|
109
|
-
color: '#
|
|
167
|
+
color: '#c00',
|
|
168
|
+
textAlign: 'center',
|
|
169
|
+
},
|
|
170
|
+
debugInfo: {
|
|
171
|
+
marginTop: 4,
|
|
172
|
+
fontSize: 9,
|
|
173
|
+
color: '#888',
|
|
110
174
|
},
|
|
111
175
|
});
|
|
112
176
|
|
|
113
|
-
export { AdBanner };
|
|
177
|
+
export { AdBanner, AdBanner as default };
|