@temple-wallet/extension-ads 17.0.0-beta.1 → 18.0.0-beta.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.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as lodash from 'lodash';
|
|
2
|
-
import memoizee from 'memoizee';
|
|
3
2
|
|
|
4
3
|
/** Current page's domain with 'www' stripped off */
|
|
5
4
|
declare const getCurrentPageDomain: (() => string) & lodash.MemoizedFunction;
|
|
@@ -12,36 +11,13 @@ interface ReferralTextIconRule {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
interface AdsBrowserExtensionMessageTypeI {
|
|
15
|
-
FetchTakeAdsReferrals: string;
|
|
16
14
|
ReferralClick: string;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
declare function processTakeAdsAnchors(supportedDomains: Set<string>, textIconRules: ReferralTextIconRule[], AdsBrowserExtensionMessageType: AdsBrowserExtensionMessageTypeI, redirectUrl?: string): Promise<undefined>;
|
|
20
|
-
|
|
21
17
|
interface TempleReferralLinkItem {
|
|
22
18
|
targetUrl: string;
|
|
23
19
|
referralLink: string;
|
|
24
20
|
}
|
|
25
21
|
declare function processTempleAnchors(linkItems: TempleReferralLinkItem[], textIconRules: ReferralTextIconRule[], AdsBrowserExtensionMessageType: AdsBrowserExtensionMessageTypeI): Promise<undefined>;
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
* API docs: https://docs.takeads.com
|
|
29
|
-
*/
|
|
30
|
-
declare class TakeAdsClient {
|
|
31
|
-
private publicKey;
|
|
32
|
-
readonly apiUrl: string;
|
|
33
|
-
private axios;
|
|
34
|
-
constructor(publicKey: string, apiUrl?: string);
|
|
35
|
-
affiliateLinks(websiteUrls: string[], subId?: string): Promise<TekeadsAffiliateResponse>;
|
|
36
|
-
}
|
|
37
|
-
declare const buildTakeadsClient: ((publicKey: string) => TakeAdsClient) & memoizee.Memoized<(publicKey: string) => TakeAdsClient>;
|
|
38
|
-
interface TekeadsAffiliateResponse {
|
|
39
|
-
data: AffiliateLink[];
|
|
40
|
-
}
|
|
41
|
-
interface AffiliateLink {
|
|
42
|
-
iri: string;
|
|
43
|
-
trackingLink: string;
|
|
44
|
-
imageUrl: string | null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { buildTakeadsClient, getCurrentPageDomain, processTakeAdsAnchors, processTempleAnchors };
|
|
23
|
+
export { getCurrentPageDomain, processTempleAnchors };
|
package/dist/referrals/index.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var M = require('webextension-polyfill');
|
|
4
4
|
var lodash = require('lodash');
|
|
5
|
-
var U = require('axios');
|
|
6
|
-
var b = require('memoizee');
|
|
7
5
|
|
|
8
6
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
7
|
|
|
10
|
-
var
|
|
11
|
-
var U__default = /*#__PURE__*/_interopDefault(U);
|
|
12
|
-
var b__default = /*#__PURE__*/_interopDefault(b);
|
|
8
|
+
var M__default = /*#__PURE__*/_interopDefault(M);
|
|
13
9
|
|
|
14
|
-
var
|
|
10
|
+
var _=(e,r,t)=>new Promise((l,c)=>{var n=s=>{try{i(t.next(s));}catch(a){c(a);}},u=s=>{try{i(t.throw(s));}catch(a){c(a);}},i=s=>s.done?l(s.value):Promise.resolve(s.value).then(n,u);i((t=t.apply(e,r)).next());});var m=process&&process.env&&process.env.NODE_ENV==="development",d=navigator.userAgent.includes("Macintosh"),S=e=>!!e;var g=lodash.memoize(()=>T(window.location.hostname,"www"));function T(e,r){return e.includes(`${r}.`)?e.slice(r.length+1):e}var h="data-tw-referral",R=e=>{let r=Array.from(document.querySelectorAll("a"));if(!r.length)throw new Error("No anchors found");return r.map(t=>{if(t.hasAttribute(h))return null;let l=y(t.href);if(!l||e&&!e.has(l))return null;let c=D(t.href);return c?{iri:c,aElem:t,urlDomain:l}:null}).filter(S)};function x(e,r,t,l,c){var A;let{aElem:n,urlDomain:u,referralUrl:i,imageUrl:s}=e,a=n.href,f=c?L(c,i):i;if(m&&console.info("Replacing referral:",a,"to",i,"for anchor:",n),n.setAttribute(h,"set"),n.onclick=o=>{o.preventDefault(),m&&console.log("Referral clicked:",a,"->",i),M__default.default.runtime.sendMessage({type:t.ReferralClick,urlDomain:u,pageDomain:g(),provider:l});let E=o.button===1||(d?o.metaKey:o.ctrlKey);window.open(f,E?"_blank":"_self");},n.oncontextmenu=()=>{n.href=f;let o=()=>{n.href=a,window.removeEventListener("focus",o);};window.addEventListener("focus",o);},!s)return;let w=g();for(let o of r){if(new RegExp(o.hostRegExStr).test(w)===!1)continue;let E=o.aChildSelector?n.querySelector(o.aChildSelector):null;if(E||(E=o.aMatchSelector&&n.matches(o.aMatchSelector)?n:null),!E)continue;let p=document.createElement("img");p.src=s,p.height=(A=o.iconHeight)!=null?A:20,p.style.display="inline-block",p.style.marginLeft="6px",p.style.verticalAlign="middle",E.appendChild(p);return}}function L(e,r){let t=new URL(e);return t.searchParams.set("url",r),t.toString()}function y(e){try{return T(new URL(e).hostname,"www")}catch(r){return null}}function D(e){try{let r=new URL(e);return r.origin+r.pathname}catch(r){return null}}function P(e,r,t){return _(this,null,function*(){let l=R();if(!l.length)return void(m&&console.info("Nothing to replace"));for(let{iri:c,aElem:n,urlDomain:u}of l){let i=e.find(f=>f.targetUrl===c),s=i==null?void 0:i.referralLink;if(!s){m&&console.warn("No affiliate link for",n);continue}x({iri:c,aElem:n,urlDomain:u,referralUrl:s,imageUrl:"https://raw.githubusercontent.com/madfish-solutions/templewallet-extension/development/public/misc/icon-128.png"},r,t,"Temple");}})}
|
|
15
11
|
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.processTakeAdsAnchors = P;
|
|
19
|
-
exports.processTempleAnchors = v;
|
|
12
|
+
exports.getCurrentPageDomain = g;
|
|
13
|
+
exports.processTempleAnchors = P;
|
package/package.json
CHANGED
package/src/referrals/common.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { getCurrentPageDomain, ReferralTextIconRule, stripSubdomain } from './ut
|
|
|
7
7
|
const TEMPLE_WALLET_ANCHOR_ATTRIBUTE = 'data-tw-referral';
|
|
8
8
|
|
|
9
9
|
export interface AdsBrowserExtensionMessageTypeI {
|
|
10
|
-
FetchTakeAdsReferrals: string;
|
|
11
10
|
ReferralClick: string;
|
|
12
11
|
}
|
|
13
12
|
|
|
@@ -42,7 +41,7 @@ export function processAnchorElement(
|
|
|
42
41
|
item: PreppedItem,
|
|
43
42
|
textIconRules: ReferralTextIconRule[],
|
|
44
43
|
AdsBrowserExtensionMessageType: AdsBrowserExtensionMessageTypeI,
|
|
45
|
-
provider: '
|
|
44
|
+
provider: 'Temple',
|
|
46
45
|
redirectUrl?: string
|
|
47
46
|
) {
|
|
48
47
|
const { aElem, urlDomain, referralUrl, imageUrl } = item;
|
package/src/referrals/index.ts
CHANGED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import browser from 'webextension-polyfill';
|
|
2
|
-
|
|
3
|
-
import { IS_DEV } from 'src/utils';
|
|
4
|
-
|
|
5
|
-
import { AdsBrowserExtensionMessageTypeI, getItemsToReplace, processAnchorElement } from './common';
|
|
6
|
-
import type { TekeadsAffiliateResponse } from './takeads';
|
|
7
|
-
import { ReferralTextIconRule } from './utils';
|
|
8
|
-
|
|
9
|
-
export async function processTakeAdsAnchors(
|
|
10
|
-
supportedDomains: Set<string>,
|
|
11
|
-
textIconRules: ReferralTextIconRule[],
|
|
12
|
-
AdsBrowserExtensionMessageType: AdsBrowserExtensionMessageTypeI,
|
|
13
|
-
redirectUrl?: string
|
|
14
|
-
) {
|
|
15
|
-
const items = getItemsToReplace(supportedDomains);
|
|
16
|
-
|
|
17
|
-
if (!items.length) return void (IS_DEV && console.info('Nothing to replace'));
|
|
18
|
-
|
|
19
|
-
const links = items.map(l => l.iri);
|
|
20
|
-
|
|
21
|
-
// Not requesting directly in content script because of CORS.
|
|
22
|
-
const takeadsItems: TekeadsAffiliateResponse = await browser.runtime.sendMessage({
|
|
23
|
-
type: AdsBrowserExtensionMessageType.FetchTakeAdsReferrals,
|
|
24
|
-
links
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
if (!takeadsItems.data.length) return void (IS_DEV && console.info('No referrals received'));
|
|
28
|
-
|
|
29
|
-
IS_DEV && console.info('Replacing', takeadsItems.data.length, 'referralas');
|
|
30
|
-
|
|
31
|
-
for (const { iri, aElem, urlDomain } of items) {
|
|
32
|
-
const data = takeadsItems.data.find(item => item.iri === iri);
|
|
33
|
-
const referralUrl = data?.trackingLink;
|
|
34
|
-
|
|
35
|
-
if (!referralUrl) {
|
|
36
|
-
IS_DEV && console.warn('No affiliate link for', aElem);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const imageUrl = data.imageUrl;
|
|
41
|
-
|
|
42
|
-
processAnchorElement(
|
|
43
|
-
{ iri, aElem, urlDomain, referralUrl, imageUrl },
|
|
44
|
-
textIconRules,
|
|
45
|
-
AdsBrowserExtensionMessageType,
|
|
46
|
-
'TakeAds',
|
|
47
|
-
redirectUrl
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return;
|
|
52
|
-
}
|
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
|
-
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: true
|
|
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
|
-
}
|