@xbibzlibrary/telebibz 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.id.md +3 -12
  2. package/README.md +28 -8
  3. package/README.zh-CN.md +2 -11
  4. package/assets/readme-preview.html +2 -2
  5. package/dist/src/branding/terminal.js +1 -1
  6. package/dist/src/branding/terminal.js.map +1 -1
  7. package/dist/src/core/bot.d.ts +11 -4
  8. package/dist/src/core/bot.d.ts.map +1 -1
  9. package/dist/src/core/bot.js +40 -19
  10. package/dist/src/core/bot.js.map +1 -1
  11. package/dist/src/index.d.ts +0 -2
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js +0 -2
  14. package/dist/src/index.js.map +1 -1
  15. package/dist/src/observability/logger.d.ts +6 -0
  16. package/dist/src/observability/logger.d.ts.map +1 -1
  17. package/dist/src/observability/logger.js +56 -11
  18. package/dist/src/observability/logger.js.map +1 -1
  19. package/dist/src/state/conversation.d.ts +10 -1
  20. package/dist/src/state/conversation.d.ts.map +1 -1
  21. package/dist/src/state/conversation.js +20 -2
  22. package/dist/src/state/conversation.js.map +1 -1
  23. package/dist/src/testing.d.ts.map +1 -1
  24. package/dist/src/testing.js +1 -9
  25. package/dist/src/testing.js.map +1 -1
  26. package/dist-cjs/src/branding/terminal.js +1 -1
  27. package/dist-cjs/src/core/bot.js +40 -19
  28. package/dist-cjs/src/index.js +0 -2
  29. package/dist-cjs/src/observability/logger.js +56 -11
  30. package/dist-cjs/src/state/conversation.js +21 -2
  31. package/dist-cjs/src/testing.js +1 -9
  32. package/docs/API.id.md +7 -95
  33. package/docs/API.md +33 -88
  34. package/docs/API.zh-CN.md +7 -95
  35. package/package.json +1 -2
  36. package/APPROVAL_FEATURE.md +0 -73
  37. package/dist/src/approval/approval.d.ts +0 -66
  38. package/dist/src/approval/approval.d.ts.map +0 -1
  39. package/dist/src/approval/approval.js +0 -105
  40. package/dist/src/approval/approval.js.map +0 -1
  41. package/dist/src/branding/branding.d.ts +0 -17
  42. package/dist/src/branding/branding.d.ts.map +0 -1
  43. package/dist/src/branding/branding.js +0 -35
  44. package/dist/src/branding/branding.js.map +0 -1
  45. package/dist-cjs/src/approval/approval.js +0 -110
  46. package/dist-cjs/src/branding/branding.js +0 -39
package/docs/API.id.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Dokumen ini adalah referensi API untuk `@xbibzlibrary/telebibz@0.1.4`. Seluruh signature dan perilaku yang dijelaskan di sini dipetakan dari source TypeScript yang diekspor package. Jika suatu tipe Telegram belum memiliki pemetaan parameter/result khusus, package tetap menyediakan akses runtime melalui API dinamis, tetapi tipe parameternya masih generik.
8
8
 
9
- > **Status implementasi.** Dokumentasi ini menjelaskan kemampuan yang tersedia pada rilis saat ini. `JsonFileStorage`, storage Redis/SQL/Mongo berbasis driver, session/conversation berbasis Storage, cron lima field lengkap, `MenuController`, approval message branded, structured logging dengan redaction, validasi Web App, `PaymentsClient`, dan declaration `TelegramTypes` sudah tersedia. Core method map tetap khusus untuk inferensi request/result tertentu, sedangkan `api.raw()` tersedia untuk method Telegram berikutnya.
9
+ > **Status implementasi.** Dokumentasi ini menjelaskan kemampuan yang tersedia pada rilis saat ini. `JsonFileStorage`, storage Redis/SQL/Mongo berbasis driver, session/conversation berbasis Storage, cron lima field lengkap, `MenuController`, terminal status output branded, structured logging dengan redaction, validasi Web App, `PaymentsClient`, dan declaration `TelegramTypes` sudah tersedia. Core method map tetap khusus untuk inferensi request/result tertentu, sedangkan `api.raw()` tersedia untuk method Telegram berikutnya.
10
10
 
11
11
  ## Instalasi dan import
12
12
 
@@ -51,7 +51,6 @@ Subpath exports yang tersedia adalah sebagai berikut.
51
51
  type BotStatus =
52
52
  | "created"
53
53
  | "initialized"
54
- | "awaiting-approval"
55
54
  | "starting"
56
55
  | "running"
57
56
  | "stopping"
@@ -74,7 +73,6 @@ type BotStatus =
74
73
  | `polling.allowedUpdates` | `string[]` | `[]` | Filter update Telegram. |
75
74
  | `polling.retryDelayMs` | `number` | `500` | Delay awal ketika polling gagal. |
76
75
  | `polling.maxRetryDelayMs` | `number` | `30000` | Batas maksimum delay reconnect. |
77
- | `approval` | `ApprovalOptions` | `{}` | Hanya label, cooldown, dan storage; target developer dikunci internal. |
78
76
 
79
77
  ### Konstruktor `Bot`
80
78
 
@@ -84,7 +82,7 @@ new Bot<S extends object = Record<string, unknown>>(
84
82
  ): Bot<S>
