Skip to content

Commit

Permalink
DEVEXP-606: Update Fax SDK (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch authored Oct 11, 2024
1 parent db3c5db commit 93dc4e7
Show file tree
Hide file tree
Showing 44 changed files with 168 additions and 121 deletions.
42 changes: 21 additions & 21 deletions examples/simple-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,27 +256,27 @@ yarn run numbers:regions:list

### Fax

| Service | Sample application name and location | Required parameters |
|----------|------------------------------------------------------------------------------------------|-------------------------------------|
| Services | [./src/fax/services/create.ts](./src/fax/services/create.ts) | `PHONE_NUMBER` |
| | [./src/fax/services/get.ts](./src/fax/services/get.ts) | `FAX_SERVICE_ID` |
| | [./src/fax/services/list.ts](./src/fax/services/list.ts) | |
| | [./src/fax/services/listNumbers.ts](./src/fax/services/listNumbers.ts) | `FAX_SERVICE_ID` |
| | [./src/fax/services/listEmailsForNumber.ts](./src/fax/services/listEmailsForNumber.ts) | `PHONE_NUMBER` + `FAX_SERVICE_ID` |
| | [./src/fax/services/update.ts](./src/fax/services/update.ts) | `FAX_SERVICE_ID` |
| | [./src/fax/services/delete.ts](./src/fax/services/delete.ts) | `FAX_SERVICE_ID` |
| Faxes | [./src/fax/faxes/send-filePaths.ts](./src/fax/faxes/send-filePaths.ts) | `PHONE_NUMBER` + `FAX_CALLBACK_URL` |
| | [./src/fax/faxes/send-fileBase64.ts](./src/fax/faxes/send-fileBase64.ts) | `PHONE_NUMBER` + `FAX_CALLBACK_URL` |
| | [./src/fax/faxes/send-multipleRecipients.ts](./src/fax/faxes/send-multipleRecipients.ts) | `PHONE_NUMBER` + `FAX_CALLBACK_URL` |
| | [./src/fax/faxes/get.ts](./src/fax/faxes/get.ts) | `FAX_ID` |
| | [./src/fax/faxes/list.ts](./src/fax/faxes/list.ts) | |
| | [./src/fax/faxes/downloadContent.ts](./src/fax/faxes/downloadContent.ts) | `FAX_ID` |
| | [./src/fax/faxes/deleteContent.ts](./src/fax/faxes/deleteContent.ts) | `FAX_ID` |
| Emails | [./src/fax/emails/add.ts](./src/fax/emails/add.ts) | `FAX_EMAIL` + `PHONE_NUMBER` |
| | [./src/fax/emails/list.ts](./src/fax/emails/list.ts) | |
| | [./src/fax/emails/listNumbers.ts](./src/fax/emails/listNumbers.ts) | `FAX_EMAIL` |
| | [./src/fax/emails/update.ts](./src/fax/emails/update.ts) | `FAX_EMAIL` + `PHONE_NUMBER` |
| | [./src/fax/emails/delete.ts](./src/fax/emails/delete.ts) | `FAX_EMAIL` |
| Service | Sample application name and location | Required parameters |
|--------------|------------------------------------------------------------------------------------------|-------------------------------------|
| Services | [./src/fax/services/create.ts](./src/fax/services/create.ts) | `PHONE_NUMBER` |
| | [./src/fax/services/get.ts](./src/fax/services/get.ts) | `FAX_SERVICE_ID` |
| | [./src/fax/services/list.ts](./src/fax/services/list.ts) | |
| | [./src/fax/services/listNumbers.ts](./src/fax/services/listNumbers.ts) | `FAX_SERVICE_ID` |
| | [./src/fax/services/listEmailsForNumber.ts](./src/fax/services/listEmailsForNumber.ts) | `PHONE_NUMBER` + `FAX_SERVICE_ID` |
| | [./src/fax/services/update.ts](./src/fax/services/update.ts) | `FAX_SERVICE_ID` |
| | [./src/fax/services/delete.ts](./src/fax/services/delete.ts) | `FAX_SERVICE_ID` |
| Faxes | [./src/fax/faxes/send-filePaths.ts](./src/fax/faxes/send-filePaths.ts) | `PHONE_NUMBER` + `FAX_CALLBACK_URL` |
| | [./src/fax/faxes/send-fileBase64.ts](./src/fax/faxes/send-fileBase64.ts) | `PHONE_NUMBER` + `FAX_CALLBACK_URL` |
| | [./src/fax/faxes/send-multipleRecipients.ts](./src/fax/faxes/send-multipleRecipients.ts) | `PHONE_NUMBER` + `FAX_CALLBACK_URL` |
| | [./src/fax/faxes/get.ts](./src/fax/faxes/get.ts) | `FAX_ID` |
| | [./src/fax/faxes/list.ts](./src/fax/faxes/list.ts) | |
| | [./src/fax/faxes/downloadContent.ts](./src/fax/faxes/downloadContent.ts) | `FAX_ID` |
| | [./src/fax/faxes/deleteContent.ts](./src/fax/faxes/deleteContent.ts) | `FAX_ID` |
| Fax to email | [./src/fax/fax-to-email/add.ts](src/fax/fax-to-email/add.ts) | `FAX_EMAIL` + `PHONE_NUMBER` |
| | [./src/fax/fax-to-email/list.ts](src/fax/fax-to-email/list.ts) | |
| | [./src/fax/fax-to-email/listNumbers.ts](src/fax/fax-to-email/listNumbers.ts) | `FAX_EMAIL` |
| | [./src/fax/fax-to-email/update.ts](src/fax/fax-to-email/update.ts) | `FAX_EMAIL` + `PHONE_NUMBER` |
| | [./src/fax/fax-to-email/delete.ts](src/fax/fax-to-email/delete.ts) | `FAX_EMAIL` |

### Elastic SIP Trunk

Expand Down
10 changes: 5 additions & 5 deletions examples/simple-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@
"fax:faxes:list": "ts-node src/fax/faxes/list.ts",
"fax:faxes:download": "ts-node src/fax/faxes/downloadContent.ts",
"fax:faxes:delete": "ts-node src/fax/faxes/deleteContent.ts",
"fax:emails:add": "ts-node src/fax/emails/add.ts",
"fax:emails:list": "ts-node src/fax/emails/list.ts",
"fax:emails:listNumbers": "ts-node src/fax/emails/listNumbers.ts",
"fax:emails:update": "ts-node src/fax/emails/update.ts",
"fax:emails:delete": "ts-node src/fax/emails/delete.ts",
"fax:fax-to-email:add": "ts-node src/fax/fax-to-email/add.ts",
"fax:fax-to-email:list": "ts-node src/fax/fax-to-email/list.ts",
"fax:fax-to-email:listNumbers": "ts-node src/fax/fax-to-email/listNumbers.ts",
"fax:fax-to-email:update": "ts-node src/fax/fax-to-email/update.ts",
"fax:fax-to-email:delete": "ts-node src/fax/fax-to-email/delete.ts",
"numbers:regions:list": "ts-node src/numbers/regions/list.ts",
"numbers:available:list": "ts-node src/numbers/available/list.ts",
"numbers:available:checkAvailability": "ts-node src/numbers/available/checkAvailability.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
};

