{"version":3,"file":"isDeviceIdEnabled.cjs","names":[],"sources":["../../src/utils/isDeviceIdEnabled.ts"],"sourcesContent":["const DIGITS = 6;\n\n/**\n * Determines whether a deviceId is enabled for the given pctEnabled. This is achieved\n * by taking a normalized hex value from the last 6 digits of the device ID, and comparing\n * it against the enabled percentage. This ensures that devices are consistently in a given\n * group for beta functionality.\n *\n * This can be used to:\n * - Select sample devices for telemetry collection\n * - Enable/disable features for a percentage of users\n *\n * The normalized device ID has 16^6 possibilities (roughly 1.6m) which should be sufficient\n * granularity for our needs.\n */\nexport const isDeviceIdEnabled = (deviceId: string, pctEnabled?: number) => {\n  if (!pctEnabled || pctEnabled <= 0 || pctEnabled > 100) {\n    return false;\n  }\n\n  const normalizedDeviceId = getNormalizedDeviceId(deviceId);\n\n  return pctEnabled >= normalizedDeviceId;\n};\n\nexport const getNormalizedDeviceId = (deviceId: string): number => {\n  if (deviceId.length < DIGITS) {\n    return 0;\n  }\n\n  const finalChars = deviceId.slice(-DIGITS); // last 6 chars\n  const radix = 16;\n  const space = radix ** DIGITS - 1;\n  const value = parseInt(finalChars, radix);\n\n  return (value / space) * 100;\n};\n"],"mappings":";;AAAA,MAAM,SAAS;;;;;;;;;;;;;;AAef,MAAa,qBAAqB,UAAkB,eAAwB;AAC1E,KAAI,CAAC,cAAc,cAAc,KAAK,aAAa,IACjD,QAAO;AAKT,QAAO,cAFoB,sBAAsB,SAAS;;AAK5D,MAAa,yBAAyB,aAA6B;AACjE,KAAI,SAAS,SAAS,OACpB,QAAO;CAGT,MAAM,aAAa,SAAS,MAAM,CAAC,OAAO;CAC1C,MAAM,QAAQ;CACd,MAAM,QAAQ,SAAS,SAAS;AAGhC,QAFc,SAAS,YAAY,MAAM,GAEzB,QAAS"}