Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@

הספריה עוקבת אחרי [Semantic Versioning](https://semver.org) ([עברית](https://semver.org/lang/he/)).

## ‏6.3.0

- נוספה אופציה `logTimestamps` להוספת חותמות זמן (timestamps) בפורמט ISO להודעות הלוג שהספרייה מדפיסה
- ברירת מחדל: `false` (כדי לשמור על תאימות לאחור)
- שימושי במיוחד בסביבות production כמו Kubernetes שבהן חשוב לראות מתי בדיוק כל פעולה התרחשה
- דוגמה לשימוש:
```javascript
const router = YemotRouter({
printLog: true,
logTimestamps: true
});
```
- פורמט הלוג עם timestamps: `[2025-11-06T17:56:55.068Z] [call-id]: message`

## ‏6.2.0

- נוסף טייפ `SYSTEM_MESSAGE_CODES` עבור הודעות מערכת, המספק גם בטיחות מפני טעות הקלדה וגם הצגת תיאור ההודעה בריחוף על שמה
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ router.get('/', async (call) => {
‫מכסה גם מקרי קצה שלא התקבלה מימות הקריאה עם hangup=yes.<br>
‫יש לשים לב לא להגדיר ערך נמוך שמחייג לגיטימי שלא הקיש מיד תשובה עלול להיתקל ב-timeout.
- **printLog** (בוליאני): האם להדפיס לוג מפורט על כל קריאה לשרת, ניתוק שיחה וכולי. שימושי לפיתוח.
- **logTimestamps** (בוליאני): האם להוסיף חותמות זמן (timestamps) בפורמט ISO להודעות הלוג שהספרייה מדפיסה. ברירת מחדל: `false`. שימושי במיוחד בסביבות production כמו Kubernetes שבהן חשוב לראות מתי בדיוק כל פעולה התרחשה.
- **uncaughtErrorHandler**: (פונקציה) ‫ פונקציה לטיפול בשגיאות לא מטופלות בתוך שיחה, שימושי לדוגמה לשמירת לוג + השמעת הודעה למשתמש, במקום קריסה של השרת, והמשתמש ישמע "אין מענה משרת API".
ראה דוגמה ב[example.js](example.js).

Expand Down
34 changes: 34 additions & 0 deletions example-timestamps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import express from 'express';
import { YemotRouter } from './index.js';

const app = express();
app.use(express.urlencoded({ extended: true }));

// דוגמה עם timestamps מופעלים
const router = YemotRouter({
printLog: true,
logTimestamps: true // 👈 הפעלת timestamps
});

router.get('/', async (call) => {
const response = await call.read([{
type: 'text',
data: 'שלום, הקש 1 להמשך'
}], 'tap', {
max_digits: 1,
digits_allowed: [1]
});

return call.id_list_message([{
type: 'text',
data: 'תודה, להתראות'
}]);
});

app.use(router);

const PORT = 9770;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
console.log(`Example with timestamps enabled`);
});
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ interface Defaults {
* @default false
*/
printLog?: boolean
/**
* האם להוסיף חותמות זמן (timestamps) בפורמט ISO להודעות הלוג של הספרייה<br>
* שימושי במיוחד בסביבות production כמו Kubernetes<br>
* @default false
*/
logTimestamps?: boolean
/**
* האם להסיר אוטומטית תווים לא חוקיים (`.`,`-`,`'`,`"`,`&`) מתשובות הקראת טקסט<br>
* ,באם לא מוגדרת הסרה (ברירת מחדל), תיזרק שגיאה<br>
Expand Down
3 changes: 2 additions & 1 deletion lib/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class Call {

#logger (msg, color = 'blue') {
if (!this.#defaults.printLog) return;
console.log(colors[color](`[${this.callId}]: ${msg}`));
const timestamp = this.#defaults.logTimestamps ? `[${new Date().toISOString()}] ` : '';
console.log(colors[color](`${timestamp}[${this.callId}]: ${msg}`));
}

async read (messages, mode = 'tap', options = {}) {
Expand Down
1 change: 1 addition & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
printLog: false,
logTimestamps: false,
removeInvalidChars: false,
read: {
// val_name is dynamic generated
Expand Down
8 changes: 6 additions & 2 deletions lib/yemot_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { parse as parseStack } from 'stack-trace';
function YemotRouter (options = {}) {
const ops = {
printLog: options.printLog,
logTimestamps: options.logTimestamps,
timeout: options.timeout,
uncaughtErrorHandler: options.uncaughtErrorHandler || null,
defaults: options.defaults || {}
Expand All @@ -29,6 +30,7 @@ function YemotRouter (options = {}) {

let mergedDefaults = {
printLog: ops.printLog ?? globalDefaults.printLog,
logTimestamps: ops.logTimestamps ?? globalDefaults.logTimestamps,
removeInvalidChars: ops.defaults?.removeInvalidChars ?? globalDefaults.removeInvalidChars,
read: {
timeout: ops.timeout ?? globalDefaults.read.timeout,
Expand Down Expand Up @@ -56,7 +58,8 @@ function YemotRouter (options = {}) {

function logger (callId, msg, color = 'blue') {
if (!(ops.printLog ?? mergedDefaults.printLog)) return;
console.log(colors[color](`[${callId}]: ${msg}`));
const timestamp = (ops.logTimestamps ?? mergedDefaults.logTimestamps) ? `[${new Date().toISOString()}] ` : '';
console.log(colors[color](`${timestamp}[${callId}]: ${msg}`));
}

function deleteCall (callId) {
Expand Down Expand Up @@ -95,7 +98,8 @@ function YemotRouter (options = {}) {
const [trace] = parseStack(err);
const errorPath = `${trace.getFileName()}:${trace.getLineNumber()}:${trace.getColumnNumber()}`;
if (err instanceof ExitError) {
console.log(`👋 the call was exited from the extension /${call.extension} in uncaughtErrorHandler ${errorPath}` + (error.context ? ` (by ${error.context?.caller} to ${error.context?.target})` : ''));
const timestamp = (ops.logTimestamps ?? mergedDefaults.logTimestamps) ? `[${new Date().toISOString()}] ` : '';
console.log(`${timestamp}👋 the call was exited from the extension /${call.extension} in uncaughtErrorHandler ${errorPath}` + (error.context ? ` (by ${error.context?.caller} to ${error.context?.target})` : ''));
} else {
console.error('💥 Error in uncaughtErrorHandler! process is crashing');
throw err;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yemot-router2",
"version": "6.2.0",
"version": "6.3.0",
"description": "",
"exports": {
"import": "./index.js",
Expand Down