import { DynamoDBClient, PutItemCommand, GetItemCommand, PutItemCommandInput, PutItemCommandOutput, GetItemCommandInput, } from '@aws-sdk/client-dynamodb'; import { unmarshall, marshall } from '@aws-sdk/util-dynamodb'; import configuration from '../aws/configuration'; import TABLE_NAMES from '../constants/tableNames'; import { IToken } from '../interfaces/IToken'; import { ITokenRepository } from '../interfaces/ITokenRepository'; const doc_client = new DynamoDBClient({ region: `${configuration.REGION}` }); class TokenRepository implements ITokenRepository { async getToken(data_event: string): Promise { const input: GetItemCommandInput = { TableName: TABLE_NAMES.CORE_TOKEN, Key: { date: { S: data_event }, }, }; const command = new GetItemCommand(input); const response = await doc_client.send(command); const item = unmarshall(response.Item) as IToken; return item; } async saveToken(token_data: IToken): Promise { const input: PutItemCommandInput = { TableName: TABLE_NAMES.CORE_TOKEN, Item: marshall(token_data), }; const command = new PutItemCommand(input); const put_response = await doc_client.send(command); return put_response; } } export default TokenRepository;