adnova-sdk 1.0.0

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.
Files changed (2) hide show
  1. package/index.js +79 -0
  2. package/package.json +18 -0
package/index.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * AdNova Official JavaScript/Node.js SDK
3
+ */
4
+ class AdNovaSDK {
5
+ constructor() {
6
+ this.baseUrl = 'https://nrejobcuwoqhxmqubmun.supabase.co';
7
+ this.publisherId = null;
8
+ }
9
+
10
+ /**
11
+ * Initialize AdNova SDK
12
+ * @param {Object} config
13
+ * @param {string} config.publisherId - Publisher API ID
14
+ * @param {string} [config.baseUrl] - Custom Supabase Edge Function Base URL
15
+ */
16
+ init({ publisherId, baseUrl }) {
17
+ this.publisherId = publisherId;
18
+ if (baseUrl) this.baseUrl = baseUrl;
19
+ console.log('[AdNova SDK] Initialized for Publisher:', this.publisherId);
20
+ }
21
+
22
+ /**
23
+ * Request an Ad from the AdNova Ad Engine
24
+ * @param {Object} params
25
+ * @param {string} params.placementId - Ad Placement Code
26
+ * @param {string} [params.adFormat='banner'] - Ad Format (banner, native, interstitial, rewarded)
27
+ * @returns {Promise<Object|null>} Ad Data or null
28
+ */
29
+ async requestAd({ placementId, adFormat = 'banner' }) {
30
+ if (!this.publisherId) {
31
+ throw new Error('[AdNova SDK] Publisher ID is missing. Call init() first.');
32
+ }
33
+
34
+ try {
35
+ const response = await fetch(`${this.baseUrl}/functions/v1/ad-request`, {
36
+ method: 'POST',
37
+ headers: { 'Content-Type': 'application/json' },
38
+ body: JSON.stringify({
39
+ publisher_id: this.publisherId,
40
+ placement_id: placementId,
41
+ ad_format: adFormat,
42
+ }),
43
+ });
44
+
45
+ const data = await response.json();
46
+ if (data.success && data.ad) {
47
+ return data.ad;
48
+ }
49
+ } catch (error) {
50
+ console.error('[AdNova SDK] Ad Request Error:', error);
51
+ }
52
+ return null;
53
+ }
54
+
55
+ /**
56
+ * Track Impression Event
57
+ * @param {string} impressionUrl
58
+ * @param {Object} payload
59
+ */
60
+ async trackImpression(impressionUrl, payload) {
61
+ try {
62
+ await fetch(impressionUrl, {
63
+ method: 'POST',
64
+ headers: { 'Content-Type': 'application/json' },
65
+ body: JSON.stringify(payload),
66
+ });
67
+ } catch (error) {
68
+ console.error('[AdNova SDK] Track Impression Error:', error);
69
+ }
70
+ }
71
+ }
72
+
73
+ // Export singleton instance
74
+ const instance = new AdNovaSDK();
75
+ if (typeof window !== 'undefined') {
76
+ window.AdNova = instance;
77
+ }
78
+
79
+ module.exports = instance;
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "adnova-sdk",
3
+ "version": "1.0.0",
4
+ "description": "AdNova Official JavaScript/TypeScript SDK for Web & Node.js Applications",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "adnova",
11
+ "ad-network",
12
+ "monetization",
13
+ "banner-ads",
14
+ "sdk"
15
+ ],
16
+ "author": "AdNova Platform",
17
+ "license": "MIT"
18
+ }