• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / #288

20 Mar 2025 07:47PM UTC coverage: 90.491% (+0.02%) from 90.476%
#288

push

travis-ci

prebidjs-release
Prebid 9.36.0 release

42390 of 53094 branches covered (79.84%)

62871 of 69478 relevant lines covered (90.49%)

226.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.99
/modules/lockrAIMIdSystem.js
1
/**
1✔
2
 * This module adds lockr AIM ID support to the User ID module
3
 * The {@link module:modules/userId} module is required.
4
 * @module modules/lockrAIMIdSystem
5
 * @requires module:modules/userId
6
 */
7

8
import { submodule } from '../src/hook.js';
9
import { ajax } from '../src/ajax.js';
10
import { logInfo, logWarn } from '../src/utils.js';
11
import { getStorageManager } from '../src/storageManager.js';
12
import { MODULE_TYPE_UID } from '../src/activities/modules.js';
13

14
/**
15
 * @typedef {import('../modules/userId/index.js').Submodule} Submodule
16
 * @typedef {import('../modules/userId/index.js').SubmoduleConfig} SubmoduleConfig
17
 * @typedef {import('../modules/userId/index.js').ConsentData} ConsentData
18
 * @typedef {import('../modules/userId/index.js').lockrAIMId} lockrAIMId
19
 */
20

21
const MODULE_NAME = 'lockrAIMId'
1✔
22
const LOG_PRE_FIX = 'lockr-AIM: ';
1✔
23

24
const AIM_PROD_URL = 'https://identity.loc.kr';
1✔
25

26
export const lockrAIMCodeVersion = '1.0';
1✔
27

28
export const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME })
1✔
29

30
function createLogger(logger, prefix) {
31
  return function (...strings) {
2✔
32
    logger(prefix + ' ', ...strings);
6✔
33
  }
34
}
35

36
const _logInfo = createLogger(logInfo, LOG_PRE_FIX);
1✔
37
const _logWarn = createLogger(logWarn, LOG_PRE_FIX);
1✔
38

39
/** @type {Submodule} */
40
export const lockrAIMSubmodule = {
1✔
41
  /**
42
   * used to link submodule with config
43
   * @type {string}
44
   */
45
  name: MODULE_NAME,
46

47
  init() {
48
    _logInfo('lockrAIM Initialization complete');
×
49
  },
50

51
  /**
52
   * performs action to obtain id and return a value.
53
   * @function
54
   * @param {SubmoduleConfig} [config]
55
   * @param {ConsentData|undefined} consentData
56
   * @returns {lockrAIMId}
57
   */
58
  getId(config, consentData) {
59
    if (consentData?.gdpr?.gdprApplies === true) {
6!
60
      _logWarn('lockrAIM is not intended for use where GDPR applies. The lockrAIM module will not run');
×
61
      return undefined;
×
62
    }
63

64
    const gppConsent = consentData?.gpp;
6✔
65
    let gppString = '';
6✔
66
    if (gppConsent) {
6!
67
      gppString = gppConsent.gppString;
×
68
    }
69
    const mappedConfig = {
6✔
70
      appID: config?.params?.appID,
71
      email: config?.params?.email,
72
      baseUrl: AIM_PROD_URL,
73
    };
74

75
    _logInfo('lockr AIM configurations loaded and mapped.', mappedConfig);
6✔
76
    if (!mappedConfig.appID || !mappedConfig.email) {
6!
77
      return undefined;
6✔
78
    }
79
    const tokenGenerator = new LockrAIMApiClient(mappedConfig, _logInfo, _logWarn, storage, gppString);
×
80
    const result = tokenGenerator.generateToken();
×
81
    _logInfo('lockr AIM results generated');
×
82
    return result;
×
83
  }
84
}
85