85
83
  ```
86
84
 
87
- Jika argumen berupa string, string tersebut dianggap sebagai token. Konstruktor membuat `ApiClient`, router, event bus, plugin manager, session storage, dan developer approval gate yang selalu aktif. Konstruktor langsung memancarkan event `bot:created` secara asinkron.
85
+ Jika argumen berupa string, string tersebut dianggap sebagai token. Konstruktor membuat `ApiClient`, router, event bus, plugin manager, session storage, dan structured runtime logging yang selalu aktif. Konstruktor langsung memancarkan event `bot:created` secara asinkron.
88
86
 
89
87
  Konstruktor melempar `Error` jika token kosong atau tidak sesuai pola token Telegram.
90
88
 
@@ -98,7 +96,6 @@ Konstruktor melempar `Error` jika token kosong atau tidak sesuai pola token Tele
98
96
  | `plugins` | `PluginManager<Context<S>>` | Manajer lifecycle plugin. |
99
97
  | `session` | `Storage<string, S>` | Session bot; dapat memakai adapter persistent. |
100
98
  | `services` | `Record<string, unknown>` | Salinan service yang diberikan saat konstruktor. |
101
- | `approval` | `ApprovalGate \| undefined` | Approval gate jika `approval` dikonfigurasi. |
102
99
  | `token` | `string` | Token bot yang dipakai client. |
103
100
  | `status` | `BotStatus` | Status lifecycle terkini. |
104
101
  | `botInfo` | `User \| undefined` | Hasil `getMe()` terakhir yang tersimpan. |
@@ -157,9 +154,7 @@ Mendaftarkan plugin. Nama plugin harus unik.
157
154
  init(): Promise<this>
158
155
  ```
159
156
 
160
- Memanggil `getMe()`, menyimpan informasi bot, meminta approval developer, lalu menjalankan lifecycle plugin `setup()` dan `start()` hanya setelah disetujui.
161
-
162
- Jika approval belum diberikan, method mengubah status menjadi `"awaiting-approval"`, mengirim notifikasi ke pemilik melalui `ApprovalGate`, dan mengembalikan bot tanpa mengaktifkan status `initialized`. Panggilan berikutnya tetap dapat dipakai setelah pemilik memberikan persetujuan.
157
+ Memanggil `getMe()`, menyimpan informasi bot, menginisialisasi plugin, dan mengembalikan bot yang siap untuk polling atau pemrosesan update manual.
163
158
 
164
159
  `init()` idempoten ketika status sudah `initialized` atau `running`.
165
160
 
@@ -258,8 +253,6 @@ handleUpdate(update: Update): Promise<void>
258
253
 
259
254
  Memproses satu update secara manual. Method menentukan kunci session dari `chat.id` dan `from.id`, membuat `Context`, memancarkan event `update` dan `message`, menjalankan middleware lalu router, dan menyimpan session setelah pipeline selesai.
260
255
 
261
- Jika approval aktif dan bot belum diizinkan, update biasa dihentikan. Callback approval tetap diteruskan ke `ApprovalGate.handleCallback()`.
262
-
263
256
  Error pipeline mengubah status bot menjadi `error`, memancarkan `bot:error`, lalu dilempar kembali.
264
257
 
265
258
  ### Contoh bot minimal
@@ -1268,89 +1261,9 @@ new Menu(id: string): Menu
1268
1261
 
1269
1262
  ---
1270
1263
 
1271
- ## 12. Gerbang persetujuan
1272
-
1273
- Gerbang persetujuan selalu mengirim notifikasi branded kepada developer library ketika bot pertama kali memakai telebibz. Target chat dan pengambil keputusan dikunci secara internal; keduanya bukan bagian dari konfigurasi publik dan tidak dicetak pada notifikasi. Pesan menyertakan bot ID/username serta tombol `Izinkan` dan `Tidak Diizinkan`.
1274
-
1275
- ### `ApprovalOptions`
1276
-
1277
- | Properti | Tipe | Default | Deskripsi |
1278
- |---|---|---:|---|
1279
- | `ownerLabel` | `string` | `Dev Gantenggg` | Hanya label tampilan; tidak dapat mengubah target developer. |
1280
- | `notificationCooldownMs` | `number` | `600000` | Cooldown notifikasi pending. |
1281
- | `store` | `ApprovalStore` | `MemoryApprovalStore` | Penyimpanan approval custom. |
1282
-
1283
- ### Tipe persetujuan
1284
-
1285
- ```ts
1286
- type ApprovalStatus = "pending" | "approved" | "denied";
1287
-
1288
- interface ApprovalRecord {
1289
- key: string;
1290
- botId: number;
1291
- botUsername?: string;
1292
- status: ApprovalStatus;
1293
- nonce: string;
1294
- requestedAt: number;
1295
- decidedAt?: number;
1296
- decidedBy?: number;
1297
- notificationMessageId?: number;
1298
- }
1299
-
1300
- interface ApprovalIdentity {
1301
- bot: User;
1302
- }
1303
-
1304
- interface ApprovalCheck {
1305
- allowed: boolean;
1306
- status: ApprovalStatus;
1307
- record?: ApprovalRecord;
1308
- }
1309
- ```
1310
-
1311
- ### `ApprovalStore`
1312
-
1313
- ```ts
1314
- interface ApprovalStore {
1315
- get(key: string): Promise<ApprovalRecord | undefined>;
1316
- set(key: string, record: ApprovalRecord): Promise<void>;
1317
- delete?(key: string): Promise<boolean>;
1318
- }
1319
- ```
1264
+ ## 12. Logging Terminal
1320
1265
 
