UNPKG

@gohighlevel/api-client

Version:
302 lines 11.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Snapshots = void 0; /** * Snapshots Service * Documentation for Snapshots API */ class Snapshots { constructor(httpClient) { this.client = httpClient; } /** * Get Snapshots * Get a list of all own and imported Snapshots */ async getCustomSnapshots(params, options) { let url = '/snapshots/'; const queryParams = {}; const headerParams = {}; // Extract security requirements for this endpoint const securityRequirements = ["Agency-Access"]; if (params) { if (params.companyId !== undefined) { queryParams['companyId'] = params.companyId; } } // Collect all parameters for token resolution (including path params) const allParams = {}; if (params) { if (params.companyId !== undefined) { allParams['companyId'] = params.companyId; } } const config = { method: 'GET', url, params: queryParams, headers: { ...headerParams, ...options?.headers }, ...options }; // Get appropriate authorization token based on security requirements const ghlInstance = this.client.__ghlInstance; if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') { try { // Combine headerParams with headers from options const combinedHeaders = { ...headerParams, ...options?.headers }; // Combine queryParams with allParams for token resolution const combinedQuery = { ...queryParams, ...allParams }; const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, {}); if (authToken) { config.headers = { ...config.headers, 'Authorization': authToken }; } } catch (error) { throw error; // Re-throw authentication errors } } const response = await this.client.request(config); return response.data; } /** * Create Snapshot Share Link * Create a share link for snapshot */ async createSnapshotShareLink(params, requestBody, options) { let url = '/snapshots/share/link'; const queryParams = {}; const headerParams = {}; // Extract security requirements for this endpoint const securityRequirements = ["Agency-Access"]; if (params) { if (params.companyId !== undefined) { queryParams['companyId'] = params.companyId; } } // Collect all parameters for token resolution (including path params) const allParams = {}; if (params) { if (params.companyId !== undefined) { allParams['companyId'] = params.companyId; } } const config = { method: 'POST', url, params: queryParams, headers: { ...headerParams, ...options?.headers }, data: requestBody, ...options }; // Get appropriate authorization token based on security requirements const ghlInstance = this.client.__ghlInstance; if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') { try { // Combine headerParams with headers from options const combinedHeaders = { ...headerParams, ...options?.headers }; // Combine queryParams with allParams for token resolution const combinedQuery = { ...queryParams, ...allParams }; const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, requestBody); if (authToken) { config.headers = { ...config.headers, 'Authorization': authToken }; } } catch (error) { throw error; // Re-throw authentication errors } } const response = await this.client.request(config); return response.data; } /** * Get Snapshot Push between Dates * Get list of sub-accounts snapshot pushed in time period */ async getSnapshotPush(params, options) { let url = '/snapshots/snapshot-status/{snapshotId}'; const queryParams = {}; const headerParams = {}; // Extract security requirements for this endpoint const securityRequirements = ["Agency-Access"]; if (params) { if (params.snapshotId !== undefined) { url = url.replace('{' + 'snapshotId' + '}', encodeURIComponent(String(params.snapshotId))); } if (params.companyId !== undefined) { queryParams['companyId'] = params.companyId; } if (params.from !== undefined) { queryParams['from'] = params.from; } if (params.to !== undefined) { queryParams['to'] = params.to; } if (params.lastDoc !== undefined) { queryParams['lastDoc'] = params.lastDoc; } if (params.limit !== undefined) { queryParams['limit'] = params.limit; } } // Collect all parameters for token resolution (including path params) const allParams = {}; if (params) { if (params.snapshotId !== undefined) { allParams['snapshotId'] = params.snapshotId; } if (params.companyId !== undefined) { allParams['companyId'] = params.companyId; } if (params.from !== undefined) { allParams['from'] = params.from; } if (params.to !== undefined) { allParams['to'] = params.to; } if (params.lastDoc !== undefined) { allParams['lastDoc'] = params.lastDoc; } if (params.limit !== undefined) { allParams['limit'] = params.limit; } } const config = { method: 'GET', url, params: queryParams, headers: { ...headerParams, ...options?.headers }, ...options }; // Get appropriate authorization token based on security requirements const ghlInstance = this.client.__ghlInstance; if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') { try { // Combine headerParams with headers from options const combinedHeaders = { ...headerParams, ...options?.headers }; // Combine queryParams with allParams for token resolution const combinedQuery = { ...queryParams, ...allParams }; const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, {}); if (authToken) { config.headers = { ...config.headers, 'Authorization': authToken }; } } catch (error) { throw error; // Re-throw authentication errors } } const response = await this.client.request(config); return response.data; } /** * Get Last Snapshot Push * Get Latest Snapshot Push Status for a location id */ async getLatestSnapshotPush(params, options) { let url = '/snapshots/snapshot-status/{snapshotId}/location/{locationId}'; const queryParams = {}; const headerParams = {}; // Extract security requirements for this endpoint const securityRequirements = ["Agency-Access"]; if (params) { if (params.companyId !== undefined) { queryParams['companyId'] = params.companyId; } if (params.snapshotId !== undefined) { url = url.replace('{' + 'snapshotId' + '}', encodeURIComponent(String(params.snapshotId))); } if (params.locationId !== undefined) { url = url.replace('{' + 'locationId' + '}', encodeURIComponent(String(params.locationId))); } } // Collect all parameters for token resolution (including path params) const allParams = {}; if (params) { if (params.companyId !== undefined) { allParams['companyId'] = params.companyId; } if (params.snapshotId !== undefined) { allParams['snapshotId'] = params.snapshotId; } if (params.locationId !== undefined) { allParams['locationId'] = params.locationId; } } const config = { method: 'GET', url, params: queryParams, headers: { ...headerParams, ...options?.headers }, ...options }; // Get appropriate authorization token based on security requirements const ghlInstance = this.client.__ghlInstance; if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') { try { // Combine headerParams with headers from options const combinedHeaders = { ...headerParams, ...options?.headers }; // Combine queryParams with allParams for token resolution const combinedQuery = { ...queryParams, ...allParams }; const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, {}); if (authToken) { config.headers = { ...config.headers, 'Authorization': authToken }; } } catch (error) { throw error; // Re-throw authentication errors } } const response = await this.client.request(config); return response.data; } } exports.Snapshots = Snapshots; exports.default = Snapshots; //# sourceMappingURL=snapshots.js.map