INNER CODE UNIT · TypeScript

CalApi

rowboatlabs/rowboat · apps/harbor/packages/server/src/connectors/cal/index.ts:45

export class CalApi {
  private me?: Promise<Me>;

  constructor(
    private readonly key: string,
    private readonly base: string = CAL_API,
  ) {}

  private call(path: string, version: string | undefined, init: RequestInit = {}): Promise<unknown> {
    const headers: Record<string, string> = { authorization: `Bearer ${this.key}`, 'content-type': 'application/json' };
    if (version) headers['cal-api-version'] = version;
    return requestJson(`${this.base}${path}`, { ...init, headers }).then((body) => (body as { data?: unknown })?.data);
  }

  profile(): Promise<Me> {
    this.me ??= (this.call('/me', undefined) as Promise<Me>).catch((err) => {
      this.me = undefined;
      throw err;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…