'use strict';
import { getRequiredStringEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';
import { envSettingKeys } from '../../common/infra/env-setting-keys.js';
import { postBaseApi } from '../../../fd-toolbox/api/base-api.js';
import { fedexTestApi, fedexRoutes } from './shipment-constants.js';
import { httpContentTypes } from '../../../fd-toolbox/constants/header-names.js';
import { tryGetFromCoreCache, setCoreCache } from '../../../fd-toolbox/server/cachings/core-cache.js';
import { oAuthGrantTypes, oAuthTokenResponseFields } from '../../../fd-toolbox/constants/internal-auth-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x322039,_0x4c8610)=>__defProp(_0x322039,'name',{'value':_0x4c8610,'configurable':!![]});const fedexTokenKey='fedex_api_token';async function getFedexTokenFromApi(){const _0x180d6d={'grant_type':oAuthGrantTypes['clientCredentials'],'client_id':getRequiredStringEnvSetting(envSettingKeys['fedexApiKey']),'client_secret':getRequiredStringEnvSetting(envSettingKeys['fedexSecretKey'])},_0x4b33cd=new Headers();_0x4b33cd['append'](httpContentTypes['contentTypeHeaderName'],httpContentTypes['contentTypeApplicationForm']);const _0x328303=await postBaseApi(fedexTestApi+fedexRoutes['token'],new URLSearchParams(_0x180d6d),_0x4b33cd);return _0x328303[oAuthTokenResponseFields['token']];}__name(getFedexTokenFromApi,'getFedexTokenFromApi');async function getFedexToken(){const _0x3c9de8=await tryGetFromCoreCache(fedexTokenKey);if(!_0x3c9de8){const _0x5da64c=await getFedexTokenFromApi();return await setCoreCache(fedexTokenKey,{'token':_0x5da64c}),_0x5da64c;}return _0x3c9de8['token'];}__name(getFedexToken,'getFedexToken');

export { fedexTokenKey, getFedexToken, getFedexTokenFromApi };