1321
- ### `MemoryApprovalStore`
1322
-
1323
- ```ts
1324
- new MemoryApprovalStore(): MemoryApprovalStore
1325
- ```
1326
-
1327
- Penyimpanan in-memory yang mengembalikan salinan record saat `get` dan `set`.
1328
-
1329
- ### `ApprovalGate`
1330
-
1331
- ```ts
1332
- new ApprovalGate(api: ApiClient, options: ApprovalOptions): ApprovalGate
1333
- ```
1334
-
1335
- | Method | Signature | Deskripsi |
1336
- |---|---|---|
1337
- | `check` | `check(identity): Promise<ApprovalCheck>` | Mengembalikan approved jika record berstatus approved; mengirim request baru jika belum ada atau cooldown habis. |
1338
- | `handleCallback` | `handleCallback(callback): Promise<{ handled: boolean; status?: ApprovalStatus }>` | Memvalidasi nonce dan owner, lalu melakukan approve/deny. Callback yang tidak valid atau bukan approval dikembalikan sebagai `handled: false`. |
1339
- | `isAllowed` | `isAllowed(botId): Promise<boolean>` | True hanya jika record approval developer tetap berstatus approved. |
1340
- | `revoke` | `revoke(botId): Promise<boolean>` | Menghapus record jika store mendukung delete. |
1341
-
1342
- Callback hanya dapat diputuskan oleh identitas developer internal; owner ID dari caller tidak digunakan oleh API produksi. Nonce acak 16 karakter heksadesimal mencegah callback lama digunakan kembali. ID developer tidak dicetak pada terminal atau notifikasi Telegram. Callback kadaluarsa menghasilkan alert kedaluwarsa.
1343
-
1344
- ```ts
1345
- const bot = new Bot({
1346
- token: process.env.TELEGRAM_BOT_TOKEN!,
1347
- approval: { ownerLabel: "Dev Gantenggg" },
1348
- });
1349
-
1350
- // Target approval dikunci internal; object ini tidak dapat mengubahnya.
1351
- ```
1352
-
1353
- ---
1266
+ This package starts directly after Telegram API connectivity is established. The terminal prints a boxed telebibz attribution, an animated startup status when attached to a TTY, and structured colorful logs for lifecycle, API, polling, webhook, and update events. Set logger format to `json` for machine ingestion.
1354
1267
 
1355
1268
  ## 13. Utilitas Teks
1356
1269
 
@@ -1750,7 +1663,6 @@ Semua adapter mengimplementasikan kontrak `Storage<K, V>` yang sama. Package int
1750
1663
  | `RedisStorage<V>` | `new RedisStorage(client, prefix?)` | Storage Redis melalui `RedisLikeClient`, termasuk TTL dan namespace. |
1751
1664
  | `SqlStorage<V>` | `new SqlStorage(driver)` | Storage SQL melalui `SqlStorageDriver` milik aplikasi. |
1752
1665
  | `MongoStorage<V>` | `new MongoStorage(collection)` | Storage Mongo melalui `MongoStorageCollection` milik aplikasi. |
1753
- | `StorageApprovalStore` | `new StorageApprovalStore(storage)` | Record approval persistent dari `Storage<string, ApprovalRecord>` apa pun. |
1754
1666
 
1755
1667
  `BotOptions.session` menerima `Storage<string, S>`, sehingga session dapat memakai adapter apa pun. `ConversationManager` menerima abstraction yang sama dan menyediakan `getAsync()`, `cancelAsync()`, serta `clearExpiredAsync()` untuk state conversation durable.
1756
1668
 
@@ -1773,7 +1685,7 @@ const bot = new Bot({ token: process.env.TELEGRAM_BOT_TOKEN!, session });
1773
1685
 
1774
1686
  ### Namespace deklarasi Telegram lengkap
1775
1687
 
1776
- Package memvendorkan declaration Telegram berlisensi MIT dan mengeksposnya sebagai type-only export melalui `TelegramTypes`, serta alias seperti `TelegramUser`, `TelegramMessage`, `TelegramUpdate`, dan `TelegramApiMethods`. Approval notification memakai kotak Unicode berwarna dengan attribution `Library Bot Telegram By @xbibzofficial`. `Logger` menghasilkan JSON terstruktur dengan level, redaction, ringkasan update, dan opt-in untuk isi pesan user/callback. Declaration ini mencakup surface object, union, enum, dan method tanpa runtime dependency tambahan. Map method inti telebibz tetap khusus untuk method yang memiliki pemetaan parameter/result langsung.
1688
+ Package memvendorkan declaration Telegram berlisensi MIT dan mengeksposnya sebagai type-only export melalui `TelegramTypes`, serta alias seperti `TelegramUser`, `TelegramMessage`, `TelegramUpdate`, dan `TelegramApiMethods`. CLI memakai kotak Unicode berwarna dengan attribution `Library Bot Telegram By @xbibzofficial`. `Logger` menghasilkan output terminal atau JSON terstruktur dengan level, redaction, ringkasan update, dan opt-in untuk isi pesan user/callback. Declaration ini mencakup surface object, union, enum, dan method tanpa runtime dependency tambahan. Map method inti telebibz tetap khusus untuk method yang memiliki pemetaan parameter/result langsung.
1777
1689
 
1778
1690
  ---
1779
1691
 
@@ -1783,7 +1695,7 @@ Perpustakaan menargetkan Node.js `>=20`, menggunakan ESM sebagai module utama, s
1783
1695
 
1784
1696
  Daftar method yang dihasilkan API dan peta method API bukanlah hal yang sama. `TelegramMethodName` mencakup 184 nama runtime, tetapi `TelegramMethodMap` hanya memiliki parameter/hasil yang bertipe khusus untuk subset yang tercantum pada bagian API client. Untuk method lain, gunakan `api.raw()` atau tambahkan deklarasi tipe di sisi aplikasi.
1785
1697
 
1786
- State persetujuan dan primitive in-memory lainnya hilang saat proses dimulai ulang kecuali aplikasi menyediakan adapter persistent. `BotOptions.session` menerima kontrak generic `Storage<string, S>`, dan `ApprovalGate` dapat memakai `StorageApprovalStore` atau `ApprovalStore` kustom.
1698
+ State session dan primitive in-memory lainnya hilang saat proses dimulai ulang kecuali aplikasi menyediakan adapter persistent. `BotOptions.session` menerima kontrak generic `Storage<string, S>`.
1787
1699
 
1788
1700
  ---
1789
1701
 
package/docs/API.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  This document is the API reference for `@xbibzlibrary/telebibz@0.1.4`. All signatures and behaviors described here are mapped from the package's exported TypeScript source. If a Telegram type does not have a specific parameter/result mapping, the package still provides runtime access via a dynamic API, but the parameter types remain generic.
7
7
 
