@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/lib/orm/query.js CHANGED
@@ -388,7 +388,7 @@ class Query
388
388
  }
389
389
 
390
390
  /**
391
- * Alias for with() mirrors Entity Framework include syntax.
391
+ * Alias for with() - mirrors Entity Framework include syntax.
392
392
  * @param {...string|object} relations - Relation names or config objects to eager-load.
393
393
  * @returns {Query} This query for chaining.
394
394
  */
@@ -998,7 +998,7 @@ class Query
998
998
  }
999
999
 
1000
1000
  /**
1001
- * Make Query thenable allows `await query`.
1001
+ * Make Query thenable - allows `await query`.
1002
1002
  * @param {Function} resolve - Fulfillment handler.
1003
1003
  * @param {Function} reject - Rejection handler.
1004
1004
  * @returns {Promise} Result of exec().
@@ -1043,7 +1043,7 @@ class Query
1043
1043
  }
1044
1044
 
1045
1045
  /**
1046
- * Alias for exec explicitly convert to array.
1046
+ * Alias for exec - explicitly convert to array.
1047
1047
  * @returns {Promise<Array>} Matching rows as an array.
1048
1048
  */
1049
1049
  toArray()
@@ -1072,7 +1072,7 @@ class Query
1072
1072
  }
1073
1073
 
1074
1074
  /**
1075
- * Alias for first() C# FirstOrDefault returns null on empty.
1075
+ * Alias for first() - C# FirstOrDefault returns null on empty.
1076
1076
  * @returns {Promise<object|null>} Matching row or null.
1077
1077
  */
1078
1078
  firstOrDefault()
@@ -1081,7 +1081,7 @@ class Query
1081
1081
  }
1082
1082
 
1083
1083
  /**
1084
- * Alias for avg() C# naming.
1084
+ * Alias for avg() - C# naming.
1085
1085
  * @param {string} field - Column name.
1086
1086
  * @returns {Promise<number>} Average of the column values.
1087
1087
  */
@@ -1091,7 +1091,7 @@ class Query
1091
1091
  }
1092
1092
 
1093
1093
  /**
1094
- * Alias for reduce() C# Aggregate naming.
1094
+ * Alias for reduce() - C# Aggregate naming.
1095
1095
  * @param {Function} fn - Callback function.
1096
1096
  * @param {*} seed - Initial accumulator value.
1097
1097
  * @returns {Promise<*>} Accumulated value.
@@ -1126,7 +1126,7 @@ class Query
1126
1126
  }
1127
1127
 
1128
1128
  /**
1129
- * Alias for last() C# naming.
1129
+ * Alias for last() - C# naming.
1130
1130
  * @returns {Promise<object|null>} Matching row or null.
1131
1131
  */
1132
1132
  lastOrDefault()
@@ -1346,7 +1346,7 @@ class Query
1346
1346
  // -- Projection --
1347
1347
 
1348
1348
  /**
1349
- * FlatMap project each element to an array and flatten.
1349
+ * FlatMap - project each element to an array and flatten.
1350
1350
  * @param {Function} fn - (item, index) => Array
1351
1351
  * @returns {Promise<Array>} Flattened projected results.
1352
1352
  */
@@ -1599,7 +1599,7 @@ class Query
1599
1599
  }
1600
1600
 
1601
1601
  /**
1602
- * Inverse of when apply query logic when condition is falsy.
1602
+ * Inverse of when - apply query logic when condition is falsy.
1603
1603
  *
1604
1604
  * @param {*} condition - Condition to evaluate.
1605
1605
  * @param {Function} fn - Callback function.
package/lib/orm/schema.js CHANGED
@@ -180,7 +180,7 @@ function validateValue(value, colDef, colName)
180
180
  try { return JSON.parse(value); }
181
181
  catch (e) { throw new Error(`"${colName}" must be valid JSON`); }
182
182
  }
183
- // Already an object/array return as-is for storage
183
+ // Already an object/array - return as-is for storage
184
184
  return value;
185
185
  }
186
186
  case 'uuid':
@@ -6,7 +6,7 @@
6
6
  * job titles, prefixes/suffixes, gender, bio phrases, zodiac signs.
7
7
  */
