Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getConsent, inferRegulation } from "./core/regs/consent";
import type { CMPApiConfig, Consent } from "./core/regs/consent";

type Experiment = "tokenize-v2";
type Experiment = "tokenize-v2" | "targeting-cascade";

type InitConsent = {
// A "cmpapi" configuration indicating that consent should be gathered from CMP apis.
Expand Down
2 changes: 1 addition & 1 deletion lib/edge/targeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TargetingResponse = {
ortb2: { user: ortb2.User };
};

async function Targeting(config: ResolvedConfig, ...ids: readonly string[]): Promise<TargetingResponse> {
async function Targeting(config: ResolvedConfig, ids: readonly string[]): Promise<TargetingResponse> {
const searchParams = new URLSearchParams(ids.map((id) => ["id", id]));
const path = "/v2/targeting?" + searchParams.toString();

Expand Down
6 changes: 4 additions & 2 deletions lib/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,10 @@ describe("behavior testing of", () => {
})
);

const targetingWithParam = await sdk.targeting("someId", "someOtherId");
expect(targetingWithParam).toBeDefined();
await expect(sdk.targeting({ ids: ["someId", "someOtherId"] })).rejects.toMatch(/targeting-cascade/);

sdk.dcn.experiments = ["targeting-cascade"];
const targetingWithParam = await sdk.targeting({ ids: ["someId", "someOtherId"] });

expect(fetchSpy).toHaveBeenLastCalledWith(
expect.objectContaining({
Expand Down
16 changes: 12 additions & 4 deletions lib/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { Profile } from "./edge/profile";
import { sha256 } from "js-sha256";
import { Tokenize, TokenizeResponse } from "./edge/tokenize";

type TargetingRequest =
| string
| {
ids?: string[];
};

class OptableSDK {
public static version = buildInfo.version;

Expand Down Expand Up @@ -54,13 +60,15 @@ class OptableSDK {
return Uid2Token(this.dcn, id);
}

async targeting(...ids: string[]): Promise<TargetingResponse> {
if (!ids.length) {
ids = ["__passport__"];
async targeting(request: TargetingRequest = "__passport__"): Promise<TargetingResponse> {
const ids = typeof request === "string" ? [request] : request?.ids || [];

if (ids.length > 1 && !this.dcn.experiments.includes("targeting-cascade")) {
throw "Targeting multiple IDs is only available with the 'targeting-cascade' experiment enabled.";
}

await this.init;
return Targeting(this.dcn, ...ids);
return Targeting(this.dcn, ids);
}

targetingFromCache(): TargetingResponse | null {
Expand Down