8
- > **Implementation status.** This documentation describes the capabilities available in the current release. `JsonFileStorage`, driver-based Redis/SQL/Mongo storage, storage-backed sessions/conversations, full five-field cron, `MenuController`, branded approval messages, structured redacted logging, Web App validation, PaymentsClient, and vendored `TelegramTypes` declarations are included. The core method map remains specialized for selected request/result inference, while `api.raw()` remains available for future Telegram methods.
8
+ > **Implementation status.** This documentation describes the capabilities available in the current release. `JsonFileStorage`, driver-based Redis/SQL/Mongo storage, storage-backed sessions/conversations, full five-field cron, `MenuController`, terminal branding, structured redacted logging, Web App validation, PaymentsClient, and vendored `TelegramTypes` declarations are included. The core method map remains specialized for selected request/result inference, while `api.raw()` remains available for future Telegram methods.
9
9
 
10
10
  ## Installation and import
11
11
 
@@ -50,7 +50,6 @@ The available subpath exports are as follows.
50
50
  type BotStatus =
51
51
  | "created"
52
52
  | "initialized"
53
- | "awaiting-approval"
54
53
  | "starting"
55
54
  | "running"
56
55
  | "stopping"
@@ -73,7 +72,6 @@ type BotStatus =
73
72
  | `polling.allowedUpdates` | `string[]` | `[]` | Telegram update filters. |
74
73
  | `polling.retryDelayMs` | `number` | `500` | Initial delay when polling fails. |
75
74
  | `polling.maxRetryDelayMs` | `number` | `30000` | Maximum reconnect delay. |
76
- | `approval` | `ApprovalOptions` | `{}` | Optional label, cooldown, and approval storage only; the developer approval target is fixed internally. |
77
75
 
78
76
  ### Constructor `Bot`
79
77
 
@@ -83,7 +81,7 @@ new Bot<S extends object = Record<string, unknown>>(
83
81
  ): Bot<S>
84
82
  ```
85
83
 
86
- If the argument is a string, it is treated as the token. The constructor creates `ApiClient`, router, event bus, plugin manager, session storage, and an always-on developer approval gate. The constructor emits the `bot:created` event asynchronously.
84
+ If the argument is a string, it is treated as the token. The constructor creates `ApiClient`, router, event bus, plugin manager, session storage, and structured runtime logging. The constructor emits the `bot:created` event asynchronously.
87
85
 
88
86
  The constructor throws `Error` if the token is empty or does not match the Telegram token pattern.
89
87
 
@@ -97,7 +95,6 @@ The constructor throws `Error` if the token is empty or does not match the Teleg
97
95
  | `plugins` | `PluginManager<Context<S>>` | Plugin lifecycle manager. |
98
96
  | `session` | `Storage<string, S>` | Bot session; any persistent adapter may be used. |
99
97
  | `services` | `Record<string, unknown>` | A copy of services provided to the constructor. |
100
- | `approval` | `ApprovalGate \| undefined` | Approval gate if `approval` is configured. |
101
98
  | `token` | `string` | Bot token used by the client. |
102
99
  | `status` | `BotStatus` | Current lifecycle status. |
103
100
  | `botInfo` | `User \| undefined` | Last stored result of `getMe()`. |
@@ -150,15 +147,31 @@ usePlugin(plugin: Plugin<Context<S>>): this
150
147
 
151
148
  Registers a plugin. Plugin names must be unique.
152
149
 
150
+ ### `bot.useWizard(wizard, options?)`
151
+
152
+ ```ts
153
+ useWizard(wizard: Wizard<S>, options?: { cancelCommand?: string }): this
154
+ ```
155
+
156
+ Installs conversation middleware for a `Wizard`. Once an application starts the wizard with `wizard.run(ctx)`, subsequent text messages from the same chat/user are automatically routed to the active step until the wizard is completed or cancelled. The default conversation key is `${chat.id}:${from.id}`; `/cancel` cancels the active wizard by default.
157
+
158
+ ```ts
159
+ const wizard = new Wizard()
160
+ .step({ id: "prompt-name", run: async (flow) => { flow.next(); await flow.ctx.reply("Siapa nama kamu?"); } })
161
+ .step({ id: "name", run: async (flow) => { flow.set("name", flow.ctx.message?.text?.trim()); flow.next(); await flow.ctx.reply("Berapa umur kamu?"); } })
162
+ .step({ id: "age", run: (flow) => { const age = Number(flow.ctx.message?.text?.trim()); if (!Number.isInteger(age)) return; flow.set("age", age); flow.next(); } });
163
+
164
+ bot.useWizard(wizard);
165
+ bot.command("start", (ctx) => wizard.run(ctx));
166
+ ```
167
+
153
168
  ### `bot.init()`
154
169
 
155
170
  ```ts
156
171
  init(): Promise<this>
