@zero-server/sdk 0.9.6 → 0.9.8

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 (94) hide show
  1. package/README.md +54 -53
  2. package/index.js +116 -4
  3. package/lib/app.js +22 -22
  4. package/lib/auth/authorize.js +11 -11
  5. package/lib/auth/enrollment.js +5 -5
  6. package/lib/auth/jwt.js +9 -9
  7. package/lib/auth/oauth.js +1 -1
  8. package/lib/auth/session.js +5 -5
  9. package/lib/auth/trustedDevice.js +2 -2
  10. package/lib/auth/twoFactor.js +11 -11
  11. package/lib/auth/webauthn.js +6 -6
  12. package/lib/body/json.js +1 -1
  13. package/lib/body/raw.js +1 -1
  14. package/lib/body/rawBuffer.js +1 -1
  15. package/lib/body/text.js +1 -1
  16. package/lib/body/urlencoded.js +3 -3
  17. package/lib/cli.js +43 -28
  18. package/lib/cluster.js +3 -3
  19. package/lib/debug.js +10 -10
  20. package/lib/env/index.js +11 -11
  21. package/lib/errors.js +131 -16
  22. package/lib/fetch/index.js +1 -1
  23. package/lib/grpc/call.js +14 -14
  24. package/lib/grpc/client.js +4 -4
  25. package/lib/grpc/codec.js +7 -7
  26. package/lib/grpc/credentials.js +2 -2
  27. package/lib/grpc/frame.js +2 -2
  28. package/lib/grpc/health.js +3 -3
  29. package/lib/grpc/index.js +3 -3
  30. package/lib/grpc/metadata.js +3 -3
  31. package/lib/grpc/proto.js +5 -5
  32. package/lib/grpc/reflection.js +2 -2
  33. package/lib/grpc/server.js +3 -3
  34. package/lib/grpc/status.js +2 -2
  35. package/lib/grpc/watch.js +1 -1
  36. package/lib/http/request.js +13 -13
  37. package/lib/http/response.js +2 -2
  38. package/lib/lifecycle.js +5 -5
  39. package/lib/middleware/compress.js +4 -4
  40. package/lib/observe/health.js +1 -1
  41. package/lib/observe/index.js +1 -1
  42. package/lib/observe/logger.js +3 -3
  43. package/lib/observe/metrics.js +4 -4
  44. package/lib/observe/tracing.js +4 -4
  45. package/lib/orm/adapters/json.js +1 -1
  46. package/lib/orm/adapters/memory.js +2 -2
  47. package/lib/orm/adapters/mongo.js +2 -2
  48. package/lib/orm/adapters/mysql.js +2 -2
  49. package/lib/orm/adapters/postgres.js +2 -2
  50. package/lib/orm/adapters/sqlite.js +3 -3
  51. package/lib/orm/audit.js +1 -1
  52. package/lib/orm/index.js +7 -7
  53. package/lib/orm/migrate.js +1 -1
  54. package/lib/orm/model.js +15 -15
  55. package/lib/orm/procedures.js +1 -1
  56. package/lib/orm/profiler.js +1 -1
  57. package/lib/orm/query.js +9 -9
  58. package/lib/orm/schema.js +1 -1
  59. package/lib/orm/seed/data/person.js +1 -1
  60. package/lib/orm/seed/fake.js +10 -10
  61. package/lib/orm/seed/index.js +4 -4
  62. package/lib/orm/seed/rng.js +1 -1
  63. package/lib/orm/snapshot.js +3 -3
  64. package/lib/orm/tenancy.js +6 -6
  65. package/lib/orm/views.js +1 -1
  66. package/lib/router/index.js +9 -9
  67. package/lib/webrtc/bot.js +405 -0
  68. package/lib/webrtc/cli.js +182 -0
  69. package/lib/webrtc/cluster.js +338 -0
  70. package/lib/webrtc/e2ee.js +274 -0
  71. package/lib/webrtc/ice.js +363 -0
  72. package/lib/webrtc/index.js +212 -0
  73. package/lib/webrtc/joinToken.js +171 -0
  74. package/lib/webrtc/observe.js +260 -0
  75. package/lib/webrtc/peer.js +143 -0
  76. package/lib/webrtc/room.js +184 -0
  77. package/lib/webrtc/sdp.js +503 -0
  78. package/lib/webrtc/sfu/index.js +251 -0
  79. package/lib/webrtc/sfu/livekit.js +304 -0
  80. package/lib/webrtc/sfu/mediasoup.js +357 -0
  81. package/lib/webrtc/sfu/memory.js +221 -0
  82. package/lib/webrtc/signaling.js +590 -0
  83. package/lib/webrtc/stun.js +484 -0
  84. package/lib/webrtc/turn/codec.js +370 -0
  85. package/lib/webrtc/turn/credentials.js +156 -0
  86. package/lib/webrtc/turn/server.js +648 -0
  87. package/package.json +2 -2
  88. package/types/body.d.ts +82 -14
  89. package/types/cli.d.ts +40 -2
  90. package/types/index.d.ts +19 -6
  91. package/types/middleware.d.ts +18 -72
  92. package/types/orm.d.ts +4 -13
  93. package/types/request.d.ts +3 -3
  94. package/types/webrtc.d.ts +501 -0
