@aoc-ts/api
v1.1.0
Published
API for Advent of Code
Readme
Advent of Code - API Client
This package, @aoc-ts/api, provides a lightweight, zero-dependency client for interacting with the Advent of Code API.
Features
- Fetch Puzzle Input: Download the input for a specific day and year.
- Fetch Puzzle Instructions: Get the puzzle description in Markdown format.
- Submit Answers: Post your solution and get feedback directly.
- Session Management: Uses a local configuration to store your Advent of Code session token.
Installation
This package is intended for internal use within the aoc-starter-kit monorepo.
API
getInput(props: { day: number, year: number })
Fetches the puzzle input as a string.
Example:
import { getInput } from '@aoc-ts/api';
const input = await getInput({ year: 2024, day: 1 });
console.log(input);getInstruction(props: { day: number, year: number })
Fetches the puzzle instructions as a Markdown string.
Example:
import { getInstruction } from '@aoc-ts/api';
const instruction = await getInstruction({ year: 2024, day: 1 });
console.log(instruction);postAnswer(props: { day: number, year: number, level: 1 | 2, answer: string | number })
Submits an answer for a given puzzle.
Example:
import { postAnswer } from '@aoc-ts/api';
await postAnswer({
year: 2024,
day: 1,
level: 1,
answer: 'your-answer',
});Configuration
The API client requires a session token to communicate with the Advent of Code API. The @aoc-ts/generator CLI will prompt you for this token and save it to a local configuration file (~/.config/configstore/aoc-ts.json).
The client will automatically use the stored session token for all API requests.