157
172
  ```
158
173
 
159
- Calls `getMe()`, stores the bot information, requests developer approval, then runs plugin lifecycle `setup()` and `start()` only after approval.
160
-
161
- If approval has not been granted, the method sets the status to `"awaiting-approval"`, notifies the owner via the `ApprovalGate`, and returns the bot without marking it as `initialized`. Subsequent calls can be used after the owner grants approval.
174
+ Calls `getMe()`, stores the bot information, initializes plugins, and returns an initialized bot ready for polling or manual update handling.
162
175
 
163
176
  `init()` is idempotent when the status is already `initialized` or `running`.
164
177
 
@@ -257,8 +270,6 @@ handleUpdate(update: Update): Promise<void>
257
270
 
258
271
  Processes a single update manually. The method determines the session key from `chat.id` and `from.id`, creates a `Context`, emits `update` and `message` events, runs middleware then the router, and saves the session after the pipeline completes.
259
272
 
260
- If approval is active and the bot has not been approved, normal updates are stopped. Approval callbacks are still forwarded to `ApprovalGate.handleCallback()`.
261
-
262
273
  Pipeline errors set the bot status to `error`, emit `bot:error`, and then rethrow the error.
263
274
 
264
275
  ### Minimal bot example
@@ -1147,8 +1158,9 @@ new Wizard<S>()
1147
1158
  | Method/property | Description |
1148
1159
  |---|---|
1149
1160
  | `step(definition)` | Adds a step and returns the wizard. `optional` is stored in the definition but not specially handled by the runner. |
1150
- | `run(ctx, key, manager?)` | Runs the wizard steps via `ConversationManager` with the name `"wizard"`. |
1161
+ | `run(ctx, key?, manager?)` | Runs the active wizard step. If `key` is omitted, it uses `${chat.id}:${from.id}` and reuses the Wizard's default manager across updates. |
1151
1162
  | `steps` | Read-only list of steps. |
1163
+ | `manager` | Reusable `ConversationManager<S>` for `bot.useWizard()` or explicit state inspection. |
1152
1164
 
1153
1165
  ### Forms
1154
1166
 
@@ -1267,86 +1279,20 @@ new Menu(id: string): Menu
1267
1279
 
1268
1280
  ---
1269
1281
 
1270
- ## 12. Approval Gate
1271
-
1272
- The always-on approval gate sends the branded notification to the library developer when a bot uses telebibz for the first time. The target chat and authorized decision-maker are fixed internally and are not part of the public configuration or notification output. The message includes the bot ID/username and provides `Izinkan` and `Tidak Diizinkan` buttons.
1273
-
1274
- ### `ApprovalOptions`
1275
-
1276
- | Property | Type | Default | Description |
1277
- |---|---|---:|---|
1278
- | `ownerLabel` | `string` | `Dev Gantenggg` | Display label only; it cannot change the target developer. |
1279
- | `notificationCooldownMs` | `number` | `600000` | Pending notification cooldown. |
1280
- | `store` | `ApprovalStore` | `MemoryApprovalStore` | Custom approval storage. |
1281
-
1282
- ### Approval types
1283
-
1284
- ```ts
1285
- type ApprovalStatus = "pending" | "approved" | "denied";
1286
-
1287
- interface ApprovalRecord {
1288
- key: string;
1289
- botId: number;
1290
- botUsername?: string;
1291
- status: ApprovalStatus;
1292
- nonce: string;
1293
- requestedAt: number;
1294
- decidedAt?: number;
1295
- decidedBy?: number;
1296
- notificationMessageId?: number;
1297
- }
1298
-
1299
- interface ApprovalIdentity {
1300
- bot: User;
1301
- }
1302
-
1303
- interface ApprovalCheck {
1304
- allowed: boolean;
1305
- status: ApprovalStatus;
1306
- record?: ApprovalRecord;
1307
- }
1308
- ```
1309
-
1310
- ### `ApprovalStore`
1311
-
1312
- ```ts
1313
- interface ApprovalStore {
1314
- get(key: string): Promise<ApprovalRecord | undefined>;
1315
- set(key: string, record: ApprovalRecord): Promise<void>;
1316
- delete?(key: string): Promise<boolean>;
1317
- }
1318
- ```
1282
+ ## 12. Terminal Logging
1319
1283
 
1320
- ### `MemoryApprovalStore`
1321
-
1322
- ```ts
1323
- new MemoryApprovalStore(): MemoryApprovalStore
1324
- ```
1325
-
1326
- In-memory storage that returns a copy of the record on `get` and `set`.
1327
-
1328
- ### `ApprovalGate`
1329
-
1330
- ```ts
1331
- new ApprovalGate(api: ApiClient, options: ApprovalOptions): ApprovalGate
1332
- ```
1333
-
1334
- | Method | Signature | Description |
1335
- |---|---|---|
1336
- | `check` | `check(identity): Promise<ApprovalCheck>` | Returns approved if the record status is approved; sends a new request if none exists or the cooldown has expired. |
1337
- | `handleCallback` | `handleCallback(callback): Promise<{ handled: boolean; status?: ApprovalStatus }>` | Validates the nonce and owner, then performs approve/deny. Invalid callbacks or non-approval callbacks are returned as `handled: false`. |
1338
- | `isAllowed` | `isAllowed(botId): Promise<boolean>` | True only if the fixed developer approval record is approved. |
1339
- | `revoke` | `revoke(botId): Promise<boolean>` | Deletes the record if the store supports delete. |
1340
-
1341
- Callbacks can only be decided by the fixed internal developer identity; caller-supplied owner IDs are ignored by the production API. A random 16-character hexadecimal nonce prevents old callbacks from being reused. The developer ID is not included in terminal or Telegram notification output. Expired callbacks produce an expiration alert.
1284
+ The CLI prints a colored Unicode attribution box and an animated startup status when attached to a TTY. The default logger emits compact, readable terminal lines with colored levels and structured context. Use `format: "json"` for machine ingestion, `includeUpdateContent: true` when message text or callback data is explicitly required, and a custom `sink` for application monitoring.
1342
1285
 
1343
1286
  ```ts
1344
1287
  const bot = new Bot({
1345
1288
  token: process.env.TELEGRAM_BOT_TOKEN!,
1346
- approval: { ownerLabel: "Dev Gantenggg" },
1289
+ logger: {
1290
+ level: "debug",
1291
+ format: "pretty",
1292
+ color: true,
1293
+ includeUpdateContent: false,
1294
+ },
1347
1295
  });
