@surfside/ads-core 2.0.16 → 2.0.18
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/lib/cjs/Api.js +11 -7
- package/lib/cjs/Api.js.map +1 -1
- package/lib/cjs/BuildInfo.js +1 -1
- package/lib/cjs/BuildInfo.js.map +1 -1
- package/lib/cjs/helpers/Functions.js +8 -0
- package/lib/cjs/helpers/Functions.js.map +1 -0
- package/lib/cjs/helpers/Handlebars.js +37 -4
- package/lib/cjs/helpers/Handlebars.js.map +1 -1
- package/lib/cjs/helpers/RequestBuilder.js +1 -1
- package/lib/cjs/helpers/RequestBuilder.js.map +1 -1
- package/lib/cjs/helpers/index.js +1 -0
- package/lib/cjs/helpers/index.js.map +1 -1
- package/lib/cjs/helpers/response/Carousel.js +50 -37
- package/lib/cjs/helpers/response/Carousel.js.map +1 -1
- package/lib/cjs/helpers/response/ProductCard.js +56 -6
- package/lib/cjs/helpers/response/ProductCard.js.map +1 -1
- package/lib/cjs/models/retail/Configuration.js +10 -0
- package/lib/cjs/models/retail/Configuration.js.map +1 -1
- package/lib/cjs/models/rtb/NativeRequest.js +6 -1
- package/lib/cjs/models/rtb/NativeRequest.js.map +1 -1
- package/lib/cjs/services/Bidder.js.map +1 -1
- package/lib/cjs/services/BotFiltering.js +9 -9
- package/lib/cjs/services/BotFiltering.js.map +1 -1
- package/lib/cjs/services/Configuration.js +4 -4
- package/lib/cjs/services/Configuration.js.map +1 -1
- package/lib/cjs/services/Memo.js +0 -5
- package/lib/cjs/services/Memo.js.map +1 -1
- package/lib/cjs/services/Product.js +28 -6
- package/lib/cjs/services/Product.js.map +1 -1
- package/lib/cjs/services/Recommender.js +11 -10
- package/lib/cjs/services/Recommender.js.map +1 -1
- package/lib/cjs/services/Tracker.js +71 -0
- package/lib/cjs/services/Tracker.js.map +1 -0
- package/lib/cjs/services/index.js +1 -0
- package/lib/cjs/services/index.js.map +1 -1
- package/lib/esm/Api.js +11 -7
- package/lib/esm/Api.js.map +1 -1
- package/lib/esm/BuildInfo.js +1 -1
- package/lib/esm/BuildInfo.js.map +1 -1
- package/lib/esm/helpers/Functions.js +3 -0
- package/lib/esm/helpers/Functions.js.map +1 -0
- package/lib/esm/helpers/Handlebars.js +33 -3
- package/lib/esm/helpers/Handlebars.js.map +1 -1
- package/lib/esm/helpers/RequestBuilder.js +1 -1
- package/lib/esm/helpers/RequestBuilder.js.map +1 -1
- package/lib/esm/helpers/index.js +1 -0
- package/lib/esm/helpers/index.js.map +1 -1
- package/lib/esm/helpers/response/Carousel.js +50 -37
- package/lib/esm/helpers/response/Carousel.js.map +1 -1
- package/lib/esm/helpers/response/ProductCard.js +55 -6
- package/lib/esm/helpers/response/ProductCard.js.map +1 -1
- package/lib/esm/models/retail/Configuration.js +8 -1
- package/lib/esm/models/retail/Configuration.js.map +1 -1
- package/lib/esm/models/rtb/NativeRequest.js +6 -1
- package/lib/esm/models/rtb/NativeRequest.js.map +1 -1
- package/lib/esm/services/Bidder.js.map +1 -1
- package/lib/esm/services/BotFiltering.js +9 -9
- package/lib/esm/services/BotFiltering.js.map +1 -1
- package/lib/esm/services/Configuration.js +4 -4
- package/lib/esm/services/Configuration.js.map +1 -1
- package/lib/esm/services/Memo.js +0 -5
- package/lib/esm/services/Memo.js.map +1 -1
- package/lib/esm/services/Product.js +26 -5
- package/lib/esm/services/Product.js.map +1 -1
- package/lib/esm/services/Recommender.js +11 -10
- package/lib/esm/services/Recommender.js.map +1 -1
- package/lib/esm/services/Tracker.js +67 -0
- package/lib/esm/services/Tracker.js.map +1 -0
- package/lib/esm/services/index.js +1 -0
- package/lib/esm/services/index.js.map +1 -1
- package/lib/types/Api.d.ts +8 -1
- package/lib/types/helpers/Functions.d.ts +2 -0
- package/lib/types/helpers/Handlebars.d.ts +18 -0
- package/lib/types/helpers/index.d.ts +1 -0
- package/lib/types/helpers/response/Carousel.d.ts +5 -4
- package/lib/types/helpers/response/ProductCard.d.ts +20 -7
- package/lib/types/models/retail/Configuration.d.ts +11 -1
- package/lib/types/models/rtb/BidResponse.d.ts +4 -1
- package/lib/types/models/rtb/NativeRequest.d.ts +2 -0
- package/lib/types/services/BotFiltering.d.ts +1 -1
- package/lib/types/services/Product.d.ts +8 -4
- package/lib/types/services/Recommender.d.ts +5 -5
- package/lib/types/services/Tracker.d.ts +25 -0
- package/lib/types/services/index.d.ts +1 -0
- package/package.json +1 -1
package/lib/esm/services/Memo.js
CHANGED
|
@@ -14,19 +14,14 @@ export const MemoizeAsync = (fn) => {
|
|
|
14
14
|
const cache = new Map();
|
|
15
15
|
return (...args) => {
|
|
16
16
|
const key = JSON.stringify(args);
|
|
17
|
-
console.log('cache key', cache, key);
|
|
18
17
|
if (cache.has(key)) {
|
|
19
|
-
console.log('cache found', key);
|
|
20
18
|
return cache.get(key);
|
|
21
19
|
}
|
|
22
|
-
console.log('cache not found', cache, key);
|
|
23
20
|
const promise = fn(...args);
|
|
24
21
|
cache.set(key, promise);
|
|
25
22
|
promise.catch(() => {
|
|
26
|
-
console.log('cache promise failed');
|
|
27
23
|
const record = cache.get(key);
|
|
28
24
|
if (promise === record) {
|
|
29
|
-
console.log('cache promise deleted');
|
|
30
25
|
cache.delete(key);
|
|
31
26
|
}
|
|
32
27
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Memo.js","sourceRoot":"src/","sources":["services/Memo.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CAA4C,EAA+B,EAAE,EAAE;IAClG,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;IACzC,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACtB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAY,CAAC;QACrC,CAAC;QACD,MAA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AAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAqB,CAAC;QAC9C,CAAC;QACD,MAAM,OAAO,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAC5B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAExB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE;YACf,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC9B,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;gBACrB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACtB,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { Ctx } from './Logger';
|
|
2
2
|
import { Err, Ok } from './Result';
|
|
3
|
-
|
|
3
|
+
const filterCategories = (productData, categories, canonicalMap) => {
|
|
4
|
+
if (categories !== undefined && categories.length > 0) {
|
|
5
|
+
return Ok(productData
|
|
6
|
+
.filter(p => p.ext?.category !== undefined)
|
|
7
|
+
.filter(p => canonicalMap[p.ext.category] !== undefined)
|
|
8
|
+
.filter(p => categories.includes(canonicalMap[p.ext.category])));
|
|
9
|
+
}
|
|
10
|
+
return Ok(productData);
|
|
11
|
+
};
|
|
12
|
+
export const GetAllSponsoredProducts = async (logger, url, config, accountId, locationId, nativeId, categories) => {
|
|
4
13
|
const log = Ctx(logger)?.with('GetSponsoredProduct').with(accountId).with(locationId).with(nativeId);
|
|
5
14
|
log?.info('Getting sponsored product');
|
|
15
|
+
log?.debug('Getting sponsored product with categories', categories);
|
|
6
16
|
try {
|
|
7
17
|
const rawResponse = await fetch(`${url}/native/${accountId}/${locationId}/${nativeId}.json`);
|
|
8
18
|
if (rawResponse.status !== 200) {
|
|
@@ -18,7 +28,9 @@ export const GetAllSponsoredProducts = async (logger, url, config, accountId, lo
|
|
|
18
28
|
log?.debug('Brand level creative');
|
|
19
29
|
const productArr = products;
|
|
20
30
|
const mapResponseToProductInfoLogged = mapResponseToProductInfo.bind(undefined, log, config);
|
|
21
|
-
|
|
31
|
+
const productData = productArr.map(mapResponseToProductInfoLogged);
|
|
32
|
+
const { canonicalMap } = config.category;
|
|
33
|
+
return filterCategories(productData, categories, canonicalMap);
|
|
22
34
|
}
|
|
23
35
|
else {
|
|
24
36
|
log?.debug('Individual product creative');
|
|
@@ -31,9 +43,10 @@ export const GetAllSponsoredProducts = async (logger, url, config, accountId, lo
|
|
|
31
43
|
return Err(err);
|
|
32
44
|
}
|
|
33
45
|
};
|
|
34
|
-
export const GetAllSponsoredBrandProducts = async (logger, url, config, accountId, locationId, nativeId) => {
|
|
46
|
+
export const GetAllSponsoredBrandProducts = async (logger, url, config, accountId, locationId, nativeId, categories) => {
|
|
35
47
|
const log = Ctx(logger)?.with('GetSponsoredBrandProducts').with(accountId).with(locationId).with(nativeId);
|
|
36
48
|
log?.info('Getting sponsored brand-level product responses');
|
|
49
|
+
log?.debug('Getting sponsored brand-level product responses with categories', categories);
|
|
37
50
|
try {
|
|
38
51
|
const rawResponse = await fetch(`${url}/native/v2/brand/${accountId}/${locationId}/${nativeId}.json`);
|
|
39
52
|
if (rawResponse.status !== 200) {
|
|
@@ -44,7 +57,9 @@ export const GetAllSponsoredBrandProducts = async (logger, url, config, accountI
|
|
|
44
57
|
return Err(new MalformedBrandResponseError(nativeId));
|
|
45
58
|
}
|
|
46
59
|
const mapResponseToProductInfoLogged = mapResponseToProductInfo.bind(undefined, log, config);
|
|
47
|
-
|
|
60
|
+
const productData = products.map(mapResponseToProductInfoLogged);
|
|
61
|
+
const { canonicalMap } = config.category;
|
|
62
|
+
return filterCategories(productData, categories, canonicalMap);
|
|
48
63
|
}
|
|
49
64
|
catch (err) {
|
|
50
65
|
log?.error(err);
|
|
@@ -63,7 +78,6 @@ export const GetRecommendedProduct = async (logger, url, config, accountId, loca
|
|
|
63
78
|
const rawProduct = await rawResponse.json();
|
|
64
79
|
log?.debug('response', rawProduct);
|
|
65
80
|
const productInfo = mapResponseToProductInfo(log, config, rawProduct);
|
|
66
|
-
log?.debug('mapped', productInfo);
|
|
67
81
|
return Ok(productInfo);
|
|
68
82
|
}
|
|
69
83
|
catch (err) {
|
|
@@ -121,4 +135,11 @@ export class MalformedBrandResponseError extends Error {
|
|
|
121
135
|
this.nativeId = nativeId;
|
|
122
136
|
}
|
|
123
137
|
}
|
|
138
|
+
export class NoProductError extends Error {
|
|
139
|
+
productId;
|
|
140
|
+
constructor(productId) {
|
|
141
|
+
super('Product ID did not exist in product feed: ' + productId);
|
|
142
|
+
this.productId = productId;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
124
145
|
//# sourceMappingURL=Product.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Product.js","sourceRoot":"src/","sources":["services/Product.ts"],"names":[],"mappings":"AACA,OAAO,EACH,GAAG,EAEN,MAAM,UAAU,CAAC;AAClB,OAAO,EACH,GAAG,EACH,EAAE,EAGL,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"Product.js","sourceRoot":"src/","sources":["services/Product.ts"],"names":[],"mappings":"AACA,OAAO,EACH,GAAG,EAEN,MAAM,UAAU,CAAC;AAClB,OAAO,EACH,GAAG,EACH,EAAE,EAGL,MAAM,UAAU,CAAC;AASlB,MAAM,gBAAgB,GAAG,CACrB,WAAkC,EAClC,UAAgC,EAChC,YAAoC,EACtC,EAAE;IACA,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,OAAO,EAAE,CAAC,WAAW;aAChB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,KAAK,SAAS,CAAE;aAC3C,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,YA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AAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,OAAO,aAAc,SAAQ,KAAK;IACjB;IAAnB,YAAmB,QAAgB;QAC/B,KAAK,CAAC,2CAA2C,GAAG,QAAQ,CAAC,CAAC;QAD/C,aAAQ,GAAR,QAAQ,CAAQ;IAEnC,CAAC;CACJ;AAED,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC/B;IAAnB,YAAmB,QAAgB;QAC/B,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAD9B,aAAQ,GAAR,QAAQ,CAAQ;IAEnC,CAAC;CACJ;AACD,MAAM,OAAO,cAAe,SAAQ,KAAK;IAClB;IAAnB,YAAmB,SAAiB;QAChC,KAAK,CAAC,4CAA4C,GAAG,SAAS,CAAC,CAAC;QADjD,cAAS,GAAT,SAAS,CAAQ;IAEpC,CAAC;CACJ"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Ctx } from './Logger';
|
|
2
2
|
import { Err, Ok } from './Result';
|
|
3
|
-
export async function* GenerateTopProducts(logger, productFeed, url, accountId, siteId, locationId) {
|
|
3
|
+
export async function* GenerateTopProducts(logger, productFeed, url, accountId, siteId, locationId, category) {
|
|
4
4
|
const log = Ctx(logger)?.with('GenerateTopProducts').with(accountId).with(siteId).with(locationId);
|
|
5
5
|
log?.info('Generating top products');
|
|
6
|
-
yield* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, undefined, 'top-products');
|
|
6
|
+
yield* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, undefined, 'top-products', category);
|
|
7
7
|
}
|
|
8
|
-
export async function* GenerateForYou(logger, productFeed, url, accountId, siteId, locationId, userId) {
|
|
8
|
+
export async function* GenerateForYou(logger, productFeed, url, accountId, siteId, locationId, userId, category) {
|
|
9
9
|
const log = Ctx(logger)?.with('GenerateForYou').with(accountId).with(siteId).with(locationId).with(userId);
|
|
10
10
|
log?.info('Generating for you');
|
|
11
|
-
yield* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, userId, 'for-you');
|
|
11
|
+
yield* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, userId, 'for-you', category);
|
|
12
12
|
}
|
|
13
|
-
export async function* GeneratePreviousPurchases(logger, productFeed, url, accountId, siteId, locationId, userId) {
|
|
13
|
+
export async function* GeneratePreviousPurchases(logger, productFeed, url, accountId, siteId, locationId, userId, category) {
|
|
14
14
|
const log = Ctx(logger)
|
|
15
15
|
?.with('GeneratePreviousPurchases')
|
|
16
16
|
.with(accountId)
|
|
@@ -18,12 +18,12 @@ export async function* GeneratePreviousPurchases(logger, productFeed, url, accou
|
|
|
18
18
|
.with(locationId)
|
|
19
19
|
.with(userId);
|
|
20
20
|
log?.info('Generating previous purchases');
|
|
21
|
-
yield* generateProductRecommendation(log, productFeed, url, accountId, siteId, locationId, userId, 'buy-again');
|
|
21
|
+
yield* generateProductRecommendation(log, productFeed, url, accountId, siteId, locationId, userId, 'buy-again', category);
|
|
22
22
|
}
|
|
23
|
-
async function* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, userId, type) {
|
|
23
|
+
async function* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, userId, type, category) {
|
|
24
24
|
const log = Ctx(logger)?.with('generateProductRecommendation');
|
|
25
25
|
log?.debug('Generating product recommendation');
|
|
26
|
-
const recommendations = await fetchRecommendations(log, url, accountId, siteId, locationId, userId, type);
|
|
26
|
+
const recommendations = await fetchRecommendations(log, url, accountId, siteId, locationId, userId, type, category);
|
|
27
27
|
if (!recommendations.ok) {
|
|
28
28
|
log?.error(recommendations.error);
|
|
29
29
|
return;
|
|
@@ -31,10 +31,11 @@ async function* generateProductRecommendation(logger, productFeed, url, accountI
|
|
|
31
31
|
yield* generateProduct(log, productFeed, accountId, locationId, recommendations.value);
|
|
32
32
|
log?.debug('out of recommendations');
|
|
33
33
|
}
|
|
34
|
-
const fetchRecommendations = async (logger, url, accountId, siteId, locationId, userId, type) => {
|
|
34
|
+
const fetchRecommendations = async (logger, url, accountId, siteId, locationId, userId, type, category) => {
|
|
35
35
|
const log = Ctx(logger)?.with('fetchRecommendations');
|
|
36
36
|
log?.debug('Fetching recommendations');
|
|
37
|
-
const key = `accountId=${accountId}&siteId=${siteId}&locationId=${locationId}&userId=${userId ?? 'null'}
|
|
37
|
+
const key = `accountId=${accountId}&siteId=${siteId}&locationId=${locationId}&userId=${userId ?? 'null'}` +
|
|
38
|
+
(category !== undefined ? `&category=${category}` : '');
|
|
38
39
|
try {
|
|
39
40
|
const results = await fetch(`${url}/r/${type}?${key}&limit=100`);
|
|
40
41
|
if (results.status !== 200) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Recommender.js","sourceRoot":"src/","sources":["services/Recommender.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAgB,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,GAAG,EAAE,EAAE,EAAoB,MAAM,UAAU,CAAC;AAKrD,MAAM,CAAC,KAAK,SAAU,CAAC,CAAA,mBAAmB,CACtC,MAA2B,EAC3B,WAAiD,EACjD,GAAW,EACX,SAAiB,EACjB,MAAc,EACd,UAAkB;
|
|
1
|
+
{"version":3,"file":"Recommender.js","sourceRoot":"src/","sources":["services/Recommender.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAgB,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,GAAG,EAAE,EAAE,EAAoB,MAAM,UAAU,CAAC;AAKrD,MAAM,CAAC,KAAK,SAAU,CAAC,CAAA,mBAAmB,CACtC,MAA2B,EAC3B,WAAiD,EACjD,GAAW,EACX,SAAiB,EACjB,MAAc,EACd,UAAkB,EAClB,QAAiB;IAEjB,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CA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W,CAAC,MAAM,CAAC,CAAC;YAC1C,GAAG,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACvC,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;gBACb,MAAM,OAAO,CAAC,KAAK,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACJ,GAAG,EAAE,IAAI,CAAC,oCAAoC,EAAE,MAAM,CAAC,CAAC;YAC5D,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,GAAG,EAAE,IAAI,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC;IAED,GAAG,EAAE,IAAI,CAAC,2BAA2B,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC7C;QACI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC1C,CAAC;CACJ"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Ctx } from './Logger';
|
|
2
|
+
export const InitTrackerService = (logger, accountId, siteId, locationId, channelId, windowInfo, userAgent, geo, device, userId, host) => {
|
|
3
|
+
const initTracker = (path, eventName) => (product) => async (context) => {
|
|
4
|
+
const log = Ctx(logger)?.with('recommended tracker').with(eventName);
|
|
5
|
+
try {
|
|
6
|
+
log?.info('Calling event tracker');
|
|
7
|
+
const url = new URL(`${windowInfo.protocol}//${host}/${path}`);
|
|
8
|
+
url.searchParams.set('location_id', locationId);
|
|
9
|
+
url.searchParams.set('item_id', product.id ?? 'undefined');
|
|
10
|
+
url.searchParams.set('next_type', context?.nextType ?? 'page');
|
|
11
|
+
url.searchParams.set('recommendation_model', context?.recommend ?? 'top-products');
|
|
12
|
+
url.searchParams.set('recommendation_page', String(context?.page ?? 1));
|
|
13
|
+
url.searchParams.set('recommendation_position_absolute', String(context?.positionAbsolute ?? 1));
|
|
14
|
+
url.searchParams.set('recommendation_position_relative', String(context?.positionRelative ?? 1));
|
|
15
|
+
url.searchParams.set('recommendation_value', String(context?.recommendationValue ?? 1));
|
|
16
|
+
url.searchParams.set('strategy', context?.strategy ?? 'hybrid');
|
|
17
|
+
url.searchParams.set('zone_id', context?.zoneId ?? 'undefined');
|
|
18
|
+
url.searchParams.set('account_id', accountId);
|
|
19
|
+
url.searchParams.set('event_name', eventName);
|
|
20
|
+
if (geo !== undefined) {
|
|
21
|
+
url.searchParams.set('geo_city', geo.city);
|
|
22
|
+
url.searchParams.set('geo_country', geo.country);
|
|
23
|
+
url.searchParams.set('geo_metro', geo.city);
|
|
24
|
+
url.searchParams.set('geo_region', geo.region);
|
|
25
|
+
url.searchParams.set('geo_utcoffset', String(geo.utcoffset));
|
|
26
|
+
url.searchParams.set('geo_zip', geo.zip);
|
|
27
|
+
url.searchParams.set('ip', geo.ip);
|
|
28
|
+
url.searchParams.set('lat', String(geo.coords.latitude));
|
|
29
|
+
url.searchParams.set('lon', String(geo.coords.longitude));
|
|
30
|
+
}
|
|
31
|
+
url.searchParams.set('isp', 'undefined');
|
|
32
|
+
if (device !== undefined) {
|
|
33
|
+
url.searchParams.set('device_type', String(device.devicetype));
|
|
34
|
+
url.searchParams.set('make', device.make ?? 'undefined');
|
|
35
|
+
url.searchParams.set('model', device.model ?? 'undefined');
|
|
36
|
+
url.searchParams.set('os', device.os ?? 'undefined');
|
|
37
|
+
url.searchParams.set('osv', device.osv ?? 'undefined');
|
|
38
|
+
}
|
|
39
|
+
url.searchParams.set('pub_bundle', windowInfo.host);
|
|
40
|
+
url.searchParams.set('pub_channel_id', channelId);
|
|
41
|
+
url.searchParams.set('pub_domain', windowInfo.host);
|
|
42
|
+
url.searchParams.set('pub_id', siteId);
|
|
43
|
+
url.searchParams.set('pub_name', windowInfo.host);
|
|
44
|
+
url.searchParams.set('pub_site_id', siteId);
|
|
45
|
+
url.searchParams.set('pub_store_id', locationId);
|
|
46
|
+
url.searchParams.set('pub_zone', context?.zoneId ?? 'undefined');
|
|
47
|
+
url.searchParams.set('ua', userAgent);
|
|
48
|
+
if (userId !== undefined) {
|
|
49
|
+
url.searchParams.set('user_id', userId ?? 'undefined');
|
|
50
|
+
}
|
|
51
|
+
const finalUrl = url.toString();
|
|
52
|
+
log?.debug(finalUrl);
|
|
53
|
+
await fetch(url);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
log?.error('Failed to call tracker. Got', e);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
recommended: {
|
|
61
|
+
getClickTracker: initTracker('rec/clk', 'click'),
|
|
62
|
+
getImpressionTracker: initTracker('rec/imp', 'imp'),
|
|
63
|
+
getAddToCartTracker: initTracker('rec/atc', 'atc')
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=Tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tracker.js","sourceRoot":"src/","sources":["services/Tracker.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,GAAG,EAAgB,MAAM,UAAU,CAAC;AAwC7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,MAA2B,EAC3B,SAAiB,EACjB,MAAc,EACd,UAAkB,EAClB,SAAiB,EACjB,UAAyC,EACzC,SAAiB,EACjB,GAA4B,EAC5B,MAA2B,EAC3B,MAA0B,EAC1B,IAAY,EACU,EAAE;IACxB,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,SAAiB,EAAE,EAAE,CACpD,CAAC,OAA4B,EAAE,EAAE,CAC7B,KAAK,EAAE,OAA0B,EAAE,EAAE;QACjC,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAErE,IAAI,CAAC;YACD,GAAG,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;YACnC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,UAAU,CAAC,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AAC,QAAQ,CAAC,CAAC;YAErB,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,GAAG,EAAE,KAAK,CAAC,6BAA6B,EAAE,CAAC,CAAC,CAAC;QACjD,CAAC;IACL,CAAC,CAAC;IACV,OAAO;QACH,WAAW,EAAE;YACT,eAAe,EAAE,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC;YAChD,oBAAoB,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC;YACnD,mBAAmB,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC;SACrD;KACJ,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["services/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["services/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
package/lib/types/Api.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { type BuildHybridCarouselFn, type BuildHybridCarouselFromInitialBidFn, t
|
|
|
6
6
|
import { type EvaluateClickthroughTemplateFn, type EvaluateProductCardTemplateFn } from './services/Template';
|
|
7
7
|
import { type BuildDynamicZoneRequestFn, type GetDynamicZoneFn } from './services/Dynamic';
|
|
8
8
|
import { type GenerateCategoriesFn } from './services/Category';
|
|
9
|
+
import { type InitTrackerServiceFn, type IProductTrackerService } from './services/Tracker';
|
|
9
10
|
export declare const PROD_BIDDER = "//bid.surfside.io/rtb/bids/surfside";
|
|
10
11
|
export declare const PROD_CONFIGURATION_SERVICE = "//r.surfside.io";
|
|
11
12
|
export declare const PROD_SPONSORED_PRODUCT_FEED = "//creative.surfside.io";
|
|
@@ -48,6 +49,11 @@ export interface ISurfsideApi {
|
|
|
48
49
|
* Generates categories for the site
|
|
49
50
|
*/
|
|
50
51
|
generateCategories: GenerateCategoriesFn;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a set of trackers from a product input. Builds a URL with all relevant info from the trackers
|
|
54
|
+
* and returns functions to call when the relevant events fire
|
|
55
|
+
*/
|
|
56
|
+
trackers: IProductTrackerService;
|
|
51
57
|
/**
|
|
52
58
|
* A handlebars runtime instance, for evaluating templates
|
|
53
59
|
*/
|
|
@@ -145,6 +151,7 @@ export declare function InitSurfAdsCoreInternal(internalApiDto: {
|
|
|
145
151
|
generateSponsoredProductCardResponse: GenerateSponsoredProductCardResponseFn;
|
|
146
152
|
evaluateProductCardTemplate: EvaluateProductCardTemplateFn;
|
|
147
153
|
evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn;
|
|
154
|
+
initTrackerService: InitTrackerServiceFn;
|
|
148
155
|
handlebars: typeof Handlebars;
|
|
149
156
|
windowInfo: INativeTemplateDelegateWindow;
|
|
150
157
|
screenInfo: IScreen;
|
|
@@ -158,7 +165,7 @@ export declare function InitSurfAdsCoreInternal(internalApiDto: {
|
|
|
158
165
|
locationId: string;
|
|
159
166
|
userId: string | undefined;
|
|
160
167
|
}): AsyncResult<ISurfsideApi>;
|
|
161
|
-
export declare const InitSurfAdsCoreServices: (logger: ILogger | undefined, bidderServiceUrl: string, configurationServiceUrl: string, productFeedUrl: string, recommendedProductFeedUrl: string, recommenderServiceUrl: string, dynamicZoneServiceUrl: string, windowInfo: INativeTemplateDelegateWindow, screenInfo: IScreen, navigator: INavigator, mobile: boolean, ip: string | undefined, geoProviderToken: string | undefined, accountId: string, siteId: string, channelId: string, locationId: string, userId: string | undefined) => AsyncResult<ISurfsideApi>;
|
|
168
|
+
export declare const InitSurfAdsCoreServices: (logger: ILogger | undefined, bidderServiceUrl: string, configurationServiceUrl: string, productFeedUrl: string, recommendedProductFeedUrl: string, recommenderServiceUrl: string, dynamicZoneServiceUrl: string, windowInfo: INativeTemplateDelegateWindow, screenInfo: IScreen, navigator: INavigator, mobile: boolean, ip: string | undefined, geoProviderToken: string | undefined, accountId: string, siteId: string, channelId: string, locationId: string, userId: string | undefined, initTrackerService?: InitTrackerServiceFn) => AsyncResult<ISurfsideApi>;
|
|
162
169
|
export declare const InitSurfAdsCoreSSR: (windowInfo: INativeTemplateDelegateWindow, screen: IScreen, navigator: INavigator, mobile: boolean, ip: string, geoProviderToken: string, accountId: string, siteId: string, channelId: string, locationId: string, userId: string | undefined, logger?: ILogger) => AsyncResult<ISurfsideApi>;
|
|
163
170
|
export declare const InitSurfAdsCore: (channelId: string, accountId: string, siteId: string, locationId: string, userId: string | undefined, logger?: ILogger) => AsyncResult<ISurfsideApi>;
|
|
164
171
|
export declare class MissingConfigurationError extends Error {
|
|
@@ -37,6 +37,11 @@ export declare function slug(name: string, options: {
|
|
|
37
37
|
* @returns A lowercase version of the passed string
|
|
38
38
|
*/
|
|
39
39
|
export declare function lower(name: string): string;
|
|
40
|
+
export declare function split(str: string, options: {
|
|
41
|
+
hash: {
|
|
42
|
+
by?: string;
|
|
43
|
+
};
|
|
44
|
+
}): string[];
|
|
40
45
|
export declare function upper(name: string): string;
|
|
41
46
|
/**
|
|
42
47
|
* Returns the path component of the URL at the specified position, 1-indexed
|
|
@@ -50,6 +55,18 @@ export declare const path: (pathname: string) => (position: number, options: {
|
|
|
50
55
|
url?: string;
|
|
51
56
|
};
|
|
52
57
|
}) => string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the domain. By default strips out subdomains. Pass a number to increase the depth of the domain. For example
|
|
60
|
+
* if the url is http://shop.mysite.co/ then {{domain}} returns `mysite.co`. `{{domain 3}}` will return
|
|
61
|
+
* `shop.mysite.co` and `{{domain 1}}` returns `co`.
|
|
62
|
+
* @returns The domain
|
|
63
|
+
*/
|
|
64
|
+
export declare const domain: (hostname: string) => (options?: {
|
|
65
|
+
hash: {
|
|
66
|
+
url?: string;
|
|
67
|
+
depth?: number;
|
|
68
|
+
};
|
|
69
|
+
}) => string | undefined;
|
|
53
70
|
export declare function money(value: number | string, options: {
|
|
54
71
|
hash: {
|
|
55
72
|
cents?: boolean;
|
|
@@ -184,5 +201,6 @@ export declare function global(...args: any[]): any;
|
|
|
184
201
|
* @returns An array of the passed arguments
|
|
185
202
|
*/
|
|
186
203
|
export declare function array(...args: any[]): any[];
|
|
204
|
+
export declare function brand(options: Handlebars.HelperOptions): string | undefined;
|
|
187
205
|
export type HandlebarsHelpers = Record<string, HelperDelegate>;
|
|
188
206
|
export declare const GetHelpers: (windowInfo: INativeTemplateDelegateWindow) => HandlebarsHelpers;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IBid, type IBidRequest } from '../../models';
|
|
2
2
|
import { type ILogger, type NonPersonalRecommenderFn, type PersonalRecommenderFn, type RequestBidsFn, type Result } from '../../services';
|
|
3
3
|
import { type EvaluateClickthroughTemplateFn } from '../../services/Template';
|
|
4
|
+
import { type IProductTrackerService } from '../../services/Tracker';
|
|
4
5
|
import type { GenerateSponsoredProductCardResponseFn, IBuiltProductCardResponse } from './ProductCard';
|
|
5
6
|
export type BuildSponsoredCarouselFn = (request: IBidRequest) => Result<IBuiltCarousel>;
|
|
6
7
|
export type BuildSponsoredCarouselFromInitialBidFn = (request: IBidRequest, initialBid: IBid) => Result<IBuiltCarousel>;
|
|
@@ -42,9 +43,9 @@ export interface IPastPurchasesProductRecommender {
|
|
|
42
43
|
export type ProductRecommender = ITopProductRecommender | IForYouProductRecommender | IPastPurchasesProductRecommender;
|
|
43
44
|
export declare const BuildSponsoredCarousel: (logger: ILogger | undefined, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, request: IBidRequest) => Result<IBuiltCarousel>;
|
|
44
45
|
export declare const BuildSponsoredCarouselFromInitialBid: (logger: ILogger | undefined, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, request: IBidRequest, initialBid: IBid) => Result<IBuiltCarousel>;
|
|
45
|
-
export declare const BuildRecommendedCarousel: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, recommenderType: PublicRecommenderType) => Result<IBuiltCarousel>;
|
|
46
|
-
export declare const BuildHybridCarousel: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, recommenderType: PublicRecommenderType, request: IBidRequest) => Result<IBuiltCarousel>;
|
|
47
|
-
export declare const BuildHybridCarouselFromInitialBid: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, recommenderType: PublicRecommenderType, request: IBidRequest, initialBid: IBid) => Result<IBuiltCarousel>;
|
|
46
|
+
export declare const BuildRecommendedCarousel: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, trackers: IProductTrackerService, recommenderType: PublicRecommenderType) => Result<IBuiltCarousel>;
|
|
47
|
+
export declare const BuildHybridCarousel: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, trackers: IProductTrackerService, recommenderType: PublicRecommenderType, request: IBidRequest) => Result<IBuiltCarousel>;
|
|
48
|
+
export declare const BuildHybridCarouselFromInitialBid: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, trackers: IProductTrackerService, recommenderType: PublicRecommenderType, request: IBidRequest, initialBid: IBid) => Result<IBuiltCarousel>;
|
|
48
49
|
export declare class InvalidRecommenderTypeError extends Error {
|
|
49
50
|
type: string;
|
|
50
51
|
constructor(type: string);
|
|
@@ -1,22 +1,34 @@
|
|
|
1
|
-
import { type IBid, type ICompiledPublisherConfiguration, type INativeResponse, type INativeTemplateDelegateWindow, type IProductInformation } from '../../models';
|
|
1
|
+
import { type IBid, type ICompiledPublisherConfiguration, type INativeResponse, type INativeTemplateDelegateWindow, type IProductInformation, type ProductCallbackExtras } from '../../models';
|
|
2
2
|
import { type AsyncResult, type GetAllSponsoredProductFromNativeIdFn, type ILogger } from '../../services';
|
|
3
|
+
import { type ProductTrackerCallback } from '../../services/Tracker';
|
|
3
4
|
import { type IBuiltResponse } from './BuiltResponse';
|
|
4
5
|
export type BuildAllSponsoredProductCardResponsesFn = (bids: IBid[]) => AsyncResult<IBuiltProductCardBidResponse[]>;
|
|
5
6
|
export type GenerateSponsoredProductCardResponseFn = (bids: IBid[]) => AsyncGenerator<IBuiltProductCardBidResponse>;
|
|
6
|
-
export interface
|
|
7
|
-
type:
|
|
7
|
+
export interface IPixelTracker {
|
|
8
|
+
type: 'pixel';
|
|
8
9
|
url: string;
|
|
9
10
|
}
|
|
10
|
-
export interface
|
|
11
|
-
type:
|
|
11
|
+
export interface IScriptTracker {
|
|
12
|
+
type: 'script';
|
|
13
|
+
src: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ICallbackTracker {
|
|
16
|
+
type: 'callback';
|
|
17
|
+
callback: ProductTrackerCallback;
|
|
12
18
|
}
|
|
13
|
-
export
|
|
14
|
-
|
|
19
|
+
export type TrackerObject = IPixelTracker | IScriptTracker | ICallbackTracker;
|
|
20
|
+
export interface ITracker {
|
|
21
|
+
type: number;
|
|
22
|
+
url: string;
|
|
15
23
|
}
|
|
16
24
|
export interface ITrackerObject {
|
|
25
|
+
/** @deprecated */
|
|
17
26
|
win: string;
|
|
27
|
+
/** @deprecated */
|
|
18
28
|
imp: string[];
|
|
29
|
+
/** @deprecated */
|
|
19
30
|
others: ITracker[];
|
|
31
|
+
namedTrackers: Record<string, TrackerObject[]>;
|
|
20
32
|
}
|
|
21
33
|
export type IBuiltProductCardBidResponse = IBuiltResponse & IBuiltProductCardResponse & {
|
|
22
34
|
native: INativeResponse;
|
|
@@ -47,3 +59,4 @@ export declare class MissingProductIdError extends Error {
|
|
|
47
59
|
readonly native: INativeResponse;
|
|
48
60
|
constructor(bid: IBid, native: INativeResponse);
|
|
49
61
|
}
|
|
62
|
+
export declare const NamedTrackersToCallbacks: (namedTrackers: Record<string, TrackerObject[]> | undefined) => ProductCallbackExtras;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { IDynamicZone, IProductInformation } from '../../models';
|
|
2
2
|
import type { ICompiledCategoryPublisherConfiguration, ICompiledCategoryPublisherConfigurationDTO } from './Category';
|
|
3
|
-
export type
|
|
3
|
+
export type TrackerCallback = () => Promise<void>;
|
|
4
|
+
export type ProductCallbackExtras = {
|
|
5
|
+
trackers: {
|
|
6
|
+
addToCart: TrackerCallback;
|
|
7
|
+
imp: TrackerCallback;
|
|
8
|
+
click: TrackerCallback;
|
|
9
|
+
[key: string]: TrackerCallback;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type ProductCallback = (e: Event, product: IProductInformation, extras: ProductCallbackExtras) => void;
|
|
4
13
|
export type Callbacks = Record<string, ProductCallback>;
|
|
5
14
|
export type TemplateDelegate = (context: IProductContext) => string;
|
|
6
15
|
export interface INativeTemplateDelegateWindow {
|
|
@@ -68,3 +77,4 @@ export interface ICompiledPublisherConfiguration {
|
|
|
68
77
|
category: ICompiledCategoryPublisherConfiguration;
|
|
69
78
|
dynamicZones?: Record<string, IDynamicZone>;
|
|
70
79
|
}
|
|
80
|
+
export declare const DefaultProductCallbackExtras: () => ProductCallbackExtras;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export interface IBidExtensions extends Record<string, any> {
|
|
2
|
+
primaryCategory?: string;
|
|
3
|
+
}
|
|
1
4
|
export interface IBid {
|
|
2
5
|
id: string;
|
|
3
6
|
impid: string;
|
|
@@ -26,7 +29,7 @@ export interface IBid {
|
|
|
26
29
|
wratio?: number;
|
|
27
30
|
hratio?: number;
|
|
28
31
|
exp?: number;
|
|
29
|
-
ext?:
|
|
32
|
+
ext?: IBidExtensions;
|
|
30
33
|
dur?: number;
|
|
31
34
|
mtype?: number;
|
|
32
35
|
slotinpid?: number;
|
|
@@ -67,6 +67,8 @@ export declare const EventTypes: {
|
|
|
67
67
|
readonly ViewableMRC50: 2;
|
|
68
68
|
readonly ViewableMRC100: 3;
|
|
69
69
|
readonly ViewableVIDEO50: 4;
|
|
70
|
+
readonly Click: 500;
|
|
71
|
+
readonly AddToCart: 501;
|
|
70
72
|
};
|
|
71
73
|
/**
|
|
72
74
|
* The context of the page for the native ad unit, i.e what type of content is being displayed
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ILogger } from './Logger';
|
|
1
|
+
import { type ILogger } from './Logger';
|
|
2
2
|
export declare const FilterBots: <TArgs extends readonly unknown[], TReturn>(logger: ILogger | undefined, userAgent: string, fn: (...args: TArgs) => TReturn, fallback: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
|
|
3
3
|
export declare const FilterBotsAsyncGenerator: <TArgs extends readonly unknown[], TReturn>(logger: ILogger | undefined, userAgent: string, fn: (...args: TArgs) => AsyncGenerator<TReturn>) => (...args: TArgs) => AsyncGenerator<Awaited<TReturn>, void, any>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ICompiledPublisherConfiguration, IProductInformation } from '../models';
|
|
2
2
|
import { type ILogger } from './Logger';
|
|
3
3
|
import { type Result, type AsyncResult } from './Result';
|
|
4
|
-
export type GetSponsoredProductFromNativeIdFn = (nativeId: string) => AsyncGenerator<IProductInformation>;
|
|
5
|
-
export type GetAllSponsoredProductFromNativeIdFn = (nativeId: string) => Promise<Result<IProductInformation[]>>;
|
|
4
|
+
export type GetSponsoredProductFromNativeIdFn = (nativeId: string, categories?: string[]) => AsyncGenerator<IProductInformation>;
|
|
5
|
+
export type GetAllSponsoredProductFromNativeIdFn = (nativeId: string, categories?: string[]) => Promise<Result<IProductInformation[]>>;
|
|
6
6
|
export type GetRecommendedProductFromProductIdFn = (productId: string) => AsyncResult<IProductInformation>;
|
|
7
|
-
export declare const GetAllSponsoredProducts: (logger: ILogger | undefined, url: string, config: ICompiledPublisherConfiguration, accountId: string, locationId: string, nativeId: string) => Promise<Result<IProductInformation[]>>;
|
|
8
|
-
export declare const GetAllSponsoredBrandProducts: (logger: ILogger | undefined, url: string, config: ICompiledPublisherConfiguration, accountId: string, locationId: string, nativeId: string) => Promise<Result<IProductInformation[]>>;
|
|
7
|
+
export declare const GetAllSponsoredProducts: (logger: ILogger | undefined, url: string, config: ICompiledPublisherConfiguration, accountId: string, locationId: string, nativeId: string, categories?: string[]) => Promise<Result<IProductInformation[]>>;
|
|
8
|
+
export declare const GetAllSponsoredBrandProducts: (logger: ILogger | undefined, url: string, config: ICompiledPublisherConfiguration, accountId: string, locationId: string, nativeId: string, categories?: string[]) => Promise<Result<IProductInformation[]>>;
|
|
9
9
|
export declare const GetRecommendedProduct: (logger: ILogger | undefined, url: string, config: ICompiledPublisherConfiguration, accountId: string, locationId: string, productId: string) => AsyncResult<IProductInformation>;
|
|
10
10
|
export declare class NoNativeError extends Error {
|
|
11
11
|
nativeId: string;
|
|
@@ -15,3 +15,7 @@ export declare class MalformedBrandResponseError extends Error {
|
|
|
15
15
|
nativeId: string;
|
|
16
16
|
constructor(nativeId: string);
|
|
17
17
|
}
|
|
18
|
+
export declare class NoProductError extends Error {
|
|
19
|
+
productId: string;
|
|
20
|
+
constructor(productId: string);
|
|
21
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { IProductInformation } from '../models';
|
|
2
2
|
import { type ILogger } from './Logger';
|
|
3
3
|
import type { GetRecommendedProductFromProductIdFn } from './Product';
|
|
4
|
-
export type NonPersonalRecommenderFn = () => AsyncGenerator<IProductInformation>;
|
|
5
|
-
export type PersonalRecommenderFn = (userId: string) => AsyncGenerator<IProductInformation>;
|
|
6
|
-
export declare function GenerateTopProducts(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string): AsyncGenerator<IProductInformation>;
|
|
7
|
-
export declare function GenerateForYou(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string, userId: string): AsyncGenerator<IProductInformation>;
|
|
8
|
-
export declare function GeneratePreviousPurchases(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string, userId: string): AsyncGenerator<IProductInformation>;
|
|
4
|
+
export type NonPersonalRecommenderFn = (category?: string) => AsyncGenerator<IProductInformation>;
|
|
5
|
+
export type PersonalRecommenderFn = (userId: string, category?: string) => AsyncGenerator<IProductInformation>;
|
|
6
|
+
export declare function GenerateTopProducts(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string, category?: string): AsyncGenerator<IProductInformation>;
|
|
7
|
+
export declare function GenerateForYou(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string, userId: string, category?: string): AsyncGenerator<IProductInformation>;
|
|
8
|
+
export declare function GeneratePreviousPurchases(logger: ILogger | undefined, productFeed: GetRecommendedProductFromProductIdFn, url: string, accountId: string, siteId: string, locationId: string, userId: string, category?: string): AsyncGenerator<IProductInformation>;
|
|
9
9
|
export declare class NoRecommendationsError extends Error {
|
|
10
10
|
constructor();
|
|
11
11
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RecommenderType } from '../helpers';
|
|
2
|
+
import type { IDevice, IGeoContext, INativeTemplateDelegateWindow, IProductInformation } from '../models';
|
|
3
|
+
import { type ILogger } from './Logger';
|
|
4
|
+
export interface ICarouselContext {
|
|
5
|
+
nextType: 'page' | 'product';
|
|
6
|
+
recommend: RecommenderType;
|
|
7
|
+
strategy: 'sponsored' | 'hybrid' | 'recommended';
|
|
8
|
+
page?: number;
|
|
9
|
+
positionAbsolute?: number;
|
|
10
|
+
positionRelative?: number;
|
|
11
|
+
recommendationValue: number;
|
|
12
|
+
zoneId: string;
|
|
13
|
+
}
|
|
14
|
+
export type ProductTrackerCallback = (context?: ICarouselContext) => Promise<void>;
|
|
15
|
+
export type ProductTrackerInitializer = (product: IProductInformation) => ProductTrackerCallback;
|
|
16
|
+
export interface IRecommendedTrackerService {
|
|
17
|
+
getClickTracker: ProductTrackerInitializer;
|
|
18
|
+
getAddToCartTracker: ProductTrackerInitializer;
|
|
19
|
+
getImpressionTracker: ProductTrackerInitializer;
|
|
20
|
+
}
|
|
21
|
+
export interface IProductTrackerService {
|
|
22
|
+
recommended: IRecommendedTrackerService;
|
|
23
|
+
}
|
|
24
|
+
export type InitTrackerServiceFn = (logger: ILogger | undefined, accountId: string, siteId: string, locationId: string, channelId: string, windowInfo: INativeTemplateDelegateWindow, userAgent: string, geo: IGeoContext | undefined, device: IDevice | undefined, userId: string | undefined, host: string) => IProductTrackerService;
|
|
25
|
+
export declare const InitTrackerService: (logger: ILogger | undefined, accountId: string, siteId: string, locationId: string, channelId: string, windowInfo: INativeTemplateDelegateWindow, userAgent: string, geo: IGeoContext | undefined, device: IDevice | undefined, userId: string | undefined, host: string) => IProductTrackerService;
|