From 279263208ff2e5523b661b7ba1dd9fdb42144582 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Thu, 14 Nov 2024 10:13:14 -0800 Subject: [PATCH 1/5] fix!: Wrap Axios type and export new type --- api/appsDev.ts | 11 +++---- api/customObjects.ts | 15 +++++---- api/designManager.ts | 7 ++--- api/developerTestAccounts.ts | 12 +++---- api/fileManager.ts | 11 +++---- api/fileMapper.ts | 18 +++++------ api/fileTransport.ts | 9 +++--- api/functions.ts | 15 ++++----- api/github.ts | 13 ++++---- api/hubdb.ts | 21 ++++++------- api/lighthouseScore.ts | 9 +++--- api/localDevAuth.ts | 9 +++--- api/marketplaceValidation.ts | 9 +++--- api/projects.ts | 57 +++++++++++++++++----------------- api/sandboxHubs.ts | 8 ++--- api/sandboxSync.ts | 9 +++--- api/secrets.ts | 11 +++---- api/validateHubl.ts | 5 ++- http/index.ts | 12 ++++--- http/unauthed.ts | 13 ++++---- lib/__tests__/validate.test.ts | 8 ++--- 21 files changed, 137 insertions(+), 145 deletions(-) diff --git a/api/appsDev.ts b/api/appsDev.ts index e6a9562..d33c4e5 100644 --- a/api/appsDev.ts +++ b/api/appsDev.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { PublicApp, PublicAppInstallCounts, @@ -11,7 +10,7 @@ const APPS_DEV_API_PATH = 'apps-dev/external/public/v3'; export function fetchPublicAppsForPortal( accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${APPS_DEV_API_PATH}/full/portal`, }); @@ -20,7 +19,7 @@ export function fetchPublicAppsForPortal( export function fetchPublicAppDeveloperTestAccountInstallData( appId: number, accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${APPS_DEV_API_PATH}/${appId}/test-portal-installs`, }); @@ -29,7 +28,7 @@ export function fetchPublicAppDeveloperTestAccountInstallData( export function fetchPublicAppProductionInstallCounts( appId: number, accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${APPS_DEV_API_PATH}/${appId}/install-counts-without-test-portals`, }); @@ -38,7 +37,7 @@ export function fetchPublicAppProductionInstallCounts( export function fetchPublicAppMetadata( appId: number, accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${APPS_DEV_API_PATH}/${appId}/full`, }); diff --git a/api/customObjects.ts b/api/customObjects.ts index f7a883b..a149374 100644 --- a/api/customObjects.ts +++ b/api/customObjects.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { FetchSchemasResponse, Schema, @@ -13,7 +12,7 @@ export function batchCreateObjects( accountId: number, objectTypeId: string, objects: JSON -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/batch/create`, data: objects, @@ -23,7 +22,7 @@ export function batchCreateObjects( export function createObjectSchema( accountId: number, schema: JSON -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: SCHEMA_API_PATH, data: schema, @@ -34,7 +33,7 @@ export function updateObjectSchema( accountId: number, schemaObjectType: string, schema: Schema -): AxiosPromise { +): HubSpotResponse { return http.patch(accountId, { url: `${SCHEMA_API_PATH}/${schemaObjectType}`, data: schema, @@ -44,7 +43,7 @@ export function updateObjectSchema( export function fetchObjectSchema( accountId: number, schemaObjectType: string -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${SCHEMA_API_PATH}/${schemaObjectType}`, }); @@ -52,7 +51,7 @@ export function fetchObjectSchema( export function fetchObjectSchemas( accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: SCHEMA_API_PATH, }); @@ -61,7 +60,7 @@ export function fetchObjectSchemas( export function deleteObjectSchema( accountId: number, schemaObjectType: string -): AxiosPromise { +): HubSpotResponse { return http.delete(accountId, { url: `${SCHEMA_API_PATH}/${schemaObjectType}`, }); diff --git a/api/designManager.ts b/api/designManager.ts index 5c373a0..f1bc712 100644 --- a/api/designManager.ts +++ b/api/designManager.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { QueryParams } from '../types/Http'; import { FetchThemesResponse, @@ -11,7 +10,7 @@ const DESIGN_MANAGER_API_PATH = 'designmanager/v1'; export function fetchThemes( accountId: number, params: QueryParams = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${DESIGN_MANAGER_API_PATH}/themes/combined`, params, @@ -20,7 +19,7 @@ export function fetchThemes( export function fetchBuiltinMapping( accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${DESIGN_MANAGER_API_PATH}/widgets/builtin-mapping`, }); diff --git a/api/developerTestAccounts.ts b/api/developerTestAccounts.ts index 4c3b6c4..0947017 100644 --- a/api/developerTestAccounts.ts +++ b/api/developerTestAccounts.ts @@ -1,5 +1,5 @@ -import axios, { AxiosPromise } from 'axios'; -import { http } from '../http'; +import axios from 'axios'; +import { http, HubSpotResponse } from '../http'; import { getAxiosConfig } from '../http/getAxiosConfig'; import { ENVIRONMENTS } from '../constants/environments'; import { @@ -13,7 +13,7 @@ const TEST_ACCOUNTS_API_PATH = 'integrators/test-portals/v2'; export function fetchDeveloperTestAccounts( accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: TEST_ACCOUNTS_API_PATH, }); @@ -22,7 +22,7 @@ export function fetchDeveloperTestAccounts( export function createDeveloperTestAccount( accountId: number, accountName: string -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: TEST_ACCOUNTS_API_PATH, data: { accountName, generatePersonalAccessKey: true }, // For CLI, generatePersonalAccessKey will always be true since we'll be saving the entry to the config @@ -33,7 +33,7 @@ export function createDeveloperTestAccount( export function deleteDeveloperTestAccount( accountId: number, testAccountId: number -): AxiosPromise { +): HubSpotResponse { return http.delete(accountId, { url: `${TEST_ACCOUNTS_API_PATH}/${testAccountId}`, }); @@ -43,7 +43,7 @@ export function fetchDeveloperTestAccountData( accessToken: string, accountId: number, env: Environment = ENVIRONMENTS.PROD -): AxiosPromise { +): HubSpotResponse { const axiosConfig = getAxiosConfig({ env, url: `${TEST_ACCOUNTS_API_PATH}/self`, diff --git a/api/fileManager.ts b/api/fileManager.ts index 397d2f1..5fd8cf2 100644 --- a/api/fileManager.ts +++ b/api/fileManager.ts @@ -1,7 +1,6 @@ -import { AxiosPromise } from 'axios'; import fs from 'fs'; import path from 'path'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { FormData } from '../types/Http'; import { FetchStatResponse, @@ -17,7 +16,7 @@ export function uploadFile( accountId: number, src: string, dest: string -): AxiosPromise { +): HubSpotResponse { const directory = path.dirname(dest); const filename = path.basename(dest); const formData: FormData = { @@ -45,7 +44,7 @@ export function uploadFile( export function fetchStat( accountId: number, src: string -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FILE_MANAGER_V2_API_PATH}/files/stat/${src}`, }); @@ -56,7 +55,7 @@ export function fetchFiles( folderId: number | 'None', offset: number, archived?: boolean -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FILE_MANAGER_V2_API_PATH}/files/`, params: { @@ -71,7 +70,7 @@ export function fetchFiles( export function fetchFolders( accountId: number, folderId: number | 'None' -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FILE_MANAGER_V2_API_PATH}/folders/`, params: { diff --git a/api/fileMapper.ts b/api/fileMapper.ts index f06c5a6..c227cbb 100644 --- a/api/fileMapper.ts +++ b/api/fileMapper.ts @@ -1,8 +1,8 @@ import fs from 'fs'; import path from 'path'; import contentDisposition from 'content-disposition'; -import { AxiosResponse, AxiosPromise } from 'axios'; -import { http } from '../http'; +import { AxiosResponse } from 'axios'; +import { http, HubSpotResponse } from '../http'; import { getCwd } from '../lib/path'; import { FileMapperNode, FileMapperOptions, FileTree } from '../types/Files'; @@ -46,7 +46,7 @@ export function upload( src: string, dest: string, options: FileMapperOptions = {} -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${FILE_MAPPER_API_PATH}/upload/${encodeURIComponent(dest)}`, data: { @@ -62,7 +62,7 @@ export function fetchModule( accountId: number, moduleId: number, options: FileMapperOptions = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FILE_MAPPER_API_PATH}/modules/${moduleId}`, ...options, @@ -92,7 +92,7 @@ export function download( accountId: number, filepath: string, options: FileMapperOptions = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FILE_MAPPER_API_PATH}/download/${encodeURIComponent(filepath)}`, ...options, @@ -104,7 +104,7 @@ export function downloadDefault( accountId: number, filepath: string, options: FileMapperOptions = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FILE_MAPPER_API_PATH}/download-default/${filepath}`, ...options, @@ -115,7 +115,7 @@ export function downloadDefault( export function deleteFile( accountId: number, filePath: string -): AxiosPromise { +): HubSpotResponse { return http.delete(accountId, { url: `${FILE_MAPPER_API_PATH}/delete/${encodeURIComponent(filePath)}`, }); @@ -126,7 +126,7 @@ export function moveFile( accountId: number, srcPath: string, destPath: string -): AxiosPromise { +): HubSpotResponse { return http.put(accountId, { url: `${FILE_MAPPER_API_PATH}/rename/${srcPath}?path=${destPath}`, headers: { 'Content-Type': 'application/json' }, @@ -137,7 +137,7 @@ export function moveFile( export function getDirectoryContentsByPath( accountId: number, path: string -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FILE_MAPPER_API_PATH}/meta/${path}`, }); diff --git a/api/fileTransport.ts b/api/fileTransport.ts index 2ea43bf..b5e2d0d 100644 --- a/api/fileTransport.ts +++ b/api/fileTransport.ts @@ -1,14 +1,13 @@ -import { AxiosPromise } from 'axios'; import fs from 'fs'; import path from 'path'; import { getCwd } from '../lib/path'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; const HUBFILES_API_PATH = '/file-transport/v1/hubfiles'; export function createSchemaFromHubFile( accountId: number, filepath: string -): AxiosPromise { +): HubSpotResponse { const file = fs.createReadStream(path.resolve(getCwd(), filepath)); return http.post(accountId, { url: `${HUBFILES_API_PATH}/object-schemas`, @@ -22,7 +21,7 @@ export function createSchemaFromHubFile( export async function updateSchemaFromHubFile( accountId: number, filepath: string -): AxiosPromise { +): HubSpotResponse { const file = fs.createReadStream(path.resolve(getCwd(), filepath)); return http.put(accountId, { url: `${HUBFILES_API_PATH}/object-schemas`, @@ -37,7 +36,7 @@ export async function fetchHubFileSchema( accountId: number, objectName: string, path: string -): AxiosPromise { +): HubSpotResponse { return http.getOctetStream( accountId, { diff --git a/api/functions.ts b/api/functions.ts index b0db478..0aceafe 100644 --- a/api/functions.ts +++ b/api/functions.ts @@ -1,11 +1,12 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { QueryParams } from '../types/Http'; import { GetBuildStatusResponse, GetRoutesResponse } from '../types/Functions'; const FUNCTION_API_PATH = 'cms/v3/functions'; -export function getRoutes(accountId: number): AxiosPromise { +export function getRoutes( + accountId: number +): HubSpotResponse { return http.get(accountId, { url: `${FUNCTION_API_PATH}/routes`, }); @@ -15,7 +16,7 @@ export function getFunctionLogs( accountId: number, route: string, params: QueryParams = {} -): AxiosPromise { +): HubSpotResponse { const { limit = 5 } = params; return http.get(accountId, { @@ -27,7 +28,7 @@ export function getFunctionLogs( export function getLatestFunctionLog( accountId: number, route: string -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FUNCTION_API_PATH}/results/by-route/${encodeURIComponent( route @@ -38,7 +39,7 @@ export function getLatestFunctionLog( export function buildPackage( accountId: number, folderPath: string -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${FUNCTION_API_PATH}/build/async`, headers: { @@ -53,7 +54,7 @@ export function buildPackage( export function getBuildStatus( accountId: number, buildId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${FUNCTION_API_PATH}/build/${buildId}/poll`, }); diff --git a/api/github.ts b/api/github.ts index 59009f5..7d3bc30 100644 --- a/api/github.ts +++ b/api/github.ts @@ -1,6 +1,7 @@ -import axios, { AxiosPromise } from 'axios'; +import axios from 'axios'; import { getDefaultUserAgentHeader } from '../http/getAxiosConfig'; import { GithubReleaseData, GithubRepoFile, RepoPath } from '../types/Github'; +import { HubSpotResponse } from '../http'; const GITHUB_REPOS_API = 'https://api.github.com/repos'; const GITHUB_RAW_CONTENT_API_PATH = 'https://raw.githubusercontent.com'; @@ -31,7 +32,7 @@ function getAdditionalHeaders(): AdditionalGitHubHeaders { export function fetchRepoReleaseData( repoPath: RepoPath, tag = '' -): AxiosPromise { +): HubSpotResponse { const URL = `${GITHUB_REPOS_API}/${repoPath}/releases`; return axios.get( @@ -47,7 +48,7 @@ export function fetchRepoReleaseData( // Returns the entire repo content as a zip, using the zipball_url from fetchRepoReleaseData() // https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#download-a-repository-archive-zip -export function fetchRepoAsZip(zipUrl: string): AxiosPromise { +export function fetchRepoAsZip(zipUrl: string): HubSpotResponse { return axios.get(zipUrl, { responseType: 'arraybuffer', headers: { ...getDefaultUserAgentHeader(), ...getAdditionalHeaders() }, @@ -59,7 +60,7 @@ export function fetchRepoFile( repoPath: RepoPath, filePath: string, ref: string -): AxiosPromise { +): HubSpotResponse { return axios.get( `${GITHUB_RAW_CONTENT_API_PATH}/${repoPath}/${ref}/${filePath}`, { @@ -74,7 +75,7 @@ export function fetchRepoFile( // Returns the raw file contents via the raw.githubusercontent endpoint export function fetchRepoFileByDownloadUrl( downloadUrl: string -): AxiosPromise { +): HubSpotResponse { return axios.get(downloadUrl, { headers: { ...getDefaultUserAgentHeader(), ...getAdditionalHeaders() }, responseType: 'arraybuffer', @@ -87,7 +88,7 @@ export function fetchRepoContents( repoPath: RepoPath, path: string, ref?: string -): AxiosPromise> { +): HubSpotResponse> { const refQuery = ref ? `?ref=${ref}` : ''; return axios.get>( diff --git a/api/hubdb.ts b/api/hubdb.ts index 7f0f670..1ae21b6 100644 --- a/api/hubdb.ts +++ b/api/hubdb.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { QueryParams } from '../types/Http'; import { CreateRowsResponse, @@ -14,7 +13,7 @@ const HUBDB_API_PATH = 'cms/v3/hubdb'; export function fetchTables( accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${HUBDB_API_PATH}/tables`, }); @@ -23,7 +22,7 @@ export function fetchTables( export function fetchTable( accountId: number, tableId: string -): AxiosPromise { +): HubSpotResponse
{ return http.get
(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}`, }); @@ -32,7 +31,7 @@ export function fetchTable( export function createTable( accountId: number, schema: Schema -): AxiosPromise
{ +): HubSpotResponse
{ return http.post
(accountId, { url: `${HUBDB_API_PATH}/tables`, data: schema, @@ -43,7 +42,7 @@ export function updateTable( accountId: number, tableId: string, schema: Schema -): AxiosPromise
{ +): HubSpotResponse
{ return http.patch
(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/draft`, data: schema, @@ -53,7 +52,7 @@ export function updateTable( export function publishTable( accountId: number, tableId: string -): AxiosPromise
{ +): HubSpotResponse
{ return http.post
(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/draft/publish`, headers: { @@ -65,7 +64,7 @@ export function publishTable( export function deleteTable( accountId: number, tableId: string -): AxiosPromise { +): HubSpotResponse { return http.delete(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}`, }); @@ -75,7 +74,7 @@ export function createRows( accountId: number, tableId: string, rows: Array -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft/batch/create`, data: { inputs: rows }, @@ -86,7 +85,7 @@ export function fetchRows( accountId: number, tableId: string, params: QueryParams = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft`, params, @@ -97,7 +96,7 @@ export function deleteRows( accountId: number, tableId: string, rowIds: Array -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft/batch/purge`, data: { inputs: rowIds }, diff --git a/api/lighthouseScore.ts b/api/lighthouseScore.ts index cccc4dd..62865e1 100644 --- a/api/lighthouseScore.ts +++ b/api/lighthouseScore.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { Data, QueryParams } from '../types/Http'; import { GetLighthouseScoreResponse, @@ -11,7 +10,7 @@ const LIGHTHOUSE_SCORE_API_BASE = 'quality-engine/v1/lighthouse'; export function requestLighthouseScore( accountId: number, data: Data = {} -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${LIGHTHOUSE_SCORE_API_BASE}/request`, data, @@ -21,7 +20,7 @@ export function requestLighthouseScore( export function getLighthouseScoreStatus( accountId: number, params: QueryParams = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${LIGHTHOUSE_SCORE_API_BASE}/status`, params, @@ -31,7 +30,7 @@ export function getLighthouseScoreStatus( export function getLighthouseScore( accountId: number, params: QueryParams = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${LIGHTHOUSE_SCORE_API_BASE}/scores`, params, diff --git a/api/localDevAuth.ts b/api/localDevAuth.ts index 5abdb71..3ed6fe6 100644 --- a/api/localDevAuth.ts +++ b/api/localDevAuth.ts @@ -1,6 +1,5 @@ -import { AxiosPromise } from 'axios'; import { getAxiosConfig } from '../http/getAxiosConfig'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { ENVIRONMENTS } from '../constants/environments'; import { Environment } from '../types/Config'; import { @@ -17,7 +16,7 @@ export function fetchAccessToken( personalAccessKey: string, env: Environment = ENVIRONMENTS.PROD, portalId?: number -): AxiosPromise { +): HubSpotResponse { const axiosConfig = getAxiosConfig({ env, localHostOverride: true, @@ -37,7 +36,7 @@ export function fetchAccessToken( export function fetchScopeData( accountId: number, scopeGroup: string -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${LOCALDEVAUTH_API_AUTH_PATH}/check-scopes`, params: { scopeGroup }, @@ -50,7 +49,7 @@ export function fetchAppInstallationData( appUid: string, requiredScopeGroups: Array, optionalScopeGroups: Array = [] -): AxiosPromise { +): HubSpotResponse { return http.post(portalId, { url: `${LOCALDEVAUTH_API_AUTH_PATH}/install-info`, data: { diff --git a/api/marketplaceValidation.ts b/api/marketplaceValidation.ts index 41a06aa..d344adc 100644 --- a/api/marketplaceValidation.ts +++ b/api/marketplaceValidation.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { Data, QueryParams } from '../types/Http'; import { GetValidationResultsResponse } from '../types/MarketplaceValidation'; @@ -8,7 +7,7 @@ const VALIDATION_API_BASE = 'quality-engine/v1/validation'; export function requestValidation( accountId: number, data: Data = {} -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${VALIDATION_API_BASE}/request`, data, @@ -18,7 +17,7 @@ export function requestValidation( export function getValidationStatus( accountId: number, params: QueryParams = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${VALIDATION_API_BASE}/status`, params, @@ -28,7 +27,7 @@ export function getValidationStatus( export function getValidationResults( accountId: number, params: QueryParams = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${VALIDATION_API_BASE}/results`, params, diff --git a/api/projects.ts b/api/projects.ts index cae069a..2504e6f 100644 --- a/api/projects.ts +++ b/api/projects.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import fs from 'fs'; import { FormData, QueryParams } from '../types/Http'; import { @@ -31,7 +30,7 @@ const MIGRATIONS_API_PATH = 'dfs/migrations/v1'; export function fetchProjects( accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: DEVELOPER_PROJECTS_API_PATH, }); @@ -40,7 +39,7 @@ export function fetchProjects( export function createProject( accountId: number, name: string -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: DEVELOPER_PROJECTS_API_PATH, data: { @@ -55,7 +54,7 @@ export function uploadProject( projectFile: string, uploadMessage: string, platformVersion?: string -): AxiosPromise { +): HubSpotResponse { const formData: FormData = { file: fs.createReadStream(projectFile), uploadMessage, @@ -75,7 +74,7 @@ export function uploadProject( export function fetchProject( accountId: number, projectName: string -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${encodeURIComponent(projectName)}`, }); @@ -84,7 +83,7 @@ export function fetchProject( export async function fetchProjectComponentsMetadata( accountId: number, projectId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${DEVELOPER_FILE_SYSTEM_PATH}/projects-deployed-build/${projectId}`, }); @@ -94,7 +93,7 @@ export async function downloadProject( accountId: number, projectName: string, buildId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -107,7 +106,7 @@ export async function downloadProject( export function deleteProject( accountId: number, projectName: string -): AxiosPromise { +): HubSpotResponse { return http.delete(accountId, { url: `${DEVELOPER_PROJECTS_API_PATH}/${encodeURIComponent(projectName)}`, }); @@ -115,7 +114,7 @@ export function deleteProject( export function fetchPlatformVersions( accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${DEVELOPER_PROJECTS_API_PATH}/platformVersion`, }); @@ -125,7 +124,7 @@ export function fetchProjectBuilds( accountId: number, projectName: string, params: QueryParams = {} -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent(projectName)}/builds`, params, @@ -136,7 +135,7 @@ export function getBuildStatus( accountId: number, projectName: string, buildId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -148,7 +147,7 @@ export function getBuildStructure( accountId: number, projectName: string, buildId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `dfs/v1/builds/by-project-name/${encodeURIComponent( projectName @@ -160,7 +159,7 @@ export function deployProject( accountId: number, projectName: string, buildId: number -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${PROJECTS_DEPLOY_API_PATH}/deploys/queue/async`, data: { @@ -174,7 +173,7 @@ export function getDeployStatus( accountId: number, projectName: string, deployId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${PROJECTS_DEPLOY_API_PATH}/deploy-status/projects/${encodeURIComponent( projectName @@ -186,7 +185,7 @@ export function getDeployStructure( accountId: number, projectName: string, deployId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${PROJECTS_DEPLOY_API_PATH}/deploys/by-project-name/${encodeURIComponent( projectName @@ -197,7 +196,7 @@ export function getDeployStructure( export function fetchProjectSettings( accountId: number, projectName: string -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${DEVELOPER_PROJECTS_API_PATH}/${encodeURIComponent(projectName)}/settings`, }); @@ -207,7 +206,7 @@ export async function provisionBuild( accountId: number, projectName: string, platformVersion?: string -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -222,7 +221,7 @@ export function queueBuild( accountId: number, projectName: string, platformVersion?: string -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -237,7 +236,7 @@ export function uploadFileToBuild( projectName: string, filePath: string, path: string -): AxiosPromise { +): HubSpotResponse { return http.put(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -253,7 +252,7 @@ export function deleteFileFromBuild( accountId: number, projectName: string, path: string -): AxiosPromise { +): HubSpotResponse { return http.delete(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -264,7 +263,7 @@ export function deleteFileFromBuild( export function cancelStagedBuild( accountId: number, projectName: string -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -281,7 +280,7 @@ export function fetchBuildWarnLogs( accountId: number, projectName: string, buildId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${PROJECTS_LOGS_API_PATH}/logs/projects/${encodeURIComponent( projectName @@ -293,7 +292,7 @@ export function fetchDeployWarnLogs( accountId: number, projectName: string, deployId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${PROJECTS_LOGS_API_PATH}/logs/projects/${encodeURIComponent( projectName @@ -305,7 +304,7 @@ export function migrateApp( accountId: number, appId: number, projectName: string -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${MIGRATIONS_API_PATH}/migrations`, data: { @@ -319,7 +318,7 @@ export function migrateApp( export function checkMigrationStatus( accountId: number, id: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${MIGRATIONS_API_PATH}/migrations/${id}`, }); @@ -328,7 +327,7 @@ export function checkMigrationStatus( export function cloneApp( accountId: number, appId: number -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: `${MIGRATIONS_API_PATH}/exports`, data: { @@ -341,7 +340,7 @@ export function cloneApp( export function checkCloneStatus( accountId: number, exportId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${MIGRATIONS_API_PATH}/exports/${exportId}/status`, }); @@ -350,7 +349,7 @@ export function checkCloneStatus( export function downloadClonedProject( accountId: number, exportId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${MIGRATIONS_API_PATH}/exports/${exportId}/download-as-clone`, responseType: 'arraybuffer', diff --git a/api/sandboxHubs.ts b/api/sandboxHubs.ts index d7f06a3..229c14c 100644 --- a/api/sandboxHubs.ts +++ b/api/sandboxHubs.ts @@ -1,5 +1,5 @@ import axios, { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { getAxiosConfig } from '../http/getAxiosConfig'; import { ENVIRONMENTS } from '../constants/environments'; import { SANDBOX_TIMEOUT } from '../constants/api'; @@ -17,7 +17,7 @@ export function createSandbox( accountId: number, name: string, type: 1 | 2 -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { data: { name, type, generatePersonalAccessKey: true }, // For CLI, generatePersonalAccessKey will always be true since we'll be saving the entry to the config timeout: SANDBOX_TIMEOUT, @@ -28,7 +28,7 @@ export function createSandbox( export function deleteSandbox( parentAccountId: number, sandboxAccountId: number -): AxiosPromise { +): HubSpotResponse { return http.delete(parentAccountId, { url: `${SANDBOX_API_PATH}/${sandboxAccountId}`, }); @@ -36,7 +36,7 @@ export function deleteSandbox( export function getSandboxUsageLimits( parentAccountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(parentAccountId, { url: `${SANDBOX_API_PATH}/parent/${parentAccountId}/usage`, }); diff --git a/api/sandboxSync.ts b/api/sandboxSync.ts index d617957..d348eec 100644 --- a/api/sandboxSync.ts +++ b/api/sandboxSync.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { InitiateSyncResponse, FetchTypesResponse, @@ -8,12 +7,12 @@ import { import { SANDBOX_TIMEOUT } from '../constants/api'; const SANDBOXES_SYNC_API_PATH = 'sandboxes-sync/v1'; -export function initiateSync( +export async function initiateSync( fromHubId: number, toHubId: number, tasks: Array, sandboxHubId: number -): AxiosPromise { +): HubSpotResponse { return http.post(fromHubId, { data: { command: 'SYNC', @@ -30,7 +29,7 @@ export function initiateSync( export async function fetchTypes( accountId: number, toHubId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${SANDBOXES_SYNC_API_PATH}/types${ toHubId ? `?toHubId=${toHubId}` : '' diff --git a/api/secrets.ts b/api/secrets.ts index 8663b02..756f858 100644 --- a/api/secrets.ts +++ b/api/secrets.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { FetchSecretsResponse } from '../types/Secrets'; const SECRETS_API_PATH = 'cms/v3/functions/secrets'; @@ -8,7 +7,7 @@ export function addSecret( accountId: number, key: string, value: string -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: SECRETS_API_PATH, data: { @@ -22,7 +21,7 @@ export function updateSecret( accountId: number, key: string, value: string -): AxiosPromise { +): HubSpotResponse { return http.put(accountId, { url: SECRETS_API_PATH, data: { @@ -35,7 +34,7 @@ export function updateSecret( export function deleteSecret( accountId: number, key: string -): AxiosPromise { +): HubSpotResponse { return http.delete(accountId, { url: `${SECRETS_API_PATH}/${key}`, }); @@ -43,7 +42,7 @@ export function deleteSecret( export function fetchSecrets( accountId: number -): AxiosPromise { +): HubSpotResponse { return http.get(accountId, { url: `${SECRETS_API_PATH}`, }); diff --git a/api/validateHubl.ts b/api/validateHubl.ts index 80cad17..50af718 100644 --- a/api/validateHubl.ts +++ b/api/validateHubl.ts @@ -1,5 +1,4 @@ -import { AxiosPromise } from 'axios'; -import { http } from '../http'; +import { http, HubSpotResponse } from '../http'; import { Validation, HublValidationOptions } from '../types/HublValidation'; const HUBL_VALIDATE_API_PATH = 'cos-rendering/v1/internal/validate'; @@ -8,7 +7,7 @@ export function validateHubl( accountId: number, sourceCode: string, hublValidationOptions?: HublValidationOptions -): AxiosPromise { +): HubSpotResponse { return http.post(accountId, { url: HUBL_VALIDATE_API_PATH, data: { diff --git a/http/index.ts b/http/index.ts index e2eda47..ffa6287 100644 --- a/http/index.ts +++ b/http/index.ts @@ -16,6 +16,8 @@ import { HubSpotHttpError } from '../models/HubSpotHttpError'; const i18nKey = 'http.index'; +export type HubSpotResponse = Promise>; + axios.interceptors.response.use(undefined, error => { // Wrap all axios errors in our own Error class. Attach the error // as the cause for the new error, so we maintain the stack trace @@ -115,7 +117,7 @@ async function withAuth( async function getRequest( accountId: number, options: HttpOptions -): AxiosPromise { +): HubSpotResponse { const { params, ...rest } = options; const optionsWithParams = addQueryParams(rest, params); const requestConfig = await withAuth(accountId, optionsWithParams); @@ -126,7 +128,7 @@ async function getRequest( async function postRequest( accountId: number, options: HttpOptions -): AxiosPromise { +): HubSpotResponse { const requestConfig = await withAuth(accountId, options); return axios({ ...requestConfig, method: 'post' }); } @@ -134,7 +136,7 @@ async function postRequest( async function putRequest( accountId: number, options: HttpOptions -): AxiosPromise { +): HubSpotResponse { const requestConfig = await withAuth(accountId, options); return axios({ ...requestConfig, method: 'put' }); } @@ -142,7 +144,7 @@ async function putRequest( async function patchRequest( accountId: number, options: HttpOptions -): AxiosPromise { +): HubSpotResponse { const requestConfig = await withAuth(accountId, options); return axios({ ...requestConfig, method: 'patch' }); } @@ -150,7 +152,7 @@ async function patchRequest( async function deleteRequest( accountId: number, options: HttpOptions -): AxiosPromise { +): HubSpotResponse { const requestConfig = await withAuth(accountId, options); return axios({ ...requestConfig, method: 'delete' }); } diff --git a/http/unauthed.ts b/http/unauthed.ts index cd14305..bd2628e 100644 --- a/http/unauthed.ts +++ b/http/unauthed.ts @@ -1,9 +1,10 @@ -import axios, { AxiosPromise } from 'axios'; +import axios from 'axios'; import { getAxiosConfig } from './getAxiosConfig'; import { addQueryParams } from './addQueryParams'; import { HttpOptions } from '../types/Http'; +import { HubSpotResponse } from './index'; -async function getRequest(options: HttpOptions): AxiosPromise { +async function getRequest(options: HttpOptions): HubSpotResponse { const { params, ...rest } = options; const optionsWithParams = addQueryParams(rest, params); const requestConfig = await getAxiosConfig(optionsWithParams); @@ -11,22 +12,22 @@ async function getRequest(options: HttpOptions): AxiosPromise { return axios(requestConfig); } -async function postRequest(options: HttpOptions): AxiosPromise { +async function postRequest(options: HttpOptions): HubSpotResponse { const requestConfig = await getAxiosConfig(options); return axios({ ...requestConfig, method: 'post' }); } -async function putRequest(options: HttpOptions): AxiosPromise { +async function putRequest(options: HttpOptions): HubSpotResponse { const requestConfig = await getAxiosConfig(options); return axios({ ...requestConfig, method: 'put' }); } -async function patchRequest(options: HttpOptions): AxiosPromise { +async function patchRequest(options: HttpOptions): HubSpotResponse { const requestConfig = await getAxiosConfig(options); return axios({ ...requestConfig, method: 'patch' }); } -async function deleteRequest(options: HttpOptions): AxiosPromise { +async function deleteRequest(options: HttpOptions): HubSpotResponse { const requestConfig = await getAxiosConfig(options); return axios({ ...requestConfig, method: 'delete' }); } diff --git a/lib/__tests__/validate.test.ts b/lib/__tests__/validate.test.ts index 7cd9816..a8b8d92 100644 --- a/lib/__tests__/validate.test.ts +++ b/lib/__tests__/validate.test.ts @@ -3,7 +3,7 @@ import { validateHubl } from '../../api/validateHubl'; import { walk } from '../fs'; import { lint } from '../cms/validate'; import { LintResult, Validation } from '../../types/HublValidation'; -import { AxiosPromise } from 'axios'; +import { HubSpotResponse } from '../../http'; jest.mock('fs-extra'); jest.mock('../../api/validateHubl'); @@ -76,7 +76,7 @@ describe('lib/cms/validate', () => { mockedFsReadFile.mockResolvedValue(mockSource); mockedValidateHubl.mockResolvedValue({ data: mockValidation, - } as unknown as AxiosPromise); + } as unknown as HubSpotResponse); const result = await lint(accountId, filePath); expect(validateHubl).toHaveBeenCalledWith(accountId, mockSource); expect(result).toEqual([{ file: filePath, validation: mockValidation }]); @@ -89,7 +89,7 @@ describe('lib/cms/validate', () => { mockedFsReadFile.mockResolvedValue('valid HUBL content'); mockedValidateHubl.mockResolvedValue({ data: mockValidation, - } as unknown as AxiosPromise); + } as unknown as HubSpotResponse); const result = await lint(accountId, filePath); @@ -104,7 +104,7 @@ describe('lib/cms/validate', () => { mockedFsReadFile.mockResolvedValue(mockSource); mockedValidateHubl.mockResolvedValue({ data: mockValidation, - } as unknown as AxiosPromise); + } as unknown as HubSpotResponse); await lint(accountId, filePath, mockCallback); expect(mockCallback).toHaveBeenCalledWith({ From fc2c94ccadcec5af6d927910894220b0a118bedd Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Thu, 14 Nov 2024 10:49:50 -0800 Subject: [PATCH 2/5] Use axios helper type --- http/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/index.ts b/http/index.ts index ffa6287..b38e1b1 100644 --- a/http/index.ts +++ b/http/index.ts @@ -16,7 +16,7 @@ import { HubSpotHttpError } from '../models/HubSpotHttpError'; const i18nKey = 'http.index'; -export type HubSpotResponse = Promise>; +export type HubSpotResponse = AxiosPromise; axios.interceptors.response.use(undefined, error => { // Wrap all axios errors in our own Error class. Attach the error From 4b69a3f33cf2b5b0bbcbaef84e4481e7f2195168 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Thu, 14 Nov 2024 15:33:56 -0800 Subject: [PATCH 3/5] Rename HubSpotResponse -> HubSpotPromise --- api/appsDev.ts | 10 +++--- api/customObjects.ts | 14 ++++----- api/designManager.ts | 6 ++-- api/developerTestAccounts.ts | 10 +++--- api/fileManager.ts | 10 +++--- api/fileMapper.ts | 16 +++++----- api/fileTransport.ts | 8 ++--- api/functions.ts | 12 ++++---- api/github.ts | 12 ++++---- api/hubdb.ts | 20 ++++++------ api/lighthouseScore.ts | 8 ++--- api/localDevAuth.ts | 8 ++--- api/marketplaceValidation.ts | 8 ++--- api/projects.ts | 56 +++++++++++++++++----------------- api/sandboxHubs.ts | 8 ++--- api/sandboxSync.ts | 6 ++-- api/secrets.ts | 10 +++--- api/validateHubl.ts | 4 +-- http/index.ts | 12 ++++---- http/unauthed.ts | 12 ++++---- lib/__tests__/validate.test.ts | 8 ++--- 21 files changed, 129 insertions(+), 129 deletions(-) diff --git a/api/appsDev.ts b/api/appsDev.ts index d33c4e5..1eb541d 100644 --- a/api/appsDev.ts +++ b/api/appsDev.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { PublicApp, PublicAppInstallCounts, @@ -10,7 +10,7 @@ const APPS_DEV_API_PATH = 'apps-dev/external/public/v3'; export function fetchPublicAppsForPortal( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${APPS_DEV_API_PATH}/full/portal`, }); @@ -19,7 +19,7 @@ export function fetchPublicAppsForPortal( export function fetchPublicAppDeveloperTestAccountInstallData( appId: number, accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${APPS_DEV_API_PATH}/${appId}/test-portal-installs`, }); @@ -28,7 +28,7 @@ export function fetchPublicAppDeveloperTestAccountInstallData( export function fetchPublicAppProductionInstallCounts( appId: number, accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${APPS_DEV_API_PATH}/${appId}/install-counts-without-test-portals`, }); @@ -37,7 +37,7 @@ export function fetchPublicAppProductionInstallCounts( export function fetchPublicAppMetadata( appId: number, accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${APPS_DEV_API_PATH}/${appId}/full`, }); diff --git a/api/customObjects.ts b/api/customObjects.ts index a149374..ee732fc 100644 --- a/api/customObjects.ts +++ b/api/customObjects.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { FetchSchemasResponse, Schema, @@ -12,7 +12,7 @@ export function batchCreateObjects( accountId: number, objectTypeId: string, objects: JSON -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/batch/create`, data: objects, @@ -22,7 +22,7 @@ export function batchCreateObjects( export function createObjectSchema( accountId: number, schema: JSON -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: SCHEMA_API_PATH, data: schema, @@ -33,7 +33,7 @@ export function updateObjectSchema( accountId: number, schemaObjectType: string, schema: Schema -): HubSpotResponse { +): HubSpotPromise { return http.patch(accountId, { url: `${SCHEMA_API_PATH}/${schemaObjectType}`, data: schema, @@ -43,7 +43,7 @@ export function updateObjectSchema( export function fetchObjectSchema( accountId: number, schemaObjectType: string -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${SCHEMA_API_PATH}/${schemaObjectType}`, }); @@ -51,7 +51,7 @@ export function fetchObjectSchema( export function fetchObjectSchemas( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: SCHEMA_API_PATH, }); @@ -60,7 +60,7 @@ export function fetchObjectSchemas( export function deleteObjectSchema( accountId: number, schemaObjectType: string -): HubSpotResponse { +): HubSpotPromise { return http.delete(accountId, { url: `${SCHEMA_API_PATH}/${schemaObjectType}`, }); diff --git a/api/designManager.ts b/api/designManager.ts index f1bc712..a9b864f 100644 --- a/api/designManager.ts +++ b/api/designManager.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { QueryParams } from '../types/Http'; import { FetchThemesResponse, @@ -10,7 +10,7 @@ const DESIGN_MANAGER_API_PATH = 'designmanager/v1'; export function fetchThemes( accountId: number, params: QueryParams = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${DESIGN_MANAGER_API_PATH}/themes/combined`, params, @@ -19,7 +19,7 @@ export function fetchThemes( export function fetchBuiltinMapping( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${DESIGN_MANAGER_API_PATH}/widgets/builtin-mapping`, }); diff --git a/api/developerTestAccounts.ts b/api/developerTestAccounts.ts index 0947017..2a0601b 100644 --- a/api/developerTestAccounts.ts +++ b/api/developerTestAccounts.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { getAxiosConfig } from '../http/getAxiosConfig'; import { ENVIRONMENTS } from '../constants/environments'; import { @@ -13,7 +13,7 @@ const TEST_ACCOUNTS_API_PATH = 'integrators/test-portals/v2'; export function fetchDeveloperTestAccounts( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: TEST_ACCOUNTS_API_PATH, }); @@ -22,7 +22,7 @@ export function fetchDeveloperTestAccounts( export function createDeveloperTestAccount( accountId: number, accountName: string -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: TEST_ACCOUNTS_API_PATH, data: { accountName, generatePersonalAccessKey: true }, // For CLI, generatePersonalAccessKey will always be true since we'll be saving the entry to the config @@ -33,7 +33,7 @@ export function createDeveloperTestAccount( export function deleteDeveloperTestAccount( accountId: number, testAccountId: number -): HubSpotResponse { +): HubSpotPromise { return http.delete(accountId, { url: `${TEST_ACCOUNTS_API_PATH}/${testAccountId}`, }); @@ -43,7 +43,7 @@ export function fetchDeveloperTestAccountData( accessToken: string, accountId: number, env: Environment = ENVIRONMENTS.PROD -): HubSpotResponse { +): HubSpotPromise { const axiosConfig = getAxiosConfig({ env, url: `${TEST_ACCOUNTS_API_PATH}/self`, diff --git a/api/fileManager.ts b/api/fileManager.ts index 5fd8cf2..a803b87 100644 --- a/api/fileManager.ts +++ b/api/fileManager.ts @@ -1,6 +1,6 @@ import fs from 'fs'; import path from 'path'; -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { FormData } from '../types/Http'; import { FetchStatResponse, @@ -16,7 +16,7 @@ export function uploadFile( accountId: number, src: string, dest: string -): HubSpotResponse { +): HubSpotPromise { const directory = path.dirname(dest); const filename = path.basename(dest); const formData: FormData = { @@ -44,7 +44,7 @@ export function uploadFile( export function fetchStat( accountId: number, src: string -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FILE_MANAGER_V2_API_PATH}/files/stat/${src}`, }); @@ -55,7 +55,7 @@ export function fetchFiles( folderId: number | 'None', offset: number, archived?: boolean -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FILE_MANAGER_V2_API_PATH}/files/`, params: { @@ -70,7 +70,7 @@ export function fetchFiles( export function fetchFolders( accountId: number, folderId: number | 'None' -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FILE_MANAGER_V2_API_PATH}/folders/`, params: { diff --git a/api/fileMapper.ts b/api/fileMapper.ts index c227cbb..c96f84f 100644 --- a/api/fileMapper.ts +++ b/api/fileMapper.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import path from 'path'; import contentDisposition from 'content-disposition'; import { AxiosResponse } from 'axios'; -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { getCwd } from '../lib/path'; import { FileMapperNode, FileMapperOptions, FileTree } from '../types/Files'; @@ -46,7 +46,7 @@ export function upload( src: string, dest: string, options: FileMapperOptions = {} -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${FILE_MAPPER_API_PATH}/upload/${encodeURIComponent(dest)}`, data: { @@ -62,7 +62,7 @@ export function fetchModule( accountId: number, moduleId: number, options: FileMapperOptions = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FILE_MAPPER_API_PATH}/modules/${moduleId}`, ...options, @@ -92,7 +92,7 @@ export function download( accountId: number, filepath: string, options: FileMapperOptions = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FILE_MAPPER_API_PATH}/download/${encodeURIComponent(filepath)}`, ...options, @@ -104,7 +104,7 @@ export function downloadDefault( accountId: number, filepath: string, options: FileMapperOptions = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FILE_MAPPER_API_PATH}/download-default/${filepath}`, ...options, @@ -115,7 +115,7 @@ export function downloadDefault( export function deleteFile( accountId: number, filePath: string -): HubSpotResponse { +): HubSpotPromise { return http.delete(accountId, { url: `${FILE_MAPPER_API_PATH}/delete/${encodeURIComponent(filePath)}`, }); @@ -126,7 +126,7 @@ export function moveFile( accountId: number, srcPath: string, destPath: string -): HubSpotResponse { +): HubSpotPromise { return http.put(accountId, { url: `${FILE_MAPPER_API_PATH}/rename/${srcPath}?path=${destPath}`, headers: { 'Content-Type': 'application/json' }, @@ -137,7 +137,7 @@ export function moveFile( export function getDirectoryContentsByPath( accountId: number, path: string -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FILE_MAPPER_API_PATH}/meta/${path}`, }); diff --git a/api/fileTransport.ts b/api/fileTransport.ts index b5e2d0d..9862c10 100644 --- a/api/fileTransport.ts +++ b/api/fileTransport.ts @@ -1,13 +1,13 @@ import fs from 'fs'; import path from 'path'; import { getCwd } from '../lib/path'; -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; const HUBFILES_API_PATH = '/file-transport/v1/hubfiles'; export function createSchemaFromHubFile( accountId: number, filepath: string -): HubSpotResponse { +): HubSpotPromise { const file = fs.createReadStream(path.resolve(getCwd(), filepath)); return http.post(accountId, { url: `${HUBFILES_API_PATH}/object-schemas`, @@ -21,7 +21,7 @@ export function createSchemaFromHubFile( export async function updateSchemaFromHubFile( accountId: number, filepath: string -): HubSpotResponse { +): HubSpotPromise { const file = fs.createReadStream(path.resolve(getCwd(), filepath)); return http.put(accountId, { url: `${HUBFILES_API_PATH}/object-schemas`, @@ -36,7 +36,7 @@ export async function fetchHubFileSchema( accountId: number, objectName: string, path: string -): HubSpotResponse { +): HubSpotPromise { return http.getOctetStream( accountId, { diff --git a/api/functions.ts b/api/functions.ts index 0aceafe..bfcb00a 100644 --- a/api/functions.ts +++ b/api/functions.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { QueryParams } from '../types/Http'; import { GetBuildStatusResponse, GetRoutesResponse } from '../types/Functions'; @@ -6,7 +6,7 @@ const FUNCTION_API_PATH = 'cms/v3/functions'; export function getRoutes( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FUNCTION_API_PATH}/routes`, }); @@ -16,7 +16,7 @@ export function getFunctionLogs( accountId: number, route: string, params: QueryParams = {} -): HubSpotResponse { +): HubSpotPromise { const { limit = 5 } = params; return http.get(accountId, { @@ -28,7 +28,7 @@ export function getFunctionLogs( export function getLatestFunctionLog( accountId: number, route: string -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FUNCTION_API_PATH}/results/by-route/${encodeURIComponent( route @@ -39,7 +39,7 @@ export function getLatestFunctionLog( export function buildPackage( accountId: number, folderPath: string -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${FUNCTION_API_PATH}/build/async`, headers: { @@ -54,7 +54,7 @@ export function buildPackage( export function getBuildStatus( accountId: number, buildId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${FUNCTION_API_PATH}/build/${buildId}/poll`, }); diff --git a/api/github.ts b/api/github.ts index 7d3bc30..cd9d3ef 100644 --- a/api/github.ts +++ b/api/github.ts @@ -1,7 +1,7 @@ import axios from 'axios'; import { getDefaultUserAgentHeader } from '../http/getAxiosConfig'; import { GithubReleaseData, GithubRepoFile, RepoPath } from '../types/Github'; -import { HubSpotResponse } from '../http'; +import { HubSpotPromise } from '../http'; const GITHUB_REPOS_API = 'https://api.github.com/repos'; const GITHUB_RAW_CONTENT_API_PATH = 'https://raw.githubusercontent.com'; @@ -32,7 +32,7 @@ function getAdditionalHeaders(): AdditionalGitHubHeaders { export function fetchRepoReleaseData( repoPath: RepoPath, tag = '' -): HubSpotResponse { +): HubSpotPromise { const URL = `${GITHUB_REPOS_API}/${repoPath}/releases`; return axios.get( @@ -48,7 +48,7 @@ export function fetchRepoReleaseData( // Returns the entire repo content as a zip, using the zipball_url from fetchRepoReleaseData() // https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#download-a-repository-archive-zip -export function fetchRepoAsZip(zipUrl: string): HubSpotResponse { +export function fetchRepoAsZip(zipUrl: string): HubSpotPromise { return axios.get(zipUrl, { responseType: 'arraybuffer', headers: { ...getDefaultUserAgentHeader(), ...getAdditionalHeaders() }, @@ -60,7 +60,7 @@ export function fetchRepoFile( repoPath: RepoPath, filePath: string, ref: string -): HubSpotResponse { +): HubSpotPromise { return axios.get( `${GITHUB_RAW_CONTENT_API_PATH}/${repoPath}/${ref}/${filePath}`, { @@ -75,7 +75,7 @@ export function fetchRepoFile( // Returns the raw file contents via the raw.githubusercontent endpoint export function fetchRepoFileByDownloadUrl( downloadUrl: string -): HubSpotResponse { +): HubSpotPromise { return axios.get(downloadUrl, { headers: { ...getDefaultUserAgentHeader(), ...getAdditionalHeaders() }, responseType: 'arraybuffer', @@ -88,7 +88,7 @@ export function fetchRepoContents( repoPath: RepoPath, path: string, ref?: string -): HubSpotResponse> { +): HubSpotPromise> { const refQuery = ref ? `?ref=${ref}` : ''; return axios.get>( diff --git a/api/hubdb.ts b/api/hubdb.ts index 1ae21b6..1479d9b 100644 --- a/api/hubdb.ts +++ b/api/hubdb.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { QueryParams } from '../types/Http'; import { CreateRowsResponse, @@ -13,7 +13,7 @@ const HUBDB_API_PATH = 'cms/v3/hubdb'; export function fetchTables( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${HUBDB_API_PATH}/tables`, }); @@ -22,7 +22,7 @@ export function fetchTables( export function fetchTable( accountId: number, tableId: string -): HubSpotResponse
{ +): HubSpotPromise
{ return http.get
(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}`, }); @@ -31,7 +31,7 @@ export function fetchTable( export function createTable( accountId: number, schema: Schema -): HubSpotResponse
{ +): HubSpotPromise
{ return http.post
(accountId, { url: `${HUBDB_API_PATH}/tables`, data: schema, @@ -42,7 +42,7 @@ export function updateTable( accountId: number, tableId: string, schema: Schema -): HubSpotResponse
{ +): HubSpotPromise
{ return http.patch
(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/draft`, data: schema, @@ -52,7 +52,7 @@ export function updateTable( export function publishTable( accountId: number, tableId: string -): HubSpotResponse
{ +): HubSpotPromise
{ return http.post
(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/draft/publish`, headers: { @@ -64,7 +64,7 @@ export function publishTable( export function deleteTable( accountId: number, tableId: string -): HubSpotResponse { +): HubSpotPromise { return http.delete(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}`, }); @@ -74,7 +74,7 @@ export function createRows( accountId: number, tableId: string, rows: Array -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft/batch/create`, data: { inputs: rows }, @@ -85,7 +85,7 @@ export function fetchRows( accountId: number, tableId: string, params: QueryParams = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft`, params, @@ -96,7 +96,7 @@ export function deleteRows( accountId: number, tableId: string, rowIds: Array -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft/batch/purge`, data: { inputs: rowIds }, diff --git a/api/lighthouseScore.ts b/api/lighthouseScore.ts index 62865e1..53a792d 100644 --- a/api/lighthouseScore.ts +++ b/api/lighthouseScore.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { Data, QueryParams } from '../types/Http'; import { GetLighthouseScoreResponse, @@ -10,7 +10,7 @@ const LIGHTHOUSE_SCORE_API_BASE = 'quality-engine/v1/lighthouse'; export function requestLighthouseScore( accountId: number, data: Data = {} -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${LIGHTHOUSE_SCORE_API_BASE}/request`, data, @@ -20,7 +20,7 @@ export function requestLighthouseScore( export function getLighthouseScoreStatus( accountId: number, params: QueryParams = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${LIGHTHOUSE_SCORE_API_BASE}/status`, params, @@ -30,7 +30,7 @@ export function getLighthouseScoreStatus( export function getLighthouseScore( accountId: number, params: QueryParams = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${LIGHTHOUSE_SCORE_API_BASE}/scores`, params, diff --git a/api/localDevAuth.ts b/api/localDevAuth.ts index 3ed6fe6..be8cddf 100644 --- a/api/localDevAuth.ts +++ b/api/localDevAuth.ts @@ -1,5 +1,5 @@ import { getAxiosConfig } from '../http/getAxiosConfig'; -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { ENVIRONMENTS } from '../constants/environments'; import { Environment } from '../types/Config'; import { @@ -16,7 +16,7 @@ export function fetchAccessToken( personalAccessKey: string, env: Environment = ENVIRONMENTS.PROD, portalId?: number -): HubSpotResponse { +): HubSpotPromise { const axiosConfig = getAxiosConfig({ env, localHostOverride: true, @@ -36,7 +36,7 @@ export function fetchAccessToken( export function fetchScopeData( accountId: number, scopeGroup: string -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${LOCALDEVAUTH_API_AUTH_PATH}/check-scopes`, params: { scopeGroup }, @@ -49,7 +49,7 @@ export function fetchAppInstallationData( appUid: string, requiredScopeGroups: Array, optionalScopeGroups: Array = [] -): HubSpotResponse { +): HubSpotPromise { return http.post(portalId, { url: `${LOCALDEVAUTH_API_AUTH_PATH}/install-info`, data: { diff --git a/api/marketplaceValidation.ts b/api/marketplaceValidation.ts index d344adc..7bbf582 100644 --- a/api/marketplaceValidation.ts +++ b/api/marketplaceValidation.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { Data, QueryParams } from '../types/Http'; import { GetValidationResultsResponse } from '../types/MarketplaceValidation'; @@ -7,7 +7,7 @@ const VALIDATION_API_BASE = 'quality-engine/v1/validation'; export function requestValidation( accountId: number, data: Data = {} -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${VALIDATION_API_BASE}/request`, data, @@ -17,7 +17,7 @@ export function requestValidation( export function getValidationStatus( accountId: number, params: QueryParams = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${VALIDATION_API_BASE}/status`, params, @@ -27,7 +27,7 @@ export function getValidationStatus( export function getValidationResults( accountId: number, params: QueryParams = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${VALIDATION_API_BASE}/results`, params, diff --git a/api/projects.ts b/api/projects.ts index 2504e6f..951fde9 100644 --- a/api/projects.ts +++ b/api/projects.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import fs from 'fs'; import { FormData, QueryParams } from '../types/Http'; import { @@ -30,7 +30,7 @@ const MIGRATIONS_API_PATH = 'dfs/migrations/v1'; export function fetchProjects( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: DEVELOPER_PROJECTS_API_PATH, }); @@ -39,7 +39,7 @@ export function fetchProjects( export function createProject( accountId: number, name: string -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: DEVELOPER_PROJECTS_API_PATH, data: { @@ -54,7 +54,7 @@ export function uploadProject( projectFile: string, uploadMessage: string, platformVersion?: string -): HubSpotResponse { +): HubSpotPromise { const formData: FormData = { file: fs.createReadStream(projectFile), uploadMessage, @@ -74,7 +74,7 @@ export function uploadProject( export function fetchProject( accountId: number, projectName: string -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${encodeURIComponent(projectName)}`, }); @@ -83,7 +83,7 @@ export function fetchProject( export async function fetchProjectComponentsMetadata( accountId: number, projectId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${DEVELOPER_FILE_SYSTEM_PATH}/projects-deployed-build/${projectId}`, }); @@ -93,7 +93,7 @@ export async function downloadProject( accountId: number, projectName: string, buildId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -106,7 +106,7 @@ export async function downloadProject( export function deleteProject( accountId: number, projectName: string -): HubSpotResponse { +): HubSpotPromise { return http.delete(accountId, { url: `${DEVELOPER_PROJECTS_API_PATH}/${encodeURIComponent(projectName)}`, }); @@ -114,7 +114,7 @@ export function deleteProject( export function fetchPlatformVersions( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${DEVELOPER_PROJECTS_API_PATH}/platformVersion`, }); @@ -124,7 +124,7 @@ export function fetchProjectBuilds( accountId: number, projectName: string, params: QueryParams = {} -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent(projectName)}/builds`, params, @@ -135,7 +135,7 @@ export function getBuildStatus( accountId: number, projectName: string, buildId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -147,7 +147,7 @@ export function getBuildStructure( accountId: number, projectName: string, buildId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `dfs/v1/builds/by-project-name/${encodeURIComponent( projectName @@ -159,7 +159,7 @@ export function deployProject( accountId: number, projectName: string, buildId: number -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${PROJECTS_DEPLOY_API_PATH}/deploys/queue/async`, data: { @@ -173,7 +173,7 @@ export function getDeployStatus( accountId: number, projectName: string, deployId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${PROJECTS_DEPLOY_API_PATH}/deploy-status/projects/${encodeURIComponent( projectName @@ -185,7 +185,7 @@ export function getDeployStructure( accountId: number, projectName: string, deployId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${PROJECTS_DEPLOY_API_PATH}/deploys/by-project-name/${encodeURIComponent( projectName @@ -196,7 +196,7 @@ export function getDeployStructure( export function fetchProjectSettings( accountId: number, projectName: string -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${DEVELOPER_PROJECTS_API_PATH}/${encodeURIComponent(projectName)}/settings`, }); @@ -206,7 +206,7 @@ export async function provisionBuild( accountId: number, projectName: string, platformVersion?: string -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -221,7 +221,7 @@ export function queueBuild( accountId: number, projectName: string, platformVersion?: string -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -236,7 +236,7 @@ export function uploadFileToBuild( projectName: string, filePath: string, path: string -): HubSpotResponse { +): HubSpotPromise { return http.put(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -252,7 +252,7 @@ export function deleteFileFromBuild( accountId: number, projectName: string, path: string -): HubSpotResponse { +): HubSpotPromise { return http.delete(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -263,7 +263,7 @@ export function deleteFileFromBuild( export function cancelStagedBuild( accountId: number, projectName: string -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${PROJECTS_API_PATH}/${encodeURIComponent( projectName @@ -280,7 +280,7 @@ export function fetchBuildWarnLogs( accountId: number, projectName: string, buildId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${PROJECTS_LOGS_API_PATH}/logs/projects/${encodeURIComponent( projectName @@ -292,7 +292,7 @@ export function fetchDeployWarnLogs( accountId: number, projectName: string, deployId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${PROJECTS_LOGS_API_PATH}/logs/projects/${encodeURIComponent( projectName @@ -304,7 +304,7 @@ export function migrateApp( accountId: number, appId: number, projectName: string -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${MIGRATIONS_API_PATH}/migrations`, data: { @@ -318,7 +318,7 @@ export function migrateApp( export function checkMigrationStatus( accountId: number, id: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${MIGRATIONS_API_PATH}/migrations/${id}`, }); @@ -327,7 +327,7 @@ export function checkMigrationStatus( export function cloneApp( accountId: number, appId: number -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: `${MIGRATIONS_API_PATH}/exports`, data: { @@ -340,7 +340,7 @@ export function cloneApp( export function checkCloneStatus( accountId: number, exportId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${MIGRATIONS_API_PATH}/exports/${exportId}/status`, }); @@ -349,7 +349,7 @@ export function checkCloneStatus( export function downloadClonedProject( accountId: number, exportId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${MIGRATIONS_API_PATH}/exports/${exportId}/download-as-clone`, responseType: 'arraybuffer', diff --git a/api/sandboxHubs.ts b/api/sandboxHubs.ts index 229c14c..e2df770 100644 --- a/api/sandboxHubs.ts +++ b/api/sandboxHubs.ts @@ -1,5 +1,5 @@ import axios, { AxiosPromise } from 'axios'; -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { getAxiosConfig } from '../http/getAxiosConfig'; import { ENVIRONMENTS } from '../constants/environments'; import { SANDBOX_TIMEOUT } from '../constants/api'; @@ -17,7 +17,7 @@ export function createSandbox( accountId: number, name: string, type: 1 | 2 -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { data: { name, type, generatePersonalAccessKey: true }, // For CLI, generatePersonalAccessKey will always be true since we'll be saving the entry to the config timeout: SANDBOX_TIMEOUT, @@ -28,7 +28,7 @@ export function createSandbox( export function deleteSandbox( parentAccountId: number, sandboxAccountId: number -): HubSpotResponse { +): HubSpotPromise { return http.delete(parentAccountId, { url: `${SANDBOX_API_PATH}/${sandboxAccountId}`, }); @@ -36,7 +36,7 @@ export function deleteSandbox( export function getSandboxUsageLimits( parentAccountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(parentAccountId, { url: `${SANDBOX_API_PATH}/parent/${parentAccountId}/usage`, }); diff --git a/api/sandboxSync.ts b/api/sandboxSync.ts index d348eec..cd9ea5e 100644 --- a/api/sandboxSync.ts +++ b/api/sandboxSync.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { InitiateSyncResponse, FetchTypesResponse, @@ -12,7 +12,7 @@ export async function initiateSync( toHubId: number, tasks: Array, sandboxHubId: number -): HubSpotResponse { +): HubSpotPromise { return http.post(fromHubId, { data: { command: 'SYNC', @@ -29,7 +29,7 @@ export async function initiateSync( export async function fetchTypes( accountId: number, toHubId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${SANDBOXES_SYNC_API_PATH}/types${ toHubId ? `?toHubId=${toHubId}` : '' diff --git a/api/secrets.ts b/api/secrets.ts index 756f858..b6c648b 100644 --- a/api/secrets.ts +++ b/api/secrets.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { FetchSecretsResponse } from '../types/Secrets'; const SECRETS_API_PATH = 'cms/v3/functions/secrets'; @@ -7,7 +7,7 @@ export function addSecret( accountId: number, key: string, value: string -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: SECRETS_API_PATH, data: { @@ -21,7 +21,7 @@ export function updateSecret( accountId: number, key: string, value: string -): HubSpotResponse { +): HubSpotPromise { return http.put(accountId, { url: SECRETS_API_PATH, data: { @@ -34,7 +34,7 @@ export function updateSecret( export function deleteSecret( accountId: number, key: string -): HubSpotResponse { +): HubSpotPromise { return http.delete(accountId, { url: `${SECRETS_API_PATH}/${key}`, }); @@ -42,7 +42,7 @@ export function deleteSecret( export function fetchSecrets( accountId: number -): HubSpotResponse { +): HubSpotPromise { return http.get(accountId, { url: `${SECRETS_API_PATH}`, }); diff --git a/api/validateHubl.ts b/api/validateHubl.ts index 50af718..d8b7ab4 100644 --- a/api/validateHubl.ts +++ b/api/validateHubl.ts @@ -1,4 +1,4 @@ -import { http, HubSpotResponse } from '../http'; +import { http, HubSpotPromise } from '../http'; import { Validation, HublValidationOptions } from '../types/HublValidation'; const HUBL_VALIDATE_API_PATH = 'cos-rendering/v1/internal/validate'; @@ -7,7 +7,7 @@ export function validateHubl( accountId: number, sourceCode: string, hublValidationOptions?: HublValidationOptions -): HubSpotResponse { +): HubSpotPromise { return http.post(accountId, { url: HUBL_VALIDATE_API_PATH, data: { diff --git a/http/index.ts b/http/index.ts index b38e1b1..0295d0d 100644 --- a/http/index.ts +++ b/http/index.ts @@ -16,7 +16,7 @@ import { HubSpotHttpError } from '../models/HubSpotHttpError'; const i18nKey = 'http.index'; -export type HubSpotResponse = AxiosPromise; +export type HubSpotPromise = AxiosPromise; axios.interceptors.response.use(undefined, error => { // Wrap all axios errors in our own Error class. Attach the error @@ -117,7 +117,7 @@ async function withAuth( async function getRequest( accountId: number, options: HttpOptions -): HubSpotResponse { +): HubSpotPromise { const { params, ...rest } = options; const optionsWithParams = addQueryParams(rest, params); const requestConfig = await withAuth(accountId, optionsWithParams); @@ -128,7 +128,7 @@ async function getRequest( async function postRequest( accountId: number, options: HttpOptions -): HubSpotResponse { +): HubSpotPromise { const requestConfig = await withAuth(accountId, options); return axios({ ...requestConfig, method: 'post' }); } @@ -136,7 +136,7 @@ async function postRequest( async function putRequest( accountId: number, options: HttpOptions -): HubSpotResponse { +): HubSpotPromise { const requestConfig = await withAuth(accountId, options); return axios({ ...requestConfig, method: 'put' }); } @@ -144,7 +144,7 @@ async function putRequest( async function patchRequest( accountId: number, options: HttpOptions -): HubSpotResponse { +): HubSpotPromise { const requestConfig = await withAuth(accountId, options); return axios({ ...requestConfig, method: 'patch' }); } @@ -152,7 +152,7 @@ async function patchRequest( async function deleteRequest( accountId: number, options: HttpOptions -): HubSpotResponse { +): HubSpotPromise { const requestConfig = await withAuth(accountId, options); return axios({ ...requestConfig, method: 'delete' }); } diff --git a/http/unauthed.ts b/http/unauthed.ts index bd2628e..cba83c2 100644 --- a/http/unauthed.ts +++ b/http/unauthed.ts @@ -2,9 +2,9 @@ import axios from 'axios'; import { getAxiosConfig } from './getAxiosConfig'; import { addQueryParams } from './addQueryParams'; import { HttpOptions } from '../types/Http'; -import { HubSpotResponse } from './index'; +import { HubSpotPromise } from './index'; -async function getRequest(options: HttpOptions): HubSpotResponse { +async function getRequest(options: HttpOptions): HubSpotPromise { const { params, ...rest } = options; const optionsWithParams = addQueryParams(rest, params); const requestConfig = await getAxiosConfig(optionsWithParams); @@ -12,22 +12,22 @@ async function getRequest(options: HttpOptions): HubSpotResponse { return axios(requestConfig); } -async function postRequest(options: HttpOptions): HubSpotResponse { +async function postRequest(options: HttpOptions): HubSpotPromise { const requestConfig = await getAxiosConfig(options); return axios({ ...requestConfig, method: 'post' }); } -async function putRequest(options: HttpOptions): HubSpotResponse { +async function putRequest(options: HttpOptions): HubSpotPromise { const requestConfig = await getAxiosConfig(options); return axios({ ...requestConfig, method: 'put' }); } -async function patchRequest(options: HttpOptions): HubSpotResponse { +async function patchRequest(options: HttpOptions): HubSpotPromise { const requestConfig = await getAxiosConfig(options); return axios({ ...requestConfig, method: 'patch' }); } -async function deleteRequest(options: HttpOptions): HubSpotResponse { +async function deleteRequest(options: HttpOptions): HubSpotPromise { const requestConfig = await getAxiosConfig(options); return axios({ ...requestConfig, method: 'delete' }); } diff --git a/lib/__tests__/validate.test.ts b/lib/__tests__/validate.test.ts index a8b8d92..f01ee01 100644 --- a/lib/__tests__/validate.test.ts +++ b/lib/__tests__/validate.test.ts @@ -3,7 +3,7 @@ import { validateHubl } from '../../api/validateHubl'; import { walk } from '../fs'; import { lint } from '../cms/validate'; import { LintResult, Validation } from '../../types/HublValidation'; -import { HubSpotResponse } from '../../http'; +import { HubSpotPromise } from '../../http'; jest.mock('fs-extra'); jest.mock('../../api/validateHubl'); @@ -76,7 +76,7 @@ describe('lib/cms/validate', () => { mockedFsReadFile.mockResolvedValue(mockSource); mockedValidateHubl.mockResolvedValue({ data: mockValidation, - } as unknown as HubSpotResponse); + } as unknown as HubSpotPromise); const result = await lint(accountId, filePath); expect(validateHubl).toHaveBeenCalledWith(accountId, mockSource); expect(result).toEqual([{ file: filePath, validation: mockValidation }]); @@ -89,7 +89,7 @@ describe('lib/cms/validate', () => { mockedFsReadFile.mockResolvedValue('valid HUBL content'); mockedValidateHubl.mockResolvedValue({ data: mockValidation, - } as unknown as HubSpotResponse); + } as unknown as HubSpotPromise); const result = await lint(accountId, filePath); @@ -104,7 +104,7 @@ describe('lib/cms/validate', () => { mockedFsReadFile.mockResolvedValue(mockSource); mockedValidateHubl.mockResolvedValue({ data: mockValidation, - } as unknown as HubSpotResponse); + } as unknown as HubSpotPromise); await lint(accountId, filePath, mockCallback); expect(mockCallback).toHaveBeenCalledWith({ From 2dcbc94d8f4e5048db83d56d1ec667726ec55dab Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Mon, 25 Nov 2024 10:31:45 -0800 Subject: [PATCH 4/5] Move the HubSpotPromise type to the types/http file --- api/appsDev.ts | 3 ++- api/customObjects.ts | 3 ++- api/designManager.ts | 4 ++-- api/developerTestAccounts.ts | 3 ++- api/fileManager.ts | 4 ++-- api/fileMapper.ts | 3 ++- api/fileTransport.ts | 3 ++- api/functions.ts | 4 ++-- api/github.ts | 2 +- api/hubdb.ts | 4 ++-- api/lighthouseScore.ts | 4 ++-- api/localDevAuth.ts | 3 ++- api/marketplaceValidation.ts | 4 ++-- api/projects.ts | 4 ++-- api/sandboxHubs.ts | 3 ++- api/sandboxSync.ts | 3 ++- api/secrets.ts | 3 ++- api/validateHubl.ts | 3 ++- http/index.ts | 4 +--- http/unauthed.ts | 3 +-- types/Http.ts | 4 +++- 21 files changed, 40 insertions(+), 31 deletions(-) diff --git a/api/appsDev.ts b/api/appsDev.ts index 1eb541d..4d72a12 100644 --- a/api/appsDev.ts +++ b/api/appsDev.ts @@ -1,10 +1,11 @@ -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { PublicApp, PublicAppInstallCounts, PublicAppDeveloperTestAccountInstallData, FetchPublicAppsForPortalResponse, } from '../types/Apps'; +import { HubSpotPromise } from '../types/Http'; const APPS_DEV_API_PATH = 'apps-dev/external/public/v3'; diff --git a/api/customObjects.ts b/api/customObjects.ts index ee732fc..abce435 100644 --- a/api/customObjects.ts +++ b/api/customObjects.ts @@ -1,9 +1,10 @@ -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { FetchSchemasResponse, Schema, CreateObjectsResponse, } from '../types/Schemas'; +import { HubSpotPromise } from '../types/Http'; const CUSTOM_OBJECTS_API_PATH = 'crm/v3/objects'; const SCHEMA_API_PATH = 'crm-object-schemas/v3/schemas'; diff --git a/api/designManager.ts b/api/designManager.ts index a9b864f..245241e 100644 --- a/api/designManager.ts +++ b/api/designManager.ts @@ -1,5 +1,5 @@ -import { http, HubSpotPromise } from '../http'; -import { QueryParams } from '../types/Http'; +import { http } from '../http'; +import { HubSpotPromise, QueryParams } from '../types/Http'; import { FetchThemesResponse, FetchBuiltinMappingResponse, diff --git a/api/developerTestAccounts.ts b/api/developerTestAccounts.ts index 2a0601b..dc784a0 100644 --- a/api/developerTestAccounts.ts +++ b/api/developerTestAccounts.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { getAxiosConfig } from '../http/getAxiosConfig'; import { ENVIRONMENTS } from '../constants/environments'; import { @@ -8,6 +8,7 @@ import { } from '../types/developerTestAccounts'; import { SANDBOX_TIMEOUT } from '../constants/api'; import { Environment } from '../types/Config'; +import { HubSpotPromise } from '../types/Http'; const TEST_ACCOUNTS_API_PATH = 'integrators/test-portals/v2'; diff --git a/api/fileManager.ts b/api/fileManager.ts index a803b87..0bac5e6 100644 --- a/api/fileManager.ts +++ b/api/fileManager.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; -import { http, HubSpotPromise } from '../http'; -import { FormData } from '../types/Http'; +import { http } from '../http'; +import { FormData, HubSpotPromise } from '../types/Http'; import { FetchStatResponse, FetchFilesResponse, diff --git a/api/fileMapper.ts b/api/fileMapper.ts index c96f84f..002068f 100644 --- a/api/fileMapper.ts +++ b/api/fileMapper.ts @@ -2,9 +2,10 @@ import fs from 'fs'; import path from 'path'; import contentDisposition from 'content-disposition'; import { AxiosResponse } from 'axios'; -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { getCwd } from '../lib/path'; import { FileMapperNode, FileMapperOptions, FileTree } from '../types/Files'; +import { HubSpotPromise } from '../types/Http'; export const FILE_MAPPER_API_PATH = 'content/filemapper/v1'; diff --git a/api/fileTransport.ts b/api/fileTransport.ts index 9862c10..6d9a3ec 100644 --- a/api/fileTransport.ts +++ b/api/fileTransport.ts @@ -1,7 +1,8 @@ import fs from 'fs'; import path from 'path'; import { getCwd } from '../lib/path'; -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; +import { HubSpotPromise } from '../types/Http'; const HUBFILES_API_PATH = '/file-transport/v1/hubfiles'; export function createSchemaFromHubFile( diff --git a/api/functions.ts b/api/functions.ts index bfcb00a..3dc4dbc 100644 --- a/api/functions.ts +++ b/api/functions.ts @@ -1,5 +1,5 @@ -import { http, HubSpotPromise } from '../http'; -import { QueryParams } from '../types/Http'; +import { http } from '../http'; +import { HubSpotPromise, QueryParams } from '../types/Http'; import { GetBuildStatusResponse, GetRoutesResponse } from '../types/Functions'; const FUNCTION_API_PATH = 'cms/v3/functions'; diff --git a/api/github.ts b/api/github.ts index cd9d3ef..46ee440 100644 --- a/api/github.ts +++ b/api/github.ts @@ -1,7 +1,7 @@ import axios from 'axios'; import { getDefaultUserAgentHeader } from '../http/getAxiosConfig'; import { GithubReleaseData, GithubRepoFile, RepoPath } from '../types/Github'; -import { HubSpotPromise } from '../http'; +import { HubSpotPromise } from '../types/Http'; const GITHUB_REPOS_API = 'https://api.github.com/repos'; const GITHUB_RAW_CONTENT_API_PATH = 'https://raw.githubusercontent.com'; diff --git a/api/hubdb.ts b/api/hubdb.ts index 1479d9b..b010b53 100644 --- a/api/hubdb.ts +++ b/api/hubdb.ts @@ -1,5 +1,5 @@ -import { http, HubSpotPromise } from '../http'; -import { QueryParams } from '../types/Http'; +import { http } from '../http'; +import { HubSpotPromise, QueryParams } from '../types/Http'; import { CreateRowsResponse, FetchRowsResponse, diff --git a/api/lighthouseScore.ts b/api/lighthouseScore.ts index 53a792d..60fe035 100644 --- a/api/lighthouseScore.ts +++ b/api/lighthouseScore.ts @@ -1,5 +1,5 @@ -import { http, HubSpotPromise } from '../http'; -import { Data, QueryParams } from '../types/Http'; +import { http } from '../http'; +import { Data, HubSpotPromise, QueryParams } from '../types/Http'; import { GetLighthouseScoreResponse, RequestLighthouseScoreResponse, diff --git a/api/localDevAuth.ts b/api/localDevAuth.ts index be8cddf..e9407f5 100644 --- a/api/localDevAuth.ts +++ b/api/localDevAuth.ts @@ -1,5 +1,5 @@ import { getAxiosConfig } from '../http/getAxiosConfig'; -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { ENVIRONMENTS } from '../constants/environments'; import { Environment } from '../types/Config'; import { @@ -9,6 +9,7 @@ import { } from '../types/Accounts'; import axios from 'axios'; import { PublicAppInstallationData } from '../types/Apps'; +import { HubSpotPromise } from '../types/Http'; const LOCALDEVAUTH_API_AUTH_PATH = 'localdevauth/v1/auth'; diff --git a/api/marketplaceValidation.ts b/api/marketplaceValidation.ts index 7bbf582..7216493 100644 --- a/api/marketplaceValidation.ts +++ b/api/marketplaceValidation.ts @@ -1,5 +1,5 @@ -import { http, HubSpotPromise } from '../http'; -import { Data, QueryParams } from '../types/Http'; +import { http } from '../http'; +import { Data, HubSpotPromise, QueryParams } from '../types/Http'; import { GetValidationResultsResponse } from '../types/MarketplaceValidation'; const VALIDATION_API_BASE = 'quality-engine/v1/validation'; diff --git a/api/projects.ts b/api/projects.ts index 951fde9..ce7be00 100644 --- a/api/projects.ts +++ b/api/projects.ts @@ -1,6 +1,6 @@ -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import fs from 'fs'; -import { FormData, QueryParams } from '../types/Http'; +import { FormData, HubSpotPromise, QueryParams } from '../types/Http'; import { Project, FetchProjectResponse, diff --git a/api/sandboxHubs.ts b/api/sandboxHubs.ts index e2df770..1af5275 100644 --- a/api/sandboxHubs.ts +++ b/api/sandboxHubs.ts @@ -1,5 +1,5 @@ import axios, { AxiosPromise } from 'axios'; -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { getAxiosConfig } from '../http/getAxiosConfig'; import { ENVIRONMENTS } from '../constants/environments'; import { SANDBOX_TIMEOUT } from '../constants/api'; @@ -9,6 +9,7 @@ import { SandboxResponse, SandboxUsageLimitsResponse, } from '../types/Sandbox'; +import { HubSpotPromise } from '../types/Http'; const SANDBOX_API_PATH = 'sandbox-hubs/v1'; const SANDBOX_API_PATH_V2 = 'sandbox-hubs/v2'; diff --git a/api/sandboxSync.ts b/api/sandboxSync.ts index cd9ea5e..6878c06 100644 --- a/api/sandboxSync.ts +++ b/api/sandboxSync.ts @@ -1,10 +1,11 @@ -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { InitiateSyncResponse, FetchTypesResponse, TaskRequestData, } from '../types/Sandbox'; import { SANDBOX_TIMEOUT } from '../constants/api'; +import { HubSpotPromise } from '../types/Http'; const SANDBOXES_SYNC_API_PATH = 'sandboxes-sync/v1'; export async function initiateSync( diff --git a/api/secrets.ts b/api/secrets.ts index b6c648b..a1d7c66 100644 --- a/api/secrets.ts +++ b/api/secrets.ts @@ -1,5 +1,6 @@ -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { FetchSecretsResponse } from '../types/Secrets'; +import { HubSpotPromise } from '../types/Http'; const SECRETS_API_PATH = 'cms/v3/functions/secrets'; diff --git a/api/validateHubl.ts b/api/validateHubl.ts index d8b7ab4..15bac8d 100644 --- a/api/validateHubl.ts +++ b/api/validateHubl.ts @@ -1,5 +1,6 @@ -import { http, HubSpotPromise } from '../http'; +import { http } from '../http'; import { Validation, HublValidationOptions } from '../types/HublValidation'; +import { HubSpotPromise } from '../types/Http'; const HUBL_VALIDATE_API_PATH = 'cos-rendering/v1/internal/validate'; diff --git a/http/index.ts b/http/index.ts index 0295d0d..6bebea8 100644 --- a/http/index.ts +++ b/http/index.ts @@ -9,15 +9,13 @@ import { addQueryParams } from './addQueryParams'; import { accessTokenForPersonalAccessKey } from '../lib/personalAccessKey'; import { getOauthManager } from '../lib/oauth'; import { FlatAccountFields } from '../types/Accounts'; -import { HttpOptions } from '../types/Http'; +import { HttpOptions, HubSpotPromise } from '../types/Http'; import { logger } from '../lib/logger'; import { i18n } from '../utils/lang'; import { HubSpotHttpError } from '../models/HubSpotHttpError'; const i18nKey = 'http.index'; -export type HubSpotPromise = AxiosPromise; - axios.interceptors.response.use(undefined, error => { // Wrap all axios errors in our own Error class. Attach the error // as the cause for the new error, so we maintain the stack trace diff --git a/http/unauthed.ts b/http/unauthed.ts index cba83c2..5e5ab37 100644 --- a/http/unauthed.ts +++ b/http/unauthed.ts @@ -1,8 +1,7 @@ import axios from 'axios'; import { getAxiosConfig } from './getAxiosConfig'; import { addQueryParams } from './addQueryParams'; -import { HttpOptions } from '../types/Http'; -import { HubSpotPromise } from './index'; +import { HttpOptions, HubSpotPromise } from '../types/Http'; async function getRequest(options: HttpOptions): HubSpotPromise { const { params, ...rest } = options; diff --git a/types/Http.ts b/types/Http.ts index c5ac5da..4b827d7 100644 --- a/types/Http.ts +++ b/types/Http.ts @@ -1,7 +1,9 @@ -import { ResponseType } from 'axios'; +import { AxiosPromise, ResponseType } from 'axios'; import { ReadStream } from 'fs'; import { Stream } from 'stream'; +export type HubSpotPromise = AxiosPromise; + export type Data = { // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; From 89d1f222f693f7e52951710bffb119ce2d887008 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Mon, 25 Nov 2024 10:37:18 -0800 Subject: [PATCH 5/5] Update bad import --- lib/__tests__/validate.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/__tests__/validate.test.ts b/lib/__tests__/validate.test.ts index f01ee01..05d9827 100644 --- a/lib/__tests__/validate.test.ts +++ b/lib/__tests__/validate.test.ts @@ -3,7 +3,7 @@ import { validateHubl } from '../../api/validateHubl'; import { walk } from '../fs'; import { lint } from '../cms/validate'; import { LintResult, Validation } from '../../types/HublValidation'; -import { HubSpotPromise } from '../../http'; +import { HubSpotPromise } from '../../types/Http'; jest.mock('fs-extra'); jest.mock('../../api/validateHubl');