package/README.md CHANGED
@@ -12,14 +12,14 @@
12
12
 
13
13
  <p align="center">
14
14
  <a href="https://github.com/tonywied17/zero-server/actions"><img src="https://img.shields.io/github/actions/workflow/status/tonywied17/zero-server/ci.yml?branch=main&style=flat-square&logo=githubactions&logoColor=white&label=CI" alt="CI"></a>
15
- <a href="https://github.com/tonywied17/zero-server/actions"><img src="https://img.shields.io/badge/tests-7443%20passing-brightgreen?style=flat-square&logo=vitest&logoColor=white" alt="tests"></a>
16
- <a href="https://github.com/tonywied17/zero-server"><img src="https://img.shields.io/badge/coverage-96.97%25-brightgreen?style=flat-square&logo=vitest&logoColor=white" alt="coverage"></a>
15
+ <a href="https://github.com/tonywied17/zero-server/actions"><img src="https://img.shields.io/badge/tests-7777%20passing-brightgreen?style=flat-square&logo=vitest&logoColor=white" alt="tests"></a>
16
+ <a href="https://github.com/tonywied17/zero-server"><img src="https://img.shields.io/badge/coverage-95.85%25-brightgreen?style=flat-square&logo=vitest&logoColor=white" alt="coverage"></a>
17
17
  <a href="https://z-server.dev"><img src="https://img.shields.io/badge/docs-z--server.dev-00d8e0?style=flat-square&logo=readthedocs&logoColor=white" alt="docs"></a>
18
18
  <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-00d8e0?style=flat-square&logo=opensourceinitiative&logoColor=white" alt="MIT"></a>
19
19
  <a href="https://nodejs.org"><img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=flat-square&logo=nodedotjs&logoColor=white" alt="node >=18"></a>
20
20
  </p>
21
21
 
22
- > **Zero-dependency backend framework for Node.js routing, ORM, auth, WebSocket, SSE, observability, and 20+ middleware as one SDK or focused scoped packages.**
22
+ > **Zero-dependency backend framework for Node.js - routing, ORM, auth, WebSocket, SSE, observability, and 20+ middleware as one SDK or focused scoped packages.**
23
23
 
24
24
  <p align="center">
25
25
  <strong>
@@ -35,9 +35,9 @@
35
35
  npm install @zero-server/sdk
