Skip to content
← Public packages

@jpfi/stories

Create personalized Teddy & Pinguin bedtime stories for your child and get the finished text back.

FollowFork

src/check-connection.ts

25 lines · 1.0 KB · TypeScript
Raw
import { packageStorage } from "kody:runtime";

import type { CheckConnectionInput, ConnectionStatus } from "./domain";
import { openStorySession } from "./story-run";

/**
 * Check whether the stored `teddyPinguinToken` reaches a Teddy & Pinguin account.
 * Call this before the first story, after saving or rotating the token, and whenever a
 * story call returns `disconnected`. Read-only: no story is created and no quota is spent.
 *
 * @param input - Optional `contentLocale` for the message language (defaults to `"de"`)
 * @returns `connected`, `disconnected` with a `tokenSetupUrl`, or `unreachable`
 *
 * @example
 * import checkConnection from 'kody:@jpfi/stories/check-connection'
 *
 * const connection = await checkConnection()
 * if (connection.status !== 'connected') console.log(connection.message)
 */
export default async function checkConnection(
  input: CheckConnectionInput = {},
): Promise<ConnectionStatus> {
  const session = await openStorySession(await packageStorage());
  return session.checkConnection(input);
}