Skip to content

Commit fe27c7d

Browse files
committed
fix: PR prebid#14255 revisions
1 parent 31d2df7 commit fe27c7d

File tree

3 files changed

+186
-115
lines changed

3 files changed

+186
-115
lines changed

modules/apsBidAdapter.js

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isStr, isNumber, logWarn, logError } from '../src/utils.js';
22
import { registerBidder } from '../src/adapters/bidderFactory.js';
33
import { config } from '../src/config.js';
44
import { BANNER, VIDEO } from '../src/mediaTypes.js';
5+
import { hasPurpose1Consent } from '../src/utils/gdpr.js';
56
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
67

78
/**
@@ -12,7 +13,7 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js';
1213
*/
1314

1415
const GVLID = 793;
15-
const ADAPTER_VERSION = '2.0.0';
16+
export const ADAPTER_VERSION = '2.0.0';
1617
const BIDDER_CODE = 'aps';
1718
const AAX_ENDPOINT = 'https://web.ads.aps.amazon-adsystem.com/e/pb/bid';
1819
const DEFAULT_PREBID_CREATIVE_JS_URL =
@@ -73,6 +74,18 @@ function record(eventName, data) {
7374
);
7475
}
7576

77+
/**
78+
* Record and log a new error.
79+
*
80+
* @param {string} eventName - The name of the event to record
81+
* @param {Error} err - Error object
82+
* @param {any} data - Event data object
83+
*/
84+
function recordAndLogError(eventName, err, data) {
85+
record(eventName, { ...data, error: err });
86+
logError(err.message);
87+
}
88+
7689
/**
7790
* Validates whether a given account ID is valid.
7891
*
@@ -127,36 +140,41 @@ export const converter = ortbConverter({
127140

128141
request.ext = request.ext ?? {};
129142
request.ext.account = config.readConfig('aps.accountID');
143+
request.ext.sdk = {
144+
version: ADAPTER_VERSION,
145+
source: 'prebid',
146+
};
130147
request.cur = request.cur ?? ['USD'];
131148

132-
// Validate and process impressions - fail fast on structural issues
133149
if (!request.imp || !Array.isArray(request.imp)) {
134-
throw new Error('Request must contain a valid impressions array');
150+
return request;
135151
}
136152

137153
request.imp.forEach((imp, index) => {
138154
if (!imp) {
139-
throw new Error(`Impression at index ${index} is null or undefined`);
155+
return; // continue to next iteration
140156
}
141157

142158
if (!imp.banner) {
143-
return;
159+
return; // continue to next iteration
144160
}
145161

146162
const doesHWExist = imp.banner.w >= 0 && imp.banner.h >= 0;
147163
const doesFormatExist =
148164
Array.isArray(imp.banner.format) && imp.banner.format.length > 0;
149165

150-
if (!doesHWExist && doesFormatExist) {
151-
const { w, h } = imp.banner.format[0];
152-
if (typeof w !== 'number' || typeof h !== 'number') {
153-
throw new Error(
154-
`Invalid banner format dimensions at impression ${index}: w=${w}, h=${h}`
155-
);
156-
}
157-
imp.banner.w = w;
158-
imp.banner.h = h;
166+
if (doesHWExist || !doesFormatExist) {
167+
return; // continue to next iteration
168+
}
169+
170+
const { w, h } = imp.banner.format[0];
171+
172+
if (typeof w !== 'number' || typeof h !== 'number') {
173+
return; // continue to next iteration
159174
}
175+
176+
imp.banner.w = w;
177+
imp.banner.h = h;
160178
});
161179

162180
return request;
@@ -201,8 +219,8 @@ export const spec = {
201219
}
202220
return true;
203221
} catch (err) {
204-
record('isBidRequestValid/didError', { error: err });
205-
logError('Error while validating bid request', err);
222+
err.message = `Error while validating bid request: ${err?.message}`;
223+
recordAndLogError('isBidRequestValid/didError', err);
206224
}
207225
},
208226

@@ -230,13 +248,10 @@ export const spec = {
230248
method: 'POST',
231249
url: endpoint,
232250
data: converter.toORTB({ bidRequests, bidderRequest }),
233-
options: {
234-
contentType: 'application/json',
235-
},
236251
};
237252
} catch (err) {
238-
record('buildRequests/didError', { error: err });
239-
logError('Error while building bid request', err);
253+
err.message = `Error while building bid request: ${err?.message}`;
254+
recordAndLogError('buildRequests/didError', err);
240255
}
241256
},
242257

@@ -283,8 +298,8 @@ export const spec = {
283298

284299
return interpretedResponse.bids;
285300
} catch (err) {
286-
record('interpretResponse/didError', { error: err });
287-
logError('Error while interpreting bid response', err);
301+
err.message = `Error while interpreting bid response: ${err?.message}`;
302+
recordAndLogError('interpretResponse/didError', err);
288303
}
289304
},
290305

@@ -305,17 +320,18 @@ export const spec = {
305320
) {
306321
record('getUserSyncs');
307322
try {
308-
const userSyncs = serverResponses.flatMap(
309-
(res) => res?.body?.ext?.userSyncs ?? []
310-
);
311-
return userSyncs.filter(
312-
(s) =>
313-
(s.type === 'iframe' && syncOptions.iframeEnabled) ||
314-
(s.type === 'image' && syncOptions.pixelEnabled)
315-
);
323+
if (hasPurpose1Consent(gdprConsent)) {
324+
return serverResponses
325+
.flatMap((res) => res?.body?.ext?.userSyncs ?? [])
326+
.filter(
327+
(s) =>
328+
(s.type === 'iframe' && syncOptions.iframeEnabled) ||
329+
(s.type === 'image' && syncOptions.pixelEnabled)
330+
);
331+
}
316332
} catch (err) {
317-
record('getUserSyncs/didError', { error: err });
318-
logError('Error while getting user syncs', err);
333+
err.message = `Error while getting user syncs: ${err?.message}`;
334+
recordAndLogError('getUserSyncs/didError', err);
319335
}
320336
},
321337

modules/apsBidAdapter.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Maintainer: [email protected]
1010

1111
Connects to Amazon Publisher Services (APS) for bids.
1212

13+
## Test Bids
14+
15+
Please contact your APS Account Manager to learn more about our testing policies.
16+
1317
# Usage
1418

1519
## Prerequisites
@@ -26,7 +30,7 @@ pbjs.setBidderConfig(
2630
}
2731
},
2832
},
29-
mergeConfig // mergeConfig toggle
33+
true // mergeConfig toggle
3034
);
3135
```
3236

0 commit comments

Comments
 (0)