36
36
  ```
37
37
 
38
- Requires Node.js 18+. No external dependencies everything is built on Node.js core APIs.
38
+ Requires Node.js 18+. No external dependencies - everything is built on Node.js core APIs.
39
39
 
40
- `@zero-server/sdk` is the recommended install it re-exports the entire framework from a single import. Use it for new projects, demos, and most production apps.
40
+ `@zero-server/sdk` is the recommended install - it re-exports the entire framework from a single import. Use it for new projects, demos, and most production apps.
41
41
 
42
42
  ### Or install only what you need (scoped packages)
43
43
 
@@ -55,15 +55,16 @@ npm install @zero-server/core @zero-server/body @zero-server/middleware
55
55
  | `@zero-server/auth` | `jwt`, `session`, `oauth`, `authorize`, `twoFactor`, `webauthn`, `trustedDevice`, `enrollment` |
56
56
  | `@zero-server/orm` | `Database`, `Model`, `Query`, `TYPES`, migrations, seeders, replicas, search, geo, tenancy, audit |
57
57
  | `@zero-server/realtime` | `WebSocketConnection`, `WebSocketPool`, `SSEStream` |
58
+ | `@zero-server/webrtc` | signaling hub, rooms/peers, STUN/TURN, SFU adapters (memory, mediasoup, LiveKit), join tokens, E2EE, `spawnBotPeer` |
58
59
  | `@zero-server/grpc` | gRPC server, client, codec, status, metadata, framing, health, reflection, balancer |
59
60
  | `@zero-server/observe` | `MetricsRegistry`, `Tracer`, structured `Logger`, health checks |
60
61
  | `@zero-server/lifecycle` | `LifecycleManager`, `ClusterManager`, `clusterize` |
61
62
  | `@zero-server/env` | typed `.env` loader |
62
63
  | `@zero-server/fetch` | server-side `fetch` client |
63
64
  | `@zero-server/errors` | every typed `HttpError` class plus ORM/framework errors |
64
- | `@zero-server/cli` | programmatic `CLI` / `runCLI` entry points for `zh` / `zs` |
65
+ | `@zero-server/cli` | programmatic `CLI` / `runCLI` entry points for `zs` |
65
66
 
66
- > Each scoped package is fully standalone at runtime its own `index.js`, its own bundled lib, its own types. Mix and match freely; versions stay aligned across the `@zero-server/*` release set.
67
+ > Each scoped package is fully standalone at runtime - its own `index.js`, its own bundled lib, its own types. Mix and match freely; versions stay aligned across the `@zero-server/*` release set.
67
68
 
68
69
  ---
69
70
 
@@ -92,7 +93,7 @@ app.listen(3000, () => console.log('Listening on :3000'))
92
93
 
93
94
  ### Middleware
94
95
 
95
- 20+ built-in middleware all zero-dependency:
96
+ 20+ built-in middleware - all zero-dependency:
96
97
 
97
98
  | Middleware | Purpose |
98
99
  |---|---|
@@ -113,14 +114,14 @@ app.listen(3000, () => console.log('Listening on :3000'))
113
114
 
114
115
  Full auth stack with no external libraries:
115
116
 
116
- - **JWT** `jwt()` middleware, `jwtSign()`, `jwtVerify()`, `jwtDecode()`, JWKS key sets, access/refresh token pairs
117
- - **Sessions** `session()` middleware with in-memory store (pluggable)
118
- - **OAuth 2.0** `oauth()` middleware with PKCE, pre-configured providers (Google, GitHub, Microsoft, etc.)
119
- - **Authorization** `authorize()` policies, `can()` / `canAny()` permission checks, `gate()` middleware
117
+ - **JWT** - `jwt()` middleware, `jwtSign()`, `jwtVerify()`, `jwtDecode()`, JWKS key sets, access/refresh token pairs
118
+ - **Sessions** - `session()` middleware with in-memory store (pluggable)
119
+ - **OAuth 2.0** - `oauth()` middleware with PKCE, pre-configured providers (Google, GitHub, Microsoft, etc.)
120
+ - **Authorization** - `authorize()` policies, `can()` / `canAny()` permission checks, `gate()` middleware
120
121
 
121
122
  ### ORM & Database
122
123
 
123
- Full-featured ORM with 7 adapters memory, JSON file, SQLite, MySQL, PostgreSQL, MongoDB, and Redis:
124
+ Full-featured ORM with 7 adapters - memory, JSON file, SQLite, MySQL, PostgreSQL, MongoDB, and Redis:
124
125
 
125
126
  ```js
126
127
  const { Database, Model, TYPES } = require('@zero-server/sdk')
@@ -142,7 +143,7 @@ await User.create({ name: 'Alice', email: 'alice@example.com' })
142
143
  const users = await User.find({ name: 'Alice' })
143
144
  ```
144
145
 
145
- **Query builder** `where()`, `select()`, `orderBy()`, `limit()`, `offset()`, `join()`, `groupBy()`, `having()`, `paginate()`, `findOrCreate()`
146
+ **Query builder** - `where()`, `select()`, `orderBy()`, `limit()`, `offset()`, `join()`, `groupBy()`, `having()`, `paginate()`, `findOrCreate()`
146
147
 
147
148
  **Advanced ORM features:**
148
149
 
@@ -163,12 +164,12 @@ const users = await User.find({ name: 'Alice' })
163
164
 
164
165
  ### Real-Time
165
166
 
166
- - **WebSocket** `app.ws(path, handler)` with RFC 6455, `WebSocketPool` for rooms, broadcasting, and sub-protocols
167
- - **Server-Sent Events** `res.sse()` with auto-IDs, named events, and keep-alive
167
+ - **WebSocket** - `app.ws(path, handler)` with RFC 6455, `WebSocketPool` for rooms, broadcasting, and sub-protocols
168
+ - **Server-Sent Events** - `res.sse()` with auto-IDs, named events, and keep-alive
168
169
 
169
170
  ### Observability
170
171
 
171
- Built-in Prometheus metrics, health checks, distributed tracing, and structured logging zero dependencies.
172
+ Built-in Prometheus metrics, health checks, distributed tracing, and structured logging - zero dependencies.
172
173
 
173
174
  ```js
174
175
  const { createApp, metricsMiddleware } = require('@zero-server/sdk')
@@ -193,7 +194,7 @@ logins.inc({ provider: 'github' })
193
194
  app.listen(3000)
194
195
  ```
195
196
 
196
- **Scrape with Prometheus** create a `prometheus.yml`:
197
+ **Scrape with Prometheus** - create a `prometheus.yml`:
197
198
 
198
199
  ```yaml
199
200
  scrape_configs:
@@ -209,26 +210,26 @@ docker run -d -p 9090:9090 -v ./prometheus.yml:/etc/prometheus/prometheus.yml pr
209
210
  ```
210
211
 
211
212
  **Also includes:**
212
- - **Distributed tracing** `Tracer` and `Span` with W3C Trace Context (`traceparent` propagation), `instrumentFetch()` for outgoing requests
213
- - **Structured logging** `Logger` with levels, JSON output, and namespaced `debug()` logger
213
+ - **Distributed tracing** - `Tracer` and `Span` with W3C Trace Context (`traceparent` propagation), `instrumentFetch()` for outgoing requests
214
+ - **Structured logging** - `Logger` with levels, JSON output, and namespaced `debug()` logger
214
215
 
215
216
  ### Lifecycle & Clustering
216
217
 
217
- - **Graceful shutdown** signal handlers (SIGTERM/SIGINT), in-flight request draining, automatic WebSocket/SSE/database cleanup
218
- - **Clustering** `clusterize()` for multi-worker processes with auto-respawn and exponential backoff
218
+ - **Graceful shutdown** - signal handlers (SIGTERM/SIGINT), in-flight request draining, automatic WebSocket/SSE/database cleanup
219
+ - **Clustering** - `clusterize()` for multi-worker processes with auto-respawn and exponential backoff
219
220
 
220
221
  ### CLI
221
222
 
222
- Scaffolding and database management via `npx zh`:
223
+ Scaffolding and database management via `npx zs`:
223
224
 
224
225
  ```bash
225
- npx zh migrate # run pending migrations
226
- npx zh migrate:rollback # rollback last migration
227
- npx zh migrate:status # show migration status
228
- npx zh seed # run seeders
229
- npx zh make:model User # scaffold a model
230
- npx zh make:migration name # create migration file
231
- npx zh make:seeder User # create seeder file
226
+ npx zs migrate # run pending migrations
227
+ npx zs migrate:rollback # rollback last migration
228
+ npx zs migrate:status # show migration status
229
+ npx zs seed # run seeders
230
+ npx zs make:model User # scaffold a model
231
+ npx zs make:migration name # create migration file
232
+ npx zs make:seeder User # create seeder file
232
233
  ```
233
234
 
234
235
  ### Environment Config
@@ -419,35 +420,35 @@ npm run docs
419
420
 
420
421
  ```
421
422
  lib/
422
- app.js App class (middleware, routing, listen, ws upgrade, lifecycle)
423
- auth/ JWT, OAuth 2.0, sessions, MFA (TOTP/WebAuthn), authorization
424
- body/ body parsers (json, urlencoded, text, raw, multipart)
425
- cli.js CLI runner (migrate, seed, scaffold commands)
426
- cluster.js multi-worker clustering with auto-respawn
427
- debug.js namespaced debug logger
428
- env/ typed .env loader with schema validation
429
- errors.js 25+ HttpError / framework / ORM error classes
430
- fetch/ HTTP/HTTPS client (mTLS, AbortSignal, retries)
431
- grpc/ HTTP/2 gRPC stack: server, client, codec, framing,
423
+ app.js - App class (middleware, routing, listen, ws upgrade, lifecycle)
424
+ auth/ - JWT, OAuth 2.0, sessions, MFA (TOTP/WebAuthn), authorization
425
+ body/ - body parsers (json, urlencoded, text, raw, multipart)
426
+ cli.js - CLI runner (migrate, seed, scaffold commands)
427
+ cluster.js - multi-worker clustering with auto-respawn
428
+ debug.js - namespaced debug logger
429
+ env/ - typed .env loader with schema validation
430
+ errors.js - 25+ HttpError / framework / ORM error classes
431
+ fetch/ - HTTP/HTTPS client (mTLS, AbortSignal, retries)
432
+ grpc/ - HTTP/2 gRPC stack: server, client, codec, framing,
432
433
  status, metadata, health, reflection, balancer, watch
433
- http/ Request & Response wrappers
434
- lifecycle.js graceful shutdown and lifecycle management
435
- middleware/ cors, helmet, logger, rateLimit, compress, static, timeout,
434
+ http/ - Request & Response wrappers
435
+ lifecycle.js - graceful shutdown and lifecycle management
436
+ middleware/ - cors, helmet, logger, rateLimit, compress, static, timeout,
436
437
  requestId, cookieParser, csrf, validate, errorHandler
437
- observe/ Prometheus metrics, W3C tracing, health checks, structured logging
438
- orm/ Database, Model, Query, adapters, migrations, seeds, cache,
438
+ observe/ - Prometheus metrics, W3C tracing, health checks, structured logging
439
+ orm/ - Database, Model, Query, adapters, migrations, seeds, cache,
439
440
  replicas, search, geo, tenancy, audit, views, procedures, plugins
440
- router/ Router with sub-app mounting and pattern matching
441
- sse/ SSE stream controller
442
- ws/ WebSocket connection, handshake, and room management
443
- packages/ generated scoped @zero-server/* re-exports (one dir per scope)
441
+ router/ - Router with sub-app mounting and pattern matching
442
+ sse/ - SSE stream controller
443
+ ws/ - WebSocket connection, handshake, and room management
444
+ packages/ - generated scoped @zero-server/* re-exports (one dir per scope)
444
445
  .tools/
445
- scope-manifest.js single source of truth for scoped packages & their surface
446
+ scope-manifest.js - single source of truth for scoped packages & their surface
446
447
  generate-package-stubs.js
447
448
  generate-scope-docs.js
448
- types/ full TypeScript definitions
449
- website-docs/ live demo server, controllers, and playground UI
450
- test/ vitest test suite (7000+ tests, 95%+ coverage)
449
+ types/ - full TypeScript definitions
450
+ website-docs/ - live demo server, controllers, and playground UI
451
+ test/ - vitest test suite (7000+ tests, 95%+ coverage)
451
452
  ```
452
453
 
453
454
  ## Testing
package/index.js CHANGED
@@ -59,6 +59,23 @@ const {
59
59
  ChannelCredentials, createRotatingCredentials,
60
60
  watchProto,
61
61
  } = require('./lib/grpc');
62
+ const {
63
+ createWebRTC, SignalingHub, Room, Peer,
64
+ parseSdp, stringifySdp,
65
+ parseCandidate, stringifyCandidate, filterCandidates,
66
+ isPrivateIp, isLoopbackIp, isLinkLocalIp, isMdnsHostname,
67
+ stunBinding, encodeBindingRequest, decodeMessage,
68
+ encodeXorMappedAddress, decodeXorMappedAddress,
69
+ STUN_MAGIC_COOKIE, STUN_METHOD, STUN_CLASS, STUN_ATTR,
70
+ issueTurnCredentials, TurnServer,
71
+ SfuAdapter, MemorySfuAdapter, MediasoupSfuAdapter, LiveKitSfuAdapter, loadSfuAdapter, signJoinToken, verifyJoinToken,
72
+ spawnBotPeer,
73
+ bindObservability,
74
+ E2eeChannel, attachE2ee, generateE2eeKeyPair, sealKey, openSealedKey,
75
+ useCluster, ClusterCoordinator, MemoryClusterAdapter,
76
+ runWebRTCCommand,
77
+ WebRTCError, SignalingError, IceError, TurnError, SdpError,
78
+ } = require('./lib/webrtc');
62
79
  const { version } = require('./package.json');
63
80
 
64
81
  module.exports = {
@@ -247,12 +264,12 @@ module.exports = {
247
264
  ClusterManager,
248
265
  /** @see module:cluster */
