From c3ae2f889c65c55941820b2b8e774c00263a77e5 Mon Sep 17 00:00:00 2001 From: Marcelo Alves Date: Sun, 5 Oct 2025 20:25:40 -0700 Subject: [PATCH] feat: add code vault api --- get/src/codes.ts | 2 ++ get/src/source/codevault.ts | 26 ++++++++++++++++++++++++++ get/src/source/orcicorn.ts | 7 +------ get/src/utils/parseDate.ts | 5 +++++ 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 get/src/source/codevault.ts create mode 100644 get/src/utils/parseDate.ts diff --git a/get/src/codes.ts b/get/src/codes.ts index a9ceeef..187e6d7 100644 --- a/get/src/codes.ts +++ b/get/src/codes.ts @@ -1,7 +1,9 @@ import { getOrcicornShiftCodes } from './source/orcicorn'; import { getFextralifeShiftCodes } from './source/fextralife'; +import { getCodeVaultShiftCodes } from './source/codevault'; export async function * getShiftCodes() { yield * getFextralifeShiftCodes(); yield * getOrcicornShiftCodes(); + yield * getCodeVaultShiftCodes(); } diff --git a/get/src/source/codevault.ts b/get/src/source/codevault.ts new file mode 100644 index 0000000..a38446f --- /dev/null +++ b/get/src/source/codevault.ts @@ -0,0 +1,26 @@ +import { ShiftCode } from '../types'; + +import { parseDate } from '../utils/parseDate'; + +const BL4_SHIFT_CODES_URL = 'https://code-vault.celo.workers.dev/api/codes'; + +export async function* getCodeVaultBL4ShiftCodes(): AsyncGenerator { + const response = await fetch(BL4_SHIFT_CODES_URL); + const json = (await response.json()) as { + data: { code: string; created_at: string }[]; + }; + + for (const entry of json.data) { + yield { + code: entry.code, + game: 'Borderlands 4', + platform: 'Universal', + reward: 'Unknown', + created: parseDate(entry.created_at), + }; + } +} + +export async function* getCodeVaultShiftCodes(): AsyncGenerator { + yield* getCodeVaultBL4ShiftCodes(); +} diff --git a/get/src/source/orcicorn.ts b/get/src/source/orcicorn.ts index bc2ba99..bcb3ee3 100644 --- a/get/src/source/orcicorn.ts +++ b/get/src/source/orcicorn.ts @@ -3,15 +3,10 @@ const Pick = require('stream-json/filters/Pick'); const {streamValues} = require('stream-json/streamers/StreamValues'); import { ShiftCode } from '../types'; +import { parseDate } from '../utils/parseDate'; const SHIFT_CODES_URL = 'https://shift.orcicorn.com/shift-code/index.json'; -function parseDate(str: string) { - const date = new Date(str); - if (isNaN(date.valueOf())) return undefined; - return date; -} - export async function * getOrcicornShiftCodes(): AsyncGenerator { const response = await fetch(SHIFT_CODES_URL); diff --git a/get/src/utils/parseDate.ts b/get/src/utils/parseDate.ts new file mode 100644 index 0000000..0e9e1d6 --- /dev/null +++ b/get/src/utils/parseDate.ts @@ -0,0 +1,5 @@ +export function parseDate(str: string) { + const date = new Date(str); + if (isNaN(date.valueOf())) return undefined; + return date; +}