@gnosticdev/highlevel-sdk
Version:
SDK for the HighLevel API
58 lines (57 loc) • 2.22 kB
JavaScript
import { t as HighLevelSDKError } from "./errors-DX_S3nKC.js";
import { i as BaseHighLevelClient, r as HighLevelClient, t as HighLevelClientWithOAuth } from "./with-oauth-oPQ6dCjf.js";
import createClient from "openapi-fetch";
//#region src/v2/client/with-integration.ts
/**
* 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
*/
var HighLevelIntegrationClient = class extends BaseHighLevelClient {
/**
* The private token for the integration
*
* @see https://help.leadconnectorhq.com/support/solutions/articles/155000002774-private-integrations-everything-you-need-to-know
*/
privateToken;
/**
* 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;
constructor(integrationConfig, clientConfig) {
const authHeaders = {
Authorization: `Bearer ${integrationConfig.privateToken}`,
Version: "2021-07-28"
};
super(clientConfig, authHeaders);
this.privateToken = integrationConfig.privateToken;
}
};
//#endregion
//#region src/v2/index.ts
function createHighLevelClient(clientConfig, authType, authConfig) {
if (!authType || !authConfig) return new HighLevelClient(clientConfig);
if (authType === "oauth" && "clientId" in authConfig && "clientSecret" in authConfig && "redirectUri" in authConfig && "accessType" in authConfig && "scopes" in authConfig) return new HighLevelClientWithOAuth(authConfig, clientConfig);
if (authType === "integration" && "privateToken" in authConfig) return new HighLevelIntegrationClient(authConfig, clientConfig);
throw new HighLevelSDKError("INVALID_AUTH_TYPE");
}
//#endregion
export { HighLevelClient, HighLevelClientWithOAuth, HighLevelIntegrationClient, createClient, createHighLevelClient };