Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Wrap Axios type and export new type #210

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions api/appsDev.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { AxiosPromise } from 'axios';
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';

export function fetchPublicAppsForPortal(
accountId: number
): AxiosPromise<FetchPublicAppsForPortalResponse> {
): HubSpotPromise<FetchPublicAppsForPortalResponse> {
return http.get<FetchPublicAppsForPortalResponse>(accountId, {
url: `${APPS_DEV_API_PATH}/full/portal`,
});
Expand All @@ -20,7 +20,7 @@ export function fetchPublicAppsForPortal(
export function fetchPublicAppDeveloperTestAccountInstallData(
appId: number,
accountId: number
): AxiosPromise<PublicAppDeveloperTestAccountInstallData> {
): HubSpotPromise<PublicAppDeveloperTestAccountInstallData> {
return http.get<PublicAppDeveloperTestAccountInstallData>(accountId, {
url: `${APPS_DEV_API_PATH}/${appId}/test-portal-installs`,
});
Expand All @@ -29,7 +29,7 @@ export function fetchPublicAppDeveloperTestAccountInstallData(
export function fetchPublicAppProductionInstallCounts(
appId: number,
accountId: number
): AxiosPromise<PublicAppInstallCounts> {
): HubSpotPromise<PublicAppInstallCounts> {
return http.get<PublicAppInstallCounts>(accountId, {
url: `${APPS_DEV_API_PATH}/${appId}/install-counts-without-test-portals`,
});
Expand All @@ -38,7 +38,7 @@ export function fetchPublicAppProductionInstallCounts(
export function fetchPublicAppMetadata(
appId: number,
accountId: number
): AxiosPromise<PublicApp> {
): HubSpotPromise<PublicApp> {
return http.get<PublicApp>(accountId, {
url: `${APPS_DEV_API_PATH}/${appId}/full`,
});
Expand Down
14 changes: 7 additions & 7 deletions api/customObjects.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AxiosPromise } from 'axios';
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';
Expand All @@ -13,7 +13,7 @@ export function batchCreateObjects(
accountId: number,
objectTypeId: string,
objects: JSON
): AxiosPromise<CreateObjectsResponse> {
): HubSpotPromise<CreateObjectsResponse> {
return http.post<CreateObjectsResponse>(accountId, {
url: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/batch/create`,
data: objects,
Expand All @@ -23,7 +23,7 @@ export function batchCreateObjects(
export function createObjectSchema(
accountId: number,
schema: JSON
): AxiosPromise<Schema> {
): HubSpotPromise<Schema> {
return http.post<Schema>(accountId, {
url: SCHEMA_API_PATH,
data: schema,
Expand All @@ -34,7 +34,7 @@ export function updateObjectSchema(
accountId: number,
schemaObjectType: string,
schema: Schema
): AxiosPromise<Schema> {
): HubSpotPromise<Schema> {
return http.patch<Schema>(accountId, {
url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
data: schema,
Expand All @@ -44,15 +44,15 @@ export function updateObjectSchema(
export function fetchObjectSchema(
accountId: number,
schemaObjectType: string
): AxiosPromise<Schema> {
): HubSpotPromise<Schema> {
return http.get<Schema>(accountId, {
url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
});
}

export function fetchObjectSchemas(
accountId: number
): AxiosPromise<FetchSchemasResponse> {
): HubSpotPromise<FetchSchemasResponse> {
return http.get<FetchSchemasResponse>(accountId, {
url: SCHEMA_API_PATH,
});
Expand All @@ -61,7 +61,7 @@ export function fetchObjectSchemas(
export function deleteObjectSchema(
accountId: number,
schemaObjectType: string
): AxiosPromise<void> {
): HubSpotPromise<void> {
return http.delete(accountId, {
url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
});
Expand Down
7 changes: 3 additions & 4 deletions api/designManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AxiosPromise } from 'axios';
import { http } from '../http';
import { QueryParams } from '../types/Http';
import { HubSpotPromise, QueryParams } from '../types/Http';
import {
FetchThemesResponse,
FetchBuiltinMappingResponse,
Expand All @@ -11,7 +10,7 @@ const DESIGN_MANAGER_API_PATH = 'designmanager/v1';
export function fetchThemes(
accountId: number,
params: QueryParams = {}
): AxiosPromise<FetchThemesResponse> {
): HubSpotPromise<FetchThemesResponse> {
return http.get<FetchThemesResponse>(accountId, {
url: `${DESIGN_MANAGER_API_PATH}/themes/combined`,
params,
Expand All @@ -20,7 +19,7 @@ export function fetchThemes(

export function fetchBuiltinMapping(
accountId: number
): AxiosPromise<FetchBuiltinMappingResponse> {
): HubSpotPromise<FetchBuiltinMappingResponse> {
return http.get<FetchBuiltinMappingResponse>(accountId, {
url: `${DESIGN_MANAGER_API_PATH}/widgets/builtin-mapping`,
});
Expand Down
11 changes: 6 additions & 5 deletions api/developerTestAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosPromise } from 'axios';
import axios from 'axios';
import { http } from '../http';
import { getAxiosConfig } from '../http/getAxiosConfig';
import { ENVIRONMENTS } from '../constants/environments';
Expand All @@ -8,12 +8,13 @@ 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';

export function fetchDeveloperTestAccounts(
accountId: number
): AxiosPromise<FetchDeveloperTestAccountsResponse> {
): HubSpotPromise<FetchDeveloperTestAccountsResponse> {
return http.get<FetchDeveloperTestAccountsResponse>(accountId, {
url: TEST_ACCOUNTS_API_PATH,
});
Expand All @@ -22,7 +23,7 @@ export function fetchDeveloperTestAccounts(
export function createDeveloperTestAccount(
accountId: number,
accountName: string
): AxiosPromise<DeveloperTestAccount> {
): HubSpotPromise<DeveloperTestAccount> {
return http.post<DeveloperTestAccount>(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
Expand All @@ -33,7 +34,7 @@ export function createDeveloperTestAccount(
export function deleteDeveloperTestAccount(
accountId: number,
testAccountId: number
): AxiosPromise<void> {
): HubSpotPromise<void> {
return http.delete(accountId, {
url: `${TEST_ACCOUNTS_API_PATH}/${testAccountId}`,
});
Expand All @@ -43,7 +44,7 @@ export function fetchDeveloperTestAccountData(
accessToken: string,
accountId: number,
env: Environment = ENVIRONMENTS.PROD
): AxiosPromise<DeveloperTestAccount> {
): HubSpotPromise<DeveloperTestAccount> {
const axiosConfig = getAxiosConfig({
env,
url: `${TEST_ACCOUNTS_API_PATH}/self`,
Expand Down
11 changes: 5 additions & 6 deletions api/fileManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AxiosPromise } from 'axios';
import fs from 'fs';
import path from 'path';
import { http } from '../http';
import { FormData } from '../types/Http';
import { FormData, HubSpotPromise } from '../types/Http';
import {
FetchStatResponse,
FetchFilesResponse,
Expand All @@ -17,7 +16,7 @@ export function uploadFile(
accountId: number,
src: string,
dest: string
): AxiosPromise<UploadResponse> {
): HubSpotPromise<UploadResponse> {
const directory = path.dirname(dest);
const filename = path.basename(dest);
const formData: FormData = {
Expand Down Expand Up @@ -45,7 +44,7 @@ export function uploadFile(
export function fetchStat(
accountId: number,
src: string
): AxiosPromise<FetchStatResponse> {
): HubSpotPromise<FetchStatResponse> {
return http.get<FetchStatResponse>(accountId, {
url: `${FILE_MANAGER_V2_API_PATH}/files/stat/${src}`,
});
Expand All @@ -56,7 +55,7 @@ export function fetchFiles(
folderId: number | 'None',
offset: number,
archived?: boolean
): AxiosPromise<FetchFilesResponse> {
): HubSpotPromise<FetchFilesResponse> {
return http.get<FetchFilesResponse>(accountId, {
url: `${FILE_MANAGER_V2_API_PATH}/files/`,
params: {
Expand All @@ -71,7 +70,7 @@ export function fetchFiles(
export function fetchFolders(
accountId: number,
folderId: number | 'None'
): AxiosPromise<FetchFolderResponse> {
): HubSpotPromise<FetchFolderResponse> {
return http.get<FetchFolderResponse>(accountId, {
url: `${FILE_MANAGER_V2_API_PATH}/folders/`,
params: {
Expand Down
17 changes: 9 additions & 8 deletions api/fileMapper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import contentDisposition from 'content-disposition';
import { AxiosResponse, AxiosPromise } from 'axios';
import { AxiosResponse } from 'axios';
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';

Expand Down Expand Up @@ -46,7 +47,7 @@ export function upload(
src: string,
dest: string,
options: FileMapperOptions = {}
): AxiosPromise<void> {
): HubSpotPromise<void> {
return http.post<void>(accountId, {
url: `${FILE_MAPPER_API_PATH}/upload/${encodeURIComponent(dest)}`,
data: {
Expand All @@ -62,7 +63,7 @@ export function fetchModule(
accountId: number,
moduleId: number,
options: FileMapperOptions = {}
): AxiosPromise<FileTree> {
): HubSpotPromise<FileTree> {
return http.get<FileTree>(accountId, {
url: `${FILE_MAPPER_API_PATH}/modules/${moduleId}`,
...options,
Expand Down Expand Up @@ -92,7 +93,7 @@ export function download(
accountId: number,
filepath: string,
options: FileMapperOptions = {}
): AxiosPromise<FileMapperNode> {
): HubSpotPromise<FileMapperNode> {
return http.get<FileMapperNode>(accountId, {
url: `${FILE_MAPPER_API_PATH}/download/${encodeURIComponent(filepath)}`,
...options,
Expand All @@ -104,7 +105,7 @@ export function downloadDefault(
accountId: number,
filepath: string,
options: FileMapperOptions = {}
): AxiosPromise<FileMapperNode> {
): HubSpotPromise<FileMapperNode> {
return http.get<FileMapperNode>(accountId, {
url: `${FILE_MAPPER_API_PATH}/download-default/${filepath}`,
...options,
Expand All @@ -115,7 +116,7 @@ export function downloadDefault(
export function deleteFile(
accountId: number,
filePath: string
): AxiosPromise<void> {
): HubSpotPromise<void> {
return http.delete(accountId, {
url: `${FILE_MAPPER_API_PATH}/delete/${encodeURIComponent(filePath)}`,
});
Expand All @@ -126,7 +127,7 @@ export function moveFile(
accountId: number,
srcPath: string,
destPath: string
): AxiosPromise<void> {
): HubSpotPromise<void> {
return http.put(accountId, {
url: `${FILE_MAPPER_API_PATH}/rename/${srcPath}?path=${destPath}`,
headers: { 'Content-Type': 'application/json' },
Expand All @@ -137,7 +138,7 @@ export function moveFile(
export function getDirectoryContentsByPath(
accountId: number,
path: string
): AxiosPromise<FileMapperNode> {
): HubSpotPromise<FileMapperNode> {
return http.get(accountId, {
url: `${FILE_MAPPER_API_PATH}/meta/${path}`,
});
Expand Down
8 changes: 4 additions & 4 deletions api/fileTransport.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { AxiosPromise } from 'axios';
import fs from 'fs';
import path from 'path';
import { getCwd } from '../lib/path';
import { http } from '../http';
import { HubSpotPromise } from '../types/Http';
const HUBFILES_API_PATH = '/file-transport/v1/hubfiles';

export function createSchemaFromHubFile(
accountId: number,
filepath: string
): AxiosPromise {
): HubSpotPromise {
const file = fs.createReadStream(path.resolve(getCwd(), filepath));
return http.post(accountId, {
url: `${HUBFILES_API_PATH}/object-schemas`,
Expand All @@ -22,7 +22,7 @@ export function createSchemaFromHubFile(
export async function updateSchemaFromHubFile(
accountId: number,
filepath: string
): AxiosPromise {
): HubSpotPromise {
const file = fs.createReadStream(path.resolve(getCwd(), filepath));
return http.put(accountId, {
url: `${HUBFILES_API_PATH}/object-schemas`,
Expand All @@ -37,7 +37,7 @@ export async function fetchHubFileSchema(
accountId: number,
objectName: string,
path: string
): AxiosPromise {
): HubSpotPromise {
return http.getOctetStream(
accountId,
{
Expand Down
15 changes: 8 additions & 7 deletions api/functions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { AxiosPromise } from 'axios';
import { http } from '../http';
import { QueryParams } from '../types/Http';
import { HubSpotPromise, QueryParams } from '../types/Http';
import { GetBuildStatusResponse, GetRoutesResponse } from '../types/Functions';

const FUNCTION_API_PATH = 'cms/v3/functions';

export function getRoutes(accountId: number): AxiosPromise<GetRoutesResponse> {
export function getRoutes(
accountId: number
): HubSpotPromise<GetRoutesResponse> {
return http.get(accountId, {
url: `${FUNCTION_API_PATH}/routes`,
});
Expand All @@ -15,7 +16,7 @@ export function getFunctionLogs(
accountId: number,
route: string,
params: QueryParams = {}
): AxiosPromise {
): HubSpotPromise {
const { limit = 5 } = params;

return http.get(accountId, {
Expand All @@ -27,7 +28,7 @@ export function getFunctionLogs(
export function getLatestFunctionLog(
accountId: number,
route: string
): AxiosPromise {
): HubSpotPromise {
return http.get(accountId, {
url: `${FUNCTION_API_PATH}/results/by-route/${encodeURIComponent(
route
Expand All @@ -38,7 +39,7 @@ export function getLatestFunctionLog(
export function buildPackage(
accountId: number,
folderPath: string
): AxiosPromise<string> {
): HubSpotPromise<string> {
return http.post(accountId, {
url: `${FUNCTION_API_PATH}/build/async`,
headers: {
Expand All @@ -53,7 +54,7 @@ export function buildPackage(
export function getBuildStatus(
accountId: number,
buildId: number
): AxiosPromise<GetBuildStatusResponse> {
): HubSpotPromise<GetBuildStatusResponse> {
return http.get(accountId, {
url: `${FUNCTION_API_PATH}/build/${buildId}/poll`,
});
Expand Down
Loading