@adsterra-ad/core 0.1.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.
- package/dist/index.cjs +145 -0
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +111 -0
- package/package.json +30 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DEFAULT_AD_CONFIGS: () => DEFAULT_AD_CONFIGS,
|
|
24
|
+
buildSrcDoc: () => buildSrcDoc,
|
|
25
|
+
configureAds: () => configureAds,
|
|
26
|
+
createBannerId: () => createBannerId,
|
|
27
|
+
getBannerStyle: () => getBannerStyle,
|
|
28
|
+
getConfiguredAdKey: () => getConfiguredAdKey,
|
|
29
|
+
resetAdsConfig: () => resetAdsConfig,
|
|
30
|
+
resolveAdConfig: () => resolveAdConfig,
|
|
31
|
+
shouldFallback: () => shouldFallback,
|
|
32
|
+
withAdKey: () => withAdKey
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var DEFAULT_AD_CONFIGS = {
|
|
36
|
+
"300x250": { key: "a63df507acd2eab9674d17bcafcb2514", width: 300, height: 250 },
|
|
37
|
+
"160x300": { key: "83f5b4a71b8b75054de5c9410db5ec31", width: 160, height: 300 },
|
|
38
|
+
"728x90": { key: "608c40ac4f99ec5b1f15de546417ccba", width: 728, height: 90 },
|
|
39
|
+
"320x50": { key: "8d6509c38d17a8bb29933c4ef9cd4327", width: 320, height: 50 },
|
|
40
|
+
"160x600": { key: "b609dd6697e15c82d9600af75401fbcc", width: 160, height: 600 },
|
|
41
|
+
native: { key: "a03627a5221f2054c614d3cc3e9ab09c", width: "100%", height: "auto" }
|
|
42
|
+
};
|
|
43
|
+
var runtimeAdKeys = {};
|
|
44
|
+
function configureAds(keys) {
|
|
45
|
+
runtimeAdKeys = { ...runtimeAdKeys, ...keys };
|
|
46
|
+
}
|
|
47
|
+
function resetAdsConfig() {
|
|
48
|
+
runtimeAdKeys = {};
|
|
49
|
+
}
|
|
50
|
+
function getConfiguredAdKey(format) {
|
|
51
|
+
return runtimeAdKeys[format];
|
|
52
|
+
}
|
|
53
|
+
function getBannerStyle(config) {
|
|
54
|
+
const width = typeof config.width === "number" ? `${config.width}px` : config.width;
|
|
55
|
+
const height = typeof config.height === "number" ? `${config.height}px` : config.height;
|
|
56
|
+
return `width: ${width}; height: ${height};`;
|
|
57
|
+
}
|
|
58
|
+
function shouldFallback(provider, format, msg) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
function reporterScript({ bannerId, format, provider }) {
|
|
62
|
+
const sOpen = "<script";
|
|
63
|
+
const sClose = "</script>";
|
|
64
|
+
return `
|
|
65
|
+
${sOpen}>
|
|
66
|
+
function report(type, reason) {
|
|
67
|
+
window.parent.postMessage({ type, bannerId: '${bannerId}', format: '${format}', provider: '${provider}', reason }, '*');
|
|
68
|
+
}
|
|
69
|
+
var observer = new MutationObserver(function() {
|
|
70
|
+
var body = document.body;
|
|
71
|
+
if (body) {
|
|
72
|
+
var hasAdElement = body.querySelector('iframe') || body.querySelector('a') || body.querySelector('img');
|
|
73
|
+
if (hasAdElement) {
|
|
74
|
+
report('ad-load-success');
|
|
75
|
+
observer.disconnect();
|
|
76
|
+
clearTimeout(timeoutId);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
81
|
+
var timeoutId = setTimeout(function() {
|
|
82
|
+
report('ad-load-error', 'timeout');
|
|
83
|
+
observer.disconnect();
|
|
84
|
+
}, 3000);
|
|
85
|
+
window.onerror = function(msg) {
|
|
86
|
+
var isSecurityError = msg && msg.indexOf('SecurityError') !== -1;
|
|
87
|
+
var isSandboxError = msg && msg.indexOf('sandboxed') !== -1;
|
|
88
|
+
report('ad-load-error', isSecurityError ? 'security-error' : isSandboxError ? 'sandbox-error' : 'generic-error');
|
|
89
|
+
return true;
|
|
90
|
+
};
|
|
91
|
+
${sClose}`;
|
|
92
|
+
}
|
|
93
|
+
function buildSrcDoc(params) {
|
|
94
|
+
const { format, provider, config, bannerId } = params;
|
|
95
|
+
const sOpen = "<script";
|
|
96
|
+
const sClose = "</script>";
|
|
97
|
+
if (provider === "hilltopads" && format === "300x250") {
|
|
98
|
+
return `
|
|
99
|
+
<html><head>${reporterScript({ bannerId, format, provider })}</head>
|
|
100
|
+
<body style="margin:0;padding:0;overflow:hidden;display:flex;align-items:center;justify-content:center;height:100vh;">
|
|
101
|
+
${sOpen}> (function(adcms){ var d = document, s = d.createElement('script'), l = d.scripts[d.scripts.length - 1]; s.settings = adcms || {}; s.src = "//untimely-hello.com/bkX.VfsldRG/l/0/YEWWcc/ueMm-9XujZsUYlTkOPmTsY/4cNGTQUPwhN/DvUattNEj/gZ1INTT/Ap0ROBQZ"; s.async = true; s.referrerPolicy = 'no-referrer-when-downgrade'; l.parentNode.insertBefore(s, l); })({}) ${sClose}
|
|
102
|
+
</body></html>`;
|
|
103
|
+
}
|
|
104
|
+
if (format === "native") {
|
|
105
|
+
return `
|
|
106
|
+
<html><head>${reporterScript({ bannerId, format, provider })}</head>
|
|
107
|
+
<body style="margin:0;padding:0;overflow:hidden;">
|
|
108
|
+
${sOpen} async="async" data-cfasync="false" src="https://pl28807911.effectivegatecpm.com/${config.key}/invoke.js">${sClose}
|
|
109
|
+
<div id="container-${config.key}"></div>
|
|
110
|
+
</body></html>`;
|
|
111
|
+
}
|
|
112
|
+
return `
|
|
113
|
+
<html><head>${reporterScript({ bannerId, format, provider })}</head>
|
|
114
|
+
<body style="margin:0;padding:0;overflow:hidden;display:flex;align-items:center;justify-content:center;height:100vh;">
|
|
115
|
+
${sOpen} type="text/javascript">
|
|
116
|
+
atOptions = { 'key': '${config.key}', 'format': 'iframe', 'height': ${config.height}, 'width': ${config.width}, 'params': {} };
|
|
117
|
+
${sClose}
|
|
118
|
+
${sOpen} type="text/javascript" src="https://www.highperformanceformat.com/${config.key}/invoke.js">${sClose}
|
|
119
|
+
</body></html>`;
|
|
120
|
+
}
|
|
121
|
+
function createBannerId() {
|
|
122
|
+
return Math.random().toString(36).slice(2, 9);
|
|
123
|
+
}
|
|
124
|
+
function withAdKey(config, adKey) {
|
|
125
|
+
if (!adKey) return config;
|
|
126
|
+
return { ...config, key: adKey };
|
|
127
|
+
}
|
|
128
|
+
function resolveAdConfig(format, adKey) {
|
|
129
|
+
const base = DEFAULT_AD_CONFIGS[format];
|
|
130
|
+
const resolvedKey = adKey || getConfiguredAdKey(format);
|
|
131
|
+
return withAdKey(base, resolvedKey);
|
|
132
|
+
}
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
DEFAULT_AD_CONFIGS,
|
|
136
|
+
buildSrcDoc,
|
|
137
|
+
configureAds,
|
|
138
|
+
createBannerId,
|
|
139
|
+
getBannerStyle,
|
|
140
|
+
getConfiguredAdKey,
|
|
141
|
+
resetAdsConfig,
|
|
142
|
+
resolveAdConfig,
|
|
143
|
+
shouldFallback,
|
|
144
|
+
withAdKey
|
|
145
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type AdFormat = '300x250' | '160x300' | '728x90' | '320x50' | '160x600' | 'native';
|
|
2
|
+
type AdProvider = 'adsterra' | 'hilltopads';
|
|
3
|
+
interface AdConfig {
|
|
4
|
+
key: string;
|
|
5
|
+
width: number | string;
|
|
6
|
+
height: number | string;
|
|
7
|
+
}
|
|
8
|
+
interface AdUnitRegistry {
|
|
9
|
+
[format: string]: AdConfig;
|
|
10
|
+
}
|
|
11
|
+
type AdKeyRegistry = Partial<Record<AdFormat, string>>;
|
|
12
|
+
interface BannerMessage {
|
|
13
|
+
type: 'ad-load-success' | 'ad-load-error';
|
|
14
|
+
bannerId?: string;
|
|
15
|
+
format?: AdFormat;
|
|
16
|
+
provider?: AdProvider;
|
|
17
|
+
reason?: string;
|
|
18
|
+
}
|
|
19
|
+
declare const DEFAULT_AD_CONFIGS: Record<AdFormat, AdConfig>;
|
|
20
|
+
declare function configureAds(keys: AdKeyRegistry): void;
|
|
21
|
+
declare function resetAdsConfig(): void;
|
|
22
|
+
declare function getConfiguredAdKey(format: AdFormat): string | undefined;
|
|
23
|
+
declare function getBannerStyle(config: AdConfig): string;
|
|
24
|
+
declare function shouldFallback(provider: AdProvider, format: AdFormat, msg: BannerMessage): boolean;
|
|
25
|
+
declare function buildSrcDoc(params: {
|
|
26
|
+
format: AdFormat;
|
|
27
|
+
provider: AdProvider;
|
|
28
|
+
config: AdConfig;
|
|
29
|
+
bannerId: string;
|
|
30
|
+
}): string;
|
|
31
|
+
declare function createBannerId(): string;
|
|
32
|
+
declare function withAdKey(config: AdConfig, adKey?: string): AdConfig;
|
|
33
|
+
declare function resolveAdConfig(format: AdFormat, adKey?: string): AdConfig;
|
|
34
|
+
|
|
35
|
+
export { type AdConfig, type AdFormat, type AdKeyRegistry, type AdProvider, type AdUnitRegistry, type BannerMessage, DEFAULT_AD_CONFIGS, buildSrcDoc, configureAds, createBannerId, getBannerStyle, getConfiguredAdKey, resetAdsConfig, resolveAdConfig, shouldFallback, withAdKey };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type AdFormat = '300x250' | '160x300' | '728x90' | '320x50' | '160x600' | 'native';
|
|
2
|
+
type AdProvider = 'adsterra' | 'hilltopads';
|
|
3
|
+
interface AdConfig {
|
|
4
|
+
key: string;
|
|
5
|
+
width: number | string;
|
|
6
|
+
height: number | string;
|
|
7
|
+
}
|
|
8
|
+
interface AdUnitRegistry {
|
|
9
|
+
[format: string]: AdConfig;
|
|
10
|
+
}
|
|
11
|
+
type AdKeyRegistry = Partial<Record<AdFormat, string>>;
|
|
12
|
+
interface BannerMessage {
|
|
13
|
+
type: 'ad-load-success' | 'ad-load-error';
|
|
14
|
+
bannerId?: string;
|
|
15
|
+
format?: AdFormat;
|
|
16
|
+
provider?: AdProvider;
|
|
17
|
+
reason?: string;
|
|
18
|
+
}
|
|
19
|
+
declare const DEFAULT_AD_CONFIGS: Record<AdFormat, AdConfig>;
|
|
20
|
+
declare function configureAds(keys: AdKeyRegistry): void;
|
|
21
|
+
declare function resetAdsConfig(): void;
|
|
22
|
+
declare function getConfiguredAdKey(format: AdFormat): string | undefined;
|
|
23
|
+
declare function getBannerStyle(config: AdConfig): string;
|
|
24
|
+
declare function shouldFallback(provider: AdProvider, format: AdFormat, msg: BannerMessage): boolean;
|
|
25
|
+
declare function buildSrcDoc(params: {
|
|
26
|
+
format: AdFormat;
|
|
27
|
+
provider: AdProvider;
|
|
28
|
+
config: AdConfig;
|
|
29
|
+
bannerId: string;
|
|
30
|
+
}): string;
|
|
31
|
+
declare function createBannerId(): string;
|
|
32
|
+
declare function withAdKey(config: AdConfig, adKey?: string): AdConfig;
|
|
33
|
+
declare function resolveAdConfig(format: AdFormat, adKey?: string): AdConfig;
|
|
34
|
+
|
|
35
|
+
export { type AdConfig, type AdFormat, type AdKeyRegistry, type AdProvider, type AdUnitRegistry, type BannerMessage, DEFAULT_AD_CONFIGS, buildSrcDoc, configureAds, createBannerId, getBannerStyle, getConfiguredAdKey, resetAdsConfig, resolveAdConfig, shouldFallback, withAdKey };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var DEFAULT_AD_CONFIGS = {
|
|
3
|
+
"300x250": { key: "a63df507acd2eab9674d17bcafcb2514", width: 300, height: 250 },
|
|
4
|
+
"160x300": { key: "83f5b4a71b8b75054de5c9410db5ec31", width: 160, height: 300 },
|
|
5
|
+
"728x90": { key: "608c40ac4f99ec5b1f15de546417ccba", width: 728, height: 90 },
|
|
6
|
+
"320x50": { key: "8d6509c38d17a8bb29933c4ef9cd4327", width: 320, height: 50 },
|
|
7
|
+
"160x600": { key: "b609dd6697e15c82d9600af75401fbcc", width: 160, height: 600 },
|
|
8
|
+
native: { key: "a03627a5221f2054c614d3cc3e9ab09c", width: "100%", height: "auto" }
|
|
9
|
+
};
|
|
10
|
+
var runtimeAdKeys = {};
|
|
11
|
+
function configureAds(keys) {
|
|
12
|
+
runtimeAdKeys = { ...runtimeAdKeys, ...keys };
|
|
13
|
+
}
|
|
14
|
+
function resetAdsConfig() {
|
|
15
|
+
runtimeAdKeys = {};
|
|
16
|
+
}
|
|
17
|
+
function getConfiguredAdKey(format) {
|
|
18
|
+
return runtimeAdKeys[format];
|
|
19
|
+
}
|
|
20
|
+
function getBannerStyle(config) {
|
|
21
|
+
const width = typeof config.width === "number" ? `${config.width}px` : config.width;
|
|
22
|
+
const height = typeof config.height === "number" ? `${config.height}px` : config.height;
|
|
23
|
+
return `width: ${width}; height: ${height};`;
|
|
24
|
+
}
|
|
25
|
+
function shouldFallback(provider, format, msg) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function reporterScript({ bannerId, format, provider }) {
|
|
29
|
+
const sOpen = "<script";
|
|
30
|
+
const sClose = "</script>";
|
|
31
|
+
return `
|
|
32
|
+
${sOpen}>
|
|
33
|
+
function report(type, reason) {
|
|
34
|
+
window.parent.postMessage({ type, bannerId: '${bannerId}', format: '${format}', provider: '${provider}', reason }, '*');
|
|
35
|
+
}
|
|
36
|
+
var observer = new MutationObserver(function() {
|
|
37
|
+
var body = document.body;
|
|
38
|
+
if (body) {
|
|
39
|
+
var hasAdElement = body.querySelector('iframe') || body.querySelector('a') || body.querySelector('img');
|
|
40
|
+
if (hasAdElement) {
|
|
41
|
+
report('ad-load-success');
|
|
42
|
+
observer.disconnect();
|
|
43
|
+
clearTimeout(timeoutId);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
48
|
+
var timeoutId = setTimeout(function() {
|
|
49
|
+
report('ad-load-error', 'timeout');
|
|
50
|
+
observer.disconnect();
|
|
51
|
+
}, 3000);
|
|
52
|
+
window.onerror = function(msg) {
|
|
53
|
+
var isSecurityError = msg && msg.indexOf('SecurityError') !== -1;
|
|
54
|
+
var isSandboxError = msg && msg.indexOf('sandboxed') !== -1;
|
|
55
|
+
report('ad-load-error', isSecurityError ? 'security-error' : isSandboxError ? 'sandbox-error' : 'generic-error');
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
${sClose}`;
|
|
59
|
+
}
|
|
60
|
+
function buildSrcDoc(params) {
|
|
61
|
+
const { format, provider, config, bannerId } = params;
|
|
62
|
+
const sOpen = "<script";
|
|
63
|
+
const sClose = "</script>";
|
|
64
|
+
if (provider === "hilltopads" && format === "300x250") {
|
|
65
|
+
return `
|
|
66
|
+
<html><head>${reporterScript({ bannerId, format, provider })}</head>
|
|
67
|
+
<body style="margin:0;padding:0;overflow:hidden;display:flex;align-items:center;justify-content:center;height:100vh;">
|
|
68
|
+
${sOpen}> (function(adcms){ var d = document, s = d.createElement('script'), l = d.scripts[d.scripts.length - 1]; s.settings = adcms || {}; s.src = "//untimely-hello.com/bkX.VfsldRG/l/0/YEWWcc/ueMm-9XujZsUYlTkOPmTsY/4cNGTQUPwhN/DvUattNEj/gZ1INTT/Ap0ROBQZ"; s.async = true; s.referrerPolicy = 'no-referrer-when-downgrade'; l.parentNode.insertBefore(s, l); })({}) ${sClose}
|
|
69
|
+
</body></html>`;
|
|
70
|
+
}
|
|
71
|
+
if (format === "native") {
|
|
72
|
+
return `
|
|
73
|
+
<html><head>${reporterScript({ bannerId, format, provider })}</head>
|
|
74
|
+
<body style="margin:0;padding:0;overflow:hidden;">
|
|
75
|
+
${sOpen} async="async" data-cfasync="false" src="https://pl28807911.effectivegatecpm.com/${config.key}/invoke.js">${sClose}
|
|
76
|
+
<div id="container-${config.key}"></div>
|
|
77
|
+
</body></html>`;
|
|
78
|
+
}
|
|
79
|
+
return `
|
|
80
|
+
<html><head>${reporterScript({ bannerId, format, provider })}</head>
|
|
81
|
+
<body style="margin:0;padding:0;overflow:hidden;display:flex;align-items:center;justify-content:center;height:100vh;">
|
|
82
|
+
${sOpen} type="text/javascript">
|
|
83
|
+
atOptions = { 'key': '${config.key}', 'format': 'iframe', 'height': ${config.height}, 'width': ${config.width}, 'params': {} };
|
|
84
|
+
${sClose}
|
|
85
|
+
${sOpen} type="text/javascript" src="https://www.highperformanceformat.com/${config.key}/invoke.js">${sClose}
|
|
86
|
+
</body></html>`;
|
|
87
|
+
}
|
|
88
|
+
function createBannerId() {
|
|
89
|
+
return Math.random().toString(36).slice(2, 9);
|
|
90
|
+
}
|
|
91
|
+
function withAdKey(config, adKey) {
|
|
92
|
+
if (!adKey) return config;
|
|
93
|
+
return { ...config, key: adKey };
|
|
94
|
+
}
|
|
95
|
+
function resolveAdConfig(format, adKey) {
|
|
96
|
+
const base = DEFAULT_AD_CONFIGS[format];
|
|
97
|
+
const resolvedKey = adKey || getConfiguredAdKey(format);
|
|
98
|
+
return withAdKey(base, resolvedKey);
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
DEFAULT_AD_CONFIGS,
|
|
102
|
+
buildSrcDoc,
|
|
103
|
+
configureAds,
|
|
104
|
+
createBannerId,
|
|
105
|
+
getBannerStyle,
|
|
106
|
+
getConfiguredAdKey,
|
|
107
|
+
resetAdsConfig,
|
|
108
|
+
resolveAdConfig,
|
|
109
|
+
shouldFallback,
|
|
110
|
+
withAdKey
|
|
111
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adsterra-ad/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"prepublishOnly": "npm run build && npm run typecheck"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"tsup": "^8.2.4",
|
|
28
|
+
"typescript": "^5.5.4"
|
|
29
|
+
}
|
|
30
|
+
}
|