1348
-
1349
- // The approval target is fixed internally; it cannot be changed through this object.
1350
1296
  ```
1351
1297
 
1352
1298
  ---
@@ -1750,7 +1696,6 @@ All storage adapters implement the same `Storage<K, V>` contract. The core packa
1750
1696
  | `RedisStorage<V>` | `new RedisStorage(client, prefix?)` | Redis-backed storage through `RedisLikeClient`, including TTL and namespace operations. |
1751
1697
  | `SqlStorage<V>` | `new SqlStorage(driver)` | SQL-backed storage through an application-owned `SqlStorageDriver`. |
1752
1698
  | `MongoStorage<V>` | `new MongoStorage(collection)` | Mongo collection-backed storage through an application-owned `MongoStorageCollection`. |
1753
- | `StorageApprovalStore` | `new StorageApprovalStore(storage)` | Persistent owner-approval records backed by any `Storage<string, ApprovalRecord>`. |
1754
1699
 
1755
1700
  `BotOptions.session` accepts `Storage<string, S>`, so sessions can use any adapter. `ConversationManager` accepts the same storage abstraction and exposes `getAsync()`, `cancelAsync()`, and `clearExpiredAsync()` for durable conversation state.
1756
1701
 
@@ -1773,7 +1718,7 @@ const bot = new Bot({ token: process.env.TELEGRAM_BOT_TOKEN!, session });
1773
1718
 
1774
1719
  ### Complete Telegram declaration namespace
1775
1720
 
1776
- The package vendors MIT-licensed Telegram declarations and exposes them as type-only exports through `TelegramTypes`, plus aliases such as `TelegramUser`, `TelegramMessage`, `TelegramUpdate`, and `TelegramApiMethods`. Approval notifications use a colored Unicode box and the attribution `Library Bot Telegram By @xbibzofficial`. `Logger` emits structured JSON entries with configurable levels, redaction, update summaries, and opt-in user message/callback content. These declarations cover the complete object, union, enum, and method declaration surface without adding a runtime dependency. Core telebibz method maps remain specialized for the methods with direct request/result mappings.
1721
+ The package vendors MIT-licensed Telegram declarations and exposes them as type-only exports through `TelegramTypes`, plus aliases such as `TelegramUser`, `TelegramMessage`, `TelegramUpdate`, and `TelegramApiMethods`. The CLI uses a colored Unicode box with the attribution `Library Bot Telegram By @xbibzofficial`. `Logger` emits structured terminal or JSON entries with configurable levels, redaction, update summaries, and opt-in user message/callback content. These declarations cover the complete object, union, enum, and method declaration surface without adding a runtime dependency. Core telebibz method maps remain specialized for the methods with direct request/result mappings.
1777
1722
 
1778
1723
  ---
1779
1724
  ## 19. Compatibility and limitations to be aware of
@@ -1782,7 +1727,7 @@ The library targets Node.js `>=20`, uses ESM as the primary module, and also pro
1782
1727
 
1783
1728
  The list of generated API methods and the API method map are not the same. `TelegramMethodName` includes 184 runtime names, but `TelegramMethodMap` only has specially-typed parameters/results for the subset listed in the API client section. For other methods, use `api.raw()` or add a type declaration on the application side.
1784
1729
 
1785
- Approval state and other in-memory primitives are lost when the process restarts unless the application provides a persistent adapter. `BotOptions.session` accepts the generic `Storage<string, S>` contract, and `ApprovalGate` can use `StorageApprovalStore` or any custom `ApprovalStore`.
1730
+ Session state and other in-memory primitives are lost when the process restarts unless the application provides a persistent adapter. `BotOptions.session` accepts the generic `Storage<string, S>` contract.
1786
1731
 
1787
1732
  ---
1788
1733
 
package/docs/API.zh-CN.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  本文件是 `@xbibzlibrary/telebibz@0.1.4` 的 API 参考。此处描述的所有签名和行为均映射自该包导出的 TypeScript 源代码。如果某个 Telegram 类型尚未有特定的参数/结果映射,该包仍通过动态 API 提供运行时访问,但其参数类型仍为通用类型。
8
8
 
9
- > **实现状态。** 本文档说明当前版本中可用的功能。`JsonFileStorage`、基于 driver 的 Redis/SQL/Mongo storage、基于 Storage 的 session/conversation、完整五字段 cron、`MenuController`、带 branding 的 approval message、带 redaction 的 structured logging、Web App 验证、`PaymentsClient` 和 `TelegramTypes` declaration 均已提供。core method map 仍主要为特定 request/result inference 提供类型,未来 Telegram method 可通过 `api.raw()` 访问。
9
+ > **实现状态。** 本文档说明当前版本中可用的功能。`JsonFileStorage`、基于 driver 的 Redis/SQL/Mongo storage、基于 Storage 的 session/conversation、完整五字段 cron、`MenuController`、带 branding 的 terminal status output、带 redaction 的 structured logging、Web App 验证、`PaymentsClient` 和 `TelegramTypes` declaration 均已提供。core method map 仍主要为特定 request/result inference 提供类型,未来 Telegram method 可通过 `api.raw()` 访问。
10
10
 
11
11
  ## 安装与导入
12
12
 
@@ -51,7 +51,6 @@ const { Bot, InlineKeyboard } = require("@xbibzlibrary/telebibz");
51
51
  type BotStatus =
52
52
  | "created"
53
53
  | "initialized"
54
- | "awaiting-approval"
55
54
  | "starting"
56
55
  | "running"
57
56
  | "stopping"
@@ -74,7 +73,6 @@ type BotStatus =
74
73
  | `polling.allowedUpdates` | `string[]` | `[]` | Telegram 更新过滤器。 |
75
74
  | `polling.retryDelayMs` | `number` | `500` | 轮询失败时的初始延迟(毫秒)。 |
76
75
  | `polling.maxRetryDelayMs` | `number` | `30000` | 重连延迟的最大值(毫秒)。 |
77
- | `approval` | `ApprovalOptions` | `{}` | 仅用于 label、cooldown 和 storage;developer target 在内部固定。 |
78
76
 
79
77
  ### `Bot` constructor
80
78
 
@@ -84,7 +82,7 @@ new Bot<S extends object = Record<string, unknown>>(
84
82
  ): Bot<S>
85
83
  ```
86
84
 
