UNPKG

aspose-barcode-cloud-node

Version:
1 lines 84.2 kB
{"version":3,"sources":["../src/httpClient.ts","../src/multipart.ts","../src/models.ts","../src/api.ts","../src/JWTAuth.ts","../src/Configuration.ts"],"sourcesContent":["import http from 'http';\nimport https from 'https';\nimport { ApiErrorResponse } from './models';\n\nexport interface StringKeyWithStringValue {\n [key: string]: string;\n}\n\nexport interface HttpOptions {\n uri: string;\n body?: any;\n encoding?: BufferEncoding | null;\n form?: StringKeyWithStringValue;\n headers?: StringKeyWithStringValue;\n json?: boolean;\n method?: string;\n qs?: StringKeyWithStringValue;\n}\n\nexport interface HttpResponse {\n statusCode: number;\n statusMessage: string;\n headers: NodeJS.Dict<string | string[]>;\n body: any;\n}\n\nexport interface HttpResult {\n response: HttpResponse;\n body: any;\n}\n\nexport interface HttpRejectType {\n response: HttpResponse | null;\n errorResponse: ApiErrorResponse | null;\n error: Error;\n}\n\nexport class HttpClient {\n public requestAsync(options: HttpOptions): Promise<HttpResult> {\n const url: URL = options.qs\n ? new URL(`?${new URLSearchParams(options.qs).toString()}`, options.uri)\n : new URL(options.uri);\n\n const requestBody = this.buildRequestBody(options);\n\n const requestOptions: http.RequestOptions = {\n method: options.method,\n headers: options.headers,\n };\n\n const responseEncoding: BufferEncoding | null = options.encoding === null ? null : options.encoding || 'utf-8';\n\n return this.doHttpRequest(url, requestBody, requestOptions, responseEncoding);\n }\n\n private buildRequestBody(options: HttpOptions) {\n let requestBody = options.body;\n if (options.form) {\n // Override requestBody for form with form content\n requestBody = new URLSearchParams(options.form).toString();\n options.headers = Object.assign(\n {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n options.headers\n );\n }\n if (options.json) {\n // Override requestBody with JSON value\n requestBody = JSON.stringify(options.body);\n options.headers = Object.assign(\n {\n 'Content-Type': 'application/json',\n },\n options.headers\n );\n }\n return requestBody;\n }\n\n private doHttpRequest(\n url: URL,\n requestBody: any,\n requestOptions: http.RequestOptions,\n responseEncoding: BufferEncoding | null\n ): Promise<HttpResult> {\n return new Promise((resolve, reject: (result: HttpRejectType) => void) => {\n function requestCallback(res: http.IncomingMessage) {\n if (responseEncoding) {\n // encoding = null for binary responses\n res.setEncoding(responseEncoding);\n }\n const chunks: any[] | Uint8Array[] = [];\n\n res.on('data', (chunk) => {\n chunks.push(chunk);\n });\n\n res.on('end', () => {\n const respBody = responseEncoding ? chunks.join('') : Buffer.concat(chunks);\n\n const response: HttpResponse = {\n statusCode: res.statusCode!,\n statusMessage: res.statusMessage!,\n headers: res.headers,\n body: respBody,\n };\n\n if (response.statusCode >= 200 && response.statusCode <= 299) {\n resolve({\n response: response,\n body: respBody,\n });\n } else {\n var rejectObject: HttpRejectType = {\n response: response,\n error: new Error(`Error on '${url}': ${res.statusCode} ${res.statusMessage}`),\n errorResponse: null,\n };\n var errorResponse = null;\n try {\n errorResponse = JSON.parse(respBody.toString()) as ApiErrorResponse;\n } catch (parseError) {}\n\n if (errorResponse) {\n rejectObject.errorResponse = errorResponse;\n } else {\n rejectObject.error.message += `. ${respBody}`;\n }\n reject(rejectObject);\n }\n });\n }\n\n const req =\n url.protocol === 'http:'\n ? http.request(url, requestOptions, requestCallback)\n : https.request(url, requestOptions, requestCallback);\n\n req.on('error', (error) => {\n reject({\n response: null,\n error: error,\n errorResponse: null,\n });\n });\n\n if (requestBody) {\n req.write(requestBody);\n }\n\n req.end();\n });\n }\n}\n","import crypto from 'crypto';\nimport { StringKeyWithStringValue } from 'httpClient';\n\nexport interface FormParamsType extends Array<Array<string>> {}\n\ninterface IRequestFile {\n name: string;\n filename: string;\n data: Buffer;\n contentType?: string;\n}\n\nexport class RequestFile implements IRequestFile {\n constructor(\n readonly name: string,\n readonly filename: string,\n readonly data: Buffer,\n readonly contentType?: string\n ) {}\n}\n\nexport class Multipart {\n readonly boundary: string;\n readonly body: Buffer;\n readonly headers: StringKeyWithStringValue;\n\n constructor(textFields: FormParamsType, files?: IRequestFile[]) {\n const random = crypto.randomUUID();\n this.boundary = '------------------------' + random.replace(/-/g, '');\n\n const bodyLines = [];\n for (const tuple of textFields) {\n bodyLines.push(`--${this.boundary}`);\n bodyLines.push(`Content-Disposition: form-data; name=\"${tuple[0]}\"`);\n bodyLines.push('');\n bodyLines.push(tuple[1]);\n }\n for (const file of files || []) {\n bodyLines.push(`--${this.boundary}`);\n bodyLines.push(\n `Content-Disposition: form-data; name=\"${file.name}\"; filename=\"${file.filename || 'filename'}\"`\n );\n bodyLines.push(`Content-Type: ${file.contentType || 'application/octet-stream'}`);\n bodyLines.push('');\n bodyLines.push(file.data.toString('binary'));\n }\n bodyLines.push(`--${this.boundary}--`);\n\n this.body = Buffer.from(bodyLines.join('\\r\\n'), 'binary');\n\n this.headers = {\n 'Content-Type': `multipart/form-data; boundary=${this.boundary}`,\n 'Content-Length': this.body.length.toString(),\n };\n }\n}\n","/**\n * Api Error.\n */\nexport class ApiError {\n /**\n * Gets or sets api error code.\n */\n 'code': string;\n /**\n * Gets or sets error message.\n */\n 'message': string;\n /**\n * Gets or sets error description.\n */\n 'description'?: string;\n /**\n * Gets or sets server datetime.\n */\n 'dateTime'?: Date;\n 'innerError'?: ApiError;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'code',\n baseName: 'code',\n type: 'string',\n },\n {\n name: 'message',\n baseName: 'message',\n type: 'string',\n },\n {\n name: 'description',\n baseName: 'description',\n type: 'string',\n },\n {\n name: 'dateTime',\n baseName: 'dateTime',\n type: 'Date',\n },\n {\n name: 'innerError',\n baseName: 'innerError',\n type: 'ApiError',\n },\n ];\n\n static getAttributeTypeMap() {\n return ApiError.attributeTypeMap;\n }\n}\n\n/**\n * ApiError Response\n */\nexport class ApiErrorResponse {\n /**\n * Gets or sets request Id.\n */\n 'requestId': string;\n 'error': ApiError;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'requestId',\n baseName: 'requestId',\n type: 'string',\n },\n {\n name: 'error',\n baseName: 'error',\n type: 'ApiError',\n },\n ];\n\n static getAttributeTypeMap() {\n return ApiErrorResponse.attributeTypeMap;\n }\n}\n\n/**\n * Specifies the file format of the image.\n */\nexport enum BarcodeImageFormat {\n Png = 'Png',\n Jpeg = 'Jpeg',\n Svg = 'Svg',\n Tiff = 'Tiff',\n Gif = 'Gif',\n}\n\n/**\n * Barcode image optional parameters\n */\nexport class BarcodeImageParams {\n 'imageFormat'?: BarcodeImageFormat;\n 'textLocation'?: CodeLocation;\n /**\n * Specify the displaying bars and content Color. Value: Color name from https://reference.aspose.com/drawing/net/system.drawing/color/ or ARGB value started with #. For example: AliceBlue or #FF000000 Default value: Black.\n */\n 'foregroundColor'?: string;\n /**\n * Background color of the barcode image. Value: Color name from https://reference.aspose.com/drawing/net/system.drawing/color/ or ARGB value started with #. For example: AliceBlue or #FF000000 Default value: White.\n */\n 'backgroundColor'?: string;\n 'units'?: GraphicsUnit;\n /**\n * Resolution of the BarCode image. One value for both dimensions. Default value: 96 dpi. Decimal separator is dot.\n */\n 'resolution'?: number;\n /**\n * Height of the barcode image in given units. Default units: pixel. Decimal separator is dot.\n */\n 'imageHeight'?: number;\n /**\n * Width of the barcode image in given units. Default units: pixel. Decimal separator is dot.\n */\n 'imageWidth'?: number;\n /**\n * BarCode image rotation angle, measured in degree, e.g. RotationAngle = 0 or RotationAngle = 360 means no rotation. If RotationAngle NOT equal to 90, 180, 270 or 0, it may increase the difficulty for the scanner to read the image. Default value: 0.\n */\n 'rotationAngle'?: number;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'imageFormat',\n baseName: 'imageFormat',\n type: 'BarcodeImageFormat',\n },\n {\n name: 'textLocation',\n baseName: 'textLocation',\n type: 'CodeLocation',\n },\n {\n name: 'foregroundColor',\n baseName: 'foregroundColor',\n type: 'string',\n },\n {\n name: 'backgroundColor',\n baseName: 'backgroundColor',\n type: 'string',\n },\n {\n name: 'units',\n baseName: 'units',\n type: 'GraphicsUnit',\n },\n {\n name: 'resolution',\n baseName: 'resolution',\n type: 'number',\n },\n {\n name: 'imageHeight',\n baseName: 'imageHeight',\n type: 'number',\n },\n {\n name: 'imageWidth',\n baseName: 'imageWidth',\n type: 'number',\n },\n {\n name: 'rotationAngle',\n baseName: 'rotationAngle',\n type: 'number',\n },\n ];\n\n static getAttributeTypeMap() {\n return BarcodeImageParams.attributeTypeMap;\n }\n}\n\n/**\n * Represents information about barcode.\n */\nexport class BarcodeResponse {\n /**\n * Barcode data.\n */\n 'barcodeValue'?: string;\n /**\n * Type of the barcode.\n */\n 'type'?: string;\n /**\n * Region with barcode.\n */\n 'region'?: Array<RegionPoint>;\n /**\n * Checksum of barcode.\n */\n 'checksum'?: string;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'barcodeValue',\n baseName: 'barcodeValue',\n type: 'string',\n },\n {\n name: 'type',\n baseName: 'type',\n type: 'string',\n },\n {\n name: 'region',\n baseName: 'region',\n type: 'Array<RegionPoint>',\n },\n {\n name: 'checksum',\n baseName: 'checksum',\n type: 'string',\n },\n ];\n\n static getAttributeTypeMap() {\n return BarcodeResponse.attributeTypeMap;\n }\n}\n\n/**\n * Represents information about barcode list.\n */\nexport class BarcodeResponseList {\n /**\n * List of barcodes which are present in image.\n */\n 'barcodes': Array<BarcodeResponse>;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'barcodes',\n baseName: 'barcodes',\n type: 'Array<BarcodeResponse>',\n },\n ];\n\n static getAttributeTypeMap() {\n return BarcodeResponseList.attributeTypeMap;\n }\n}\nexport enum CodeLocation {\n Below = 'Below',\n Above = 'Above',\n None = 'None',\n}\n\n/**\n * See Aspose.BarCode.Aspose.BarCode.BarCodeRecognition.DecodeType\n */\nexport enum DecodeBarcodeType {\n MostCommonlyUsed = 'MostCommonlyUsed',\n Qr = 'QR',\n AustraliaPost = 'AustraliaPost',\n AustralianPosteParcel = 'AustralianPosteParcel',\n Aztec = 'Aztec',\n Codabar = 'Codabar',\n CodablockF = 'CodablockF',\n Code11 = 'Code11',\n Code128 = 'Code128',\n Code16K = 'Code16K',\n Code32 = 'Code32',\n Code39 = 'Code39',\n Code39FullAscii = 'Code39FullASCII',\n Code93 = 'Code93',\n CompactPdf417 = 'CompactPdf417',\n DataLogic2of5 = 'DataLogic2of5',\n DataMatrix = 'DataMatrix',\n DatabarExpanded = 'DatabarExpanded',\n DatabarExpandedStacked = 'DatabarExpandedStacked',\n DatabarLimited = 'DatabarLimited',\n DatabarOmniDirectional = 'DatabarOmniDirectional',\n DatabarStacked = 'DatabarStacked',\n DatabarStackedOmniDirectional = 'DatabarStackedOmniDirectional',\n DatabarTruncated = 'DatabarTruncated',\n DeutschePostIdentcode = 'DeutschePostIdentcode',\n DeutschePostLeitcode = 'DeutschePostLeitcode',\n DotCode = 'DotCode',\n DutchKix = 'DutchKIX',\n Ean13 = 'EAN13',\n Ean14 = 'EAN14',\n Ean8 = 'EAN8',\n Gs1Aztec = 'GS1Aztec',\n Gs1Code128 = 'GS1Code128',\n Gs1CompositeBar = 'GS1CompositeBar',\n Gs1DataMatrix = 'GS1DataMatrix',\n Gs1DotCode = 'GS1DotCode',\n Gs1HanXin = 'GS1HanXin',\n Gs1MicroPdf417 = 'GS1MicroPdf417',\n Gs1Qr = 'GS1QR',\n HanXin = 'HanXin',\n HibcAztecLic = 'HIBCAztecLIC',\n HibcAztecPas = 'HIBCAztecPAS',\n HibcCode128Lic = 'HIBCCode128LIC',\n HibcCode128Pas = 'HIBCCode128PAS',\n HibcCode39Lic = 'HIBCCode39LIC',\n HibcCode39Pas = 'HIBCCode39PAS',\n HibcDataMatrixLic = 'HIBCDataMatrixLIC',\n HibcDataMatrixPas = 'HIBCDataMatrixPAS',\n Hibcqrlic = 'HIBCQRLIC',\n Hibcqrpas = 'HIBCQRPAS',\n Iata2of5 = 'IATA2of5',\n Isbn = 'ISBN',\n Ismn = 'ISMN',\n Issn = 'ISSN',\n Itf14 = 'ITF14',\n Itf6 = 'ITF6',\n Interleaved2of5 = 'Interleaved2of5',\n ItalianPost25 = 'ItalianPost25',\n MacroPdf417 = 'MacroPdf417',\n Mailmark = 'Mailmark',\n Matrix2of5 = 'Matrix2of5',\n MaxiCode = 'MaxiCode',\n MicrE13B = 'MicrE13B',\n MicroPdf417 = 'MicroPdf417',\n MicroQr = 'MicroQR',\n Msi = 'MSI',\n OneCode = 'OneCode',\n Opc = 'OPC',\n PatchCode = 'PatchCode',\n Pdf417 = 'Pdf417',\n Pharmacode = 'Pharmacode',\n Planet = 'Planet',\n Postnet = 'Postnet',\n Pzn = 'PZN',\n RectMicroQr = 'RectMicroQR',\n Rm4Scc = 'RM4SCC',\n Scc14 = 'SCC14',\n Sscc18 = 'SSCC18',\n Standard2of5 = 'Standard2of5',\n Supplement = 'Supplement',\n SwissPostParcel = 'SwissPostParcel',\n Upca = 'UPCA',\n Upce = 'UPCE',\n Vin = 'VIN',\n}\n\n/**\n * See Aspose.BarCode.Generation.EncodeTypes\n */\nexport enum EncodeBarcodeType {\n Qr = 'QR',\n AustraliaPost = 'AustraliaPost',\n AustralianPosteParcel = 'AustralianPosteParcel',\n Aztec = 'Aztec',\n Codabar = 'Codabar',\n CodablockF = 'CodablockF',\n Code11 = 'Code11',\n Code128 = 'Code128',\n Code16K = 'Code16K',\n Code32 = 'Code32',\n Code39 = 'Code39',\n Code39FullAscii = 'Code39FullASCII',\n Code93 = 'Code93',\n DataLogic2of5 = 'DataLogic2of5',\n DataMatrix = 'DataMatrix',\n DatabarExpanded = 'DatabarExpanded',\n DatabarExpandedStacked = 'DatabarExpandedStacked',\n DatabarLimited = 'DatabarLimited',\n DatabarOmniDirectional = 'DatabarOmniDirectional',\n DatabarStacked = 'DatabarStacked',\n DatabarStackedOmniDirectional = 'DatabarStackedOmniDirectional',\n DatabarTruncated = 'DatabarTruncated',\n DeutschePostIdentcode = 'DeutschePostIdentcode',\n DeutschePostLeitcode = 'DeutschePostLeitcode',\n DotCode = 'DotCode',\n DutchKix = 'DutchKIX',\n Ean13 = 'EAN13',\n Ean14 = 'EAN14',\n Ean8 = 'EAN8',\n Gs1Aztec = 'GS1Aztec',\n Gs1CodablockF = 'GS1CodablockF',\n Gs1Code128 = 'GS1Code128',\n Gs1DataMatrix = 'GS1DataMatrix',\n Gs1DotCode = 'GS1DotCode',\n Gs1HanXin = 'GS1HanXin',\n Gs1MicroPdf417 = 'GS1MicroPdf417',\n Gs1Qr = 'GS1QR',\n HanXin = 'HanXin',\n Iata2of5 = 'IATA2of5',\n Isbn = 'ISBN',\n Ismn = 'ISMN',\n Issn = 'ISSN',\n Itf14 = 'ITF14',\n Itf6 = 'ITF6',\n Interleaved2of5 = 'Interleaved2of5',\n ItalianPost25 = 'ItalianPost25',\n Msi = 'MSI',\n MacroPdf417 = 'MacroPdf417',\n Mailmark = 'Mailmark',\n Matrix2of5 = 'Matrix2of5',\n MaxiCode = 'MaxiCode',\n MicroPdf417 = 'MicroPdf417',\n MicroQr = 'MicroQR',\n Opc = 'OPC',\n OneCode = 'OneCode',\n Pzn = 'PZN',\n PatchCode = 'PatchCode',\n Pdf417 = 'Pdf417',\n Pharmacode = 'Pharmacode',\n Planet = 'Planet',\n Postnet = 'Postnet',\n Rm4Scc = 'RM4SCC',\n RectMicroQr = 'RectMicroQR',\n Scc14 = 'SCC14',\n Sscc18 = 'SSCC18',\n SingaporePost = 'SingaporePost',\n Standard2of5 = 'Standard2of5',\n SwissPostParcel = 'SwissPostParcel',\n Upca = 'UPCA',\n Upce = 'UPCE',\n UpcaGs1Code128Coupon = 'UpcaGs1Code128Coupon',\n UpcaGs1DatabarCoupon = 'UpcaGs1DatabarCoupon',\n Vin = 'VIN',\n}\n\n/**\n * Data to encode in barcode\n */\nexport class EncodeData {\n 'dataType'?: EncodeDataType;\n /**\n * String represents data to encode\n */\n 'data': string;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'dataType',\n baseName: 'dataType',\n type: 'EncodeDataType',\n },\n {\n name: 'data',\n baseName: 'data',\n type: 'string',\n },\n ];\n\n static getAttributeTypeMap() {\n return EncodeData.attributeTypeMap;\n }\n}\n\n/**\n * Types of data can be encoded to barcode\n */\nexport enum EncodeDataType {\n StringData = 'StringData',\n Base64Bytes = 'Base64Bytes',\n HexBytes = 'HexBytes',\n}\n\n/**\n * Barcode generation parameters\n */\nexport class GenerateParams {\n 'barcodeType': EncodeBarcodeType;\n 'encodeData': EncodeData;\n 'barcodeImageParams'?: BarcodeImageParams;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'barcodeType',\n baseName: 'barcodeType',\n type: 'EncodeBarcodeType',\n },\n {\n name: 'encodeData',\n baseName: 'encodeData',\n type: 'EncodeData',\n },\n {\n name: 'barcodeImageParams',\n baseName: 'barcodeImageParams',\n type: 'BarcodeImageParams',\n },\n ];\n\n static getAttributeTypeMap() {\n return GenerateParams.attributeTypeMap;\n }\n}\n\n/**\n * Subset of Aspose.Drawing.GraphicsUnit.\n */\nexport enum GraphicsUnit {\n Pixel = 'Pixel',\n Point = 'Point',\n Inch = 'Inch',\n Millimeter = 'Millimeter',\n}\n\n/**\n * Kind of image to recognize\n */\nexport enum RecognitionImageKind {\n Photo = 'Photo',\n ScannedDocument = 'ScannedDocument',\n ClearImage = 'ClearImage',\n}\n\n/**\n * Recognition mode.\n */\nexport enum RecognitionMode {\n Fast = 'Fast',\n Normal = 'Normal',\n Excellent = 'Excellent',\n}\n\n/**\n * Barcode recognize request\n */\nexport class RecognizeBase64Request {\n /**\n * Array of decode types to find on barcode\n */\n 'barcodeTypes': Array<DecodeBarcodeType>;\n /**\n * Barcode image bytes encoded as base-64.\n */\n 'fileBase64': string;\n 'recognitionMode'?: RecognitionMode;\n 'recognitionImageKind'?: RecognitionImageKind;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'barcodeTypes',\n baseName: 'barcodeTypes',\n type: 'Array<DecodeBarcodeType>',\n },\n {\n name: 'fileBase64',\n baseName: 'fileBase64',\n type: 'string',\n },\n {\n name: 'recognitionMode',\n baseName: 'recognitionMode',\n type: 'RecognitionMode',\n },\n {\n name: 'recognitionImageKind',\n baseName: 'recognitionImageKind',\n type: 'RecognitionImageKind',\n },\n ];\n\n static getAttributeTypeMap() {\n return RecognizeBase64Request.attributeTypeMap;\n }\n}\n\n/**\n * Wrapper around Drawing.Point for proper specification.\n */\nexport class RegionPoint {\n /**\n * X-coordinate\n */\n 'x'?: number;\n /**\n * Y-coordinate\n */\n 'y'?: number;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'x',\n baseName: 'x',\n type: 'number',\n },\n {\n name: 'y',\n baseName: 'y',\n type: 'number',\n },\n ];\n\n static getAttributeTypeMap() {\n return RegionPoint.attributeTypeMap;\n }\n}\n\n/**\n * Scan barcode request.\n */\nexport class ScanBase64Request {\n /**\n * Barcode image bytes encoded as base-64.\n */\n 'fileBase64': string;\n\n static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [\n {\n name: 'fileBase64',\n baseName: 'fileBase64',\n type: 'string',\n },\n ];\n\n static getAttributeTypeMap() {\n return ScanBase64Request.attributeTypeMap;\n }\n}\n\n// GenerateApi\n\n/**\n * Generate barcode using GET request with parameters in route and query string.\n */\nexport class GenerateRequestWrapper {\n /**\n * Type of barcode to generate.\n */\n 'barcodeType': EncodeBarcodeType;\n /**\n * String represents data to encode\n */\n 'data': string;\n /**\n * Type of data to encode.\nDefault value: StringData.\n */\n 'dataType'?: EncodeDataType;\n /**\n * Barcode output image format.\nDefault value: png\n */\n 'imageFormat'?: BarcodeImageFormat;\n /**\n * Specify the displaying Text Location, set to CodeLocation.None to hide CodeText.\nDefault value: Depends on BarcodeType. CodeLocation.Below for 1D Barcodes. CodeLocation.None for 2D Barcodes.\n */\n 'textLocation'?: CodeLocation;\n /**\n * Specify the displaying bars and content Color.\nValue: Color name from https://reference.aspose.com/drawing/net/system.drawing/color/ or ARGB value started with #.\nFor example: AliceBlue or #FF000000\nDefault value: Black.\n */\n 'foregroundColor'?: string = \"'Black'\";\n /**\n * Background color of the barcode image.\nValue: Color name from https://reference.aspose.com/drawing/net/system.drawing/color/ or ARGB value started with #.\nFor example: AliceBlue or #FF000000\nDefault value: White.\n */\n 'backgroundColor'?: string = \"'White'\";\n /**\n * Common Units for all measuring in query. Default units: pixel.\n */\n 'units'?: GraphicsUnit;\n /**\n * Resolution of the BarCode image.\nOne value for both dimensions.\nDefault value: 96 dpi.\nDecimal separator is dot.\n */\n 'resolution'?: number;\n /**\n * Height of the barcode image in given units. Default units: pixel.\nDecimal separator is dot.\n */\n 'imageHeight'?: number;\n /**\n * Width of the barcode image in given units. Default units: pixel.\nDecimal separator is dot.\n */\n 'imageWidth'?: number;\n /**\n * BarCode image rotation angle, measured in degree, e.g. RotationAngle = 0 or RotationAngle = 360 means no rotation.\nIf RotationAngle NOT equal to 90, 180, 270 or 0, it may increase the difficulty for the scanner to read the image.\nDefault value: 0.\n */\n 'rotationAngle'?: number;\n\n /**\n * @param barcodeType Type of barcode to generate.\n \n * @param data String represents data to encode\n */\n constructor(barcodeType: EncodeBarcodeType, data: string) {\n this.barcodeType = barcodeType;\n this.data = data;\n }\n}\n\n/**\n * Generate barcode using POST request with parameters in body in json or xml format.\n */\nexport class GenerateBodyRequestWrapper {\n /**\n *\n */\n 'generateParams': GenerateParams;\n\n /**\n * @param generateParams\n */\n constructor(generateParams: GenerateParams) {\n this.generateParams = generateParams;\n }\n}\n\n/**\n * Generate barcode using POST request with parameters in multipart form.\n */\nexport class GenerateMultipartRequestWrapper {\n /**\n *\n */\n 'barcodeType': EncodeBarcodeType;\n /**\n * String represents data to encode\n */\n 'data': string;\n /**\n *\n */\n 'dataType'?: EncodeDataType;\n /**\n *\n */\n 'imageFormat'?: BarcodeImageFormat;\n /**\n *\n */\n 'textLocation'?: CodeLocation;\n /**\n * Specify the displaying bars and content Color. Value: Color name from https://reference.aspose.com/drawing/net/system.drawing/color/ or ARGB value started with #. For example: AliceBlue or #FF000000 Default value: Black.\n */\n 'foregroundColor'?: string = \"'Black'\";\n /**\n * Background color of the barcode image. Value: Color name from https://reference.aspose.com/drawing/net/system.drawing/color/ or ARGB value started with #. For example: AliceBlue or #FF000000 Default value: White.\n */\n 'backgroundColor'?: string = \"'White'\";\n /**\n *\n */\n 'units'?: GraphicsUnit;\n /**\n * Resolution of the BarCode image. One value for both dimensions. Default value: 96 dpi. Decimal separator is dot.\n */\n 'resolution'?: number;\n /**\n * Height of the barcode image in given units. Default units: pixel. Decimal separator is dot.\n */\n 'imageHeight'?: number;\n /**\n * Width of the barcode image in given units. Default units: pixel. Decimal separator is dot.\n */\n 'imageWidth'?: number;\n /**\n * BarCode image rotation angle, measured in degree, e.g. RotationAngle = 0 or RotationAngle = 360 means no rotation. If RotationAngle NOT equal to 90, 180, 270 or 0, it may increase the difficulty for the scanner to read the image. Default value: 0.\n */\n 'rotationAngle'?: number;\n\n /**\n * @param barcodeType \n \n * @param data String represents data to encode\n */\n constructor(barcodeType: EncodeBarcodeType, data: string) {\n this.barcodeType = barcodeType;\n this.data = data;\n }\n}\n\n// RecognizeApi\n\n/**\n * Recognize barcode from file on server using GET requests with parameters in route and query string.\n */\nexport class RecognizeRequestWrapper {\n /**\n * Type of barcode to recognize\n */\n 'barcodeType': DecodeBarcodeType;\n /**\n * Url to barcode image\n */\n 'fileUrl': string;\n /**\n * Recognition mode\n */\n 'recognitionMode'?: RecognitionMode;\n /**\n * Image kind for recognition\n */\n 'recognitionImageKind'?: RecognitionImageKind;\n\n /**\n * @param barcodeType Type of barcode to recognize\n \n * @param fileUrl Url to barcode image\n */\n constructor(barcodeType: DecodeBarcodeType, fileUrl: string) {\n this.barcodeType = barcodeType;\n this.fileUrl = fileUrl;\n }\n}\n\n/**\n * Recognize barcode from file in request body using POST requests with parameters in body in json or xml format.\n */\nexport class RecognizeBase64RequestWrapper {\n /**\n *\n */\n 'recognizeBase64Request': RecognizeBase64Request;\n\n /**\n * @param recognizeBase64Request\n */\n constructor(recognizeBase64Request: RecognizeBase64Request) {\n this.recognizeBase64Request = recognizeBase64Request;\n }\n}\n\n/**\n * Recognize barcode from file in request body using POST requests with parameters in multipart form.\n */\nexport class RecognizeMultipartRequestWrapper {\n /**\n *\n */\n 'barcodeType': DecodeBarcodeType;\n /**\n * Barcode image file\n */\n 'fileBytes': Buffer;\n /**\n *\n */\n 'recognitionMode'?: RecognitionMode;\n /**\n *\n */\n 'recognitionImageKind'?: RecognitionImageKind;\n\n /**\n * @param barcodeType \n \n * @param fileBytes Barcode image file\n */\n constructor(barcodeType: DecodeBarcodeType, fileBytes: Buffer) {\n this.barcodeType = barcodeType;\n this.fileBytes = fileBytes;\n }\n}\n\n// ScanApi\n\n/**\n * Scan barcode from file on server using GET requests with parameter in query string.\n */\nexport class ScanRequestWrapper {\n /**\n * Url to barcode image\n */\n 'fileUrl': string;\n\n /**\n * @param fileUrl Url to barcode image\n */\n constructor(fileUrl: string) {\n this.fileUrl = fileUrl;\n }\n}\n\n/**\n * Scan barcode from file in request body using POST requests with parameter in body in json or xml format.\n */\nexport class ScanBase64RequestWrapper {\n /**\n *\n */\n 'scanBase64Request': ScanBase64Request;\n\n /**\n * @param scanBase64Request\n */\n constructor(scanBase64Request: ScanBase64Request) {\n this.scanBase64Request = scanBase64Request;\n }\n}\n\n/**\n * Scan barcode from file in request body using POST requests with parameter in multipart form.\n */\nexport class ScanMultipartRequestWrapper {\n /**\n * Barcode image file\n */\n 'fileBytes': Buffer;\n\n /**\n * @param fileBytes Barcode image file\n */\n constructor(fileBytes: Buffer) {\n this.fileBytes = fileBytes;\n }\n}\n","import { Configuration } from './Configuration';\nimport { HttpClient, HttpOptions, HttpResponse, HttpResult } from './httpClient';\nimport { Multipart, RequestFile, FormParamsType } from './multipart';\n\nexport * from './models';\n\nimport {\n ApiError,\n ApiErrorResponse,\n BarcodeImageFormat,\n BarcodeImageParams,\n BarcodeResponse,\n BarcodeResponseList,\n CodeLocation,\n DecodeBarcodeType,\n EncodeBarcodeType,\n EncodeData,\n EncodeDataType,\n GenerateParams,\n GraphicsUnit,\n RecognitionImageKind,\n RecognitionMode,\n RecognizeBase64Request,\n RegionPoint,\n ScanBase64Request,\n} from './models';\n\nimport {\n GenerateRequestWrapper,\n GenerateBodyRequestWrapper,\n GenerateMultipartRequestWrapper,\n RecognizeRequestWrapper,\n RecognizeBase64RequestWrapper,\n RecognizeMultipartRequestWrapper,\n ScanRequestWrapper,\n ScanBase64RequestWrapper,\n ScanMultipartRequestWrapper,\n} from './models';\n\nlet primitives = ['string', 'boolean', 'double', 'integer', 'long', 'float', 'number', 'any'];\n\nclass ObjectSerializer {\n public static findCorrectType(data: any, expectedType: string) {\n if (data == null) {\n return expectedType;\n }\n\n if (primitives.indexOf(expectedType.toLowerCase()) !== -1) {\n return expectedType;\n }\n\n if (expectedType === 'Date') {\n return expectedType;\n }\n\n if (enumsMap[expectedType]) {\n return expectedType;\n }\n\n if (!typeMap[expectedType]) {\n return expectedType; // w/e we don't know the type\n }\n\n // Check the discriminator\n let discriminatorProperty = typeMap[expectedType].discriminator;\n if (discriminatorProperty == null) {\n return expectedType; // the type does not have a discriminator. use it.\n }\n\n if (data[discriminatorProperty]) {\n return data[discriminatorProperty]; // use the type given in the discriminator\n }\n\n return expectedType; // discriminator was not present (or an empty string)\n }\n\n public static serialize(data: any, type: string) {\n if (data == null) {\n return data;\n }\n\n if (primitives.indexOf(type.toLowerCase()) !== -1) {\n return data;\n }\n\n if (type.lastIndexOf('Array<', 0) === 0) {\n // string.startsWith pre es6\n let subType: string = type.replace('Array<', ''); // Array<Type> => Type>\n subType = subType.substring(0, subType.length - 1); // Type> => Type\n let transformedData: any[] = [];\n for (let index in data) {\n let date = data[index];\n transformedData.push(ObjectSerializer.serialize(date, subType));\n }\n\n return transformedData;\n }\n\n if (type === 'Date') {\n return data.toString();\n }\n\n if (enumsMap[type] && Object.values(enumsMap[type]).includes(data)) {\n return data;\n }\n\n if (!typeMap[type]) {\n // in case we don't know the type\n return data;\n }\n\n // get the map for the correct type.\n let attributeTypes = typeMap[type].getAttributeTypeMap();\n let instance: { [index: string]: any } = {};\n for (let index in attributeTypes) {\n let attributeType = attributeTypes[index];\n instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);\n }\n\n return instance;\n }\n\n public static deserialize(data: any, type: string) {\n // polymorphism may change the actual type.\n type = ObjectSerializer.findCorrectType(data, type);\n\n if (data == null) {\n return data;\n }\n\n if (primitives.indexOf(type.toLowerCase()) !== -1) {\n return data;\n }\n\n if (type.lastIndexOf('Array<', 0) === 0) {\n // string.startsWith pre es6\n let subType: string = type.replace('Array<', ''); // Array<Type> => Type>\n subType = subType.substring(0, subType.length - 1); // Type> => Type\n let transformedData: any[] = [];\n for (let index in data) {\n let date = data[index];\n transformedData.push(ObjectSerializer.deserialize(date, subType));\n }\n return transformedData;\n }\n\n if (type === 'Date') {\n return new Date(data);\n }\n\n if (enumsMap[type]) {\n // is Enum\n return data;\n }\n\n if (!typeMap[type]) {\n // don't know the type\n return data;\n }\n\n if (typeof data === 'string') {\n // data should be deserialized before usage\n data = JSON.parse(data);\n }\n\n let instance = new typeMap[type]();\n let attributeTypes = typeMap[type].getAttributeTypeMap();\n for (const attributeType of attributeTypes) {\n const key = attributeType.baseName.replace(/^(.)/, ($1: string) => {\n return $1.toLowerCase();\n });\n instance[attributeType.name] = ObjectSerializer.deserialize(data[key], attributeType.type);\n }\n\n return instance;\n }\n}\n\nlet enumsMap: { [index: string]: any } = {\n BarcodeImageFormat: BarcodeImageFormat,\n CodeLocation: CodeLocation,\n DecodeBarcodeType: DecodeBarcodeType,\n EncodeBarcodeType: EncodeBarcodeType,\n EncodeDataType: EncodeDataType,\n GraphicsUnit: GraphicsUnit,\n RecognitionImageKind: RecognitionImageKind,\n RecognitionMode: RecognitionMode,\n};\n\nlet typeMap: { [index: string]: any } = {\n ApiError: ApiError,\n ApiErrorResponse: ApiErrorResponse,\n BarcodeImageParams: BarcodeImageParams,\n BarcodeResponse: BarcodeResponse,\n BarcodeResponseList: BarcodeResponseList,\n EncodeData: EncodeData,\n GenerateParams: GenerateParams,\n RecognizeBase64Request: RecognizeBase64Request,\n RegionPoint: RegionPoint,\n ScanBase64Request: ScanBase64Request,\n};\n\nexport class GenerateApi {\n protected defaultHeaders: any = {\n 'x-aspose-client': 'nodejs sdk',\n 'x-aspose-client-version': '25.3.0',\n };\n protected _configuration: Configuration;\n private _client: HttpClient;\n\n constructor(configuration: Configuration) {\n this._configuration = configuration;\n this._client = new HttpClient();\n }\n\n /**\n *\n * @summary Generate barcode using GET request with parameters in route and query string.\n * @param request GenerateRequestWrapper\n */\n public async generate(request: GenerateRequestWrapper): Promise<{ response: HttpResponse; body: Buffer }> {\n const requestPath =\n this._configuration.getApiBaseUrl() +\n '/barcode/generate/{barcodeType}'.replace('{' + 'barcodeType' + '}', String(request.barcodeType));\n let queryParameters: any = {};\n let headerParams: any = (Object as any).assign({}, this.defaultHeaders);\n\n // verify required parameter 'request.barcodeType' is not null or undefined\n if (request.barcodeType == null) {\n throw new Error('Required parameter request.barcodeType was null or undefined when calling generate.');\n }\n\n // verify required parameter 'request.data' is not null or undefined\n if (request.data == null) {\n throw new Error('Required parameter request.data was null or undefined when calling generate.');\n }\n\n if (request.dataType != null) {\n queryParameters['dataType'] = ObjectSerializer.serialize(request.dataType, 'EncodeDataType');\n }\n\n if (request.data != null) {\n queryParameters['data'] = ObjectSerializer.serialize(request.data, 'string');\n }\n\n if (request.imageFormat != null) {\n queryParameters['imageFormat'] = ObjectSerializer.serialize(request.imageFormat, 'BarcodeImageFormat');\n }\n\n if (request.textLocation != null) {\n queryParameters['textLocation'] = ObjectSerializer.serialize(request.textLocation, 'CodeLocation');\n }\n\n if (request.foregroundColor != null) {\n queryParameters['foregroundColor'] = ObjectSerializer.serialize(request.foregroundColor, 'string');\n }\n\n if (request.backgroundColor != null) {\n queryParameters['backgroundColor'] = ObjectSerializer.serialize(request.backgroundColor, 'string');\n }\n\n if (request.units != null) {\n queryParameters['units'] = ObjectSerializer.serialize(request.units, 'GraphicsUnit');\n }\n\n if (request.resolution != null) {\n queryParameters['resolution'] = ObjectSerializer.serialize(request.resolution, 'number');\n }\n\n if (request.imageHeight != null) {\n queryParameters['imageHeight'] = ObjectSerializer.serialize(request.imageHeight, 'number');\n }\n\n if (request.imageWidth != null) {\n queryParameters['imageWidth'] = ObjectSerializer.serialize(request.imageWidth, 'number');\n }\n\n if (request.rotationAngle != null) {\n queryParameters['rotationAngle'] = ObjectSerializer.serialize(request.rotationAngle, 'number');\n }\n\n const requestOptions: HttpOptions = {\n method: 'GET',\n qs: queryParameters,\n headers: headerParams,\n uri: requestPath,\n encoding: null,\n };\n\n await this._configuration.authentication.applyToRequestAsync(requestOptions);\n\n const result: HttpResult = await this._client.requestAsync(requestOptions);\n\n return {\n response: result.response,\n body: ObjectSerializer.deserialize(result.body, 'Buffer'),\n };\n }\n\n /**\n *\n * @summary Generate barcode using POST request with parameters in body in json or xml format.\n * @param request GenerateBodyRequestWrapper\n */\n public async generateBody(request: GenerateBodyRequestWrapper): Promise<{ response: HttpResponse; body: Buffer }> {\n const requestPath = this._configuration.getApiBaseUrl() + '/barcode/generate-body';\n let queryParameters: any = {};\n let headerParams: any = (Object as any).assign({}, this.defaultHeaders);\n\n // verify required parameter 'request.generateParams' is not null or undefined\n if (request.generateParams == null) {\n throw new Error(\n 'Required parameter request.generateParams was null or undefined when calling generateBody.'\n );\n }\n\n const requestOptions: HttpOptions = {\n method: 'POST',\n qs: queryParameters,\n headers: headerParams,\n uri: requestPath,\n body: ObjectSerializer.serialize(request.generateParams, 'GenerateParams'),\n json: true,\n encoding: null,\n };\n\n await this._configuration.authentication.applyToRequestAsync(requestOptions);\n\n const result: HttpResult = await this._client.requestAsync(requestOptions);\n\n return {\n response: result.response,\n body: ObjectSerializer.deserialize(result.body, 'Buffer'),\n };\n }\n\n /**\n *\n * @summary Generate barcode using POST request with parameters in multipart form.\n * @param request GenerateMultipartRequestWrapper\n */\n public async generateMultipart(\n request: GenerateMultipartRequestWrapper\n ): Promise<{ response: HttpResponse; body: Buffer }> {\n const requestPath = this._configuration.getApiBaseUrl() + '/barcode/generate-multipart';\n let queryParameters: any = {};\n let headerParams: any = (Object as any).assign({}, this.defaultHeaders);\n const formParams: FormParamsType = [];\n\n // verify required parameter 'request.barcodeType' is not null or undefined\n if (request.barcodeType == null) {\n throw new Error(\n 'Required parameter request.barcodeType was null or undefined when calling generateMultipart.'\n );\n }\n\n // verify required parameter 'request.data' is not null or undefined\n if (request.data == null) {\n throw new Error('Required parameter request.data was null or undefined when calling generateMultipart.');\n }\n\n if (request.barcodeType != null) {\n formParams.push(['barcodeType', ObjectSerializer.serialize(request.barcodeType, 'EncodeBarcodeType')]);\n }\n if (request.dataType != null) {\n formParams.push(['dataType', ObjectSerializer.serialize(request.dataType, 'EncodeDataType')]);\n }\n if (request.data != null) {\n formParams.push(['data', ObjectSerializer.serialize(request.data, 'string')]);\n }\n if (request.imageFormat != null) {\n formParams.push(['imageFormat', ObjectSerializer.serialize(request.imageFormat, 'BarcodeImageFormat')]);\n }\n if (request.textLocation != null) {\n formParams.push(['textLocation', ObjectSerializer.serialize(request.textLocation, 'CodeLocation')]);\n }\n if (request.foregroundColor != null) {\n formParams.push(['foregroundColor', ObjectSerializer.serialize(request.foregroundColor, 'string')]);\n }\n if (request.backgroundColor != null) {\n formParams.push(['backgroundColor', ObjectSerializer.serialize(request.backgroundColor, 'string')]);\n }\n if (request.units != null) {\n formParams.push(['units', ObjectSerializer.serialize(request.units, 'GraphicsUnit')]);\n }\n if (request.resolution != null) {\n formParams.push(['resolution', ObjectSerializer.serialize(request.resolution, 'number')]);\n }\n if (request.imageHeight != null) {\n formParams.push(['imageHeight', ObjectSerializer.serialize(request.imageHeight, 'number')]);\n }\n if (request.imageWidth != null) {\n formParams.push(['imageWidth', ObjectSerializer.serialize(request.imageWidth, 'number')]);\n }\n if (request.rotationAngle != null) {\n formParams.push(['rotationAngle', ObjectSerializer.serialize(request.rotationAngle, 'number')]);\n }\n const requestOptions: HttpOptions = {\n method: 'POST',\n qs: queryParameters,\n headers: headerParams,\n uri: requestPath,\n encoding: null,\n };\n\n let fileArray = new Array<RequestFile>();\n\n const multipartForm = new Multipart(formParams, fileArray);\n requestOptions.body = multipartForm.body;\n requestOptions.headers = { ...requestOptions.headers, ...multipartForm.headers };\n\n await this._configuration.authentication.applyToRequestAsync(requestOptions);\n\n const result: HttpResult = await this._client.requestAsync(requestOptions);\n\n return {\n response: result.response,\n body: ObjectSerializer.deserialize(result.body, 'Buffer'),\n };\n }\n}\n\nexport class RecognizeApi {\n protected defaultHeaders: any = {\n 'x-aspose-client': 'nodejs sdk',\n 'x-aspose-client-version': '25.3.0',\n };\n protected _configuration: Configuration;\n private _client: HttpClient;\n\n constructor(configuration: Configuration) {\n this._configuration = configuration;\n this._client = new HttpClient();\n }\n\n /**\n *\n * @summary Recognize barcode from file on server using GET requests with parameters in route and query string.\n * @param request RecognizeRequestWrapper\n */\n public async recognize(\n request: RecognizeRequestWrapper\n ): Promise<{ response: HttpResponse; body: BarcodeResponseList }> {\n const requestPath = this._configuration.getApiBaseUrl() + '/barcode/recognize';\n let queryParameters: any = {};\n let headerParams: any = (Object as any).assign({}, this.defaultHeaders);\n\n // verify required parameter 'request.barcodeType' is not null or undefined\n if (request.barcodeType == null) {\n throw new Error('Required parameter request.barcodeType was null or undefined when calling recognize.');\n }\n\n // verify required parameter 'request.fileUrl' is not null or undefined\n if (request.fileUrl == null) {\n throw new Error('Required parameter request.fileUrl was null or undefined when calling recognize.');\n }\n\n if (request.barcodeType != null) {\n queryParameters['barcodeType'] = ObjectSerializer.serialize(request.barcodeType, 'DecodeBarcodeType');\n }\n\n if (request.fileUrl != null) {\n queryParameters['fileUrl'] = ObjectSerializer.serialize(request.fileUrl, 'string');\n }\n\n if (request.recognitionMode != null) {\n queryParameters['recognitionMode'] = ObjectSerializer.serialize(request.recognitionMode, 'RecognitionMode');\n }\n\n if (request.recognitionImageKind != null) {\n queryParameters['recognitionImageKind'] = ObjectSerializer.serialize(\n request.recognitionImageKind,\n 'RecognitionImageKind'\n );\n }\n\n const requestOptions: HttpOptions = {\n method: 'GET',\n qs: queryParameters,\n headers: headerParams,\n uri: requestPath,\n };\n\n await this._configuration.authentication.applyToRequestAsync(requestOptions);\n\n const result: HttpResult = await this._client.requestAsync(requestOptions);\n\n return {\n response: result.response,\n body: ObjectSerializer.deserialize(result.body, 'BarcodeResponseList'),\n };\n }\n\n /**\n *\n * @summary Recognize barcode from file in request body using POST requests with parameters in body in json or xml format.\n * @param request RecognizeBase64RequestWrapper\n */\n public async recognizeBase64(\n req