Skip to content

Commit

Permalink
add some typing for message api
Browse files Browse the repository at this point in the history
  • Loading branch information
jin60641 committed Mar 2, 2020
1 parent d250bef commit ca86088
Showing 1 changed file with 108 additions and 13 deletions.
121 changes: 108 additions & 13 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,107 @@ declare module 'nexmo' {
parseError: Error;
}

/* message API */
export enum MessageRequestResponseStatusCode {
Success = 0,
Throttled = 1,
MissingParameters = 2,
InvalidParameters = 3,
InvalidCredentials = 4,
InternalError = 5,
InvalidMessage = 6,
NumberBarred = 7,
PartnerAccountBarred = 8,
PartnerQuotaViolation = 9,
TooManyExistingBinds = 10,
AccountNotEnabledForHTTP = 11,
MessageTooLong = 12,
InvalidSignature = 14,
InvalidSenderAddress = 15,
InvalidNetworkCode = 22,
InvalidCallbackURL = 23,
NonWhitelistedDestination = 29,
SignatureAndAPISecretDisallowed = 32,
NumberDeActivated = 33,
}

export interface MessageRequestResponseSuccess {
to: string,
'message-id': string,
status: MessageRequestResponseStatusCode,
'remaining-balance': string,
'message-price': string,
'network': string,
'account-ref': string,
}

export interface MessageError {
status: MessageRequestResponseStatusCode;
error_text: string;
}

export interface MessageRequestResponse {
'message-count': number;
messages: (MessageRequestResponseSuccess | MessageError)[];
}

export interface SendSmsOptions {
from: string;
to: string;
text?: string;
sig?: string;
ttl?: number;
'status-report-req'?: boolean;
callback?: string;
'message-class'?: number;
type?: string;
vcard?: string | any;
vcal?: string | any;
body?: string;
udh?: string;
'protocol-id'?: number;
title?: string;
url?: string;
validity?: string;
'client-ref'?: string;
'account-ref'?: string;
}

export type SendSms = (
sender: string,
recipient: string,
message: string,
opts: Partial<SendSmsOptions>,
callback: (err: MessageError, data: MessageRequestResponse) => void
) => void;

export class Message {
constructor(credentials: CredentialsObject, options: { [key: string]: any });
sendSms: SendSms;

/**
* TODO: typing
*/
sendBinaryMessage: any;
sendWapPushMessage: any;
shortcodeAlert: any;
shortcode2FA: any;
shortcodeMarketing: any;
search: any;
searchRejections: any;

__proto__: any;
[key: string]: any;
}

/* verify API */
export interface VerifyError extends NexmoApiError {
status: RequestResponseStatusCode | ControlResponseStatusCode | string;
status: VerifyRequestResponseStatusCode | VerifyControlResponseStatusCode | string;
error_text: string;
[key: string]: any;
}

export interface RequestObject {
export interface VerifyRequestObject {
brand: string;
number: string;
sender_id?: string;
Expand All @@ -39,12 +132,12 @@ declare module 'nexmo' {
workflow_id?: number;
}

export interface RequestResponse {
export interface VerifyRequestResponse {
request_id: string;
status: string;
}

export enum RequestResponseStatusCode {
export enum VerifyRequestResponseStatusCode {
Success = "0",
Throttled = "1",
MissingParameters = "2",
Expand All @@ -62,28 +155,28 @@ declare module 'nexmo' {
NoRequestFound = "14",
}

export interface ControlObject {
export interface VerifyControlObject {
request_id: string;
cmd: string;
}

export interface ControlResponse {
export interface VerifyControlResponse {
status: string;
command: string;
}

export enum ControlResponseStatusCode {
export enum VerifyControlResponseStatusCode {
Success = "0",
CancelOrTriggerNextEvent = "19",
}

export interface CheckObject {
export interface VerifyCheckObject {
request_id: string;
code: string;
ip_address?: string;
}

export interface CheckResponse {
export interface VerifyCheckResponse {
request_id: string;
event_id: string;
status: string;
Expand All @@ -93,16 +186,18 @@ declare module 'nexmo' {

export class Verify {
constructor(credentials: CredentialsObject, options: { [key: string]: any });
request(request: RequestObject, callback: (err: VerifyError, data: RequestResponse) => void): void;
control(request: ControlObject, callback: (err: VerifyError, data: ControlResponse) => void): void;
check(request: CheckObject, callback: (err: VerifyError, data: CheckResponse) => void): void;
request(request: VerifyRequestObject, callback: (err: VerifyError, data: VerifyRequestResponse) => void): void;
control(request: VerifyControlObject, callback: (err: VerifyError, data: VerifyControlResponse) => void): void;
check(request: VerifyCheckObject, callback: (err: VerifyError, data: VerifyCheckResponse) => void): void;
__proto__: any;
[key: string]: any;
}


/* Nexmo */
export default class Nexmo {
constructor(credentials: CredentialsObject, options?: { [key: string]: any });
public readonly verify: Verify;
}
public readonly message: Message;
}
}

0 comments on commit ca86088

Please sign in to comment.