@upeex/ads-sdk 0.1.0 → 0.1.2

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.
@@ -1,4 +1,9 @@
1
- export default function AdBanner({ client, slot }: {
2
- client: any;
3
- slot: any;
4
- }): any;
1
+ type Props = {
2
+ client: string;
3
+ slot: string;
4
+ baseUrl?: string;
5
+ theme?: 'light' | 'dark';
6
+ style?: object;
7
+ };
8
+ export default function AdBanner({ client, slot, baseUrl, theme, style, }: Props): any;
9
+ export {};
package/dist/core.d.ts CHANGED
@@ -1,2 +1,9 @@
1
- export declare function loadAd(client: string, slot: string): Promise<any>;
2
- export declare function countView(token: string): void;
1
+ type LoadAdParams = {
2
+ baseUrl: string;
3
+ client: string;
4
+ slot: string;
5
+ display?: string;
6
+ };
7
+ export declare function fetchAd({ baseUrl, client, slot, display, }: LoadAdParams): Promise<any>;
8
+ export declare function countView(baseUrl: string, token: string): Promise<void>;
9
+ export {};
package/dist/index.js CHANGED
@@ -1,90 +1,113 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { useState, useRef, useEffect } from 'react';
3
- import { StyleSheet, AppState, View, Text, TouchableOpacity, Image, Linking } from 'react-native';
2
+ import { useState, useEffect } from 'react';
3
+ import { Platform, Dimensions, StyleSheet, TouchableOpacity, Text, Linking } from 'react-native';
4
4
 
