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

Expose axios response #167

Merged
merged 18 commits into from
Jul 30, 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
15 changes: 7 additions & 8 deletions api/appsDev.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosPromise } from 'axios';
import { http } from '../http';
import {
PublicApp,
Expand All @@ -11,20 +12,18 @@ type FetchPublicAppsForPortalResponse = {
results: Array<PublicApp>;
};

export async function fetchPublicAppsForPortal(
export function fetchPublicAppsForPortal(
accountId: number
): Promise<Array<PublicApp>> {
const resp = await http.get<FetchPublicAppsForPortalResponse>(accountId, {
): AxiosPromise<FetchPublicAppsForPortalResponse> {
return http.get<FetchPublicAppsForPortalResponse>(accountId, {
url: `${APPS_DEV_API_PATH}/full/portal`,
});

return resp ? resp.results : [];
}

export function fetchPublicAppDeveloperTestAccountInstallData(
appId: number,
accountId: number
): Promise<PublicAppDeveloperTestAccountInstallData> {
): AxiosPromise<PublicAppDeveloperTestAccountInstallData> {
return http.get<PublicAppDeveloperTestAccountInstallData>(accountId, {
url: `${APPS_DEV_API_PATH}/${appId}/test-portal-installs`,
});
Expand All @@ -33,7 +32,7 @@ export function fetchPublicAppDeveloperTestAccountInstallData(
export function fetchPublicAppProductionInstallCounts(
appId: number,
accountId: number
): Promise<PublicApInstallCounts> {
): AxiosPromise<PublicApInstallCounts> {
return http.get<PublicApInstallCounts>(accountId, {
url: `${APPS_DEV_API_PATH}/${appId}/install-counts-without-test-portals`,
});
Expand All @@ -42,7 +41,7 @@ export function fetchPublicAppProductionInstallCounts(
export function fetchPublicAppMetadata(
appId: number,
accountId: number
): Promise<PublicApp> {
): AxiosPromise<PublicApp> {
return http.get<PublicApp>(accountId, {
url: `${APPS_DEV_API_PATH}/${appId}/full`,
});
Expand Down
33 changes: 17 additions & 16 deletions api/customObjects.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosPromise } from 'axios';
import { http } from '../http';
import { FetchSchemasResponse, Schema } from '../types/Schemas';

Expand All @@ -18,59 +19,59 @@ type CreateObjectsResponse = {
}>;
};

export async function batchCreateObjects(
export function batchCreateObjects(
accountId: number,
objectTypeId: string,
objects: JSON
): Promise<CreateObjectsResponse> {
): AxiosPromise<CreateObjectsResponse> {
return http.post<CreateObjectsResponse>(accountId, {
url: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/batch/create`,
data: objects,
});
}

export async function createObjectSchema(
export function createObjectSchema(
accountId: number,
schema: JSON
): Promise<Schema> {
return http.post(accountId, {
): AxiosPromise<Schema> {
return http.post<Schema>(accountId, {
url: SCHEMA_API_PATH,
data: schema,
});
}

export async function updateObjectSchema(
export function updateObjectSchema(
accountId: number,
schemaObjectType: string,
schema: Schema
): Promise<Schema> {
return http.patch(accountId, {
): AxiosPromise<Schema> {
return http.patch<Schema>(accountId, {
url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
data: schema,
});
}

export async function fetchObjectSchema(
export function fetchObjectSchema(
accountId: number,
schemaObjectType: string
): Promise<Schema> {
return http.get(accountId, {
): AxiosPromise<Schema> {
return http.get<Schema>(accountId, {
url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
});
}

export async function fetchObjectSchemas(
export function fetchObjectSchemas(
accountId: number
): Promise<FetchSchemasResponse> {
return http.get(accountId, {
): AxiosPromise<FetchSchemasResponse> {
return http.get<FetchSchemasResponse>(accountId, {
url: SCHEMA_API_PATH,
});
}

export async function deleteObjectSchema(
export function deleteObjectSchema(
accountId: number,
schemaObjectType: string
): Promise<void> {
): AxiosPromise<void> {
return http.delete(accountId, {
url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
});
Expand Down
9 changes: 5 additions & 4 deletions api/designManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosPromise } from 'axios';
import { http } from '../http';
import { QueryParams } from '../types/Http';

Expand All @@ -11,10 +12,10 @@ type FetchThemesResponse = {
}>;
};

export async function fetchThemes(
export function fetchThemes(
accountId: number,
params: QueryParams = {}
): Promise<FetchThemesResponse> {
): AxiosPromise<FetchThemesResponse> {
return http.get<FetchThemesResponse>(accountId, {
url: `${DESIGN_MANAGER_API_PATH}/themes/combined`,
params,
Expand All @@ -25,9 +26,9 @@ type FetchBuiltinMappingResponse = {
[key: string]: string;
};

export async function fetchBuiltinMapping(
export function fetchBuiltinMapping(
accountId: number
): Promise<FetchBuiltinMappingResponse> {
): AxiosPromise<FetchBuiltinMappingResponse> {
return http.get<FetchBuiltinMappingResponse>(accountId, {
url: `${DESIGN_MANAGER_API_PATH}/widgets/builtin-mapping`,
});
Expand Down
26 changes: 12 additions & 14 deletions api/developerTestAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import axios, { AxiosPromise } from 'axios';
import { http } from '../http';
import { getAxiosConfig } from '../http/getAxiosConfig';
import { ENVIRONMENTS } from '../constants/environments';
Expand All @@ -11,39 +11,39 @@ import { Environment } from '../types/Config';

const TEST_ACCOUNTS_API_PATH = 'integrators/test-portals/v2';

export async function fetchDeveloperTestAccounts(
export function fetchDeveloperTestAccounts(
accountId: number
): Promise<FetchDeveloperTestAccountsResponse> {
return http.get(accountId, {
): AxiosPromise<FetchDeveloperTestAccountsResponse> {
return http.get<FetchDeveloperTestAccountsResponse>(accountId, {
url: TEST_ACCOUNTS_API_PATH,
});
}

export async function createDeveloperTestAccount(
export function createDeveloperTestAccount(
accountId: number,
accountName: string
): Promise<DeveloperTestAccount> {
return http.post(accountId, {
): AxiosPromise<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
timeout: SANDBOX_TIMEOUT,
});
}

export async function deleteDeveloperTestAccount(
export function deleteDeveloperTestAccount(
accountId: number,
testAccountId: number
): Promise<void> {
): AxiosPromise<void> {
return http.delete(accountId, {
url: `${TEST_ACCOUNTS_API_PATH}/${testAccountId}`,
});
}

export async function fetchDeveloperTestAccountData(
export function fetchDeveloperTestAccountData(
accessToken: string,
accountId: number,
env: Environment = ENVIRONMENTS.PROD
): Promise<DeveloperTestAccount> {
): AxiosPromise<DeveloperTestAccount> {
const axiosConfig = getAxiosConfig({
env,
url: `${TEST_ACCOUNTS_API_PATH}/self`,
Expand All @@ -57,7 +57,5 @@ export async function fetchDeveloperTestAccountData(
},
};

const { data } = await axios<DeveloperTestAccount>(reqWithToken);

return data;
return axios<DeveloperTestAccount>(reqWithToken);
}
25 changes: 13 additions & 12 deletions api/fileManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosPromise } from 'axios';
import fs from 'fs';
import path from 'path';
import { http } from '../http';
Expand All @@ -12,11 +13,11 @@ import {
const FILE_MANAGER_V2_API_PATH = 'filemanager/api/v2';
const FILE_MANAGER_V3_API_PATH = 'filemanager/api/v3';

export async function uploadFile(
export function uploadFile(
accountId: number,
src: string,
dest: string
): Promise<UploadResponse> {
): AxiosPromise<UploadResponse> {
const directory = path.dirname(dest);
const filename = path.basename(dest);
const formData: FormData = {
Expand All @@ -34,29 +35,29 @@ export async function uploadFile(
formData.folderPath = '/';
}

return http.post(accountId, {
return http.post<UploadResponse>(accountId, {
url: `${FILE_MANAGER_V3_API_PATH}/files/upload`,
data: formData,
headers: { 'Content-Type': 'multipart/form-data' },
});
}

export async function fetchStat(
export function fetchStat(
accountId: number,
src: string
): Promise<FetchStatResponse> {
return http.get(accountId, {
): AxiosPromise<FetchStatResponse> {
return http.get<FetchStatResponse>(accountId, {
url: `${FILE_MANAGER_V2_API_PATH}/files/stat/${src}`,
});
}

export async function fetchFiles(
export function fetchFiles(
accountId: number,
folderId: number | 'None',
offset: number,
archived?: boolean
): Promise<FetchFilesResponse> {
return http.get(accountId, {
): AxiosPromise<FetchFilesResponse> {
return http.get<FetchFilesResponse>(accountId, {
url: `${FILE_MANAGER_V2_API_PATH}/files/`,
params: {
hidden: 0,
Expand All @@ -67,11 +68,11 @@ export async function fetchFiles(
});
}

export async function fetchFolders(
export function fetchFolders(
accountId: number,
folderId: number | 'None'
): Promise<FetchFolderResponse> {
return http.get(accountId, {
): AxiosPromise<FetchFolderResponse> {
return http.get<FetchFolderResponse>(accountId, {
url: `${FILE_MANAGER_V2_API_PATH}/folders/`,
params: {
hidden: 0,
Expand Down
30 changes: 15 additions & 15 deletions api/fileMapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import contentDisposition from 'content-disposition';
import { AxiosResponse } from 'axios';
import { AxiosResponse, AxiosPromise } from 'axios';
import { http } from '../http';
import { getCwd } from '../lib/path';
import { FileMapperNode, FileMapperOptions, FileTree } from '../types/Files';
Expand Down Expand Up @@ -41,12 +41,12 @@ export function createFileMapperNodeFromStreamResponse(
};
}

export async function upload(
export function upload(
accountId: number,
src: string,
dest: string,
options: FileMapperOptions = {}
): Promise<void> {
): AxiosPromise<void> {
return http.post<void>(accountId, {
url: `${FILE_MAPPER_API_PATH}/upload/${encodeURIComponent(dest)}`,
data: {
Expand All @@ -58,11 +58,11 @@ export async function upload(
}

// Fetch a module by moduleId
export async function fetchModule(
export function fetchModule(
accountId: number,
moduleId: number,
options: FileMapperOptions = {}
): Promise<FileTree> {
): AxiosPromise<FileTree> {
return http.get<FileTree>(accountId, {
url: `${FILE_MAPPER_API_PATH}/modules/${moduleId}`,
...options,
Expand All @@ -88,56 +88,56 @@ export async function fetchFileStream(
}

// Fetch a folder or file node by path.
export async function download(
export function download(
accountId: number,
filepath: string,
options: FileMapperOptions = {}
): Promise<FileMapperNode> {
): AxiosPromise<FileMapperNode> {
return http.get<FileMapperNode>(accountId, {
url: `${FILE_MAPPER_API_PATH}/download/${encodeURIComponent(filepath)}`,
...options,
});
}

// Fetch a folder or file node by path.
export async function downloadDefault(
export function downloadDefault(
accountId: number,
filepath: string,
options: FileMapperOptions = {}
): Promise<FileMapperNode> {
): AxiosPromise<FileMapperNode> {
return http.get<FileMapperNode>(accountId, {
url: `${FILE_MAPPER_API_PATH}/download-default/${filepath}`,
...options,
});
}

// Delete a file or folder by path
export async function deleteFile(
export function deleteFile(
accountId: number,
filePath: string
): Promise<void> {
): AxiosPromise<void> {
return http.delete(accountId, {
url: `${FILE_MAPPER_API_PATH}/delete/${encodeURIComponent(filePath)}`,
});
}

// Moves file from srcPath to destPath
export async function moveFile(
export function moveFile(
accountId: number,
srcPath: string,
destPath: string
): Promise<void> {
): AxiosPromise<void> {
return http.put(accountId, {
url: `${FILE_MAPPER_API_PATH}/rename/${srcPath}?path=${destPath}`,
headers: { 'Content-Type': 'application/json' },
});
}

// Get directory contents
export async function getDirectoryContentsByPath(
export function getDirectoryContentsByPath(
accountId: number,
path: string
): Promise<FileMapperNode> {
): AxiosPromise<FileMapperNode> {
return http.get(accountId, {
url: `${FILE_MAPPER_API_PATH}/meta/${path}`,
});
Expand Down
Loading