Skip to content

Commit 242f6c1

Browse files
committed
Revert "feat: Use Basic auth credentials for Advertiser IDSync search"
This reverts commit 1225871.
1 parent 1225871 commit 242f6c1

2 files changed

Lines changed: 17 additions & 159 deletions

File tree

src/Rokt-Kit.ts

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ interface RoktKitSettings {
3030
loggingUrl?: string;
3131
errorUrl?: string;
3232
isLoggingEnabled?: string | boolean;
33-
/**
34-
* Comma-separated `apiKey,secret` for the advertiser workspace whose
35-
* IDSync `/v1/search` endpoint we should query on every onUserIdentified.
36-
* Empty/missing/malformed values disable the feature.
37-
*/
38-
advertiserIdSyncCredentials?: string;
33+
advertiserIdSyncApiKey?: string;
3934
}
4035

4136
interface EventAttributeCondition {
@@ -106,7 +101,6 @@ interface AdvertiserIdSyncResult {
106101

107102
type AdvertiserIdSyncSearcher = (
108103
apiKey: string,
109-
secret: string,
110104
knownIdentities: { email: string },
111105
callback: (result: AdvertiserIdSyncResult) => void,
112106
) => void;
@@ -428,29 +422,6 @@ function isString(value: unknown): value is string {
428422
return typeof value === 'string';
429423
}
430424

431-
/**
432-
* Parse the kit's `advertiserIdSyncCredentials` setting into apiKey and
433-
* secret components. The setting is a comma-separated string `apiKey,secret`.
434-
* Returns undefined for any malformed/empty value (including missing
435-
* comma, more than one comma, or whitespace-only halves) so the caller can
436-
* gate the feature off cleanly.
437-
*/
438-
function parseAdvertiserIdSyncCredentials(raw: unknown): { apiKey: string; secret: string } | undefined {
439-
if (!isString(raw)) {
440-
return undefined;
441-
}
442-
const parts = raw.split(',');
443-
if (parts.length !== 2) {
444-
return undefined;
445-
}
446-
const apiKey = parts[0].trim();
447-
const secret = parts[1].trim();
448-
if (!apiKey || !secret) {
449-
return undefined;
450-
}
451-
return { apiKey, secret };
452-
}
453-
454425
function generateIntegrationName(customIntegrationName?: string): string {
455426
const coreSdkVersion = mp().getVersion();
456427
const kitVersion = process.env.PACKAGE_VERSION;
@@ -729,7 +700,6 @@ class RoktKit implements KitInterface {
729700
private _mappedEmailSha256Key?: string;
730701
private _onboardingExpProvider?: string;
731702
private _advertiserIdSyncApiKey?: string;
732-
private _advertiserIdSyncSecret?: string;
733703

734704
// ---- Private helpers ----
735705

@@ -1080,12 +1050,9 @@ class RoktKit implements KitInterface {
10801050
this._mappedEmailSha256Key = kitSettings.hashedEmailUserIdentityType.toLowerCase();
10811051
}
10821052

1083-
// advertiserIdSyncCredentials is a comma-separated `apiKey,secret`. We
1084-
// parse it here so the SDK API stays simple (separate apiKey + secret
1085-
// arguments). Anything malformed disables the feature.
1086-
const credentials = parseAdvertiserIdSyncCredentials(kitSettings.advertiserIdSyncCredentials);
1087-
this._advertiserIdSyncApiKey = credentials?.apiKey;
1088-
this._advertiserIdSyncSecret = credentials?.secret;
1053+
this._advertiserIdSyncApiKey = isString(kitSettings.advertiserIdSyncApiKey)
1054+
? kitSettings.advertiserIdSyncApiKey
1055+
: undefined;
10891056

10901057
const domain = mp().Rokt?.domain;
10911058
const { roktExtensionsQueryParams, legacyRoktExtensions, loadThankYouElement } = extractRoktExtensionConfig(
@@ -1236,8 +1203,7 @@ class RoktKit implements KitInterface {
12361203

12371204
private searchAdvertiser(filteredUser: FilteredUser): void {
12381205
const apiKey = this._advertiserIdSyncApiKey;
1239-
const secret = this._advertiserIdSyncSecret;
1240-
if (!apiKey || !secret) {
1206+
if (!apiKey) {
12411207
return;
12421208
}
12431209
const searchAdvertiser = mp().Identity?.searchAdvertiser;
@@ -1250,7 +1216,7 @@ class RoktKit implements KitInterface {
12501216
return;
12511217
}
12521218
try {
1253-
searchAdvertiser(apiKey, secret, { email }, (result: AdvertiserIdSyncResult) => {
1219+
searchAdvertiser(apiKey, { email }, (result: AdvertiserIdSyncResult) => {
12541220
if (result?.httpCode === 200) {
12551221
this.userAttributes[USER_IDENTIFIED_IN_ADVERTISER_KEY] = true;
12561222
}

test/src/tests.spec.ts

Lines changed: 11 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,8 +2974,6 @@ describe('Rokt Forwarder', () => {
29742974

29752975
describe('#advertiserIdSync', () => {
29762976
const ADVERTISER_API_KEY = 'advertiser-key-abc123';
2977-
const ADVERTISER_API_SECRET = 'advertiser-secret-xyz789';
2978-
const ADVERTISER_CREDENTIALS = `${ADVERTISER_API_KEY},${ADVERTISER_API_SECRET}`;
29792977

29802978
function makeUser(overrides: any = {}) {
29812979
return {
@@ -2997,21 +2995,19 @@ describe('Rokt Forwarder', () => {
29972995
(window as any).mParticle.forwarder.userAttributes = {};
29982996
});
29992997

3000-
it('should split advertiserIdSyncCredentials into apiKey + secret and forward both, setting userIdentifiedInAdvertiser when 200 returned', async () => {
2998+
it('should call Identity.searchAdvertiser with the configured api key and set userIdentifiedInAdvertiser when 200 returned', async () => {
30012999
let receivedApiKey: any = null;
3002-
let receivedSecret: any = null;
30033000
let receivedKnownIdentities: any = null;
30043001
(window as any).mParticle.Identity = {
3005-
searchAdvertiser: (apiKey: any, secret: any, knownIdentities: any, cb: any) => {
3002+
searchAdvertiser: (apiKey: any, knownIdentities: any, cb: any) => {
30063003
receivedApiKey = apiKey;
3007-
receivedSecret = secret;
30083004
receivedKnownIdentities = knownIdentities;
30093005
cb({ httpCode: 200, body: { mpid: '999' } });
30103006
},
30113007
};
30123008

30133009
await (window as any).mParticle.forwarder.init(
3014-
{ accountId: '123456', advertiserIdSyncCredentials: ADVERTISER_CREDENTIALS },
3010+
{ accountId: '123456', advertiserIdSyncApiKey: ADVERTISER_API_KEY },
30153011
reportService.cb,
30163012
true,
30173013
null,
@@ -3021,48 +3017,19 @@ describe('Rokt Forwarder', () => {
30213017
(window as any).mParticle.forwarder.onUserIdentified(makeUser());
30223018

30233019
expect(receivedApiKey).toBe(ADVERTISER_API_KEY);
3024-
expect(receivedSecret).toBe(ADVERTISER_API_SECRET);
30253020
expect(receivedKnownIdentities).toEqual({ email: 'test@example.com' });
30263021
expect((window as any).mParticle.forwarder.userAttributes.userIdentifiedInAdvertiser).toBe(true);
30273022
});
30283023

3029-
it('should trim whitespace around the comma-separated credentials', async () => {
3030-
let receivedApiKey: any = null;
3031-
let receivedSecret: any = null;
3032-
(window as any).mParticle.Identity = {
3033-
searchAdvertiser: (apiKey: any, secret: any, _knownIdentities: any, cb: any) => {
3034-
receivedApiKey = apiKey;
3035-
receivedSecret = secret;
3036-
cb({ httpCode: 200 });
3037-
},
3038-
};
3039-
3040-
await (window as any).mParticle.forwarder.init(
3041-
{
3042-
accountId: '123456',
3043-
advertiserIdSyncCredentials: ` ${ADVERTISER_API_KEY} , ${ADVERTISER_API_SECRET} `,
3044-
},
3045-
reportService.cb,
3046-
true,
3047-
null,
3048-
{},
3049-
);
3050-
3051-
(window as any).mParticle.forwarder.onUserIdentified(makeUser());
3052-
3053-
expect(receivedApiKey).toBe(ADVERTISER_API_KEY);
3054-
expect(receivedSecret).toBe(ADVERTISER_API_SECRET);
3055-
});
3056-
30573024
it('should not set userIdentifiedInAdvertiser when search returns 404', async () => {
30583025
(window as any).mParticle.Identity = {
3059-
searchAdvertiser: (_apiKey: any, _secret: any, _knownIdentities: any, cb: any) => {
3026+
searchAdvertiser: (_apiKey: any, _knownIdentities: any, cb: any) => {
30603027
cb({ httpCode: 404 });
30613028
},
30623029
};
30633030

30643031
await (window as any).mParticle.forwarder.init(
3065-
{ accountId: '123456', advertiserIdSyncCredentials: ADVERTISER_CREDENTIALS },
3032+
{ accountId: '123456', advertiserIdSyncApiKey: ADVERTISER_API_KEY },
30663033
reportService.cb,
30673034
true,
30683035
null,
@@ -3074,7 +3041,7 @@ describe('Rokt Forwarder', () => {
30743041
expect((window as any).mParticle.forwarder.userAttributes.userIdentifiedInAdvertiser).toBeUndefined();
30753042
});
30763043

3077-
it('should not call searchAdvertiser when advertiserIdSyncCredentials is missing', async () => {
3044+
it('should not call searchAdvertiser when advertiserIdSyncApiKey is missing', async () => {
30783045
let searchCalled = false;
30793046
(window as any).mParticle.Identity = {
30803047
searchAdvertiser: () => {
@@ -3090,7 +3057,7 @@ describe('Rokt Forwarder', () => {
30903057
expect((window as any).mParticle.forwarder.userAttributes.userIdentifiedInAdvertiser).toBeUndefined();
30913058
});
30923059

3093-
it('should not call searchAdvertiser when advertiserIdSyncCredentials is an empty string', async () => {
3060+
it('should not call searchAdvertiser when advertiserIdSyncApiKey is an empty string', async () => {
30943061
let searchCalled = false;
30953062
(window as any).mParticle.Identity = {
30963063
searchAdvertiser: () => {
@@ -3099,7 +3066,7 @@ describe('Rokt Forwarder', () => {
30993066
};
31003067

31013068
await (window as any).mParticle.forwarder.init(
3102-
{ accountId: '123456', advertiserIdSyncCredentials: '' },
3069+
{ accountId: '123456', advertiserIdSyncApiKey: '' },
31033070
reportService.cb,
31043071
true,
31053072
null,
@@ -3112,81 +3079,6 @@ describe('Rokt Forwarder', () => {
31123079
expect((window as any).mParticle.forwarder.userAttributes.userIdentifiedInAdvertiser).toBeUndefined();
31133080
});
31143081

3115-
it('should not call searchAdvertiser when advertiserIdSyncCredentials has no comma', async () => {
3116-
let searchCalled = false;
3117-
(window as any).mParticle.Identity = {
3118-
searchAdvertiser: () => {
3119-
searchCalled = true;
3120-
},
3121-
};
3122-
3123-
await (window as any).mParticle.forwarder.init(
3124-
{ accountId: '123456', advertiserIdSyncCredentials: 'no-comma-here' },
3125-
reportService.cb,
3126-
true,
3127-
null,
3128-
{},
3129-
);
3130-
3131-
(window as any).mParticle.forwarder.onUserIdentified(makeUser());
3132-
3133-
expect(searchCalled).toBe(false);
3134-
});
3135-
3136-
it('should not call searchAdvertiser when advertiserIdSyncCredentials has more than one comma', async () => {
3137-
let searchCalled = false;
3138-
(window as any).mParticle.Identity = {
3139-
searchAdvertiser: () => {
3140-
searchCalled = true;
3141-
},
3142-
};
3143-
3144-
await (window as any).mParticle.forwarder.init(
3145-
{ accountId: '123456', advertiserIdSyncCredentials: 'a,b,c' },
3146-
reportService.cb,
3147-
true,
3148-
null,
3149-
{},
3150-
);
3151-
3152-
(window as any).mParticle.forwarder.onUserIdentified(makeUser());
3153-
3154-
expect(searchCalled).toBe(false);
3155-
});
3156-
3157-
it('should not call searchAdvertiser when one half of advertiserIdSyncCredentials is empty', async () => {
3158-
let searchCalled = false;
3159-
(window as any).mParticle.Identity = {
3160-
searchAdvertiser: () => {
3161-
searchCalled = true;
3162-
},
3163-
};
3164-
3165-
await (window as any).mParticle.forwarder.init(
3166-
{ accountId: '123456', advertiserIdSyncCredentials: 'apikey-only,' },
3167-
reportService.cb,
3168-
true,
3169-
null,
3170-
{},
3171-
);
3172-
3173-
(window as any).mParticle.forwarder.onUserIdentified(makeUser());
3174-
3175-
expect(searchCalled).toBe(false);
3176-
3177-
await (window as any).mParticle.forwarder.init(
3178-
{ accountId: '123456', advertiserIdSyncCredentials: ',secret-only' },
3179-
reportService.cb,
3180-
true,
3181-
null,
3182-
{},
3183-
);
3184-
3185-
(window as any).mParticle.forwarder.onUserIdentified(makeUser());
3186-
3187-
expect(searchCalled).toBe(false);
3188-
});
3189-
31903082
it('should not call searchAdvertiser when the user has no plain email identity', async () => {
31913083
let searchCalled = false;
31923084
(window as any).mParticle.Identity = {
@@ -3196,7 +3088,7 @@ describe('Rokt Forwarder', () => {
31963088
};
31973089

31983090
await (window as any).mParticle.forwarder.init(
3199-
{ accountId: '123456', advertiserIdSyncCredentials: ADVERTISER_CREDENTIALS },
3091+
{ accountId: '123456', advertiserIdSyncApiKey: ADVERTISER_API_KEY },
32003092
reportService.cb,
32013093
true,
32023094
null,
@@ -3215,7 +3107,7 @@ describe('Rokt Forwarder', () => {
32153107
(window as any).mParticle.Identity = {};
32163108

32173109
await (window as any).mParticle.forwarder.init(
3218-
{ accountId: '123456', advertiserIdSyncCredentials: ADVERTISER_CREDENTIALS },
3110+
{ accountId: '123456', advertiserIdSyncApiKey: ADVERTISER_API_KEY },
32193111
reportService.cb,
32203112
true,
32213113
null,
@@ -3236,7 +3128,7 @@ describe('Rokt Forwarder', () => {
32363128
};
32373129

32383130
await (window as any).mParticle.forwarder.init(
3239-
{ accountId: '123456', advertiserIdSyncCredentials: ADVERTISER_CREDENTIALS },
3131+
{ accountId: '123456', advertiserIdSyncApiKey: ADVERTISER_API_KEY },
32403132
reportService.cb,
32413133
true,
32423134
null,

0 commit comments

Comments
 (0)