'use strict';
import _0x58b317 from 'jsonwebtoken';
import { getConfig } from '../../../fd-toolbox/server/configs/configs.js';
import { isNullOrUndefined } from '../../../fd-toolbox/functions/value-checking-functions.js';
import { createError } from '../../../fd-toolbox/errors/errors.js';
import { metaErrorMessages } from '../../meta/constants/meta-error-messages-constants.js';
import { fdConfigKeys } from '../../../fd-toolbox/server/constants/configs/fd-config-keys.js';
import { userTokenConstants } from './user-token-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x27ba18,_0x5c23d2)=>__defProp(_0x27ba18,'name',{'value':_0x5c23d2,'configurable':!![]});const jwtKey=getConfig()[fdConfigKeys['jwtKey']]??'';function createToken(_0x173f35){const _0x1bc5dc=mapUserToUserPayload(_0x173f35);return _0x58b317['sign'](_0x1bc5dc,jwtKey,{'algorithm':userTokenConstants['signingAlgorithm'],'expiresIn':'14d'});}__name(createToken,'createToken');function decodeToken(_0x62a2a8){try{const _0x1e66c3=_0x58b317['verify'](_0x62a2a8,jwtKey,{'algorithms':[userTokenConstants['signingAlgorithm']]});if(isUserPayload(_0x1e66c3))return _0x1e66c3;else throw createError(metaErrorMessages['invalidToken']);}catch{return void(0x9*-0x327+0x4*-0x46a+0x1*0x2e07);}}__name(decodeToken,'decodeToken');function mapUserToUserPayload(_0x190780){return {'userId':_0x190780['id'],'email':_0x190780['email']};}__name(mapUserToUserPayload,'mapUserToUserPayload');function isUserPayload(_0x2d6c00){return !isNullOrUndefined(_0x2d6c00)&&typeof _0x2d6c00==='object'&&Object['keys'](_0x2d6c00)['every'](_0x5c9217=>_0x5c9217 in _0x2d6c00);}__name(isUserPayload,'isUserPayload');

export { createToken, decodeToken };
