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

Typings for the Number Insight API #373

Merged
merged 15 commits into from
Oct 15, 2020
Merged
Changes from 11 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
246 changes: 190 additions & 56 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* CheckResponse -> VerifyCheckResponse
*/

declare module '@vonage/server-sdk' {
sudiptog81 marked this conversation as resolved.
Show resolved Hide resolved
declare module "@vonage/server-sdk" {
/* general */
export interface CredentialsObject {
apiKey: string;
Expand All @@ -20,8 +20,8 @@ declare module '@vonage/server-sdk' {
}

export interface VonageApiError {
body: { [key: string]: any };
headers?: { [key: string]: any };
body: { [key: string]: any };
headers?: { [key: string]: any };
}

export interface ParserError {
Expand All @@ -33,80 +33,83 @@ declare module '@vonage/server-sdk' {

/* 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',
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,
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;
"error-text": string;
}

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

export interface SendSmsOptions {
from: string;
to: string;
text?: string;
sig?: string;
ttl?: number;
'status-report-req'?: boolean;
"status-report-req"?: boolean;
callback?: string;
'message-class'?: number;
"message-class"?: number;
type?: string;
vcard?: string | any;
vcal?: string | any;
body?: string;
udh?: string;
'protocol-id'?: number;
"protocol-id"?: number;
title?: string;
url?: string;
validity?: string;
'client-ref'?: string;
'account-ref'?: 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
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 });
constructor(
credentials: CredentialsObject,
options: { [key: string]: any }
);
sendSms: SendSms;

/**
Expand All @@ -119,7 +122,7 @@ declare module '@vonage/server-sdk' {
shortcodeMarketing: any;
search: any;
searchRejections: any;

__proto__: any;
[key: string]: any;
}
Expand Down Expand Up @@ -164,7 +167,7 @@ declare module '@vonage/server-sdk' {
WrongVerificationCode = "11",
TooManyRequests = "12",
NoMoreEvents = "13",
NoRequestFound = "14",
NoRequestFound = "14"
}

export interface ControlObject {
Expand All @@ -179,7 +182,7 @@ declare module '@vonage/server-sdk' {

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

export interface CheckObject {
Expand All @@ -197,14 +200,141 @@ declare module '@vonage/server-sdk' {
}

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;
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;
__proto__: any;
[key: string]: any;
}

/* number-insight API */
export interface NumberInsightError extends VonageApiError {
status: NumberInsightResponseStatusCode | number;
error_text: string;
[key: string]: any;
}

export interface NumberInsightObject {
sudiptog81 marked this conversation as resolved.
Show resolved Hide resolved
level: NumberInsightLevel;
number: string;
country?: string;
cnam?: boolean;
callback?: string;
ip?: string;
}

export interface NumberInsightResponse {
status: NumberInsightResponseStatusCode | number;
status_message: string;
request_id: string;
international_format_number: string;
national_format_number: string;
country_code: string;
country_code_iso3: string;
country_name: string;
country_prefix: string;
request_price?: string;
refund_price?: string;
remaining_balance?: string;
current_carrier?: {
network_code?: string;
name?: string;
country?: string;
network_type?: string;
};
original_carrier?: {
network_code?: string;
name?: string;
country?: string;
network_type?: string;
};
ported?: string;
roaming?: {
status?: string;
roaming_country_code?: string;
roaming_network_code?: string;
roaming_network_name?: string;
};
caller_identity?: {
caller_type?: string;
caller_name?: string;
first_name?: string;
last_name?: string;
};
caller_name?: string;
first_name?: string;
last_name?: string;
caller_type?: NumberInsightCallerType;
lookup_outcome?: NumberInsightLookupCode;
lookup_outcome_message?: string;
valid_number?: string;
reachable?: string;
error_text?: string;
}

export interface NumberInsightWebhookRequest
extends NumberInsightResponse {}

export enum NumberInsightLookupCode {
Success = 0,
PartialSuccess = 1,
Failed = 2
}

export enum NumberInsightLevel {
Basic = "basic",
Standard = "standard",
AdvancedAsync = "advancedAsync",
AdvancedSync = "advancedSync"
}

export enum NumberInsightCallerType {
Business = "business",
Consumer = "consumer",
Unknown = "unknown"
}

export enum NumberInsightResponseStatusCode {
Success = 0,
Busy = 1,
InvalidRequest = 3,
InvalidCredentials = 4,
InternalError = 5,
PartnerQuotaExceeded = 9,
FacilityNotAllowed = 19,
LiveMobileLookupNotReturned1 = 43,
LiveMobileLookupNotReturned2 = 44,
LiveMobileLookupNotReturned3 = 45,
RequestUnparseable = 999
}

export class NumberInsight {
constructor(
credentials: CredentialsObject,
options: { [key: string]: any }
);
get(
options: NumberInsightObject,
callback: (
err: NumberInsightError,
data: NumberInsightResponse
) => void
): void;
}

/* Media API */
export interface MediaSearchRequestObject {
order: string;
Expand Down Expand Up @@ -276,9 +406,13 @@ declare module '@vonage/server-sdk' {

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