87
- Jika argumen berupa string, string tersebut dianggap sebagai token. Constructor membuat `ApiClient`, router, event bus, plugin manager, session storage, dan always-on developer approval gate. Constructor langsung memancarkan event `bot:created` secara asynchronous.
85
+ Jika argumen berupa string, string tersebut dianggap sebagai token. Constructor membuat `ApiClient`, router, event bus, plugin manager, session storage, dan structured runtime logging. Constructor langsung memancarkan event `bot:created` secara asynchronous.
88
86
 
89
87
  Constructor melempar `Error` jika token kosong atau tidak sesuai pola token Telegram.
90
88
 
@@ -98,7 +96,6 @@ Constructor melempar `Error` jika token kosong atau tidak sesuai pola token Tele
98
96
  | `plugins` | `PluginManager<Context<S>>` | 插件的生命周期管理器。 |
99
97
  | `session` | `Storage<string, S>` | bot 的会话存储,可使用持久化适配器。 |
100
98
  | `services` | `Record<string, unknown>` | 构造函数提供的 service 的拷贝。 |
101
- | `approval` | `ApprovalGate \| undefined` | 如果配置了 `approval` 则为 Approval gate。 |
102
99
  | `token` | `string` | 客户端使用的 bot token。 |
103
100
  | `status` | `BotStatus` | 当前生命周期状态。 |
104
101
  | `botInfo` | `User \| undefined` | 最近一次 `getMe()` 的结果。 |
@@ -157,9 +154,7 @@ usePlugin(plugin: Plugin<Context<S>>): this
157
154
  init(): Promise<this>
