UNPKG

@gnosticdev/highlevel-sdk

Version:
199 lines (195 loc) 6.74 kB
import { A as AccessType, H as HighLevelScopes } from './type-utils-BG2wp-D1.js'; import { H as HighLevelClient, D as DefaultOauthClient, A as AuthHeaders, a as HighLevelClientConfig, b as HighLevelOauthConfig, c as HighLevelClientWithOAuth } from './default-CCCeHE9L.js'; import 'openapi-fetch'; import './types/blogs.js'; import './types/businesses.js'; import './types/calendars.js'; import './types/campaigns.js'; import './types/companies.js'; import './types/contacts.js'; import './types/conversations.js'; import './types/courses.js'; import './types/custom-menus.js'; import './types/email-isv.js'; import './types/emails.js'; import './types/forms.js'; import './types/funnels.js'; import './types/invoices.js'; import './types/links.js'; import './types/locations.js'; import './types/medias.js'; import './types/opportunities.js'; import './types/payments.js'; import './types/products.js'; import './types/saas-api.js'; import './types/snapshots.js'; import './types/social-media-posting.js'; import './types/surveys.js'; import './types/users.js'; import './types/workflows.js'; import './types/oauth.js'; import 'openapi-fetch/src/index.js'; type PrivateIntegrationConfig<T extends AccessType> = { /** * The access type for the integration. Decides what scopes are available. */ accessType: T; /** * The private integration token. * * @see https://help.leadconnectorhq.com/support/solutions/articles/155000002774-private-integrations-everything-you-need-to-know */ privateToken: string; /** * The scopes for the integration. * * @example * ```ts * // use all available scopes * const scopes = new ScopesBuilder().all().join(' ') * ``` */ scopes?: HighLevelScopes<T>; }; /** * HighLevel API client using private integration token for authentication. * To create an instance, use the `createHighLevelClient` function from the main client. * * @see {@link createHighLevelClient} * * @example * ```ts * const client = createHighLevelClient({}, 'integration', { * privateToken: 'your-token', * accessType: 'Sub-Account', * scopes: ['contacts.readonly'] * }) * ``` * @internal */ declare class HighLevelIntegrationClient<T extends AccessType> extends HighLevelClient<T, DefaultOauthClient, AuthHeaders> { /** * The private token for the integration * * @see https://help.leadconnectorhq.com/support/solutions/articles/155000002774-private-integrations-everything-you-need-to-know */ privateToken: string; /** * The scopes for the integration. * * _NOTE_: in a private integration, we never send off the scopes like we do in Oauth2, but leaving this here for potential future use. * * @example * ```ts * const scopes = new ScopesBuilder().all().build() * ``` */ scopes?: HighLevelScopes<T>; constructor( /** * The integration config uses your private token and scopes to add the appropriate headers to the client. */ integrationConfig: PrivateIntegrationConfig<T>, /** * The `openapi-fetch` client config. * * @default { baseUrl: `https://services.leadconnectorhq.com` } * * @see https://openapi-ts.dev/openapi-fetch */ clientConfig?: HighLevelClientConfig); } type AuthConfig<T extends AccessType, TType extends 'oauth' | 'integration'> = TType extends 'oauth' ? HighLevelOauthConfig<T> : PrivateIntegrationConfig<T>; type AuthClient<T extends AccessType, TType extends 'oauth' | 'integration' = never> = TType extends never ? HighLevelClient<T, DefaultOauthClient, undefined> : TType extends 'oauth' ? HighLevelClientWithOAuth<T> : HighLevelIntegrationClient<T>; /** * Creates a HighLevel client with typed endpoints. * * @param clientConfig - the client configuration that will be used on each request. * @param authType - the type of authentication to use. * @param authConfig - the authentication configuration for either OAuth or Private Integration. * * @example * ```ts * // basic client * const client = createHighLevelClient() * const contacts = client.contacts.GET('/contacts/', { * params: { * header: { * Authorization: 'Bearer 1234567890', * Version: '2021-07-28', * }, * query: { * locationId: '1234567890', * query: 'John Doe', * }, * }, * }) * ``` */ declare function createHighLevelClient<T extends AccessType>(): HighLevelClient<T, DefaultOauthClient, undefined>; /** * Creates a default HighLevel client with typed endpoints. * * @example * ```ts * // pass in client config * const client = createHighLevelClient({ baseUrl: 'https://custom-url.com' }) * ``` */ declare function createHighLevelClient<T extends AccessType>(clientConfig?: HighLevelClientConfig): HighLevelClient<T, DefaultOauthClient, undefined>; /** * Creates a HighLevel client with support for OAuth. * * @example * ```ts * // client with OAuth * const client = createHighLevelClient({}, 'oauth', { * clientId: 'your-client-id', * clientSecret: 'your-client-secret', * redirectUri: 'http://localhost:3000/callback', * accessType: 'Sub-Account', * scopes: ['contacts.readonly'], * storageFunction: async (tokenData) => { * await db.set('tokenData', tokenData) * return tokenData * } * }) * const authUrl = client.oauth.getAuthorizationUrl() * // redirect to authUrl, get the code from your callback route. * app.get('/auth/callback', async (c) => { * const code = c.req.query('code') * if (!code) { * throw new Error('No code found in callback') * } * const token = await client.oauth.getAccessToken(code) * const contacts = client.contacts.GET('/contacts/', { * params: { * query: { * locationId: '1234567890', * query: 'John Doe', * }, * header: { * Authorization: `Bearer ${token}`, * Version: '2021-07-28', * }, * }, * }) * return c.json(contacts) * }) * ``` */ declare function createHighLevelClient<T extends AccessType, TType extends 'oauth' | 'integration' = 'oauth'>(clientConfig?: HighLevelClientConfig, authType?: TType, authConfig?: AuthConfig<T, TType>): AuthClient<T, TType>; /** * Creates a HighLevel client with support for Private Integration. * * @example * ```ts * const client = createHighLevelClient({}, 'integration', { * privateToken: 'your-token', * accessType: 'Agency', * scopes: ['saas/company.write'] * }) * ``` */ declare function createHighLevelClient<T extends AccessType, TType extends 'oauth' | 'integration' = 'integration'>(clientConfig?: HighLevelClientConfig, authType?: TType, authConfig?: AuthConfig<T, TType>): AuthClient<T, TType>; export { createHighLevelClient };