Skip to content

Commit

Permalink
docs(sms): adding doc blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck committed Nov 21, 2023
1 parent d069e28 commit a5a0ad4
Show file tree
Hide file tree
Showing 43 changed files with 996 additions and 262 deletions.
16 changes: 15 additions & 1 deletion packages/sms/lib/classes/Error/MessageSendAllFailure.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { SMSMessages } from '../../interfaces';
import { SMSMessages } from '../../types';
import { SMSFailure } from './SMSFailure';

/**
* Class representing a failure when sending all SMS messages.
*
* Extends the SMSFailure class and is used to indicate that all SMS messages failed to send.
*
* @class
* @extends {SMSFailure}
*/
export class MessageSendAllFailure extends SMSFailure {
/**
* Creates an instance of MessageSendAllFailure.
*
* @constructor
* @param {SMSMessages} response - The response containing details about the failed SMS messages.
*/
constructor(response: SMSMessages) {
super('All SMS messages failed to send', response);
}
Expand Down
16 changes: 15 additions & 1 deletion packages/sms/lib/classes/Error/MessageSendPartialFailure.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { SMSMessages } from '../../interfaces';
import { SMSMessages } from '../../types';
import { SMSFailure } from './SMSFailure';

/**
* Class representing a partial failure when sending SMS messages.
*
* Extends the SMSFailure class and is used to indicate that some SMS messages failed to send.
*
* @class
* @extends {SMSFailure}
*/
export class MessageSendPartialFailure extends SMSFailure {
/**
* Creates an instance of MessageSendPartialFailure.
*
* @constructor
* @param {SMSMessages} response - The response containing details about the partially failed SMS messages.
*/
constructor(response: SMSMessages) {
super('Some SMS messages failed to send', response);
}
Expand Down
41 changes: 40 additions & 1 deletion packages/sms/lib/classes/Error/SMSFailure.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,67 @@
import { SMSStatus } from '../../enums';
import { SMSMessages, ErrorMessage, Message } from '../../interfaces/index';
import { SMSMessages, ErrorMessage, Message } from '../../types';

/**
* Class representing a failure response when sending SMS messages.
*
* Extends the built-in Error class and provides methods for accessing and handling failed SMS messages.
*
* @class
* @extends {Error}
*/
export class SMSFailure extends Error {
/**
* The response containing details about the SMS messages.
* @protected
*/
protected response: SMSMessages;

/**
* Creates an instance of SMSFailure.
*
* @constructor
* @param {string} message - The error message.
* @param {SMSMessages} response - The response containing details about the SMS messages.
*/
constructor(message: string, response: SMSMessages) {
super(message);
this.response = response;
}

/**
* Retrieves an array of all messages in the response.
*
* @return {Array<ErrorMessage & Message>} An array of all messages in the response.
*/
public getMessages(): Array<ErrorMessage & Message> {
return (this.response.messages as Array<ErrorMessage & Message>) || [];
}

/**
* Retrieves an array of failed messages in the response.
*
* @return {Array<ErrorMessage>} An array of failed messages in the response.
*/
public getFailedMessages(): Array<ErrorMessage> {
return this.getMessages().filter(
({ status }: ErrorMessage) => status !== SMSStatus.SUCCESS,
);
}

/**
* Retrieves the original response containing details about the SMS messages.
*
* @return {SMSMessages} The original response containing details about the SMS messages.
*/
public getResponse(): SMSMessages {
return this.response;
}

/**
* Retrieves an array of successfully sent messages in the response.
*
* @return {Array<Message>} An array of successfully sent messages in the response.
*/
public getSuccessfulMessages(): Array<Message> {
return this.getMessages().filter(
({ status }: Message) => status === SMSStatus.SUCCESS,
Expand Down
24 changes: 24 additions & 0 deletions packages/sms/lib/enums/CollectionFormats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
/**
* Collection Formats for API Parameter Serialization.
*
* Defines various collection formats used for serializing API parameters.
*
* @constant
* @enum {string}
* @readonly
*/
export const COLLECTION_FORMATS = {
/**
* Comma-separated values collection format.
*/
csv: ',',

/**
* Space-separated values collection format.
*/
ssv: ' ',

/**
* Tab-separated values collection format.
*/
tsv: '\t',

/**
* Pipe-separated values collection format.
*/
pipes: '|',
};
31 changes: 27 additions & 4 deletions packages/sms/lib/enums/MessageClassEnum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
/**
* Enumeration representing the possible message classes.
*
* Defines different message classes that can be associated with SMS messages.
*
* @enum {number}
* @readonly
*/
export enum MessageClassEnum {
NUMBER_0 = 0,
NUMBER_1 = 1,
NUMBER_2 = 2,
NUMBER_3 = 3,
/**
* Class 0: Flash SMS.
*/
NUMBER_0 = 0,

/**
* Class 1: Immediate display (user should be able to read the message instantly).
*/
NUMBER_1 = 1,

/**
* Class 2: Mobile equipment-to-mobile equipment (ME-to-ME) communication.
*/
NUMBER_2 = 2,

/**
* Class 3: SIM card-based storage.
*/
NUMBER_3 = 3,
}
132 changes: 111 additions & 21 deletions packages/sms/lib/enums/SMSErrors.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,112 @@
export enum SMSStatus {
SUCCESS = '0',
THROTTLED = '1',
MISSING_REQUIRED_PARAM = '2',
INVALID_PARAM = '3',
INVALID_CREDENTIALS = '4',
INTERNAL_ERROR = '5',
INVALID_MESSAGE = '6',
BARRED_NUMBER = '7',
PARTNER_ACCOUNT_BARRED = '7',
PARTNER_QUOTA_violation = '9',
TOO_MANY_EXISTING_BINDS = '10',
ACCOUNT_NOT_ENABLED = '11',
MESSAGE_TOO_LONG = '12',
INVALID_SIGNATURE = '14',
INVALID_SENDER_ADDRESS = '15',
INVALID_NETWORK_CODE = '22',
INVALID_CALLBACK_URL = '23',
NON_WHITELISTED_DESTINATION = '29',
SIGNATURE_AND_API_SECRET_DISALLOWED = '32',
NUMBER_DEACTIVATED = '33',
/**
* Enumeration representing possible SMS status codes.
*
* Defines different status codes that can be associated with SMS messages.
*
* @remarks This matches SMSStatus. Since Enums can't be joined, this is here
* to help check valid statuses
*
* @enum {string}
* @readonly
*/
export enum SMSErrors {
/**
* Success: The message was sent successfully.
*/
SUCCESS = '0',

/**
* Throttled: Sending SMS faster than the account limit.
*/
THROTTLED = '1',

/**
* Missing Required Parameter: One or more required parameters are missing.
*/
MISSING_REQUIRED_PARAM = '2',

/**
* Invalid Parameter: The value of one or more parameters is invalid.
*/
INVALID_PARAM = '3',

/**
* Invalid Credentials: API key and/or secret are incorrect, invalid, or disabled.
*/
INVALID_CREDENTIALS = '4',

/**
* Internal Error: An error occurred while processing the message.
*/
INTERNAL_ERROR = '5',

/**
* Invalid Message: The platform was unable to process the message.
*/
INVALID_MESSAGE = '6',

/**
* Barred Number: The number you're trying to send messages to is blacklisted.
*/
BARRED_NUMBER = '7',

/**
* Partner Account Barred: Your Vonage account has been suspended.
*/
PARTNER_ACCOUNT_BARRED = '7',

/**
* Partner Quota Violation: Insufficient credit to send the message.
*/
PARTNER_QUOTA_VIOLATION = '9',

/**
* Too Many Existing Binds: Number of simultaneous connections exceeds account allocation.
*/
TOO_MANY_EXISTING_BINDS = '10',

/**
* Account Not Enabled For HTTP: Account is not provisioned for the SMS API.
*/
ACCOUNT_NOT_ENABLED = '11',

/**
* Message Too Long: Message length exceeds the maximum allowed.
*/
MESSAGE_TOO_LONG = '12',

/**
* Invalid Signature: The supplied signature could not be verified.
*/
INVALID_SIGNATURE = '14',

/**
* Invalid Sender Address: Using a non-authorized sender ID in the 'from' field.
*/
INVALID_SENDER_ADDRESS = '15',

/**
* Invalid Network Code: Network code is unrecognized or doesn't match the destination.
*/
INVALID_NETWORK_CODE = '22',

/**
* Invalid Callback URL: Callback URL is too long or contains illegal characters.
*/
INVALID_CALLBACK_URL = '23',

/**
* Non-Whitelisted Destination: Vonage account is in demo mode and requires whitelisted numbers.
*/
NON_WHITELISTED_DESTINATION = '29',

/**
* Signature And API Secret Disallowed: A signed request may not present an API secret.
*/
SIGNATURE_AND_API_SECRET_DISALLOWED = '32',

/**
* Number Deactivated: The number you're trying to send messages to is deactivated.
*/
NUMBER_DEACTIVATED = '33',
}
Loading

0 comments on commit a5a0ad4

Please sign in to comment.