'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _regeneratorRuntime = require('@babel/runtime/regenerator');
var tslib_es6 = require('../../tslib.es6-0d92ef81.js');
var tencentCloud_base_base = require('../base/base.js');
var tencentCloud_cdn_config = require('./config.js');
require('axios');
require('../../nodejs/crypto.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);

/**
 * 刷新腾讯云 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 ? tencentCloud_cdn_config.AREA_MAP.MAINLAND : _ref$area,
    urls = _ref.urls;
  return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
    return _regeneratorRuntime__default["default"].wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          return _context.abrupt("return", tencentCloud_base_base.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);
  }));
}

exports.purgeUrlCache = purgeUrlCache;
