'use strict';
import _0x589480 from 'process';
import { aliasSymbols } from '../../../base-repo/app-constants/aliases.js';
import { nonRootProjectPaths } from '../../../base-repo/app-constants/project-paths.js';
import { npmPackages } from '../../../base-repo/constants/packages.js';
import { ciArtifacts } from '../../../base-repo/constants/gitlab.js';
import { environmentVariables } from '../constants/ci-constants.js';
import { verifyPublishedVersion } from '../setup/verify-published-version.js';
import { setupNpmAuth, cleanupNpmAuth } from '../setup/npm-auth.js';
import { execSyncCommand } from '../tools/exec.js';
import { npmUnpublish } from '../tools/npm-command-funcs.js';
import { cliLogSubtitle, cliLogSeparator, cliLogError, cliLogInfo } from '../../../fd-toolbox/logging/cli-logger.js';
import { getBooleanEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';
import { logDryRun } from './sync-saas-kit-version-to-main.js';

var __defProp=Object['defineProperty'],__name=(_0x4c2d6f,_0x44ab9a)=>__defProp(_0x4c2d6f,'name',{'value':_0x44ab9a,'configurable':!![]});async function unpublishPackage(){cliLogSubtitle('Initiating\x20rollback:\x20unpublishing\x20package'),cliLogSeparator();let _0x33bd96;try{cliLogSubtitle('Step\x201:\x20Reading\x20version\x20to\x20unpublish\x20from\x20artifact');const _0x4c9806=await verifyPublishedVersion(ciArtifacts['ciSaasKitPublishVersionFile']);_0x33bd96=_0x4c9806['expectedVersion'];}catch(_0x525a03){cliLogError('Automated\x20unpublish\x20aborted\x20due\x20to\x20inconsistent\x20state'),cliLogError('Reason:\x20The\x20\x27latest\x27\x20version\x20in\x20NPM\x20does\x20not\x20match\x20the\x20version\x20published\x20by\x20this\x20pipeline.'),cliLogError('This\x20requires\x20manual\x20intervention.\x0a',_0x525a03),_0x589480['exit'](0x17*0x17b+-0x4*0x8be+0x3b*0x4);}cliLogSeparator(),cliLogSubtitle('Step\x202:\x20Setting\x20up\x20NPM\x20authentication');const {npmrcPath:_0x747ed2,originalContent:_0x2a1e00}=await setupNpmAuth(nonRootProjectPaths['currentDirRef']);cliLogSeparator();try{const _0x4009c6=npmPackages['saasKit']+aliasSymbols['atSign']+_0x33bd96;cliLogSubtitle('Step\x203:\x20Unpublishing\x20package\x20\x27'+_0x4009c6+'\x27');const _0x53e44e=npmUnpublish(_0x4009c6);cliLogInfo('Executing\x20command:\x20'+_0x53e44e);const _0x2ea2bb=getBooleanEnvSetting(environmentVariables['ciPublishAndTestPackageDryRun']);if(_0x2ea2bb){const _0x353b95='[DRY\x20RUN]\x20Bypassing\x20actual\x20execution\x20of\x20the\x20unpublish\x20command\x20to\x20avoid\x20failure\x20(package\x20was\x20never\x20published).';logDryRun(_0x353b95);}else execSyncCommand(_0x53e44e);cliLogSeparator();}catch(_0x5b7e79){cliLogError('Emergency\x20rollback\x20failed.\x20Manual\x20intervention\x20may\x20be\x20required.');throw _0x5b7e79;}finally{cliLogSubtitle('Step\x204:\x20Cleaning\x20up\x20npm\x20authentication\x20files'),await cleanupNpmAuth(_0x747ed2,_0x2a1e00);}}__name(unpublishPackage,'unpublishPackage');

export { unpublishPackage };
