Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

3.4 KB
Raw Blame
// This file is auto-generated by @hey-api/openapi-ts

import type { Client, ClientMeta, Options as Options2, RequestResult, TDataShape } from './client';
import { client } from './client.gen';
import type { GetUnfurlBulkData, GetUnfurlBulkErrors, GetUnfurlBulkResponses, GetUnfurlData, GetUnfurlErrors, GetUnfurlResponses, ProxyRequestHandlerData } from './types.gen';

export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = Options2<TData, ThrowOnError, TResponse> & {
    /**
     * You can provide a client instance returned by `createClient()` instead of
     * individual options. This might be also useful if you want to implement a
     * custom client.
     */
    client?: Client;
    /**
     * You can pass arbitrary values through the `meta` object. This can be
     * used to access values that aren't defined as part of the SDK function.
     */
    meta?: keyof ClientMeta extends never ? Record<string, unknown> : ClientMeta;
};

class HeyApiClient {
    protected client: Client;

    constructor(args?: {
        client?: Client;
    }) {
        this.client = args?.client ?? client;
    }
}

class HeyApiRegistry<T> {
    private readonly defaultKey = 'default';

    private readonly instances: Map<string, T> = new Map();

    get(key?: string): T {
        const instance = this.instances.get(key ?? this.defaultKey);
        if (!instance) {
            throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`);
        }
        return instance;
    }

    set(value: T, key?: string): void {
        this.instances.set(key ?? this.defaultKey, value);
    }
}

export class Sdk extends HeyApiClient {
    public static readonly __registry: HeyApiRegistry<Sdk> = new HeyApiRegistry<Sdk>();

    constructor(args?: {
        client?: Client;
        key?: string;
    }) {
        super(args);
        Sdk.__registry.set(this, args?.key);
    }

    public proxyRequestHandler<ThrowOnError extends boolean = false>(options: Options<ProxyRequestHandlerData, ThrowOnError>): RequestResult<unknown, unknown, ThrowOnError> {
        return (options.client ?? this.client).get<unknown, unknown, ThrowOnError>({ url: '/proxy', ...options });
    }

    /**
     * Unfurl the URL passed via the `url` query parameter and return its
     * extracted metadata (title, description, image, favicon).
     *
     * On success returns `200` with a [`GetUnfurlResponse`] body. On any
     * failure returns `500` with a JSON `null` body — the response type is an
     * `Option<GetUnfurlResponse>` so this contract is reflected in the
     * signature and OpenAPI spec.
     */
    public getUnfurl<ThrowOnError extends boolean = false>(options: Options<GetUnfurlData, ThrowOnError>): RequestResult<GetUnfurlResponses, GetUnfurlErrors, ThrowOnError> {
        return (options.client ?? this.client).get<GetUnfurlResponses, GetUnfurlErrors, ThrowOnError>({ url: '/unfurl', ...options });
    }

    public getUnfurlBulk<ThrowOnError extends boolean = false>(options: Options<GetUnfurlBulkData, ThrowOnError>): RequestResult<GetUnfurlBulkResponses, GetUnfurlBulkErrors, ThrowOnError> {
        return (options.client ?? this.client).post<GetUnfurlBulkResponses, GetUnfurlBulkErrors, ThrowOnError>({
            url: '/unfurl/bulk',
            ...options,
            headers: {
                'Content-Type': 'application/json',
                ...options.headers
            }
        });
    }
}