@optable/web-sdk 0.21.4-rc1 → 0.21.4-rc3
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/dist/addons/gpt.d.ts +7 -0
- package/lib/dist/addons/gpt.js +53 -0
- package/lib/dist/addons/paapi.d.ts +20 -0
- package/lib/dist/addons/paapi.js +143 -0
- package/lib/dist/addons/topics-api.d.ts +14 -0
- package/lib/dist/addons/topics-api.js +68 -0
- package/lib/dist/addons/try-identify.d.ts +6 -0
- package/lib/dist/addons/try-identify.js +20 -0
- package/lib/dist/build.json +3 -0
- package/lib/dist/config.d.ts +10 -0
- package/lib/dist/config.js +9 -0
- package/lib/dist/core/network.d.ts +5 -0
- package/lib/dist/core/network.js +53 -0
- package/lib/dist/core/storage.d.ts +23 -0
- package/lib/dist/core/storage.js +82 -0
- package/lib/dist/edge/identify.d.ts +4 -0
- package/lib/dist/edge/identify.js +12 -0
- package/lib/dist/edge/profile.d.ts +7 -0
- package/lib/dist/edge/profile.js +15 -0
- package/lib/dist/edge/rtb2.d.ts +36 -0
- package/lib/dist/edge/rtb2.js +7 -0
- package/lib/dist/edge/site.d.ts +22 -0
- package/lib/dist/edge/site.js +30 -0
- package/lib/dist/edge/targeting.d.ts +32 -0
- package/lib/dist/edge/targeting.js +83 -0
- package/lib/dist/edge/tokenize.d.ts +11 -0
- package/lib/dist/edge/tokenize.js +15 -0
- package/lib/dist/edge/uid2_token.d.ts +12 -0
- package/lib/dist/edge/uid2_token.js +12 -0
- package/lib/dist/edge/witness.d.ts +7 -0
- package/lib/dist/edge/witness.js +16 -0
- package/lib/dist/sdk.d.ts +40 -15
- package/lib/dist/sdk.js +123 -2
- package/package.json +1 -1
- package/lib/dist/commands.d.ts +0 -7
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import OptableSDK from "../sdk";
|
|
2
|
+
function toWitnessProperties(event) {
|
|
3
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
4
|
+
return {
|
|
5
|
+
advertiserId: (_a = event.advertiserId) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
6
|
+
campaignId: (_b = event.campaignId) === null || _b === void 0 ? void 0 : _b.toString(),
|
|
7
|
+
creativeId: (_c = event.creativeId) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
8
|
+
isEmpty: (_d = event.isEmpty) === null || _d === void 0 ? void 0 : _d.toString(),
|
|
9
|
+
lineItemId: (_e = event.lineItemId) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
10
|
+
serviceName: (_f = event.serviceName) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
11
|
+
size: (_g = event.size) === null || _g === void 0 ? void 0 : _g.toString(),
|
|
12
|
+
slotElementId: (_h = event.slot) === null || _h === void 0 ? void 0 : _h.getSlotElementId(),
|
|
13
|
+
sourceAgnosticCreativeId: (_j = event.sourceAgnosticCreativeId) === null || _j === void 0 ? void 0 : _j.toString(),
|
|
14
|
+
sourceAgnosticLineItemId: (_k = event.sourceAgnosticLineItemId) === null || _k === void 0 ? void 0 : _k.toString(),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/*
|
|
18
|
+
* installGPTEventListeners() sets up event listeners on the Google Publisher Tag
|
|
19
|
+
* "slotRenderEnded" and "impressionViewable" page events, and calls witness()
|
|
20
|
+
* on the OptableSDK instance to send log data to a DCN.
|
|
21
|
+
*/
|
|
22
|
+
OptableSDK.prototype.installGPTEventListeners = function () {
|
|
23
|
+
// Next time we get called is a no-op:
|
|
24
|
+
const sdk = this;
|
|
25
|
+
sdk.installGPTEventListeners = function () { };
|
|
26
|
+
window.googletag = window.googletag || { cmd: [] };
|
|
27
|
+
const gpt = window.googletag;
|
|
28
|
+
gpt.cmd.push(function () {
|
|
29
|
+
gpt.pubads().addEventListener("slotRenderEnded", function (event) {
|
|
30
|
+
sdk.witness("googletag.events.slotRenderEnded", toWitnessProperties(event));
|
|
31
|
+
});
|
|
32
|
+
gpt.pubads().addEventListener("impressionViewable", function (event) {
|
|
33
|
+
sdk.witness("googletag.events.impressionViewable", toWitnessProperties(event));
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
/*
|
|
38
|
+
* Pass user-defined signals to GAM Secure Signals
|
|
39
|
+
*/
|
|
40
|
+
OptableSDK.prototype.installGPTSecureSignals = function (...signals) {
|
|
41
|
+
window.googletag = window.googletag || { cmd: [] };
|
|
42
|
+
const gpt = window.googletag;
|
|
43
|
+
if (signals && signals.length > 0) {
|
|
44
|
+
gpt.cmd.push(() => {
|
|
45
|
+
signals.forEach(({ provider, id }) => {
|
|
46
|
+
gpt.secureSignalProviders.push({
|
|
47
|
+
id: provider,
|
|
48
|
+
collectorFunction: () => Promise.resolve(id),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="googletag" />
|
|
2
|
+
import { AuctionConfig } from "../edge/site";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Navigator {
|
|
5
|
+
runAdAuction: (config: AuctionConfig) => Promise<any>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
type GPTSlotFilter = (slot: googletag.Slot) => boolean;
|
|
9
|
+
type RunAdAuctionOptions = {
|
|
10
|
+
iframe?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare module "../sdk" {
|
|
13
|
+
interface OptableSDK {
|
|
14
|
+
joinAdInterestGroups: () => Promise<void>;
|
|
15
|
+
auctionConfigFromCache: () => AuctionConfig | null;
|
|
16
|
+
runAdAuction: (domID: string, options?: RunAdAuctionOptions) => Promise<boolean>;
|
|
17
|
+
installGPTAuctionConfigs: (filter?: GPTSlotFilter) => void;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import OptableSDK from "../sdk";
|
|
11
|
+
/*
|
|
12
|
+
* auctionConfigFromCache obtains the cached auction configuration for the current origin
|
|
13
|
+
*/
|
|
14
|
+
OptableSDK.prototype.auctionConfigFromCache = function () {
|
|
15
|
+
var _a;
|
|
16
|
+
const siteConfig = this.siteFromCache();
|
|
17
|
+
if (!siteConfig) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return (_a = siteConfig.auctionConfig) !== null && _a !== void 0 ? _a : null;
|
|
21
|
+
};
|
|
22
|
+
function elementInnerSize(element) {
|
|
23
|
+
const style = window.getComputedStyle(element, null);
|
|
24
|
+
return {
|
|
25
|
+
width: style.getPropertyValue("width"),
|
|
26
|
+
height: style.getPropertyValue("height"),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/*
|
|
30
|
+
* installGPTAuctionConfigs obtains the auction configuration for the current origin
|
|
31
|
+
* and installs it into the page GPT slots, optionally filtered.
|
|
32
|
+
*/
|
|
33
|
+
OptableSDK.prototype.installGPTAuctionConfigs = function (filter) {
|
|
34
|
+
const sdk = this;
|
|
35
|
+
sdk.installGPTAuctionConfigs = function () { };
|
|
36
|
+
window.googletag = window.googletag || { cmd: [] };
|
|
37
|
+
const gpt = window.googletag;
|
|
38
|
+
gpt.cmd.push(function () {
|
|
39
|
+
let slots = gpt.pubads().getSlots();
|
|
40
|
+
if (filter) {
|
|
41
|
+
slots = slots.filter(filter);
|
|
42
|
+
}
|
|
43
|
+
const siteAuctionConfig = sdk.auctionConfigFromCache();
|
|
44
|
+
if (!siteAuctionConfig) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
for (const slot of slots) {
|
|
48
|
+
const sizes = slot.getSizes();
|
|
49
|
+
const componentAuction = [];
|
|
50
|
+
for (const size of sizes) {
|
|
51
|
+
if (size === "fluid") {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
componentAuction.push({
|
|
55
|
+
configKey: siteAuctionConfig.seller + "-" + size.getWidth() + "x" + size.getHeight(),
|
|
56
|
+
auctionConfig: Object.assign(Object.assign({}, siteAuctionConfig), { requestedSize: { width: size.getWidth() + "px", height: size.getHeight() + "px" } }),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// @ts-ignore // outdated typings for componentAuction expects some legacy field names
|
|
60
|
+
slot.setConfig({ componentAuction });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
/*
|
|
65
|
+
* runAdAuction runs an ad auction locally for a given spot dom ID.
|
|
66
|
+
*/
|
|
67
|
+
OptableSDK.prototype.runAdAuction = function (domID, options) {
|
|
68
|
+
var _a;
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const supported = "runAdAuction" in navigator;
|
|
71
|
+
if (!supported) {
|
|
72
|
+
throw "run-ad-auction not supported";
|
|
73
|
+
}
|
|
74
|
+
const spot = document.getElementById(domID);
|
|
75
|
+
if (!spot) {
|
|
76
|
+
throw "spot not found";
|
|
77
|
+
}
|
|
78
|
+
const requestedSize = elementInnerSize(spot);
|
|
79
|
+
const siteAuctionConfig = this.auctionConfigFromCache();
|
|
80
|
+
if (!siteAuctionConfig) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const auctionConfig = Object.assign(Object.assign({}, siteAuctionConfig), { requestedSize, resolveToConfig: true });
|
|
84
|
+
const useIframe = (_a = options === null || options === void 0 ? void 0 : options.iframe) !== null && _a !== void 0 ? _a : false;
|
|
85
|
+
if (useIframe) {
|
|
86
|
+
auctionConfig.resolveToConfig = false;
|
|
87
|
+
}
|
|
88
|
+
const result = yield navigator.runAdAuction(auctionConfig);
|
|
89
|
+
if (!result) {
|
|
90
|
+
spot.replaceChildren();
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (useIframe) {
|
|
94
|
+
const iframe = document.createElement("iframe");
|
|
95
|
+
iframe.src = result;
|
|
96
|
+
iframe.style.border = "none";
|
|
97
|
+
iframe.style.width = requestedSize.width;
|
|
98
|
+
iframe.style.height = requestedSize.height;
|
|
99
|
+
spot.replaceChildren(iframe);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const fencedFrame = document.createElement("fencedframe");
|
|
103
|
+
fencedFrame.config = result;
|
|
104
|
+
fencedFrame.style.border = "none";
|
|
105
|
+
spot.replaceChildren(fencedFrame);
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
/*
|
|
111
|
+
* joinAdInterestGroups injects an iframe into the page that tags the device into the matching audiences interest group.
|
|
112
|
+
*/
|
|
113
|
+
OptableSDK.prototype.joinAdInterestGroups = function () {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const supported = "joinAdInterestGroup" in navigator;
|
|
116
|
+
if (!supported) {
|
|
117
|
+
throw "join-ad-interest-group not supported";
|
|
118
|
+
}
|
|
119
|
+
const siteConfig = yield this.site();
|
|
120
|
+
if (!siteConfig.interestGroupPixel) {
|
|
121
|
+
throw "origin not enabled for protected audience apis";
|
|
122
|
+
}
|
|
123
|
+
const pixelURL = new URL(siteConfig.interestGroupPixel);
|
|
124
|
+
const pixel = document.createElement("iframe");
|
|
125
|
+
pixel.src = pixelURL.toString();
|
|
126
|
+
pixel.allow = "join-ad-interest-group " + pixelURL.origin;
|
|
127
|
+
pixel.style.display = "none";
|
|
128
|
+
const joinPromise = new Promise((resolve, reject) => {
|
|
129
|
+
window.addEventListener("message", (event) => {
|
|
130
|
+
if (event.source !== pixel.contentWindow) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (event.data.result === "success") {
|
|
134
|
+
resolve();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
reject();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
document.body.appendChild(pixel);
|
|
141
|
+
return joinPromise;
|
|
142
|
+
});
|
|
143
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface BrowsingTopic {
|
|
2
|
+
configVersion: string;
|
|
3
|
+
modelVersion: string;
|
|
4
|
+
taxonomyVersion: string;
|
|
5
|
+
topic: number;
|
|
6
|
+
version: string;
|
|
7
|
+
}
|
|
8
|
+
declare module "../sdk" {
|
|
9
|
+
interface OptableSDK {
|
|
10
|
+
getTopics: () => Promise<BrowsingTopic[]>;
|
|
11
|
+
ingestTopics: () => void;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import OptableSDK from "../sdk";
|
|
11
|
+
/*
|
|
12
|
+
* getTopics injects an iframe into the page that obtains the browsingTopics observed by optable.
|
|
13
|
+
*/
|
|
14
|
+
OptableSDK.prototype.getTopics = function () {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const supported = "browsingTopics" in document;
|
|
17
|
+
if (!supported) {
|
|
18
|
+
throw "browsing-topics not supported";
|
|
19
|
+
}
|
|
20
|
+
const siteConfig = yield this.site();
|
|
21
|
+
if (!siteConfig.getTopicsURL) {
|
|
22
|
+
throw "origin not enabled for topics api";
|
|
23
|
+
}
|
|
24
|
+
const getTopicsURL = new URL(siteConfig.getTopicsURL);
|
|
25
|
+
const topicsFrame = document.createElement("iframe");
|
|
26
|
+
topicsFrame.src = getTopicsURL.toString();
|
|
27
|
+
topicsFrame.allow = "browsing-topics " + getTopicsURL.origin;
|
|
28
|
+
topicsFrame.style.display = "none";
|
|
29
|
+
const topicsPromise = new Promise((resolve, reject) => {
|
|
30
|
+
window.addEventListener("message", (event) => {
|
|
31
|
+
if (event.source !== topicsFrame.contentWindow) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (event.data.error) {
|
|
35
|
+
reject(new Error(event.data.error.toString()));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
resolve(event.data.result);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
document.body.appendChild(topicsFrame);
|
|
42
|
+
return topicsPromise;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
/*
|
|
46
|
+
* ingestTopics invokes getTopics then makes a profile() call with the resulting topics, if any.
|
|
47
|
+
*/
|
|
48
|
+
OptableSDK.prototype.ingestTopics = function () {
|
|
49
|
+
this.getTopics()
|
|
50
|
+
.then((topics) => {
|
|
51
|
+
if (!topics.length) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const traits = topics.reduce((acc, topic) => {
|
|
55
|
+
const traitKey = `topics_v${topic.taxonomyVersion}`;
|
|
56
|
+
if (acc[traitKey]) {
|
|
57
|
+
acc[traitKey] += ",";
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
acc[traitKey] = "";
|
|
61
|
+
}
|
|
62
|
+
acc[traitKey] += String(topic.topic);
|
|
63
|
+
return acc;
|
|
64
|
+
}, {});
|
|
65
|
+
this.profile(traits);
|
|
66
|
+
})
|
|
67
|
+
.catch(() => { });
|
|
68
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import OptableSDK from "../sdk";
|
|
2
|
+
const eidRegexp = /^[a-f0-9]{64}$/i;
|
|
3
|
+
function maybeValidEID(eid) {
|
|
4
|
+
return eidRegexp.test(eid);
|
|
5
|
+
}
|
|
6
|
+
OptableSDK.prototype.tryIdentifyFromParams = function (key, prefix) {
|
|
7
|
+
const keyRegexp = new RegExp(`^${key || "oeid"}$`, "i");
|
|
8
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
9
|
+
let eid = "";
|
|
10
|
+
for (const [key, value] of searchParams) {
|
|
11
|
+
if (keyRegexp.test(key)) {
|
|
12
|
+
eid = value;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (eid == "" || (!prefix && !maybeValidEID(eid))) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.identify((prefix || "e") + ":" + eid.toLowerCase());
|
|
20
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type OptableConfig = {
|
|
2
|
+
host: string;
|
|
3
|
+
site: string;
|
|
4
|
+
insecure?: boolean;
|
|
5
|
+
cookies?: boolean;
|
|
6
|
+
initPassport?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare function getConfig(config: OptableConfig): Required<OptableConfig>;
|
|
9
|
+
export { OptableConfig, getConfig };
|
|
10
|
+
export default OptableConfig;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OptableConfig } from "../config";
|
|
2
|
+
declare function buildRequest(path: string, config: Required<OptableConfig>, init?: RequestInit): Request;
|
|
3
|
+
declare function fetch<T>(path: string, config: Required<OptableConfig>, init?: RequestInit): Promise<T>;
|
|
4
|
+
export { fetch, buildRequest };
|
|
5
|
+
export default fetch;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { default as buildInfo } from "../build.json";
|
|
11
|
+
import { LocalStorage } from "./storage";
|
|
12
|
+
function buildRequest(path, config, init) {
|
|
13
|
+
const { site, host, insecure, cookies } = config;
|
|
14
|
+
const proto = insecure ? "http" : "https";
|
|
15
|
+
const url = new URL(`${site}${path}`, `${proto}://${host}`);
|
|
16
|
+
url.searchParams.set("osdk", `web-${buildInfo.version}`);
|
|
17
|
+
if (cookies) {
|
|
18
|
+
url.searchParams.set("cookies", "yes");
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const ls = new LocalStorage(config);
|
|
22
|
+
const pass = ls.getPassport();
|
|
23
|
+
url.searchParams.set("cookies", "no");
|
|
24
|
+
url.searchParams.set("passport", pass ? pass : "");
|
|
25
|
+
}
|
|
26
|
+
const requestInit = Object.assign({}, init);
|
|
27
|
+
requestInit.credentials = "include";
|
|
28
|
+
const request = new Request(url.toString(), requestInit);
|
|
29
|
+
return request;
|
|
30
|
+
}
|
|
31
|
+
function fetch(path, config, init) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const response = yield globalThis.fetch(buildRequest(path, config, init));
|
|
34
|
+
const contentType = response.headers.get("Content-Type");
|
|
35
|
+
const data = (contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("application/json")) ? yield response.json() : yield response.text();
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
throw new Error(data.error);
|
|
38
|
+
}
|
|
39
|
+
if (data.passport) {
|
|
40
|
+
const ls = new LocalStorage(config);
|
|
41
|
+
ls.setPassport(data.passport);
|
|
42
|
+
// We delete the passport attribute from the returned payload. This is because
|
|
43
|
+
// the targeting edge handler was initially made to return targeting data directly
|
|
44
|
+
// in the form of 'key values' on the returned JSON payload -- if we don't delete
|
|
45
|
+
// the `passport` attribute here, it may end up sent as targeting data to ad servers.
|
|
46
|
+
// Not the end of the world, but something we want to avoid due to passport size.
|
|
47
|
+
delete data.passport;
|
|
48
|
+
}
|
|
49
|
+
return data;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export { fetch, buildRequest };
|
|
53
|
+
export default fetch;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SiteResponse } from "../edge/site";
|
|
2
|
+
import type { OptableConfig } from "../config";
|
|
3
|
+
import type { TargetingResponse } from "../edge/targeting";
|
|
4
|
+
declare class LocalStorage {
|
|
5
|
+
private Config;
|
|
6
|
+
private passportKey;
|
|
7
|
+
private targetingV1Key;
|
|
8
|
+
private targetingKey;
|
|
9
|
+
private siteKey;
|
|
10
|
+
constructor(Config: OptableConfig);
|
|
11
|
+
getPassport(): string | null;
|
|
12
|
+
getV1Targeting(): TargetingResponse | null;
|
|
13
|
+
getTargeting(): TargetingResponse | null;
|
|
14
|
+
setPassport(passport: string): void;
|
|
15
|
+
setTargeting(targeting?: TargetingResponse | null): void;
|
|
16
|
+
setSite(site?: SiteResponse | null): void;
|
|
17
|
+
getSite(): SiteResponse | null;
|
|
18
|
+
clearPassport(): void;
|
|
19
|
+
clearTargeting(): void;
|
|
20
|
+
clearSite(): void;
|
|
21
|
+
}
|
|
22
|
+
export { LocalStorage };
|
|
23
|
+
export default LocalStorage;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
function toBinary(str) {
|
|
2
|
+
const codeUnits = new Uint16Array(str.length);
|
|
3
|
+
for (let i = 0; i < codeUnits.length; i++) {
|
|
4
|
+
codeUnits[i] = str.charCodeAt(i);
|
|
5
|
+
}
|
|
6
|
+
return String.fromCharCode(...new Uint8Array(codeUnits.buffer));
|
|
7
|
+
}
|
|
8
|
+
class LocalStorage {
|
|
9
|
+
constructor(Config) {
|
|
10
|
+
this.Config = Config;
|
|
11
|
+
const sfx = btoa(toBinary(`${this.Config.host}/${this.Config.site}`));
|
|
12
|
+
// Legacy targeting key
|
|
13
|
+
this.targetingV1Key = "OPTABLE_TGT_" + sfx;
|
|
14
|
+
this.passportKey = "OPTABLE_PASS_" + sfx;
|
|
15
|
+
this.targetingKey = "OPTABLE_V2_TGT_" + sfx;
|
|
16
|
+
this.siteKey = "OPTABLE_SITE_" + sfx;
|
|
17
|
+
}
|
|
18
|
+
getPassport() {
|
|
19
|
+
return window.localStorage.getItem(this.passportKey);
|
|
20
|
+
}
|
|
21
|
+
getV1Targeting() {
|
|
22
|
+
const raw = window.localStorage.getItem(this.targetingV1Key);
|
|
23
|
+
const parsed = raw ? JSON.parse(raw) : null;
|
|
24
|
+
if (!parsed) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const audiences = Object.entries(parsed).map(([keyspace, values]) => {
|
|
28
|
+
return {
|
|
29
|
+
provider: "optable.co",
|
|
30
|
+
keyspace,
|
|
31
|
+
// 5001 is Optable Private Member Defined Audiences
|
|
32
|
+
// See: https://github.com/InteractiveAdvertisingBureau/openrtb/pull/81
|
|
33
|
+
//
|
|
34
|
+
// Starting v2 this is returned in the targeting payload directly
|
|
35
|
+
rtb_segtax: 5001,
|
|
36
|
+
ids: [].concat(...[values]).map((id) => ({ id: String(id) })),
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
user: [],
|
|
41
|
+
audience: audiences,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
getTargeting() {
|
|
45
|
+
const raw = window.localStorage.getItem(this.targetingKey);
|
|
46
|
+
const parsed = raw ? JSON.parse(raw) : null;
|
|
47
|
+
return parsed ? parsed : this.getV1Targeting();
|
|
48
|
+
}
|
|
49
|
+
setPassport(passport) {
|
|
50
|
+
if (passport && passport.length > 0) {
|
|
51
|
+
window.localStorage.setItem(this.passportKey, passport);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
setTargeting(targeting) {
|
|
55
|
+
if (!targeting) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
window.localStorage.setItem(this.targetingKey, JSON.stringify(targeting));
|
|
59
|
+
}
|
|
60
|
+
setSite(site) {
|
|
61
|
+
if (!site) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
window.localStorage.setItem(this.siteKey, JSON.stringify(site));
|
|
65
|
+
}
|
|
66
|
+
getSite() {
|
|
67
|
+
const raw = window.localStorage.getItem(this.siteKey);
|
|
68
|
+
const parsed = raw ? JSON.parse(raw) : null;
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
clearPassport() {
|
|
72
|
+
window.localStorage.removeItem(this.passportKey);
|
|
73
|
+
}
|
|
74
|
+
clearTargeting() {
|
|
75
|
+
window.localStorage.removeItem(this.targetingKey);
|
|
76
|
+
}
|
|
77
|
+
clearSite() {
|
|
78
|
+
window.localStorage.removeItem(this.siteKey);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export { LocalStorage };
|
|
82
|
+
export default LocalStorage;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fetch } from "../core/network";
|
|
2
|
+
function Identify(config, ids) {
|
|
3
|
+
return fetch("/identify", config, {
|
|
4
|
+
method: "POST",
|
|
5
|
+
headers: {
|
|
6
|
+
"Content-Type": "application/json",
|
|
7
|
+
},
|
|
8
|
+
body: JSON.stringify(ids),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export { Identify };
|
|
12
|
+
export default Identify;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OptableConfig } from "../config";
|
|
2
|
+
type ProfileTraits = {
|
|
3
|
+
[key: string]: string | number | boolean;
|
|
4
|
+
};
|
|
5
|
+
declare function Profile(config: Required<OptableConfig>, traits: ProfileTraits): Promise<void>;
|
|
6
|
+
export { Profile, ProfileTraits };
|
|
7
|
+
export default Profile;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { fetch } from "../core/network";
|
|
2
|
+
function Profile(config, traits) {
|
|
3
|
+
const profile = {
|
|
4
|
+
traits: traits,
|
|
5
|
+
};
|
|
6
|
+
return fetch("/profile", config, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
headers: {
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify(profile),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export { Profile };
|
|
15
|
+
export default Profile;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type UserSegment = {
|
|
2
|
+
id?: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
value?: string;
|
|
5
|
+
ext?: any;
|
|
6
|
+
};
|
|
7
|
+
type UserData = {
|
|
8
|
+
id?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
segment?: UserSegment[];
|
|
11
|
+
ext?: {
|
|
12
|
+
segtax: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type ExtendedIdentifierUID = {
|
|
16
|
+
id: string;
|
|
17
|
+
atype: UIDAgentType;
|
|
18
|
+
ext?: any;
|
|
19
|
+
};
|
|
20
|
+
type ExtendedIdentifiers = {
|
|
21
|
+
source: string;
|
|
22
|
+
uids: ExtendedIdentifierUID[];
|
|
23
|
+
};
|
|
24
|
+
type UserExt = {
|
|
25
|
+
eids?: ExtendedIdentifiers[];
|
|
26
|
+
};
|
|
27
|
+
type User = {
|
|
28
|
+
data?: UserData[];
|
|
29
|
+
ext?: UserExt;
|
|
30
|
+
};
|
|
31
|
+
declare enum UIDAgentType {
|
|
32
|
+
DeviceID = 1,
|
|
33
|
+
InAppImpression = 2,
|
|
34
|
+
PersonID = 3
|
|
35
|
+
}
|
|
36
|
+
export { User, UIDAgentType };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var UIDAgentType;
|
|
2
|
+
(function (UIDAgentType) {
|
|
3
|
+
UIDAgentType[UIDAgentType["DeviceID"] = 1] = "DeviceID";
|
|
4
|
+
UIDAgentType[UIDAgentType["InAppImpression"] = 2] = "InAppImpression";
|
|
5
|
+
UIDAgentType[UIDAgentType["PersonID"] = 3] = "PersonID";
|
|
6
|
+
})(UIDAgentType || (UIDAgentType = {}));
|
|
7
|
+
export { UIDAgentType };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OptableConfig } from "../config";
|
|
2
|
+
type Size = {
|
|
3
|
+
width: string;
|
|
4
|
+
height: string;
|
|
5
|
+
};
|
|
6
|
+
type AuctionConfig = {
|
|
7
|
+
seller: string;
|
|
8
|
+
decisionLogicURL: string;
|
|
9
|
+
requestedSize?: Size;
|
|
10
|
+
interestGroupBuyers: string[];
|
|
11
|
+
resolveToConfig?: boolean;
|
|
12
|
+
auctionSignals?: any;
|
|
13
|
+
};
|
|
14
|
+
type SiteResponse = {
|
|
15
|
+
interestGroupPixel: string;
|
|
16
|
+
auctionConfig?: AuctionConfig | null;
|
|
17
|
+
getTopicsURL: string;
|
|
18
|
+
};
|
|
19
|
+
declare function Site(config: Required<OptableConfig>): Promise<SiteResponse>;
|
|
20
|
+
declare function SiteFromCache(config: Required<OptableConfig>): SiteResponse | null;
|
|
21
|
+
export { Site, SiteResponse, SiteFromCache, Size, AuctionConfig };
|
|
22
|
+
export default Site;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { fetch } from "../core/network";
|
|
11
|
+
import { LocalStorage } from "../core/storage";
|
|
12
|
+
// Grab the site configuration from the server and store it in local storage
|
|
13
|
+
function Site(config) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const response = yield fetch("/config", config, {
|
|
16
|
+
method: "GET",
|
|
17
|
+
headers: { Accept: "application/json" },
|
|
18
|
+
});
|
|
19
|
+
const ls = new LocalStorage(config);
|
|
20
|
+
ls.setSite(response);
|
|
21
|
+
return response;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// Obtain the site configuration from local storage
|
|
25
|
+
function SiteFromCache(config) {
|
|
26
|
+
const ls = new LocalStorage(config);
|
|
27
|
+
return ls.getSite();
|
|
28
|
+
}
|
|
29
|
+
export { Site, SiteFromCache };
|
|
30
|
+
export default Site;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { OptableConfig } from "../config";
|
|
2
|
+
import { User as RTB2User } from "./rtb2";
|
|
3
|
+
type Identifier = {
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
type AudienceIdentifiers = {
|
|
7
|
+
ids: Identifier[];
|
|
8
|
+
provider: string;
|
|
9
|
+
rtb_segtax: number;
|
|
10
|
+
keyspace?: string;
|
|
11
|
+
};
|
|
12
|
+
type UserIdentifiers = {
|
|
13
|
+
ids: Identifier[];
|
|
14
|
+
provider: string;
|
|
15
|
+
};
|
|
16
|
+
type TargetingResponse = {
|
|
17
|
+
audience?: AudienceIdentifiers[];
|
|
18
|
+
user?: UserIdentifiers[];
|
|
19
|
+
};
|
|
20
|
+
declare function Targeting(config: Required<OptableConfig>, id: string): Promise<TargetingResponse>;
|
|
21
|
+
declare function TargetingFromCache(config: Required<OptableConfig>): TargetingResponse | null;
|
|
22
|
+
declare function TargetingClearCache(config: Required<OptableConfig>): void;
|
|
23
|
+
type PrebidORTB2 = {
|
|
24
|
+
user?: RTB2User;
|
|
25
|
+
};
|
|
26
|
+
declare function PrebidORTB2(tdata: TargetingResponse | null): PrebidORTB2;
|
|
27
|
+
type TargetingKeyValues = {
|
|
28
|
+
[key: string]: string[];
|
|
29
|
+
};
|
|
30
|
+
declare function TargetingKeyValues(tdata: TargetingResponse | null): TargetingKeyValues;
|
|
31
|
+
export { Targeting, TargetingFromCache, TargetingClearCache, TargetingResponse, PrebidORTB2, TargetingKeyValues };
|
|
32
|
+
export default Targeting;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { fetch } from "../core/network";
|
|
11
|
+
import { LocalStorage } from "../core/storage";
|
|
12
|
+
import { UIDAgentType } from "./rtb2";
|
|
13
|
+
function Targeting(config, id) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const searchParams = new URLSearchParams({ id });
|
|
16
|
+
const path = "/v2/targeting?" + searchParams.toString();
|
|
17
|
+
const response = yield fetch(path, config, {
|
|
18
|
+
method: "GET",
|
|
19
|
+
headers: { Accept: "application/json" },
|
|
20
|
+
});
|
|
21
|
+
if (response) {
|
|
22
|
+
const ls = new LocalStorage(config);
|
|
23
|
+
ls.setTargeting(response);
|
|
24
|
+
}
|
|
25
|
+
return response;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function TargetingFromCache(config) {
|
|
29
|
+
const ls = new LocalStorage(config);
|
|
30
|
+
return ls.getTargeting();
|
|
31
|
+
}
|
|
32
|
+
function TargetingClearCache(config) {
|
|
33
|
+
const ls = new LocalStorage(config);
|
|
34
|
+
ls.clearTargeting();
|
|
35
|
+
}
|
|
36
|
+
/*
|
|
37
|
+
* Prebid.js supports passing seller-defined audiences to compatible
|
|
38
|
+
* bidder adapters.
|
|
39
|
+
*
|
|
40
|
+
* We return the contents to be merged in ortb2 and passed to
|
|
41
|
+
* bidder adapters via mergeConfig(ortb2)... the caller is free
|
|
42
|
+
* to append additional objects before setting the final result.
|
|
43
|
+
*
|
|
44
|
+
* References:
|
|
45
|
+
* https://docs.prebid.org/features/firstPartyData.html#segments-and-taxonomy
|
|
46
|
+
* https://iabtechlab.com/wp-content/uploads/2021/03/IABTechLab_Taxonomy_and_Data_Transparency_Standards_to_Support_Seller-defined_Audience_and_Context_Signaling_2021-03.pdf
|
|
47
|
+
*/
|
|
48
|
+
function PrebidORTB2(tdata) {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return {
|
|
51
|
+
user: {
|
|
52
|
+
data: ((_a = tdata === null || tdata === void 0 ? void 0 : tdata.audience) !== null && _a !== void 0 ? _a : []).map((identifiers) => ({
|
|
53
|
+
name: identifiers.provider,
|
|
54
|
+
segment: identifiers.ids,
|
|
55
|
+
ext: { segtax: identifiers.rtb_segtax },
|
|
56
|
+
})),
|
|
57
|
+
ext: {
|
|
58
|
+
eids: ((_b = tdata === null || tdata === void 0 ? void 0 : tdata.user) !== null && _b !== void 0 ? _b : []).map((identifiers) => ({
|
|
59
|
+
source: identifiers.provider,
|
|
60
|
+
uids: identifiers.ids.map(({ id }) => ({ id, atype: UIDAgentType.PersonID })),
|
|
61
|
+
})),
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function TargetingKeyValues(tdata) {
|
|
67
|
+
var _a;
|
|
68
|
+
const result = {};
|
|
69
|
+
if (!tdata) {
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
for (const identifiers of (_a = tdata.audience) !== null && _a !== void 0 ? _a : []) {
|
|
73
|
+
if (identifiers.keyspace) {
|
|
74
|
+
if (!(identifiers.keyspace in result)) {
|
|
75
|
+
result[identifiers.keyspace] = [];
|
|
76
|
+
}
|
|
77
|
+
result[identifiers.keyspace].push(...identifiers.ids.map((el) => el.id));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
export { Targeting, TargetingFromCache, TargetingClearCache, PrebidORTB2, TargetingKeyValues };
|
|
83
|
+
export default Targeting;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OptableConfig } from "../config";
|
|
2
|
+
import { User } from "./rtb2";
|
|
3
|
+
type TokenizeResponse = {
|
|
4
|
+
User: User;
|
|
5
|
+
};
|
|
6
|
+
type TokenizeRequest = {
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
declare function Tokenize(config: Required<OptableConfig>, id: string): Promise<TokenizeResponse>;
|
|
10
|
+
export { Tokenize, TokenizeRequest, TokenizeResponse };
|
|
11
|
+
export default Tokenize;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { fetch } from "../core/network";
|
|
2
|
+
function Tokenize(config, id) {
|
|
3
|
+
let request = {
|
|
4
|
+
id: id,
|
|
5
|
+
};
|
|
6
|
+
return fetch("/v1/tokenize", config, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
headers: {
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify(request),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export { Tokenize };
|
|
15
|
+
export default Tokenize;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OptableConfig } from "../config";
|
|
2
|
+
type Uid2TokenResponse = {
|
|
3
|
+
advertising_token: string;
|
|
4
|
+
RefreshToken: string;
|
|
5
|
+
IdentityExpires: number;
|
|
6
|
+
RefreshFrom: number;
|
|
7
|
+
RefreshExpires: number;
|
|
8
|
+
RefreshResponseKey: string;
|
|
9
|
+
};
|
|
10
|
+
declare function Uid2Token(config: Required<OptableConfig>, id: string): Promise<Uid2TokenResponse>;
|
|
11
|
+
export { Uid2Token };
|
|
12
|
+
export default Uid2Token;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fetch } from "../core/network";
|
|
2
|
+
function Uid2Token(config, id) {
|
|
3
|
+
return fetch("/uid2/token", config, {
|
|
4
|
+
method: "POST",
|
|
5
|
+
headers: {
|
|
6
|
+
"Content-Type": "application/json",
|
|
7
|
+
},
|
|
8
|
+
body: JSON.stringify(id),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export { Uid2Token };
|
|
12
|
+
export default Uid2Token;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OptableConfig } from "../config";
|
|
2
|
+
type WitnessProperties = {
|
|
3
|
+
[key: string]: string | number | boolean;
|
|
4
|
+
};
|
|
5
|
+
declare function Witness(config: Required<OptableConfig>, event: string, properties: WitnessProperties): Promise<void>;
|
|
6
|
+
export { Witness, WitnessProperties };
|
|
7
|
+
export default Witness;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fetch } from "../core/network";
|
|
2
|
+
function Witness(config, event, properties) {
|
|
3
|
+
const evt = {
|
|
4
|
+
event: event,
|
|
5
|
+
properties: properties,
|
|
6
|
+
};
|
|
7
|
+
return fetch("/witness", config, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
},
|
|
12
|
+
body: JSON.stringify(evt),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export { Witness };
|
|
16
|
+
export default Witness;
|
package/lib/dist/sdk.d.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import "
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import type { OptableConfig } from "./config";
|
|
2
|
+
import type { WitnessProperties } from "./edge/witness";
|
|
3
|
+
import type { ProfileTraits } from "./edge/profile";
|
|
4
|
+
import { SiteResponse } from "./edge/site";
|
|
5
|
+
import { TargetingKeyValues, TargetingResponse, PrebidORTB2 } from "./edge/targeting";
|
|
6
|
+
import { TokenizeResponse } from "./edge/tokenize";
|
|
7
|
+
declare class OptableSDK {
|
|
8
|
+
static version: string;
|
|
9
|
+
dcn: Required<OptableConfig>;
|
|
10
|
+
private init;
|
|
11
|
+
constructor(dcn: OptableConfig);
|
|
12
|
+
identify(...ids: string[]): Promise<void>;
|
|
13
|
+
uid2Token(id: string): Promise<{
|
|
14
|
+
advertising_token: string;
|
|
15
|
+
RefreshToken: string;
|
|
16
|
+
IdentityExpires: number;
|
|
17
|
+
RefreshFrom: number;
|
|
18
|
+
RefreshExpires: number;
|
|
19
|
+
RefreshResponseKey: string;
|
|
20
|
+
}>;
|
|
21
|
+
targeting(id?: string): Promise<TargetingResponse>;
|
|
22
|
+
targetingFromCache(): TargetingResponse | null;
|
|
23
|
+
site(): Promise<SiteResponse>;
|
|
24
|
+
siteFromCache(): SiteResponse | null;
|
|
25
|
+
targetingClearCache(): void;
|
|
26
|
+
prebidORTB2(): Promise<PrebidORTB2>;
|
|
27
|
+
prebidORTB2FromCache(): PrebidORTB2;
|
|
28
|
+
targetingKeyValues(): Promise<TargetingKeyValues>;
|
|
29
|
+
targetingKeyValuesFromCache(): TargetingKeyValues;
|
|
30
|
+
witness(event: string, properties?: WitnessProperties): Promise<void>;
|
|
31
|
+
profile(traits: ProfileTraits): Promise<void>;
|
|
32
|
+
tokenize(id: string): Promise<TokenizeResponse>;
|
|
33
|
+
static eid(email: string): string;
|
|
34
|
+
static sha256(string: string): string;
|
|
35
|
+
static cid(ppid: string, variant?: number): string;
|
|
36
|
+
static TargetingKeyValues(tdata: TargetingResponse): TargetingKeyValues;
|
|
37
|
+
static PrebidORTB2(tdata: TargetingResponse): PrebidORTB2;
|
|
15
38
|
}
|
|
16
|
-
export {};
|
|
39
|
+
export { OptableSDK };
|
|
40
|
+
export type { OptableConfig };
|
|
41
|
+
export default OptableSDK;
|
package/lib/dist/sdk.js
CHANGED
|
@@ -1,2 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
(()=>{var t={396:t=>{t.exports=function(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}},312:(t,e,i)=>{var r;!function(){"use strict";var e="input is invalid type",n="object"==typeof window,s=n?window:{};s.JS_SHA256_NO_WINDOW&&(n=!1);var o=!n&&"object"==typeof self,a=!s.JS_SHA256_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;a?s=i.g:o&&(s=self);var h=!s.JS_SHA256_NO_COMMON_JS&&t.exports,c=i.amdO,u=!s.JS_SHA256_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,d="0123456789abcdef".split(""),p=[-2147483648,8388608,32768,128],l=[24,16,8,0],f=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],g=["hex","array","digest","arrayBuffer"],y=[];!s.JS_SHA256_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!u||!s.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});var w=function(t,e){return function(i){return new A(e,!0).update(i)[t]()}},m=function(t){var e=w("hex",t);a&&(e=v(e,t)),e.create=function(){return new A(t)},e.update=function(t){return e.create().update(t)};for(var i=0;i<g.length;++i){var r=g[i];e[r]=w(r,t)}return e},v=function(t,r){var n,o=i(394),a=i(903).Buffer,h=r?"sha224":"sha256";return n=a.from&&!s.JS_SHA256_NO_BUFFER_FROM?a.from:function(t){return new a(t)},function(i){if("string"==typeof i)return o.createHash(h).update(i,"utf8").digest("hex");if(null==i)throw new Error(e);return i.constructor===ArrayBuffer&&(i=new Uint8Array(i)),Array.isArray(i)||ArrayBuffer.isView(i)||i.constructor===a?o.createHash(h).update(n(i)).digest("hex"):t(i)}},S=function(t,e){return function(i,r){return new T(i,e,!0).update(r)[t]()}},b=function(t){var e=S("hex",t);e.create=function(e){return new T(e,t)},e.update=function(t,i){return e.create(t).update(i)};for(var i=0;i<g.length;++i){var r=g[i];e[r]=S(r,t)}return e};function A(t,e){e?(y[0]=y[16]=y[1]=y[2]=y[3]=y[4]=y[5]=y[6]=y[7]=y[8]=y[9]=y[10]=y[11]=y[12]=y[13]=y[14]=y[15]=0,this.blocks=y):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,this.h7=3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225),this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=t}function T(t,i,r){var n,s=typeof t;if("string"===s){var o,a=[],h=t.length,c=0;for(n=0;n<h;++n)(o=t.charCodeAt(n))<128?a[c++]=o:o<2048?(a[c++]=192|o>>>6,a[c++]=128|63&o):o<55296||o>=57344?(a[c++]=224|o>>>12,a[c++]=128|o>>>6&63,a[c++]=128|63&o):(o=65536+((1023&o)<<10|1023&t.charCodeAt(++n)),a[c++]=240|o>>>18,a[c++]=128|o>>>12&63,a[c++]=128|o>>>6&63,a[c++]=128|63&o);t=a}else{if("object"!==s)throw new Error(e);if(null===t)throw new Error(e);if(u&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||u&&ArrayBuffer.isView(t)))throw new Error(e)}t.length>64&&(t=new A(i,!0).update(t).array());var d=[],p=[];for(n=0;n<64;++n){var l=t[n]||0;d[n]=92^l,p[n]=54^l}A.call(this,i,r),this.update(p),this.oKeyPad=d,this.inner=!0,this.sharedMemory=r}A.prototype.update=function(t){if(!this.finalized){var i,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(e);if(null===t)throw new Error(e);if(u&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||u&&ArrayBuffer.isView(t)))throw new Error(e);i=!0}for(var n,s,o=0,a=t.length,h=this.blocks;o<a;){if(this.hashed&&(this.hashed=!1,h[0]=this.block,this.block=h[16]=h[1]=h[2]=h[3]=h[4]=h[5]=h[6]=h[7]=h[8]=h[9]=h[10]=h[11]=h[12]=h[13]=h[14]=h[15]=0),i)for(s=this.start;o<a&&s<64;++o)h[s>>>2]|=t[o]<<l[3&s++];else for(s=this.start;o<a&&s<64;++o)(n=t.charCodeAt(o))<128?h[s>>>2]|=n<<l[3&s++]:n<2048?(h[s>>>2]|=(192|n>>>6)<<l[3&s++],h[s>>>2]|=(128|63&n)<<l[3&s++]):n<55296||n>=57344?(h[s>>>2]|=(224|n>>>12)<<l[3&s++],h[s>>>2]|=(128|n>>>6&63)<<l[3&s++],h[s>>>2]|=(128|63&n)<<l[3&s++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++o)),h[s>>>2]|=(240|n>>>18)<<l[3&s++],h[s>>>2]|=(128|n>>>12&63)<<l[3&s++],h[s>>>2]|=(128|n>>>6&63)<<l[3&s++],h[s>>>2]|=(128|63&n)<<l[3&s++]);this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.block=h[16],this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this}},A.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex;t[16]=this.block,t[e>>>2]|=p[3&e],this.block=t[16],e>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},A.prototype.hash=function(){var t,e,i,r,n,s,o,a,h,c=this.h0,u=this.h1,d=this.h2,p=this.h3,l=this.h4,g=this.h5,y=this.h6,w=this.h7,m=this.blocks;for(t=16;t<64;++t)e=((n=m[t-15])>>>7|n<<25)^(n>>>18|n<<14)^n>>>3,i=((n=m[t-2])>>>17|n<<15)^(n>>>19|n<<13)^n>>>10,m[t]=m[t-16]+e+m[t-7]+i|0;for(h=u&d,t=0;t<64;t+=4)this.first?(this.is224?(s=300032,w=(n=m[0]-1413257819)-150054599|0,p=n+24177077|0):(s=704751109,w=(n=m[0]-210244248)-1521486534|0,p=n+143694565|0),this.first=!1):(e=(c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),r=(s=c&u)^c&d^h,w=p+(n=w+(i=(l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7))+(l&g^~l&y)+f[t]+m[t])|0,p=n+(e+r)|0),e=(p>>>2|p<<30)^(p>>>13|p<<19)^(p>>>22|p<<10),r=(o=p&c)^p&u^s,y=d+(n=y+(i=(w>>>6|w<<26)^(w>>>11|w<<21)^(w>>>25|w<<7))+(w&l^~w&g)+f[t+1]+m[t+1])|0,e=((d=n+(e+r)|0)>>>2|d<<30)^(d>>>13|d<<19)^(d>>>22|d<<10),r=(a=d&p)^d&c^o,g=u+(n=g+(i=(y>>>6|y<<26)^(y>>>11|y<<21)^(y>>>25|y<<7))+(y&w^~y&l)+f[t+2]+m[t+2])|0,e=((u=n+(e+r)|0)>>>2|u<<30)^(u>>>13|u<<19)^(u>>>22|u<<10),r=(h=u&d)^u&p^a,l=c+(n=l+(i=(g>>>6|g<<26)^(g>>>11|g<<21)^(g>>>25|g<<7))+(g&y^~g&w)+f[t+3]+m[t+3])|0,c=n+(e+r)|0,this.chromeBugWorkAround=!0;this.h0=this.h0+c|0,this.h1=this.h1+u|0,this.h2=this.h2+d|0,this.h3=this.h3+p|0,this.h4=this.h4+l|0,this.h5=this.h5+g|0,this.h6=this.h6+y|0,this.h7=this.h7+w|0},A.prototype.hex=function(){this.finalize();var t=this.h0,e=this.h1,i=this.h2,r=this.h3,n=this.h4,s=this.h5,o=this.h6,a=this.h7,h=d[t>>>28&15]+d[t>>>24&15]+d[t>>>20&15]+d[t>>>16&15]+d[t>>>12&15]+d[t>>>8&15]+d[t>>>4&15]+d[15&t]+d[e>>>28&15]+d[e>>>24&15]+d[e>>>20&15]+d[e>>>16&15]+d[e>>>12&15]+d[e>>>8&15]+d[e>>>4&15]+d[15&e]+d[i>>>28&15]+d[i>>>24&15]+d[i>>>20&15]+d[i>>>16&15]+d[i>>>12&15]+d[i>>>8&15]+d[i>>>4&15]+d[15&i]+d[r>>>28&15]+d[r>>>24&15]+d[r>>>20&15]+d[r>>>16&15]+d[r>>>12&15]+d[r>>>8&15]+d[r>>>4&15]+d[15&r]+d[n>>>28&15]+d[n>>>24&15]+d[n>>>20&15]+d[n>>>16&15]+d[n>>>12&15]+d[n>>>8&15]+d[n>>>4&15]+d[15&n]+d[s>>>28&15]+d[s>>>24&15]+d[s>>>20&15]+d[s>>>16&15]+d[s>>>12&15]+d[s>>>8&15]+d[s>>>4&15]+d[15&s]+d[o>>>28&15]+d[o>>>24&15]+d[o>>>20&15]+d[o>>>16&15]+d[o>>>12&15]+d[o>>>8&15]+d[o>>>4&15]+d[15&o];return this.is224||(h+=d[a>>>28&15]+d[a>>>24&15]+d[a>>>20&15]+d[a>>>16&15]+d[a>>>12&15]+d[a>>>8&15]+d[a>>>4&15]+d[15&a]),h},A.prototype.toString=A.prototype.hex,A.prototype.digest=function(){this.finalize();var t=this.h0,e=this.h1,i=this.h2,r=this.h3,n=this.h4,s=this.h5,o=this.h6,a=this.h7,h=[t>>>24&255,t>>>16&255,t>>>8&255,255&t,e>>>24&255,e>>>16&255,e>>>8&255,255&e,i>>>24&255,i>>>16&255,i>>>8&255,255&i,r>>>24&255,r>>>16&255,r>>>8&255,255&r,n>>>24&255,n>>>16&255,n>>>8&255,255&n,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o>>>24&255,o>>>16&255,o>>>8&255,255&o];return this.is224||h.push(a>>>24&255,a>>>16&255,a>>>8&255,255&a),h},A.prototype.array=A.prototype.digest,A.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(this.is224?28:32),e=new DataView(t);return e.setUint32(0,this.h0),e.setUint32(4,this.h1),e.setUint32(8,this.h2),e.setUint32(12,this.h3),e.setUint32(16,this.h4),e.setUint32(20,this.h5),e.setUint32(24,this.h6),this.is224||e.setUint32(28,this.h7),t},T.prototype=new A,T.prototype.finalize=function(){if(A.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();A.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(t),A.prototype.finalize.call(this)}};var C=m();C.sha256=C,C.sha224=m(!0),C.sha256.hmac=b(),C.sha224.hmac=b(!0),h?t.exports=C:(s.sha256=C.sha256,s.sha224=C.sha224,c&&(void 0===(r=function(){return C}.call(C,i,C,t))||(t.exports=r)))}()},903:()=>{},394:()=>{}},e={};function i(r){var n=e[r];if(void 0!==n)return n.exports;var s=e[r]={exports:{}};return t[r](s,s.exports,i),s.exports}i.amdO={},i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{"use strict";var t=i(396),e=i.n(t);const r=JSON.parse('{"r":"0.0.0-experimental"}'),n={insecure:!1,cookies:!0,initPassport:!0};async function s(t){const e=await a("/config",t,{method:"GET",headers:{Accept:"application/json"}});return new o(t).setSite(e),e}class o{constructor(t){this.Config=t,e()(this,"passportKey",void 0),e()(this,"targetingV1Key",void 0),e()(this,"targetingKey",void 0),e()(this,"siteKey",void 0);const i=btoa(function(t){const e=new Uint16Array(t.length);for(let i=0;i<e.length;i++)e[i]=t.charCodeAt(i);return String.fromCharCode(...new Uint8Array(e.buffer))}(`${this.Config.host}/${this.Config.site}`));this.targetingV1Key="OPTABLE_TGT_"+i,this.passportKey="OPTABLE_PASS_"+i,this.targetingKey="OPTABLE_V2_TGT_"+i,this.siteKey="OPTABLE_SITE_"+i}getPassport(){return window.localStorage.getItem(this.passportKey)}getV1Targeting(){const t=window.localStorage.getItem(this.targetingV1Key),e=t?JSON.parse(t):null;return e?{user:[],audience:Object.entries(e).map((t=>{let[e,i]=t;return{provider:"optable.co",keyspace:e,rtb_segtax:5001,ids:[].concat(i).map((t=>({id:String(t)})))}}))}:null}getTargeting(){const t=window.localStorage.getItem(this.targetingKey);return(t?JSON.parse(t):null)||this.getV1Targeting()}setPassport(t){t&&t.length>0&&window.localStorage.setItem(this.passportKey,t)}setTargeting(t){t&&window.localStorage.setItem(this.targetingKey,JSON.stringify(t))}setSite(t){t&&window.localStorage.setItem(this.siteKey,JSON.stringify(t))}getSite(){const t=window.localStorage.getItem(this.siteKey);return t?JSON.parse(t):null}clearPassport(){window.localStorage.removeItem(this.passportKey)}clearTargeting(){window.localStorage.removeItem(this.targetingKey)}clearSite(){window.localStorage.removeItem(this.siteKey)}}async function a(t,e,i){const n=await globalThis.fetch(function(t,e,i){const{site:n,host:s,insecure:a,cookies:h}=e,c=new URL(`${n}${t}`,`${a?"http":"https"}://${s}`);if(c.searchParams.set("osdk",`web-${r.r}`),h)c.searchParams.set("cookies","yes");else{const t=new o(e).getPassport();c.searchParams.set("cookies","no"),c.searchParams.set("passport",t||"")}const u={...i};return u.credentials="include",new Request(c.toString(),u)}(t,e,i)),s=n.headers.get("Content-Type"),a=s?.startsWith("application/json")?await n.json():await n.text();if(!n.ok)throw new Error(a.error);return a.passport&&(new o(e).setPassport(a.passport),delete a.passport),a}var h;function c(t){return{user:{data:(t?.audience??[]).map((t=>({name:t.provider,segment:t.ids,ext:{segtax:t.rtb_segtax}}))),ext:{eids:(t?.user??[]).map((t=>({source:t.provider,uids:t.ids.map((t=>{let{id:e}=t;return{id:e,atype:h.PersonID}}))})))}}}}function u(t){const e={};if(!t)return e;for(const i of t.audience??[])i.keyspace&&(i.keyspace in e||(e[i.keyspace]=[]),e[i.keyspace].push(...i.ids.map((t=>t.id))));return e}!function(t){t[t.DeviceID=1]="DeviceID",t[t.InAppImpression=2]="InAppImpression",t[t.PersonID=3]="PersonID"}(h||(h={}));var d=i(312);class p{constructor(t){var i;e()(this,"dcn",void 0),e()(this,"init",void 0),this.dcn=(i=t,{...n,...i});const r=()=>{};this.init=this.dcn.initPassport?s(this.dcn).then(r).catch(r):Promise.resolve()}async identify(){await this.init;for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return function(t,e){return a("/identify",t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}(this.dcn,e.filter((t=>t)))}async uid2Token(t){return await this.init,function(t,e){return a("/uid2/token",t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}(this.dcn,t)}async targeting(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"__passport__";return await this.init,async function(t,e){const i="/v2/targeting?"+new URLSearchParams({id:e}).toString(),r=await a(i,t,{method:"GET",headers:{Accept:"application/json"}});return r&&new o(t).setTargeting(r),r}(this.dcn,t)}targetingFromCache(){return t=this.dcn,new o(t).getTargeting();var t}async site(){return s(this.dcn)}siteFromCache(){return t=this.dcn,new o(t).getSite();var t}targetingClearCache(){var t;t=this.dcn,new o(t).clearTargeting()}async prebidORTB2(){return c(await this.targeting())}prebidORTB2FromCache(){return c(this.targetingFromCache())}async targetingKeyValues(){return u(await this.targeting())}targetingKeyValuesFromCache(){return u(this.targetingFromCache())}async witness(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return await this.init,function(t,e,i){const r={event:e,properties:i};return a("/witness",t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})}(this.dcn,t,e)}async profile(t){return await this.init,function(t,e){const i={traits:e};return a("/profile",t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}(this.dcn,t)}async tokenize(t){return await this.init,function(t,e){let i={id:e};return a("/v1/tokenize",t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}(this.dcn,t)}static eid(t){return t?"e:"+d.sha256.hex(t.toLowerCase().trim()):""}static sha256(t){return t?d.sha256.hex(t):""}static cid(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i="c:";if("string"!=typeof t)throw new Error("Invalid ppid");if("number"!=typeof e||isNaN(e)||e<0||e>9)throw new Error("Invalid variant");return e>0&&(i=`c${e}:`),t?i+t.trim():""}static TargetingKeyValues(t){return u(t)}static PrebidORTB2(t){return c(t)}}e()(p,"version",r.r);const l=p;function f(t){return{advertiserId:t.advertiserId?.toString(),campaignId:t.campaignId?.toString(),creativeId:t.creativeId?.toString(),isEmpty:t.isEmpty?.toString(),lineItemId:t.lineItemId?.toString(),serviceName:t.serviceName?.toString(),size:t.size?.toString(),slotElementId:t.slot?.getSlotElementId(),sourceAgnosticCreativeId:t.sourceAgnosticCreativeId?.toString(),sourceAgnosticLineItemId:t.sourceAgnosticLineItemId?.toString()}}l.prototype.installGPTEventListeners=function(){const t=this;t.installGPTEventListeners=function(){},window.googletag=window.googletag||{cmd:[]};const e=window.googletag;e.cmd.push((function(){e.pubads().addEventListener("slotRenderEnded",(function(e){t.witness("googletag.events.slotRenderEnded",f(e))})),e.pubads().addEventListener("impressionViewable",(function(e){t.witness("googletag.events.impressionViewable",f(e))}))}))},l.prototype.installGPTSecureSignals=function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];window.googletag=window.googletag||{cmd:[]};const r=window.googletag;e&&e.length>0&&r.cmd.push((()=>{e.forEach((t=>{let{provider:e,id:i}=t;r.secureSignalProviders.push({id:e,collectorFunction:()=>Promise.resolve(i)})}))}))};const g=/^[a-f0-9]{64}$/i;l.prototype.tryIdentifyFromParams=function(t,e){const i=new RegExp(`^${t||"oeid"}$`,"i"),r=new URLSearchParams(window.location.search);let n="";for(const[t,e]of r)if(i.test(t)){n=e;break}""!=n&&(e||function(t){return g.test(t)}(n))&&this.identify((e||"e")+":"+n.toLowerCase())},l.prototype.auctionConfigFromCache=function(){const t=this.siteFromCache();return t?t.auctionConfig??null:null},l.prototype.installGPTAuctionConfigs=function(t){const e=this;e.installGPTAuctionConfigs=function(){},window.googletag=window.googletag||{cmd:[]};const i=window.googletag;i.cmd.push((function(){let r=i.pubads().getSlots();t&&(r=r.filter(t));const n=e.auctionConfigFromCache();if(n)for(const t of r){const e=t.getSizes(),i=[];for(const t of e)"fluid"!==t&&i.push({configKey:n.seller+"-"+t.getWidth()+"x"+t.getHeight(),auctionConfig:{...n,requestedSize:{width:t.getWidth()+"px",height:t.getHeight()+"px"}}});t.setConfig({componentAuction:i})}}))},l.prototype.runAdAuction=async function(t,e){if(!("runAdAuction"in navigator))throw"run-ad-auction not supported";const i=document.getElementById(t);if(!i)throw"spot not found";const r=function(t){const e=window.getComputedStyle(t,null);return{width:e.getPropertyValue("width"),height:e.getPropertyValue("height")}}(i),n=this.auctionConfigFromCache();if(!n)return!1;const s={...n,requestedSize:r,resolveToConfig:!0},o=e?.iframe??!1;o&&(s.resolveToConfig=!1);const a=await navigator.runAdAuction(s);if(!a)return i.replaceChildren(),!1;if(o){const t=document.createElement("iframe");t.src=a,t.style.border="none",t.style.width=r.width,t.style.height=r.height,i.replaceChildren(t)}else{const t=document.createElement("fencedframe");t.config=a,t.style.border="none",i.replaceChildren(t)}return!0},l.prototype.joinAdInterestGroups=async function(){if(!("joinAdInterestGroup"in navigator))throw"join-ad-interest-group not supported";const t=await this.site();if(!t.interestGroupPixel)throw"origin not enabled for protected audience apis";const e=new URL(t.interestGroupPixel),i=document.createElement("iframe");i.src=e.toString(),i.allow="join-ad-interest-group "+e.origin,i.style.display="none";const r=new Promise(((t,e)=>{window.addEventListener("message",(r=>{r.source===i.contentWindow&&("success"!==r.data.result?e():t())}))}));return document.body.appendChild(i),r},l.prototype.getTopics=async function(){if(!("browsingTopics"in document))throw"browsing-topics not supported";const t=await this.site();if(!t.getTopicsURL)throw"origin not enabled for topics api";const e=new URL(t.getTopicsURL),i=document.createElement("iframe");i.src=e.toString(),i.allow="browsing-topics "+e.origin,i.style.display="none";const r=new Promise(((t,e)=>{window.addEventListener("message",(r=>{r.source===i.contentWindow&&(r.data.error?e(new Error(r.data.error.toString())):t(r.data.result))}))}));return document.body.appendChild(i),r},l.prototype.ingestTopics=function(){this.getTopics().then((t=>{if(!t.length)return;const e=t.reduce(((t,e)=>{const i=`topics_v${e.taxonomyVersion}`;return t[i]?t[i]+=",":t[i]="",t[i]+=String(e.topic),t}),{});this.profile(e)})).catch((()=>{}))},window.optable=window.optable||{},window.optable.SDK=l,window.optable.cmd=new class{constructor(t){if(this.cmds=t,Array.isArray(this.cmds))for(const t of this.cmds)"function"==typeof t&&t()}push(t){t()}}(window.optable.cmd||[])})()})();
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { default as buildInfo } from "./build.json";
|
|
11
|
+
import { getConfig } from "./config";
|
|
12
|
+
import { Identify } from "./edge/identify";
|
|
13
|
+
import { Uid2Token } from "./edge/uid2_token";
|
|
14
|
+
import { Site, SiteFromCache } from "./edge/site";
|
|
15
|
+
import { TargetingKeyValues, Targeting, TargetingFromCache, TargetingClearCache, PrebidORTB2, } from "./edge/targeting";
|
|
16
|
+
import { Witness } from "./edge/witness";
|
|
17
|
+
import { Profile } from "./edge/profile";
|
|
18
|
+
import { sha256 } from "js-sha256";
|
|
19
|
+
import { Tokenize } from "./edge/tokenize";
|
|
20
|
+
class OptableSDK {
|
|
21
|
+
constructor(dcn) {
|
|
22
|
+
this.dcn = getConfig(dcn);
|
|
23
|
+
// If initPassport, prefetch site config and cache it, it assigns a passport as a side effect
|
|
24
|
+
const noop = () => { };
|
|
25
|
+
this.init = this.dcn.initPassport ? Site(this.dcn).then(noop).catch(noop) : Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
identify(...ids) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
yield this.init;
|
|
30
|
+
return Identify(this.dcn, ids.filter((id) => id));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
uid2Token(id) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield this.init;
|
|
36
|
+
return Uid2Token(this.dcn, id);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
targeting(id = "__passport__") {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
yield this.init;
|
|
42
|
+
return Targeting(this.dcn, id);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
targetingFromCache() {
|
|
46
|
+
return TargetingFromCache(this.dcn);
|
|
47
|
+
}
|
|
48
|
+
site() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return Site(this.dcn);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
siteFromCache() {
|
|
54
|
+
return SiteFromCache(this.dcn);
|
|
55
|
+
}
|
|
56
|
+
targetingClearCache() {
|
|
57
|
+
TargetingClearCache(this.dcn);
|
|
58
|
+
}
|
|
59
|
+
prebidORTB2() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
return PrebidORTB2(yield this.targeting());
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
prebidORTB2FromCache() {
|
|
65
|
+
const tdata = this.targetingFromCache();
|
|
66
|
+
return PrebidORTB2(tdata);
|
|
67
|
+
}
|
|
68
|
+
targetingKeyValues() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
return TargetingKeyValues(yield this.targeting());
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
targetingKeyValuesFromCache() {
|
|
74
|
+
const tdata = this.targetingFromCache();
|
|
75
|
+
return TargetingKeyValues(tdata);
|
|
76
|
+
}
|
|
77
|
+
witness(event, properties = {}) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
yield this.init;
|
|
80
|
+
return Witness(this.dcn, event, properties);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
profile(traits) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
yield this.init;
|
|
86
|
+
return Profile(this.dcn, traits);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
tokenize(id) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
yield this.init;
|
|
92
|
+
return Tokenize(this.dcn, id);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
static eid(email) {
|
|
96
|
+
return email ? "e:" + sha256.hex(email.toLowerCase().trim()) : "";
|
|
97
|
+
}
|
|
98
|
+
static sha256(string) {
|
|
99
|
+
return string ? sha256.hex(string) : "";
|
|
100
|
+
}
|
|
101
|
+
static cid(ppid, variant = 0) {
|
|
102
|
+
let prefix = "c:";
|
|
103
|
+
if (typeof ppid !== "string") {
|
|
104
|
+
throw new Error("Invalid ppid");
|
|
105
|
+
}
|
|
106
|
+
if (typeof variant !== "number" || isNaN(variant) || variant < 0 || variant > 9) {
|
|
107
|
+
throw new Error("Invalid variant");
|
|
108
|
+
}
|
|
109
|
+
if (variant > 0) {
|
|
110
|
+
prefix = `c${variant}:`;
|
|
111
|
+
}
|
|
112
|
+
return ppid ? prefix + ppid.trim() : "";
|
|
113
|
+
}
|
|
114
|
+
static TargetingKeyValues(tdata) {
|
|
115
|
+
return TargetingKeyValues(tdata);
|
|
116
|
+
}
|
|
117
|
+
static PrebidORTB2(tdata) {
|
|
118
|
+
return PrebidORTB2(tdata);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
OptableSDK.version = buildInfo.version;
|
|
122
|
+
export { OptableSDK };
|
|
123
|
+
export default OptableSDK;
|
package/package.json
CHANGED