Skip to content

Commit

Permalink
[sc-50473] Enabled pixel client api key to be set by client api key.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Ramzi committed Sep 18, 2023
1 parent b2e27cb commit 4858f8d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ class DecisionClient {
logger(
'warn',
'--------------------------------------------------------------\n' +
'--------------!!! WARNING - WARNING - WARNING !!!-------------\n' +
'' +
'You have opted to include explainer details with this request!\n' +
'This will cause performance degradation and should not be done\n' +
'in production environments.\n' +
'--------------------------------------------------------------'
'--------------!!! WARNING - WARNING - WARNING !!!-------------\n' +
'' +
'You have opted to include explainer details with this request!\n' +
'This will cause performance degradation and should not be done\n' +
'in production environments.\n' +
'--------------------------------------------------------------'
);

if (additionalOpts.desiredAds) {
Expand Down Expand Up @@ -295,16 +295,22 @@ class UserDbClient {
}
}

type PixelClientOptions = {
apiKey?: string;
}

class PixelClient {
private _fetch: FetchAPI;
private _agent: any;
private _logger: LoggerFunc;
private _options?: PixelClientOptions;
private _versionString: string;

constructor(fetch: FetchAPI, agent: any, logger: LoggerFunc, versionString: string) {
constructor(fetch: FetchAPI, agent: any, logger: LoggerFunc, versionString: string, options?: PixelClientOptions) {
this._fetch = fetch;
this._agent = agent;
this._logger = logger;
this._options = options;
this._versionString = versionString;
}

Expand Down Expand Up @@ -335,7 +341,7 @@ class PixelClient {
method: 'GET',
headers: {
'X-Adzerk-Sdk-Version': this._versionString,
'X-Kevel-ApiKey': additionalOpts?.apiKey,
'X-Kevel-ApiKey': additionalOpts?.apiKey ?? this._options?.apiKey,
'User-Agent': additionalOpts?.userAgent || 'OpenAPI-Generator/1.0/js',
},
redirect: 'manual',
Expand Down Expand Up @@ -452,7 +458,7 @@ export class Client {
adzerkApiKey
);
this._userDbClient = new UserDbClient(configuration, opts.networkId);
this._pixelClient = new PixelClient(fetch, this._agent, logger, versionString);
this._pixelClient = new PixelClient(fetch, this._agent, logger, versionString, { apiKey: adzerkApiKey });
}

get decisions(): DecisionClient {
Expand Down

0 comments on commit 4858f8d

Please sign in to comment.