@apidog/multibot-sdk-ts
Advanced tools
Comparing version 0.0.8-2 to 0.0.8-3
@@ -42,5 +42,4 @@ /// <reference types="node" /> | ||
protected getApiEndpoint: (method: string) => string; | ||
private readonly handleMethodsForFiles; | ||
private handleParamsForFiles; | ||
request: <T>(apiMethod: string, params?: Record<string, any>) => Promise<T>; | ||
private createFormDataFromParams; | ||
request: <T>(apiMethod: string, params?: Record<string, unknown>) => Promise<T>; | ||
/** | ||
@@ -47,0 +46,0 @@ * Public API |
@@ -15,3 +15,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs = require("fs"); | ||
const axios_1 = require("axios"); | ||
@@ -28,40 +27,25 @@ const FormData = require("form-data"); | ||
}; | ||
this.handleMethodsForFiles = { | ||
'sendPhoto': 'photo', | ||
'sendAudio': 'audio', | ||
'sendDocument': 'document', | ||
'sendSticker': 'sticker', | ||
'sendVideo': 'video', | ||
'sendAnimation': 'animation', | ||
'sendVideoNote': 'video_note', | ||
'sendVoice': 'voice', | ||
'setChatPhoto': 'file', | ||
/* 'uploadStickerFile', | ||
'createNewStickerSet', | ||
'addStickerToSet',*/ | ||
'sendMediaGroup': undefined | ||
}; | ||
this.handleParamsForFiles = (data, name) => { | ||
const entry = data[name]; | ||
if (typeof entry === 'string') { | ||
if (fs.existsSync(entry)) { | ||
data[name] = fs.createReadStream(entry); | ||
this.createFormDataFromParams = (params) => { | ||
return Object.entries(params).reduce((form, [key, value]) => { | ||
if (value !== undefined) { | ||
switch (typeof value) { | ||
case 'number': | ||
case 'boolean': { | ||
value = String(value); | ||
break; | ||
} | ||
case 'object': { | ||
value = JSON.stringify(value); | ||
break; | ||
} | ||
} | ||
form.append(key, value); | ||
} | ||
} | ||
return form; | ||
}, new FormData()); | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
this.request = (apiMethod, params = {}) => __awaiter(this, void 0, void 0, function* () { | ||
if (apiMethod in this.handleMethodsForFiles) { | ||
this.handleParamsForFiles(params, this.handleMethodsForFiles[apiMethod]); | ||
} | ||
const form = Object.keys(params).reduce((form, key) => { | ||
if (params[key] !== undefined) { | ||
const v = params[key]; | ||
form.append(key, typeof v === 'object' ? JSON.stringify(v) : v); | ||
} | ||
return form; | ||
}, new FormData()); | ||
const endpoint = this.getApiEndpoint(apiMethod); | ||
const { data, status, statusText } = yield axios_1.default.post(endpoint, form, { | ||
headers: Object.assign({}, (form.getHeaders())) | ||
const form = this.createFormDataFromParams(params); | ||
const { data, status, statusText } = yield axios_1.default.post(this.getApiEndpoint(apiMethod), form, { | ||
headers: form.getHeaders(), | ||
}); | ||
@@ -68,0 +52,0 @@ if (status !== 200) { |
{ | ||
"name": "@apidog/multibot-sdk-ts", | ||
"version": "0.0.8-2", | ||
"version": "0.0.8-3", | ||
"description": "Telegram and VK bot SDK for TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
191718
2811