249
266
  cluster: clusterize,
250
- // Observability Structured Logging
267
+ // Observability - Structured Logging
251
268
  /** @see module:observe/logger */
252
269
  Logger,
253
270
  /** @see module:observe/logger */
254
271
  structuredLogger,
255
- // Observability Metrics
272
+ // Observability - Metrics
256
273
  /** @see module:observe/metrics */
257
274
  Counter,
258
275
  /** @see module:observe/metrics */
@@ -269,7 +286,7 @@ module.exports = {
269
286
  metricsMiddleware,
270
287
  /** @see module:observe/metrics */
271
288
  metricsEndpoint: metricsEndpointHandler,
272
- // Observability Tracing
289
+ // Observability - Tracing
273
290
  /** @see module:observe/tracing */
274
291
  Span,
275
292
  /** @see module:observe/tracing */
@@ -282,7 +299,7 @@ module.exports = {
282
299
  tracingMiddleware,
283
300
  /** @see module:observe/tracing */
284
301
  instrumentFetch,
285
- // Observability Health Checks
302
+ // Observability - Health Checks
286
303
  /** @see module:observe/health */
287
304
  healthCheck,
288
305
  /** @see module:observe/health */
@@ -409,6 +426,101 @@ module.exports = {
409
426
  // gRPC: Proto hot-reload
410
427
  /** @see module:grpc/watch */
411
428
  watchProto,
429
+ // WebRTC
430
+ /** @see module:webrtc */
431
+ createWebRTC,
432
+ /** @see module:webrtc/signaling */
433
+ SignalingHub,
434
+ /** @see module:webrtc/room */
435
+ Room,
436
+ /** @see module:webrtc/peer */
437
+ Peer,
438
+ /** @see module:webrtc/sdp */
439
+ parseSdp,
440
+ /** @see module:webrtc/sdp */
441
+ stringifySdp,
442
+ /** @see module:webrtc/ice */
443
+ parseCandidate,
444
+ /** @see module:webrtc/ice */
445
+ stringifyCandidate,
446
+ /** @see module:webrtc/ice */
447
+ filterCandidates,
448
+ /** @see module:webrtc/ice */
449
+ isPrivateIp,
450
+ /** @see module:webrtc/ice */
451
+ isLoopbackIp,
452
+ /** @see module:webrtc/ice */
453
+ isLinkLocalIp,
454
+ /** @see module:webrtc/ice */
455
+ isMdnsHostname,
456
+ /** @see module:webrtc/stun */
457
+ stunBinding,
458
+ /** @see module:webrtc/stun */
459
+ encodeBindingRequest,
460
+ /** @see module:webrtc/stun */
461
+ decodeMessage,
462
+ /** @see module:webrtc/stun */
463
+ encodeXorMappedAddress,
464
+ /** @see module:webrtc/stun */
465
+ decodeXorMappedAddress,
466
+ /** @see module:webrtc/stun */
467
+ STUN_MAGIC_COOKIE,
468
+ /** @see module:webrtc/stun */
469
+ STUN_METHOD,
470
+ /** @see module:webrtc/stun */
471
+ STUN_CLASS,
472
+ /** @see module:webrtc/stun */
473
+ STUN_ATTR,
474
+ /** @see module:webrtc/turn/credentials */
475
+ issueTurnCredentials,
476
+ /** @see module:webrtc/turn/server */
477
+ TurnServer,
478
+ /** @see module:webrtc/sfu */
479
+ SfuAdapter,
480
+ /** @see module:webrtc/sfu/memory */
481
+ MemorySfuAdapter,
482
+ /** @see module:webrtc/sfu/mediasoup */
483
+ MediasoupSfuAdapter,
484
+ /** @see module:webrtc/sfu/livekit */
485
+ LiveKitSfuAdapter,
486
+ /** @see module:webrtc/sfu */
487
+ loadSfuAdapter,
488
+ /** @see module:webrtc/signaling */
489
+ signJoinToken,
490
+ /** @see module:webrtc/signaling */
491
+ verifyJoinToken,
492
+ /** @see module:webrtc/bot */
493
+ spawnBotPeer,
494
+ /** @see module:webrtc/observe */
495
+ bindObservability,
496
+ /** @see module:webrtc/e2ee */
497
+ E2eeChannel,
498
+ /** @see module:webrtc/e2ee */
499
+ attachE2ee,
500
+ /** @see module:webrtc/e2ee */
501
+ generateE2eeKeyPair,
502
+ /** @see module:webrtc/e2ee */
503
+ sealKey,
504
+ /** @see module:webrtc/e2ee */
505
+ openSealedKey,
506
+ /** @see module:webrtc/cluster */
507
+ useCluster,
508
+ /** @see module:webrtc/cluster */
509
+ ClusterCoordinator,
510
+ /** @see module:webrtc/cluster */
511
+ MemoryClusterAdapter,
512
+ /** @see module:webrtc/cli */
513
+ runWebRTCCommand,
514
+ /** @see module:errors */
515
+ WebRTCError,
516
+ /** @see module:errors */
517
+ SignalingError,
518
+ /** @see module:errors */
519
+ IceError,
520
+ /** @see module:errors */
521
+ TurnError,
522
+ /** @see module:errors */
523
+ SdpError,
412
524
  /** Package version */
413
525
  version,
414
526
  };
package/lib/app.js CHANGED
@@ -74,7 +74,7 @@ class App
74
74
  this._settings = {};
75
75
 
76
76
  /**
77
- * Application-level locals persistent across the app lifecycle.
77
+ * Application-level locals - persistent across the app lifecycle.
78
78
  * Merged into every `req.locals` and `res.locals` on every request.
79
79
  * @type {Object<string, *>}
80
80
  */
@@ -167,10 +167,10 @@ class App
167
167
 
168
168
  /**
169
169
  * Register middleware or mount a sub-router.
170
- * - `use(fn)` global middleware applied to every request.
171
- * - `use('/prefix', fn)` path-scoped middleware (strips the prefix
170
+ * - `use(fn)` - global middleware applied to every request.
171
+ * - `use('/prefix', fn)` - path-scoped middleware (strips the prefix
172
172
  * before calling `fn` so downstream sees relative paths).
173
- * - `use('/prefix', router)` mount a Router sub-app at the given prefix.
173
+ * - `use('/prefix', router)` - mount a Router sub-app at the given prefix.
174
174
  *
175
175
  * @param {string|Function} pathOrFn - A path prefix string, or middleware function.
176
176
  * @param {Function|Router} [fn] - Middleware function or Router when first arg is a path.
@@ -254,7 +254,7 @@ class App
254
254
  */
255
255
  handle(req, res)
256
256
  {
257
- // Skip gRPC requests already handled via server.on('stream')
257
+ // Skip gRPC requests - already handled via server.on('stream')
258
258
  if (this._grpcRegistry && req.headers['content-type']?.startsWith('application/grpc'))
259
259
  return;
260
260
 
@@ -356,7 +356,7 @@ class App
356
356
  */
357
357
  listen(port = 3000, opts, cb)
358
358
  {
359
- // Normalise arguments allow `listen(port, cb)` without opts
359
+ // Normalise arguments - allow `listen(port, cb)` without opts
360
360
  if (typeof opts === 'function') { cb = opts; opts = undefined; }
361
361
 
362
362
  const isH2 = opts && opts.http2;
@@ -376,7 +376,7 @@ class App
376
376
  }
377
377
  else if (isH2)
378
378
  {
379
- // HTTP/2 cleartext (h2c) no TLS, for internal services
379
+ // HTTP/2 cleartext (h2c) - no TLS, for internal services
380
380
  const h2Opts = opts ? { ...opts } : {};
381
381
  delete h2Opts.http2;
382
382
  server = http2.createServer(h2Opts, this.handler);
@@ -402,7 +402,7 @@ class App
402
402
  {
403
403
  if (this._grpcRegistry.handleStream(stream, headers))
404
404
  return; // handled as gRPC
405
- // Otherwise fall through the compat handler fires the normal request event
405
+ // Otherwise fall through - the compat handler fires the normal request event
406
406
  });
407
407
  }
408
408
 
@@ -461,8 +461,8 @@ class App
461
461
  * Register a lifecycle event listener.
462
462
  *
463
463
  * Supported events:
464
- * - `'beforeShutdown'` fires before shutdown begins (flush caches, finish writes)
465
- * - `'shutdown'` fires after shutdown is complete
464
+ * - `'beforeShutdown'` - fires before shutdown begins (flush caches, finish writes)
465
+ * - `'shutdown'` - fires after shutdown is complete
466
466
  *
467
467
  * @param {'beforeShutdown'|'shutdown'} event - Lifecycle event name.
468
468
  * @param {Function} fn - Async or sync callback.
@@ -570,7 +570,7 @@ class App
570
570
  }
571
571
 
572
572
  /**
573
- * Configure the shutdown timeoutthe maximum time (ms) to wait for
573
+ * Configure the shutdown timeout-the maximum time (ms) to wait for
574
574
  * in-flight requests to finish before forcefully terminating them.
575
575
  *
576
576
  * @param {number} ms - Timeout in milliseconds.
@@ -730,7 +730,7 @@ class App
730
730
  * @param {object|Function} [opts] - Options object, or the handler function directly.
731
731
  * @param {number} [opts.maxPayload=1048576] - Maximum incoming frame size in bytes (default 1 MB).
732
732
  * @param {number} [opts.pingInterval=30000] - Auto-ping interval in ms. Set `0` to disable.
733
- * @param {Function} [opts.verifyClient] - `(req) => boolean` return false to reject the upgrade.
733
+ * @param {Function} [opts.verifyClient] - `(req) => boolean` - return false to reject the upgrade.
734
734
  * @param {Function} handler - `(ws, req) => void`.
735
735
  *
736
736
  * @example | Simple
@@ -815,56 +815,56 @@ class App
815
815
  route(method, path, ...fns) { const o = this._extractOpts(fns); this.router.add(method, path, fns, o); }
816
816
 
817
817
  /**
818
- * @see App#route shortcut for GET requests.
818
+ * @see App#route - shortcut for GET requests.
819
819
  * @param {string} path - Route pattern.
820
820
  * @param {...Function} fns - Handler functions.
821
821
  * @returns {App} `this` for chaining.
822
822
  */
823
823
  get(path, ...fns) { if (arguments.length === 1 && typeof path === 'string' && fns.length === 0) return this.set(path); this.route('GET', path, ...fns); return this; }
824
824
  /**
825
- * @see App#route shortcut for POST requests.
825
+ * @see App#route - shortcut for POST requests.
826
826
  * @param {string} path - Route pattern.
827
827
  * @param {...Function} fns - Handler functions.
828
828
  * @returns {App} `this` for chaining.
829
829
  */
830
830
  post(path, ...fns) { this.route('POST', path, ...fns); return this; }
831
831
  /**
832
- * @see App#route shortcut for PUT requests.
832
+ * @see App#route - shortcut for PUT requests.
833
833
  * @param {string} path - Route pattern.
834
834
  * @param {...Function} fns - Handler functions.
835
835
  * @returns {App} `this` for chaining.
836
836
  */
837
837
  put(path, ...fns) { this.route('PUT', path, ...fns); return this; }
838
838
  /**
839
- * @see App#route shortcut for DELETE requests.
839
+ * @see App#route - shortcut for DELETE requests.
840
840
  * @param {string} path - Route pattern.
841
841
  * @param {...Function} fns - Handler functions.
842
842
  * @returns {App} `this` for chaining.
843
843
  */
844
844
  delete(path, ...fns) { this.route('DELETE', path, ...fns); return this; }
845
845
  /**
846
- * @see App#route shortcut for PATCH requests.
846
+ * @see App#route - shortcut for PATCH requests.
847
847
  * @param {string} path - Route pattern.
848
848
  * @param {...Function} fns - Handler functions.
849
849
  * @returns {App} `this` for chaining.
850
850
  */
851
851
  patch(path, ...fns) { this.route('PATCH', path, ...fns); return this; }
852
852
  /**
853
- * @see App#route shortcut for OPTIONS requests.
853
+ * @see App#route - shortcut for OPTIONS requests.
854
854
  * @param {string} path - Route pattern.
855
855
  * @param {...Function} fns - Handler functions.
856
856
  * @returns {App} `this` for chaining.
857
857
  */
858
858
  options(path, ...fns) { this.route('OPTIONS', path, ...fns); return this; }
859
859
  /**
860
- * @see App#route shortcut for HEAD requests.
860
+ * @see App#route - shortcut for HEAD requests.
861
861
  * @param {string} path - Route pattern.
862
862
  * @param {...Function} fns - Handler functions.
863
863
  * @returns {App} `this` for chaining.
864
864
  */
865
865
  head(path, ...fns) { this.route('HEAD', path, ...fns); return this; }
866
866
  /**
867
- * @see App#route matches every HTTP method.
867
+ * @see App#route - matches every HTTP method.
868
868
  * @param {string} path - Route pattern.
869
869
  * @param {...Function} fns - Handler functions.
870
870
  * @returns {App} `this` for chaining.
@@ -872,7 +872,7 @@ class App
872
872
  all(path, ...fns) { this.route('ALL', path, ...fns); return this; }
873
873
 
874
874
  /**
875
- * Chainable route builder register multiple methods on the same path.
875
+ * Chainable route builder - register multiple methods on the same path.
876
876
  *
877
877
  * @param {string} path - Route pattern.
878
878
  * @returns {object} Chain object with HTTP verb methods.
@@ -1149,7 +1149,7 @@ class App
1149
1149
 
1150
1150
  /**
1151
1151
  * Create an OAuth2 client bound to this app.
1152
- * Returns the client does NOT mount any middleware automatically.
1152
+ * Returns the client - does NOT mount any middleware automatically.
1153
1153
  *
1154
1154
  * @param {object} opts - OAuth options (see `oauth()` for full documentation).
1155
1155
  * @returns {{ authorize: Function, callback: Function, refresh: Function, userInfo: Function }}
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module auth/authorize
3
- * @description Authorization helpers role-based access control (RBAC),
3
+ * @description Authorization helpers - role-based access control (RBAC),
4
4
  * permission-based access, and policy classes.
5
5
  *
6
6
  * Works with any authentication middleware that sets `req.user`.
@@ -13,22 +13,22 @@
13
13
  * app.use(jwt({ secret: process.env.JWT_SECRET }));
14
14
  * app.use(attachUserHelpers());
15
15
  *
16
- * // Role-based only admins and editors can modify posts
16
+ * // Role-based - only admins and editors can modify posts
17
17
  * app.put('/posts/:id', authorize('admin', 'editor'), (req, res) => {
18
18
  * res.json({ updated: true });
19
19
  * });
20
20
  *
21
- * // Permission-based require ALL listed permissions
21
+ * // Permission-based - require ALL listed permissions
22
22
  * app.delete('/users/:id', can('users:read', 'users:delete'), (req, res) => {
23
23
  * res.json({ deleted: true });
24
24
  * });
25
25
  *
26
- * // ANY permission useful for overlapping access
26
+ * // ANY permission - useful for overlapping access
27
27
  * app.get('/reports', canAny('reports:read', 'admin:read'), (req, res) => {
28
28
  * res.json({ reports: [] });
29
29
  * });
30
30
  *
31
- * // Policy class resource-level authorization
31
+ * // Policy class - resource-level authorization
32
32
  * class PostPolicy extends Policy {
33
33
  * before(user) { if (user.role === 'superadmin') return true; }
34
34
  * update(user, post) { return user.id === post.authorId || user.role === 'admin'; }
@@ -114,9 +114,9 @@ function authorize(...roles)
114
114
  * Checks `req.user.permissions` (array or Set) for the required permission(s).
115
115
  *
116
116
  * Permission strings follow a `resource:action` convention:
117
- * - `'posts:write'` write access to posts
118
- * - `'users:delete'` delete users
119
- * - `'*'` superuser wildcard
117
+ * - `'posts:write'` - write access to posts
118
+ * - `'users:delete'` - delete users
119
+ * - `'*'` - superuser wildcard
120
120
  *
121
121
  * @param {...string} permissions - Required permissions (ALL must be present unless `opts.any` is true).
122
122
  * @returns {Function} Middleware `(req, res, next) => void`.
@@ -293,7 +293,7 @@ function gate(policy, action, getResource)
293
293
  });
294
294
  }
295
295
 
296
- // Attach resource if loaded saves a redundant DB query in the handler
296
+ // Attach resource if loaded - saves a redundant DB query in the handler
297
297
  if (resource && !req.resource) req.resource = resource;
298
298
  next();
299
299
  };
@@ -306,8 +306,8 @@ function gate(policy, action, getResource)
306
306
  * Call this middleware after JWT/session middleware.
307
307
  *
308
308
  * Adds:
309
- * - `req.user.is(...roles)` check roles
310
- * - `req.user.can(...perms)` check permissions
309
+ * - `req.user.is(...roles)` - check roles
310
+ * - `req.user.can(...perms)` - check permissions
311
311
  *
312
312
  * @returns {Function} Middleware.
313
313
  *
@@ -5,10 +5,10 @@
5
5
  * for TOTP-based two-factor authentication.
6
6
  *
7
7
  * Steps:
8
- * 1. `start()` Generate secret + backup codes, store in session
9
- * 2. `verify()` Confirm user can produce a valid TOTP code
10
- * 3. `complete()` Persist the verified secret to the database
11
- * 4. `disable()` Remove 2FA from the account
8
+ * 1. `start()` - Generate secret + backup codes, store in session
9
+ * 2. `verify()` - Confirm user can produce a valid TOTP code
10
+ * 3. `complete()` - Persist the verified secret to the database
11
+ * 4. `disable()` - Remove 2FA from the account
12
12
  *
13
13
  * @example | Full enrollment flow
14
14
  * const { enrollment } = require('@zero-server/sdk');
@@ -356,7 +356,7 @@ function enrollment(opts = {})
356
356
 
357
357
  function _defaultGetAccount(req)
358
358
  {
359
- if (!req.user) throw new Error('No user on request authentication middleware required');
359
+ if (!req.user) throw new Error('No user on request - authentication middleware required');
360
360
  return req.user.email || req.user.id || req.user.sub;
361
361
  }
362
362