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

prebid / Prebid.js / #306

01 Jul 2025 06:03PM UTC coverage: 90.335% (-0.07%) from 90.409%
#306

push

travis-ci

prebidjs-release
Prebid 9.53.1 release

43587 of 54762 branches covered (79.59%)

64461 of 71358 relevant lines covered (90.33%)

148.96 hits per line

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

81.13
/modules/permutiveIdentityManagerIdSystem.js
1
import {MODULE_TYPE_UID} from '../src/activities/modules.js'
1✔
2
import {submodule} from '../src/hook.js'
3
import {getStorageManager} from '../src/storageManager.js'
4
import {prefixLog, safeJSONParse} from '../src/utils.js'
5
/**
6
 * @typedef {import('../modules/userId/index.js').Submodule} Submodule
7
 * @typedef {import('../modules/userId/index.js').SubmoduleConfig} SubmoduleConfig
8
 * @typedef {import('../modules/userId/index.js').ConsentData} ConsentData
9
 * @typedef {import('../modules/userId/index.js').IdResponse} IdResponse
10
 */
11

12
const MODULE_NAME = 'permutiveIdentityManagerId'
1✔
13
const PERMUTIVE_ID_DATA_STORAGE_KEY = 'permutive-prebid-id'
1✔
14

15
const ID5_DOMAIN = 'id5-sync.com'
1✔
16
const LIVERAMP_DOMAIN = 'liveramp.com'
1✔
17
const UID_DOMAIN = 'uidapi.com'
1✔
18

19
const PRIMARY_IDS = ['id5id', 'idl_env', 'uid2']
1✔
20

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

23
const logger = prefixLog('[PermutiveID]')
1✔
24

25
const readFromSdkLocalStorage = () => {
1✔
26
  const data = safeJSONParse(storage.getDataFromLocalStorage(PERMUTIVE_ID_DATA_STORAGE_KEY))
3✔
27
  const id = {}
3✔
28
  if (data && typeof data === 'object' && 'providers' in data && typeof data.providers === 'object') {
3✔
29
    const now = Date.now()
1✔
30
    for (const [idName, value] of Object.entries(data.providers)) {
1✔
31
      if (PRIMARY_IDS.includes(idName) && value.userId) {
2✔
32
        if (!value.expiryTime || value.expiryTime > now) {
1!
33
          id[idName] = value.userId
1✔
34
        }
35
      }
36
    }
37
  }
38
  return id
3✔
39
}
40

41
/**
42
 * Catch and log errors
43
 * @param {function} fn - Function to safely evaluate
44
 */
45
function makeSafe (fn) {
46
  try {
2✔
47
    return fn()
2✔
48
  } catch (e) {
49
    logger.logError(e)
×
50
  }
51
}
52

53
const waitAndRetrieveFromSdk = (timeoutMs) =>
1✔
54
  new Promise(
1✔
55
    resolve => {
56
      const fallback = setTimeout(() => {
1✔
57
        logger.logInfo('timeout expired waiting for SDK - attempting read from local storage again')
×
58
        resolve(readFromSdkLocalStorage())
×
59
      }, timeoutMs)
60
      return window?.permutive?.ready(() => makeSafe(() => {
1✔
61
        logger.logInfo('Permutive SDK is ready')
1✔
62
        const onReady = makeSafe(() => window.permutive.addons.identity_manager.prebid.onReady)
1✔
63
        if (typeof onReady === 'function') {
1!
64
          onReady((ids) => {
1✔
65
            logger.logInfo('Permutive SDK has provided ids')
1✔
66
            resolve(ids)
1✔
67
            clearTimeout(fallback)
1✔
68
          })
69
        } else {
70
          logger.logError('Permutive SDK initialised but identity manager prebid api not present')
×
71
        }
72
      }))
73
    }
74
  )
75

76
/** @type {Submodule} */
77
export const permutiveIdentityManagerIdSubmodule = {
1✔
78
  /**
79
   * used to link submodule with config
80
   * @type {string}
81
   */
82
  name: MODULE_NAME,
83

84
  /**
85
   * decode the stored id value for passing to bid requests
86
   * @function decode
87
   * @param {(Object|string)} value
88
   * @param {SubmoduleConfig|undefined} config
89
   * @returns {(Object|undefined)}
90
   */
91
  decode(value, config) {
92
    return value
1✔
93
  },
94

95
  /**
96
   * performs action to obtain id and return a value in the callback's response argument
97
   * @function getId
98
   * @param {SubmoduleConfig} submoduleConfig
99
   * @param {ConsentData} consentData
100
   * @param {(Object|undefined)} cacheIdObj
101
   * @returns {IdResponse|undefined}
102
   */
103
  getId(submoduleConfig, consentData, cacheIdObj) {
104
    const id = readFromSdkLocalStorage()
3✔
105
    if (Object.entries(id).length > 0) {
3✔
106
      logger.logInfo('found id in sdk storage')
1✔
107
      return { id }
1✔
108
    } else if ('params' in submoduleConfig && submoduleConfig.params.ajaxTimeout) {
2✔
109
      logger.logInfo('failed to find id in sdk storage - waiting for sdk')
1✔
110
      // Is ajaxTimeout an appropriate timeout to use here?
111
      return { callback: (done) => waitAndRetrieveFromSdk(submoduleConfig.params.ajaxTimeout).then(done) }
1✔
112
    } else {
113
      logger.logInfo('failed to find id in sdk storage and no wait time specified')
1✔
114
    }
115
  },
116

117
  primaryIds: PRIMARY_IDS,
118

119
  eids: {
120
    'id5id': {
121
      getValue: function (data) {
122
        return data.uid
×
123
      },
124
      source: ID5_DOMAIN,
125
      atype: 1,
126
      getUidExt: function (data) {
127
        if (data.ext) {
×
128
          return data.ext
×
129
        }
130
      }
131
    },
132
    'idl_env': {
133
      source: LIVERAMP_DOMAIN,
134
      atype: 3,
135
    },
136
    'uid2': {
137
      source: UID_DOMAIN,
138
      atype: 3,
139
      getValue: function(data) {
140
        return data.id
×
141
      },
142
      getUidExt: function(data) {
143
        if (data.ext) {
×
144
          return data.ext
×
145
        }
146
      }
147
    }
148
  }
149
}
150

151
submodule('userId', permutiveIdentityManagerIdSubmodule)
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