@overlayed/ads 0.1.3 → 0.1.4
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.d.ts +1 -2
- package/dist/index.js +1 -150
- package/package.json +5 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -61,5 +61,4 @@ declare function showConsent(): void;
|
|
|
61
61
|
*/
|
|
62
62
|
declare function init(): void;
|
|
63
63
|
//#endregion
|
|
64
|
-
export { init, setAdsEnabled, setKv, setKvs, setUid, showConsent };
|
|
65
|
-
//# sourceMappingURL=index.d.ts.map
|
|
64
|
+
export { init, setAdsEnabled, setKv, setKvs, setUid, showConsent };
|
package/dist/index.js
CHANGED
|
@@ -1,150 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function logError(message, ...args) {
|
|
3
|
-
console.error(`[Overlayed] ${message}`, ...args);
|
|
4
|
-
}
|
|
5
|
-
function logInfo(message, ...args) {
|
|
6
|
-
console.info(`[Overlayed] ${message}`, ...args);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/utils.ts
|
|
11
|
-
function useAdsCallback(command) {
|
|
12
|
-
globalThis.reviq = globalThis.reviq || [];
|
|
13
|
-
globalThis.reviq.push(command);
|
|
14
|
-
}
|
|
15
|
-
function setIntervalImmediate(callback, delay) {
|
|
16
|
-
callback();
|
|
17
|
-
return setInterval(callback, delay);
|
|
18
|
-
}
|
|
19
|
-
function isOverlayedReady() {
|
|
20
|
-
if (typeof window === "undefined") return false;
|
|
21
|
-
if (!("overlayed" in window) || !window.overlayed || !window.overlayed.getAppInfo) {
|
|
22
|
-
logError("Could not find overlayed instance - did you import the preload script?");
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/reviq.ts
|
|
30
|
-
/**
|
|
31
|
-
* Sets a key-value pair for optional targeting
|
|
32
|
-
*
|
|
33
|
-
* WARNING: You may not pass any user-identifiable data (including names, addresses, or user IDs) in targeting.
|
|
34
|
-
*
|
|
35
|
-
* @param key - The key to set.
|
|
36
|
-
* @param value - The value to set.
|
|
37
|
-
* @returns void
|
|
38
|
-
*/
|
|
39
|
-
function setKv(key, value) {
|
|
40
|
-
if (key === "app_id") {
|
|
41
|
-
logError("[Overlayed] app_id is a reserved key");
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
useAdsCallback((reviq) => {
|
|
45
|
-
reviq.setKv(key, value);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function _setKv(key, value) {
|
|
49
|
-
useAdsCallback((reviq) => {
|
|
50
|
-
reviq.setKv(key, value);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Sets multiple key-value pairs for optional targeting
|
|
55
|
-
*
|
|
56
|
-
* WARNING: You may not pass any user-identifiable data (including names, addresses, or user IDs) in targeting.
|
|
57
|
-
*
|
|
58
|
-
* @param kvs - The key-value pairs to set.
|
|
59
|
-
* @returns void
|
|
60
|
-
*/
|
|
61
|
-
function setKvs(kvs) {
|
|
62
|
-
if (kvs.app_id) {
|
|
63
|
-
logError("[Overlayed] app_id is a reserved key");
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
useAdsCallback((reviq) => {
|
|
67
|
-
reviq.setKvs(kvs);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Sets whether ads are enabled or not
|
|
72
|
-
*
|
|
73
|
-
* @param enabled - Whether ads are enabled or not.
|
|
74
|
-
* @returns void
|
|
75
|
-
*/
|
|
76
|
-
function setAdsEnabled(enabled) {
|
|
77
|
-
useAdsCallback((reviq) => {
|
|
78
|
-
reviq.setAdsEnabled(enabled);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Provide a user ID (uid) for targeting. Variadic.
|
|
83
|
-
*
|
|
84
|
-
* Providing a UID significantly improves ad performance. As such, it is optional, but highly recommended.
|
|
85
|
-
*
|
|
86
|
-
* We comply with all privacy regulations and do not store any user-identifiable data. Once passed to RevIQ, the UID is normalized and then hashed; we never store the original value.
|
|
87
|
-
*
|
|
88
|
-
* If the user has opted out of tracking, the UID will not be stored or transmitted. Thus it is safe to call this function regardless of the user’s tracking preferences.
|
|
89
|
-
*
|
|
90
|
-
* @param uid - The user ID to set.
|
|
91
|
-
* @param uid.u - The username.
|
|
92
|
-
* @param uid.e - The email.
|
|
93
|
-
* @param uid.p - The phone.
|
|
94
|
-
* @returns void
|
|
95
|
-
*/
|
|
96
|
-
function setUid(uid) {
|
|
97
|
-
if (!isOverlayedReady() || uid.u) {
|
|
98
|
-
useAdsCallback((reviq) => {
|
|
99
|
-
reviq.setUid(uid);
|
|
100
|
-
});
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
window.overlayed.getAppInfo().then((appInfo) => {
|
|
104
|
-
useAdsCallback((reviq) => {
|
|
105
|
-
reviq.setUid({
|
|
106
|
-
...uid,
|
|
107
|
-
u: appInfo.userId
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Shows the consent dialog
|
|
114
|
-
*
|
|
115
|
-
* @returns void
|
|
116
|
-
*/
|
|
117
|
-
function showConsent() {
|
|
118
|
-
useAdsCallback((reviq) => {
|
|
119
|
-
reviq.showConsent();
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/index.ts
|
|
125
|
-
let interval = null;
|
|
126
|
-
/**
|
|
127
|
-
* Initializes the Overlayed Ads.
|
|
128
|
-
* Overlayed must have been initialized on the electron side.
|
|
129
|
-
*
|
|
130
|
-
* This function only needs to be called once as it will retry initiailizing the ads until it succeeds.
|
|
131
|
-
*/
|
|
132
|
-
function init() {
|
|
133
|
-
if (interval) clearInterval(interval);
|
|
134
|
-
interval = setIntervalImmediate(() => {
|
|
135
|
-
logInfo("[Overlayed] Attempting to intiailize ads...");
|
|
136
|
-
if (!isOverlayedReady()) return;
|
|
137
|
-
if (interval) clearInterval(interval);
|
|
138
|
-
initOverlayed(window.overlayed);
|
|
139
|
-
}, 1e3);
|
|
140
|
-
}
|
|
141
|
-
async function initOverlayed(overlayed) {
|
|
142
|
-
const appInfo = await overlayed.getAppInfo();
|
|
143
|
-
_setKv("app_id", appInfo.slug);
|
|
144
|
-
setUid({ u: appInfo.userId });
|
|
145
|
-
logInfo("[Overlayed] Ads initialized!");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
//#endregion
|
|
149
|
-
export { init, setAdsEnabled, setKv, setKvs, setUid, showConsent };
|
|
150
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
function e(e,...t){console.error(`[Overlayed] ${e}`,...t)}function t(e,...t){console.info(`[Overlayed] ${e}`,...t)}function n(e){globalThis.reviq=globalThis.reviq||[],globalThis.reviq.push(e)}function r(e,t){return e(),setInterval(e,t)}function i(){return typeof window>`u`?!1:!(`overlayed`in window)||!window.overlayed||!window.overlayed.getAppInfo?(e(`Could not find overlayed instance - did you import the preload script?`),!1):!0}function a(t,r){if(t===`app_id`){e(`[Overlayed] app_id is a reserved key`);return}n(e=>{e.setKv(t,r)})}function o(e,t){n(n=>{n.setKv(e,t)})}function s(t){if(t.app_id){e(`[Overlayed] app_id is a reserved key`);return}n(e=>{e.setKvs(t)})}function c(e){n(t=>{t.setAdsEnabled(e)})}function l(e){if(!i()||e.u){n(t=>{t.setUid(e)});return}window.overlayed.getAppInfo().then(t=>{n(n=>{n.setUid({...e,u:t.userId})})})}function u(){n(e=>{e.showConsent()})}let d=null;function f(){d&&clearInterval(d),d=r(()=>{t(`[Overlayed] Attempting to intiailize ads...`),i()&&(d&&clearInterval(d),p(window.overlayed))},1e3)}async function p(e){let n=await e.getAppInfo();o(`app_id`,n.slug),l({u:n.userId}),t(`[Overlayed] Ads initialized!`)}export{f as init,c as setAdsEnabled,a as setKv,s as setKvs,l as setUid,u as showConsent};
|
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "@overlayed/ads",
|
|
3
3
|
"author": "overlayed.gg",
|
|
4
4
|
"homepage": "https://overlayed.gg",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.4",
|
|
6
6
|
"description": "Overlayed ads",
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
8
8
|
"repository": {
|
|
9
9
|
"url": "https://github.com/overlayed-gg/overlayed-typescript",
|
|
10
10
|
"type": "git"
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@ark/attest": "^0.
|
|
38
|
+
"@ark/attest": "^0.48.2",
|
|
39
39
|
"happy-dom": "^18.0.1",
|
|
40
40
|
"tsdown": "^0.12.9",
|
|
41
|
-
"typescript": "^5.8.
|
|
42
|
-
"vitest": "^3.
|
|
41
|
+
"typescript": "^5.8.3",
|
|
42
|
+
"vitest": "^3.2.4"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=20.10.0"
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["key: string","value: string","kvs: Record<string, string>","enabled: boolean","uid: {\n\tu?: string; // username\n\te?: string; // email\n\tp?: string; // phone\n}"],"sources":["../src/reviq.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;AAYA;AAyBA;AAgBA;AAqBA;AA4BA;;;;ACxFgB,iBDFA,KAAA,CCEA,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;;;;;;;;iBDuBA,MAAA,MAAY;;;;;;;iBAgBZ,aAAA;;;;;;;;;;;;;;;;iBAqBA,MAAA;;;;;;;;;;iBA4BA,WAAA,CAAA;;;AA1FhB;AAyBA;AAgBA;AAqBA;AA4BA;;iBCxFgB,IAAA,CAAA"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["message: string","command: (reviq: Reviq) => void","callback: () => void","delay: number","key: string","value: string","kvs: Record<string, string>","enabled: boolean","uid: {\n\tu?: string; // username\n\te?: string; // email\n\tp?: string; // phone\n}","interval: NodeJS.Timeout | null","overlayed: Overlayed"],"sources":["../src/log.ts","../src/utils.ts","../src/reviq.ts","../src/index.ts"],"sourcesContent":["export function logError(message: string, ...args: any[]) {\n\tconsole.error(`[Overlayed] ${message}`, ...args);\n}\n\nexport function logWarning(message: string, ...args: any[]) {\n\tconsole.warn(`[Overlayed] ${message}`, ...args);\n}\n\nexport function logInfo(message: string, ...args: any[]) {\n\tconsole.info(`[Overlayed] ${message}`, ...args);\n}\n","import { logError } from \"./log\";\nimport type { Reviq } from \"./types\";\n\nexport function useAdsCallback(command: (reviq: Reviq) => void) {\n\tglobalThis.reviq = globalThis.reviq || [];\n\tglobalThis.reviq.push(command);\n}\n\nexport function setIntervalImmediate(callback: () => void, delay: number): NodeJS.Timeout {\n\tcallback();\n\treturn setInterval(callback, delay);\n}\n\nexport function isOverlayedReady() {\n\t// SSR check\n\tif (typeof window === \"undefined\") {\n\t\treturn false;\n\t}\n\n\tif (!(\"overlayed\" in window) || !window.overlayed || !window.overlayed.getAppInfo) {\n\t\tlogError(\"Could not find overlayed instance - did you import the preload script?\");\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import { logError } from \"./log\";\nimport { isOverlayedReady, useAdsCallback } from \"./utils\";\n\n/**\n * Sets a key-value pair for optional targeting\n *\n * WARNING: You may not pass any user-identifiable data (including names, addresses, or user IDs) in targeting.\n *\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns void\n */\nexport function setKv(key: string, value: string): void {\n\tif (key === \"app_id\") {\n\t\tlogError(\"[Overlayed] app_id is a reserved key\");\n\t\treturn;\n\t}\n\n\tuseAdsCallback((reviq) => {\n\t\treviq.setKv(key, value);\n\t});\n}\n\nexport function _setKv(key: string, value: string): void {\n\tuseAdsCallback((reviq) => {\n\t\treviq.setKv(key, value);\n\t});\n}\n\n/**\n * Sets multiple key-value pairs for optional targeting\n *\n * WARNING: You may not pass any user-identifiable data (including names, addresses, or user IDs) in targeting.\n *\n * @param kvs - The key-value pairs to set.\n * @returns void\n */\nexport function setKvs(kvs: Record<string, string>): void {\n\tif (kvs.app_id) {\n\t\tlogError(\"[Overlayed] app_id is a reserved key\");\n\t\treturn;\n\t}\n\n\tuseAdsCallback((reviq) => {\n\t\treviq.setKvs(kvs);\n\t});\n}\n/**\n * Sets whether ads are enabled or not\n *\n * @param enabled - Whether ads are enabled or not.\n * @returns void\n */\nexport function setAdsEnabled(enabled: boolean): void {\n\tuseAdsCallback((reviq) => {\n\t\treviq.setAdsEnabled(enabled);\n\t});\n}\n\n/**\n * Provide a user ID (uid) for targeting. Variadic.\n *\n * Providing a UID significantly improves ad performance. As such, it is optional, but highly recommended.\n *\n * We comply with all privacy regulations and do not store any user-identifiable data. Once passed to RevIQ, the UID is normalized and then hashed; we never store the original value.\n *\n * If the user has opted out of tracking, the UID will not be stored or transmitted. Thus it is safe to call this function regardless of the user’s tracking preferences.\n *\n * @param uid - The user ID to set.\n * @param uid.u - The username.\n * @param uid.e - The email.\n * @param uid.p - The phone.\n * @returns void\n */\nexport function setUid(uid: {\n\tu?: string; // username\n\te?: string; // email\n\tp?: string; // phone\n}): void {\n\tif (!isOverlayedReady() || uid.u) {\n\t\tuseAdsCallback((reviq) => {\n\t\t\treviq.setUid(uid);\n\t\t});\n\n\t\treturn;\n\t}\n\n\twindow.overlayed.getAppInfo().then((appInfo) => {\n\t\tuseAdsCallback((reviq) => {\n\t\t\treviq.setUid({\n\t\t\t\t...uid,\n\t\t\t\tu: appInfo.userId,\n\t\t\t});\n\t\t});\n\t});\n}\n\n/**\n * Shows the consent dialog\n *\n * @returns void\n */\nexport function showConsent(): void {\n\tuseAdsCallback((reviq) => {\n\t\treviq.showConsent();\n\t});\n}\n","import type { Overlayed } from \"./types\";\nimport { _setKv, setUid } from \"./reviq\";\nimport { isOverlayedReady, setIntervalImmediate } from \"./utils\";\nimport { logInfo } from \"./log\";\n\nexport { setKv, setKvs, setAdsEnabled, setUid, showConsent } from \"./reviq\";\n\nlet interval: NodeJS.Timeout | null = null;\n/**\n * Initializes the Overlayed Ads.\n * Overlayed must have been initialized on the electron side.\n *\n * This function only needs to be called once as it will retry initiailizing the ads until it succeeds.\n */\nexport function init(): void {\n\tif (interval) {\n\t\tclearInterval(interval);\n\t}\n\n\tinterval = setIntervalImmediate(() => {\n\t\tlogInfo(\"[Overlayed] Attempting to intiailize ads...\");\n\t\tif (!isOverlayedReady()) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (interval) {\n\t\t\tclearInterval(interval);\n\t\t}\n\n\t\tinitOverlayed(window.overlayed);\n\t}, 1000);\n}\n\nasync function initOverlayed(overlayed: Overlayed) {\n\tconst appInfo = await overlayed.getAppInfo();\n\n\t_setKv(\"app_id\", appInfo.slug);\n\tsetUid({\n\t\tu: appInfo.userId,\n\t});\n\n\tlogInfo(\"[Overlayed] Ads initialized!\");\n}\n"],"mappings":";AAAA,SAAgB,SAASA,SAAiB,GAAG,MAAa;AACzD,SAAQ,MAAM,CAAC,YAAY,EAAE,SAAS,EAAE,GAAG,KAAK;AAChD;AAMD,SAAgB,QAAQA,SAAiB,GAAG,MAAa;AACxD,SAAQ,KAAK,CAAC,YAAY,EAAE,SAAS,EAAE,GAAG,KAAK;AAC/C;;;;ACPD,SAAgB,eAAeC,SAAiC;AAC/D,YAAW,QAAQ,WAAW,SAAS,CAAE;AACzC,YAAW,MAAM,KAAK,QAAQ;AAC9B;AAED,SAAgB,qBAAqBC,UAAsBC,OAA+B;AACzF,WAAU;AACV,QAAO,YAAY,UAAU,MAAM;AACnC;A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