import _regeneratorRuntime from '@babel/runtime/regenerator';
import { _ as __awaiter } from '../../tslib.es6-848120af.js';
import { fetchCloudData } from '../base/base.mjs';
import { AREA_MAP } from './config.mjs';
import 'axios';
import '../../nodejs/crypto.mjs';

/**
 * 刷新腾讯云 CDN URL 缓存
 * 提交 URL 刷新请求，使 CDN 节点上的缓存内容失效
 * @param {object} config 配置信息
 * @param {string} config.secretId 腾讯云 secretId
 * @param {string} config.secretKey 腾讯云 secretKey
 * @param {string} [config.area='mainland'] 刷新区域，默认为中国大陆
 * @param {Array<string>} config.urls 需要刷新的 URL 列表
 * @returns {Promise<any>} 刷新结果
 * @example
 * ```ts
 * await purgeUrlCache({
 *   secretId: 'xxx',
 *   secretKey: 'xxx',
 *   urls: ['https://cdn.example.com/file1.js', 'https://cdn.example.com/file2.css'],
 * });
 * ```
 */
function purgeUrlCache(_ref) {
  var secretId = _ref.secretId,
    secretKey = _ref.secretKey,
    _ref$area = _ref.area,
    area = _ref$area === void 0 ? AREA_MAP.MAINLAND : _ref$area,
    urls = _ref.urls;
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          return _context.abrupt("return", fetchCloudData({
            secretId: secretId,
            secretKey: secretKey,
            action: 'PurgeUrlsCache',
            version: '2018-06-06',
            endpoint: 'cdn.tencentcloudapi.com',
            service: 'cdn',
            // region: '',
            payload: JSON.stringify({
              Urls: urls,
              Area: area
            })
          }));
        case 1:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

export { purgeUrlCache };