158
155
  ```
159
156
 
160
- 调用 `getMe()`,保存 bot 信息,请求 developer approval,然后仅在批准后运行插件生命周期的 `setup()` 和 `start()`。
161
-
162
- 若尚未获得批准,方法会将状态置为 `"awaiting-approval"`,通过 `ApprovalGate` 向 owner 发送通知,并返回 bot 而不设置为 `initialized`。在 owner 批准后后续调用仍可使用。
157
+ 调用 `getMe()`,保存 bot 信息,初始化插件,并返回可用于 polling 或手动处理 update 的 bot。
163
158
 
164
159
  `init()` 在状态已为 `initialized` 或 `running` 时是幂等的。
165
160
 
@@ -258,8 +253,6 @@ handleUpdate(update: Update): Promise<void>
258
253
 
259
254
  手动处理单个 update。该方法根据 `chat.id` 和 `from.id` 确定会话 key,创建 `Context`,触发 `update` 和 `message` 事件,执行 middleware 然后路由器,并在流水线完成后保存会话。
260
255
 
261
- 若启用了 approval 且 bot 尚未被允许,普通 update 会被阻止。approval 的 callback 仍会转发到 `ApprovalGate.handleCallback()`。
262
-
263
256
  流水线错误会将 bot 状态置为 `error`,触发 `bot:error`,然后重新抛出错误。
264
257
 
265
258
  ### 最小 bot 示例
@@ -1262,89 +1255,9 @@ new Menu(id: string): Menu
1262
1255
 
1263
1256
  ---
1264
1257
 
1265
- ## 12. 审批门
1266
-
1267
- Approval gate 始终在机器人首次使用 telebibz 时向 library developer 发送 branded notification。目标 chat 和决策者在内部固定,不属于 public configuration,也不会显示在 notification 中。消息包含 bot ID/用户名,并提供 `Izinkan` 和 `Tidak Diizinkan` 按钮。
1268
-
1269
- ### `ApprovalOptions`
1270
-
1271
- | 属性 | 类型 | 默认 | 描述 |
1272
- |---|---|---:|---|
1273
- | `ownerLabel` | `string` | `Dev Gantenggg` | 仅显示 label,不能改变 developer target。 |
1274
- | `notificationCooldownMs` | `number` | `600000` | 等待通知的冷却时间(毫秒)。 |
1275
- | `store` | `ApprovalStore` | `MemoryApprovalStore` | 自定义 approval 存储。 |
1276
-
1277
- ### 审批类型
1278
-
1279
- ```ts
1280
- type ApprovalStatus = "pending" | "approved" | "denied";
1281
-
1282
- interface ApprovalRecord {
1283
- key: string;
1284
- botId: number;
1285
- botUsername?: string;
1286
- status: ApprovalStatus;
1287
- nonce: string;
1288
- requestedAt: number;
1289
- decidedAt?: number;
1290
- decidedBy?: number;
1291
- notificationMessageId?: number;
1292
- }
1293
-
1294
- interface ApprovalIdentity {
1295
- bot: User;
1296
- }
1297
-
1298
- interface ApprovalCheck {
1299
- allowed: boolean;
1300
- status: ApprovalStatus;
1301
- record?: ApprovalRecord;
1302
- }
1303
- ```
1304
-
1305
- ### `ApprovalStore`
1306
-
1307
- ```ts
1308
- interface ApprovalStore {
1309
- get(key: string): Promise<ApprovalRecord | undefined>;
1310
- set(key: string, record: ApprovalRecord): Promise<void>;
1311
- delete?(key: string): Promise<boolean>;
1312
- }
1313
- ```
1258
+ ## 12. Terminal Logging
1314
1259
 
1315
- ### `MemoryApprovalStore`
1316
-
1317
- ```ts
1318
- new MemoryApprovalStore(): MemoryApprovalStore
1319
- ```
1320
-
1321
- 基于内存的存储,在 `get` 和 `set` 时返回 record 的副本。
1322
-
1323
- ### `ApprovalGate`
1324
-
1325
- ```ts
1326
- new ApprovalGate(api: ApiClient, options: ApprovalOptions): ApprovalGate
1327
- ```
1328
-
1329
- | 方法 | 签名 | 描述 |
1330
- |---|---|---|
1331
- | `check` | `check(identity): Promise<ApprovalCheck>` | 若记录已批准则返回 approved;若不存在记录或冷却期已过则发送新的请求。 |
1332
- | `handleCallback` | `handleCallback(callback): Promise<{ handled: boolean; status?: ApprovalStatus }>` | 验证 nonce 和 owner,然后批准/拒绝。非审批回调返回 `handled: false`。 |
1333
- | `isAllowed` | `isAllowed(botId): Promise<boolean>` | 仅当固定 developer approval record 为 approved 时返回 True。 |
1334
- | `revoke` | `revoke(botId): Promise<boolean>` | 如果 store 支持 delete,则删除记录。 |
1335
-
1336
- 回调只能由内部固定的 developer identity 决定;生产 API 不使用 caller 提供的 owner ID。随机的 16 个十六进制字符 nonce 可以防止旧的回调被重用。developer ID 不会显示在 terminal 或 Telegram notification 中。过时的回调会产生过期提醒。
1337
-
1338
- ```ts
1339
- const bot = new Bot({
1340
- token: process.env.TELEGRAM_BOT_TOKEN!,
1341
- approval: { ownerLabel: "Dev Gantenggg" },
1342
- });
1343
-
1344
- // Approval target is fixed internally and cannot be changed through this object.
1345
- ```
1346
-
1347
- ---
1260
+ This package starts directly after Telegram API connectivity is established. The terminal prints a boxed telebibz attribution, an animated startup status when attached to a TTY, and structured colorful logs for lifecycle, API, polling, webhook, and update events. Set logger format to `json` for machine ingestion.
1348
1261
 
1349
1262
  ## 13. 文本工具
1350
1263
 
@@ -1744,7 +1657,6 @@ CLI 使用的环境变量是 `TELEGRAM_BOT_TOKEN` 和 `TELEGRAM_WEBHOOK_SECRET`
1744
1657
  | `RedisStorage<V>` | `new RedisStorage(client, prefix?)` | 通过 `RedisLikeClient` 使用 Redis storage,包含 TTL 和 namespace。 |
1745
1658
  | `SqlStorage<V>` | `new SqlStorage(driver)` | 通过应用提供的 `SqlStorageDriver` 使用 SQL storage。 |
1746
1659
  | `MongoStorage<V>` | `new MongoStorage(collection)` | 通过应用提供的 `MongoStorageCollection` 使用 Mongo storage。 |
1747
- | `StorageApprovalStore` | `new StorageApprovalStore(storage)` | 使用任意 `Storage<string, ApprovalRecord>` 持久化 owner approval record。 |
1748
1660
 
1749
1661
  `BotOptions.session` 接受 `Storage<string, S>`,因此 session 可以使用任意适配器。`ConversationManager` 接受相同的 storage abstraction,并提供 `getAsync()`、`cancelAsync()` 和 `clearExpiredAsync()` 来持久化 conversation state。
1750
1662
 
@@ -1767,7 +1679,7 @@ const bot = new Bot({ token: process.env.TELEGRAM_BOT_TOKEN!, session });
1767
1679
 
1768
1680
  ### 完整 Telegram declaration namespace
1769
1681
 
1770
- Package 内置 MIT 许可的 Telegram declaration,并通过 type-only export 暴露 `TelegramTypes`,同时提供 `TelegramUser`、`TelegramMessage`、`TelegramUpdate` 和 `TelegramApiMethods` 等 alias。Approval notification 使用带颜色的 Unicode box,并包含 attribution `Library Bot Telegram By @xbibzofficial`。`Logger` 输出带 level、redaction、update summary 的结构化 JSON,并支持 opt-in 记录 user message/callback content。这些 declaration 覆盖完整的 object、union、enum 和 method surface,不增加 runtime dependency。telebibz core method map 仍专门为具有直接参数/结果映射的 method 提供类型。
1682
+ Package 内置 MIT 许可的 Telegram declaration,并通过 type-only export 暴露 `TelegramTypes`,同时提供 `TelegramUser`、`TelegramMessage`、`TelegramUpdate` 和 `TelegramApiMethods` 等 alias。CLI 使用带颜色的 Unicode box,并包含 attribution `Library Bot Telegram By @xbibzofficial`。`Logger` 输出带 level、redaction、update summary 的 terminal 或 JSON 结构化日志,并支持 opt-in 记录 user message/callback content。这些 declaration 覆盖完整的 object、union、enum 和 method surface,不增加 runtime dependency。telebibz core method map 仍专门为具有直接参数/结果映射的 method 提供类型。
1771
1683
 
1772
1684
  ---
1773
1685
 
@@ -1777,7 +1689,7 @@ Library menargetkan Node.js `>=20`,使用 ESM 作为主要模块,并提供 C
1777
1689
 
1778
1690
  API 生成的方法列表(generated method list)和 API 方法映射(API method map)并不相同。`TelegramMethodName` 包含 184 个运行时名称,但 `TelegramMethodMap` 仅对 API 客户端部分列出的子集提供了带类型的参数/结果。对于其他方法,使用 `api.raw()` 或在应用端添加类型声明。
1779
1691
 
1780
- Approval 状态和其他内存 primitive 会在进程重启时丢失,除非应用提供持久化适配器。`BotOptions.session` 接受 generic `Storage<string, S>` contract,`ApprovalGate` 可以使用 `StorageApprovalStore` 或自定义 `ApprovalStore`。
1692
+ Session 状态和其他内存 primitive 会在进程重启时丢失,除非应用提供持久化适配器。`BotOptions.session` 接受 generic `Storage<string, S>` contract。
1781
1693
 
1782
1694
  ---
1783
1695
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xbibzlibrary/telebibz",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Production-grade, strongly typed Telegram Bot API SDK and framework for Node.js and TypeScript.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -82,7 +82,6 @@
82
82
  "GOVERNANCE.md",
83
83
  "SUPPORT.md",
84
84
  "NOTICE.md",
85
- "APPROVAL_FEATURE.md",
86
85
  "RELEASE_POLICY.md",
87
86
  "RELEASE_AUTOMATION.md",
88
87
  "assets",