-
Notifications
You must be signed in to change notification settings - Fork 1
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
Clean up operator backend proxy endpoints #23
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81250a4
Clean up operator backend proxy endpoints
OlivierChirouze bce0ab1
Add version in "proxy specific" endpoints
OlivierChirouze af98a13
Proxy "sign preferences": refactor for better message model
OlivierChirouze a5694f3
Introduce ProxyRestRequestBuilder to contact the operator proxy
OlivierChirouze 473acf0
[generate-model] fix to avoid having duplicated types
OlivierChirouze de5da01
[model] rename PostSignPreferencesRequest, remove duplicate types, ad…
OlivierChirouze ece5383
Merge branch 'main' into proxy-cleanup
OlivierChirouze 971ed6c
Merge branch 'main' into proxy-cleanup
OlivierChirouze 14605ab
[paf-lib] rename proxyhost
OlivierChirouze 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 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 |
---|---|---|
@@ -1,24 +1,34 @@ | ||
// TODO refactor to group endpoints and params | ||
export const proxyEndpoints = { | ||
verifyRedirectRead: '/verify/redirectRead', | ||
signWrite: '/sign/write', | ||
signPrefs: '/sign/prefs', | ||
} | ||
|
||
export const proxyUriParams = { | ||
returnUrl: 'returnUrl', | ||
message: 'message' | ||
} | ||
// TODO refactor to group by operator / operator proxy | ||
|
||
// Endpoints exposed by the operator API | ||
export const redirectEndpoints = { | ||
read: '/v1/redirect/get-ids-prefs', | ||
write: "/v1/redirect/post-ids-prefs" | ||
write: '/v1/redirect/post-ids-prefs' | ||
} | ||
export const jsonEndpoints = { | ||
read: '/v1/ids-prefs', | ||
write: "/v1/ids-prefs", | ||
write: '/v1/ids-prefs', | ||
verify3PC: '/v1/3pc', | ||
newId: '/v1/new-id', | ||
identity: '/v1/identity' | ||
} | ||
|
||
// Endpoints exposed by the operator proxy | ||
const proxyPrefix = '/paf-proxy' | ||
export const jsonProxyEndpoints = { | ||
verifyRead: `${proxyPrefix}/v1/verify/read`, | ||
signWrite: `${proxyPrefix}/v1/sign/write`, | ||
signPrefs: `${proxyPrefix}/v1/sign/prefs`, | ||
read: `${proxyPrefix}${jsonEndpoints.read}`, | ||
write: `${proxyPrefix}${jsonEndpoints.write}`, | ||
verify3PC: `${proxyPrefix}${jsonEndpoints.verify3PC}`, | ||
} | ||
export const redirectProxyEndpoints = { | ||
read: `${proxyPrefix}${redirectEndpoints.read}`, | ||
write: `${proxyPrefix}${redirectEndpoints.write}`, | ||
} | ||
|
||
export const proxyUriParams = { | ||
returnUrl: 'returnUrl', | ||
message: 'message' | ||
} |
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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,67 @@ | ||
import { | ||
GetIdsPrefsResponse, | ||
Identifiers, | ||
IdsAndPreferences, | ||
NewUnsignedPreferences, | ||
Preferences, | ||
PreferencesData | ||
} from "./generated-model"; | ||
import {jsonProxyEndpoints} from "../endpoints"; | ||
import {setInQueryString} from "../express"; | ||
|
||
export abstract class ProxyRestRequestBuilder<T extends object | undefined> { | ||
constructor(public proxyHost: string, protected restEndpoint: string) { | ||
} | ||
|
||
protected getProxyUrl(endpoint: string, pafQuery: object | undefined = undefined): URL { | ||
let url = new URL(`https://${this.proxyHost}${endpoint}`); | ||
|
||
if (pafQuery) { | ||
url = setInQueryString(url, pafQuery) | ||
} | ||
|
||
return url | ||
} | ||
|
||
getRestUrl(request: T): URL { | ||
return this.getProxyUrl(this.restEndpoint, request) | ||
} | ||
} | ||
|
||
export class ProxyRestSignPreferencesRequestBuilder extends ProxyRestRequestBuilder<NewUnsignedPreferences> { | ||
|
||
constructor(proxyHost: string) { | ||
super(proxyHost, jsonProxyEndpoints.signPrefs); | ||
} | ||
|
||
buildRequest(identifiers: Identifiers, data: PreferencesData): NewUnsignedPreferences { | ||
return { | ||
identifiers, | ||
unsignedPreferences: { | ||
version: "0.1", | ||
data | ||
} | ||
} | ||
} | ||
} | ||
|
||
export class ProxyRestSignPostIdsPrefsRequestBuilder extends ProxyRestRequestBuilder<IdsAndPreferences> { | ||
|
||
constructor(proxyHost: string) { | ||
super(proxyHost, jsonProxyEndpoints.signWrite); | ||
} | ||
|
||
buildRequest(identifiers: Identifiers, preferences: Preferences): IdsAndPreferences { | ||
return { | ||
identifiers, | ||
preferences | ||
} | ||
} | ||
} | ||
|
||
export class ProxyRestVerifyGetIdsPrefsRequestBuilder extends ProxyRestRequestBuilder<GetIdsPrefsResponse> { | ||
|
||
constructor(proxyHost: string) { | ||
super(proxyHost, jsonProxyEndpoints.verifyRead); | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, the semantics and compositions of the Preferences models are confusing. If I translate this line: "new unsigned preferences object that potentially contains unsigned preferences"...
Can you describe how this class helps us, please? It will help to find an alternative.
More generally speaking, in this file, we have many entities that express the Preferences concept: Preferences, PreferenceData, NewUnsignedPreferences, IdsAndPreferences. I have the impression that we generate classes based on the JSON-Schema and so the readability of the models is impacted by how the JSON-Schema works.
Can it be simplified with less class and more semantics? I want to be constructive so here are a few examples but I may not have all the corner cases in mind.
Example 1, the simplest
Exemple 2, more atomical approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
I get your point and I agree this model is becoming confusing.
I will rework to rename and refine some models.
However, a few comments:
unsignedPreferences
shouldn't be optional, I'll fix it, thanks for the heads up.PrebidData
where I favored explicit (but sometimes pretty long) names such asIdsAndPreferences
. I'm not sure PrebidData is more explicit, WDYT?To sum up, I'll rework these interfaces to make names more explicit and when possible, simplify it, in line with your suggestion 2.