@betarena/ad-engine 0.0.62 → 0.0.63

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betarena/ad-engine",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
4
4
  "private": false,
5
5
  "description": "Betarena ad-engine widget",
6
6
  "keywords": [
@@ -64,7 +64,9 @@
64
64
  "@betarena/scores-lib": "1.11.0-alpha.17",
65
65
  "@fontsource/roboto": "5.0.12",
66
66
  "colorthief": "2.6.0",
67
- "svelte-preprocess": "5.1.3"
67
+ "device-detector-js": "3.0.3",
68
+ "svelte-preprocess": "5.1.3",
69
+ "ua-parser-js": "2.0.0"
68
70
  },
69
71
  "main": "./dist/index.js",
70
72
  "svelte": "./src/index.js",
@@ -47,7 +47,7 @@
47
47
  import { betarenaEndpoint } from './constants/instance.js';
48
48
  import { storeSession } from './store/session.js';
49
49
  import { logger } from './utils/debug.js';
50
- import { detectDeviceType } from './utils/device.js';
50
+ import { detectDeviceWithUA } from './utils/device.js';
51
51
  import { postMod } from './utils/fetch.js';
52
52
  import { getUserLocation } from './utils/geo.js';
53
53
 
@@ -634,7 +634,7 @@
634
634
  (
635
635
  ): Promise < void >
636
636
  {
637
- deviceType = detectDeviceType() as IDeviceType;
637
+ deviceType = detectDeviceWithUA() as IDeviceType;
638
638
  geoLocation = await getUserLocation();
639
639
  generateElementMap();
640
640
 
@@ -642,9 +642,7 @@
642
642
  logger
643
643
  (
644
644
  [
645
- '🚏 checkpoint ➤ initialize(..) // START',
646
- `🔹 [var] ➤ deviceType ${deviceType}`,
647
- `🔹 [var] ➤ geoLocation ${JSON.stringify(geoLocation)}`
645
+ '🚏 checkpoint ➤ initialize(..) // START'
648
646
  ]
649
647
  );
650
648
 
@@ -698,7 +696,7 @@
698
696
  {
699
697
  () =>
700
698
  {
701
- detectDeviceType();
699
+ detectDeviceWithUA();
702
700
  return;
703
701
  }
704
702
  }
@@ -15,63 +15,94 @@
15
15
 
16
16
  // #region ➤ 📦 Package Imports
17
17
 
18
+ import DeviceDetector from 'device-detector-js';
19
+ import { UAParser } from 'ua-parser-js';
20
+
18
21
  import { logger } from './debug.js';
19
22
 
23
+ import type { IDeviceType } from '@betarena/scores-lib/types/ad-engine/index.js';
24
+
20
25
  // #endregion ➤ 📦 Package Imports
21
26
 
22
27
  /**
23
28
  * @author
24
29
  * @migbash
25
30
  * @summary
26
- * 🟥 MAIN
31
+ * 🟦 HELPER
27
32
  * @description
28
- * 📝 Detect target device type, such as: `mobile` | `tablet` | `desktop`.
29
- * @returns { string }
30
- * 📤
33
+ * 📝 Detect device used from `User-Agent` data.
34
+ * @see https://discord.com/channels/457912077277855764/1067871458233159750
35
+ * @see https://discord.com/channels/457912077277855764/1067529519294070885/1067827869004341319
36
+ * @return { string }
37
+ * 📤 `device` type.
31
38
  */
32
- export function detectDeviceType
39
+ export function detectDeviceWithUA
33
40
  (
34
- ): string
41
+ ): IDeviceType
35
42
  {
36
- const
43
+ let
37
44
  /**
38
45
  * @description
46
+ * 📝 `device type`.
39
47
  */
40
- userAgentObject = navigator.userAgent.toLowerCase(),
48
+ deviceType: IDeviceType = 'mobile'
49
+ ;
50
+
51
+ const
41
52
  /**
42
53
  * @description
54
+ * 📝 `user-agent` data.
55
+ * @example
56
+ * => 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
57
+ * => [production] navigator.userAgent
43
58
  */
44
- isUserAgentMobile = userAgentObject.includes('mobile'),
59
+ userAgent = navigator.userAgent,
45
60
  /**
46
61
  * @description
62
+ * 📝 Using `ua-parser-js` module.
47
63
  */
48
- isUserAgentTablet = /tablet|ipad/.test(userAgentObject)
49
- ;
50
-
51
- let
64
+ methodRes0
65
+ // eslint-disable-next-line new-cap
66
+ = UAParser
67
+ (
68
+ userAgent
69
+ ),
52
70
  /**
53
71
  * @description
54
- * 📝 Type of device
72
+ * 📝 Using 'device-detector-js' module.
55
73
  */
56
- strDeviceType = 'desktop'
57
- ;
58
-
59
- if (isUserAgentMobile)
60
- strDeviceType = 'mobile';
61
- else if (isUserAgentTablet)
62
- strDeviceType = 'tablet';
63
- else
64
- strDeviceType = 'desktop';
74
+ methodRes1
75
+ = new DeviceDetector().parse
76
+ (
77
+ userAgent
78
+ )
65
79
  ;
66
80
 
67
81
  // [🐞]
68
82
  logger
69
83
  (
70
84
  [
71
- `🔹 [var] ➤ strDeviceType ${JSON.stringify(strDeviceType)}`,
72
- '🚏 checkpointdetectDeviceType(..) // END'
85
+ `🔹 [var] ➤ userAgent ${userAgent}`,
86
+ // `🔹 [var] methodRes0 ${JSON.stringify(methodRes0, null, 4)}`,
87
+ `🔹 [var] ➤ methodRes1 ${JSON.stringify(methodRes1, null, 4)}`,
88
+ `🔹 [var] ➤ deviceType ${deviceType}`,
89
+ '🚏 checkpoint ➤ detectDeviceWithUA(..) // END'
73
90
  ]
74
91
  );
75
92
 
76
- return strDeviceType;
93
+ // ╭─────
94
+ // │ NOTE:
95
+ // │ |: Alternative method to get device type.
96
+ // ╰─────
97
+ // deviceType = (methodRes0.device.type ?? 'mobile');
98
+
99
+ if (methodRes1.device?.type === 'smartphone')
100
+ deviceType = 'mobile';
101
+ else if (methodRes1.device?.type === 'tablet')
102
+ deviceType = 'tablet';
103
+ else
104
+ deviceType = 'desktop';
105
+ ;
106
+
107
+ return deviceType;
77
108
  }
