Skip to content

Commit 486afff

Browse files
authored
Add support for hids (#211)
1 parent 0329a2c commit 486afff

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

lib/edge/targeting.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type UserIdentifiers = {
2323

2424
type TargetingRequest = {
2525
ids: string[];
26+
hids: string[];
2627
};
2728

2829
type TargetingResponse = {
@@ -32,7 +33,9 @@ type TargetingResponse = {
3233
};
3334

3435
async function Targeting(config: ResolvedConfig, req: TargetingRequest): Promise<TargetingResponse> {
35-
const searchParams = new URLSearchParams(req.ids.map((id) => ["id", id]));
36+
const searchParams = new URLSearchParams();
37+
req.ids.forEach((id) => searchParams.append("id", id));
38+
req.hids.forEach((id) => searchParams.append("hid", id));
3639
const path = "/v2/targeting?" + searchParams.toString();
3740

3841
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
@@ -514,12 +514,12 @@ describe("normalizeTargetingRequest", () => {
514514
test("normalizes string input", () => {
515515
const input = "c:123";
516516
const result = normalizeTargetingRequest(input);
517-
expect(result).toEqual({ ids: ["c:123"] });
517+
expect(result).toEqual({ ids: ["c:123"], hids: [] });
518518
});
519519

520520
test("normalizes object input", () => {
521521
const result = normalizeTargetingRequest({});
522-
expect(result).toEqual({ ids: [] });
522+
expect(result).toEqual({ ids: [], hids: [] });
523523
});
524524

525525
test("fails for unknown types", () => {

lib/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ class OptableSDK {
157157

158158
function normalizeTargetingRequest(input: string | TargetingRequest): TargetingRequest {
159159
if (typeof input === "string") {
160-
return { ids: [input] };
160+
return { ids: [input], hids: [] };
161161
}
162162

163163
if (isObject(input)) {
164-
return { ids: input?.ids ?? [] };
164+
return { ids: input?.ids ?? [], hids: input?.hids ?? [] };
165165
}
166166

167167
throw "Invalid request type for targeting. Expected string or object.";

0 commit comments

Comments
 (0)