@upeex/ads-sdk 0.1.0 → 0.1.1

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/core.d.ts CHANGED
@@ -1,2 +1,7 @@
1
- export declare function loadAd(client: string, slot: string): Promise<any>;
2
- export declare function countView(token: string): void;
1
+ export interface LoadAdOptions {
2
+ baseUrl?: string;
3
+ client: string;
4
+ slot: string;
5
+ }
6
+ export declare function loadAd({ baseUrl, client, slot }: LoadAdOptions): Promise<any>;
7
+ export declare function countView(baseUrl: string, token: string): void;
package/dist/index.js CHANGED
@@ -1,82 +1,74 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { useState, useRef, useEffect } from 'react';
3
- import { StyleSheet, AppState, View, Text, TouchableOpacity, Image, Linking } from 'react-native';
3
+ import { StyleSheet, View, Text, TouchableOpacity, Image, 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)
6
+ let lang = 'pt-BR';
7
+ let tz = 'UTC';
14
8
  try {
15
- const Device = await import('expo-device');
16
- os = Device.osName;
17
- model = Device.modelName;
9
+ const intl = Intl.DateTimeFormat().resolvedOptions();
10
+ lang = intl.locale;
11
+ tz = intl.timeZone;
18
12
  }
19
- catch (_b) {
20
- // não é Expo, segue a vida
13
+ catch (_a) { }
14
+ let userAgent = 'unknown';
15
+ if (typeof navigator !== 'undefined' && navigator.userAgent) {
16
+ userAgent = navigator.userAgent;
21
17
  }
22
- try {
23
- const Application = await import('expo-application');
24
- bundle = (_a = Application.applicationId) !== null && _a !== void 0 ? _a : null;
25
- }
26
- catch (_c) {
27
- // não é Expo
18
+ let screenWidth = 0;
19
+ let screenHeight = 0;
20
+ if (typeof window !== 'undefined' && window.screen) {
21
+ screenWidth = window.screen.width;
22
+ screenHeight = window.screen.height;
28
23
  }
29
24
  return {
30
- os,
31
- model,
32
- bundle,
25
+ isMobile: true,
26
+ screenWidth,
27
+ screenHeight,
28
+ userAgent,
33
29
  lang,
34
- tz
30
+ tz,
31
+ href: typeof location !== 'undefined' ? location.href : 'app://mobile',
32
+ hostname: typeof location !== 'undefined' ? location.hostname : 'mobile-app'
35
33
  };
36
34
  }
37
35
 
38
- const BASE_URL = 'https://teste.hosthp.com.br/ads';
39
- async function loadAd(client, slot) {
36
+ async function loadAd({ baseUrl = 'http://localhost:3000', client, slot }) {
40
37
  const signals = await getSignals();
41
- const makeRes = await fetch(`${BASE_URL}/make/index.php`, {
38
+ const makeRes = await fetch(`${baseUrl}/ad/make/mobile`, {
42
39
  method: 'POST',
43
- headers: { 'Content-Type': 'application/json' },
40
+ headers: {
41
+ 'Content-Type': 'application/json'
42
+ },
44
43
  body: JSON.stringify({
45
44
  client,
46
45
  slot,
47
- platform: 'app',
48
- signals
46
+ display: 'BANNER',
47
+ responsive: 1,
48
+ ...signals
49
49
  })
50
50
  });
51
+ if (!makeRes.ok) {
52
+ throw new Error('Erro ao chamar /ad/make/mobile');
53
+ }
51
54
  const makeData = await makeRes.json();
52
- const showRes = await fetch(makeData.show_url);
55
+ if (!makeData.url) {
56
+ throw new Error('MAKE não retornou URL');
57
+ }
58
+ const showRes = await fetch(makeData.url);
53
59
  return showRes.json();
54
60
  }
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
- });
61
- }
62
61
 
63
62
  function AdBanner({ client, slot }) {
64
63
  const [ad, setAd] = useState(null);
65
- const viewed = useRef(false);
64
+ useRef(false);
66
65
  useEffect(() => {
67
- loadAd(client, slot).then(setAd);
68
- }, []);
69
- 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]);
66
+ loadAd({
67
+ baseUrl: 'http://localhost:3000',
68
+ client,
69
+ slot
70
+ }).then(setAd);
71
+ }, [client, slot]);
80
72
  if (!ad)
81
73
  return null;
82
74
  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" }) })] }));
package/dist/signals.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- type Signals = {
2
- os?: string;
3
- model?: string;
4
- bundle?: string | null;
1
+ export declare function getSignals(): Promise<{
2
+ isMobile: boolean;
3
+ screenWidth: number;
4
+ screenHeight: number;
5
+ userAgent: string;
5
6
  lang: string;
6
7
  tz: string;
7
- };
8
- export declare function getSignals(): Promise<Signals>;
9
- export {};
8
+ href: string;
9
+ hostname: string;
10
+ }>;
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "@upeex/ads-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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",
@@ -24,7 +23,15 @@
24
23
  "sdk",
25
24
  "upeex"
26
25
  ],
27
-
28
26
  "author": "Upeex",
29
- "license": "MIT"
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "expo-localization": "^17.0.8"
30
+ },
31
+ "devDependencies": {
32
+ "rollup": "^4.57.0",
33
+ "rollup-plugin-typescript2": "^0.36.0",
34
+ "tslib": "^2.8.1",
35
+ "typescript": "^5.9.3"
36
+ }
30
37
  }