@@ -1,5 +1,26 @@
1
+ // ╭──────────────────────────────────────────────────────────────────────────────────╮
2
+ // │ 📌 High Order Overview │
3
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
4
+ // │ ➤ Code Format // V.8.0 │
5
+ // │ ➤ Status // 🔒 LOCKED │
6
+ // │ ➤ Author(s) // @migbash │
7
+ // │ ➤ Maintainer(s) // @migbash │
8
+ // │ ➤ Created on // <date-created> │
9
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
10
+ // │ 📝 Description │
11
+ // ┣──────────────────────────────────────────────────────────────────────────────────┫
12
+ // │ BETARENA (Module)
13
+ // │ |: Geo Location Logic
14
+ // ╰──────────────────────────────────────────────────────────────────────────────────╯
15
+
16
+ // #region ➤ 📦 Package Imports
17
+
18
+ import { logger } from './debug.js';
19
+
1
20
  import type { GeoJsResponse } from '../types/geojs.js';
2
21
 
22
+ // #endregion ➤ 📦 Package Imports
23
+
3
24
  /**
4
25
  * @author
5
26
  * @migbash
@@ -7,7 +28,8 @@ import type { GeoJsResponse } from '../types/geojs.js';
7
28
  * 🟥 MAIN
8
29
  * @description
9
30
  * 📝 Detect user `geo-location`.
10
- * @returns { Promise <void> }
31
+ * @return { Promise < GeoJsResponse > }
32
+ * 📤 `geo-location` data.
11
33
  */
12
34
  export async function getUserLocation
13
35
  (
@@ -18,17 +40,29 @@ export async function getUserLocation
18
40
  * @description
19
41
  * 📝 Response from `fetch`
20
42
  */
21
- response = await fetch
22
- (
23
- 'https://get.geojs.io/v1/ip/geo.json',
24
- {
25
- method: 'GET'
26
- }
27
- )
43
+ dataRes0
44
+ = await fetch
45
+ (
46
+ 'https://get.geojs.io/v1/ip/geo.json',
47
+ {
48
+ method: 'GET'
49
+ }
50
+ ),
51
+ /**
52
+ * @description
53
+ * 📝 Response from `fetch`
54
+ */
55
+ dataRes1 = await dataRes0.json()
28
56
  ;
29
57
 
30
58
  // [🐞]
31
- // console.log('geoLocation', geoLocation);
59
+ logger
60
+ (
61
+ [
62
+ `🔹 [var] ➤ dataRes0 :: ${JSON.stringify(dataRes1, null, 4)}`,
63
+ '🚏 checkpoint ➤ getUserLocation(..) // END'
64
+ ]
65
+ );
32
66
 
33
- return await response.json();
67
+ return dataRes1;
34
68
  }