@temple-wallet/extension-ads 7.1.1 → 8.1.0-dev.1
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 +33 -52
- package/dist/index.js +13 -12
- package/package.json +3 -6
- package/src/ads-actions/helpers.ts +25 -11
- package/src/ads-actions/index.ts +6 -3
- package/src/ads-actions/process-permanent-rule.ts +9 -1
- package/src/ads-actions/process-providers-ads.ts +39 -16
- package/src/ads-actions/process-rule.ts +2 -0
- package/src/ads-configuration.ts +8 -8
- package/src/constants.ts +2 -0
- package/src/execute-ads-actions/ads-views/index.ts +2 -2
- package/src/execute-ads-actions/ads-views/{make-hypelab-ad.ts → make-ads-tw-view.ts} +11 -9
- package/src/execute-ads-actions/ads-views/make-extension-iframe-view.ts +26 -0
- package/src/execute-ads-actions/ads-views/make-tkey-ad.ts +1 -1
- package/src/execute-ads-actions/observing.ts +13 -7
- package/src/execute-ads-actions/process-insert-ad-action.ts +11 -3
- package/src/render-ads-stack.ts +70 -14
- package/src/temple-wallet-api.ts +9 -2
- package/src/transform-raw-rules.ts +27 -11
- package/src/types/ad-view.ts +3 -0
- package/src/types/ads-actions.ts +4 -1
- package/src/types/ads-meta.ts +3 -18
- package/src/types/ads-provider.ts +1 -0
- package/src/types/ads-rules.ts +1 -1
- package/src/types/temple-wallet-api.ts +1 -0
- package/src/utils.ts +0 -4
- package/dist/referrals/index.d.ts +0 -33
- package/dist/referrals/index.js +0 -18
- package/src/execute-ads-actions/ads-views/make-persona-ad.ts +0 -15
- package/src/referrals/index.ts +0 -5
- package/src/referrals/replace.ts +0 -129
- package/src/referrals/takeads.ts +0 -44
- package/src/referrals/utils.ts +0 -14
package/dist/referrals/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var T = require('webextension-polyfill');
|
|
4
|
-
var lodash = require('lodash');
|
|
5
|
-
var E = require('axios');
|
|
6
|
-
var D = require('memoizee');
|
|
7
|
-
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
var T__default = /*#__PURE__*/_interopDefault(T);
|
|
11
|
-
var E__default = /*#__PURE__*/_interopDefault(E);
|
|
12
|
-
var D__default = /*#__PURE__*/_interopDefault(D);
|
|
13
|
-
|
|
14
|
-
var p=(r,t,e)=>new Promise((c,s)=>{var a=i=>{try{n(e.next(i));}catch(l){s(l);}},o=i=>{try{n(e.throw(i));}catch(l){s(l);}},n=i=>i.done?c(i.value):Promise.resolve(i.value).then(a,o);n((e=e.apply(r,t)).next());});var f=process&&process.env&&process.env.NODE_ENV==="development",h=navigator.userAgent.includes("Macintosh"),w=r=>!!r;var u=lodash.memoize(()=>m(window.location.hostname,"www"));function m(r,t){return r.includes(`${t}.`)?r.slice(t.length+1):r}var A="data-tw-referral";function y(r,t){return p(this,null,function*(){var o;let e=Array.from(document.querySelectorAll("a"));if(!e.length)throw new Error("No anchors found");let c=e.map(n=>{if(n.hasAttribute(A))return null;let i=R(n.href);if(!i||!r.has(i))return null;let l=v(n.href);return l?{iri:l,aElem:n,urlDomain:i}:null}).filter(w);if(!c.length)return void(f&&console.info("Nothing to replace"));let s=c.map(n=>n.iri),a=yield T__default.default.runtime.sendMessage({type:t.FetchReferrals,links:s});if(!a.data.length)return void(f&&console.info("No referrals received"));f&&console.info("Replacing",a.data.length,"referralas");for(let{iri:n,aElem:i,urlDomain:l}of c){let g=(o=a.data.find(x=>x.iri===n))==null?void 0:o.trackingLink;if(!g){f&&console.warn("No affiliate link for",i);continue}L({iri:n,aElem:i,urlDomain:l,referralUrl:g},t);}})}function L(r,t){let{aElem:e,urlDomain:c,referralUrl:s}=r,a=e.href;f&&console.info("Replacing referral:",a,"to",s,"for anchor:",e),e.setAttribute(A,"set"),e.onclick=o=>{o.preventDefault(),f&&console.log("Referral clicked:",a,"->",s),T__default.default.runtime.sendMessage({type:t.ReferralClick,urlDomain:c,pageDomain:u()});let n=o.button===1||(h?o.metaKey:o.ctrlKey);window.open(s,n?"_blank":"_self");},e.oncontextmenu=()=>{e.href=s;let o=()=>{e.href=a,window.removeEventListener("focus",o);};window.addEventListener("focus",o);};}function R(r){try{return m(new URL(r).hostname,"www")}catch(t){return null}}function v(r){try{let t=new URL(r);return t.origin+t.pathname}catch(t){return null}}var d=class{constructor(t,e="https://api.takeads.com"){this.publicKey=t;this.apiUrl=e;this.axios=E__default.default.create({baseURL:e,headers:{Authorization:`Bearer ${this.publicKey}`},adapter:"fetch"});}affiliateLinks(t,e){return p(this,null,function*(){return (yield this.axios.put("/v1/product/monetize-api/v2/resolve",{iris:t,subId:e,withImages:!1})).data})}},I=D__default.default(r=>new d(r),{max:2});
|
|
15
|
-
|
|
16
|
-
exports.buildTakeadsClient = I;
|
|
17
|
-
exports.getCurrentPageDomain = u;
|
|
18
|
-
exports.processAnchors = y;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AdsConfiguration } from 'src/ads-configuration';
|
|
2
|
-
import { AdView } from 'src/types/ad-view';
|
|
3
|
-
import { AdDimensions, PersonaAdSource } from 'src/types/ads-meta';
|
|
4
|
-
|
|
5
|
-
export const makePersonaAdView = (id: string, source: PersonaAdSource, { width, height }: AdDimensions): AdView => {
|
|
6
|
-
const element = document.createElement('iframe');
|
|
7
|
-
element.src = AdsConfiguration.getPersonaIframeURL(id, source.slug);
|
|
8
|
-
element.id = id;
|
|
9
|
-
|
|
10
|
-
element.style.width = `${width}px`;
|
|
11
|
-
element.style.height = `${height}px`;
|
|
12
|
-
element.style.border = 'none';
|
|
13
|
-
|
|
14
|
-
return { element };
|
|
15
|
-
};
|
package/src/referrals/index.ts
DELETED
package/src/referrals/replace.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import browser from 'webextension-polyfill';
|
|
2
|
-
|
|
3
|
-
import { IS_DEV, IS_MAC_OS, isTruthy } from 'src/utils';
|
|
4
|
-
|
|
5
|
-
import type { TekeadsAffiliateResponse } from './takeads';
|
|
6
|
-
import { getCurrentPageDomain, stripSubdomain } from './utils';
|
|
7
|
-
|
|
8
|
-
const TEMPLE_WALLET_ANCHOR_ATTRIBUTE = 'data-tw-referral';
|
|
9
|
-
|
|
10
|
-
export async function processAnchors(
|
|
11
|
-
supportedDomains: Set<string>,
|
|
12
|
-
AdsBrowserExtensionMessageType: AdsBrowserExtensionMessageTypeI
|
|
13
|
-
) {
|
|
14
|
-
const anchors = Array.from(document.querySelectorAll('a'));
|
|
15
|
-
if (!anchors.length) throw new Error('No anchors found');
|
|
16
|
-
|
|
17
|
-
const items = anchors
|
|
18
|
-
.map(aElem => {
|
|
19
|
-
if (aElem.hasAttribute(TEMPLE_WALLET_ANCHOR_ATTRIBUTE)) return null;
|
|
20
|
-
|
|
21
|
-
const urlDomain = getDomain(aElem.href);
|
|
22
|
-
if (!urlDomain || !supportedDomains.has(urlDomain)) return null;
|
|
23
|
-
|
|
24
|
-
const iri = cleanLink(aElem.href);
|
|
25
|
-
if (!iri) return null;
|
|
26
|
-
|
|
27
|
-
return { iri, aElem, urlDomain };
|
|
28
|
-
})
|
|
29
|
-
.filter(isTruthy);
|
|
30
|
-
|
|
31
|
-
if (!items.length) return void (IS_DEV && console.info('Nothing to replace'));
|
|
32
|
-
|
|
33
|
-
const links = items.map(l => l.iri);
|
|
34
|
-
|
|
35
|
-
// Not requesting directly in content script because of CORS.
|
|
36
|
-
const takeadsItems: TekeadsAffiliateResponse = await browser.runtime.sendMessage({
|
|
37
|
-
type: AdsBrowserExtensionMessageType.FetchReferrals,
|
|
38
|
-
links
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
if (!takeadsItems.data.length) return void (IS_DEV && console.info('No referrals received'));
|
|
42
|
-
|
|
43
|
-
IS_DEV && console.info('Replacing', takeadsItems.data.length, 'referralas');
|
|
44
|
-
|
|
45
|
-
for (const { iri, aElem, urlDomain } of items) {
|
|
46
|
-
const referralUrl = takeadsItems.data.find(item => item.iri === iri)?.trackingLink;
|
|
47
|
-
|
|
48
|
-
if (!referralUrl) {
|
|
49
|
-
IS_DEV && console.warn('No affiliate link for', aElem);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
processAnchorElement({ iri, aElem, urlDomain, referralUrl }, AdsBrowserExtensionMessageType);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
interface AdsBrowserExtensionMessageTypeI {
|
|
60
|
-
FetchReferrals: string;
|
|
61
|
-
ReferralClick: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
interface PreppedItem {
|
|
65
|
-
iri: string;
|
|
66
|
-
aElem: HTMLAnchorElement;
|
|
67
|
-
urlDomain: string;
|
|
68
|
-
referralUrl: string;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function processAnchorElement(item: PreppedItem, AdsBrowserExtensionMessageType: AdsBrowserExtensionMessageTypeI) {
|
|
72
|
-
const { aElem, urlDomain, referralUrl } = item;
|
|
73
|
-
|
|
74
|
-
const showHref = aElem.href;
|
|
75
|
-
|
|
76
|
-
IS_DEV && console.info('Replacing referral:', showHref, 'to', referralUrl, 'for anchor:', aElem);
|
|
77
|
-
|
|
78
|
-
aElem.setAttribute(TEMPLE_WALLET_ANCHOR_ATTRIBUTE, 'set');
|
|
79
|
-
|
|
80
|
-
aElem.onclick = event => {
|
|
81
|
-
event.preventDefault();
|
|
82
|
-
|
|
83
|
-
IS_DEV && console.log('Referral clicked:', showHref, '->', referralUrl);
|
|
84
|
-
|
|
85
|
-
browser.runtime.sendMessage({
|
|
86
|
-
type: AdsBrowserExtensionMessageType.ReferralClick,
|
|
87
|
-
urlDomain,
|
|
88
|
-
pageDomain: getCurrentPageDomain()
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const newTab = event.button === 1 || (IS_MAC_OS ? event.metaKey : event.ctrlKey);
|
|
92
|
-
|
|
93
|
-
window.open(referralUrl, newTab ? '_blank' : '_self');
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
aElem.oncontextmenu = () => {
|
|
97
|
-
/*
|
|
98
|
-
Making sure, user opens referral URL via Context Menu's 'Open in new tab' button.
|
|
99
|
-
Note: 'Copy to clipboard' button will also provide referral URL this way.
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
aElem.href = referralUrl;
|
|
103
|
-
|
|
104
|
-
const revertHref = () => {
|
|
105
|
-
aElem.href = showHref;
|
|
106
|
-
window.removeEventListener('focus', revertHref);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
window.addEventListener('focus', revertHref);
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function getDomain(href: string) {
|
|
114
|
-
try {
|
|
115
|
-
return stripSubdomain(new URL(href).hostname, 'www');
|
|
116
|
-
} catch {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function cleanLink(href: string) {
|
|
122
|
-
try {
|
|
123
|
-
const dirtyLink = new URL(href);
|
|
124
|
-
|
|
125
|
-
return dirtyLink.origin + dirtyLink.pathname;
|
|
126
|
-
} catch {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
}
|
package/src/referrals/takeads.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosInstance } from 'axios';
|
|
2
|
-
import memoizee from 'memoizee';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* API docs: https://docs.takeads.com
|
|
6
|
-
*/
|
|
7
|
-
export class TakeAdsClient {
|
|
8
|
-
private axios: AxiosInstance;
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
private publicKey: string,
|
|
12
|
-
readonly apiUrl: string = 'https://api.takeads.com'
|
|
13
|
-
) {
|
|
14
|
-
this.axios = axios.create({
|
|
15
|
-
baseURL: apiUrl,
|
|
16
|
-
headers: {
|
|
17
|
-
Authorization: `Bearer ${this.publicKey}`
|
|
18
|
-
},
|
|
19
|
-
adapter: 'fetch'
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async affiliateLinks(websiteUrls: string[], subId?: string) {
|
|
24
|
-
const response = await this.axios.put<TekeadsAffiliateResponse>('/v1/product/monetize-api/v2/resolve', {
|
|
25
|
-
iris: websiteUrls,
|
|
26
|
-
subId,
|
|
27
|
-
withImages: false
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return response.data;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const buildTakeadsClient = memoizee((publicKey: string) => new TakeAdsClient(publicKey), { max: 2 });
|
|
35
|
-
|
|
36
|
-
export interface TekeadsAffiliateResponse {
|
|
37
|
-
data: AffiliateLink[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface AffiliateLink {
|
|
41
|
-
iri: string;
|
|
42
|
-
trackingLink: string;
|
|
43
|
-
imageUrl: string | null;
|
|
44
|
-
}
|
package/src/referrals/utils.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { memoize } from 'lodash';
|
|
2
|
-
|
|
3
|
-
/** Current page's domain with 'www' stripped off */
|
|
4
|
-
export const getCurrentPageDomain = memoize(() => {
|
|
5
|
-
return stripSubdomain(window.location.hostname, 'www');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export function stripSubdomain(hostname: string, subdomain: string) {
|
|
9
|
-
if (hostname.includes(`${subdomain}.`)) {
|
|
10
|
-
return hostname.slice(subdomain.length + 1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return hostname;
|
|
14
|
-
}
|