5
5
  async function getSignals() {
6
- var _a;
7
- let os;
8
- let model;
9
- let bundle = null;
10
- // 🌍 Sempre disponível (JS puro)
11
- const lang = Intl.DateTimeFormat().resolvedOptions().locale;
12
- const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
13
- // 📱 Tenta Expo (se existir)
14
- try {
15
- const Device = await import('expo-device');
16
- os = Device.osName;
17
- model = Device.modelName;
18
- }
19
- catch (_b) {
20
- // não é Expo, segue a vida
21
- }
22
- try {
23
- const Application = await import('expo-application');
24
- bundle = (_a = Application.applicationId) !== null && _a !== void 0 ? _a : null;
6
+ var _a, _b, _c, _d, _e, _f;
7
+ let platform = 'unknown';
8
+ let screenWidth = 0;
9
+ let screenHeight = 0;
10
+ let userAgent = 'unknown';
11
+ let locale = 'en-US';
12
+ let timezone = 'UTC';
13
+ if (typeof window !== 'undefined') {
14
+ // Web / PWA
15
+ platform = 'web';
16
+ screenWidth = window.innerWidth;
17
+ screenHeight = window.innerHeight;
18
+ userAgent = navigator.userAgent;
19
+ locale =
20
+ ((_c = (_b = (_a = Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat) === null || _a === void 0 ? void 0 : _a.call(Intl)) === null || _b === void 0 ? void 0 : _b.resolvedOptions) === null || _c === void 0 ? void 0 : _c.call(_b).locale) || 'en-US';
21
+ timezone =
22
+ ((_f = (_e = (_d = Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat) === null || _d === void 0 ? void 0 : _d.call(Intl)) === null || _e === void 0 ? void 0 : _e.resolvedOptions) === null || _f === void 0 ? void 0 : _f.call(_e).timeZone) || 'UTC';
25
23
  }
26
- catch (_c) {
27
- // não é Expo
24
+ else if (typeof Platform !== 'undefined') {
25
+ // React Native
26
+ platform = Platform.OS;
27
+ const dim = Dimensions.get('window');
28
+ screenWidth = dim.width;
29
+ screenHeight = dim.height;
30
+ // RN não tem userAgent nativo
28
31
  }
29
32
  return {
30
- os,
31
- model,
32
- bundle,
33
- lang,
34
- tz
33
+ platform,
34
+ screenWidth,
35
+ screenHeight,
36
+ userAgent,
37
+ locale,
38
+ timezone,
35
39
  };
36
40
  }
37
41
 
38
- const BASE_URL = 'https://teste.hosthp.com.br/ads';
39
- async function loadAd(client, slot) {
42
+ async function fetchAd({ baseUrl, client, slot, display = 'BANNER', }) {
40
43
  const signals = await getSignals();
41
- const makeRes = await fetch(`${BASE_URL}/make/index.php`, {
44
+ const res = await fetch(`${baseUrl}/make`, {
42
45
  method: 'POST',
43
46
  headers: { 'Content-Type': 'application/json' },
44
47
  body: JSON.stringify({
45
48
  client,
46
49
  slot,
47
- platform: 'app',
48
- signals
49
- })
50
+ display,
51
+ isMobile: signals.platform !== 'web' ? 1 : 0,
52
+ ...signals,
53
+ }),
50
54
  });
51
- const makeData = await makeRes.json();
52
- const showRes = await fetch(makeData.show_url);
53
- return showRes.json();
55
+ if (!res.ok)
56
+ return null;
57
+ return res.json();
54
58
  }
55
- function countView(token) {
56
- fetch(`${BASE_URL}/count/view.php`, {
57
- method: 'POST',
58
- headers: { 'Content-Type': 'application/json' },
59
- body: JSON.stringify({ token })
60
- });
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
+ }
67
+ catch (_a) { }
61
68
  }
62
69
 
63
- function AdBanner({ client, slot }) {
70
+ function AdBanner({ client, slot, baseUrl = 'http://localhost:3000', theme = 'light', style = {}, }) {
64
71
  const [ad, setAd] = useState(null);
65
- const viewed = useRef(false);
66
- useEffect(() => {
67
- loadAd(client, slot).then(setAd);
68
- }, []);
69
72
  useEffect(() => {
70
- if (!(ad === null || ad === void 0 ? void 0 : ad.token))
71
- return;
72
- const t = setTimeout(() => {
73
- if (!viewed.current && AppState.currentState === 'active') {
74
- viewed.current = true;
75
- countView(ad.token);
76
- }
77
- }, (ad.view_time || 5) * 1000);
78
- return () => clearTimeout(t);
79
- }, [ad]);
73
+ fetchAd({ baseUrl, client, slot }).then((data) => {
74
+ if (!data)
75
+ return;
76
+ setAd(data);
77
+ countView(baseUrl, data.adtoken);
78
+ });
79
+ }, [client, slot, baseUrl]);
80
80
  if (!ad)
81
81
  return null;
82
- return (jsxs(View, { style: styles.container, children: [jsx(Text, { style: styles.label, children: "Promovido" }), jsx(TouchableOpacity, { onPress: () => Linking.openURL(ad.click_url), children: jsx(Image, { source: { uri: ad.image }, style: styles.banner, resizeMode: "contain" }) })] }));
82
+ const handlePress = () => {
83
+ if (Platform.OS === 'web') {
84
+ window.open(ad.url, '_blank');
85
+ }
86
+ else {
87
+ Linking.openURL(ad.url);
88
+ }
89
+ };
90
+ return (jsxs(TouchableOpacity, { style: [styles.container, theme === 'dark' && styles.dark, style], onPress: handlePress, children: [jsx(Text, { style: styles.title, children: "Publicidade" }), jsx(Text, { style: styles.text, children: ad.url })] }));
83
91
  }
84
92
  const styles = StyleSheet.create({
85
- container: { width: '100%', alignItems: 'center', marginVertical: 8 },
86
- label: { fontSize: 10, color: '#777', marginBottom: 2 },
87
- banner: { width: '100%', height: 50 }
93
+ container: {
94
+ backgroundColor: '#f2f2f2',
95
+ padding: 12,
96
+ borderTopWidth: 1,
97
+ borderColor: '#ddd',
98
+ },
99
+ dark: {
100
+ backgroundColor: '#121212',
101
+ },
102
+ title: {
103
+ fontSize: 12,
104
+ fontWeight: '600',
105
+ marginBottom: 4,
106
+ },
107
+ text: {
108
+ fontSize: 11,
109
+ color: '#555',
110
+ },
88
111
  });
89
112
 
90
113
  export { AdBanner };
package/dist/signals.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- type Signals = {
2
- os?: string;
3
- model?: string;
4
- bundle?: string | null;
5
- lang: string;
6
- tz: string;
7
- };
8
- export declare function getSignals(): Promise<Signals>;
9
- export {};
1
+ export declare function getSignals(): Promise<{
2
+ platform: string;
3
+ screenWidth: number;
4
+ screenHeight: number;
5
+ userAgent: string;
6
+ locale: string;
7
+ timezone: string;
8
+ }>;
package/package.json CHANGED
@@ -1,30 +1,38 @@
1
1
  {
2
2
  "name": "@upeex/ads-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Upeex Ads SDK for React Native and universal apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "files": ["dist"],
7
+ "files": [
8
+ "dist"
9
+ ],
8
10
  "sideEffects": false,
9
-
10
11
  "peerDependencies": {
11
12
  "react": ">=17",
12
13
  "react-native": ">=0.68"
13
14
  },
14
-
15
15
  "scripts": {
16
16
  "build": "rollup -c"
17
17
  },
18
-
19
18
  "keywords": [
20
19
  "ads",
21
20
  "mobile-ads",
22
21
  "react-native",
23
22
  "expo",
24
23
  "sdk",
25
- "upeex"
24
+ "upeex",
25
+ "upee"
26
26
  ],
27
-
28
27
  "author": "Upeex",
29
- "license": "MIT"
28
+ "license": "MIT",
29
+ "dependencies": {
30
+ "expo-localization": "^17.0.8"
31
+ },
32
+ "devDependencies": {
33
+ "rollup": "^4.57.0",
34
+ "rollup-plugin-typescript2": "^0.36.0",
35
+ "tslib": "^2.8.1",
36
+ "typescript": "^5.9.3"
37
+ }
30
38
  }