Skip to content

Commit 499ffcd

Browse files
committed
Support targeting cascade
1 parent 0eda091 commit 499ffcd

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

lib/edge/targeting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type TargetingResponse = {
2727
ortb2: { user: ortb2.User };
2828
};
2929

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

3434
const response: TargetingResponse = await fetch(path, config, {

lib/sdk.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,13 @@ describe("behavior testing of", () => {
395395
})
396396
);
397397

398-
const targetingWithParam = await sdk.targeting("someId");
398+
const targetingWithParam = await sdk.targeting("someId", "someOtherId");
399399
expect(targetingWithParam).toBeDefined();
400400

401401
expect(fetchSpy).toHaveBeenLastCalledWith(
402402
expect.objectContaining({
403403
method: "GET",
404-
url: expect.stringContaining("v2/targeting?id=someId"),
404+
url: expect.stringContaining("v2/targeting?id=someId&id=someOtherId"),
405405
})
406406
);
407407

lib/sdk.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ class OptableSDK {
5454
return Uid2Token(this.dcn, id);
5555
}
5656

57-
async targeting(id: string = "__passport__"): Promise<TargetingResponse> {
57+
async targeting(...ids: string[]): Promise<TargetingResponse> {
58+
if (!ids.length) {
59+
ids = ["__passport__"];
60+
}
61+
5862
await this.init;
59-
return Targeting(this.dcn, id);
63+
return Targeting(this.dcn, ...ids);
6064
}
6165

6266
targetingFromCache(): TargetingResponse | null {

0 commit comments

Comments
 (0)