"use strict";const UPDATE_ID_SEP=":",BUILD_PREFIX="b",PRODUCT_EFFECT="effect",PRODUCT_SAMPLER="sampler",PRODUCT_M4L="m4l",CHANNEL_ALPHA="alpha",CHANNEL_NIGHTLY="nightly",PLATFORM_MAC="mac",PLATFORM_WIN="win",MAX_NUMERIC_FIELD_DIGITS=15;function isAllDigits(e){return"string"==typeof e&&e.length>0&&e.length<=15&&/^[0-9]+$/.test(e)}function makeUpdateId(e,r,t,i){return e+":"+r+":"+t+":b"+String(i)}const VERSION_PREFIX="v";function makeDismissalKey(e,r,t,i,a){return"alpha"===r?e+":"+r+":"+t+":v"+String(a):makeUpdateId(e,r,t,i)}function parseUpdateId(e){const r={valid:!1};if("string"!=typeof e)return r;const t=e.split(":");if(4!==t.length)return r;const i=t[3];if(i.length<2||"b"!==i[0])return r;const a=i.slice(1);return isAllDigits(a)&&t[0]&&t[1]&&t[2]?{valid:!0,product:t[0],channel:t[1],platform:t[2],build:Number(a)}:r}function isNewerBuild(e,r){return e>r}function parseSemver(e){const r={valid:!1};if("string"!=typeof e)return r;const t=e.split(".");if(3!==t.length)return r;for(const e of t)if(!isAllDigits(e))return r;return{valid:!0,major:Number(t[0]),minor:Number(t[1]),patch:Number(t[2])}}function isNewerVersion(e,r){const t=parseSemver(e),i=parseSemver(r);return!(!t.valid||!i.valid)&&(t.major!==i.major?t.major>i.major:t.minor!==i.minor?t.minor>i.minor:t.patch>i.patch)}function validateManifest(e,r,t,i){if(!e||"object"!=typeof e)return{ok:!1,error:"no manifest"};if(e.product!==r)return{ok:!1,error:"product mismatch"};if(e.channel!==t)return{ok:!1,error:"channel mismatch"};if(e.platform!==i)return{ok:!1,error:"platform mismatch"};const a=Number(e.latestBuild);if(!Number.isFinite(a)||a<=0)return{ok:!1,error:"invalid latestBuild"};const n=parseUpdateId(e.updateId);return n.valid&&n.product===e.product&&n.channel===e.channel&&n.platform===e.platform&&n.build===a?{ok:!0,error:""}:{ok:!1,error:"updateId inconsistent with manifest fields"}}function isUpdateAvailable(e,r,t,i,a,n){const s=validateManifest(e,r,t,i);if(!s.ok)return{available:!1,error:s.error};return{available:"alpha"===t?isNewerVersion(e.version,n):isNewerBuild(Number(e.latestBuild),a),error:""}}module.exports={UPDATE_ID_SEP:":",BUILD_PREFIX:"b",VERSION_PREFIX:"v",MAX_NUMERIC_FIELD_DIGITS:15,PRODUCT_EFFECT:"effect",PRODUCT_SAMPLER:"sampler",PRODUCT_M4L:"m4l",CHANNEL_ALPHA:"alpha",CHANNEL_NIGHTLY:"nightly",PLATFORM_MAC:"mac",PLATFORM_WIN:"win",makeUpdateId:makeUpdateId,makeDismissalKey:makeDismissalKey,parseUpdateId:parseUpdateId,isNewerBuild:isNewerBuild,parseSemver:parseSemver,isNewerVersion:isNewerVersion,validateManifest:validateManifest,isUpdateAvailable:isUpdateAvailable};