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

feat: remove specific error typing from the method definitions #142

Merged
merged 4 commits into from
Jun 21, 2023
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
8 changes: 4 additions & 4 deletions src/billing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BalanceList, Balance, RequestFunction, ErrorResponse } from "./types";
import { BalanceList, Balance, RequestFunction } from "./types";

export class Billing {
constructor(
Expand All @@ -13,12 +13,12 @@ export class Billing {
* @param {string} projectId Unique identifier of the project
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<BalanceList | ErrorResponse>}
* @returns {Promise<BalanceList>}
*/
async listBalances(
projectId: string,
endpoint = "v1/projects"
): Promise<BalanceList | ErrorResponse> {
): Promise<BalanceList> {
return this._request(
"GET",
this._credentials,
Expand All @@ -40,7 +40,7 @@ export class Billing {
projectId: string,
balanceId: string,
endpoint = "v1/projects"
): Promise<Balance | ErrorResponse> {
): Promise<Balance> {
return this._request(
"GET",
this._credentials,
Expand Down
12 changes: 4 additions & 8 deletions src/invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
InvitationOptions,
InvitationList,
RequestFunction,
ErrorResponse
} from "./types";

export class Invitation {
Expand All @@ -24,7 +23,7 @@ export class Invitation {
async list(
projectId: string,
endpoint = "v1/projects"
): Promise<InvitationList | ErrorResponse> {
): Promise<InvitationList> {
return this._request(
"GET",
this._credentials,
Expand All @@ -46,7 +45,7 @@ export class Invitation {
projectId: string,
options: InvitationOptions,
endpoint = "v1/projects"
): Promise<Message | ErrorResponse> {
): Promise<Message> {
return this._request(
"POST",
this._credentials,
Expand All @@ -67,10 +66,7 @@ export class Invitation {
*
* @returns {Promise<Message>}
*/
async leave(
projectId: string,
endpoint = "v1/projects"
): Promise<Message | ErrorResponse> {
async leave(projectId: string, endpoint = "v1/projects"): Promise<Message> {
return this._request(
"DELETE",
this._credentials,
Expand All @@ -93,7 +89,7 @@ export class Invitation {
projectId: string,
email: string,
endpoint = "v1/projects"
): Promise<Message | ErrorResponse> {
): Promise<Message> {
return this._request(
"DELETE",
this._credentials,
Expand Down
8 changes: 4 additions & 4 deletions src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Key,
KeyResponseObj,
RequestFunction,
ErrorResponse
ErrorResponse,
} from "./types";

export class Keys {
Expand All @@ -25,7 +25,7 @@ export class Keys {
async list(
projectId: string,
endpoint = "v1/projects"
): Promise<KeyResponse | ErrorResponse> {
): Promise<KeyResponse> {
const response = await this._request(
"GET",
this._credentials,
Expand Down Expand Up @@ -56,7 +56,7 @@ export class Keys {
projectId: string,
keyId: string,
endpoint = "v1/projects"
): Promise<Key | ErrorResponse> {
): Promise<Key> {
return this._request(
"GET",
this._credentials,
Expand All @@ -82,7 +82,7 @@ export class Keys {
scopes: Array<string>,
options?: CreateKeyOptions,
endpoint = "v1/projects"
): Promise<Key | ErrorResponse> {
): Promise<Key> {
/** Throw an error if the user provided both expirationDate and timeToLive */
if (
options &&
Expand Down
10 changes: 5 additions & 5 deletions src/members.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MemberList, Message, RequestFunction, ErrorResponse } from "./types";
import { MemberList, Message, RequestFunction } from "./types";

export class Members {
constructor(
Expand All @@ -13,12 +13,12 @@ export class Members {
* @param {string} projectId Unique identifier of the project
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<MemberList | ErrorResponse>}
* @returns {Promise<MemberList>}
*/
async listMembers(
projectId: string,
endpoint = "v1/projects"
): Promise<MemberList | ErrorResponse> {
): Promise<MemberList> {
return this._request(
"GET",
this._credentials,
Expand All @@ -34,13 +34,13 @@ export class Members {
* @param {string} memberId Unique identifier of the member
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<Message | ErrorResponse>}
* @returns {Promise<Message>}
*/
async removeMember(
projectId: string,
memberId: string,
endpoint = "v1/projects"
): Promise<Message | ErrorResponse> {
): Promise<Message> {
return this._request(
"DELETE",
this._credentials,
Expand Down
19 changes: 7 additions & 12 deletions src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ export class Projects {
* Returns all projects accessible by the API key.
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<ProjectResponse | ErrorResponse>}
* @returns {Promise<ProjectResponse>}
*/

async list(
endpoint = "v1/projects"
): Promise<ProjectResponse | ErrorResponse> {
async list(endpoint = "v1/projects"): Promise<ProjectResponse> {
return this._request(
"GET",
this._credentials,
Expand All @@ -39,12 +37,9 @@ export class Projects {
* @param {string} projectId Unique identifier of the project
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<Project | ErrorResponse>}
* @returns {Promise<Project>}
*/
async get(
projectId: string,
endpoint = "v1/projects"
): Promise<Project | ErrorResponse> {
async get(projectId: string, endpoint = "v1/projects"): Promise<Project> {
return this._request(
"GET",
this._credentials,
Expand All @@ -60,13 +55,13 @@ export class Projects {
* @param {ProjectPatchRequest} payload Details to change as an object
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<ProjectPatchResponse | ErrorResponse>}
* @returns {Promise<ProjectPatchResponse>}
*/
async update(
project: string | Project,
payload: ProjectPatchRequest,
endpoint = "v1/projects"
): Promise<ProjectPatchResponse | ErrorResponse> {
): Promise<ProjectPatchResponse> {
const projectObj = project as Project;
let projectId = project as string;

Expand All @@ -89,7 +84,7 @@ export class Projects {
* @param {string} projectId Unique identifier of the project
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<Message | ErrorResponse>}
* @returns {Promise<void | ErrorResponse>}
*/
async delete(
projectId: string,
Expand Down
10 changes: 5 additions & 5 deletions src/scopes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScopeList, Message, RequestFunction, ErrorResponse } from "./types";
import { ScopeList, Message, RequestFunction } from "./types";

export class Scopes {
constructor(
Expand All @@ -14,13 +14,13 @@ export class Scopes {
* @param {string} memberId Unique identifier of the member
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<ScopeList | ErrorResponse>}
* @returns {Promise<ScopeList>}
*/
async get(
projectId: string,
memberId: string,
endpoint = "v1/projects"
): Promise<ScopeList | ErrorResponse> {
): Promise<ScopeList> {
return this._request(
"GET",
this._credentials,
Expand All @@ -37,14 +37,14 @@ export class Scopes {
* @param {string} scope Scope to update the member to
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<Message | ErrorResponse>}
* @returns {Promise<Message>}
*/
async update(
projectID: string,
memberId: string,
scope: string,
endpoint = "v1/projects"
): Promise<Message | ErrorResponse> {
): Promise<Message> {
return this._request(
"PUT",
this._credentials,
Expand Down
10 changes: 5 additions & 5 deletions src/transcription/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PrerecordedTranscriptionOptions,
PrerecordedTranscriptionResponse,
TranscriptionSource,
ErrorResponse
ErrorResponse,

Check warning on line 6 in src/transcription/index.ts

View workflow job for this annotation

GitHub Actions / build

'ErrorResponse' is defined but never used
} from "../types";
import { LiveTranscription } from "./liveTranscription";
import { preRecordedTranscription } from "./preRecordedTranscription";
Expand All @@ -21,13 +21,13 @@
* @param {PrerecordedTranscriptionOptions} options Options used to toggle transcription features
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<PrerecordedTranscriptionResponse | ErrorResponse>}
* @returns {Promise<PrerecordedTranscriptionResponse>}
*/
async preRecorded(
source: TranscriptionSource,
options?: PrerecordedTranscriptionOptions,
endpoint?: string
): Promise<PrerecordedTranscriptionResponse | ErrorResponse> {
): Promise<PrerecordedTranscriptionResponse> {
return await preRecordedTranscription(
this._credentials,
this._apiUrl || "",
Expand All @@ -43,12 +43,12 @@
* @param {LiveTranscriptionOptions} options Options used to toggle transcription features
* @param {string} endpoint Custom API endpoint
*
* @returns {LiveTranscription | ErrorResponse}
* @returns {LiveTranscription}
*/
live(
options?: LiveTranscriptionOptions,
endpoint?: string
): LiveTranscription | ErrorResponse {
): LiveTranscription {
return new LiveTranscription(
this._credentials,
this._apiUrl || "",
Expand Down
2 changes: 2 additions & 0 deletions src/types/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export type Balance = {
amount: number;
units: string;
purchase: string;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/balanceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import { Balance } from "./balance";

export type BalanceList = {
balances?: Array<Balance>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/invitationList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import { InvitationOptions } from "./invitationOptions";

export type InvitationList = {
invites?: Array<InvitationOptions>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ export type Key = {
* Array of scopes assigned to the key
*/
scopes: Array<string>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/keyResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export type KeyResponse = {
* Array of API keys associated with the project
*/
api_keys: Array<KeyResponseObj>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/memberList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import { Member } from "./member";

export type MemberList = {
members?: Array<Member>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/message.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type Message = {
message?: string;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/prerecordedTranscriptionResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import { WordBase } from "./wordBase";

export class PrerecordedTranscriptionResponse {
err_code?: string;
err_msg?: string;
request_id?: string;
metadata?: Metadata;
results?: {
Expand Down Expand Up @@ -35,8 +37,8 @@
lines.push(`Channels: ${this.metadata?.channels}`);
lines.push("");

const chunk = (arr: any[], length: number) => {

Check warning on line 40 in src/types/prerecordedTranscriptionResponse.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
const res: any[] = [];

Check warning on line 41 in src/types/prerecordedTranscriptionResponse.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

for (let i = 0; i < arr.length; i += length) {
const chunkarr = arr.slice(i, i + length);
Expand Down Expand Up @@ -89,8 +91,8 @@

const lines: string[] = [];

const chunk = (arr: any[], length: number) => {

Check warning on line 94 in src/types/prerecordedTranscriptionResponse.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
const res: any[] = [];

Check warning on line 95 in src/types/prerecordedTranscriptionResponse.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

for (let i = 0; i < arr.length; i += length) {
const chunkarr = arr.slice(i, i + length);
Expand Down
2 changes: 2 additions & 0 deletions src/types/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export type Project = {
* Name of the company associated with the project. Optional.
*/
company?: string;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/projectPatchResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export type ProjectPatchResponse = {
* Success message.
*/
message: string;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/projectResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import { Project } from "./project";

export type ProjectResponse = {
projects: Array<Project>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/scopeList.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type ScopeList = {
scopes: Array<string>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/usageField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export type UsageField = {
processing_methods: Array<string>;
languages: Array<string>;
features: Array<string>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/usageRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export type UsageRequest = {
accessor: string;
response?: UsageRequestDetail | UsageRequestMessage;
callback?: UsageCallback;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/usageRequestList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export type UsageRequestList = {
page: number;
limit: number;
requests?: Array<UsageRequest>;
err_code?: string;
err_msg?: string;
};
2 changes: 2 additions & 0 deletions src/types/usageResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export type UsageResponse = {
amount: number;
};
results: Array<UsageResponseDetail>;
err_code?: string;
err_msg?: string;
};
Loading
Loading