86
class LockrAIMApiClient {
87
  static expiryDateKeys = [];
1✔
88
  static canRefreshToken = false;
1✔
89

90
  constructor(opts, logInfo, logWarn, prebidStorageManager, gppString) {
91
    this._baseUrl = opts.baseUrl;
×
92
    this._appID = opts.appID;
×
93
    this._email = opts.email;
×
94
    this._logInfo = logInfo;
×
95
    this._logWarn = logWarn;
×
96
    this._gppString = gppString;
×
97
    this.prebidStorageManager = prebidStorageManager;
×
98
    LockrAIMApiClient.expiryDateKeys = this.prebidStorageManager.getDataFromLocalStorage('lockr_expiry_keys') ? JSON.parse(this.prebidStorageManager.getDataFromLocalStorage('lockr_expiry_keys')) : []
×
99
    this.initializeRefresher();
×
100
  }
101

102
  async generateToken(type = 'email', value) {
×
103
    const url = this._baseUrl + '/publisher/app/v1/identityLockr/generate-tokens';
×
104
    let rejectPromise;
105
    const promise = new Promise((resolve, reject) => {
×
106
      rejectPromise = reject;
×
107
    });
108
    const requestBody = {
×
109
      appID: this._appID,
110
      data: {
111
        type: type,
112
        value: value ?? this._email,
×
113
        gppString: this._gppString,
114
      }
115
    }
116
    this._logInfo('Sending the token generation request')
×
117
    ajax(url, {
×
118
      success: (responseText) => {
119
        try {
×
120
          const response = JSON.parse(responseText);
×
121
          LockrAIMApiClient.canRefreshToken = false;
×
122
          const token = response.lockrMappingToken;
×
123
          this.prebidStorageManager.setDataInLocalStorage('ilui', token);
×
124
          response.data.forEach(cookieitem => {
×
125
            const settings = cookieitem?.settings;
×
126
            this.prebidStorageManager.setDataInLocalStorage(`${cookieitem.key_name}_expiry`, cookieitem.identity_expires);
×
127
            if (!LockrAIMApiClient.expiryDateKeys.includes(`${cookieitem.key_name}_expiry`)) {
×
128
              LockrAIMApiClient.expiryDateKeys.push(`${cookieitem.key_name}_expiry`);
×
129
            }
130
            this.prebidStorageManager.setDataInLocalStorage('lockr_expiry_keys', JSON.stringify(LockrAIMApiClient.expiryDateKeys));
×
131
            if (!settings?.dropLocalStorage) {
×
132
              this.prebidStorageManager.setDataInLocalStorage(cookieitem.key_name, cookieitem.advertising_token);
×
133
            }
134
            if (!settings?.dropCookie) {
×
135
              this.prebidStorageManager.setCookie(cookieitem.key_name, cookieitem.advertising_token);
×
136
            }
137
          });
138
          LockrAIMApiClient.canRefreshToken = true;
×
139
        } catch (_err) {
140
          this._logWarn(_err);
×
141
          rejectPromise(responseText);
×
142
          LockrAIMApiClient.canRefreshToken = true;
×
143
        }
144
      }
145
    }, JSON.stringify(requestBody), { method: 'POST', contentType: 'application/json;charset=UTF-8' });
146
    return promise;
×
147
  }
148

149
  async initializeRefresher() {
150
    setInterval(() => {
×
151
      LockrAIMApiClient.expiryDateKeys.forEach(expiryItem => {
×
152
        const currentMillis = new Date().getTime();
×
153
        const dateMillis = this.prebidStorageManager.getDataFromLocalStorage(expiryItem);
×
154
        if (currentMillis > dateMillis && dateMillis !== null && this.prebidStorageManager.getDataFromLocalStorage('ilui') && LockrAIMApiClient.canRefreshToken) {
×
155
          this.generateToken('refresh', this.prebidStorageManager.getDataFromLocalStorage('ilui'));
×
156
        }
157
      })
158
    }, 1000);
159
  }
160
}
161

162
// Register submodule for userId
163
submodule('userId', lockrAIMSubmodule);
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc