Repository navigation
secureSignals: add secureSignalsFromEids building GPT secure signals from cached EIDs #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+138
−3
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
16f93a8
secureSignals: add secureSignalsFromEids building GPT secure signals …
etiennelatendresse-optable 9a1e270
secureSignals: emit one signal per source since GPT keys providers un…
etiennelatendresse-optable 62f7957
secureSignals: derive SecureSignalEid from the ORTB EID and expose th…
etiennelatendresse-optable 1ac390d
secureSignals: read the cache through the instance in the README and …
etiennelatendresse-optable 3e5be56
secureSignals: accept the cache EID type and pin the per-source fall-…
etiennelatendresse-optable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { secureSignalsFromEids } from "./secure-signals"; | ||
|
|
||
| const EIDS = [ | ||
| { source: "uidapi.com", matcher: "m1", inserter: "optable", uids: [{ id: "uid2-a" }, { id: "uid2-b" }] }, | ||
| { source: "id5-sync.com", matcher: "m2", uids: [{ id: "id5-a" }] }, | ||
| { source: "liveramp.com", uids: [] }, | ||
| ]; | ||
|
|
||
| describe("secureSignalsFromEids", () => { | ||
| it("emits one signal per source, taking the first non-empty uid", () => { | ||
| expect(secureSignalsFromEids(EIDS)).toEqual([ | ||
| { provider: "uidapi.com", id: "uid2-a" }, | ||
| { provider: "id5-sync.com", id: "id5-a" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("keeps the first EID when a source appears twice", () => { | ||
| const dup = [ | ||
| { source: "pair.optable.co", uids: [{ id: "pair-1" }] }, | ||
| { source: "pair.optable.co", uids: [{ id: "pair-2" }] }, | ||
| ]; | ||
| expect(secureSignalsFromEids(dup)).toEqual([{ provider: "pair.optable.co", id: "pair-1" }]); | ||
| }); | ||
|
|
||
| it("falls through to a later EID of the same source when the first is empty or filtered out", () => { | ||
| expect( | ||
| secureSignalsFromEids([ | ||
| { source: "s.com", uids: [{ id: "" }] }, | ||
| { source: "s.com", uids: [{ id: "second" }] }, | ||
| ]) | ||
| ).toEqual([{ provider: "s.com", id: "second" }]); | ||
| expect( | ||
| secureSignalsFromEids( | ||
| [ | ||
| { source: "s.com", inserter: "other", uids: [{ id: "first" }] }, | ||
| { source: "s.com", inserter: "optable", uids: [{ id: "second" }] }, | ||
| ], | ||
| { inserters: ["optable"] } | ||
| ) | ||
| ).toEqual([{ provider: "s.com", id: "second" }]); | ||
| }); | ||
|
|
||
| it("filters by source, inserter and matcher", () => { | ||
| expect(secureSignalsFromEids(EIDS, { sources: ["id5-sync.com"] })).toEqual([ | ||
| { provider: "id5-sync.com", id: "id5-a" }, | ||
| ]); | ||
| expect(secureSignalsFromEids(EIDS, { inserters: ["optable"] }).map((s) => s.provider)).toEqual(["uidapi.com"]); | ||
| expect(secureSignalsFromEids(EIDS, { matchers: ["m2"] })).toEqual([{ provider: "id5-sync.com", id: "id5-a" }]); | ||
| }); | ||
|
|
||
| it("requires every provided filter to match", () => { | ||
| expect(secureSignalsFromEids(EIDS, { sources: ["uidapi.com"], matchers: ["m2"] })).toEqual([]); | ||
| }); | ||
|
|
||
| it("treats an empty filter list as no constraint", () => { | ||
| expect(secureSignalsFromEids(EIDS, { sources: [] })).toHaveLength(2); | ||
| }); | ||
|
|
||
| it("skips uids without an id and tolerates empty input", () => { | ||
| expect(secureSignalsFromEids([{ source: "a.com", uids: [{ id: "" }, {}] }])).toEqual([]); | ||
| expect(secureSignalsFromEids([{ source: "a.com", uids: [{ id: "" }, { id: "real" }] }])).toEqual([ | ||
| { provider: "a.com", id: "real" }, | ||
| ]); | ||
| expect(secureSignalsFromEids([])).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { EID, UID } from "iab-openrtb/v26"; | ||
|
|
||
| // Converts cached EIDs into GPT secure-signal pairs for | ||
| // installGPTSecureSignals, optionally filtered by source, inserter or | ||
| // matcher. An empty or missing filter list means no constraint on that field. | ||
| // | ||
| // One signal per source: GPT keys secure signals by provider, so registering | ||
| // a provider twice drops all but one id. The first EID that passes the filter | ||
| // and carries a non-empty uid wins its source. | ||
|
|
||
| // Cached EIDs are parsed from storage, so ORTB's required fields may be | ||
| // absent at runtime. Derived from EID so new or renamed ORTB fields flow through. | ||
| type SecureSignalEid = Partial<Omit<EID, "uids">> & Pick<EID, "source"> & { uids?: Array<Pick<Partial<UID>, "id">> }; | ||
|
|
||
| type SecureSignalsFilter = { | ||
| sources?: string[]; | ||
| inserters?: string[]; | ||
| matchers?: string[]; | ||
| }; | ||
|
|
||
| type SecureSignal = { provider: string; id: string }; | ||
|
|
||
| export function secureSignalsFromEids(eids: SecureSignalEid[], filter: SecureSignalsFilter = {}): SecureSignal[] { | ||
| const allows = (list: string[] | undefined, value: string | undefined) => !list?.length || list.includes(value ?? ""); | ||
|
|
||
| const bySource = new Map<string, SecureSignal>(); | ||
| eids.forEach((eid) => { | ||
| if (bySource.has(eid.source)) return; | ||
| if (!allows(filter.sources, eid.source)) return; | ||
| if (!allows(filter.inserters, eid.inserter)) return; | ||
| if (!allows(filter.matchers, eid.matcher)) return; | ||
|
|
||
| const uid = eid.uids?.find((u) => u.id); | ||
| if (uid?.id) { | ||
| bySource.set(eid.source, { provider: eid.source, id: uid.id }); | ||
| } | ||
| }); | ||
| return [...bySource.values()]; | ||
| } | ||
|
|
||
| export type { SecureSignalEid, SecureSignalsFilter, SecureSignal }; | ||
|
etiennelatendresse-optable marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.