@overlayed/ads 0.1.1 → 0.1.3

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.
@@ -0,0 +1,65 @@
1
+ //#region src/reviq.d.ts
2
+ /**
3
+ * Sets a key-value pair for optional targeting
4
+ *
5
+ * WARNING: You may not pass any user-identifiable data (including names, addresses, or user IDs) in targeting.
6
+ *
7
+ * @param key - The key to set.
8
+ * @param value - The value to set.
9
+ * @returns void
10
+ */
11
+ declare function setKv(key: string, value: string): void;
12
+ /**
13
+ * Sets multiple key-value pairs for optional targeting
14
+ *
15
+ * WARNING: You may not pass any user-identifiable data (including names, addresses, or user IDs) in targeting.
16
+ *
17
+ * @param kvs - The key-value pairs to set.
18
+ * @returns void
19
+ */
20
+ declare function setKvs(kvs: Record<string, string>): void;
21
+ /**
22
+ * Sets whether ads are enabled or not
23
+ *
24
+ * @param enabled - Whether ads are enabled or not.
25
+ * @returns void
26
+ */
27
+ declare function setAdsEnabled(enabled: boolean): void;
28
+ /**
29
+ * Provide a user ID (uid) for targeting. Variadic.
30
+ *
31
+ * Providing a UID significantly improves ad performance. As such, it is optional, but highly recommended.
32
+ *
33
+ * 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.
34
+ *
35
+ * 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.
36
+ *
37
+ * @param uid - The user ID to set.
38
+ * @param uid.u - The username.
39
+ * @param uid.e - The email.
40
+ * @param uid.p - The phone.
41
+ * @returns void
42
+ */
43
+ declare function setUid(uid: {
44
+ u?: string;
45
+ e?: string;
46
+ p?: string;
47
+ }): void;
48
+ /**
49
+ * Shows the consent dialog
50
+ *
51
+ * @returns void
52
+ */
53
+ declare function showConsent(): void;
54
+ //#endregion
55
+ //#region src/index.d.ts
56
+ /**
57
+ * Initializes the Overlayed Ads.
58
+ * Overlayed must have been initialized on the electron side.
59
+ *
60
+ * This function only needs to be called once as it will retry initiailizing the ads until it succeeds.
61
+ */
62
+ declare function init(): void;
63
+ //#endregion
64
+ export { init, setAdsEnabled, setKv, setKvs, setUid, showConsent };
65
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,150 @@
1
+ //#region src/log.ts
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
@@ -0,0 +1 @@
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;AAED,SAAgB,mBAAmB;AAElC,YAAW,WAAW,YACrB,QAAO;AAGR,OAAM,eAAe,YAAY,OAAO,cAAc,OAAO,UAAU,YAAY;AAClF,WAAS,yEAAyE;AAClF,SAAO;CACP;AAED,QAAO;AACP;;;;;;;;;;;;;ACbD,SAAgB,MAAMC,KAAaC,OAAqB;AACvD,KAAI,QAAQ,UAAU;AACrB,WAAS,uCAAuC;AAChD;CACA;AAED,gBAAe,CAAC,UAAU;AACzB,QAAM,MAAM,KAAK,MAAM;CACvB,EAAC;AACF;AAED,SAAgB,OAAOD,KAAaC,OAAqB;AACxD,gBAAe,CAAC,UAAU;AACzB,QAAM,MAAM,KAAK,MAAM;CACvB,EAAC;AACF;;;;;;;;;AAUD,SAAgB,OAAOC,KAAmC;AACzD,KAAI,IAAI,QAAQ;AACf,WAAS,uCAAuC;AAChD;CACA;AAED,gBAAe,CAAC,UAAU;AACzB,QAAM,OAAO,IAAI;CACjB,EAAC;AACF;;;;;;;AAOD,SAAgB,cAAcC,SAAwB;AACrD,gBAAe,CAAC,UAAU;AACzB,QAAM,cAAc,QAAQ;CAC5B,EAAC;AACF;;;;;;;;;;;;;;;;AAiBD,SAAgB,OAAOC,KAId;AACR,MAAK,kBAAkB,IAAI,IAAI,GAAG;AACjC,iBAAe,CAAC,UAAU;AACzB,SAAM,OAAO,IAAI;EACjB,EAAC;AAEF;CACA;AAED,QAAO,UAAU,YAAY,CAAC,KAAK,CAAC,YAAY;AAC/C,iBAAe,CAAC,UAAU;AACzB,SAAM,OAAO;IACZ,GAAG;IACH,GAAG,QAAQ;GACX,EAAC;EACF,EAAC;CACF,EAAC;AACF;;;;;;AAOD,SAAgB,cAAoB;AACnC,gBAAe,CAAC,UAAU;AACzB,QAAM,aAAa;CACnB,EAAC;AACF;;;;ACnGD,IAAIC,WAAkC;;;;;;;AAOtC,SAAgB,OAAa;AAC5B,KAAI,SACH,eAAc,SAAS;AAGxB,YAAW,qBAAqB,MAAM;AACrC,UAAQ,8CAA8C;AACtD,OAAK,kBAAkB,CACtB;AAGD,MAAI,SACH,eAAc,SAAS;AAGxB,gBAAc,OAAO,UAAU;CAC/B,GAAE,IAAK;AACR;AAED,eAAe,cAAcC,WAAsB;CAClD,MAAM,UAAU,MAAM,UAAU,YAAY;AAE5C,QAAO,UAAU,QAAQ,KAAK;AAC9B,QAAO,EACN,GAAG,QAAQ,OACX,EAAC;AAEF,SAAQ,+BAA+B;AACvC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@overlayed/ads",
3
3
  "author": "overlayed.gg",
4
4
  "homepage": "https://overlayed.gg",
5
- "version": "0.1.1",
5
+ "version": "0.1.3",
6
6
  "description": "Overlayed ads",
7
7
  "license": "BSD-3-Clause",
8
8
  "repository": {
@@ -36,11 +36,9 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@ark/attest": "^0.45.0",
39
- "rollup-plugin-node-externals": "^8.0.0",
39
+ "happy-dom": "^18.0.1",
40
+ "tsdown": "^0.12.9",
40
41
  "typescript": "^5.8.2",
41
- "vite": "^6.2.6",
42
- "vite-plugin-dts": "^4.5.3",
43
- "vite-plugin-static-copy": "^2.3.1",
44
42
  "vitest": "^3.0.9"
45
43
  },
46
44
  "engines": {