'use strict';
import { readFile } from 'node:fs/promises';
import { npmPackages } from '../../../base-repo/constants/packages.js';
import { stringEncodingNames } from '../../../base-repo/app-constants/internal-system-constants.js';
import { npmRegistry } from '../constants/npm-commands.js';
import { ciLogMessages, environmentVariables } from '../constants/ci-constants.js';
import { getLatestNpmPackageInfo } from './get-latest-npm-package-info.js';
import { pathExists } from '../tools/exec.js';
import { createEarlyInfraError } from '../tools/create-early-infra-error.js';
import { cliLogInfo, cliLogSeparator, cliLogSubtitle, cliLogError, cliLogSuccess } from '../../../fd-toolbox/logging/cli-logger.js';
import { getBooleanEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';

var __defProp=Object['defineProperty'],__name=(_0x181cb6,_0x362c00)=>__defProp(_0x181cb6,'name',{'value':_0x362c00,'configurable':!![]});async function verifyPublishedVersion(_0x19ae22){const _0x3e5393=new URL(npmPackages['saasKit'],'https://'+npmRegistry['url'])['toString']();if(!pathExists(_0x19ae22))throw createEarlyInfraError('CRITICAL:\x20Version\x20artifact\x20\x27'+_0x19ae22+'\x27\x20not\x20found.');const _0x31367d=await readFile(_0x19ae22,stringEncodingNames['utfDash8']),_0x3762b6=_0x31367d['trim']();if(!_0x3762b6)throw createEarlyInfraError(''+ciLogMessages['artifactPrefix']+_0x19ae22+'\x27\x20is\x20empty.');cliLogInfo('Expected\x20version\x20from\x20artifact:\x20'+_0x3762b6),cliLogSeparator(),cliLogSubtitle('Verifying\x20package\x20version\x20by\x20fetching\x20from:\x20'+_0x3e5393);const {version:_0x4b39dc,data:_0x59bc68}=await getLatestNpmPackageInfo(_0x3e5393),_0x300496={[npmRegistry['distTagsKey']]:_0x59bc68[npmRegistry['distTagsKey']],'version':_0x4b39dc};cliLogInfo(JSON['stringify'](_0x300496,void(0x4*0xf7+-0x49*0x1+-0x3*0x131),0x1*-0x1357+0x15f3+-0x29a));const _0x5bb917=getBooleanEnvSetting(environmentVariables['ciPublishAndTestPackageDryRun']),_0x1b5468=_0x5bb917?_0x3762b6===_0x4b39dc:_0x3762b6!==_0x4b39dc;if(_0x1b5468){const _0x1ec032=['CRITICAL:\x20Version\x20mismatch!','Artifact\x20says\x20\x27'+_0x3762b6+'\x27,\x20but\x20NPM\x20registry\x20has\x20\x27'+_0x4b39dc+'\x27.']['join']('\x20');cliLogError(_0x1ec032);throw createEarlyInfraError(_0x1ec032);}return _0x5bb917?(cliLogInfo(''+ciLogMessages['dryRun']+environmentVariables['ciPublishAndTestPackageDryRun']+'\x27\x20is\x20active.\x20Bypassing\x20the\x20version\x20mismatch\x20error.'),cliLogInfo('[DRY\x20RUN]\x20The\x20pipeline\x20successfully\x20built\x20and\x20recorded\x20the\x20existing\x20version\x20\x27'+_0x3762b6+'\x27.'),cliLogInfo('[DRY\x20RUN]\x20However,\x20the\x20actual\x20NPM\x20registry\x20currently\x20holds\x20version\x20\x27'+_0x4b39dc+'\x27.'),cliLogInfo('[DRY\x20RUN]\x20This\x20behavior\x20is\x20expected\x20because\x20the\x20actual\x20publish\x20process\x20was\x20skipped\x20in\x20dry-run\x20mode.')):cliLogSuccess('Verification\x20successful:\x20Registry\x20version\x20matches\x20expected\x20version\x20(\x27'+_0x4b39dc+'\x27).'),{'expectedVersion':_0x3762b6,'actualVersion':_0x4b39dc};}__name(verifyPublishedVersion,'verifyPublishedVersion');

export { verifyPublishedVersion };