const faxService = initFaxService();
const response = await faxService.emails.addToNumbers(requestData);
const response = await faxService.faxToEmail.addToNumbers(requestData);

const printFormat = getPrintFormat(process.argv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getFaxEmailFromConfig, initFaxService } from '../../config';
};

const faxService = initFaxService();
await faxService.emails.delete(requestData);
await faxService.faxToEmail.delete(requestData);

console.log(`The email '${requestData.email}' has been successfully removed`);
})();
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const populateEmailsList = (
// ----------------------------------------------
// Method 1: Fetch the data page by page manually
// ----------------------------------------------
let response = await faxService.emails.list(requestData);
let response = await faxService.faxToEmail.list(requestData);

// Init data structure to hold the response content
const fullEmailsList: Fax.Email[] = [];
Expand Down Expand Up @@ -57,7 +57,7 @@ const populateEmailsList = (
// ---------------------------------------------------------------------
// Method 2: Use the iterator and fetch data on more pages automatically
// ---------------------------------------------------------------------
for await (const email of faxService.emails.list(requestData)) {
for await (const email of faxService.faxToEmail.list(requestData)) {
if (printFormat === 'pretty') {
console.log(`Email '${email.email}' - Phone numbers: '${email.phoneNumbers?.join(', ')}'`);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const populateServiceNumbersList = (
// ----------------------------------------------
// Method 1: Fetch the data page by page manually
// ----------------------------------------------
let response = await faxService.emails.listNumbers(requestData);
let response = await faxService.faxToEmail.listNumbers(requestData);

// Init data structure to hold the response content
const fullServiceNumbersList: Fax.ServicePhoneNumber[] = [];
Expand Down Expand Up @@ -63,7 +63,7 @@ const populateServiceNumbersList = (
// ---------------------------------------------------------------------
// Method 2: Use the iterator and fetch data on more pages automatically
// ---------------------------------------------------------------------
for await (const number of faxService.emails.listNumbers(requestData)) {
for await (const number of faxService.faxToEmail.listNumbers(requestData)) {
if (printFormat === 'pretty') {
console.log(`Phone numbers: '${number.phoneNumber}'`);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
};

const faxService = initFaxService();
const response = await faxService.emails.update(requestData);
const response = await faxService.faxToEmail.update(requestData);

const printFormat = getPrintFormat(process.argv);

Expand Down
5 changes: 1 addition & 4 deletions examples/simple-examples/src/fax/services/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import {
imageConversionMethod: 'MONOCHROME',
saveOutboundFaxDocuments: true,
saveInboundFaxDocuments: true,
emailSettings: {
pdfPassword: 'pwd',
useBodyAsCoverPage: true,
},
scanIncomingBarcodes: true,
},
};

Expand Down
4 changes: 2 additions & 2 deletions packages/fax/src/models/v3/bar-code/bar-code.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BarCodeType } from '../enums';

/**
* Sinch will scan all pages of all incoming faxes for Code-128 and DataMatrix bar codes and include this information in webhook requests and via the API.
*/
export interface BarCode {

/** The type of barcode found. */
type?: 'CODE_128' | 'DATA_MATRIX';
type?: BarCodeType;
/** The page number on which the barcode was found. */
page?: number;
/** The information of the barcode. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { DateFormat } from '@sinch/sdk-client';
* - `from: '2024-02'` will return all faxes for February 2024
*/
export interface DateRangeFilter {
/** */
/** Start of the date range */
from?: string | Date | DateFormat;
/** */
/** End of the date range */
to?: string | Date | DateFormat;
}
1 change: 0 additions & 1 deletion packages/fax/src/models/v3/email/email.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
interface EmailBase {

email?: string;
/** Numbers you want to associate with this email. */
phoneNumbers?: string[];
Expand Down
19 changes: 11 additions & 8 deletions packages/fax/src/models/v3/enums.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export type ImageConversionMethod = 'HALFTONE' | 'MONOCHROME';
export type ImageConversionMethod = 'HALFTONE' | 'MONOCHROME' | string;

export type WebhookContentType = 'multipart/form-data' | 'application/json';
export type WebhookContentType = 'multipart/form-data' | 'application/json' | string;

/**
* The direction of the fax.
*/
export type FaxDirection = 'OUTBOUND' | 'INBOUND';
export type FaxDirection = 'OUTBOUND' | 'INBOUND' | string;

/**
* The status of the fax
*/
export type FaxStatus = 'QUEUED' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILURE';
export type FaxStatus = 'QUEUED' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILURE' | string;

/**
* Type of error for the fax
Expand All @@ -21,11 +21,14 @@ export type ErrorType =
| 'FAX_ERROR'
| 'FATAL_ERROR'
| 'GENERAL_ERROR'
| 'LINE_ERROR';
| 'LINE_ERROR'
| string;

export type FaxBase64FileType = 'DOC' | 'DOCX' | 'PDF' | 'TIF' | 'JPG' | 'ODT' | 'TXT' | 'HTML' | 'PNG';
export type FaxBase64FileType = 'DOCX' | 'PDF' | 'TIF' | 'JPG' | 'TXT' | 'HTML' | 'PNG' | string;

export const validBase64FileTypes: FaxBase64FileType[]
= ['DOC', 'DOCX', 'PDF', 'TIF', 'JPG', 'ODT', 'TXT', 'HTML', 'PNG'];
= ['DOCX', 'PDF', 'TIF', 'JPG', 'TXT', 'HTML', 'PNG'];

export type FaxWebhookEvent = 'INCOMING_FAX' | 'FAX_COMPLETED';
export type FaxWebhookEvent = 'INCOMING_FAX' | 'FAX_COMPLETED' | string;

export type BarCodeType = 'CODE_128' | 'DATA_MATRIX' | string;
13 changes: 13 additions & 0 deletions packages/fax/src/models/v3/errors/call-error/call-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* There was a problem with the phone line. The call could not be placed. Many times you can just try again
*/
export interface CallError {
/** Type of error for the Call */
errorType?: 'CALL_ERROR';
/** A developer-facing error message */
errorMessage?: string;
/** The error code returned describing the error of the call */
errorCode?: CallErrorCodeEnum;
}

export type CallErrorCodeEnum = '11' | '15' | '16' | '17' | '19' | '30' | '32' | '34' | '43' | '49' | string;
1 change: 1 addition & 0 deletions packages/fax/src/models/v3/errors/call-error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { CallError, CallErrorCodeEnum } from './call-error';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Conversion errors usually occur when there is a problem with one of the files you posted.
*/
export interface DocumentConversionError {
/** Type of error for the Document conversion */
errorType?: 'DOCUMENT_CONVERSION_ERROR';
/** The error message */
errorMessage?: string;
/** The error code returned during document conversion. */
errorCode?: DocumentConversionErrorCodeEnum;
}

export type DocumentConversionErrorCodeEnum = '4' | '54' | '55' | '57' | '69' | '122'
| '128' | '129' | '130' | '133 | string';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { DocumentConversionError, DocumentConversionErrorCodeEnum } from './document-conversion-error';
16 changes: 16 additions & 0 deletions packages/fax/src/models/v3/errors/fax-error/fax-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* A problem occurred during the fax communication process.
*/
export interface FaxError {
/** Type of error for the fax */
errorType?: 'FAX_ERROR';
/** A developer-facing error message */
errorMessage?: string;
/** The error code returned describing the error of the call */
errorCode?: FaxErrorCodeEnum;
}

export type FaxErrorCodeEnum = '6' | '7' | '8' | '10' | '12' | '13' | '14' | '18'
| '20' | '21' | '22' | '25' | '26' | '28' | '29' | '31' | '38' | '40' | '41'
| '44' | '46' | '48' | '53' | '60' | '63' | '68' | '75' | '76' | '77' | '79'
| '80' | '82' | '84' | '113' | '117' | '119' | '131' | '132' | string;
1 change: 1 addition & 0 deletions packages/fax/src/models/v3/errors/fax-error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { FaxError, FaxErrorCodeEnum } from './fax-error';
3 changes: 3 additions & 0 deletions packages/fax/src/models/v3/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './call-error';
export * from './document-conversion-error';
export * from './fax-error';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FaxBase64FileType } from '../enums';

export interface FaxBase64File {

/** When application/json Base64 encoded file content, this is only present when using application/json for request/response. */
file?: string;
/** When request/response is application json and file is part of payload. This is the file type of the file. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Give us any URL on the Internet (including ones with basic authentication) At least one file or contentUrl parameter is required.
* Please note: If you are passing fax a secure URL (starting with https://), make sure that your SSL certificate (including your intermediate cert, if you have one) is installed properly, valid, and up-to-date.
Expand Down
2 changes: 0 additions & 2 deletions packages/fax/src/models/v3/fax-money/fax-money.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

/**
* This is where we need description to be overridden by `$ref:` description
*/
export interface FaxMoney {

/** The 3-letter currency code defined in ISO 4217. */
currencyCode?: string;
/** The amount with 4 decimals and decimal delimiter `.`. */
Expand Down
7 changes: 3 additions & 4 deletions packages/fax/src/models/v3/fax/fax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { FaxMoney } from '../fax-money';
import { ErrorType, FaxDirection, FaxStatus, ImageConversionMethod, WebhookContentType } from '../enums';

export interface Fax {

/** The id of a fax */
id?: string;
/** @see FaxDirection */
Expand Down Expand Up @@ -41,13 +40,13 @@ export interface Fax {
callbackUrl?: string;
/** The content type of the callback. */
callbackUrlContentType?: WebhookContentType;
/** Determines how documents are converted to black and white. Defaults to value selected on Fax Service object. */
/** Determines how documents are converted to black and white on OUTBOUND faxes only. Image conversion is not done on INBOUND faxes. Defaults to value selected on Fax Service object. */
imageConversionMethod?: ImageConversionMethod;
/** @see ErrorType */
errorType?: ErrorType;
/** One of the error numbers listed in the [Fax Error Messages section](#FaxErrors). */
/** One of the error numbers listed in the [Fax Error Messages section](https://developers.sinch.com/docs/fax/api-reference/fax/tag/Error-Messages/). */
errorCode?: number;
/** One of the error messages listed in the [Fax Error Messages section](#FaxErrors). */
/** One of the error messages listed in the [Fax Error Messages section](https://developers.sinch.com/docs/fax/api-reference/fax/tag/Error-Messages/). */
errorMessage?: string;
/** The `Id` of the project associated with the call. */
projectId?: string;
Expand Down
6 changes: 5 additions & 1 deletion packages/fax/src/models/v3/helper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { FaxBase64FileType, validBase64FileTypes } from './enums';

export const convertToSupportedFileType = (fileType: string | undefined): FaxBase64FileType | undefined => {
if (!fileType || !validBase64FileTypes.includes(fileType.toUpperCase() as FaxBase64FileType)) {
if (!fileType) {
console.warn('No file extension has been defined.');
return undefined;
}
if (!validBase64FileTypes.includes(fileType.toUpperCase() as FaxBase64FileType)) {
console.warn(`The file extension "${fileType.toUpperCase()}" is not supported.`);
}
return fileType.toUpperCase() as FaxBase64FileType;
};
2 changes: 1 addition & 1 deletion packages/fax/src/models/v3/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './bar-code';
export * from './date-range-filter';
export * from './email';
export * from './errors';
export * from './fax';
export * from './fax-base64-file';
export * from './fax-content-url';
Expand All @@ -9,7 +10,6 @@ export * from './fax-request';
export * from './faxes-list';
export * from './mod-events';
export * from './service';
export * from './service-email-settings';
export * from './service-phone-number';
export * from './update-email-request';
export * from './webhook-event-parsed';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface GetFaxRequestData {
'id': string;
}
export interface ListFaxesRequestData {
/** Limits results to faxes that were sent using the specified service. */
'serviceId'?: string;
/** Filter calls based on `createTime`. It can be a year, a month or a day. */
'createTime'?: string | Date;
/** Filter calls based on `createTime`. It will filter the faxes on a range of dates. */
Expand Down
2 changes: 1 addition & 1 deletion packages/fax/src/models/v3/requests/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './emails/emails-request-data';
export * from './fax-to-email/fax-to-email-request-data';
export * from './faxes/faxes-request-data';
export * from './services/services-request-data';
1 change: 0 additions & 1 deletion packages/fax/src/models/v3/service-email-settings/index.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

export interface ServicePhoneNumber {

/** A phone number in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format, including the leading '+'. */
phoneNumber?: string;
/** The `Id` of the project associated with the call. */
Expand Down
Loading

0 comments on commit 93dc4e7

Please sign in to comment.