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.1 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 { SimpleUnifiedSearchData, SimpleUnifiedSearchErrors, SimpleUnifiedSearchResponses, UnifiedSearchData, UnifiedSearchErrors, UnifiedSearchResponses } 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);
    }

    /**
     * Perform a search through all items
     */
    public unifiedSearch<ThrowOnError extends boolean = false>(options: Options<UnifiedSearchData, ThrowOnError>): RequestResult<UnifiedSearchResponses, UnifiedSearchErrors, ThrowOnError> {
        return (options.client ?? this.client).post<UnifiedSearchResponses, UnifiedSearchErrors, ThrowOnError>({
            url: '/search',
            ...options,
            headers: {
                'Content-Type': 'application/json',
                ...options.headers
            }
        });
    }

    /**
     * Perform a search through all items.
     * This is a simple search where we do not group your results by entity id.
     */
    public simpleUnifiedSearch<ThrowOnError extends boolean = false>(options: Options<SimpleUnifiedSearchData, ThrowOnError>): RequestResult<SimpleUnifiedSearchResponses, SimpleUnifiedSearchErrors, ThrowOnError> {
        return (options.client ?? this.client).post<SimpleUnifiedSearchResponses, SimpleUnifiedSearchErrors, ThrowOnError>({
            url: '/search/simple',
            ...options,
            headers: {
                'Content-Type': 'application/json',
                ...options.headers
            }
        });
    }
}