@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.
- package/README.md +54 -53
- package/index.js +116 -4
- package/lib/app.js +22 -22
- package/lib/auth/authorize.js +11 -11
- package/lib/auth/enrollment.js +5 -5
- package/lib/auth/jwt.js +9 -9
- package/lib/auth/oauth.js +1 -1
- package/lib/auth/session.js +5 -5
- package/lib/auth/trustedDevice.js +2 -2
- package/lib/auth/twoFactor.js +11 -11
- package/lib/auth/webauthn.js +6 -6
- package/lib/body/json.js +1 -1
- package/lib/body/raw.js +1 -1
- package/lib/body/rawBuffer.js +1 -1
- package/lib/body/text.js +1 -1
- package/lib/body/urlencoded.js +3 -3
- package/lib/cli.js +43 -28
- package/lib/cluster.js +3 -3
- package/lib/debug.js +10 -10
- package/lib/env/index.js +11 -11
- package/lib/errors.js +131 -16
- package/lib/fetch/index.js +1 -1
- package/lib/grpc/call.js +14 -14
- package/lib/grpc/client.js +4 -4
- package/lib/grpc/codec.js +7 -7
- package/lib/grpc/credentials.js +2 -2
- package/lib/grpc/frame.js +2 -2
- package/lib/grpc/health.js +3 -3
- package/lib/grpc/index.js +3 -3
- package/lib/grpc/metadata.js +3 -3
- package/lib/grpc/proto.js +5 -5
- package/lib/grpc/reflection.js +2 -2
- package/lib/grpc/server.js +3 -3
- package/lib/grpc/status.js +2 -2
- package/lib/grpc/watch.js +1 -1
- package/lib/http/request.js +13 -13
- package/lib/http/response.js +2 -2
- package/lib/lifecycle.js +5 -5
- package/lib/middleware/compress.js +4 -4
- package/lib/observe/health.js +1 -1
- package/lib/observe/index.js +1 -1
- package/lib/observe/logger.js +3 -3
- package/lib/observe/metrics.js +4 -4
- package/lib/observe/tracing.js +4 -4
- package/lib/orm/adapters/json.js +1 -1
- package/lib/orm/adapters/memory.js +2 -2
- package/lib/orm/adapters/mongo.js +2 -2
- package/lib/orm/adapters/mysql.js +2 -2
- package/lib/orm/adapters/postgres.js +2 -2
- package/lib/orm/adapters/sqlite.js +3 -3
- package/lib/orm/audit.js +1 -1
- package/lib/orm/index.js +7 -7
- package/lib/orm/migrate.js +1 -1
- package/lib/orm/model.js +15 -15
- package/lib/orm/procedures.js +1 -1
- package/lib/orm/profiler.js +1 -1
- package/lib/orm/query.js +9 -9
- package/lib/orm/schema.js +1 -1
- package/lib/orm/seed/data/person.js +1 -1
- package/lib/orm/seed/fake.js +10 -10
- package/lib/orm/seed/index.js +4 -4
- package/lib/orm/seed/rng.js +1 -1
- package/lib/orm/snapshot.js +3 -3
- package/lib/orm/tenancy.js +6 -6
- package/lib/orm/views.js +1 -1
- package/lib/router/index.js +9 -9
- package/lib/webrtc/bot.js +405 -0
- package/lib/webrtc/cli.js +182 -0
- package/lib/webrtc/cluster.js +338 -0
- package/lib/webrtc/e2ee.js +274 -0
- package/lib/webrtc/ice.js +363 -0
- package/lib/webrtc/index.js +212 -0
- package/lib/webrtc/joinToken.js +171 -0
- package/lib/webrtc/observe.js +260 -0
- package/lib/webrtc/peer.js +143 -0
- package/lib/webrtc/room.js +184 -0
- package/lib/webrtc/sdp.js +503 -0
- package/lib/webrtc/sfu/index.js +251 -0
- package/lib/webrtc/sfu/livekit.js +304 -0
- package/lib/webrtc/sfu/mediasoup.js +357 -0
- package/lib/webrtc/sfu/memory.js +221 -0
- package/lib/webrtc/signaling.js +590 -0
- package/lib/webrtc/stun.js +484 -0
- package/lib/webrtc/turn/codec.js +370 -0
- package/lib/webrtc/turn/credentials.js +156 -0
- package/lib/webrtc/turn/server.js +648 -0
- package/package.json +2 -2
- package/types/body.d.ts +82 -14
- package/types/cli.d.ts +40 -2
- package/types/index.d.ts +19 -6
- package/types/middleware.d.ts +18 -72
- package/types/orm.d.ts +4 -13
- package/types/request.d.ts +3 -3
- 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()
|
|
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
|
|
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
|
|
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()
|
|
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()
|
|
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()
|
|
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()
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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'],
|
package/lib/orm/seed/fake.js
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* @description Extensible fake data generator.
|
|
6
6
|
*
|
|
7
7
|
* Key capabilities:
|
|
8
|
-
* • Seeded / reproducible output
|
|
9
|
-
* • Guaranteed-unique values
|
|
10
|
-
* • Multi-locale names
|
|
11
|
-
* • Rich phone formats
|
|
12
|
-
* • Configurable emails
|
|
13
|
-
* • Flexible usernames
|
|
14
|
-
* • Fixed-length numeric strings
|
|
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
|
|
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
|
|
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
|
|
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 };
|
package/lib/orm/seed/index.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* @description Public API for the seed subsystem.
|
|
6
6
|
*
|
|
7
7
|
* Re-exports:
|
|
8
|
-
* - `Fake`
|
|
9
|
-
* - `Factory`
|
|
10
|
-
* - `Seeder`
|
|
11
|
-
* - `SeederRunner`
|
|
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');
|
package/lib/orm/seed/rng.js
CHANGED
package/lib/orm/snapshot.js
CHANGED
|
@@ -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
|
|
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
|
|
272
|
-
* Generated by: npx
|
|
271
|
+
* Auto-generated migration - ${migrationName}
|
|
272
|
+
* Generated by: npx zs make:migration
|
|
273
273
|
*/
|
|
274
274
|
module.exports = {
|
|
275
275
|
name: '${migrationName}',
|
package/lib/orm/tenancy.js
CHANGED
|
@@ -43,8 +43,8 @@ class TenantContext
|
|
|
43
43
|
/**
|
|
44
44
|
* Multi-tenancy manager.
|
|
45
45
|
* Supports two strategies:
|
|
46
|
-
* - `'row'`
|
|
47
|
-
* - `'schema'`
|
|
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()
|
|
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()
|
|
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()
|
|
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
|
|
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
|
|
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(', ') || '*'
|
package/lib/router/index.js
CHANGED
|
@@ -298,56 +298,56 @@ class Router
|
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
/**
|
|
301
|
-
* @see Router#add
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
358
|
+
* Chainable route builder - register multiple methods on the same path.
|
|
359
359
|
*
|
|
360
360
|
* @example
|
|
361
361
|
* router.route('/users')
|