https://github.com/vitalets/yandex-cloud-fn
Хелперы для функций в Yandex Cloud (Node.js)
https://github.com/vitalets/yandex-cloud-fn
Last synced: 3 months ago
JSON representation
Хелперы для функций в Yandex Cloud (Node.js)
- Host: GitHub
- URL: https://github.com/vitalets/yandex-cloud-fn
- Owner: vitalets
- Created: 2021-10-28T10:54:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-07T09:21:43.000Z (almost 3 years ago)
- Last Synced: 2025-08-05T06:16:13.589Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.34 MB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# yandex-cloud-fn
Runtime-хелперы для Node.js функций в Yandex Cloud.
## Что включает
* покрытие типами: `event`, `context`, итд
* определение источника запроса: `isHttpRequest`, `isTimerRequest`, итд
* получение тела запроса (с учетом base64): `getHttpBody`
* отправка json ответа: `sendJson`
* корректное логирование: `fixConsoleForLogging`, `fixValueForLogging`.
## Установка
```
npm i yandex-cloud-fn
```
## Использование
```ts
import { Handler, HttpRequest, TimerRequest, isHttpRequest, sendJson } from 'yandex-cloud-fn';
export const handler: Handler = async event => {
if (isHttpRequest(event)) {
const reqBody = JSON.parse(getHttpBody(event));
console.log(`Triggered by http request: ${JSON.stringify(reqBody)}`);
return sendJson({ ok: true });
} else {
console.log(`Triggered by timer: ${event.messages[0].details.trigger_id}`);
}
}
```
Больше примеров в папке [/examples](/examples).
## Доступные методы
tbd
## Лицензия
MIT @ [Vitaliy Potapov](https://github.com/vitalets)