'use strict';
import { getS3Client } from '../tools/cloud-client.js';
import { environmentVariables } from '../constants/ci-constants.js';
import { setupClearNxCacheEnvironment } from '../setup/clear-nx-cache-environment.js';
import { cliLogError, cliLogInfo } from '../../../fd-toolbox/logging/cli-logger.js';
import { ListObjectsV2Command, DeleteObjectsCommand } from '@aws-sdk/client-s3';
import { getStringEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';

var __defProp=Object['defineProperty'],__name=(_0x106dfb,_0x253828)=>__defProp(_0x106dfb,'name',{'value':_0x253828,'configurable':!![]});async function clearNxCache(){try{setupClearNxCacheEnvironment();const _0x37a309=getStringEnvSetting(environmentVariables['r2NxCacheBucketName']),_0x2b6671=getS3Client();(!_0x2b6671||!_0x37a309)&&(cliLogError('Missing\x20required\x20environment\x20variables.'),process['exit'](0x168e+0x1f92+-0x361f));cliLogInfo('Deleting\x20NX\x20cache\x20from\x20bucket:\x20'+_0x37a309);let _0x3e7a67,_0x54024d=-0x22*0x1e+-0x1828*-0x1+-0x4*0x50b;do{const _0x3a0535=new ListObjectsV2Command({'Bucket':_0x37a309,'ContinuationToken':_0x3e7a67}),_0x2add26=await _0x2b6671['send'](_0x3a0535),_0x1f826a=_0x2add26['Contents']??[];if(_0x1f826a['length']===-0x1387*0x1+-0x2f0+0x1b*0xd5){cliLogInfo('No\x20objects\x20found\x20to\x20delete.');break;}const _0x1dc269=new DeleteObjectsCommand({'Bucket':_0x37a309,'Delete':{'Objects':_0x1f826a['map'](_0x535777=>({'Key':_0x535777['Key']}))}});await _0x2b6671['send'](_0x1dc269),_0x54024d+=_0x1f826a['length'],cliLogInfo('Deleted\x20'+_0x1f826a['length']+'\x20objects...'),_0x3e7a67=_0x2add26['IsTruncated']?_0x2add26['NextContinuationToken']:void(-0x9*0x223+-0x103d*0x1+-0x4*-0x8de);}while(_0x3e7a67);cliLogInfo('Done.\x20Deleted\x20total:\x20'+_0x54024d+'\x20objects.');}catch(_0xdf4793){cliLogError('Error\x20clearing\x20NX\x20cache:',_0xdf4793),process['exit'](-0x405+0x22b*0x7+0x23b*-0x5);}}__name(clearNxCache,'clearNxCache');

export { clearNxCache };