8
8
 
9
- /** Title prefixes separate lists per target sex for contextual use. */
9
+ /** Title prefixes - separate lists per target sex for contextual use. */
10
10
  const NAME_PREFIXES = {
11
11
  male: ['Mr.', 'Dr.', 'Prof.'],
12
12
  female: ['Ms.', 'Mrs.', 'Dr.', 'Prof.', 'Miss'],
@@ -5,13 +5,13 @@
5
5
  * @description Extensible fake data generator.
6
6
  *
7
7
  * Key capabilities:
8
- * • Seeded / reproducible output Fake.seed(42)
9
- * • Guaranteed-unique values Fake.unique(() => Fake.email())
10
- * • Multi-locale names Fake.firstName({ locale: 'ja', sex: 'female' })
11
- * • Rich phone formats Fake.phone({ countryCode: 'DE', format: 'international' })
12
- * • Configurable emails Fake.email({ provider: 'company.io' })
13
- * • Flexible usernames Fake.username({ style: 'underscore' })
14
- * • Fixed-length numeric strings Fake.numericString(8)
8
+ * • Seeded / reproducible output - Fake.seed(42)
9
+ * • Guaranteed-unique values - Fake.unique(() => Fake.email())
10
+ * • Multi-locale names - Fake.firstName({ locale: 'ja', sex: 'female' })
11
+ * • Rich phone formats - Fake.phone({ countryCode: 'DE', format: 'international' })
12
+ * • Configurable emails - Fake.email({ provider: 'company.io' })
13
+ * • Flexible usernames - Fake.username({ style: 'underscore' })
14
+ * • Fixed-length numeric strings - Fake.numericString(8)
15
15
  * • Person: job titles, bio, zodiac, gender, prefix/suffix
16
16
  * • Location: city, country, state, address, lat/lng, timezone
17
17
  * • Commerce: product, company, category, price, industry
@@ -928,7 +928,7 @@ class Fake
928
928
  // -- Internet & Network -------------------------------------------------
929
929
 
930
930
  /**
931
- * Random email address (backward-compatible shorthand same as email()).
931
+ * Random email address (backward-compatible shorthand - same as email()).
932
932
  * Accepts no arguments for historical use.
933
933
  */
934
934
 
@@ -1051,7 +1051,7 @@ class Fake
1051
1051
  static userAgent() { return _pick(USER_AGENTS); }
1052
1052
 
1053
1053
  /**
1054
- * Random password-like string. NOT suitable for real passwords uses a
1054
+ * Random password-like string. NOT suitable for real passwords - uses a
1055
1055
  * PRNG seeded from Math.random, not a CSPRNG.
1056
1056
  *
1057
1057
  * @param {object} [options] - Configuration options.
@@ -1180,7 +1180,7 @@ class Fake
1180
1180
  }
1181
1181
  }
1182
1182
 
1183
- // Static uniqueness tracker shared across all calls in the process lifetime
1183
+ // Static uniqueness tracker - shared across all calls in the process lifetime
1184
1184
  Fake._tracker = new UniqueTracker();
1185
1185
 
1186
1186
  module.exports = { Fake };
@@ -5,10 +5,10 @@
5
5
  * @description Public API for the seed subsystem.
6
6
  *
7
7
  * Re-exports:
8
- * - `Fake` static fake-data generator
9
- * - `Factory` model factory for defining / creating test fixtures
10
- * - `Seeder` base class for database seeders
11
- * - `SeederRunner` orchestrates running multiple seeders
8
+ * - `Fake` - static fake-data generator
9
+ * - `Factory` - model factory for defining / creating test fixtures
10
+ * - `Seeder` - base class for database seeders
11
+ * - `SeederRunner` - orchestrates running multiple seeders
12
12
  */
13
13
 
14
14
  const { Fake } = require('./fake');
@@ -14,7 +14,7 @@
14
14
  */
15
15
 
16
16
  /**
17
- * mulberry32 minimal, high-quality 32-bit PRNG.
17
+ * mulberry32 - minimal, high-quality 32-bit PRNG.
18
18
  * @param {number} s - Unsigned 32-bit integer seed.
19
19
  * @returns {() => number} Float in [0, 1).
20
20
  */
@@ -234,7 +234,7 @@ function generateMigrationCode(migrationName, changes, currentSnap)
234
234
  for (const table of changes.tables.dropped)
235
235
  {
236
236
  upLines.push(` await db.adapter.dropTable('${table}');`);
237
- // down recreates but we need the previous snapshot's schema for that
237
+ // down recreates - but we need the previous snapshot's schema for that
238
238
  // This is handled via the `prev` reference embedded in the dropped table
239
239
  }
240
240
 
@@ -268,8 +268,8 @@ function generateMigrationCode(migrationName, changes, currentSnap)
268
268
  return `'use strict';
269
269
 
270
270
  /**
271
- * Auto-generated migration ${migrationName}
272
- * Generated by: npx zh make:migration
271
+ * Auto-generated migration - ${migrationName}
272
+ * Generated by: npx zs make:migration
273
273
  */
274
274
  module.exports = {
275
275
  name: '${migrationName}',
@@ -43,8 +43,8 @@ class TenantContext
43
43
  /**
44
44
  * Multi-tenancy manager.
45
45
  * Supports two strategies:
46
- * - `'row'` adds a tenant column to every query (row-level isolation)
47
- * - `'schema'` uses separate database schemas per tenant (PostgreSQL)
46
+ * - `'row'` - adds a tenant column to every query (row-level isolation)
47
+ * - `'schema'` - uses separate database schemas per tenant (PostgreSQL)
48
48
  */
49
49
  class TenantManager
50
50
  {
@@ -242,7 +242,7 @@ class TenantManager
242
242
  const origCount = ModelClass.count.bind(ModelClass);
243
243
  const origExists = ModelClass.exists.bind(ModelClass);
244
244
 
245
- // Patch query() all query builder paths
245
+ // Patch query() - all query builder paths
246
246
  ModelClass.query = function ()
247
247
  {
248
248
  const q = origQuery();
@@ -251,7 +251,7 @@ class TenantManager
251
251
  return q;
252
252
  };
253
253
 
254
- // Patch create() inject tenant column
254
+ // Patch create() - inject tenant column
255
255
  ModelClass.create = async function (data)
256
256
  {
257
257
  const tid = manager.getCurrentTenant();
@@ -283,7 +283,7 @@ class TenantManager
283
283
  return origFindOne(conditions);
284
284
  };
285
285
 
286
- // Patch findById() still applies tenant scope
286
+ // Patch findById() - still applies tenant scope
287
287
  ModelClass.findById = async function (id)
288
288
  {
289
289
  const tid = manager.getCurrentTenant();
@@ -344,7 +344,7 @@ class TenantManager
344
344
  throw new Error('Schema-based tenancy requires a SQL adapter');
345
345
  }
346
346
 
347
- // Sanitize schema name only allow alphanumerics and underscores
347
+ // Sanitize schema name - only allow alphanumerics and underscores
348
348
  if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(schema))
349
349
  {
350
350
  throw new Error(`Invalid schema name: "${schema}"`);
package/lib/orm/views.js CHANGED
@@ -293,7 +293,7 @@ class DatabaseView
293
293
  const descriptor = this._query.build();
294
294
  const table = descriptor.table;
295
295
 
296
- // Validate field names and table identifier-safe only
296
+ // Validate field names and table - identifier-safe only
297
297
  const idRe = /^[a-zA-Z_][a-zA-Z0-9_.*]*$/;
298
298
  const fields = descriptor.fields
299
299
  ? descriptor.fields.filter(f => idRe.test(f)).join(', ') || '*'
@@ -298,56 +298,56 @@ class Router
298
298
  }
299
299
 
300
300
  /**
301
- * @see Router#add shortcut for GET requests.
301
+ * @see Router#add - shortcut for GET requests.
302
302
  * @param {string} path - Route pattern.
303
303
  * @param {...Function} fns - Handler functions.
304
304
  * @returns {Router} `this` for chaining.
305
305
  */
306
306
  get(path, ...fns) { const o = this._extractOpts(fns); this.add('GET', path, fns, o); return this; }
307
307
  /**
308
- * @see Router#add shortcut for POST requests.
308
+ * @see Router#add - shortcut for POST requests.
309
309
  * @param {string} path - Route pattern.
310
310
  * @param {...Function} fns - Handler functions.
311
311
  * @returns {Router} `this` for chaining.
312
312
  */
313
313
  post(path, ...fns) { const o = this._extractOpts(fns); this.add('POST', path, fns, o); return this; }
314
314
  /**
315
- * @see Router#add shortcut for PUT requests.
315
+ * @see Router#add - shortcut for PUT requests.
316
316
  * @param {string} path - Route pattern.
317
317
  * @param {...Function} fns - Handler functions.
318
318
  * @returns {Router} `this` for chaining.
319
319
  */
320
320
  put(path, ...fns) { const o = this._extractOpts(fns); this.add('PUT', path, fns, o); return this; }
321
321
  /**
322
- * @see Router#add shortcut for DELETE requests.
322
+ * @see Router#add - shortcut for DELETE requests.
323
323
  * @param {string} path - Route pattern.
324
324
  * @param {...Function} fns - Handler functions.
325
325
  * @returns {Router} `this` for chaining.
326
326
  */
327
327
  delete(path, ...fns) { const o = this._extractOpts(fns); this.add('DELETE', path, fns, o); return this; }
328
328
  /**
329
- * @see Router#add shortcut for PATCH requests.
329
+ * @see Router#add - shortcut for PATCH requests.
330
330
  * @param {string} path - Route pattern.
331
331
  * @param {...Function} fns - Handler functions.
332
332
  * @returns {Router} `this` for chaining.
333
333
  */
334
334
  patch(path, ...fns) { const o = this._extractOpts(fns); this.add('PATCH', path, fns, o); return this; }
335
335
  /**
336
- * @see Router#add shortcut for OPTIONS requests.
336
+ * @see Router#add - shortcut for OPTIONS requests.
337
337
  * @param {string} path - Route pattern.
338
338
  * @param {...Function} fns - Handler functions.
339
339
  * @returns {Router} `this` for chaining.
340
340
  */
341
341
  options(path, ...fns) { const o = this._extractOpts(fns); this.add('OPTIONS', path, fns, o); return this; }
342
342
  /**
343
- * @see Router#add shortcut for HEAD requests.
343
+ * @see Router#add - shortcut for HEAD requests.
344
344
  * @param {string} path - Route pattern.
345
345
  * @param {...Function} fns - Handler functions.
346
346
  * @returns {Router} `this` for chaining.
347
347
  */
348
348
  head(path, ...fns) { const o = this._extractOpts(fns); this.add('HEAD', path, fns, o); return this; }
349
349
  /**
350
- * @see Router#add matches every HTTP method.
350
+ * @see Router#add - matches every HTTP method.
351
351
  * @param {string} path - Route pattern.
352
352
  * @param {...Function} fns - Handler functions.
353
353
  * @returns {Router} `this` for chaining.
@@ -355,7 +355,7 @@ class Router
355
355
  all(path, ...fns) { const o = this._extractOpts(fns); this.add('ALL', path, fns, o); return this; }
356
356
 
357
357
  /**
358
- * Chainable route builder register multiple methods on the same path.
358
+ * Chainable route builder - register multiple methods on the same path.
359
359
  *
360
360
  * @example
361
361
  * router.route('/users')