From a8f239c988133d57eb944e2427f04da9502b017d Mon Sep 17 00:00:00 2001 From: Nikola Milekic <45809529+Nikola-Milekic@users.noreply.github.com> Date: Thu, 12 Oct 2023 12:53:56 -0400 Subject: [PATCH] Add init flag to config (#61) --- .circleci/config.yml | 2 ++ Makefile | 35 ++++++++++--------- .../protected-audience/advertiser.html.tpl | 2 ++ demos/integration/lmpid-prebid-gpt.html.tpl | 1 + demos/integration/lmpid-signal-gpt.html.tpl | 1 + demos/react/webpack.config.js | 1 + demos/vanilla/identify.html.tpl | 1 + demos/vanilla/nocookies/identify.html.tpl | 1 + demos/vanilla/nocookies/profile.html.tpl | 1 + .../targeting/gam360-cached.html.tpl | 1 + .../nocookies/targeting/gam360.html.tpl | 1 + .../nocookies/targeting/prebid.html.tpl | 1 + demos/vanilla/nocookies/witness.html.tpl | 1 + demos/vanilla/profile.html.tpl | 1 + .../vanilla/targeting/gam360-cached.html.tpl | 1 + demos/vanilla/targeting/gam360.html.tpl | 1 + demos/vanilla/targeting/prebid.html.tpl | 1 + demos/vanilla/uid2_token/login.html.tpl | 1 + demos/vanilla/witness.html.tpl | 1 + lib/addons/try-identify.test.js | 2 +- lib/config.ts | 2 ++ lib/core/network.ts | 7 ++-- lib/edge/identify.ts | 2 +- lib/edge/init.ts | 2 +- lib/edge/profile.ts | 2 +- lib/edge/site.ts | 2 +- lib/edge/targeting.ts | 8 ++--- lib/edge/uid2_token.ts | 2 +- lib/edge/witness.ts | 2 +- lib/sdk.ts | 9 ++--- 30 files changed, 59 insertions(+), 36 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2f2c26d0..abb34836 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,6 +43,7 @@ jobs: SDK_URI: https://cdn.optable.co/web-sdk/latest/sdk.js SANDBOX_HOST: sandbox.optable.co SANDBOX_INSECURE: "false" + SANDBOX_INIT: "true" UID2_BASE_URL: https://prod.uidapi.com steps: - checkout @@ -55,6 +56,7 @@ jobs: export SDK_URI="https://cdn.optable.co/web-sdk/${CIRCLE_TAG}/sdk.js" export SANDBOX_HOST="sandbox.optable.co" export SANDBOX_INSECURE="false" + export SANDBOX_INIT="true" export UID2_BASE_URL="https://prod.uidapi.com" make -j --output-sync - persist_to_workspace: diff --git a/Makefile b/Makefile index e2e117ce..b240117b 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ deps: export SDK_URI ?= https://localhost:8181/sdk.js export SANDBOX_HOST ?= sandbox.optable.co export SANDBOX_INSECURE ?= false +export SANDBOX_INIT ?= true export ADS_HOST ?= ads.optable.co export UID2_BASE_URL ?= https://operator-integ.uidapi.com @@ -30,24 +31,24 @@ demos: demo-html demo-react demo-npm .PHONY: demo-html demo-html: - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/identify.html.tpl > demos/vanilla/identify.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/witness.html.tpl > demos/vanilla/witness.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/profile.html.tpl > demos/vanilla/profile.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/targeting/gam360.html.tpl > demos/vanilla/targeting/gam360.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/targeting/gam360-cached.html.tpl > demos/vanilla/targeting/gam360-cached.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/targeting/prebid.html.tpl > demos/vanilla/targeting/prebid.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/nocookies/identify.html.tpl > demos/vanilla/nocookies/identify.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/nocookies/witness.html.tpl > demos/vanilla/nocookies/witness.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/nocookies/profile.html.tpl > demos/vanilla/nocookies/profile.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/nocookies/targeting/gam360.html.tpl > demos/vanilla/nocookies/targeting/gam360.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/nocookies/targeting/gam360-cached.html.tpl > demos/vanilla/nocookies/targeting/gam360-cached.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/vanilla/nocookies/targeting/prebid.html.tpl > demos/vanilla/nocookies/targeting/prebid.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/integration/lmpid-prebid-gpt.html.tpl > demos/integration/lmpid-prebid-gpt.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/integration/lmpid-signal-gpt.html.tpl > demos/integration/lmpid-signal-gpt.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE}' < demos/ads/protected-audience/advertiser.html.tpl > demos/ads/protected-audience/advertiser.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/identify.html.tpl > demos/vanilla/identify.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/witness.html.tpl > demos/vanilla/witness.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/profile.html.tpl > demos/vanilla/profile.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/targeting/gam360.html.tpl > demos/vanilla/targeting/gam360.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/targeting/gam360-cached.html.tpl > demos/vanilla/targeting/gam360-cached.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/targeting/prebid.html.tpl > demos/vanilla/targeting/prebid.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/nocookies/identify.html.tpl > demos/vanilla/nocookies/identify.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/nocookies/witness.html.tpl > demos/vanilla/nocookies/witness.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/nocookies/profile.html.tpl > demos/vanilla/nocookies/profile.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/nocookies/targeting/gam360.html.tpl > demos/vanilla/nocookies/targeting/gam360.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/nocookies/targeting/gam360-cached.html.tpl > demos/vanilla/nocookies/targeting/gam360-cached.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/vanilla/nocookies/targeting/prebid.html.tpl > demos/vanilla/nocookies/targeting/prebid.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/integration/lmpid-prebid-gpt.html.tpl > demos/integration/lmpid-prebid-gpt.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/integration/lmpid-signal-gpt.html.tpl > demos/integration/lmpid-signal-gpt.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT}' < demos/ads/protected-audience/advertiser.html.tpl > demos/ads/protected-audience/advertiser.html envsubst '$${ADS_HOST}' < demos/ads/protected-audience/publisher.html.tpl > demos/ads/protected-audience/publisher.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${UID2_BASE_URL}' < demos/vanilla/uid2_token/login.html.tpl > demos/vanilla/uid2_token/login.html - envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${UID2_BASE_URL}' < demos/vanilla/uid2_token/index.html.tpl > demos/vanilla/uid2_token/index.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT} $${UID2_BASE_URL}' < demos/vanilla/uid2_token/login.html.tpl > demos/vanilla/uid2_token/login.html + envsubst '$${SDK_URI} $${SANDBOX_HOST} $${SANDBOX_INSECURE} $${SANDBOX_INIT} $${UID2_BASE_URL}' < demos/vanilla/uid2_token/index.html.tpl > demos/vanilla/uid2_token/index.html .PHONY: demo-react demo-react: build-lib diff --git a/demos/ads/protected-audience/advertiser.html.tpl b/demos/ads/protected-audience/advertiser.html.tpl index 12939943..d62346f8 100644 --- a/demos/ads/protected-audience/advertiser.html.tpl +++ b/demos/ads/protected-audience/advertiser.html.tpl @@ -34,6 +34,7 @@ window.optable = window.optable || { cmd: [] }; optable.cmd.push(() => { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: ${SANDBOX_INSECURE}, cookies: cookiesTransport, @@ -52,6 +53,7 @@ optable.cmd.push(() => { optable.cmd.push(() => { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: cookiesTransport, diff --git a/demos/integration/lmpid-prebid-gpt.html.tpl b/demos/integration/lmpid-prebid-gpt.html.tpl index 7b68115f..9b6571a7 100644 --- a/demos/integration/lmpid-prebid-gpt.html.tpl +++ b/demos/integration/lmpid-prebid-gpt.html.tpl @@ -276,6 +276,7 @@ olivia.anderson@acme.test optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: cookiesTransport, diff --git a/demos/integration/lmpid-signal-gpt.html.tpl b/demos/integration/lmpid-signal-gpt.html.tpl index a54e79e0..15bd6bfc 100644 --- a/demos/integration/lmpid-signal-gpt.html.tpl +++ b/demos/integration/lmpid-signal-gpt.html.tpl @@ -222,6 +222,7 @@ olivia.anderson@acme.test optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: (new URLSearchParams(window.location.search)).get("cookies") === "yes", diff --git a/demos/react/webpack.config.js b/demos/react/webpack.config.js index 5414ec61..d0cb7ccb 100644 --- a/demos/react/webpack.config.js +++ b/demos/react/webpack.config.js @@ -27,6 +27,7 @@ module.exports = { new webpack.DefinePlugin({ SANDBOX_CONFIG: JSON.stringify({ host: process.env.SANDBOX_HOST, + initPassport: process.env.SANDBOX_INIT === "true", site: "web-sdk-demo", insecure: process.env.SANDBOX_INSECURE === "true", }), diff --git a/demos/vanilla/identify.html.tpl b/demos/vanilla/identify.html.tpl index dd69e3f0..0151a7fa 100644 --- a/demos/vanilla/identify.html.tpl +++ b/demos/vanilla/identify.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), }); diff --git a/demos/vanilla/nocookies/identify.html.tpl b/demos/vanilla/nocookies/identify.html.tpl index 34e89416..be202577 100644 --- a/demos/vanilla/nocookies/identify.html.tpl +++ b/demos/vanilla/nocookies/identify.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: false, diff --git a/demos/vanilla/nocookies/profile.html.tpl b/demos/vanilla/nocookies/profile.html.tpl index 2f7c3a33..193362b4 100644 --- a/demos/vanilla/nocookies/profile.html.tpl +++ b/demos/vanilla/nocookies/profile.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: false, diff --git a/demos/vanilla/nocookies/targeting/gam360-cached.html.tpl b/demos/vanilla/nocookies/targeting/gam360-cached.html.tpl index d4084f02..53af68ed 100644 --- a/demos/vanilla/nocookies/targeting/gam360-cached.html.tpl +++ b/demos/vanilla/nocookies/targeting/gam360-cached.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: false, diff --git a/demos/vanilla/nocookies/targeting/gam360.html.tpl b/demos/vanilla/nocookies/targeting/gam360.html.tpl index 1f5818cd..f109c0f4 100644 --- a/demos/vanilla/nocookies/targeting/gam360.html.tpl +++ b/demos/vanilla/nocookies/targeting/gam360.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: false, diff --git a/demos/vanilla/nocookies/targeting/prebid.html.tpl b/demos/vanilla/nocookies/targeting/prebid.html.tpl index bcfbb00f..c2292f7f 100644 --- a/demos/vanilla/nocookies/targeting/prebid.html.tpl +++ b/demos/vanilla/nocookies/targeting/prebid.html.tpl @@ -24,6 +24,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: false, diff --git a/demos/vanilla/nocookies/witness.html.tpl b/demos/vanilla/nocookies/witness.html.tpl index eb1b0028..a9f4e744 100644 --- a/demos/vanilla/nocookies/witness.html.tpl +++ b/demos/vanilla/nocookies/witness.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), cookies: false, diff --git a/demos/vanilla/profile.html.tpl b/demos/vanilla/profile.html.tpl index 13071bc3..b92fc4b4 100644 --- a/demos/vanilla/profile.html.tpl +++ b/demos/vanilla/profile.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), }); diff --git a/demos/vanilla/targeting/gam360-cached.html.tpl b/demos/vanilla/targeting/gam360-cached.html.tpl index 36427d5e..8b4c6a10 100644 --- a/demos/vanilla/targeting/gam360-cached.html.tpl +++ b/demos/vanilla/targeting/gam360-cached.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), }); diff --git a/demos/vanilla/targeting/gam360.html.tpl b/demos/vanilla/targeting/gam360.html.tpl index 25a0d95d..d7bd8a2b 100644 --- a/demos/vanilla/targeting/gam360.html.tpl +++ b/demos/vanilla/targeting/gam360.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), }); diff --git a/demos/vanilla/targeting/prebid.html.tpl b/demos/vanilla/targeting/prebid.html.tpl index 6e079c3c..78fb9212 100644 --- a/demos/vanilla/targeting/prebid.html.tpl +++ b/demos/vanilla/targeting/prebid.html.tpl @@ -24,6 +24,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), }); diff --git a/demos/vanilla/uid2_token/login.html.tpl b/demos/vanilla/uid2_token/login.html.tpl index 6d3f319c..f931fb88 100644 --- a/demos/vanilla/uid2_token/login.html.tpl +++ b/demos/vanilla/uid2_token/login.html.tpl @@ -20,6 +20,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), }); diff --git a/demos/vanilla/witness.html.tpl b/demos/vanilla/witness.html.tpl index 6320b5f5..b0e99d13 100644 --- a/demos/vanilla/witness.html.tpl +++ b/demos/vanilla/witness.html.tpl @@ -18,6 +18,7 @@ optable.cmd.push(function () { optable.instance = new optable.SDK({ host: "${SANDBOX_HOST}", + initPassport: JSON.parse("${SANDBOX_INIT}"), site: "web-sdk-demo", insecure: JSON.parse("${SANDBOX_INSECURE}"), }); diff --git a/lib/addons/try-identify.test.js b/lib/addons/try-identify.test.js index 7846575c..a67e63d8 100644 --- a/lib/addons/try-identify.test.js +++ b/lib/addons/try-identify.test.js @@ -6,7 +6,7 @@ describe("tryIdentifyFromParams", () => { beforeEach(() => { delete window.location; - SDK = new OptableSDK({ host: "localhost", site: "test" }, false); + SDK = new OptableSDK({ host: "localhost", site: "test" }); SDK.identify = jest.fn(); }); diff --git a/lib/config.ts b/lib/config.ts index 6f7d3a4f..30b5e567 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -3,11 +3,13 @@ type OptableConfig = { site: string; insecure?: boolean; cookies?: boolean; + initPassport?: boolean; }; const SANDBOX_DEFAULTS = { insecure: false, cookies: true, + initPassport: true, }; function getConfig(config: OptableConfig): Required { diff --git a/lib/core/network.ts b/lib/core/network.ts index 5c2652de..e52dd6ef 100644 --- a/lib/core/network.ts +++ b/lib/core/network.ts @@ -1,10 +1,9 @@ import type { OptableConfig } from "../config"; -import { getConfig } from "../config"; import { default as buildInfo } from "../build.json"; import { LocalStorage } from "./storage"; -function buildRequest(path: string, config: OptableConfig, init?: RequestInit): Request { - const { site, host, insecure, cookies } = getConfig(config); +function buildRequest(path: string, config: Required, init?: RequestInit): Request { + const { site, host, insecure, cookies } = config; const proto = insecure ? "http" : "https"; const url = new URL(`${site}${path}`, `${proto}://${host}`); @@ -32,7 +31,7 @@ function buildRequest(path: string, config: OptableConfig, init?: RequestInit): return request; } -async function fetch(path: string, config: OptableConfig, init?: RequestInit): Promise { +async function fetch(path: string, config: Required, init?: RequestInit): Promise { const response = await window.fetch(buildRequest(path, config, init)); const contentType = response.headers.get("Content-Type"); diff --git a/lib/edge/identify.ts b/lib/edge/identify.ts index 5a2b5ce3..dcd44231 100644 --- a/lib/edge/identify.ts +++ b/lib/edge/identify.ts @@ -1,7 +1,7 @@ import type { OptableConfig } from "../config"; import { fetch } from "../core/network"; -function Identify(config: OptableConfig, ids: string[]): Promise { +function Identify(config: Required, ids: string[]): Promise { return fetch("/identify", config, { method: "POST", headers: { diff --git a/lib/edge/init.ts b/lib/edge/init.ts index 9a71e621..56a945c1 100644 --- a/lib/edge/init.ts +++ b/lib/edge/init.ts @@ -1,7 +1,7 @@ import type { OptableConfig } from "../config"; import { fetch } from "../core/network"; -function Init(config: OptableConfig): Promise { +function Init(config: Required): Promise { return fetch("/init", config, { method: "POST", headers: { diff --git a/lib/edge/profile.ts b/lib/edge/profile.ts index 3e12e292..d49b6c16 100644 --- a/lib/edge/profile.ts +++ b/lib/edge/profile.ts @@ -5,7 +5,7 @@ type ProfileTraits = { [key: string]: string | number | boolean; }; -function Profile(config: OptableConfig, traits: ProfileTraits): Promise { +function Profile(config: Required, traits: ProfileTraits): Promise { const profile = { traits: traits, }; diff --git a/lib/edge/site.ts b/lib/edge/site.ts index 6c9c6308..3d21d550 100644 --- a/lib/edge/site.ts +++ b/lib/edge/site.ts @@ -5,7 +5,7 @@ type SiteResponse = { interestGroupPixel: string; }; -async function Site(config: OptableConfig): Promise { +async function Site(config: Required): Promise { return await fetch("/config", config, { method: "GET", headers: { "Content-Type": "application/json" }, diff --git a/lib/edge/targeting.ts b/lib/edge/targeting.ts index e9e8dc3b..9692bf4e 100644 --- a/lib/edge/targeting.ts +++ b/lib/edge/targeting.ts @@ -26,7 +26,7 @@ type TargetingResponse = { const lmpidProvider = "loblawmedia.ca" -async function Targeting(config: OptableConfig): Promise { +async function Targeting(config: Required): Promise { const response: TargetingResponse = await fetch("/v2/targeting", config, { method: "GET", headers: { @@ -42,17 +42,17 @@ async function Targeting(config: OptableConfig): Promise { return response; } -function LmpidFromCache(config: OptableConfig): string | null { +function LmpidFromCache(config: Required): string | null { const ls = new LocalStorage(config); return ls.getLmpid(); } -function TargetingFromCache(config: OptableConfig): TargetingResponse | null { +function TargetingFromCache(config: Required): TargetingResponse | null { const ls = new LocalStorage(config); return ls.getTargeting(); } -function TargetingClearCache(config: OptableConfig) { +function TargetingClearCache(config: Required) { const ls = new LocalStorage(config); ls.clearTargeting(); } diff --git a/lib/edge/uid2_token.ts b/lib/edge/uid2_token.ts index f10cb35f..6f02fb11 100644 --- a/lib/edge/uid2_token.ts +++ b/lib/edge/uid2_token.ts @@ -10,7 +10,7 @@ type Uid2TokenResponse = { RefreshResponseKey: string; }; -function Uid2Token(config: OptableConfig, id: string): Promise { +function Uid2Token(config: Required, id: string): Promise { return fetch("/uid2/token", config, { method: "POST", headers: { diff --git a/lib/edge/witness.ts b/lib/edge/witness.ts index 8e83df66..4a6d5a7e 100644 --- a/lib/edge/witness.ts +++ b/lib/edge/witness.ts @@ -5,7 +5,7 @@ type WitnessProperties = { [key: string]: string | number | boolean; }; -function Witness(config: OptableConfig, event: string, properties: WitnessProperties): Promise { +function Witness(config: Required, event: string, properties: WitnessProperties): Promise { const evt = { event: event, properties: properties, diff --git a/lib/sdk.ts b/lib/sdk.ts index e17bdced..9d4133b6 100644 --- a/lib/sdk.ts +++ b/lib/sdk.ts @@ -1,4 +1,5 @@ import type { OptableConfig } from "./config"; +import { getConfig } from "./config"; import type { WitnessProperties } from "./edge/witness"; import type { ProfileTraits } from "./edge/profile"; import { Identify } from "./edge/identify"; @@ -19,12 +20,12 @@ import { Profile } from "./edge/profile"; import { sha256 } from "js-sha256"; class OptableSDK { - public sandbox: OptableConfig; // legacy + public dcn: Required; private init: any - constructor(public dcn: OptableConfig, writePassport: boolean = true) { - this.sandbox = dcn; // legacy - this.init = writePassport ? Init(dcn).catch(()=>{}) : Promise.resolve(); + constructor(dcn: OptableConfig) { + this.dcn = getConfig(dcn); + this.init = this.dcn.initPassport ? Init(this.dcn).catch(()=>{}) : Promise.resolve(); } async identify(...ids: string[]) {